@nestia/core 1.0.18 → 1.1.0-dev.20230413
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 -34
- package/lib/decorators/DynamicModule.d.ts +23 -23
- package/lib/decorators/DynamicModule.js +103 -103
- package/lib/decorators/EncryptedBody.d.ts +23 -23
- package/lib/decorators/EncryptedBody.js +125 -125
- package/lib/decorators/EncryptedController.d.ts +31 -31
- package/lib/decorators/EncryptedController.js +41 -41
- package/lib/decorators/EncryptedModule.d.ts +49 -49
- package/lib/decorators/EncryptedModule.js +161 -161
- package/lib/decorators/EncryptedRoute.d.ts +78 -78
- package/lib/decorators/EncryptedRoute.js +216 -216
- 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 +94 -94
- package/lib/decorators/TypedParam.d.ts +25 -25
- package/lib/decorators/TypedParam.js +61 -61
- package/lib/decorators/TypedQuery.d.ts +14 -14
- package/lib/decorators/TypedQuery.js +99 -99
- 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/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 +78 -78
- 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 +2 -2
- 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 +86 -86
- package/lib/decorators/internal/validate_request_body.d.ts +2 -2
- package/lib/decorators/internal/validate_request_body.js +57 -57
- 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 +45 -45
- package/lib/programmers/TypedQueryProgrammer.d.ts +5 -5
- package/lib/programmers/TypedQueryProgrammer.js +260 -165
- package/lib/programmers/TypedQueryProgrammer.js.map +1 -1
- package/lib/programmers/TypedRouteProgrammer.d.ts +5 -5
- package/lib/programmers/TypedRouteProgrammer.js +47 -47
- package/lib/transform.d.ts +3 -3
- package/lib/transform.js +20 -20
- package/lib/transformers/FileTransformer.d.ts +5 -5
- package/lib/transformers/FileTransformer.js +32 -32
- package/lib/transformers/MethodDecoratorTransformer.d.ts +5 -5
- package/lib/transformers/MethodDecoratorTransformer.js +87 -87
- package/lib/transformers/MethodTransformer.d.ts +5 -5
- package/lib/transformers/MethodTransformer.js +54 -54
- package/lib/transformers/MethodTransformer.js.map +1 -1
- package/lib/transformers/NodeTransformer.d.ts +5 -5
- package/lib/transformers/NodeTransformer.js +20 -20
- package/lib/transformers/ParameterDecoratorTransformer.d.ts +5 -5
- package/lib/transformers/ParameterDecoratorTransformer.js +53 -53
- package/lib/transformers/ParameterTransformer.d.ts +5 -5
- package/lib/transformers/ParameterTransformer.js +33 -33
- 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/Singleton.d.ts +1 -1
- package/lib/utils/Singleton.js +23 -23
- package/package.json +8 -9
- package/src/decorators/TypedQuery.ts +10 -8
- package/src/programmers/TypedQueryProgrammer.ts +104 -33
- package/src/transformers/MethodTransformer.ts +1 -1
- package/src/transformers/ParameterTransformer.ts +1 -1
- package/lib/executable/core.d.ts +0 -2
- package/lib/executable/core.js +0 -124
- package/lib/executable/core.js.map +0 -1
- package/lib/executable/internal/ArgumentParser.d.ts +0 -9
- package/lib/executable/internal/ArgumentParser.js +0 -256
- package/lib/executable/internal/ArgumentParser.js.map +0 -1
- package/lib/executable/internal/CommandExecutor.d.ts +0 -3
- package/lib/executable/internal/CommandExecutor.js +0 -17
- package/lib/executable/internal/CommandExecutor.js.map +0 -1
- package/lib/executable/internal/FileRetriever.d.ts +0 -5
- package/lib/executable/internal/FileRetriever.js +0 -109
- package/lib/executable/internal/FileRetriever.js.map +0 -1
- package/lib/executable/internal/PackageManager.d.ts +0 -27
- package/lib/executable/internal/PackageManager.js +0 -126
- package/lib/executable/internal/PackageManager.js.map +0 -1
- package/lib/executable/internal/PluginConfigurator.d.ts +0 -5
- package/lib/executable/internal/PluginConfigurator.js +0 -145
- package/lib/executable/internal/PluginConfigurator.js.map +0 -1
- package/src/executable/core.ts +0 -70
- package/src/executable/internal/ArgumentParser.ts +0 -156
- package/src/executable/internal/CommandExecutor.ts +0 -8
- package/src/executable/internal/FileRetriever.ts +0 -33
- package/src/executable/internal/PackageManager.ts +0 -92
- package/src/executable/internal/PluginConfigurator.ts +0 -130
package/README.md
CHANGED
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
|
|
8
8
|
Super-fast validation decorators for NestJS.
|
|
9
9
|
|
|
10
|
-
-
|
|
11
|
-
-
|
|
10
|
+
- 20,000x faster request body validation
|
|
11
|
+
- 200x faster JSON response, even type safe
|
|
12
12
|
- Do not need DTO class definition, just fine with interface
|
|
13
13
|
|
|
14
|
-
`@nestia/core` is a transformer library of NestJS, supporting super-fast validation decorators, by wrapping [typia](https://github.com/samchon/typia). Comparing validation speed with `class-validator`, [typia](https://github.com/samchon/typia) is maximum **
|
|
14
|
+
`@nestia/core` is a transformer library of NestJS, supporting super-fast validation decorators, by wrapping [typia](https://github.com/samchon/typia). Comparing validation speed with `class-validator`, [typia](https://github.com/samchon/typia) is maximum **20,000x faster** and it is even much safer.
|
|
15
15
|
|
|
16
16
|
Furthermore, `@nestia/core` can use pure interface typed DTO with **only one line**. With `@nestia/core`, you don't need any extra dedication like defining JSON schema (`@nestjs/swagger`), or using class definition with decorator function calls (`class-validator`). Just enjoy the superfast decorators with pure TypeScript type.
|
|
17
17
|
|
|
@@ -29,7 +29,7 @@ export class BbsArticlesController {
|
|
|
29
29
|
* @param inupt Content to store
|
|
30
30
|
* @returns Newly archived article
|
|
31
31
|
*/
|
|
32
|
-
@TypedRoute.Post() //
|
|
32
|
+
@TypedRoute.Post() // 200x faster and safer JSON serialization
|
|
33
33
|
public async store(
|
|
34
34
|
@TypedBody() input: IBbsArticle.IStore // super-fast validator
|
|
35
35
|
): Promise<IBbsArticle>;
|
|
@@ -51,38 +51,11 @@ Just run above command, then boilerplate project would be constructed.
|
|
|
51
51
|
|
|
52
52
|
### Setup Wizard
|
|
53
53
|
```bash
|
|
54
|
-
|
|
54
|
+
npm install --save-dev nestia
|
|
55
55
|
npx nestia setup
|
|
56
|
-
|
|
57
|
-
# setup @nestia/core only
|
|
58
|
-
npx @nestia/core setup
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
Just type `npx nestia setup`, that's all.
|
|
62
|
-
|
|
63
|
-
If you've installed [ttypescript](https://github.com/cevek/ttypescript) during setup, you should compile `@nestia/core` utilization code through `ttsc` command, instead of `tsc`.
|
|
64
|
-
|
|
65
|
-
```bash
|
|
66
|
-
# COMPILE THROUGH TTYPESCRIPT
|
|
67
|
-
npx ttsc
|
|
68
|
-
|
|
69
|
-
# RUN TS-NODE WITH TTYPESCRIPT
|
|
70
|
-
npx ts-node -C ttypescript src/index.ts
|
|
71
56
|
```
|
|
72
57
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
By the way, when using `@nest/cli`, you must just choose [ts-patch](https://github.com/nonara/ts-patch).
|
|
76
|
-
|
|
77
|
-
```bash
|
|
78
|
-
# USE ORIGINAL TSC COMMAND
|
|
79
|
-
tsc
|
|
80
|
-
npx ts-node src/index.ts
|
|
81
|
-
|
|
82
|
-
# HOWEVER, WHENVER UPDATE
|
|
83
|
-
npm install --save-dev typescript@latest
|
|
84
|
-
npm run prepare
|
|
85
|
-
```
|
|
58
|
+
Just type above two commands, that's all.
|
|
86
59
|
|
|
87
60
|
### Manual Setup
|
|
88
61
|
If you want to install and configure `@nestia/core` manually, read [Guide Documents - Setup](https://github.com/samchon/nestia/wiki/Setup).
|
|
@@ -105,7 +78,7 @@ export class BbsArticlesController {
|
|
|
105
78
|
* @param inupt Content to store
|
|
106
79
|
* @returns Newly archived article
|
|
107
80
|
*/
|
|
108
|
-
@TypedRoute.Put(":id") //
|
|
81
|
+
@TypedRoute.Put(":id") // 200x faster and safer JSON serialization
|
|
109
82
|
public async store(
|
|
110
83
|
@TypedParam("section", "string") section: string,
|
|
111
84
|
@TypedParam("id", "uuid") id: string,
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { ModuleMetadata } from "@nestjs/common/interfaces";
|
|
2
|
-
/**
|
|
3
|
-
* Dynamic module.
|
|
4
|
-
*
|
|
5
|
-
* `DynamicModule` is a namespace wrapping a convenient function, which can load
|
|
6
|
-
* controller classes dynamically just by specifying their directory path.
|
|
7
|
-
*
|
|
8
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
9
|
-
*/
|
|
10
|
-
export declare namespace DynamicModule {
|
|
11
|
-
/**
|
|
12
|
-
* Mount dynamic module.
|
|
13
|
-
*
|
|
14
|
-
* Constructs a module instance with directory path of controller classes.
|
|
15
|
-
*
|
|
16
|
-
* Every controller classes in the target directory would be dynamically mounted.
|
|
17
|
-
*
|
|
18
|
-
* @param path Path of controllers
|
|
19
|
-
* @param metadata Addtional metadata except controllers
|
|
20
|
-
* @returns module instance
|
|
21
|
-
*/
|
|
22
|
-
function mount(path: string, metadata?: Omit<ModuleMetadata, "controllers">): Promise<object>;
|
|
23
|
-
}
|
|
1
|
+
import { ModuleMetadata } from "@nestjs/common/interfaces";
|
|
2
|
+
/**
|
|
3
|
+
* Dynamic module.
|
|
4
|
+
*
|
|
5
|
+
* `DynamicModule` is a namespace wrapping a convenient function, which can load
|
|
6
|
+
* controller classes dynamically just by specifying their directory path.
|
|
7
|
+
*
|
|
8
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
9
|
+
*/
|
|
10
|
+
export declare namespace DynamicModule {
|
|
11
|
+
/**
|
|
12
|
+
* Mount dynamic module.
|
|
13
|
+
*
|
|
14
|
+
* Constructs a module instance with directory path of controller classes.
|
|
15
|
+
*
|
|
16
|
+
* Every controller classes in the target directory would be dynamically mounted.
|
|
17
|
+
*
|
|
18
|
+
* @param path Path of controllers
|
|
19
|
+
* @param metadata Addtional metadata except controllers
|
|
20
|
+
* @returns module instance
|
|
21
|
+
*/
|
|
22
|
+
function mount(path: string, metadata?: Omit<ModuleMetadata, "controllers">): Promise<object>;
|
|
23
|
+
}
|
|
@@ -1,104 +1,104 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
14
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
15
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
16
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
17
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
18
|
-
};
|
|
19
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
20
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
21
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
22
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
23
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
24
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
25
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
29
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
30
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
31
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
32
|
-
function step(op) {
|
|
33
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
34
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
35
|
-
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;
|
|
36
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
37
|
-
switch (op[0]) {
|
|
38
|
-
case 0: case 1: t = op; break;
|
|
39
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
40
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
41
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
42
|
-
default:
|
|
43
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
44
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
45
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
46
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
47
|
-
if (t[2]) _.ops.pop();
|
|
48
|
-
_.trys.pop(); continue;
|
|
49
|
-
}
|
|
50
|
-
op = body.call(thisArg, _);
|
|
51
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
52
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
56
|
-
exports.DynamicModule = void 0;
|
|
57
|
-
var common_1 = require("@nestjs/common");
|
|
58
|
-
var load_controller_1 = require("./internal/load_controller");
|
|
59
|
-
/**
|
|
60
|
-
* Dynamic module.
|
|
61
|
-
*
|
|
62
|
-
* `DynamicModule` is a namespace wrapping a convenient function, which can load
|
|
63
|
-
* controller classes dynamically just by specifying their directory path.
|
|
64
|
-
*
|
|
65
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
66
|
-
*/
|
|
67
|
-
var DynamicModule;
|
|
68
|
-
(function (DynamicModule) {
|
|
69
|
-
/**
|
|
70
|
-
* Mount dynamic module.
|
|
71
|
-
*
|
|
72
|
-
* Constructs a module instance with directory path of controller classes.
|
|
73
|
-
*
|
|
74
|
-
* Every controller classes in the target directory would be dynamically mounted.
|
|
75
|
-
*
|
|
76
|
-
* @param path Path of controllers
|
|
77
|
-
* @param metadata Addtional metadata except controllers
|
|
78
|
-
* @returns module instance
|
|
79
|
-
*/
|
|
80
|
-
function mount(path, metadata) {
|
|
81
|
-
if (metadata === void 0) { metadata = {}; }
|
|
82
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
83
|
-
var controllers, NestiaModule;
|
|
84
|
-
return __generator(this, function (_a) {
|
|
85
|
-
switch (_a.label) {
|
|
86
|
-
case 0: return [4 /*yield*/, (0, load_controller_1.load_controllers)(path)];
|
|
87
|
-
case 1:
|
|
88
|
-
controllers = _a.sent();
|
|
89
|
-
NestiaModule = /** @class */ (function () {
|
|
90
|
-
function NestiaModule() {
|
|
91
|
-
}
|
|
92
|
-
NestiaModule = __decorate([
|
|
93
|
-
(0, common_1.Module)(__assign(__assign({}, metadata), { controllers: controllers }))
|
|
94
|
-
], NestiaModule);
|
|
95
|
-
return NestiaModule;
|
|
96
|
-
}());
|
|
97
|
-
return [2 /*return*/, NestiaModule];
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
DynamicModule.mount = mount;
|
|
103
|
-
})(DynamicModule = exports.DynamicModule || (exports.DynamicModule = {}));
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
14
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
15
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
16
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
17
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
18
|
+
};
|
|
19
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
20
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
21
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
22
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
23
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
24
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
25
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
29
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
30
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
31
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
32
|
+
function step(op) {
|
|
33
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
34
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
35
|
+
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;
|
|
36
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
37
|
+
switch (op[0]) {
|
|
38
|
+
case 0: case 1: t = op; break;
|
|
39
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
40
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
41
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
42
|
+
default:
|
|
43
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
44
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
45
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
46
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
47
|
+
if (t[2]) _.ops.pop();
|
|
48
|
+
_.trys.pop(); continue;
|
|
49
|
+
}
|
|
50
|
+
op = body.call(thisArg, _);
|
|
51
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
52
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
56
|
+
exports.DynamicModule = void 0;
|
|
57
|
+
var common_1 = require("@nestjs/common");
|
|
58
|
+
var load_controller_1 = require("./internal/load_controller");
|
|
59
|
+
/**
|
|
60
|
+
* Dynamic module.
|
|
61
|
+
*
|
|
62
|
+
* `DynamicModule` is a namespace wrapping a convenient function, which can load
|
|
63
|
+
* controller classes dynamically just by specifying their directory path.
|
|
64
|
+
*
|
|
65
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
66
|
+
*/
|
|
67
|
+
var DynamicModule;
|
|
68
|
+
(function (DynamicModule) {
|
|
69
|
+
/**
|
|
70
|
+
* Mount dynamic module.
|
|
71
|
+
*
|
|
72
|
+
* Constructs a module instance with directory path of controller classes.
|
|
73
|
+
*
|
|
74
|
+
* Every controller classes in the target directory would be dynamically mounted.
|
|
75
|
+
*
|
|
76
|
+
* @param path Path of controllers
|
|
77
|
+
* @param metadata Addtional metadata except controllers
|
|
78
|
+
* @returns module instance
|
|
79
|
+
*/
|
|
80
|
+
function mount(path, metadata) {
|
|
81
|
+
if (metadata === void 0) { metadata = {}; }
|
|
82
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
83
|
+
var controllers, NestiaModule;
|
|
84
|
+
return __generator(this, function (_a) {
|
|
85
|
+
switch (_a.label) {
|
|
86
|
+
case 0: return [4 /*yield*/, (0, load_controller_1.load_controllers)(path)];
|
|
87
|
+
case 1:
|
|
88
|
+
controllers = _a.sent();
|
|
89
|
+
NestiaModule = /** @class */ (function () {
|
|
90
|
+
function NestiaModule() {
|
|
91
|
+
}
|
|
92
|
+
NestiaModule = __decorate([
|
|
93
|
+
(0, common_1.Module)(__assign(__assign({}, metadata), { controllers: controllers }))
|
|
94
|
+
], NestiaModule);
|
|
95
|
+
return NestiaModule;
|
|
96
|
+
}());
|
|
97
|
+
return [2 /*return*/, NestiaModule];
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
DynamicModule.mount = mount;
|
|
103
|
+
})(DynamicModule = exports.DynamicModule || (exports.DynamicModule = {}));
|
|
104
104
|
//# sourceMappingURL=DynamicModule.js.map
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
|
|
2
|
-
/**
|
|
3
|
-
* Encrypted body decorator.
|
|
4
|
-
*
|
|
5
|
-
* `EncryptedBody` is a decorator function getting `application/json` typed data from
|
|
6
|
-
* requeset body which has been encrypted by AES-128/256 algorithm. Also,
|
|
7
|
-
* `EncyrptedBody` validates the request body data type through
|
|
8
|
-
* [typia](https://github.com/samchon/typia) ad the validation speed is
|
|
9
|
-
* maximum 15,000x times faster than `class-validator`.
|
|
10
|
-
*
|
|
11
|
-
* For reference, when the request body data is not following the promised type `T`,
|
|
12
|
-
* `BadRequestException` error (status code: 400) would be thrown. Also,
|
|
13
|
-
* `EncryptedRoute` decrypts request body using those options.
|
|
14
|
-
*
|
|
15
|
-
* - AES-128/256
|
|
16
|
-
* - CBC mode
|
|
17
|
-
* - PKCS #5 Padding
|
|
18
|
-
* - Base64 Encoding
|
|
19
|
-
*
|
|
20
|
-
* @return Parameter decorator
|
|
21
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
22
|
-
*/
|
|
23
|
-
export declare function EncryptedBody<T>(validator?: IRequestBodyValidator<T>): ParameterDecorator;
|
|
1
|
+
import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
|
|
2
|
+
/**
|
|
3
|
+
* Encrypted body decorator.
|
|
4
|
+
*
|
|
5
|
+
* `EncryptedBody` is a decorator function getting `application/json` typed data from
|
|
6
|
+
* requeset body which has been encrypted by AES-128/256 algorithm. Also,
|
|
7
|
+
* `EncyrptedBody` validates the request body data type through
|
|
8
|
+
* [typia](https://github.com/samchon/typia) ad the validation speed is
|
|
9
|
+
* maximum 15,000x times faster than `class-validator`.
|
|
10
|
+
*
|
|
11
|
+
* For reference, when the request body data is not following the promised type `T`,
|
|
12
|
+
* `BadRequestException` error (status code: 400) would be thrown. Also,
|
|
13
|
+
* `EncryptedRoute` decrypts request body using those options.
|
|
14
|
+
*
|
|
15
|
+
* - AES-128/256
|
|
16
|
+
* - CBC mode
|
|
17
|
+
* - PKCS #5 Padding
|
|
18
|
+
* - Base64 Encoding
|
|
19
|
+
*
|
|
20
|
+
* @return Parameter decorator
|
|
21
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
22
|
+
*/
|
|
23
|
+
export declare function EncryptedBody<T>(validator?: IRequestBodyValidator<T>): ParameterDecorator;
|
|
@@ -1,126 +1,126 @@
|
|
|
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.EncryptedBody = void 0;
|
|
43
|
-
var fetcher_1 = require("@nestia/fetcher");
|
|
44
|
-
var common_1 = require("@nestjs/common");
|
|
45
|
-
var raw_body_1 = __importDefault(require("raw-body"));
|
|
46
|
-
var typia_1 = require("typia");
|
|
47
|
-
var Singleton_1 = require("../utils/Singleton");
|
|
48
|
-
var EncryptedConstant_1 = require("./internal/EncryptedConstant");
|
|
49
|
-
var headers_to_object_1 = require("./internal/headers_to_object");
|
|
50
|
-
var validate_request_body_1 = require("./internal/validate_request_body");
|
|
51
|
-
/**
|
|
52
|
-
* Encrypted body decorator.
|
|
53
|
-
*
|
|
54
|
-
* `EncryptedBody` is a decorator function getting `application/json` typed data from
|
|
55
|
-
* requeset body which has been encrypted by AES-128/256 algorithm. Also,
|
|
56
|
-
* `EncyrptedBody` validates the request body data type through
|
|
57
|
-
* [typia](https://github.com/samchon/typia) ad the validation speed is
|
|
58
|
-
* maximum 15,000x times faster than `class-validator`.
|
|
59
|
-
*
|
|
60
|
-
* For reference, when the request body data is not following the promised type `T`,
|
|
61
|
-
* `BadRequestException` error (status code: 400) would be thrown. Also,
|
|
62
|
-
* `EncryptedRoute` decrypts request body using those options.
|
|
63
|
-
*
|
|
64
|
-
* - AES-128/256
|
|
65
|
-
* - CBC mode
|
|
66
|
-
* - PKCS #5 Padding
|
|
67
|
-
* - Base64 Encoding
|
|
68
|
-
*
|
|
69
|
-
* @return Parameter decorator
|
|
70
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
71
|
-
*/
|
|
72
|
-
function EncryptedBody(validator) {
|
|
73
|
-
var checker = (0, validate_request_body_1.validate_request_body)("EncryptedBody")(validator);
|
|
74
|
-
return (0, common_1.createParamDecorator)(function EncryptedBody(_unknown, ctx) {
|
|
75
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
76
|
-
var request, param, headers, body, password, disabled, data;
|
|
77
|
-
return __generator(this, function (_a) {
|
|
78
|
-
switch (_a.label) {
|
|
79
|
-
case 0:
|
|
80
|
-
request = ctx.switchToHttp().getRequest();
|
|
81
|
-
if (request.readable === false)
|
|
82
|
-
throw new common_1.BadRequestException("Request body is not the text/plain.");
|
|
83
|
-
param = Reflect.getMetadata(EncryptedConstant_1.ENCRYPTION_METADATA_KEY, ctx.getClass());
|
|
84
|
-
if (!param)
|
|
85
|
-
throw new Error("Error on nestia.core.EncryptedBody(): no encryption password is given.");
|
|
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
|
-
});
|
|
105
|
-
});
|
|
106
|
-
})();
|
|
107
|
-
}
|
|
108
|
-
exports.EncryptedBody = EncryptedBody;
|
|
109
|
-
Object.assign(EncryptedBody, typia_1.is);
|
|
110
|
-
Object.assign(EncryptedBody, typia_1.assert);
|
|
111
|
-
Object.assign(EncryptedBody, typia_1.validate);
|
|
112
|
-
/**
|
|
113
|
-
* @internal
|
|
114
|
-
*/
|
|
115
|
-
function decrypt(body, key, iv) {
|
|
116
|
-
try {
|
|
117
|
-
return fetcher_1.AesPkcs5.decrypt(body, key, iv);
|
|
118
|
-
}
|
|
119
|
-
catch (exp) {
|
|
120
|
-
if (exp instanceof Error)
|
|
121
|
-
throw new common_1.BadRequestException("Failed to decrypt the request body. Check your body content or encryption password.");
|
|
122
|
-
else
|
|
123
|
-
throw exp;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
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.EncryptedBody = void 0;
|
|
43
|
+
var fetcher_1 = require("@nestia/fetcher");
|
|
44
|
+
var common_1 = require("@nestjs/common");
|
|
45
|
+
var raw_body_1 = __importDefault(require("raw-body"));
|
|
46
|
+
var typia_1 = require("typia");
|
|
47
|
+
var Singleton_1 = require("../utils/Singleton");
|
|
48
|
+
var EncryptedConstant_1 = require("./internal/EncryptedConstant");
|
|
49
|
+
var headers_to_object_1 = require("./internal/headers_to_object");
|
|
50
|
+
var validate_request_body_1 = require("./internal/validate_request_body");
|
|
51
|
+
/**
|
|
52
|
+
* Encrypted body decorator.
|
|
53
|
+
*
|
|
54
|
+
* `EncryptedBody` is a decorator function getting `application/json` typed data from
|
|
55
|
+
* requeset body which has been encrypted by AES-128/256 algorithm. Also,
|
|
56
|
+
* `EncyrptedBody` validates the request body data type through
|
|
57
|
+
* [typia](https://github.com/samchon/typia) ad the validation speed is
|
|
58
|
+
* maximum 15,000x times faster than `class-validator`.
|
|
59
|
+
*
|
|
60
|
+
* For reference, when the request body data is not following the promised type `T`,
|
|
61
|
+
* `BadRequestException` error (status code: 400) would be thrown. Also,
|
|
62
|
+
* `EncryptedRoute` decrypts request body using those options.
|
|
63
|
+
*
|
|
64
|
+
* - AES-128/256
|
|
65
|
+
* - CBC mode
|
|
66
|
+
* - PKCS #5 Padding
|
|
67
|
+
* - Base64 Encoding
|
|
68
|
+
*
|
|
69
|
+
* @return Parameter decorator
|
|
70
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
71
|
+
*/
|
|
72
|
+
function EncryptedBody(validator) {
|
|
73
|
+
var checker = (0, validate_request_body_1.validate_request_body)("EncryptedBody")(validator);
|
|
74
|
+
return (0, common_1.createParamDecorator)(function EncryptedBody(_unknown, ctx) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
76
|
+
var request, param, headers, body, password, disabled, data;
|
|
77
|
+
return __generator(this, function (_a) {
|
|
78
|
+
switch (_a.label) {
|
|
79
|
+
case 0:
|
|
80
|
+
request = ctx.switchToHttp().getRequest();
|
|
81
|
+
if (request.readable === false)
|
|
82
|
+
throw new common_1.BadRequestException("Request body is not the text/plain.");
|
|
83
|
+
param = Reflect.getMetadata(EncryptedConstant_1.ENCRYPTION_METADATA_KEY, ctx.getClass());
|
|
84
|
+
if (!param)
|
|
85
|
+
throw new Error("Error on nestia.core.EncryptedBody(): no encryption password is given.");
|
|
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
|
+
});
|
|
105
|
+
});
|
|
106
|
+
})();
|
|
107
|
+
}
|
|
108
|
+
exports.EncryptedBody = EncryptedBody;
|
|
109
|
+
Object.assign(EncryptedBody, typia_1.is);
|
|
110
|
+
Object.assign(EncryptedBody, typia_1.assert);
|
|
111
|
+
Object.assign(EncryptedBody, typia_1.validate);
|
|
112
|
+
/**
|
|
113
|
+
* @internal
|
|
114
|
+
*/
|
|
115
|
+
function decrypt(body, key, iv) {
|
|
116
|
+
try {
|
|
117
|
+
return fetcher_1.AesPkcs5.decrypt(body, key, iv);
|
|
118
|
+
}
|
|
119
|
+
catch (exp) {
|
|
120
|
+
if (exp instanceof Error)
|
|
121
|
+
throw new common_1.BadRequestException("Failed to decrypt the request body. Check your body content or encryption password.");
|
|
122
|
+
else
|
|
123
|
+
throw exp;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
126
|
//# sourceMappingURL=EncryptedBody.js.map
|