@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.
Files changed (32) hide show
  1. package/lib/decorators/TypedParam.js +5 -5
  2. package/lib/decorators/TypedParam.js.map +1 -1
  3. package/lib/transform.d.ts +2 -1
  4. package/lib/transform.js +7 -8
  5. package/lib/transform.js.map +1 -1
  6. package/lib/transformers/FileTransformer.d.ts +1 -1
  7. package/lib/transformers/FileTransformer.js +28 -20
  8. package/lib/transformers/FileTransformer.js.map +1 -1
  9. package/lib/transformers/MethodDecoratorTransformer.d.ts +1 -1
  10. package/lib/transformers/MethodDecoratorTransformer.js +48 -43
  11. package/lib/transformers/MethodDecoratorTransformer.js.map +1 -1
  12. package/lib/transformers/MethodTransformer.d.ts +1 -1
  13. package/lib/transformers/MethodTransformer.js +51 -43
  14. package/lib/transformers/MethodTransformer.js.map +1 -1
  15. package/lib/transformers/NodeTransformer.d.ts +1 -1
  16. package/lib/transformers/NodeTransformer.js +9 -8
  17. package/lib/transformers/NodeTransformer.js.map +1 -1
  18. package/lib/transformers/ParameterDecoratorTransformer.d.ts +1 -1
  19. package/lib/transformers/ParameterDecoratorTransformer.js +41 -38
  20. package/lib/transformers/ParameterDecoratorTransformer.js.map +1 -1
  21. package/lib/transformers/ParameterTransformer.d.ts +1 -1
  22. package/lib/transformers/ParameterTransformer.js +23 -22
  23. package/lib/transformers/ParameterTransformer.js.map +1 -1
  24. package/package.json +2 -4
  25. package/src/decorators/TypedParam.ts +5 -8
  26. package/src/transform.ts +5 -8
  27. package/src/transformers/FileTransformer.ts +35 -39
  28. package/src/transformers/MethodDecoratorTransformer.ts +57 -58
  29. package/src/transformers/MethodTransformer.ts +72 -68
  30. package/src/transformers/NodeTransformer.ts +8 -10
  31. package/src/transformers/ParameterDecoratorTransformer.ts +50 -49
  32. 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 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;
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;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"}
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.1.2-dev.20230503",
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.1"
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
- const deco = createParamDecorator(function TypedParam(
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
- })(name);
73
- (deco as any).nullable = !!nullable;
74
- (deco as any).type = type;
75
- return deco;
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 default function transform(
6
+ export const transform = (
8
7
  program: ts.Program,
9
8
  options?: INestiaTransformOptions,
10
- ): ts.TransformerFactory<ts.SourceFile> {
11
- const project: INestiaTransformProject = {
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
- return (context) => (file) =>
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 function transform(
8
- project: INestiaTransformProject,
9
- context: ts.TransformationContext,
10
- file: ts.SourceFile,
11
- ): ts.SourceFile {
12
- // ITERATE NODES
13
- return ts.visitEachChild(
14
- file,
15
- (node) => iterate_node(project, context, node),
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
- function iterate_node(
21
- project: INestiaTransformProject,
22
- context: ts.TransformationContext,
23
- node: ts.Node,
24
- ): ts.Node {
25
- return ts.visitEachChild(
26
- try_transform_node(project, node),
27
- (child) => iterate_node(project, context, child),
28
- context,
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
- function try_transform_node(
33
- project: INestiaTransformProject,
34
- node: ts.Node,
35
- ): ts.Node {
36
- try {
37
- return NodeTransformer.transform(project, node);
38
- } catch (exp) {
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
- const file: ts.SourceFile = node.getSourceFile();
42
- const { line, character } = file.getLineAndCharacterOfPosition(
43
- node.pos,
44
- );
45
- exp.message += ` - ${file.fileName}.${line + 1}:${character + 1}`;
46
- throw exp;
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 function transform(
9
- project: INestiaTransformProject,
10
- type: ts.Type,
11
- decorator: ts.Decorator,
12
- ): ts.Decorator {
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
- // CHECK SIGNATURE
16
- const signature: ts.Signature | undefined =
17
- project.checker.getResolvedSignature(decorator.expression);
18
- if (!signature || !signature.declaration) return decorator;
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
- // 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;
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
- // 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;
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
- // CHECK TYPE NODE
47
- const typeNode: ts.TypeNode | undefined =
48
- project.checker.typeToTypeNode(type, undefined, undefined);
49
- if (typeNode === undefined) return decorator;
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
- // 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
- }
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
- function isObject(checker: ts.TypeChecker, type: ts.Type): boolean {
68
- return (
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 function transform(
8
- project: INestiaTransformProject,
9
- method: ts.MethodDeclaration,
10
- ): ts.MethodDeclaration {
11
- const decorators: readonly ts.Decorator[] | undefined = ts.getDecorators
12
- ? ts.getDecorators(method)
13
- : (method as any).decorators;
14
- if (!decorators?.length) return method;
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
- const signature: ts.Signature | undefined =
17
- project.checker.getSignatureFromDeclaration(method);
18
- const original: ts.Type | undefined =
19
- signature && project.checker.getReturnTypeOfSignature(signature);
20
- const escaped: ts.Type | undefined =
21
- original && get_escaped_type(project.checker, original);
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
- if (escaped === undefined) return method;
24
+ if (escaped === undefined) return method;
24
25
 
25
- if (ts.getDecorators !== undefined)
26
- return ts.factory.updateMethodDeclaration(
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
- (method.modifiers || []).map((mod) =>
29
- ts.isDecorator(mod)
30
- ? MethodDecoratorTransformer.transform(
31
- project,
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
- // eslint-disable-next-line
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
- function get_escaped_type(checker: ts.TypeChecker, type: ts.Type): ts.Type {
64
- const symbol: ts.Symbol | undefined = type.getSymbol() || type.aliasSymbol;
65
- return symbol && get_name(symbol) === "Promise"
66
- ? escape_promise(checker, type)
67
- : type;
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
- function escape_promise(checker: ts.TypeChecker, type: ts.Type): ts.Type {
71
- const generic: readonly ts.Type[] = checker.getTypeArguments(
72
- type as ts.TypeReference,
73
- );
74
- if (generic.length !== 1)
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
- return generic[0];
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
- function get_name(symbol: ts.Symbol): string {
82
- return explore_name(
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
- function explore_name(name: string, decl: ts.Node): string {
89
- return ts.isModuleBlock(decl)
90
- ? explore_name(
91
- `${decl.parent.name.getFullText().trim()}.${name}`,
92
- decl.parent.parent,
93
- )
94
- : name;
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 function transform(
9
- project: INestiaTransformProject,
10
- node: ts.Node,
11
- ): ts.Node {
12
- if (ts.isMethodDeclaration(node))
13
- return MethodTransformer.transform(project, node);
14
- else if (ts.isParameter(node))
15
- return ParameterTransformer.transform(project, node);
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
  }