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