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