@nestia/migrate 10.0.2 → 11.0.0-dev.20260305

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