@nestia/migrate 12.0.0-rc.2 → 12.0.0-rc.3

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