@nestia/core 4.2.0-dev.20241211 → 4.2.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 (74) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +87 -87
  3. package/package.json +3 -3
  4. package/src/adaptors/WebSocketAdaptor.ts +426 -426
  5. package/src/decorators/DynamicModule.ts +43 -43
  6. package/src/decorators/EncryptedBody.ts +101 -101
  7. package/src/decorators/EncryptedController.ts +38 -38
  8. package/src/decorators/EncryptedModule.ts +100 -100
  9. package/src/decorators/EncryptedRoute.ts +219 -219
  10. package/src/decorators/NoTransformConfigurationError.ts +32 -32
  11. package/src/decorators/PlainBody.ts +79 -79
  12. package/src/decorators/SwaggerCustomizer.ts +115 -115
  13. package/src/decorators/SwaggerExample.ts +100 -100
  14. package/src/decorators/TypedBody.ts +59 -59
  15. package/src/decorators/TypedException.ts +128 -128
  16. package/src/decorators/TypedFormData.ts +195 -195
  17. package/src/decorators/TypedHeaders.ts +64 -64
  18. package/src/decorators/TypedParam.ts +66 -66
  19. package/src/decorators/TypedQuery.ts +245 -245
  20. package/src/decorators/TypedRoute.ts +214 -214
  21. package/src/decorators/WebSocketRoute.ts +242 -242
  22. package/src/decorators/internal/EncryptedConstant.ts +4 -4
  23. package/src/decorators/internal/IWebSocketRouteReflect.ts +23 -23
  24. package/src/decorators/internal/NoTransformConfigureError.ts +2 -2
  25. package/src/decorators/internal/get_path_and_querify.ts +108 -108
  26. package/src/decorators/internal/get_path_and_stringify.ts +122 -122
  27. package/src/decorators/internal/get_text_body.ts +20 -20
  28. package/src/decorators/internal/headers_to_object.ts +13 -13
  29. package/src/decorators/internal/is_request_body_undefined.ts +14 -14
  30. package/src/decorators/internal/load_controller.ts +49 -49
  31. package/src/decorators/internal/route_error.ts +45 -45
  32. package/src/decorators/internal/validate_request_body.ts +74 -74
  33. package/src/decorators/internal/validate_request_form_data.ts +77 -77
  34. package/src/decorators/internal/validate_request_headers.ts +86 -86
  35. package/src/decorators/internal/validate_request_query.ts +74 -74
  36. package/src/index.ts +5 -5
  37. package/src/module.ts +21 -21
  38. package/src/options/INestiaTransformOptions.ts +24 -24
  39. package/src/options/INestiaTransformProject.ts +8 -8
  40. package/src/options/IRequestBodyValidator.ts +20 -20
  41. package/src/options/IRequestFormDataProps.ts +27 -27
  42. package/src/options/IRequestHeadersValidator.ts +22 -22
  43. package/src/options/IRequestQueryValidator.ts +20 -20
  44. package/src/options/IResponseBodyQuerifier.ts +25 -25
  45. package/src/options/IResponseBodyStringifier.ts +30 -30
  46. package/src/programmers/PlainBodyProgrammer.ts +70 -70
  47. package/src/programmers/TypedBodyProgrammer.ts +132 -132
  48. package/src/programmers/TypedFormDataBodyProgrammer.ts +118 -118
  49. package/src/programmers/TypedHeadersProgrammer.ts +63 -63
  50. package/src/programmers/TypedParamProgrammer.ts +30 -30
  51. package/src/programmers/TypedQueryBodyProgrammer.ts +63 -63
  52. package/src/programmers/TypedQueryProgrammer.ts +65 -65
  53. package/src/programmers/TypedQueryRouteProgrammer.ts +56 -56
  54. package/src/programmers/TypedRouteProgrammer.ts +76 -76
  55. package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +72 -72
  56. package/src/programmers/http/HttpIsQuerifyProgrammer.ts +75 -75
  57. package/src/programmers/http/HttpQuerifyProgrammer.ts +108 -108
  58. package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +76 -76
  59. package/src/programmers/internal/CoreMetadataUtil.ts +21 -21
  60. package/src/transform.ts +35 -35
  61. package/src/transformers/FileTransformer.ts +110 -110
  62. package/src/transformers/MethodTransformer.ts +103 -103
  63. package/src/transformers/NodeTransformer.ts +23 -23
  64. package/src/transformers/ParameterDecoratorTransformer.ts +143 -143
  65. package/src/transformers/ParameterTransformer.ts +57 -57
  66. package/src/transformers/TypedRouteTransformer.ts +85 -85
  67. package/src/transformers/WebSocketRouteTransformer.ts +120 -120
  68. package/src/typings/Creator.ts +3 -3
  69. package/src/typings/get-function-location.d.ts +7 -7
  70. package/src/utils/ArrayUtil.ts +7 -7
  71. package/src/utils/ExceptionManager.ts +112 -112
  72. package/src/utils/Singleton.ts +20 -20
  73. package/src/utils/SourceFinder.ts +57 -57
  74. package/src/utils/VersioningStrategy.ts +27 -27
