@nestia/migrate 0.7.1 → 0.7.3

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.
@@ -99,8 +99,7 @@ export namespace ApiFunctionProgrammer {
99
99
  (importer: ImportProgrammer) =>
100
100
  (props: IProps): ts.Statement[] => {
101
101
  const encrypted: boolean = !!props.route.success?.["x-nestia-encrypted"];
102
- const contentType: string =
103
- props.route.success?.type ?? "application/json";
102
+ const contentType: string = props.route.body?.type ?? "application/json";
104
103
 
105
104
  const caller = () =>
106
105
  ts.factory.createCallExpression(
@@ -115,7 +114,7 @@ export namespace ApiFunctionProgrammer {
115
114
  )("fetch"),
116
115
  undefined,
117
116
  [
118
- contentType
117
+ contentType && contentType !== "multipart/form-data"
119
118
  ? ts.factory.createObjectLiteralExpression(
120
119
  [
121
120
  ts.factory.createSpreadAssignment(
@@ -119,7 +119,7 @@ export namespace ApiNamespaceProgrammer {
119
119
  "request",
120
120
  props.route.body
121
121
  ? LiteralFactory.generate({
122
- type: "application/json",
122
+ type: props.route.body.type,
123
123
  encrypted: !!props.route.body["x-nestia-encrypted"],
124
124
  })
125
125
  : ts.factory.createNull(),
@@ -190,9 +190,17 @@ export namespace NestMethodProgrammer {
190
190
  ...(route.body
191
191
  ? [
192
192
  writeDtoParameter({
193
- method: route.body?.["x-nestia-encrypted"]
193
+ method: route.body["x-nestia-encrypted"]
194
194
  ? "EncryptedBody"
195
- : "TypedBody",
195
+ : route.body.type === "application/json"
196
+ ? "TypedBody"
197
+ : route.body.type === "application/x-www-form-urlencoded"
198
+ ? ["TypedQuery", "Body"]
199
+ : route.body.type === "text/plain"
200
+ ? "PlainBody"
201
+ : route.body.type === "multipart/form-data"
202
+ ? ["TypedFormData", "Body"]
203
+ : "TypedBody",
196
204
  variable: "body",
197
205
  })(components)(importer)(route.body.schema),
198
206
  ]
@@ -200,21 +208,27 @@ export namespace NestMethodProgrammer {
200
208
  ];
201
209
 
202
210
  const writeDtoParameter =
203
- (accessor: { method: string; variable: string }) =>
211
+ (accessor: { method: string | [string, string]; variable: string }) =>
204
212
  (components: ISwaggerComponents) =>
205
213
  (importer: ImportProgrammer) =>
206
- (schema: ISwaggerSchema): ts.ParameterDeclaration =>
207
- ts.factory.createParameterDeclaration(
214
+ (schema: ISwaggerSchema): ts.ParameterDeclaration => {
215
+ const instance = ts.factory.createIdentifier(
216
+ importer.external({
217
+ type: "instance",
218
+ library: "@nestia/core",
219
+ name:
220
+ typeof accessor.method === "string"
221
+ ? accessor.method
222
+ : accessor.method[0],
223
+ }),
224
+ );
225
+ return ts.factory.createParameterDeclaration(
208
226
  [
209
227
  ts.factory.createDecorator(
210
228
  ts.factory.createCallExpression(
211
- ts.factory.createIdentifier(
212
- importer.external({
213
- type: "instance",
214
- library: "@nestia/core",
215
- name: accessor.method,
216
- }),
217
- ),
229
+ typeof accessor.method === "string"
230
+ ? instance
231
+ : IdentifierFactory.access(instance)(accessor.method[1]),
218
232
  undefined,
219
233
  undefined,
220
234
  ),
@@ -225,4 +239,5 @@ export namespace NestMethodProgrammer {
225
239
  undefined,
226
240
  SchemaProgrammer.write(components)(importer)(schema),
227
241
  );
242
+ };
228
243
  }
@@ -117,6 +117,9 @@ export namespace SchemaProgrammer {
117
117
  const writeString =
118
118
  (importer: ImportProgrammer) =>
119
119
  (schema: ISwaggerSchema.IString): ts.TypeNode => {
120
+ if (schema.format === "binary")
121
+ return ts.factory.createTypeReferenceNode("File");
122
+
120
123
  const intersection: ts.TypeNode[] = [TypeFactory.keyword("string")];
121
124
  if (schema.default !== undefined)
122
125
  intersection.push(importer.tag("Default", schema.default));
@@ -33,7 +33,8 @@ export namespace IMigrateRoute {
33
33
  type:
34
34
  | "text/plain"
35
35
  | "application/json"
36
- | "application/x-www-form-urlencoded";
36
+ | "application/x-www-form-urlencoded"
37
+ | "multipart/form-data";
37
38
  schema: ISwaggerSchema;
38
39
  "x-nestia-encrypted"?: boolean;
39
40
  }
@@ -45,6 +45,9 @@ export namespace ISwaggerRoute {
45
45
  "application/x-www-form-urlencoded"?: {
46
46
  schema: ISwaggerSchema;
47
47
  };
48
+ "multipart/form-data"?: {
49
+ schema: ISwaggerSchema;
50
+ };
48
51
  "*/*"?: {
49
52
  schema: ISwaggerSchema;
50
53
  };