@nestia/migrate 0.19.0 → 0.21.0-dev.20241127

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 (30) hide show
  1. package/lib/MigrateApplication.js +1151 -1126
  2. package/lib/MigrateApplication.js.map +1 -1
  3. package/lib/bundles/NEST_TEMPLATE.js +2 -2
  4. package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
  5. package/lib/bundles/SDK_TEMPLATE.js +1 -1
  6. package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
  7. package/lib/index.mjs +1095 -1076
  8. package/lib/index.mjs.map +1 -1
  9. package/lib/internal/MigrateCommander.js +25 -1
  10. package/lib/internal/MigrateCommander.js.map +1 -1
  11. package/lib/programmers/MigrateApiFunctionProgrammer.js +33 -26
  12. package/lib/programmers/MigrateApiFunctionProgrammer.js.map +1 -1
  13. package/lib/programmers/MigrateApiNamespaceProgrammer.js +6 -6
  14. package/lib/programmers/MigrateApiNamespaceProgrammer.js.map +1 -1
  15. package/lib/programmers/MigrateApiSimulatationProgrammer.js +19 -16
  16. package/lib/programmers/MigrateApiSimulatationProgrammer.js.map +1 -1
  17. package/lib/programmers/MigrateApiStartProgrammer.js +7 -4
  18. package/lib/programmers/MigrateApiStartProgrammer.js.map +1 -1
  19. package/lib/programmers/MigrateNestMethodProgrammer.js +83 -59
  20. package/lib/programmers/MigrateNestMethodProgrammer.js.map +1 -1
  21. package/lib/utils/openapi-down-convert/RefVisitor.js +0 -1
  22. package/lib/utils/openapi-down-convert/RefVisitor.js.map +1 -1
  23. package/package.json +9 -8
  24. package/src/bundles/NEST_TEMPLATE.ts +2 -2
  25. package/src/bundles/SDK_TEMPLATE.ts +1 -1
  26. package/src/programmers/MigrateApiFunctionProgrammer.ts +13 -4
  27. package/src/programmers/MigrateApiNamespaceProgrammer.ts +10 -6
  28. package/src/programmers/MigrateApiSimulatationProgrammer.ts +14 -9
  29. package/src/programmers/MigrateApiStartProgrammer.ts +4 -4
  30. package/src/programmers/MigrateNestMethodProgrammer.ts +61 -19
