@nestia/core 10.0.2 → 11.0.0-dev.20260305
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/LICENSE +21 -21
- package/README.md +93 -93
- package/lib/adaptors/WebSocketAdaptor.js.map +1 -1
- package/lib/decorators/DynamicModule.js +54 -10
- package/lib/decorators/DynamicModule.js.map +1 -1
- package/lib/decorators/EncryptedBody.js +2 -2
- package/lib/decorators/EncryptedBody.js.map +1 -1
- package/lib/decorators/EncryptedController.d.ts +1 -1
- package/lib/decorators/EncryptedModule.d.ts +1 -1
- package/lib/decorators/EncryptedModule.js +54 -10
- package/lib/decorators/EncryptedModule.js.map +1 -1
- package/lib/decorators/EncryptedRoute.js +2 -2
- package/lib/decorators/EncryptedRoute.js.map +1 -1
- package/lib/decorators/HumanRoute.d.ts +1 -2
- package/lib/decorators/HumanRoute.js +1 -2
- package/lib/decorators/HumanRoute.js.map +1 -1
- package/lib/decorators/NoTransformConfigurationError.js +1 -1
- package/lib/decorators/NoTransformConfigurationError.js.map +1 -1
- package/lib/decorators/SwaggerCustomizer.d.ts +1 -1
- package/lib/decorators/TypedFormData.js.map +1 -1
- package/lib/decorators/TypedParam.js +1 -1
- package/lib/decorators/TypedParam.js.map +1 -1
- package/lib/decorators/internal/get_path_and_querify.js +1 -1
- package/lib/decorators/internal/get_path_and_querify.js.map +1 -1
- package/lib/decorators/internal/get_path_and_stringify.js +1 -1
- package/lib/decorators/internal/get_path_and_stringify.js.map +1 -1
- package/lib/decorators/internal/headers_to_object.js.map +1 -1
- package/lib/decorators/internal/validate_request_body.js +1 -1
- package/lib/decorators/internal/validate_request_body.js.map +1 -1
- package/lib/decorators/internal/validate_request_form_data.js +1 -1
- package/lib/decorators/internal/validate_request_form_data.js.map +1 -1
- package/lib/decorators/internal/validate_request_headers.js +1 -1
- package/lib/decorators/internal/validate_request_headers.js.map +1 -1
- package/lib/decorators/internal/validate_request_query.js +1 -1
- package/lib/decorators/internal/validate_request_query.js.map +1 -1
- package/lib/module.d.ts +1 -0
- package/lib/module.js +1 -0
- package/lib/module.js.map +1 -1
- package/lib/options/INestiaTransformProject.d.ts +1 -1
- package/lib/programmers/PlainBodyProgrammer.js +5 -8
- package/lib/programmers/PlainBodyProgrammer.js.map +1 -1
- package/lib/programmers/TypedBodyProgrammer.js +13 -21
- package/lib/programmers/TypedBodyProgrammer.js.map +1 -1
- package/lib/programmers/TypedFormDataBodyProgrammer.js +11 -20
- package/lib/programmers/TypedFormDataBodyProgrammer.js.map +1 -1
- package/lib/programmers/TypedHeadersProgrammer.js +4 -6
- package/lib/programmers/TypedHeadersProgrammer.js.map +1 -1
- package/lib/programmers/TypedParamProgrammer.js +2 -2
- package/lib/programmers/TypedParamProgrammer.js.map +1 -1
- package/lib/programmers/TypedQueryBodyProgrammer.js +9 -16
- package/lib/programmers/TypedQueryBodyProgrammer.js.map +1 -1
- package/lib/programmers/TypedQueryProgrammer.js +9 -16
- package/lib/programmers/TypedQueryProgrammer.js.map +1 -1
- package/lib/programmers/TypedQueryRouteProgrammer.js +6 -10
- package/lib/programmers/TypedQueryRouteProgrammer.js.map +1 -1
- package/lib/programmers/TypedRouteProgrammer.js +8 -13
- package/lib/programmers/TypedRouteProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpAssertQuerifyProgrammer.d.ts +1 -1
- package/lib/programmers/http/HttpAssertQuerifyProgrammer.js +5 -7
- package/lib/programmers/http/HttpAssertQuerifyProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpIsQuerifyProgrammer.d.ts +1 -1
- package/lib/programmers/http/HttpIsQuerifyProgrammer.js +5 -7
- package/lib/programmers/http/HttpIsQuerifyProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpQuerifyProgrammer.d.ts +1 -1
- package/lib/programmers/http/HttpQuerifyProgrammer.js +13 -19
- package/lib/programmers/http/HttpQuerifyProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpValidateQuerifyProgrammer.d.ts +1 -1
- package/lib/programmers/http/HttpValidateQuerifyProgrammer.js +6 -8
- package/lib/programmers/http/HttpValidateQuerifyProgrammer.js.map +1 -1
- package/lib/programmers/internal/CoreMetadataUtil.d.ts +3 -3
- package/lib/programmers/internal/CoreMetadataUtil.js.map +1 -1
- package/lib/transform.d.ts +1 -1
- package/lib/transform.js.map +1 -1
- package/lib/transformers/FileTransformer.js +2 -2
- package/lib/transformers/FileTransformer.js.map +1 -1
- package/lib/transformers/MethodTransformer.js.map +1 -1
- package/lib/transformers/ParameterDecoratorTransformer.js +1 -1
- package/lib/transformers/ParameterDecoratorTransformer.js.map +1 -1
- package/lib/transformers/TypedRouteTransformer.js +1 -1
- package/lib/transformers/TypedRouteTransformer.js.map +1 -1
- package/lib/transformers/WebSocketRouteTransformer.js +1 -1
- package/lib/transformers/WebSocketRouteTransformer.js.map +1 -1
- package/package.json +34 -26
- package/src/adaptors/WebSocketAdaptor.ts +429 -429
- package/src/decorators/DynamicModule.ts +44 -44
- package/src/decorators/EncryptedBody.ts +96 -97
- package/src/decorators/EncryptedController.ts +40 -40
- package/src/decorators/EncryptedModule.ts +98 -98
- package/src/decorators/EncryptedRoute.ts +212 -213
- package/src/decorators/HumanRoute.ts +21 -22
- package/src/decorators/NoTransformConfigurationError.ts +34 -34
- package/src/decorators/PlainBody.ts +76 -76
- package/src/decorators/SwaggerCustomizer.ts +97 -97
- package/src/decorators/SwaggerExample.ts +100 -100
- package/src/decorators/TypedBody.ts +57 -57
- package/src/decorators/TypedException.ts +147 -147
- package/src/decorators/TypedFormData.ts +187 -195
- package/src/decorators/TypedHeaders.ts +66 -66
- package/src/decorators/TypedParam.ts +77 -77
- package/src/decorators/TypedQuery.ts +234 -234
- package/src/decorators/TypedRoute.ts +196 -196
- package/src/decorators/WebSocketRoute.ts +242 -242
- package/src/decorators/internal/EncryptedConstant.ts +2 -2
- package/src/decorators/internal/IWebSocketRouteReflect.ts +23 -23
- package/src/decorators/internal/NoTransformConfigureError.ts +2 -2
- package/src/decorators/internal/get_path_and_querify.ts +94 -94
- package/src/decorators/internal/get_path_and_stringify.ts +110 -110
- package/src/decorators/internal/get_text_body.ts +16 -16
- package/src/decorators/internal/headers_to_object.ts +11 -11
- package/src/decorators/internal/is_request_body_undefined.ts +12 -12
- package/src/decorators/internal/load_controller.ts +45 -45
- package/src/decorators/internal/route_error.ts +43 -43
- package/src/decorators/internal/validate_request_body.ts +64 -64
- package/src/decorators/internal/validate_request_form_data.ts +67 -67
- package/src/decorators/internal/validate_request_headers.ts +76 -76
- package/src/decorators/internal/validate_request_query.ts +64 -64
- package/src/index.ts +5 -5
- package/src/module.ts +23 -22
- package/src/options/INestiaTransformOptions.ts +34 -34
- package/src/options/INestiaTransformProject.ts +10 -8
- 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 +30 -30
- package/src/programmers/PlainBodyProgrammer.ts +72 -70
- package/src/programmers/TypedBodyProgrammer.ts +144 -142
- package/src/programmers/TypedFormDataBodyProgrammer.ts +118 -118
- package/src/programmers/TypedHeadersProgrammer.ts +65 -63
- package/src/programmers/TypedParamProgrammer.ts +33 -33
- package/src/programmers/TypedQueryBodyProgrammer.ts +111 -109
- package/src/programmers/TypedQueryProgrammer.ts +113 -111
- package/src/programmers/TypedQueryRouteProgrammer.ts +104 -102
- package/src/programmers/TypedRouteProgrammer.ts +96 -94
- package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +74 -72
- package/src/programmers/http/HttpIsQuerifyProgrammer.ts +77 -75
- package/src/programmers/http/HttpQuerifyProgrammer.ts +110 -108
- package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +78 -76
- package/src/programmers/internal/CoreMetadataUtil.ts +21 -21
- package/src/transform.ts +35 -35
- package/src/transformers/FileTransformer.ts +109 -110
- package/src/transformers/MethodTransformer.ts +103 -103
- package/src/transformers/NodeTransformer.ts +23 -23
- package/src/transformers/ParameterDecoratorTransformer.ts +143 -143
- package/src/transformers/ParameterTransformer.ts +57 -57
- package/src/transformers/TypedRouteTransformer.ts +85 -85
- package/src/transformers/WebSocketRouteTransformer.ts +120 -120
- package/src/typings/Creator.ts +3 -3
- package/src/typings/get-function-location.d.ts +7 -7
- package/src/utils/ArrayUtil.ts +7 -7
- package/src/utils/ExceptionManager.ts +115 -115
- package/src/utils/Singleton.ts +16 -16
- package/src/utils/SourceFinder.ts +54 -54
- package/src/utils/VersioningStrategy.ts +27 -27
|
@@ -1,63 +1,65 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
ts.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
category === "
|
|
58
|
-
category === "
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
1
|
+
import {
|
|
2
|
+
HttpAssertHeadersProgrammer,
|
|
3
|
+
HttpIsHeadersProgrammer,
|
|
4
|
+
HttpValidateHeadersProgrammer,
|
|
5
|
+
ITypiaContext,
|
|
6
|
+
} from "@typia/core";
|
|
7
|
+
import ts from "typescript";
|
|
8
|
+
|
|
9
|
+
import { INestiaTransformContext } from "../options/INestiaTransformProject";
|
|
10
|
+
import { IRequestHeadersValidator } from "../options/IRequestHeadersValidator";
|
|
11
|
+
|
|
12
|
+
export namespace TypedHeadersProgrammer {
|
|
13
|
+
export const generate = (props: {
|
|
14
|
+
context: INestiaTransformContext;
|
|
15
|
+
modulo: ts.LeftHandSideExpression;
|
|
16
|
+
type: ts.Type;
|
|
17
|
+
}): ts.Expression => {
|
|
18
|
+
// GENERATE VALIDATION PLAN
|
|
19
|
+
const parameter =
|
|
20
|
+
(key: IRequestHeadersValidator<any>["type"]) =>
|
|
21
|
+
(
|
|
22
|
+
programmer: (next: {
|
|
23
|
+
context: ITypiaContext;
|
|
24
|
+
modulo: ts.LeftHandSideExpression;
|
|
25
|
+
type: ts.Type;
|
|
26
|
+
name: string | undefined;
|
|
27
|
+
}) => ts.Expression,
|
|
28
|
+
) =>
|
|
29
|
+
ts.factory.createObjectLiteralExpression([
|
|
30
|
+
ts.factory.createPropertyAssignment(
|
|
31
|
+
ts.factory.createIdentifier("type"),
|
|
32
|
+
ts.factory.createStringLiteral(key),
|
|
33
|
+
),
|
|
34
|
+
ts.factory.createPropertyAssignment(
|
|
35
|
+
ts.factory.createIdentifier(key),
|
|
36
|
+
programmer({
|
|
37
|
+
context: {
|
|
38
|
+
...props.context,
|
|
39
|
+
options: {
|
|
40
|
+
numeric: false,
|
|
41
|
+
finite: false,
|
|
42
|
+
functional: false,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
modulo: props.modulo,
|
|
46
|
+
type: props.type,
|
|
47
|
+
name: undefined,
|
|
48
|
+
}),
|
|
49
|
+
),
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
// RETURNS
|
|
53
|
+
const category = props.context.options.validate;
|
|
54
|
+
if (category === "is" || category === "equals")
|
|
55
|
+
return parameter("is")(HttpIsHeadersProgrammer.write);
|
|
56
|
+
else if (
|
|
57
|
+
category === "validate" ||
|
|
58
|
+
category === "validateEquals" ||
|
|
59
|
+
category === "validateClone" ||
|
|
60
|
+
category === "validatePrune"
|
|
61
|
+
)
|
|
62
|
+
return parameter("validate")(HttpValidateHeadersProgrammer.write);
|
|
63
|
+
return parameter("assert")(HttpAssertHeadersProgrammer.write);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import { INestiaTransformContext } from "../options/INestiaTransformProject";
|
|
5
|
-
|
|
6
|
-
export namespace TypedParamProgrammer {
|
|
7
|
-
export const generate = (props: {
|
|
8
|
-
context: INestiaTransformContext;
|
|
9
|
-
modulo: ts.LeftHandSideExpression;
|
|
10
|
-
arguments: readonly ts.Expression[];
|
|
11
|
-
type: ts.Type;
|
|
12
|
-
}): readonly ts.Expression[] => {
|
|
13
|
-
// ALREADY BEING TRANSFORMED
|
|
14
|
-
if (props.arguments.length !== 1) return props.arguments;
|
|
15
|
-
return [
|
|
16
|
-
props.arguments[0]
|
|
17
|
-
HttpParameterProgrammer.write({
|
|
18
|
-
context: {
|
|
19
|
-
...props.context,
|
|
20
|
-
options: {
|
|
21
|
-
numeric: true,
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
modulo: props.modulo,
|
|
25
|
-
type: props.type,
|
|
26
|
-
name: undefined,
|
|
27
|
-
}),
|
|
28
|
-
...(props.context.options?.validate?.startsWith("validate")
|
|
29
|
-
? [ts.factory.createTrue()]
|
|
30
|
-
: []),
|
|
31
|
-
];
|
|
32
|
-
};
|
|
33
|
-
}
|
|
1
|
+
import { HttpParameterProgrammer } from "@typia/core";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
|
|
4
|
+
import { INestiaTransformContext } from "../options/INestiaTransformProject";
|
|
5
|
+
|
|
6
|
+
export namespace TypedParamProgrammer {
|
|
7
|
+
export const generate = (props: {
|
|
8
|
+
context: INestiaTransformContext;
|
|
9
|
+
modulo: ts.LeftHandSideExpression;
|
|
10
|
+
arguments: readonly ts.Expression[];
|
|
11
|
+
type: ts.Type;
|
|
12
|
+
}): readonly ts.Expression[] => {
|
|
13
|
+
// ALREADY BEING TRANSFORMED
|
|
14
|
+
if (props.arguments.length !== 1) return props.arguments;
|
|
15
|
+
return [
|
|
16
|
+
props.arguments[0]!,
|
|
17
|
+
HttpParameterProgrammer.write({
|
|
18
|
+
context: {
|
|
19
|
+
...props.context,
|
|
20
|
+
options: {
|
|
21
|
+
numeric: true,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
modulo: props.modulo,
|
|
25
|
+
type: props.type,
|
|
26
|
+
name: undefined,
|
|
27
|
+
}),
|
|
28
|
+
...(props.context.options?.validate?.startsWith("validate")
|
|
29
|
+
? [ts.factory.createTrue()]
|
|
30
|
+
: []),
|
|
31
|
+
];
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -1,109 +1,111 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
ts.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
category === "
|
|
104
|
-
category === "
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
1
|
+
import {
|
|
2
|
+
HttpAssertQueryProgrammer,
|
|
3
|
+
HttpIsQueryProgrammer,
|
|
4
|
+
HttpQueryProgrammer,
|
|
5
|
+
HttpValidateQueryProgrammer,
|
|
6
|
+
ITypiaContext,
|
|
7
|
+
LlmSchemaProgrammer,
|
|
8
|
+
MetadataCollection,
|
|
9
|
+
MetadataFactory,
|
|
10
|
+
MetadataSchema,
|
|
11
|
+
TransformerError,
|
|
12
|
+
} from "@typia/core";
|
|
13
|
+
import { ValidationPipe } from "@typia/interface";
|
|
14
|
+
import ts from "typescript";
|
|
15
|
+
|
|
16
|
+
import { INestiaTransformOptions } from "../options/INestiaTransformOptions";
|
|
17
|
+
import { INestiaTransformContext } from "../options/INestiaTransformProject";
|
|
18
|
+
import { IRequestQueryValidator } from "../options/IRequestQueryValidator";
|
|
19
|
+
|
|
20
|
+
export namespace TypedQueryBodyProgrammer {
|
|
21
|
+
export const generate = (props: {
|
|
22
|
+
context: INestiaTransformContext;
|
|
23
|
+
modulo: ts.LeftHandSideExpression;
|
|
24
|
+
type: ts.Type;
|
|
25
|
+
}): ts.ObjectLiteralExpression => {
|
|
26
|
+
// VALIDATE TYPE
|
|
27
|
+
if (props.context.options.llm) {
|
|
28
|
+
const llm: INestiaTransformOptions.ILlm = props.context.options.llm;
|
|
29
|
+
const result: ValidationPipe<MetadataSchema, MetadataFactory.IError> =
|
|
30
|
+
MetadataFactory.analyze({
|
|
31
|
+
checker: props.context.checker,
|
|
32
|
+
transformer: props.context.transformer,
|
|
33
|
+
options: {
|
|
34
|
+
escape: false,
|
|
35
|
+
constant: true,
|
|
36
|
+
absorb: true,
|
|
37
|
+
validate: (meta, explore) => {
|
|
38
|
+
const errors: string[] = HttpQueryProgrammer.validate(
|
|
39
|
+
meta,
|
|
40
|
+
explore,
|
|
41
|
+
true,
|
|
42
|
+
);
|
|
43
|
+
errors.push(
|
|
44
|
+
...LlmSchemaProgrammer.validate({
|
|
45
|
+
config: {
|
|
46
|
+
strict: llm.strict ?? false,
|
|
47
|
+
},
|
|
48
|
+
metadata: meta,
|
|
49
|
+
}),
|
|
50
|
+
);
|
|
51
|
+
return errors;
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
components: new MetadataCollection(),
|
|
55
|
+
type: props.type,
|
|
56
|
+
});
|
|
57
|
+
if (result.success === false)
|
|
58
|
+
throw TransformerError.from({
|
|
59
|
+
code: props.modulo.getText(),
|
|
60
|
+
errors: result.errors,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// GENERATE VALIDATION PLAN
|
|
65
|
+
const parameter =
|
|
66
|
+
(key: IRequestQueryValidator<any>["type"]) =>
|
|
67
|
+
(
|
|
68
|
+
programmer: (next: {
|
|
69
|
+
context: ITypiaContext;
|
|
70
|
+
modulo: ts.LeftHandSideExpression;
|
|
71
|
+
type: ts.Type;
|
|
72
|
+
name: string | undefined;
|
|
73
|
+
}) => ts.Expression,
|
|
74
|
+
) =>
|
|
75
|
+
ts.factory.createObjectLiteralExpression([
|
|
76
|
+
ts.factory.createPropertyAssignment(
|
|
77
|
+
ts.factory.createIdentifier("type"),
|
|
78
|
+
ts.factory.createStringLiteral(key),
|
|
79
|
+
),
|
|
80
|
+
ts.factory.createPropertyAssignment(
|
|
81
|
+
ts.factory.createIdentifier(key),
|
|
82
|
+
programmer({
|
|
83
|
+
context: {
|
|
84
|
+
...props.context,
|
|
85
|
+
options: {
|
|
86
|
+
numeric: false,
|
|
87
|
+
finite: false,
|
|
88
|
+
functional: false,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
modulo: props.modulo,
|
|
92
|
+
type: props.type,
|
|
93
|
+
name: undefined,
|
|
94
|
+
}),
|
|
95
|
+
),
|
|
96
|
+
]);
|
|
97
|
+
|
|
98
|
+
// RETURNS
|
|
99
|
+
const category = props.context.options.validate;
|
|
100
|
+
if (category === "is" || category === "equals")
|
|
101
|
+
return parameter("is")(HttpIsQueryProgrammer.write);
|
|
102
|
+
else if (
|
|
103
|
+
category === "validate" ||
|
|
104
|
+
category === "validateEquals" ||
|
|
105
|
+
category === "validateClone" ||
|
|
106
|
+
category === "validatePrune"
|
|
107
|
+
)
|
|
108
|
+
return parameter("validate")(HttpValidateQueryProgrammer.write);
|
|
109
|
+
return parameter("assert")(HttpAssertQueryProgrammer.write);
|
|
110
|
+
};
|
|
111
|
+
}
|
|
@@ -1,111 +1,113 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
ts.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
category === "
|
|
106
|
-
category === "
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
1
|
+
import {
|
|
2
|
+
HttpAssertQueryProgrammer,
|
|
3
|
+
HttpIsQueryProgrammer,
|
|
4
|
+
HttpQueryProgrammer,
|
|
5
|
+
HttpValidateQueryProgrammer,
|
|
6
|
+
ITypiaContext,
|
|
7
|
+
LlmSchemaProgrammer,
|
|
8
|
+
MetadataCollection,
|
|
9
|
+
MetadataFactory,
|
|
10
|
+
MetadataSchema,
|
|
11
|
+
TransformerError,
|
|
12
|
+
} from "@typia/core";
|
|
13
|
+
import { ValidationPipe } from "@typia/interface";
|
|
14
|
+
import ts from "typescript";
|
|
15
|
+
|
|
16
|
+
import { INestiaTransformOptions } from "../options/INestiaTransformOptions";
|
|
17
|
+
import { INestiaTransformContext } from "../options/INestiaTransformProject";
|
|
18
|
+
import { IRequestQueryValidator } from "../options/IRequestQueryValidator";
|
|
19
|
+
|
|
20
|
+
export namespace TypedQueryProgrammer {
|
|
21
|
+
export const generate = (props: {
|
|
22
|
+
context: INestiaTransformContext;
|
|
23
|
+
modulo: ts.LeftHandSideExpression;
|
|
24
|
+
type: ts.Type;
|
|
25
|
+
}): ts.Expression => {
|
|
26
|
+
// VALIDATE TYPE
|
|
27
|
+
if (props.context.options.llm) {
|
|
28
|
+
const llm: INestiaTransformOptions.ILlm = props.context.options.llm;
|
|
29
|
+
const result: ValidationPipe<MetadataSchema, MetadataFactory.IError> =
|
|
30
|
+
MetadataFactory.analyze({
|
|
31
|
+
checker: props.context.checker,
|
|
32
|
+
transformer: props.context.transformer,
|
|
33
|
+
options: {
|
|
34
|
+
escape: false,
|
|
35
|
+
constant: true,
|
|
36
|
+
absorb: true,
|
|
37
|
+
validate: (meta, explore) => {
|
|
38
|
+
const errors: string[] = HttpQueryProgrammer.validate(
|
|
39
|
+
meta,
|
|
40
|
+
explore,
|
|
41
|
+
true,
|
|
42
|
+
);
|
|
43
|
+
errors.push(
|
|
44
|
+
...LlmSchemaProgrammer.validate({
|
|
45
|
+
config: {
|
|
46
|
+
strict: llm.strict ?? false,
|
|
47
|
+
},
|
|
48
|
+
metadata: meta,
|
|
49
|
+
}),
|
|
50
|
+
);
|
|
51
|
+
return errors;
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
components: new MetadataCollection(),
|
|
55
|
+
type: props.type,
|
|
56
|
+
});
|
|
57
|
+
if (result.success === false)
|
|
58
|
+
throw TransformerError.from({
|
|
59
|
+
code: "@nestia.core.TypedQuery",
|
|
60
|
+
errors: result.errors,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// GENERATE VALIDATION PLAN
|
|
65
|
+
const parameter =
|
|
66
|
+
(key: IRequestQueryValidator<any>["type"]) =>
|
|
67
|
+
(
|
|
68
|
+
programmer: (next: {
|
|
69
|
+
context: ITypiaContext;
|
|
70
|
+
modulo: ts.LeftHandSideExpression;
|
|
71
|
+
type: ts.Type;
|
|
72
|
+
name: string | undefined;
|
|
73
|
+
allowOptional: boolean;
|
|
74
|
+
}) => ts.Expression,
|
|
75
|
+
) =>
|
|
76
|
+
ts.factory.createObjectLiteralExpression([
|
|
77
|
+
ts.factory.createPropertyAssignment(
|
|
78
|
+
ts.factory.createIdentifier("type"),
|
|
79
|
+
ts.factory.createStringLiteral(key),
|
|
80
|
+
),
|
|
81
|
+
ts.factory.createPropertyAssignment(
|
|
82
|
+
ts.factory.createIdentifier(key),
|
|
83
|
+
programmer({
|
|
84
|
+
context: {
|
|
85
|
+
...props.context,
|
|
86
|
+
options: {
|
|
87
|
+
numeric: false,
|
|
88
|
+
finite: false,
|
|
89
|
+
functional: false,
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
modulo: props.modulo,
|
|
93
|
+
type: props.type,
|
|
94
|
+
name: undefined,
|
|
95
|
+
allowOptional: true,
|
|
96
|
+
}),
|
|
97
|
+
),
|
|
98
|
+
]);
|
|
99
|
+
|
|
100
|
+
// RETURNS
|
|
101
|
+
const category = props.context.options.validate;
|
|
102
|
+
if (category === "is" || category === "equals")
|
|
103
|
+
return parameter("is")(HttpIsQueryProgrammer.write);
|
|
104
|
+
else if (
|
|
105
|
+
category === "validate" ||
|
|
106
|
+
category === "validateEquals" ||
|
|
107
|
+
category === "validateClone" ||
|
|
108
|
+
category === "validatePrune"
|
|
109
|
+
)
|
|
110
|
+
return parameter("validate")(HttpValidateQueryProgrammer.write);
|
|
111
|
+
return parameter("assert")(HttpAssertQueryProgrammer.write);
|
|
112
|
+
};
|
|
113
|
+
}
|