@nestia/core 2.5.1 → 2.5.2-dev.20240204
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/TypedMultipart.d.ts +45 -0
- package/lib/decorators/TypedMultipart.js +257 -0
- package/lib/decorators/TypedMultipart.js.map +1 -0
- package/lib/decorators/TypedQuery.d.ts +6 -1
- package/lib/decorators/TypedQuery.js +6 -1
- package/lib/decorators/TypedQuery.js.map +1 -1
- package/lib/decorators/internal/validate_request_multipart.d.ts +3 -0
- package/lib/decorators/internal/validate_request_multipart.js +64 -0
- package/lib/decorators/internal/validate_request_multipart.js.map +1 -0
- package/lib/module.d.ts +1 -0
- package/lib/module.js +1 -0
- package/lib/module.js.map +1 -1
- package/lib/options/IRequestMulltipartProps.d.ts +23 -0
- package/lib/options/IRequestMulltipartProps.js +3 -0
- package/lib/options/IRequestMulltipartProps.js.map +1 -0
- package/lib/programmers/PlainBodyProgrammer.js +1 -1
- package/lib/programmers/PlainBodyProgrammer.js.map +1 -1
- package/lib/programmers/TypedExceptionProgrammer.js +2 -2
- package/lib/programmers/TypedExceptionProgrammer.js.map +1 -1
- package/lib/programmers/TypedMultipartBodyProgrammer.d.ts +6 -0
- package/lib/programmers/TypedMultipartBodyProgrammer.js +84 -0
- package/lib/programmers/TypedMultipartBodyProgrammer.js.map +1 -0
- package/lib/programmers/http/HttpQuerifyProgrammer.js +1 -1
- package/lib/programmers/http/HttpQuerifyProgrammer.js.map +1 -1
- package/lib/transformers/ParameterDecoratorTransformer.js +6 -0
- package/lib/transformers/ParameterDecoratorTransformer.js.map +1 -1
- package/package.json +7 -5
- package/src/decorators/TypedMultipart.ts +146 -0
- package/src/decorators/TypedQuery.ts +6 -1
- package/src/decorators/internal/validate_request_multipart.ts +60 -0
- package/src/module.ts +1 -0
- package/src/options/IRequestMulltipartProps.ts +27 -0
- package/src/programmers/PlainBodyProgrammer.ts +1 -1
- package/src/programmers/TypedExceptionProgrammer.ts +2 -2
- package/src/programmers/TypedMultipartBodyProgrammer.ts +108 -0
- package/src/programmers/http/HttpQuerifyProgrammer.ts +1 -1
- package/src/transformers/ParameterDecoratorTransformer.ts +5 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { IRequestMultipartProps } from "../options/IRequestMulltipartProps";
|
|
2
|
+
/**
|
|
3
|
+
* Type safe multipart/form-data decorator.
|
|
4
|
+
*
|
|
5
|
+
* `TypedMultipart.Body()` is a request body decorator function for the
|
|
6
|
+
* `multipart/form-data` content type. It automatically casts property type
|
|
7
|
+
* following its DTO definition, and performs the type validation too.
|
|
8
|
+
*
|
|
9
|
+
* Also, `TypedMultipart.Body()` is much easier and type safer than `@nest.UploadFile()`.
|
|
10
|
+
* If you're considering the [SDK library](https://nestia.io/docs/sdk/sdk) generation,
|
|
11
|
+
* only `TypedMultipart.Body()` can do it. Therefore, I recommend you to use
|
|
12
|
+
* `TypedMultipart.Body()` instead of the `@nest.UploadFile()` function.
|
|
13
|
+
*
|
|
14
|
+
* For reference, target type `T` must follow such restriction. Of course, if actual
|
|
15
|
+
* form-data values are different with their promised type `T`,
|
|
16
|
+
* `BadRequestException` error (status code: 400) would be thrown.
|
|
17
|
+
*
|
|
18
|
+
* 1. Type `T` must be an object type
|
|
19
|
+
* 2. Do not allow dynamic property
|
|
20
|
+
* 3. Only `boolean`, `bigint`, `number`, `string`, `Blob`, `File` or their array types are allowed
|
|
21
|
+
* 4. By the way, union type never be not allowed
|
|
22
|
+
* 5. Supports only Express, not Fastify
|
|
23
|
+
*
|
|
24
|
+
* @todo Change to ReadableStream through configuring storage engine of multer
|
|
25
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
26
|
+
*/
|
|
27
|
+
export declare namespace TypedMultipart {
|
|
28
|
+
/**
|
|
29
|
+
* Request body decorator.
|
|
30
|
+
*
|
|
31
|
+
* Request body decorator for the `multipart/form-data` type.
|
|
32
|
+
*
|
|
33
|
+
* Much easier and type safer than `@nest.UploadFile()` decorator.
|
|
34
|
+
*
|
|
35
|
+
* @param props Automatically filled by transformer
|
|
36
|
+
*/
|
|
37
|
+
function Body<T extends object>(props?: IRequestMultipartProps<T>): ParameterDecorator;
|
|
38
|
+
interface IProps<T> {
|
|
39
|
+
files: Array<{
|
|
40
|
+
name: string;
|
|
41
|
+
limit: number | null;
|
|
42
|
+
}>;
|
|
43
|
+
validator: IRequestMultipartProps<T>;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __values = (this && this.__values) || function(o) {
|
|
50
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
51
|
+
if (m) return m.call(o);
|
|
52
|
+
if (o && typeof o.length === "number") return {
|
|
53
|
+
next: function () {
|
|
54
|
+
if (o && i >= o.length) o = void 0;
|
|
55
|
+
return { value: o && o[i++], done: !o };
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
59
|
+
};
|
|
60
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
61
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
62
|
+
if (!m) return o;
|
|
63
|
+
var i = m.call(o), r, ar = [], e;
|
|
64
|
+
try {
|
|
65
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
66
|
+
}
|
|
67
|
+
catch (error) { e = { error: error }; }
|
|
68
|
+
finally {
|
|
69
|
+
try {
|
|
70
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
71
|
+
}
|
|
72
|
+
finally { if (e) throw e.error; }
|
|
73
|
+
}
|
|
74
|
+
return ar;
|
|
75
|
+
};
|
|
76
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
77
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
78
|
+
};
|
|
79
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
80
|
+
exports.TypedMultipart = void 0;
|
|
81
|
+
var common_1 = require("@nestjs/common");
|
|
82
|
+
var multer_1 = __importDefault(require("multer"));
|
|
83
|
+
var typia_1 = __importDefault(require("typia"));
|
|
84
|
+
var Singleton_1 = require("../utils/Singleton");
|
|
85
|
+
var validate_request_multipart_1 = require("./internal/validate_request_multipart");
|
|
86
|
+
/**
|
|
87
|
+
* Type safe multipart/form-data decorator.
|
|
88
|
+
*
|
|
89
|
+
* `TypedMultipart.Body()` is a request body decorator function for the
|
|
90
|
+
* `multipart/form-data` content type. It automatically casts property type
|
|
91
|
+
* following its DTO definition, and performs the type validation too.
|
|
92
|
+
*
|
|
93
|
+
* Also, `TypedMultipart.Body()` is much easier and type safer than `@nest.UploadFile()`.
|
|
94
|
+
* If you're considering the [SDK library](https://nestia.io/docs/sdk/sdk) generation,
|
|
95
|
+
* only `TypedMultipart.Body()` can do it. Therefore, I recommend you to use
|
|
96
|
+
* `TypedMultipart.Body()` instead of the `@nest.UploadFile()` function.
|
|
97
|
+
*
|
|
98
|
+
* For reference, target type `T` must follow such restriction. Of course, if actual
|
|
99
|
+
* form-data values are different with their promised type `T`,
|
|
100
|
+
* `BadRequestException` error (status code: 400) would be thrown.
|
|
101
|
+
*
|
|
102
|
+
* 1. Type `T` must be an object type
|
|
103
|
+
* 2. Do not allow dynamic property
|
|
104
|
+
* 3. Only `boolean`, `bigint`, `number`, `string`, `Blob`, `File` or their array types are allowed
|
|
105
|
+
* 4. By the way, union type never be not allowed
|
|
106
|
+
* 5. Supports only Express, not Fastify
|
|
107
|
+
*
|
|
108
|
+
* @todo Change to ReadableStream through configuring storage engine of multer
|
|
109
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
110
|
+
*/
|
|
111
|
+
var TypedMultipart;
|
|
112
|
+
(function (TypedMultipart) {
|
|
113
|
+
/**
|
|
114
|
+
* Request body decorator.
|
|
115
|
+
*
|
|
116
|
+
* Request body decorator for the `multipart/form-data` type.
|
|
117
|
+
*
|
|
118
|
+
* Much easier and type safer than `@nest.UploadFile()` decorator.
|
|
119
|
+
*
|
|
120
|
+
* @param props Automatically filled by transformer
|
|
121
|
+
*/
|
|
122
|
+
function Body(props) {
|
|
123
|
+
var checker = (0, validate_request_multipart_1.validate_request_multipart)(props);
|
|
124
|
+
var upload = app.get().fields(props.files.map(function (file) { return (__assign({ name: file.name }, (file.limit === 1 ? { maxCount: 1 } : {}))); }));
|
|
125
|
+
var interceptor = function (request, response) {
|
|
126
|
+
return new Promise(function (resolve, reject) {
|
|
127
|
+
return upload(request, response, function (error) {
|
|
128
|
+
if (error)
|
|
129
|
+
reject(error);
|
|
130
|
+
else
|
|
131
|
+
resolve();
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
return (0, common_1.createParamDecorator)(function TypedMultipartBody(_unknown, context) {
|
|
136
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
137
|
+
var http, request, data, _a, _b, _c, key, value, _d, _e, elem, output;
|
|
138
|
+
var e_1, _f, e_2, _g;
|
|
139
|
+
return __generator(this, function (_h) {
|
|
140
|
+
switch (_h.label) {
|
|
141
|
+
case 0:
|
|
142
|
+
http = context.switchToHttp();
|
|
143
|
+
request = http.getRequest();
|
|
144
|
+
if (isMultipartFormData(request.headers["content-type"]) === false)
|
|
145
|
+
throw new common_1.BadRequestException("Request body type is not \"application/x-www-form-urlencoded\".");
|
|
146
|
+
return [4 /*yield*/, interceptor(request, http.getResponse())];
|
|
147
|
+
case 1:
|
|
148
|
+
_h.sent();
|
|
149
|
+
data = new FormData();
|
|
150
|
+
try {
|
|
151
|
+
for (_a = __values(Object.entries(request.body)), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
152
|
+
_c = __read(_b.value, 2), key = _c[0], value = _c[1];
|
|
153
|
+
try {
|
|
154
|
+
for (_d = (e_2 = void 0, __values(String(value).split(","))), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
155
|
+
elem = _e.value;
|
|
156
|
+
data.append(key, elem);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
160
|
+
finally {
|
|
161
|
+
try {
|
|
162
|
+
if (_e && !_e.done && (_g = _d.return)) _g.call(_d);
|
|
163
|
+
}
|
|
164
|
+
finally { if (e_2) throw e_2.error; }
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
169
|
+
finally {
|
|
170
|
+
try {
|
|
171
|
+
if (_b && !_b.done && (_f = _a.return)) _f.call(_a);
|
|
172
|
+
}
|
|
173
|
+
finally { if (e_1) throw e_1.error; }
|
|
174
|
+
}
|
|
175
|
+
if (request.files)
|
|
176
|
+
parseFiles(data)(request.files);
|
|
177
|
+
output = checker(data);
|
|
178
|
+
if (output instanceof Error)
|
|
179
|
+
throw output;
|
|
180
|
+
return [2 /*return*/, output];
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
})();
|
|
185
|
+
}
|
|
186
|
+
TypedMultipart.Body = Body;
|
|
187
|
+
Object.assign(Body, typia_1.default.http.assertFormData);
|
|
188
|
+
Object.assign(Body, typia_1.default.http.isFormData);
|
|
189
|
+
Object.assign(Body, typia_1.default.http.validateFormData);
|
|
190
|
+
})(TypedMultipart || (exports.TypedMultipart = TypedMultipart = {}));
|
|
191
|
+
/**
|
|
192
|
+
* @internal
|
|
193
|
+
*/
|
|
194
|
+
var parseFiles = function (data) {
|
|
195
|
+
return function (files) {
|
|
196
|
+
var e_3, _a, e_4, _b, e_5, _c;
|
|
197
|
+
if (Array.isArray(files))
|
|
198
|
+
try {
|
|
199
|
+
for (var files_1 = __values(files), files_1_1 = files_1.next(); !files_1_1.done; files_1_1 = files_1.next()) {
|
|
200
|
+
var file = files_1_1.value;
|
|
201
|
+
data.append(file.fieldname, new File([file.buffer], file.originalname, {
|
|
202
|
+
type: file.mimetype,
|
|
203
|
+
}));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
207
|
+
finally {
|
|
208
|
+
try {
|
|
209
|
+
if (files_1_1 && !files_1_1.done && (_a = files_1.return)) _a.call(files_1);
|
|
210
|
+
}
|
|
211
|
+
finally { if (e_3) throw e_3.error; }
|
|
212
|
+
}
|
|
213
|
+
else
|
|
214
|
+
try {
|
|
215
|
+
for (var _d = __values(Object.entries(files)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
216
|
+
var _f = __read(_e.value, 2), key = _f[0], value = _f[1];
|
|
217
|
+
try {
|
|
218
|
+
for (var value_1 = (e_5 = void 0, __values(value)), value_1_1 = value_1.next(); !value_1_1.done; value_1_1 = value_1.next()) {
|
|
219
|
+
var file = value_1_1.value;
|
|
220
|
+
data.append(key, new File([file.buffer], file.originalname, {
|
|
221
|
+
type: file.mimetype,
|
|
222
|
+
}));
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
226
|
+
finally {
|
|
227
|
+
try {
|
|
228
|
+
if (value_1_1 && !value_1_1.done && (_c = value_1.return)) _c.call(value_1);
|
|
229
|
+
}
|
|
230
|
+
finally { if (e_5) throw e_5.error; }
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
235
|
+
finally {
|
|
236
|
+
try {
|
|
237
|
+
if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
|
|
238
|
+
}
|
|
239
|
+
finally { if (e_4) throw e_4.error; }
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
};
|
|
243
|
+
/**
|
|
244
|
+
* @internal
|
|
245
|
+
*/
|
|
246
|
+
function isMultipartFormData(text) {
|
|
247
|
+
return (text !== undefined &&
|
|
248
|
+
text
|
|
249
|
+
.split(";")
|
|
250
|
+
.map(function (str) { return str.trim(); })
|
|
251
|
+
.some(function (str) { return str === "multipart/form-data"; }));
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* @internal
|
|
255
|
+
*/
|
|
256
|
+
var app = new Singleton_1.Singleton(function () { return (0, multer_1.default)(); });
|
|
257
|
+
//# sourceMappingURL=TypedMultipart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypedMultipart.js","sourceRoot":"","sources":["../../src/decorators/TypedMultipart.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAIwB;AAGxB,kDAA4B;AAC5B,gDAA0B;AAG1B,gDAA+C;AAC/C,oFAAmF;AAEnF;;;;;;;;;;;;;;;;;;;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EACd,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE;wBACzC,IAAI,EAAE,IAAI,CAAC,QAAQ;qBACpB,CAAC,CACH,CAAC;iBAAA;;;;;;;;;;;gBAEJ,KAA2B,IAAA,KAAA,SAAA,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA,gBAAA;oBAArC,IAAA,KAAA,mBAAY,EAAX,GAAG,QAAA,EAAE,KAAK,QAAA;;wBACpB,KAAmB,IAAA,yBAAA,SAAA,KAAK,CAAA,CAAA,4BAAA;4BAAnB,IAAM,IAAI,kBAAA;4BACb,IAAI,CAAC,MAAM,CACT,GAAG,EACH,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE;gCACzC,IAAI,EAAE,IAAI,CAAC,QAAQ;6BACpB,CAAC,CACH,CAAC;yBAAA;;;;;;;;;iBAAA;;;;;;;;aAAA;IACV,CAAC;AAlBD,CAkBC,CAAC;AAEJ;;GAEG;AACH,SAAS,mBAAmB,CAAC,IAAa;IACxC,OAAO,CACL,IAAI,KAAK,SAAS;QAClB,IAAI;aACD,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,UAAC,GAAG,IAAK,OAAA,GAAG,CAAC,IAAI,EAAE,EAAV,CAAU,CAAC;aACxB,IAAI,CAAC,UAAC,GAAG,IAAK,OAAA,GAAG,KAAK,qBAAqB,EAA7B,CAA6B,CAAC,CAChD,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,IAAM,GAAG,GAAG,IAAI,qBAAS,CAAC,cAAM,OAAA,IAAA,gBAAM,GAAE,EAAR,CAAQ,CAAC,CAAC"}
|
|
@@ -7,7 +7,7 @@ import { IResponseBodyQuerifier } from "../options/IResponseBodyQuerifier";
|
|
|
7
7
|
* same with {@link nest.Query}, but it can automatically cast property type following
|
|
8
8
|
* its DTO definition. Also, `TypedQuery` performs type validation.
|
|
9
9
|
*
|
|
10
|
-
* For reference, target type `T` must
|
|
10
|
+
* For reference, target type `T` must follow such restriction. Also, if actual URL
|
|
11
11
|
* query parameter values are different with their promised type `T`,
|
|
12
12
|
* `BadRequestException` error (status code: 400) would be thrown.
|
|
13
13
|
*
|
|
@@ -21,6 +21,11 @@ import { IResponseBodyQuerifier } from "../options/IResponseBodyQuerifier";
|
|
|
21
21
|
*/
|
|
22
22
|
export declare function TypedQuery<T extends object>(validator?: IRequestQueryValidator<T>): ParameterDecorator;
|
|
23
23
|
export declare namespace TypedQuery {
|
|
24
|
+
/**
|
|
25
|
+
* Request body decorator.
|
|
26
|
+
*
|
|
27
|
+
* Request body decorator for the `application/x-www-form-urlencoded` type.
|
|
28
|
+
*/
|
|
24
29
|
function Body<T extends object>(validator?: IRequestQueryValidator<T>): ParameterDecorator;
|
|
25
30
|
/**
|
|
26
31
|
* Router decorator function for the GET method.
|
|
@@ -53,7 +53,7 @@ var validate_request_query_1 = require("./internal/validate_request_query");
|
|
|
53
53
|
* same with {@link nest.Query}, but it can automatically cast property type following
|
|
54
54
|
* its DTO definition. Also, `TypedQuery` performs type validation.
|
|
55
55
|
*
|
|
56
|
-
* For reference, target type `T` must
|
|
56
|
+
* For reference, target type `T` must follow such restriction. Also, if actual URL
|
|
57
57
|
* query parameter values are different with their promised type `T`,
|
|
58
58
|
* `BadRequestException` error (status code: 400) would be thrown.
|
|
59
59
|
*
|
|
@@ -81,6 +81,11 @@ function TypedQuery(validator) {
|
|
|
81
81
|
exports.TypedQuery = TypedQuery;
|
|
82
82
|
(function (TypedQuery) {
|
|
83
83
|
var e_1, _a, e_2, _b, e_3, _c;
|
|
84
|
+
/**
|
|
85
|
+
* Request body decorator.
|
|
86
|
+
*
|
|
87
|
+
* Request body decorator for the `application/x-www-form-urlencoded` type.
|
|
88
|
+
*/
|
|
84
89
|
function Body(validator) {
|
|
85
90
|
var checker = (0, validate_request_query_1.validate_request_query)(validator);
|
|
86
91
|
return (0, common_1.createParamDecorator)(function TypedQueryBody(_unknown, context) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypedQuery.js","sourceRoot":"","sources":["../../src/decorators/TypedQuery.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAawB;AAIxB,6BAAuC;AACvC,gDAA0B;AAI1B,wEAAuE;AACvE,sDAAqD;AACrD,4EAA2E;AAE3E;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,UAAU,CACxB,SAAqC;IAErC,IAAM,OAAO,GAAG,IAAA,+CAAsB,EAAC,SAAS,CAAC,CAAC;IAClD,OAAO,IAAA,6BAAoB,EAAC,SAAS,UAAU,CAC7C,QAAa,EACb,OAAyB;QAEzB,IAAM,OAAO,GAAqC,OAAO;aACtD,YAAY,EAAE;aACd,UAAU,EAAE,CAAC;QAChB,IAAM,MAAM,GAAoB,IAAI,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;QAEvE,IAAM,MAAM,GAAc,OAAO,CAAC,MAAM,CAAC,CAAC;QAC1C,IAAI,MAAM,YAAY,KAAK;YAAE,MAAM,MAAM,CAAC;QAC1C,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC,EAAE,CAAC;AACP,CAAC;AAjBD,gCAiBC;AACD,WAAiB,UAAU;;IACzB,SAAgB,IAAI,CAClB,SAAqC;QAErC,IAAM,OAAO,GAAG,IAAA,+CAAsB,EAAC,SAAS,CAAC,CAAC;QAClD,OAAO,IAAA,6BAAoB,EAAC,SAAS,cAAc,CACjD,QAAa,EACb,OAAyB;YAEzB,IAAM,OAAO,GAAqC,OAAO;iBACtD,YAAY,EAAE;iBACd,UAAU,EAAE,CAAC;YAChB,IAAI,kBAAkB,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,KAAK,KAAK;gBAC/D,MAAM,IAAI,4BAAmB,CAC3B,iEAA+D,CAChE,CAAC;YACJ,IAA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C,EACrD,IAAA,iBAAU,EAAC,UAAC,GAAG,IAAK,OAAA,IAAA,yBAAW,EAAC,IAAI,CAAC,UAAU,EAAE,EAAE,GAAG,CAAC,EAAnC,CAAmC,CAAC,CACzD,CAAC;IACJ,CAAC;IACH,iCAAC;AAAD,CAAC,AAfD,IAeC;AAED;;GAEG;AACH,IAAM,OAAO,GAAG;IACd,GAAG,cAAA;IACH,IAAI,eAAA;IACJ,KAAK,gBAAA;IACL,GAAG,cAAA;IACH,MAAM,iBAAA;CACP,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { BadRequestException } from "@nestjs/common";
|
|
2
|
+
import { IRequestMultipartProps } from "../../options/IRequestMulltipartProps";
|
|
3
|
+
export declare const validate_request_multipart: <T>(props?: IRequestMultipartProps<T> | undefined) => (() => Error) | ((input: FormData) => BadRequestException | T);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.validate_request_multipart = void 0;
|
|
7
|
+
var common_1 = require("@nestjs/common");
|
|
8
|
+
var typia_1 = __importDefault(require("typia"));
|
|
9
|
+
var NoTransformConfigureError_1 = require("./NoTransformConfigureError");
|
|
10
|
+
var validate_request_multipart = function (props) {
|
|
11
|
+
if (!props)
|
|
12
|
+
return function () { return (0, NoTransformConfigureError_1.NoTransformConfigureError)("TypedMultipart.Bpdu"); };
|
|
13
|
+
else if (props.validator.type === "assert")
|
|
14
|
+
return assert(props.validator.assert);
|
|
15
|
+
else if (props.validator.type === "is")
|
|
16
|
+
return is(props.validator.is);
|
|
17
|
+
else if (props.validator.type === "validate")
|
|
18
|
+
return validate(props.validator.validate);
|
|
19
|
+
return function () {
|
|
20
|
+
return new Error("Error on nestia.core.TypedMultipart.Body(): invalid typed validator.");
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
exports.validate_request_multipart = validate_request_multipart;
|
|
24
|
+
var assert = function (closure) {
|
|
25
|
+
return function (input) {
|
|
26
|
+
try {
|
|
27
|
+
return closure(input);
|
|
28
|
+
}
|
|
29
|
+
catch (exp) {
|
|
30
|
+
if ((function (input) {
|
|
31
|
+
var $io0 = function (input) { return "string" === typeof input.method && (undefined === input.path || "string" === typeof input.path) && "string" === typeof input.expected && true && "string" === typeof input.name && "string" === typeof input.message && (undefined === input.stack || "string" === typeof input.stack); };
|
|
32
|
+
return "object" === typeof input && null !== input && $io0(input);
|
|
33
|
+
})(exp)) {
|
|
34
|
+
return new common_1.BadRequestException({
|
|
35
|
+
path: exp.path,
|
|
36
|
+
reason: exp.message,
|
|
37
|
+
expected: exp.expected,
|
|
38
|
+
value: exp.value,
|
|
39
|
+
message: MESSAGE,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
throw exp;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
var is = function (closure) {
|
|
47
|
+
return function (input) {
|
|
48
|
+
var result = closure(input);
|
|
49
|
+
return result !== null ? result : new common_1.BadRequestException(MESSAGE);
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
var validate = function (closure) {
|
|
53
|
+
return function (input) {
|
|
54
|
+
var result = closure(input);
|
|
55
|
+
return result.success
|
|
56
|
+
? result.data
|
|
57
|
+
: new common_1.BadRequestException({
|
|
58
|
+
errors: result.errors,
|
|
59
|
+
message: MESSAGE,
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
var MESSAGE = "Request multipart data is not following the promised type.";
|
|
64
|
+
//# sourceMappingURL=validate_request_multipart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate_request_multipart.js","sourceRoot":"","sources":["../../../src/decorators/internal/validate_request_multipart.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAq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MAAM,GAAa,OAAO,CAAC,KAAK,CAAC,CAAC;QACxC,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,4BAAmB,CAAC,OAAO,CAAC,CAAC;IACrE,CAAC;AAHD,CAGC,CAAC;AAEJ,IAAM,QAAQ,GACZ,UAAI,OAA4C;IAChD,OAAA,UAAC,KAAe;QACd,IAAM,MAAM,GAAmB,OAAO,CAAC,KAAK,CAAC,CAAC;QAC9C,OAAO,MAAM,CAAC,OAAO;YACnB,CAAC,CAAC,MAAM,CAAC,IAAI;YACb,CAAC,CAAC,IAAI,4BAAmB,CAAC;gBACtB,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,OAAO,EAAE,OAAO;aACjB,CAAC,CAAC;IACT,CAAC;AARD,CAQC,CAAC;AAEJ,IAAM,OAAO,GAAG,4DAA4D,CAAC"}
|
package/lib/module.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from "./decorators/PlainBody";
|
|
|
8
8
|
export * from "./decorators/TypedBody";
|
|
9
9
|
export * from "./decorators/TypedException";
|
|
10
10
|
export * from "./decorators/TypedHeaders";
|
|
11
|
+
export * from "./decorators/TypedMultipart";
|
|
11
12
|
export * from "./decorators/TypedParam";
|
|
12
13
|
export * from "./decorators/TypedRoute";
|
|
13
14
|
export * from "./decorators/TypedQuery";
|
package/lib/module.js
CHANGED
|
@@ -24,6 +24,7 @@ __exportStar(require("./decorators/PlainBody"), exports);
|
|
|
24
24
|
__exportStar(require("./decorators/TypedBody"), exports);
|
|
25
25
|
__exportStar(require("./decorators/TypedException"), exports);
|
|
26
26
|
__exportStar(require("./decorators/TypedHeaders"), exports);
|
|
27
|
+
__exportStar(require("./decorators/TypedMultipart"), exports);
|
|
27
28
|
__exportStar(require("./decorators/TypedParam"), exports);
|
|
28
29
|
__exportStar(require("./decorators/TypedRoute"), exports);
|
|
29
30
|
__exportStar(require("./decorators/TypedQuery"), exports);
|
package/lib/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.js","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6DAA2C;AAC3C,6DAA2C;AAC3C,mEAAiD;AACjD,+DAA6C;AAC7C,8DAA4C;AAC5C,2DAAyC;AACzC,yDAAuC;AACvC,yDAAuC;AACvC,8DAA4C;AAC5C,4DAA0C;AAC1C,0DAAwC;AACxC,0DAAwC;AACxC,0DAAwC;AACxC,oEAAkD"}
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6DAA2C;AAC3C,6DAA2C;AAC3C,mEAAiD;AACjD,+DAA6C;AAC7C,8DAA4C;AAC5C,2DAAyC;AACzC,yDAAuC;AACvC,yDAAuC;AACvC,8DAA4C;AAC5C,4DAA0C;AAC1C,8DAA4C;AAC5C,0DAAwC;AACxC,0DAAwC;AACxC,0DAAwC;AACxC,oEAAkD"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IValidation } from "typia";
|
|
2
|
+
export interface IRequestMultipartProps<T> {
|
|
3
|
+
files: Array<IRequestMultipartProps.IFile>;
|
|
4
|
+
validator: IRequestMultipartProps.IAssert<T> | IRequestMultipartProps.IIs<T> | IRequestMultipartProps.IValidate<T>;
|
|
5
|
+
}
|
|
6
|
+
export declare namespace IRequestMultipartProps {
|
|
7
|
+
interface IAssert<T> {
|
|
8
|
+
type: "assert";
|
|
9
|
+
assert: (input: FormData) => T;
|
|
10
|
+
}
|
|
11
|
+
interface IIs<T> {
|
|
12
|
+
type: "is";
|
|
13
|
+
is: (input: FormData) => T | null;
|
|
14
|
+
}
|
|
15
|
+
interface IValidate<T> {
|
|
16
|
+
type: "validate";
|
|
17
|
+
validate: (input: FormData) => IValidation<T>;
|
|
18
|
+
}
|
|
19
|
+
interface IFile {
|
|
20
|
+
name: string;
|
|
21
|
+
limit: number | null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IRequestMulltipartProps.js","sourceRoot":"","sources":["../../src/options/IRequestMulltipartProps.ts"],"names":[],"mappings":""}
|
|
@@ -28,7 +28,7 @@ var PlainBodyProgrammer;
|
|
|
28
28
|
validate: validate,
|
|
29
29
|
})(new MetadataCollection_1.MetadataCollection())(type);
|
|
30
30
|
if (result.success === false)
|
|
31
|
-
throw TransformerError_1.TransformerError.from("
|
|
31
|
+
throw TransformerError_1.TransformerError.from("nestia.core.TypedParam")(result.errors);
|
|
32
32
|
return AssertProgrammer_1.AssertProgrammer.write(__assign(__assign({}, project), { options: {
|
|
33
33
|
numeric: false,
|
|
34
34
|
finite: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlainBodyProgrammer.js","sourceRoot":"","sources":["../../src/programmers/PlainBodyProgrammer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,6EAA4E;AAC5E,uEAAsE;AACtE,2EAA0E;AAE1E,4EAA2E;AAI3E,IAAiB,mBAAmB,CAsBnC;AAtBD,WAAiB,mBAAmB;IACrB,4BAAQ,GACnB,UAAC,OAAgC;QACjC,OAAA,UAAC,MAAiC;YAClC,OAAA,UAAC,IAAa;gBACZ,IAAM,MAAM,GAAG,iCAAe,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;oBACtD,MAAM,EAAE,KAAK;oBACb,QAAQ,EAAE,IAAI;oBACd,MAAM,EAAE,IAAI;oBACZ,QAAQ,UAAA;iBACT,CAAC,CAAC,IAAI,uCAAkB,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;gBACnC,IAAI,MAAM,CAAC,OAAO,KAAK,KAAK;oBAC1B,MAAM,mCAAgB,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"PlainBodyProgrammer.js","sourceRoot":"","sources":["../../src/programmers/PlainBodyProgrammer.ts"],"names":[],"mappings":";;;;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,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3D,QAAQ,CAAC,SAAS,CAAC,MAAM;QACzB,QAAQ,CAAC,SAAS;aACf,MAAM,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,IAAI,KAAK,QAAQ,EAAnB,CAAmB,CAAC;aAClC,GAAG,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,MAAM,CAAC,MAAM,EAAf,CAAe,CAAC;aAC3B,MAAM,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CAAC,GAAG,CAAC,EAAL,CAAK,EAAE,CAAC,CAAC,CAAC;IAChC,IAAI,QAAQ,KAAK,CAAC,IAAI,QAAQ,KAAK,QAAQ,CAAC,IAAI,EAAE;QAChD,MAAM,CAAC,6BAA6B,CAAC,CAAC;IACxC,IAAI,QAAQ,CAAC,UAAU,EAAE,KAAK,KAAK;QAAE,MAAM,CAAC,gCAAgC,CAAC,CAAC;IAC9E,IAAI,QAAQ,CAAC,QAAQ,KAAK,IAAI;QAAE,MAAM,CAAC,4BAA4B,CAAC,CAAC;SAChE,IAAI,QAAQ,CAAC,GAAG,KAAK,IAAI;QAAE,MAAM,CAAC,uBAAuB,CAAC,CAAC;IAEhE,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
|
@@ -16,7 +16,7 @@ var TypedExceptionProgrammer;
|
|
|
16
16
|
var _a, _b;
|
|
17
17
|
// CHECK GENERIC ARGUMENT EXISTENCE
|
|
18
18
|
if (!((_a = expression.typeArguments) === null || _a === void 0 ? void 0 : _a[0]))
|
|
19
|
-
throw TransformerError_1.TransformerError.from("
|
|
19
|
+
throw TransformerError_1.TransformerError.from("nestia.core.TypedException")([
|
|
20
20
|
{
|
|
21
21
|
name: "uknown",
|
|
22
22
|
messages: [NOT_SPECIFIED],
|
|
@@ -35,7 +35,7 @@ var TypedExceptionProgrammer;
|
|
|
35
35
|
var type = checker.getTypeFromTypeNode(node);
|
|
36
36
|
// VALIDATE TYPE
|
|
37
37
|
if (type.isTypeParameter())
|
|
38
|
-
throw TransformerError_1.TransformerError.from("
|
|
38
|
+
throw TransformerError_1.TransformerError.from("nestia.core.TypedException")([
|
|
39
39
|
{
|
|
40
40
|
name: TypeFactory_1.TypeFactory.getFullName(checker)(type),
|
|
41
41
|
messages: [NO_GENERIC_ARGUMENT],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypedExceptionProgrammer.js","sourceRoot":"","sources":["../../src/programmers/TypedExceptionProgrammer.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAC5B,+EAA8E;AAC9E,+DAA8D;AAC9D,4EAA2E;AAI3E,IAAiB,wBAAwB,CA2DxC;AA3DD,WAAiB,wBAAwB;IAC1B,iCAAQ,GACnB,UAAC,EAAoC;YAAlC,OAAO,aAAA;QACV,OAAA,UAAC,UAA6B;;YAC5B,mCAAmC;YACnC,IAAI,CAAC,CAAA,MAAA,UAAU,CAAC,aAAa,0CAAG,CAAC,CAAC,CAAA;gBAChC,MAAM,mCAAgB,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"TypedExceptionProgrammer.js","sourceRoot":"","sources":["../../src/programmers/TypedExceptionProgrammer.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAC5B,+EAA8E;AAC9E,+DAA8D;AAC9D,4EAA2E;AAI3E,IAAiB,wBAAwB,CA2DxC;AA3DD,WAAiB,wBAAwB;IAC1B,iCAAQ,GACnB,UAAC,EAAoC;YAAlC,OAAO,aAAA;QACV,OAAA,UAAC,UAA6B;;YAC5B,mCAAmC;YACnC,IAAI,CAAC,CAAA,MAAA,UAAU,CAAC,aAAa,0CAAG,CAAC,CAAC,CAAA;gBAChC,MAAM,mCAAgB,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;oBACxD;wBACE,IAAI,EAAE,QAAQ;wBACd,QAAQ,EAAE,CAAC,aAAa,CAAC;wBACzB,OAAO,EAAE;4BACP,GAAG,EA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AAI,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC;gBACnE,oBAAE,CAAC,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC;aACrC,CACF,CAAC;QACJ,CAAC;IAvDD,CAuDC,CAAC;AACN,CAAC,EA3DgB,wBAAwB,wCAAxB,wBAAwB,QA2DxC;AAED,IAAM,aAAa,GACjB,4EAA4E,CAAC;AAC/E,IAAM,mBAAmB,GACvB,yEAAyE,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="ts-expose-internals/typescript" />
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
4
|
+
export declare namespace TypedMultipartBodyProgrammer {
|
|
5
|
+
const generate: (project: INestiaTransformProject) => (modulo: ts.LeftHandSideExpression) => (type: ts.Type) => ts.ObjectLiteralExpression;
|
|
6
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.TypedMultipartBodyProgrammer = void 0;
|
|
18
|
+
var typescript_1 = __importDefault(require("typescript"));
|
|
19
|
+
var LiteralFactory_1 = require("typia/lib/factories/LiteralFactory");
|
|
20
|
+
var MetadataCollection_1 = require("typia/lib/factories/MetadataCollection");
|
|
21
|
+
var MetadataFactory_1 = require("typia/lib/factories/MetadataFactory");
|
|
22
|
+
var HttpAssertFormDataProgrammer_1 = require("typia/lib/programmers/http/HttpAssertFormDataProgrammer");
|
|
23
|
+
var HttpFormDataProgrammer_1 = require("typia/lib/programmers/http/HttpFormDataProgrammer");
|
|
24
|
+
var HttpIsFormDataProgrammer_1 = require("typia/lib/programmers/http/HttpIsFormDataProgrammer");
|
|
25
|
+
var HttpValidateFormDataProgrammer_1 = require("typia/lib/programmers/http/HttpValidateFormDataProgrammer");
|
|
26
|
+
var TransformerError_1 = require("typia/lib/transformers/TransformerError");
|
|
27
|
+
var TypedMultipartBodyProgrammer;
|
|
28
|
+
(function (TypedMultipartBodyProgrammer) {
|
|
29
|
+
TypedMultipartBodyProgrammer.generate = function (project) {
|
|
30
|
+
return function (modulo) {
|
|
31
|
+
return function (type) {
|
|
32
|
+
// VALIDATE TYPE
|
|
33
|
+
var collection = new MetadataCollection_1.MetadataCollection();
|
|
34
|
+
var result = MetadataFactory_1.MetadataFactory.analyze(project.checker, project.context)({
|
|
35
|
+
escape: false,
|
|
36
|
+
constant: true,
|
|
37
|
+
absorb: true,
|
|
38
|
+
validate: HttpFormDataProgrammer_1.HttpFormDataProgrammer.validate,
|
|
39
|
+
})(collection)(type);
|
|
40
|
+
if (result.success === false)
|
|
41
|
+
throw TransformerError_1.TransformerError.from("nestia.core.TypedMultipart.Body")(result.errors);
|
|
42
|
+
var files = result.data.objects[0].properties
|
|
43
|
+
.filter(function (p) {
|
|
44
|
+
return isFile(p.value) ||
|
|
45
|
+
p.value.arrays.some(function (a) { return isFile(a.type.value); });
|
|
46
|
+
})
|
|
47
|
+
.map(function (p) { return ({
|
|
48
|
+
name: p.key.constants[0].values[0],
|
|
49
|
+
limit: !!p.value.natives.length ? 1 : null,
|
|
50
|
+
}); });
|
|
51
|
+
// GENERATE VALIDATION PLAN
|
|
52
|
+
var parameter = function (key) {
|
|
53
|
+
return function (programmer) {
|
|
54
|
+
return typescript_1.default.factory.createObjectLiteralExpression([
|
|
55
|
+
typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier("files"), LiteralFactory_1.LiteralFactory.generate(files)),
|
|
56
|
+
typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier("validator"), typescript_1.default.factory.createObjectLiteralExpression([
|
|
57
|
+
typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier("type"), typescript_1.default.factory.createStringLiteral(key)),
|
|
58
|
+
typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier(key), programmer(__assign(__assign({}, project), { options: {
|
|
59
|
+
numeric: false,
|
|
60
|
+
finite: false,
|
|
61
|
+
functional: false,
|
|
62
|
+
} }))(modulo)(type)),
|
|
63
|
+
], true)),
|
|
64
|
+
], true);
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
// RETURNS
|
|
68
|
+
var category = project.options.validate;
|
|
69
|
+
if (category === "is" || category === "equals")
|
|
70
|
+
return parameter("is")(HttpIsFormDataProgrammer_1.HttpIsFormDataProgrammer.write);
|
|
71
|
+
else if (category === "validate" ||
|
|
72
|
+
category === "validateEquals" ||
|
|
73
|
+
category === "validateClone" ||
|
|
74
|
+
category === "validatePrune")
|
|
75
|
+
return parameter("validate")(HttpValidateFormDataProgrammer_1.HttpValidateFormDataProgrammer.write);
|
|
76
|
+
return parameter("assert")(HttpAssertFormDataProgrammer_1.HttpAssertFormDataProgrammer.write);
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
})(TypedMultipartBodyProgrammer || (exports.TypedMultipartBodyProgrammer = TypedMultipartBodyProgrammer = {}));
|
|
81
|
+
var isFile = function (meta) {
|
|
82
|
+
return meta.natives.some(function (n) { return n === "File" || n === "Blob"; });
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=TypedMultipartBodyProgrammer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version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Q,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC;gBAC1C,IAAI,QAAQ,KAAK,IAAI,IAAI,QAAQ,KAAK,QAAQ;oBAC5C,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,mDAAwB,CAAC,KAAK,CAAC,CAAC;qBACpD,IACH,QAAQ,KAAK,UAAU;oBACvB,QAAQ,KAAK,gBAAgB;oBAC7B,QAAQ,KAAK,eAAe;oBAC5B,QAAQ,KAAK,eAAe;oBAE5B,OAAO,SAAS,CAAC,UAAU,CAAC,CAAC,+DAA8B,CAAC,KAAK,CAAC,CAAC;gBACrE,OAAO,SAAS,CAAC,QAAQ,CAAC,CAAC,2DAA4B,CAAC,KAAK,CAAC,CAAC;YACjE,CAAC;QApFD,CAoFC;IArFD,CAqFC,CAAC;AACN,CAAC,EAzFgB,4BAA4B,4CAA5B,4BAA4B,QAyF5C;AAED,IAAM,MAAM,GAAG,UAAC,IAAc;IAC5B,OAAA,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,KAAK,MAAM,IAAI,CAAC,KAAK,MAAM,EAA5B,CAA4B,CAAC;AAAtD,CAAsD,CAAC"}
|
|
@@ -52,7 +52,7 @@ var HttpQuerifyProgrammer;
|
|
|
52
52
|
validate: HttpQueryProgrammer_1.HttpQueryProgrammer.validate,
|
|
53
53
|
})(collection)(type);
|
|
54
54
|
if (result.success === false)
|
|
55
|
-
throw TransformerError_1.TransformerError.from("
|
|
55
|
+
throw TransformerError_1.TransformerError.from("nestia.core.TypedQuery.".concat(importer.method))(result.errors);
|
|
56
56
|
var object = result.data.objects[0];
|
|
57
57
|
return typescript_1.default.factory.createArrowFunction(undefined, undefined, [IdentifierFactory_1.IdentifierFactory.parameter("input")], undefined, undefined, typescript_1.default.factory.createBlock(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(importer.declare(modulo)), false), [
|
|
58
58
|
StatementFactory_1.StatementFactory.constant("output", typescript_1.default.factory.createNewExpression(typescript_1.default.factory.createIdentifier("URLSearchParams"), undefined, []))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpQuerifyProgrammer.js","sourceRoot":"","sources":["../../../src/programmers/http/HttpQuerifyProgrammer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA4B;AAC5B,2EAA0E;AAC1E,6EAA4E;AAC5E,uEAAsE;AACtE,yEAAwE;AACxE,qFAAmF;AACnF,sFAAqF;AAIrF,4EAA2E;AAE3E,IAAiB,qBAAqB,CAmFrC;AAnFD,WAAiB,qBAAqB;IACvB,2BAAK,GAChB,UAAC,OAAiB;QAClB,OAAA,UAAC,MAAiC;YAClC,OAAA,UAAC,IAAa;gBACZ,kBAAkB;gBAClB,IAAM,QAAQ,GAAqB,IAAI,oCAAgB,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;gBAC1E,IAAM,UAAU,GAAuB,IAAI,uCAAkB,EAAE,CAAC;gBAChE,IAAM,MAAM,GAAG,iCAAe,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;oBACtD,MAAM,EAAE,KAAK;oBACb,QAAQ,EAAE,IAAI;oBACd,MAAM,EAAE,IAAI;oBACZ,QAAQ,EAAE,yCAAmB,CAAC,QAAQ;iBACvC,CAAC,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC;gBACrB,IAAI,MAAM,CAAC,OAAO,KAAK,KAAK;oBAC1B,MAAM,mCAAgB,CAAC,IAAI,CACzB,
|
|
1
|
+
{"version":3,"file":"HttpQuerifyProgrammer.js","sourceRoot":"","sources":["../../../src/programmers/http/HttpQuerifyProgrammer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA4B;AAC5B,2EAA0E;AAC1E,6EAA4E;AAC5E,uEAAsE;AACtE,yEAAwE;AACxE,qFAAmF;AACnF,sFAAqF;AAIrF,4EAA2E;AAE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IAAmB;QAClD,OAAA,oBAAE,CAAC,OAAO,CAAC,oBAAoB,CAC7B,qCAAiB,CAAC,MAAM,CAAC,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,EACzE,SAAS,EACT,CAAC,oBAAE,CAAC,OAAO,CAAC,mBAAmB,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAC5C;IAJD,CAIC,EAL6B,CAK7B,CAAC;AACN,CAAC,EAnFgB,qBAAqB,qCAArB,qBAAqB,QAmFrC"}
|
|
@@ -9,6 +9,7 @@ var typescript_1 = __importDefault(require("typescript"));
|
|
|
9
9
|
var PlainBodyProgrammer_1 = require("../programmers/PlainBodyProgrammer");
|
|
10
10
|
var TypedBodyProgrammer_1 = require("../programmers/TypedBodyProgrammer");
|
|
11
11
|
var TypedHeadersProgrammer_1 = require("../programmers/TypedHeadersProgrammer");
|
|
12
|
+
var TypedMultipartBodyProgrammer_1 = require("../programmers/TypedMultipartBodyProgrammer");
|
|
12
13
|
var TypedParamProgrammer_1 = require("../programmers/TypedParamProgrammer");
|
|
13
14
|
var TypedQueryBodyProgrammer_1 = require("../programmers/TypedQueryBodyProgrammer");
|
|
14
15
|
var TypedQueryProgrammer_1 = require("../programmers/TypedQueryProgrammer");
|
|
@@ -76,6 +77,11 @@ var FUNCTORS = {
|
|
|
76
77
|
? parameters
|
|
77
78
|
: [TypedQueryBodyProgrammer_1.TypedQueryBodyProgrammer.generate(project)(modulo)(type)];
|
|
78
79
|
}; }; }; },
|
|
80
|
+
"TypedMultipart.Body": function (project) { return function (modulo) { return function (parameters) { return function (type) {
|
|
81
|
+
return parameters.length
|
|
82
|
+
? parameters
|
|
83
|
+
: [TypedMultipartBodyProgrammer_1.TypedMultipartBodyProgrammer.generate(project)(modulo)(type)];
|
|
84
|
+
}; }; }; },
|
|
79
85
|
PlainBody: function (project) { return function (modulo) { return function (parameters) { return function (type) {
|
|
80
86
|
return parameters.length
|
|
81
87
|
? parameters
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ParameterDecoratorTransformer.js","sourceRoot":"","sources":["../../src/transformers/ParameterDecoratorTransformer.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAwB;AACxB,0DAA4B;AAG5B,0EAAyE;AACzE,0EAAyE;AACzE,gFAA+E;AAC/E,4EAA2E;AAC3E,oFAAmF;AACnF,4EAA2E;AAE3E,IAAiB,6BAA6B,CAmD7C;AAnDD,WAAiB,6BAA6B;IAC/B,uCAAS,GACpB,UAAC,OAAgC;QACjC,OAAA,UAAC,IAAa;YACd,OAAA,UAAC,SAAuB;;gBACtB,MAAM;gBACN,cAAc;gBACd,MAAM;gBACN,kBAAkB;gBAClB,IAAI,CAAC,oBAAE,CAAC,gBAAgB,CAAC,SAAS,CAAC,UAAU,CAAC;oBAAE,OAAO,SAAS,CAAC;gBAEjE,wBAAwB;gBACxB,IAAM,WAAW,GACf,MAAA,OAAO,CAAC,OAAO,CAAC,oBAAoB,CAAC,SAAS,CAAC,UAAU,CAAC,0CAAE,WAAW,CAAC;gBAC1E,IAAI,WAAW,KAAK,SAAS;oBAAE,OAAO,SAAS,CAAC;gBAEhD,YAAY;gBACZ,IAAM,IAAI,GAAW,cAAI,CAAC,OAAO,CAAC,WAAW,CAAC,aAAa,EAAE,CAAC,QAAQ,CAAC,CAAC;gBACxE,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;oBAChE,OAAO,SAAS,CAAC;gBAEnB,MAAM;gBACN,iBAAiB;gBACjB,MAAM;gBACN,kBAAkB;gBAClB,IAAM,UAAU,GACd,QAAQ,CACN,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAC/D,CAAC;gBACJ,IAAI,UAAU,KAAK,SAAS;oBAAE,OAAO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OAAA,UAAU,CAAC,MAAM;YACf,CAAC,CAAC,UAAU;YACZ,CAAC,CAAC,CAAC,yCAAmB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC;IAFzD,CAEyD,EAHP,CAGO,EAHvB,CAGuB,EAHnC,CAGmC;CAC5D,CAAC;AAEF,IAAM,QAAQ,GAAG,cAAI,CAAC,IAAI,CACxB,cAAc,EACd,SAAS,EACT,MAAM,EACN,KAAK,EACL,YAAY,CACb,CAAC;AACF,IAAM,QAAQ,GAAG,cAAI,CAAC,OAAO,CAAC,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC;AAExE,IAAM,OAAO,GAAG,UAAC,MAAiB;;IAChC,IAAM,MAAM,GAAG,MAAA,MAAA,MAAM,CAAC,eAAe,EAAE,0CAAG,CAAC,CAAC,0CAAE,MAAM,CAAC;IACrD,OAAO,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;AAChF,CAAC,CAAC;AACF,IAAM,WAAW,GACf,UAAC,IAAa;IACd,OAAA,UAAC,IAAY;QACX,OAAA,oBAAE,CAAC,aAAa,CAAC,IAAI,CAAC;YACpB,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAC7B,UAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,cAAI,IAAI,CAAE,CACnD;YACH,CAAC,CAAC,IAAI;IAJR,CAIQ;AALV,CAKU,CAAC"}
|
|
1
|
+
{"version":3,"file":"ParameterDecoratorTransformer.js","sourceRoot":"","sources":["../../src/transformers/ParameterDecoratorTransformer.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAwB;AACxB,0DAA4B;AAG5B,0EAAyE;A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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestia/core",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.2-dev.20240204",
|
|
4
4
|
"description": "Super-fast validation decorators of NestJS",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -36,20 +36,21 @@
|
|
|
36
36
|
},
|
|
37
37
|
"homepage": "https://nestia.io",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@nestia/fetcher": "^2.5.
|
|
39
|
+
"@nestia/fetcher": "^2.5.2-dev.20240204",
|
|
40
40
|
"@nestjs/common": ">=7.0.1",
|
|
41
41
|
"@nestjs/core": ">=7.0.1",
|
|
42
42
|
"@nestjs/platform-express": ">=7.0.1",
|
|
43
43
|
"@nestjs/platform-fastify": ">=7.0.1",
|
|
44
44
|
"detect-ts-node": "^1.0.5",
|
|
45
45
|
"glob": "^7.2.0",
|
|
46
|
+
"multer": "1.4.5-lts.1",
|
|
46
47
|
"raw-body": ">=2.0.0",
|
|
47
48
|
"reflect-metadata": ">=0.1.12",
|
|
48
49
|
"rxjs": ">=6.0.0",
|
|
49
|
-
"typia": "^5.4.
|
|
50
|
+
"typia": "^5.4.4"
|
|
50
51
|
},
|
|
51
52
|
"peerDependencies": {
|
|
52
|
-
"@nestia/fetcher": ">=2.5.
|
|
53
|
+
"@nestia/fetcher": ">=2.5.2-dev.20240204",
|
|
53
54
|
"@nestjs/common": ">=7.0.1",
|
|
54
55
|
"@nestjs/core": ">=7.0.1",
|
|
55
56
|
"@nestjs/platform-express": ">=7.0.1",
|
|
@@ -57,12 +58,13 @@
|
|
|
57
58
|
"raw-body": ">=2.0.0",
|
|
58
59
|
"reflect-metadata": ">=0.1.12",
|
|
59
60
|
"rxjs": ">=6.0.0",
|
|
60
|
-
"typia": ">=5.4.
|
|
61
|
+
"typia": ">=5.4.4 <6.0.0"
|
|
61
62
|
},
|
|
62
63
|
"devDependencies": {
|
|
63
64
|
"@types/express": "^4.17.15",
|
|
64
65
|
"@types/glob": "^7.2.0",
|
|
65
66
|
"@types/inquirer": "^9.0.3",
|
|
67
|
+
"@types/multer": "^1.4.11",
|
|
66
68
|
"@types/ts-expose-internals": "npm:ts-expose-internals@5.2.2",
|
|
67
69
|
"@typescript-eslint/eslint-plugin": "^5.46.1",
|
|
68
70
|
"@typescript-eslint/parser": "^5.46.1",
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BadRequestException,
|
|
3
|
+
ExecutionContext,
|
|
4
|
+
createParamDecorator,
|
|
5
|
+
} from "@nestjs/common";
|
|
6
|
+
import { HttpArgumentsHost } from "@nestjs/common/interfaces";
|
|
7
|
+
import express from "express";
|
|
8
|
+
import multer from "multer";
|
|
9
|
+
import typia from "typia";
|
|
10
|
+
|
|
11
|
+
import { IRequestMultipartProps } from "../options/IRequestMulltipartProps";
|
|
12
|
+
import { Singleton } from "../utils/Singleton";
|
|
13
|
+
import { validate_request_multipart } from "./internal/validate_request_multipart";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Type safe multipart/form-data decorator.
|
|
17
|
+
*
|
|
18
|
+
* `TypedMultipart.Body()` is a request body decorator function for the
|
|
19
|
+
* `multipart/form-data` content type. It automatically casts property type
|
|
20
|
+
* following its DTO definition, and performs the type validation too.
|
|
21
|
+
*
|
|
22
|
+
* Also, `TypedMultipart.Body()` is much easier and type safer than `@nest.UploadFile()`.
|
|
23
|
+
* If you're considering the [SDK library](https://nestia.io/docs/sdk/sdk) generation,
|
|
24
|
+
* only `TypedMultipart.Body()` can do it. Therefore, I recommend you to use
|
|
25
|
+
* `TypedMultipart.Body()` instead of the `@nest.UploadFile()` function.
|
|
26
|
+
*
|
|
27
|
+
* For reference, target type `T` must follow such restriction. Of course, if actual
|
|
28
|
+
* form-data values are different with their promised type `T`,
|
|
29
|
+
* `BadRequestException` error (status code: 400) would be thrown.
|
|
30
|
+
*
|
|
31
|
+
* 1. Type `T` must be an object type
|
|
32
|
+
* 2. Do not allow dynamic property
|
|
33
|
+
* 3. Only `boolean`, `bigint`, `number`, `string`, `Blob`, `File` or their array types are allowed
|
|
34
|
+
* 4. By the way, union type never be not allowed
|
|
35
|
+
* 5. Supports only Express, not Fastify
|
|
36
|
+
*
|
|
37
|
+
* @todo Change to ReadableStream through configuring storage engine of multer
|
|
38
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
39
|
+
*/
|
|
40
|
+
export namespace TypedMultipart {
|
|
41
|
+
/**
|
|
42
|
+
* Request body decorator.
|
|
43
|
+
*
|
|
44
|
+
* Request body decorator for the `multipart/form-data` type.
|
|
45
|
+
*
|
|
46
|
+
* Much easier and type safer than `@nest.UploadFile()` decorator.
|
|
47
|
+
*
|
|
48
|
+
* @param props Automatically filled by transformer
|
|
49
|
+
*/
|
|
50
|
+
export function Body<T extends object>(
|
|
51
|
+
props?: IRequestMultipartProps<T>,
|
|
52
|
+
): ParameterDecorator {
|
|
53
|
+
const checker = validate_request_multipart(props);
|
|
54
|
+
const upload = app.get().fields(
|
|
55
|
+
props!.files.map((file) => ({
|
|
56
|
+
name: file.name,
|
|
57
|
+
...(file.limit === 1 ? { maxCount: 1 } : {}),
|
|
58
|
+
})),
|
|
59
|
+
);
|
|
60
|
+
const interceptor = (
|
|
61
|
+
request: express.Request,
|
|
62
|
+
response: express.Response,
|
|
63
|
+
) =>
|
|
64
|
+
new Promise<void>((resolve, reject) =>
|
|
65
|
+
upload(request, response, (error) => {
|
|
66
|
+
if (error) reject(error);
|
|
67
|
+
else resolve();
|
|
68
|
+
}),
|
|
69
|
+
);
|
|
70
|
+
return createParamDecorator(async function TypedMultipartBody(
|
|
71
|
+
_unknown: any,
|
|
72
|
+
context: ExecutionContext,
|
|
73
|
+
) {
|
|
74
|
+
const http: HttpArgumentsHost = context.switchToHttp();
|
|
75
|
+
const request: express.Request = http.getRequest();
|
|
76
|
+
if (isMultipartFormData(request.headers["content-type"]) === false)
|
|
77
|
+
throw new BadRequestException(
|
|
78
|
+
`Request body type is not "application/x-www-form-urlencoded".`,
|
|
79
|
+
);
|
|
80
|
+
await interceptor(request, http.getResponse());
|
|
81
|
+
|
|
82
|
+
const data: FormData = new FormData();
|
|
83
|
+
for (const [key, value] of Object.entries(request.body))
|
|
84
|
+
for (const elem of String(value).split(",")) data.append(key, elem);
|
|
85
|
+
if (request.files) parseFiles(data)(request.files);
|
|
86
|
+
|
|
87
|
+
const output: T | Error = checker(data);
|
|
88
|
+
if (output instanceof Error) throw output;
|
|
89
|
+
return output;
|
|
90
|
+
})();
|
|
91
|
+
}
|
|
92
|
+
Object.assign(Body, typia.http.assertFormData);
|
|
93
|
+
Object.assign(Body, typia.http.isFormData);
|
|
94
|
+
Object.assign(Body, typia.http.validateFormData);
|
|
95
|
+
|
|
96
|
+
export interface IProps<T> {
|
|
97
|
+
files: Array<{
|
|
98
|
+
name: string;
|
|
99
|
+
limit: number | null;
|
|
100
|
+
}>;
|
|
101
|
+
validator: IRequestMultipartProps<T>;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @internal
|
|
107
|
+
*/
|
|
108
|
+
const parseFiles =
|
|
109
|
+
(data: FormData) =>
|
|
110
|
+
(files: Express.Multer.File[] | Record<string, Express.Multer.File[]>) => {
|
|
111
|
+
if (Array.isArray(files))
|
|
112
|
+
for (const file of files)
|
|
113
|
+
data.append(
|
|
114
|
+
file.fieldname,
|
|
115
|
+
new File([file.buffer], file.originalname, {
|
|
116
|
+
type: file.mimetype,
|
|
117
|
+
}),
|
|
118
|
+
);
|
|
119
|
+
else
|
|
120
|
+
for (const [key, value] of Object.entries(files))
|
|
121
|
+
for (const file of value)
|
|
122
|
+
data.append(
|
|
123
|
+
key,
|
|
124
|
+
new File([file.buffer], file.originalname, {
|
|
125
|
+
type: file.mimetype,
|
|
126
|
+
}),
|
|
127
|
+
);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* @internal
|
|
132
|
+
*/
|
|
133
|
+
function isMultipartFormData(text?: string): boolean {
|
|
134
|
+
return (
|
|
135
|
+
text !== undefined &&
|
|
136
|
+
text
|
|
137
|
+
.split(";")
|
|
138
|
+
.map((str) => str.trim())
|
|
139
|
+
.some((str) => str === "multipart/form-data")
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* @internal
|
|
145
|
+
*/
|
|
146
|
+
const app = new Singleton(() => multer());
|
|
@@ -31,7 +31,7 @@ import { validate_request_query } from "./internal/validate_request_query";
|
|
|
31
31
|
* same with {@link nest.Query}, but it can automatically cast property type following
|
|
32
32
|
* its DTO definition. Also, `TypedQuery` performs type validation.
|
|
33
33
|
*
|
|
34
|
-
* For reference, target type `T` must
|
|
34
|
+
* For reference, target type `T` must follow such restriction. Also, if actual URL
|
|
35
35
|
* query parameter values are different with their promised type `T`,
|
|
36
36
|
* `BadRequestException` error (status code: 400) would be thrown.
|
|
37
37
|
*
|
|
@@ -62,6 +62,11 @@ export function TypedQuery<T extends object>(
|
|
|
62
62
|
})();
|
|
63
63
|
}
|
|
64
64
|
export namespace TypedQuery {
|
|
65
|
+
/**
|
|
66
|
+
* Request body decorator.
|
|
67
|
+
*
|
|
68
|
+
* Request body decorator for the `application/x-www-form-urlencoded` type.
|
|
69
|
+
*/
|
|
65
70
|
export function Body<T extends object>(
|
|
66
71
|
validator?: IRequestQueryValidator<T>,
|
|
67
72
|
): ParameterDecorator {
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { BadRequestException } from "@nestjs/common";
|
|
2
|
+
import typia, { IValidation, TypeGuardError } from "typia";
|
|
3
|
+
|
|
4
|
+
import { IRequestMultipartProps } from "../../options/IRequestMulltipartProps";
|
|
5
|
+
import { NoTransformConfigureError } from "./NoTransformConfigureError";
|
|
6
|
+
|
|
7
|
+
export const validate_request_multipart = <T>(
|
|
8
|
+
props?: IRequestMultipartProps<T>,
|
|
9
|
+
) => {
|
|
10
|
+
if (!props) return () => NoTransformConfigureError("TypedMultipart.Bpdu");
|
|
11
|
+
else if (props.validator.type === "assert")
|
|
12
|
+
return assert(props.validator.assert);
|
|
13
|
+
else if (props.validator.type === "is") return is(props.validator.is);
|
|
14
|
+
else if (props.validator.type === "validate")
|
|
15
|
+
return validate(props.validator.validate);
|
|
16
|
+
return () =>
|
|
17
|
+
new Error(
|
|
18
|
+
`Error on nestia.core.TypedMultipart.Body(): invalid typed validator.`,
|
|
19
|
+
);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const assert =
|
|
23
|
+
<T>(closure: (input: FormData) => T) =>
|
|
24
|
+
(input: FormData): T | BadRequestException => {
|
|
25
|
+
try {
|
|
26
|
+
return closure(input);
|
|
27
|
+
} catch (exp) {
|
|
28
|
+
if (typia.is<TypeGuardError>(exp)) {
|
|
29
|
+
return new BadRequestException({
|
|
30
|
+
path: exp.path,
|
|
31
|
+
reason: exp.message,
|
|
32
|
+
expected: exp.expected,
|
|
33
|
+
value: exp.value,
|
|
34
|
+
message: MESSAGE,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
throw exp;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const is =
|
|
42
|
+
<T>(closure: (input: FormData) => T | null) =>
|
|
43
|
+
(input: FormData): T | BadRequestException => {
|
|
44
|
+
const result: T | null = closure(input);
|
|
45
|
+
return result !== null ? result : new BadRequestException(MESSAGE);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const validate =
|
|
49
|
+
<T>(closure: (input: FormData) => IValidation<T>) =>
|
|
50
|
+
(input: FormData): T | BadRequestException => {
|
|
51
|
+
const result: IValidation<T> = closure(input);
|
|
52
|
+
return result.success
|
|
53
|
+
? result.data
|
|
54
|
+
: new BadRequestException({
|
|
55
|
+
errors: result.errors,
|
|
56
|
+
message: MESSAGE,
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const MESSAGE = "Request multipart data is not following the promised type.";
|
package/src/module.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from "./decorators/PlainBody";
|
|
|
8
8
|
export * from "./decorators/TypedBody";
|
|
9
9
|
export * from "./decorators/TypedException";
|
|
10
10
|
export * from "./decorators/TypedHeaders";
|
|
11
|
+
export * from "./decorators/TypedMultipart";
|
|
11
12
|
export * from "./decorators/TypedParam";
|
|
12
13
|
export * from "./decorators/TypedRoute";
|
|
13
14
|
export * from "./decorators/TypedQuery";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { IValidation } from "typia";
|
|
2
|
+
|
|
3
|
+
export interface IRequestMultipartProps<T> {
|
|
4
|
+
files: Array<IRequestMultipartProps.IFile>;
|
|
5
|
+
validator:
|
|
6
|
+
| IRequestMultipartProps.IAssert<T>
|
|
7
|
+
| IRequestMultipartProps.IIs<T>
|
|
8
|
+
| IRequestMultipartProps.IValidate<T>;
|
|
9
|
+
}
|
|
10
|
+
export namespace IRequestMultipartProps {
|
|
11
|
+
export interface IAssert<T> {
|
|
12
|
+
type: "assert";
|
|
13
|
+
assert: (input: FormData) => T;
|
|
14
|
+
}
|
|
15
|
+
export interface IIs<T> {
|
|
16
|
+
type: "is";
|
|
17
|
+
is: (input: FormData) => T | null;
|
|
18
|
+
}
|
|
19
|
+
export interface IValidate<T> {
|
|
20
|
+
type: "validate";
|
|
21
|
+
validate: (input: FormData) => IValidation<T>;
|
|
22
|
+
}
|
|
23
|
+
export interface IFile {
|
|
24
|
+
name: string;
|
|
25
|
+
limit: number | null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -19,7 +19,7 @@ export namespace PlainBodyProgrammer {
|
|
|
19
19
|
validate,
|
|
20
20
|
})(new MetadataCollection())(type);
|
|
21
21
|
if (result.success === false)
|
|
22
|
-
throw TransformerError.from("
|
|
22
|
+
throw TransformerError.from("nestia.core.TypedParam")(result.errors);
|
|
23
23
|
return AssertProgrammer.write({
|
|
24
24
|
...project,
|
|
25
25
|
options: {
|
|
@@ -11,7 +11,7 @@ export namespace TypedExceptionProgrammer {
|
|
|
11
11
|
(expression: ts.CallExpression): ts.CallExpression => {
|
|
12
12
|
// CHECK GENERIC ARGUMENT EXISTENCE
|
|
13
13
|
if (!expression.typeArguments?.[0])
|
|
14
|
-
throw TransformerError.from("
|
|
14
|
+
throw TransformerError.from("nestia.core.TypedException")([
|
|
15
15
|
{
|
|
16
16
|
name: "uknown",
|
|
17
17
|
messages: [NOT_SPECIFIED],
|
|
@@ -32,7 +32,7 @@ export namespace TypedExceptionProgrammer {
|
|
|
32
32
|
|
|
33
33
|
// VALIDATE TYPE
|
|
34
34
|
if (type.isTypeParameter())
|
|
35
|
-
throw TransformerError.from("
|
|
35
|
+
throw TransformerError.from("nestia.core.TypedException")([
|
|
36
36
|
{
|
|
37
37
|
name: TypeFactory.getFullName(checker)(type),
|
|
38
38
|
messages: [NO_GENERIC_ARGUMENT],
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { LiteralFactory } from "typia/lib/factories/LiteralFactory";
|
|
3
|
+
import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
|
|
4
|
+
import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
|
|
5
|
+
import { HttpAssertFormDataProgrammer } from "typia/lib/programmers/http/HttpAssertFormDataProgrammer";
|
|
6
|
+
import { HttpFormDataProgrammer } from "typia/lib/programmers/http/HttpFormDataProgrammer";
|
|
7
|
+
import { HttpIsFormDataProgrammer } from "typia/lib/programmers/http/HttpIsFormDataProgrammer";
|
|
8
|
+
import { HttpValidateFormDataProgrammer } from "typia/lib/programmers/http/HttpValidateFormDataProgrammer";
|
|
9
|
+
import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
10
|
+
import { IProject } from "typia/lib/transformers/IProject";
|
|
11
|
+
import { TransformerError } from "typia/lib/transformers/TransformerError";
|
|
12
|
+
|
|
13
|
+
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
14
|
+
import { IRequestMultipartProps } from "../options/IRequestMulltipartProps";
|
|
15
|
+
|
|
16
|
+
export namespace TypedMultipartBodyProgrammer {
|
|
17
|
+
export const generate =
|
|
18
|
+
(project: INestiaTransformProject) =>
|
|
19
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
20
|
+
(type: ts.Type): ts.ObjectLiteralExpression => {
|
|
21
|
+
// VALIDATE TYPE
|
|
22
|
+
const collection: MetadataCollection = new MetadataCollection();
|
|
23
|
+
const result = MetadataFactory.analyze(
|
|
24
|
+
project.checker,
|
|
25
|
+
project.context,
|
|
26
|
+
)({
|
|
27
|
+
escape: false,
|
|
28
|
+
constant: true,
|
|
29
|
+
absorb: true,
|
|
30
|
+
validate: HttpFormDataProgrammer.validate,
|
|
31
|
+
})(collection)(type);
|
|
32
|
+
if (result.success === false)
|
|
33
|
+
throw TransformerError.from("nestia.core.TypedMultipart.Body")(
|
|
34
|
+
result.errors,
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const files: IRequestMultipartProps.IFile[] =
|
|
38
|
+
result.data.objects[0].properties
|
|
39
|
+
.filter(
|
|
40
|
+
(p) =>
|
|
41
|
+
isFile(p.value) ||
|
|
42
|
+
p.value.arrays.some((a) => isFile(a.type.value)),
|
|
43
|
+
)
|
|
44
|
+
.map((p) => ({
|
|
45
|
+
name: p.key.constants[0].values[0] as string,
|
|
46
|
+
limit: !!p.value.natives.length ? 1 : null,
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
// GENERATE VALIDATION PLAN
|
|
50
|
+
const parameter =
|
|
51
|
+
(key: IRequestMultipartProps<any>["validator"]["type"]) =>
|
|
52
|
+
(
|
|
53
|
+
programmer: (
|
|
54
|
+
project: IProject,
|
|
55
|
+
) => (
|
|
56
|
+
modulo: ts.LeftHandSideExpression,
|
|
57
|
+
) => (type: ts.Type) => ts.ArrowFunction,
|
|
58
|
+
) =>
|
|
59
|
+
ts.factory.createObjectLiteralExpression(
|
|
60
|
+
[
|
|
61
|
+
ts.factory.createPropertyAssignment(
|
|
62
|
+
ts.factory.createIdentifier("files"),
|
|
63
|
+
LiteralFactory.generate(files),
|
|
64
|
+
),
|
|
65
|
+
ts.factory.createPropertyAssignment(
|
|
66
|
+
ts.factory.createIdentifier("validator"),
|
|
67
|
+
ts.factory.createObjectLiteralExpression(
|
|
68
|
+
[
|
|
69
|
+
ts.factory.createPropertyAssignment(
|
|
70
|
+
ts.factory.createIdentifier("type"),
|
|
71
|
+
ts.factory.createStringLiteral(key),
|
|
72
|
+
),
|
|
73
|
+
ts.factory.createPropertyAssignment(
|
|
74
|
+
ts.factory.createIdentifier(key),
|
|
75
|
+
programmer({
|
|
76
|
+
...project,
|
|
77
|
+
options: {
|
|
78
|
+
numeric: false,
|
|
79
|
+
finite: false,
|
|
80
|
+
functional: false,
|
|
81
|
+
},
|
|
82
|
+
})(modulo)(type),
|
|
83
|
+
),
|
|
84
|
+
],
|
|
85
|
+
true,
|
|
86
|
+
),
|
|
87
|
+
),
|
|
88
|
+
],
|
|
89
|
+
true,
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
// RETURNS
|
|
93
|
+
const category = project.options.validate;
|
|
94
|
+
if (category === "is" || category === "equals")
|
|
95
|
+
return parameter("is")(HttpIsFormDataProgrammer.write);
|
|
96
|
+
else if (
|
|
97
|
+
category === "validate" ||
|
|
98
|
+
category === "validateEquals" ||
|
|
99
|
+
category === "validateClone" ||
|
|
100
|
+
category === "validatePrune"
|
|
101
|
+
)
|
|
102
|
+
return parameter("validate")(HttpValidateFormDataProgrammer.write);
|
|
103
|
+
return parameter("assert")(HttpAssertFormDataProgrammer.write);
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const isFile = (meta: Metadata) =>
|
|
108
|
+
meta.natives.some((n) => n === "File" || n === "Blob");
|
|
@@ -26,7 +26,7 @@ export namespace HttpQuerifyProgrammer {
|
|
|
26
26
|
})(collection)(type);
|
|
27
27
|
if (result.success === false)
|
|
28
28
|
throw TransformerError.from(
|
|
29
|
-
|
|
29
|
+
`nestia.core.TypedQuery.${importer.method}`,
|
|
30
30
|
)(result.errors);
|
|
31
31
|
|
|
32
32
|
const object: MetadataObject = result.data.objects[0]!;
|
|
@@ -5,6 +5,7 @@ import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
|
5
5
|
import { PlainBodyProgrammer } from "../programmers/PlainBodyProgrammer";
|
|
6
6
|
import { TypedBodyProgrammer } from "../programmers/TypedBodyProgrammer";
|
|
7
7
|
import { TypedHeadersProgrammer } from "../programmers/TypedHeadersProgrammer";
|
|
8
|
+
import { TypedMultipartBodyProgrammer } from "../programmers/TypedMultipartBodyProgrammer";
|
|
8
9
|
import { TypedParamProgrammer } from "../programmers/TypedParamProgrammer";
|
|
9
10
|
import { TypedQueryBodyProgrammer } from "../programmers/TypedQueryBodyProgrammer";
|
|
10
11
|
import { TypedQueryProgrammer } from "../programmers/TypedQueryProgrammer";
|
|
@@ -92,6 +93,10 @@ const FUNCTORS: Record<string, Programmer> = {
|
|
|
92
93
|
parameters.length
|
|
93
94
|
? parameters
|
|
94
95
|
: [TypedQueryBodyProgrammer.generate(project)(modulo)(type)],
|
|
96
|
+
"TypedMultipart.Body": (project) => (modulo) => (parameters) => (type) =>
|
|
97
|
+
parameters.length
|
|
98
|
+
? parameters
|
|
99
|
+
: [TypedMultipartBodyProgrammer.generate(project)(modulo)(type)],
|
|
95
100
|
PlainBody: (project) => (modulo) => (parameters) => (type) =>
|
|
96
101
|
parameters.length
|
|
97
102
|
? parameters
|