@nestia/core 1.2.0-dev.20230504 → 1.2.1-dev.20230505
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/README.md +7 -3
- package/lib/decorators/EncryptedBody.js +35 -73
- package/lib/decorators/EncryptedBody.js.map +1 -1
- package/lib/decorators/EncryptedController.d.ts +0 -5
- package/lib/decorators/EncryptedController.js +0 -5
- package/lib/decorators/EncryptedController.js.map +1 -1
- package/lib/decorators/EncryptedRoute.js +2 -9
- package/lib/decorators/EncryptedRoute.js.map +1 -1
- package/lib/decorators/PlainBody.js +14 -55
- package/lib/decorators/PlainBody.js.map +1 -1
- package/lib/decorators/TypedBody.js +20 -65
- package/lib/decorators/TypedBody.js.map +1 -1
- package/lib/decorators/TypedParam.js +6 -5
- package/lib/decorators/TypedParam.js.map +1 -1
- package/lib/decorators/TypedQuery.js +42 -59
- package/lib/decorators/TypedQuery.js.map +1 -1
- package/lib/decorators/internal/get_path_and_stringify.js +5 -3
- package/lib/decorators/internal/get_path_and_stringify.js.map +1 -1
- package/lib/decorators/internal/send_bad_request.d.ts +2 -0
- package/lib/decorators/internal/send_bad_request.js +13 -0
- package/lib/decorators/internal/send_bad_request.js.map +1 -0
- package/lib/decorators/internal/validate_request_body.d.ts +2 -1
- package/lib/decorators/internal/validate_request_body.js +15 -9
- package/lib/decorators/internal/validate_request_body.js.map +1 -1
- package/package.json +3 -3
- package/src/decorators/EncryptedBody.ts +30 -21
- package/src/decorators/EncryptedController.ts +0 -5
- package/src/decorators/EncryptedRoute.ts +2 -15
- package/src/decorators/PlainBody.ts +21 -7
- package/src/decorators/TypedBody.ts +26 -12
- package/src/decorators/TypedParam.ts +16 -8
- package/src/decorators/TypedQuery.ts +21 -15
- package/src/decorators/internal/get_path_and_stringify.ts +2 -3
- package/src/decorators/internal/send_bad_request.ts +12 -0
- package/src/decorators/internal/validate_request_body.ts +16 -13
package/README.md
CHANGED
|
@@ -10,7 +10,10 @@
|
|
|
10
10
|
Nestia is a set of helper libraries for NestJS, supporting below features:
|
|
11
11
|
|
|
12
12
|
- `@nestia/core`: super-fast decorators
|
|
13
|
-
- `@nestia/sdk
|
|
13
|
+
- `@nestia/sdk`
|
|
14
|
+
- SDK generator for clients
|
|
15
|
+
- Swagger generator evolved than ever
|
|
16
|
+
- Automatic E2E test functions generator
|
|
14
17
|
- `nestia`: just CLI (command line interface) tool
|
|
15
18
|
|
|
16
19
|
> **Note**
|
|
@@ -50,6 +53,7 @@ Check out the document in the [website](https://nestia.io/docs/):
|
|
|
50
53
|
- [TypedBody](https://nestia.io/docs/core/TypedBody/)
|
|
51
54
|
- [TypedParam](https://nestia.io/docs/core/TypedParam/)
|
|
52
55
|
- [TypedQuery](https://nestia.io/docs/core/TypedRoute/)
|
|
53
|
-
-
|
|
56
|
+
- Generators
|
|
54
57
|
- [SDK Library](https://nestia.io/docs/sdk/sdk/)
|
|
55
|
-
- [Swagger Documents](https://nestia.io/docs/sdk/swagger/)
|
|
58
|
+
- [Swagger Documents](https://nestia.io/docs/sdk/swagger/)
|
|
59
|
+
- [E2E Functions](https://nestia.io/docs/sdk/e2e/)
|
|
@@ -1,52 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
3
|
exports.EncryptedBody = void 0;
|
|
43
4
|
var fetcher_1 = require("@nestia/fetcher");
|
|
44
5
|
var common_1 = require("@nestjs/common");
|
|
45
|
-
var raw_body_1 = __importDefault(require("raw-body"));
|
|
46
6
|
var typia_1 = require("typia");
|
|
47
7
|
var Singleton_1 = require("../utils/Singleton");
|
|
48
8
|
var EncryptedConstant_1 = require("./internal/EncryptedConstant");
|
|
49
9
|
var headers_to_object_1 = require("./internal/headers_to_object");
|
|
10
|
+
var send_bad_request_1 = require("./internal/send_bad_request");
|
|
50
11
|
var validate_request_body_1 = require("./internal/validate_request_body");
|
|
51
12
|
/**
|
|
52
13
|
* Encrypted body decorator.
|
|
@@ -71,38 +32,32 @@ var validate_request_body_1 = require("./internal/validate_request_body");
|
|
|
71
32
|
*/
|
|
72
33
|
function EncryptedBody(validator) {
|
|
73
34
|
var checker = (0, validate_request_body_1.validate_request_body)("EncryptedBody")(validator);
|
|
74
|
-
return (0, common_1.createParamDecorator)(function EncryptedBody(_unknown,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
headers = new Singleton_1.Singleton(function () {
|
|
87
|
-
return (0, headers_to_object_1.headers_to_object)(request.headers);
|
|
88
|
-
});
|
|
89
|
-
return [4 /*yield*/, (0, raw_body_1.default)(request, "utf8")];
|
|
90
|
-
case 1:
|
|
91
|
-
body = (_a.sent()).trim();
|
|
92
|
-
password = typeof param === "function"
|
|
93
|
-
? param({ headers: headers.get(), body: body }, false)
|
|
94
|
-
: param;
|
|
95
|
-
disabled = password.disabled === undefined
|
|
96
|
-
? false
|
|
97
|
-
: typeof password.disabled === "function"
|
|
98
|
-
? password.disabled({ headers: headers.get(), body: body }, true)
|
|
99
|
-
: password.disabled;
|
|
100
|
-
data = JSON.parse(disabled ? body : decrypt(body, password.key, password.iv));
|
|
101
|
-
checker(data);
|
|
102
|
-
return [2 /*return*/, data];
|
|
103
|
-
}
|
|
104
|
-
});
|
|
35
|
+
return (0, common_1.createParamDecorator)(function EncryptedBody(_unknown, context) {
|
|
36
|
+
var request = context
|
|
37
|
+
.switchToHttp()
|
|
38
|
+
.getRequest();
|
|
39
|
+
if (isTextPlain(request.headers["content-type"]) === false)
|
|
40
|
+
return (0, send_bad_request_1.send_bad_request)(context)(new common_1.BadRequestException("Request body type is not \"text/plain\"."));
|
|
41
|
+
var param = Reflect.getMetadata(EncryptedConstant_1.ENCRYPTION_METADATA_KEY, context.getClass());
|
|
42
|
+
if (!param)
|
|
43
|
+
throw new Error("Error on nestia.core.EncryptedBody(): no encryption password is given.");
|
|
44
|
+
// GET BODY DATA
|
|
45
|
+
var headers = new Singleton_1.Singleton(function () {
|
|
46
|
+
return (0, headers_to_object_1.headers_to_object)(request.headers);
|
|
105
47
|
});
|
|
48
|
+
var body = request.body;
|
|
49
|
+
var password = typeof param === "function"
|
|
50
|
+
? param({ headers: headers.get(), body: body }, false)
|
|
51
|
+
: param;
|
|
52
|
+
// PARSE AND VALIDATE DATA
|
|
53
|
+
var data = JSON.parse(decrypt(body, password.key, password.iv));
|
|
54
|
+
var error = checker(data);
|
|
55
|
+
if (error !== null)
|
|
56
|
+
if (error instanceof common_1.HttpException)
|
|
57
|
+
return (0, send_bad_request_1.send_bad_request)(context)(error);
|
|
58
|
+
else
|
|
59
|
+
throw error;
|
|
60
|
+
return data;
|
|
106
61
|
})();
|
|
107
62
|
}
|
|
108
63
|
exports.EncryptedBody = EncryptedBody;
|
|
@@ -112,7 +67,7 @@ Object.assign(EncryptedBody, typia_1.validate);
|
|
|
112
67
|
/**
|
|
113
68
|
* @internal
|
|
114
69
|
*/
|
|
115
|
-
function
|
|
70
|
+
var decrypt = function (body, key, iv) {
|
|
116
71
|
try {
|
|
117
72
|
return fetcher_1.AesPkcs5.decrypt(body, key, iv);
|
|
118
73
|
}
|
|
@@ -122,5 +77,12 @@ function decrypt(body, key, iv) {
|
|
|
122
77
|
else
|
|
123
78
|
throw exp;
|
|
124
79
|
}
|
|
125
|
-
}
|
|
80
|
+
};
|
|
81
|
+
var isTextPlain = function (text) {
|
|
82
|
+
return text !== undefined &&
|
|
83
|
+
text
|
|
84
|
+
.split(";")
|
|
85
|
+
.map(function (str) { return str.trim(); })
|
|
86
|
+
.some(function (str) { return str === "text/plain"; });
|
|
87
|
+
};
|
|
126
88
|
//# sourceMappingURL=EncryptedBody.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EncryptedBody.js","sourceRoot":"","sources":["../../src/decorators/EncryptedBody.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EncryptedBody.js","sourceRoot":"","sources":["../../src/decorators/EncryptedBody.ts"],"names":[],"mappings":";;;AAAA,2CAAgE;AAChE,yCAKwB;AAIxB,+BAA6C;AAG7C,gDAA+C;AAC/C,kEAAuE;AACvE,kEAAiE;AACjE,gEAA+D;AAC/D,0EAAyE;AAEzE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,aAAa,CACzB,SAAoC;IAEpC,IAAM,OAAO,GAAG,IAAA,6CAAqB,EAAC,eAAe,CAAC,CAAC,SAAS,CAAC,CAAC;IAClE,OAAO,IAAA,6BAAoB,EAAC,SAAS,aAAa,CAC9C,QAAa,EACb,OAAyB;QAEzB,IAAM,OAAO,GAAqC,OAAO;aACpD,YAAY,EAAE;aACd,UAAU,EAAE,CAAC;QAClB,IAAI,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,KAAK,KAAK;YACtD,OAAO,IAAA,mCAAgB,EAAC,OAAO,CAAC,CAC5B,IAAI,4BAAmB,CACnB,0CAAwC,CAC3C,CACJ,CAAC;QAEN,IAAM,KAAK,GAGO,OAAO,CAAC,WAAW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,OAAO,kBAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;KAC1C;IAAC,OAAO,GAAG,EAAE;QACV,IAAI,GAAG,YAAY,KAAK;YACpB,MAAM,IAAI,4BAAmB,CACzB,qFAAqF,CACxF,CAAC;;YACD,MAAM,GAAG,CAAC;KAClB;AACL,CAAC,CAAC;AAEF,IAAM,WAAW,GAAG,UAAC,IAAa;IAC9B,OAAA,IAAI,KAAK,SAAS;QAClB,IAAI;aACC,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,YAAY,EAApB,CAAoB,CAAC;AAJxC,CAIwC,CAAC"}
|
|
@@ -7,11 +7,6 @@ import { IEncryptionPassword } from "@nestia/fetcher";
|
|
|
7
7
|
* encryption algorithm and password would be used by {@link EncryptedRoute} and
|
|
8
8
|
* {@link EncryptedBody} to encrypt the request and response body of the HTTP protocol.
|
|
9
9
|
*
|
|
10
|
-
* > However, if you've configure the {@link IEncryptionPassword.disabled} to be `true`,
|
|
11
|
-
* > you can disable the encryption and decryption algorithm. Therefore, when the
|
|
12
|
-
* > {@link IEncryptionPassword.disable} becomes the `true`, content like request and
|
|
13
|
-
* > response body would be considered as a plain text instead.
|
|
14
|
-
*
|
|
15
10
|
* By the way, you can configure the encryption password in the global level by using
|
|
16
11
|
* {@link EncryptedModule} instead of the {@link nest.Module} in the module level. In
|
|
17
12
|
* that case, you don't need to use this `EncryptedController` more. Just use the
|
|
@@ -11,11 +11,6 @@ var EncryptedConstant_1 = require("./internal/EncryptedConstant");
|
|
|
11
11
|
* encryption algorithm and password would be used by {@link EncryptedRoute} and
|
|
12
12
|
* {@link EncryptedBody} to encrypt the request and response body of the HTTP protocol.
|
|
13
13
|
*
|
|
14
|
-
* > However, if you've configure the {@link IEncryptionPassword.disabled} to be `true`,
|
|
15
|
-
* > you can disable the encryption and decryption algorithm. Therefore, when the
|
|
16
|
-
* > {@link IEncryptionPassword.disable} becomes the `true`, content like request and
|
|
17
|
-
* > response body would be considered as a plain text instead.
|
|
18
|
-
*
|
|
19
14
|
* By the way, you can configure the encryption password in the global level by using
|
|
20
15
|
* {@link EncryptedModule} instead of the {@link nest.Module} in the module level. In
|
|
21
16
|
* that case, you don't need to use this `EncryptedController` more. Just use the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EncryptedController.js","sourceRoot":"","sources":["../../src/decorators/EncryptedController.ts"],"names":[],"mappings":";;;AACA,yCAA4C;AAE5C,kEAAuE;AAEvE
|
|
1
|
+
{"version":3,"file":"EncryptedController.js","sourceRoot":"","sources":["../../src/decorators/EncryptedController.ts"],"names":[],"mappings":";;;AACA,yCAA4C;AAE5C,kEAAuE;AAEvE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,SAAgB,mBAAmB,CAC/B,IAAY,EACZ,QAA2D;IAE3D,OAAO,UAAU,MAAW;QACxB,OAAO,CAAC,cAAc,CAAC,2CAAuB,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;QAClE,IAAA,mBAAU,EAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC;IAC7B,CAAC,CAAC;AACN,CAAC;AARD,kDAQC"}
|
|
@@ -188,16 +188,9 @@ var EncryptedRouteInterceptor = /** @class */ (function () {
|
|
|
188
188
|
var password = typeof param === "function"
|
|
189
189
|
? param({ headers: headers.get(), body: body }, false)
|
|
190
190
|
: param;
|
|
191
|
-
var disabled = password.disabled === undefined
|
|
192
|
-
? false
|
|
193
|
-
: typeof password.disabled === "function"
|
|
194
|
-
? password.disabled({ headers: headers.get(), body: body }, false)
|
|
195
|
-
: password.disabled;
|
|
196
191
|
var response = http.getResponse();
|
|
197
|
-
response.header("Content-Type",
|
|
198
|
-
if (
|
|
199
|
-
return body;
|
|
200
|
-
else if (body === undefined)
|
|
192
|
+
response.header("Content-Type", "text/plain");
|
|
193
|
+
if (body === undefined)
|
|
201
194
|
return body;
|
|
202
195
|
return fetcher_1.AesPkcs5.encrypt(body, password.key, password.iv);
|
|
203
196
|
}), (0, operators_1.catchError)(function (err) { return (0, route_error_1.route_error)(http.getRequest(), err); }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EncryptedRoute.js","sourceRoot":"","sources":["../../src/decorators/EncryptedRoute.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAgE;AAChE,yCAWwB;AAGxB,4CAAiD;AAEjD,+BAKe;AAGf,gDAA+C;AAC/C,kEAAuE;AACvE,4DAA2D;AAC3D,4EAA2E;AAC3E,kEAAiE;AACjE,sDAAqD;AAErD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,IAAiB,cAAc,CAgE9B;AAhED,WAAiB,cAAc;IAC3B;;;;;OAKG;IACU,kBAAG,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;IAEpC;;;;;OAKG;IACU,mBAAI,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;IAEtC;;;;;OAKG;IACU,oBAAK,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;IAExC;;;;;OAKG;IACU,kBAAG,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;IAEpC;;;;;OAKG;IACU,qBAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;IAE1C,SAAS,SAAS,CAAC,MAAmD;QAUlE,SAAS,KAAK;YAAC,cAAc;iBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;gBAAd,yBAAc;;YACnB,IAAA,KAAA,OAAoB,IAAA,+CAAsB,EAC5C,yBAAkB,MAAM,CAAE,CAC7B,wCAAI,IAAI,cAAC,EAFH,IAAI,QAAA,EAAE,SAAS,QAEZ,CAAC;YACX,OAAO,IAAA,wBAAe,EAClB,OAAO,CAAC,MAAM,CAAC,CAAC,IA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EAAE,KAAK,CAAC;gBAChD,CAAC,CAAC,KAAK,CAAC;YAEhB,IAAM,QAAQ,GAAqB,IAAI,CAAC,WAAW,EAAE,CAAC;YACtD,QAAQ,CAAC,MAAM,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;YAE9C,IAAI,IAAI,KAAK,SAAS;gBAAE,OAAO,IAAI,CAAC;YACpC,OAAO,kBAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC;QAC7D,CAAC,CAAC,EACF,IAAA,sBAAU,EAAC,UAAC,GAAG,IAAK,OAAA,IAAA,yBAAW,EAAC,IAAI,CAAC,UAAU,EAAE,EAAE,GAAG,CAAC,EAAnC,CAAmC,CAAC,CAC3D,CAAC;IACN,CAAC;IACL,gCAAC;AAAD,CAAC,AAxCD,IAwCC;AAED;;GAEG;AACH,IAAM,OAAO,GAAG;IACZ,GAAG,cAAA;IACH,IAAI,eAAA;IACJ,GAAG,cAAA;IACH,KAAK,gBAAA;IACL,MAAM,iBAAA;CACT,CAAC"}
|
|
@@ -1,47 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
3
|
exports.PlainBody = void 0;
|
|
43
4
|
var common_1 = require("@nestjs/common");
|
|
44
|
-
var
|
|
5
|
+
var send_bad_request_1 = require("./internal/send_bad_request");
|
|
45
6
|
/**
|
|
46
7
|
* Plain body decorator.
|
|
47
8
|
*
|
|
@@ -64,20 +25,18 @@ var raw_body_1 = __importDefault(require("raw-body"));
|
|
|
64
25
|
* @author Jeongho Nam - https://github.com/samchon
|
|
65
26
|
*/
|
|
66
27
|
exports.PlainBody = (0, common_1.createParamDecorator)(function PlainBody(_data, context) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (!request.readable)
|
|
74
|
-
throw new common_1.BadRequestException("Invalid body");
|
|
75
|
-
return [4 /*yield*/, (0, raw_body_1.default)(request)];
|
|
76
|
-
case 1:
|
|
77
|
-
body = (_a.sent()).toString("utf8").trim();
|
|
78
|
-
return [2 /*return*/, body];
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
});
|
|
28
|
+
var request = context
|
|
29
|
+
.switchToHttp()
|
|
30
|
+
.getRequest();
|
|
31
|
+
return isTextPlain(request.headers["content-type"])
|
|
32
|
+
? request.body
|
|
33
|
+
: (0, send_bad_request_1.send_bad_request)(context)(new common_1.BadRequestException("Request body type is not \"text/plain\"."));
|
|
82
34
|
});
|
|
35
|
+
var isTextPlain = function (text) {
|
|
36
|
+
return text !== undefined &&
|
|
37
|
+
text
|
|
38
|
+
.split(";")
|
|
39
|
+
.map(function (str) { return str.trim(); })
|
|
40
|
+
.some(function (str) { return str === "text/plain"; });
|
|
41
|
+
};
|
|
83
42
|
//# sourceMappingURL=PlainBody.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlainBody.js","sourceRoot":"","sources":["../../src/decorators/PlainBody.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PlainBody.js","sourceRoot":"","sources":["../../src/decorators/PlainBody.ts"],"names":[],"mappings":";;;AAAA,yCAIwB;AAIxB,gEAA+D;AAE/D;;;;;;;;;;;;;;;;;;;;GAoBG;AACU,QAAA,SAAS,GAA6B,IAAA,6BAAoB,EACnE,SAAS,SAAS,CAAC,KAAU,EAAE,OAAyB;IACpD,IAAM,OAAO,GAAqC,OAAO;SACpD,YAAY,EAAE;SACd,UAAU,EAAE,CAAC;IAClB,OAAO,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QAC/C,CAAC,CAAC,OAAO,CAAC,IAAI;QACd,CAAC,CAAC,IAAA,mCAAgB,EAAC,OAAO,CAAC,CACrB,IAAI,4BAAmB,CACnB,0CAAwC,CAC3C,CACJ,CAAC;AACZ,CAAC,CACJ,CAAC;AAEF,IAAM,WAAW,GAAG,UAAC,IAAa;IAC9B,OAAA,IAAI,KAAK,SAAS;QAClB,IAAI;aACC,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,YAAY,EAApB,CAAoB,CAAC;AAJxC,CAIwC,CAAC"}
|
|
@@ -1,48 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
3
|
exports.TypedBody = void 0;
|
|
43
4
|
var common_1 = require("@nestjs/common");
|
|
44
|
-
var raw_body_1 = __importDefault(require("raw-body"));
|
|
45
5
|
var typia_1 = require("typia");
|
|
6
|
+
var send_bad_request_1 = require("./internal/send_bad_request");
|
|
46
7
|
var validate_request_body_1 = require("./internal/validate_request_body");
|
|
47
8
|
/**
|
|
48
9
|
* Type safe body decorator.
|
|
@@ -61,35 +22,29 @@ var validate_request_body_1 = require("./internal/validate_request_body");
|
|
|
61
22
|
function TypedBody(validator) {
|
|
62
23
|
var checker = (0, validate_request_body_1.validate_request_body)("TypedBody")(validator);
|
|
63
24
|
return (0, common_1.createParamDecorator)(function TypedBody(_unknown, context) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
case 1:
|
|
77
|
-
_c = (_b = JSON).parse;
|
|
78
|
-
return [4 /*yield*/, (0, raw_body_1.default)(request, "utf8")];
|
|
79
|
-
case 2:
|
|
80
|
-
_a = _c.apply(_b, [(_d.sent()).trim()]);
|
|
81
|
-
_d.label = 3;
|
|
82
|
-
case 3:
|
|
83
|
-
data = _a;
|
|
84
|
-
checker(data);
|
|
85
|
-
return [2 /*return*/, data];
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
});
|
|
25
|
+
var request = context
|
|
26
|
+
.switchToHttp()
|
|
27
|
+
.getRequest();
|
|
28
|
+
if (isApplicationJson(request.headers["content-type"]) === false)
|
|
29
|
+
return (0, send_bad_request_1.send_bad_request)(context)(new common_1.BadRequestException("Request body type is not \"application/json\"."));
|
|
30
|
+
var error = checker(request.body);
|
|
31
|
+
if (error !== null)
|
|
32
|
+
if (error instanceof common_1.HttpException)
|
|
33
|
+
return (0, send_bad_request_1.send_bad_request)(context)(error);
|
|
34
|
+
else
|
|
35
|
+
throw error;
|
|
36
|
+
return request.body;
|
|
89
37
|
})();
|
|
90
38
|
}
|
|
91
39
|
exports.TypedBody = TypedBody;
|
|
92
40
|
Object.assign(TypedBody, typia_1.is);
|
|
93
41
|
Object.assign(TypedBody, typia_1.assert);
|
|
94
42
|
Object.assign(TypedBody, typia_1.validate);
|
|
43
|
+
var isApplicationJson = function (text) {
|
|
44
|
+
return text !== undefined &&
|
|
45
|
+
text
|
|
46
|
+
.split(";")
|
|
47
|
+
.map(function (str) { return str.trim(); })
|
|
48
|
+
.some(function (str) { return str === "application/json"; });
|
|
49
|
+
};
|
|
95
50
|
//# sourceMappingURL=TypedBody.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypedBody.js","sourceRoot":"","sources":["../../src/decorators/TypedBody.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TypedBody.js","sourceRoot":"","sources":["../../src/decorators/TypedBody.ts"],"names":[],"mappings":";;;AAAA,yCAKwB;AAIxB,+BAA6C;AAG7C,gEAA+D;AAC/D,0EAAyE;AAEzE;;;;;;;;;;;;;GAaG;AACH,SAAgB,SAAS,CACrB,SAAoC;IAEpC,IAAM,OAAO,GAAG,IAAA,6CAAqB,EAAC,WAAW,CAAC,CAAC,SAAS,CAAC,CAAC;IAC9D,OAAO,IAAA,6BAAoB,EAAC,SAAS,SAAS,CAC1C,QAAa,EACb,OAAyB;QAEzB,IAAM,OAAO,GAAqC,OAAO;aACpD,YAAY,EAAE;aACd,UAAU,EAAE,CAAC;QAClB,IAAI,iBAAiB,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,KAAK,KAAK;YAC5D,OAAO,IAAA,mCAAgB,EAAC,OAAO,CAAC,CAC5B,IAAI,4BAAmB,CACnB,gDAA8C,CACjD,CACJ,CAAC;QAEN,IAAM,KAAK,GAAiB,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAClD,IAAI,KAAK,KAAK,IAAI;YACd,IAAI,KAAK,YAAY,sBAAa;gBAC9B,OAAO,IAAA,mCAAgB,EAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC;;gBACvC,MAAM,KAAK,CAAC;QACrB,OAAO,OAAO,CAAC,IAAI,CAAC;IACxB,CAAC,CAAC,EAAE,CAAC;AACT,CAAC;AAzBD,8BAyBC;AAED,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,UAAE,CAAC,CAAC;AAC7B,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,cAAM,CAAC,CAAC;AACjC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,gBAAQ,CAAC,CAAC;AAEnC,IAAM,iBAAiB,GAAG,UAAC,IAAa;IACpC,OAAA,IAAI,KAAK,SAAS;QAClB,IAAI;aACC,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,kBAAkB,EAA1B,CAA0B,CAAC;AAJ9C,CAI8C,CAAC"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TypedParam = void 0;
|
|
4
4
|
var common_1 = require("@nestjs/common");
|
|
5
|
+
var send_bad_request_1 = require("./internal/send_bad_request");
|
|
5
6
|
/**
|
|
6
7
|
* Type safe URL parameter decorator.
|
|
7
8
|
*
|
|
@@ -33,8 +34,8 @@ var common_1 = require("@nestjs/common");
|
|
|
33
34
|
* @author Jeongho Nam - https://github.com/samchon
|
|
34
35
|
*/
|
|
35
36
|
function TypedParam(name, type, nullable) {
|
|
36
|
-
function TypedParam(_a,
|
|
37
|
-
var request =
|
|
37
|
+
function TypedParam(_a, context) {
|
|
38
|
+
var request = context.switchToHttp().getRequest();
|
|
38
39
|
var str = request.params[name];
|
|
39
40
|
if (nullable === true && str === "null")
|
|
40
41
|
return null;
|
|
@@ -44,17 +45,17 @@ function TypedParam(name, type, nullable) {
|
|
|
44
45
|
else if (str === "false" || str === "0")
|
|
45
46
|
return false;
|
|
46
47
|
else
|
|
47
|
-
|
|
48
|
+
return (0, send_bad_request_1.send_bad_request)(context)(new common_1.BadRequestException("Value of the URL parameter '".concat(name, "' is not a boolean.")));
|
|
48
49
|
}
|
|
49
50
|
else if (type === "number") {
|
|
50
51
|
var value = Number(str);
|
|
51
52
|
if (isNaN(value))
|
|
52
|
-
|
|
53
|
+
return (0, send_bad_request_1.send_bad_request)(context)(new common_1.BadRequestException("Value of the URL parameter \"".concat(name, "\" is not a number.")));
|
|
53
54
|
return value;
|
|
54
55
|
}
|
|
55
56
|
else if (type === "uuid") {
|
|
56
57
|
if (UUID_PATTERN.test(str) === false)
|
|
57
|
-
|
|
58
|
+
return (0, send_bad_request_1.send_bad_request)(context)(new common_1.BadRequestException("Value of the URL parameter \"".concat(name, "\" is not a valid UUID.")));
|
|
58
59
|
return str;
|
|
59
60
|
}
|
|
60
61
|
else
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypedParam.js","sourceRoot":"","sources":["../../src/decorators/TypedParam.ts"],"names":[],"mappings":";;;AAAA,yCAIwB;AAGxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,SAAgB,UAAU,CACtB,IAAY,EACZ,IAA+C,EAC/C,QAAuB;IAEvB,SAAS,UAAU,CAAC,EAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"TypedParam.js","sourceRoot":"","sources":["../../src/decorators/TypedParam.ts"],"names":[],"mappings":";;;AAAA,yCAIwB;AAGxB,gEAA+D;AAE/D;;;;;;;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AkB,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC;IACzC,UAAkB,CAAC,IAAI,GAAG,IAAI,CAAC;IAChC,OAAO,IAAA,6BAAoB,EAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC;AAClD,CAAC;AAzCD,gCAyCC;AAED,IAAM,YAAY,GACd,qHAAqH,CAAC"}
|
|
@@ -1,45 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
36
7
|
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
37
24
|
};
|
|
38
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
26
|
exports.TypedQuery = void 0;
|
|
40
27
|
var common_1 = require("@nestjs/common");
|
|
41
|
-
var typia_1 = require("typia");
|
|
28
|
+
var typia_1 = __importStar(require("typia"));
|
|
42
29
|
var TransformError_1 = require("./internal/TransformError");
|
|
30
|
+
var send_bad_request_1 = require("./internal/send_bad_request");
|
|
43
31
|
/**
|
|
44
32
|
* Type safe URL query decorator.
|
|
45
33
|
*
|
|
@@ -56,30 +44,25 @@ var TransformError_1 = require("./internal/TransformError");
|
|
|
56
44
|
function TypedQuery(decoder) {
|
|
57
45
|
if (decoder === undefined)
|
|
58
46
|
throw (0, TransformError_1.TransformError)("TypedQuery");
|
|
59
|
-
return (0, common_1.createParamDecorator)(function TypedQuery(_unknown,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
throw exp;
|
|
79
|
-
}
|
|
80
|
-
return [2 /*return*/];
|
|
81
|
-
});
|
|
82
|
-
});
|
|
47
|
+
return (0, common_1.createParamDecorator)(function TypedQuery(_unknown, context) {
|
|
48
|
+
var request = context
|
|
49
|
+
.switchToHttp()
|
|
50
|
+
.getRequest();
|
|
51
|
+
var params = new URLSearchParams(tail(request.url));
|
|
52
|
+
try {
|
|
53
|
+
return decoder(params);
|
|
54
|
+
}
|
|
55
|
+
catch (exp) {
|
|
56
|
+
if (typia_1.default.is(exp))
|
|
57
|
+
return (0, send_bad_request_1.send_bad_request)(context)(new common_1.BadRequestException({
|
|
58
|
+
path: exp.path,
|
|
59
|
+
reason: exp.message,
|
|
60
|
+
expected: exp.expected,
|
|
61
|
+
value: exp.value,
|
|
62
|
+
message: "Request query parameters are not following the promised type.",
|
|
63
|
+
}));
|
|
64
|
+
throw exp;
|
|
65
|
+
}
|
|
83
66
|
})();
|
|
84
67
|
}
|
|
85
68
|
exports.TypedQuery = TypedQuery;
|