@nestia/core 11.0.0-dev.20260316 → 11.0.1

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 (47) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +93 -93
  3. package/lib/decorators/NoTransformConfigurationError.d.ts +1 -24
  4. package/lib/decorators/NoTransformConfigurationError.js +2 -0
  5. package/lib/decorators/NoTransformConfigurationError.js.map +1 -1
  6. package/lib/decorators/doNotThrowTransformError.d.ts +1 -0
  7. package/lib/decorators/doNotThrowTransformError.js +9 -0
  8. package/lib/decorators/doNotThrowTransformError.js.map +1 -0
  9. package/lib/module.d.ts +1 -1
  10. package/lib/module.js +1 -1
  11. package/lib/module.js.map +1 -1
  12. package/package.json +8 -8
  13. package/src/adaptors/WebSocketAdaptor.ts +429 -429
  14. package/src/decorators/EncryptedBody.ts +96 -96
  15. package/src/decorators/EncryptedController.ts +40 -40
  16. package/src/decorators/EncryptedModule.ts +98 -98
  17. package/src/decorators/EncryptedRoute.ts +212 -212
  18. package/src/decorators/HumanRoute.ts +21 -21
  19. package/src/decorators/NoTransformConfigurationError.ts +37 -34
  20. package/src/decorators/SwaggerCustomizer.ts +97 -97
  21. package/src/decorators/TypedFormData.ts +187 -187
  22. package/src/decorators/TypedRoute.ts +196 -196
  23. package/src/decorators/doNotThrowTransformError.ts +5 -0
  24. package/src/decorators/internal/headers_to_object.ts +11 -11
  25. package/src/module.ts +23 -23
  26. package/src/options/INestiaTransformOptions.ts +34 -34
  27. package/src/options/INestiaTransformProject.ts +10 -10
  28. package/src/programmers/PlainBodyProgrammer.ts +72 -72
  29. package/src/programmers/TypedBodyProgrammer.ts +148 -148
  30. package/src/programmers/TypedFormDataBodyProgrammer.ts +118 -118
  31. package/src/programmers/TypedHeadersProgrammer.ts +65 -65
  32. package/src/programmers/TypedParamProgrammer.ts +33 -33
  33. package/src/programmers/TypedQueryBodyProgrammer.ts +113 -113
  34. package/src/programmers/TypedQueryProgrammer.ts +115 -115
  35. package/src/programmers/TypedQueryRouteProgrammer.ts +107 -107
  36. package/src/programmers/TypedRouteProgrammer.ts +103 -103
  37. package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +74 -74
  38. package/src/programmers/http/HttpIsQuerifyProgrammer.ts +77 -77
  39. package/src/programmers/http/HttpQuerifyProgrammer.ts +110 -110
  40. package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +78 -78
  41. package/src/programmers/internal/CoreMetadataUtil.ts +21 -21
  42. package/src/transform.ts +35 -35
  43. package/src/transformers/FileTransformer.ts +109 -109
  44. package/src/transformers/MethodTransformer.ts +103 -103
  45. package/src/transformers/ParameterDecoratorTransformer.ts +143 -143
  46. package/src/transformers/TypedRouteTransformer.ts +85 -85
  47. package/src/transformers/WebSocketRouteTransformer.ts +120 -120
