@nestia/core 1.1.0 → 1.1.2-dev.20230503

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.
Files changed (101) hide show
  1. package/lib/decorators/DynamicModule.d.ts +26 -23
  2. package/lib/decorators/DynamicModule.js +103 -103
  3. package/lib/decorators/DynamicModule.js.map +1 -1
  4. package/lib/decorators/EncryptedBody.d.ts +23 -23
  5. package/lib/decorators/EncryptedBody.js +125 -125
  6. package/lib/decorators/EncryptedController.d.ts +31 -31
  7. package/lib/decorators/EncryptedController.js +41 -41
  8. package/lib/decorators/EncryptedModule.d.ts +52 -49
  9. package/lib/decorators/EncryptedModule.js +161 -161
  10. package/lib/decorators/EncryptedModule.js.map +1 -1
  11. package/lib/decorators/EncryptedRoute.d.ts +78 -78
  12. package/lib/decorators/EncryptedRoute.js +216 -216
  13. package/lib/decorators/PlainBody.d.ts +22 -22
  14. package/lib/decorators/PlainBody.js +82 -82
  15. package/lib/decorators/TypedBody.d.ts +16 -16
  16. package/lib/decorators/TypedBody.js +94 -94
  17. package/lib/decorators/TypedParam.d.ts +31 -31
  18. package/lib/decorators/TypedParam.js +68 -65
  19. package/lib/decorators/TypedParam.js.map +1 -1
  20. package/lib/decorators/TypedQuery.d.ts +14 -14
  21. package/lib/decorators/TypedQuery.js +124 -103
  22. package/lib/decorators/TypedQuery.js.map +1 -1
  23. package/lib/decorators/TypedRoute.d.ts +72 -72
  24. package/lib/decorators/TypedRoute.js +185 -185
  25. package/lib/decorators/internal/EncryptedConstant.d.ts +1 -1
  26. package/lib/decorators/internal/EncryptedConstant.js +7 -7
  27. package/lib/decorators/internal/TransformError.d.ts +1 -1
  28. package/lib/decorators/internal/TransformError.js +10 -10
  29. package/lib/decorators/internal/TransformError.js.map +1 -1
  30. package/lib/decorators/internal/get_path_and_stringify.d.ts +1 -1
  31. package/lib/decorators/internal/get_path_and_stringify.js +78 -78
  32. package/lib/decorators/internal/headers_to_object.d.ts +3 -3
  33. package/lib/decorators/internal/headers_to_object.js +49 -49
  34. package/lib/decorators/internal/load_controller.d.ts +5 -2
  35. package/lib/decorators/internal/load_controller.js +152 -151
  36. package/lib/decorators/internal/load_controller.js.map +1 -1
  37. package/lib/decorators/internal/route_error.d.ts +2 -2
  38. package/lib/decorators/internal/route_error.js +86 -86
  39. package/lib/decorators/internal/validate_request_body.d.ts +2 -2
  40. package/lib/decorators/internal/validate_request_body.js +57 -57
  41. package/lib/index.d.ts +3 -3
  42. package/lib/index.js +31 -31
  43. package/lib/module.d.ts +12 -12
  44. package/lib/module.js +28 -28
  45. package/lib/options/INestiaTransformOptions.d.ts +4 -4
  46. package/lib/options/INestiaTransformOptions.js +2 -2
  47. package/lib/options/INestiaTransformProject.d.ts +5 -5
  48. package/lib/options/INestiaTransformProject.js +2 -2
  49. package/lib/options/IRequestBodyValidator.d.ts +16 -16
  50. package/lib/options/IRequestBodyValidator.js +2 -2
  51. package/lib/options/IResponseBodyStringifier.d.ts +20 -20
  52. package/lib/options/IResponseBodyStringifier.js +2 -2
  53. package/lib/programmers/TypedBodyProgrammer.d.ts +5 -5
  54. package/lib/programmers/TypedBodyProgrammer.js +47 -45
  55. package/lib/programmers/TypedBodyProgrammer.js.map +1 -1
  56. package/lib/programmers/TypedParamProgrammer.d.ts +5 -5
  57. package/lib/programmers/TypedParamProgrammer.js +107 -107
  58. package/lib/programmers/TypedQueryProgrammer.d.ts +5 -5
  59. package/lib/programmers/TypedQueryProgrammer.js +263 -260
  60. package/lib/programmers/TypedQueryProgrammer.js.map +1 -1
  61. package/lib/programmers/TypedRouteProgrammer.d.ts +5 -5
  62. package/lib/programmers/TypedRouteProgrammer.js +49 -47
  63. package/lib/programmers/TypedRouteProgrammer.js.map +1 -1
  64. package/lib/transform.d.ts +3 -3
  65. package/lib/transform.js +20 -20
  66. package/lib/transformers/FileTransformer.d.ts +5 -5
  67. package/lib/transformers/FileTransformer.js +32 -32
  68. package/lib/transformers/MethodDecoratorTransformer.d.ts +5 -5
  69. package/lib/transformers/MethodDecoratorTransformer.js +87 -87
  70. package/lib/transformers/MethodDecoratorTransformer.js.map +1 -1
  71. package/lib/transformers/MethodTransformer.d.ts +5 -5
  72. package/lib/transformers/MethodTransformer.js +54 -54
  73. package/lib/transformers/NodeTransformer.d.ts +5 -5
  74. package/lib/transformers/NodeTransformer.js +20 -20
  75. package/lib/transformers/ParameterDecoratorTransformer.d.ts +5 -5
  76. package/lib/transformers/ParameterDecoratorTransformer.js +65 -65
  77. package/lib/transformers/ParameterDecoratorTransformer.js.map +1 -1
  78. package/lib/transformers/ParameterTransformer.d.ts +5 -5
  79. package/lib/transformers/ParameterTransformer.js +33 -33
  80. package/lib/typings/Creator.d.ts +3 -3
  81. package/lib/typings/Creator.js +2 -2
  82. package/lib/utils/ExceptionManager.d.ts +64 -64
  83. package/lib/utils/ExceptionManager.js +112 -112
  84. package/lib/utils/Singleton.d.ts +1 -1
  85. package/lib/utils/Singleton.js +23 -23
  86. package/lib/utils/SourceFinder.d.ts +9 -0
  87. package/lib/utils/SourceFinder.js +239 -0
  88. package/lib/utils/SourceFinder.js.map +1 -0
  89. package/package.json +7 -7
  90. package/src/decorators/DynamicModule.ts +1 -1
  91. package/src/decorators/EncryptedModule.ts +1 -1
  92. package/src/decorators/TypedParam.ts +4 -1
  93. package/src/decorators/TypedQuery.ts +27 -4
  94. package/src/decorators/internal/TransformError.ts +1 -1
  95. package/src/decorators/internal/load_controller.ts +32 -25
  96. package/src/programmers/TypedBodyProgrammer.ts +2 -1
  97. package/src/programmers/TypedQueryProgrammer.ts +3 -1
  98. package/src/programmers/TypedRouteProgrammer.ts +2 -1
  99. package/src/transformers/MethodDecoratorTransformer.ts +1 -2
  100. package/src/transformers/ParameterDecoratorTransformer.ts +3 -3
  101. package/src/utils/SourceFinder.ts +60 -0
