@nestia/core 1.0.7 → 1.0.9
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 +24 -0
- 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 -8
- 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 -8
- 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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
|
|
3
3
|
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
4
|
-
import {
|
|
4
|
+
import { MethodDecoratorTransformer } from "./MethodDecoratorTransformer";
|
|
5
5
|
|
|
6
6
|
export namespace MethodTransformer {
|
|
7
7
|
export function transform(
|
|
@@ -27,7 +27,11 @@ export namespace MethodTransformer {
|
|
|
27
27
|
method,
|
|
28
28
|
(method.modifiers || []).map((mod) =>
|
|
29
29
|
ts.isDecorator(mod)
|
|
30
|
-
?
|
|
30
|
+
? MethodDecoratorTransformer.transform(
|
|
31
|
+
project,
|
|
32
|
+
escaped,
|
|
33
|
+
mod,
|
|
34
|
+
)
|
|
31
35
|
: mod,
|
|
32
36
|
),
|
|
33
37
|
method.asteriskToken,
|
|
@@ -42,7 +46,7 @@ export namespace MethodTransformer {
|
|
|
42
46
|
return ts.factory.updateMethodDeclaration(
|
|
43
47
|
method,
|
|
44
48
|
decorators.map((deco) =>
|
|
45
|
-
|
|
49
|
+
MethodDecoratorTransformer.transform(project, escaped, deco),
|
|
46
50
|
),
|
|
47
51
|
(method as any).modifiers,
|
|
48
52
|
method.asteriskToken,
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
|
|
4
|
+
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
5
|
+
import { TypedBodyProgrammer } from "../programmers/TypedBodyProgrammer";
|
|
6
|
+
import { TypedQueryProgrammer } from "../programmers/TypedQueryProgrammer";
|
|
7
|
+
|
|
8
|
+
export namespace ParameterDecoratorTransformer {
|
|
9
|
+
export function transform(
|
|
10
|
+
project: INestiaTransformProject,
|
|
11
|
+
type: ts.Type,
|
|
12
|
+
decorator: ts.Decorator,
|
|
13
|
+
): ts.Decorator {
|
|
14
|
+
//----
|
|
15
|
+
// VALIDATIONS
|
|
16
|
+
//----
|
|
17
|
+
// CHECK DECORATOR
|
|
18
|
+
if (!ts.isCallExpression(decorator.expression)) return decorator;
|
|
19
|
+
else if (decorator.expression.arguments.length !== 0) return decorator;
|
|
20
|
+
|
|
21
|
+
// SIGNATURE DECLARATION
|
|
22
|
+
const declaration: ts.Declaration | undefined =
|
|
23
|
+
project.checker.getResolvedSignature(
|
|
24
|
+
decorator.expression,
|
|
25
|
+
)?.declaration;
|
|
26
|
+
if (declaration === undefined) return decorator;
|
|
27
|
+
|
|
28
|
+
// FILE PATH
|
|
29
|
+
const file: string = path.resolve(declaration.getSourceFile().fileName);
|
|
30
|
+
if (file.indexOf(LIB_PATH) === -1 && file.indexOf(SRC_PATH) === -1)
|
|
31
|
+
return decorator;
|
|
32
|
+
|
|
33
|
+
//----
|
|
34
|
+
// TRANSFORMATION
|
|
35
|
+
//----
|
|
36
|
+
// FIND PROGRAMMER
|
|
37
|
+
const programmer: Programmer | undefined =
|
|
38
|
+
FUNCTORS[
|
|
39
|
+
project.checker.getTypeAtLocation(declaration).symbol.name
|
|
40
|
+
]?.();
|
|
41
|
+
if (programmer === undefined) return decorator;
|
|
42
|
+
|
|
43
|
+
// GET TYPE INFO
|
|
44
|
+
const typeNode: ts.TypeNode | undefined =
|
|
45
|
+
project.checker.typeToTypeNode(type, undefined, undefined);
|
|
46
|
+
if (typeNode === undefined) return decorator;
|
|
47
|
+
|
|
48
|
+
// DO TRANSFORM
|
|
49
|
+
return ts.factory.createDecorator(
|
|
50
|
+
ts.factory.updateCallExpression(
|
|
51
|
+
decorator.expression,
|
|
52
|
+
decorator.expression.expression,
|
|
53
|
+
decorator.expression.typeArguments,
|
|
54
|
+
[programmer(project, decorator.expression.expression)(type)],
|
|
55
|
+
),
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface Programmer {
|
|
61
|
+
(project: INestiaTransformProject, expression: ts.LeftHandSideExpression): (
|
|
62
|
+
type: ts.Type,
|
|
63
|
+
) => ts.Expression;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const FUNCTORS: Record<string, () => Programmer> = {
|
|
67
|
+
EncryptedBody: () => TypedBodyProgrammer.generate,
|
|
68
|
+
TypedBody: () => TypedBodyProgrammer.generate,
|
|
69
|
+
TypedQuery: () => TypedQueryProgrammer.generate,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const LIB_PATH = path.join(
|
|
73
|
+
"node_modules",
|
|
74
|
+
"@nestia",
|
|
75
|
+
"core",
|
|
76
|
+
"lib",
|
|
77
|
+
"decorators",
|
|
78
|
+
);
|
|
79
|
+
const SRC_PATH = path.resolve(path.join(__dirname, "..", "decorators"));
|
|
@@ -1,25 +1,33 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
|
|
3
3
|
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
4
|
-
import {
|
|
4
|
+
import { ParameterDecoratorTransformer } from "./ParameterDecoratorTransformer";
|
|
5
5
|
|
|
6
6
|
export namespace ParameterTransformer {
|
|
7
7
|
export function transform(
|
|
8
8
|
project: INestiaTransformProject,
|
|
9
9
|
param: ts.ParameterDeclaration,
|
|
10
10
|
): ts.ParameterDeclaration {
|
|
11
|
+
// CHECK DECORATOR
|
|
11
12
|
const decorators: readonly ts.Decorator[] | undefined = ts.getDecorators
|
|
12
13
|
? ts.getDecorators(param)
|
|
13
14
|
: (param as any).decorators;
|
|
14
15
|
if (!decorators?.length) return param;
|
|
15
16
|
|
|
17
|
+
// GET TYPE INFO
|
|
16
18
|
const type: ts.Type = project.checker.getTypeAtLocation(param);
|
|
19
|
+
|
|
20
|
+
// WHEN LATEST TS VERSION
|
|
17
21
|
if (ts.getDecorators !== undefined)
|
|
18
22
|
return ts.factory.updateParameterDeclaration(
|
|
19
23
|
param,
|
|
20
24
|
(param.modifiers || []).map((mod) =>
|
|
21
25
|
ts.isDecorator(mod)
|
|
22
|
-
?
|
|
26
|
+
? ParameterDecoratorTransformer.transform(
|
|
27
|
+
project,
|
|
28
|
+
type,
|
|
29
|
+
mod,
|
|
30
|
+
)
|
|
23
31
|
: mod,
|
|
24
32
|
),
|
|
25
33
|
param.dotDotDotToken,
|
|
@@ -32,7 +40,7 @@ export namespace ParameterTransformer {
|
|
|
32
40
|
return ts.factory.updateParameterDeclaration(
|
|
33
41
|
param,
|
|
34
42
|
decorators.map((deco) =>
|
|
35
|
-
|
|
43
|
+
ParameterDecoratorTransformer.transform(project, type, deco),
|
|
36
44
|
),
|
|
37
45
|
(param as any).modifiers,
|
|
38
46
|
param.dotDotDotToken,
|
|
@@ -1,84 +0,0 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.BodyTransformer = void 0;
|
|
18
|
-
var path_1 = __importDefault(require("path"));
|
|
19
|
-
var typescript_1 = __importDefault(require("typescript"));
|
|
20
|
-
var AssertProgrammer_1 = require("typia/lib/programmers/AssertProgrammer");
|
|
21
|
-
var IsProgrammer_1 = require("typia/lib/programmers/IsProgrammer");
|
|
22
|
-
var ValidateProgrammer_1 = require("typia/lib/programmers/ValidateProgrammer");
|
|
23
|
-
var BodyTransformer;
|
|
24
|
-
(function (BodyTransformer) {
|
|
25
|
-
function transform(project, type, decorator) {
|
|
26
|
-
if (!typescript_1.default.isCallExpression(decorator.expression))
|
|
27
|
-
return decorator;
|
|
28
|
-
return typescript_1.default.factory.createDecorator(validate(project, type, decorator.expression));
|
|
29
|
-
}
|
|
30
|
-
BodyTransformer.transform = transform;
|
|
31
|
-
function validate(project, type, expression) {
|
|
32
|
-
// CHECK SIGNATURE
|
|
33
|
-
var signature = project.checker.getResolvedSignature(expression);
|
|
34
|
-
if (!signature || !signature.declaration)
|
|
35
|
-
return expression;
|
|
36
|
-
// CHECK TO BE TRANSFORMED
|
|
37
|
-
var validate = (function () {
|
|
38
|
-
// CHECK FILENAME
|
|
39
|
-
var location = path_1.default.resolve(signature.declaration.getSourceFile().fileName);
|
|
40
|
-
if (LIB_PATHS.every(function (str) { return location.indexOf(str) === -1; }) &&
|
|
41
|
-
SRC_PATHS.every(function (str) { return location !== str; }))
|
|
42
|
-
return false;
|
|
43
|
-
// CHECK DUPLICATED TRANSFORMATION
|
|
44
|
-
return expression.arguments.length === 0;
|
|
45
|
-
})();
|
|
46
|
-
if (validate === false)
|
|
47
|
-
return expression;
|
|
48
|
-
// CHECK TYPE NODE
|
|
49
|
-
var typeNode = project.checker.typeToTypeNode(type, undefined, undefined);
|
|
50
|
-
if (typeNode === undefined)
|
|
51
|
-
return expression;
|
|
52
|
-
//----
|
|
53
|
-
// TRANSFORMATION
|
|
54
|
-
//----
|
|
55
|
-
// GENERATE VALIDATION PLAN
|
|
56
|
-
var parameter = function (key, programmer) {
|
|
57
|
-
return typescript_1.default.factory.createObjectLiteralExpression([
|
|
58
|
-
typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier("type"), typescript_1.default.factory.createStringLiteral(key)),
|
|
59
|
-
typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier(key), programmer(__assign(__assign({}, project), { options: {
|
|
60
|
-
numeric: false,
|
|
61
|
-
finite: false,
|
|
62
|
-
functional: false,
|
|
63
|
-
} }), expression.expression)(type)),
|
|
64
|
-
]);
|
|
65
|
-
};
|
|
66
|
-
var validator = (function () {
|
|
67
|
-
if (project.options.validate === "is")
|
|
68
|
-
return parameter("is", IsProgrammer_1.IsProgrammer.generate);
|
|
69
|
-
else if (project.options.validate === "validate")
|
|
70
|
-
return parameter("validate", ValidateProgrammer_1.ValidateProgrammer.generate);
|
|
71
|
-
return parameter("assert", AssertProgrammer_1.AssertProgrammer.generate);
|
|
72
|
-
})();
|
|
73
|
-
// UPDATE DECORATOR FUNCTION CALL
|
|
74
|
-
return typescript_1.default.factory.updateCallExpression(expression, expression.expression, expression.typeArguments, [validator]);
|
|
75
|
-
}
|
|
76
|
-
var CLASSES = ["EncryptedBody", "TypedBody"];
|
|
77
|
-
var LIB_PATHS = CLASSES.map(function (cla) {
|
|
78
|
-
return path_1.default.join("node_modules", "@nestia", "core", "lib", "decorators", "".concat(cla, ".d.ts"));
|
|
79
|
-
});
|
|
80
|
-
var SRC_PATHS = CLASSES.map(function (cla) {
|
|
81
|
-
return path_1.default.resolve(path_1.default.join(__dirname, "..", "decorators", "".concat(cla, ".ts")));
|
|
82
|
-
});
|
|
83
|
-
})(BodyTransformer = exports.BodyTransformer || (exports.BodyTransformer = {}));
|
|
84
|
-
//# sourceMappingURL=B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Q,CAAC,CAAC;YAC9D,OAAO,SAAS,CAAC,QAAQ,EAAE,mCAAgB,CAAC,QAAQ,CAAC,CAAC;QAC1D,CAAC,CAAC,EAAE,CAAC;QAEL,iCAAiC;QACjC,OAAO,oBAAE,CAAC,OAAO,CAAC,oBAAoB,CAClC,UAAU,EACV,UAAU,CAAC,UAAU,EACrB,UAAU,CAAC,aAAa,EACxB,CAAC,SAAS,CAAC,CACd,CAAC;IACN,CAAC;IAED,IAAM,OAAO,GAAG,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC;IAC/C,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,EA1GgB,eAAe,GAAf,uBAAe,KAAf,uBAAe,QA0G/B"}
|
|
@@ -1,127 +0,0 @@
|
|
|
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 __read = (this && this.__read) || function (o, n) {
|
|
14
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
-
if (!m) return o;
|
|
16
|
-
var i = m.call(o), r, ar = [], e;
|
|
17
|
-
try {
|
|
18
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
-
}
|
|
20
|
-
catch (error) { e = { error: error }; }
|
|
21
|
-
finally {
|
|
22
|
-
try {
|
|
23
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
-
}
|
|
25
|
-
finally { if (e) throw e.error; }
|
|
26
|
-
}
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
30
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
-
if (ar || !(i in from)) {
|
|
32
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
-
ar[i] = from[i];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
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.RouteTransformer = void 0;
|
|
43
|
-
var path_1 = __importDefault(require("path"));
|
|
44
|
-
var typescript_1 = __importDefault(require("typescript"));
|
|
45
|
-
var AssertStringifyProgrammer_1 = require("typia/lib/programmers/AssertStringifyProgrammer");
|
|
46
|
-
var IsStringifyProgrammer_1 = require("typia/lib/programmers/IsStringifyProgrammer");
|
|
47
|
-
var StringifyProgrammer_1 = require("typia/lib/programmers/StringifyProgrammer");
|
|
48
|
-
var ValidateStringifyProgrammer_1 = require("typia/lib/programmers/ValidateStringifyProgrammer");
|
|
49
|
-
var RouteTransformer;
|
|
50
|
-
(function (RouteTransformer) {
|
|
51
|
-
function transform(project, type, decorator) {
|
|
52
|
-
if (!typescript_1.default.isCallExpression(decorator.expression))
|
|
53
|
-
return decorator;
|
|
54
|
-
return typescript_1.default.factory.createDecorator(stringify(project, type, decorator.expression));
|
|
55
|
-
}
|
|
56
|
-
RouteTransformer.transform = transform;
|
|
57
|
-
function stringify(project, type, expression) {
|
|
58
|
-
//----
|
|
59
|
-
// VALIDATIONS
|
|
60
|
-
//----
|
|
61
|
-
// CHECK SIGNATURE
|
|
62
|
-
var signature = project.checker.getResolvedSignature(expression);
|
|
63
|
-
if (!signature || !signature.declaration)
|
|
64
|
-
return expression;
|
|
65
|
-
// CHECK TO BE TRANSFORMED
|
|
66
|
-
var done = (function () {
|
|
67
|
-
// CHECK FILENAME
|
|
68
|
-
var location = path_1.default.resolve(signature.declaration.getSourceFile().fileName);
|
|
69
|
-
if (LIB_PATHS.every(function (str) { return location.indexOf(str) === -1; }) &&
|
|
70
|
-
SRC_PATHS.every(function (str) { return location !== str; }))
|
|
71
|
-
return false;
|
|
72
|
-
// CHECK DUPLICATE BOOSTER
|
|
73
|
-
if (expression.arguments.length >= 2)
|
|
74
|
-
return false;
|
|
75
|
-
else if (expression.arguments.length === 1) {
|
|
76
|
-
var last = expression.arguments[expression.arguments.length - 1];
|
|
77
|
-
var type_1 = project.checker.getTypeAtLocation(last);
|
|
78
|
-
if (isObject(project.checker, type_1))
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
return true;
|
|
82
|
-
})();
|
|
83
|
-
if (done === false)
|
|
84
|
-
return expression;
|
|
85
|
-
// CHECK TYPE NODE
|
|
86
|
-
var typeNode = project.checker.typeToTypeNode(type, undefined, undefined);
|
|
87
|
-
if (typeNode === undefined)
|
|
88
|
-
return expression;
|
|
89
|
-
//----
|
|
90
|
-
// TRANSFORMATION
|
|
91
|
-
//----
|
|
92
|
-
// GENERATE STRINGIFY PLAN
|
|
93
|
-
var parameter = function (key, programmer) {
|
|
94
|
-
return typescript_1.default.factory.createObjectLiteralExpression([
|
|
95
|
-
typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier("type"), typescript_1.default.factory.createStringLiteral(key)),
|
|
96
|
-
typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier(key), programmer(__assign(__assign({}, project), { options: {} }), expression.expression)(type)),
|
|
97
|
-
]);
|
|
98
|
-
};
|
|
99
|
-
var stringify = (function () {
|
|
100
|
-
if (project.options.stringify === "stringify")
|
|
101
|
-
return parameter("stringify", StringifyProgrammer_1.StringifyProgrammer.generate);
|
|
102
|
-
else if (project.options.stringify === "assert")
|
|
103
|
-
return parameter("assert", AssertStringifyProgrammer_1.AssertStringifyProgrammer.generate);
|
|
104
|
-
else if (project.options.stringify === "validate")
|
|
105
|
-
return parameter("validate", ValidateStringifyProgrammer_1.ValidateStringifyProgrammer.generate);
|
|
106
|
-
else if (project.options.stringify === null)
|
|
107
|
-
return typescript_1.default.factory.createNull();
|
|
108
|
-
return parameter("is", IsStringifyProgrammer_1.IsStringifyProgrammer.generate);
|
|
109
|
-
})();
|
|
110
|
-
// UPDATE DECORATOR FUNCTION CALL
|
|
111
|
-
return typescript_1.default.factory.updateCallExpression(expression, expression.expression, expression.typeArguments, __spreadArray(__spreadArray([], __read(expression.arguments), false), [stringify], false));
|
|
112
|
-
}
|
|
113
|
-
function isObject(checker, type) {
|
|
114
|
-
return ((type.getFlags() & typescript_1.default.TypeFlags.Object) !== 0 &&
|
|
115
|
-
!checker.isTupleType(type) &&
|
|
116
|
-
!checker.isArrayType(type) &&
|
|
117
|
-
!checker.isArrayLikeType(type));
|
|
118
|
-
}
|
|
119
|
-
var CLASSES = ["EncryptedRoute", "TypedRoute"];
|
|
120
|
-
var LIB_PATHS = CLASSES.map(function (cla) {
|
|
121
|
-
return path_1.default.join("node_modules", "@nestia", "core", "lib", "decorators", "".concat(cla, ".d.ts"));
|
|
122
|
-
});
|
|
123
|
-
var SRC_PATHS = CLASSES.map(function (cla) {
|
|
124
|
-
return path_1.default.resolve(path_1.default.join(__dirname, "..", "decorators", "".concat(cla, ".ts")));
|
|
125
|
-
});
|
|
126
|
-
})(RouteTransformer = exports.RouteTransformer || (exports.RouteTransformer = {}));
|
|
127
|
-
//# sourceMappingURL=RouteTransformer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RouteTransformer.js","sourceRoot":"","sources":["../../src/transformers/RouteTransformer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAwB;AACxB,0DAA4B;AAC5B,6FAA4F;AAC5F,qFAAoF;AACpF,iFAAgF;AAChF,iGAAgG;AAKhG,IAAiB,gBAAgB,CAgIhC;AAhID,WAAiB,gBAAgB;IAC7B,SAAgB,SAAS,CACrB,OAAgC,EAChC,IAAa,EACb,SAAuB;QAEvB,IAAI,CAAC,oBAAE,CAAC,gBAAgB,CAAC,SAAS,CAAC,UAAU,CAAC;YAAE,OAAO,SAAS,CAAC;QACjE,OAAO,oBAAE,CAAC,OAAO,CAAC,eAAe,CAC7B,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,SAAS,CAAC,UAAU,CAAC,CACjD,CAAC;IACN,CAAC;IATe,0BAAS,YASxB,CAAA;IAED,SAAS,SAAS,CACd,OAAgC,EAChC,IAAa,EACb,UAA6B;QAE7B,MAAM;QACN,cAAc;QACd,MAAM;QACN,kBAAkB;QAClB,IAAM,SAAS,GACX,OAAO,CAAC,OAAO,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;QACrD,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC,WAAW;YAAE,OAAO,UAAU,CAAC;QAE5D,0BAA0B;QAC1B,IAAM,IAAI,GAAY,CAAC;YACnB,iBAAiB;YACjB,IAAM,QAAQ,GAAW,cAAI,CAAC,OAAO,CACjC,SAAS,CAAC,WAAW,CAAC,aAAa,EAAE,CAAC,QAAQ,CACjD,CAAC;YACF,IACI,SAAS,CAAC,KAAK,CAAC,UAAC,GAAG,IAA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I,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,EAhIgB,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAgIhC"}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import ts from "typescript";
|
|
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 BodyTransformer {
|
|
11
|
-
export function transform(
|
|
12
|
-
project: INestiaTransformProject,
|
|
13
|
-
type: ts.Type,
|
|
14
|
-
decorator: ts.Decorator,
|
|
15
|
-
): ts.Decorator {
|
|
16
|
-
if (!ts.isCallExpression(decorator.expression)) return decorator;
|
|
17
|
-
return ts.factory.createDecorator(
|
|
18
|
-
validate(project, type, decorator.expression),
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function validate(
|
|
23
|
-
project: INestiaTransformProject,
|
|
24
|
-
type: ts.Type,
|
|
25
|
-
expression: ts.CallExpression,
|
|
26
|
-
): ts.LeftHandSideExpression {
|
|
27
|
-
// CHECK SIGNATURE
|
|
28
|
-
const signature: ts.Signature | undefined =
|
|
29
|
-
project.checker.getResolvedSignature(expression);
|
|
30
|
-
if (!signature || !signature.declaration) return expression;
|
|
31
|
-
|
|
32
|
-
// CHECK TO BE TRANSFORMED
|
|
33
|
-
const validate: boolean = (() => {
|
|
34
|
-
// CHECK FILENAME
|
|
35
|
-
const location: string = path.resolve(
|
|
36
|
-
signature.declaration.getSourceFile().fileName,
|
|
37
|
-
);
|
|
38
|
-
if (
|
|
39
|
-
LIB_PATHS.every((str) => location.indexOf(str) === -1) &&
|
|
40
|
-
SRC_PATHS.every((str) => location !== str)
|
|
41
|
-
)
|
|
42
|
-
return false;
|
|
43
|
-
|
|
44
|
-
// CHECK DUPLICATED TRANSFORMATION
|
|
45
|
-
return expression.arguments.length === 0;
|
|
46
|
-
})();
|
|
47
|
-
if (validate === false) return expression;
|
|
48
|
-
|
|
49
|
-
// CHECK TYPE NODE
|
|
50
|
-
const typeNode: ts.TypeNode | undefined =
|
|
51
|
-
project.checker.typeToTypeNode(type, undefined, undefined);
|
|
52
|
-
if (typeNode === undefined) return expression;
|
|
53
|
-
|
|
54
|
-
//----
|
|
55
|
-
// TRANSFORMATION
|
|
56
|
-
//----
|
|
57
|
-
// GENERATE VALIDATION PLAN
|
|
58
|
-
const parameter = (
|
|
59
|
-
key: string,
|
|
60
|
-
programmer: (
|
|
61
|
-
project: IProject,
|
|
62
|
-
modulo: ts.LeftHandSideExpression,
|
|
63
|
-
) => (type: ts.Type) => ts.ArrowFunction,
|
|
64
|
-
) =>
|
|
65
|
-
ts.factory.createObjectLiteralExpression([
|
|
66
|
-
ts.factory.createPropertyAssignment(
|
|
67
|
-
ts.factory.createIdentifier("type"),
|
|
68
|
-
ts.factory.createStringLiteral(key),
|
|
69
|
-
),
|
|
70
|
-
ts.factory.createPropertyAssignment(
|
|
71
|
-
ts.factory.createIdentifier(key),
|
|
72
|
-
programmer(
|
|
73
|
-
{
|
|
74
|
-
...project,
|
|
75
|
-
options: {
|
|
76
|
-
numeric: false,
|
|
77
|
-
finite: false,
|
|
78
|
-
functional: false,
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
expression.expression,
|
|
82
|
-
)(type),
|
|
83
|
-
),
|
|
84
|
-
]);
|
|
85
|
-
const validator: ts.ObjectLiteralExpression = (() => {
|
|
86
|
-
if (project.options.validate === "is")
|
|
87
|
-
return parameter("is", IsProgrammer.generate);
|
|
88
|
-
else if (project.options.validate === "validate")
|
|
89
|
-
return parameter("validate", ValidateProgrammer.generate);
|
|
90
|
-
return parameter("assert", AssertProgrammer.generate);
|
|
91
|
-
})();
|
|
92
|
-
|
|
93
|
-
// UPDATE DECORATOR FUNCTION CALL
|
|
94
|
-
return ts.factory.updateCallExpression(
|
|
95
|
-
expression,
|
|
96
|
-
expression.expression,
|
|
97
|
-
expression.typeArguments,
|
|
98
|
-
[validator],
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const CLASSES = ["EncryptedBody", "TypedBody"];
|
|
103
|
-
const LIB_PATHS = CLASSES.map((cla) =>
|
|
104
|
-
path.join(
|
|
105
|
-
"node_modules",
|
|
106
|
-
"@nestia",
|
|
107
|
-
"core",
|
|
108
|
-
"lib",
|
|
109
|
-
"decorators",
|
|
110
|
-
`${cla}.d.ts`,
|
|
111
|
-
),
|
|
112
|
-
);
|
|
113
|
-
const SRC_PATHS = CLASSES.map((cla) =>
|
|
114
|
-
path.resolve(path.join(__dirname, "..", "decorators", `${cla}.ts`)),
|
|
115
|
-
);
|
|
116
|
-
}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import ts from "typescript";
|
|
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 RouteTransformer {
|
|
12
|
-
export function transform(
|
|
13
|
-
project: INestiaTransformProject,
|
|
14
|
-
type: ts.Type,
|
|
15
|
-
decorator: ts.Decorator,
|
|
16
|
-
): ts.Decorator {
|
|
17
|
-
if (!ts.isCallExpression(decorator.expression)) return decorator;
|
|
18
|
-
return ts.factory.createDecorator(
|
|
19
|
-
stringify(project, type, decorator.expression),
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function stringify(
|
|
24
|
-
project: INestiaTransformProject,
|
|
25
|
-
type: ts.Type,
|
|
26
|
-
expression: ts.CallExpression,
|
|
27
|
-
): ts.LeftHandSideExpression {
|
|
28
|
-
//----
|
|
29
|
-
// VALIDATIONS
|
|
30
|
-
//----
|
|
31
|
-
// CHECK SIGNATURE
|
|
32
|
-
const signature: ts.Signature | undefined =
|
|
33
|
-
project.checker.getResolvedSignature(expression);
|
|
34
|
-
if (!signature || !signature.declaration) return expression;
|
|
35
|
-
|
|
36
|
-
// CHECK TO BE TRANSFORMED
|
|
37
|
-
const done: boolean = (() => {
|
|
38
|
-
// CHECK FILENAME
|
|
39
|
-
const location: string = path.resolve(
|
|
40
|
-
signature.declaration.getSourceFile().fileName,
|
|
41
|
-
);
|
|
42
|
-
if (
|
|
43
|
-
LIB_PATHS.every((str) => location.indexOf(str) === -1) &&
|
|
44
|
-
SRC_PATHS.every((str) => location !== str)
|
|
45
|
-
)
|
|
46
|
-
return false;
|
|
47
|
-
|
|
48
|
-
// CHECK DUPLICATE BOOSTER
|
|
49
|
-
if (expression.arguments.length >= 2) return false;
|
|
50
|
-
else if (expression.arguments.length === 1) {
|
|
51
|
-
const last: ts.Expression =
|
|
52
|
-
expression.arguments[expression.arguments.length - 1];
|
|
53
|
-
const type: ts.Type = project.checker.getTypeAtLocation(last);
|
|
54
|
-
if (isObject(project.checker, type)) return false;
|
|
55
|
-
}
|
|
56
|
-
return true;
|
|
57
|
-
})();
|
|
58
|
-
if (done === false) return expression;
|
|
59
|
-
|
|
60
|
-
// CHECK TYPE NODE
|
|
61
|
-
const typeNode: ts.TypeNode | undefined =
|
|
62
|
-
project.checker.typeToTypeNode(type, undefined, undefined);
|
|
63
|
-
if (typeNode === undefined) return expression;
|
|
64
|
-
|
|
65
|
-
//----
|
|
66
|
-
// TRANSFORMATION
|
|
67
|
-
//----
|
|
68
|
-
// GENERATE STRINGIFY PLAN
|
|
69
|
-
const parameter = (
|
|
70
|
-
key: string,
|
|
71
|
-
programmer: (
|
|
72
|
-
project: IProject,
|
|
73
|
-
modulo: ts.LeftHandSideExpression,
|
|
74
|
-
) => (type: ts.Type) => ts.ArrowFunction,
|
|
75
|
-
) =>
|
|
76
|
-
ts.factory.createObjectLiteralExpression([
|
|
77
|
-
ts.factory.createPropertyAssignment(
|
|
78
|
-
ts.factory.createIdentifier("type"),
|
|
79
|
-
ts.factory.createStringLiteral(key),
|
|
80
|
-
),
|
|
81
|
-
ts.factory.createPropertyAssignment(
|
|
82
|
-
ts.factory.createIdentifier(key),
|
|
83
|
-
programmer(
|
|
84
|
-
{
|
|
85
|
-
...project,
|
|
86
|
-
options: {}, // use default option
|
|
87
|
-
},
|
|
88
|
-
expression.expression,
|
|
89
|
-
)(type),
|
|
90
|
-
),
|
|
91
|
-
]);
|
|
92
|
-
const stringify: ts.Expression = (() => {
|
|
93
|
-
if (project.options.stringify === "stringify")
|
|
94
|
-
return parameter("stringify", StringifyProgrammer.generate);
|
|
95
|
-
else if (project.options.stringify === "assert")
|
|
96
|
-
return parameter("assert", AssertStringifyProgrammer.generate);
|
|
97
|
-
else if (project.options.stringify === "validate")
|
|
98
|
-
return parameter(
|
|
99
|
-
"validate",
|
|
100
|
-
ValidateStringifyProgrammer.generate,
|
|
101
|
-
);
|
|
102
|
-
else if (project.options.stringify === null)
|
|
103
|
-
return ts.factory.createNull();
|
|
104
|
-
return parameter("is", IsStringifyProgrammer.generate);
|
|
105
|
-
})();
|
|
106
|
-
|
|
107
|
-
// UPDATE DECORATOR FUNCTION CALL
|
|
108
|
-
return ts.factory.updateCallExpression(
|
|
109
|
-
expression,
|
|
110
|
-
expression.expression,
|
|
111
|
-
expression.typeArguments,
|
|
112
|
-
[...expression.arguments, stringify],
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function isObject(checker: ts.TypeChecker, type: ts.Type): boolean {
|
|
117
|
-
return (
|
|
118
|
-
(type.getFlags() & ts.TypeFlags.Object) !== 0 &&
|
|
119
|
-
!(checker as any).isTupleType(type) &&
|
|
120
|
-
!(checker as any).isArrayType(type) &&
|
|
121
|
-
!(checker as any).isArrayLikeType(type)
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const CLASSES = ["EncryptedRoute", "TypedRoute"];
|
|
126
|
-
const LIB_PATHS = CLASSES.map((cla) =>
|
|
127
|
-
path.join(
|
|
128
|
-
"node_modules",
|
|
129
|
-
"@nestia",
|
|
130
|
-
"core",
|
|
131
|
-
"lib",
|
|
132
|
-
"decorators",
|
|
133
|
-
`${cla}.d.ts`,
|
|
134
|
-
),
|
|
135
|
-
);
|
|
136
|
-
const SRC_PATHS = CLASSES.map((cla) =>
|
|
137
|
-
path.resolve(path.join(__dirname, "..", "decorators", `${cla}.ts`)),
|
|
138
|
-
);
|
|
139
|
-
}
|