@nestia/migrate 4.6.1-dev.20250117 → 4.6.1

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 (49) hide show
  1. package/README.md +87 -87
  2. package/lib/bundles/NEST_TEMPLATE.js +66 -66
  3. package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
  4. package/lib/bundles/SDK_TEMPLATE.js +30 -30
  5. package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
  6. package/lib/index.mjs +92 -92
  7. package/lib/utils/openapi-down-convert/converter.js +2 -2
  8. package/package.json +6 -6
  9. package/src/MigrateApplication.ts +107 -107
  10. package/src/analyzers/MigrateApplicationAnalyzer.ts +18 -18
  11. package/src/analyzers/MigrateControllerAnalyzer.ts +51 -51
  12. package/src/archivers/MigrateFileArchiver.ts +38 -38
  13. package/src/bundles/NEST_TEMPLATE.ts +66 -66
  14. package/src/bundles/SDK_TEMPLATE.ts +30 -30
  15. package/src/executable/bundle.js +125 -125
  16. package/src/executable/migrate.ts +7 -7
  17. package/src/factories/TypeLiteralFactory.ts +57 -57
  18. package/src/index.ts +4 -4
  19. package/src/internal/MigrateCommander.ts +86 -86
  20. package/src/internal/MigrateInquirer.ts +89 -89
  21. package/src/module.ts +8 -8
  22. package/src/programmers/MigrateApiFileProgrammer.ts +49 -49
  23. package/src/programmers/MigrateApiFunctionProgrammer.ts +210 -210
  24. package/src/programmers/MigrateApiNamespaceProgrammer.ts +417 -417
  25. package/src/programmers/MigrateApiProgrammer.ts +103 -103
  26. package/src/programmers/MigrateApiSimulatationProgrammer.ts +324 -324
  27. package/src/programmers/MigrateApiStartProgrammer.ts +194 -194
  28. package/src/programmers/MigrateDtoProgrammer.ts +87 -87
  29. package/src/programmers/MigrateE2eFileProgrammer.ts +117 -117
  30. package/src/programmers/MigrateE2eProgrammer.ts +34 -34
  31. package/src/programmers/MigrateImportProgrammer.ts +118 -118
  32. package/src/programmers/MigrateNestControllerProgrammer.ts +50 -50
  33. package/src/programmers/MigrateNestMethodProgrammer.ts +393 -393
  34. package/src/programmers/MigrateNestModuleProgrammer.ts +65 -65
  35. package/src/programmers/MigrateNestProgrammer.ts +81 -81
  36. package/src/programmers/MigrateSchemaProgrammer.ts +373 -373
  37. package/src/structures/IHttpMigrateController.ts +8 -8
  38. package/src/structures/IHttpMigrateDto.ts +8 -8
  39. package/src/structures/IHttpMigrateFile.ts +5 -5
  40. package/src/structures/IHttpMigrateProgram.ts +27 -27
  41. package/src/structures/IHttpMigrateRoute.ts +1 -1
  42. package/src/structures/IHttpMigrateSchema.ts +4 -4
  43. package/src/utils/FilePrinter.ts +36 -36
  44. package/src/utils/MapUtil.ts +13 -13
  45. package/src/utils/OpenApiTypeChecker.ts +73 -73
  46. package/src/utils/SetupWizard.ts +12 -12
  47. package/src/utils/StringUtil.ts +113 -113
  48. package/src/utils/openapi-down-convert/RefVisitor.ts +139 -139
  49. package/src/utils/openapi-down-convert/converter.ts +527 -527