@@ -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
- var __importDefault = (this && this.__importDefault) || function (mod) {
39
- return (mod && mod.__esModule) ? mod : { "default": mod };
40
- };
41
- Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.PlainBody = void 0;
43
- var common_1 = require("@nestjs/common");
44
- var raw_body_1 = __importDefault(require("raw-body"));
45
- /**
46
- * Plain body decorator.
47
- *
48
- * `PlainBody` is a decorator function getting full body text from the HTTP request.
49
- *
50
- * If you adjust the regular {@link Body} decorator function to the body parameter,
51
- * you can't get the full body text because the {@link Body} tries to convert the
52
- * body text to JSON object. Therefore, `@nestia/core` provides this `PlainBody`
53
- * decorator function to get the full body text.
54
- *
55
- * ```typescript
56
- * \@TypedRoute.Post("memo")
57
- * public store
58
- * (
59
- * \@PlainBody() body: string
60
- * ): void;
61
- * ```
62
- *
63
- * @return Parameter decorator
64
- * @author Jeongho Nam - https://github.com/samchon
65
- */
66
- exports.PlainBody = (0, common_1.createParamDecorator)(function PlainBody(_data, context) {
67
- return __awaiter(this, void 0, void 0, function () {
68
- var request, body;
69
- return __generator(this, function (_a) {
70
- switch (_a.label) {
71
- case 0:
72
- request = context.switchToHttp().getRequest();
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
- });
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.PlainBody = void 0;
43
+ var common_1 = require("@nestjs/common");
44
+ var raw_body_1 = __importDefault(require("raw-body"));
45
+ /**
46
+ * Plain body decorator.
47
+ *
48
+ * `PlainBody` is a decorator function getting full body text from the HTTP request.
49
+ *
50
+ * If you adjust the regular {@link Body} decorator function to the body parameter,
51
+ * you can't get the full body text because the {@link Body} tries to convert the
52
+ * body text to JSON object. Therefore, `@nestia/core` provides this `PlainBody`
53
+ * decorator function to get the full body text.
54
+ *
55
+ * ```typescript
56
+ * \@TypedRoute.Post("memo")
57
+ * public store
58
+ * (
59
+ * \@PlainBody() body: string
60
+ * ): void;
61
+ * ```
62
+ *
63
+ * @return Parameter decorator
64
+ * @author Jeongho Nam - https://github.com/samchon
65
+ */
66
+ exports.PlainBody = (0, common_1.createParamDecorator)(function PlainBody(_data, context) {
67
+ return __awaiter(this, void 0, void 0, function () {
68
+ var request, body;
69
+ return __generator(this, function (_a) {
70
+ switch (_a.label) {
71
+ case 0:
72
+ request = context.switchToHttp().getRequest();
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
+ });
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,95 +1,95 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.TypedBody = void 0;
43
- var common_1 = require("@nestjs/common");
44
- var raw_body_1 = __importDefault(require("raw-body"));
45
- var typia_1 = require("typia");
46
- var validate_request_body_1 = require("./internal/validate_request_body");
47
- /**
48
- * Type safe body decorator.
49
- *
50
- * `TypedBody` is a decoratur function getting `application/json` typed data from
51
- * request body. Also, it validates the request body data type through
52
- * [typia](https://github.com/samchon/typia) and the validation speed is
53
- * maximum 15,000x times faster than `class-validator`.
54
- *
55
- * For reference, when the request body data is not following the promised type `T`,
56
- * `BadRequestException` error (status code: 400) would be thrown.
57
- *
58
- * @param validator Custom validator if required. Default is `typia.assert()`
59
- * @author Jeongho Nam - https://github.com/samchon
60
- */
61
- function TypedBody(validator) {
62
- var checker = (0, validate_request_body_1.validate_request_body)("TypedBody")(validator);
63
- return (0, common_1.createParamDecorator)(function TypedBody(_unknown, context) {
64
- return __awaiter(this, void 0, void 0, function () {
65
- var request, data, _a, _b, _c;
66
- return __generator(this, function (_d) {
67
- switch (_d.label) {
68
- case 0:
69
- request = context.switchToHttp().getRequest();
70
- if (!request.is("application/json")) {
71
- throw new common_1.BadRequestException("Request body is not the application/json.");
72
- }
73
- if (!request.body) return [3 /*break*/, 1];
74
- _a = request.body;
75
- return [3 /*break*/, 3];
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
- });
89
- })();
90
- }
91
- exports.TypedBody = TypedBody;
92
- Object.assign(TypedBody, typia_1.is);
93
- Object.assign(TypedBody, typia_1.assert);
94
- Object.assign(TypedBody, typia_1.validate);
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
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.TypedBody = void 0;
43
+ var common_1 = require("@nestjs/common");
44
+ var raw_body_1 = __importDefault(require("raw-body"));
45
+ var typia_1 = require("typia");
46
+ var validate_request_body_1 = require("./internal/validate_request_body");
47
+ /**
48
+ * Type safe body decorator.
49
+ *
50
+ * `TypedBody` is a decoratur function getting `application/json` typed data from
51
+ * request body. Also, it validates the request body data type through
52
+ * [typia](https://github.com/samchon/typia) and the validation speed is
53
+ * maximum 15,000x times faster than `class-validator`.
54
+ *
55
+ * For reference, when the request body data is not following the promised type `T`,
56
+ * `BadRequestException` error (status code: 400) would be thrown.
57
+ *
58
+ * @param validator Custom validator if required. Default is `typia.assert()`
59
+ * @author Jeongho Nam - https://github.com/samchon
60
+ */
61
+ function TypedBody(validator) {
62
+ var checker = (0, validate_request_body_1.validate_request_body)("TypedBody")(validator);
63
+ return (0, common_1.createParamDecorator)(function TypedBody(_unknown, context) {
64
+ return __awaiter(this, void 0, void 0, function () {
65
+ var request, data, _a, _b, _c;
66
+ return __generator(this, function (_d) {
67
+ switch (_d.label) {
68
+ case 0:
69
+ request = context.switchToHttp().getRequest();
70
+ if (!request.is("application/json")) {
71
+ throw new common_1.BadRequestException("Request body is not the application/json.");
72
+ }
73
+ if (!request.body) return [3 /*break*/, 1];
74
+ _a = request.body;
75
+ return [3 /*break*/, 3];
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
+ });
89
+ })();
90
+ }
91
+ exports.TypedBody = TypedBody;
92
+ Object.assign(TypedBody, typia_1.is);
93
+ Object.assign(TypedBody, typia_1.assert);
94
+ Object.assign(TypedBody, typia_1.validate);
95
95
  //# 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", 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", nullable?: false | true): ParameterDecorator;
@@ -1,66 +1,69 @@
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
- return (0, common_1.createParamDecorator)(function TypedParam(_a, ctx) {
37
- var request = ctx.switchToHttp().getRequest();
38
- var str = request.params[name];
39
- if (nullable === true && str === "null")
40
- return null;
41
- else if (type === "boolean") {
42
- if (str === "true" || str === "1")
43
- return true;
44
- else if (str === "false" || str === "0")
45
- return false;
46
- else
47
- throw new common_1.BadRequestException("Value of the URL parameter '".concat(name, "' is not a boolean."));
48
- }
49
- else if (type === "number") {
50
- var value = Number(str);
51
- if (isNaN(value))
52
- throw new common_1.BadRequestException("Value of the URL parameter \"".concat(name, "\" is not a number."));
53
- return value;
54
- }
55
- else if (type === "uuid") {
56
- if (UUID_PATTERN.test(str) === false)
57
- throw new common_1.BadRequestException("Value of the URL parameter \"".concat(name, "\" is not a valid UUID."));
58
- return str;
59
- }
60
- else
61
- return str;
62
- })(name);
63
- }
64
- exports.TypedParam = TypedParam;
65
- 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;
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
+ var deco = (0, common_1.createParamDecorator)(function TypedParam(_a, ctx) {
37
+ var request = ctx.switchToHttp().getRequest();
38
+ var str = request.params[name];
39
+ if (nullable === true && str === "null")
40
+ return null;
41
+ else if (type === "boolean") {
42
+ if (str === "true" || str === "1")
43
+ return true;
44
+ else if (str === "false" || str === "0")
45
+ return false;
46
+ else
47
+ throw new common_1.BadRequestException("Value of the URL parameter '".concat(name, "' is not a boolean."));
48
+ }
49
+ else if (type === "number") {
50
+ var value = Number(str);
51
+ if (isNaN(value))
52
+ throw new common_1.BadRequestException("Value of the URL parameter \"".concat(name, "\" is not a number."));
53
+ return value;
54
+ }
55
+ else if (type === "uuid") {
56
+ if (UUID_PATTERN.test(str) === false)
57
+ throw new common_1.BadRequestException("Value of the URL parameter \"".concat(name, "\" is not a valid UUID."));
58
+ return str;
59
+ }
60
+ else
61
+ return str;
62
+ })(name);
63
+ deco.nullable = !!nullable;
64
+ deco.type = type;
65
+ return deco;
66
+ }
67
+ exports.TypedParam = TypedParam;
68
+ 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;
66
69
  //# sourceMappingURL=TypedParam.js.map
@@ -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,OAAO,IAAA,6BAAoB,EAAC,SAAS,UAAU,CAC3C,EAAO,EACP,GAAqB;QAErB,IAAM,OAAO,GAAoB,GAAG,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;QACjE,IAAM,GAAG,GAAW,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEzC,IAAI,QAAQ,KAAK,IAAI,IAAI,GAAG,KAAK,MAAM;YAAE,OAAO,IAAI,CAAC;aAChD,IAAI,IAAI,KAAK,SAAS,EAAE;YACzB,IAAI,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,GAAG;gBAAE,OAAO,IAAI,CAAC;iBAC1C,IAAI,GAAG,KAAK,OAAO,IAAI,GAAG,KAAK,GAAG;gBAAE,OAAO,KAAK,CAAC;;gBAElD,MAAM,IAAI,4BAAmB,CACzB,sCAA+B,IAAI,wBAAqB,CAC3D,CAAC;SACT;aAAM,IAAI,IAAI,KAAK,QAAQ,EAAE;YAC1B,IAAM,KAAK,GAAW,MAAM,CAAC,GAAG,CAAC,CAAC;YAClC,IAAI,KAAK,CAAC,KAAK,CAAC;gBACZ,MAAM,IAAI,4BAAmB,CACzB,uCAA+B,IAAI,wBAAoB,CAC1D,CAAC;YACN,OAAO,KAAK,CAAC;SAChB;aAAM,IAAI,IAAI,KAAK,MAAM,EAAE;YACxB,IAAI,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,KAAK;gBAChC,MAAM,IAAI,4BAAmB,CACzB,uCAA+B,IAAI,4BAAwB,CAC9D,CAAC;YACN,OAAO,GAAG,CAAC;SACd;;YAAM,OAAO,GAAG,CAAC;IACtB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AACb,CAAC;AAnCD,gCAmCC;AAED,IAAM,YAAY,GACd,qHAAqH,CAAC"}
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,IAAM,IAAI,GAAG,IAAA,6BAAoB,EAAC,SAAS,UAAU,CACjD,EAAO,EACP,GAAqB;QAErB,IAAM,OAAO,GAAoB,GAAG,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;QACjE,IAAM,GAAG,GAAW,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEzC,IAAI,QAAQ,KAAK,IAAI,IAAI,GAAG,KAAK,MAAM;YAAE,OAAO,IAAI,CAAC;aAChD,IAAI,IAAI,KAAK,SAAS,EAAE;YACzB,IAAI,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,GAAG;gBAAE,OAAO,IAAI,CAAC;iBAC1C,IAAI,GAAG,KAAK,OAAO,IAAI,GAAG,KAAK,GAAG;gBAAE,OAAO,KAAK,CAAC;;gBAElD,MAAM,IAAI,4BAAmB,CACzB,sCAA+B,IAAI,wBAAqB,CAC3D,CAAC;SACT;aAAM,IAAI,IAAI,KAAK,QAAQ,EAAE;YAC1B,IAAM,KAAK,GAAW,MAAM,CAAC,GAAG,CAAC,CAAC;YAClC,IAAI,KAAK,CAAC,KAAK,CAAC;gBACZ,MAAM,IAAI,4BAAmB,CACzB,uCAA+B,IAAI,wBAAoB,CAC1D,CAAC;YACN,OAAO,KAAK,CAAC;SAChB;aAAM,IAAI,IAAI,KAAK,MAAM,EAAE;YACxB,IAAI,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,KAAK;gBAChC,MAAM,IAAI,4BAAmB,CACzB,uCAA+B,IAAI,4BAAwB,CAC9D,CAAC;YACN,OAAO,GAAG,CAAC;SACd;;YAAM,OAAO,GAAG,CAAC;IACtB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACR,IAAY,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC;IACnC,IAAY,CAAC,IAAI,GAAG,IAAI,CAAC;IAC1B,OAAO,IAAI,CAAC;AAChB,CAAC;AAtCD,gCAsCC;AAED,IAAM,YAAY,GACd,qHAAqH,CAAC"}
@@ -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;