@nestia/core 2.5.4-dev.20240204 → 2.5.5-dev.20240213
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/package.json +3 -3
- package/src/module.ts +15 -15
- package/src/programmers/PlainBodyProgrammer.ts +52 -52
- package/src/programmers/TypedExceptionProgrammer.ts +72 -72
- package/src/programmers/http/HttpQuerifyProgrammer.ts +96 -96
- package/src/transformers/ParameterDecoratorTransformer.ts +126 -126
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestia/core",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.5-dev.20240213",
|
|
4
4
|
"description": "Super-fast validation decorators of NestJS",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"homepage": "https://nestia.io",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@nestia/fetcher": "^2.5.
|
|
39
|
+
"@nestia/fetcher": "^2.5.5-dev.20240213",
|
|
40
40
|
"@nestjs/common": ">=7.0.1",
|
|
41
41
|
"@nestjs/core": ">=7.0.1",
|
|
42
42
|
"@nestjs/platform-express": ">=7.0.1",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"typia": "^5.4.5"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@nestia/fetcher": ">=2.5.
|
|
53
|
+
"@nestia/fetcher": ">=2.5.5-dev.20240213",
|
|
54
54
|
"@nestjs/common": ">=7.0.1",
|
|
55
55
|
"@nestjs/core": ">=7.0.1",
|
|
56
56
|
"@nestjs/platform-express": ">=7.0.1",
|
package/src/module.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export * from "./decorators/DynamicModule";
|
|
2
|
-
export * from "./decorators/EncryptedBody";
|
|
3
|
-
export * from "./decorators/EncryptedController";
|
|
4
|
-
export * from "./decorators/EncryptedModule";
|
|
5
|
-
export * from "./decorators/EncryptedRoute";
|
|
6
|
-
export * from "./utils/ExceptionManager";
|
|
7
|
-
export * from "./decorators/PlainBody";
|
|
8
|
-
export * from "./decorators/TypedBody";
|
|
9
|
-
export * from "./decorators/TypedException";
|
|
10
|
-
export * from "./decorators/TypedHeaders";
|
|
11
|
-
export * from "./decorators/TypedFormData";
|
|
12
|
-
export * from "./decorators/TypedParam";
|
|
13
|
-
export * from "./decorators/TypedRoute";
|
|
14
|
-
export * from "./decorators/TypedQuery";
|
|
15
|
-
export * from "./options/INestiaTransformOptions";
|
|
1
|
+
export * from "./decorators/DynamicModule";
|
|
2
|
+
export * from "./decorators/EncryptedBody";
|
|
3
|
+
export * from "./decorators/EncryptedController";
|
|
4
|
+
export * from "./decorators/EncryptedModule";
|
|
5
|
+
export * from "./decorators/EncryptedRoute";
|
|
6
|
+
export * from "./utils/ExceptionManager";
|
|
7
|
+
export * from "./decorators/PlainBody";
|
|
8
|
+
export * from "./decorators/TypedBody";
|
|
9
|
+
export * from "./decorators/TypedException";
|
|
10
|
+
export * from "./decorators/TypedHeaders";
|
|
11
|
+
export * from "./decorators/TypedFormData";
|
|
12
|
+
export * from "./decorators/TypedParam";
|
|
13
|
+
export * from "./decorators/TypedRoute";
|
|
14
|
+
export * from "./decorators/TypedQuery";
|
|
15
|
+
export * from "./options/INestiaTransformOptions";
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
|
|
3
|
-
import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
|
|
4
|
-
import { AssertProgrammer } from "typia/lib/programmers/AssertProgrammer";
|
|
5
|
-
import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
6
|
-
import { TransformerError } from "typia/lib/transformers/TransformerError";
|
|
7
|
-
|
|
8
|
-
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
9
|
-
|
|
10
|
-
export namespace PlainBodyProgrammer {
|
|
11
|
-
export const generate =
|
|
12
|
-
(project: INestiaTransformProject) =>
|
|
13
|
-
(modulo: ts.LeftHandSideExpression) =>
|
|
14
|
-
(type: ts.Type): ts.Expression => {
|
|
15
|
-
const result = MetadataFactory.analyze(project.checker)({
|
|
16
|
-
escape: false,
|
|
17
|
-
constant: true,
|
|
18
|
-
absorb: true,
|
|
19
|
-
validate,
|
|
20
|
-
})(new MetadataCollection())(type);
|
|
21
|
-
if (result.success === false)
|
|
22
|
-
throw TransformerError.from("nestia.core.TypedParam")(result.errors);
|
|
23
|
-
return AssertProgrammer.write({
|
|
24
|
-
...project,
|
|
25
|
-
options: {
|
|
26
|
-
numeric: false,
|
|
27
|
-
finite: false,
|
|
28
|
-
functional: false,
|
|
29
|
-
},
|
|
30
|
-
})(modulo)(false)(type);
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const validate = (metadata: Metadata): string[] => {
|
|
35
|
-
const errors: string[] = [];
|
|
36
|
-
const insert = (msg: string) => errors.push(msg);
|
|
37
|
-
|
|
38
|
-
const expected: number =
|
|
39
|
-
(metadata.atomics.some((a) => a.type === "string") ? 1 : 0) +
|
|
40
|
-
metadata.templates.length +
|
|
41
|
-
metadata.constants
|
|
42
|
-
.filter((c) => c.type === "string")
|
|
43
|
-
.map((c) => c.values.length)
|
|
44
|
-
.reduce((a, b) => a + b, 0);
|
|
45
|
-
if (expected === 0 || expected !== metadata.size())
|
|
46
|
-
insert(`only string type is allowed`);
|
|
47
|
-
if (metadata.isRequired() === false) insert(`do not allow undefindable type`);
|
|
48
|
-
if (metadata.nullable === true) insert(`do not allow nullable type`);
|
|
49
|
-
else if (metadata.any === true) insert(`do not allow any type`);
|
|
50
|
-
|
|
51
|
-
return errors;
|
|
52
|
-
};
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
|
|
3
|
+
import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
|
|
4
|
+
import { AssertProgrammer } from "typia/lib/programmers/AssertProgrammer";
|
|
5
|
+
import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
6
|
+
import { TransformerError } from "typia/lib/transformers/TransformerError";
|
|
7
|
+
|
|
8
|
+
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
9
|
+
|
|
10
|
+
export namespace PlainBodyProgrammer {
|
|
11
|
+
export const generate =
|
|
12
|
+
(project: INestiaTransformProject) =>
|
|
13
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
14
|
+
(type: ts.Type): ts.Expression => {
|
|
15
|
+
const result = MetadataFactory.analyze(project.checker)({
|
|
16
|
+
escape: false,
|
|
17
|
+
constant: true,
|
|
18
|
+
absorb: true,
|
|
19
|
+
validate,
|
|
20
|
+
})(new MetadataCollection())(type);
|
|
21
|
+
if (result.success === false)
|
|
22
|
+
throw TransformerError.from("nestia.core.TypedParam")(result.errors);
|
|
23
|
+
return AssertProgrammer.write({
|
|
24
|
+
...project,
|
|
25
|
+
options: {
|
|
26
|
+
numeric: false,
|
|
27
|
+
finite: false,
|
|
28
|
+
functional: false,
|
|
29
|
+
},
|
|
30
|
+
})(modulo)(false)(type);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const validate = (metadata: Metadata): string[] => {
|
|
35
|
+
const errors: string[] = [];
|
|
36
|
+
const insert = (msg: string) => errors.push(msg);
|
|
37
|
+
|
|
38
|
+
const expected: number =
|
|
39
|
+
(metadata.atomics.some((a) => a.type === "string") ? 1 : 0) +
|
|
40
|
+
metadata.templates.length +
|
|
41
|
+
metadata.constants
|
|
42
|
+
.filter((c) => c.type === "string")
|
|
43
|
+
.map((c) => c.values.length)
|
|
44
|
+
.reduce((a, b) => a + b, 0);
|
|
45
|
+
if (expected === 0 || expected !== metadata.size())
|
|
46
|
+
insert(`only string type is allowed`);
|
|
47
|
+
if (metadata.isRequired() === false) insert(`do not allow undefindable type`);
|
|
48
|
+
if (metadata.nullable === true) insert(`do not allow nullable type`);
|
|
49
|
+
else if (metadata.any === true) insert(`do not allow any type`);
|
|
50
|
+
|
|
51
|
+
return errors;
|
|
52
|
+
};
|
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
import { JsonMetadataFactory } from "typia/lib/factories/JsonMetadataFactory";
|
|
3
|
-
import { TypeFactory } from "typia/lib/factories/TypeFactory";
|
|
4
|
-
import { TransformerError } from "typia/lib/transformers/TransformerError";
|
|
5
|
-
|
|
6
|
-
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
7
|
-
|
|
8
|
-
export namespace TypedExceptionProgrammer {
|
|
9
|
-
export const generate =
|
|
10
|
-
({ checker }: INestiaTransformProject) =>
|
|
11
|
-
(expression: ts.CallExpression): ts.CallExpression => {
|
|
12
|
-
// CHECK GENERIC ARGUMENT EXISTENCE
|
|
13
|
-
if (!expression.typeArguments?.[0])
|
|
14
|
-
throw TransformerError.from("nestia.core.TypedException")([
|
|
15
|
-
{
|
|
16
|
-
name: "uknown",
|
|
17
|
-
messages: [NOT_SPECIFIED],
|
|
18
|
-
explore: {
|
|
19
|
-
top: true,
|
|
20
|
-
object: null,
|
|
21
|
-
property: null,
|
|
22
|
-
nested: null,
|
|
23
|
-
escaped: false,
|
|
24
|
-
aliased: false,
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
]);
|
|
28
|
-
|
|
29
|
-
// GET TYPE INFO
|
|
30
|
-
const node: ts.TypeNode = expression.typeArguments[0];
|
|
31
|
-
const type: ts.Type = checker.getTypeFromTypeNode(node);
|
|
32
|
-
|
|
33
|
-
// VALIDATE TYPE
|
|
34
|
-
if (type.isTypeParameter())
|
|
35
|
-
throw TransformerError.from("nestia.core.TypedException")([
|
|
36
|
-
{
|
|
37
|
-
name: TypeFactory.getFullName(checker)(type),
|
|
38
|
-
messages: [NO_GENERIC_ARGUMENT],
|
|
39
|
-
explore: {
|
|
40
|
-
top: true,
|
|
41
|
-
object: null,
|
|
42
|
-
property: null,
|
|
43
|
-
nested: null,
|
|
44
|
-
escaped: false,
|
|
45
|
-
aliased: false,
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
]);
|
|
49
|
-
JsonMetadataFactory.analyze("@nestia.core.TypedException")(checker)(type);
|
|
50
|
-
|
|
51
|
-
// CHECK DUPLICATED TRNASFORMATION
|
|
52
|
-
if (expression.arguments.length === 3) return expression;
|
|
53
|
-
|
|
54
|
-
// DO TRANSFORM
|
|
55
|
-
const name: string = TypeFactory.getFullName(checker)(type);
|
|
56
|
-
return ts.factory.updateCallExpression(
|
|
57
|
-
expression,
|
|
58
|
-
expression.expression,
|
|
59
|
-
expression.typeArguments,
|
|
60
|
-
[
|
|
61
|
-
expression.arguments[0],
|
|
62
|
-
expression.arguments[1] ?? ts.factory.createIdentifier("undefined"),
|
|
63
|
-
ts.factory.createStringLiteral(name),
|
|
64
|
-
],
|
|
65
|
-
);
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const NOT_SPECIFIED =
|
|
70
|
-
"Error on @nestia.core.TypedException(): generic argument is not specified.";
|
|
71
|
-
const NO_GENERIC_ARGUMENT =
|
|
72
|
-
"Error on @nestia.core.TypedException(): non-specified generic argument.";
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { JsonMetadataFactory } from "typia/lib/factories/JsonMetadataFactory";
|
|
3
|
+
import { TypeFactory } from "typia/lib/factories/TypeFactory";
|
|
4
|
+
import { TransformerError } from "typia/lib/transformers/TransformerError";
|
|
5
|
+
|
|
6
|
+
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
7
|
+
|
|
8
|
+
export namespace TypedExceptionProgrammer {
|
|
9
|
+
export const generate =
|
|
10
|
+
({ checker }: INestiaTransformProject) =>
|
|
11
|
+
(expression: ts.CallExpression): ts.CallExpression => {
|
|
12
|
+
// CHECK GENERIC ARGUMENT EXISTENCE
|
|
13
|
+
if (!expression.typeArguments?.[0])
|
|
14
|
+
throw TransformerError.from("nestia.core.TypedException")([
|
|
15
|
+
{
|
|
16
|
+
name: "uknown",
|
|
17
|
+
messages: [NOT_SPECIFIED],
|
|
18
|
+
explore: {
|
|
19
|
+
top: true,
|
|
20
|
+
object: null,
|
|
21
|
+
property: null,
|
|
22
|
+
nested: null,
|
|
23
|
+
escaped: false,
|
|
24
|
+
aliased: false,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
// GET TYPE INFO
|
|
30
|
+
const node: ts.TypeNode = expression.typeArguments[0];
|
|
31
|
+
const type: ts.Type = checker.getTypeFromTypeNode(node);
|
|
32
|
+
|
|
33
|
+
// VALIDATE TYPE
|
|
34
|
+
if (type.isTypeParameter())
|
|
35
|
+
throw TransformerError.from("nestia.core.TypedException")([
|
|
36
|
+
{
|
|
37
|
+
name: TypeFactory.getFullName(checker)(type),
|
|
38
|
+
messages: [NO_GENERIC_ARGUMENT],
|
|
39
|
+
explore: {
|
|
40
|
+
top: true,
|
|
41
|
+
object: null,
|
|
42
|
+
property: null,
|
|
43
|
+
nested: null,
|
|
44
|
+
escaped: false,
|
|
45
|
+
aliased: false,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
]);
|
|
49
|
+
JsonMetadataFactory.analyze("@nestia.core.TypedException")(checker)(type);
|
|
50
|
+
|
|
51
|
+
// CHECK DUPLICATED TRNASFORMATION
|
|
52
|
+
if (expression.arguments.length === 3) return expression;
|
|
53
|
+
|
|
54
|
+
// DO TRANSFORM
|
|
55
|
+
const name: string = TypeFactory.getFullName(checker)(type);
|
|
56
|
+
return ts.factory.updateCallExpression(
|
|
57
|
+
expression,
|
|
58
|
+
expression.expression,
|
|
59
|
+
expression.typeArguments,
|
|
60
|
+
[
|
|
61
|
+
expression.arguments[0],
|
|
62
|
+
expression.arguments[1] ?? ts.factory.createIdentifier("undefined"),
|
|
63
|
+
ts.factory.createStringLiteral(name),
|
|
64
|
+
],
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const NOT_SPECIFIED =
|
|
70
|
+
"Error on @nestia.core.TypedException(): generic argument is not specified.";
|
|
71
|
+
const NO_GENERIC_ARGUMENT =
|
|
72
|
+
"Error on @nestia.core.TypedException(): non-specified generic argument.";
|
|
@@ -1,96 +1,96 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
|
3
|
-
import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
|
|
4
|
-
import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
|
|
5
|
-
import { StatementFactory } from "typia/lib/factories/StatementFactory";
|
|
6
|
-
import { FunctionImporter } from "typia/lib/programmers/helpers/FunctionImporeter";
|
|
7
|
-
import { HttpQueryProgrammer } from "typia/lib/programmers/http/HttpQueryProgrammer";
|
|
8
|
-
import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
9
|
-
import { MetadataObject } from "typia/lib/schemas/metadata/MetadataObject";
|
|
10
|
-
import { IProject } from "typia/lib/transformers/IProject";
|
|
11
|
-
import { TransformerError } from "typia/lib/transformers/TransformerError";
|
|
12
|
-
|
|
13
|
-
export namespace HttpQuerifyProgrammer {
|
|
14
|
-
export const write =
|
|
15
|
-
(project: IProject) =>
|
|
16
|
-
(modulo: ts.LeftHandSideExpression) =>
|
|
17
|
-
(type: ts.Type): ts.ArrowFunction => {
|
|
18
|
-
// GET OBJECT TYPE
|
|
19
|
-
const importer: FunctionImporter = new FunctionImporter(modulo.getText());
|
|
20
|
-
const collection: MetadataCollection = new MetadataCollection();
|
|
21
|
-
const result = MetadataFactory.analyze(project.checker)({
|
|
22
|
-
escape: false,
|
|
23
|
-
constant: true,
|
|
24
|
-
absorb: true,
|
|
25
|
-
validate: HttpQueryProgrammer.validate,
|
|
26
|
-
})(collection)(type);
|
|
27
|
-
if (result.success === false)
|
|
28
|
-
throw TransformerError.from(
|
|
29
|
-
`nestia.core.TypedQuery.${importer.method}`,
|
|
30
|
-
)(result.errors);
|
|
31
|
-
|
|
32
|
-
const object: MetadataObject = result.data.objects[0]!;
|
|
33
|
-
return ts.factory.createArrowFunction(
|
|
34
|
-
undefined,
|
|
35
|
-
undefined,
|
|
36
|
-
[IdentifierFactory.parameter("input")],
|
|
37
|
-
undefined,
|
|
38
|
-
undefined,
|
|
39
|
-
ts.factory.createBlock(
|
|
40
|
-
[
|
|
41
|
-
...importer.declare(modulo),
|
|
42
|
-
StatementFactory.constant(
|
|
43
|
-
"output",
|
|
44
|
-
ts.factory.createNewExpression(
|
|
45
|
-
ts.factory.createIdentifier("URLSearchParams"),
|
|
46
|
-
undefined,
|
|
47
|
-
[],
|
|
48
|
-
),
|
|
49
|
-
),
|
|
50
|
-
...object.properties.map((p) =>
|
|
51
|
-
ts.factory.createExpressionStatement(
|
|
52
|
-
decode(p.key.constants[0]!.values[0] as string)(p.value),
|
|
53
|
-
),
|
|
54
|
-
),
|
|
55
|
-
ts.factory.createReturnStatement(
|
|
56
|
-
ts.factory.createIdentifier("output"),
|
|
57
|
-
),
|
|
58
|
-
],
|
|
59
|
-
true,
|
|
60
|
-
),
|
|
61
|
-
);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const decode =
|
|
65
|
-
(key: string) =>
|
|
66
|
-
(value: Metadata): ts.CallExpression =>
|
|
67
|
-
!!value.arrays.length
|
|
68
|
-
? ts.factory.createCallExpression(
|
|
69
|
-
IdentifierFactory.access(
|
|
70
|
-
IdentifierFactory.access(ts.factory.createIdentifier("input"))(
|
|
71
|
-
key,
|
|
72
|
-
),
|
|
73
|
-
)("forEach"),
|
|
74
|
-
undefined,
|
|
75
|
-
[
|
|
76
|
-
ts.factory.createArrowFunction(
|
|
77
|
-
undefined,
|
|
78
|
-
undefined,
|
|
79
|
-
[IdentifierFactory.parameter("elem")],
|
|
80
|
-
undefined,
|
|
81
|
-
undefined,
|
|
82
|
-
append(key)(ts.factory.createIdentifier("elem")),
|
|
83
|
-
),
|
|
84
|
-
],
|
|
85
|
-
)
|
|
86
|
-
: append(key)(
|
|
87
|
-
IdentifierFactory.access(ts.factory.createIdentifier("input"))(key),
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
const append = (key: string) => (elem: ts.Expression) =>
|
|
91
|
-
ts.factory.createCallExpression(
|
|
92
|
-
IdentifierFactory.access(ts.factory.createIdentifier("output"))("append"),
|
|
93
|
-
undefined,
|
|
94
|
-
[ts.factory.createStringLiteral(key), elem],
|
|
95
|
-
);
|
|
96
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
|
3
|
+
import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
|
|
4
|
+
import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
|
|
5
|
+
import { StatementFactory } from "typia/lib/factories/StatementFactory";
|
|
6
|
+
import { FunctionImporter } from "typia/lib/programmers/helpers/FunctionImporeter";
|
|
7
|
+
import { HttpQueryProgrammer } from "typia/lib/programmers/http/HttpQueryProgrammer";
|
|
8
|
+
import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
9
|
+
import { MetadataObject } from "typia/lib/schemas/metadata/MetadataObject";
|
|
10
|
+
import { IProject } from "typia/lib/transformers/IProject";
|
|
11
|
+
import { TransformerError } from "typia/lib/transformers/TransformerError";
|
|
12
|
+
|
|
13
|
+
export namespace HttpQuerifyProgrammer {
|
|
14
|
+
export const write =
|
|
15
|
+
(project: IProject) =>
|
|
16
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
17
|
+
(type: ts.Type): ts.ArrowFunction => {
|
|
18
|
+
// GET OBJECT TYPE
|
|
19
|
+
const importer: FunctionImporter = new FunctionImporter(modulo.getText());
|
|
20
|
+
const collection: MetadataCollection = new MetadataCollection();
|
|
21
|
+
const result = MetadataFactory.analyze(project.checker)({
|
|
22
|
+
escape: false,
|
|
23
|
+
constant: true,
|
|
24
|
+
absorb: true,
|
|
25
|
+
validate: HttpQueryProgrammer.validate,
|
|
26
|
+
})(collection)(type);
|
|
27
|
+
if (result.success === false)
|
|
28
|
+
throw TransformerError.from(
|
|
29
|
+
`nestia.core.TypedQuery.${importer.method}`,
|
|
30
|
+
)(result.errors);
|
|
31
|
+
|
|
32
|
+
const object: MetadataObject = result.data.objects[0]!;
|
|
33
|
+
return ts.factory.createArrowFunction(
|
|
34
|
+
undefined,
|
|
35
|
+
undefined,
|
|
36
|
+
[IdentifierFactory.parameter("input")],
|
|
37
|
+
undefined,
|
|
38
|
+
undefined,
|
|
39
|
+
ts.factory.createBlock(
|
|
40
|
+
[
|
|
41
|
+
...importer.declare(modulo),
|
|
42
|
+
StatementFactory.constant(
|
|
43
|
+
"output",
|
|
44
|
+
ts.factory.createNewExpression(
|
|
45
|
+
ts.factory.createIdentifier("URLSearchParams"),
|
|
46
|
+
undefined,
|
|
47
|
+
[],
|
|
48
|
+
),
|
|
49
|
+
),
|
|
50
|
+
...object.properties.map((p) =>
|
|
51
|
+
ts.factory.createExpressionStatement(
|
|
52
|
+
decode(p.key.constants[0]!.values[0] as string)(p.value),
|
|
53
|
+
),
|
|
54
|
+
),
|
|
55
|
+
ts.factory.createReturnStatement(
|
|
56
|
+
ts.factory.createIdentifier("output"),
|
|
57
|
+
),
|
|
58
|
+
],
|
|
59
|
+
true,
|
|
60
|
+
),
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const decode =
|
|
65
|
+
(key: string) =>
|
|
66
|
+
(value: Metadata): ts.CallExpression =>
|
|
67
|
+
!!value.arrays.length
|
|
68
|
+
? ts.factory.createCallExpression(
|
|
69
|
+
IdentifierFactory.access(
|
|
70
|
+
IdentifierFactory.access(ts.factory.createIdentifier("input"))(
|
|
71
|
+
key,
|
|
72
|
+
),
|
|
73
|
+
)("forEach"),
|
|
74
|
+
undefined,
|
|
75
|
+
[
|
|
76
|
+
ts.factory.createArrowFunction(
|
|
77
|
+
undefined,
|
|
78
|
+
undefined,
|
|
79
|
+
[IdentifierFactory.parameter("elem")],
|
|
80
|
+
undefined,
|
|
81
|
+
undefined,
|
|
82
|
+
append(key)(ts.factory.createIdentifier("elem")),
|
|
83
|
+
),
|
|
84
|
+
],
|
|
85
|
+
)
|
|
86
|
+
: append(key)(
|
|
87
|
+
IdentifierFactory.access(ts.factory.createIdentifier("input"))(key),
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const append = (key: string) => (elem: ts.Expression) =>
|
|
91
|
+
ts.factory.createCallExpression(
|
|
92
|
+
IdentifierFactory.access(ts.factory.createIdentifier("output"))("append"),
|
|
93
|
+
undefined,
|
|
94
|
+
[ts.factory.createStringLiteral(key), elem],
|
|
95
|
+
);
|
|
96
|
+
}
|
|
@@ -1,126 +1,126 @@
|
|
|
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(
|
|
107
|
-
"node_modules",
|
|
108
|
-
"@nestia",
|
|
109
|
-
"core",
|
|
110
|
-
"lib",
|
|
111
|
-
"decorators",
|
|
112
|
-
);
|
|
113
|
-
const SRC_PATH = path.resolve(path.join(__dirname, "..", "decorators"));
|
|
114
|
-
|
|
115
|
-
const getName = (symbol: ts.Symbol): string => {
|
|
116
|
-
const parent = symbol.getDeclarations()?.[0]?.parent;
|
|
117
|
-
return parent ? exploreName(parent)(symbol.escapedName.toString()) : "__type";
|
|
118
|
-
};
|
|
119
|
-
const exploreName =
|
|
120
|
-
(decl: ts.Node) =>
|
|
121
|
-
(name: string): string =>
|
|
122
|
-
ts.isModuleBlock(decl)
|
|
123
|
-
? exploreName(decl.parent.parent)(
|
|
124
|
-
`${decl.parent.name.getFullText().trim()}.${name}`,
|
|
125
|
-
)
|
|
126
|
-
: 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(
|
|
107
|
+
"node_modules",
|
|
108
|
+
"@nestia",
|
|
109
|
+
"core",
|
|
110
|
+
"lib",
|
|
111
|
+
"decorators",
|
|
112
|
+
);
|
|
113
|
+
const SRC_PATH = path.resolve(path.join(__dirname, "..", "decorators"));
|
|
114
|
+
|
|
115
|
+
const getName = (symbol: ts.Symbol): string => {
|
|
116
|
+
const parent = symbol.getDeclarations()?.[0]?.parent;
|
|
117
|
+
return parent ? exploreName(parent)(symbol.escapedName.toString()) : "__type";
|
|
118
|
+
};
|
|
119
|
+
const exploreName =
|
|
120
|
+
(decl: ts.Node) =>
|
|
121
|
+
(name: string): string =>
|
|
122
|
+
ts.isModuleBlock(decl)
|
|
123
|
+
? exploreName(decl.parent.parent)(
|
|
124
|
+
`${decl.parent.name.getFullText().trim()}.${name}`,
|
|
125
|
+
)
|
|
126
|
+
: name;
|