@@ -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", "src", "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", "src", "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,85 +1,85 @@
1
- import path from "path";
2
- import ts from "typescript";
3
-
4
- import { INestiaTransformContext } from "../options/INestiaTransformProject";
5
- import { TypedQueryRouteProgrammer } from "../programmers/TypedQueryRouteProgrammer";
6
- import { TypedRouteProgrammer } from "../programmers/TypedRouteProgrammer";
7
-
8
- export namespace TypedRouteTransformer {
9
- export const transform = (props: {
10
- context: INestiaTransformContext;
11
- decorator: ts.Decorator;
12
- type: ts.Type;
13
- }): ts.Decorator => {
14
- if (!ts.isCallExpression(props.decorator.expression))
15
- return props.decorator;
16
-
17
- // CHECK SIGNATURE
18
- const signature: ts.Signature | undefined =
19
- props.context.checker.getResolvedSignature(props.decorator.expression);
20
- if (!signature || !signature.declaration) return props.decorator;
21
-
22
- // CHECK TO BE TRANSFORMED
23
- const modulo = (() => {
24
- // CHECK FILENAME
25
- const location: string = path.resolve(
26
- signature.declaration.getSourceFile().fileName,
27
- );
28
- if (LIB_PATHS.every((str) => location.indexOf(str) === -1)) return null;
29
-
30
- // CHECK DUPLICATE BOOSTER
31
- if (props.decorator.expression.arguments.length >= 2) return false;
32
- else if (props.decorator.expression.arguments.length === 1) {
33
- const last: ts.Expression =
34
- props.decorator.expression.arguments[
35
- props.decorator.expression.arguments.length - 1
36
- ]!;
37
- const type: ts.Type = props.context.checker.getTypeAtLocation(last);
38
- if (isObject(props.context.checker)(type)) return false;
39
- }
40
- return location.split(path.sep).at(-1)?.split(".")[0] === "TypedQuery"
41
- ? "TypedQuery"
42
- : "TypedRoute";
43
- })();
44
- if (modulo === null) return props.decorator;
45
-
46
- // CHECK TYPE NODE
47
- const typeNode: ts.TypeNode | undefined =
48
- props.context.checker.typeToTypeNode(props.type, undefined, undefined);
49
- if (typeNode === undefined) return props.decorator;
50
-
51
- // DO TRANSFORM
52
- return ts.factory.createDecorator(
53
- ts.factory.updateCallExpression(
54
- props.decorator.expression,
55
- props.decorator.expression.expression,
56
- props.decorator.expression.typeArguments,
57
- [
58
- ...props.decorator.expression.arguments,
59
- (modulo === "TypedQuery"
60
- ? TypedQueryRouteProgrammer
61
- : TypedRouteProgrammer
62
- ).generate({
63
- context: props.context,
64
- type: props.type,
65
- modulo: props.decorator.expression.expression,
66
- }),
67
- ],
68
- ),
69
- );
70
- };
71
-
72
- const isObject =
73
- (checker: ts.TypeChecker) =>
74
- (type: ts.Type): boolean =>
75
- (type.getFlags() & ts.TypeFlags.Object) !== 0 &&
76
- !(checker as any).isTupleType(type) &&
77
- !(checker as any).isArrayType(type) &&
78
- !(checker as any).isArrayLikeType(type);
79
-
80
- const CLASSES: string[] = ["EncryptedRoute", "TypedRoute", "TypedQuery"];
81
- const LIB_PATHS: string[] = CLASSES.map((cla) => [
82
- path.join("@nestia", "core", "lib", "decorators", `${cla}.d.ts`),
83
- path.join("packages", "core", "src", "decorators", `${cla}.ts`),
84
- ]).flat();
85
- }
1
+ import path from "path";
2
+ import ts from "typescript";
3
+
4
+ import { INestiaTransformContext } from "../options/INestiaTransformProject";
5
+ import { TypedQueryRouteProgrammer } from "../programmers/TypedQueryRouteProgrammer";
6
+ import { TypedRouteProgrammer } from "../programmers/TypedRouteProgrammer";
7
+
8
+ export namespace TypedRouteTransformer {
9
+ export const transform = (props: {
10
+ context: INestiaTransformContext;
11
+ decorator: ts.Decorator;
12
+ type: ts.Type;
13
+ }): ts.Decorator => {
14
+ if (!ts.isCallExpression(props.decorator.expression))
15
+ return props.decorator;
16
+
17
+ // CHECK SIGNATURE
18
+ const signature: ts.Signature | undefined =
19
+ props.context.checker.getResolvedSignature(props.decorator.expression);
20
+ if (!signature || !signature.declaration) return props.decorator;
21
+
22
+ // CHECK TO BE TRANSFORMED
23
+ const modulo = (() => {
24
+ // CHECK FILENAME
25
+ const location: string = path.resolve(
26
+ signature.declaration.getSourceFile().fileName,
27
+ );
28
+ if (LIB_PATHS.every((str) => location.indexOf(str) === -1)) return null;
29
+
30
+ // CHECK DUPLICATE BOOSTER
31
+ if (props.decorator.expression.arguments.length >= 2) return false;
32
+ else if (props.decorator.expression.arguments.length === 1) {
33
+ const last: ts.Expression =
34
+ props.decorator.expression.arguments[
35
+ props.decorator.expression.arguments.length - 1
36
+ ]!;
37
+ const type: ts.Type = props.context.checker.getTypeAtLocation(last);
38
+ if (isObject(props.context.checker)(type)) return false;
39
+ }
40
+ return location.split(path.sep).at(-1)?.split(".")[0] === "TypedQuery"
41
+ ? "TypedQuery"
42
+ : "TypedRoute";
43
+ })();
44
+ if (modulo === null) return props.decorator;
45
+
46
+ // CHECK TYPE NODE
47
+ const typeNode: ts.TypeNode | undefined =
48
+ props.context.checker.typeToTypeNode(props.type, undefined, undefined);
49
+ if (typeNode === undefined) return props.decorator;
50
+
51
+ // DO TRANSFORM
52
+ return ts.factory.createDecorator(
53
+ ts.factory.updateCallExpression(
54
+ props.decorator.expression,
55
+ props.decorator.expression.expression,
56
+ props.decorator.expression.typeArguments,
57
+ [
58
+ ...props.decorator.expression.arguments,
59
+ (modulo === "TypedQuery"
60
+ ? TypedQueryRouteProgrammer
61
+ : TypedRouteProgrammer
62
+ ).generate({
63
+ context: props.context,
64
+ type: props.type,
65
+ modulo: props.decorator.expression.expression,
66
+ }),
67
+ ],
68
+ ),
69
+ );
70
+ };
71
+
72
+ const isObject =
73
+ (checker: ts.TypeChecker) =>
74
+ (type: ts.Type): boolean =>
75
+ (type.getFlags() & ts.TypeFlags.Object) !== 0 &&
76
+ !(checker as any).isTupleType(type) &&
77
+ !(checker as any).isArrayType(type) &&
78
+ !(checker as any).isArrayLikeType(type);
79
+
80
+ const CLASSES: string[] = ["EncryptedRoute", "TypedRoute", "TypedQuery"];
81
+ const LIB_PATHS: string[] = CLASSES.map((cla) => [
82
+ path.join("@nestia", "core", "lib", "decorators", `${cla}.d.ts`),
83
+ path.join("packages", "core", "src", "decorators", `${cla}.ts`),
84
+ ]).flat();
85
+ }