@nestia/core 3.0.0-dev.20231209 → 3.0.0

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 (132) hide show
  1. package/README.md +12 -9
  2. package/lib/decorators/DynamicModule.js +3 -3
  3. package/lib/decorators/DynamicModule.js.map +1 -1
  4. package/lib/decorators/EncryptedBody.js +14 -13
  5. package/lib/decorators/EncryptedBody.js.map +1 -1
  6. package/lib/decorators/EncryptedModule.d.ts +1 -1
  7. package/lib/decorators/EncryptedModule.js +45 -21
  8. package/lib/decorators/EncryptedModule.js.map +1 -1
  9. package/lib/decorators/EncryptedRoute.d.ts +5 -5
  10. package/lib/decorators/EncryptedRoute.js +12 -29
  11. package/lib/decorators/EncryptedRoute.js.map +1 -1
  12. package/lib/decorators/PlainBody.js +3 -0
  13. package/lib/decorators/PlainBody.js.map +1 -1
  14. package/lib/decorators/SwaggerCustomizer.d.ts +79 -0
  15. package/lib/decorators/SwaggerCustomizer.js +32 -0
  16. package/lib/decorators/SwaggerCustomizer.js.map +1 -0
  17. package/lib/decorators/TypedBody.js +3 -0
  18. package/lib/decorators/TypedBody.js.map +1 -1
  19. package/lib/decorators/TypedException.d.ts +0 -1
  20. package/lib/decorators/TypedException.js +0 -1
  21. package/lib/decorators/TypedException.js.map +1 -1
  22. package/lib/decorators/TypedFormData.d.ts +60 -0
  23. package/lib/decorators/TypedFormData.js +403 -0
  24. package/lib/decorators/TypedFormData.js.map +1 -0
  25. package/lib/decorators/TypedQuery.d.ts +11 -6
  26. package/lib/decorators/TypedQuery.js +6 -1
  27. package/lib/decorators/TypedQuery.js.map +1 -1
  28. package/lib/decorators/TypedRoute.d.ts +5 -5
  29. package/lib/decorators/internal/get_path_and_querify.js +3 -0
  30. package/lib/decorators/internal/get_path_and_querify.js.map +1 -1
  31. package/lib/decorators/internal/load_controller.js.map +1 -1
  32. package/lib/decorators/internal/validate_request_body.d.ts +1 -3
  33. package/lib/decorators/internal/validate_request_body.js +15 -0
  34. package/lib/decorators/internal/validate_request_body.js.map +1 -1
  35. package/lib/decorators/internal/validate_request_form_data.js +79 -0
  36. package/lib/decorators/internal/validate_request_form_data.js.map +1 -0
  37. package/lib/decorators/internal/validate_request_headers.d.ts +1 -3
  38. package/lib/decorators/internal/validate_request_headers.js +15 -0
  39. package/lib/decorators/internal/validate_request_headers.js.map +1 -1
  40. package/lib/decorators/internal/validate_request_query.d.ts +1 -3
  41. package/lib/decorators/internal/validate_request_query.js +15 -0
  42. package/lib/decorators/internal/validate_request_query.js.map +1 -1
  43. package/lib/module.d.ts +2 -0
  44. package/lib/module.js +2 -0
  45. package/lib/module.js.map +1 -1
  46. package/lib/options/IRequestFormDataProps.d.ts +23 -0
  47. package/lib/options/IRequestFormDataProps.js +3 -0
  48. package/lib/options/IRequestFormDataProps.js.map +1 -0
  49. package/lib/programmers/PlainBodyProgrammer.js +1 -1
  50. package/lib/programmers/PlainBodyProgrammer.js.map +1 -1
  51. package/lib/programmers/TypedExceptionProgrammer.js +5 -5
  52. package/lib/programmers/TypedExceptionProgrammer.js.map +1 -1
  53. package/lib/programmers/TypedFormDataBodyProgrammer.d.ts +6 -0
  54. package/lib/programmers/TypedFormDataBodyProgrammer.js +84 -0
  55. package/lib/programmers/TypedFormDataBodyProgrammer.js.map +1 -0
  56. package/lib/programmers/http/HttpQuerifyProgrammer.js +2 -2
  57. package/lib/programmers/http/HttpQuerifyProgrammer.js.map +1 -1
  58. package/lib/transformers/NodeTransformer.js.map +1 -1
  59. package/lib/transformers/ParameterDecoratorTransformer.js +7 -1
  60. package/lib/transformers/ParameterDecoratorTransformer.js.map +1 -1
  61. package/lib/transformers/TypedExceptionTransformer.js +1 -1
  62. package/lib/transformers/TypedExceptionTransformer.js.map +1 -1
  63. package/lib/transformers/TypedRouteTransformer.js +1 -1
  64. package/lib/transformers/TypedRouteTransformer.js.map +1 -1
  65. package/package.json +15 -16
  66. package/src/decorators/DynamicModule.ts +39 -39
  67. package/src/decorators/EncryptedBody.ts +105 -107
  68. package/src/decorators/EncryptedController.ts +38 -38
  69. package/src/decorators/EncryptedModule.ts +96 -79
  70. package/src/decorators/EncryptedRoute.ts +182 -206
  71. package/src/decorators/PlainBody.ts +75 -72
  72. package/src/decorators/SwaggerCustomizer.ts +115 -0
  73. package/src/decorators/TypedBody.ts +62 -59
  74. package/src/decorators/TypedException.ts +90 -89
  75. package/src/decorators/TypedFormData.ts +219 -0
  76. package/src/decorators/TypedHeaders.ts +69 -69
  77. package/src/decorators/TypedParam.ts +65 -65
  78. package/src/decorators/TypedQuery.ts +251 -246
  79. package/src/decorators/TypedRoute.ts +144 -144
  80. package/src/decorators/internal/EncryptedConstant.ts +4 -4
  81. package/src/decorators/internal/NoTransformConfigureError.ts +8 -8
  82. package/src/decorators/internal/get_path_and_querify.ts +106 -103
  83. package/src/decorators/internal/get_path_and_stringify.ts +91 -91
  84. package/src/decorators/internal/get_text_body.ts +20 -20
  85. package/src/decorators/internal/headers_to_object.ts +13 -13
  86. package/src/decorators/internal/load_controller.ts +51 -51
  87. package/src/decorators/internal/route_error.ts +45 -45
  88. package/src/decorators/internal/validate_request_body.ts +72 -57
  89. package/src/decorators/internal/validate_request_form_data.ts +75 -0
  90. package/src/decorators/internal/validate_request_headers.ts +83 -68
  91. package/src/decorators/internal/validate_request_query.ts +71 -56
  92. package/src/index.ts +5 -5
  93. package/src/module.ts +16 -14
  94. package/src/options/INestiaTransformOptions.ts +17 -17
  95. package/src/options/INestiaTransformProject.ts +7 -7
  96. package/src/options/IRequestBodyValidator.ts +20 -20
  97. package/src/options/IRequestFormDataProps.ts +27 -0
  98. package/src/options/IRequestHeadersValidator.ts +22 -22
  99. package/src/options/IRequestQueryValidator.ts +20 -20
  100. package/src/options/IResponseBodyQuerifier.ts +25 -25
  101. package/src/options/IResponseBodyStringifier.ts +25 -25
  102. package/src/programmers/PlainBodyProgrammer.ts +52 -52
  103. package/src/programmers/TypedBodyProgrammer.ts +108 -108
  104. package/src/programmers/TypedExceptionProgrammer.ts +71 -72
  105. package/src/programmers/TypedFormDataBodyProgrammer.ts +108 -0
  106. package/src/programmers/TypedHeadersProgrammer.ts +56 -56
  107. package/src/programmers/TypedParamProgrammer.ts +24 -24
  108. package/src/programmers/TypedQueryBodyProgrammer.ts +56 -56
  109. package/src/programmers/TypedQueryProgrammer.ts +56 -56
  110. package/src/programmers/TypedQueryRouteProgrammer.ts +51 -51
  111. package/src/programmers/TypedRouteProgrammer.ts +51 -51
  112. package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +58 -58
  113. package/src/programmers/http/HttpIsQuerifyProgrammer.ts +62 -62
  114. package/src/programmers/http/HttpQuerifyProgrammer.ts +96 -96
  115. package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +63 -63
  116. package/src/programmers/internal/CoreMetadataUtil.ts +21 -21
  117. package/src/transform.ts +35 -35
  118. package/src/transformers/FileTransformer.ts +66 -66
  119. package/src/transformers/MethodTransformer.ts +94 -94
  120. package/src/transformers/NodeTransformer.ts +16 -16
  121. package/src/transformers/ParameterDecoratorTransformer.ts +120 -121
  122. package/src/transformers/ParameterTransformer.ts +48 -48
  123. package/src/transformers/TypedExceptionTransformer.ts +48 -49
  124. package/src/transformers/TypedRouteTransformer.ts +88 -95
  125. package/src/typings/Creator.ts +3 -3
  126. package/src/utils/ExceptionManager.ts +112 -112
  127. package/src/utils/Singleton.ts +20 -20
  128. package/src/utils/SourceFinder.ts +57 -57
  129. package/lib/decorators/internal/get_binary_body.js +0 -66
  130. package/lib/decorators/internal/get_binary_body.js.map +0 -1
  131. package/src/decorators/internal/get_binary_body.ts +0 -18
  132. /package/lib/decorators/internal/{get_binary_body.d.ts → validate_request_form_data.d.ts} +0 -0
