typia 5.1.4 → 5.1.5
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/TypeGuardError.d.ts +2 -2
- package/lib/executable/TypiaGenerateWizard.js.map +1 -1
- package/lib/executable/TypiaSetupWizard.js +16 -7
- package/lib/executable/TypiaSetupWizard.js.map +1 -1
- package/lib/factories/internal/metadata/emplace_metadata_object.js +25 -6
- package/lib/factories/internal/metadata/emplace_metadata_object.js.map +1 -1
- package/lib/programmers/CheckerProgrammer.d.ts +3 -3
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/programmers/FeatureProgrammer.d.ts +11 -11
- package/lib/programmers/FeatureProgrammer.js.map +1 -1
- package/lib/schemas/json/IJsonComponents.d.ts +12 -12
- package/lib/schemas/json/IJsonSchema.d.ts +32 -32
- package/lib/schemas/metadata/IMetadataObject.d.ts +1 -1
- package/lib/transformers/ITransformOptions.d.ts +4 -4
- package/package.json +1 -1
- package/src/TypeGuardError.ts +2 -2
- package/src/executable/TypiaGenerateWizard.ts +2 -2
- package/src/executable/TypiaSetupWizard.ts +7 -3
- package/src/factories/MetadataCollection.ts +277 -277
- package/src/factories/MetadataFactory.ts +238 -238
- package/src/factories/MetadataTypeTagFactory.ts +325 -325
- package/src/factories/internal/metadata/emend_metadata_atomics.ts +41 -41
- package/src/factories/internal/metadata/emplace_metadata_object.ts +30 -8
- package/src/factories/internal/metadata/iterate_metadata_intersection.ts +259 -259
- package/src/functional/$HeadersReader.ts +28 -28
- package/src/functional/$ParameterReader.ts +31 -31
- package/src/functional/$QueryReader.ts +56 -56
- package/src/functional/Namespace.ts +142 -142
- package/src/http.ts +1149 -1149
- package/src/json.ts +648 -648
- package/src/misc.ts +651 -651
- package/src/module.ts +657 -657
- package/src/programmers/CheckerProgrammer.ts +11 -9
- package/src/programmers/FeatureProgrammer.ts +25 -17
- package/src/programmers/helpers/HttpMetadataUtil.ts +21 -21
- package/src/programmers/helpers/RandomRanger.ts +1 -1
- package/src/programmers/http/HttpAssertHeadersProgrammer.ts +77 -77
- package/src/programmers/http/HttpAssertQueryProgrammer.ts +77 -77
- package/src/programmers/http/HttpHeadersProgrammer.ts +339 -339
- package/src/programmers/http/HttpIsHeadersProgrammer.ts +87 -87
- package/src/programmers/http/HttpIsQueryProgrammer.ts +87 -87
- package/src/programmers/http/HttpParameterProgrammer.ts +104 -104
- package/src/programmers/http/HttpQueryProgrammer.ts +273 -273
- package/src/programmers/http/HttpValidateHeadersProgrammer.ts +77 -77
- package/src/programmers/http/HttpValidateQueryProgrammer.ts +77 -77
- package/src/programmers/internal/application_boolean.ts +30 -30
- package/src/programmers/internal/application_number.ts +90 -90
- package/src/programmers/internal/application_object.ts +1 -1
- package/src/programmers/internal/application_schema.ts +180 -180
- package/src/programmers/internal/application_string.ts +54 -54
- package/src/programmers/internal/check_array_length.ts +44 -44
- package/src/programmers/internal/check_bigint.ts +48 -48
- package/src/programmers/internal/check_number.ts +108 -108
- package/src/programmers/internal/check_object.ts +2 -2
- package/src/programmers/internal/check_string.ts +48 -48
- package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +882 -882
- package/src/protobuf.ts +887 -887
- package/src/schemas/json/IJsonComponents.ts +36 -34
- package/src/schemas/json/IJsonSchema.ts +112 -112
- package/src/schemas/metadata/IMetadataConstant.ts +25 -25
- package/src/schemas/metadata/IMetadataObject.ts +1 -1
- package/src/schemas/metadata/IMetadataTypeTag.ts +8 -8
- package/src/schemas/metadata/Metadata.ts +686 -686
- package/src/tags/Default.ts +15 -15
- package/src/tags/Format.ts +30 -30
- package/src/tags/Pattern.ts +9 -9
- package/src/tags/TagBase.ts +68 -68
- package/src/tags/index.ts +14 -14
- package/src/transformers/CallExpressionTransformer.ts +289 -289
- package/src/transformers/ITransformOptions.ts +4 -4
- package/src/transformers/features/http/CreateHttpAssertHeadersTransformer.ts +12 -12
- package/src/transformers/features/http/CreateHttpAssertQueryTransformer.ts +12 -12
- package/src/transformers/features/http/CreateHttpHeadersTransformer.ts +9 -9
- package/src/transformers/features/http/CreateHttpIsHeadersTransformer.ts +9 -9
- package/src/transformers/features/http/CreateHttpIsQueryTransformer.ts +9 -9
- package/src/transformers/features/http/CreateHttpParameterTransformer.ts +9 -9
- package/src/transformers/features/http/CreateHttpQueryTransformer.ts +9 -9
- package/src/transformers/features/http/CreateHttpValidateHeadersTransformer.ts +12 -12
- package/src/transformers/features/http/CreateHttpValidateQueryTransformer.ts +12 -12
- package/src/transformers/features/http/HttpAssertHeadersTransformer.ts +10 -10
- package/src/transformers/features/http/HttpAssertQueryTransformer.ts +10 -10
- package/src/transformers/features/http/HttpHeadersTransformer.ts +9 -9
- package/src/transformers/features/http/HttpIsHeadersTransformer.ts +9 -9
- package/src/transformers/features/http/HttpIsQueryTransformer.ts +9 -9
- package/src/transformers/features/http/HttpParameterTransformer.ts +9 -9
- package/src/transformers/features/http/HttpQueryTransformer.ts +9 -9
- package/src/transformers/features/http/HttpValidateHeadersTransformer.ts +10 -10
- package/src/transformers/features/http/HttpValidateQueryTransformer.ts +10 -10
|
@@ -1,180 +1,180 @@
|
|
|
1
|
-
import { IJsonComponents } from "../../schemas/json/IJsonComponents";
|
|
2
|
-
import { IJsonSchema } from "../../schemas/json/IJsonSchema";
|
|
3
|
-
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
4
|
-
import { MetadataAtomic } from "../../schemas/metadata/MetadataAtomic";
|
|
5
|
-
|
|
6
|
-
import { AtomicPredicator } from "../helpers/AtomicPredicator";
|
|
7
|
-
import { JsonApplicationProgrammer } from "../json/JsonApplicationProgrammer";
|
|
8
|
-
import { application_alias } from "./application_alias";
|
|
9
|
-
import { application_array } from "./application_array";
|
|
10
|
-
import { application_boolean } from "./application_boolean";
|
|
11
|
-
import { application_constant } from "./application_constant";
|
|
12
|
-
import { application_escaped } from "./application_escaped";
|
|
13
|
-
import { application_native } from "./application_native";
|
|
14
|
-
import { application_number } from "./application_number";
|
|
15
|
-
import { application_object } from "./application_object";
|
|
16
|
-
import { application_string } from "./application_string";
|
|
17
|
-
import { application_templates } from "./application_templates";
|
|
18
|
-
import { application_tuple } from "./application_tuple";
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @internal
|
|
22
|
-
*/
|
|
23
|
-
export const application_schema =
|
|
24
|
-
(options: JsonApplicationProgrammer.IOptions) =>
|
|
25
|
-
<BlockNever extends boolean>(blockNever: BlockNever) =>
|
|
26
|
-
(components: IJsonComponents) =>
|
|
27
|
-
(meta: Metadata) =>
|
|
28
|
-
(
|
|
29
|
-
attribute: IJsonSchema.IAttribute,
|
|
30
|
-
): BlockNever extends true ? IJsonSchema | null : IJsonSchema => {
|
|
31
|
-
// VULNERABLE CASE
|
|
32
|
-
if (meta.any === true)
|
|
33
|
-
return {
|
|
34
|
-
...attribute,
|
|
35
|
-
type: undefined,
|
|
36
|
-
};
|
|
37
|
-
else if (meta.nullable && meta.empty())
|
|
38
|
-
return { type: "null", ...attribute };
|
|
39
|
-
|
|
40
|
-
//----
|
|
41
|
-
// GATHER UNION SCHEMAS
|
|
42
|
-
//----
|
|
43
|
-
const union: IJsonSchema[] = [];
|
|
44
|
-
if (meta.nullable && options.purpose !== "swagger")
|
|
45
|
-
union.push({
|
|
46
|
-
...attribute,
|
|
47
|
-
type: "null",
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
const insert =
|
|
51
|
-
meta.nullable && options.purpose === "swagger"
|
|
52
|
-
? (s: IJsonSchema) =>
|
|
53
|
-
union.push({
|
|
54
|
-
...s,
|
|
55
|
-
nullable: (s as IJsonSchema.ISignificant<any>).type
|
|
56
|
-
? true
|
|
57
|
-
: undefined,
|
|
58
|
-
} as IJsonSchema)
|
|
59
|
-
: (schema: IJsonSchema) => union.push(schema);
|
|
60
|
-
|
|
61
|
-
// toJSON() METHOD
|
|
62
|
-
if (meta.escaped !== null)
|
|
63
|
-
union.push(
|
|
64
|
-
...application_escaped(options)(blockNever)(components)(
|
|
65
|
-
meta.escaped,
|
|
66
|
-
)(attribute),
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
// ATOMIC TYPES
|
|
70
|
-
if (meta.templates.length && AtomicPredicator.template(meta))
|
|
71
|
-
insert(application_templates(meta)(attribute));
|
|
72
|
-
for (const constant of meta.constants)
|
|
73
|
-
if (constant.type === "bigint") throw new TypeError(NO_BIGINT);
|
|
74
|
-
else if (
|
|
75
|
-
(constant.type === "string" && meta.templates.length) ||
|
|
76
|
-
AtomicPredicator.constant(meta)(constant.type) === false
|
|
77
|
-
)
|
|
78
|
-
continue;
|
|
79
|
-
else insert(application_constant(constant)(attribute));
|
|
80
|
-
for (const a of meta.atomics)
|
|
81
|
-
if (a.type === "bigint") throw new TypeError(NO_BIGINT);
|
|
82
|
-
else if (a.type === "boolean")
|
|
83
|
-
application_boolean(a)(attribute).forEach(insert);
|
|
84
|
-
else if (a.type === "number")
|
|
85
|
-
application_number(a)(attribute).forEach(insert);
|
|
86
|
-
else if (a.type === "string")
|
|
87
|
-
application_string(meta)(a)(attribute).forEach(insert);
|
|
88
|
-
|
|
89
|
-
// ARRAY
|
|
90
|
-
for (const array of meta.arrays)
|
|
91
|
-
application_array(options)(components)(array)(attribute).forEach(
|
|
92
|
-
(s) => insert(s),
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
// TUPLE
|
|
96
|
-
for (const tuple of meta.tuples)
|
|
97
|
-
insert(application_tuple(options)(components)(tuple)(attribute));
|
|
98
|
-
|
|
99
|
-
// NATIVES
|
|
100
|
-
for (const native of meta.natives)
|
|
101
|
-
if (AtomicPredicator.native(native)) {
|
|
102
|
-
const type: string = native.toLowerCase();
|
|
103
|
-
if (meta.atomics.some((a) => a.type === type)) continue;
|
|
104
|
-
else if (type === "bigint") throw new TypeError(NO_BIGINT);
|
|
105
|
-
else if (type === "boolean")
|
|
106
|
-
insert(
|
|
107
|
-
application_boolean(
|
|
108
|
-
MetadataAtomic.create({
|
|
109
|
-
type: "boolean",
|
|
110
|
-
tags: [],
|
|
111
|
-
}),
|
|
112
|
-
)(attribute)[0]!,
|
|
113
|
-
);
|
|
114
|
-
else if (type === "number")
|
|
115
|
-
insert(
|
|
116
|
-
application_number(
|
|
117
|
-
MetadataAtomic.create({
|
|
118
|
-
type: "number",
|
|
119
|
-
tags: [],
|
|
120
|
-
}),
|
|
121
|
-
)(attribute)[0]!,
|
|
122
|
-
);
|
|
123
|
-
else if (type === "string")
|
|
124
|
-
insert(
|
|
125
|
-
application_string(meta)(
|
|
126
|
-
MetadataAtomic.create({
|
|
127
|
-
type: "string",
|
|
128
|
-
tags: [],
|
|
129
|
-
}),
|
|
130
|
-
)(attribute)[0]!,
|
|
131
|
-
);
|
|
132
|
-
} else
|
|
133
|
-
insert(
|
|
134
|
-
application_native(options)(components)(native)({
|
|
135
|
-
nullable: meta.nullable,
|
|
136
|
-
attribute,
|
|
137
|
-
}),
|
|
138
|
-
);
|
|
139
|
-
if (meta.sets.length)
|
|
140
|
-
insert(
|
|
141
|
-
application_native(options)(components)(`Set`)({
|
|
142
|
-
nullable: meta.nullable,
|
|
143
|
-
attribute,
|
|
144
|
-
}),
|
|
145
|
-
);
|
|
146
|
-
if (meta.maps.length)
|
|
147
|
-
insert(
|
|
148
|
-
application_native(options)(components)(`Map`)({
|
|
149
|
-
nullable: meta.nullable,
|
|
150
|
-
attribute,
|
|
151
|
-
}),
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
// OBJECT
|
|
155
|
-
for (const obj of meta.objects)
|
|
156
|
-
insert(application_object(options)(components)(obj)(meta.nullable));
|
|
157
|
-
|
|
158
|
-
// ALIASES
|
|
159
|
-
for (const alias of meta.aliases)
|
|
160
|
-
insert(
|
|
161
|
-
application_alias(options)(blockNever)(components)(alias)(
|
|
162
|
-
meta.nullable,
|
|
163
|
-
),
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
//----
|
|
167
|
-
// RETURNS
|
|
168
|
-
//----
|
|
169
|
-
if (union.length === 0)
|
|
170
|
-
return blockNever === true
|
|
171
|
-
? null!
|
|
172
|
-
: {
|
|
173
|
-
...attribute,
|
|
174
|
-
type: undefined,
|
|
175
|
-
};
|
|
176
|
-
else if (union.length === 1) return union[0]!;
|
|
177
|
-
return { oneOf: union, ...attribute };
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
const NO_BIGINT = "Error on typia.application(): does not allow bigint type.";
|
|
1
|
+
import { IJsonComponents } from "../../schemas/json/IJsonComponents";
|
|
2
|
+
import { IJsonSchema } from "../../schemas/json/IJsonSchema";
|
|
3
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
4
|
+
import { MetadataAtomic } from "../../schemas/metadata/MetadataAtomic";
|
|
5
|
+
|
|
6
|
+
import { AtomicPredicator } from "../helpers/AtomicPredicator";
|
|
7
|
+
import { JsonApplicationProgrammer } from "../json/JsonApplicationProgrammer";
|
|
8
|
+
import { application_alias } from "./application_alias";
|
|
9
|
+
import { application_array } from "./application_array";
|
|
10
|
+
import { application_boolean } from "./application_boolean";
|
|
11
|
+
import { application_constant } from "./application_constant";
|
|
12
|
+
import { application_escaped } from "./application_escaped";
|
|
13
|
+
import { application_native } from "./application_native";
|
|
14
|
+
import { application_number } from "./application_number";
|
|
15
|
+
import { application_object } from "./application_object";
|
|
16
|
+
import { application_string } from "./application_string";
|
|
17
|
+
import { application_templates } from "./application_templates";
|
|
18
|
+
import { application_tuple } from "./application_tuple";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export const application_schema =
|
|
24
|
+
(options: JsonApplicationProgrammer.IOptions) =>
|
|
25
|
+
<BlockNever extends boolean>(blockNever: BlockNever) =>
|
|
26
|
+
(components: IJsonComponents) =>
|
|
27
|
+
(meta: Metadata) =>
|
|
28
|
+
(
|
|
29
|
+
attribute: IJsonSchema.IAttribute,
|
|
30
|
+
): BlockNever extends true ? IJsonSchema | null : IJsonSchema => {
|
|
31
|
+
// VULNERABLE CASE
|
|
32
|
+
if (meta.any === true)
|
|
33
|
+
return {
|
|
34
|
+
...attribute,
|
|
35
|
+
type: undefined,
|
|
36
|
+
};
|
|
37
|
+
else if (meta.nullable && meta.empty())
|
|
38
|
+
return { type: "null", ...attribute };
|
|
39
|
+
|
|
40
|
+
//----
|
|
41
|
+
// GATHER UNION SCHEMAS
|
|
42
|
+
//----
|
|
43
|
+
const union: IJsonSchema[] = [];
|
|
44
|
+
if (meta.nullable && options.purpose !== "swagger")
|
|
45
|
+
union.push({
|
|
46
|
+
...attribute,
|
|
47
|
+
type: "null",
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const insert =
|
|
51
|
+
meta.nullable && options.purpose === "swagger"
|
|
52
|
+
? (s: IJsonSchema) =>
|
|
53
|
+
union.push({
|
|
54
|
+
...s,
|
|
55
|
+
nullable: (s as IJsonSchema.ISignificant<any>).type
|
|
56
|
+
? true
|
|
57
|
+
: undefined,
|
|
58
|
+
} as IJsonSchema)
|
|
59
|
+
: (schema: IJsonSchema) => union.push(schema);
|
|
60
|
+
|
|
61
|
+
// toJSON() METHOD
|
|
62
|
+
if (meta.escaped !== null)
|
|
63
|
+
union.push(
|
|
64
|
+
...application_escaped(options)(blockNever)(components)(
|
|
65
|
+
meta.escaped,
|
|
66
|
+
)(attribute),
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
// ATOMIC TYPES
|
|
70
|
+
if (meta.templates.length && AtomicPredicator.template(meta))
|
|
71
|
+
insert(application_templates(meta)(attribute));
|
|
72
|
+
for (const constant of meta.constants)
|
|
73
|
+
if (constant.type === "bigint") throw new TypeError(NO_BIGINT);
|
|
74
|
+
else if (
|
|
75
|
+
(constant.type === "string" && meta.templates.length) ||
|
|
76
|
+
AtomicPredicator.constant(meta)(constant.type) === false
|
|
77
|
+
)
|
|
78
|
+
continue;
|
|
79
|
+
else insert(application_constant(constant)(attribute));
|
|
80
|
+
for (const a of meta.atomics)
|
|
81
|
+
if (a.type === "bigint") throw new TypeError(NO_BIGINT);
|
|
82
|
+
else if (a.type === "boolean")
|
|
83
|
+
application_boolean(a)(attribute).forEach(insert);
|
|
84
|
+
else if (a.type === "number")
|
|
85
|
+
application_number(a)(attribute).forEach(insert);
|
|
86
|
+
else if (a.type === "string")
|
|
87
|
+
application_string(meta)(a)(attribute).forEach(insert);
|
|
88
|
+
|
|
89
|
+
// ARRAY
|
|
90
|
+
for (const array of meta.arrays)
|
|
91
|
+
application_array(options)(components)(array)(attribute).forEach(
|
|
92
|
+
(s) => insert(s),
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
// TUPLE
|
|
96
|
+
for (const tuple of meta.tuples)
|
|
97
|
+
insert(application_tuple(options)(components)(tuple)(attribute));
|
|
98
|
+
|
|
99
|
+
// NATIVES
|
|
100
|
+
for (const native of meta.natives)
|
|
101
|
+
if (AtomicPredicator.native(native)) {
|
|
102
|
+
const type: string = native.toLowerCase();
|
|
103
|
+
if (meta.atomics.some((a) => a.type === type)) continue;
|
|
104
|
+
else if (type === "bigint") throw new TypeError(NO_BIGINT);
|
|
105
|
+
else if (type === "boolean")
|
|
106
|
+
insert(
|
|
107
|
+
application_boolean(
|
|
108
|
+
MetadataAtomic.create({
|
|
109
|
+
type: "boolean",
|
|
110
|
+
tags: [],
|
|
111
|
+
}),
|
|
112
|
+
)(attribute)[0]!,
|
|
113
|
+
);
|
|
114
|
+
else if (type === "number")
|
|
115
|
+
insert(
|
|
116
|
+
application_number(
|
|
117
|
+
MetadataAtomic.create({
|
|
118
|
+
type: "number",
|
|
119
|
+
tags: [],
|
|
120
|
+
}),
|
|
121
|
+
)(attribute)[0]!,
|
|
122
|
+
);
|
|
123
|
+
else if (type === "string")
|
|
124
|
+
insert(
|
|
125
|
+
application_string(meta)(
|
|
126
|
+
MetadataAtomic.create({
|
|
127
|
+
type: "string",
|
|
128
|
+
tags: [],
|
|
129
|
+
}),
|
|
130
|
+
)(attribute)[0]!,
|
|
131
|
+
);
|
|
132
|
+
} else
|
|
133
|
+
insert(
|
|
134
|
+
application_native(options)(components)(native)({
|
|
135
|
+
nullable: meta.nullable,
|
|
136
|
+
attribute,
|
|
137
|
+
}),
|
|
138
|
+
);
|
|
139
|
+
if (meta.sets.length)
|
|
140
|
+
insert(
|
|
141
|
+
application_native(options)(components)(`Set`)({
|
|
142
|
+
nullable: meta.nullable,
|
|
143
|
+
attribute,
|
|
144
|
+
}),
|
|
145
|
+
);
|
|
146
|
+
if (meta.maps.length)
|
|
147
|
+
insert(
|
|
148
|
+
application_native(options)(components)(`Map`)({
|
|
149
|
+
nullable: meta.nullable,
|
|
150
|
+
attribute,
|
|
151
|
+
}),
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
// OBJECT
|
|
155
|
+
for (const obj of meta.objects)
|
|
156
|
+
insert(application_object(options)(components)(obj)(meta.nullable));
|
|
157
|
+
|
|
158
|
+
// ALIASES
|
|
159
|
+
for (const alias of meta.aliases)
|
|
160
|
+
insert(
|
|
161
|
+
application_alias(options)(blockNever)(components)(alias)(
|
|
162
|
+
meta.nullable,
|
|
163
|
+
),
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
//----
|
|
167
|
+
// RETURNS
|
|
168
|
+
//----
|
|
169
|
+
if (union.length === 0)
|
|
170
|
+
return blockNever === true
|
|
171
|
+
? null!
|
|
172
|
+
: {
|
|
173
|
+
...attribute,
|
|
174
|
+
type: undefined,
|
|
175
|
+
};
|
|
176
|
+
else if (union.length === 1) return union[0]!;
|
|
177
|
+
return { oneOf: union, ...attribute };
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const NO_BIGINT = "Error on typia.application(): does not allow bigint type.";
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import { IJsonSchema } from "../../schemas/json/IJsonSchema";
|
|
2
|
-
import { IMetadataTypeTag } from "../../schemas/metadata/IMetadataTypeTag";
|
|
3
|
-
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
4
|
-
import { MetadataAtomic } from "../../schemas/metadata/MetadataAtomic";
|
|
5
|
-
|
|
6
|
-
import { application_default_string } from "./application_default_string";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @internal
|
|
10
|
-
*/
|
|
11
|
-
export const application_string =
|
|
12
|
-
(meta: Metadata) =>
|
|
13
|
-
(atomic: MetadataAtomic) =>
|
|
14
|
-
(attribute: IJsonSchema.IAttribute): IJsonSchema.IString[] => {
|
|
15
|
-
// DEFAULT CONFIGURATION
|
|
16
|
-
const base: IJsonSchema.IString = {
|
|
17
|
-
...attribute,
|
|
18
|
-
type: "string",
|
|
19
|
-
};
|
|
20
|
-
const out = (schema: IJsonSchema.IString) => {
|
|
21
|
-
schema.default ??=
|
|
22
|
-
application_default_string(meta)(attribute)(base);
|
|
23
|
-
return schema;
|
|
24
|
-
};
|
|
25
|
-
if (atomic.tags.length === 0) return [out(base)];
|
|
26
|
-
|
|
27
|
-
// CONSIDER TYPE TAGS
|
|
28
|
-
const union: IJsonSchema.IString[] = atomic.tags.map(
|
|
29
|
-
(row) => application_string_tags({ ...base })(row)!,
|
|
30
|
-
);
|
|
31
|
-
const map: Map<string, IJsonSchema.IString> = new Map(
|
|
32
|
-
union.map((u) => [JSON.stringify(u), u]),
|
|
33
|
-
);
|
|
34
|
-
return [...map.values()].map((s) => out(s));
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const application_string_tags =
|
|
38
|
-
(base: IJsonSchema.IString) =>
|
|
39
|
-
(row: IMetadataTypeTag[]): IJsonSchema.IString | null => {
|
|
40
|
-
for (const tag of row
|
|
41
|
-
.slice()
|
|
42
|
-
.sort((a, b) => a.kind.localeCompare(b.kind)))
|
|
43
|
-
if (tag.kind === "minLength" && typeof tag.value === "number")
|
|
44
|
-
base.minLength = tag.value;
|
|
45
|
-
else if (tag.kind === "maxLength" && typeof tag.value === "number")
|
|
46
|
-
base.maxLength = tag.value;
|
|
47
|
-
else if (tag.kind === "format" && typeof tag.value === "string")
|
|
48
|
-
base.format = tag.value;
|
|
49
|
-
else if (tag.kind === "pattern") base.pattern = tag.value;
|
|
50
|
-
else if (tag.kind === "default" && typeof tag.value === "string")
|
|
51
|
-
base.default = tag.value;
|
|
52
|
-
base["x-typia-typeTags"] = row;
|
|
53
|
-
return base;
|
|
54
|
-
};
|
|
1
|
+
import { IJsonSchema } from "../../schemas/json/IJsonSchema";
|
|
2
|
+
import { IMetadataTypeTag } from "../../schemas/metadata/IMetadataTypeTag";
|
|
3
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
4
|
+
import { MetadataAtomic } from "../../schemas/metadata/MetadataAtomic";
|
|
5
|
+
|
|
6
|
+
import { application_default_string } from "./application_default_string";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export const application_string =
|
|
12
|
+
(meta: Metadata) =>
|
|
13
|
+
(atomic: MetadataAtomic) =>
|
|
14
|
+
(attribute: IJsonSchema.IAttribute): IJsonSchema.IString[] => {
|
|
15
|
+
// DEFAULT CONFIGURATION
|
|
16
|
+
const base: IJsonSchema.IString = {
|
|
17
|
+
...attribute,
|
|
18
|
+
type: "string",
|
|
19
|
+
};
|
|
20
|
+
const out = (schema: IJsonSchema.IString) => {
|
|
21
|
+
schema.default ??=
|
|
22
|
+
application_default_string(meta)(attribute)(base);
|
|
23
|
+
return schema;
|
|
24
|
+
};
|
|
25
|
+
if (atomic.tags.length === 0) return [out(base)];
|
|
26
|
+
|
|
27
|
+
// CONSIDER TYPE TAGS
|
|
28
|
+
const union: IJsonSchema.IString[] = atomic.tags.map(
|
|
29
|
+
(row) => application_string_tags({ ...base })(row)!,
|
|
30
|
+
);
|
|
31
|
+
const map: Map<string, IJsonSchema.IString> = new Map(
|
|
32
|
+
union.map((u) => [JSON.stringify(u), u]),
|
|
33
|
+
);
|
|
34
|
+
return [...map.values()].map((s) => out(s));
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const application_string_tags =
|
|
38
|
+
(base: IJsonSchema.IString) =>
|
|
39
|
+
(row: IMetadataTypeTag[]): IJsonSchema.IString | null => {
|
|
40
|
+
for (const tag of row
|
|
41
|
+
.slice()
|
|
42
|
+
.sort((a, b) => a.kind.localeCompare(b.kind)))
|
|
43
|
+
if (tag.kind === "minLength" && typeof tag.value === "number")
|
|
44
|
+
base.minLength = tag.value;
|
|
45
|
+
else if (tag.kind === "maxLength" && typeof tag.value === "number")
|
|
46
|
+
base.maxLength = tag.value;
|
|
47
|
+
else if (tag.kind === "format" && typeof tag.value === "string")
|
|
48
|
+
base.format = tag.value;
|
|
49
|
+
else if (tag.kind === "pattern") base.pattern = tag.value;
|
|
50
|
+
else if (tag.kind === "default" && typeof tag.value === "string")
|
|
51
|
+
base.default = tag.value;
|
|
52
|
+
base["x-typia-typeTags"] = row;
|
|
53
|
+
return base;
|
|
54
|
+
};
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { ExpressionFactory } from "../../factories/ExpressionFactory";
|
|
4
|
-
|
|
5
|
-
import { IMetadataTypeTag } from "../../schemas/metadata/IMetadataTypeTag";
|
|
6
|
-
import { MetadataArray } from "../../schemas/metadata/MetadataArray";
|
|
7
|
-
|
|
8
|
-
import { IProject } from "../../transformers/IProject";
|
|
9
|
-
|
|
10
|
-
import { ICheckEntry } from "../helpers/ICheckEntry";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @internal
|
|
14
|
-
*/
|
|
15
|
-
export const check_array_length =
|
|
16
|
-
(project: IProject) =>
|
|
17
|
-
(array: MetadataArray) =>
|
|
18
|
-
(input: ts.Expression): ICheckEntry => {
|
|
19
|
-
const conditions: ICheckEntry.ICondition[][] = check_string_type_tags(
|
|
20
|
-
project,
|
|
21
|
-
)(array.tags)(input);
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
expected: array.getName(),
|
|
25
|
-
expression: null,
|
|
26
|
-
conditions,
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const check_string_type_tags =
|
|
31
|
-
(project: IProject) =>
|
|
32
|
-
(matrix: IMetadataTypeTag[][]) =>
|
|
33
|
-
(input: ts.Expression): ICheckEntry.ICondition[][] =>
|
|
34
|
-
matrix
|
|
35
|
-
.map((row) => row.filter((tag) => !!tag.validate))
|
|
36
|
-
.filter((row) => !!row.length)
|
|
37
|
-
.map((row) =>
|
|
38
|
-
row.map((tag) => ({
|
|
39
|
-
expected: `Array<> & ${tag.name}`,
|
|
40
|
-
expression: ExpressionFactory.transpile(project.context)(
|
|
41
|
-
tag.validate!,
|
|
42
|
-
)(input),
|
|
43
|
-
})),
|
|
44
|
-
);
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { ExpressionFactory } from "../../factories/ExpressionFactory";
|
|
4
|
+
|
|
5
|
+
import { IMetadataTypeTag } from "../../schemas/metadata/IMetadataTypeTag";
|
|
6
|
+
import { MetadataArray } from "../../schemas/metadata/MetadataArray";
|
|
7
|
+
|
|
8
|
+
import { IProject } from "../../transformers/IProject";
|
|
9
|
+
|
|
10
|
+
import { ICheckEntry } from "../helpers/ICheckEntry";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export const check_array_length =
|
|
16
|
+
(project: IProject) =>
|
|
17
|
+
(array: MetadataArray) =>
|
|
18
|
+
(input: ts.Expression): ICheckEntry => {
|
|
19
|
+
const conditions: ICheckEntry.ICondition[][] = check_string_type_tags(
|
|
20
|
+
project,
|
|
21
|
+
)(array.tags)(input);
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
expected: array.getName(),
|
|
25
|
+
expression: null,
|
|
26
|
+
conditions,
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const check_string_type_tags =
|
|
31
|
+
(project: IProject) =>
|
|
32
|
+
(matrix: IMetadataTypeTag[][]) =>
|
|
33
|
+
(input: ts.Expression): ICheckEntry.ICondition[][] =>
|
|
34
|
+
matrix
|
|
35
|
+
.map((row) => row.filter((tag) => !!tag.validate))
|
|
36
|
+
.filter((row) => !!row.length)
|
|
37
|
+
.map((row) =>
|
|
38
|
+
row.map((tag) => ({
|
|
39
|
+
expected: `Array<> & ${tag.name}`,
|
|
40
|
+
expression: ExpressionFactory.transpile(project.context)(
|
|
41
|
+
tag.validate!,
|
|
42
|
+
)(input),
|
|
43
|
+
})),
|
|
44
|
+
);
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { ExpressionFactory } from "../../factories/ExpressionFactory";
|
|
4
|
-
|
|
5
|
-
import { MetadataAtomic } from "../../schemas/metadata/MetadataAtomic";
|
|
6
|
-
|
|
7
|
-
import { IProject } from "../../transformers/IProject";
|
|
8
|
-
|
|
9
|
-
import { ICheckEntry } from "../helpers/ICheckEntry";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
export const check_bigint =
|
|
15
|
-
(project: IProject) =>
|
|
16
|
-
(atomic: MetadataAtomic) =>
|
|
17
|
-
(input: ts.Expression): ICheckEntry => {
|
|
18
|
-
const conditions: ICheckEntry.ICondition[][] =
|
|
19
|
-
check_bigint_type_tags(project)(atomic)(input);
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
expected: atomic.getName(),
|
|
23
|
-
expression: ts.factory.createStrictEquality(
|
|
24
|
-
ts.factory.createStringLiteral("bigint"),
|
|
25
|
-
ts.factory.createTypeOfExpression(input),
|
|
26
|
-
),
|
|
27
|
-
conditions,
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* @internal
|
|
33
|
-
*/
|
|
34
|
-
const check_bigint_type_tags =
|
|
35
|
-
(project: IProject) =>
|
|
36
|
-
(atomic: MetadataAtomic) =>
|
|
37
|
-
(input: ts.Expression): ICheckEntry.ICondition[][] =>
|
|
38
|
-
atomic.tags
|
|
39
|
-
.map((row) => row.filter((tag) => !!tag.validate))
|
|
40
|
-
.filter((row) => !!row.length)
|
|
41
|
-
.map((row) =>
|
|
42
|
-
row.map((tag) => ({
|
|
43
|
-
expected: `bigint & ${tag.name}`,
|
|
44
|
-
expression: ExpressionFactory.transpile(project.context)(
|
|
45
|
-
tag.validate!,
|
|
46
|
-
)(input),
|
|
47
|
-
})),
|
|
48
|
-
);
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { ExpressionFactory } from "../../factories/ExpressionFactory";
|
|
4
|
+
|
|
5
|
+
import { MetadataAtomic } from "../../schemas/metadata/MetadataAtomic";
|
|
6
|
+
|
|
7
|
+
import { IProject } from "../../transformers/IProject";
|
|
8
|
+
|
|
9
|
+
import { ICheckEntry } from "../helpers/ICheckEntry";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export const check_bigint =
|
|
15
|
+
(project: IProject) =>
|
|
16
|
+
(atomic: MetadataAtomic) =>
|
|
17
|
+
(input: ts.Expression): ICheckEntry => {
|
|
18
|
+
const conditions: ICheckEntry.ICondition[][] =
|
|
19
|
+
check_bigint_type_tags(project)(atomic)(input);
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
expected: atomic.getName(),
|
|
23
|
+
expression: ts.factory.createStrictEquality(
|
|
24
|
+
ts.factory.createStringLiteral("bigint"),
|
|
25
|
+
ts.factory.createTypeOfExpression(input),
|
|
26
|
+
),
|
|
27
|
+
conditions,
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
const check_bigint_type_tags =
|
|
35
|
+
(project: IProject) =>
|
|
36
|
+
(atomic: MetadataAtomic) =>
|
|
37
|
+
(input: ts.Expression): ICheckEntry.ICondition[][] =>
|
|
38
|
+
atomic.tags
|
|
39
|
+
.map((row) => row.filter((tag) => !!tag.validate))
|
|
40
|
+
.filter((row) => !!row.length)
|
|
41
|
+
.map((row) =>
|
|
42
|
+
row.map((tag) => ({
|
|
43
|
+
expected: `bigint & ${tag.name}`,
|
|
44
|
+
expression: ExpressionFactory.transpile(project.context)(
|
|
45
|
+
tag.validate!,
|
|
46
|
+
)(input),
|
|
47
|
+
})),
|
|
48
|
+
);
|