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