@nestia/core 10.0.1 → 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,142 +1,144 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
ts.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
ts.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
//----
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
else if (category === "
|
|
124
|
-
|
|
125
|
-
else if (category === "
|
|
126
|
-
return check("
|
|
127
|
-
else if (category === "
|
|
128
|
-
return check("
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
else if (category === "
|
|
133
|
-
return misc("
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
else if (category === "
|
|
138
|
-
return misc("
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
1
|
+
import {
|
|
2
|
+
AssertProgrammer,
|
|
3
|
+
ITypiaContext,
|
|
4
|
+
IsProgrammer,
|
|
5
|
+
JsonMetadataFactory,
|
|
6
|
+
LlmSchemaProgrammer,
|
|
7
|
+
MiscAssertCloneProgrammer,
|
|
8
|
+
MiscAssertPruneProgrammer,
|
|
9
|
+
MiscValidateCloneProgrammer,
|
|
10
|
+
MiscValidatePruneProgrammer,
|
|
11
|
+
ValidateProgrammer,
|
|
12
|
+
} from "@typia/core";
|
|
13
|
+
import ts from "typescript";
|
|
14
|
+
|
|
15
|
+
import { INestiaTransformContext } from "../options/INestiaTransformProject";
|
|
16
|
+
import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
|
|
17
|
+
|
|
18
|
+
export namespace TypedBodyProgrammer {
|
|
19
|
+
export const generate = (props: {
|
|
20
|
+
context: INestiaTransformContext;
|
|
21
|
+
modulo: ts.LeftHandSideExpression;
|
|
22
|
+
type: ts.Type;
|
|
23
|
+
}): ts.ObjectLiteralExpression => {
|
|
24
|
+
// VALIDATE TYPE
|
|
25
|
+
JsonMetadataFactory.analyze({
|
|
26
|
+
method: "@nestia.core.TypedBody",
|
|
27
|
+
checker: props.context.checker,
|
|
28
|
+
transformer: props.context.transformer,
|
|
29
|
+
type: props.type,
|
|
30
|
+
validate: props.context.options.llm
|
|
31
|
+
? (metadata) =>
|
|
32
|
+
LlmSchemaProgrammer.validate({
|
|
33
|
+
config: {
|
|
34
|
+
strict: props.context.options.llm?.strict ?? false,
|
|
35
|
+
},
|
|
36
|
+
metadata,
|
|
37
|
+
})
|
|
38
|
+
: undefined,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// GENERATE VALIDATION PLAN
|
|
42
|
+
const check =
|
|
43
|
+
(key: IRequestBodyValidator<any>["type"]) =>
|
|
44
|
+
(equals: boolean) =>
|
|
45
|
+
(
|
|
46
|
+
programmer: (next: {
|
|
47
|
+
context: ITypiaContext;
|
|
48
|
+
modulo: ts.LeftHandSideExpression;
|
|
49
|
+
config: {
|
|
50
|
+
equals: boolean;
|
|
51
|
+
guard: boolean;
|
|
52
|
+
};
|
|
53
|
+
type: ts.Type;
|
|
54
|
+
name: string | undefined;
|
|
55
|
+
}) => ts.Expression,
|
|
56
|
+
) =>
|
|
57
|
+
ts.factory.createObjectLiteralExpression([
|
|
58
|
+
ts.factory.createPropertyAssignment(
|
|
59
|
+
ts.factory.createIdentifier("type"),
|
|
60
|
+
ts.factory.createStringLiteral(key),
|
|
61
|
+
),
|
|
62
|
+
ts.factory.createPropertyAssignment(
|
|
63
|
+
ts.factory.createIdentifier(key),
|
|
64
|
+
programmer({
|
|
65
|
+
context: {
|
|
66
|
+
...props.context,
|
|
67
|
+
options: {
|
|
68
|
+
numeric: false,
|
|
69
|
+
finite: false,
|
|
70
|
+
functional: false,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
modulo: props.modulo,
|
|
74
|
+
config: {
|
|
75
|
+
equals,
|
|
76
|
+
guard: false,
|
|
77
|
+
},
|
|
78
|
+
type: props.type,
|
|
79
|
+
name: undefined,
|
|
80
|
+
}),
|
|
81
|
+
),
|
|
82
|
+
]);
|
|
83
|
+
const misc =
|
|
84
|
+
(key: IRequestBodyValidator<any>["type"]) =>
|
|
85
|
+
(
|
|
86
|
+
programmer: (next: {
|
|
87
|
+
context: ITypiaContext;
|
|
88
|
+
modulo: ts.LeftHandSideExpression;
|
|
89
|
+
type: ts.Type;
|
|
90
|
+
name: string | undefined;
|
|
91
|
+
}) => ts.Expression,
|
|
92
|
+
) =>
|
|
93
|
+
ts.factory.createObjectLiteralExpression([
|
|
94
|
+
ts.factory.createPropertyAssignment(
|
|
95
|
+
ts.factory.createIdentifier("type"),
|
|
96
|
+
ts.factory.createStringLiteral(key),
|
|
97
|
+
),
|
|
98
|
+
ts.factory.createPropertyAssignment(
|
|
99
|
+
ts.factory.createIdentifier(key),
|
|
100
|
+
programmer({
|
|
101
|
+
context: {
|
|
102
|
+
...props.context,
|
|
103
|
+
options: {
|
|
104
|
+
numeric: false,
|
|
105
|
+
finite: false,
|
|
106
|
+
functional: false,
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
modulo: props.modulo,
|
|
110
|
+
type: props.type,
|
|
111
|
+
name: undefined,
|
|
112
|
+
}),
|
|
113
|
+
),
|
|
114
|
+
]);
|
|
115
|
+
|
|
116
|
+
//----
|
|
117
|
+
// RETURNS
|
|
118
|
+
//----
|
|
119
|
+
const category = props.context.options.validate;
|
|
120
|
+
// NORMAL
|
|
121
|
+
if (category === "assert")
|
|
122
|
+
return check("assert")(false)(AssertProgrammer.write);
|
|
123
|
+
else if (category === "is") return check("is")(false)(IsProgrammer.write);
|
|
124
|
+
// STRICT
|
|
125
|
+
else if (category === "validateEquals")
|
|
126
|
+
return check("validate")(true)(ValidateProgrammer.write);
|
|
127
|
+
else if (category === "equals")
|
|
128
|
+
return check("is")(true)(IsProgrammer.write);
|
|
129
|
+
else if (category === "assertEquals")
|
|
130
|
+
return check("assert")(true)(AssertProgrammer.write);
|
|
131
|
+
// CLONE
|
|
132
|
+
else if (category === "assertClone")
|
|
133
|
+
return misc("assert")(MiscAssertCloneProgrammer.write);
|
|
134
|
+
else if (category === "validateClone")
|
|
135
|
+
return misc("validate")(MiscValidateCloneProgrammer.write);
|
|
136
|
+
// PRUNE
|
|
137
|
+
else if (category === "assertPrune")
|
|
138
|
+
return misc("assert")(MiscAssertPruneProgrammer.write);
|
|
139
|
+
else if (category === "validatePrune")
|
|
140
|
+
return misc("validate")(MiscValidatePruneProgrammer.write);
|
|
141
|
+
// DEFAULT
|
|
142
|
+
return check("validate")(false)(ValidateProgrammer.write);
|
|
143
|
+
};
|
|
144
|
+
}
|
|
@@ -1,118 +1,118 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
// GENERATE VALIDATION PLAN
|
|
54
|
-
const parameter =
|
|
55
|
-
(key: IRequestFormDataProps<any>["validator"]["type"]) =>
|
|
56
|
-
(
|
|
57
|
-
programmer: (next: {
|
|
58
|
-
context: ITypiaContext;
|
|
59
|
-
modulo: ts.LeftHandSideExpression;
|
|
60
|
-
type: ts.Type;
|
|
61
|
-
name: string | undefined;
|
|
62
|
-
}) => ts.Expression,
|
|
63
|
-
) =>
|
|
64
|
-
ts.factory.createObjectLiteralExpression(
|
|
65
|
-
[
|
|
66
|
-
ts.factory.createPropertyAssignment(
|
|
67
|
-
ts.factory.createIdentifier("files"),
|
|
68
|
-
LiteralFactory.write(files),
|
|
69
|
-
),
|
|
70
|
-
ts.factory.createPropertyAssignment(
|
|
71
|
-
ts.factory.createIdentifier("validator"),
|
|
72
|
-
ts.factory.createObjectLiteralExpression(
|
|
73
|
-
[
|
|
74
|
-
ts.factory.createPropertyAssignment(
|
|
75
|
-
ts.factory.createIdentifier("type"),
|
|
76
|
-
ts.factory.createStringLiteral(key),
|
|
77
|
-
),
|
|
78
|
-
ts.factory.createPropertyAssignment(
|
|
79
|
-
ts.factory.createIdentifier(key),
|
|
80
|
-
programmer({
|
|
81
|
-
context: {
|
|
82
|
-
...props.context,
|
|
83
|
-
options: {
|
|
84
|
-
numeric: false,
|
|
85
|
-
finite: false,
|
|
86
|
-
functional: false,
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
modulo: props.modulo,
|
|
90
|
-
type: props.type,
|
|
91
|
-
name: undefined,
|
|
92
|
-
}),
|
|
93
|
-
),
|
|
94
|
-
],
|
|
95
|
-
true,
|
|
96
|
-
),
|
|
97
|
-
),
|
|
98
|
-
],
|
|
99
|
-
true,
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
// RETURNS
|
|
103
|
-
const category = props.context.options.validate;
|
|
104
|
-
if (category === "is" || category === "equals")
|
|
105
|
-
return parameter("is")(HttpIsFormDataProgrammer.write);
|
|
106
|
-
else if (
|
|
107
|
-
category === "validate" ||
|
|
108
|
-
category === "validateEquals" ||
|
|
109
|
-
category === "validateClone" ||
|
|
110
|
-
category === "validatePrune"
|
|
111
|
-
)
|
|
112
|
-
return parameter("validate")(HttpValidateFormDataProgrammer.write);
|
|
113
|
-
return parameter("assert")(HttpAssertFormDataProgrammer.write);
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const isFile = (meta:
|
|
118
|
-
meta.natives.some(({ name }) => name === "File" || name === "Blob");
|
|
1
|
+
import {
|
|
2
|
+
HttpAssertFormDataProgrammer,
|
|
3
|
+
HttpFormDataProgrammer,
|
|
4
|
+
HttpIsFormDataProgrammer,
|
|
5
|
+
HttpValidateFormDataProgrammer,
|
|
6
|
+
ITypiaContext,
|
|
7
|
+
LiteralFactory,
|
|
8
|
+
MetadataCollection,
|
|
9
|
+
MetadataFactory,
|
|
10
|
+
MetadataSchema,
|
|
11
|
+
TransformerError,
|
|
12
|
+
} from "@typia/core";
|
|
13
|
+
import ts from "typescript";
|
|
14
|
+
|
|
15
|
+
import { INestiaTransformContext } from "../options/INestiaTransformProject";
|
|
16
|
+
import { IRequestFormDataProps } from "../options/IRequestFormDataProps";
|
|
17
|
+
|
|
18
|
+
export namespace TypedFormDataBodyProgrammer {
|
|
19
|
+
export const generate = (props: {
|
|
20
|
+
context: INestiaTransformContext;
|
|
21
|
+
modulo: ts.LeftHandSideExpression;
|
|
22
|
+
type: ts.Type;
|
|
23
|
+
}): ts.ObjectLiteralExpression => {
|
|
24
|
+
// VALIDATE TYPE
|
|
25
|
+
const storage: MetadataCollection = new MetadataCollection();
|
|
26
|
+
const result = MetadataFactory.analyze({
|
|
27
|
+
checker: props.context.checker,
|
|
28
|
+
transformer: props.context.transformer,
|
|
29
|
+
options: {
|
|
30
|
+
escape: false,
|
|
31
|
+
constant: true,
|
|
32
|
+
absorb: true,
|
|
33
|
+
validate: HttpFormDataProgrammer.validate,
|
|
34
|
+
},
|
|
35
|
+
type: props.type,
|
|
36
|
+
components: storage,
|
|
37
|
+
});
|
|
38
|
+
if (result.success === false)
|
|
39
|
+
throw TransformerError.from({
|
|
40
|
+
code: "nestia.core.TypedFormData.Body",
|
|
41
|
+
errors: result.errors,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const files: IRequestFormDataProps.IFile[] =
|
|
45
|
+
result.data.objects[0]!.type.properties.filter(
|
|
46
|
+
(p) =>
|
|
47
|
+
isFile(p.value) || p.value.arrays.some((a) => isFile(a.type.value)),
|
|
48
|
+
).map((p) => ({
|
|
49
|
+
name: p.key.constants[0]!.values[0]!.value as string,
|
|
50
|
+
limit: !!p.value.natives.length ? 1 : null,
|
|
51
|
+
}));
|
|
52
|
+
|
|
53
|
+
// GENERATE VALIDATION PLAN
|
|
54
|
+
const parameter =
|
|
55
|
+
(key: IRequestFormDataProps<any>["validator"]["type"]) =>
|
|
56
|
+
(
|
|
57
|
+
programmer: (next: {
|
|
58
|
+
context: ITypiaContext;
|
|
59
|
+
modulo: ts.LeftHandSideExpression;
|
|
60
|
+
type: ts.Type;
|
|
61
|
+
name: string | undefined;
|
|
62
|
+
}) => ts.Expression,
|
|
63
|
+
) =>
|
|
64
|
+
ts.factory.createObjectLiteralExpression(
|
|
65
|
+
[
|
|
66
|
+
ts.factory.createPropertyAssignment(
|
|
67
|
+
ts.factory.createIdentifier("files"),
|
|
68
|
+
LiteralFactory.write(files),
|
|
69
|
+
),
|
|
70
|
+
ts.factory.createPropertyAssignment(
|
|
71
|
+
ts.factory.createIdentifier("validator"),
|
|
72
|
+
ts.factory.createObjectLiteralExpression(
|
|
73
|
+
[
|
|
74
|
+
ts.factory.createPropertyAssignment(
|
|
75
|
+
ts.factory.createIdentifier("type"),
|
|
76
|
+
ts.factory.createStringLiteral(key),
|
|
77
|
+
),
|
|
78
|
+
ts.factory.createPropertyAssignment(
|
|
79
|
+
ts.factory.createIdentifier(key),
|
|
80
|
+
programmer({
|
|
81
|
+
context: {
|
|
82
|
+
...props.context,
|
|
83
|
+
options: {
|
|
84
|
+
numeric: false,
|
|
85
|
+
finite: false,
|
|
86
|
+
functional: false,
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
modulo: props.modulo,
|
|
90
|
+
type: props.type,
|
|
91
|
+
name: undefined,
|
|
92
|
+
}),
|
|
93
|
+
),
|
|
94
|
+
],
|
|
95
|
+
true,
|
|
96
|
+
),
|
|
97
|
+
),
|
|
98
|
+
],
|
|
99
|
+
true,
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
// RETURNS
|
|
103
|
+
const category = props.context.options.validate;
|
|
104
|
+
if (category === "is" || category === "equals")
|
|
105
|
+
return parameter("is")(HttpIsFormDataProgrammer.write);
|
|
106
|
+
else if (
|
|
107
|
+
category === "validate" ||
|
|
108
|
+
category === "validateEquals" ||
|
|
109
|
+
category === "validateClone" ||
|
|
110
|
+
category === "validatePrune"
|
|
111
|
+
)
|
|
112
|
+
return parameter("validate")(HttpValidateFormDataProgrammer.write);
|
|
113
|
+
return parameter("assert")(HttpAssertFormDataProgrammer.write);
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const isFile = (meta: MetadataSchema) =>
|
|
118
|
+
meta.natives.some(({ name }) => name === "File" || name === "Blob");
|