@@ -117,7 +117,7 @@ export namespace MigrateApiNamespaceProgrammer {
117
117
  ts.factory.createPropertyAssignment(
118
118
  "request",
119
119
  route.body
120
- ? LiteralFactory.generate({
120
+ ? LiteralFactory.write({
121
121
  type: route.body.type,
122
122
  encrypted: !!route.body["x-nestia-encrypted"],
123
123
  })
@@ -126,7 +126,7 @@ export namespace MigrateApiNamespaceProgrammer {
126
126
  ts.factory.createPropertyAssignment(
127
127
  "response",
128
128
  route.method.toUpperCase() !== "HEAD"
129
- ? LiteralFactory.generate({
129
+ ? LiteralFactory.write({
130
130
  type: route.success?.type ?? "application/json",
131
131
  encrypted: !!route.success?.["x-nestia-encrypted"],
132
132
  })
@@ -306,7 +306,8 @@ export namespace MigrateApiNamespaceProgrammer {
306
306
  ts.factory.createCallExpression(
307
307
  IdentifierFactory.access(
308
308
  ts.factory.createIdentifier(variables),
309
- )("append"),
309
+ "append",
310
+ ),
310
311
  undefined,
311
312
  [
312
313
  ts.factory.createIdentifier("key"),
@@ -325,7 +326,8 @@ export namespace MigrateApiNamespaceProgrammer {
325
326
  ts.factory.createCallExpression(
326
327
  IdentifierFactory.access(
327
328
  ts.factory.createIdentifier(variables),
328
- )("set"),
329
+ "set",
330
+ ),
329
331
  undefined,
330
332
  [
331
333
  ts.factory.createIdentifier("key"),
@@ -347,7 +349,8 @@ export namespace MigrateApiNamespaceProgrammer {
347
349
  ExpressionFactory.number(0),
348
350
  IdentifierFactory.access(
349
351
  ts.factory.createIdentifier(variables),
350
- )("size"),
352
+ "size",
353
+ ),
351
354
  ),
352
355
  undefined,
353
356
  ts.factory.createIdentifier("location"),
@@ -363,7 +366,8 @@ export namespace MigrateApiNamespaceProgrammer {
363
366
  ts.factory.createCallExpression(
364
367
  IdentifierFactory.access(
365
368
  ts.factory.createIdentifier(variables),
366
- )("toString"),
369
+ "toString",
370
+ ),
367
371
  undefined,
368
372
  undefined,
369
373
  ),
@@ -55,7 +55,8 @@ export namespace MigrateApiSimulatationProgrammer {
55
55
  name: "typia",
56
56
  }),
57
57
  ),
58
- )("random"),
58
+ "random",
59
+ ),
59
60
  [output],
60
61
  [ts.factory.createIdentifier("g")],
61
62
  ),
@@ -147,9 +148,9 @@ export namespace MigrateApiSimulatationProgrammer {
147
148
  ];
148
149
  if (parameters.length === 0) return [];
149
150
 
150
- const validator = StatementFactory.constant(
151
- "assert",
152
- ts.factory.createCallExpression(
151
+ const validator = StatementFactory.constant({
152
+ name: "assert",
153
+ value: ts.factory.createCallExpression(
153
154
  IdentifierFactory.access(
154
155
  ts.factory.createIdentifier(
155
156
  importer.external({
@@ -158,7 +159,8 @@ export namespace MigrateApiSimulatationProgrammer {
158
159
  name: "NestiaSimulator",
159
160
  }),
160
161
  ),
161
- )("assert"),
162
+ "assert",
163
+ ),
162
164
  undefined,
163
165
  [
164
166
  ts.factory.createObjectLiteralExpression(
@@ -186,14 +188,15 @@ export namespace MigrateApiSimulatationProgrammer {
186
188
  ),
187
189
  ],
188
190
  ),
189
- );
191
+ });
190
192
  const individual = parameters
191
193
  .map((p) =>
192
194
  ts.factory.createCallExpression(
193
195
  (() => {
194
196
  const base = IdentifierFactory.access(
195
197
  ts.factory.createIdentifier("assert"),
196
- )(p.category);
198
+ p.category,
199
+ );
197
200
  if (p.category !== "param") return base;
198
201
  return ts.factory.createCallExpression(base, undefined, [
199
202
  ts.factory.createStringLiteral(p.name),
@@ -216,7 +219,8 @@ export namespace MigrateApiSimulatationProgrammer {
216
219
  name: "typia",
217
220
  }),
218
221
  ),
219
- )("assert"),
222
+ "assert",
223
+ ),
220
224
  undefined,
221
225
  [
222
226
  ts.factory.createIdentifier(
@@ -251,7 +255,8 @@ export namespace MigrateApiSimulatationProgrammer {
251
255
  name: "typia",
252
256
  }),
253
257
  ),
254
- )("is"),
258
+ "is",
259
+ ),
255
260
  [
256
261
  ts.factory.createTypeReferenceNode(
257
262
  importer.external({
@@ -53,9 +53,9 @@ export namespace MigrateApiStartProgrammer {
53
53
  (document: OpenApi.IDocument) =>
54
54
  (importer: MigrateImportProgrammer) =>
55
55
  (route: IHttpMigrateRoute): ts.VariableStatement =>
56
- StatementFactory.constant(
57
- "main",
58
- ts.factory.createArrowFunction(
56
+ StatementFactory.constant({
57
+ name: "main",
58
+ value: ts.factory.createArrowFunction(
59
59
  [ts.factory.createToken(ts.SyntaxKind.AsyncKeyword)],
60
60
  undefined,
61
61
  [],
@@ -71,7 +71,7 @@ export namespace MigrateApiStartProgrammer {
71
71
  true,
72
72
  ),
73
73
  ),
74
- );
74
+ });
75
75
 
76
76
  const writeConnection =
77
77
  (config: IHttpMigrateProgram.IConfig) =>
@@ -56,7 +56,8 @@ export namespace MigrateNestMethodProgrammer {
56
56
  name: "typia",
57
57
  }),
58
58
  ),
59
- )("random"),
59
+ "random",
60
+ ),
60
61
  [output],
61
62
  undefined,
62
63
  ),
@@ -102,7 +103,8 @@ export namespace MigrateNestMethodProgrammer {
102
103
  const router = (instance: string) =>
103
104
  ts.factory.createDecorator(
104
105
  ts.factory.createCallExpression(
105
- IdentifierFactory.access(external("@nestia/core")(instance))(
106
+ IdentifierFactory.access(
107
+ external("@nestia/core")(instance),
106
108
  StringUtil.capitalize(route.method),
107
109
  ),
108
110
  [],
@@ -196,9 +198,12 @@ export namespace MigrateNestMethodProgrammer {
196
198
  ),
197
199
  ...(route.headers
198
200
  ? [
199
- writeDtoParameter({ method: "TypedHeaders", variable: "headers" })(
200
- components,
201
- )(importer)({
201
+ writeDtoParameter({
202
+ method: "TypedHeaders",
203
+ variable: "headers",
204
+ arguments: [],
205
+ })(components)(importer)({
206
+ required: true,
202
207
  schema: route.headers.schema,
203
208
  example: route.headers.example(),
204
209
  examples: route.headers.examples(),
@@ -207,9 +212,12 @@ export namespace MigrateNestMethodProgrammer {
207
212
  : []),
208
213
  ...(route.query
209
214
  ? [
210
- writeDtoParameter({ method: "TypedQuery", variable: "query" })(
211
- components,
212
- )(importer)({
215
+ writeDtoParameter({
216
+ method: "TypedQuery",
217
+ variable: "query",
218
+ arguments: [],
219
+ })(components)(importer)({
220
+ required: true,
213
221
  schema: route.query.schema,
214
222
  example: route.query.example(),
215
223
  examples: route.query.examples(),
@@ -231,8 +239,36 @@ export namespace MigrateNestMethodProgrammer {
231
239
  ? ["TypedFormData", "Body"]
232
240
  : "TypedBody",
233
241
  variable: "body",
242
+ arguments:
243
+ route.body.type === "multipart/form-data"
244
+ ? [
245
+ ts.factory.createArrowFunction(
246
+ undefined,
247
+ undefined,
248
+ [],
249
+ undefined,
250
+ undefined,
251
+ ts.factory.createCallExpression(
252
+ ts.factory.createIdentifier(
253
+ importer.external({
254
+ type: "default",
255
+ library: "multer",
256
+ name: "Multer",
257
+ }),
258
+ ),
259
+ undefined,
260
+ undefined,
261
+ ),
262
+ ),
263
+ ]
264
+ : [],
234
265
  })(components)(importer)({
235
266
  schema: route.body.schema,
267
+ required: !(
268
+ (route.body.type === "application/json" ||
269
+ route.body.type === "text/plain") &&
270
+ route.operation().requestBody?.required === false
271
+ ),
236
272
  example: route.body.media().example,
237
273
  examples: route.body.media().examples,
238
274
  }),
@@ -241,11 +277,16 @@ export namespace MigrateNestMethodProgrammer {
241
277
  ];
242
278
 
243
279
  const writeDtoParameter =
244
- (accessor: { method: string | [string, string]; variable: string }) =>
280
+ (accessor: {
281
+ method: string | [string, string];
282
+ variable: string;
283
+ arguments: ts.Expression[];
284
+ }) =>
245
285
  (components: OpenApi.IComponents) =>
246
286
  (importer: MigrateImportProgrammer) =>
247
287
  (props: {
248
288
  schema: OpenApi.IJsonSchema;
289
+ required: boolean;
249
290
  example?: any;
250
291
  examples?: Record<string, any>;
251
292
  }): ts.ParameterDeclaration => {
@@ -266,15 +307,17 @@ export namespace MigrateNestMethodProgrammer {
266
307
  ts.factory.createCallExpression(
267
308
  typeof accessor.method === "string"
268
309
  ? instance
269
- : IdentifierFactory.access(instance)(accessor.method[1]),
270
- undefined,
310
+ : IdentifierFactory.access(instance, accessor.method[1]),
271
311
  undefined,
312
+ accessor.arguments,
272
313
  ),
273
314
  ),
274
315
  ],
275
316
  undefined,
276
317
  accessor.variable,
277
- undefined,
318
+ props.required === false
319
+ ? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
320
+ : undefined,
278
321
  MigrateSchemaProgrammer.write(components)(importer)(props.schema),
279
322
  );
280
323
  };
@@ -298,9 +341,10 @@ export namespace MigrateNestMethodProgrammer {
298
341
  name: "SwaggerExample",
299
342
  }),
300
343
  ),
301
- )(kind),
344
+ kind,
345
+ ),
302
346
  [],
303
- [LiteralFactory.generate(media.example)],
347
+ [LiteralFactory.write(media.example)],
304
348
  ),
305
349
  ),
306
350
  ]
@@ -316,12 +360,10 @@ export namespace MigrateNestMethodProgrammer {
316
360
  name: "SwaggerExample",
317
361
  }),
318
362
  ),
319
- )(kind),
363
+ kind,
364
+ ),
320
365
  [],
321
- [
322
- ts.factory.createStringLiteral(key),
323
- LiteralFactory.generate(value),
324
- ],
366
+ [ts.factory.createStringLiteral(key), LiteralFactory.write(value)],
325
367
  ),
326
368
  ),
327
369
  ),