@nestia/core 2.4.3 → 3.0.0-dev.20231209
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/decorators/EncryptedBody.js +13 -11
- package/lib/decorators/EncryptedBody.js.map +1 -1
- package/lib/decorators/EncryptedRoute.js +29 -12
- package/lib/decorators/EncryptedRoute.js.map +1 -1
- package/lib/decorators/internal/get_binary_body.d.ts +1 -0
- package/lib/decorators/internal/get_binary_body.js +66 -0
- package/lib/decorators/internal/get_binary_body.js.map +1 -0
- package/package.json +3 -3
- package/src/decorators/DynamicModule.ts +39 -39
- package/src/decorators/EncryptedBody.ts +17 -12
- package/src/decorators/EncryptedController.ts +38 -38
- package/src/decorators/EncryptedModule.ts +79 -79
- package/src/decorators/EncryptedRoute.ts +38 -14
- package/src/decorators/PlainBody.ts +72 -72
- package/src/decorators/TypedBody.ts +59 -59
- package/src/decorators/TypedException.ts +89 -89
- package/src/decorators/TypedHeaders.ts +69 -69
- package/src/decorators/TypedParam.ts +65 -65
- package/src/decorators/TypedQuery.ts +246 -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_binary_body.ts +18 -0
- package/src/decorators/internal/get_path_and_querify.ts +103 -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 +57 -57
- package/src/decorators/internal/validate_request_headers.ts +68 -68
- package/src/decorators/internal/validate_request_query.ts +56 -56
- package/src/index.ts +5 -5
- package/src/module.ts +14 -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/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 +72 -72
- 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 +121 -121
- package/src/transformers/ParameterTransformer.ts +48 -48
- package/src/transformers/TypedExceptionTransformer.ts +49 -49
- package/src/transformers/TypedRouteTransformer.ts +95 -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
|
@@ -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("@core.nestia.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("@core.nestia.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,108 +1,108 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
import { JsonMetadataFactory } from "typia/lib/factories/JsonMetadataFactory";
|
|
3
|
-
import { AssertProgrammer } from "typia/lib/programmers/AssertProgrammer";
|
|
4
|
-
import { IsProgrammer } from "typia/lib/programmers/IsProgrammer";
|
|
5
|
-
import { ValidateProgrammer } from "typia/lib/programmers/ValidateProgrammer";
|
|
6
|
-
import { MiscAssertCloneProgrammer } from "typia/lib/programmers/misc/MiscAssertCloneProgrammer";
|
|
7
|
-
import { MiscAssertPruneProgrammer } from "typia/lib/programmers/misc/MiscAssertPruneProgrammer";
|
|
8
|
-
import { MiscValidateCloneProgrammer } from "typia/lib/programmers/misc/MiscValidateCloneProgrammer";
|
|
9
|
-
import { MiscValidatePruneProgrammer } from "typia/lib/programmers/misc/MiscValidatePruneProgrammer";
|
|
10
|
-
import { IProject } from "typia/lib/transformers/IProject";
|
|
11
|
-
|
|
12
|
-
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
13
|
-
import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
|
|
14
|
-
|
|
15
|
-
export namespace TypedBodyProgrammer {
|
|
16
|
-
export const generate =
|
|
17
|
-
(project: INestiaTransformProject) =>
|
|
18
|
-
(modulo: ts.LeftHandSideExpression) =>
|
|
19
|
-
(type: ts.Type): ts.ObjectLiteralExpression => {
|
|
20
|
-
// VALIDATE TYPE
|
|
21
|
-
JsonMetadataFactory.analyze("@nestia.core.TypedBody")(project.checker)(
|
|
22
|
-
type,
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
// GENERATE VALIDATION PLAN
|
|
26
|
-
const check =
|
|
27
|
-
(key: IRequestBodyValidator<any>["type"]) =>
|
|
28
|
-
(equals: boolean) =>
|
|
29
|
-
(
|
|
30
|
-
programmer: (
|
|
31
|
-
project: IProject,
|
|
32
|
-
) => (
|
|
33
|
-
modulo: ts.LeftHandSideExpression,
|
|
34
|
-
) => (equals: boolean) => (type: ts.Type) => ts.ArrowFunction,
|
|
35
|
-
) =>
|
|
36
|
-
ts.factory.createObjectLiteralExpression([
|
|
37
|
-
ts.factory.createPropertyAssignment(
|
|
38
|
-
ts.factory.createIdentifier("type"),
|
|
39
|
-
ts.factory.createStringLiteral(key),
|
|
40
|
-
),
|
|
41
|
-
ts.factory.createPropertyAssignment(
|
|
42
|
-
ts.factory.createIdentifier(key),
|
|
43
|
-
programmer({
|
|
44
|
-
...project,
|
|
45
|
-
options: {
|
|
46
|
-
numeric: false,
|
|
47
|
-
finite: false,
|
|
48
|
-
functional: false,
|
|
49
|
-
},
|
|
50
|
-
})(modulo)(equals)(type),
|
|
51
|
-
),
|
|
52
|
-
]);
|
|
53
|
-
const misc =
|
|
54
|
-
(key: IRequestBodyValidator<any>["type"]) =>
|
|
55
|
-
(
|
|
56
|
-
programmer: (
|
|
57
|
-
project: IProject,
|
|
58
|
-
) => (
|
|
59
|
-
modulo: ts.LeftHandSideExpression,
|
|
60
|
-
) => (type: ts.Type) => ts.ArrowFunction,
|
|
61
|
-
) =>
|
|
62
|
-
ts.factory.createObjectLiteralExpression([
|
|
63
|
-
ts.factory.createPropertyAssignment(
|
|
64
|
-
ts.factory.createIdentifier("type"),
|
|
65
|
-
ts.factory.createStringLiteral(key),
|
|
66
|
-
),
|
|
67
|
-
ts.factory.createPropertyAssignment(
|
|
68
|
-
ts.factory.createIdentifier(key),
|
|
69
|
-
programmer({
|
|
70
|
-
...project,
|
|
71
|
-
options: {
|
|
72
|
-
numeric: false,
|
|
73
|
-
finite: false,
|
|
74
|
-
functional: false,
|
|
75
|
-
},
|
|
76
|
-
})(modulo)(type),
|
|
77
|
-
),
|
|
78
|
-
]);
|
|
79
|
-
|
|
80
|
-
//----
|
|
81
|
-
// RETURNS
|
|
82
|
-
//----
|
|
83
|
-
const category = project.options.validate;
|
|
84
|
-
// NORMAL
|
|
85
|
-
if (category === "is") return check("is")(false)(IsProgrammer.write);
|
|
86
|
-
else if (category === "validate")
|
|
87
|
-
return check("validate")(false)(ValidateProgrammer.write);
|
|
88
|
-
// STRICT
|
|
89
|
-
else if (category === "validateEquals")
|
|
90
|
-
return check("validate")(true)(ValidateProgrammer.write);
|
|
91
|
-
else if (category === "equals")
|
|
92
|
-
return check("is")(true)(IsProgrammer.write);
|
|
93
|
-
else if (category === "assertEquals")
|
|
94
|
-
return check("assert")(true)(AssertProgrammer.write);
|
|
95
|
-
// CLONE
|
|
96
|
-
else if (category === "assertClone")
|
|
97
|
-
return misc("assert")(MiscAssertCloneProgrammer.write);
|
|
98
|
-
else if (category === "validateClone")
|
|
99
|
-
return misc("validate")(MiscValidateCloneProgrammer.write);
|
|
100
|
-
// PRUNE
|
|
101
|
-
else if (category === "assertPrune")
|
|
102
|
-
return misc("assert")(MiscAssertPruneProgrammer.write);
|
|
103
|
-
else if (category === "validatePrune")
|
|
104
|
-
return misc("validate")(MiscValidatePruneProgrammer.write);
|
|
105
|
-
// DEFAULT
|
|
106
|
-
return check("assert")(false)(AssertProgrammer.write);
|
|
107
|
-
};
|
|
108
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { JsonMetadataFactory } from "typia/lib/factories/JsonMetadataFactory";
|
|
3
|
+
import { AssertProgrammer } from "typia/lib/programmers/AssertProgrammer";
|
|
4
|
+
import { IsProgrammer } from "typia/lib/programmers/IsProgrammer";
|
|
5
|
+
import { ValidateProgrammer } from "typia/lib/programmers/ValidateProgrammer";
|
|
6
|
+
import { MiscAssertCloneProgrammer } from "typia/lib/programmers/misc/MiscAssertCloneProgrammer";
|
|
7
|
+
import { MiscAssertPruneProgrammer } from "typia/lib/programmers/misc/MiscAssertPruneProgrammer";
|
|
8
|
+
import { MiscValidateCloneProgrammer } from "typia/lib/programmers/misc/MiscValidateCloneProgrammer";
|
|
9
|
+
import { MiscValidatePruneProgrammer } from "typia/lib/programmers/misc/MiscValidatePruneProgrammer";
|
|
10
|
+
import { IProject } from "typia/lib/transformers/IProject";
|
|
11
|
+
|
|
12
|
+
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
13
|
+
import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
|
|
14
|
+
|
|
15
|
+
export namespace TypedBodyProgrammer {
|
|
16
|
+
export const generate =
|
|
17
|
+
(project: INestiaTransformProject) =>
|
|
18
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
19
|
+
(type: ts.Type): ts.ObjectLiteralExpression => {
|
|
20
|
+
// VALIDATE TYPE
|
|
21
|
+
JsonMetadataFactory.analyze("@nestia.core.TypedBody")(project.checker)(
|
|
22
|
+
type,
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
// GENERATE VALIDATION PLAN
|
|
26
|
+
const check =
|
|
27
|
+
(key: IRequestBodyValidator<any>["type"]) =>
|
|
28
|
+
(equals: boolean) =>
|
|
29
|
+
(
|
|
30
|
+
programmer: (
|
|
31
|
+
project: IProject,
|
|
32
|
+
) => (
|
|
33
|
+
modulo: ts.LeftHandSideExpression,
|
|
34
|
+
) => (equals: boolean) => (type: ts.Type) => ts.ArrowFunction,
|
|
35
|
+
) =>
|
|
36
|
+
ts.factory.createObjectLiteralExpression([
|
|
37
|
+
ts.factory.createPropertyAssignment(
|
|
38
|
+
ts.factory.createIdentifier("type"),
|
|
39
|
+
ts.factory.createStringLiteral(key),
|
|
40
|
+
),
|
|
41
|
+
ts.factory.createPropertyAssignment(
|
|
42
|
+
ts.factory.createIdentifier(key),
|
|
43
|
+
programmer({
|
|
44
|
+
...project,
|
|
45
|
+
options: {
|
|
46
|
+
numeric: false,
|
|
47
|
+
finite: false,
|
|
48
|
+
functional: false,
|
|
49
|
+
},
|
|
50
|
+
})(modulo)(equals)(type),
|
|
51
|
+
),
|
|
52
|
+
]);
|
|
53
|
+
const misc =
|
|
54
|
+
(key: IRequestBodyValidator<any>["type"]) =>
|
|
55
|
+
(
|
|
56
|
+
programmer: (
|
|
57
|
+
project: IProject,
|
|
58
|
+
) => (
|
|
59
|
+
modulo: ts.LeftHandSideExpression,
|
|
60
|
+
) => (type: ts.Type) => ts.ArrowFunction,
|
|
61
|
+
) =>
|
|
62
|
+
ts.factory.createObjectLiteralExpression([
|
|
63
|
+
ts.factory.createPropertyAssignment(
|
|
64
|
+
ts.factory.createIdentifier("type"),
|
|
65
|
+
ts.factory.createStringLiteral(key),
|
|
66
|
+
),
|
|
67
|
+
ts.factory.createPropertyAssignment(
|
|
68
|
+
ts.factory.createIdentifier(key),
|
|
69
|
+
programmer({
|
|
70
|
+
...project,
|
|
71
|
+
options: {
|
|
72
|
+
numeric: false,
|
|
73
|
+
finite: false,
|
|
74
|
+
functional: false,
|
|
75
|
+
},
|
|
76
|
+
})(modulo)(type),
|
|
77
|
+
),
|
|
78
|
+
]);
|
|
79
|
+
|
|
80
|
+
//----
|
|
81
|
+
// RETURNS
|
|
82
|
+
//----
|
|
83
|
+
const category = project.options.validate;
|
|
84
|
+
// NORMAL
|
|
85
|
+
if (category === "is") return check("is")(false)(IsProgrammer.write);
|
|
86
|
+
else if (category === "validate")
|
|
87
|
+
return check("validate")(false)(ValidateProgrammer.write);
|
|
88
|
+
// STRICT
|
|
89
|
+
else if (category === "validateEquals")
|
|
90
|
+
return check("validate")(true)(ValidateProgrammer.write);
|
|
91
|
+
else if (category === "equals")
|
|
92
|
+
return check("is")(true)(IsProgrammer.write);
|
|
93
|
+
else if (category === "assertEquals")
|
|
94
|
+
return check("assert")(true)(AssertProgrammer.write);
|
|
95
|
+
// CLONE
|
|
96
|
+
else if (category === "assertClone")
|
|
97
|
+
return misc("assert")(MiscAssertCloneProgrammer.write);
|
|
98
|
+
else if (category === "validateClone")
|
|
99
|
+
return misc("validate")(MiscValidateCloneProgrammer.write);
|
|
100
|
+
// PRUNE
|
|
101
|
+
else if (category === "assertPrune")
|
|
102
|
+
return misc("assert")(MiscAssertPruneProgrammer.write);
|
|
103
|
+
else if (category === "validatePrune")
|
|
104
|
+
return misc("validate")(MiscValidatePruneProgrammer.write);
|
|
105
|
+
// DEFAULT
|
|
106
|
+
return check("assert")(false)(AssertProgrammer.write);
|
|
107
|
+
};
|
|
108
|
+
}
|
|
@@ -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,56 +1,56 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
import { HttpAssertHeadersProgrammer } from "typia/lib/programmers/http/HttpAssertHeadersProgrammer";
|
|
3
|
-
import { HttpIsHeadersProgrammer } from "typia/lib/programmers/http/HttpIsHeadersProgrammer";
|
|
4
|
-
import { HttpValidateHeadersProgrammer } from "typia/lib/programmers/http/HttpValidateHeadersProgrammer";
|
|
5
|
-
import { IProject } from "typia/lib/transformers/IProject";
|
|
6
|
-
|
|
7
|
-
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
8
|
-
import { IRequestHeadersValidator } from "../options/IRequestHeadersValidator";
|
|
9
|
-
|
|
10
|
-
export namespace TypedHeadersProgrammer {
|
|
11
|
-
export const generate =
|
|
12
|
-
(project: INestiaTransformProject) =>
|
|
13
|
-
(modulo: ts.LeftHandSideExpression) =>
|
|
14
|
-
(type: ts.Type): ts.Expression => {
|
|
15
|
-
// GENERATE VALIDATION PLAN
|
|
16
|
-
const parameter =
|
|
17
|
-
(key: IRequestHeadersValidator<any>["type"]) =>
|
|
18
|
-
(
|
|
19
|
-
programmer: (
|
|
20
|
-
project: IProject,
|
|
21
|
-
) => (
|
|
22
|
-
modulo: ts.LeftHandSideExpression,
|
|
23
|
-
) => (type: ts.Type) => ts.ArrowFunction,
|
|
24
|
-
) =>
|
|
25
|
-
ts.factory.createObjectLiteralExpression([
|
|
26
|
-
ts.factory.createPropertyAssignment(
|
|
27
|
-
ts.factory.createIdentifier("type"),
|
|
28
|
-
ts.factory.createStringLiteral(key),
|
|
29
|
-
),
|
|
30
|
-
ts.factory.createPropertyAssignment(
|
|
31
|
-
ts.factory.createIdentifier(key),
|
|
32
|
-
programmer({
|
|
33
|
-
...project,
|
|
34
|
-
options: {
|
|
35
|
-
numeric: false,
|
|
36
|
-
finite: false,
|
|
37
|
-
functional: false,
|
|
38
|
-
},
|
|
39
|
-
})(modulo)(type),
|
|
40
|
-
),
|
|
41
|
-
]);
|
|
42
|
-
|
|
43
|
-
// RETURNS
|
|
44
|
-
const category = project.options.validate;
|
|
45
|
-
if (category === "is" || category === "equals")
|
|
46
|
-
return parameter("is")(HttpIsHeadersProgrammer.write);
|
|
47
|
-
else if (
|
|
48
|
-
category === "validate" ||
|
|
49
|
-
category === "validateEquals" ||
|
|
50
|
-
category === "validateClone" ||
|
|
51
|
-
category === "validatePrune"
|
|
52
|
-
)
|
|
53
|
-
return parameter("validate")(HttpValidateHeadersProgrammer.write);
|
|
54
|
-
return parameter("assert")(HttpAssertHeadersProgrammer.write);
|
|
55
|
-
};
|
|
56
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { HttpAssertHeadersProgrammer } from "typia/lib/programmers/http/HttpAssertHeadersProgrammer";
|
|
3
|
+
import { HttpIsHeadersProgrammer } from "typia/lib/programmers/http/HttpIsHeadersProgrammer";
|
|
4
|
+
import { HttpValidateHeadersProgrammer } from "typia/lib/programmers/http/HttpValidateHeadersProgrammer";
|
|
5
|
+
import { IProject } from "typia/lib/transformers/IProject";
|
|
6
|
+
|
|
7
|
+
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
8
|
+
import { IRequestHeadersValidator } from "../options/IRequestHeadersValidator";
|
|
9
|
+
|
|
10
|
+
export namespace TypedHeadersProgrammer {
|
|
11
|
+
export const generate =
|
|
12
|
+
(project: INestiaTransformProject) =>
|
|
13
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
14
|
+
(type: ts.Type): ts.Expression => {
|
|
15
|
+
// GENERATE VALIDATION PLAN
|
|
16
|
+
const parameter =
|
|
17
|
+
(key: IRequestHeadersValidator<any>["type"]) =>
|
|
18
|
+
(
|
|
19
|
+
programmer: (
|
|
20
|
+
project: IProject,
|
|
21
|
+
) => (
|
|
22
|
+
modulo: ts.LeftHandSideExpression,
|
|
23
|
+
) => (type: ts.Type) => ts.ArrowFunction,
|
|
24
|
+
) =>
|
|
25
|
+
ts.factory.createObjectLiteralExpression([
|
|
26
|
+
ts.factory.createPropertyAssignment(
|
|
27
|
+
ts.factory.createIdentifier("type"),
|
|
28
|
+
ts.factory.createStringLiteral(key),
|
|
29
|
+
),
|
|
30
|
+
ts.factory.createPropertyAssignment(
|
|
31
|
+
ts.factory.createIdentifier(key),
|
|
32
|
+
programmer({
|
|
33
|
+
...project,
|
|
34
|
+
options: {
|
|
35
|
+
numeric: false,
|
|
36
|
+
finite: false,
|
|
37
|
+
functional: false,
|
|
38
|
+
},
|
|
39
|
+
})(modulo)(type),
|
|
40
|
+
),
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
// RETURNS
|
|
44
|
+
const category = project.options.validate;
|
|
45
|
+
if (category === "is" || category === "equals")
|
|
46
|
+
return parameter("is")(HttpIsHeadersProgrammer.write);
|
|
47
|
+
else if (
|
|
48
|
+
category === "validate" ||
|
|
49
|
+
category === "validateEquals" ||
|
|
50
|
+
category === "validateClone" ||
|
|
51
|
+
category === "validatePrune"
|
|
52
|
+
)
|
|
53
|
+
return parameter("validate")(HttpValidateHeadersProgrammer.write);
|
|
54
|
+
return parameter("assert")(HttpAssertHeadersProgrammer.write);
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
import { HttpParameterProgrammer } from "typia/lib/programmers/http/HttpParameterProgrammer";
|
|
3
|
-
|
|
4
|
-
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
5
|
-
|
|
6
|
-
export namespace TypedParamProgrammer {
|
|
7
|
-
export const generate =
|
|
8
|
-
(project: INestiaTransformProject) =>
|
|
9
|
-
(modulo: ts.LeftHandSideExpression) =>
|
|
10
|
-
(parameters: readonly ts.Expression[]) =>
|
|
11
|
-
(type: ts.Type): readonly ts.Expression[] => {
|
|
12
|
-
// ALREADY BEING TRANSFORMED
|
|
13
|
-
if (parameters.length !== 1) return parameters;
|
|
14
|
-
return [
|
|
15
|
-
parameters[0],
|
|
16
|
-
HttpParameterProgrammer.write({
|
|
17
|
-
...project,
|
|
18
|
-
options: {
|
|
19
|
-
numeric: true,
|
|
20
|
-
},
|
|
21
|
-
})(modulo)(type),
|
|
22
|
-
];
|
|
23
|
-
};
|
|
24
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { HttpParameterProgrammer } from "typia/lib/programmers/http/HttpParameterProgrammer";
|
|
3
|
+
|
|
4
|
+
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
5
|
+
|
|
6
|
+
export namespace TypedParamProgrammer {
|
|
7
|
+
export const generate =
|
|
8
|
+
(project: INestiaTransformProject) =>
|
|
9
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
10
|
+
(parameters: readonly ts.Expression[]) =>
|
|
11
|
+
(type: ts.Type): readonly ts.Expression[] => {
|
|
12
|
+
// ALREADY BEING TRANSFORMED
|
|
13
|
+
if (parameters.length !== 1) return parameters;
|
|
14
|
+
return [
|
|
15
|
+
parameters[0],
|
|
16
|
+
HttpParameterProgrammer.write({
|
|
17
|
+
...project,
|
|
18
|
+
options: {
|
|
19
|
+
numeric: true,
|
|
20
|
+
},
|
|
21
|
+
})(modulo)(type),
|
|
22
|
+
];
|
|
23
|
+
};
|
|
24
|
+
}
|