@nestia/core 4.0.0-dev.20241027 → 4.0.0-dev.20241027-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.
@@ -1,4 +1,3 @@
1
- import type { IRequestFormDataProps } from "../options/IRequestFormDataProps";
2
1
  /**
3
2
  * Type safe multipart/form-data decorator.
4
3
  *
@@ -20,13 +19,13 @@ import type { IRequestFormDataProps } from "../options/IRequestFormDataProps";
20
19
  * 3. Only `boolean`, `bigint`, `number`, `string`, `Blob`, `File` or their array types are allowed
21
20
  * 4. By the way, union type never be not allowed
22
21
  *
23
- * By the way, if you're using `fastify`, you have to setup `@fastify/multipart`
22
+ * By the way, if you're using `fastify`, you have to setup `fastify-multer`
24
23
  * and configure like below when composing the NestJS application. If you don't do
25
24
  * that, `@TypedFormData.Body()` will not work properly, and throw 500 internal
26
25
  * server error when `Blob` or `File` type being utilized.
27
26
  *
28
27
  * ```typescript
29
- * import multipart from "fastify-multipart";
28
+ * import fastifyMulter from "fastify-multer";
30
29
  * import { NestFactory } from "@nestjs/core";
31
30
  * import {
32
31
  * FastifyAdapter,
@@ -38,7 +37,7 @@ import type { IRequestFormDataProps } from "../options/IRequestFormDataProps";
38
37
  * AppModule,
39
38
  * new FastifyAdapter(),
40
39
  * );
41
- * app.register(multipart);
40
+ * app.register(fastifyMulter.contentParser);
42
41
  * await app.listen(3000);
43
42
  * }
44
43
  * ```
@@ -54,7 +53,19 @@ export declare namespace TypedFormData {
54
53
  *
55
54
  * Much easier and type safer than `@nest.UploadFile()` decorator.
56
55
  *
57
- * @param props Automatically filled by transformer
56
+ * @param factory Factory function ncreating the `multer` or `fastify-multer`
57
+ * instance. In the factory function, you also can specify the
58
+ * multer composition options like `storage` engine.
58
59
  */
59
- function Body<T extends object>(props?: IRequestFormDataProps<T>): ParameterDecorator;
60
+ function Body<Multer extends IMulterBase>(factory: () => Multer): ParameterDecorator;
61
+ /**
62
+ * Base type of the `multer` or `fastify-multer`.
63
+ */
64
+ interface IMulterBase {
65
+ single(fieldName: string): any;
66
+ array(fieldName: string, maxCount?: number): any;
67
+ fields(fields: readonly object[]): any;
68
+ any(): any;
69
+ none(): any;
70
+ }
60
71
  }
@@ -8,21 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __asyncValues = (this && this.__asyncValues) || function (o) {
12
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
13
- var m = o[Symbol.asyncIterator], i;
14
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
15
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
16
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
17
- };
18
- var __importDefault = (this && this.__importDefault) || function (mod) {
19
- return (mod && mod.__esModule) ? mod : { "default": mod };
20
- };
21
11
  Object.defineProperty(exports, "__esModule", { value: true });
22
12
  exports.TypedFormData = void 0;
23
13
  const common_1 = require("@nestjs/common");
24
- const multer_1 = __importDefault(require("multer"));
25
- const Singleton_1 = require("../utils/Singleton");
26
14
  const validate_request_form_data_1 = require("./internal/validate_request_form_data");
