@nestia/core 4.0.0-dev.20241027 → 4.0.0-dev.20241027-2
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/decorators/TypedFormData.d.ts +7 -6
- package/lib/decorators/TypedFormData.js +36 -55
- package/lib/decorators/TypedFormData.js.map +1 -1
- package/lib/transformers/ParameterDecoratorTransformer.js +8 -3
- package/lib/transformers/ParameterDecoratorTransformer.js.map +1 -1
- package/package.json +7 -7
- package/src/decorators/TypedFormData.ts +57 -36
- package/src/transformers/ParameterDecoratorTransformer.ts +8 -3
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type * as FastifyMulter from "fastify-multer/lib/interfaces";
|
|
2
|
+
import ExpressMulter from "multer";
|
|
2
3
|
/**
|
|
3
4
|
* Type safe multipart/form-data decorator.
|
|
4
5
|
*
|
|
@@ -20,13 +21,13 @@ import type { IRequestFormDataProps } from "../options/IRequestFormDataProps";
|
|
|
20
21
|
* 3. Only `boolean`, `bigint`, `number`, `string`, `Blob`, `File` or their array types are allowed
|
|
21
22
|
* 4. By the way, union type never be not allowed
|
|
22
23
|
*
|
|
23
|
-
* By the way, if you're using `fastify`, you have to setup
|
|
24
|
+
* By the way, if you're using `fastify`, you have to setup `fastify-multer`
|
|
24
25
|
* and configure like below when composing the NestJS application. If you don't do
|
|
25
26
|
* that, `@TypedFormData.Body()` will not work properly, and throw 500 internal
|
|
26
27
|
* server error when `Blob` or `File` type being utilized.
|
|
27
28
|
*
|
|
28
29
|
* ```typescript
|
|
29
|
-
* import
|
|
30
|
+
* import fastifyMulter from "fastify-multer";
|
|
30
31
|
* import { NestFactory } from "@nestjs/core";
|
|
31
32
|
* import {
|
|
32
33
|
* FastifyAdapter,
|
|
@@ -38,7 +39,7 @@ import type { IRequestFormDataProps } from "../options/IRequestFormDataProps";
|
|
|
38
39
|
* AppModule,
|
|
39
40
|
* new FastifyAdapter(),
|
|
40
41
|
* );
|
|
41
|
-
* app.register(
|
|
42
|
+
* app.register(fastifyMulter.contentParser);
|
|
42
43
|
* await app.listen(3000);
|
|
43
44
|
* }
|
|
44
45
|
* ```
|
|
@@ -54,7 +55,7 @@ export declare namespace TypedFormData {
|
|
|
54
55
|
*
|
|
55
56
|
* Much easier and type safer than `@nest.UploadFile()` decorator.
|
|
56
57
|
*
|
|
57
|
-
* @param
|
|
58
|
+
* @param options Options for the `multer` or `fastify-multer`
|
|
58
59
|
*/
|
|
59
|
-
function Body
|
|
60
|
+
function Body(options?: ExpressMulter.Options | FastifyMulter.Options): ParameterDecorator;
|
|
60
61
|
}
|
|
@@ -8,19 +8,13 @@ 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
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
19
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
13
|
};
|
|
21
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
15
|
exports.TypedFormData = void 0;
|
|
23
16
|
const common_1 = require("@nestjs/common");
|
|
17
|
+
const fastify_multer_1 = __importDefault(require("fastify-multer"));
|
|
24
18
|
const multer_1 = __importDefault(require("multer"));
|
|
25
19
|
const Singleton_1 = require("../utils/Singleton");
|
|
26
20
|
const validate_request_form_data_1 = require("./internal/validate_request_form_data");
|
|
@@ -45,13 +39,13 @@ const validate_request_form_data_1 = require("./internal/validate_request_form_d
|
|
|
45
39
|
* 3. Only `boolean`, `bigint`, `number`, `string`, `Blob`, `File` or their array types are allowed
|
|
46
40
|
* 4. By the way, union type never be not allowed
|
|
47
41
|
*
|
|
48
|
-
* By the way, if you're using `fastify`, you have to setup
|
|
42
|
+
* By the way, if you're using `fastify`, you have to setup `fastify-multer`
|
|
49
43
|
* and configure like below when composing the NestJS application. If you don't do
|
|
50
44
|
* that, `@TypedFormData.Body()` will not work properly, and throw 500 internal
|
|
51
45
|
* server error when `Blob` or `File` type being utilized.
|
|
52
46
|
*
|
|
53
47
|
* ```typescript
|
|
54
|
-
* import
|
|
48
|
+
* import fastifyMulter from "fastify-multer";
|
|
55
49
|
* import { NestFactory } from "@nestjs/core";
|
|
56
50
|
* import {
|
|
57
51
|
* FastifyAdapter,
|
|
@@ -63,7 +57,7 @@ const validate_request_form_data_1 = require("./internal/validate_request_form_d
|
|
|
63
57
|
* AppModule,
|
|
64
58
|
* new FastifyAdapter(),
|
|
65
59
|
* );
|
|
66
|
-
* app.register(
|
|
60
|
+
* app.register(fastifyMulter.contentParser);
|
|
67
61
|
* await app.listen(3000);
|
|
68
62
|
* }
|
|
69
63
|
* ```
|
|
@@ -74,19 +68,15 @@ const validate_request_form_data_1 = require("./internal/validate_request_form_d
|
|
|
74
68
|
var TypedFormData;
|
|
75
69
|
(function (TypedFormData) {
|
|
76
70
|
/**
|
|
77
|
-
*
|
|
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
|
|
71
|
+
* @internal
|
|
84
72
|
*/
|
|
85
|
-
function Body(props) {
|
|
73
|
+
function Body(options, props) {
|
|
86
74
|
if (typeof File === "undefined")
|
|
87
75
|
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
76
|
const checker = (0, validate_request_form_data_1.validate_request_form_data)(props);
|
|
89
|
-
const predicator = (type) => new Singleton_1.Singleton(() => type === "express"
|
|
77
|
+
const predicator = (type) => new Singleton_1.Singleton(() => type === "express"
|
|
78
|
+
? decodeExpress(options, props)
|
|
79
|
+
: decodeFastify(options, props));
|
|
90
80
|
return (0, common_1.createParamDecorator)(function TypedFormDataBody(_unknown, context) {
|
|
91
81
|
return __awaiter(this, void 0, void 0, function* () {
|
|
92
82
|
const http = context.switchToHttp();
|
|
@@ -112,8 +102,8 @@ var TypedFormData;
|
|
|
112
102
|
/**
|
|
113
103
|
* @internal
|
|
114
104
|
*/
|
|
115
|
-
const decodeExpress = (props) => {
|
|
116
|
-
const upload =
|
|
105
|
+
const decodeExpress = (options, props) => {
|
|
106
|
+
const upload = (0, multer_1.default)(options).fields(props.files.map((file) => (Object.assign({ name: file.name }, (file.limit === 1 ? { maxCount: 1 } : {})))));
|
|
117
107
|
const interceptor = (request, response) => new Promise((resolve, reject) => upload(request, response, (error) => {
|
|
118
108
|
if (error)
|
|
119
109
|
reject(error);
|
|
@@ -137,37 +127,32 @@ const decodeExpress = (props) => {
|
|
|
137
127
|
/**
|
|
138
128
|
* @internal
|
|
139
129
|
*/
|
|
140
|
-
const decodeFastify = (
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
130
|
+
const decodeFastify = (options, props) => {
|
|
131
|
+
const fastifyInstance = (0, fastify_multer_1.default)(options);
|
|
132
|
+
const upload = fastifyInstance.fields(props.files.map((file) => (Object.assign({ name: file.name }, (file.limit === 1 ? { maxCount: 1 } : {})))));
|
|
133
|
+
const interceptor = (request, response) => new Promise((resolve, reject) => upload.call(request.server, request, response, (error) => {
|
|
134
|
+
if (error)
|
|
135
|
+
reject(error);
|
|
136
|
+
else
|
|
137
|
+
resolve();
|
|
138
|
+
}));
|
|
139
|
+
return (socket) => __awaiter(void 0, void 0, void 0, function* () {
|
|
140
|
+
if (socket.request.files === undefined ||
|
|
141
|
+
(typeof socket.request).files !== "function")
|
|
142
|
+
throw new common_1.InternalServerErrorException("Have not configured the `fastify-multer` plugin yet. Inquiry to the backend developer.");
|
|
143
|
+
yield interceptor(socket.request, socket.response);
|
|
144
|
+
const data = new FormData();
|
|
145
|
+
for (const [key, value] of Object.entries(socket.request.body))
|
|
146
|
+
if (Array.isArray(value))
|
|
147
|
+
for (const elem of value)
|
|
148
|
+
data.append(key, String(elem));
|
|
158
149
|
else
|
|
159
|
-
data.append(
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
-
});
|
|
150
|
+
data.append(key, String(value));
|
|
151
|
+
if (socket.request.files)
|
|
152
|
+
parseFiles(data)(socket.request.files);
|
|
153
|
+
return data;
|
|
154
|
+
});
|
|
155
|
+
};
|
|
171
156
|
/**
|
|
172
157
|
* @internal
|
|
173
158
|
*/
|
|
@@ -196,8 +181,4 @@ const isMultipartFormData = (text) => text !== undefined &&
|
|
|
196
181
|
* @internal
|
|
197
182
|
*/
|
|
198
183
|
const isExpressRequest = (request) => request.app !== undefined;
|
|
199
|
-
/**
|
|
200
|
-
* @internal
|
|
201
|
-
*/
|
|
202
|
-
const multerApplication = new Singleton_1.Singleton(() => (0, multer_1.default)());
|
|
203
184
|
//# sourceMappingURL=TypedFormData.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypedFormData.js","sourceRoot":"","sources":["../../src/decorators/TypedFormData.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TypedFormData.js","sourceRoot":"","sources":["../../src/decorators/TypedFormData.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAKwB;AAIxB,oEAA2C;AAE3C,oDAAmC;AAGnC,kDAA+C;AAC/C,sFAAmF;AAEnF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,IAAiB,aAAa,CAuD7B;AAvDD,WAAiB,aAAa;IAc5B;;OAEG;IACH,SAAgB,IAAI,CAClB,OAAkE,EAClE,KAA4C;QAE5C,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;YAChB,CAAC,CAAC,aAAa,CAAC,OAA4C,EAAE,KAAM,CAAC;YACrE,CAAC,CAAC,aAAa,CAAC,OAA4C,EAAE,KAAM,CAAC,CACxE,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,MAA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B,CAAC,KAAoE,EAAE,EAAE;IACvE,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACtB,KAAK,MAAM,IAAI,IAAI,KAAK;YACtB,IAAI,CAAC,MAAM,CACT,IAAI,CAAC,SAAS,EACd,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE;gBACzC,IAAI,EAAE,IAAI,CAAC,QAAQ;aACpB,CAAC,CACH,CAAC;;QAEJ,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;YAC9C,KAAK,MAAM,IAAI,IAAI,KAAK;gBACtB,IAAI,CAAC,MAAM,CACT,GAAG,EACH,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE;oBACzC,IAAI,EAAE,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;AAElD;;GAEG;AACH,MAAM,gBAAgB,GAAG,CACvB,OAAyC,EACb,EAAE,CAAE,OAA2B,CAAC,GAAG,KAAK,SAAS,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
|
-
?
|
|
75
|
-
|
|
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,uCAAS,GAAG,CAAC,KAIzB,EAAgB,EAAE;;QACjB,MAAM;QACN,cAAc;QACd,MAAM;QACN,kBAAkB;QAClB,IAAI,CAAC,oBAAE,CAAC,gBAAgB,CAAC,KAAK,CAAC,SAAS,CAAC,UAAU,CAAC;YAClD,OAAO,KAAK,CAAC,SAAS,CAAC;QAEzB,wBAAwB;QACxB,MAAM,WAAW,GACf,MAAA,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,oBAAoB,CACxC,KAAK,CAAC,SAAS,CAAC,UAAU,CAC3B,0CAAE,WAAW,CAAC;QACjB,IAAI,WAAW,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC,SAAS,CAAC;QAEtD,YAAY;QACZ,MAAM,IAAI,GAAW,cAAI,CAAC,OAAO,C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
{"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,uCAAS,GAAG,CAAC,KAIzB,EAAgB,EAAE;;QACjB,MAAM;QACN,cAAc;QACd,MAAM;QACN,kBAAkB;QAClB,IAAI,CAAC,oBAAE,CAAC,gBAAgB,CAAC,KAAK,CAAC,SAAS,CAAC,UAAU,CAAC;YAClD,OAAO,KAAK,CAAC,SAAS,CAAC;QAEzB,wBAAwB;QACxB,MAAM,WAAW,GACf,MAAA,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,oBAAoB,CACxC,KAAK,CAAC,SAAS,CAAC,UAAU,CAC3B,0CAAE,WAAW,CAAC;QACjB,IAAI,WAAW,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC,SAAS,CAAC;QAEtD,YAAY;QACZ,MAAM,IAAI,GAAW,cAAI,CAAC,OAAO,CAAC,WAAW,CAAC,aAAa,EAAE,CAAC,QAAQ,CAAC,CAAC;QACxE,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAChE,OAAO,KAAK,CAAC,SAAS,CAAC;QAEzB,MAAM;QACN,iBAAiB;QACjB,MAAM;QACN,kBAAkB;QAClB,MAAM,UAAU,GACd,QAAQ,CACN,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CACrE,CAAC;QACJ,IAAI,UAAU,KAAK,SAAS;YAAE,OAAO,KAAK,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IAAY,EAAU,EAAE,CACvB,oBAAE,CAAC,aAAa,CAAC,IAAI,CAAC;IACpB,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAC7B,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,IAAI,IAAI,EAAE,CACnD;IACH,CAAC,CAAC,IAAI,CAAC"}
|
package/package.json
CHANGED
|
@@ -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-2",
|
|
4
4
|
"description": "Super-fast validation decorators of NestJS",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -36,11 +36,13 @@
|
|
|
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-2",
|
|
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
|
+
"@types/multer": "^1.4.11",
|
|
43
44
|
"detect-ts-node": "^1.0.5",
|
|
45
|
+
"fastify-multer": "^2.0.3",
|
|
44
46
|
"get-function-location": "^2.0.0",
|
|
45
47
|
"glob": "^7.2.0",
|
|
46
48
|
"multer": "1.4.5-lts.1",
|
|
@@ -49,11 +51,11 @@
|
|
|
49
51
|
"reflect-metadata": ">=0.1.12",
|
|
50
52
|
"rxjs": ">=6.0.3",
|
|
51
53
|
"tgrid": "^1.0.0",
|
|
52
|
-
"typia": "
|
|
54
|
+
"typia": ">=7.0.0-dev.20241027-2 <8.0.0",
|
|
53
55
|
"ws": "^7.5.3"
|
|
54
56
|
},
|
|
55
57
|
"peerDependencies": {
|
|
56
|
-
"@nestia/fetcher": ">=4.0.0-dev.20241027",
|
|
58
|
+
"@nestia/fetcher": ">=4.0.0-dev.20241027-2",
|
|
57
59
|
"@nestjs/common": ">=7.0.1",
|
|
58
60
|
"@nestjs/core": ">=7.0.1",
|
|
59
61
|
"reflect-metadata": ">=0.1.12",
|
|
@@ -61,13 +63,11 @@
|
|
|
61
63
|
"typia": ">=7.0.0-dev.20241027-2 <8.0.0"
|
|
62
64
|
},
|
|
63
65
|
"devDependencies": {
|
|
64
|
-
"@fastify/multipart": "^8.1.0",
|
|
65
66
|
"@nestjs/common": "^10.3.3",
|
|
66
67
|
"@nestjs/core": "^10.3.3",
|
|
67
68
|
"@types/express": "^4.17.15",
|
|
68
69
|
"@types/glob": "^7.2.0",
|
|
69
70
|
"@types/inquirer": "^9.0.3",
|
|
70
|
-
"@types/multer": "^1.4.11",
|
|
71
71
|
"@types/ts-expose-internals": "npm:ts-expose-internals@5.4.5",
|
|
72
72
|
"@types/ws": "^8.5.10",
|
|
73
73
|
"@typescript-eslint/eslint-plugin": "^5.46.1",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"commander": "^10.0.0",
|
|
76
76
|
"comment-json": "^4.2.3",
|
|
77
77
|
"eslint-plugin-deprecation": "^1.4.1",
|
|
78
|
-
"fastify": "^4.
|
|
78
|
+
"fastify": "^4.28.1",
|
|
79
79
|
"git-last-commit": "^1.0.1",
|
|
80
80
|
"inquirer": "^8.2.5",
|
|
81
81
|
"rimraf": "^3.0.2",
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Multipart } from "@fastify/multipart";
|
|
2
1
|
import {
|
|
3
2
|
BadRequestException,
|
|
4
3
|
ExecutionContext,
|
|
@@ -8,7 +7,9 @@ import {
|
|
|
8
7
|
import type { HttpArgumentsHost } from "@nestjs/common/interfaces";
|
|
9
8
|
import type express from "express";
|
|
10
9
|
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
11
|
-
import
|
|
10
|
+
import fastifyMulter from "fastify-multer";
|
|
11
|
+
import type * as FastifyMulter from "fastify-multer/lib/interfaces";
|
|
12
|
+
import ExpressMulter from "multer";
|
|
12
13
|
|
|
13
14
|
import type { IRequestFormDataProps } from "../options/IRequestFormDataProps";
|
|
14
15
|
import { Singleton } from "../utils/Singleton";
|
|
@@ -35,13 +36,13 @@ import { validate_request_form_data } from "./internal/validate_request_form_dat
|
|
|
35
36
|
* 3. Only `boolean`, `bigint`, `number`, `string`, `Blob`, `File` or their array types are allowed
|
|
36
37
|
* 4. By the way, union type never be not allowed
|
|
37
38
|
*
|
|
38
|
-
* By the way, if you're using `fastify`, you have to setup
|
|
39
|
+
* By the way, if you're using `fastify`, you have to setup `fastify-multer`
|
|
39
40
|
* and configure like below when composing the NestJS application. If you don't do
|
|
40
41
|
* that, `@TypedFormData.Body()` will not work properly, and throw 500 internal
|
|
41
42
|
* server error when `Blob` or `File` type being utilized.
|
|
42
43
|
*
|
|
43
44
|
* ```typescript
|
|
44
|
-
* import
|
|
45
|
+
* import fastifyMulter from "fastify-multer";
|
|
45
46
|
* import { NestFactory } from "@nestjs/core";
|
|
46
47
|
* import {
|
|
47
48
|
* FastifyAdapter,
|
|
@@ -53,7 +54,7 @@ import { validate_request_form_data } from "./internal/validate_request_form_dat
|
|
|
53
54
|
* AppModule,
|
|
54
55
|
* new FastifyAdapter(),
|
|
55
56
|
* );
|
|
56
|
-
* app.register(
|
|
57
|
+
* app.register(fastifyMulter.contentParser);
|
|
57
58
|
* await app.listen(3000);
|
|
58
59
|
* }
|
|
59
60
|
* ```
|
|
@@ -69,10 +70,18 @@ export namespace TypedFormData {
|
|
|
69
70
|
*
|
|
70
71
|
* Much easier and type safer than `@nest.UploadFile()` decorator.
|
|
71
72
|
*
|
|
72
|
-
* @param
|
|
73
|
+
* @param options Options for the `multer` or `fastify-multer`
|
|
74
|
+
*/
|
|
75
|
+
export function Body(
|
|
76
|
+
options?: ExpressMulter.Options | FastifyMulter.Options,
|
|
77
|
+
): ParameterDecorator;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @internal
|
|
73
81
|
*/
|
|
74
82
|
export function Body<T extends object>(
|
|
75
|
-
|
|
83
|
+
options: ExpressMulter.Options | FastifyMulter.Options | undefined,
|
|
84
|
+
props?: IRequestFormDataProps<T> | undefined,
|
|
76
85
|
): ParameterDecorator {
|
|
77
86
|
if (typeof File === "undefined")
|
|
78
87
|
throw new Error(
|
|
@@ -81,7 +90,9 @@ export namespace TypedFormData {
|
|
|
81
90
|
const checker = validate_request_form_data(props);
|
|
82
91
|
const predicator = (type: "express" | "fastify") =>
|
|
83
92
|
new Singleton(() =>
|
|
84
|
-
type === "express"
|
|
93
|
+
type === "express"
|
|
94
|
+
? decodeExpress(options as ExpressMulter.Options | undefined, props!)
|
|
95
|
+
: decodeFastify(options as FastifyMulter.Options | undefined, props!),
|
|
85
96
|
);
|
|
86
97
|
return createParamDecorator(async function TypedFormDataBody(
|
|
87
98
|
_unknown: any,
|
|
@@ -111,8 +122,11 @@ export namespace TypedFormData {
|
|
|
111
122
|
/**
|
|
112
123
|
* @internal
|
|
113
124
|
*/
|
|
114
|
-
const decodeExpress = <T>(
|
|
115
|
-
|
|
125
|
+
const decodeExpress = <T>(
|
|
126
|
+
options: ExpressMulter.Options | undefined,
|
|
127
|
+
props: IRequestFormDataProps<T>,
|
|
128
|
+
) => {
|
|
129
|
+
const upload = ExpressMulter(options).fields(
|
|
116
130
|
props!.files.map((file) => ({
|
|
117
131
|
name: file.name,
|
|
118
132
|
...(file.limit === 1 ? { maxCount: 1 } : {}),
|
|
@@ -144,36 +158,48 @@ const decodeExpress = <T>(props: IRequestFormDataProps<T>) => {
|
|
|
144
158
|
/**
|
|
145
159
|
* @internal
|
|
146
160
|
*/
|
|
147
|
-
const decodeFastify =
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
161
|
+
const decodeFastify = <T>(
|
|
162
|
+
options: FastifyMulter.Options | undefined,
|
|
163
|
+
props: IRequestFormDataProps<T>,
|
|
164
|
+
) => {
|
|
165
|
+
const fastifyInstance = fastifyMulter(options);
|
|
166
|
+
const upload = fastifyInstance.fields(
|
|
167
|
+
props!.files.map((file) => ({
|
|
168
|
+
name: file.name,
|
|
169
|
+
...(file.limit === 1 ? { maxCount: 1 } : {}),
|
|
170
|
+
})),
|
|
171
|
+
);
|
|
172
|
+
const interceptor = (request: FastifyRequest, response: FastifyReply) =>
|
|
173
|
+
new Promise<void>((resolve, reject) =>
|
|
174
|
+
upload.call(request.server, request, response, (error) => {
|
|
175
|
+
if (error) reject(error);
|
|
176
|
+
else resolve();
|
|
177
|
+
}),
|
|
178
|
+
);
|
|
179
|
+
return async (socket: {
|
|
180
|
+
request: FastifyRequest;
|
|
153
181
|
response: FastifyReply;
|
|
154
182
|
}): Promise<FormData> => {
|
|
155
183
|
if (
|
|
156
|
-
socket.request.files === undefined ||
|
|
157
|
-
typeof socket.request.files !== "function"
|
|
184
|
+
(socket.request as any).files === undefined ||
|
|
185
|
+
(typeof socket.request as any).files !== "function"
|
|
158
186
|
)
|
|
159
187
|
throw new InternalServerErrorException(
|
|
160
|
-
"Have not configured the `fastify-
|
|
188
|
+
"Have not configured the `fastify-multer` plugin yet. Inquiry to the backend developer.",
|
|
161
189
|
);
|
|
190
|
+
|
|
191
|
+
await interceptor(socket.request, socket.response);
|
|
192
|
+
|
|
162
193
|
const data: FormData = new FormData();
|
|
163
|
-
for
|
|
164
|
-
if (
|
|
165
|
-
data.append(
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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));
|
|
194
|
+
for (const [key, value] of Object.entries(socket.request.body as any))
|
|
195
|
+
if (Array.isArray(value))
|
|
196
|
+
for (const elem of value) data.append(key, String(elem));
|
|
197
|
+
else data.append(key, String(value));
|
|
198
|
+
if ((socket.request as any).files)
|
|
199
|
+
parseFiles(data)((socket.request as any).files);
|
|
175
200
|
return data;
|
|
176
201
|
};
|
|
202
|
+
};
|
|
177
203
|
|
|
178
204
|
/**
|
|
179
205
|
* @internal
|
|
@@ -216,8 +242,3 @@ const isMultipartFormData = (text?: string): boolean =>
|
|
|
216
242
|
const isExpressRequest = (
|
|
217
243
|
request: express.Request | FastifyRequest,
|
|
218
244
|
): 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
|
-
?
|
|
105
|
-
|
|
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
|