@@ -1,103 +1,103 @@
1
- import ts from "typescript";
2
-
3
- import { INestiaTransformContext } from "../options/INestiaTransformProject";
4
- import { TypedRouteTransformer } from "./TypedRouteTransformer";
5
- import { WebSocketRouteTransformer } from "./WebSocketRouteTransformer";
6
-
7
- export namespace MethodTransformer {
8
- export const transform = (props: {
9
- context: INestiaTransformContext;
10
- method: ts.MethodDeclaration;
11
- }): ts.MethodDeclaration => {
12
- const decorators: readonly ts.Decorator[] | undefined = ts.getDecorators
13
- ? ts.getDecorators(props.method)
14
- : (props.method as any).decorators;
15
- if (!decorators?.length) return props.method;
16
-
17
- const signature: ts.Signature | undefined =
18
- props.context.checker.getSignatureFromDeclaration(props.method);
19
- const original: ts.Type | undefined =
20
- signature && props.context.checker.getReturnTypeOfSignature(signature);
21
- const type: ts.Type | undefined =
22
- original && get_escaped_type(props.context.checker)(original);
23
-
24
- if (type === undefined) return props.method;
25
-
26
- const operator = (decorator: ts.Decorator): ts.Decorator => {
27
- decorator = TypedRouteTransformer.transform({
28
- context: props.context,
29
- decorator,
30
- type,
31
- });
32
- decorator = WebSocketRouteTransformer.validate({
33
- context: props.context,
34
- method: props.method,
35
- decorator,
36
- });
37
- return decorator;
38
- };
39
- if (ts.getDecorators !== undefined)
40
- return ts.factory.updateMethodDeclaration(
41
- props.method,
42
- (props.method.modifiers || []).map((mod) =>
43
- ts.isDecorator(mod) ? operator(mod) : mod,
44
- ),
45
- props.method.asteriskToken,
46
- props.method.name,
47
- props.method.questionToken,
48
- props.method.typeParameters,
49
- props.method.parameters,
50
- props.method.type,
51
- props.method.body,
52
- );
53
- // eslint-disable-next-line
54
- return (ts.factory.updateMethodDeclaration as any)(
55
- props.method,
56
- decorators.map(operator),
57
- (props.method as any).modifiers,
58
- props.method.asteriskToken,
59
- props.method.name,
60
- props.method.questionToken,
61
- props.method.typeParameters,
62
- props.method.parameters,
63
- props.method.type,
64
- props.method.body,
65
- );
66
- };
67
- }
68
-
69
- const get_escaped_type =
70
- (checker: ts.TypeChecker) =>
71
- (type: ts.Type): ts.Type => {
72
- const symbol: ts.Symbol | undefined = type.getSymbol() || type.aliasSymbol;
73
- return symbol && get_name(symbol) === "Promise"
74
- ? escape_promise(checker)(type)
75
- : type;
76
- };
77
-
78
- const escape_promise =
79
- (checker: ts.TypeChecker) =>
80
- (type: ts.Type): ts.Type => {
81
- const generic: readonly ts.Type[] = checker.getTypeArguments(
82
- type as ts.TypeReference,
83
- );
84
- if (generic.length !== 1)
85
- throw new Error(
86
- "Error on ImportAnalyzer.analyze(): invalid promise type.",
87
- );
88
- return generic[0];
89
- };
90
-
91
- const get_name = (symbol: ts.Symbol): string =>
92
- explore_name(symbol.getDeclarations()![0].parent)(
93
- symbol.escapedName.toString(),
94
- );
95
-
96
- const explore_name =
97
- (decl: ts.Node) =>
98
- (name: string): string =>
99
- ts.isModuleBlock(decl)
100
- ? explore_name(decl.parent.parent)(
101
- `${decl.parent.name.getFullText().trim()}.${name}`,
102
- )
103
- : name;
1
+ import ts from "typescript";
2
+
3
+ import { INestiaTransformContext } from "../options/INestiaTransformProject";
4
+ import { TypedRouteTransformer } from "./TypedRouteTransformer";
5
+ import { WebSocketRouteTransformer } from "./WebSocketRouteTransformer";
6
+
7
+ export namespace MethodTransformer {
8
+ export const transform = (props: {
9
+ context: INestiaTransformContext;
10
+ method: ts.MethodDeclaration;
11
+ }): ts.MethodDeclaration => {
12
+ const decorators: readonly ts.Decorator[] | undefined = ts.getDecorators
13
+ ? ts.getDecorators(props.method)
14
+ : (props.method as any).decorators;
15
+ if (!decorators?.length) return props.method;
16
+
17
+ const signature: ts.Signature | undefined =
18
+ props.context.checker.getSignatureFromDeclaration(props.method);
19
+ const original: ts.Type | undefined =
20
+ signature && props.context.checker.getReturnTypeOfSignature(signature);
21
+ const type: ts.Type | undefined =
22
+ original && get_escaped_type(props.context.checker)(original);
23
+
24
+ if (type === undefined) return props.method;
25
+
26
+ const operator = (decorator: ts.Decorator): ts.Decorator => {
27
+ decorator = TypedRouteTransformer.transform({
28
+ context: props.context,
29
+ decorator,
30
+ type,
31
+ });
32
+ decorator = WebSocketRouteTransformer.validate({
33
+ context: props.context,
34
+ method: props.method,
35
+ decorator,
36
+ });
37
+ return decorator;
38
+ };
39
+ if (ts.getDecorators !== undefined)
40
+ return ts.factory.updateMethodDeclaration(
41
+ props.method,
42
+ (props.method.modifiers || []).map((mod) =>
43
+ ts.isDecorator(mod) ? operator(mod) : mod,
44
+ ),
45
+ props.method.asteriskToken,
46
+ props.method.name,
47
+ props.method.questionToken,
48
+ props.method.typeParameters,
49
+ props.method.parameters,
50
+ props.method.type,
51
+ props.method.body,
52
+ );
53
+ // eslint-disable-next-line
54
+ return (ts.factory.updateMethodDeclaration as any)(
55
+ props.method,
56
+ decorators.map(operator),
57
+ (props.method as any).modifiers,
58
+ props.method.asteriskToken,
59
+ props.method.name,
60
+ props.method.questionToken,
61
+ props.method.typeParameters,
62
+ props.method.parameters,
63
+ props.method.type,
64
+ props.method.body,
65
+ );
66
+ };
67
+ }
68
+
69
+ const get_escaped_type =
70
+ (checker: ts.TypeChecker) =>
71
+ (type: ts.Type): ts.Type => {
72
+ const symbol: ts.Symbol | undefined = type.getSymbol() || type.aliasSymbol;
73
+ return symbol && get_name(symbol) === "Promise"
74
+ ? escape_promise(checker)(type)
75
+ : type;
76
+ };
77
+
78
+ const escape_promise =
79
+ (checker: ts.TypeChecker) =>
80
+ (type: ts.Type): ts.Type => {
81
+ const generic: readonly ts.Type[] = checker.getTypeArguments(
82
+ type as ts.TypeReference,
83
+ );
84
+ if (generic.length !== 1)
85
+ throw new Error(
86
+ "Error on ImportAnalyzer.analyze(): invalid promise type.",
87
+ );
88
+ return generic[0];
89
+ };
90
+
91
+ const get_name = (symbol: ts.Symbol): string =>
92
+ explore_name(symbol.getDeclarations()![0].parent)(
93
+ symbol.escapedName.toString(),
94
+ );
95
+
96
+ const explore_name =
97
+ (decl: ts.Node) =>
98
+ (name: string): string =>
99
+ ts.isModuleBlock(decl)
100
+ ? explore_name(decl.parent.parent)(
101
+ `${decl.parent.name.getFullText().trim()}.${name}`,
102
+ )
103
+ : name;
@@ -1,23 +1,23 @@
1
- import ts from "typescript";
2
-
3
- import { INestiaTransformContext } from "../options/INestiaTransformProject";
4
- import { MethodTransformer } from "./MethodTransformer";
5
- import { ParameterTransformer } from "./ParameterTransformer";
6
-
7
- export namespace NodeTransformer {
8
- export const transform = (props: {
9
- context: INestiaTransformContext;
10
- node: ts.Node;
11
- }): ts.Node =>
12
- ts.isMethodDeclaration(props.node)
13
- ? MethodTransformer.transform({
14
- context: props.context,
15
- method: props.node,
16
- })
17
- : ts.isParameter(props.node)
18
- ? ParameterTransformer.transform({
19
- context: props.context,
20
- param: props.node,
21
- })
22
- : props.node;
23
- }
1
+ import ts from "typescript";
2
+
3
+ import { INestiaTransformContext } from "../options/INestiaTransformProject";
4
+ import { MethodTransformer } from "./MethodTransformer";
5
+ import { ParameterTransformer } from "./ParameterTransformer";
6
+
7
+ export namespace NodeTransformer {
8
+ export const transform = (props: {
9
+ context: INestiaTransformContext;
10
+ node: ts.Node;
11
+ }): ts.Node =>
12
+ ts.isMethodDeclaration(props.node)
13
+ ? MethodTransformer.transform({
14
+ context: props.context,
15
+ method: props.node,
16
+ })
17
+ : ts.isParameter(props.node)
18
+ ? ParameterTransformer.transform({
19
+ context: props.context,
20
+ param: props.node,
21
+ })
22
+ : props.node;
23
+ }
@@ -1,143 +1,143 @@
1
- import path from "path";
2
- import ts from "typescript";
3
-
4
- import { INestiaTransformContext } 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 = (props: {
15
- context: INestiaTransformContext;
16
- type: ts.Type;
17
- decorator: ts.Decorator;
18
- }): ts.Decorator => {
19
- //----
20
- // VALIDATIONS
21
- //----
22
- // CHECK DECORATOR
23
- if (!ts.isCallExpression(props.decorator.expression))
24
- return props.decorator;
25
-
26
- // SIGNATURE DECLARATION
27
- const declaration: ts.Declaration | undefined =
28
- props.context.checker.getResolvedSignature(
29
- props.decorator.expression,
30
- )?.declaration;
31
- if (declaration === undefined) return props.decorator;
32
-
33
- // FILE PATH
34
- const file: string = path.resolve(declaration.getSourceFile().fileName);
35
- if (file.indexOf(LIB_PATH) === -1 && file.indexOf(MONO_PATH) === -1)
36
- return props.decorator;
37
-
38
- //----
39
- // TRANSFORMATION
40
- //----
41
- // FIND PROGRAMMER
42
- const programmer: Programmer | undefined =
43
- FUNCTORS[
44
- getName(props.context.checker.getTypeAtLocation(declaration).symbol)
45
- ];
46
- if (programmer === undefined) return props.decorator;
47
-
48
- // GET TYPE INFO
49
- const typeNode: ts.TypeNode | undefined =
50
- props.context.checker.typeToTypeNode(props.type, undefined, undefined);
51
- if (typeNode === undefined) return props.decorator;
52
-
53
- // DO TRANSFORM
54
- return ts.factory.createDecorator(
55
- ts.factory.updateCallExpression(
56
- props.decorator.expression,
57
- props.decorator.expression.expression,
58
- props.decorator.expression.typeArguments,
59
- programmer({
60
- context: props.context,
61
- modulo: props.decorator.expression.expression,
62
- arguments: props.decorator.expression.arguments,
63
- type: props.type,
64
- }),
65
- ),
66
- );
67
- };
68
- }
69
-
70
- type Programmer = (props: {
71
- context: INestiaTransformContext;
72
- modulo: ts.LeftHandSideExpression;
73
- arguments: readonly ts.Expression[];
74
- type: ts.Type;
75
- }) => readonly ts.Expression[];
76
-
77
- const FUNCTORS: Record<string, Programmer> = {
78
- EncryptedBody: (props) =>
79
- props.arguments.length
80
- ? props.arguments
81
- : [TypedBodyProgrammer.generate(props)],
82
- TypedBody: (props) =>
83
- props.arguments.length
84
- ? props.arguments
85
- : [TypedBodyProgrammer.generate(props)],
86
- TypedHeaders: (props) =>
87
- props.arguments.length
88
- ? props.arguments
89
- : [TypedHeadersProgrammer.generate(props)],
90
- TypedParam: (props) =>
91
- props.arguments.length !== 1
92
- ? props.arguments
93
- : TypedParamProgrammer.generate(props),
94
- TypedQuery: (props) =>
95
- props.arguments.length
96
- ? props.arguments
97
- : [TypedQueryProgrammer.generate(props)],
98
- "TypedQuery.Body": (props) =>
99
- props.arguments.length
100
- ? props.arguments
101
- : [TypedQueryBodyProgrammer.generate(props)],
102
- "TypedFormData.Body": (props) =>
103
- props.arguments.length === 0
104
- ? [
105
- ts.factory.createIdentifier("undefined"),
106
- TypedFormDataBodyProgrammer.generate(props),
107
- ]
108
- : props.arguments.length === 1
109
- ? [props.arguments[0], TypedFormDataBodyProgrammer.generate(props)]
110
- : props.arguments,
111
- PlainBody: (props) =>
112
- props.arguments.length
113
- ? props.arguments
114
- : [PlainBodyProgrammer.generate(props)],
115
- "WebSocketRoute.Header": (props) =>
116
- props.arguments.length
117
- ? props.arguments
118
- : [TypedBodyProgrammer.generate(props)],
119
- "WebSocketRoute.Param": (props) =>
120
- props.arguments.length !== 1
121
- ? props.arguments
122
- : TypedParamProgrammer.generate(props),
123
- "WebSocketRoute.Query": (props) =>
124
- props.arguments.length
125
- ? props.arguments
126
- : [TypedQueryProgrammer.generate(props)],
127
- };
128
-
129
- const LIB_PATH = path.join("@nestia", "core", "lib", "decorators");
130
- const MONO_PATH = path.join("packages", "core", "lib", "decorators");
131
-
132
- const getName = (symbol: ts.Symbol): string => {
133
- const parent = symbol.getDeclarations()?.[0]?.parent;
134
- return parent ? exploreName(parent)(symbol.escapedName.toString()) : "__type";
135
- };
136
- const exploreName =
137
- (decl: ts.Node) =>
138
- (name: string): string =>
139
- ts.isModuleBlock(decl)
140
- ? exploreName(decl.parent.parent)(
141
- `${decl.parent.name.getFullText().trim()}.${name}`,
142
- )
143
- : name;
1
+ import path from "path";
2
+ import ts from "typescript";
3
+
4
+ import { INestiaTransformContext } 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 = (props: {
15
+ context: INestiaTransformContext;
16
+ type: ts.Type;
17
+ decorator: ts.Decorator;
18
+ }): ts.Decorator => {
19
+ //----
20
+ // VALIDATIONS
21
+ //----
22
+ // CHECK DECORATOR
23
+ if (!ts.isCallExpression(props.decorator.expression))
24
+ return props.decorator;
25
+
26
+ // SIGNATURE DECLARATION
27
+ const declaration: ts.Declaration | undefined =
28
+ props.context.checker.getResolvedSignature(
29
+ props.decorator.expression,
30
+ )?.declaration;
31
+ if (declaration === undefined) return props.decorator;
32
+
33
+ // FILE PATH
34
+ const file: string = path.resolve(declaration.getSourceFile().fileName);
35
+ if (file.indexOf(LIB_PATH) === -1 && file.indexOf(MONO_PATH) === -1)
36
+ return props.decorator;
37
+
38
+ //----
39
+ // TRANSFORMATION
40
+ //----
41
+ // FIND PROGRAMMER
42
+ const programmer: Programmer | undefined =
43
+ FUNCTORS[
44
+ getName(props.context.checker.getTypeAtLocation(declaration).symbol)
45
+ ];
46
+ if (programmer === undefined) return props.decorator;
47
+
48
+ // GET TYPE INFO
49
+ const typeNode: ts.TypeNode | undefined =
50
+ props.context.checker.typeToTypeNode(props.type, undefined, undefined);
51
+ if (typeNode === undefined) return props.decorator;
52
+
53
+ // DO TRANSFORM
54
+ return ts.factory.createDecorator(
55
+ ts.factory.updateCallExpression(
56
+ props.decorator.expression,
57
+ props.decorator.expression.expression,
58
+ props.decorator.expression.typeArguments,
59
+ programmer({
60
+ context: props.context,
61
+ modulo: props.decorator.expression.expression,
62
+ arguments: props.decorator.expression.arguments,
63
+ type: props.type,
64
+ }),
65
+ ),
66
+ );
67
+ };
68
+ }
69
+
70
+ type Programmer = (props: {
71
+ context: INestiaTransformContext;
72
+ modulo: ts.LeftHandSideExpression;
73
+ arguments: readonly ts.Expression[];
74
+ type: ts.Type;
75
+ }) => readonly ts.Expression[];
76
+
77
+ const FUNCTORS: Record<string, Programmer> = {
78
+ EncryptedBody: (props) =>
79
+ props.arguments.length
80
+ ? props.arguments
81
+ : [TypedBodyProgrammer.generate(props)],
82
+ TypedBody: (props) =>
83
+ props.arguments.length
84
+ ? props.arguments
85
+ : [TypedBodyProgrammer.generate(props)],
86
+ TypedHeaders: (props) =>
87
+ props.arguments.length
88
+ ? props.arguments
89
+ : [TypedHeadersProgrammer.generate(props)],
90
+ TypedParam: (props) =>
91
+ props.arguments.length !== 1
92
+ ? props.arguments
93
+ : TypedParamProgrammer.generate(props),
94
+ TypedQuery: (props) =>
95
+ props.arguments.length
96
+ ? props.arguments
97
+ : [TypedQueryProgrammer.generate(props)],
98
+ "TypedQuery.Body": (props) =>
99
+ props.arguments.length
100
+ ? props.arguments
101
+ : [TypedQueryBodyProgrammer.generate(props)],
102
+ "TypedFormData.Body": (props) =>
103
+ props.arguments.length === 0
104
+ ? [
105
+ ts.factory.createIdentifier("undefined"),
106
+ TypedFormDataBodyProgrammer.generate(props),
107
+ ]
108
+ : props.arguments.length === 1
109
+ ? [props.arguments[0], TypedFormDataBodyProgrammer.generate(props)]
110
+ : props.arguments,
111
+ PlainBody: (props) =>
112
+ props.arguments.length
113
+ ? props.arguments
114
+ : [PlainBodyProgrammer.generate(props)],
115
+ "WebSocketRoute.Header": (props) =>
116
+ props.arguments.length
117
+ ? props.arguments
118
+ : [TypedBodyProgrammer.generate(props)],
119
+ "WebSocketRoute.Param": (props) =>
120
+ props.arguments.length !== 1
121
+ ? props.arguments
122
+ : TypedParamProgrammer.generate(props),
123
+ "WebSocketRoute.Query": (props) =>
124
+ props.arguments.length
125
+ ? props.arguments
126
+ : [TypedQueryProgrammer.generate(props)],
127
+ };
128
+
129
+ const LIB_PATH = path.join("@nestia", "core", "lib", "decorators");
130
+ const MONO_PATH = path.join("packages", "core", "lib", "decorators");
131
+
132
+ const getName = (symbol: ts.Symbol): string => {
133
+ const parent = symbol.getDeclarations()?.[0]?.parent;
134
+ return parent ? exploreName(parent)(symbol.escapedName.toString()) : "__type";
135
+ };
136
+ const exploreName =
137
+ (decl: ts.Node) =>
138
+ (name: string): string =>
139
+ ts.isModuleBlock(decl)
140
+ ? exploreName(decl.parent.parent)(
141
+ `${decl.parent.name.getFullText().trim()}.${name}`,
142
+ )
143
+ : name;
@@ -1,57 +1,57 @@
1
- import ts from "typescript";
2
-
3
- import { INestiaTransformContext } from "../options/INestiaTransformProject";
4
- import { ParameterDecoratorTransformer } from "./ParameterDecoratorTransformer";
5
-
6
- export namespace ParameterTransformer {
7
- export const transform = (props: {
8
- context: INestiaTransformContext;
9
- param: ts.ParameterDeclaration;
10
- }): ts.ParameterDeclaration => {
11
- // CHECK DECORATOR
12
- const decorators: readonly ts.Decorator[] | undefined = ts.getDecorators
13
- ? ts.getDecorators(props.param)
14
- : (props.param as any).decorators;
15
- if (!decorators?.length) return props.param;
16
-
17
- // GET TYPE INFO
18
- const type: ts.Type = props.context.checker.getTypeAtLocation(props.param);
19
-
20
- // WHEN LATEST TS VERSION
21
- if (ts.getDecorators !== undefined)
22
- return ts.factory.updateParameterDeclaration(
23
- props.param,
24
- (props.param.modifiers || []).map((mod) =>
25
- ts.isDecorator(mod)
26
- ? ParameterDecoratorTransformer.transform({
27
- context: props.context,
28
- decorator: mod,
29
- type,
30
- })
31
- : mod,
32
- ),
33
- props.param.dotDotDotToken,
34
- props.param.name,
35
- props.param.questionToken,
36
- props.param.type,
37
- props.param.initializer,
38
- );
39
- // eslint-disable-next-line
40
- return (ts.factory.updateParameterDeclaration as any)(
41
- props.param,
42
- decorators.map((deco) =>
43
- ParameterDecoratorTransformer.transform({
44
- context: props.context,
45
- decorator: deco,
46
- type,
47
- }),
48
- ),
49
- (props.param as any).modifiers,
50
- props.param.dotDotDotToken,
51
- props.param.name,
52
- props.param.questionToken,
53
- props.param.type,
54
- props.param.initializer,
55
- );
56
- };
57
- }
1
+ import ts from "typescript";
2
+
3
+ import { INestiaTransformContext } from "../options/INestiaTransformProject";
4
+ import { ParameterDecoratorTransformer } from "./ParameterDecoratorTransformer";
5
+
6
+ export namespace ParameterTransformer {
7
+ export const transform = (props: {
8
+ context: INestiaTransformContext;
9
+ param: ts.ParameterDeclaration;
10
+ }): ts.ParameterDeclaration => {
11
+ // CHECK DECORATOR
12
+ const decorators: readonly ts.Decorator[] | undefined = ts.getDecorators
13
+ ? ts.getDecorators(props.param)
14
+ : (props.param as any).decorators;
15
+ if (!decorators?.length) return props.param;
16
+
17
+ // GET TYPE INFO
18
+ const type: ts.Type = props.context.checker.getTypeAtLocation(props.param);
19
+
20
+ // WHEN LATEST TS VERSION
21
+ if (ts.getDecorators !== undefined)
22
+ return ts.factory.updateParameterDeclaration(
23
+ props.param,
24
+ (props.param.modifiers || []).map((mod) =>
25
+ ts.isDecorator(mod)
26
+ ? ParameterDecoratorTransformer.transform({
27
+ context: props.context,
28
+ decorator: mod,
29
+ type,
30
+ })
31
+ : mod,
32
+ ),
33
+ props.param.dotDotDotToken,
34
+ props.param.name,
35
+ props.param.questionToken,
36
+ props.param.type,
37
+ props.param.initializer,
38
+ );
39
+ // eslint-disable-next-line
40
+ return (ts.factory.updateParameterDeclaration as any)(
41
+ props.param,
42
+ decorators.map((deco) =>
43
+ ParameterDecoratorTransformer.transform({
44
+ context: props.context,
45
+ decorator: deco,
46
+ type,
47
+ }),
48
+ ),
49
+ (props.param as any).modifiers,
50
+ props.param.dotDotDotToken,
51
+ props.param.name,
52
+ props.param.questionToken,
53
+ props.param.type,
54
+ props.param.initializer,
55
+ );
56
+ };
57
+ }