@nestia/core 3.17.0 → 4.0.0-dev.20241010-2
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 +0 -1
- package/lib/options/INestiaTransformProject.d.ts +2 -2
- package/lib/programmers/PlainBodyProgrammer.d.ts +6 -2
- package/lib/programmers/PlainBodyProgrammer.js +31 -13
- package/lib/programmers/PlainBodyProgrammer.js.map +1 -1
- package/lib/programmers/TypedBodyProgrammer.d.ts +6 -2
- package/lib/programmers/TypedBodyProgrammer.js +32 -13
- package/lib/programmers/TypedBodyProgrammer.js.map +1 -1
- package/lib/programmers/TypedFormDataBodyProgrammer.d.ts +6 -2
- package/lib/programmers/TypedFormDataBodyProgrammer.js +30 -17
- package/lib/programmers/TypedFormDataBodyProgrammer.js.map +1 -1
- package/lib/programmers/TypedHeadersProgrammer.d.ts +6 -2
- package/lib/programmers/TypedHeadersProgrammer.js +12 -7
- package/lib/programmers/TypedHeadersProgrammer.js.map +1 -1
- package/lib/programmers/TypedParamProgrammer.d.ts +7 -2
- package/lib/programmers/TypedParamProgrammer.js +12 -7
- package/lib/programmers/TypedParamProgrammer.js.map +1 -1
- package/lib/programmers/TypedQueryBodyProgrammer.d.ts +6 -2
- package/lib/programmers/TypedQueryBodyProgrammer.js +12 -7
- package/lib/programmers/TypedQueryBodyProgrammer.js.map +1 -1
- package/lib/programmers/TypedQueryProgrammer.d.ts +6 -2
- package/lib/programmers/TypedQueryProgrammer.js +13 -7
- package/lib/programmers/TypedQueryProgrammer.js.map +1 -1
- package/lib/programmers/TypedQueryRouteProgrammer.d.ts +6 -2
- package/lib/programmers/TypedQueryRouteProgrammer.js +10 -6
- package/lib/programmers/TypedQueryRouteProgrammer.js.map +1 -1
- package/lib/programmers/TypedRouteProgrammer.d.ts +6 -2
- package/lib/programmers/TypedRouteProgrammer.js +14 -9
- package/lib/programmers/TypedRouteProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpAssertQuerifyProgrammer.d.ts +6 -2
- package/lib/programmers/http/HttpAssertQuerifyProgrammer.js +22 -3
- package/lib/programmers/http/HttpAssertQuerifyProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpIsQuerifyProgrammer.d.ts +6 -2
- package/lib/programmers/http/HttpIsQuerifyProgrammer.js +21 -3
- package/lib/programmers/http/HttpIsQuerifyProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpQuerifyProgrammer.d.ts +6 -2
- package/lib/programmers/http/HttpQuerifyProgrammer.js +27 -15
- package/lib/programmers/http/HttpQuerifyProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpValidateQuerifyProgrammer.d.ts +6 -2
- package/lib/programmers/http/HttpValidateQuerifyProgrammer.js +25 -4
- package/lib/programmers/http/HttpValidateQuerifyProgrammer.js.map +1 -1
- package/lib/transform.d.ts +2 -2
- package/lib/transform.js.map +1 -1
- package/lib/transformers/FileTransformer.d.ts +2 -2
- package/lib/transformers/FileTransformer.js +24 -10
- package/lib/transformers/FileTransformer.js.map +1 -1
- package/lib/transformers/MethodTransformer.d.ts +5 -2
- package/lib/transformers/MethodTransformer.js +21 -14
- package/lib/transformers/MethodTransformer.js.map +1 -1
- package/lib/transformers/NodeTransformer.d.ts +5 -2
- package/lib/transformers/NodeTransformer.js +11 -5
- package/lib/transformers/NodeTransformer.js.map +1 -1
- package/lib/transformers/ParameterDecoratorTransformer.d.ts +6 -2
- package/lib/transformers/ParameterDecoratorTransformer.js +49 -40
- package/lib/transformers/ParameterDecoratorTransformer.js.map +1 -1
- package/lib/transformers/ParameterTransformer.d.ts +5 -2
- package/lib/transformers/ParameterTransformer.js +17 -9
- package/lib/transformers/ParameterTransformer.js.map +1 -1
- package/lib/transformers/TypedRouteTransformer.d.ts +6 -2
- package/lib/transformers/TypedRouteTransformer.js +20 -16
- package/lib/transformers/TypedRouteTransformer.js.map +1 -1
- package/lib/transformers/WebSocketRouteTransformer.d.ts +6 -2
- package/lib/transformers/WebSocketRouteTransformer.js +11 -11
- package/lib/transformers/WebSocketRouteTransformer.js.map +1 -1
- package/package.json +5 -5
- package/src/options/INestiaTransformProject.ts +3 -2
- package/src/programmers/PlainBodyProgrammer.ts +32 -13
- package/src/programmers/TypedBodyProgrammer.ts +106 -82
- package/src/programmers/TypedFormDataBodyProgrammer.ts +87 -77
- package/src/programmers/TypedHeadersProgrammer.ts +48 -41
- package/src/programmers/TypedParamProgrammer.ts +21 -15
- package/src/programmers/TypedQueryBodyProgrammer.ts +48 -41
- package/src/programmers/TypedQueryProgrammer.ts +50 -45
- package/src/programmers/TypedQueryRouteProgrammer.ts +44 -39
- package/src/programmers/TypedRouteProgrammer.ts +63 -61
- package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +54 -40
- package/src/programmers/http/HttpIsQuerifyProgrammer.ts +54 -41
- package/src/programmers/http/HttpQuerifyProgrammer.ts +60 -48
- package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +54 -41
- package/src/transform.ts +2 -2
- package/src/transformers/FileTransformer.ts +68 -46
- package/src/transformers/MethodTransformer.ts +56 -51
- package/src/transformers/NodeTransformer.ts +16 -9
- package/src/transformers/ParameterDecoratorTransformer.ts +100 -91
- package/src/transformers/ParameterTransformer.ts +47 -38
- package/src/transformers/TypedRouteTransformer.ts +58 -55
- package/src/transformers/WebSocketRouteTransformer.ts +81 -78
|
@@ -2,61 +2,74 @@ import ts from "typescript";
|
|
|
2
2
|
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
|
3
3
|
import { StatementFactory } from "typia/lib/factories/StatementFactory";
|
|
4
4
|
import { IsProgrammer } from "typia/lib/programmers/IsProgrammer";
|
|
5
|
-
import {
|
|
5
|
+
import { ITypiaContext } from "typia/lib/transformers/ITypiaContext";
|
|
6
6
|
|
|
7
7
|
import { HttpQuerifyProgrammer } from "./HttpQuerifyProgrammer";
|
|
8
8
|
|
|
9
9
|
export namespace HttpIsQuerifyProgrammer {
|
|
10
|
-
export const write =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
10
|
+
export const write = (props: {
|
|
11
|
+
context: ITypiaContext;
|
|
12
|
+
modulo: ts.LeftHandSideExpression;
|
|
13
|
+
type: ts.Type;
|
|
14
|
+
}): ts.ArrowFunction =>
|
|
15
|
+
ts.factory.createArrowFunction(
|
|
16
|
+
undefined,
|
|
17
|
+
undefined,
|
|
18
|
+
[IdentifierFactory.parameter("input")],
|
|
19
|
+
undefined,
|
|
20
|
+
undefined,
|
|
21
|
+
ts.factory.createBlock([
|
|
22
|
+
StatementFactory.constant({
|
|
23
|
+
name: "is",
|
|
24
|
+
value: IsProgrammer.write({
|
|
25
|
+
config: {
|
|
26
|
+
equals: false,
|
|
27
|
+
},
|
|
28
|
+
context: {
|
|
29
|
+
...props.context,
|
|
25
30
|
options: {
|
|
26
|
-
...
|
|
31
|
+
...props.context.options,
|
|
27
32
|
functional: false,
|
|
28
33
|
numeric: false,
|
|
29
34
|
},
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
},
|
|
36
|
+
modulo: props.modulo,
|
|
37
|
+
type: props.type,
|
|
38
|
+
name: undefined,
|
|
39
|
+
}),
|
|
40
|
+
}),
|
|
41
|
+
StatementFactory.constant({
|
|
42
|
+
name: "stringify",
|
|
43
|
+
value: HttpQuerifyProgrammer.write({
|
|
44
|
+
context: {
|
|
45
|
+
...props.context,
|
|
36
46
|
options: {
|
|
37
|
-
...
|
|
47
|
+
...props.context.options,
|
|
38
48
|
functional: false,
|
|
39
49
|
numeric: false,
|
|
40
50
|
},
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
),
|
|
51
|
+
},
|
|
52
|
+
modulo: props.modulo,
|
|
53
|
+
type: props.type,
|
|
54
|
+
}),
|
|
55
|
+
}),
|
|
56
|
+
ts.factory.createReturnStatement(
|
|
57
|
+
ts.factory.createConditionalExpression(
|
|
58
|
+
ts.factory.createCallExpression(
|
|
59
|
+
ts.factory.createIdentifier("is"),
|
|
50
60
|
undefined,
|
|
51
|
-
ts.factory.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
),
|
|
61
|
+
[ts.factory.createIdentifier("input")],
|
|
62
|
+
),
|
|
63
|
+
undefined,
|
|
64
|
+
ts.factory.createCallExpression(
|
|
65
|
+
ts.factory.createIdentifier("stringify"),
|
|
56
66
|
undefined,
|
|
57
|
-
ts.factory.
|
|
67
|
+
[ts.factory.createIdentifier("input")],
|
|
58
68
|
),
|
|
69
|
+
undefined,
|
|
70
|
+
ts.factory.createNull(),
|
|
59
71
|
),
|
|
60
|
-
|
|
61
|
-
)
|
|
72
|
+
),
|
|
73
|
+
]),
|
|
74
|
+
);
|
|
62
75
|
}
|
|
@@ -3,63 +3,73 @@ import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
|
|
3
3
|
import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
|
|
4
4
|
import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
|
|
5
5
|
import { StatementFactory } from "typia/lib/factories/StatementFactory";
|
|
6
|
-
import {
|
|
6
|
+
import { FunctionProgrammer } from "typia/lib/programmers/helpers/FunctionProgrammer";
|
|
7
7
|
import { HttpQueryProgrammer } from "typia/lib/programmers/http/HttpQueryProgrammer";
|
|
8
8
|
import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
9
9
|
import { MetadataObject } from "typia/lib/schemas/metadata/MetadataObject";
|
|
10
|
-
import {
|
|
10
|
+
import { ITypiaContext } from "typia/lib/transformers/ITypiaContext";
|
|
11
11
|
import { TransformerError } from "typia/lib/transformers/TransformerError";
|
|
12
12
|
|
|
13
13
|
export namespace HttpQuerifyProgrammer {
|
|
14
|
-
export const write =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
export const write = (props: {
|
|
15
|
+
context: ITypiaContext;
|
|
16
|
+
modulo: ts.LeftHandSideExpression;
|
|
17
|
+
type: ts.Type;
|
|
18
|
+
}): ts.ArrowFunction => {
|
|
19
|
+
// GET OBJECT TYPE
|
|
20
|
+
const functor: FunctionProgrammer = new FunctionProgrammer(
|
|
21
|
+
props.modulo.getText(),
|
|
22
|
+
);
|
|
23
|
+
const collection: MetadataCollection = new MetadataCollection();
|
|
24
|
+
const result = MetadataFactory.analyze({
|
|
25
|
+
checker: props.context.checker,
|
|
26
|
+
transformer: props.context.transformer,
|
|
27
|
+
options: {
|
|
22
28
|
escape: false,
|
|
23
29
|
constant: true,
|
|
24
30
|
absorb: true,
|
|
25
31
|
validate: HttpQueryProgrammer.validate,
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
},
|
|
33
|
+
type: props.type,
|
|
34
|
+
collection,
|
|
35
|
+
});
|
|
36
|
+
if (result.success === false)
|
|
37
|
+
throw TransformerError.from({
|
|
38
|
+
code: `nestia.core.TypedQuery.${functor.method}`,
|
|
39
|
+
errors: result.errors,
|
|
40
|
+
});
|
|
31
41
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
),
|
|
49
|
-
),
|
|
50
|
-
...object.properties.map((p) =>
|
|
51
|
-
ts.factory.createExpressionStatement(
|
|
52
|
-
decode(p.key.constants[0]!.values[0].value as string)(p.value),
|
|
53
|
-
),
|
|
42
|
+
const object: MetadataObject = result.data.objects[0]!;
|
|
43
|
+
return ts.factory.createArrowFunction(
|
|
44
|
+
undefined,
|
|
45
|
+
undefined,
|
|
46
|
+
[IdentifierFactory.parameter("input")],
|
|
47
|
+
undefined,
|
|
48
|
+
undefined,
|
|
49
|
+
ts.factory.createBlock(
|
|
50
|
+
[
|
|
51
|
+
...functor.declare(),
|
|
52
|
+
StatementFactory.constant({
|
|
53
|
+
name: "output",
|
|
54
|
+
value: ts.factory.createNewExpression(
|
|
55
|
+
ts.factory.createIdentifier("URLSearchParams"),
|
|
56
|
+
undefined,
|
|
57
|
+
[],
|
|
54
58
|
),
|
|
55
|
-
|
|
56
|
-
|
|
59
|
+
}),
|
|
60
|
+
...object.properties.map((p) =>
|
|
61
|
+
ts.factory.createExpressionStatement(
|
|
62
|
+
decode(p.key.constants[0]!.values[0].value as string)(p.value),
|
|
57
63
|
),
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
),
|
|
65
|
+
ts.factory.createReturnStatement(
|
|
66
|
+
ts.factory.createIdentifier("output"),
|
|
67
|
+
),
|
|
68
|
+
],
|
|
69
|
+
true,
|
|
70
|
+
),
|
|
71
|
+
);
|
|
72
|
+
};
|
|
63
73
|
|
|
64
74
|
const decode =
|
|
65
75
|
(key: string) =>
|
|
@@ -67,10 +77,12 @@ export namespace HttpQuerifyProgrammer {
|
|
|
67
77
|
!!value.arrays.length
|
|
68
78
|
? ts.factory.createCallExpression(
|
|
69
79
|
IdentifierFactory.access(
|
|
70
|
-
IdentifierFactory.access(
|
|
80
|
+
IdentifierFactory.access(
|
|
81
|
+
ts.factory.createIdentifier("input"),
|
|
71
82
|
key,
|
|
72
83
|
),
|
|
73
|
-
|
|
84
|
+
"forEach",
|
|
85
|
+
),
|
|
74
86
|
undefined,
|
|
75
87
|
[
|
|
76
88
|
ts.factory.createArrowFunction(
|
|
@@ -84,12 +96,12 @@ export namespace HttpQuerifyProgrammer {
|
|
|
84
96
|
],
|
|
85
97
|
)
|
|
86
98
|
: append(key)(
|
|
87
|
-
IdentifierFactory.access(ts.factory.createIdentifier("input")
|
|
99
|
+
IdentifierFactory.access(ts.factory.createIdentifier("input"), key),
|
|
88
100
|
);
|
|
89
101
|
|
|
90
102
|
const append = (key: string) => (elem: ts.Expression) =>
|
|
91
103
|
ts.factory.createCallExpression(
|
|
92
|
-
IdentifierFactory.access(ts.factory.createIdentifier("output")
|
|
104
|
+
IdentifierFactory.access(ts.factory.createIdentifier("output"), "append"),
|
|
93
105
|
undefined,
|
|
94
106
|
[ts.factory.createStringLiteral(key), elem],
|
|
95
107
|
);
|
|
@@ -2,62 +2,75 @@ import ts from "typescript";
|
|
|
2
2
|
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
|
3
3
|
import { StatementFactory } from "typia/lib/factories/StatementFactory";
|
|
4
4
|
import { ValidateProgrammer } from "typia/lib/programmers/ValidateProgrammer";
|
|
5
|
-
import {
|
|
5
|
+
import { ITypiaContext } from "typia/lib/transformers/ITypiaContext";
|
|
6
6
|
|
|
7
7
|
import { HttpQuerifyProgrammer } from "./HttpQuerifyProgrammer";
|
|
8
8
|
|
|
9
9
|
export namespace HttpValidateQuerifyProgrammer {
|
|
10
|
-
export const write =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
10
|
+
export const write = (props: {
|
|
11
|
+
context: ITypiaContext;
|
|
12
|
+
modulo: ts.LeftHandSideExpression;
|
|
13
|
+
type: ts.Type;
|
|
14
|
+
}): ts.ArrowFunction =>
|
|
15
|
+
ts.factory.createArrowFunction(
|
|
16
|
+
undefined,
|
|
17
|
+
undefined,
|
|
18
|
+
[IdentifierFactory.parameter("input")],
|
|
19
|
+
undefined,
|
|
20
|
+
undefined,
|
|
21
|
+
ts.factory.createBlock([
|
|
22
|
+
StatementFactory.constant({
|
|
23
|
+
name: "validate",
|
|
24
|
+
value: ValidateProgrammer.write({
|
|
25
|
+
config: {
|
|
26
|
+
equals: false,
|
|
27
|
+
},
|
|
28
|
+
context: {
|
|
29
|
+
...props.context,
|
|
25
30
|
options: {
|
|
26
|
-
...
|
|
31
|
+
...props.context.options,
|
|
27
32
|
functional: false,
|
|
28
33
|
numeric: true,
|
|
29
34
|
},
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
},
|
|
36
|
+
modulo: props.modulo,
|
|
37
|
+
type: props.type,
|
|
38
|
+
name: undefined,
|
|
39
|
+
}),
|
|
40
|
+
}),
|
|
41
|
+
StatementFactory.constant({
|
|
42
|
+
name: "query",
|
|
43
|
+
value: HttpQuerifyProgrammer.write({
|
|
44
|
+
context: {
|
|
45
|
+
...props.context,
|
|
36
46
|
options: {
|
|
37
|
-
...
|
|
47
|
+
...props.context.options,
|
|
38
48
|
functional: false,
|
|
39
49
|
numeric: false,
|
|
40
50
|
},
|
|
41
|
-
}
|
|
51
|
+
},
|
|
52
|
+
modulo: props.modulo,
|
|
53
|
+
type: props.type,
|
|
54
|
+
}),
|
|
55
|
+
}),
|
|
56
|
+
StatementFactory.constant({
|
|
57
|
+
name: "output",
|
|
58
|
+
value: ts.factory.createCallExpression(
|
|
59
|
+
ts.factory.createIdentifier("query"),
|
|
60
|
+
undefined,
|
|
61
|
+
[ts.factory.createIdentifier("input")],
|
|
42
62
|
),
|
|
43
|
-
|
|
44
|
-
|
|
63
|
+
}),
|
|
64
|
+
ts.factory.createReturnStatement(
|
|
65
|
+
ts.factory.createAsExpression(
|
|
45
66
|
ts.factory.createCallExpression(
|
|
46
|
-
ts.factory.createIdentifier("
|
|
67
|
+
ts.factory.createIdentifier("validate"),
|
|
47
68
|
undefined,
|
|
48
|
-
[ts.factory.createIdentifier("
|
|
49
|
-
),
|
|
50
|
-
),
|
|
51
|
-
ts.factory.createReturnStatement(
|
|
52
|
-
ts.factory.createAsExpression(
|
|
53
|
-
ts.factory.createCallExpression(
|
|
54
|
-
ts.factory.createIdentifier("validate"),
|
|
55
|
-
undefined,
|
|
56
|
-
[ts.factory.createIdentifier("output")],
|
|
57
|
-
),
|
|
58
|
-
ts.factory.createTypeReferenceNode("any"),
|
|
69
|
+
[ts.factory.createIdentifier("output")],
|
|
59
70
|
),
|
|
71
|
+
ts.factory.createTypeReferenceNode("any"),
|
|
60
72
|
),
|
|
61
|
-
|
|
62
|
-
)
|
|
73
|
+
),
|
|
74
|
+
]),
|
|
75
|
+
);
|
|
63
76
|
}
|
package/src/transform.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
|
-
import {
|
|
2
|
+
import { ITypiaContext } from "typia/lib/transformers/ITypiaContext";
|
|
3
3
|
|
|
4
4
|
import { INestiaTransformOptions } from "./options/INestiaTransformOptions";
|
|
5
5
|
import { FileTransformer } from "./transformers/FileTransformer";
|
|
@@ -7,7 +7,7 @@ import { FileTransformer } from "./transformers/FileTransformer";
|
|
|
7
7
|
export const transform = (
|
|
8
8
|
program: ts.Program,
|
|
9
9
|
options: INestiaTransformOptions | undefined,
|
|
10
|
-
extras:
|
|
10
|
+
extras: ITypiaContext["extras"],
|
|
11
11
|
): ts.TransformerFactory<ts.SourceFile> => {
|
|
12
12
|
const compilerOptions: ts.CompilerOptions = program.getCompilerOptions();
|
|
13
13
|
const strict: boolean =
|
|
@@ -1,61 +1,83 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
|
+
import { ImportProgrammer } from "typia/lib/programmers/ImportProgrammer";
|
|
2
3
|
import { TransformerError } from "typia/lib/transformers/TransformerError";
|
|
3
4
|
|
|
4
|
-
import {
|
|
5
|
+
import { INestiaTransformContext } from "../options/INestiaTransformProject";
|
|
5
6
|
import { NodeTransformer } from "./NodeTransformer";
|
|
6
7
|
|
|
7
8
|
export namespace FileTransformer {
|
|
8
9
|
export const transform =
|
|
9
|
-
(
|
|
10
|
-
(
|
|
11
|
-
(file: ts.SourceFile): ts.SourceFile =>
|
|
12
|
-
file.isDeclarationFile
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
(context: Omit<INestiaTransformContext, "importer" | "transformer">) =>
|
|
11
|
+
(transformer: ts.TransformationContext) =>
|
|
12
|
+
(file: ts.SourceFile): ts.SourceFile => {
|
|
13
|
+
if (file.isDeclarationFile) return file;
|
|
14
|
+
const importer = new ImportProgrammer();
|
|
15
|
+
file = ts.visitEachChild(
|
|
16
|
+
file,
|
|
17
|
+
(node) =>
|
|
18
|
+
iterate_node({
|
|
19
|
+
context: {
|
|
20
|
+
...context,
|
|
21
|
+
transformer,
|
|
22
|
+
importer,
|
|
23
|
+
},
|
|
15
24
|
file,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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,
|
|
25
|
+
node,
|
|
26
|
+
}),
|
|
27
|
+
transformer,
|
|
28
|
+
);
|
|
29
|
+
return ts.factory.updateSourceFile(
|
|
30
|
+
file,
|
|
31
|
+
[...importer.toStatements(), ...file.statements],
|
|
32
|
+
false,
|
|
33
|
+
file.referencedFiles,
|
|
34
|
+
file.typeReferenceDirectives,
|
|
35
|
+
file.hasNoDefaultLib,
|
|
36
|
+
file.libReferenceDirectives,
|
|
33
37
|
);
|
|
38
|
+
};
|
|
34
39
|
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
const iterate_node = (props: {
|
|
41
|
+
context: INestiaTransformContext;
|
|
42
|
+
file: ts.SourceFile;
|
|
43
|
+
node: ts.Node;
|
|
44
|
+
}): ts.Node =>
|
|
45
|
+
ts.visitEachChild(
|
|
46
|
+
try_transform_node(props) ?? props.node,
|
|
47
|
+
(child) =>
|
|
48
|
+
iterate_node({
|
|
49
|
+
context: props.context,
|
|
50
|
+
file: props.file,
|
|
51
|
+
node: child,
|
|
52
|
+
}),
|
|
53
|
+
props.context.transformer,
|
|
54
|
+
);
|
|
44
55
|
|
|
45
|
-
|
|
46
|
-
|
|
56
|
+
const try_transform_node = (props: {
|
|
57
|
+
context: INestiaTransformContext;
|
|
58
|
+
file: ts.SourceFile;
|
|
59
|
+
node: ts.Node;
|
|
60
|
+
}): ts.Node | null => {
|
|
61
|
+
try {
|
|
62
|
+
return NodeTransformer.transform(props);
|
|
63
|
+
} catch (exp) {
|
|
64
|
+
// ONLY ACCEPT TRANSFORMER-ERROR
|
|
65
|
+
if (!isTransformerError(exp)) throw exp;
|
|
47
66
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
67
|
+
// AVOID SPECIAL BUG OF TYPESCRIPT COMPILER API
|
|
68
|
+
(props.node as any).parent ??= props.file;
|
|
69
|
+
|
|
70
|
+
// REPORT DIAGNOSTIC
|
|
71
|
+
const diagnostic = (ts as any).createDiagnosticForNode(props.node, {
|
|
72
|
+
key: exp.code,
|
|
73
|
+
category: ts.DiagnosticCategory.Error,
|
|
74
|
+
message: exp.message,
|
|
75
|
+
code: `(${exp.code})` as any,
|
|
76
|
+
});
|
|
77
|
+
props.context.extras.addDiagnostic(diagnostic);
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
59
81
|
}
|
|
60
82
|
|
|
61
83
|
const isTransformerError = (error: any): error is TransformerError =>
|
|
@@ -1,64 +1,69 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { INestiaTransformContext } from "../options/INestiaTransformProject";
|
|
4
4
|
import { TypedRouteTransformer } from "./TypedRouteTransformer";
|
|
5
5
|
import { WebSocketRouteTransformer } from "./WebSocketRouteTransformer";
|
|
6
6
|
|
|
7
7
|
export namespace MethodTransformer {
|
|
8
|
-
export const transform =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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;
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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);
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
if (type === undefined) return props.method;
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
decorator
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
(method.modifiers || []).map((mod) =>
|
|
38
|
-
ts.isDecorator(mod) ? operator(mod) : mod,
|
|
39
|
-
),
|
|
40
|
-
method.asteriskToken,
|
|
41
|
-
method.name,
|
|
42
|
-
method.questionToken,
|
|
43
|
-
method.typeParameters,
|
|
44
|
-
method.parameters,
|
|
45
|
-
method.type,
|
|
46
|
-
method.body,
|
|
47
|
-
);
|
|
48
|
-
// eslint-disable-next-line
|
|
49
|
-
return (ts.factory.updateMethodDeclaration as any)(
|
|
50
|
-
method,
|
|
51
|
-
decorators.map(operator),
|
|
52
|
-
(method as any).modifiers,
|
|
53
|
-
method.asteriskToken,
|
|
54
|
-
method.name,
|
|
55
|
-
method.questionToken,
|
|
56
|
-
method.typeParameters,
|
|
57
|
-
method.parameters,
|
|
58
|
-
method.type,
|
|
59
|
-
method.body,
|
|
60
|
-
);
|
|
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;
|
|
61
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
|
+
};
|
|
62
67
|
}
|
|
63
68
|
|
|
64
69
|
const get_escaped_type =
|