@nestia/migrate 0.7.5 → 0.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/MigrateApplication.d.ts +9 -2
- package/lib/MigrateApplication.js +21 -12
- package/lib/MigrateApplication.js.map +1 -1
- package/lib/analyzers/MigrateAnalyzer.d.ts +2 -3
- package/lib/analyzers/MigrateAnalyzer.js +2 -6
- package/lib/analyzers/MigrateAnalyzer.js.map +1 -1
- package/lib/analyzers/MigrateControllerAnalyzer.d.ts +5 -0
- package/lib/analyzers/{ControllerAnalyzer.js → MigrateControllerAnalyzer.js} +31 -20
- package/lib/analyzers/MigrateControllerAnalyzer.js.map +1 -0
- package/lib/analyzers/{MethodAnalyzer.d.ts → MigrateMethodAnalyzer.d.ts} +3 -3
- package/lib/analyzers/{MethodAnalyzer.js → MigrateMethodAnalyzer.js} +40 -39
- package/lib/analyzers/MigrateMethodAnalyzer.js.map +1 -0
- package/lib/archivers/{FileArchiver.d.ts → MigrateFileArchiver.d.ts} +1 -1
- package/lib/archivers/{FileArchiver.js → MigrateFileArchiver.js} +6 -6
- package/lib/archivers/MigrateFileArchiver.js.map +1 -0
- package/lib/bundles/SDK_TEMPLATE.js +0 -5
- package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
- package/lib/executable/bundle.js +1 -0
- package/lib/executable/bundle.js.map +1 -1
- package/lib/internal/MigrateCommander.js +3 -3
- package/lib/internal/MigrateCommander.js.map +1 -1
- package/lib/module.d.ts +8 -0
- package/lib/module.js +8 -0
- package/lib/module.js.map +1 -1
- package/lib/programmers/{ApiFileProgrammer.d.ts → MigrateApiFileProgrammer.d.ts} +3 -3
- package/lib/programmers/MigrateApiFileProgrammer.js +28 -0
- package/lib/programmers/MigrateApiFileProgrammer.js.map +1 -0
- package/lib/programmers/MigrateApiFunctionProgrammer.d.ts +15 -0
- package/lib/programmers/{ApiFunctionProgrammer.js → MigrateApiFunctionProgrammer.js} +10 -10
- package/lib/programmers/MigrateApiFunctionProgrammer.js.map +1 -0
- package/lib/programmers/{ApiNamespaceProgrammer.d.ts → MigrateApiNamespaceProgrammer.d.ts} +4 -4
- package/lib/programmers/{ApiNamespaceProgrammer.js → MigrateApiNamespaceProgrammer.js} +19 -19
- package/lib/programmers/MigrateApiNamespaceProgrammer.js.map +1 -0
- package/lib/programmers/{ApiProgrammer.d.ts → MigrateApiProgrammer.d.ts} +1 -1
- package/lib/programmers/{ApiProgrammer.js → MigrateApiProgrammer.js} +27 -22
- package/lib/programmers/MigrateApiProgrammer.js.map +1 -0
- package/lib/programmers/{ApiSimulatationProgrammer.d.ts → MigrateApiSimulatationProgrammer.d.ts} +4 -4
- package/lib/programmers/{ApiSimulatationProgrammer.js → MigrateApiSimulatationProgrammer.js} +16 -16
- package/lib/programmers/MigrateApiSimulatationProgrammer.js.map +1 -0
- package/lib/programmers/{DtoProgrammer.d.ts → MigrateDtoProgrammer.d.ts} +3 -3
- package/lib/programmers/{DtoProgrammer.js → MigrateDtoProgrammer.js} +8 -8
- package/lib/programmers/MigrateDtoProgrammer.js.map +1 -0
- package/lib/programmers/{ImportProgrammer.d.ts → MigrateImportProgrammer.d.ts} +3 -3
- package/lib/programmers/{ImportProgrammer.js → MigrateImportProgrammer.js} +12 -10
- package/lib/programmers/MigrateImportProgrammer.js.map +1 -0
- package/lib/programmers/{NestControllerProgrammer.d.ts → MigrateNestControllerProgrammer.d.ts} +1 -1
- package/lib/programmers/{NestControllerProgrammer.js → MigrateNestControllerProgrammer.js} +11 -11
- package/lib/programmers/MigrateNestControllerProgrammer.js.map +1 -0
- package/lib/programmers/{NestMethodProgrammer.d.ts → MigrateNestMethodProgrammer.d.ts} +3 -3
- package/lib/programmers/{NestMethodProgrammer.js → MigrateNestMethodProgrammer.js} +13 -11
- package/lib/programmers/MigrateNestMethodProgrammer.js.map +1 -0
- package/lib/programmers/{NestModuleProgrammer.d.ts → MigrateNestModuleProgrammer.d.ts} +1 -1
- package/lib/programmers/{NestModuleProgrammer.js → MigrateNestModuleProgrammer.js} +8 -8
- package/lib/programmers/MigrateNestModuleProgrammer.js.map +1 -0
- package/lib/programmers/{NestProgrammer.d.ts → MigrateNestProgrammer.d.ts} +1 -1
- package/lib/programmers/{NestProgrammer.js → MigrateNestProgrammer.js} +17 -15
- package/lib/programmers/MigrateNestProgrammer.js.map +1 -0
- package/lib/programmers/MigrateSchemaProgrammer.d.ts +7 -0
- package/lib/programmers/{SchemaProgrammer.js → MigrateSchemaProgrammer.js} +23 -23
- package/lib/programmers/MigrateSchemaProgrammer.js.map +1 -0
- package/lib/structures/IMigrateDto.d.ts +1 -1
- package/lib/structures/IMigrateProgram.d.ts +20 -4
- package/lib/structures/IMigrateRoute.d.ts +2 -1
- package/lib/structures/ISwaggerComponents.d.ts +1 -1
- package/lib/structures/ISwaggerRoute.d.ts +1 -1
- package/lib/structures/{ISwaggeSchema.js → ISwaggerSchema.js} +1 -1
- package/lib/structures/ISwaggerSchema.js.map +1 -0
- package/lib/utils/FilePrinter.d.ts +1 -1
- package/lib/utils/FilePrinter.js +1 -1
- package/lib/utils/FilePrinter.js.map +1 -1
- package/lib/utils/{JsonTypeChecker.d.ts → SwaggerTypeChecker.d.ts} +2 -2
- package/lib/utils/SwaggerTypeChecker.js +34 -0
- package/lib/utils/SwaggerTypeChecker.js.map +1 -0
- package/package.json +68 -68
- package/src/MigrateApplication.ts +35 -16
- package/src/analyzers/MigrateAnalyzer.ts +6 -10
- package/src/analyzers/{ControllerAnalyzer.ts → MigrateControllerAnalyzer.ts} +39 -23
- package/src/analyzers/{MethodAnalyzer.ts → MigrateMethodAnalyzer.ts} +45 -42
- package/src/archivers/{FileArchiver.ts → MigrateFileArchiver.ts} +1 -1
- package/src/bundles/SDK_TEMPLATE.ts +0 -5
- package/src/executable/bundle.ts +1 -0
- package/src/executable/migrate.ts +7 -7
- package/src/internal/MigrateCommander.ts +3 -4
- package/src/internal/MigrateInquirer.ts +79 -79
- package/src/module.ts +14 -4
- package/src/programmers/{ApiFileProgrammer.ts → MigrateApiFileProgrammer.ts} +9 -9
- package/src/programmers/{ApiFunctionProgrammer.ts → MigrateApiFunctionProgrammer.ts} +10 -10
- package/src/programmers/{ApiNamespaceProgrammer.ts → MigrateApiNamespaceProgrammer.ts} +33 -21
- package/src/programmers/{ApiProgrammer.ts → MigrateApiProgrammer.ts} +44 -40
- package/src/programmers/{ApiSimulatationProgrammer.ts → MigrateApiSimulatationProgrammer.ts} +15 -15
- package/src/programmers/{DtoProgrammer.ts → MigrateDtoProgrammer.ts} +12 -8
- package/src/programmers/{ImportProgrammer.ts → MigrateImportProgrammer.ts} +16 -16
- package/src/programmers/{NestControllerProgrammer.ts → MigrateNestControllerProgrammer.ts} +8 -6
- package/src/programmers/{NestMethodProgrammer.ts → MigrateNestMethodProgrammer.ts} +18 -12
- package/src/programmers/{NestModuleProgrammer.ts → MigrateNestModuleProgrammer.ts} +3 -3
- package/src/programmers/{NestProgrammer.ts → MigrateNestProgrammer.ts} +21 -21
- package/src/programmers/{SchemaProgrammer.ts → MigrateSchemaProgrammer.ts} +29 -27
- package/src/structures/IMigrateDto.ts +1 -1
- package/src/structures/IMigrateProgram.ts +25 -9
- package/src/structures/IMigrateRoute.ts +2 -1
- package/src/structures/ISwaggerComponents.ts +1 -1
- package/src/structures/ISwaggerInfo.ts +80 -80
- package/src/structures/ISwaggerRoute.ts +1 -1
- package/src/structures/{ISwaggeSchema.ts → ISwaggerSchema.ts} +90 -90
- package/src/utils/FilePrinter.ts +1 -1
- package/src/utils/SetupWizard.ts +12 -12
- package/src/utils/StringUtil.ts +60 -60
- package/src/utils/{JsonTypeChecker.ts → SwaggerTypeChecker.ts} +5 -5
- package/lib/IMigrateConfig.d.ts +0 -4
- package/lib/IMigrateConfig.js +0 -3
- package/lib/IMigrateConfig.js.map +0 -1
- package/lib/analyzers/ControllerAnalyzer.d.ts +0 -5
- package/lib/analyzers/ControllerAnalyzer.js.map +0 -1
- package/lib/analyzers/MethodAnalyzer.js.map +0 -1
- package/lib/archivers/FileArchiver.js.map +0 -1
- package/lib/programmers/ApiFileProgrammer.js +0 -28
- package/lib/programmers/ApiFileProgrammer.js.map +0 -1
- package/lib/programmers/ApiFunctionProgrammer.d.ts +0 -15
- package/lib/programmers/ApiFunctionProgrammer.js.map +0 -1
- package/lib/programmers/ApiNamespaceProgrammer.js.map +0 -1
- package/lib/programmers/ApiProgrammer.js.map +0 -1
- package/lib/programmers/ApiSimulatationProgrammer.js.map +0 -1
- package/lib/programmers/DtoProgrammer.js.map +0 -1
- package/lib/programmers/ImportProgrammer.js.map +0 -1
- package/lib/programmers/NestControllerProgrammer.js.map +0 -1
- package/lib/programmers/NestMethodProgrammer.js.map +0 -1
- package/lib/programmers/NestModuleProgrammer.js.map +0 -1
- package/lib/programmers/NestProgrammer.js.map +0 -1
- package/lib/programmers/SchemaProgrammer.d.ts +0 -7
- package/lib/programmers/SchemaProgrammer.js.map +0 -1
- package/lib/structures/ISwaggeSchema.js.map +0 -1
- package/lib/utils/JsonTypeChecker.js +0 -34
- package/lib/utils/JsonTypeChecker.js.map +0 -1
- package/src/IMigrateConfig.ts +0 -4
- /package/lib/structures/{ISwaggeSchema.d.ts → ISwaggerSchema.d.ts} +0 -0
@@ -1,79 +1,79 @@
|
|
1
|
-
import commander from "commander";
|
2
|
-
import inquirer from "inquirer";
|
3
|
-
|
4
|
-
export namespace MigrateInquirer {
|
5
|
-
export interface IOutput {
|
6
|
-
mode: "nest" | "sdk";
|
7
|
-
simulate: boolean;
|
8
|
-
input: string;
|
9
|
-
output: string;
|
10
|
-
}
|
11
|
-
|
12
|
-
export const parse = async (): Promise<IOutput> => {
|
13
|
-
// PREPARE ASSETS
|
14
|
-
commander.program.option("--mode [nest/sdk]", "migration mode");
|
15
|
-
commander.program.option(
|
16
|
-
"--input [swagger.json]",
|
17
|
-
"location of target swagger.json file",
|
18
|
-
);
|
19
|
-
commander.program.option("--output [directory]", "output directory path");
|
20
|
-
commander.program.option("--simulate", "Mockup simulator");
|
21
|
-
|
22
|
-
// INTERNAL PROCEDURES
|
23
|
-
const questioned = { value: false };
|
24
|
-
const action = (closure: (options: Partial<IOutput>) => Promise<IOutput>) =>
|
25
|
-
new Promise<IOutput>((resolve, reject) => {
|
26
|
-
commander.program.action(async (options) => {
|
27
|
-
try {
|
28
|
-
resolve(await closure(options));
|
29
|
-
} catch (exp) {
|
30
|
-
reject(exp);
|
31
|
-
}
|
32
|
-
});
|
33
|
-
commander.program.parseAsync().catch(reject);
|
34
|
-
});
|
35
|
-
const select =
|
36
|
-
(name: string) =>
|
37
|
-
(message: string) =>
|
38
|
-
async <Choice extends string>(
|
39
|
-
choices: Choice[],
|
40
|
-
filter?: (value: string) => Choice,
|
41
|
-
): Promise<Choice> => {
|
42
|
-
questioned.value = true;
|
43
|
-
return (
|
44
|
-
await inquirer.createPromptModule()({
|
45
|
-
type: "list",
|
46
|
-
name: name,
|
47
|
-
message: message,
|
48
|
-
choices: choices,
|
49
|
-
filter,
|
50
|
-
})
|
51
|
-
)[name];
|
52
|
-
};
|
53
|
-
const input = (name: string) => async (message: string) =>
|
54
|
-
(
|
55
|
-
await inquirer.createPromptModule()({
|
56
|
-
type: "input",
|
57
|
-
name,
|
58
|
-
message,
|
59
|
-
})
|
60
|
-
)[name];
|
61
|
-
|
62
|
-
// DO CONSTRUCT
|
63
|
-
return action(async (partial) => {
|
64
|
-
partial.mode ??= await select("mode")("Migration mode")(
|
65
|
-
["NestJS" as "nest", "SDK" as "sdk"],
|
66
|
-
(value) => (value === "NestJS" ? "nest" : "sdk"),
|
67
|
-
);
|
68
|
-
partial.input ??= await input("input")("Swagger file location");
|
69
|
-
partial.output ??= await input("output")("Output directory path");
|
70
|
-
if (partial.simulate)
|
71
|
-
partial.simulate = (partial.simulate as any) === "true";
|
72
|
-
else
|
73
|
-
partial.simulate =
|
74
|
-
(await select("simulate")("Mokup Simulator")(["true", "false"])) ===
|
75
|
-
"true";
|
76
|
-
return partial as IOutput;
|
77
|
-
});
|
78
|
-
};
|
79
|
-
}
|
1
|
+
import commander from "commander";
|
2
|
+
import inquirer from "inquirer";
|
3
|
+
|
4
|
+
export namespace MigrateInquirer {
|
5
|
+
export interface IOutput {
|
6
|
+
mode: "nest" | "sdk";
|
7
|
+
simulate: boolean;
|
8
|
+
input: string;
|
9
|
+
output: string;
|
10
|
+
}
|
11
|
+
|
12
|
+
export const parse = async (): Promise<IOutput> => {
|
13
|
+
// PREPARE ASSETS
|
14
|
+
commander.program.option("--mode [nest/sdk]", "migration mode");
|
15
|
+
commander.program.option(
|
16
|
+
"--input [swagger.json]",
|
17
|
+
"location of target swagger.json file",
|
18
|
+
);
|
19
|
+
commander.program.option("--output [directory]", "output directory path");
|
20
|
+
commander.program.option("--simulate", "Mockup simulator");
|
21
|
+
|
22
|
+
// INTERNAL PROCEDURES
|
23
|
+
const questioned = { value: false };
|
24
|
+
const action = (closure: (options: Partial<IOutput>) => Promise<IOutput>) =>
|
25
|
+
new Promise<IOutput>((resolve, reject) => {
|
26
|
+
commander.program.action(async (options) => {
|
27
|
+
try {
|
28
|
+
resolve(await closure(options));
|
29
|
+
} catch (exp) {
|
30
|
+
reject(exp);
|
31
|
+
}
|
32
|
+
});
|
33
|
+
commander.program.parseAsync().catch(reject);
|
34
|
+
});
|
35
|
+
const select =
|
36
|
+
(name: string) =>
|
37
|
+
(message: string) =>
|
38
|
+
async <Choice extends string>(
|
39
|
+
choices: Choice[],
|
40
|
+
filter?: (value: string) => Choice,
|
41
|
+
): Promise<Choice> => {
|
42
|
+
questioned.value = true;
|
43
|
+
return (
|
44
|
+
await inquirer.createPromptModule()({
|
45
|
+
type: "list",
|
46
|
+
name: name,
|
47
|
+
message: message,
|
48
|
+
choices: choices,
|
49
|
+
filter,
|
50
|
+
})
|
51
|
+
)[name];
|
52
|
+
};
|
53
|
+
const input = (name: string) => async (message: string) =>
|
54
|
+
(
|
55
|
+
await inquirer.createPromptModule()({
|
56
|
+
type: "input",
|
57
|
+
name,
|
58
|
+
message,
|
59
|
+
})
|
60
|
+
)[name];
|
61
|
+
|
62
|
+
// DO CONSTRUCT
|
63
|
+
return action(async (partial) => {
|
64
|
+
partial.mode ??= await select("mode")("Migration mode")(
|
65
|
+
["NestJS" as "nest", "SDK" as "sdk"],
|
66
|
+
(value) => (value === "NestJS" ? "nest" : "sdk"),
|
67
|
+
);
|
68
|
+
partial.input ??= await input("input")("Swagger file location");
|
69
|
+
partial.output ??= await input("output")("Output directory path");
|
70
|
+
if (partial.simulate)
|
71
|
+
partial.simulate = (partial.simulate as any) === "true";
|
72
|
+
else
|
73
|
+
partial.simulate =
|
74
|
+
(await select("simulate")("Mokup Simulator")(["true", "false"])) ===
|
75
|
+
"true";
|
76
|
+
return partial as IOutput;
|
77
|
+
});
|
78
|
+
};
|
79
|
+
}
|
package/src/module.ts
CHANGED
@@ -1,4 +1,14 @@
|
|
1
|
-
export * from "./MigrateApplication";
|
2
|
-
|
3
|
-
export * from "./
|
4
|
-
|
1
|
+
export * from "./MigrateApplication";
|
2
|
+
|
3
|
+
export * from "./analyzers/MigrateAnalyzer";
|
4
|
+
|
5
|
+
export * from "./archivers/MigrateFileArchiver";
|
6
|
+
|
7
|
+
export * from "./structures/ISwagger";
|
8
|
+
export * from "./structures/ISwaggerComponents";
|
9
|
+
export * from "./structures/ISwaggerInfo";
|
10
|
+
export * from "./structures/ISwaggerRoute";
|
11
|
+
export * from "./structures/ISwaggerSecurity";
|
12
|
+
export * from "./structures/ISwaggerSchema";
|
13
|
+
export * from "./structures/IMigrateProgram";
|
14
|
+
export * from "./structures/IMigrateSchema";
|
@@ -1,14 +1,14 @@
|
|
1
1
|
import ts from "typescript";
|
2
2
|
|
3
|
-
import {
|
3
|
+
import { IMigrateProgram } from "../module";
|
4
4
|
import { IMigrateController } from "../structures/IMigrateController";
|
5
5
|
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
6
6
|
import { ISwaggerComponents } from "../structures/ISwaggerComponents";
|
7
|
-
import {
|
8
|
-
import {
|
9
|
-
import {
|
7
|
+
import { MigrateApiFunctionProgrammer } from "./MigrateApiFunctionProgrammer";
|
8
|
+
import { MigrateApiNamespaceProgrammer } from "./MigrateApiNamespaceProgrammer";
|
9
|
+
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
10
10
|
|
11
|
-
export namespace
|
11
|
+
export namespace MigrateApiFileProgrammer {
|
12
12
|
export interface IProps {
|
13
13
|
namespace: string[];
|
14
14
|
entries: IEntry[];
|
@@ -21,14 +21,14 @@ export namespace ApiFileProgrammer {
|
|
21
21
|
}
|
22
22
|
|
23
23
|
export const write =
|
24
|
-
(config:
|
24
|
+
(config: IMigrateProgram.IConfig) =>
|
25
25
|
(components: ISwaggerComponents) =>
|
26
26
|
(props: IProps): ts.Statement[] => {
|
27
|
-
const importer:
|
27
|
+
const importer: MigrateImportProgrammer = new MigrateImportProgrammer();
|
28
28
|
const statements: ts.Statement[] = props.entries
|
29
29
|
.map((p) => [
|
30
|
-
|
31
|
-
|
30
|
+
MigrateApiFunctionProgrammer.write(config)(components)(importer)(p),
|
31
|
+
MigrateApiNamespaceProgrammer.write(config)(components)(importer)(p),
|
32
32
|
])
|
33
33
|
.flat();
|
34
34
|
return [
|
@@ -1,15 +1,15 @@
|
|
1
1
|
import ts from "typescript";
|
2
2
|
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
3
3
|
|
4
|
-
import {
|
4
|
+
import { IMigrateProgram } from "../module";
|
5
5
|
import { IMigrateController } from "../structures/IMigrateController";
|
6
6
|
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
7
7
|
import { ISwaggerComponents } from "../structures/ISwaggerComponents";
|
8
8
|
import { FilePrinter } from "../utils/FilePrinter";
|
9
|
-
import {
|
10
|
-
import {
|
9
|
+
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
10
|
+
import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
|
11
11
|
|
12
|
-
export namespace
|
12
|
+
export namespace MigrateApiFunctionProgrammer {
|
13
13
|
export interface IProps {
|
14
14
|
controller: IMigrateController;
|
15
15
|
route: IMigrateRoute;
|
@@ -17,9 +17,9 @@ export namespace ApiFunctionProgrammer {
|
|
17
17
|
}
|
18
18
|
|
19
19
|
export const write =
|
20
|
-
(config:
|
20
|
+
(config: IMigrateProgram.IConfig) =>
|
21
21
|
(components: ISwaggerComponents) =>
|
22
|
-
(importer:
|
22
|
+
(importer: MigrateImportProgrammer) =>
|
23
23
|
(props: IProps): ts.FunctionDeclaration =>
|
24
24
|
FilePrinter.description(
|
25
25
|
ts.factory.createFunctionDeclaration(
|
@@ -43,7 +43,7 @@ export namespace ApiFunctionProgrammer {
|
|
43
43
|
|
44
44
|
export const writeParameterDeclarations =
|
45
45
|
(components: ISwaggerComponents) =>
|
46
|
-
(importer:
|
46
|
+
(importer: MigrateImportProgrammer) =>
|
47
47
|
(props: IProps): ts.ParameterDeclaration[] => [
|
48
48
|
IdentifierFactory.parameter(
|
49
49
|
"connection",
|
@@ -61,7 +61,7 @@ export namespace ApiFunctionProgrammer {
|
|
61
61
|
...props.route.parameters.map((p) =>
|
62
62
|
IdentifierFactory.parameter(
|
63
63
|
p.key,
|
64
|
-
|
64
|
+
MigrateSchemaProgrammer.write(components)(importer)(p.schema),
|
65
65
|
),
|
66
66
|
),
|
67
67
|
...(props.route.query
|
@@ -95,8 +95,8 @@ export namespace ApiFunctionProgrammer {
|
|
95
95
|
].join("\n");
|
96
96
|
|
97
97
|
const writeBody =
|
98
|
-
(config:
|
99
|
-
(importer:
|
98
|
+
(config: IMigrateProgram.IConfig) =>
|
99
|
+
(importer: MigrateImportProgrammer) =>
|
100
100
|
(props: IProps): ts.Statement[] => {
|
101
101
|
const encrypted: boolean = !!props.route.success?.["x-nestia-encrypted"];
|
102
102
|
const contentType: string = props.route.body?.type ?? "application/json";
|
@@ -4,16 +4,16 @@ import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
|
4
4
|
import { LiteralFactory } from "typia/lib/factories/LiteralFactory";
|
5
5
|
import { TypeFactory } from "typia/lib/factories/TypeFactory";
|
6
6
|
|
7
|
-
import { IMigrateConfig } from "../IMigrateConfig";
|
8
7
|
import { IMigrateController } from "../structures/IMigrateController";
|
8
|
+
import { IMigrateProgram } from "../structures/IMigrateProgram";
|
9
9
|
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
10
10
|
import { ISwaggerComponents } from "../structures/ISwaggerComponents";
|
11
11
|
import { FilePrinter } from "../utils/FilePrinter";
|
12
|
-
import {
|
13
|
-
import {
|
14
|
-
import {
|
12
|
+
import { MigrateApiSimulatationProgrammer } from "./MigrateApiSimulatationProgrammer";
|
13
|
+
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
14
|
+
import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
|
15
15
|
|
16
|
-
export namespace
|
16
|
+
export namespace MigrateApiNamespaceProgrammer {
|
17
17
|
export interface IProps {
|
18
18
|
controller: IMigrateController;
|
19
19
|
route: IMigrateRoute;
|
@@ -21,9 +21,9 @@ export namespace ApiNamespaceProgrammer {
|
|
21
21
|
}
|
22
22
|
|
23
23
|
export const write =
|
24
|
-
(config:
|
24
|
+
(config: IMigrateProgram.IConfig) =>
|
25
25
|
(components: ISwaggerComponents) =>
|
26
|
-
(importer:
|
26
|
+
(importer: MigrateImportProgrammer) =>
|
27
27
|
(props: IProps): ts.ModuleDeclaration => {
|
28
28
|
const types = writeTypes(components)(importer)(props.route);
|
29
29
|
return ts.factory.createModuleDeclaration(
|
@@ -31,14 +31,18 @@ export namespace ApiNamespaceProgrammer {
|
|
31
31
|
ts.factory.createIdentifier(props.alias),
|
32
32
|
ts.factory.createModuleBlock([
|
33
33
|
...types,
|
34
|
-
...(types.length ? [FilePrinter.
|
34
|
+
...(types.length ? [FilePrinter.newLine()] : []),
|
35
35
|
writeMetadata(components)(importer)(props),
|
36
|
-
FilePrinter.
|
36
|
+
FilePrinter.newLine(),
|
37
37
|
writePath(components)(importer)(props),
|
38
38
|
...(config.simulate
|
39
39
|
? [
|
40
|
-
|
41
|
-
|
40
|
+
MigrateApiSimulatationProgrammer.random(components)(importer)(
|
41
|
+
props,
|
42
|
+
),
|
43
|
+
MigrateApiSimulatationProgrammer.simulate(components)(importer)(
|
44
|
+
props,
|
45
|
+
),
|
42
46
|
]
|
43
47
|
: []),
|
44
48
|
]),
|
@@ -62,7 +66,7 @@ export namespace ApiNamespaceProgrammer {
|
|
62
66
|
|
63
67
|
const writeTypes =
|
64
68
|
(components: ISwaggerComponents) =>
|
65
|
-
(importer:
|
69
|
+
(importer: MigrateImportProgrammer) =>
|
66
70
|
(route: IMigrateRoute): ts.TypeAliasDeclaration[] => {
|
67
71
|
const array: ts.TypeAliasDeclaration[] = [];
|
68
72
|
const declare = (name: string, type: ts.TypeNode) =>
|
@@ -77,29 +81,37 @@ export namespace ApiNamespaceProgrammer {
|
|
77
81
|
if (route.headers)
|
78
82
|
declare(
|
79
83
|
"Headers",
|
80
|
-
|
84
|
+
MigrateSchemaProgrammer.write(components)(importer)(
|
85
|
+
route.headers.schema,
|
86
|
+
),
|
81
87
|
);
|
82
88
|
if (route.query)
|
83
89
|
declare(
|
84
90
|
"Query",
|
85
|
-
|
91
|
+
MigrateSchemaProgrammer.write(components)(importer)(
|
92
|
+
route.query.schema,
|
93
|
+
),
|
86
94
|
);
|
87
95
|
if (route.body)
|
88
96
|
declare(
|
89
97
|
"Input",
|
90
|
-
|
98
|
+
MigrateSchemaProgrammer.write(components)(importer)(
|
99
|
+
route.body.schema,
|
100
|
+
),
|
91
101
|
);
|
92
102
|
if (route.success)
|
93
103
|
declare(
|
94
104
|
"Output",
|
95
|
-
|
105
|
+
MigrateSchemaProgrammer.write(components)(importer)(
|
106
|
+
route.success.schema,
|
107
|
+
),
|
96
108
|
);
|
97
109
|
return array;
|
98
110
|
};
|
99
111
|
|
100
112
|
const writeMetadata =
|
101
113
|
(components: ISwaggerComponents) =>
|
102
|
-
(importer:
|
114
|
+
(importer: MigrateImportProgrammer) =>
|
103
115
|
(props: IProps): ts.VariableStatement =>
|
104
116
|
constant("METADATA")(
|
105
117
|
ts.factory.createAsExpression(
|
@@ -147,7 +159,7 @@ export namespace ApiNamespaceProgrammer {
|
|
147
159
|
})}.http.createAssertQuery`,
|
148
160
|
),
|
149
161
|
[
|
150
|
-
|
162
|
+
MigrateSchemaProgrammer.write(components)(importer)(
|
151
163
|
props.route.success.schema,
|
152
164
|
),
|
153
165
|
],
|
@@ -167,7 +179,7 @@ export namespace ApiNamespaceProgrammer {
|
|
167
179
|
|
168
180
|
const writePath =
|
169
181
|
(components: ISwaggerComponents) =>
|
170
|
-
(importer:
|
182
|
+
(importer: MigrateImportProgrammer) =>
|
171
183
|
(props: IProps): ts.VariableStatement => {
|
172
184
|
const out = (body: ts.ConciseBody) =>
|
173
185
|
constant("path")(
|
@@ -178,7 +190,7 @@ export namespace ApiNamespaceProgrammer {
|
|
178
190
|
...props.route.parameters.map((p) =>
|
179
191
|
IdentifierFactory.parameter(
|
180
192
|
p.key,
|
181
|
-
|
193
|
+
MigrateSchemaProgrammer.write(components)(importer)(p.schema),
|
182
194
|
),
|
183
195
|
),
|
184
196
|
...(props.route.query
|
@@ -397,7 +409,7 @@ const constant = (name: string) => (expression: ts.Expression) =>
|
|
397
409
|
ts.NodeFlags.Const,
|
398
410
|
),
|
399
411
|
);
|
400
|
-
const getPath = (props:
|
412
|
+
const getPath = (props: MigrateApiNamespaceProgrammer.IProps) =>
|
401
413
|
[...props.controller.path.split("/"), ...props.route.path.split("/")]
|
402
414
|
.filter((str) => !!str.length)
|
403
415
|
.join("/");
|
@@ -6,16 +6,17 @@ import { IMigrateProgram } from "../module";
|
|
6
6
|
import { IMigrateFile } from "../structures/IMigrateFile";
|
7
7
|
import { FilePrinter } from "../utils/FilePrinter";
|
8
8
|
import { StringUtil } from "../utils/StringUtil";
|
9
|
-
import {
|
10
|
-
import {
|
11
|
-
import {
|
9
|
+
import { MigrateApiFileProgrammer } from "./MigrateApiFileProgrammer";
|
10
|
+
import { MigrateDtoProgrammer } from "./MigrateDtoProgrammer";
|
11
|
+
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
12
12
|
|
13
|
-
export namespace
|
13
|
+
export namespace MigrateApiProgrammer {
|
14
14
|
export const write = (program: IMigrateProgram): IMigrateFile[] => {
|
15
|
-
const dict: HashMap<string[],
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
const dict: HashMap<string[], MigrateApiFileProgrammer.IProps> =
|
16
|
+
new HashMap(
|
17
|
+
(x) => hash(x.join(".")),
|
18
|
+
(a, b) => a.join(".") === b.join("."),
|
19
|
+
);
|
19
20
|
for (const controller of program.controllers)
|
20
21
|
for (const route of controller.routes) {
|
21
22
|
const namespace: string[] = [
|
@@ -25,7 +26,7 @@ export namespace ApiProgrammer {
|
|
25
26
|
.filter((str) => !!str.length && str[0] !== ":")
|
26
27
|
.map(StringUtil.normalize)
|
27
28
|
.map((str) => (Escaper.variable(str) ? str : `_${str}`));
|
28
|
-
const last: IPointer<
|
29
|
+
const last: IPointer<MigrateApiFileProgrammer.IProps> = {
|
29
30
|
value: dict.take(namespace, () => ({
|
30
31
|
namespace,
|
31
32
|
children: new Set(),
|
@@ -39,11 +40,14 @@ export namespace ApiProgrammer {
|
|
39
40
|
});
|
40
41
|
namespace.slice(0, -1).forEach((_i, i, array) => {
|
41
42
|
const partial: string[] = namespace.slice(0, array.length - i);
|
42
|
-
const props:
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
const props: MigrateApiFileProgrammer.IProps = dict.take(
|
44
|
+
partial,
|
45
|
+
() => ({
|
46
|
+
namespace: partial,
|
47
|
+
children: new Set(),
|
48
|
+
entries: [],
|
49
|
+
}),
|
50
|
+
);
|
47
51
|
props.children.add(last.value.namespace.at(-1)!);
|
48
52
|
last.value = props;
|
49
53
|
});
|
@@ -55,59 +59,59 @@ export namespace ApiProgrammer {
|
|
55
59
|
if (namespace.length) top.children.add(namespace[0]);
|
56
60
|
}
|
57
61
|
for (const { second: props } of dict)
|
58
|
-
props.entries.forEach(
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
);
|
62
|
+
props.entries.forEach((entry, i) => {
|
63
|
+
entry.alias = StringUtil.escapeDuplicate([
|
64
|
+
...props.children,
|
65
|
+
...entry.route.parameters.map((p) => p.key),
|
66
|
+
...(entry.route.body ? [entry.route.body.key] : []),
|
67
|
+
...(entry.route.query ? [entry.route.query.key] : []),
|
68
|
+
...props.entries.filter((_, j) => i !== j).map((e) => e.alias),
|
69
|
+
])(entry.alias);
|
70
|
+
entry.route.accessor = [...props.namespace, entry.alias];
|
71
|
+
});
|
68
72
|
|
69
73
|
const output: IMigrateFile[] = [...dict].map(({ second: props }) => ({
|
70
|
-
location: `src/${program.
|
74
|
+
location: `src/${program.mode === "nest" ? "api/" : ""}functional/${props.namespace.join("/")}`,
|
71
75
|
file: "index.ts",
|
72
76
|
content: FilePrinter.write({
|
73
|
-
statements:
|
77
|
+
statements: MigrateApiFileProgrammer.write(program)(
|
74
78
|
program.swagger.components,
|
75
79
|
)(props),
|
76
80
|
}),
|
77
81
|
}));
|
78
|
-
if (program.
|
82
|
+
if (program.mode === "sdk")
|
79
83
|
output.push(
|
80
|
-
...[
|
81
|
-
(
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
84
|
+
...[
|
85
|
+
...MigrateDtoProgrammer.write(program.swagger.components).entries(),
|
86
|
+
].map(([key, value]) => ({
|
87
|
+
location: "src/structures",
|
88
|
+
file: `${key}.ts`,
|
89
|
+
content: FilePrinter.write({
|
90
|
+
statements: writeDtoFile(key, value),
|
87
91
|
}),
|
88
|
-
),
|
92
|
+
})),
|
89
93
|
);
|
90
94
|
return output;
|
91
95
|
};
|
92
96
|
|
93
97
|
const writeDtoFile = (
|
94
98
|
key: string,
|
95
|
-
modulo:
|
99
|
+
modulo: MigrateDtoProgrammer.IModule,
|
96
100
|
): ts.Statement[] => {
|
97
|
-
const importer = new
|
101
|
+
const importer = new MigrateImportProgrammer();
|
98
102
|
const statements: ts.Statement[] = iterate(importer)(modulo);
|
99
103
|
if (statements.length === 0) return [];
|
100
104
|
|
101
105
|
return [
|
102
106
|
...importer.toStatements((name) => `./${name}`, key),
|
103
|
-
...(importer.empty() ? [] : [FilePrinter.
|
107
|
+
...(importer.empty() ? [] : [FilePrinter.newLine()]),
|
104
108
|
...statements,
|
105
109
|
];
|
106
110
|
};
|
107
111
|
|
108
112
|
const iterate =
|
109
|
-
(importer:
|
110
|
-
(modulo:
|
113
|
+
(importer: MigrateImportProgrammer) =>
|
114
|
+
(modulo: MigrateDtoProgrammer.IModule): ts.Statement[] => {
|
111
115
|
const output: ts.Statement[] = [];
|
112
116
|
if (modulo.programmer !== null) output.push(modulo.programmer(importer));
|
113
117
|
if (modulo.children.size) {
|
package/src/programmers/{ApiSimulatationProgrammer.ts → MigrateApiSimulatationProgrammer.ts}
RENAMED
@@ -6,12 +6,12 @@ import { TypeFactory } from "typia/lib/factories/TypeFactory";
|
|
6
6
|
import { IMigrateController } from "../structures/IMigrateController";
|
7
7
|
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
8
8
|
import { ISwaggerComponents } from "../structures/ISwaggerComponents";
|
9
|
-
import {
|
10
|
-
import {
|
11
|
-
import {
|
12
|
-
import {
|
9
|
+
import { MigrateApiFunctionProgrammer } from "./MigrateApiFunctionProgrammer";
|
10
|
+
import { MigrateApiNamespaceProgrammer } from "./MigrateApiNamespaceProgrammer";
|
11
|
+
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
12
|
+
import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
|
13
13
|
|
14
|
-
export namespace
|
14
|
+
export namespace MigrateApiSimulatationProgrammer {
|
15
15
|
export interface IProps {
|
16
16
|
controller: IMigrateController;
|
17
17
|
route: IMigrateRoute;
|
@@ -19,7 +19,7 @@ export namespace ApiSimulatationProgrammer {
|
|
19
19
|
}
|
20
20
|
export const random =
|
21
21
|
(components: ISwaggerComponents) =>
|
22
|
-
(importer:
|
22
|
+
(importer: MigrateImportProgrammer) =>
|
23
23
|
(props: IProps) =>
|
24
24
|
constant("random")(
|
25
25
|
ts.factory.createArrowFunction(
|
@@ -59,7 +59,7 @@ export namespace ApiSimulatationProgrammer {
|
|
59
59
|
)("random"),
|
60
60
|
[
|
61
61
|
props.route.success
|
62
|
-
?
|
62
|
+
? MigrateSchemaProgrammer.write(components)(importer)(
|
63
63
|
props.route.success.schema,
|
64
64
|
)
|
65
65
|
: TypeFactory.keyword("void"),
|
@@ -71,7 +71,7 @@ export namespace ApiSimulatationProgrammer {
|
|
71
71
|
|
72
72
|
export const simulate =
|
73
73
|
(components: ISwaggerComponents) =>
|
74
|
-
(importer:
|
74
|
+
(importer: MigrateImportProgrammer) =>
|
75
75
|
(props: IProps): ts.VariableStatement => {
|
76
76
|
const caller = () =>
|
77
77
|
ts.factory.createCallExpression(
|
@@ -103,7 +103,7 @@ export namespace ApiSimulatationProgrammer {
|
|
103
103
|
ts.factory.createArrowFunction(
|
104
104
|
undefined,
|
105
105
|
undefined,
|
106
|
-
|
106
|
+
MigrateApiFunctionProgrammer.writeParameterDeclarations(components)(
|
107
107
|
importer,
|
108
108
|
)(props),
|
109
109
|
ts.factory.createTypeReferenceNode(
|
@@ -123,20 +123,20 @@ export namespace ApiSimulatationProgrammer {
|
|
123
123
|
|
124
124
|
const assert =
|
125
125
|
(components: ISwaggerComponents) =>
|
126
|
-
(importer:
|
126
|
+
(importer: MigrateImportProgrammer) =>
|
127
127
|
(props: IProps): ts.Statement[] => {
|
128
128
|
const parameters = [
|
129
129
|
...props.route.parameters.map((p) => ({
|
130
130
|
category: "param",
|
131
131
|
name: p.key,
|
132
|
-
schema:
|
132
|
+
schema: MigrateSchemaProgrammer.write(components)(importer)(p.schema),
|
133
133
|
})),
|
134
134
|
...(props.route.query
|
135
135
|
? [
|
136
136
|
{
|
137
137
|
category: "query",
|
138
138
|
name: props.route.query.key,
|
139
|
-
schema:
|
139
|
+
schema: MigrateSchemaProgrammer.write(components)(importer)(
|
140
140
|
props.route.query.schema,
|
141
141
|
),
|
142
142
|
},
|
@@ -147,7 +147,7 @@ export namespace ApiSimulatationProgrammer {
|
|
147
147
|
{
|
148
148
|
category: "body",
|
149
149
|
name: props.route.body.key,
|
150
|
-
schema:
|
150
|
+
schema: MigrateSchemaProgrammer.write(components)(importer)(
|
151
151
|
props.route.body.schema,
|
152
152
|
),
|
153
153
|
},
|
@@ -182,7 +182,7 @@ export namespace ApiSimulatationProgrammer {
|
|
182
182
|
),
|
183
183
|
ts.factory.createPropertyAssignment(
|
184
184
|
"path",
|
185
|
-
|
185
|
+
MigrateApiNamespaceProgrammer.writePathCallExpression(props),
|
186
186
|
),
|
187
187
|
ts.factory.createPropertyAssignment(
|
188
188
|
"contentType",
|
@@ -242,7 +242,7 @@ export namespace ApiSimulatationProgrammer {
|
|
242
242
|
};
|
243
243
|
|
244
244
|
const tryAndCatch =
|
245
|
-
(importer:
|
245
|
+
(importer: MigrateImportProgrammer) => (individual: ts.Statement[]) =>
|
246
246
|
ts.factory.createTryStatement(
|
247
247
|
ts.factory.createBlock(individual, true),
|
248
248
|
ts.factory.createCatchClause(
|