@nestia/migrate 0.11.4 → 0.11.5

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.
Files changed (52) hide show
  1. package/lib/bundles/NEST_TEMPLATE.js +5 -5
  2. package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
  3. package/lib/bundles/SDK_TEMPLATE.js +1 -1
  4. package/lib/utils/openapi-down-convert/converter.js +2 -2
  5. package/package.json +2 -2
  6. package/src/MigrateApplication.ts +81 -81
  7. package/src/analyzers/MigrateAnalyzer.ts +9 -9
  8. package/src/analyzers/MigrateControllerAnalyzer.ts +135 -135
  9. package/src/analyzers/MigrateMethodAnalyzer.ts +439 -439
  10. package/src/archivers/MigrateFileArchiver.ts +38 -38
  11. package/src/bundles/NEST_TEMPLATE.ts +5 -5
  12. package/src/bundles/SDK_TEMPLATE.ts +1 -1
  13. package/src/executable/bundle.ts +110 -110
  14. package/src/internal/MigrateCommander.ts +70 -70
  15. package/src/internal/MigrateInquirer.ts +86 -86
  16. package/src/module.ts +14 -14
  17. package/src/programmers/MigrateApiFileProgrammer.ts +53 -53
  18. package/src/programmers/MigrateApiFunctionProgrammer.ts +199 -199
  19. package/src/programmers/MigrateApiNamespaceProgrammer.ts +431 -431
  20. package/src/programmers/MigrateApiProgrammer.ts +170 -170
  21. package/src/programmers/MigrateApiSimulatationProgrammer.ts +327 -327
  22. package/src/programmers/MigrateApiStartProgrammer.ts +194 -194
  23. package/src/programmers/MigrateDtoProgrammer.ts +78 -78
  24. package/src/programmers/MigrateE2eFileProgrammer.ts +117 -117
  25. package/src/programmers/MigrateE2eProgrammer.ts +36 -36
  26. package/src/programmers/MigrateImportProgrammer.ts +121 -121
  27. package/src/programmers/MigrateNestControllerProgrammer.ts +50 -50
  28. package/src/programmers/MigrateNestMethodProgrammer.ts +250 -250
  29. package/src/programmers/MigrateNestModuleProgrammer.ts +63 -63
  30. package/src/programmers/MigrateNestProgrammer.ts +74 -74
  31. package/src/programmers/MigrateSchemaProgrammer.ts +267 -267
  32. package/src/structures/IMigrateDto.ts +8 -8
  33. package/src/structures/IMigrateProgram.ts +27 -27
  34. package/src/structures/IMigrateRoute.ts +51 -51
  35. package/src/structures/ISwagger.ts +23 -23
  36. package/src/structures/ISwaggerComponents.ts +14 -14
  37. package/src/structures/ISwaggerRoute.ts +20 -20
  38. package/src/structures/ISwaggerRouteBodyContent.ts +15 -15
  39. package/src/structures/ISwaggerRouteParameter.ts +14 -14
  40. package/src/structures/ISwaggerRouteRequestBody.ts +12 -12
  41. package/src/structures/ISwaggerRouteResponse.ts +11 -11
  42. package/src/structures/ISwaggerSchema.ts +90 -90
  43. package/src/structures/ISwaggerSecurityScheme.ts +47 -47
  44. package/src/structures/ISwaggerV20.ts +10 -10
  45. package/src/structures/ISwaggerV31.ts +10 -10
  46. package/src/utils/FilePrinter.ts +36 -36
  47. package/src/utils/OpenApiConverter.ts +19 -19
  48. package/src/utils/StringUtil.ts +60 -60
  49. package/src/utils/SwaggerComponentsExplorer.ts +43 -43
  50. package/src/utils/SwaggerTypeChecker.ts +67 -67
  51. package/src/utils/openapi-down-convert/RefVisitor.ts +139 -139
  52. package/src/utils/openapi-down-convert/converter.ts +527 -527
