Skip to content

Commit 6b54b98

Browse files
committed
fix: Unify some types
Unified some types across functions. Fixed loadConfig to not being async.
1 parent 2e8a1ce commit 6b54b98

File tree

9 files changed

+56
-42
lines changed

9 files changed

+56
-42
lines changed

src/cli.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import 'dotenv/config';
22

33
import pkg from "../package.json" with { type: "json" };
44

5-
// @ts-ignore
6-
import { Command } from 'commander';
5+
import { Command, } from 'commander';
76
import { loadConfig, printConfig } from './features/config/index.js';
8-
import { del, down, typescript, up, type TypescriptConversionOptions } from './features/schema/index.js';
7+
import { del, down, typescript, up, type CLI_DeleteType, type CLI_DownType, type CLI_UpType, type TypescriptConversionOptions } from './features/schema/index.js';
98

109
main().catch((error) => {
1110
console.error("Error: " + error.message);
@@ -23,8 +22,8 @@ async function main() {
2322
program
2423
.command("config")
2524
.description("Returns the current configuration")
26-
.action(async () => {
27-
await loadConfig(program.opts().configPath);
25+
.action(() => {
26+
loadConfig(program.opts().configPath);
2827

2928
printConfig();
3029
});
@@ -38,8 +37,8 @@ async function main() {
3837
)
3938
.option("--ignore <ignore...>", "Class(es) to ignore", "")
4039
.description("Fetch the schema from Parse Server")
41-
.action(async (schemaPath: string, options: { prefix?: string; ignore?: string[]; } | undefined) => {
42-
await loadConfig(program.opts().configPath, {
40+
.action(async (schemaPath: string, options: CLI_DownType | undefined) => {
41+
loadConfig(program.opts().configPath, {
4342
operation: "down",
4443
});
4544

@@ -57,8 +56,8 @@ async function main() {
5756
.option("--safe", "This will prevent destructive operations", "")
5857
.option("--deleteNonEmptyClass", "Delete non-empty classes", false)
5958
.description("Upload the local schema to Parse Server")
60-
.action(async (schemaPath: string, options: { prefix: any; ignore: any; safe: any; deleteNonEmptyClass: any; }) => {
61-
await loadConfig(program.opts().configPath, {
59+
.action(async (schemaPath: string, options: CLI_UpType) => {
60+
loadConfig(program.opts().configPath, {
6261
operation: "up",
6362
});
6463

@@ -80,8 +79,8 @@ async function main() {
8079
)
8180
.option("--deleteNonEmptyClass", "Delete non-empty classes", false)
8281
.description("Delete the local schema from Parse Server")
83-
.action(async (schemaPath: string, options: { prefix?: string; deleteNonEmptyClass?: boolean; } | undefined) => {
84-
await loadConfig(program.opts().configPath);
82+
.action(async (schemaPath: string, options: CLI_DeleteType | undefined) => {
83+
loadConfig(program.opts().configPath);
8584

8685
await del( schemaPath, options);
8786
});
@@ -100,7 +99,7 @@ async function main() {
10099
.option("--custom-class-field-types-config <path>", "Path to .json config file for custom class field types")
101100
.option("--verbose", "Enable verbose logging including dependency graph", false)
102101
.action(async (typescriptPath: string, options: TypescriptConversionOptions | undefined) => {
103-
await loadConfig(program.opts().configPath);
102+
loadConfig(program.opts().configPath);
104103

105104
await typescript(typescriptPath, options);
106105
});

src/features/config/services/loadConfig.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import type { ConfigInterface } from "../index.js";
1010
* @param options Options for loading the config.
1111
* @returns The loaded config.
1212
*/
13-
export async function loadConfig(
13+
export function loadConfig(
1414
configPath?: string,
15-
options?: { operation: string }
16-
): Promise<ConfigInterface> {
15+
options?: { operation: "down" | "up" }
16+
): ConfigInterface {
1717
const {
1818
PARSE_SERVER_APPLICATION_ID,
1919
PARSE_SERVER_MASTER_KEY,

src/features/schema/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ export {
2020
type SetterType,
2121
type TypescriptConversionOptions,
2222
} from "./types/TypescriptConversionTypes.js";
23+
24+
export { type CLI_DeleteType, type DeleteType } from "./types/DeleteTypes.js";
25+
export { type CLI_DownType, type DownType } from "./types/DownTypes.js";
26+
export { type CLI_UpType, type UpType } from "./types/UpTypes.js";

src/features/schema/services/del.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import path from "path";
2-
import { deleteSchema, getLocalSchema, getRemoteSchema } from "../index.js";
2+
import {
3+
deleteSchema,
4+
getLocalSchema,
5+
getRemoteSchema,
6+
type DeleteType,
7+
} from "../index.js";
38

49
/**
510
* Deletes the schema from Parse Server.
@@ -9,13 +14,7 @@ import { deleteSchema, getLocalSchema, getRemoteSchema } from "../index.js";
914
* @param options.prefix Only classes with the given prefix will be deleted. The prefix will be added to the class names in the local schema.
1015
* @param options.deleteNonEmptyClass Whether to delete non-empty classes when deleting a class. Default is
1116
*/
12-
export async function del(
13-
schemaPath: string,
14-
options: {
15-
prefix?: string;
16-
deleteNonEmptyClass?: boolean;
17-
} = {}
18-
) {
17+
export async function del(schemaPath: string, options: DeleteType = {}) {
1918
const localSchemaPath = schemaPath
2019
? path.resolve(schemaPath)
2120
: path.resolve(".", "schema", "classes");

src/features/schema/services/down.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from "fs";
22
import { mkdirp } from "mkdirp";
33
import path from "path";
4-
import { getRemoteSchema } from "../index.js";
4+
import { getRemoteSchema, type DownType } from "../index.js";
55

66
/**
77
* Fetches the schema from Parse Server and saves it to a local file or folder.
@@ -11,13 +11,7 @@ import { getRemoteSchema } from "../index.js";
1111
* @param options.prefix Only classes with the given prefix will be pulled. The prefix will be removed from the class names in the local schema.
1212
* @param options.ignore Class(es) to ignore. You can use * at the end to ignore all classes that start with the given string.
1313
*/
14-
export async function down(
15-
schemaPath: string,
16-
options: {
17-
prefix?: string;
18-
ignore?: string[];
19-
} = {}
20-
) {
14+
export async function down(schemaPath: string, options: DownType = {}) {
2115
let schema = await getRemoteSchema();
2216

2317
const prefix = options.prefix;

src/features/schema/services/up.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
getLocalSchema,
77
getRemoteSchema,
88
updateSchema,
9+
type UpType,
910
} from "../index.js";
1011

1112
/**
@@ -19,17 +20,7 @@ import {
1920
* @param options.deleteFields Whether to delete fields that are not in the local schema. Default is true.
2021
* @param options.deleteNonEmptyClass Whether to delete non-empty classes when deleting a class. Default is
2122
*/
22-
export async function up(
23-
schemaPath: string,
24-
options: {
25-
ignore?: string[];
26-
prefix?: string;
27-
deleteClasses?: boolean;
28-
deleteFields?: boolean;
29-
deleteNonEmptyClass?: boolean;
30-
filter?: (className: string) => boolean;
31-
} = {}
32-
) {
23+
export async function up(schemaPath: string, options: UpType = {}) {
3324
const localSchemaPath = schemaPath
3425
? path.resolve(schemaPath)
3526
: path.resolve(".", "schema", "classes");
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export type DeleteType = {
2+
prefix?: string;
3+
deleteNonEmptyClass?: boolean;
4+
};
5+
6+
export type CLI_DeleteType = { prefix?: string; deleteNonEmptyClass?: boolean };
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export type DownType = {
2+
prefix?: string;
3+
ignore?: string[];
4+
};
5+
6+
export type CLI_DownType = { prefix?: string; ignore?: string[] };
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export type UpType = {
2+
ignore?: string[];
3+
prefix?: string;
4+
deleteClasses?: boolean;
5+
deleteFields?: boolean;
6+
deleteNonEmptyClass?: boolean;
7+
filter?: (className: string) => boolean;
8+
};
9+
10+
export type CLI_UpType = {
11+
prefix: string | undefined;
12+
ignore: string[] | undefined;
13+
safe: boolean | undefined;
14+
deleteNonEmptyClass: boolean | undefined;
15+
};

0 commit comments

Comments
 (0)