@nestia/core 3.1.0-dev.20240426 → 3.1.0-dev.20240430
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/lib/adaptors/WebSocketAdaptor.js +15 -17
- package/lib/adaptors/WebSocketAdaptor.js.map +1 -1
- package/lib/transformers/MethodTransformer.js +7 -4
- package/lib/transformers/MethodTransformer.js.map +1 -1
- package/lib/transformers/TypedExceptionTransformer.js +2 -3
- package/lib/transformers/TypedExceptionTransformer.js.map +1 -1
- package/lib/transformers/TypedRouteTransformer.js +1 -3
- package/lib/transformers/TypedRouteTransformer.js.map +1 -1
- package/lib/transformers/WebSocketRouteTransformer.d.ts +6 -0
- package/lib/transformers/WebSocketRouteTransformer.js +72 -0
- package/lib/transformers/WebSocketRouteTransformer.js.map +1 -0
- package/package.json +4 -4
- package/src/adaptors/WebSocketAdaptor.ts +19 -17
- package/src/decorators/DynamicModule.ts +39 -39
- package/src/decorators/EncryptedBody.ts +105 -105
- package/src/decorators/EncryptedController.ts +38 -38
- package/src/decorators/EncryptedModule.ts +96 -96
- package/src/decorators/EncryptedRoute.ts +182 -182
- package/src/decorators/PlainBody.ts +75 -75
- package/src/decorators/TypedBody.ts +62 -62
- package/src/decorators/TypedException.ts +90 -90
- package/src/decorators/TypedFormData.ts +219 -219
- package/src/decorators/TypedHeaders.ts +69 -69
- package/src/decorators/TypedParam.ts +64 -64
- 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 -106
- 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/index.ts +5 -5
- 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 -27
- 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 -71
- 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/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 +97 -94
- package/src/transformers/NodeTransformer.ts +16 -16
- package/src/transformers/ParameterTransformer.ts +48 -48
- package/src/transformers/TypedExceptionTransformer.ts +44 -48
- package/src/transformers/TypedRouteTransformer.ts +81 -88
- package/src/transformers/WebSocketRouteTransformer.ts +103 -0
- 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
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
import { TransformerError } from "typia/lib/transformers/TransformerError";
|
|
3
|
-
|
|
4
|
-
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
5
|
-
import { NodeTransformer } from "./NodeTransformer";
|
|
6
|
-
|
|
7
|
-
export namespace FileTransformer {
|
|
8
|
-
export const transform =
|
|
9
|
-
(project: Omit<INestiaTransformProject, "context">) =>
|
|
10
|
-
(context: ts.TransformationContext) =>
|
|
11
|
-
(file: ts.SourceFile): ts.SourceFile =>
|
|
12
|
-
file.isDeclarationFile
|
|
13
|
-
? file
|
|
14
|
-
: ts.visitEachChild(
|
|
15
|
-
file,
|
|
16
|
-
(node) =>
|
|
17
|
-
iterate_node({
|
|
18
|
-
...project,
|
|
19
|
-
context,
|
|
20
|
-
})(context)(file)(node),
|
|
21
|
-
context,
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
const iterate_node =
|
|
25
|
-
(project: INestiaTransformProject) =>
|
|
26
|
-
(context: ts.TransformationContext) =>
|
|
27
|
-
(file: ts.SourceFile) =>
|
|
28
|
-
(node: ts.Node): ts.Node =>
|
|
29
|
-
ts.visitEachChild(
|
|
30
|
-
try_transform_node(project)(file)(node) ?? node,
|
|
31
|
-
(child) => iterate_node(project)(context)(file)(child),
|
|
32
|
-
context,
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
const try_transform_node =
|
|
36
|
-
(project: INestiaTransformProject) =>
|
|
37
|
-
(file: ts.SourceFile) =>
|
|
38
|
-
(node: ts.Node): ts.Node | null => {
|
|
39
|
-
try {
|
|
40
|
-
return NodeTransformer.transform(project)(node);
|
|
41
|
-
} catch (exp) {
|
|
42
|
-
// ONLY ACCEPT TRANSFORMER-ERROR
|
|
43
|
-
if (!isTransformerError(exp)) throw exp;
|
|
44
|
-
|
|
45
|
-
// AVOID SPECIAL BUG OF TYPESCRIPT COMPILER API
|
|
46
|
-
(node as any).parent ??= file;
|
|
47
|
-
|
|
48
|
-
// REPORT DIAGNOSTIC
|
|
49
|
-
const diagnostic = ts.createDiagnosticForNode(node, {
|
|
50
|
-
key: exp.code,
|
|
51
|
-
category: ts.DiagnosticCategory.Error,
|
|
52
|
-
message: exp.message,
|
|
53
|
-
code: `(${exp.code})` as any,
|
|
54
|
-
});
|
|
55
|
-
project.extras.addDiagnostic(diagnostic);
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const isTransformerError = (error: any): error is TransformerError =>
|
|
62
|
-
typeof error === "object" &&
|
|
63
|
-
error !== null &&
|
|
64
|
-
error.constructor.name === "TransformerError" &&
|
|
65
|
-
typeof error.code === "string" &&
|
|
66
|
-
typeof error.message === "string";
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { TransformerError } from "typia/lib/transformers/TransformerError";
|
|
3
|
+
|
|
4
|
+
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
5
|
+
import { NodeTransformer } from "./NodeTransformer";
|
|
6
|
+
|
|
7
|
+
export namespace FileTransformer {
|
|
8
|
+
export const transform =
|
|
9
|
+
(project: Omit<INestiaTransformProject, "context">) =>
|
|
10
|
+
(context: ts.TransformationContext) =>
|
|
11
|
+
(file: ts.SourceFile): ts.SourceFile =>
|
|
12
|
+
file.isDeclarationFile
|
|
13
|
+
? file
|
|
14
|
+
: ts.visitEachChild(
|
|
15
|
+
file,
|
|
16
|
+
(node) =>
|
|
17
|
+
iterate_node({
|
|
18
|
+
...project,
|
|
19
|
+
context,
|
|
20
|
+
})(context)(file)(node),
|
|
21
|
+
context,
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const iterate_node =
|
|
25
|
+
(project: INestiaTransformProject) =>
|
|
26
|
+
(context: ts.TransformationContext) =>
|
|
27
|
+
(file: ts.SourceFile) =>
|
|
28
|
+
(node: ts.Node): ts.Node =>
|
|
29
|
+
ts.visitEachChild(
|
|
30
|
+
try_transform_node(project)(file)(node) ?? node,
|
|
31
|
+
(child) => iterate_node(project)(context)(file)(child),
|
|
32
|
+
context,
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const try_transform_node =
|
|
36
|
+
(project: INestiaTransformProject) =>
|
|
37
|
+
(file: ts.SourceFile) =>
|
|
38
|
+
(node: ts.Node): ts.Node | null => {
|
|
39
|
+
try {
|
|
40
|
+
return NodeTransformer.transform(project)(node);
|
|
41
|
+
} catch (exp) {
|
|
42
|
+
// ONLY ACCEPT TRANSFORMER-ERROR
|
|
43
|
+
if (!isTransformerError(exp)) throw exp;
|
|
44
|
+
|
|
45
|
+
// AVOID SPECIAL BUG OF TYPESCRIPT COMPILER API
|
|
46
|
+
(node as any).parent ??= file;
|
|
47
|
+
|
|
48
|
+
// REPORT DIAGNOSTIC
|
|
49
|
+
const diagnostic = ts.createDiagnosticForNode(node, {
|
|
50
|
+
key: exp.code,
|
|
51
|
+
category: ts.DiagnosticCategory.Error,
|
|
52
|
+
message: exp.message,
|
|
53
|
+
code: `(${exp.code})` as any,
|
|
54
|
+
});
|
|
55
|
+
project.extras.addDiagnostic(diagnostic);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const isTransformerError = (error: any): error is TransformerError =>
|
|
62
|
+
typeof error === "object" &&
|
|
63
|
+
error !== null &&
|
|
64
|
+
error.constructor.name === "TransformerError" &&
|
|
65
|
+
typeof error.code === "string" &&
|
|
66
|
+
typeof error.message === "string";
|
|
@@ -1,94 +1,97 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
4
|
-
import { TypedExceptionTransformer } from "./TypedExceptionTransformer";
|
|
5
|
-
import { TypedRouteTransformer } from "./TypedRouteTransformer";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
method.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
method.
|
|
40
|
-
method.
|
|
41
|
-
method.
|
|
42
|
-
method.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
method
|
|
50
|
-
|
|
51
|
-
method.
|
|
52
|
-
method.
|
|
53
|
-
method.
|
|
54
|
-
method.
|
|
55
|
-
method.
|
|
56
|
-
|
|
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
|
-
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
4
|
+
import { TypedExceptionTransformer } from "./TypedExceptionTransformer";
|
|
5
|
+
import { TypedRouteTransformer } from "./TypedRouteTransformer";
|
|
6
|
+
import { WebSocketRouteTransformer } from "./WebSocketRouteTransformer";
|
|
7
|
+
|
|
8
|
+
export namespace MethodTransformer {
|
|
9
|
+
export const transform =
|
|
10
|
+
(project: INestiaTransformProject) =>
|
|
11
|
+
(method: ts.MethodDeclaration): ts.MethodDeclaration => {
|
|
12
|
+
const decorators: readonly ts.Decorator[] | undefined = ts.getDecorators
|
|
13
|
+
? ts.getDecorators(method)
|
|
14
|
+
: (method as any).decorators;
|
|
15
|
+
if (!decorators?.length) return method;
|
|
16
|
+
|
|
17
|
+
const signature: ts.Signature | undefined =
|
|
18
|
+
project.checker.getSignatureFromDeclaration(method);
|
|
19
|
+
const original: ts.Type | undefined =
|
|
20
|
+
signature && project.checker.getReturnTypeOfSignature(signature);
|
|
21
|
+
const escaped: ts.Type | undefined =
|
|
22
|
+
original && get_escaped_type(project.checker)(original);
|
|
23
|
+
|
|
24
|
+
if (escaped === undefined) return method;
|
|
25
|
+
|
|
26
|
+
const operator = (decorator: ts.Decorator): ts.Decorator => {
|
|
27
|
+
decorator = TypedExceptionTransformer.transform(project)(decorator);
|
|
28
|
+
decorator =
|
|
29
|
+
TypedRouteTransformer.transform(project)(escaped)(decorator);
|
|
30
|
+
WebSocketRouteTransformer.validate(project)(decorator, method);
|
|
31
|
+
return decorator;
|
|
32
|
+
};
|
|
33
|
+
if (ts.getDecorators !== undefined)
|
|
34
|
+
return ts.factory.updateMethodDeclaration(
|
|
35
|
+
method,
|
|
36
|
+
(method.modifiers || []).map((mod) =>
|
|
37
|
+
ts.isDecorator(mod) ? operator(mod) : mod,
|
|
38
|
+
),
|
|
39
|
+
method.asteriskToken,
|
|
40
|
+
method.name,
|
|
41
|
+
method.questionToken,
|
|
42
|
+
method.typeParameters,
|
|
43
|
+
method.parameters,
|
|
44
|
+
method.type,
|
|
45
|
+
method.body,
|
|
46
|
+
);
|
|
47
|
+
// eslint-disable-next-line
|
|
48
|
+
return (ts.factory.updateMethodDeclaration as any)(
|
|
49
|
+
method,
|
|
50
|
+
decorators.map(operator),
|
|
51
|
+
(method as any).modifiers,
|
|
52
|
+
method.asteriskToken,
|
|
53
|
+
method.name,
|
|
54
|
+
method.questionToken,
|
|
55
|
+
method.typeParameters,
|
|
56
|
+
method.parameters,
|
|
57
|
+
method.type,
|
|
58
|
+
method.body,
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const get_escaped_type =
|
|
64
|
+
(checker: ts.TypeChecker) =>
|
|
65
|
+
(type: ts.Type): ts.Type => {
|
|
66
|
+
const symbol: ts.Symbol | undefined = type.getSymbol() || type.aliasSymbol;
|
|
67
|
+
return symbol && get_name(symbol) === "Promise"
|
|
68
|
+
? escape_promise(checker)(type)
|
|
69
|
+
: type;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const escape_promise =
|
|
73
|
+
(checker: ts.TypeChecker) =>
|
|
74
|
+
(type: ts.Type): ts.Type => {
|
|
75
|
+
const generic: readonly ts.Type[] = checker.getTypeArguments(
|
|
76
|
+
type as ts.TypeReference,
|
|
77
|
+
);
|
|
78
|
+
if (generic.length !== 1)
|
|
79
|
+
throw new Error(
|
|
80
|
+
"Error on ImportAnalyzer.analyze(): invalid promise type.",
|
|
81
|
+
);
|
|
82
|
+
return generic[0];
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const get_name = (symbol: ts.Symbol): string =>
|
|
86
|
+
explore_name(symbol.getDeclarations()![0].parent)(
|
|
87
|
+
symbol.escapedName.toString(),
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const explore_name =
|
|
91
|
+
(decl: ts.Node) =>
|
|
92
|
+
(name: string): string =>
|
|
93
|
+
ts.isModuleBlock(decl)
|
|
94
|
+
? explore_name(decl.parent.parent)(
|
|
95
|
+
`${decl.parent.name.getFullText().trim()}.${name}`,
|
|
96
|
+
)
|
|
97
|
+
: name;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
4
|
-
import { MethodTransformer } from "./MethodTransformer";
|
|
5
|
-
import { ParameterTransformer } from "./ParameterTransformer";
|
|
6
|
-
|
|
7
|
-
export namespace NodeTransformer {
|
|
8
|
-
export const transform =
|
|
9
|
-
(project: INestiaTransformProject) =>
|
|
10
|
-
(node: ts.Node): ts.Node =>
|
|
11
|
-
ts.isMethodDeclaration(node)
|
|
12
|
-
? MethodTransformer.transform(project)(node)
|
|
13
|
-
: ts.isParameter(node)
|
|
14
|
-
? ParameterTransformer.transform(project)(node)
|
|
15
|
-
: node;
|
|
16
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
4
|
+
import { MethodTransformer } from "./MethodTransformer";
|
|
5
|
+
import { ParameterTransformer } from "./ParameterTransformer";
|
|
6
|
+
|
|
7
|
+
export namespace NodeTransformer {
|
|
8
|
+
export const transform =
|
|
9
|
+
(project: INestiaTransformProject) =>
|
|
10
|
+
(node: ts.Node): ts.Node =>
|
|
11
|
+
ts.isMethodDeclaration(node)
|
|
12
|
+
? MethodTransformer.transform(project)(node)
|
|
13
|
+
: ts.isParameter(node)
|
|
14
|
+
? ParameterTransformer.transform(project)(node)
|
|
15
|
+
: node;
|
|
16
|
+
}
|
|
@@ -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,48 +1,44 @@
|
|
|
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
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const SRC_PATH = path.resolve(
|
|
46
|
-
path.join(__dirname, "..", "decorators", `TypedException.ts`),
|
|
47
|
-
);
|
|
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) return false;
|
|
25
|
+
|
|
26
|
+
// CHECK DUPLICATED
|
|
27
|
+
return decorator.expression.arguments.length !== 3;
|
|
28
|
+
})();
|
|
29
|
+
if (done === false) return decorator;
|
|
30
|
+
|
|
31
|
+
// DO TRANSFORM
|
|
32
|
+
return ts.factory.createDecorator(
|
|
33
|
+
TypedExceptionProgrammer.generate(project)(decorator.expression),
|
|
34
|
+
);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const LIB_PATH = path.join(
|
|
39
|
+
"@nestia",
|
|
40
|
+
"core",
|
|
41
|
+
"lib",
|
|
42
|
+
"decorators",
|
|
43
|
+
`TypedException.d.ts`,
|
|
44
|
+
);
|