@nestia/migrate 0.6.2 → 0.7.0-dev.20240201
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/IMigrateConfig.d.ts +4 -0
- package/lib/IMigrateConfig.js +3 -0
- package/lib/IMigrateConfig.js.map +1 -0
- package/lib/MigrateApplication.d.ts +2 -12
- package/lib/MigrateApplication.js +20 -60
- package/lib/MigrateApplication.js.map +1 -1
- package/lib/analyzers/MigrateAnalyzer.d.ts +2 -1
- package/lib/analyzers/MigrateAnalyzer.js +2 -1
- package/lib/analyzers/MigrateAnalyzer.js.map +1 -1
- package/lib/bundles/NEST_TEMPLATE.d.ts +5 -0
- package/{src/bundles/TEMPLATE.ts → lib/bundles/NEST_TEMPLATE.js} +71 -27
- package/lib/bundles/NEST_TEMPLATE.js.map +1 -0
- package/lib/bundles/SDK_TEMPLATE.d.ts +5 -0
- package/lib/bundles/SDK_TEMPLATE.js +61 -0
- package/lib/bundles/SDK_TEMPLATE.js.map +1 -0
- package/lib/bundles/TEMPLATE.d.ts +1 -1
- package/lib/bundles/TEMPLATE.js +23 -23
- package/lib/bundles/TEMPLATE.js.map +1 -1
- package/lib/executable/bundle.js +70 -51
- package/lib/executable/bundle.js.map +1 -1
- package/lib/executable/migrate.js +2 -59
- package/lib/executable/migrate.js.map +1 -1
- package/lib/internal/MigrateCli.d.ts +3 -0
- package/lib/internal/MigrateCli.js +59 -0
- package/lib/internal/MigrateCli.js.map +1 -0
- package/lib/internal/MigrateCommander.d.ts +9 -0
- package/lib/internal/MigrateCommander.js +70 -0
- package/lib/internal/MigrateCommander.js.map +1 -0
- package/lib/programmers/ApiFileProgrammer.d.ts +2 -1
- package/lib/programmers/ApiFileProgrammer.js +3 -3
- package/lib/programmers/ApiFileProgrammer.js.map +1 -1
- package/lib/programmers/ApiFunctionProgrammer.d.ts +3 -1
- package/lib/programmers/ApiFunctionProgrammer.js +34 -23
- package/lib/programmers/ApiFunctionProgrammer.js.map +1 -1
- package/lib/programmers/ApiNamespaceProgrammer.d.ts +3 -1
- package/lib/programmers/ApiNamespaceProgrammer.js +15 -2
- package/lib/programmers/ApiNamespaceProgrammer.js.map +1 -1
- package/lib/programmers/ApiProgrammer.js +48 -3
- package/lib/programmers/ApiProgrammer.js.map +1 -1
- package/lib/programmers/ApiSimulatationProgrammer.d.ts +14 -0
- package/lib/programmers/ApiSimulatationProgrammer.js +127 -0
- package/lib/programmers/ApiSimulatationProgrammer.js.map +1 -0
- package/lib/structures/IMigrateProgram.d.ts +2 -0
- package/package.json +68 -64
- package/src/IMigrateConfig.ts +4 -0
- package/src/MigrateApplication.ts +20 -63
- package/src/analyzers/MigrateAnalyzer.ts +8 -4
- package/src/bundles/NEST_TEMPLATE.ts +202 -0
- package/src/bundles/SDK_TEMPLATE.ts +57 -0
- package/src/executable/bundle.ts +80 -50
- package/src/executable/migrate.ts +2 -54
- package/src/internal/MigrateCommander.ts +52 -0
- package/src/internal/MigrateInquirer.ts +79 -0
- package/src/programmers/ApiFileProgrammer.ts +4 -2
- package/src/programmers/ApiFunctionProgrammer.ts +47 -20
- package/src/programmers/ApiNamespaceProgrammer.ts +24 -1
- package/src/programmers/ApiProgrammer.ts +63 -3
- package/src/programmers/ApiSimulatationProgrammer.ts +328 -0
- package/src/structures/IMigrateProgram.ts +2 -0
@@ -0,0 +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 { ApiFunctionProgrammer } from "./ApiFunctionProgrammer";
|
10
|
+
import { ApiNamespaceProgrammer } from "./ApiNamespaceProgrammer";
|
11
|
+
import { ImportProgrammer } from "./ImportProgrammer";
|
12
|
+
import { SchemaProgrammer } from "./SchemaProgrammer";
|
13
|
+
|
14
|
+
export namespace ApiSimulatationProgrammer {
|
15
|
+
export interface IProps {
|
16
|
+
controller: IMigrateController;
|
17
|
+
route: IMigrateRoute;
|
18
|
+
alias: string;
|
19
|
+
}
|
20
|
+
export const random =
|
21
|
+
(components: ISwaggerComponents) =>
|
22
|
+
(importer: ImportProgrammer) =>
|
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
|
+
? SchemaProgrammer.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: ImportProgrammer) =>
|
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
|
+
ApiFunctionProgrammer.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: ImportProgrammer) =>
|
127
|
+
(props: IProps): ts.Statement[] => {
|
128
|
+
const parameters = [
|
129
|
+
...props.route.parameters.map((p) => ({
|
130
|
+
category: "param",
|
131
|
+
name: p.key,
|
132
|
+
schema: SchemaProgrammer.write(components)(importer)(p.schema),
|
133
|
+
})),
|
134
|
+
...(props.route.query
|
135
|
+
? [
|
136
|
+
{
|
137
|
+
category: "query",
|
138
|
+
name: props.route.query.key,
|
139
|
+
schema: SchemaProgrammer.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: SchemaProgrammer.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
|
+
ApiNamespaceProgrammer.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: ImportProgrammer) => (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
|
+
);
|
@@ -1,7 +1,9 @@
|
|
1
|
+
import { IMigrateConfig } from "../IMigrateConfig";
|
1
2
|
import { IMigrateController } from "./IMigrateController";
|
2
3
|
import { ISwagger } from "./ISwagger";
|
3
4
|
|
4
5
|
export interface IMigrateProgram {
|
6
|
+
config: IMigrateConfig;
|
5
7
|
controllers: IMigrateController[];
|
6
8
|
swagger: ISwagger;
|
7
9
|
}
|