@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,20 +1,20 @@
|
|
1
1
|
import { IPointer } from "tstl";
|
2
2
|
import ts from "typescript";
|
3
3
|
|
4
|
-
import { ISwaggerSchema } from "../structures/
|
4
|
+
import { ISwaggerSchema } from "../structures/ISwaggerSchema";
|
5
5
|
import { ISwaggerComponents } from "../structures/ISwaggerComponents";
|
6
6
|
import { FilePrinter } from "../utils/FilePrinter";
|
7
7
|
import { MapUtil } from "../utils/MapUtil";
|
8
|
-
import {
|
9
|
-
import {
|
8
|
+
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
9
|
+
import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
|
10
10
|
|
11
|
-
export namespace
|
11
|
+
export namespace MigrateDtoProgrammer {
|
12
12
|
export interface IModule {
|
13
13
|
name: string;
|
14
14
|
children: Map<string, IModule>;
|
15
15
|
programmer:
|
16
16
|
| null
|
17
|
-
| ((importer:
|
17
|
+
| ((importer: MigrateImportProgrammer) => ts.TypeAliasDeclaration);
|
18
18
|
}
|
19
19
|
|
20
20
|
export const write = (
|
@@ -31,7 +31,11 @@ export namespace DtoProgrammer {
|
|
31
31
|
const prepare =
|
32
32
|
(dict: Map<string, IModule>) =>
|
33
33
|
(name: string) =>
|
34
|
-
(
|
34
|
+
(
|
35
|
+
programmer: (
|
36
|
+
importer: MigrateImportProgrammer,
|
37
|
+
) => ts.TypeAliasDeclaration,
|
38
|
+
) => {
|
35
39
|
const accessors: string[] = name.split(".");
|
36
40
|
const modulo: IPointer<IModule> = { value: null! };
|
37
41
|
|
@@ -49,14 +53,14 @@ export namespace DtoProgrammer {
|
|
49
53
|
|
50
54
|
const writeAlias =
|
51
55
|
(components: ISwaggerComponents) =>
|
52
|
-
(importer:
|
56
|
+
(importer: MigrateImportProgrammer) =>
|
53
57
|
(key: string, value: ISwaggerSchema) =>
|
54
58
|
FilePrinter.description(
|
55
59
|
ts.factory.createTypeAliasDeclaration(
|
56
60
|
[ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
|
57
61
|
key.split(".").at(-1)!,
|
58
62
|
[],
|
59
|
-
|
63
|
+
MigrateSchemaProgrammer.write(components)(importer)(value),
|
60
64
|
),
|
61
65
|
writeComment(value),
|
62
66
|
);
|
@@ -4,14 +4,8 @@ import { ExpressionFactory } from "typia/lib/factories/ExpressionFactory";
|
|
4
4
|
import { FilePrinter } from "../utils/FilePrinter";
|
5
5
|
import { MapUtil } from "../utils/MapUtil";
|
6
6
|
|
7
|
-
export class
|
8
|
-
private external_: Map<
|
9
|
-
string,
|
10
|
-
{
|
11
|
-
default: string | null;
|
12
|
-
instances: Set<string>;
|
13
|
-
}
|
14
|
-
> = new Map();
|
7
|
+
export class MigrateImportProgrammer {
|
8
|
+
private external_: Map<string, IClause> = new Map();
|
15
9
|
private dtos_: Set<string> = new Set();
|
16
10
|
|
17
11
|
public constructor() {}
|
@@ -20,14 +14,14 @@ export class ImportProgrammer {
|
|
20
14
|
return this.external_.size === 0 && this.dtos_.size === 0;
|
21
15
|
}
|
22
16
|
|
23
|
-
public external(props:
|
24
|
-
const
|
17
|
+
public external(props: MigrateImportProgrammer.IProps): string {
|
18
|
+
const clause: IClause = MapUtil.take(this.external_)(props.library)(() => ({
|
25
19
|
default: null,
|
26
20
|
instances: new Set(),
|
27
21
|
}));
|
28
22
|
const name: string = props.name.split(".")[0];
|
29
|
-
if (props.type === "default")
|
30
|
-
else
|
23
|
+
if (props.type === "default") clause.default = props.name;
|
24
|
+
else clause.instances.add(name);
|
31
25
|
return name;
|
32
26
|
}
|
33
27
|
|
@@ -38,12 +32,12 @@ export class ImportProgrammer {
|
|
38
32
|
}
|
39
33
|
|
40
34
|
public tag(type: string, arg: number | string): ts.TypeReferenceNode {
|
41
|
-
this.external({
|
35
|
+
const instance: string = this.external({
|
42
36
|
type: "instance",
|
43
37
|
library: "typia",
|
44
38
|
name: "tags",
|
45
39
|
});
|
46
|
-
return ts.factory.createTypeReferenceNode(
|
40
|
+
return ts.factory.createTypeReferenceNode(`${instance}.${type}`, [
|
47
41
|
ts.factory.createLiteralTypeNode(
|
48
42
|
typeof arg === "string"
|
49
43
|
? ts.factory.createStringLiteral(arg)
|
@@ -80,7 +74,9 @@ export class ImportProgrammer {
|
|
80
74
|
ts.factory.createStringLiteral(library),
|
81
75
|
);
|
82
76
|
}),
|
83
|
-
...(this.external_.size && this.dtos_.size
|
77
|
+
...(this.external_.size && this.dtos_.size
|
78
|
+
? [FilePrinter.newLine()]
|
79
|
+
: []),
|
84
80
|
...[...this.dtos_]
|
85
81
|
.filter(
|
86
82
|
current ? (name) => name !== current!.split(".")[0] : () => true,
|
@@ -105,10 +101,14 @@ export class ImportProgrammer {
|
|
105
101
|
];
|
106
102
|
}
|
107
103
|
}
|
108
|
-
export namespace
|
104
|
+
export namespace MigrateImportProgrammer {
|
109
105
|
export interface IProps {
|
110
106
|
type: "default" | "instance";
|
111
107
|
library: string;
|
112
108
|
name: string;
|
113
109
|
}
|
114
110
|
}
|
111
|
+
interface IClause {
|
112
|
+
default: string | null;
|
113
|
+
instances: Set<string>;
|
114
|
+
}
|
@@ -4,14 +4,14 @@ import { IMigrateController } from "../structures/IMigrateController";
|
|
4
4
|
import { ISwaggerComponents } from "../structures/ISwaggerComponents";
|
5
5
|
import { FilePrinter } from "../utils/FilePrinter";
|
6
6
|
import { StringUtil } from "../utils/StringUtil";
|
7
|
-
import {
|
8
|
-
import {
|
7
|
+
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
8
|
+
import { MigrateNestMethodProgrammer } from "./MigrateNestMethodProgrammer";
|
9
9
|
|
10
|
-
export namespace
|
10
|
+
export namespace MigrateNestControllerProgrammer {
|
11
11
|
export const write =
|
12
12
|
(components: ISwaggerComponents) =>
|
13
13
|
(controller: IMigrateController): ts.Statement[] => {
|
14
|
-
const importer:
|
14
|
+
const importer: MigrateImportProgrammer = new MigrateImportProgrammer();
|
15
15
|
const $class = ts.factory.createClassDeclaration(
|
16
16
|
[
|
17
17
|
ts.factory.createDecorator(
|
@@ -32,7 +32,9 @@ export namespace NestControllerProgrammer {
|
|
32
32
|
controller.name,
|
33
33
|
[],
|
34
34
|
[],
|
35
|
-
controller.routes.map(
|
35
|
+
controller.routes.map(
|
36
|
+
MigrateNestMethodProgrammer.write(components)(importer),
|
37
|
+
),
|
36
38
|
);
|
37
39
|
return [
|
38
40
|
...importer.toStatements(
|
@@ -41,7 +43,7 @@ export namespace NestControllerProgrammer {
|
|
41
43
|
StringUtil.splitWithNormalization(controller.location).length - 1,
|
42
44
|
)}api/structures/${ref}`,
|
43
45
|
),
|
44
|
-
...(importer.empty() ? [] : [FilePrinter.
|
46
|
+
...(importer.empty() ? [] : [FilePrinter.newLine()]),
|
45
47
|
$class,
|
46
48
|
];
|
47
49
|
};
|
@@ -4,20 +4,22 @@ import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
|
4
4
|
import { TypeFactory } from "typia/lib/factories/TypeFactory";
|
5
5
|
|
6
6
|
import { IMigrateRoute } from "../structures/IMigrateRoute";
|
7
|
-
import { ISwaggerSchema } from "../structures/
|
7
|
+
import { ISwaggerSchema } from "../structures/ISwaggerSchema";
|
8
8
|
import { ISwaggerComponents } from "../structures/ISwaggerComponents";
|
9
9
|
import { FilePrinter } from "../utils/FilePrinter";
|
10
10
|
import { StringUtil } from "../utils/StringUtil";
|
11
|
-
import {
|
12
|
-
import {
|
11
|
+
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
12
|
+
import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
|
13
13
|
|
14
|
-
export namespace
|
14
|
+
export namespace MigrateNestMethodProgrammer {
|
15
15
|
export const write =
|
16
16
|
(components: ISwaggerComponents) =>
|
17
|
-
(importer:
|
17
|
+
(importer: MigrateImportProgrammer) =>
|
18
18
|
(route: IMigrateRoute): ts.MethodDeclaration => {
|
19
19
|
const output: ts.TypeNode = route.success
|
20
|
-
?
|
20
|
+
? MigrateSchemaProgrammer.write(components)(importer)(
|
21
|
+
route.success.schema,
|
22
|
+
)
|
21
23
|
: TypeFactory.keyword("void");
|
22
24
|
|
23
25
|
const method: ts.MethodDeclaration = ts.factory.createMethodDeclaration(
|
@@ -76,7 +78,7 @@ export namespace NestMethodProgrammer {
|
|
76
78
|
|
77
79
|
const writeMethodDecorators =
|
78
80
|
(components: ISwaggerComponents) =>
|
79
|
-
(importer:
|
81
|
+
(importer: MigrateImportProgrammer) =>
|
80
82
|
(route: IMigrateRoute): ts.Decorator[] => {
|
81
83
|
const external =
|
82
84
|
(lib: string) =>
|
@@ -131,7 +133,11 @@ export namespace NestMethodProgrammer {
|
|
131
133
|
ts.factory.createDecorator(
|
132
134
|
ts.factory.createCallExpression(
|
133
135
|
external("@nestia/core")("TypedException"),
|
134
|
-
[
|
136
|
+
[
|
137
|
+
MigrateSchemaProgrammer.write(components)(importer)(
|
138
|
+
value.schema,
|
139
|
+
),
|
140
|
+
],
|
135
141
|
[
|
136
142
|
isNaN(Number(key))
|
137
143
|
? ts.factory.createStringLiteral(key)
|
@@ -148,7 +154,7 @@ export namespace NestMethodProgrammer {
|
|
148
154
|
|
149
155
|
const writeParameters =
|
150
156
|
(components: ISwaggerComponents) =>
|
151
|
-
(importer:
|
157
|
+
(importer: MigrateImportProgrammer) =>
|
152
158
|
(route: IMigrateRoute): ts.ParameterDeclaration[] => [
|
153
159
|
...route.parameters.map(({ key, schema: value }) =>
|
154
160
|
ts.factory.createParameterDeclaration(
|
@@ -170,7 +176,7 @@ export namespace NestMethodProgrammer {
|
|
170
176
|
undefined,
|
171
177
|
StringUtil.normalize(key),
|
172
178
|
undefined,
|
173
|
-
|
179
|
+
MigrateSchemaProgrammer.write(components)(importer)(value),
|
174
180
|
),
|
175
181
|
),
|
176
182
|
...(route.headers
|
@@ -210,7 +216,7 @@ export namespace NestMethodProgrammer {
|
|
210
216
|
const writeDtoParameter =
|
211
217
|
(accessor: { method: string | [string, string]; variable: string }) =>
|
212
218
|
(components: ISwaggerComponents) =>
|
213
|
-
(importer:
|
219
|
+
(importer: MigrateImportProgrammer) =>
|
214
220
|
(schema: ISwaggerSchema): ts.ParameterDeclaration => {
|
215
221
|
const instance = ts.factory.createIdentifier(
|
216
222
|
importer.external({
|
@@ -237,7 +243,7 @@ export namespace NestMethodProgrammer {
|
|
237
243
|
undefined,
|
238
244
|
StringUtil.normalize(accessor.variable),
|
239
245
|
undefined,
|
240
|
-
|
246
|
+
MigrateSchemaProgrammer.write(components)(importer)(schema),
|
241
247
|
);
|
242
248
|
};
|
243
249
|
}
|
@@ -3,14 +3,14 @@ import ts from "typescript";
|
|
3
3
|
import { IMigrateController } from "../structures/IMigrateController";
|
4
4
|
import { FilePrinter } from "../utils/FilePrinter";
|
5
5
|
|
6
|
-
export namespace
|
6
|
+
export namespace MigrateNestModuleProgrammer {
|
7
7
|
export const write = (controllers: IMigrateController[]): ts.Statement[] => [
|
8
8
|
$import("@nestjs/common")("Module"),
|
9
|
-
...(controllers.length ? [FilePrinter.
|
9
|
+
...(controllers.length ? [FilePrinter.newLine()] : []),
|
10
10
|
...controllers.map((c) =>
|
11
11
|
$import(`${c.location.replace("src/", "./")}/${c.name}`)(c.name),
|
12
12
|
),
|
13
|
-
...(controllers.length ? [FilePrinter.
|
13
|
+
...(controllers.length ? [FilePrinter.newLine()] : []),
|
14
14
|
ts.factory.createClassDeclaration(
|
15
15
|
[
|
16
16
|
ts.factory.createDecorator(
|
@@ -3,33 +3,33 @@ import ts from "typescript";
|
|
3
3
|
import { IMigrateFile } from "../structures/IMigrateFile";
|
4
4
|
import { IMigrateProgram } from "../structures/IMigrateProgram";
|
5
5
|
import { FilePrinter } from "../utils/FilePrinter";
|
6
|
-
import {
|
7
|
-
import {
|
8
|
-
import {
|
9
|
-
import {
|
6
|
+
import { MigrateDtoProgrammer } from "./MigrateDtoProgrammer";
|
7
|
+
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
8
|
+
import { MigrateNestControllerProgrammer } from "./MigrateNestControllerProgrammer";
|
9
|
+
import { MigrateNestModuleProgrammer } from "./MigrateNestModuleProgrammer";
|
10
10
|
|
11
|
-
export namespace
|
11
|
+
export namespace MigrateNestProgrammer {
|
12
12
|
export const write = (program: IMigrateProgram): IMigrateFile[] =>
|
13
13
|
[
|
14
14
|
{
|
15
15
|
location: "src",
|
16
16
|
file: "MyModule.ts",
|
17
|
-
statements:
|
17
|
+
statements: MigrateNestModuleProgrammer.write(program.controllers),
|
18
18
|
},
|
19
19
|
...program.controllers.map((c) => ({
|
20
20
|
location: c.location,
|
21
21
|
file: `${c.name}.ts`,
|
22
|
-
statements:
|
23
|
-
|
24
|
-
),
|
22
|
+
statements: MigrateNestControllerProgrammer.write(
|
23
|
+
program.swagger.components,
|
24
|
+
)(c),
|
25
|
+
})),
|
26
|
+
...[
|
27
|
+
...MigrateDtoProgrammer.write(program.swagger.components).entries(),
|
28
|
+
].map(([key, value]) => ({
|
29
|
+
location: "src/api/structures",
|
30
|
+
file: `${key}.ts`,
|
31
|
+
statements: writeDtoFile(key, value),
|
25
32
|
})),
|
26
|
-
...[...DtoProgrammer.write(program.swagger.components).entries()].map(
|
27
|
-
([key, value]) => ({
|
28
|
-
location: "src/api/structures",
|
29
|
-
file: `${key}.ts`,
|
30
|
-
statements: writeDtoFile(key, value),
|
31
|
-
}),
|
32
|
-
),
|
33
33
|
].map((o) => ({
|
34
34
|
location: o.location,
|
35
35
|
file: o.file,
|
@@ -38,22 +38,22 @@ export namespace NestProgrammer {
|
|
38
38
|
|
39
39
|
const writeDtoFile = (
|
40
40
|
key: string,
|
41
|
-
modulo:
|
41
|
+
modulo: MigrateDtoProgrammer.IModule,
|
42
42
|
): ts.Statement[] => {
|
43
|
-
const importer = new
|
43
|
+
const importer = new MigrateImportProgrammer();
|
44
44
|
const statements: ts.Statement[] = iterate(importer)(modulo);
|
45
45
|
if (statements.length === 0) return [];
|
46
46
|
|
47
47
|
return [
|
48
48
|
...importer.toStatements((name) => `./${name}`, key),
|
49
|
-
...(importer.empty() ? [] : [FilePrinter.
|
49
|
+
...(importer.empty() ? [] : [FilePrinter.newLine()]),
|
50
50
|
...statements,
|
51
51
|
];
|
52
52
|
};
|
53
53
|
|
54
54
|
const iterate =
|
55
|
-
(importer:
|
56
|
-
(modulo:
|
55
|
+
(importer: MigrateImportProgrammer) =>
|
56
|
+
(modulo: MigrateDtoProgrammer.IModule): ts.Statement[] => {
|
57
57
|
const output: ts.Statement[] = [];
|
58
58
|
if (modulo.programmer !== null) output.push(modulo.programmer(importer));
|
59
59
|
if (modulo.children.size) {
|
@@ -4,47 +4,49 @@ import { TypeFactory } from "typia/lib/factories/TypeFactory";
|
|
4
4
|
import { FormatCheatSheet } from "typia/lib/tags/internal/FormatCheatSheet";
|
5
5
|
import { Escaper } from "typia/lib/utils/Escaper";
|
6
6
|
|
7
|
-
import { ISwaggerSchema } from "../structures/
|
7
|
+
import { ISwaggerSchema } from "../structures/ISwaggerSchema";
|
8
8
|
import { ISwaggerComponents } from "../structures/ISwaggerComponents";
|
9
9
|
import { FilePrinter } from "../utils/FilePrinter";
|
10
|
-
import {
|
11
|
-
import {
|
10
|
+
import { SwaggerSwaggerChecker } from "../utils/SwaggerTypeChecker";
|
11
|
+
import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
|
12
12
|
|
13
|
-
export namespace
|
13
|
+
export namespace MigrateSchemaProgrammer {
|
14
14
|
/* -----------------------------------------------------------
|
15
15
|
FACADE
|
16
16
|
----------------------------------------------------------- */
|
17
17
|
export const write =
|
18
18
|
(components: ISwaggerComponents) =>
|
19
|
-
(importer:
|
19
|
+
(importer: MigrateImportProgrammer) =>
|
20
20
|
(schema: ISwaggerSchema): ts.TypeNode => {
|
21
21
|
const union: ts.TypeNode[] = [];
|
22
|
-
if (
|
22
|
+
if (SwaggerSwaggerChecker.isUnknown(schema))
|
23
23
|
return TypeFactory.keyword("any");
|
24
|
-
else if (
|
25
|
-
|
24
|
+
else if (SwaggerSwaggerChecker.isNullOnly(schema))
|
25
|
+
return createNode("null");
|
26
|
+
else if (SwaggerSwaggerChecker.isNullable(components)(schema))
|
26
27
|
union.push(createNode("null"));
|
27
28
|
|
28
29
|
const type: ts.TypeNode = (() => {
|
29
30
|
// ATOMIC
|
30
|
-
if (
|
31
|
-
|
31
|
+
if (SwaggerSwaggerChecker.isBoolean(schema))
|
32
|
+
return writeBoolean(schema);
|
33
|
+
else if (SwaggerSwaggerChecker.isInteger(schema))
|
32
34
|
return writeInteger(importer)(schema);
|
33
|
-
else if (
|
35
|
+
else if (SwaggerSwaggerChecker.isNumber(schema))
|
34
36
|
return writeNumber(importer)(schema);
|
35
37
|
// INSTANCES
|
36
|
-
else if (
|
38
|
+
else if (SwaggerSwaggerChecker.isString(schema))
|
37
39
|
return writeString(importer)(schema);
|
38
|
-
else if (
|
40
|
+
else if (SwaggerSwaggerChecker.isArray(schema))
|
39
41
|
return writeArray(components)(importer)(schema);
|
40
|
-
else if (
|
42
|
+
else if (SwaggerSwaggerChecker.isObject(schema))
|
41
43
|
return writeObject(components)(importer)(schema);
|
42
|
-
else if (
|
44
|
+
else if (SwaggerSwaggerChecker.isReference(schema))
|
43
45
|
return writeReference(importer)(schema);
|
44
46
|
// NESTED UNION
|
45
|
-
else if (
|
47
|
+
else if (SwaggerSwaggerChecker.isAnyOf(schema))
|
46
48
|
return writeUnion(components)(importer)(schema.anyOf);
|
47
|
-
else if (
|
49
|
+
else if (SwaggerSwaggerChecker.isOneOf(schema))
|
48
50
|
return writeUnion(components)(importer)(schema.oneOf);
|
49
51
|
else return TypeFactory.keyword("any");
|
50
52
|
})();
|
@@ -67,7 +69,7 @@ export namespace SchemaProgrammer {
|
|
67
69
|
};
|
68
70
|
|
69
71
|
const writeInteger =
|
70
|
-
(importer:
|
72
|
+
(importer: MigrateImportProgrammer) =>
|
71
73
|
(schema: ISwaggerSchema.IInteger): ts.TypeNode =>
|
72
74
|
writeNumeric(() => [
|
73
75
|
TypeFactory.keyword("number"),
|
@@ -75,13 +77,13 @@ export namespace SchemaProgrammer {
|
|
75
77
|
])(importer)(schema);
|
76
78
|
|
77
79
|
const writeNumber =
|
78
|
-
(importer:
|
80
|
+
(importer: MigrateImportProgrammer) =>
|
79
81
|
(schema: ISwaggerSchema.INumber): ts.TypeNode =>
|
80
82
|
writeNumeric(() => [TypeFactory.keyword("number")])(importer)(schema);
|
81
83
|
|
82
84
|
const writeNumeric =
|
83
85
|
(factory: () => ts.TypeNode[]) =>
|
84
|
-
(importer:
|
86
|
+
(importer: MigrateImportProgrammer) =>
|
85
87
|
(schema: ISwaggerSchema.IInteger | ISwaggerSchema.INumber): ts.TypeNode => {
|
86
88
|
if (schema.enum?.length)
|
87
89
|
return ts.factory.createUnionTypeNode(
|
@@ -115,7 +117,7 @@ export namespace SchemaProgrammer {
|
|
115
117
|
};
|
116
118
|
|
117
119
|
const writeString =
|
118
|
-
(importer:
|
120
|
+
(importer: MigrateImportProgrammer) =>
|
119
121
|
(schema: ISwaggerSchema.IString): ts.TypeNode => {
|
120
122
|
if (schema.format === "binary")
|
121
123
|
return ts.factory.createTypeReferenceNode("File");
|
@@ -145,7 +147,7 @@ export namespace SchemaProgrammer {
|
|
145
147
|
----------------------------------------------------------- */
|
146
148
|
const writeArray =
|
147
149
|
(components: ISwaggerComponents) =>
|
148
|
-
(importer:
|
150
|
+
(importer: MigrateImportProgrammer) =>
|
149
151
|
(schema: ISwaggerSchema.IArray): ts.TypeNode => {
|
150
152
|
const intersection: ts.TypeNode[] = [
|
151
153
|
ts.factory.createArrayTypeNode(
|
@@ -163,7 +165,7 @@ export namespace SchemaProgrammer {
|
|
163
165
|
|
164
166
|
const writeObject =
|
165
167
|
(components: ISwaggerComponents) =>
|
166
|
-
(importer:
|
168
|
+
(importer: MigrateImportProgrammer) =>
|
167
169
|
(schema: ISwaggerSchema.IObject): ts.TypeNode => {
|
168
170
|
const regular = () =>
|
169
171
|
ts.factory.createTypeLiteralNode(
|
@@ -190,7 +192,7 @@ export namespace SchemaProgrammer {
|
|
190
192
|
|
191
193
|
const writeRegularProperty =
|
192
194
|
(components: ISwaggerComponents) =>
|
193
|
-
(importer:
|
195
|
+
(importer: MigrateImportProgrammer) =>
|
194
196
|
(required: string[]) =>
|
195
197
|
(key: string, value: ISwaggerSchema) =>
|
196
198
|
FilePrinter.description(
|
@@ -209,7 +211,7 @@ export namespace SchemaProgrammer {
|
|
209
211
|
|
210
212
|
const writeDynamicProperty =
|
211
213
|
(components: ISwaggerComponents) =>
|
212
|
-
(importer:
|
214
|
+
(importer: MigrateImportProgrammer) =>
|
213
215
|
(value: ISwaggerSchema) =>
|
214
216
|
FilePrinter.description(
|
215
217
|
ts.factory.createIndexSignature(
|
@@ -229,7 +231,7 @@ export namespace SchemaProgrammer {
|
|
229
231
|
);
|
230
232
|
|
231
233
|
const writeReference =
|
232
|
-
(importer:
|
234
|
+
(importer: MigrateImportProgrammer) =>
|
233
235
|
(schema: ISwaggerSchema.IReference): ts.TypeReferenceNode =>
|
234
236
|
importer.dto(schema.$ref.split("/").at(-1)!);
|
235
237
|
|
@@ -238,7 +240,7 @@ export namespace SchemaProgrammer {
|
|
238
240
|
----------------------------------------------------------- */
|
239
241
|
const writeUnion =
|
240
242
|
(components: ISwaggerComponents) =>
|
241
|
-
(importer:
|
243
|
+
(importer: MigrateImportProgrammer) =>
|
242
244
|
(elements: ISwaggerSchema[]): ts.UnionTypeNode =>
|
243
245
|
ts.factory.createUnionTypeNode(elements.map(write(components)(importer)));
|
244
246
|
}
|
@@ -1,9 +1,25 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
3
|
-
import { ISwagger } from "./ISwagger";
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
controllers: IMigrateController[];
|
8
|
-
|
9
|
-
|
1
|
+
import { IMigrateController } from "./IMigrateController";
|
2
|
+
import { IMigrateRoute } from "./IMigrateRoute";
|
3
|
+
import { ISwagger } from "./ISwagger";
|
4
|
+
import { ISwaggerRoute } from "./ISwaggerRoute";
|
5
|
+
|
6
|
+
export interface IMigrateProgram extends IMigrateProgram.IProps {
|
7
|
+
controllers: IMigrateController[];
|
8
|
+
}
|
9
|
+
export namespace IMigrateProgram {
|
10
|
+
export type Dictionary = Map<ISwaggerRoute, IEntry>;
|
11
|
+
export interface IEntry {
|
12
|
+
controller: IMigrateController;
|
13
|
+
route: IMigrateRoute;
|
14
|
+
}
|
15
|
+
export interface IProps {
|
16
|
+
mode: "nest" | "sdk";
|
17
|
+
simulate: boolean;
|
18
|
+
swagger: ISwagger;
|
19
|
+
dictionary: Dictionary;
|
20
|
+
}
|
21
|
+
export interface IConfig {
|
22
|
+
mode: "nest" | "sdk";
|
23
|
+
simulate: boolean;
|
24
|
+
}
|
25
|
+
}
|
@@ -1,9 +1,10 @@
|
|
1
|
-
import { ISwaggerSchema } from "./
|
1
|
+
import { ISwaggerSchema } from "./ISwaggerSchema";
|
2
2
|
|
3
3
|
export interface IMigrateRoute {
|
4
4
|
name: string;
|
5
5
|
path: string;
|
6
6
|
method: string;
|
7
|
+
accessor: string[];
|
7
8
|
parameters: IMigrateRoute.IParameter[];
|
8
9
|
headers: IMigrateRoute.IHeaders | null;
|
9
10
|
query: IMigrateRoute.IQuery | null;
|