@nestia/core 1.0.6 → 1.0.8
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 +28 -1
- package/lib/decorators/EncryptedBody.js +1 -1
- package/lib/decorators/EncryptedBody.js.map +1 -1
- package/lib/decorators/EncryptedRoute.js +1 -1
- package/lib/decorators/EncryptedRoute.js.map +1 -1
- package/lib/decorators/TypedBody.js +1 -1
- package/lib/decorators/TypedBody.js.map +1 -1
- package/lib/decorators/TypedQuery.d.ts +1 -0
- package/lib/decorators/TypedQuery.js +83 -0
- package/lib/decorators/TypedQuery.js.map +1 -0
- package/lib/module.d.ts +1 -0
- package/lib/module.js +1 -0
- package/lib/module.js.map +1 -1
- package/lib/programmers/TypedBodyProgrammer.d.ts +5 -0
- package/lib/programmers/TypedBodyProgrammer.js +46 -0
- package/lib/programmers/TypedBodyProgrammer.js.map +1 -0
- package/lib/programmers/TypedQueryProgrammer.d.ts +5 -0
- package/lib/programmers/TypedQueryProgrammer.js +166 -0
- package/lib/programmers/TypedQueryProgrammer.js.map +1 -0
- package/lib/programmers/TypedRouteProgrammer.d.ts +5 -0
- package/lib/programmers/TypedRouteProgrammer.js +47 -0
- package/lib/programmers/TypedRouteProgrammer.js.map +1 -0
- package/lib/transformers/{BodyTransformer.d.ts → MethodDecoratorTransformer.d.ts} +1 -1
- package/lib/transformers/MethodDecoratorTransformer.js +88 -0
- package/lib/transformers/MethodDecoratorTransformer.js.map +1 -0
- package/lib/transformers/MethodTransformer.js +3 -3
- package/lib/transformers/MethodTransformer.js.map +1 -1
- package/lib/transformers/{RouteTransformer.d.ts → ParameterDecoratorTransformer.d.ts} +1 -1
- package/lib/transformers/ParameterDecoratorTransformer.js +54 -0
- package/lib/transformers/ParameterDecoratorTransformer.js.map +1 -0
- package/lib/transformers/ParameterTransformer.js +6 -3
- package/lib/transformers/ParameterTransformer.js.map +1 -1
- package/package.json +1 -1
- package/src/decorators/EncryptedBody.ts +1 -1
- package/src/decorators/EncryptedRoute.ts +1 -1
- package/src/decorators/TypedBody.ts +1 -1
- package/src/decorators/TypedQuery.ts +42 -0
- package/src/module.ts +1 -0
- package/src/programmers/TypedBodyProgrammer.ts +50 -0
- package/src/programmers/TypedQueryProgrammer.ts +181 -0
- package/src/programmers/TypedRouteProgrammer.ts +54 -0
- package/src/transformers/MethodDecoratorTransformer.ts +91 -0
- package/src/transformers/MethodTransformer.ts +7 -3
- package/src/transformers/ParameterDecoratorTransformer.ts +79 -0
- package/src/transformers/ParameterTransformer.ts +11 -3
- package/lib/transformers/BodyTransformer.js +0 -84
- package/lib/transformers/BodyTransformer.js.map +0 -1
- package/lib/transformers/RouteTransformer.js +0 -127
- package/lib/transformers/RouteTransformer.js.map +0 -1
- package/src/transformers/BodyTransformer.ts +0 -116
- package/src/transformers/RouteTransformer.ts +0 -139
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MethodDecoratorTransformer.js","sourceRoot":"","sources":["../../src/transformers/MethodDecoratorTransformer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAwB;AACxB,0DAA4B;AAG5B,4EAA2E;AAE3E,IAAiB,0BAA0B,CAoF1C;AApFD,WAAiB,0BAA0B;IACvC,SAAgB,SAAS,CACrB,OAAgC,EAChC,IAAa,EACb,SAAuB;QAEvB,IAAI,CAAC,oBAAE,CAAC,gBAAgB,CAAC,SAAS,CAAC,UAAU,CAAC;YAAE,OAAO,SAAS,CAAC;QAEjE,kBAAkB;QAClB,IAAM,SAAS,GACX,OAAO,CAAC,OAAO,CAAC,oBAAoB,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAC/D,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC,WAAW;YAAE,OAAO,SAAS,CAAC;QAE3D,0BAA0B;QAC1B,IAAM,IAAI,GAAY,CAAC;YACnB,iBAAiB;YACjB,IAAM,QAAQ,GAAW,cAAI,CAAC,OAAO,C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CAAC,UAAU,EAC/B,SAAS,CAAC,UAAU,CAAC,aAAa,yCAE3B,SAAS,CAAC,UAAU,CAAC,SAAS;YACjC,2CAAoB,CAAC,QAAQ,CACzB,OAAO,EACP,SAAS,CAAC,UAAU,CAAC,UAAU,CAClC,CAAC,IAAI,CAAC;kBAEd,CACJ,CAAC;IACN,CAAC;IA1De,oCAAS,YA0DxB,CAAA;IAED,SAAS,QAAQ,CAAC,OAAuB,EAAE,IAAa;QACpD,OAAO,CACH,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,oBAAE,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC;YAC7C,CAAE,OAAe,CAAC,WAAW,CAAC,IAAI,CAAC;YACnC,CAAE,OAAe,CAAC,WAAW,CAAC,IAAI,CAAC;YACnC,CAAE,OAAe,CAAC,eAAe,CAAC,IAAI,CAAC,CAC1C,CAAC;IACN,CAAC;IAED,IAAM,OAAO,GAAG,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAAC;IACjD,IAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,UAAC,GAAG;QAC9B,OAAA,cAAI,CAAC,IAAI,CACL,cAAc,EACd,SAAS,EACT,MAAM,EACN,KAAK,EACL,YAAY,EACZ,UAAG,GAAG,UAAO,CAChB;IAPD,CAOC,CACJ,CAAC;IACF,IAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,UAAC,GAAG;QAC9B,OAAA,cAAI,CAAC,OAAO,CAAC,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,YAAY,EAAE,UAAG,GAAG,QAAK,CAAC,CAAC;IAAnE,CAAmE,CACtE,CAAC;AACN,CAAC,EApFgB,0BAA0B,GAA1B,kCAA0B,KAA1B,kCAA0B,QAoF1C"}
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.MethodTransformer = void 0;
|
|
7
7
|
var typescript_1 = __importDefault(require("typescript"));
|
|
8
|
-
var
|
|
8
|
+
var MethodDecoratorTransformer_1 = require("./MethodDecoratorTransformer");
|
|
9
9
|
var MethodTransformer;
|
|
10
10
|
(function (MethodTransformer) {
|
|
11
11
|
function transform(project, method) {
|
|
@@ -22,12 +22,12 @@ var MethodTransformer;
|
|
|
22
22
|
if (typescript_1.default.getDecorators !== undefined)
|
|
23
23
|
return typescript_1.default.factory.updateMethodDeclaration(method, (method.modifiers || []).map(function (mod) {
|
|
24
24
|
return typescript_1.default.isDecorator(mod)
|
|
25
|
-
?
|
|
25
|
+
? MethodDecoratorTransformer_1.MethodDecoratorTransformer.transform(project, escaped, mod)
|
|
26
26
|
: mod;
|
|
27
27
|
}), method.asteriskToken, method.name, method.questionToken, method.typeParameters, method.parameters, method.type, method.body);
|
|
28
28
|
// eslint-disable-next-line
|
|
29
29
|
return typescript_1.default.factory.updateMethodDeclaration(method, decorators.map(function (deco) {
|
|
30
|
-
return
|
|
30
|
+
return MethodDecoratorTransformer_1.MethodDecoratorTransformer.transform(project, escaped, deco);
|
|
31
31
|
}), method.modifiers, method.asteriskToken, method.name, method.questionToken, method.typeParameters, method.parameters, method.type, method.body);
|
|
32
32
|
}
|
|
33
33
|
MethodTransformer.transform = transform;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MethodTransformer.js","sourceRoot":"","sources":["../../src/transformers/MethodTransformer.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAG5B,
|
|
1
|
+
{"version":3,"file":"MethodTransformer.js","sourceRoot":"","sources":["../../src/transformers/MethodTransformer.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAG5B,2EAA0E;AAE1E,IAAiB,iBAAiB,CAuDjC;AAvDD,WAAiB,iBAAiB;IAC9B,SAAgB,SAAS,CACrB,OAAgC,EAChC,MAA4B;QAE5B,IAAM,UAAU,GAAwC,oBAAE,CAAC,aAAa;YACpE,CAAC,CAAC,o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I,CAAC,MAAM,CAAC,MAAM,CACrB;QACH,CAAC,CAAC,IAAI,CAAC;AACf,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
3
|
-
export declare namespace
|
|
3
|
+
export declare namespace ParameterDecoratorTransformer {
|
|
4
4
|
function transform(project: INestiaTransformProject, type: ts.Type, decorator: ts.Decorator): ts.Decorator;
|
|
5
5
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
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.ParameterDecoratorTransformer = void 0;
|
|
7
|
+
var path_1 = __importDefault(require("path"));
|
|
8
|
+
var typescript_1 = __importDefault(require("typescript"));
|
|
9
|
+
var TypedBodyProgrammer_1 = require("../programmers/TypedBodyProgrammer");
|
|
10
|
+
var TypedQueryProgrammer_1 = require("../programmers/TypedQueryProgrammer");
|
|
11
|
+
var ParameterDecoratorTransformer;
|
|
12
|
+
(function (ParameterDecoratorTransformer) {
|
|
13
|
+
function transform(project, type, decorator) {
|
|
14
|
+
var _a, _b;
|
|
15
|
+
//----
|
|
16
|
+
// VALIDATIONS
|
|
17
|
+
//----
|
|
18
|
+
// CHECK DECORATOR
|
|
19
|
+
if (!typescript_1.default.isCallExpression(decorator.expression))
|
|
20
|
+
return decorator;
|
|
21
|
+
else if (decorator.expression.arguments.length !== 0)
|
|
22
|
+
return decorator;
|
|
23
|
+
// SIGNATURE DECLARATION
|
|
24
|
+
var declaration = (_a = project.checker.getResolvedSignature(decorator.expression)) === null || _a === void 0 ? void 0 : _a.declaration;
|
|
25
|
+
if (declaration === undefined)
|
|
26
|
+
return decorator;
|
|
27
|
+
// FILE PATH
|
|
28
|
+
var file = path_1.default.resolve(declaration.getSourceFile().fileName);
|
|
29
|
+
if (file.indexOf(LIB_PATH) === -1 && file.indexOf(SRC_PATH) === -1)
|
|
30
|
+
return decorator;
|
|
31
|
+
//----
|
|
32
|
+
// TRANSFORMATION
|
|
33
|
+
//----
|
|
34
|
+
// FIND PROGRAMMER
|
|
35
|
+
var programmer = (_b = FUNCTORS[project.checker.getTypeAtLocation(declaration).symbol.name]) === null || _b === void 0 ? void 0 : _b.call(FUNCTORS);
|
|
36
|
+
if (programmer === undefined)
|
|
37
|
+
return decorator;
|
|
38
|
+
// GET TYPE INFO
|
|
39
|
+
var typeNode = project.checker.typeToTypeNode(type, undefined, undefined);
|
|
40
|
+
if (typeNode === undefined)
|
|
41
|
+
return decorator;
|
|
42
|
+
// DO TRANSFORM
|
|
43
|
+
return typescript_1.default.factory.createDecorator(typescript_1.default.factory.updateCallExpression(decorator.expression, decorator.expression.expression, decorator.expression.typeArguments, [programmer(project, decorator.expression.expression)(type)]));
|
|
44
|
+
}
|
|
45
|
+
ParameterDecoratorTransformer.transform = transform;
|
|
46
|
+
})(ParameterDecoratorTransformer = exports.ParameterDecoratorTransformer || (exports.ParameterDecoratorTransformer = {}));
|
|
47
|
+
var FUNCTORS = {
|
|
48
|
+
EncryptedBody: function () { return TypedBodyProgrammer_1.TypedBodyProgrammer.generate; },
|
|
49
|
+
TypedBody: function () { return TypedBodyProgrammer_1.TypedBodyProgrammer.generate; },
|
|
50
|
+
TypedQuery: function () { return TypedQueryProgrammer_1.TypedQueryProgrammer.generate; },
|
|
51
|
+
};
|
|
52
|
+
var LIB_PATH = path_1.default.join("node_modules", "@nestia", "core", "lib", "decorators");
|
|
53
|
+
var SRC_PATH = path_1.default.resolve(path_1.default.join(__dirname, "..", "decorators"));
|
|
54
|
+
//# sourceMappingURL=ParameterDecoratorTransformer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ParameterDecoratorTransformer.js","sourceRoot":"","sources":["../../src/transformers/ParameterDec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CAAC,CAAC;QAC/D,IAAI,QAAQ,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;QAE7C,eAAe;QACf,OAAO,oBAAE,CAAC,OAAO,CAAC,eAAe,CAC7B,oBAAE,CAAC,OAAO,CAAC,oBAAoB,CAC3B,SAAS,CAAC,UAAU,EACpB,SAAS,CAAC,UAAU,CAAC,UAAU,EAC/B,SAAS,CAAC,UAAU,CAAC,aAAa,EAClC,CAAC,UAAU,CAAC,OAAO,EAAE,SAAS,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAC/D,CACJ,CAAC;IACN,CAAC;IAhDe,uCAAS,YAgDxB,CAAA;AACL,CAAC,EAlDgB,6BAA6B,GAA7B,qCAA6B,KAA7B,qCAA6B,QAkD7C;AAQD,IAAM,QAAQ,GAAqC;IAC/C,aAAa,EAAE,cAAM,OAAA,yCAAmB,CAAC,QAAQ,EAA5B,CAA4B;IACjD,SAAS,EAAE,cAAM,OAAA,yCAAmB,CAAC,QAAQ,EAA5B,CAA4B;IAC7C,UAAU,EAAE,cAAM,OAAA,2CAAoB,CAAC,QAAQ,EAA7B,CAA6B;CAClD,CAAC;AAEF,IAAM,QAAQ,GAAG,cAAI,CAAC,IAAI,CACtB,cAAc,EACd,SAAS,EACT,MAAM,EACN,KAAK,EACL,YAAY,CACf,CAAC;AACF,IAAM,QAAQ,GAAG,cAAI,CAAC,OAAO,CAAC,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC"}
|
|
@@ -5,25 +5,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ParameterTransformer = void 0;
|
|
7
7
|
var typescript_1 = __importDefault(require("typescript"));
|
|
8
|
-
var
|
|
8
|
+
var ParameterDecoratorTransformer_1 = require("./ParameterDecoratorTransformer");
|
|
9
9
|
var ParameterTransformer;
|
|
10
10
|
(function (ParameterTransformer) {
|
|
11
11
|
function transform(project, param) {
|
|
12
|
+
// CHECK DECORATOR
|
|
12
13
|
var decorators = typescript_1.default.getDecorators
|
|
13
14
|
? typescript_1.default.getDecorators(param)
|
|
14
15
|
: param.decorators;
|
|
15
16
|
if (!(decorators === null || decorators === void 0 ? void 0 : decorators.length))
|
|
16
17
|
return param;
|
|
18
|
+
// GET TYPE INFO
|
|
17
19
|
var type = project.checker.getTypeAtLocation(param);
|
|
20
|
+
// WHEN LATEST TS VERSION
|
|
18
21
|
if (typescript_1.default.getDecorators !== undefined)
|
|
19
22
|
return typescript_1.default.factory.updateParameterDeclaration(param, (param.modifiers || []).map(function (mod) {
|
|
20
23
|
return typescript_1.default.isDecorator(mod)
|
|
21
|
-
?
|
|
24
|
+
? ParameterDecoratorTransformer_1.ParameterDecoratorTransformer.transform(project, type, mod)
|
|
22
25
|
: mod;
|
|
23
26
|
}), param.dotDotDotToken, param.name, param.questionToken, param.type, param.initializer);
|
|
24
27
|
// eslint-disable-next-line
|
|
25
28
|
return typescript_1.default.factory.updateParameterDeclaration(param, decorators.map(function (deco) {
|
|
26
|
-
return
|
|
29
|
+
return ParameterDecoratorTransformer_1.ParameterDecoratorTransformer.transform(project, type, deco);
|
|
27
30
|
}), param.modifiers, param.dotDotDotToken, param.name, param.questionToken, param.type, param.initializer);
|
|
28
31
|
}
|
|
29
32
|
ParameterTransformer.transform = transform;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ParameterTransformer.js","sourceRoot":"","sources":["../../src/transformers/ParameterTransformer.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAG5B,
|
|
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,OAAg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C;IA7Ce,8BAAS,YA6CxB,CAAA;AACL,CAAC,EA/CgB,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QA+CpC"}
|
package/package.json
CHANGED
|
@@ -55,7 +55,7 @@ export function EncryptedBody<T>(validator?: IRequestBodyValidator<T>) {
|
|
|
55
55
|
);
|
|
56
56
|
if (!param)
|
|
57
57
|
throw new Error(
|
|
58
|
-
"Error on EncryptedBody(): no encryption password is given.",
|
|
58
|
+
"Error on nestia.core.EncryptedBody(): no encryption password is given.",
|
|
59
59
|
);
|
|
60
60
|
|
|
61
61
|
// GET BODY DATA
|
|
@@ -156,7 +156,7 @@ class EncryptedRouteInterceptor implements NestInterceptor {
|
|
|
156
156
|
);
|
|
157
157
|
if (!param)
|
|
158
158
|
throw new Error(
|
|
159
|
-
`Error on EncryptedRoute.${this.method}(): no encryption password is given.`,
|
|
159
|
+
`Error on nestia.core.EncryptedRoute.${this.method}(): no encryption password is given.`,
|
|
160
160
|
);
|
|
161
161
|
|
|
162
162
|
const headers: Singleton<Record<string, string>> =
|
|
@@ -31,7 +31,7 @@ export function TypedBody<T>(
|
|
|
31
31
|
context: ExecutionContext,
|
|
32
32
|
) {
|
|
33
33
|
const request: express.Request = context.switchToHttp().getRequest();
|
|
34
|
-
if (request.
|
|
34
|
+
if (!request.is("application/json")) {
|
|
35
35
|
throw new BadRequestException(
|
|
36
36
|
"Request body is not the application/json.",
|
|
37
37
|
);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ExecutionContext, createParamDecorator } from "@nestjs/common";
|
|
2
|
+
import express from "express";
|
|
3
|
+
|
|
4
|
+
import { assert } from "typia";
|
|
5
|
+
|
|
6
|
+
export function TypedQuery(decoder?: (params: URLSearchParams) => any) {
|
|
7
|
+
if (decoder === undefined)
|
|
8
|
+
throw new Error("Error on TypedQuery(): no decoder function provided.");
|
|
9
|
+
|
|
10
|
+
return createParamDecorator(async function TypedQuery(
|
|
11
|
+
_unknown: any,
|
|
12
|
+
ctx: ExecutionContext,
|
|
13
|
+
) {
|
|
14
|
+
const request: express.Request = ctx.switchToHttp().getRequest();
|
|
15
|
+
const params: URLSearchParams = new URLSearchParams(tail(request.url));
|
|
16
|
+
return decoder(params);
|
|
17
|
+
})();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export namespace TypedQuery {
|
|
24
|
+
export function boolean(str: string | null): boolean | undefined {
|
|
25
|
+
return str !== null ? Boolean(str) : undefined;
|
|
26
|
+
}
|
|
27
|
+
export function number(str: string | null): number | undefined {
|
|
28
|
+
return str !== null ? Number(str) : undefined;
|
|
29
|
+
}
|
|
30
|
+
export function bigint(str: string | null): bigint | undefined {
|
|
31
|
+
return str !== null ? BigInt(str) : undefined;
|
|
32
|
+
}
|
|
33
|
+
export function string(str: string | null): string | undefined {
|
|
34
|
+
return str ?? undefined;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
Object.assign(TypedQuery, assert);
|
|
38
|
+
|
|
39
|
+
function tail(url: string): string {
|
|
40
|
+
const index: number = url.indexOf("?");
|
|
41
|
+
return index === -1 ? "" : url.substring(index + 1);
|
|
42
|
+
}
|
package/src/module.ts
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { AssertProgrammer } from "typia/lib/programmers/AssertProgrammer";
|
|
4
|
+
import { IsProgrammer } from "typia/lib/programmers/IsProgrammer";
|
|
5
|
+
import { ValidateProgrammer } from "typia/lib/programmers/ValidateProgrammer";
|
|
6
|
+
import { IProject } from "typia/lib/transformers/IProject";
|
|
7
|
+
|
|
8
|
+
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
9
|
+
|
|
10
|
+
export namespace TypedBodyProgrammer {
|
|
11
|
+
export const generate =
|
|
12
|
+
(project: INestiaTransformProject, modulo: ts.LeftHandSideExpression) =>
|
|
13
|
+
(type: ts.Type): ts.ObjectLiteralExpression => {
|
|
14
|
+
// GENERATE VALIDATION PLAN
|
|
15
|
+
const parameter = (
|
|
16
|
+
key: string,
|
|
17
|
+
programmer: (
|
|
18
|
+
project: IProject,
|
|
19
|
+
modulo: ts.LeftHandSideExpression,
|
|
20
|
+
) => (type: ts.Type) => ts.ArrowFunction,
|
|
21
|
+
) =>
|
|
22
|
+
ts.factory.createObjectLiteralExpression([
|
|
23
|
+
ts.factory.createPropertyAssignment(
|
|
24
|
+
ts.factory.createIdentifier("type"),
|
|
25
|
+
ts.factory.createStringLiteral(key),
|
|
26
|
+
),
|
|
27
|
+
ts.factory.createPropertyAssignment(
|
|
28
|
+
ts.factory.createIdentifier(key),
|
|
29
|
+
programmer(
|
|
30
|
+
{
|
|
31
|
+
...project,
|
|
32
|
+
options: {
|
|
33
|
+
numeric: false,
|
|
34
|
+
finite: false,
|
|
35
|
+
functional: false,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
modulo,
|
|
39
|
+
)(type),
|
|
40
|
+
),
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
// RETURNS
|
|
44
|
+
if (project.options.validate === "is")
|
|
45
|
+
return parameter("is", IsProgrammer.generate);
|
|
46
|
+
else if (project.options.validate === "validate")
|
|
47
|
+
return parameter("validate", ValidateProgrammer.generate);
|
|
48
|
+
return parameter("assert", AssertProgrammer.generate);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
|
4
|
+
import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
|
|
5
|
+
import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
|
|
6
|
+
import { StatementFactory } from "typia/lib/factories/StatementFactory";
|
|
7
|
+
import { Metadata } from "typia/lib/metadata/Metadata";
|
|
8
|
+
import { MetadataObject } from "typia/lib/metadata/MetadataObject";
|
|
9
|
+
import { MetadataProperty } from "typia/lib/metadata/MetadataProperty";
|
|
10
|
+
import { AssertProgrammer } from "typia/lib/programmers/AssertProgrammer";
|
|
11
|
+
import { FunctionImporter } from "typia/lib/programmers/helpers/FunctionImporeter";
|
|
12
|
+
import { Atomic } from "typia/lib/typings/Atomic";
|
|
13
|
+
|
|
14
|
+
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
15
|
+
|
|
16
|
+
export namespace TypedQueryProgrammer {
|
|
17
|
+
export const generate =
|
|
18
|
+
(project: INestiaTransformProject, modulo: ts.LeftHandSideExpression) =>
|
|
19
|
+
(type: ts.Type): ts.Expression => {
|
|
20
|
+
const object: MetadataObject = getObject(project.checker)(type);
|
|
21
|
+
return decode(project, modulo)(type, object);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const getObject =
|
|
25
|
+
(checker: ts.TypeChecker) =>
|
|
26
|
+
(type: ts.Type): MetadataObject => {
|
|
27
|
+
const collection: MetadataCollection = new MetadataCollection();
|
|
28
|
+
const metadata: Metadata = MetadataFactory.generate(
|
|
29
|
+
checker,
|
|
30
|
+
collection,
|
|
31
|
+
type,
|
|
32
|
+
{
|
|
33
|
+
resolve: false,
|
|
34
|
+
constant: true,
|
|
35
|
+
},
|
|
36
|
+
);
|
|
37
|
+
if (metadata.objects.length !== 1 || metadata.bucket() !== 1)
|
|
38
|
+
throw new Error(
|
|
39
|
+
ErrorMessages.object(metadata)(
|
|
40
|
+
"only one object type is allowed.",
|
|
41
|
+
),
|
|
42
|
+
);
|
|
43
|
+
else if (metadata.nullable === true)
|
|
44
|
+
throw new Error(
|
|
45
|
+
ErrorMessages.object(metadata)(
|
|
46
|
+
"target type T cannot be null.",
|
|
47
|
+
),
|
|
48
|
+
);
|
|
49
|
+
else if (metadata.required === false)
|
|
50
|
+
throw new Error(
|
|
51
|
+
ErrorMessages.object(metadata)(
|
|
52
|
+
"target type T cannot be undefined.",
|
|
53
|
+
),
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const object = metadata.objects[0]!;
|
|
57
|
+
for (const property of object.properties) {
|
|
58
|
+
const key: Metadata = property.key;
|
|
59
|
+
const value: Metadata = property.value;
|
|
60
|
+
|
|
61
|
+
if (
|
|
62
|
+
(value.atomics.length ? 1 : 0) +
|
|
63
|
+
(value.constants.length ? 1 : 0) +
|
|
64
|
+
(value.templates.length ? 1 : 0) !==
|
|
65
|
+
value.bucket()
|
|
66
|
+
)
|
|
67
|
+
throw new Error(
|
|
68
|
+
ErrorMessages.property(object)(key)(
|
|
69
|
+
"only atomic typed propertie are allowed.",
|
|
70
|
+
),
|
|
71
|
+
);
|
|
72
|
+
else if (value.atomics.length > 1 || value.constants.length > 1)
|
|
73
|
+
throw new Error(
|
|
74
|
+
ErrorMessages.property(object)(key)(
|
|
75
|
+
"union type is not allowed.",
|
|
76
|
+
),
|
|
77
|
+
);
|
|
78
|
+
else if (value.nullable === true)
|
|
79
|
+
throw new Error(
|
|
80
|
+
ErrorMessages.property(object)(key)(
|
|
81
|
+
"property type cannot be null. Use undefined instead.",
|
|
82
|
+
),
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
return object;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const decode =
|
|
89
|
+
(project: INestiaTransformProject, modulo: ts.LeftHandSideExpression) =>
|
|
90
|
+
(type: ts.Type, object: MetadataObject): ts.ArrowFunction =>
|
|
91
|
+
ts.factory.createArrowFunction(
|
|
92
|
+
undefined,
|
|
93
|
+
undefined,
|
|
94
|
+
[IdentifierFactory.parameter("input")],
|
|
95
|
+
undefined,
|
|
96
|
+
undefined,
|
|
97
|
+
decode_object(project, modulo)(type, object),
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const decode_object =
|
|
101
|
+
(project: INestiaTransformProject, modulo: ts.LeftHandSideExpression) =>
|
|
102
|
+
(type: ts.Type, object: MetadataObject): ts.ConciseBody => {
|
|
103
|
+
const assert: ts.ArrowFunction = AssertProgrammer.generate(
|
|
104
|
+
{
|
|
105
|
+
...project,
|
|
106
|
+
options: {
|
|
107
|
+
numeric: true,
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
modulo,
|
|
111
|
+
)(type);
|
|
112
|
+
const output = ts.factory.createIdentifier("output");
|
|
113
|
+
|
|
114
|
+
const importer = new FunctionImporter();
|
|
115
|
+
const statements: ts.Statement[] = [
|
|
116
|
+
StatementFactory.constant(
|
|
117
|
+
"output",
|
|
118
|
+
ts.factory.createObjectLiteralExpression(
|
|
119
|
+
object.properties
|
|
120
|
+
.filter((prop) => (prop.key as any).isSoleLiteral())
|
|
121
|
+
.map((prop) =>
|
|
122
|
+
decode_regular_property(importer)(prop),
|
|
123
|
+
),
|
|
124
|
+
true,
|
|
125
|
+
),
|
|
126
|
+
),
|
|
127
|
+
ts.factory.createReturnStatement(
|
|
128
|
+
ts.factory.createCallExpression(assert, undefined, [
|
|
129
|
+
output,
|
|
130
|
+
]),
|
|
131
|
+
),
|
|
132
|
+
];
|
|
133
|
+
|
|
134
|
+
return ts.factory.createBlock(
|
|
135
|
+
[...importer.declare(modulo), ...statements],
|
|
136
|
+
true,
|
|
137
|
+
);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const decode_regular_property =
|
|
141
|
+
(importer: FunctionImporter) =>
|
|
142
|
+
(property: MetadataProperty): ts.PropertyAssignment => {
|
|
143
|
+
const key: string = property.key.constants[0]!.values[0] as string;
|
|
144
|
+
const value: Metadata = property.value;
|
|
145
|
+
|
|
146
|
+
const type: Atomic.Literal = value.atomics.length
|
|
147
|
+
? value.atomics[0]!
|
|
148
|
+
: value.constants.length
|
|
149
|
+
? value.constants[0]!.type
|
|
150
|
+
: "string";
|
|
151
|
+
return ts.factory.createPropertyAssignment(
|
|
152
|
+
key,
|
|
153
|
+
decode_value(importer)(type)(
|
|
154
|
+
ts.factory.createCallExpression(
|
|
155
|
+
ts.factory.createIdentifier("input.get"),
|
|
156
|
+
undefined,
|
|
157
|
+
[ts.factory.createStringLiteral(key)],
|
|
158
|
+
),
|
|
159
|
+
),
|
|
160
|
+
);
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const decode_value =
|
|
164
|
+
(importer: FunctionImporter) =>
|
|
165
|
+
(type: Atomic.Literal) =>
|
|
166
|
+
(value: ts.Expression) =>
|
|
167
|
+
ts.factory.createCallExpression(importer.use(type), undefined, [
|
|
168
|
+
value,
|
|
169
|
+
]);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
namespace ErrorMessages {
|
|
173
|
+
export const object = (type: Metadata) => (message: string) =>
|
|
174
|
+
`Error on nestia.core.TypedQuery<${type}>(): ${message}`;
|
|
175
|
+
|
|
176
|
+
export const property =
|
|
177
|
+
(obj: MetadataObject) => (key: Metadata) => (message: string) =>
|
|
178
|
+
`Error on nestia.core.TypedQuery<${
|
|
179
|
+
obj.name
|
|
180
|
+
}>(): property ${key.getName()} - ${message}`;
|
|
181
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { AssertStringifyProgrammer } from "typia/lib/programmers/AssertStringifyProgrammer";
|
|
4
|
+
import { IsStringifyProgrammer } from "typia/lib/programmers/IsStringifyProgrammer";
|
|
5
|
+
import { StringifyProgrammer } from "typia/lib/programmers/StringifyProgrammer";
|
|
6
|
+
import { ValidateStringifyProgrammer } from "typia/lib/programmers/ValidateStringifyProgrammer";
|
|
7
|
+
import { IProject } from "typia/lib/transformers/IProject";
|
|
8
|
+
|
|
9
|
+
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
10
|
+
|
|
11
|
+
export namespace TypedRouteProgrammer {
|
|
12
|
+
export const generate =
|
|
13
|
+
(project: INestiaTransformProject, modulo: ts.LeftHandSideExpression) =>
|
|
14
|
+
(type: ts.Type): ts.Expression => {
|
|
15
|
+
// GENERATE STRINGIFY PLAN
|
|
16
|
+
const parameter = (
|
|
17
|
+
key: string,
|
|
18
|
+
programmer: (
|
|
19
|
+
project: IProject,
|
|
20
|
+
modulo: ts.LeftHandSideExpression,
|
|
21
|
+
) => (type: ts.Type) => ts.ArrowFunction,
|
|
22
|
+
) =>
|
|
23
|
+
ts.factory.createObjectLiteralExpression([
|
|
24
|
+
ts.factory.createPropertyAssignment(
|
|
25
|
+
ts.factory.createIdentifier("type"),
|
|
26
|
+
ts.factory.createStringLiteral(key),
|
|
27
|
+
),
|
|
28
|
+
ts.factory.createPropertyAssignment(
|
|
29
|
+
ts.factory.createIdentifier(key),
|
|
30
|
+
programmer(
|
|
31
|
+
{
|
|
32
|
+
...project,
|
|
33
|
+
options: {}, // use default option
|
|
34
|
+
},
|
|
35
|
+
modulo,
|
|
36
|
+
)(type),
|
|
37
|
+
),
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
// RETURNS
|
|
41
|
+
if (project.options.stringify === "stringify")
|
|
42
|
+
return parameter("stringify", StringifyProgrammer.generate);
|
|
43
|
+
else if (project.options.stringify === "assert")
|
|
44
|
+
return parameter("assert", AssertStringifyProgrammer.generate);
|
|
45
|
+
else if (project.options.stringify === "validate")
|
|
46
|
+
return parameter(
|
|
47
|
+
"validate",
|
|
48
|
+
ValidateStringifyProgrammer.generate,
|
|
49
|
+
);
|
|
50
|
+
else if (project.options.stringify === null)
|
|
51
|
+
return ts.factory.createNull();
|
|
52
|
+
return parameter("is", IsStringifyProgrammer.generate);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
|
|
4
|
+
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
5
|
+
import { TypedRouteProgrammer } from "../programmers/TypedRouteProgrammer";
|
|
6
|
+
|
|
7
|
+
export namespace MethodDecoratorTransformer {
|
|
8
|
+
export function transform(
|
|
9
|
+
project: INestiaTransformProject,
|
|
10
|
+
type: ts.Type,
|
|
11
|
+
decorator: ts.Decorator,
|
|
12
|
+
): ts.Decorator {
|
|
13
|
+
if (!ts.isCallExpression(decorator.expression)) return decorator;
|
|
14
|
+
|
|
15
|
+
// CHECK SIGNATURE
|
|
16
|
+
const signature: ts.Signature | undefined =
|
|
17
|
+
project.checker.getResolvedSignature(decorator.expression);
|
|
18
|
+
if (!signature || !signature.declaration) return decorator;
|
|
19
|
+
|
|
20
|
+
// CHECK TO BE TRANSFORMED
|
|
21
|
+
const done: boolean = (() => {
|
|
22
|
+
// CHECK FILENAME
|
|
23
|
+
const location: string = path.resolve(
|
|
24
|
+
signature.declaration.getSourceFile().fileName,
|
|
25
|
+
);
|
|
26
|
+
if (
|
|
27
|
+
LIB_PATHS.every((str) => location.indexOf(str) === -1) &&
|
|
28
|
+
SRC_PATHS.every((str) => location !== str)
|
|
29
|
+
)
|
|
30
|
+
return false;
|
|
31
|
+
|
|
32
|
+
// CHECK DUPLICATE BOOSTER
|
|
33
|
+
if (decorator.expression.arguments.length >= 2) return false;
|
|
34
|
+
else if (decorator.expression.arguments.length === 1) {
|
|
35
|
+
const last: ts.Expression =
|
|
36
|
+
decorator.expression.arguments[
|
|
37
|
+
decorator.expression.arguments.length - 1
|
|
38
|
+
];
|
|
39
|
+
const type: ts.Type = project.checker.getTypeAtLocation(last);
|
|
40
|
+
if (isObject(project.checker, type)) return false;
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
})();
|
|
44
|
+
if (done === false) return decorator;
|
|
45
|
+
|
|
46
|
+
// CHECK TYPE NODE
|
|
47
|
+
const typeNode: ts.TypeNode | undefined =
|
|
48
|
+
project.checker.typeToTypeNode(type, undefined, undefined);
|
|
49
|
+
if (typeNode === undefined) return decorator;
|
|
50
|
+
|
|
51
|
+
// DO TRANSFORM
|
|
52
|
+
return ts.factory.createDecorator(
|
|
53
|
+
ts.factory.updateCallExpression(
|
|
54
|
+
decorator.expression,
|
|
55
|
+
decorator.expression.expression,
|
|
56
|
+
decorator.expression.typeArguments,
|
|
57
|
+
[
|
|
58
|
+
...decorator.expression.arguments,
|
|
59
|
+
TypedRouteProgrammer.generate(
|
|
60
|
+
project,
|
|
61
|
+
decorator.expression.expression,
|
|
62
|
+
)(type),
|
|
63
|
+
],
|
|
64
|
+
),
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function isObject(checker: ts.TypeChecker, type: ts.Type): boolean {
|
|
69
|
+
return (
|
|
70
|
+
(type.getFlags() & ts.TypeFlags.Object) !== 0 &&
|
|
71
|
+
!(checker as any).isTupleType(type) &&
|
|
72
|
+
!(checker as any).isArrayType(type) &&
|
|
73
|
+
!(checker as any).isArrayLikeType(type)
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const CLASSES = ["EncryptedRoute", "TypedRoute"];
|
|
78
|
+
const LIB_PATHS = CLASSES.map((cla) =>
|
|
79
|
+
path.join(
|
|
80
|
+
"node_modules",
|
|
81
|
+
"@nestia",
|
|
82
|
+
"core",
|
|
83
|
+
"lib",
|
|
84
|
+
"decorators",
|
|
85
|
+
`${cla}.d.ts`,
|
|
86
|
+
),
|
|
87
|
+
);
|
|
88
|
+
const SRC_PATHS = CLASSES.map((cla) =>
|
|
89
|
+
path.resolve(path.join(__dirname, "..", "decorators", `${cla}.ts`)),
|
|
90
|
+
);
|
|
91
|
+
}
|