typia 5.4.2 → 5.4.3
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/CamelCase.d.ts +1 -1
- package/lib/PascalCase.d.ts +1 -1
- package/lib/Resolved.d.ts +1 -1
- package/lib/SnakeCase.d.ts +1 -1
- package/lib/factories/internal/metadata/iterate_metadata_native.js +20 -21
- package/lib/factories/internal/metadata/iterate_metadata_native.js.map +1 -1
- package/lib/functional/$FormDataReader/$FormDataReader.d.ts +7 -0
- package/lib/functional/$FormDataReader/$FormDataReader.js +80 -0
- package/lib/functional/$FormDataReader/$FormDataReader.js.map +1 -0
- package/lib/functional/$FormDataReader/index.d.ts +1 -0
- package/lib/functional/$FormDataReader/index.js +28 -0
- package/lib/functional/$FormDataReader/index.js.map +1 -0
- package/lib/functional/Namespace/http.d.ts +3 -1
- package/lib/functional/Namespace/http.js +6 -3
- package/lib/functional/Namespace/http.js.map +1 -1
- package/lib/http.d.ts +334 -0
- package/lib/http.js +78 -1
- package/lib/http.js.map +1 -1
- package/lib/programmers/RandomProgrammer.js +18 -0
- package/lib/programmers/RandomProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpAssertFormDataProgrammer.d.ts +6 -0
- package/lib/programmers/http/HttpAssertFormDataProgrammer.js +41 -0
- package/lib/programmers/http/HttpAssertFormDataProgrammer.js.map +1 -0
- package/lib/programmers/http/HttpFormDataProgrammer.d.ts +9 -0
- package/lib/programmers/http/HttpFormDataProgrammer.js +191 -0
- package/lib/programmers/http/HttpFormDataProgrammer.js.map +1 -0
- package/lib/programmers/http/HttpIsFormDataProgrammer.d.ts +6 -0
- package/lib/programmers/http/HttpIsFormDataProgrammer.js +45 -0
- package/lib/programmers/http/HttpIsFormDataProgrammer.js.map +1 -0
- package/lib/programmers/http/HttpIsHeadersProgrammer.js +2 -2
- package/lib/programmers/http/HttpIsHeadersProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpIsQueryProgrammer.js +2 -2
- package/lib/programmers/http/HttpIsQueryProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpValidateFormDataProgrammer.d.ts +6 -0
- package/lib/programmers/http/HttpValidateFormDataProgrammer.js +41 -0
- package/lib/programmers/http/HttpValidateFormDataProgrammer.js.map +1 -0
- package/lib/programmers/http/HttpValidateHeadersProgrammer.js +2 -2
- package/lib/programmers/http/HttpValidateHeadersProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpValidateQueryProgrammer.js +2 -2
- package/lib/programmers/http/HttpValidateQueryProgrammer.js.map +1 -1
- package/lib/programmers/internal/application_native.js +6 -0
- package/lib/programmers/internal/application_native.js.map +1 -1
- package/lib/programmers/json/JsonApplicationProgrammer.d.ts +1 -0
- package/lib/programmers/json/JsonApplicationProgrammer.js +46 -0
- package/lib/programmers/json/JsonApplicationProgrammer.js.map +1 -1
- package/lib/transformers/CallExpressionTransformer.js +19 -0
- package/lib/transformers/CallExpressionTransformer.js.map +1 -1
- package/lib/transformers/features/http/CreateHttpAssertFormDataTransformer.d.ts +4 -0
- package/lib/transformers/features/http/CreateHttpAssertFormDataTransformer.js +12 -0
- package/lib/transformers/features/http/CreateHttpAssertFormDataTransformer.js.map +1 -0
- package/lib/transformers/features/http/CreateHttpFormDataTransformer.d.ts +4 -0
- package/lib/transformers/features/http/CreateHttpFormDataTransformer.js +10 -0
- package/lib/transformers/features/http/CreateHttpFormDataTransformer.js.map +1 -0
- package/lib/transformers/features/http/CreateHttpIsFormDataTransformer.d.ts +4 -0
- package/lib/transformers/features/http/CreateHttpIsFormDataTransformer.js +10 -0
- package/lib/transformers/features/http/CreateHttpIsFormDataTransformer.js.map +1 -0
- package/lib/transformers/features/http/CreateHttpValidateFormDataTransformer.d.ts +4 -0
- package/lib/transformers/features/http/CreateHttpValidateFormDataTransformer.js +12 -0
- package/lib/transformers/features/http/CreateHttpValidateFormDataTransformer.js.map +1 -0
- package/lib/transformers/features/http/HttpAssertFormDataTransformer.d.ts +4 -0
- package/lib/transformers/features/http/HttpAssertFormDataTransformer.js +12 -0
- package/lib/transformers/features/http/HttpAssertFormDataTransformer.js.map +1 -0
- package/lib/transformers/features/http/HttpFormDataTransformer.d.ts +4 -0
- package/lib/transformers/features/http/HttpFormDataTransformer.js +10 -0
- package/lib/transformers/features/http/HttpFormDataTransformer.js.map +1 -0
- package/lib/transformers/features/http/HttpIsFormDataTransformer.d.ts +4 -0
- package/lib/transformers/features/http/HttpIsFormDataTransformer.js +10 -0
- package/lib/transformers/features/http/HttpIsFormDataTransformer.js.map +1 -0
- package/lib/transformers/features/http/HttpValidateFormDataTransformer.d.ts +4 -0
- package/lib/transformers/features/http/HttpValidateFormDataTransformer.js +12 -0
- package/lib/transformers/features/http/HttpValidateFormDataTransformer.js.map +1 -0
- package/lib/transformers/features/json/JsonApplicationTransformer.js +1 -2
- package/lib/transformers/features/json/JsonApplicationTransformer.js.map +1 -1
- package/package.json +1 -1
- package/src/CamelCase.ts +2 -0
- package/src/PascalCase.ts +2 -0
- package/src/Resolved.ts +2 -0
- package/src/SnakeCase.ts +2 -0
- package/src/factories/internal/metadata/iterate_metadata_native.ts +21 -20
- package/src/functional/$FormDataReader/$FormDataReader.ts +77 -0
- package/src/functional/$FormDataReader/index.ts +1 -0
- package/src/functional/Namespace/http.ts +3 -1
- package/src/http.ts +474 -1
- package/src/programmers/RandomProgrammer.ts +44 -0
- package/src/programmers/http/HttpAssertFormDataProgrammer.ts +75 -0
- package/src/programmers/http/HttpFormDataProgrammer.ts +247 -0
- package/src/programmers/http/HttpIsFormDataProgrammer.ts +82 -0
- package/src/programmers/http/HttpIsHeadersProgrammer.ts +2 -2
- package/src/programmers/http/HttpIsQueryProgrammer.ts +2 -2
- package/src/programmers/http/HttpValidateFormDataProgrammer.ts +75 -0
- package/src/programmers/http/HttpValidateHeadersProgrammer.ts +2 -2
- package/src/programmers/http/HttpValidateQueryProgrammer.ts +2 -2
- package/src/programmers/internal/application_native.ts +7 -1
- package/src/programmers/json/JsonApplicationProgrammer.ts +28 -1
- package/src/transformers/CallExpressionTransformer.ts +19 -0
- package/src/transformers/features/http/CreateHttpAssertFormDataTransformer.ts +12 -0
- package/src/transformers/features/http/CreateHttpFormDataTransformer.ts +9 -0
- package/src/transformers/features/http/CreateHttpIsFormDataTransformer.ts +9 -0
- package/src/transformers/features/http/CreateHttpValidateFormDataTransformer.ts +12 -0
- package/src/transformers/features/http/HttpAssertFormDataTransformer.ts +10 -0
- package/src/transformers/features/http/HttpFormDataTransformer.ts +9 -0
- package/src/transformers/features/http/HttpIsFormDataTransformer.ts +9 -0
- package/src/transformers/features/http/HttpValidateFormDataTransformer.ts +10 -0
- package/src/transformers/features/json/JsonApplicationTransformer.ts +1 -2
|
@@ -620,6 +620,8 @@ export namespace RandomProgrammer {
|
|
|
620
620
|
else if (type === "ArrayBuffer" || type === "SharedArrayBuffer")
|
|
621
621
|
return decode_native_array_buffer(importer)(type);
|
|
622
622
|
else if (type === "DataView") return decode_native_data_view(importer);
|
|
623
|
+
else if (type === "Blob") return decode_native_blob(importer);
|
|
624
|
+
else if (type === "File") return decode_native_file(importer);
|
|
623
625
|
else
|
|
624
626
|
return ts.factory.createNewExpression(
|
|
625
627
|
ts.factory.createIdentifier(type),
|
|
@@ -709,6 +711,48 @@ export namespace RandomProgrammer {
|
|
|
709
711
|
);
|
|
710
712
|
};
|
|
711
713
|
|
|
714
|
+
const decode_native_blob = (importer: FunctionImporter) =>
|
|
715
|
+
ts.factory.createNewExpression(
|
|
716
|
+
ts.factory.createIdentifier("Blob"),
|
|
717
|
+
undefined,
|
|
718
|
+
[
|
|
719
|
+
ts.factory.createArrayLiteralExpression(
|
|
720
|
+
[decode_native_byte_array(importer)("Uint8Array")],
|
|
721
|
+
true,
|
|
722
|
+
),
|
|
723
|
+
],
|
|
724
|
+
);
|
|
725
|
+
|
|
726
|
+
const decode_native_file = (importer: FunctionImporter) =>
|
|
727
|
+
ts.factory.createNewExpression(
|
|
728
|
+
ts.factory.createIdentifier("File"),
|
|
729
|
+
undefined,
|
|
730
|
+
[
|
|
731
|
+
ts.factory.createArrayLiteralExpression(
|
|
732
|
+
[decode_native_byte_array(importer)("Uint8Array")],
|
|
733
|
+
true,
|
|
734
|
+
),
|
|
735
|
+
ts.factory.createTemplateExpression(ts.factory.createTemplateHead(""), [
|
|
736
|
+
ts.factory.createTemplateSpan(
|
|
737
|
+
ts.factory.createCallExpression(
|
|
738
|
+
COALESCE(importer)("string"),
|
|
739
|
+
undefined,
|
|
740
|
+
[ts.factory.createNumericLiteral(8)],
|
|
741
|
+
),
|
|
742
|
+
ts.factory.createTemplateMiddle("."),
|
|
743
|
+
),
|
|
744
|
+
ts.factory.createTemplateSpan(
|
|
745
|
+
ts.factory.createCallExpression(
|
|
746
|
+
COALESCE(importer)("string"),
|
|
747
|
+
undefined,
|
|
748
|
+
[ts.factory.createNumericLiteral(3)],
|
|
749
|
+
),
|
|
750
|
+
ts.factory.createTemplateTail(""),
|
|
751
|
+
),
|
|
752
|
+
]),
|
|
753
|
+
],
|
|
754
|
+
);
|
|
755
|
+
|
|
712
756
|
const decode_native_array_buffer =
|
|
713
757
|
(importer: FunctionImporter) =>
|
|
714
758
|
(type: "ArrayBuffer" | "SharedArrayBuffer"): ts.Expression =>
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
+
import { StatementFactory } from "../../factories/StatementFactory";
|
|
5
|
+
import { TypeFactory } from "../../factories/TypeFactory";
|
|
6
|
+
|
|
7
|
+
import { IProject } from "../../transformers/IProject";
|
|
8
|
+
|
|
9
|
+
import { AssertProgrammer } from "../AssertProgrammer";
|
|
10
|
+
import { HttpFormDataProgrammer } from "./HttpFormDataProgrammer";
|
|
11
|
+
|
|
12
|
+
export namespace HttpAssertFormDataProgrammer {
|
|
13
|
+
export const write =
|
|
14
|
+
(project: IProject) =>
|
|
15
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
16
|
+
(type: ts.Type, name?: string): ts.ArrowFunction =>
|
|
17
|
+
ts.factory.createArrowFunction(
|
|
18
|
+
undefined,
|
|
19
|
+
undefined,
|
|
20
|
+
[
|
|
21
|
+
IdentifierFactory.parameter(
|
|
22
|
+
"input",
|
|
23
|
+
ts.factory.createTypeReferenceNode("FormData"),
|
|
24
|
+
),
|
|
25
|
+
],
|
|
26
|
+
ts.factory.createTypeReferenceNode(
|
|
27
|
+
`typia.Resolved<${
|
|
28
|
+
name ?? TypeFactory.getFullName(project.checker)(type)
|
|
29
|
+
}>`,
|
|
30
|
+
),
|
|
31
|
+
undefined,
|
|
32
|
+
ts.factory.createBlock([
|
|
33
|
+
StatementFactory.constant(
|
|
34
|
+
"decode",
|
|
35
|
+
HttpFormDataProgrammer.write({
|
|
36
|
+
...project,
|
|
37
|
+
options: {
|
|
38
|
+
...project.options,
|
|
39
|
+
functional: false,
|
|
40
|
+
numeric: false,
|
|
41
|
+
},
|
|
42
|
+
})(modulo)(type, name),
|
|
43
|
+
),
|
|
44
|
+
StatementFactory.constant(
|
|
45
|
+
"assert",
|
|
46
|
+
AssertProgrammer.write({
|
|
47
|
+
...project,
|
|
48
|
+
options: {
|
|
49
|
+
...project.options,
|
|
50
|
+
functional: false,
|
|
51
|
+
numeric: false,
|
|
52
|
+
},
|
|
53
|
+
})(modulo)(false)(type, name),
|
|
54
|
+
),
|
|
55
|
+
StatementFactory.constant(
|
|
56
|
+
"output",
|
|
57
|
+
ts.factory.createCallExpression(
|
|
58
|
+
ts.factory.createIdentifier("decode"),
|
|
59
|
+
undefined,
|
|
60
|
+
[ts.factory.createIdentifier("input")],
|
|
61
|
+
),
|
|
62
|
+
),
|
|
63
|
+
ts.factory.createReturnStatement(
|
|
64
|
+
ts.factory.createAsExpression(
|
|
65
|
+
ts.factory.createCallExpression(
|
|
66
|
+
ts.factory.createIdentifier("assert"),
|
|
67
|
+
undefined,
|
|
68
|
+
[ts.factory.createIdentifier("output")],
|
|
69
|
+
),
|
|
70
|
+
TypeFactory.keyword("any"),
|
|
71
|
+
),
|
|
72
|
+
),
|
|
73
|
+
]),
|
|
74
|
+
);
|
|
75
|
+
}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
+
import { MetadataCollection } from "../../factories/MetadataCollection";
|
|
5
|
+
import { MetadataFactory } from "../../factories/MetadataFactory";
|
|
6
|
+
import { StatementFactory } from "../../factories/StatementFactory";
|
|
7
|
+
import { TypeFactory } from "../../factories/TypeFactory";
|
|
8
|
+
|
|
9
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
10
|
+
import { MetadataArrayType } from "../../schemas/metadata/MetadataArrayType";
|
|
11
|
+
import { MetadataObject } from "../../schemas/metadata/MetadataObject";
|
|
12
|
+
import { MetadataProperty } from "../../schemas/metadata/MetadataProperty";
|
|
13
|
+
|
|
14
|
+
import { IProject } from "../../transformers/IProject";
|
|
15
|
+
import { TransformerError } from "../../transformers/TransformerError";
|
|
16
|
+
|
|
17
|
+
import { Atomic } from "../../typings/Atomic";
|
|
18
|
+
|
|
19
|
+
import { Escaper } from "../../utils/Escaper";
|
|
20
|
+
|
|
21
|
+
import { FunctionImporter } from "../helpers/FunctionImporeter";
|
|
22
|
+
import { HttpMetadataUtil } from "../helpers/HttpMetadataUtil";
|
|
23
|
+
|
|
24
|
+
export namespace HttpFormDataProgrammer {
|
|
25
|
+
export const write =
|
|
26
|
+
(project: IProject) =>
|
|
27
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
28
|
+
(type: ts.Type, name?: string): ts.ArrowFunction => {
|
|
29
|
+
// GET OBJECT TYPE
|
|
30
|
+
const importer: FunctionImporter = new FunctionImporter(modulo.getText());
|
|
31
|
+
const collection: MetadataCollection = new MetadataCollection();
|
|
32
|
+
const result = MetadataFactory.analyze(
|
|
33
|
+
project.checker,
|
|
34
|
+
project.context,
|
|
35
|
+
)({
|
|
36
|
+
escape: false,
|
|
37
|
+
constant: true,
|
|
38
|
+
absorb: true,
|
|
39
|
+
validate,
|
|
40
|
+
})(collection)(type);
|
|
41
|
+
if (result.success === false)
|
|
42
|
+
throw TransformerError.from(`typia.http.${importer.method}`)(
|
|
43
|
+
result.errors,
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
// DO TRANSFORM
|
|
47
|
+
const object: MetadataObject = result.data.objects[0]!;
|
|
48
|
+
const statements: ts.Statement[] = decode_object(importer)(object);
|
|
49
|
+
return ts.factory.createArrowFunction(
|
|
50
|
+
undefined,
|
|
51
|
+
undefined,
|
|
52
|
+
[
|
|
53
|
+
IdentifierFactory.parameter(
|
|
54
|
+
"input",
|
|
55
|
+
ts.factory.createTypeReferenceNode("FormData"),
|
|
56
|
+
),
|
|
57
|
+
],
|
|
58
|
+
ts.factory.createTypeReferenceNode(
|
|
59
|
+
`typia.Resolved<${
|
|
60
|
+
name ?? TypeFactory.getFullName(project.checker)(type)
|
|
61
|
+
}>`,
|
|
62
|
+
),
|
|
63
|
+
undefined,
|
|
64
|
+
ts.factory.createBlock(
|
|
65
|
+
[...importer.declare(modulo), ...statements],
|
|
66
|
+
true,
|
|
67
|
+
),
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const validate = (
|
|
72
|
+
meta: Metadata,
|
|
73
|
+
explore: MetadataFactory.IExplore,
|
|
74
|
+
): string[] => {
|
|
75
|
+
const errors: string[] = [];
|
|
76
|
+
const insert = (msg: string) => errors.push(msg);
|
|
77
|
+
|
|
78
|
+
if (explore.top === true) {
|
|
79
|
+
// TOP MUST BE ONLY OBJECT
|
|
80
|
+
if (meta.objects.length !== 1 || meta.bucket() !== 1)
|
|
81
|
+
insert("only one object type is allowed.");
|
|
82
|
+
if (meta.nullable === true) insert("formdata parameters cannot be null.");
|
|
83
|
+
if (meta.isRequired() === false)
|
|
84
|
+
insert("formdata parameters cannot be undefined.");
|
|
85
|
+
} else if (
|
|
86
|
+
explore.nested !== null &&
|
|
87
|
+
explore.nested instanceof MetadataArrayType
|
|
88
|
+
) {
|
|
89
|
+
//----
|
|
90
|
+
// ARRAY
|
|
91
|
+
//----
|
|
92
|
+
const atomics = HttpMetadataUtil.atomics(meta);
|
|
93
|
+
const expected: number =
|
|
94
|
+
meta.atomics.length +
|
|
95
|
+
meta.templates.length +
|
|
96
|
+
meta.constants.map((c) => c.values.length).reduce((a, b) => a + b, 0) +
|
|
97
|
+
meta.natives.filter((n) => n === "Blob" || n === "File").length;
|
|
98
|
+
if (atomics.size > 1) insert("union type is not allowed in array.");
|
|
99
|
+
if (meta.size() !== expected)
|
|
100
|
+
insert(
|
|
101
|
+
"only atomic, constant or blob (file) types are allowed in array.",
|
|
102
|
+
);
|
|
103
|
+
} else if (explore.object && explore.property !== null) {
|
|
104
|
+
//----
|
|
105
|
+
// COMMON
|
|
106
|
+
//----
|
|
107
|
+
// PROPERTY MUST BE SOLE
|
|
108
|
+
if (typeof explore.property === "object")
|
|
109
|
+
insert("dynamic property is not allowed.");
|
|
110
|
+
// DO NOT ALLOW TUPLE TYPE
|
|
111
|
+
if (meta.tuples.length) insert("tuple type is not allowed.");
|
|
112
|
+
// DO NOT ALLOW UNION TYPE
|
|
113
|
+
if (HttpMetadataUtil.isUnion(meta)) insert("union type is not allowed.");
|
|
114
|
+
// DO NOT ALLOW NESTED OBJECT
|
|
115
|
+
if (
|
|
116
|
+
meta.objects.length ||
|
|
117
|
+
meta.sets.length ||
|
|
118
|
+
meta.maps.length ||
|
|
119
|
+
meta.natives.length
|
|
120
|
+
)
|
|
121
|
+
insert("nested object type is not allowed.");
|
|
122
|
+
}
|
|
123
|
+
return errors;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const decode_object =
|
|
127
|
+
(importer: FunctionImporter) =>
|
|
128
|
+
(object: MetadataObject): ts.Statement[] => {
|
|
129
|
+
// const input: ts.Identifier = ts.factory.createIdentifier("input");
|
|
130
|
+
const output: ts.Identifier = ts.factory.createIdentifier("output");
|
|
131
|
+
return [
|
|
132
|
+
StatementFactory.constant(
|
|
133
|
+
"output",
|
|
134
|
+
ts.factory.createObjectLiteralExpression(
|
|
135
|
+
object.properties.map((prop) =>
|
|
136
|
+
decode_regular_property(importer)(prop),
|
|
137
|
+
),
|
|
138
|
+
true,
|
|
139
|
+
),
|
|
140
|
+
),
|
|
141
|
+
ts.factory.createReturnStatement(
|
|
142
|
+
ts.factory.createAsExpression(output, TypeFactory.keyword("any")),
|
|
143
|
+
),
|
|
144
|
+
];
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const decode_regular_property =
|
|
148
|
+
(importer: FunctionImporter) =>
|
|
149
|
+
(property: MetadataProperty): ts.PropertyAssignment => {
|
|
150
|
+
const key: string = property.key.constants[0]!.values[0] as string;
|
|
151
|
+
const value: Metadata = property.value;
|
|
152
|
+
|
|
153
|
+
const [type, isArray]: [Atomic.Literal | "blob" | "file", boolean] = value
|
|
154
|
+
.atomics.length
|
|
155
|
+
? [value.atomics[0]!.type, false]
|
|
156
|
+
: value.constants.length
|
|
157
|
+
? [value.constants[0]!.type, false]
|
|
158
|
+
: value.templates.length
|
|
159
|
+
? ["string", false]
|
|
160
|
+
: value.natives.includes("Blob")
|
|
161
|
+
? ["blob", false]
|
|
162
|
+
: value.natives.includes("File")
|
|
163
|
+
? ["file", false]
|
|
164
|
+
: (() => {
|
|
165
|
+
const meta =
|
|
166
|
+
value.arrays[0]?.type.value ?? value.tuples[0]!.type.elements[0]!;
|
|
167
|
+
return meta.atomics.length
|
|
168
|
+
? [meta.atomics[0]!.type, true]
|
|
169
|
+
: meta.templates.length
|
|
170
|
+
? ["string", true]
|
|
171
|
+
: meta.natives.includes("Blob")
|
|
172
|
+
? ["blob", true]
|
|
173
|
+
: meta.natives.includes("File")
|
|
174
|
+
? ["file", true]
|
|
175
|
+
: [meta.constants[0]!.type, true];
|
|
176
|
+
})();
|
|
177
|
+
return ts.factory.createPropertyAssignment(
|
|
178
|
+
Escaper.variable(key) ? key : ts.factory.createStringLiteral(key),
|
|
179
|
+
isArray
|
|
180
|
+
? decode_array(importer)(value)(
|
|
181
|
+
ts.factory.createCallExpression(
|
|
182
|
+
IdentifierFactory.access(
|
|
183
|
+
ts.factory.createCallExpression(
|
|
184
|
+
ts.factory.createIdentifier("input.getAll"),
|
|
185
|
+
undefined,
|
|
186
|
+
[ts.factory.createStringLiteral(key)],
|
|
187
|
+
),
|
|
188
|
+
)("map"),
|
|
189
|
+
undefined,
|
|
190
|
+
[
|
|
191
|
+
ts.factory.createArrowFunction(
|
|
192
|
+
undefined,
|
|
193
|
+
undefined,
|
|
194
|
+
[IdentifierFactory.parameter("elem")],
|
|
195
|
+
undefined,
|
|
196
|
+
undefined,
|
|
197
|
+
decode_value(importer)(type)(false)(
|
|
198
|
+
ts.factory.createIdentifier("elem"),
|
|
199
|
+
),
|
|
200
|
+
),
|
|
201
|
+
],
|
|
202
|
+
),
|
|
203
|
+
)
|
|
204
|
+
: decode_value(importer)(type)(
|
|
205
|
+
value.nullable === false && value.isRequired() === false,
|
|
206
|
+
)(
|
|
207
|
+
ts.factory.createCallExpression(
|
|
208
|
+
ts.factory.createIdentifier("input.get"),
|
|
209
|
+
undefined,
|
|
210
|
+
[ts.factory.createStringLiteral(key)],
|
|
211
|
+
),
|
|
212
|
+
),
|
|
213
|
+
);
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
const decode_value =
|
|
217
|
+
(importer: FunctionImporter) =>
|
|
218
|
+
(type: Atomic.Literal | "blob" | "file") =>
|
|
219
|
+
(onlyUndefindable: boolean) =>
|
|
220
|
+
(value: ts.Expression) => {
|
|
221
|
+
const call = ts.factory.createCallExpression(
|
|
222
|
+
importer.use(type),
|
|
223
|
+
undefined,
|
|
224
|
+
[value],
|
|
225
|
+
);
|
|
226
|
+
return onlyUndefindable
|
|
227
|
+
? ts.factory.createBinaryExpression(
|
|
228
|
+
call,
|
|
229
|
+
ts.factory.createToken(ts.SyntaxKind.QuestionQuestionToken),
|
|
230
|
+
ts.factory.createIdentifier("undefined"),
|
|
231
|
+
)
|
|
232
|
+
: call;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const decode_array =
|
|
236
|
+
(importer: FunctionImporter) =>
|
|
237
|
+
(value: Metadata) =>
|
|
238
|
+
(expression: ts.Expression): ts.Expression =>
|
|
239
|
+
value.nullable || value.isRequired() === false
|
|
240
|
+
? ts.factory.createCallExpression(importer.use("array"), undefined, [
|
|
241
|
+
expression,
|
|
242
|
+
value.nullable
|
|
243
|
+
? ts.factory.createNull()
|
|
244
|
+
: ts.factory.createIdentifier("undefined"),
|
|
245
|
+
])
|
|
246
|
+
: expression;
|
|
247
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
+
import { StatementFactory } from "../../factories/StatementFactory";
|
|
5
|
+
import { TypeFactory } from "../../factories/TypeFactory";
|
|
6
|
+
|
|
7
|
+
import { IProject } from "../../transformers/IProject";
|
|
8
|
+
|
|
9
|
+
import { IsProgrammer } from "../IsProgrammer";
|
|
10
|
+
import { HttpFormDataProgrammer } from "./HttpFormDataProgrammer";
|
|
11
|
+
|
|
12
|
+
export namespace HttpIsFormDataProgrammer {
|
|
13
|
+
export const write =
|
|
14
|
+
(project: IProject) =>
|
|
15
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
16
|
+
(type: ts.Type, name?: string): ts.ArrowFunction =>
|
|
17
|
+
ts.factory.createArrowFunction(
|
|
18
|
+
undefined,
|
|
19
|
+
undefined,
|
|
20
|
+
[
|
|
21
|
+
IdentifierFactory.parameter(
|
|
22
|
+
"input",
|
|
23
|
+
ts.factory.createTypeReferenceNode("FormData"),
|
|
24
|
+
),
|
|
25
|
+
],
|
|
26
|
+
ts.factory.createUnionTypeNode([
|
|
27
|
+
ts.factory.createTypeReferenceNode(
|
|
28
|
+
`typia.Resolved<${
|
|
29
|
+
name ?? TypeFactory.getFullName(project.checker)(type)
|
|
30
|
+
}>`,
|
|
31
|
+
),
|
|
32
|
+
ts.factory.createLiteralTypeNode(ts.factory.createNull()),
|
|
33
|
+
]),
|
|
34
|
+
undefined,
|
|
35
|
+
ts.factory.createBlock([
|
|
36
|
+
StatementFactory.constant(
|
|
37
|
+
"is",
|
|
38
|
+
IsProgrammer.write({
|
|
39
|
+
...project,
|
|
40
|
+
options: {
|
|
41
|
+
...project.options,
|
|
42
|
+
functional: false,
|
|
43
|
+
numeric: false,
|
|
44
|
+
},
|
|
45
|
+
})(modulo)(false)(type, name),
|
|
46
|
+
),
|
|
47
|
+
StatementFactory.constant(
|
|
48
|
+
"decode",
|
|
49
|
+
HttpFormDataProgrammer.write({
|
|
50
|
+
...project,
|
|
51
|
+
options: {
|
|
52
|
+
...project.options,
|
|
53
|
+
functional: false,
|
|
54
|
+
numeric: false,
|
|
55
|
+
},
|
|
56
|
+
})(modulo)(type, name),
|
|
57
|
+
),
|
|
58
|
+
StatementFactory.constant(
|
|
59
|
+
"output",
|
|
60
|
+
ts.factory.createCallExpression(
|
|
61
|
+
ts.factory.createIdentifier("decode"),
|
|
62
|
+
undefined,
|
|
63
|
+
[ts.factory.createIdentifier("input")],
|
|
64
|
+
),
|
|
65
|
+
),
|
|
66
|
+
ts.factory.createIfStatement(
|
|
67
|
+
ts.factory.createPrefixUnaryExpression(
|
|
68
|
+
ts.SyntaxKind.ExclamationToken,
|
|
69
|
+
ts.factory.createCallExpression(
|
|
70
|
+
ts.factory.createIdentifier("is"),
|
|
71
|
+
undefined,
|
|
72
|
+
[ts.factory.createIdentifier("output")],
|
|
73
|
+
),
|
|
74
|
+
),
|
|
75
|
+
ts.factory.createReturnStatement(ts.factory.createNull()),
|
|
76
|
+
),
|
|
77
|
+
ts.factory.createReturnStatement(
|
|
78
|
+
ts.factory.createIdentifier("output"),
|
|
79
|
+
),
|
|
80
|
+
]),
|
|
81
|
+
);
|
|
82
|
+
}
|
|
@@ -47,7 +47,7 @@ export namespace HttpIsHeadersProgrammer {
|
|
|
47
47
|
})(modulo)(false)(type, name),
|
|
48
48
|
),
|
|
49
49
|
StatementFactory.constant(
|
|
50
|
-
"
|
|
50
|
+
"decode",
|
|
51
51
|
HttpHeadersProgrammer.write({
|
|
52
52
|
...project,
|
|
53
53
|
options: {
|
|
@@ -60,7 +60,7 @@ export namespace HttpIsHeadersProgrammer {
|
|
|
60
60
|
StatementFactory.constant(
|
|
61
61
|
"output",
|
|
62
62
|
ts.factory.createCallExpression(
|
|
63
|
-
ts.factory.createIdentifier("
|
|
63
|
+
ts.factory.createIdentifier("decode"),
|
|
64
64
|
undefined,
|
|
65
65
|
[ts.factory.createIdentifier("input")],
|
|
66
66
|
),
|
|
@@ -45,7 +45,7 @@ export namespace HttpIsQueryProgrammer {
|
|
|
45
45
|
})(modulo)(false)(type, name),
|
|
46
46
|
),
|
|
47
47
|
StatementFactory.constant(
|
|
48
|
-
"
|
|
48
|
+
"decode",
|
|
49
49
|
HttpQueryProgrammer.write({
|
|
50
50
|
...project,
|
|
51
51
|
options: {
|
|
@@ -58,7 +58,7 @@ export namespace HttpIsQueryProgrammer {
|
|
|
58
58
|
StatementFactory.constant(
|
|
59
59
|
"output",
|
|
60
60
|
ts.factory.createCallExpression(
|
|
61
|
-
ts.factory.createIdentifier("
|
|
61
|
+
ts.factory.createIdentifier("decode"),
|
|
62
62
|
undefined,
|
|
63
63
|
[ts.factory.createIdentifier("input")],
|
|
64
64
|
),
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
+
import { StatementFactory } from "../../factories/StatementFactory";
|
|
5
|
+
import { TypeFactory } from "../../factories/TypeFactory";
|
|
6
|
+
|
|
7
|
+
import { IProject } from "../../transformers/IProject";
|
|
8
|
+
|
|
9
|
+
import { ValidateProgrammer } from "../ValidateProgrammer";
|
|
10
|
+
import { HttpFormDataProgrammer } from "./HttpFormDataProgrammer";
|
|
11
|
+
|
|
12
|
+
export namespace HttpValidateFormDataProgrammer {
|
|
13
|
+
export const write =
|
|
14
|
+
(project: IProject) =>
|
|
15
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
16
|
+
(type: ts.Type, name?: string): ts.ArrowFunction =>
|
|
17
|
+
ts.factory.createArrowFunction(
|
|
18
|
+
undefined,
|
|
19
|
+
undefined,
|
|
20
|
+
[
|
|
21
|
+
IdentifierFactory.parameter(
|
|
22
|
+
"input",
|
|
23
|
+
ts.factory.createTypeReferenceNode("FormData"),
|
|
24
|
+
),
|
|
25
|
+
],
|
|
26
|
+
ts.factory.createTypeReferenceNode(
|
|
27
|
+
`typia.IValidation<typia.Resolved<${
|
|
28
|
+
name ?? TypeFactory.getFullName(project.checker)(type)
|
|
29
|
+
}>>`,
|
|
30
|
+
),
|
|
31
|
+
undefined,
|
|
32
|
+
ts.factory.createBlock([
|
|
33
|
+
StatementFactory.constant(
|
|
34
|
+
"validate",
|
|
35
|
+
ValidateProgrammer.write({
|
|
36
|
+
...project,
|
|
37
|
+
options: {
|
|
38
|
+
...project.options,
|
|
39
|
+
functional: false,
|
|
40
|
+
numeric: true,
|
|
41
|
+
},
|
|
42
|
+
})(modulo)(false)(type, name),
|
|
43
|
+
),
|
|
44
|
+
StatementFactory.constant(
|
|
45
|
+
"decode",
|
|
46
|
+
HttpFormDataProgrammer.write({
|
|
47
|
+
...project,
|
|
48
|
+
options: {
|
|
49
|
+
...project.options,
|
|
50
|
+
functional: false,
|
|
51
|
+
numeric: false,
|
|
52
|
+
},
|
|
53
|
+
})(modulo)(type, name),
|
|
54
|
+
),
|
|
55
|
+
StatementFactory.constant(
|
|
56
|
+
"output",
|
|
57
|
+
ts.factory.createCallExpression(
|
|
58
|
+
ts.factory.createIdentifier("decode"),
|
|
59
|
+
undefined,
|
|
60
|
+
[ts.factory.createIdentifier("input")],
|
|
61
|
+
),
|
|
62
|
+
),
|
|
63
|
+
ts.factory.createReturnStatement(
|
|
64
|
+
ts.factory.createAsExpression(
|
|
65
|
+
ts.factory.createCallExpression(
|
|
66
|
+
ts.factory.createIdentifier("validate"),
|
|
67
|
+
undefined,
|
|
68
|
+
[ts.factory.createIdentifier("output")],
|
|
69
|
+
),
|
|
70
|
+
ts.factory.createTypeReferenceNode("any"),
|
|
71
|
+
),
|
|
72
|
+
),
|
|
73
|
+
]),
|
|
74
|
+
);
|
|
75
|
+
}
|
|
@@ -44,7 +44,7 @@ export namespace HttpValidateHeadersProgrammer {
|
|
|
44
44
|
})(modulo)(false)(type, name),
|
|
45
45
|
),
|
|
46
46
|
StatementFactory.constant(
|
|
47
|
-
"
|
|
47
|
+
"decode",
|
|
48
48
|
HttpHeadersProgrammer.write({
|
|
49
49
|
...project,
|
|
50
50
|
options: {
|
|
@@ -57,7 +57,7 @@ export namespace HttpValidateHeadersProgrammer {
|
|
|
57
57
|
StatementFactory.constant(
|
|
58
58
|
"output",
|
|
59
59
|
ts.factory.createCallExpression(
|
|
60
|
-
ts.factory.createIdentifier("
|
|
60
|
+
ts.factory.createIdentifier("decode"),
|
|
61
61
|
undefined,
|
|
62
62
|
[ts.factory.createIdentifier("input")],
|
|
63
63
|
),
|
|
@@ -42,7 +42,7 @@ export namespace HttpValidateQueryProgrammer {
|
|
|
42
42
|
})(modulo)(false)(type, name),
|
|
43
43
|
),
|
|
44
44
|
StatementFactory.constant(
|
|
45
|
-
"
|
|
45
|
+
"decode",
|
|
46
46
|
HttpQueryProgrammer.write({
|
|
47
47
|
...project,
|
|
48
48
|
options: {
|
|
@@ -55,7 +55,7 @@ export namespace HttpValidateQueryProgrammer {
|
|
|
55
55
|
StatementFactory.constant(
|
|
56
56
|
"output",
|
|
57
57
|
ts.factory.createCallExpression(
|
|
58
|
-
ts.factory.createIdentifier("
|
|
58
|
+
ts.factory.createIdentifier("decode"),
|
|
59
59
|
undefined,
|
|
60
60
|
[ts.factory.createIdentifier("input")],
|
|
61
61
|
),
|
|
@@ -11,7 +11,13 @@ export const application_native =
|
|
|
11
11
|
(options: JsonApplicationProgrammer.IOptions) =>
|
|
12
12
|
(components: IJsonComponents) =>
|
|
13
13
|
(name: string) =>
|
|
14
|
-
(nullable: boolean): IJsonSchema
|
|
14
|
+
(nullable: boolean): IJsonSchema => {
|
|
15
|
+
if (name === "Blob" || name === "File")
|
|
16
|
+
return {
|
|
17
|
+
type: "string",
|
|
18
|
+
format: "binary",
|
|
19
|
+
nullable,
|
|
20
|
+
};
|
|
15
21
|
const key: string =
|
|
16
22
|
options.purpose === "ajv"
|
|
17
23
|
? name
|
|
@@ -4,6 +4,7 @@ import { IJsonSchema } from "../../schemas/json/IJsonSchema";
|
|
|
4
4
|
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
5
5
|
|
|
6
6
|
import { TransformerError } from "../../transformers/TransformerError";
|
|
7
|
+
import { AtomicPredicator } from "../helpers/AtomicPredicator";
|
|
7
8
|
|
|
8
9
|
import { application_schema } from "../internal/application_schema";
|
|
9
10
|
|
|
@@ -31,7 +32,6 @@ export namespace JsonApplicationProgrammer {
|
|
|
31
32
|
schemas: {},
|
|
32
33
|
};
|
|
33
34
|
const generator = application_schema(fullOptions)(true)(components);
|
|
34
|
-
|
|
35
35
|
return {
|
|
36
36
|
schemas: metadatas.map((meta, i) => {
|
|
37
37
|
const schema: IJsonSchema | null = generator(meta)({});
|
|
@@ -46,4 +46,31 @@ export namespace JsonApplicationProgrammer {
|
|
|
46
46
|
...fullOptions,
|
|
47
47
|
};
|
|
48
48
|
};
|
|
49
|
+
|
|
50
|
+
export const validate = (meta: Metadata) => {
|
|
51
|
+
const output: string[] = [];
|
|
52
|
+
if (
|
|
53
|
+
meta.atomics.some((a) => a.type === "bigint") ||
|
|
54
|
+
meta.constants.some((c) => c.type === "bigint")
|
|
55
|
+
)
|
|
56
|
+
output.push("JSON schema does not support bigint type.");
|
|
57
|
+
if (
|
|
58
|
+
meta.tuples.some((t) =>
|
|
59
|
+
t.type.elements.some((e) => e.isRequired() === false),
|
|
60
|
+
) ||
|
|
61
|
+
meta.arrays.some((a) => a.type.value.isRequired() === false)
|
|
62
|
+
)
|
|
63
|
+
output.push("JSON schema does not support undefined type in array.");
|
|
64
|
+
if (meta.maps.length) output.push("JSON schema does not support Map type.");
|
|
65
|
+
if (meta.sets.length) output.push("JSON schema does not support Set type.");
|
|
66
|
+
for (const native of meta.natives)
|
|
67
|
+
if (
|
|
68
|
+
AtomicPredicator.native(native) === false &&
|
|
69
|
+
native !== "Date" &&
|
|
70
|
+
native !== "Blob" &&
|
|
71
|
+
native !== "File"
|
|
72
|
+
)
|
|
73
|
+
output.push(`JSON schema does not support ${native} type.`);
|
|
74
|
+
return output;
|
|
75
|
+
};
|
|
49
76
|
}
|