27
15
  /**
28
16
  * Type safe multipart/form-data decorator.
@@ -45,13 +33,13 @@ const validate_request_form_data_1 = require("./internal/validate_request_form_d
45
33
  * 3. Only `boolean`, `bigint`, `number`, `string`, `Blob`, `File` or their array types are allowed
46
34
  * 4. By the way, union type never be not allowed
47
35
  *
48
- * By the way, if you're using `fastify`, you have to setup `@fastify/multipart`
36
+ * By the way, if you're using `fastify`, you have to setup `fastify-multer`
49
37
  * and configure like below when composing the NestJS application. If you don't do
50
38
  * that, `@TypedFormData.Body()` will not work properly, and throw 500 internal
51
39
  * server error when `Blob` or `File` type being utilized.
52
40
  *
53
41
  * ```typescript
54
- * import multipart from "fastify-multipart";
42
+ * import fastifyMulter from "fastify-multer";
55
43
  * import { NestFactory } from "@nestjs/core";
56
44
  * import {
57
45
  * FastifyAdapter,
@@ -63,7 +51,7 @@ const validate_request_form_data_1 = require("./internal/validate_request_form_d
63
51
  * AppModule,
64
52
  * new FastifyAdapter(),
65
53
  * );
66
- * app.register(multipart);
54
+ * app.register(fastifyMulter.contentParser);
67
55
  * await app.listen(3000);
68
56
  * }
69
57
  * ```
@@ -74,29 +62,20 @@ const validate_request_form_data_1 = require("./internal/validate_request_form_d
74
62
  var TypedFormData;
75
63
  (function (TypedFormData) {
76
64
  /**
77
- * Request body decorator.
78
- *
79
- * Request body decorator for the `multipart/form-data` type.
80
- *
81
- * Much easier and type safer than `@nest.UploadFile()` decorator.
82
- *
83
- * @param props Automatically filled by transformer
65
+ * @internal
84
66
  */