@@ -1,194 +1,194 @@
1
- import ts from "typescript";
2
- import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
3
- import { StatementFactory } from "typia/lib/factories/StatementFactory";
4
-
5
- import { IMigrateFile } from "../structures/IMigrateFile";
6
- import { IMigrateProgram } from "../structures/IMigrateProgram";
7
- import { IMigrateRoute } from "../structures/IMigrateRoute";
8
- import { ISwagger } from "../structures/ISwagger";
9
- import { FilePrinter } from "../utils/FilePrinter";
10
- import { MigrateE2eFunctionProgrammer } from "./MigrateE2eFileProgrammer";
11
- import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
12
-
13
- export namespace MigrateApiStartProgrammer {
14
- export const write = (program: IMigrateProgram): IMigrateFile => {
15
- const importer: MigrateImportProgrammer = new MigrateImportProgrammer();
16
- const main: ts.VariableStatement = writeMain(program)(program.swagger)(
17
- importer,
18
- )(pick(program.controllers.map((c) => c.routes).flat()));
19
- const statements: ts.Statement[] = [
20
- ...importer.toStatements(
21
- (name) => `@ORGANIZATION/PROJECT-api/lib/structures/${name}`,
22
- ),
23
- FilePrinter.newLine(),
24
- ts.factory.createImportDeclaration(
25
- undefined,
26
- ts.factory.createImportClause(
27
- false,
28
- undefined,
29
- ts.factory.createNamedImports([
30
- ts.factory.createImportSpecifier(
31
- false,
32
- undefined,
33
- ts.factory.createIdentifier("TestGlobal"),
34
- ),
35
- ]),
36
- ),
37
- ts.factory.createStringLiteral("./TestGlobal"),
38
- undefined,
39
- ),
40
- FilePrinter.newLine(),
41
- main,
42
- ts.factory.createExpressionStatement(writeStarter()),
43
- ];
44
- return {
45
- location: `test`,
46
- file: "start.ts",
47
- content: FilePrinter.write({ statements }),
48
- };
49
- };
50
-
51
- const writeMain =
52
- (config: IMigrateProgram.IConfig) =>
53
- (swagger: ISwagger) =>
54
- (importer: MigrateImportProgrammer) =>
55
- (route: IMigrateRoute): ts.VariableStatement =>
56
- StatementFactory.constant(
57
- "main",
58
- ts.factory.createArrowFunction(
59
- [ts.factory.createToken(ts.SyntaxKind.AsyncKeyword)],
60
- undefined,
61
- [],
62
- undefined,
63
- undefined,
64
- ts.factory.createBlock(
65
- [
66
- writeConnection(config)(swagger)(importer),
67
- ...MigrateE2eFunctionProgrammer.writeBody(swagger.components)(
68
- importer,
69
- )(route),
70
- ],
71
- true,
72
- ),
73
- ),
74
- );
75
-
76
- const writeConnection =
77
- (config: IMigrateProgram.IConfig) =>
78
- (swagger: ISwagger) =>
79
- (importer: MigrateImportProgrammer): ts.VariableStatement =>
80
- ts.factory.createVariableStatement(
81
- undefined,
82
- ts.factory.createVariableDeclarationList(
83
- [
84
- ts.factory.createVariableDeclaration(
85
- "connection",
86
- undefined,
87
- ts.factory.createTypeReferenceNode(
88
- ts.factory.createQualifiedName(
89
- ts.factory.createIdentifier(
90
- importer.external({
91
- type: "default",
92
- library: "@ORGANIZATION/PROJECT-api",
93
- name: "api",
94
- }),
95
- ),
96
- ts.factory.createIdentifier("IConnection"),
97
- ),
98
- ),
99
- ts.factory.createObjectLiteralExpression(
100
- [
101
- ts.factory.createSpreadAssignment(
102
- ts.factory.createCallExpression(
103
- ts.factory.createPropertyAccessExpression(
104
- ts.factory.createIdentifier("TestGlobal"),
105
- "connection",
106
- ),
107
- undefined,
108
- undefined,
109
- ),
110
- ),
111
- ...(swagger.servers[0]?.url?.length
112
- ? [
113
- ts.factory.createPropertyAssignment(
114
- "host",
115
- ts.factory.createStringLiteral(
116
- swagger.servers[0].url,
117
- ),
118
- ),
119
- ]
120
- : []),
121
- ...(config.simulate === true
122
- ? [
123
- ts.factory.createPropertyAssignment(
124
- "simulate",
125
- ts.factory.createTrue(),
126
- ),
127
- ]
128
- : []),
129
- ],
130
- true,
131
- ),
132
- ),
133
- ],
134
- ts.NodeFlags.Const,
135
- ),
136
- );
137
-
138
- const writeStarter = (): ts.CallExpression =>
139
- ts.factory.createCallExpression(
140
- ts.factory.createPropertyAccessExpression(
141
- ts.factory.createCallExpression(
142
- ts.factory.createIdentifier("main"),
143
- undefined,
144
- undefined,
145
- ),
146
- "catch",
147
- ),
148
- undefined,
149
- [
150
- ts.factory.createArrowFunction(
151
- undefined,
152
- undefined,
153
- [IdentifierFactory.parameter("exp")],
154
- undefined,
155
- undefined,
156
- ts.factory.createBlock(
157
- [
158
- ts.factory.createExpressionStatement(
159
- ts.factory.createCallExpression(
160
- ts.factory.createPropertyAccessExpression(
161
- ts.factory.createIdentifier("console"),
162
- "log",
163
- ),
164
- undefined,
165
- [ts.factory.createIdentifier("exp")],
166
- ),
167
- ),
168
- ts.factory.createExpressionStatement(
169
- ts.factory.createCallExpression(
170
- ts.factory.createPropertyAccessExpression(
171
- ts.factory.createIdentifier("process"),
172
- "exit",
173
- ),
174
- undefined,
175
- [
176
- ts.factory.createPrefixMinus(
177
- ts.factory.createNumericLiteral("1"),
178
- ),
179
- ],
180
- ),
181
- ),
182
- ],
183
- true,
184
- ),
185
- ),
186
- ],
187
- );
188
- }
189
-
190
- const pick = <T>(array: T[]): T => {
191
- const rand: number = Math.random() * array.length;
192
- const index: number = Math.min(array.length - 1, Math.floor(rand));
193
- return array[index];
194
- };
1
+ import ts from "typescript";
2
+ import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
3
+ import { StatementFactory } from "typia/lib/factories/StatementFactory";
4
+
5
+ import { IMigrateFile } from "../structures/IMigrateFile";
6
+ import { IMigrateProgram } from "../structures/IMigrateProgram";
7
+ import { IMigrateRoute } from "../structures/IMigrateRoute";
8
+ import { ISwagger } from "../structures/ISwagger";
9
+ import { FilePrinter } from "../utils/FilePrinter";
10
+ import { MigrateE2eFunctionProgrammer } from "./MigrateE2eFileProgrammer";
11
+ import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
12
+
13
+ export namespace MigrateApiStartProgrammer {
14
+ export const write = (program: IMigrateProgram): IMigrateFile => {
15
+ const importer: MigrateImportProgrammer = new MigrateImportProgrammer();
16
+ const main: ts.VariableStatement = writeMain(program)(program.swagger)(
17
+ importer,
18
+ )(pick(program.controllers.map((c) => c.routes).flat()));
19
+ const statements: ts.Statement[] = [
20
+ ...importer.toStatements(
21
+ (name) => `@ORGANIZATION/PROJECT-api/lib/structures/${name}`,
22
+ ),
23
+ FilePrinter.newLine(),
24
+ ts.factory.createImportDeclaration(
25
+ undefined,
26
+ ts.factory.createImportClause(
27
+ false,
28
+ undefined,
29
+ ts.factory.createNamedImports([
30
+ ts.factory.createImportSpecifier(
31
+ false,
32
+ undefined,
33
+ ts.factory.createIdentifier("TestGlobal"),
34
+ ),
35
+ ]),
36
+ ),
37
+ ts.factory.createStringLiteral("./TestGlobal"),
38
+ undefined,
39
+ ),
40
+ FilePrinter.newLine(),
41
+ main,
42
+ ts.factory.createExpressionStatement(writeStarter()),
43
+ ];
44
+ return {
45
+ location: `test`,
46
+ file: "start.ts",
47
+ content: FilePrinter.write({ statements }),
48
+ };
49
+ };
50
+
51
+ const writeMain =
52
+ (config: IMigrateProgram.IConfig) =>
53
+ (swagger: ISwagger) =>
54
+ (importer: MigrateImportProgrammer) =>
55
+ (route: IMigrateRoute): ts.VariableStatement =>
56
+ StatementFactory.constant(
57
+ "main",
58
+ ts.factory.createArrowFunction(
59
+ [ts.factory.createToken(ts.SyntaxKind.AsyncKeyword)],
60
+ undefined,
61
+ [],
62
+ undefined,
63
+ undefined,
64
+ ts.factory.createBlock(
65
+ [
66
+ writeConnection(config)(swagger)(importer),
67
+ ...MigrateE2eFunctionProgrammer.writeBody(swagger.components)(
68
+ importer,
69
+ )(route),
70
+ ],
71
+ true,
72
+ ),
73
+ ),
74
+ );
75
+
76
+ const writeConnection =
77
+ (config: IMigrateProgram.IConfig) =>
78
+ (swagger: ISwagger) =>
79
+ (importer: MigrateImportProgrammer): ts.VariableStatement =>
80
+ ts.factory.createVariableStatement(
81
+ undefined,
82
+ ts.factory.createVariableDeclarationList(
83
+ [
84
+ ts.factory.createVariableDeclaration(
85
+ "connection",
86
+ undefined,
87
+ ts.factory.createTypeReferenceNode(
88
+ ts.factory.createQualifiedName(
89
+ ts.factory.createIdentifier(
90
+ importer.external({
91
+ type: "default",
92
+ library: "@ORGANIZATION/PROJECT-api",
93
+ name: "api",
94
+ }),
95
+ ),
96
+ ts.factory.createIdentifier("IConnection"),
97
+ ),
98
+ ),
99
+ ts.factory.createObjectLiteralExpression(
100
+ [
101
+ ts.factory.createSpreadAssignment(
102
+ ts.factory.createCallExpression(
103
+ ts.factory.createPropertyAccessExpression(
104
+ ts.factory.createIdentifier("TestGlobal"),
105
+ "connection",
106
+ ),
107
+ undefined,
108
+ undefined,
109
+ ),
110
+ ),
111
+ ...(swagger.servers[0]?.url?.length
112
+ ? [
113
+ ts.factory.createPropertyAssignment(
114
+ "host",
115
+ ts.factory.createStringLiteral(
116
+ swagger.servers[0].url,
117
+ ),
118
+ ),
119
+ ]
120
+ : []),
121
+ ...(config.simulate === true
122
+ ? [
123
+ ts.factory.createPropertyAssignment(
124
+ "simulate",
125
+ ts.factory.createTrue(),
126
+ ),
127
+ ]
128
+ : []),
129
+ ],
130
+ true,
131
+ ),
132
+ ),
133
+ ],
134
+ ts.NodeFlags.Const,
135
+ ),
136
+ );
137
+
138
+ const writeStarter = (): ts.CallExpression =>
139
+ ts.factory.createCallExpression(
140
+ ts.factory.createPropertyAccessExpression(
141
+ ts.factory.createCallExpression(
142
+ ts.factory.createIdentifier("main"),
143
+ undefined,
144
+ undefined,
145
+ ),
146
+ "catch",
147
+ ),
148
+ undefined,
149
+ [
150
+ ts.factory.createArrowFunction(
151
+ undefined,
152
+ undefined,
153
+ [IdentifierFactory.parameter("exp")],
154
+ undefined,
155
+ undefined,
156
+ ts.factory.createBlock(
157
+ [
158
+ ts.factory.createExpressionStatement(
159
+ ts.factory.createCallExpression(
160
+ ts.factory.createPropertyAccessExpression(
161
+ ts.factory.createIdentifier("console"),
162
+ "log",
163
+ ),
164
+ undefined,
165
+ [ts.factory.createIdentifier("exp")],
166
+ ),
167
+ ),
168
+ ts.factory.createExpressionStatement(
169
+ ts.factory.createCallExpression(
170
+ ts.factory.createPropertyAccessExpression(
171
+ ts.factory.createIdentifier("process"),
172
+ "exit",
173
+ ),
174
+ undefined,
175
+ [
176
+ ts.factory.createPrefixMinus(
177
+ ts.factory.createNumericLiteral("1"),
178
+ ),
179
+ ],
180
+ ),
181
+ ),
182
+ ],
183
+ true,
184
+ ),
185
+ ),
186
+ ],
187
+ );
188
+ }
189
+
190
+ const pick = <T>(array: T[]): T => {
191
+ const rand: number = Math.random() * array.length;
192
+ const index: number = Math.min(array.length - 1, Math.floor(rand));
193
+ return array[index];
194
+ };
@@ -1,78 +1,78 @@
1
- import { IPointer } from "tstl";
2
- import ts from "typescript";
3
-
4
- import { ISwaggerComponents } from "../structures/ISwaggerComponents";
5
- import { ISwaggerSchema } from "../structures/ISwaggerSchema";
6
- import { FilePrinter } from "../utils/FilePrinter";
7
- import { MapUtil } from "../utils/MapUtil";
8
- import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
9
- import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
10
-
11
- export namespace MigrateDtoProgrammer {
12
- export interface IModule {
13
- name: string;
14
- children: Map<string, IModule>;
15
- programmer:
16
- | null
17
- | ((importer: MigrateImportProgrammer) => ts.TypeAliasDeclaration);
18
- }
19
-
20
- export const compose = (
21
- components: ISwaggerComponents,
22
- ): Map<string, IModule> => {
23
- const dict: Map<string, IModule> = new Map();
24
- for (const [key, value] of Object.entries(components.schemas ?? {}))
25
- prepare(dict)(key)((importer) =>
26
- writeAlias(components)(importer)(key, value),
27
- );
28
- return dict;
29
- };
30
-
31
- const prepare =
32
- (dict: Map<string, IModule>) =>
33
- (name: string) =>
34
- (
35
- programmer: (
36
- importer: MigrateImportProgrammer,
37
- ) => ts.TypeAliasDeclaration,
38
- ) => {
39
- const accessors: string[] = name.split(".");
40
- const modulo: IPointer<IModule> = { value: null! };
41
-
42
- accessors.forEach((acc, i) => {
43
- modulo.value = MapUtil.take(dict)(acc)(() => ({
44
- name: acc,
45
- children: new Map(),
46
- programmer: null,
47
- }));
48
- if (i === accessors.length - 1) modulo.value.programmer = programmer;
49
- dict = modulo.value.children;
50
- });
51
- return modulo!;
52
- };
53
-
54
- const writeAlias =
55
- (components: ISwaggerComponents) =>
56
- (importer: MigrateImportProgrammer) =>
57
- (key: string, value: ISwaggerSchema) =>
58
- FilePrinter.description(
59
- ts.factory.createTypeAliasDeclaration(
60
- [ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
61
- key.split(".").at(-1)!,
62
- [],
63
- MigrateSchemaProgrammer.write(components)(importer)(value),
64
- ),
65
- writeComment(value),
66
- );
67
- }
68
-
69
- const writeComment = (schema: ISwaggerSchema): string =>
70
- [
71
- ...(schema.description?.length ? [schema.description] : []),
72
- ...(schema.description?.length &&
73
- (schema.title !== undefined || schema.deprecated === true)
74
- ? [""]
75
- : []),
76
- ...(schema.title !== undefined ? [`@title ${schema.title}`] : []),
77
- ...(schema.deprecated === true ? [`@deprecated`] : []),
78
- ].join("\n");
1
+ import { IPointer } from "tstl";
2
+ import ts from "typescript";
3
+
4
+ import { ISwaggerComponents } from "../structures/ISwaggerComponents";
5
+ import { ISwaggerSchema } from "../structures/ISwaggerSchema";
6
+ import { FilePrinter } from "../utils/FilePrinter";
7
+ import { MapUtil } from "../utils/MapUtil";
8
+ import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
9
+ import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
10
+
11
+ export namespace MigrateDtoProgrammer {
12
+ export interface IModule {
13
+ name: string;
14
+ children: Map<string, IModule>;
15
+ programmer:
16
+ | null
17
+ | ((importer: MigrateImportProgrammer) => ts.TypeAliasDeclaration);
18
+ }
19
+
20
+ export const compose = (
21
+ components: ISwaggerComponents,
22
+ ): Map<string, IModule> => {
23
+ const dict: Map<string, IModule> = new Map();
24
+ for (const [key, value] of Object.entries(components.schemas ?? {}))
25
+ prepare(dict)(key)((importer) =>
26
+ writeAlias(components)(importer)(key, value),
27
+ );
28
+ return dict;
29
+ };
30
+
31
+ const prepare =
32
+ (dict: Map<string, IModule>) =>
33
+ (name: string) =>
34
+ (
35
+ programmer: (
36
+ importer: MigrateImportProgrammer,
37
+ ) => ts.TypeAliasDeclaration,
38
+ ) => {
39
+ const accessors: string[] = name.split(".");
40
+ const modulo: IPointer<IModule> = { value: null! };
41
+
42
+ accessors.forEach((acc, i) => {
43
+ modulo.value = MapUtil.take(dict)(acc)(() => ({
44
+ name: acc,
45
+ children: new Map(),
46
+ programmer: null,
47
+ }));
48
+ if (i === accessors.length - 1) modulo.value.programmer = programmer;
49
+ dict = modulo.value.children;
50
+ });
51
+ return modulo!;
52
+ };
53
+
54
+ const writeAlias =
55
+ (components: ISwaggerComponents) =>
56
+ (importer: MigrateImportProgrammer) =>
57
+ (key: string, value: ISwaggerSchema) =>
58
+ FilePrinter.description(
59
+ ts.factory.createTypeAliasDeclaration(
60
+ [ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
61
+ key.split(".").at(-1)!,
62
+ [],
63
+ MigrateSchemaProgrammer.write(components)(importer)(value),
64
+ ),
65
+ writeComment(value),
66
+ );
67
+ }
68
+
69
+ const writeComment = (schema: ISwaggerSchema): string =>
70
+ [
71
+ ...(schema.description?.length ? [schema.description] : []),
72
+ ...(schema.description?.length &&
73
+ (schema.title !== undefined || schema.deprecated === true)
74
+ ? [""]
75
+ : []),
76
+ ...(schema.title !== undefined ? [`@title ${schema.title}`] : []),
77
+ ...(schema.deprecated === true ? [`@deprecated`] : []),
78
+ ].join("\n");