@nestia/core 1.3.5 → 1.3.7
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 +9 -4
- package/lib/decorators/DynamicModule.d.ts +26 -26
- package/lib/decorators/DynamicModule.js +103 -103
- package/lib/decorators/DynamicModule.js.map +1 -1
- package/lib/decorators/EncryptedBody.d.ts +23 -23
- package/lib/decorators/EncryptedBody.js +128 -128
- package/lib/decorators/EncryptedController.d.ts +26 -26
- package/lib/decorators/EncryptedController.js +36 -36
- package/lib/decorators/EncryptedModule.d.ts +52 -52
- package/lib/decorators/EncryptedModule.js +161 -161
- package/lib/decorators/EncryptedModule.js.map +1 -1
- package/lib/decorators/EncryptedRoute.d.ts +78 -78
- package/lib/decorators/EncryptedRoute.js +209 -209
- package/lib/decorators/EncryptedRoute.js.map +1 -1
- package/lib/decorators/PlainBody.d.ts +22 -22
- package/lib/decorators/PlainBody.js +82 -82
- package/lib/decorators/TypedBody.d.ts +16 -16
- package/lib/decorators/TypedBody.js +45 -45
- package/lib/decorators/TypedParam.d.ts +31 -31
- package/lib/decorators/TypedParam.js +76 -76
- package/lib/decorators/TypedQuery.d.ts +14 -14
- package/lib/decorators/TypedQuery.js +109 -109
- package/lib/decorators/TypedQuery.js.map +1 -1
- package/lib/decorators/TypedRoute.d.ts +72 -72
- package/lib/decorators/TypedRoute.js +185 -185
- package/lib/decorators/TypedRoute.js.map +1 -1
- package/lib/decorators/internal/EncryptedConstant.d.ts +1 -1
- package/lib/decorators/internal/EncryptedConstant.js +7 -7
- package/lib/decorators/internal/TransformError.d.ts +1 -1
- package/lib/decorators/internal/TransformError.js +10 -10
- package/lib/decorators/internal/get_path_and_stringify.d.ts +1 -1
- package/lib/decorators/internal/get_path_and_stringify.js +83 -83
- package/lib/decorators/internal/get_text_body.d.ts +3 -3
- package/lib/decorators/internal/get_text_body.js +62 -62
- package/lib/decorators/internal/headers_to_object.d.ts +3 -3
- package/lib/decorators/internal/headers_to_object.js +49 -49
- package/lib/decorators/internal/load_controller.d.ts +5 -5
- package/lib/decorators/internal/load_controller.js +151 -152
- package/lib/decorators/internal/load_controller.js.map +1 -1
- package/lib/decorators/internal/route_error.d.ts +3 -3
- package/lib/decorators/internal/route_error.js +88 -88
- package/lib/decorators/internal/validate_request_body.d.ts +3 -3
- package/lib/decorators/internal/validate_request_body.js +66 -66
- package/lib/index.d.ts +3 -3
- package/lib/index.js +31 -31
- package/lib/module.d.ts +12 -12
- package/lib/module.js +28 -28
- package/lib/options/INestiaTransformOptions.d.ts +4 -4
- package/lib/options/INestiaTransformOptions.js +2 -2
- package/lib/options/INestiaTransformProject.d.ts +5 -5
- package/lib/options/INestiaTransformProject.js +2 -2
- package/lib/options/IRequestBodyValidator.d.ts +16 -16
- package/lib/options/IRequestBodyValidator.js +2 -2
- package/lib/options/IResponseBodyStringifier.d.ts +20 -20
- package/lib/options/IResponseBodyStringifier.js +2 -2
- package/lib/programmers/TypedBodyProgrammer.d.ts +5 -5
- package/lib/programmers/TypedBodyProgrammer.js +58 -58
- package/lib/programmers/TypedBodyProgrammer.js.map +1 -1
- package/lib/programmers/TypedParamProgrammer.d.ts +5 -5
- package/lib/programmers/TypedParamProgrammer.js +110 -110
- package/lib/programmers/TypedParamProgrammer.js.map +1 -1
- package/lib/programmers/TypedQueryProgrammer.d.ts +5 -5
- package/lib/programmers/TypedQueryProgrammer.js +264 -264
- package/lib/programmers/TypedQueryProgrammer.js.map +1 -1
- package/lib/programmers/TypedRouteProgrammer.d.ts +5 -5
- package/lib/programmers/TypedRouteProgrammer.js +49 -49
- package/lib/programmers/TypedRouteProgrammer.js.map +1 -1
- package/lib/transform.d.ts +4 -4
- package/lib/transform.js +25 -25
- package/lib/transformers/FileTransformer.d.ts +5 -5
- package/lib/transformers/FileTransformer.js +40 -40
- package/lib/transformers/FileTransformer.js.map +1 -1
- package/lib/transformers/MethodDecoratorTransformer.d.ts +5 -5
- package/lib/transformers/MethodDecoratorTransformer.js +92 -92
- package/lib/transformers/MethodDecoratorTransformer.js.map +1 -1
- package/lib/transformers/MethodTransformer.d.ts +5 -5
- package/lib/transformers/MethodTransformer.js +62 -62
- package/lib/transformers/MethodTransformer.js.map +1 -1
- package/lib/transformers/NodeTransformer.d.ts +5 -5
- package/lib/transformers/NodeTransformer.js +21 -21
- package/lib/transformers/NodeTransformer.js.map +1 -1
- package/lib/transformers/ParameterDecoratorTransformer.d.ts +5 -5
- package/lib/transformers/ParameterDecoratorTransformer.js +68 -68
- package/lib/transformers/ParameterDecoratorTransformer.js.map +1 -1
- package/lib/transformers/ParameterTransformer.d.ts +5 -5
- package/lib/transformers/ParameterTransformer.js +34 -34
- package/lib/transformers/ParameterTransformer.js.map +1 -1
- package/lib/typings/Creator.d.ts +3 -3
- package/lib/typings/Creator.js +2 -2
- package/lib/utils/ExceptionManager.d.ts +64 -64
- package/lib/utils/ExceptionManager.js +112 -112
- package/lib/utils/ExceptionManager.js.map +1 -1
- package/lib/utils/Singleton.d.ts +1 -1
- package/lib/utils/Singleton.js +23 -23
- package/lib/utils/SourceFinder.d.ts +9 -9
- package/lib/utils/SourceFinder.js +238 -238
- package/lib/utils/SourceFinder.js.map +1 -1
- package/package.json +6 -6
|
@@ -1,83 +1,83 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.PlainBody = void 0;
|
|
40
|
-
var common_1 = require("@nestjs/common");
|
|
41
|
-
var get_text_body_1 = require("./internal/get_text_body");
|
|
42
|
-
/**
|
|
43
|
-
* Plain body decorator.
|
|
44
|
-
*
|
|
45
|
-
* `PlainBody` is a decorator function getting full body text from the HTTP request.
|
|
46
|
-
*
|
|
47
|
-
* If you adjust the regular {@link Body} decorator function to the body parameter,
|
|
48
|
-
* you can't get the full body text because the {@link Body} tries to convert the
|
|
49
|
-
* body text to JSON object. Therefore, `@nestia/core` provides this `PlainBody`
|
|
50
|
-
* decorator function to get the full body text.
|
|
51
|
-
*
|
|
52
|
-
* ```typescript
|
|
53
|
-
* \@TypedRoute.Post("memo")
|
|
54
|
-
* public store
|
|
55
|
-
* (
|
|
56
|
-
* \@PlainBody() body: string
|
|
57
|
-
* ): void;
|
|
58
|
-
* ```
|
|
59
|
-
*
|
|
60
|
-
* @return Parameter decorator
|
|
61
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
62
|
-
*/
|
|
63
|
-
exports.PlainBody = (0, common_1.createParamDecorator)(function PlainBody(_data, context) {
|
|
64
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
65
|
-
var request;
|
|
66
|
-
return __generator(this, function (_a) {
|
|
67
|
-
request = context
|
|
68
|
-
.switchToHttp()
|
|
69
|
-
.getRequest();
|
|
70
|
-
if (!isTextPlain(request.headers["content-type"]))
|
|
71
|
-
throw new common_1.BadRequestException("Request body type is not \"text/plain\".");
|
|
72
|
-
return [2 /*return*/, (0, get_text_body_1.get_text_body)(request)];
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
var isTextPlain = function (text) {
|
|
77
|
-
return text !== undefined &&
|
|
78
|
-
text
|
|
79
|
-
.split(";")
|
|
80
|
-
.map(function (str) { return str.trim(); })
|
|
81
|
-
.some(function (str) { return str === "text/plain"; });
|
|
82
|
-
};
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.PlainBody = void 0;
|
|
40
|
+
var common_1 = require("@nestjs/common");
|
|
41
|
+
var get_text_body_1 = require("./internal/get_text_body");
|
|
42
|
+
/**
|
|
43
|
+
* Plain body decorator.
|
|
44
|
+
*
|
|
45
|
+
* `PlainBody` is a decorator function getting full body text from the HTTP request.
|
|
46
|
+
*
|
|
47
|
+
* If you adjust the regular {@link Body} decorator function to the body parameter,
|
|
48
|
+
* you can't get the full body text because the {@link Body} tries to convert the
|
|
49
|
+
* body text to JSON object. Therefore, `@nestia/core` provides this `PlainBody`
|
|
50
|
+
* decorator function to get the full body text.
|
|
51
|
+
*
|
|
52
|
+
* ```typescript
|
|
53
|
+
* \@TypedRoute.Post("memo")
|
|
54
|
+
* public store
|
|
55
|
+
* (
|
|
56
|
+
* \@PlainBody() body: string
|
|
57
|
+
* ): void;
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @return Parameter decorator
|
|
61
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
62
|
+
*/
|
|
63
|
+
exports.PlainBody = (0, common_1.createParamDecorator)(function PlainBody(_data, context) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
65
|
+
var request;
|
|
66
|
+
return __generator(this, function (_a) {
|
|
67
|
+
request = context
|
|
68
|
+
.switchToHttp()
|
|
69
|
+
.getRequest();
|
|
70
|
+
if (!isTextPlain(request.headers["content-type"]))
|
|
71
|
+
throw new common_1.BadRequestException("Request body type is not \"text/plain\".");
|
|
72
|
+
return [2 /*return*/, (0, get_text_body_1.get_text_body)(request)];
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
var isTextPlain = function (text) {
|
|
77
|
+
return text !== undefined &&
|
|
78
|
+
text
|
|
79
|
+
.split(";")
|
|
80
|
+
.map(function (str) { return str.trim(); })
|
|
81
|
+
.some(function (str) { return str === "text/plain"; });
|
|
82
|
+
};
|
|
83
83
|
//# sourceMappingURL=PlainBody.js.map
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
|
|
2
|
-
/**
|
|
3
|
-
* Type safe body decorator.
|
|
4
|
-
*
|
|
5
|
-
* `TypedBody` is a decoratur function getting `application/json` typed data from
|
|
6
|
-
* request body. Also, it validates the request body data type through
|
|
7
|
-
* [typia](https://github.com/samchon/typia) and the validation speed is
|
|
8
|
-
* maximum 15,000x times faster than `class-validator`.
|
|
9
|
-
*
|
|
10
|
-
* For reference, when the request body data is not following the promised type `T`,
|
|
11
|
-
* `BadRequestException` error (status code: 400) would be thrown.
|
|
12
|
-
*
|
|
13
|
-
* @param validator Custom validator if required. Default is `typia.assert()`
|
|
14
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
15
|
-
*/
|
|
16
|
-
export declare function TypedBody<T>(validator?: IRequestBodyValidator<T>): ParameterDecorator;
|
|
1
|
+
import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
|
|
2
|
+
/**
|
|
3
|
+
* Type safe body decorator.
|
|
4
|
+
*
|
|
5
|
+
* `TypedBody` is a decoratur function getting `application/json` typed data from
|
|
6
|
+
* request body. Also, it validates the request body data type through
|
|
7
|
+
* [typia](https://github.com/samchon/typia) and the validation speed is
|
|
8
|
+
* maximum 15,000x times faster than `class-validator`.
|
|
9
|
+
*
|
|
10
|
+
* For reference, when the request body data is not following the promised type `T`,
|
|
11
|
+
* `BadRequestException` error (status code: 400) would be thrown.
|
|
12
|
+
*
|
|
13
|
+
* @param validator Custom validator if required. Default is `typia.assert()`
|
|
14
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
15
|
+
*/
|
|
16
|
+
export declare function TypedBody<T>(validator?: IRequestBodyValidator<T>): ParameterDecorator;
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TypedBody = void 0;
|
|
4
|
-
var common_1 = require("@nestjs/common");
|
|
5
|
-
var typia_1 = require("typia");
|
|
6
|
-
var validate_request_body_1 = require("./internal/validate_request_body");
|
|
7
|
-
/**
|
|
8
|
-
* Type safe body decorator.
|
|
9
|
-
*
|
|
10
|
-
* `TypedBody` is a decoratur function getting `application/json` typed data from
|
|
11
|
-
* request body. Also, it validates the request body data type through
|
|
12
|
-
* [typia](https://github.com/samchon/typia) and the validation speed is
|
|
13
|
-
* maximum 15,000x times faster than `class-validator`.
|
|
14
|
-
*
|
|
15
|
-
* For reference, when the request body data is not following the promised type `T`,
|
|
16
|
-
* `BadRequestException` error (status code: 400) would be thrown.
|
|
17
|
-
*
|
|
18
|
-
* @param validator Custom validator if required. Default is `typia.assert()`
|
|
19
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
20
|
-
*/
|
|
21
|
-
function TypedBody(validator) {
|
|
22
|
-
var checker = (0, validate_request_body_1.validate_request_body)("TypedBody")(validator);
|
|
23
|
-
return (0, common_1.createParamDecorator)(function TypedBody(_unknown, context) {
|
|
24
|
-
var request = context
|
|
25
|
-
.switchToHttp()
|
|
26
|
-
.getRequest();
|
|
27
|
-
if (isApplicationJson(request.headers["content-type"]) === false)
|
|
28
|
-
throw new common_1.BadRequestException("Request body type is not \"application/json\".");
|
|
29
|
-
var error = checker(request.body);
|
|
30
|
-
if (error !== null)
|
|
31
|
-
throw error;
|
|
32
|
-
return request.body;
|
|
33
|
-
})();
|
|
34
|
-
}
|
|
35
|
-
exports.TypedBody = TypedBody;
|
|
36
|
-
Object.assign(TypedBody, typia_1.is);
|
|
37
|
-
Object.assign(TypedBody, typia_1.assert);
|
|
38
|
-
Object.assign(TypedBody, typia_1.validate);
|
|
39
|
-
var isApplicationJson = function (text) {
|
|
40
|
-
return text !== undefined &&
|
|
41
|
-
text
|
|
42
|
-
.split(";")
|
|
43
|
-
.map(function (str) { return str.trim(); })
|
|
44
|
-
.some(function (str) { return str === "application/json"; });
|
|
45
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypedBody = void 0;
|
|
4
|
+
var common_1 = require("@nestjs/common");
|
|
5
|
+
var typia_1 = require("typia");
|
|
6
|
+
var validate_request_body_1 = require("./internal/validate_request_body");
|
|
7
|
+
/**
|
|
8
|
+
* Type safe body decorator.
|
|
9
|
+
*
|
|
10
|
+
* `TypedBody` is a decoratur function getting `application/json` typed data from
|
|
11
|
+
* request body. Also, it validates the request body data type through
|
|
12
|
+
* [typia](https://github.com/samchon/typia) and the validation speed is
|
|
13
|
+
* maximum 15,000x times faster than `class-validator`.
|
|
14
|
+
*
|
|
15
|
+
* For reference, when the request body data is not following the promised type `T`,
|
|
16
|
+
* `BadRequestException` error (status code: 400) would be thrown.
|
|
17
|
+
*
|
|
18
|
+
* @param validator Custom validator if required. Default is `typia.assert()`
|
|
19
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
20
|
+
*/
|
|
21
|
+
function TypedBody(validator) {
|
|
22
|
+
var checker = (0, validate_request_body_1.validate_request_body)("TypedBody")(validator);
|
|
23
|
+
return (0, common_1.createParamDecorator)(function TypedBody(_unknown, context) {
|
|
24
|
+
var request = context
|
|
25
|
+
.switchToHttp()
|
|
26
|
+
.getRequest();
|
|
27
|
+
if (isApplicationJson(request.headers["content-type"]) === false)
|
|
28
|
+
throw new common_1.BadRequestException("Request body type is not \"application/json\".");
|
|
29
|
+
var error = checker(request.body);
|
|
30
|
+
if (error !== null)
|
|
31
|
+
throw error;
|
|
32
|
+
return request.body;
|
|
33
|
+
})();
|
|
34
|
+
}
|
|
35
|
+
exports.TypedBody = TypedBody;
|
|
36
|
+
Object.assign(TypedBody, typia_1.is);
|
|
37
|
+
Object.assign(TypedBody, typia_1.assert);
|
|
38
|
+
Object.assign(TypedBody, typia_1.validate);
|
|
39
|
+
var isApplicationJson = function (text) {
|
|
40
|
+
return text !== undefined &&
|
|
41
|
+
text
|
|
42
|
+
.split(";")
|
|
43
|
+
.map(function (str) { return str.trim(); })
|
|
44
|
+
.some(function (str) { return str === "application/json"; });
|
|
45
|
+
};
|
|
46
46
|
//# sourceMappingURL=TypedBody.js.map
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type safe URL parameter decorator.
|
|
3
|
-
*
|
|
4
|
-
* `TypedParam` is a decorator function getting specific typed parameter from the
|
|
5
|
-
* HTTP request URL. It's almost same with the {@link nest.Param}, but `TypedParam`
|
|
6
|
-
* automatically casts parameter value to be following its type. Beside, the
|
|
7
|
-
* {@link nest.Param} always parses all of the parameters as `string` type.
|
|
8
|
-
*
|
|
9
|
-
* Note that, if you just omit the `type` and `nullable` parameters, then
|
|
10
|
-
* `TypedParam` automatically determines the `type` and `nullable` values
|
|
11
|
-
* just by analyzing the parameter type. Only when you need to specify them
|
|
12
|
-
* are, you want to use the `uuid` type.
|
|
13
|
-
*
|
|
14
|
-
* ```typescript
|
|
15
|
-
* \@TypedRoute.Get("shopping/sales/:id/:no/:paused")
|
|
16
|
-
* public async pause
|
|
17
|
-
* (
|
|
18
|
-
* \@TypedParam("id", "uuid"), id: string, // uuid specification
|
|
19
|
-
* \@TypedParam("no") id: number, // auto casting
|
|
20
|
-
* \@TypedParam("paused") paused: boolean | null // auto casting
|
|
21
|
-
* ): Promise<void>;
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* @param name URL Parameter name
|
|
25
|
-
* @param type If omit, automatically determined by the parameter type.
|
|
26
|
-
* @param nullable If omit, automatically determined by the parameter type.
|
|
27
|
-
* @returns Parameter decorator
|
|
28
|
-
*
|
|
29
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
30
|
-
*/
|
|
31
|
-
export declare function TypedParam(name: string, type?: "boolean" | "number" | "string" | "uuid" | "date", nullable?: false | true): ParameterDecorator;
|
|
1
|
+
/**
|
|
2
|
+
* Type safe URL parameter decorator.
|
|
3
|
+
*
|
|
4
|
+
* `TypedParam` is a decorator function getting specific typed parameter from the
|
|
5
|
+
* HTTP request URL. It's almost same with the {@link nest.Param}, but `TypedParam`
|
|
6
|
+
* automatically casts parameter value to be following its type. Beside, the
|
|
7
|
+
* {@link nest.Param} always parses all of the parameters as `string` type.
|
|
8
|
+
*
|
|
9
|
+
* Note that, if you just omit the `type` and `nullable` parameters, then
|
|
10
|
+
* `TypedParam` automatically determines the `type` and `nullable` values
|
|
11
|
+
* just by analyzing the parameter type. Only when you need to specify them
|
|
12
|
+
* are, you want to use the `uuid` type.
|
|
13
|
+
*
|
|
14
|
+
* ```typescript
|
|
15
|
+
* \@TypedRoute.Get("shopping/sales/:id/:no/:paused")
|
|
16
|
+
* public async pause
|
|
17
|
+
* (
|
|
18
|
+
* \@TypedParam("id", "uuid"), id: string, // uuid specification
|
|
19
|
+
* \@TypedParam("no") id: number, // auto casting
|
|
20
|
+
* \@TypedParam("paused") paused: boolean | null // auto casting
|
|
21
|
+
* ): Promise<void>;
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @param name URL Parameter name
|
|
25
|
+
* @param type If omit, automatically determined by the parameter type.
|
|
26
|
+
* @param nullable If omit, automatically determined by the parameter type.
|
|
27
|
+
* @returns Parameter decorator
|
|
28
|
+
*
|
|
29
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
30
|
+
*/
|
|
31
|
+
export declare function TypedParam(name: string, type?: "boolean" | "number" | "string" | "uuid" | "date", nullable?: false | true): ParameterDecorator;
|
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TypedParam = void 0;
|
|
4
|
-
var common_1 = require("@nestjs/common");
|
|
5
|
-
/**
|
|
6
|
-
* Type safe URL parameter decorator.
|
|
7
|
-
*
|
|
8
|
-
* `TypedParam` is a decorator function getting specific typed parameter from the
|
|
9
|
-
* HTTP request URL. It's almost same with the {@link nest.Param}, but `TypedParam`
|
|
10
|
-
* automatically casts parameter value to be following its type. Beside, the
|
|
11
|
-
* {@link nest.Param} always parses all of the parameters as `string` type.
|
|
12
|
-
*
|
|
13
|
-
* Note that, if you just omit the `type` and `nullable` parameters, then
|
|
14
|
-
* `TypedParam` automatically determines the `type` and `nullable` values
|
|
15
|
-
* just by analyzing the parameter type. Only when you need to specify them
|
|
16
|
-
* are, you want to use the `uuid` type.
|
|
17
|
-
*
|
|
18
|
-
* ```typescript
|
|
19
|
-
* \@TypedRoute.Get("shopping/sales/:id/:no/:paused")
|
|
20
|
-
* public async pause
|
|
21
|
-
* (
|
|
22
|
-
* \@TypedParam("id", "uuid"), id: string, // uuid specification
|
|
23
|
-
* \@TypedParam("no") id: number, // auto casting
|
|
24
|
-
* \@TypedParam("paused") paused: boolean | null // auto casting
|
|
25
|
-
* ): Promise<void>;
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* @param name URL Parameter name
|
|
29
|
-
* @param type If omit, automatically determined by the parameter type.
|
|
30
|
-
* @param nullable If omit, automatically determined by the parameter type.
|
|
31
|
-
* @returns Parameter decorator
|
|
32
|
-
*
|
|
33
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
34
|
-
*/
|
|
35
|
-
function TypedParam(name, type, nullable) {
|
|
36
|
-
function TypedParam(_a, context) {
|
|
37
|
-
var request = context
|
|
38
|
-
.switchToHttp()
|
|
39
|
-
.getRequest();
|
|
40
|
-
var str = request.params[name];
|
|
41
|
-
if (nullable === true && str === "null")
|
|
42
|
-
return null;
|
|
43
|
-
else if (type === "boolean") {
|
|
44
|
-
if (str === "true" || str === "1")
|
|
45
|
-
return true;
|
|
46
|
-
else if (str === "false" || str === "0")
|
|
47
|
-
return false;
|
|
48
|
-
else
|
|
49
|
-
throw new common_1.BadRequestException("Value of the URL parameter '".concat(name, "' is not a boolean."));
|
|
50
|
-
}
|
|
51
|
-
else if (type === "number") {
|
|
52
|
-
var value = Number(str);
|
|
53
|
-
if (isNaN(value))
|
|
54
|
-
throw new common_1.BadRequestException("Value of the URL parameter \"".concat(name, "\" is not a number."));
|
|
55
|
-
return value;
|
|
56
|
-
}
|
|
57
|
-
else if (type === "uuid") {
|
|
58
|
-
if (UUID_PATTERN.test(str) === false)
|
|
59
|
-
throw new common_1.BadRequestException("Value of the URL parameter \"".concat(name, "\" is not a valid UUID."));
|
|
60
|
-
return str;
|
|
61
|
-
}
|
|
62
|
-
else if (type === "date") {
|
|
63
|
-
if (DATE_PATTERN.test(str) === false)
|
|
64
|
-
throw new common_1.BadRequestException("Value of the URL parameter \"".concat(name, "\" is not a valid date."));
|
|
65
|
-
return str;
|
|
66
|
-
}
|
|
67
|
-
else
|
|
68
|
-
return str;
|
|
69
|
-
}
|
|
70
|
-
TypedParam.nullable = !!nullable;
|
|
71
|
-
TypedParam.type = type;
|
|
72
|
-
return (0, common_1.createParamDecorator)(TypedParam)(name);
|
|
73
|
-
}
|
|
74
|
-
exports.TypedParam = TypedParam;
|
|
75
|
-
var UUID_PATTERN = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
|
|
76
|
-
var DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypedParam = void 0;
|
|
4
|
+
var common_1 = require("@nestjs/common");
|
|
5
|
+
/**
|
|
6
|
+
* Type safe URL parameter decorator.
|
|
7
|
+
*
|
|
8
|
+
* `TypedParam` is a decorator function getting specific typed parameter from the
|
|
9
|
+
* HTTP request URL. It's almost same with the {@link nest.Param}, but `TypedParam`
|
|
10
|
+
* automatically casts parameter value to be following its type. Beside, the
|
|
11
|
+
* {@link nest.Param} always parses all of the parameters as `string` type.
|
|
12
|
+
*
|
|
13
|
+
* Note that, if you just omit the `type` and `nullable` parameters, then
|
|
14
|
+
* `TypedParam` automatically determines the `type` and `nullable` values
|
|
15
|
+
* just by analyzing the parameter type. Only when you need to specify them
|
|
16
|
+
* are, you want to use the `uuid` type.
|
|
17
|
+
*
|
|
18
|
+
* ```typescript
|
|
19
|
+
* \@TypedRoute.Get("shopping/sales/:id/:no/:paused")
|
|
20
|
+
* public async pause
|
|
21
|
+
* (
|
|
22
|
+
* \@TypedParam("id", "uuid"), id: string, // uuid specification
|
|
23
|
+
* \@TypedParam("no") id: number, // auto casting
|
|
24
|
+
* \@TypedParam("paused") paused: boolean | null // auto casting
|
|
25
|
+
* ): Promise<void>;
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @param name URL Parameter name
|
|
29
|
+
* @param type If omit, automatically determined by the parameter type.
|
|
30
|
+
* @param nullable If omit, automatically determined by the parameter type.
|
|
31
|
+
* @returns Parameter decorator
|
|
32
|
+
*
|
|
33
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
34
|
+
*/
|
|
35
|
+
function TypedParam(name, type, nullable) {
|
|
36
|
+
function TypedParam(_a, context) {
|
|
37
|
+
var request = context
|
|
38
|
+
.switchToHttp()
|
|
39
|
+
.getRequest();
|
|
40
|
+
var str = request.params[name];
|
|
41
|
+
if (nullable === true && str === "null")
|
|
42
|
+
return null;
|
|
43
|
+
else if (type === "boolean") {
|
|
44
|
+
if (str === "true" || str === "1")
|
|
45
|
+
return true;
|
|
46
|
+
else if (str === "false" || str === "0")
|
|
47
|
+
return false;
|
|
48
|
+
else
|
|
49
|
+
throw new common_1.BadRequestException("Value of the URL parameter '".concat(name, "' is not a boolean."));
|
|
50
|
+
}
|
|
51
|
+
else if (type === "number") {
|
|
52
|
+
var value = Number(str);
|
|
53
|
+
if (isNaN(value))
|
|
54
|
+
throw new common_1.BadRequestException("Value of the URL parameter \"".concat(name, "\" is not a number."));
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
else if (type === "uuid") {
|
|
58
|
+
if (UUID_PATTERN.test(str) === false)
|
|
59
|
+
throw new common_1.BadRequestException("Value of the URL parameter \"".concat(name, "\" is not a valid UUID."));
|
|
60
|
+
return str;
|
|
61
|
+
}
|
|
62
|
+
else if (type === "date") {
|
|
63
|
+
if (DATE_PATTERN.test(str) === false)
|
|
64
|
+
throw new common_1.BadRequestException("Value of the URL parameter \"".concat(name, "\" is not a valid date."));
|
|
65
|
+
return str;
|
|
66
|
+
}
|
|
67
|
+
else
|
|
68
|
+
return str;
|
|
69
|
+
}
|
|
70
|
+
TypedParam.nullable = !!nullable;
|
|
71
|
+
TypedParam.type = type;
|
|
72
|
+
return (0, common_1.createParamDecorator)(TypedParam)(name);
|
|
73
|
+
}
|
|
74
|
+
exports.TypedParam = TypedParam;
|
|
75
|
+
var UUID_PATTERN = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
|
|
76
|
+
var DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
|
|
77
77
|
//# sourceMappingURL=TypedParam.js.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type safe URL query decorator.
|
|
3
|
-
*
|
|
4
|
-
* `TypedQuery` is a decorator function that can parse URL query string. It is almost
|
|
5
|
-
* same with {@link nest.Query}, but it can automatically cast property type following
|
|
6
|
-
* its DTO definition. Also, `TypedQuery` performs type validation.
|
|
7
|
-
*
|
|
8
|
-
* For referecen, when URL query parameters are different with their promised
|
|
9
|
-
* type `T`, `BadRequestException` error (status code: 400) would be thrown.
|
|
10
|
-
*
|
|
11
|
-
* @returns Parameter decorator
|
|
12
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
13
|
-
*/
|
|
14
|
-
export declare function TypedQuery<T>(decoder?: (params: URLSearchParams) => T): ParameterDecorator;
|
|
1
|
+
/**
|
|
2
|
+
* Type safe URL query decorator.
|
|
3
|
+
*
|
|
4
|
+
* `TypedQuery` is a decorator function that can parse URL query string. It is almost
|
|
5
|
+
* same with {@link nest.Query}, but it can automatically cast property type following
|
|
6
|
+
* its DTO definition. Also, `TypedQuery` performs type validation.
|
|
7
|
+
*
|
|
8
|
+
* For referecen, when URL query parameters are different with their promised
|
|
9
|
+
* type `T`, `BadRequestException` error (status code: 400) would be thrown.
|
|
10
|
+
*
|
|
11
|
+
* @returns Parameter decorator
|
|
12
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
13
|
+
*/
|
|
14
|
+
export declare function TypedQuery<T>(decoder?: (params: URLSearchParams) => T): ParameterDecorator;
|