85
- function Body(props) {
67
+ function Body(factory, props) {
86
68
  if (typeof File === "undefined")
87
69
  throw new Error("Error on TypedFormData.Body(): 'File' class is not supported in the older version of NodeJS. Upgrade the NodeJS to the modern.");
88
70
  const checker = (0, validate_request_form_data_1.validate_request_form_data)(props);
89
- const predicator = (type) => new Singleton_1.Singleton(() => type === "express" ? decodeExpress(props) : decodeFastify(props));
71
+ const uploader = decode(factory(), props);
90
72
  return (0, common_1.createParamDecorator)(function TypedFormDataBody(_unknown, context) {
91
73
  return __awaiter(this, void 0, void 0, function* () {
92
74
  const http = context.switchToHttp();
93
75
  const request = http.getRequest();
94
76
  if (isMultipartFormData(request.headers["content-type"]) === false)
95
77
  throw new common_1.BadRequestException(`Request body type is not "multipart/form-data".`);
96
- const decoder = isExpressRequest(request)
97
- ? predicator("express").get()
98
- : predicator("fastify").get();
99
- const data = yield decoder({
78
+ const data = yield uploader({
100
79
  request: request,
101
80
  response: http.getResponse(),
102
81
  });
@@ -112,8 +91,8 @@ var TypedFormData;
112
91
  /**
113
92
  * @internal
114
93
  */
115
- const decodeExpress = (props) => {
116
- const upload = multerApplication.get().fields(props.files.map((file) => (Object.assign({ name: file.name }, (file.limit === 1 ? { maxCount: 1 } : {})))));
94
+ const decode = (multer, props) => {
95
+ const upload = multer.fields(props.files.map((file) => (Object.assign({ name: file.name }, (file.limit === 1 ? { maxCount: 1 } : {})))));
117
96
  const interceptor = (request, response) => new Promise((resolve, reject) => upload(request, response, (error) => {
118
97
  if (error)
119
98
  reject(error);
@@ -134,40 +113,6 @@ const decodeExpress = (props) => {
134
113
  return data;
135
114
  });
136
115
  };
137
- /**
138
- * @internal
139
- */
140
- const decodeFastify = (_props) => (socket) => __awaiter(void 0, void 0, void 0, function* () {
141
- var _a, e_1, _b, _c;
142
- if (socket.request.files === undefined ||
143
- typeof socket.request.files !== "function")
144
- throw new common_1.InternalServerErrorException("Have not configured the `fastify-multipart` plugin yet. Inquiry to the backend developer.");
145
- const data = new FormData();
146
- try {
147
- for (var _d = true, _e = __asyncValues(socket.request.parts()), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
148
- _c = _f.value;
149
- _d = false;
150
- const part = _c;
151
- if (part.type === "file")
152
- data.append(part.fieldname, new File([yield part.toBuffer()], part.filename, {
153
- type: part.mimetype,
154
- }));
155
- else if (Array.isArray(part.value))
156
- for (const elem of part.value)
157
- data.append(part.fieldname, String(elem));
158
- else
159
- data.append(part.fieldname, String(part.value));
160
- }
161
- }
162
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
163
- finally {
164
- try {
165
- if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
166
- }
167
- finally { if (e_1) throw e_1.error; }
168
- }
169
- return data;
170
- });
171
116
  /**
172
117
  * @internal
173
118
  */
@@ -192,12 +137,4 @@ const isMultipartFormData = (text) => text !== undefined &&
192
137
  .split(";")
193
138
  .map((str) => str.trim())
194
139
  .some((str) => str === "multipart/form-data");
195
- /**
196
- * @internal
197
- */
198
- const isExpressRequest = (request) => request.app !== undefined;
199
- /**
200
- * @internal
201
- */
202
- const multerApplication = new Singleton_1.Singleton(() => (0, multer_1.default)());
203
140
  //# sourceMappingURL=TypedFormData.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"TypedFormData.js","sourceRoot":"","sources":["../../src/decorators/TypedFormData.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AACA,2CAKwB;AAIxB,oDAA4B;AAG5B,kDAA+C;AAC/C,sFAAmF;AAEnF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,IAAiB,aAAa,CA6C7B;AA7CD,WAAiB,aAAa;IAC5B;;;;;;;;OAQG;IACH,SAAgB,IAAI,CAClB,KAAgC;QAEhC,IAAI,OAAO,IAAI,KAAK,WAAW;YAC7B,MAAM,IAAI,KAAK,CACb,gIAAgI,CACjI,CAAC;QACJ,MAAM,OAAO,GAAG,IAAA,uDAA0B,EAAC,KAAK,CAAC,CAAC;QAClD,MAAM,UAAU,GAAG,CAAC,IAA2B,EAAE,EAAE,CACjD,IAAI,qBAAS,CAAC,GAAG,EAAE,CACjB,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,KAAM,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,KAAM,CAAC,CACnE,CAAC;QACJ,OAAO,IAAA,6BAAoB,EAAC,SAAe,iBAAiB,CAC1D,QAAa,EACb,OAAyB;;gBAEzB,MAAM,IAAI,GAAsB,OAAO,CAAC,YAAY,EAAE,CAAC;gBACvD,MAAM,OAAO,GAAoB,IAAI,CAAC,UAAU,EAAE,CAAC;gBACnD,IAAI,mBAAmB,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,KAAK,KAAK;oBAChE,MAAM,IAAI,4BAAmB,CAC3B,iDAAiD,CAClD,CAAC;gBAEJ,MAAM,OAAO,GAAG,gBAAgB,CAAC,OAAO,CAAC;oBACvC,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,G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E,IAAI,CAAC,QAAQ;iBACpB,CAAC,CACH,CAAC;AACV,CAAC,CAAC;AAEJ;;GAEG;AACH,MAAM,mBAAmB,GAAG,CAAC,IAAa,EAAW,EAAE,CACrD,IAAI,KAAK,SAAS;IAClB,IAAI;SACD,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;SACxB,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,qBAAqB,CAAC,CAAC"}
@@ -70,9 +70,14 @@ const FUNCTORS = {
70
70
  "TypedQuery.Body": (props) => props.arguments.length
71
71
  ? props.arguments
72
72
  : [TypedQueryBodyProgrammer_1.TypedQueryBodyProgrammer.generate(props)],
73
- "TypedFormData.Body": (props) => props.arguments.length
74
- ? props.arguments
75
- : [TypedFormDataBodyProgrammer_1.TypedFormDataBodyProgrammer.generate(props)],
73
+ "TypedFormData.Body": (props) => props.arguments.length === 0
74
+ ? [
75
+ typescript_1.default.factory.createIdentifier("undefined"),
76
+ TypedFormDataBodyProgrammer_1.TypedFormDataBodyProgrammer.generate(props),
77
+ ]
78
+ : props.arguments.length === 1
79
+ ? [props.arguments[0], TypedFormDataBodyProgrammer_1.TypedFormDataBodyProgrammer.generate(props)]
80
+ : props.arguments,
76
81
  PlainBody: (props) => props.arguments.length
77
82
  ? props.arguments
78
83
  : [PlainBodyProgrammer_1.PlainBodyProgrammer.generate(props)],
@@ -1 +1 @@
1
- {"version":3,"file":"ParameterDecoratorTransformer.js","sourceRoot":"","sources":["../../src/transformers/ParameterDecoratorTransformer.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,4DAA4B;AAG5B,4EAAyE;AACzE,4EAAyE;AACzE,4FAAyF;AACzF,kFAA+E;AAC/E,8EAA2E;AAC3E,sFAAmF;AACnF,8EAA2E;AAE3E,IAAiB,6BAA6B,CAuD7C;AAvDD,WAAiB,6BAA6B;IAC/B,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ANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestia/core",
3
- "version": "4.0.0-dev.20241027",
3
+ "version": "4.0.0-dev.20241027-3",
4
4
  "description": "Super-fast validation decorators of NestJS",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -36,24 +36,23 @@
36
36
  },
37
37
  "homepage": "https://nestia.io",
38
38
  "dependencies": {
39
- "@nestia/fetcher": "^4.0.0-dev.20241027",
39
+ "@nestia/fetcher": "^4.0.0-dev.20241027-3",
40
40
  "@nestjs/common": ">=7.0.1",
41
41
  "@nestjs/core": ">=7.0.1",
42
42
  "@samchon/openapi": "^2.0.0-dev.20241127-2",
43
43
  "detect-ts-node": "^1.0.5",
44
44
  "get-function-location": "^2.0.0",
45
45
  "glob": "^7.2.0",
46
- "multer": "1.4.5-lts.1",
47
46
  "path-parser": "^6.1.0",
48
47
  "raw-body": "^2.0.0",
49
48
  "reflect-metadata": ">=0.1.12",
50
49
  "rxjs": ">=6.0.3",
51
50
  "tgrid": "^1.0.0",
52
- "typia": "^7.0.0-dev.20241027-2",
51
+ "typia": ">=7.0.0-dev.20241027-2 <8.0.0",
53
52
  "ws": "^7.5.3"
54
53
  },
55
54
  "peerDependencies": {
56
- "@nestia/fetcher": ">=4.0.0-dev.20241027",
55
+ "@nestia/fetcher": ">=4.0.0-dev.20241027-3",
57
56
  "@nestjs/common": ">=7.0.1",
58
57
  "@nestjs/core": ">=7.0.1",
59
58
  "reflect-metadata": ">=0.1.12",
@@ -61,13 +60,12 @@
61
60
  "typia": ">=7.0.0-dev.20241027-2 <8.0.0"
62
61
  },
63
62
  "devDependencies": {
64
- "@fastify/multipart": "^8.1.0",
65
63
  "@nestjs/common": "^10.3.3",
66
64
  "@nestjs/core": "^10.3.3",
67
65
  "@types/express": "^4.17.15",
68
66
  "@types/glob": "^7.2.0",
69
67
  "@types/inquirer": "^9.0.3",
70
- "@types/multer": "^1.4.11",
68
+ "@types/multer": "^1.4.12",
71
69
  "@types/ts-expose-internals": "npm:ts-expose-internals@5.4.5",
72
70
  "@types/ws": "^8.5.10",
73
71
  "@typescript-eslint/eslint-plugin": "^5.46.1",
@@ -75,7 +73,7 @@
75
73
  "commander": "^10.0.0",
76
74
  "comment-json": "^4.2.3",
77
75
  "eslint-plugin-deprecation": "^1.4.1",
78
- "fastify": "^4.25.2",
76
+ "fastify": "^4.28.1",
79
77
  "git-last-commit": "^1.0.1",
80
78
  "inquirer": "^8.2.5",
81
79
  "rimraf": "^3.0.2",
@@ -1,17 +1,13 @@
1
- import type { Multipart } from "@fastify/multipart";
2
1
  import {
3
2
  BadRequestException,
4
3
  ExecutionContext,
5
- InternalServerErrorException,
6
4
  createParamDecorator,
7
5
  } from "@nestjs/common";
8
6
  import type { HttpArgumentsHost } from "@nestjs/common/interfaces";
9
7
  import type express from "express";
10
- import type { FastifyReply, FastifyRequest } from "fastify";
11
- import multer from "multer";
8
+ import type ExpressMulter from "multer";
12
9
 
13
10
  import type { IRequestFormDataProps } from "../options/IRequestFormDataProps";
14
- import { Singleton } from "../utils/Singleton";
15
11
  import { validate_request_form_data } from "./internal/validate_request_form_data";
16
12
 
17
13
  /**
@@ -35,13 +31,13 @@ import { validate_request_form_data } from "./internal/validate_request_form_dat
35
31
  * 3. Only `boolean`, `bigint`, `number`, `string`, `Blob`, `File` or their array types are allowed
36
32
  * 4. By the way, union type never be not allowed
37
33
  *
38
- * By the way, if you're using `fastify`, you have to setup `@fastify/multipart`
34
+ * By the way, if you're using `fastify`, you have to setup `fastify-multer`
39
35
  * and configure like below when composing the NestJS application. If you don't do
40
36
  * that, `@TypedFormData.Body()` will not work properly, and throw 500 internal
41
37
  * server error when `Blob` or `File` type being utilized.
42
38
  *
43
39
  * ```typescript
44
- * import multipart from "fastify-multipart";
40
+ * import fastifyMulter from "fastify-multer";
45
41
  * import { NestFactory } from "@nestjs/core";
46
42
  * import {
47
43
  * FastifyAdapter,
@@ -53,7 +49,7 @@ import { validate_request_form_data } from "./internal/validate_request_form_dat
53
49
  * AppModule,
54
50
  * new FastifyAdapter(),
55
51
  * );
56
- * app.register(multipart);
52
+ * app.register(fastifyMulter.contentParser);
57
53
  * await app.listen(3000);
58
54
  * }
59
55
  * ```
@@ -69,20 +65,27 @@ export namespace TypedFormData {
69
65
  *
70
66
  * Much easier and type safer than `@nest.UploadFile()` decorator.
71
67
  *
72
- * @param props Automatically filled by transformer
68
+ * @param factory Factory function ncreating the `multer` or `fastify-multer`
69
+ * instance. In the factory function, you also can specify the
70
+ * multer composition options like `storage` engine.
71
+ */
72
+ export function Body<Multer extends IMulterBase>(
73
+ factory: () => Multer,
74
+ ): ParameterDecorator;
75
+
76
+ /**
77
+ * @internal
73
78
  */
74
79
  export function Body<T extends object>(
75
- props?: IRequestFormDataProps<T>,
80
+ factory: () => IMulterBase,
81
+ props?: IRequestFormDataProps<T> | undefined,
76
82
  ): ParameterDecorator {
77
83
  if (typeof File === "undefined")
78
84
  throw new Error(
79
85
  "Error on TypedFormData.Body(): 'File' class is not supported in the older version of NodeJS. Upgrade the NodeJS to the modern.",
80
86
  );
81
87
  const checker = validate_request_form_data(props);
82
- const predicator = (type: "express" | "fastify") =>
83
- new Singleton(() =>
84
- type === "express" ? decodeExpress(props!) : decodeFastify(props!),
85
- );
88
+ const uploader = decode(factory() as ExpressMulter.Multer, props!);
86
89
  return createParamDecorator(async function TypedFormDataBody(
87
90
  _unknown: any,
88
91
  context: ExecutionContext,
@@ -93,11 +96,7 @@ export namespace TypedFormData {
93
96
  throw new BadRequestException(
94
97
  `Request body type is not "multipart/form-data".`,
95
98
  );
96
-
97
- const decoder = isExpressRequest(request)
98
- ? predicator("express").get()
99
- : predicator("fastify").get();
100
- const data: FormData = await decoder({
99
+ const data: FormData = await uploader({
101
100
  request: request as any,
102
101
  response: http.getResponse(),
103
102
  });
@@ -106,13 +105,27 @@ export namespace TypedFormData {
106
105
  return output;
107
106
  })();
108
107
  }
108
+
109
+ /**
110
+ * Base type of the `multer` or `fastify-multer`.
111
+ */
112
+ export interface IMulterBase {
113
+ single(fieldName: string): any;
114
+ array(fieldName: string, maxCount?: number): any;
115
+ fields(fields: readonly object[]): any;
116
+ any(): any;
117
+ none(): any;
118
+ }
109
119
  }
110
120
 
111
121
  /**
112
122
  * @internal
113
123
  */
114
- const decodeExpress = <T>(props: IRequestFormDataProps<T>) => {
115
- const upload = multerApplication.get().fields(
124
+ const decode = <T>(
125
+ multer: ExpressMulter.Multer,
126
+ props: IRequestFormDataProps<T>,
127
+ ) => {
128
+ const upload = multer.fields(
116
129
  props!.files.map((file) => ({
117
130
  name: file.name,
118
131
  ...(file.limit === 1 ? { maxCount: 1 } : {}),
@@ -141,40 +154,6 @@ const decodeExpress = <T>(props: IRequestFormDataProps<T>) => {
141
154
  };
142
155
  };
143
156
 
144
- /**
145
- * @internal
146
- */
147
- const decodeFastify =
148
- <T>(_props: IRequestFormDataProps<T>) =>
149
- async (socket: {
150
- request: FastifyRequest & {
151
- parts?(): AsyncIterableIterator<Multipart>;
152
- };
153
- response: FastifyReply;
154
- }): Promise<FormData> => {
155
- if (
156
- socket.request.files === undefined ||
157
- typeof socket.request.files !== "function"
158
- )
159
- throw new InternalServerErrorException(
160
- "Have not configured the `fastify-multipart` plugin yet. Inquiry to the backend developer.",
161
- );
162
- const data: FormData = new FormData();
163
- for await (const part of socket.request.parts())
164
- if (part.type === "file")
165
- data.append(
166
- part.fieldname,
167
- new File([await part.toBuffer()], part.filename, {
168
- type: part.mimetype,
169
- }),
170
- );
171
- else if (Array.isArray(part.value))
172
- for (const elem of part.value)
173
- data.append(part.fieldname, String(elem));
174
- else data.append(part.fieldname, String(part.value));
175
- return data;
176
- };
177
-
178
157
  /**
179
158
  * @internal
180
159
  */
@@ -209,15 +188,3 @@ const isMultipartFormData = (text?: string): boolean =>
209
188
  .split(";")
210
189
  .map((str) => str.trim())
211
190
  .some((str) => str === "multipart/form-data");
212
-
213
- /**
214
- * @internal
215
- */
216
- const isExpressRequest = (
217
- request: express.Request | FastifyRequest,
218
- ): request is express.Request => (request as express.Request).app !== undefined;
219
-
220
- /**
221
- * @internal
222
- */
223
- const multerApplication = new Singleton(() => multer());
@@ -100,9 +100,14 @@ const FUNCTORS: Record<string, Programmer> = {
100
100
  ? props.arguments
101
101
  : [TypedQueryBodyProgrammer.generate(props)],
102
102
  "TypedFormData.Body": (props) =>
103
- props.arguments.length
104
- ? props.arguments
105
- : [TypedFormDataBodyProgrammer.generate(props)],
103
+ props.arguments.length === 0
104
+ ? [
105
+ ts.factory.createIdentifier("undefined"),
106
+ TypedFormDataBodyProgrammer.generate(props),
107
+ ]
108
+ : props.arguments.length === 1
109
+ ? [props.arguments[0], TypedFormDataBodyProgrammer.generate(props)]
110
+ : props.arguments,
106
111
  PlainBody: (props) =>
107
112
  props.arguments.length
108
113
  ? props.arguments