@@ -1,324 +1,324 @@
1
- import { OpenApi } from "@samchon/openapi";
2
- import ts from "typescript";
3
- import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
4
- import { StatementFactory } from "typia/lib/factories/StatementFactory";
5
- import { TypeFactory } from "typia/lib/factories/TypeFactory";
6
-
7
- import { IHttpMigrateRoute } from "../structures/IHttpMigrateRoute";
8
- import { MigrateApiFunctionProgrammer } from "./MigrateApiFunctionProgrammer";
9
- import { MigrateApiNamespaceProgrammer } from "./MigrateApiNamespaceProgrammer";
10
- import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
11
- import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
12
-
13
- export namespace MigrateApiSimulatationProgrammer {
14
- export const random =
15
- (components: OpenApi.IComponents) =>
16
- (importer: MigrateImportProgrammer) =>
17
- (route: IHttpMigrateRoute) => {
18
- const output = route.success
19
- ? MigrateSchemaProgrammer.write(components)(importer)(
20
- route.success.schema,
21
- )
22
- : TypeFactory.keyword("void");
23
- return constant("random")(
24
- ts.factory.createArrowFunction(
25
- undefined,
26
- undefined,
27
- [
28
- ts.factory.createParameterDeclaration(
29
- undefined,
30
- undefined,
31
- "g",
32
- ts.factory.createToken(ts.SyntaxKind.QuestionToken),
33
- ts.factory.createTypeReferenceNode(
34
- ts.factory.createIdentifier("Partial"),
35
- [
36
- ts.factory.createTypeReferenceNode(
37
- `${importer.external({
38
- type: "default",
39
- library: "typia",
40
- name: "typia",
41
- })}.IRandomGenerator`,
42
- ),
43
- ],
44
- ),
45
- ),
46
- ],
47
- output,
48
- undefined,
49
- ts.factory.createCallExpression(
50
- IdentifierFactory.access(
51
- ts.factory.createIdentifier(
52
- importer.external({
53
- type: "default",
54
- library: "typia",
55
- name: "typia",
56
- }),
57
- ),
58
- "random",
59
- ),
60
- [output],
61
- [ts.factory.createIdentifier("g")],
62
- ),
63
- ),
64
- );
65
- };
66
-
67
- export const simulate =
68
- (components: OpenApi.IComponents) =>
69
- (importer: MigrateImportProgrammer) =>
70
- (route: IHttpMigrateRoute): ts.VariableStatement => {
71
- const caller = () =>
72
- ts.factory.createCallExpression(
73
- ts.factory.createIdentifier("random"),
74
- undefined,
75
- [
76
- ts.factory.createConditionalExpression(
77
- ts.factory.createLogicalAnd(
78
- ts.factory.createStrictEquality(
79
- ts.factory.createStringLiteral("object"),
80
- ts.factory.createTypeOfExpression(
81
- ts.factory.createIdentifier("connection.simulate"),
82
- ),
83
- ),
84
- ts.factory.createStrictInequality(
85
- ts.factory.createNull(),
86
- ts.factory.createIdentifier("connection.simulate"),
87
- ),
88
- ),
89
- undefined,
90
- ts.factory.createIdentifier("connection.simulate"),
91
- undefined,
92
- ts.factory.createIdentifier("undefined"),
93
- ),
94
- ],
95
- );
96
- return constant("simulate")(
97
- ts.factory.createArrowFunction(
98
- undefined,
99
- undefined,
100
- MigrateApiFunctionProgrammer.writeParameterDeclarations(components)(
101
- importer,
102
- )(route),
103
- ts.factory.createTypeReferenceNode(route.success ? "Output" : "void"),
104
- undefined,
105
- ts.factory.createBlock(
106
- [
107
- ...assert(components)(importer)(route),
108
- ts.factory.createReturnStatement(caller()),
109
- ],
110
- true,
111
- ),
112
- ),
113
- );
114
- };
115
-
116
- const assert =
117
- (components: OpenApi.IComponents) =>
118
- (importer: MigrateImportProgrammer) =>
119
- (route: IHttpMigrateRoute): ts.Statement[] => {
120
- const parameters = [
121
- ...route.parameters.map((p) => ({
122
- category: "param",
123
- name: p.key,
124
- schema: MigrateSchemaProgrammer.write(components)(importer)(p.schema),
125
- })),
126
- ...(route.query
127
- ? [
128
- {
129
- category: "query",
130
- name: route.query.key,
131
- schema: MigrateSchemaProgrammer.write(components)(importer)(
132
- route.query.schema,
133
- ),
134
- },
135
- ]
136
- : []),
137
- ...(route.body
138
- ? [
139
- {
140
- category: "body",
141
- name: route.body.key,
142
- schema: MigrateSchemaProgrammer.write(components)(importer)(
143
- route.body.schema,
144
- ),
145
- },
146
- ]
147
- : []),
148
- ];
149
- if (parameters.length === 0) return [];
150
-
151
- const validator = StatementFactory.constant({
152
- name: "assert",
153
- value: ts.factory.createCallExpression(
154
- IdentifierFactory.access(
155
- ts.factory.createIdentifier(
156
- importer.external({
157
- type: "instance",
158
- library: `@nestia/fetcher/lib/NestiaSimulator`,
159
- name: "NestiaSimulator",
160
- }),
161
- ),
162
- "assert",
163
- ),
164
- undefined,
165
- [
166
- ts.factory.createObjectLiteralExpression(
167
- [
168
- ts.factory.createPropertyAssignment(
169
- "method",
170
- ts.factory.createIdentifier("METADATA.method"),
171
- ),
172
- ts.factory.createPropertyAssignment(
173
- "host",
174
- ts.factory.createIdentifier("connection.host"),
175
- ),
176
- ts.factory.createPropertyAssignment(
177
- "path",
178
- MigrateApiNamespaceProgrammer.writePathCallExpression(route),
179
- ),
180
- ts.factory.createPropertyAssignment(
181
- "contentType",
182
- ts.factory.createStringLiteral(
183
- route.success?.type ?? "application/json",
184
- ),
185
- ),
186
- ],
187
- true,
188
- ),
189
- ],
190
- ),
191
- });
192
- const individual = parameters
193
- .map((p) =>
194
- ts.factory.createCallExpression(
195
- (() => {
196
- const base = IdentifierFactory.access(
197
- ts.factory.createIdentifier("assert"),
198
- p.category,
199
- );
200
- if (p.category !== "param") return base;
201
- return ts.factory.createCallExpression(base, undefined, [
202
- ts.factory.createStringLiteral(p.name),
203
- ]);
204
- })(),
205
- undefined,
206
- [
207
- ts.factory.createArrowFunction(
208
- undefined,
209
- undefined,
210
- [],
211
- undefined,
212
- undefined,
213
- ts.factory.createCallExpression(
214
- IdentifierFactory.access(
215
- ts.factory.createIdentifier(
216
- importer.external({
217
- type: "default",
218
- library: "typia",
219
- name: "typia",
220
- }),
221
- ),
222
- "assert",
223
- ),
224
- undefined,
225
- [
226
- ts.factory.createIdentifier(
227
- p.category === "headers" ? "connection.headers" : p.name,
228
- ),
229
- ],
230
- ),
231
- ),
232
- ],
233
- ),
234
- )
235
- .map(ts.factory.createExpressionStatement);
236
- return [validator, tryAndCatch(importer)(individual)];
237
- };
238
-
239
- const tryAndCatch =
240
- (importer: MigrateImportProgrammer) => (individual: ts.Statement[]) =>
241
- ts.factory.createTryStatement(
242
- ts.factory.createBlock(individual, true),
243
- ts.factory.createCatchClause(
244
- "exp",
245
- ts.factory.createBlock(
246
- [
247
- ts.factory.createIfStatement(
248
- ts.factory.createLogicalNot(
249
- ts.factory.createCallExpression(
250
- IdentifierFactory.access(
251
- ts.factory.createIdentifier(
252
- importer.external({
253
- type: "default",
254
- library: "typia",
255
- name: "typia",
256
- }),
257
- ),
258
- "is",
259
- ),
260
- [
261
- ts.factory.createTypeReferenceNode(
262
- importer.external({
263
- type: "instance",
264
- library: "@nestia/fetcher",
265
- name: "HttpError",
266
- }),
267
- ),
268
- ],
269
- [ts.factory.createIdentifier("exp")],
270
- ),
271
- ),
272
- ts.factory.createThrowStatement(
273
- ts.factory.createIdentifier("exp"),
274
- ),
275
- ),
276
- ts.factory.createReturnStatement(
277
- ts.factory.createAsExpression(
278
- ts.factory.createObjectLiteralExpression(
279
- [
280
- ts.factory.createPropertyAssignment(
281
- "success",
282
- ts.factory.createFalse(),
283
- ),
284
- ts.factory.createPropertyAssignment(
285
- "status",
286
- ts.factory.createIdentifier("exp.status"),
287
- ),
288
- ts.factory.createPropertyAssignment(
289
- "headers",
290
- ts.factory.createIdentifier("exp.headers"),
291
- ),
292
- ts.factory.createPropertyAssignment(
293
- "data",
294
- ts.factory.createIdentifier("exp.toJSON().message"),
295
- ),
296
- ],
297
- true,
298
- ),
299
- TypeFactory.keyword("any"),
300
- ),
301
- ),
302
- ],
303
- true,
304
- ),
305
- ),
306
- undefined,
307
- );
308
- }
309
-
310
- const constant = (name: string) => (expression: ts.Expression) =>
311
- ts.factory.createVariableStatement(
312
- [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
313
- ts.factory.createVariableDeclarationList(
314
- [
315
- ts.factory.createVariableDeclaration(
316
- ts.factory.createIdentifier(name),
317
- undefined,
318
- undefined,
319
- expression,
320
- ),
321
- ],
322
- ts.NodeFlags.Const,
323
- ),
324
- );
1
+ import { OpenApi } from "@samchon/openapi";
2
+ import ts from "typescript";
3
+ import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
4
+ import { StatementFactory } from "typia/lib/factories/StatementFactory";
5
+ import { TypeFactory } from "typia/lib/factories/TypeFactory";
6
+
7
+ import { IHttpMigrateRoute } from "../structures/IHttpMigrateRoute";
8
+ import { MigrateApiFunctionProgrammer } from "./MigrateApiFunctionProgrammer";
9
+ import { MigrateApiNamespaceProgrammer } from "./MigrateApiNamespaceProgrammer";
10
+ import { MigrateImportProgrammer } from "./MigrateImportProgrammer";
11
+ import { MigrateSchemaProgrammer } from "./MigrateSchemaProgrammer";
12
+
13
+ export namespace MigrateApiSimulatationProgrammer {
14
+ export const random =
15
+ (components: OpenApi.IComponents) =>
16
+ (importer: MigrateImportProgrammer) =>
17
+ (route: IHttpMigrateRoute) => {
18
+ const output = route.success
19
+ ? MigrateSchemaProgrammer.write(components)(importer)(
20
+ route.success.schema,
21
+ )
22
+ : TypeFactory.keyword("void");
23
+ return constant("random")(
24
+ ts.factory.createArrowFunction(
25
+ undefined,
26
+ undefined,
27
+ [
28
+ ts.factory.createParameterDeclaration(
29
+ undefined,
30
+ undefined,
31
+ "g",
32
+ ts.factory.createToken(ts.SyntaxKind.QuestionToken),
33
+ ts.factory.createTypeReferenceNode(
34
+ ts.factory.createIdentifier("Partial"),
35
+ [
36
+ ts.factory.createTypeReferenceNode(
37
+ `${importer.external({
38
+ type: "default",
39
+ library: "typia",
40
+ name: "typia",
41
+ })}.IRandomGenerator`,
42
+ ),
43
+ ],
44
+ ),
45
+ ),
46
+ ],
47
+ output,
48
+ undefined,
49
+ ts.factory.createCallExpression(
50
+ IdentifierFactory.access(
51
+ ts.factory.createIdentifier(
52
+ importer.external({
53
+ type: "default",
54
+ library: "typia",
55
+ name: "typia",
56
+ }),
57
+ ),
58
+ "random",
59
+ ),
60
+ [output],
61
+ [ts.factory.createIdentifier("g")],
62
+ ),
63
+ ),
64
+ );
65
+ };
66
+
67
+ export const simulate =
68
+ (components: OpenApi.IComponents) =>
69
+ (importer: MigrateImportProgrammer) =>
70
+ (route: IHttpMigrateRoute): ts.VariableStatement => {
71
+ const caller = () =>
72
+ ts.factory.createCallExpression(
73
+ ts.factory.createIdentifier("random"),
74
+ undefined,
75
+ [
76
+ ts.factory.createConditionalExpression(
77
+ ts.factory.createLogicalAnd(
78
+ ts.factory.createStrictEquality(
79
+ ts.factory.createStringLiteral("object"),
80
+ ts.factory.createTypeOfExpression(
81
+ ts.factory.createIdentifier("connection.simulate"),
82
+ ),
83
+ ),
84
+ ts.factory.createStrictInequality(
85
+ ts.factory.createNull(),
86
+ ts.factory.createIdentifier("connection.simulate"),
87
+ ),
88
+ ),
89
+ undefined,
90
+ ts.factory.createIdentifier("connection.simulate"),
91
+ undefined,
92
+ ts.factory.createIdentifier("undefined"),
93
+ ),
94
+ ],
95
+ );
96
+ return constant("simulate")(
97
+ ts.factory.createArrowFunction(
98
+ undefined,
99
+ undefined,
100
+ MigrateApiFunctionProgrammer.writeParameterDeclarations(components)(
101
+ importer,
102
+ )(route),
103
+ ts.factory.createTypeReferenceNode(route.success ? "Output" : "void"),
104
+ undefined,
105
+ ts.factory.createBlock(
106
+ [
107
+ ...assert(components)(importer)(route),
108
+ ts.factory.createReturnStatement(caller()),
109
+ ],
110
+ true,
111
+ ),
112
+ ),
113
+ );
114
+ };
115
+
116
+ const assert =
117
+ (components: OpenApi.IComponents) =>
118
+ (importer: MigrateImportProgrammer) =>
119
+ (route: IHttpMigrateRoute): ts.Statement[] => {
120
+ const parameters = [
121
+ ...route.parameters.map((p) => ({
122
+ category: "param",
123
+ name: p.key,
124
+ schema: MigrateSchemaProgrammer.write(components)(importer)(p.schema),
125
+ })),
126
+ ...(route.query
127
+ ? [
128
+ {
129
+ category: "query",
130
+ name: route.query.key,
131
+ schema: MigrateSchemaProgrammer.write(components)(importer)(
132
+ route.query.schema,
133
+ ),
134
+ },
135
+ ]
136
+ : []),
137
+ ...(route.body
138
+ ? [
139
+ {
140
+ category: "body",
141
+ name: route.body.key,
142
+ schema: MigrateSchemaProgrammer.write(components)(importer)(
143
+ route.body.schema,
144
+ ),
145
+ },
146
+ ]
147
+ : []),
148
+ ];
149
+ if (parameters.length === 0) return [];
150
+
151
+ const validator = StatementFactory.constant({
152
+ name: "assert",
153
+ value: ts.factory.createCallExpression(
154
+ IdentifierFactory.access(
155
+ ts.factory.createIdentifier(
156
+ importer.external({
157
+ type: "instance",
158
+ library: `@nestia/fetcher/lib/NestiaSimulator`,
159
+ name: "NestiaSimulator",
160
+ }),
161
+ ),
162
+ "assert",
163
+ ),
164
+ undefined,
165
+ [
166
+ ts.factory.createObjectLiteralExpression(
167
+ [
168
+ ts.factory.createPropertyAssignment(
169
+ "method",
170
+ ts.factory.createIdentifier("METADATA.method"),
171
+ ),
172
+ ts.factory.createPropertyAssignment(
173
+ "host",
174
+ ts.factory.createIdentifier("connection.host"),
175
+ ),
176
+ ts.factory.createPropertyAssignment(
177
+ "path",
178
+ MigrateApiNamespaceProgrammer.writePathCallExpression(route),
179
+ ),
180
+ ts.factory.createPropertyAssignment(
181
+ "contentType",
182
+ ts.factory.createStringLiteral(
183
+ route.success?.type ?? "application/json",
184
+ ),
185
+ ),
186
+ ],
187
+ true,
188
+ ),
189
+ ],
190
+ ),
191
+ });
192
+ const individual = parameters
193
+ .map((p) =>
194
+ ts.factory.createCallExpression(
195
+ (() => {
196
+ const base = IdentifierFactory.access(
197
+ ts.factory.createIdentifier("assert"),
198
+ p.category,
199
+ );
200
+ if (p.category !== "param") return base;
201
+ return ts.factory.createCallExpression(base, undefined, [
202
+ ts.factory.createStringLiteral(p.name),
203
+ ]);
204
+ })(),
205
+ undefined,
206
+ [
207
+ ts.factory.createArrowFunction(
208
+ undefined,
209
+ undefined,
210
+ [],
211
+ undefined,
212
+ undefined,
213
+ ts.factory.createCallExpression(
214
+ IdentifierFactory.access(
215
+ ts.factory.createIdentifier(
216
+ importer.external({
217
+ type: "default",
218
+ library: "typia",
219
+ name: "typia",
220
+ }),
221
+ ),
222
+ "assert",
223
+ ),
224
+ undefined,
225
+ [
226
+ ts.factory.createIdentifier(
227
+ p.category === "headers" ? "connection.headers" : p.name,
228
+ ),
229
+ ],
230
+ ),
231
+ ),
232
+ ],
233
+ ),
234
+ )
235
+ .map(ts.factory.createExpressionStatement);
236
+ return [validator, tryAndCatch(importer)(individual)];
237
+ };
238
+
239
+ const tryAndCatch =
240
+ (importer: MigrateImportProgrammer) => (individual: ts.Statement[]) =>
241
+ ts.factory.createTryStatement(
242
+ ts.factory.createBlock(individual, true),
243
+ ts.factory.createCatchClause(
244
+ "exp",
245
+ ts.factory.createBlock(
246
+ [
247
+ ts.factory.createIfStatement(
248
+ ts.factory.createLogicalNot(
249
+ ts.factory.createCallExpression(
250
+ IdentifierFactory.access(
251
+ ts.factory.createIdentifier(
252
+ importer.external({
253
+ type: "default",
254
+ library: "typia",
255
+ name: "typia",
256
+ }),
257
+ ),
258
+ "is",
259
+ ),
260
+ [
261
+ ts.factory.createTypeReferenceNode(
262
+ importer.external({
263
+ type: "instance",
264
+ library: "@nestia/fetcher",
265
+ name: "HttpError",
266
+ }),
267
+ ),
268
+ ],
269
+ [ts.factory.createIdentifier("exp")],
270
+ ),
271
+ ),
272
+ ts.factory.createThrowStatement(
273
+ ts.factory.createIdentifier("exp"),
274
+ ),
275
+ ),
276
+ ts.factory.createReturnStatement(
277
+ ts.factory.createAsExpression(
278
+ ts.factory.createObjectLiteralExpression(
279
+ [
280
+ ts.factory.createPropertyAssignment(
281
+ "success",
282
+ ts.factory.createFalse(),
283
+ ),
284
+ ts.factory.createPropertyAssignment(
285
+ "status",
286
+ ts.factory.createIdentifier("exp.status"),
287
+ ),
288
+ ts.factory.createPropertyAssignment(
289
+ "headers",
290
+ ts.factory.createIdentifier("exp.headers"),
291
+ ),
292
+ ts.factory.createPropertyAssignment(
293
+ "data",
294
+ ts.factory.createIdentifier("exp.toJSON().message"),
295
+ ),
296
+ ],
297
+ true,
298
+ ),
299
+ TypeFactory.keyword("any"),
300
+ ),
301
+ ),
302
+ ],
303
+ true,
304
+ ),
305
+ ),
306
+ undefined,
307
+ );
308
+ }
309
+
310
+ const constant = (name: string) => (expression: ts.Expression) =>
311
+ ts.factory.createVariableStatement(
312
+ [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
313
+ ts.factory.createVariableDeclarationList(
314
+ [
315
+ ts.factory.createVariableDeclaration(
316
+ ts.factory.createIdentifier(name),
317
+ undefined,
318
+ undefined,
319
+ expression,
320
+ ),
321
+ ],
322
+ ts.NodeFlags.Const,
323
+ ),
324
+ );