@nestia/core 7.0.0-dev.20250607 → 7.0.0
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 +92 -92
- package/package.json +3 -3
- package/src/adaptors/WebSocketAdaptor.ts +429 -429
- package/src/decorators/DynamicModule.ts +43 -43
- package/src/decorators/EncryptedBody.ts +101 -101
- package/src/decorators/EncryptedController.ts +38 -38
- package/src/decorators/EncryptedModule.ts +100 -100
- package/src/decorators/EncryptedRoute.ts +219 -219
- package/src/decorators/HumanRoute.ts +22 -22
- package/src/decorators/NoTransformConfigurationError.ts +32 -32
- package/src/decorators/PlainBody.ts +79 -79
- package/src/decorators/SwaggerCustomizer.ts +115 -115
- package/src/decorators/SwaggerExample.ts +100 -100
- package/src/decorators/TypedBody.ts +59 -59
- package/src/decorators/TypedException.ts +166 -166
- package/src/decorators/TypedFormData.ts +195 -195
- package/src/decorators/TypedHeaders.ts +64 -64
- package/src/decorators/TypedParam.ts +77 -77
- package/src/decorators/TypedQuery.ts +245 -245
- package/src/decorators/TypedRoute.ts +214 -214
- package/src/decorators/WebSocketRoute.ts +242 -242
- package/src/decorators/internal/EncryptedConstant.ts +4 -4
- 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 +108 -108
- package/src/decorators/internal/get_path_and_stringify.ts +122 -122
- package/src/decorators/internal/get_text_body.ts +20 -20
- package/src/decorators/internal/headers_to_object.ts +13 -13
- package/src/decorators/internal/is_request_body_undefined.ts +14 -14
- package/src/decorators/internal/load_controller.ts +49 -49
- package/src/decorators/internal/route_error.ts +45 -45
- package/src/decorators/internal/validate_request_body.ts +74 -74
- package/src/decorators/internal/validate_request_form_data.ts +77 -77
- package/src/decorators/internal/validate_request_headers.ts +86 -86
- package/src/decorators/internal/validate_request_query.ts +74 -74
- package/src/index.ts +5 -5
- package/src/module.ts +22 -22
- package/src/options/INestiaTransformOptions.ts +38 -38
- package/src/options/INestiaTransformProject.ts +8 -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 +70 -70
- package/src/programmers/TypedBodyProgrammer.ts +142 -142
- package/src/programmers/TypedFormDataBodyProgrammer.ts +118 -118
- package/src/programmers/TypedHeadersProgrammer.ts +63 -63
- package/src/programmers/TypedParamProgrammer.ts +33 -33
- package/src/programmers/TypedQueryBodyProgrammer.ts +112 -112
- package/src/programmers/TypedQueryProgrammer.ts +114 -114
- package/src/programmers/TypedQueryRouteProgrammer.ts +105 -105
- package/src/programmers/TypedRouteProgrammer.ts +94 -94
- package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +72 -72
- package/src/programmers/http/HttpIsQuerifyProgrammer.ts +75 -75
- package/src/programmers/http/HttpQuerifyProgrammer.ts +108 -108
- package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +76 -76
- package/src/programmers/internal/CoreMetadataUtil.ts +21 -21
- package/src/transform.ts +35 -35
- package/src/transformers/FileTransformer.ts +110 -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 +112 -112
- package/src/utils/Singleton.ts +20 -20
- package/src/utils/SourceFinder.ts +57 -57
- package/src/utils/VersioningStrategy.ts +27 -27
|
@@ -1,70 +1,70 @@
|
|
|
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 { INestiaTransformContext } from "../options/INestiaTransformProject";
|
|
9
|
-
|
|
10
|
-
export namespace PlainBodyProgrammer {
|
|
11
|
-
export const generate = (props: {
|
|
12
|
-
context: INestiaTransformContext;
|
|
13
|
-
modulo: ts.LeftHandSideExpression;
|
|
14
|
-
type: ts.Type;
|
|
15
|
-
}): ts.Expression => {
|
|
16
|
-
const result = MetadataFactory.analyze({
|
|
17
|
-
checker: props.context.checker,
|
|
18
|
-
transformer: props.context.transformer,
|
|
19
|
-
options: {
|
|
20
|
-
escape: false,
|
|
21
|
-
constant: true,
|
|
22
|
-
absorb: true,
|
|
23
|
-
validate,
|
|
24
|
-
},
|
|
25
|
-
collection: new MetadataCollection(),
|
|
26
|
-
type: props.type,
|
|
27
|
-
});
|
|
28
|
-
if (result.success === false)
|
|
29
|
-
throw TransformerError.from({
|
|
30
|
-
code: "nestia.core.TypedParam",
|
|
31
|
-
errors: result.errors,
|
|
32
|
-
});
|
|
33
|
-
return AssertProgrammer.write({
|
|
34
|
-
context: {
|
|
35
|
-
...props.context,
|
|
36
|
-
options: {
|
|
37
|
-
numeric: false,
|
|
38
|
-
finite: false,
|
|
39
|
-
functional: false,
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
modulo: props.modulo,
|
|
43
|
-
config: {
|
|
44
|
-
equals: false,
|
|
45
|
-
guard: false,
|
|
46
|
-
},
|
|
47
|
-
type: props.type,
|
|
48
|
-
name: undefined,
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const validate = (metadata: Metadata): string[] => {
|
|
54
|
-
const errors: string[] = [];
|
|
55
|
-
const insert = (msg: string) => errors.push(msg);
|
|
56
|
-
|
|
57
|
-
const expected: number =
|
|
58
|
-
(metadata.atomics.some((a) => a.type === "string") ? 1 : 0) +
|
|
59
|
-
metadata.templates.length +
|
|
60
|
-
metadata.constants
|
|
61
|
-
.filter((c) => c.type === "string")
|
|
62
|
-
.map((c) => c.values.length)
|
|
63
|
-
.reduce((a, b) => a + b, 0);
|
|
64
|
-
if (expected === 0 || expected !== metadata.size())
|
|
65
|
-
insert(`only string type is allowed`);
|
|
66
|
-
if (metadata.nullable === true) insert(`do not allow nullable type`);
|
|
67
|
-
else if (metadata.any === true) insert(`do not allow any type`);
|
|
68
|
-
|
|
69
|
-
return errors;
|
|
70
|
-
};
|
|
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 { INestiaTransformContext } from "../options/INestiaTransformProject";
|
|
9
|
+
|
|
10
|
+
export namespace PlainBodyProgrammer {
|
|
11
|
+
export const generate = (props: {
|
|
12
|
+
context: INestiaTransformContext;
|
|
13
|
+
modulo: ts.LeftHandSideExpression;
|
|
14
|
+
type: ts.Type;
|
|
15
|
+
}): ts.Expression => {
|
|
16
|
+
const result = MetadataFactory.analyze({
|
|
17
|
+
checker: props.context.checker,
|
|
18
|
+
transformer: props.context.transformer,
|
|
19
|
+
options: {
|
|
20
|
+
escape: false,
|
|
21
|
+
constant: true,
|
|
22
|
+
absorb: true,
|
|
23
|
+
validate,
|
|
24
|
+
},
|
|
25
|
+
collection: new MetadataCollection(),
|
|
26
|
+
type: props.type,
|
|
27
|
+
});
|
|
28
|
+
if (result.success === false)
|
|
29
|
+
throw TransformerError.from({
|
|
30
|
+
code: "nestia.core.TypedParam",
|
|
31
|
+
errors: result.errors,
|
|
32
|
+
});
|
|
33
|
+
return AssertProgrammer.write({
|
|
34
|
+
context: {
|
|
35
|
+
...props.context,
|
|
36
|
+
options: {
|
|
37
|
+
numeric: false,
|
|
38
|
+
finite: false,
|
|
39
|
+
functional: false,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
modulo: props.modulo,
|
|
43
|
+
config: {
|
|
44
|
+
equals: false,
|
|
45
|
+
guard: false,
|
|
46
|
+
},
|
|
47
|
+
type: props.type,
|
|
48
|
+
name: undefined,
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const validate = (metadata: Metadata): string[] => {
|
|
54
|
+
const errors: string[] = [];
|
|
55
|
+
const insert = (msg: string) => errors.push(msg);
|
|
56
|
+
|
|
57
|
+
const expected: number =
|
|
58
|
+
(metadata.atomics.some((a) => a.type === "string") ? 1 : 0) +
|
|
59
|
+
metadata.templates.length +
|
|
60
|
+
metadata.constants
|
|
61
|
+
.filter((c) => c.type === "string")
|
|
62
|
+
.map((c) => c.values.length)
|
|
63
|
+
.reduce((a, b) => a + b, 0);
|
|
64
|
+
if (expected === 0 || expected !== metadata.size())
|
|
65
|
+
insert(`only string type is allowed`);
|
|
66
|
+
if (metadata.nullable === true) insert(`do not allow nullable type`);
|
|
67
|
+
else if (metadata.any === true) insert(`do not allow any type`);
|
|
68
|
+
|
|
69
|
+
return errors;
|
|
70
|
+
};
|
|
@@ -1,142 +1,142 @@
|
|
|
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 { LlmSchemaProgrammer } from "typia/lib/programmers/llm/LlmSchemaProgrammer";
|
|
7
|
-
import { MiscAssertCloneProgrammer } from "typia/lib/programmers/misc/MiscAssertCloneProgrammer";
|
|
8
|
-
import { MiscAssertPruneProgrammer } from "typia/lib/programmers/misc/MiscAssertPruneProgrammer";
|
|
9
|
-
import { MiscValidateCloneProgrammer } from "typia/lib/programmers/misc/MiscValidateCloneProgrammer";
|
|
10
|
-
import { MiscValidatePruneProgrammer } from "typia/lib/programmers/misc/MiscValidatePruneProgrammer";
|
|
11
|
-
import { ITypiaContext } from "typia/lib/transformers/ITypiaContext";
|
|
12
|
-
|
|
13
|
-
import { INestiaTransformContext } from "../options/INestiaTransformProject";
|
|
14
|
-
import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
|
|
15
|
-
|
|
16
|
-
export namespace TypedBodyProgrammer {
|
|
17
|
-
export const generate = (props: {
|
|
18
|
-
context: INestiaTransformContext;
|
|
19
|
-
modulo: ts.LeftHandSideExpression;
|
|
20
|
-
type: ts.Type;
|
|
21
|
-
}): ts.ObjectLiteralExpression => {
|
|
22
|
-
// VALIDATE TYPE
|
|
23
|
-
JsonMetadataFactory.analyze({
|
|
24
|
-
method: "@nestia.core.TypedBody",
|
|
25
|
-
checker: props.context.checker,
|
|
26
|
-
transformer: props.context.transformer,
|
|
27
|
-
type: props.type,
|
|
28
|
-
validate: props.context.options.llm
|
|
29
|
-
? LlmSchemaProgrammer.validate({
|
|
30
|
-
model: props.context.options.llm.model,
|
|
31
|
-
config: {
|
|
32
|
-
strict: props.context.options.llm.strict,
|
|
33
|
-
recursive: props.context.options.llm.recursive,
|
|
34
|
-
},
|
|
35
|
-
})
|
|
36
|
-
: undefined,
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
// GENERATE VALIDATION PLAN
|
|
40
|
-
const check =
|
|
41
|
-
(key: IRequestBodyValidator<any>["type"]) =>
|
|
42
|
-
(equals: boolean) =>
|
|
43
|
-
(
|
|
44
|
-
programmer: (next: {
|
|
45
|
-
context: ITypiaContext;
|
|
46
|
-
modulo: ts.LeftHandSideExpression;
|
|
47
|
-
config: {
|
|
48
|
-
equals: boolean;
|
|
49
|
-
guard: boolean;
|
|
50
|
-
};
|
|
51
|
-
type: ts.Type;
|
|
52
|
-
name: string | undefined;
|
|
53
|
-
}) => ts.Expression,
|
|
54
|
-
) =>
|
|
55
|
-
ts.factory.createObjectLiteralExpression([
|
|
56
|
-
ts.factory.createPropertyAssignment(
|
|
57
|
-
ts.factory.createIdentifier("type"),
|
|
58
|
-
ts.factory.createStringLiteral(key),
|
|
59
|
-
),
|
|
60
|
-
ts.factory.createPropertyAssignment(
|
|
61
|
-
ts.factory.createIdentifier(key),
|
|
62
|
-
programmer({
|
|
63
|
-
context: {
|
|
64
|
-
...props.context,
|
|
65
|
-
options: {
|
|
66
|
-
numeric: false,
|
|
67
|
-
finite: false,
|
|
68
|
-
functional: false,
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
modulo: props.modulo,
|
|
72
|
-
config: {
|
|
73
|
-
equals,
|
|
74
|
-
guard: false,
|
|
75
|
-
},
|
|
76
|
-
type: props.type,
|
|
77
|
-
name: undefined,
|
|
78
|
-
}),
|
|
79
|
-
),
|
|
80
|
-
]);
|
|
81
|
-
const misc =
|
|
82
|
-
(key: IRequestBodyValidator<any>["type"]) =>
|
|
83
|
-
(
|
|
84
|
-
programmer: (next: {
|
|
85
|
-
context: ITypiaContext;
|
|
86
|
-
modulo: ts.LeftHandSideExpression;
|
|
87
|
-
type: ts.Type;
|
|
88
|
-
name: string | undefined;
|
|
89
|
-
}) => ts.Expression,
|
|
90
|
-
) =>
|
|
91
|
-
ts.factory.createObjectLiteralExpression([
|
|
92
|
-
ts.factory.createPropertyAssignment(
|
|
93
|
-
ts.factory.createIdentifier("type"),
|
|
94
|
-
ts.factory.createStringLiteral(key),
|
|
95
|
-
),
|
|
96
|
-
ts.factory.createPropertyAssignment(
|
|
97
|
-
ts.factory.createIdentifier(key),
|
|
98
|
-
programmer({
|
|
99
|
-
context: {
|
|
100
|
-
...props.context,
|
|
101
|
-
options: {
|
|
102
|
-
numeric: false,
|
|
103
|
-
finite: false,
|
|
104
|
-
functional: false,
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
modulo: props.modulo,
|
|
108
|
-
type: props.type,
|
|
109
|
-
name: undefined,
|
|
110
|
-
}),
|
|
111
|
-
),
|
|
112
|
-
]);
|
|
113
|
-
|
|
114
|
-
//----
|
|
115
|
-
// RETURNS
|
|
116
|
-
//----
|
|
117
|
-
const category = props.context.options.validate;
|
|
118
|
-
// NORMAL
|
|
119
|
-
if (category === "assert")
|
|
120
|
-
return check("assert")(false)(AssertProgrammer.write);
|
|
121
|
-
else if (category === "is") return check("is")(false)(IsProgrammer.write);
|
|
122
|
-
// STRICT
|
|
123
|
-
else if (category === "validateEquals")
|
|
124
|
-
return check("validate")(true)(ValidateProgrammer.write);
|
|
125
|
-
else if (category === "equals")
|
|
126
|
-
return check("is")(true)(IsProgrammer.write);
|
|
127
|
-
else if (category === "assertEquals")
|
|
128
|
-
return check("assert")(true)(AssertProgrammer.write);
|
|
129
|
-
// CLONE
|
|
130
|
-
else if (category === "assertClone")
|
|
131
|
-
return misc("assert")(MiscAssertCloneProgrammer.write);
|
|
132
|
-
else if (category === "validateClone")
|
|
133
|
-
return misc("validate")(MiscValidateCloneProgrammer.write);
|
|
134
|
-
// PRUNE
|
|
135
|
-
else if (category === "assertPrune")
|
|
136
|
-
return misc("assert")(MiscAssertPruneProgrammer.write);
|
|
137
|
-
else if (category === "validatePrune")
|
|
138
|
-
return misc("validate")(MiscValidatePruneProgrammer.write);
|
|
139
|
-
// DEFAULT
|
|
140
|
-
return check("validate")(false)(ValidateProgrammer.write);
|
|
141
|
-
};
|
|
142
|
-
}
|
|
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 { LlmSchemaProgrammer } from "typia/lib/programmers/llm/LlmSchemaProgrammer";
|
|
7
|
+
import { MiscAssertCloneProgrammer } from "typia/lib/programmers/misc/MiscAssertCloneProgrammer";
|
|
8
|
+
import { MiscAssertPruneProgrammer } from "typia/lib/programmers/misc/MiscAssertPruneProgrammer";
|
|
9
|
+
import { MiscValidateCloneProgrammer } from "typia/lib/programmers/misc/MiscValidateCloneProgrammer";
|
|
10
|
+
import { MiscValidatePruneProgrammer } from "typia/lib/programmers/misc/MiscValidatePruneProgrammer";
|
|
11
|
+
import { ITypiaContext } from "typia/lib/transformers/ITypiaContext";
|
|
12
|
+
|
|
13
|
+
import { INestiaTransformContext } from "../options/INestiaTransformProject";
|
|
14
|
+
import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
|
|
15
|
+
|
|
16
|
+
export namespace TypedBodyProgrammer {
|
|
17
|
+
export const generate = (props: {
|
|
18
|
+
context: INestiaTransformContext;
|
|
19
|
+
modulo: ts.LeftHandSideExpression;
|
|
20
|
+
type: ts.Type;
|
|
21
|
+
}): ts.ObjectLiteralExpression => {
|
|
22
|
+
// VALIDATE TYPE
|
|
23
|
+
JsonMetadataFactory.analyze({
|
|
24
|
+
method: "@nestia.core.TypedBody",
|
|
25
|
+
checker: props.context.checker,
|
|
26
|
+
transformer: props.context.transformer,
|
|
27
|
+
type: props.type,
|
|
28
|
+
validate: props.context.options.llm
|
|
29
|
+
? LlmSchemaProgrammer.validate({
|
|
30
|
+
model: props.context.options.llm.model,
|
|
31
|
+
config: {
|
|
32
|
+
strict: props.context.options.llm.strict,
|
|
33
|
+
recursive: props.context.options.llm.recursive,
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
: undefined,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// GENERATE VALIDATION PLAN
|
|
40
|
+
const check =
|
|
41
|
+
(key: IRequestBodyValidator<any>["type"]) =>
|
|
42
|
+
(equals: boolean) =>
|
|
43
|
+
(
|
|
44
|
+
programmer: (next: {
|
|
45
|
+
context: ITypiaContext;
|
|
46
|
+
modulo: ts.LeftHandSideExpression;
|
|
47
|
+
config: {
|
|
48
|
+
equals: boolean;
|
|
49
|
+
guard: boolean;
|
|
50
|
+
};
|
|
51
|
+
type: ts.Type;
|
|
52
|
+
name: string | undefined;
|
|
53
|
+
}) => ts.Expression,
|
|
54
|
+
) =>
|
|
55
|
+
ts.factory.createObjectLiteralExpression([
|
|
56
|
+
ts.factory.createPropertyAssignment(
|
|
57
|
+
ts.factory.createIdentifier("type"),
|
|
58
|
+
ts.factory.createStringLiteral(key),
|
|
59
|
+
),
|
|
60
|
+
ts.factory.createPropertyAssignment(
|
|
61
|
+
ts.factory.createIdentifier(key),
|
|
62
|
+
programmer({
|
|
63
|
+
context: {
|
|
64
|
+
...props.context,
|
|
65
|
+
options: {
|
|
66
|
+
numeric: false,
|
|
67
|
+
finite: false,
|
|
68
|
+
functional: false,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
modulo: props.modulo,
|
|
72
|
+
config: {
|
|
73
|
+
equals,
|
|
74
|
+
guard: false,
|
|
75
|
+
},
|
|
76
|
+
type: props.type,
|
|
77
|
+
name: undefined,
|
|
78
|
+
}),
|
|
79
|
+
),
|
|
80
|
+
]);
|
|
81
|
+
const misc =
|
|
82
|
+
(key: IRequestBodyValidator<any>["type"]) =>
|
|
83
|
+
(
|
|
84
|
+
programmer: (next: {
|
|
85
|
+
context: ITypiaContext;
|
|
86
|
+
modulo: ts.LeftHandSideExpression;
|
|
87
|
+
type: ts.Type;
|
|
88
|
+
name: string | undefined;
|
|
89
|
+
}) => ts.Expression,
|
|
90
|
+
) =>
|
|
91
|
+
ts.factory.createObjectLiteralExpression([
|
|
92
|
+
ts.factory.createPropertyAssignment(
|
|
93
|
+
ts.factory.createIdentifier("type"),
|
|
94
|
+
ts.factory.createStringLiteral(key),
|
|
95
|
+
),
|
|
96
|
+
ts.factory.createPropertyAssignment(
|
|
97
|
+
ts.factory.createIdentifier(key),
|
|
98
|
+
programmer({
|
|
99
|
+
context: {
|
|
100
|
+
...props.context,
|
|
101
|
+
options: {
|
|
102
|
+
numeric: false,
|
|
103
|
+
finite: false,
|
|
104
|
+
functional: false,
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
modulo: props.modulo,
|
|
108
|
+
type: props.type,
|
|
109
|
+
name: undefined,
|
|
110
|
+
}),
|
|
111
|
+
),
|
|
112
|
+
]);
|
|
113
|
+
|
|
114
|
+
//----
|
|
115
|
+
// RETURNS
|
|
116
|
+
//----
|
|
117
|
+
const category = props.context.options.validate;
|
|
118
|
+
// NORMAL
|
|
119
|
+
if (category === "assert")
|
|
120
|
+
return check("assert")(false)(AssertProgrammer.write);
|
|
121
|
+
else if (category === "is") return check("is")(false)(IsProgrammer.write);
|
|
122
|
+
// STRICT
|
|
123
|
+
else if (category === "validateEquals")
|
|
124
|
+
return check("validate")(true)(ValidateProgrammer.write);
|
|
125
|
+
else if (category === "equals")
|
|
126
|
+
return check("is")(true)(IsProgrammer.write);
|
|
127
|
+
else if (category === "assertEquals")
|
|
128
|
+
return check("assert")(true)(AssertProgrammer.write);
|
|
129
|
+
// CLONE
|
|
130
|
+
else if (category === "assertClone")
|
|
131
|
+
return misc("assert")(MiscAssertCloneProgrammer.write);
|
|
132
|
+
else if (category === "validateClone")
|
|
133
|
+
return misc("validate")(MiscValidateCloneProgrammer.write);
|
|
134
|
+
// PRUNE
|
|
135
|
+
else if (category === "assertPrune")
|
|
136
|
+
return misc("assert")(MiscAssertPruneProgrammer.write);
|
|
137
|
+
else if (category === "validatePrune")
|
|
138
|
+
return misc("validate")(MiscValidatePruneProgrammer.write);
|
|
139
|
+
// DEFAULT
|
|
140
|
+
return check("validate")(false)(ValidateProgrammer.write);
|
|
141
|
+
};
|
|
142
|
+
}
|
|
@@ -1,118 +1,118 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
import { LiteralFactory } from "typia/lib/factories/LiteralFactory";
|
|
3
|
-
import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
|
|
4
|
-
import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
|
|
5
|
-
import { HttpAssertFormDataProgrammer } from "typia/lib/programmers/http/HttpAssertFormDataProgrammer";
|
|
6
|
-
import { HttpFormDataProgrammer } from "typia/lib/programmers/http/HttpFormDataProgrammer";
|
|
7
|
-
import { HttpIsFormDataProgrammer } from "typia/lib/programmers/http/HttpIsFormDataProgrammer";
|
|
8
|
-
import { HttpValidateFormDataProgrammer } from "typia/lib/programmers/http/HttpValidateFormDataProgrammer";
|
|
9
|
-
import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
10
|
-
import { ITypiaContext } from "typia/lib/transformers/ITypiaContext";
|
|
11
|
-
import { TransformerError } from "typia/lib/transformers/TransformerError";
|
|
12
|
-
|
|
13
|
-
import { INestiaTransformContext } from "../options/INestiaTransformProject";
|
|
14
|
-
import { IRequestFormDataProps } from "../options/IRequestFormDataProps";
|
|
15
|
-
|
|
16
|
-
export namespace TypedFormDataBodyProgrammer {
|
|
17
|
-
export const generate = (props: {
|
|
18
|
-
context: INestiaTransformContext;
|
|
19
|
-
modulo: ts.LeftHandSideExpression;
|
|
20
|
-
type: ts.Type;
|
|
21
|
-
}): ts.ObjectLiteralExpression => {
|
|
22
|
-
// VALIDATE TYPE
|
|
23
|
-
const collection: MetadataCollection = new MetadataCollection();
|
|
24
|
-
const result = MetadataFactory.analyze({
|
|
25
|
-
checker: props.context.checker,
|
|
26
|
-
transformer: props.context.transformer,
|
|
27
|
-
options: {
|
|
28
|
-
escape: false,
|
|
29
|
-
constant: true,
|
|
30
|
-
absorb: true,
|
|
31
|
-
validate: HttpFormDataProgrammer.validate,
|
|
32
|
-
},
|
|
33
|
-
type: props.type,
|
|
34
|
-
collection,
|
|
35
|
-
});
|
|
36
|
-
if (result.success === false)
|
|
37
|
-
throw TransformerError.from({
|
|
38
|
-
code: "nestia.core.TypedFormData.Body",
|
|
39
|
-
errors: result.errors,
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
const files: IRequestFormDataProps.IFile[] =
|
|
43
|
-
result.data.objects[0].type.properties
|
|
44
|
-
.filter(
|
|
45
|
-
(p) =>
|
|
46
|
-
isFile(p.value) || p.value.arrays.some((a) => isFile(a.type.value)),
|
|
47
|
-
)
|
|
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: Metadata) =>
|
|
118
|
-
meta.natives.some(({ name }) => name === "File" || name === "Blob");
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { LiteralFactory } from "typia/lib/factories/LiteralFactory";
|
|
3
|
+
import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
|
|
4
|
+
import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
|
|
5
|
+
import { HttpAssertFormDataProgrammer } from "typia/lib/programmers/http/HttpAssertFormDataProgrammer";
|
|
6
|
+
import { HttpFormDataProgrammer } from "typia/lib/programmers/http/HttpFormDataProgrammer";
|
|
7
|
+
import { HttpIsFormDataProgrammer } from "typia/lib/programmers/http/HttpIsFormDataProgrammer";
|
|
8
|
+
import { HttpValidateFormDataProgrammer } from "typia/lib/programmers/http/HttpValidateFormDataProgrammer";
|
|
9
|
+
import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
10
|
+
import { ITypiaContext } from "typia/lib/transformers/ITypiaContext";
|
|
11
|
+
import { TransformerError } from "typia/lib/transformers/TransformerError";
|
|
12
|
+
|
|
13
|
+
import { INestiaTransformContext } from "../options/INestiaTransformProject";
|
|
14
|
+
import { IRequestFormDataProps } from "../options/IRequestFormDataProps";
|
|
15
|
+
|
|
16
|
+
export namespace TypedFormDataBodyProgrammer {
|
|
17
|
+
export const generate = (props: {
|
|
18
|
+
context: INestiaTransformContext;
|
|
19
|
+
modulo: ts.LeftHandSideExpression;
|
|
20
|
+
type: ts.Type;
|
|
21
|
+
}): ts.ObjectLiteralExpression => {
|
|
22
|
+
// VALIDATE TYPE
|
|
23
|
+
const collection: MetadataCollection = new MetadataCollection();
|
|
24
|
+
const result = MetadataFactory.analyze({
|
|
25
|
+
checker: props.context.checker,
|
|
26
|
+
transformer: props.context.transformer,
|
|
27
|
+
options: {
|
|
28
|
+
escape: false,
|
|
29
|
+
constant: true,
|
|
30
|
+
absorb: true,
|
|
31
|
+
validate: HttpFormDataProgrammer.validate,
|
|
32
|
+
},
|
|
33
|
+
type: props.type,
|
|
34
|
+
collection,
|
|
35
|
+
});
|
|
36
|
+
if (result.success === false)
|
|
37
|
+
throw TransformerError.from({
|
|
38
|
+
code: "nestia.core.TypedFormData.Body",
|
|
39
|
+
errors: result.errors,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const files: IRequestFormDataProps.IFile[] =
|
|
43
|
+
result.data.objects[0].type.properties
|
|
44
|
+
.filter(
|
|
45
|
+
(p) =>
|
|
46
|
+
isFile(p.value) || p.value.arrays.some((a) => isFile(a.type.value)),
|
|
47
|
+
)
|
|
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: Metadata) =>
|
|
118
|
+
meta.natives.some(({ name }) => name === "File" || name === "Blob");
|