@nestia/core 1.1.2-dev.20230503 → 1.2.0-dev.20230503
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/decorators/TypedParam.js +5 -5
- package/lib/decorators/TypedParam.js.map +1 -1
- package/lib/transform.d.ts +2 -1
- package/lib/transform.js +7 -8
- package/lib/transform.js.map +1 -1
- package/lib/transformers/FileTransformer.d.ts +1 -1
- package/lib/transformers/FileTransformer.js +28 -20
- package/lib/transformers/FileTransformer.js.map +1 -1
- package/lib/transformers/MethodDecoratorTransformer.d.ts +1 -1
- package/lib/transformers/MethodDecoratorTransformer.js +48 -43
- package/lib/transformers/MethodDecoratorTransformer.js.map +1 -1
- package/lib/transformers/MethodTransformer.d.ts +1 -1
- package/lib/transformers/MethodTransformer.js +51 -43
- package/lib/transformers/MethodTransformer.js.map +1 -1
- package/lib/transformers/NodeTransformer.d.ts +1 -1
- package/lib/transformers/NodeTransformer.js +9 -8
- package/lib/transformers/NodeTransformer.js.map +1 -1
- package/lib/transformers/ParameterDecoratorTransformer.d.ts +1 -1
- package/lib/transformers/ParameterDecoratorTransformer.js +41 -38
- package/lib/transformers/ParameterDecoratorTransformer.js.map +1 -1
- package/lib/transformers/ParameterTransformer.d.ts +1 -1
- package/lib/transformers/ParameterTransformer.js +23 -22
- package/lib/transformers/ParameterTransformer.js.map +1 -1
- package/package.json +2 -4
- package/src/decorators/TypedParam.ts +5 -8
- package/src/transform.ts +5 -8
- package/src/transformers/FileTransformer.ts +35 -39
- package/src/transformers/MethodDecoratorTransformer.ts +57 -58
- package/src/transformers/MethodTransformer.ts +72 -68
- package/src/transformers/NodeTransformer.ts +8 -10
- package/src/transformers/ParameterDecoratorTransformer.ts +50 -49
- package/src/transformers/ParameterTransformer.ts +36 -36
|
@@ -8,27 +8,28 @@ var typescript_1 = __importDefault(require("typescript"));
|
|
|
8
8
|
var ParameterDecoratorTransformer_1 = require("./ParameterDecoratorTransformer");
|
|
9
9
|
var ParameterTransformer;
|
|
10
10
|
(function (ParameterTransformer) {
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return typescript_1.default.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
11
|
+
ParameterTransformer.transform = function (project) {
|
|
12
|
+
return function (param) {
|
|
13
|
+
// CHECK DECORATOR
|
|
14
|
+
var decorators = typescript_1.default.getDecorators
|
|
15
|
+
? typescript_1.default.getDecorators(param)
|
|
16
|
+
: param.decorators;
|
|
17
|
+
if (!(decorators === null || decorators === void 0 ? void 0 : decorators.length))
|
|
18
|
+
return param;
|
|
19
|
+
// GET TYPE INFO
|
|
20
|
+
var type = project.checker.getTypeAtLocation(param);
|
|
21
|
+
// WHEN LATEST TS VERSION
|
|
22
|
+
if (typescript_1.default.getDecorators !== undefined)
|
|
23
|
+
return typescript_1.default.factory.updateParameterDeclaration(param, (param.modifiers || []).map(function (mod) {
|
|
24
|
+
return typescript_1.default.isDecorator(mod)
|
|
25
|
+
? ParameterDecoratorTransformer_1.ParameterDecoratorTransformer.transform(project)(type)(mod)
|
|
26
|
+
: mod;
|
|
27
|
+
}), param.dotDotDotToken, param.name, param.questionToken, param.type, param.initializer);
|
|
28
|
+
// eslint-disable-next-line
|
|
29
|
+
return typescript_1.default.factory.updateParameterDeclaration(param, decorators.map(function (deco) {
|
|
30
|
+
return ParameterDecoratorTransformer_1.ParameterDecoratorTransformer.transform(project)(type)(deco);
|
|
31
|
+
}), param.modifiers, param.dotDotDotToken, param.name, param.questionToken, param.type, param.initializer);
|
|
32
|
+
};
|
|
33
|
+
};
|
|
33
34
|
})(ParameterTransformer = exports.ParameterTransformer || (exports.ParameterTransformer = {}));
|
|
34
35
|
//# 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;
|
|
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;IACpB,8BAAS,GAClB,UAAC,OAAgC;QACjC,OAAA,UAAC,KAA8B;YAC3B,kBAAkB;YAClB,IAAM,UAAU,GACZ,oBAAE,CAAC,aAAa;gBACZ,CAAC,CAAC,oBAAE,CAAC,aAAa,CAAC,KAAK,CAAC;gBACzB,CAAC,CAAE,KAAa,CAAC,UAAU,CAAC;YACpC,IAAI,CAAC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,MAAM,CAAA;gBAAE,OAAO,KAAK,CAAC;YAEtC,gBAAgB;YAChB,IAAM,IAAI,GAAY,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;YAE/D,yBAAyB;YACzB,IAAI,oBAAE,CAAC,aAAa,KAAK,SAAS;gBAC9B,OAAO,oBAAE,CAAC,OAAO,CAAC,0BAA0B,CACxC,KAAK,EACL,CAAC,KAAK,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,UAAC,GAAG;oBAC5B,OAAA,oBAAE,CAAC,WAAW,CAAC,GAAG,CAAC;wBACf,CAAC,CAAC,6DAA6B,CAAC,SAAS,CAAC,OAAO,CAAC,CAC5C,IAAI,CACP,CAAC,GAAG,CAAC;wBACR,CAAC,CAAC,GAAG;gBAJT,CAIS,CACZ,EACD,KAAK,CAAC,cAAc,EACpB,KAAK,CAAC,IAAI,EACV,KAAK,CAAC,aAAa,EACnB,KAAK,CAAC,IAAI,EACV,KAAK,CAAC,WAAW,CACpB,CAAC;YACN,2BAA2B;YAC3B,OAAQ,oBAAE,CAAC,OAAO,CAAC,0BAAkC,CACjD,KAAK,EACL,UAAU,CAAC,GAAG,CAAC,UAAC,IAAI;gBAChB,OAAA,6DAA6B,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAClD,IAAI,CACP;YAFD,CAEC,CACJ,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;QACN,CAAC;IA3CD,CA2CC,CAAC;AACV,CAAC,EA/CgB,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QA+CpC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestia/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0-dev.20230503",
|
|
4
4
|
"description": "Super-fast validation decorators of NestJS",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
"eslint:fix": "eslint ./**/*.ts --fix",
|
|
12
12
|
"package:latest": "npm run build && npm publish --access public",
|
|
13
13
|
"package:next": "npm run package:latest -- --tag next",
|
|
14
|
-
"prepare": "ts-patch install",
|
|
15
14
|
"prettier": "prettier ./**/*.ts --write"
|
|
16
15
|
},
|
|
17
16
|
"repository": {
|
|
@@ -43,7 +42,7 @@
|
|
|
43
42
|
"raw-body": ">= 2.0.0",
|
|
44
43
|
"reflect-metadata": ">= 0.1.12",
|
|
45
44
|
"rxjs": ">= 6.0.0",
|
|
46
|
-
"typia": "^3.8.
|
|
45
|
+
"typia": "^3.8.4"
|
|
47
46
|
},
|
|
48
47
|
"peerDependencies": {
|
|
49
48
|
"typescript": ">= 4.5.2"
|
|
@@ -63,7 +62,6 @@
|
|
|
63
62
|
"prettier": "^2.8.7",
|
|
64
63
|
"rimraf": "^3.0.2",
|
|
65
64
|
"ts-node": "^10.9.1",
|
|
66
|
-
"ts-patch": "^2.1.0",
|
|
67
65
|
"tstl": "^2.5.13",
|
|
68
66
|
"typescript": "^4.9.5",
|
|
69
67
|
"typescript-transform-paths": "^3.4.6"
|
|
@@ -40,10 +40,7 @@ export function TypedParam(
|
|
|
40
40
|
type?: "boolean" | "number" | "string" | "uuid",
|
|
41
41
|
nullable?: false | true,
|
|
42
42
|
): ParameterDecorator {
|
|
43
|
-
|
|
44
|
-
{}: any,
|
|
45
|
-
ctx: ExecutionContext,
|
|
46
|
-
) {
|
|
43
|
+
function TypedParam({}: any, ctx: ExecutionContext) {
|
|
47
44
|
const request: express.Request = ctx.switchToHttp().getRequest();
|
|
48
45
|
const str: string = request.params[name];
|
|
49
46
|
|
|
@@ -69,10 +66,10 @@ export function TypedParam(
|
|
|
69
66
|
);
|
|
70
67
|
return str;
|
|
71
68
|
} else return str;
|
|
72
|
-
}
|
|
73
|
-
(
|
|
74
|
-
(
|
|
75
|
-
return
|
|
69
|
+
}
|
|
70
|
+
(TypedParam as any).nullable = !!nullable;
|
|
71
|
+
(TypedParam as any).type = type;
|
|
72
|
+
return createParamDecorator(TypedParam)(name);
|
|
76
73
|
}
|
|
77
74
|
|
|
78
75
|
const UUID_PATTERN =
|
package/src/transform.ts
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
|
|
3
3
|
import { INestiaTransformOptions } from "./options/INestiaTransformOptions";
|
|
4
|
-
import { INestiaTransformProject } from "./options/INestiaTransformProject";
|
|
5
4
|
import { FileTransformer } from "./transformers/FileTransformer";
|
|
6
5
|
|
|
7
|
-
export
|
|
6
|
+
export const transform = (
|
|
8
7
|
program: ts.Program,
|
|
9
8
|
options?: INestiaTransformOptions,
|
|
10
|
-
): ts.TransformerFactory<ts.SourceFile>
|
|
11
|
-
|
|
9
|
+
): ts.TransformerFactory<ts.SourceFile> =>
|
|
10
|
+
FileTransformer.transform({
|
|
12
11
|
program,
|
|
13
12
|
compilerOptions: program.getCompilerOptions(),
|
|
14
13
|
checker: program.getTypeChecker(),
|
|
15
14
|
printer: ts.createPrinter(),
|
|
16
15
|
options: options || {},
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
FileTransformer.transform(project, context, file);
|
|
20
|
-
}
|
|
16
|
+
});
|
|
17
|
+
export default transform;
|
|
@@ -4,46 +4,42 @@ import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
|
4
4
|
import { NodeTransformer } from "./NodeTransformer";
|
|
5
5
|
|
|
6
6
|
export namespace FileTransformer {
|
|
7
|
-
export
|
|
8
|
-
project: INestiaTransformProject
|
|
9
|
-
context: ts.TransformationContext
|
|
10
|
-
file: ts.SourceFile
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
context,
|
|
17
|
-
);
|
|
18
|
-
}
|
|
7
|
+
export const transform =
|
|
8
|
+
(project: INestiaTransformProject) =>
|
|
9
|
+
(context: ts.TransformationContext) =>
|
|
10
|
+
(file: ts.SourceFile): ts.SourceFile =>
|
|
11
|
+
ts.visitEachChild(
|
|
12
|
+
file,
|
|
13
|
+
(node) => iterate_node(project)(context)(node),
|
|
14
|
+
context,
|
|
15
|
+
);
|
|
19
16
|
|
|
20
|
-
|
|
21
|
-
project: INestiaTransformProject
|
|
22
|
-
context: ts.TransformationContext
|
|
23
|
-
node: ts.Node
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
);
|
|
30
|
-
}
|
|
17
|
+
const iterate_node =
|
|
18
|
+
(project: INestiaTransformProject) =>
|
|
19
|
+
(context: ts.TransformationContext) =>
|
|
20
|
+
(node: ts.Node): ts.Node =>
|
|
21
|
+
ts.visitEachChild(
|
|
22
|
+
try_transform_node(project)(node),
|
|
23
|
+
(child) => iterate_node(project)(context)(child),
|
|
24
|
+
context,
|
|
25
|
+
);
|
|
31
26
|
|
|
32
|
-
|
|
33
|
-
project: INestiaTransformProject
|
|
34
|
-
node: ts.Node
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (!(exp instanceof Error)) throw exp;
|
|
27
|
+
const try_transform_node =
|
|
28
|
+
(project: INestiaTransformProject) =>
|
|
29
|
+
(node: ts.Node): ts.Node => {
|
|
30
|
+
try {
|
|
31
|
+
return NodeTransformer.transform(project)(node);
|
|
32
|
+
} catch (exp) {
|
|
33
|
+
if (!(exp instanceof Error)) throw exp;
|
|
40
34
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
35
|
+
const file: ts.SourceFile = node.getSourceFile();
|
|
36
|
+
const { line, character } = file.getLineAndCharacterOfPosition(
|
|
37
|
+
node.pos,
|
|
38
|
+
);
|
|
39
|
+
exp.message += ` - ${file.fileName}.${line + 1}:${
|
|
40
|
+
character + 1
|
|
41
|
+
}`;
|
|
42
|
+
throw exp;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
49
45
|
}
|
|
@@ -5,73 +5,72 @@ import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
|
5
5
|
import { TypedRouteProgrammer } from "../programmers/TypedRouteProgrammer";
|
|
6
6
|
|
|
7
7
|
export namespace MethodDecoratorTransformer {
|
|
8
|
-
export
|
|
9
|
-
project: INestiaTransformProject
|
|
10
|
-
type: ts.Type
|
|
11
|
-
decorator: ts.Decorator
|
|
12
|
-
|
|
13
|
-
if (!ts.isCallExpression(decorator.expression)) return decorator;
|
|
8
|
+
export const transform =
|
|
9
|
+
(project: INestiaTransformProject) =>
|
|
10
|
+
(type: ts.Type) =>
|
|
11
|
+
(decorator: ts.Decorator): ts.Decorator => {
|
|
12
|
+
if (!ts.isCallExpression(decorator.expression)) return decorator;
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
// CHECK SIGNATURE
|
|
15
|
+
const signature: ts.Signature | undefined =
|
|
16
|
+
project.checker.getResolvedSignature(decorator.expression);
|
|
17
|
+
if (!signature || !signature.declaration) return decorator;
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
19
|
+
// CHECK TO BE TRANSFORMED
|
|
20
|
+
const done: boolean = (() => {
|
|
21
|
+
// CHECK FILENAME
|
|
22
|
+
const location: string = path.resolve(
|
|
23
|
+
signature.declaration.getSourceFile().fileName,
|
|
24
|
+
);
|
|
25
|
+
if (
|
|
26
|
+
LIB_PATHS.every((str) => location.indexOf(str) === -1) &&
|
|
27
|
+
SRC_PATHS.every((str) => location !== str)
|
|
28
|
+
)
|
|
29
|
+
return false;
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
31
|
+
// CHECK DUPLICATE BOOSTER
|
|
32
|
+
if (decorator.expression.arguments.length >= 2) return false;
|
|
33
|
+
else if (decorator.expression.arguments.length === 1) {
|
|
34
|
+
const last: ts.Expression =
|
|
35
|
+
decorator.expression.arguments[
|
|
36
|
+
decorator.expression.arguments.length - 1
|
|
37
|
+
];
|
|
38
|
+
const type: ts.Type =
|
|
39
|
+
project.checker.getTypeAtLocation(last);
|
|
40
|
+
if (isObject(project.checker)(type)) return false;
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
})();
|
|
44
|
+
if (done === false) return decorator;
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
// CHECK TYPE NODE
|
|
47
|
+
const typeNode: ts.TypeNode | undefined =
|
|
48
|
+
project.checker.typeToTypeNode(type, undefined, undefined);
|
|
49
|
+
if (typeNode === undefined) return decorator;
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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(project)(
|
|
60
|
+
decorator.expression.expression,
|
|
61
|
+
)(type),
|
|
62
|
+
],
|
|
63
|
+
),
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
const isObject =
|
|
68
|
+
(checker: ts.TypeChecker) =>
|
|
69
|
+
(type: ts.Type): boolean =>
|
|
69
70
|
(type.getFlags() & ts.TypeFlags.Object) !== 0 &&
|
|
70
71
|
!(checker as any).isTupleType(type) &&
|
|
71
72
|
!(checker as any).isArrayType(type) &&
|
|
72
|
-
!(checker as any).isArrayLikeType(type)
|
|
73
|
-
);
|
|
74
|
-
}
|
|
73
|
+
!(checker as any).isArrayLikeType(type);
|
|
75
74
|
|
|
76
75
|
const CLASSES = ["EncryptedRoute", "TypedRoute"];
|
|
77
76
|
const LIB_PATHS = CLASSES.map((cla) =>
|
|
@@ -4,36 +4,52 @@ import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
|
4
4
|
import { MethodDecoratorTransformer } from "./MethodDecoratorTransformer";
|
|
5
5
|
|
|
6
6
|
export namespace MethodTransformer {
|
|
7
|
-
export
|
|
8
|
-
project: INestiaTransformProject
|
|
9
|
-
method: ts.MethodDeclaration
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
export const transform =
|
|
8
|
+
(project: INestiaTransformProject) =>
|
|
9
|
+
(method: ts.MethodDeclaration): ts.MethodDeclaration => {
|
|
10
|
+
const decorators: readonly ts.Decorator[] | undefined =
|
|
11
|
+
ts.getDecorators
|
|
12
|
+
? ts.getDecorators(method)
|
|
13
|
+
: (method as any).decorators;
|
|
14
|
+
if (!decorators?.length) return method;
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
const signature: ts.Signature | undefined =
|
|
17
|
+
project.checker.getSignatureFromDeclaration(method);
|
|
18
|
+
const original: ts.Type | undefined =
|
|
19
|
+
signature &&
|
|
20
|
+
project.checker.getReturnTypeOfSignature(signature);
|
|
21
|
+
const escaped: ts.Type | undefined =
|
|
22
|
+
original && get_escaped_type(project.checker)(original);
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
if (escaped === undefined) return method;
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
if (ts.getDecorators !== undefined)
|
|
27
|
+
return ts.factory.updateMethodDeclaration(
|
|
28
|
+
method,
|
|
29
|
+
(method.modifiers || []).map((mod) =>
|
|
30
|
+
ts.isDecorator(mod)
|
|
31
|
+
? MethodDecoratorTransformer.transform(project)(
|
|
32
|
+
escaped,
|
|
33
|
+
)(mod)
|
|
34
|
+
: mod,
|
|
35
|
+
),
|
|
36
|
+
method.asteriskToken,
|
|
37
|
+
method.name,
|
|
38
|
+
method.questionToken,
|
|
39
|
+
method.typeParameters,
|
|
40
|
+
method.parameters,
|
|
41
|
+
method.type,
|
|
42
|
+
method.body,
|
|
43
|
+
);
|
|
44
|
+
// eslint-disable-next-line
|
|
45
|
+
return (ts.factory.updateMethodDeclaration as any)(
|
|
27
46
|
method,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
escaped,
|
|
33
|
-
mod,
|
|
34
|
-
)
|
|
35
|
-
: mod,
|
|
47
|
+
decorators.map((deco) =>
|
|
48
|
+
MethodDecoratorTransformer.transform(project)(escaped)(
|
|
49
|
+
deco,
|
|
50
|
+
),
|
|
36
51
|
),
|
|
52
|
+
(method as any).modifiers,
|
|
37
53
|
method.asteriskToken,
|
|
38
54
|
method.name,
|
|
39
55
|
method.questionToken,
|
|
@@ -42,54 +58,42 @@ export namespace MethodTransformer {
|
|
|
42
58
|
method.type,
|
|
43
59
|
method.body,
|
|
44
60
|
);
|
|
45
|
-
|
|
46
|
-
return (ts.factory.updateMethodDeclaration as any)(
|
|
47
|
-
method,
|
|
48
|
-
decorators.map((deco) =>
|
|
49
|
-
MethodDecoratorTransformer.transform(project, escaped, deco),
|
|
50
|
-
),
|
|
51
|
-
(method as any).modifiers,
|
|
52
|
-
method.asteriskToken,
|
|
53
|
-
method.name,
|
|
54
|
-
method.questionToken,
|
|
55
|
-
method.typeParameters,
|
|
56
|
-
method.parameters,
|
|
57
|
-
method.type,
|
|
58
|
-
method.body,
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
+
};
|
|
61
62
|
}
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
const get_escaped_type =
|
|
65
|
+
(checker: ts.TypeChecker) =>
|
|
66
|
+
(type: ts.Type): ts.Type => {
|
|
67
|
+
const symbol: ts.Symbol | undefined =
|
|
68
|
+
type.getSymbol() || type.aliasSymbol;
|
|
69
|
+
return symbol && get_name(symbol) === "Promise"
|
|
70
|
+
? escape_promise(checker)(type)
|
|
71
|
+
: type;
|
|
72
|
+
};
|
|
69
73
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
throw new Error(
|
|
76
|
-
"Error on ImportAnalyzer.analyze(): invalid promise type.",
|
|
74
|
+
const escape_promise =
|
|
75
|
+
(checker: ts.TypeChecker) =>
|
|
76
|
+
(type: ts.Type): ts.Type => {
|
|
77
|
+
const generic: readonly ts.Type[] = checker.getTypeArguments(
|
|
78
|
+
type as ts.TypeReference,
|
|
77
79
|
);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
+
if (generic.length !== 1)
|
|
81
|
+
throw new Error(
|
|
82
|
+
"Error on ImportAnalyzer.analyze(): invalid promise type.",
|
|
83
|
+
);
|
|
84
|
+
return generic[0];
|
|
85
|
+
};
|
|
80
86
|
|
|
81
|
-
|
|
82
|
-
|
|
87
|
+
const get_name = (symbol: ts.Symbol): string =>
|
|
88
|
+
explore_name(symbol.getDeclarations()![0].parent)(
|
|
83
89
|
symbol.escapedName.toString(),
|
|
84
|
-
symbol.getDeclarations()![0].parent,
|
|
85
90
|
);
|
|
86
|
-
}
|
|
87
91
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
92
|
+
const explore_name =
|
|
93
|
+
(decl: ts.Node) =>
|
|
94
|
+
(name: string): string =>
|
|
95
|
+
ts.isModuleBlock(decl)
|
|
96
|
+
? explore_name(decl.parent.parent)(
|
|
97
|
+
`${decl.parent.name.getFullText().trim()}.${name}`,
|
|
98
|
+
)
|
|
99
|
+
: name;
|
|
@@ -5,14 +5,12 @@ import { MethodTransformer } from "./MethodTransformer";
|
|
|
5
5
|
import { ParameterTransformer } from "./ParameterTransformer";
|
|
6
6
|
|
|
7
7
|
export namespace NodeTransformer {
|
|
8
|
-
export
|
|
9
|
-
project: INestiaTransformProject
|
|
10
|
-
node: ts.Node
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return node;
|
|
17
|
-
}
|
|
8
|
+
export const transform =
|
|
9
|
+
(project: INestiaTransformProject) =>
|
|
10
|
+
(node: ts.Node): ts.Node =>
|
|
11
|
+
ts.isMethodDeclaration(node)
|
|
12
|
+
? MethodTransformer.transform(project)(node)
|
|
13
|
+
: ts.isParameter(node)
|
|
14
|
+
? ParameterTransformer.transform(project)(node)
|
|
15
|
+
: node;
|
|
18
16
|
}
|