@nestia/core 1.0.19 → 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 +1 -23
- 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 +7 -5
- 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
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ParameterTransformer = void 0;
|
|
7
|
-
var typescript_1 = __importDefault(require("typescript"));
|
|
8
|
-
var ParameterDecoratorTransformer_1 = require("./ParameterDecoratorTransformer");
|
|
9
|
-
var ParameterTransformer;
|
|
10
|
-
(function (ParameterTransformer) {
|
|
11
|
-
function transform(project, param) {
|
|
12
|
-
// CHECK DECORATOR
|
|
13
|
-
var decorators = typescript_1.default.getDecorators
|
|
14
|
-
? typescript_1.default.getDecorators(param)
|
|
15
|
-
: param.decorators;
|
|
16
|
-
if (!(decorators === null || decorators === void 0 ? void 0 : decorators.length))
|
|
17
|
-
return param;
|
|
18
|
-
// GET TYPE INFO
|
|
19
|
-
var type = project.checker.getTypeAtLocation(param);
|
|
20
|
-
// WHEN LATEST TS VERSION
|
|
21
|
-
if (typescript_1.default.getDecorators !== undefined)
|
|
22
|
-
return typescript_1.default.factory.updateParameterDeclaration(param, (param.modifiers || []).map(function (mod) {
|
|
23
|
-
return typescript_1.default.isDecorator(mod)
|
|
24
|
-
? ParameterDecoratorTransformer_1.ParameterDecoratorTransformer.transform(project, type, mod)
|
|
25
|
-
: mod;
|
|
26
|
-
}), param.dotDotDotToken, param.name, param.questionToken, param.type, param.initializer);
|
|
27
|
-
// eslint-disable-next-line
|
|
28
|
-
return typescript_1.default.factory.updateParameterDeclaration(param, decorators.map(function (deco) {
|
|
29
|
-
return ParameterDecoratorTransformer_1.ParameterDecoratorTransformer.transform(project, type, deco);
|
|
30
|
-
}), param.modifiers, param.dotDotDotToken, param.name, param.questionToken, param.type, param.initializer);
|
|
31
|
-
}
|
|
32
|
-
ParameterTransformer.transform = transform;
|
|
33
|
-
})(ParameterTransformer = exports.ParameterTransformer || (exports.ParameterTransformer = {}));
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ParameterTransformer = void 0;
|
|
7
|
+
var typescript_1 = __importDefault(require("typescript"));
|
|
8
|
+
var ParameterDecoratorTransformer_1 = require("./ParameterDecoratorTransformer");
|
|
9
|
+
var ParameterTransformer;
|
|
10
|
+
(function (ParameterTransformer) {
|
|
11
|
+
function transform(project, param) {
|
|
12
|
+
// CHECK DECORATOR
|
|
13
|
+
var decorators = typescript_1.default.getDecorators
|
|
14
|
+
? typescript_1.default.getDecorators(param)
|
|
15
|
+
: param.decorators;
|
|
16
|
+
if (!(decorators === null || decorators === void 0 ? void 0 : decorators.length))
|
|
17
|
+
return param;
|
|
18
|
+
// GET TYPE INFO
|
|
19
|
+
var type = project.checker.getTypeAtLocation(param);
|
|
20
|
+
// WHEN LATEST TS VERSION
|
|
21
|
+
if (typescript_1.default.getDecorators !== undefined)
|
|
22
|
+
return typescript_1.default.factory.updateParameterDeclaration(param, (param.modifiers || []).map(function (mod) {
|
|
23
|
+
return typescript_1.default.isDecorator(mod)
|
|
24
|
+
? ParameterDecoratorTransformer_1.ParameterDecoratorTransformer.transform(project, type, mod)
|
|
25
|
+
: mod;
|
|
26
|
+
}), param.dotDotDotToken, param.name, param.questionToken, param.type, param.initializer);
|
|
27
|
+
// eslint-disable-next-line
|
|
28
|
+
return typescript_1.default.factory.updateParameterDeclaration(param, decorators.map(function (deco) {
|
|
29
|
+
return ParameterDecoratorTransformer_1.ParameterDecoratorTransformer.transform(project, type, deco);
|
|
30
|
+
}), param.modifiers, param.dotDotDotToken, param.name, param.questionToken, param.type, param.initializer);
|
|
31
|
+
}
|
|
32
|
+
ParameterTransformer.transform = transform;
|
|
33
|
+
})(ParameterTransformer = exports.ParameterTransformer || (exports.ParameterTransformer = {}));
|
|
34
34
|
//# sourceMappingURL=ParameterTransformer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ParameterTransformer.js","sourceRoot":"","sources":["../../src/transformers/ParameterTransformer.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAG5B,iFAAgF;AAEhF,IAAiB,oBAAoB,CA+CpC;AA/CD,WAAiB,oBAAoB;IACjC,SAAgB,SAAS,CACrB,OAAgC,EAChC,KAA8B;QAE9B,kBAAkB;QAClB,IAAM,UAAU,GAAwC,oBAAE,CAAC,aAAa;YACpE,CAAC,CAAC,oBAAE,CAAC,aAAa,CAAC,KAAK,CAAC;YACzB,CAAC,CAAE,KAAa,CAAC,UAAU,CAAC;QAChC,IAAI,CAAC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,MAAM,CAAA;YAAE,OAAO,KAAK,CAAC;QAEtC,gBAAgB;QAChB,IAAM,IAAI,GAAY,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;QAE/D,yBAAyB;QACzB,IAAI,oBAAE,CAAC,aAAa,KAAK,SAAS;YAC9B,OAAO,oBAAE,CAAC,OAAO,CAAC,0BAA0B,CACxC,KAAK,EACL,CAAC,KAAK,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,UAAC,GAAG;gBAC5B,OAAA,oBAAE,CAAC,WAAW,CAAC,GAAG,CAAC;oBACf,CAAC,CAAC,6DAA6B,CAAC,SAAS,CACnC,OAAO,EACP,IAAI,EACJ,GAAG,CACN;oBACH,CAAC,CAAC,GAAG;YANT,CAMS,CACZ,EACD,KAAK,CAAC,cAAc,EACpB,KAAK,CAAC,IAAI,EACV,KAAK,CAAC,aAAa,EACnB,KAAK,CAAC,IAAI,EACV,KAAK,CAAC,WAAW,CACpB,CAAC;QACN,2BAA2B;QAC3B,
|
|
1
|
+
{"version":3,"file":"ParameterTransformer.js","sourceRoot":"","sources":["../../src/transformers/ParameterTransformer.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAG5B,iFAAgF;AAEhF,IAAiB,oBAAoB,CA+CpC;AA/CD,WAAiB,oBAAoB;IACjC,SAAgB,SAAS,CACrB,OAAgC,EAChC,KAA8B;QAE9B,kBAAkB;QAClB,IAAM,UAAU,GAAwC,oBAAE,CAAC,aAAa;YACpE,CAAC,CAAC,oBAAE,CAAC,aAAa,CAAC,KAAK,CAAC;YACzB,CAAC,CAAE,KAAa,CAAC,UAAU,CAAC;QAChC,IAAI,CAAC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,MAAM,CAAA;YAAE,OAAO,KAAK,CAAC;QAEtC,gBAAgB;QAChB,IAAM,IAAI,GAAY,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;QAE/D,yBAAyB;QACzB,IAAI,oBAAE,CAAC,aAAa,KAAK,SAAS;YAC9B,OAAO,oBAAE,CAAC,OAAO,CAAC,0BAA0B,CACxC,KAAK,EACL,CAAC,KAAK,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,UAAC,GAAG;gBAC5B,OAAA,oBAAE,CAAC,WAAW,CAAC,GAAG,CAAC;oBACf,CAAC,CAAC,6DAA6B,CAAC,SAAS,CACnC,OAAO,EACP,IAAI,EACJ,GAAG,CACN;oBACH,CAAC,CAAC,GAAG;YANT,CAMS,CACZ,EACD,KAAK,CAAC,cAAc,EACpB,KAAK,CAAC,IAAI,EACV,KAAK,CAAC,aAAa,EACnB,KAAK,CAAC,IAAI,EACV,KAAK,CAAC,WAAW,CACpB,CAAC;QACN,2BAA2B;QAC3B,OAAQ,oBAAE,CAAC,OAAO,CAAC,0BAAkC,CACjD,KAAK,EACL,UAAU,CAAC,GAAG,CAAC,UAAC,IAAI;YAChB,OAAA,6DAA6B,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC;QAA5D,CAA4D,CAC/D,EACA,KAAa,CAAC,SAAS,EACxB,KAAK,CAAC,cAAc,EACpB,KAAK,CAAC,IAAI,EACV,KAAK,CAAC,aAAa,EACnB,KAAK,CAAC,IAAI,EACV,KAAK,CAAC,WAAW,CACpB,CAAC;IACN,CAAC;IA7Ce,8BAAS,YA6CxB,CAAA;AACL,CAAC,EA/CgB,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QA+CpC"}
|
package/lib/typings/Creator.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type Creator<T extends object> = {
|
|
2
|
-
new (...args: any[]): T;
|
|
3
|
-
};
|
|
1
|
+
export type Creator<T extends object> = {
|
|
2
|
+
new (...args: any[]): T;
|
|
3
|
+
};
|
package/lib/typings/Creator.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
//# sourceMappingURL=Creator.js.map
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
import { HttpException } from "@nestjs/common";
|
|
2
|
-
import { Creator } from "../typings/Creator";
|
|
3
|
-
/**
|
|
4
|
-
* Exception manager for HTTP server.
|
|
5
|
-
*
|
|
6
|
-
* `ExceptionManager` is an utility class who can insert or erase custom error class with
|
|
7
|
-
* its convertion method to a regular {@link nest.HttpException} instance.
|
|
8
|
-
*
|
|
9
|
-
* If you define an API function through {@link TypedRoute} or {@link EncryptedRoute}
|
|
10
|
-
* instead of the basic router decorator functions like {@link nest.Get} or
|
|
11
|
-
* {@link nest.Post} and the API function throws a custom error whose class has been
|
|
12
|
-
* {@link ExceptionManager.insert inserted} in this `EntityManager`, the error would be
|
|
13
|
-
* automatically converted to the regular {@link nest.HttpException} instance by the
|
|
14
|
-
* {@link ExceptionManager.Closure} function.
|
|
15
|
-
*
|
|
16
|
-
* Therefore, with this `ExceptionManager` and {@link TypedRoute} or {@link EncryptedRoute},
|
|
17
|
-
* you can manage your custom error classes much systemtically. You can avoid 500 internal
|
|
18
|
-
* server error or hard coding implementation about the custom error classes.
|
|
19
|
-
*
|
|
20
|
-
* Below error classes are defaultly configured in this `ExceptionManager`
|
|
21
|
-
*
|
|
22
|
-
* - `typia.TypeGuardError`
|
|
23
|
-
* - `@nestia/fetcher.HttpError`
|
|
24
|
-
*
|
|
25
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
26
|
-
*/
|
|
27
|
-
export declare namespace ExceptionManager {
|
|
28
|
-
/**
|
|
29
|
-
* Insert an error class with converter.
|
|
30
|
-
*
|
|
31
|
-
* If you've inserted an duplicated error class, the closure would be overwritten.
|
|
32
|
-
*
|
|
33
|
-
* @param creator Target error class
|
|
34
|
-
* @param closure A closure function converting to the `HttpException` class
|
|
35
|
-
*/
|
|
36
|
-
function insert<T extends Error>(creator: Creator<T>, closure: Closure<T>): void;
|
|
37
|
-
/**
|
|
38
|
-
* Erase an error class.
|
|
39
|
-
*
|
|
40
|
-
* @param creator Target error class
|
|
41
|
-
* @returns Whether be erased or not
|
|
42
|
-
*/
|
|
43
|
-
function erase<T extends Error>(creator: Creator<T>): boolean;
|
|
44
|
-
function on(closure: (error: any) => any): void;
|
|
45
|
-
function off(closure: (error: any) => any): void;
|
|
46
|
-
/**
|
|
47
|
-
* Type of a closure function converting to the regular {@link nest.HttpException}.
|
|
48
|
-
*
|
|
49
|
-
* `ExceptionManager.Closure` is a type of closure function who are converting from
|
|
50
|
-
* custom error to the regular {@link nest.HttpException} instance. It would be used
|
|
51
|
-
* in the {@link ExceptionManager} with {@link TypedRoute} or {@link EncryptedRoute}.
|
|
52
|
-
*/
|
|
53
|
-
interface Closure<T extends Error> {
|
|
54
|
-
/**
|
|
55
|
-
* Error converter.
|
|
56
|
-
*
|
|
57
|
-
* Convert from custom error to the regular {@link nest.HttpException} instance.
|
|
58
|
-
*
|
|
59
|
-
* @param exception Custom error instance
|
|
60
|
-
* @return Regular {@link nest.HttpException} instance
|
|
61
|
-
*/
|
|
62
|
-
(exception: T): HttpException;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
1
|
+
import { HttpException } from "@nestjs/common";
|
|
2
|
+
import { Creator } from "../typings/Creator";
|
|
3
|
+
/**
|
|
4
|
+
* Exception manager for HTTP server.
|
|
5
|
+
*
|
|
6
|
+
* `ExceptionManager` is an utility class who can insert or erase custom error class with
|
|
7
|
+
* its convertion method to a regular {@link nest.HttpException} instance.
|
|
8
|
+
*
|
|
9
|
+
* If you define an API function through {@link TypedRoute} or {@link EncryptedRoute}
|
|
10
|
+
* instead of the basic router decorator functions like {@link nest.Get} or
|
|
11
|
+
* {@link nest.Post} and the API function throws a custom error whose class has been
|
|
12
|
+
* {@link ExceptionManager.insert inserted} in this `EntityManager`, the error would be
|
|
13
|
+
* automatically converted to the regular {@link nest.HttpException} instance by the
|
|
14
|
+
* {@link ExceptionManager.Closure} function.
|
|
15
|
+
*
|
|
16
|
+
* Therefore, with this `ExceptionManager` and {@link TypedRoute} or {@link EncryptedRoute},
|
|
17
|
+
* you can manage your custom error classes much systemtically. You can avoid 500 internal
|
|
18
|
+
* server error or hard coding implementation about the custom error classes.
|
|
19
|
+
*
|
|
20
|
+
* Below error classes are defaultly configured in this `ExceptionManager`
|
|
21
|
+
*
|
|
22
|
+
* - `typia.TypeGuardError`
|
|
23
|
+
* - `@nestia/fetcher.HttpError`
|
|
24
|
+
*
|
|
25
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
26
|
+
*/
|
|
27
|
+
export declare namespace ExceptionManager {
|
|
28
|
+
/**
|
|
29
|
+
* Insert an error class with converter.
|
|
30
|
+
*
|
|
31
|
+
* If you've inserted an duplicated error class, the closure would be overwritten.
|
|
32
|
+
*
|
|
33
|
+
* @param creator Target error class
|
|
34
|
+
* @param closure A closure function converting to the `HttpException` class
|
|
35
|
+
*/
|
|
36
|
+
function insert<T extends Error>(creator: Creator<T>, closure: Closure<T>): void;
|
|
37
|
+
/**
|
|
38
|
+
* Erase an error class.
|
|
39
|
+
*
|
|
40
|
+
* @param creator Target error class
|
|
41
|
+
* @returns Whether be erased or not
|
|
42
|
+
*/
|
|
43
|
+
function erase<T extends Error>(creator: Creator<T>): boolean;
|
|
44
|
+
function on(closure: (error: any) => any): void;
|
|
45
|
+
function off(closure: (error: any) => any): void;
|
|
46
|
+
/**
|
|
47
|
+
* Type of a closure function converting to the regular {@link nest.HttpException}.
|
|
48
|
+
*
|
|
49
|
+
* `ExceptionManager.Closure` is a type of closure function who are converting from
|
|
50
|
+
* custom error to the regular {@link nest.HttpException} instance. It would be used
|
|
51
|
+
* in the {@link ExceptionManager} with {@link TypedRoute} or {@link EncryptedRoute}.
|
|
52
|
+
*/
|
|
53
|
+
interface Closure<T extends Error> {
|
|
54
|
+
/**
|
|
55
|
+
* Error converter.
|
|
56
|
+
*
|
|
57
|
+
* Convert from custom error to the regular {@link nest.HttpException} instance.
|
|
58
|
+
*
|
|
59
|
+
* @param exception Custom error instance
|
|
60
|
+
* @return Regular {@link nest.HttpException} instance
|
|
61
|
+
*/
|
|
62
|
+
(exception: T): HttpException;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -1,113 +1,113 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.ExceptionManager = void 0;
|
|
20
|
-
var fetcher_1 = require("@nestia/fetcher");
|
|
21
|
-
var common_1 = require("@nestjs/common");
|
|
22
|
-
var typia_1 = require("typia");
|
|
23
|
-
/**
|
|
24
|
-
* Exception manager for HTTP server.
|
|
25
|
-
*
|
|
26
|
-
* `ExceptionManager` is an utility class who can insert or erase custom error class with
|
|
27
|
-
* its convertion method to a regular {@link nest.HttpException} instance.
|
|
28
|
-
*
|
|
29
|
-
* If you define an API function through {@link TypedRoute} or {@link EncryptedRoute}
|
|
30
|
-
* instead of the basic router decorator functions like {@link nest.Get} or
|
|
31
|
-
* {@link nest.Post} and the API function throws a custom error whose class has been
|
|
32
|
-
* {@link ExceptionManager.insert inserted} in this `EntityManager`, the error would be
|
|
33
|
-
* automatically converted to the regular {@link nest.HttpException} instance by the
|
|
34
|
-
* {@link ExceptionManager.Closure} function.
|
|
35
|
-
*
|
|
36
|
-
* Therefore, with this `ExceptionManager` and {@link TypedRoute} or {@link EncryptedRoute},
|
|
37
|
-
* you can manage your custom error classes much systemtically. You can avoid 500 internal
|
|
38
|
-
* server error or hard coding implementation about the custom error classes.
|
|
39
|
-
*
|
|
40
|
-
* Below error classes are defaultly configured in this `ExceptionManager`
|
|
41
|
-
*
|
|
42
|
-
* - `typia.TypeGuardError`
|
|
43
|
-
* - `@nestia/fetcher.HttpError`
|
|
44
|
-
*
|
|
45
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
46
|
-
*/
|
|
47
|
-
var ExceptionManager;
|
|
48
|
-
(function (ExceptionManager) {
|
|
49
|
-
/**
|
|
50
|
-
* Insert an error class with converter.
|
|
51
|
-
*
|
|
52
|
-
* If you've inserted an duplicated error class, the closure would be overwritten.
|
|
53
|
-
*
|
|
54
|
-
* @param creator Target error class
|
|
55
|
-
* @param closure A closure function converting to the `HttpException` class
|
|
56
|
-
*/
|
|
57
|
-
function insert(creator, closure) {
|
|
58
|
-
var index = ExceptionManager.tuples.findIndex(function (tuple) { return tuple[0] === creator; });
|
|
59
|
-
if (index !== -1)
|
|
60
|
-
ExceptionManager.tuples.splice(index, 1);
|
|
61
|
-
ExceptionManager.tuples.push([creator, closure]);
|
|
62
|
-
ExceptionManager.tuples.sort(function (_a, _b) {
|
|
63
|
-
var _c = __read(_a, 1), x = _c[0];
|
|
64
|
-
var _d = __read(_b, 1), y = _d[0];
|
|
65
|
-
return (x.prototype instanceof y ? -1 : 1);
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
ExceptionManager.insert = insert;
|
|
69
|
-
/**
|
|
70
|
-
* Erase an error class.
|
|
71
|
-
*
|
|
72
|
-
* @param creator Target error class
|
|
73
|
-
* @returns Whether be erased or not
|
|
74
|
-
*/
|
|
75
|
-
function erase(creator) {
|
|
76
|
-
var index = ExceptionManager.tuples.findIndex(function (tuple) { return tuple[0] === creator; });
|
|
77
|
-
if (index === -1)
|
|
78
|
-
return false;
|
|
79
|
-
ExceptionManager.tuples.splice(index, 1);
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
ExceptionManager.erase = erase;
|
|
83
|
-
function on(closure) {
|
|
84
|
-
ExceptionManager.listeners.add(closure);
|
|
85
|
-
}
|
|
86
|
-
ExceptionManager.on = on;
|
|
87
|
-
function off(closure) {
|
|
88
|
-
ExceptionManager.listeners.delete(closure);
|
|
89
|
-
}
|
|
90
|
-
ExceptionManager.off = off;
|
|
91
|
-
/**
|
|
92
|
-
* @internal
|
|
93
|
-
*/
|
|
94
|
-
ExceptionManager.tuples = [];
|
|
95
|
-
/**
|
|
96
|
-
* @internal
|
|
97
|
-
*/
|
|
98
|
-
ExceptionManager.listeners = new Set();
|
|
99
|
-
})(ExceptionManager = exports.ExceptionManager || (exports.ExceptionManager = {}));
|
|
100
|
-
ExceptionManager.insert(typia_1.TypeGuardError, function (error) {
|
|
101
|
-
return new common_1.HttpException({
|
|
102
|
-
path: error.path,
|
|
103
|
-
reason: error.message,
|
|
104
|
-
message: "Request message is not following the promised type.",
|
|
105
|
-
}, 400);
|
|
106
|
-
});
|
|
107
|
-
ExceptionManager.insert(fetcher_1.HttpError, function (error) {
|
|
108
|
-
return new common_1.HttpException({
|
|
109
|
-
path: error.path,
|
|
110
|
-
message: error.message,
|
|
111
|
-
}, error.status);
|
|
112
|
-
});
|
|
1
|
+
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.ExceptionManager = void 0;
|
|
20
|
+
var fetcher_1 = require("@nestia/fetcher");
|
|
21
|
+
var common_1 = require("@nestjs/common");
|
|
22
|
+
var typia_1 = require("typia");
|
|
23
|
+
/**
|
|
24
|
+
* Exception manager for HTTP server.
|
|
25
|
+
*
|
|
26
|
+
* `ExceptionManager` is an utility class who can insert or erase custom error class with
|
|
27
|
+
* its convertion method to a regular {@link nest.HttpException} instance.
|
|
28
|
+
*
|
|
29
|
+
* If you define an API function through {@link TypedRoute} or {@link EncryptedRoute}
|
|
30
|
+
* instead of the basic router decorator functions like {@link nest.Get} or
|
|
31
|
+
* {@link nest.Post} and the API function throws a custom error whose class has been
|
|
32
|
+
* {@link ExceptionManager.insert inserted} in this `EntityManager`, the error would be
|
|
33
|
+
* automatically converted to the regular {@link nest.HttpException} instance by the
|
|
34
|
+
* {@link ExceptionManager.Closure} function.
|
|
35
|
+
*
|
|
36
|
+
* Therefore, with this `ExceptionManager` and {@link TypedRoute} or {@link EncryptedRoute},
|
|
37
|
+
* you can manage your custom error classes much systemtically. You can avoid 500 internal
|
|
38
|
+
* server error or hard coding implementation about the custom error classes.
|
|
39
|
+
*
|
|
40
|
+
* Below error classes are defaultly configured in this `ExceptionManager`
|
|
41
|
+
*
|
|
42
|
+
* - `typia.TypeGuardError`
|
|
43
|
+
* - `@nestia/fetcher.HttpError`
|
|
44
|
+
*
|
|
45
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
46
|
+
*/
|
|
47
|
+
var ExceptionManager;
|
|
48
|
+
(function (ExceptionManager) {
|
|
49
|
+
/**
|
|
50
|
+
* Insert an error class with converter.
|
|
51
|
+
*
|
|
52
|
+
* If you've inserted an duplicated error class, the closure would be overwritten.
|
|
53
|
+
*
|
|
54
|
+
* @param creator Target error class
|
|
55
|
+
* @param closure A closure function converting to the `HttpException` class
|
|
56
|
+
*/
|
|
57
|
+
function insert(creator, closure) {
|
|
58
|
+
var index = ExceptionManager.tuples.findIndex(function (tuple) { return tuple[0] === creator; });
|
|
59
|
+
if (index !== -1)
|
|
60
|
+
ExceptionManager.tuples.splice(index, 1);
|
|
61
|
+
ExceptionManager.tuples.push([creator, closure]);
|
|
62
|
+
ExceptionManager.tuples.sort(function (_a, _b) {
|
|
63
|
+
var _c = __read(_a, 1), x = _c[0];
|
|
64
|
+
var _d = __read(_b, 1), y = _d[0];
|
|
65
|
+
return (x.prototype instanceof y ? -1 : 1);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
ExceptionManager.insert = insert;
|
|
69
|
+
/**
|
|
70
|
+
* Erase an error class.
|
|
71
|
+
*
|
|
72
|
+
* @param creator Target error class
|
|
73
|
+
* @returns Whether be erased or not
|
|
74
|
+
*/
|
|
75
|
+
function erase(creator) {
|
|
76
|
+
var index = ExceptionManager.tuples.findIndex(function (tuple) { return tuple[0] === creator; });
|
|
77
|
+
if (index === -1)
|
|
78
|
+
return false;
|
|
79
|
+
ExceptionManager.tuples.splice(index, 1);
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
ExceptionManager.erase = erase;
|
|
83
|
+
function on(closure) {
|
|
84
|
+
ExceptionManager.listeners.add(closure);
|
|
85
|
+
}
|
|
86
|
+
ExceptionManager.on = on;
|
|
87
|
+
function off(closure) {
|
|
88
|
+
ExceptionManager.listeners.delete(closure);
|
|
89
|
+
}
|
|
90
|
+
ExceptionManager.off = off;
|
|
91
|
+
/**
|
|
92
|
+
* @internal
|
|
93
|
+
*/
|
|
94
|
+
ExceptionManager.tuples = [];
|
|
95
|
+
/**
|
|
96
|
+
* @internal
|
|
97
|
+
*/
|
|
98
|
+
ExceptionManager.listeners = new Set();
|
|
99
|
+
})(ExceptionManager = exports.ExceptionManager || (exports.ExceptionManager = {}));
|
|
100
|
+
ExceptionManager.insert(typia_1.TypeGuardError, function (error) {
|
|
101
|
+
return new common_1.HttpException({
|
|
102
|
+
path: error.path,
|
|
103
|
+
reason: error.message,
|
|
104
|
+
message: "Request message is not following the promised type.",
|
|
105
|
+
}, 400);
|
|
106
|
+
});
|
|
107
|
+
ExceptionManager.insert(fetcher_1.HttpError, function (error) {
|
|
108
|
+
return new common_1.HttpException({
|
|
109
|
+
path: error.path,
|
|
110
|
+
message: error.message,
|
|
111
|
+
}, error.status);
|
|
112
|
+
});
|
|
113
113
|
//# sourceMappingURL=ExceptionManager.js.map
|
package/lib/utils/Singleton.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/lib/utils/Singleton.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Singleton = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* @internal
|
|
6
|
-
*/
|
|
7
|
-
var Singleton = /** @class */ (function () {
|
|
8
|
-
function Singleton(closure_) {
|
|
9
|
-
this.closure_ = closure_;
|
|
10
|
-
this.value_ = NOT_MOUNTED_YET;
|
|
11
|
-
}
|
|
12
|
-
Singleton.prototype.get = function () {
|
|
13
|
-
if (this.value_ === NOT_MOUNTED_YET)
|
|
14
|
-
this.value_ = this.closure_();
|
|
15
|
-
return this.value_;
|
|
16
|
-
};
|
|
17
|
-
return Singleton;
|
|
18
|
-
}());
|
|
19
|
-
exports.Singleton = Singleton;
|
|
20
|
-
/**
|
|
21
|
-
* @internal
|
|
22
|
-
*/
|
|
23
|
-
var NOT_MOUNTED_YET = {};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Singleton = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
var Singleton = /** @class */ (function () {
|
|
8
|
+
function Singleton(closure_) {
|
|
9
|
+
this.closure_ = closure_;
|
|
10
|
+
this.value_ = NOT_MOUNTED_YET;
|
|
11
|
+
}
|
|
12
|
+
Singleton.prototype.get = function () {
|
|
13
|
+
if (this.value_ === NOT_MOUNTED_YET)
|
|
14
|
+
this.value_ = this.closure_();
|
|
15
|
+
return this.value_;
|
|
16
|
+
};
|
|
17
|
+
return Singleton;
|
|
18
|
+
}());
|
|
19
|
+
exports.Singleton = Singleton;
|
|
20
|
+
/**
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
var NOT_MOUNTED_YET = {};
|
|
24
24
|
//# sourceMappingURL=Singleton.js.map
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestia/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.1.0-dev.20230413",
|
|
4
4
|
"description": "Super-fast validation decorators of NestJS",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "rimraf lib && tsc",
|
|
9
|
-
"build:test": "rimraf bin &&
|
|
9
|
+
"build:test": "rimraf bin && tsc -p test/tsconfig.json",
|
|
10
10
|
"dev": "npm run build -- --watch",
|
|
11
11
|
"eslint": "eslint ./**/*.ts",
|
|
12
12
|
"eslint:fix": "eslint ./**/*.ts --fix",
|
|
13
13
|
"package": "npm publish --access public",
|
|
14
|
+
"prepare": "ts-patch install",
|
|
14
15
|
"prettier": "prettier ./**/*.ts --write",
|
|
15
16
|
"test": "node bin/test"
|
|
16
17
|
},
|
|
@@ -44,11 +45,12 @@
|
|
|
44
45
|
"eslint-plugin-deprecation": "^1.3.3",
|
|
45
46
|
"git-last-commit": "^1.0.1",
|
|
46
47
|
"inquirer": "^8.2.5",
|
|
48
|
+
"prettier": "^2.8.7",
|
|
47
49
|
"rimraf": "^3.0.2",
|
|
48
50
|
"ts-node": "^10.9.1",
|
|
51
|
+
"ts-patch": "^3.0.0-beta2",
|
|
49
52
|
"tstl": "^2.5.13",
|
|
50
|
-
"
|
|
51
|
-
"typescript": "^4.9.5",
|
|
53
|
+
"typescript": "^5.0.4",
|
|
52
54
|
"typescript-transform-paths": "^3.4.6"
|
|
53
55
|
},
|
|
54
56
|
"dependencies": {
|
|
@@ -63,7 +65,7 @@
|
|
|
63
65
|
"typia": "^3.7.4"
|
|
64
66
|
},
|
|
65
67
|
"peerDependencies": {
|
|
66
|
-
"typescript": ">= 4.5.2
|
|
68
|
+
"typescript": ">= 4.5.2"
|
|
67
69
|
},
|
|
68
70
|
"files": [
|
|
69
71
|
"README.md",
|
|
@@ -37,17 +37,19 @@ export function TypedQuery<T>(
|
|
|
37
37
|
* @internal
|
|
38
38
|
*/
|
|
39
39
|
export namespace TypedQuery {
|
|
40
|
-
export function boolean(
|
|
41
|
-
|
|
40
|
+
export function boolean(
|
|
41
|
+
str: string | null | undefined,
|
|
42
|
+
): boolean | undefined {
|
|
43
|
+
return str?.length ? Boolean(str) : undefined;
|
|
42
44
|
}
|
|
43
|
-
export function number(str: string | null): number | undefined {
|
|
44
|
-
return str
|
|
45
|
+
export function number(str: string | null | undefined): number | undefined {
|
|
46
|
+
return str?.length ? Number(str) : undefined;
|
|
45
47
|
}
|
|
46
|
-
export function bigint(str: string | null): bigint | undefined {
|
|
47
|
-
return str
|
|
48
|
+
export function bigint(str: string | null | undefined): bigint | undefined {
|
|
49
|
+
return str?.length ? BigInt(str) : undefined;
|
|
48
50
|
}
|
|
49
|
-
export function string(str: string | null): string | undefined {
|
|
50
|
-
return str
|
|
51
|
+
export function string(str: string | null | undefined): string | undefined {
|
|
52
|
+
return str !== undefined && str !== null ? str : undefined;
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
Object.assign(TypedQuery, assert);
|