@@ -1,121 +1,120 @@
1
- import path from "path";
2
- import ts from "typescript";
3
-
4
- import { INestiaTransformProject } from "../options/INestiaTransformProject";
5
- import { PlainBodyProgrammer } from "../programmers/PlainBodyProgrammer";
6
- import { TypedBodyProgrammer } from "../programmers/TypedBodyProgrammer";
7
- import { TypedHeadersProgrammer } from "../programmers/TypedHeadersProgrammer";
8
- import { TypedParamProgrammer } from "../programmers/TypedParamProgrammer";
9
- import { TypedQueryBodyProgrammer } from "../programmers/TypedQueryBodyProgrammer";
10
- import { TypedQueryProgrammer } from "../programmers/TypedQueryProgrammer";
11
-
12
- export namespace ParameterDecoratorTransformer {
13
- export const transform =
14
- (project: INestiaTransformProject) =>
15
- (type: ts.Type) =>
16
- (decorator: ts.Decorator): ts.Decorator => {
17
- //----
18
- // VALIDATIONS
19
- //----
20
- // CHECK DECORATOR
21
- if (!ts.isCallExpression(decorator.expression)) return decorator;
22
-
23
- // SIGNATURE DECLARATION
24
- const declaration: ts.Declaration | undefined =
25
- project.checker.getResolvedSignature(decorator.expression)?.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
- getName(project.checker.getTypeAtLocation(declaration).symbol)
40
- ];
41
- if (programmer === undefined) return decorator;
42
-
43
- // GET TYPE INFO
44
- const typeNode: ts.TypeNode | undefined = project.checker.typeToTypeNode(
45
- type,
46
- undefined,
47
- undefined,
48
- );
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
- programmer(project)(decorator.expression.expression)(
58
- decorator.expression.arguments,
59
- )(type),
60
- ),
61
- );
62
- };
63
- }
64
-
65
- type Programmer = (
66
- project: INestiaTransformProject,
67
- ) => (
68
- modulo: ts.LeftHandSideExpression,
69
- ) => (
70
- parameters: readonly ts.Expression[],
71
- ) => (type: ts.Type) => readonly ts.Expression[];
72
-
73
- const FUNCTORS: Record<string, Programmer> = {
74
- EncryptedBody: (project) => (modulo) => (parameters) => (type) =>
75
- parameters.length
76
- ? parameters
77
- : [TypedBodyProgrammer.generate(project)(modulo)(type)],
78
- TypedBody: (project) => (modulo) => (parameters) => (type) =>
79
- parameters.length
80
- ? parameters
81
- : [TypedBodyProgrammer.generate(project)(modulo)(type)],
82
- TypedHeaders: (project) => (modulo) => (parameters) => (type) =>
83
- parameters.length
84
- ? parameters
85
- : [TypedHeadersProgrammer.generate(project)(modulo)(type)],
86
- TypedParam: (project) => TypedParamProgrammer.generate(project),
87
- TypedQuery: (project) => (modulo) => (parameters) => (type) =>
88
- parameters.length
89
- ? parameters
90
- : [TypedQueryProgrammer.generate(project)(modulo)(type)],
91
- "TypedQuery.Body": (project) => (modulo) => (parameters) => (type) =>
92
- parameters.length
93
- ? parameters
94
- : [TypedQueryBodyProgrammer.generate(project)(modulo)(type)],
95
- PlainBody: (project) => (modulo) => (parameters) => (type) =>
96
- parameters.length
97
- ? parameters
98
- : [PlainBodyProgrammer.generate(project)(modulo)(type)],
99
- };
100
-
101
- const LIB_PATH = path.join(
102
- "node_modules",
103
- "@nestia",
104
- "core",
105
- "lib",
106
- "decorators",
107
- );
108
- const SRC_PATH = path.resolve(path.join(__dirname, "..", "decorators"));
109
-
110
- const getName = (symbol: ts.Symbol): string => {
111
- const parent = symbol.getDeclarations()?.[0]?.parent;
112
- return parent ? exploreName(parent)(symbol.escapedName.toString()) : "__type";
113
- };
114
- const exploreName =
115
- (decl: ts.Node) =>
116
- (name: string): string =>
117
- ts.isModuleBlock(decl)
118
- ? exploreName(decl.parent.parent)(
119
- `${decl.parent.name.getFullText().trim()}.${name}`,
120
- )
121
- : name;
1
+ import path from "path";
2
+ import ts from "typescript";
3
+
4
+ import { INestiaTransformProject } from "../options/INestiaTransformProject";
5
+ import { PlainBodyProgrammer } from "../programmers/PlainBodyProgrammer";
6
+ import { TypedBodyProgrammer } from "../programmers/TypedBodyProgrammer";
7
+ import { TypedFormDataBodyProgrammer } from "../programmers/TypedFormDataBodyProgrammer";
8
+ import { TypedHeadersProgrammer } from "../programmers/TypedHeadersProgrammer";
9
+ import { TypedParamProgrammer } from "../programmers/TypedParamProgrammer";
10
+ import { TypedQueryBodyProgrammer } from "../programmers/TypedQueryBodyProgrammer";
11
+ import { TypedQueryProgrammer } from "../programmers/TypedQueryProgrammer";
12
+
13
+ export namespace ParameterDecoratorTransformer {
14
+ export const transform =
15
+ (project: INestiaTransformProject) =>
16
+ (type: ts.Type) =>
17
+ (decorator: ts.Decorator): ts.Decorator => {
18
+ //----
19
+ // VALIDATIONS
20
+ //----
21
+ // CHECK DECORATOR
22
+ if (!ts.isCallExpression(decorator.expression)) return decorator;
23
+
24
+ // SIGNATURE DECLARATION
25
+ const declaration: ts.Declaration | undefined =
26
+ project.checker.getResolvedSignature(decorator.expression)?.declaration;
27
+ if (declaration === undefined) return decorator;
28
+
29
+ // FILE PATH
30
+ const file: string = path.resolve(declaration.getSourceFile().fileName);
31
+ if (file.indexOf(LIB_PATH) === -1 && file.indexOf(SRC_PATH) === -1)
32
+ return decorator;
33
+
34
+ //----
35
+ // TRANSFORMATION
36
+ //----
37
+ // FIND PROGRAMMER
38
+ const programmer: Programmer | undefined =
39
+ FUNCTORS[
40
+ getName(project.checker.getTypeAtLocation(declaration).symbol)
41
+ ];
42
+ if (programmer === undefined) return decorator;
43
+
44
+ // GET TYPE INFO
45
+ const typeNode: ts.TypeNode | undefined = project.checker.typeToTypeNode(
46
+ type,
47
+ undefined,
48
+ undefined,
49
+ );
50
+ if (typeNode === undefined) return decorator;
51
+
52
+ // DO TRANSFORM
53
+ return ts.factory.createDecorator(
54
+ ts.factory.updateCallExpression(
55
+ decorator.expression,
56
+ decorator.expression.expression,
57
+ decorator.expression.typeArguments,
58
+ programmer(project)(decorator.expression.expression)(
59
+ decorator.expression.arguments,
60
+ )(type),
61
+ ),
62
+ );
63
+ };
64
+ }
65
+
66
+ type Programmer = (
67
+ project: INestiaTransformProject,
68
+ ) => (
69
+ modulo: ts.LeftHandSideExpression,
70
+ ) => (
71
+ parameters: readonly ts.Expression[],
72
+ ) => (type: ts.Type) => readonly ts.Expression[];
73
+
74
+ const FUNCTORS: Record<string, Programmer> = {
75
+ EncryptedBody: (project) => (modulo) => (parameters) => (type) =>
76
+ parameters.length
77
+ ? parameters
78
+ : [TypedBodyProgrammer.generate(project)(modulo)(type)],
79
+ TypedBody: (project) => (modulo) => (parameters) => (type) =>
80
+ parameters.length
81
+ ? parameters
82
+ : [TypedBodyProgrammer.generate(project)(modulo)(type)],
83
+ TypedHeaders: (project) => (modulo) => (parameters) => (type) =>
84
+ parameters.length
85
+ ? parameters
86
+ : [TypedHeadersProgrammer.generate(project)(modulo)(type)],
87
+ TypedParam: (project) => TypedParamProgrammer.generate(project),
88
+ TypedQuery: (project) => (modulo) => (parameters) => (type) =>
89
+ parameters.length
90
+ ? parameters
91
+ : [TypedQueryProgrammer.generate(project)(modulo)(type)],
92
+ "TypedQuery.Body": (project) => (modulo) => (parameters) => (type) =>
93
+ parameters.length
94
+ ? parameters
95
+ : [TypedQueryBodyProgrammer.generate(project)(modulo)(type)],
96
+ "TypedFormData.Body": (project) => (modulo) => (parameters) => (type) =>
97
+ parameters.length
98
+ ? parameters
99
+ : [TypedFormDataBodyProgrammer.generate(project)(modulo)(type)],
100
+ PlainBody: (project) => (modulo) => (parameters) => (type) =>
101
+ parameters.length
102
+ ? parameters
103
+ : [PlainBodyProgrammer.generate(project)(modulo)(type)],
104
+ };
105
+
106
+ const LIB_PATH = path.join("@nestia", "core", "lib", "decorators");
107
+ const SRC_PATH = path.resolve(path.join(__dirname, "..", "decorators"));
108
+
109
+ const getName = (symbol: ts.Symbol): string => {
110
+ const parent = symbol.getDeclarations()?.[0]?.parent;
111
+ return parent ? exploreName(parent)(symbol.escapedName.toString()) : "__type";
112
+ };
113
+ const exploreName =
114
+ (decl: ts.Node) =>
115
+ (name: string): string =>
116
+ ts.isModuleBlock(decl)
117
+ ? exploreName(decl.parent.parent)(
118
+ `${decl.parent.name.getFullText().trim()}.${name}`,
119
+ )
120
+ : name;
@@ -1,48 +1,48 @@
1
- import ts from "typescript";
2
-
3
- import { INestiaTransformProject } from "../options/INestiaTransformProject";
4
- import { ParameterDecoratorTransformer } from "./ParameterDecoratorTransformer";
5
-
6
- export namespace ParameterTransformer {
7
- export const transform =
8
- (project: INestiaTransformProject) =>
9
- (param: ts.ParameterDeclaration): ts.ParameterDeclaration => {
10
- // CHECK DECORATOR
11
- const decorators: readonly ts.Decorator[] | undefined = ts.getDecorators
12
- ? ts.getDecorators(param)
13
- : (param as any).decorators;
14
- if (!decorators?.length) return param;
15
-
16
- // GET TYPE INFO
17
- const type: ts.Type = project.checker.getTypeAtLocation(param);
18
-
19
- // WHEN LATEST TS VERSION
20
- if (ts.getDecorators !== undefined)
21
- return ts.factory.updateParameterDeclaration(
22
- param,
23
- (param.modifiers || []).map((mod) =>
24
- ts.isDecorator(mod)
25
- ? ParameterDecoratorTransformer.transform(project)(type)(mod)
26
- : mod,
27
- ),
28
- param.dotDotDotToken,
29
- param.name,
30
- param.questionToken,
31
- param.type,
32
- param.initializer,
33
- );
34
- // eslint-disable-next-line
35
- return (ts.factory.updateParameterDeclaration as any)(
36
- param,
37
- decorators.map((deco) =>
38
- ParameterDecoratorTransformer.transform(project)(type)(deco),
39
- ),
40
- (param as any).modifiers,
41
- param.dotDotDotToken,
42
- param.name,
43
- param.questionToken,
44
- param.type,
45
- param.initializer,
46
- );
47
- };
48
- }
1
+ import ts from "typescript";
2
+
3
+ import { INestiaTransformProject } from "../options/INestiaTransformProject";
4
+ import { ParameterDecoratorTransformer } from "./ParameterDecoratorTransformer";
5
+
6
+ export namespace ParameterTransformer {
7
+ export const transform =
8
+ (project: INestiaTransformProject) =>
9
+ (param: ts.ParameterDeclaration): ts.ParameterDeclaration => {
10
+ // CHECK DECORATOR
11
+ const decorators: readonly ts.Decorator[] | undefined = ts.getDecorators
12
+ ? ts.getDecorators(param)
13
+ : (param as any).decorators;
14
+ if (!decorators?.length) return param;
15
+
16
+ // GET TYPE INFO
17
+ const type: ts.Type = project.checker.getTypeAtLocation(param);
18
+
19
+ // WHEN LATEST TS VERSION
20
+ if (ts.getDecorators !== undefined)
21
+ return ts.factory.updateParameterDeclaration(
22
+ param,
23
+ (param.modifiers || []).map((mod) =>
24
+ ts.isDecorator(mod)
25
+ ? ParameterDecoratorTransformer.transform(project)(type)(mod)
26
+ : mod,
27
+ ),
28
+ param.dotDotDotToken,
29
+ param.name,
30
+ param.questionToken,
31
+ param.type,
32
+ param.initializer,
33
+ );
34
+ // eslint-disable-next-line
35
+ return (ts.factory.updateParameterDeclaration as any)(
36
+ param,
37
+ decorators.map((deco) =>
38
+ ParameterDecoratorTransformer.transform(project)(type)(deco),
39
+ ),
40
+ (param as any).modifiers,
41
+ param.dotDotDotToken,
42
+ param.name,
43
+ param.questionToken,
44
+ param.type,
45
+ param.initializer,
46
+ );
47
+ };
48
+ }
@@ -1,49 +1,48 @@
1
- import path from "path";
2
- import ts from "typescript";
3
-
4
- import { INestiaTransformProject } from "../options/INestiaTransformProject";
5
- import { TypedExceptionProgrammer } from "../programmers/TypedExceptionProgrammer";
6
-
7
- export namespace TypedExceptionTransformer {
8
- export const transform =
9
- (project: INestiaTransformProject) =>
10
- (decorator: ts.Decorator): ts.Decorator => {
11
- if (!ts.isCallExpression(decorator.expression)) return decorator;
12
-
13
- // CHECK SIGNATURE
14
- const signature: ts.Signature | undefined =
15
- project.checker.getResolvedSignature(decorator.expression);
16
- if (!signature || !signature.declaration) return decorator;
17
-
18
- // CHECK TO BE TRANSFORMED
19
- const done: boolean = (() => {
20
- // CHECK FILENAME
21
- const location: string = path.resolve(
22
- signature.declaration.getSourceFile().fileName,
23
- );
24
- if (location.indexOf(LIB_PATH) === -1 && location !== SRC_PATH)
25
- return false;
26
-
27
- // CHECK DUPLICATED
28
- return decorator.expression.arguments.length !== 3;
29
- })();
30
- if (done === false) return decorator;
31
-
32
- // DO TRANSFORM
33
- return ts.factory.createDecorator(
34
- TypedExceptionProgrammer.generate(project)(decorator.expression),
35
- );
36
- };
37
-
38
- const LIB_PATH = path.join(
39
- "node_modules",
40
- "@nestia",
41
- "core",
42
- "lib",
43
- "decorators",
44
- `TypedException.d.ts`,
45
- );
46
- const SRC_PATH = path.resolve(
47
- path.join(__dirname, "..", "decorators", `TypedException.ts`),
48
- );
49
- }
1
+ import path from "path";
2
+ import ts from "typescript";
3
+
4
+ import { INestiaTransformProject } from "../options/INestiaTransformProject";
5
+ import { TypedExceptionProgrammer } from "../programmers/TypedExceptionProgrammer";
6
+
7
+ export namespace TypedExceptionTransformer {
8
+ export const transform =
9
+ (project: INestiaTransformProject) =>
10
+ (decorator: ts.Decorator): ts.Decorator => {
11
+ if (!ts.isCallExpression(decorator.expression)) return decorator;
12
+
13
+ // CHECK SIGNATURE
14
+ const signature: ts.Signature | undefined =
15
+ project.checker.getResolvedSignature(decorator.expression);
16
+ if (!signature || !signature.declaration) return decorator;
17
+
18
+ // CHECK TO BE TRANSFORMED
19
+ const done: boolean = (() => {
20
+ // CHECK FILENAME
21
+ const location: string = path.resolve(
22
+ signature.declaration.getSourceFile().fileName,
23
+ );
24
+ if (location.indexOf(LIB_PATH) === -1 && location !== SRC_PATH)
25
+ return false;
26
+
27
+ // CHECK DUPLICATED
28
+ return decorator.expression.arguments.length !== 3;
29
+ })();
30
+ if (done === false) return decorator;
31
+
32
+ // DO TRANSFORM
33
+ return ts.factory.createDecorator(
34
+ TypedExceptionProgrammer.generate(project)(decorator.expression),
35
+ );
36
+ };
37
+
38
+ const LIB_PATH = path.join(
39
+ "@nestia",
40
+ "core",
41
+ "lib",
42
+ "decorators",
43
+ `TypedException.d.ts`,
44
+ );
45
+ const SRC_PATH = path.resolve(
46
+ path.join(__dirname, "..", "decorators", `TypedException.ts`),
47
+ );
48
+ }
@@ -1,95 +1,88 @@
1
- import path from "path";
2
- import ts from "typescript";
3
-
4
- import { INestiaTransformProject } from "../options/INestiaTransformProject";
5
- import { TypedQueryRouteProgrammer } from "../programmers/TypedQueryRouteProgrammer";
6
- import { TypedRouteProgrammer } from "../programmers/TypedRouteProgrammer";
7
-
8
- export namespace TypedRouteTransformer {
9
- export const transform =
10
- (project: INestiaTransformProject) =>
11
- (type: ts.Type) =>
12
- (decorator: ts.Decorator): 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 modulo = (() => {
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 null;
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 location.split(path.sep).at(-1)?.split(".")[0] === "TypedQuery"
43
- ? "TypedQuery"
44
- : "TypedRoute";
45
- })();
46
- if (modulo === null) return decorator;
47
-
48
- // CHECK TYPE NODE
49
- const typeNode: ts.TypeNode | undefined = project.checker.typeToTypeNode(
50
- type,
51
- undefined,
52
- undefined,
53
- );
54
- if (typeNode === undefined) return decorator;
55
-
56
- // DO TRANSFORM
57
- return ts.factory.createDecorator(
58
- ts.factory.updateCallExpression(
59
- decorator.expression,
60
- decorator.expression.expression,
61
- decorator.expression.typeArguments,
62
- [
63
- ...decorator.expression.arguments,
64
- (modulo === "TypedQuery"
65
- ? TypedQueryRouteProgrammer
66
- : TypedRouteProgrammer
67
- ).generate(project)(decorator.expression.expression)(type),
68
- ],
69
- ),
70
- );
71
- };
72
-
73
- const isObject =
74
- (checker: ts.TypeChecker) =>
75
- (type: ts.Type): boolean =>
76
- (type.getFlags() & ts.TypeFlags.Object) !== 0 &&
77
- !(checker as any).isTupleType(type) &&
78
- !(checker as any).isArrayType(type) &&
79
- !(checker as any).isArrayLikeType(type);
80
-
81
- const CLASSES = ["EncryptedRoute", "TypedRoute", "TypedQuery"];
82
- const LIB_PATHS = CLASSES.map((cla) =>
83
- path.join(
84
- "node_modules",
85
- "@nestia",
86
- "core",
87
- "lib",
88
- "decorators",
89
- `${cla}.d.ts`,
90
- ),
91
- );
92
- const SRC_PATHS = CLASSES.map((cla) =>
93
- path.resolve(path.join(__dirname, "..", "decorators", `${cla}.ts`)),
94
- );
95
- }
1
+ import path from "path";
2
+ import ts from "typescript";
3
+
4
+ import { INestiaTransformProject } from "../options/INestiaTransformProject";
5
+ import { TypedQueryRouteProgrammer } from "../programmers/TypedQueryRouteProgrammer";
6
+ import { TypedRouteProgrammer } from "../programmers/TypedRouteProgrammer";
7
+
8
+ export namespace TypedRouteTransformer {
9
+ export const transform =
10
+ (project: INestiaTransformProject) =>
11
+ (type: ts.Type) =>
12
+ (decorator: ts.Decorator): 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 modulo = (() => {
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 null;
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 location.split(path.sep).at(-1)?.split(".")[0] === "TypedQuery"
43
+ ? "TypedQuery"
44
+ : "TypedRoute";
45
+ })();
46
+ if (modulo === null) return decorator;
47
+
48
+ // CHECK TYPE NODE
49
+ const typeNode: ts.TypeNode | undefined = project.checker.typeToTypeNode(
50
+ type,
51
+ undefined,
52
+ undefined,
53
+ );
54
+ if (typeNode === undefined) return decorator;
55
+
56
+ // DO TRANSFORM
57
+ return ts.factory.createDecorator(
58
+ ts.factory.updateCallExpression(
59
+ decorator.expression,
60
+ decorator.expression.expression,
61
+ decorator.expression.typeArguments,
62
+ [
63
+ ...decorator.expression.arguments,
64
+ (modulo === "TypedQuery"
65
+ ? TypedQueryRouteProgrammer
66
+ : TypedRouteProgrammer
67
+ ).generate(project)(decorator.expression.expression)(type),
68
+ ],
69
+ ),
70
+ );
71
+ };
72
+
73
+ const isObject =
74
+ (checker: ts.TypeChecker) =>
75
+ (type: ts.Type): boolean =>
76
+ (type.getFlags() & ts.TypeFlags.Object) !== 0 &&
77
+ !(checker as any).isTupleType(type) &&
78
+ !(checker as any).isArrayType(type) &&
79
+ !(checker as any).isArrayLikeType(type);
80
+
81
+ const CLASSES = ["EncryptedRoute", "TypedRoute", "TypedQuery"];
82
+ const LIB_PATHS = CLASSES.map((cla) =>
83
+ path.join("@nestia", "core", "lib", "decorators", `${cla}.d.ts`),
84
+ );
85
+ const SRC_PATHS = CLASSES.map((cla) =>
86
+ path.resolve(path.join(__dirname, "..", "decorators", `${cla}.ts`)),
87
+ );
88
+ }
@@ -1,3 +1,3 @@
1
- export type Creator<T extends object> = {
2
- new (...args: any[]): T;
3
- };
1
+ export type Creator<T extends object> = {
2
+ new (...args: any[]): T;
3
+ };