@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.
- package/README.md +12 -9
- package/lib/decorators/DynamicModule.js +3 -3
- package/lib/decorators/DynamicModule.js.map +1 -1
- package/lib/decorators/EncryptedBody.js +14 -13
- package/lib/decorators/EncryptedBody.js.map +1 -1
- package/lib/decorators/EncryptedModule.d.ts +1 -1
- package/lib/decorators/EncryptedModule.js +45 -21
- package/lib/decorators/EncryptedModule.js.map +1 -1
- package/lib/decorators/EncryptedRoute.d.ts +5 -5
- package/lib/decorators/EncryptedRoute.js +12 -29
- package/lib/decorators/EncryptedRoute.js.map +1 -1
- package/lib/decorators/PlainBody.js +3 -0
- package/lib/decorators/PlainBody.js.map +1 -1
- package/lib/decorators/SwaggerCustomizer.d.ts +79 -0
- package/lib/decorators/SwaggerCustomizer.js +32 -0
- package/lib/decorators/SwaggerCustomizer.js.map +1 -0
- package/lib/decorators/TypedBody.js +3 -0
- package/lib/decorators/TypedBody.js.map +1 -1
- package/lib/decorators/TypedException.d.ts +0 -1
- package/lib/decorators/TypedException.js +0 -1
- package/lib/decorators/TypedException.js.map +1 -1
- package/lib/decorators/TypedFormData.d.ts +60 -0
- package/lib/decorators/TypedFormData.js +403 -0
- package/lib/decorators/TypedFormData.js.map +1 -0
- package/lib/decorators/TypedQuery.d.ts +11 -6
- package/lib/decorators/TypedQuery.js +6 -1
- package/lib/decorators/TypedQuery.js.map +1 -1
- package/lib/decorators/TypedRoute.d.ts +5 -5
- package/lib/decorators/internal/get_path_and_querify.js +3 -0
- package/lib/decorators/internal/get_path_and_querify.js.map +1 -1
- package/lib/decorators/internal/load_controller.js.map +1 -1
- package/lib/decorators/internal/validate_request_body.d.ts +1 -3
- package/lib/decorators/internal/validate_request_body.js +15 -0
- package/lib/decorators/internal/validate_request_body.js.map +1 -1
- package/lib/decorators/internal/validate_request_form_data.js +79 -0
- package/lib/decorators/internal/validate_request_form_data.js.map +1 -0
- package/lib/decorators/internal/validate_request_headers.d.ts +1 -3
- package/lib/decorators/internal/validate_request_headers.js +15 -0
- package/lib/decorators/internal/validate_request_headers.js.map +1 -1
- package/lib/decorators/internal/validate_request_query.d.ts +1 -3
- package/lib/decorators/internal/validate_request_query.js +15 -0
- package/lib/decorators/internal/validate_request_query.js.map +1 -1
- package/lib/module.d.ts +2 -0
- package/lib/module.js +2 -0
- package/lib/module.js.map +1 -1
- package/lib/options/IRequestFormDataProps.d.ts +23 -0
- package/lib/options/IRequestFormDataProps.js +3 -0
- package/lib/options/IRequestFormDataProps.js.map +1 -0
- package/lib/programmers/PlainBodyProgrammer.js +1 -1
- package/lib/programmers/PlainBodyProgrammer.js.map +1 -1
- package/lib/programmers/TypedExceptionProgrammer.js +5 -5
- package/lib/programmers/TypedExceptionProgrammer.js.map +1 -1
- package/lib/programmers/TypedFormDataBodyProgrammer.d.ts +6 -0
- package/lib/programmers/TypedFormDataBodyProgrammer.js +84 -0
- package/lib/programmers/TypedFormDataBodyProgrammer.js.map +1 -0
- package/lib/programmers/http/HttpQuerifyProgrammer.js +2 -2
- package/lib/programmers/http/HttpQuerifyProgrammer.js.map +1 -1
- package/lib/transformers/NodeTransformer.js.map +1 -1
- package/lib/transformers/ParameterDecoratorTransformer.js +7 -1
- package/lib/transformers/ParameterDecoratorTransformer.js.map +1 -1
- package/lib/transformers/TypedExceptionTransformer.js +1 -1
- package/lib/transformers/TypedExceptionTransformer.js.map +1 -1
- package/lib/transformers/TypedRouteTransformer.js +1 -1
- package/lib/transformers/TypedRouteTransformer.js.map +1 -1
- package/package.json +15 -16
- package/src/decorators/DynamicModule.ts +39 -39
- package/src/decorators/EncryptedBody.ts +105 -107
- package/src/decorators/EncryptedController.ts +38 -38
- package/src/decorators/EncryptedModule.ts +96 -79
- package/src/decorators/EncryptedRoute.ts +182 -206
- package/src/decorators/PlainBody.ts +75 -72
- package/src/decorators/SwaggerCustomizer.ts +115 -0
- package/src/decorators/TypedBody.ts +62 -59
- package/src/decorators/TypedException.ts +90 -89
- package/src/decorators/TypedFormData.ts +219 -0
- package/src/decorators/TypedHeaders.ts +69 -69
- package/src/decorators/TypedParam.ts +65 -65
- package/src/decorators/TypedQuery.ts +251 -246
- package/src/decorators/TypedRoute.ts +144 -144
- package/src/decorators/internal/EncryptedConstant.ts +4 -4
- package/src/decorators/internal/NoTransformConfigureError.ts +8 -8
- package/src/decorators/internal/get_path_and_querify.ts +106 -103
- package/src/decorators/internal/get_path_and_stringify.ts +91 -91
- package/src/decorators/internal/get_text_body.ts +20 -20
- package/src/decorators/internal/headers_to_object.ts +13 -13
- package/src/decorators/internal/load_controller.ts +51 -51
- package/src/decorators/internal/route_error.ts +45 -45
- package/src/decorators/internal/validate_request_body.ts +72 -57
- package/src/decorators/internal/validate_request_form_data.ts +75 -0
- package/src/decorators/internal/validate_request_headers.ts +83 -68
- package/src/decorators/internal/validate_request_query.ts +71 -56
- package/src/index.ts +5 -5
- package/src/module.ts +16 -14
- package/src/options/INestiaTransformOptions.ts +17 -17
- package/src/options/INestiaTransformProject.ts +7 -7
- package/src/options/IRequestBodyValidator.ts +20 -20
- package/src/options/IRequestFormDataProps.ts +27 -0
- package/src/options/IRequestHeadersValidator.ts +22 -22
- package/src/options/IRequestQueryValidator.ts +20 -20
- package/src/options/IResponseBodyQuerifier.ts +25 -25
- package/src/options/IResponseBodyStringifier.ts +25 -25
- package/src/programmers/PlainBodyProgrammer.ts +52 -52
- package/src/programmers/TypedBodyProgrammer.ts +108 -108
- package/src/programmers/TypedExceptionProgrammer.ts +71 -72
- package/src/programmers/TypedFormDataBodyProgrammer.ts +108 -0
- package/src/programmers/TypedHeadersProgrammer.ts +56 -56
- package/src/programmers/TypedParamProgrammer.ts +24 -24
- package/src/programmers/TypedQueryBodyProgrammer.ts +56 -56
- package/src/programmers/TypedQueryProgrammer.ts +56 -56
- package/src/programmers/TypedQueryRouteProgrammer.ts +51 -51
- package/src/programmers/TypedRouteProgrammer.ts +51 -51
- package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +58 -58
- package/src/programmers/http/HttpIsQuerifyProgrammer.ts +62 -62
- package/src/programmers/http/HttpQuerifyProgrammer.ts +96 -96
- package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +63 -63
- package/src/programmers/internal/CoreMetadataUtil.ts +21 -21
- package/src/transform.ts +35 -35
- package/src/transformers/FileTransformer.ts +66 -66
- package/src/transformers/MethodTransformer.ts +94 -94
- package/src/transformers/NodeTransformer.ts +16 -16
- package/src/transformers/ParameterDecoratorTransformer.ts +120 -121
- package/src/transformers/ParameterTransformer.ts +48 -48
- package/src/transformers/TypedExceptionTransformer.ts +48 -49
- package/src/transformers/TypedRouteTransformer.ts +88 -95
- package/src/typings/Creator.ts +3 -3
- package/src/utils/ExceptionManager.ts +112 -112
- package/src/utils/Singleton.ts +20 -20
- package/src/utils/SourceFinder.ts +57 -57
- package/lib/decorators/internal/get_binary_body.js +0 -66
- package/lib/decorators/internal/get_binary_body.js.map +0 -1
- package/src/decorators/internal/get_binary_body.ts +0 -18
- /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 {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
(
|
|
16
|
-
(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
undefined,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
decorator.expression
|
|
56
|
-
decorator.expression.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
+
}
|
package/src/typings/Creator.ts
CHANGED
|
@@ -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
|
+
};
|