typia 3.4.15 → 3.5.0-dev.20221222
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/README.md +48 -7
- package/lib/factories/MetadataCollection.d.ts +1 -9
- package/lib/factories/MetadataCollection.js +2 -75
- package/lib/factories/MetadataCollection.js.map +1 -1
- package/lib/factories/ProtocolFactory.d.ts +8 -0
- package/lib/factories/ProtocolFactory.js +119 -0
- package/lib/factories/ProtocolFactory.js.map +1 -0
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.d.ts +11 -0
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.js +76 -0
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.js.map +1 -0
- package/lib/factories/internal/protocols/emplace_protocol_object.d.ts +3 -0
- package/lib/factories/internal/protocols/emplace_protocol_object.js +47 -0
- package/lib/factories/internal/protocols/emplace_protocol_object.js.map +1 -0
- package/lib/factories/internal/protocols/emplace_protocol_property.d.ts +4 -0
- package/lib/factories/internal/protocols/emplace_protocol_property.js +20 -0
- package/lib/factories/internal/protocols/emplace_protocol_property.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_atomic.d.ts +3 -0
- package/lib/factories/internal/protocols/iterate_protocol_atomic.js +69 -0
- package/lib/factories/internal/protocols/iterate_protocol_atomic.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_constant.d.ts +2 -0
- package/lib/factories/internal/protocols/iterate_protocol_constant.js +30 -0
- package/lib/factories/internal/protocols/iterate_protocol_constant.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_main.d.ts +3 -0
- package/lib/factories/internal/protocols/iterate_protocol_main.js +17 -0
- package/lib/factories/internal/protocols/iterate_protocol_main.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_map.d.ts +3 -0
- package/lib/factories/internal/protocols/iterate_protocol_map.js +71 -0
- package/lib/factories/internal/protocols/iterate_protocol_map.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_metadata.d.ts +5 -0
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js +192 -0
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_native.d.ts +2 -0
- package/lib/factories/internal/protocols/iterate_protocol_native.js +33 -0
- package/lib/factories/internal/protocols/iterate_protocol_native.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_repeated.d.ts +4 -0
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js +24 -0
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_tuple.d.ts +3 -0
- package/lib/factories/internal/protocols/iterate_protocol_tuple.js +46 -0
- package/lib/factories/internal/protocols/iterate_protocol_tuple.js.map +1 -0
- package/lib/functional/$proto_bytes.d.ts +2 -0
- package/lib/functional/$proto_bytes.js +37 -0
- package/lib/functional/$proto_bytes.js.map +1 -0
- package/lib/functional/$proto_field.d.ts +10 -0
- package/lib/functional/$proto_field.js +42 -0
- package/lib/functional/$proto_field.js.map +1 -0
- package/lib/functional/$proto_float.d.ts +4 -0
- package/lib/functional/$proto_float.js +28 -0
- package/lib/functional/$proto_float.js.map +1 -0
- package/lib/functional/$proto_i32.d.ts +2 -0
- package/lib/functional/$proto_i32.js +23 -0
- package/lib/functional/$proto_i32.js.map +1 -0
- package/lib/functional/$proto_i64.d.ts +2 -0
- package/lib/functional/$proto_i64.js +31 -0
- package/lib/functional/$proto_i64.js.map +1 -0
- package/lib/functional/$proto_size.d.ts +6 -0
- package/lib/functional/$proto_size.js +76 -0
- package/lib/functional/$proto_size.js.map +1 -0
- package/lib/functional/$proto_string.d.ts +2 -0
- package/lib/functional/$proto_string.js +34 -0
- package/lib/functional/$proto_string.js.map +1 -0
- package/lib/functional/$varint.d.ts +6 -0
- package/lib/functional/$varint.js +99 -0
- package/lib/functional/$varint.js.map +1 -0
- package/lib/functional/$zigzag.d.ts +4 -0
- package/lib/functional/$zigzag.js +34 -0
- package/lib/functional/$zigzag.js.map +1 -0
- package/lib/messages/IProtocolMessage.d.ts +5 -0
- package/lib/messages/IProtocolMessage.js +3 -0
- package/lib/messages/IProtocolMessage.js.map +1 -0
- package/lib/messages/IProtocolProperty.d.ts +11 -0
- package/lib/messages/IProtocolProperty.js +3 -0
- package/lib/messages/IProtocolProperty.js.map +1 -0
- package/lib/metadata/IMetadataTag.d.ts +7 -3
- package/lib/metadata/Metadata.js +1 -1
- package/lib/metadata/Metadata.js.map +1 -1
- package/lib/module.d.ts +2 -0
- package/lib/module.js +5 -1
- package/lib/module.js.map +1 -1
- package/lib/programmers/MessageProgrammer.d.ts +5 -0
- package/lib/programmers/MessageProgrammer.js +134 -0
- package/lib/programmers/MessageProgrammer.js.map +1 -0
- package/lib/programmers/internal/application_object.js +9 -9
- package/lib/programmers/internal/application_object.js.map +1 -1
- package/lib/programmers/internal/application_schema.js +5 -3
- package/lib/programmers/internal/application_schema.js.map +1 -1
- package/lib/transformers/CallExpressionTransformer.js +3 -1
- package/lib/transformers/CallExpressionTransformer.js.map +1 -1
- package/lib/transformers/features/miscellaneous/ApplicationTransformer.js +1 -3
- package/lib/transformers/features/miscellaneous/ApplicationTransformer.js.map +1 -1
- package/lib/transformers/features/protocols/MessageTransformer.d.ts +5 -0
- package/lib/transformers/features/protocols/MessageTransformer.js +17 -0
- package/lib/transformers/features/protocols/MessageTransformer.js.map +1 -0
- package/lib/utils/NameEncoder.d.ts +4 -0
- package/lib/utils/NameEncoder.js +89 -0
- package/lib/utils/NameEncoder.js.map +1 -0
- package/package.json +2 -3
- package/src/executable/internal/TypiaSetupWizard.ts +173 -173
- package/src/factories/MetadataCollection.ts +83 -122
- package/src/factories/MetadataFactory.ts +47 -47
- package/src/factories/MetadataTagFactory.ts +351 -351
- package/src/factories/ProtocolFactory.ts +92 -0
- package/src/factories/internal/metadata/MetadataHelper.ts +12 -12
- package/src/factories/internal/metadata/emplace_metadata_object.ts +140 -140
- package/src/factories/internal/metadata/explore_metadata.ts +92 -92
- package/src/factories/internal/metadata/iterate_metadata.ts +80 -80
- package/src/factories/internal/metadata/iterate_metadata_array.ts +29 -29
- package/src/factories/internal/metadata/iterate_metadata_atomic.ts +59 -59
- package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
- package/src/factories/internal/metadata/iterate_metadata_constant.ts +58 -58
- package/src/factories/internal/metadata/iterate_metadata_map.ts +41 -41
- package/src/factories/internal/metadata/iterate_metadata_native.ts +227 -227
- package/src/factories/internal/metadata/iterate_metadata_object.ts +48 -48
- package/src/factories/internal/metadata/iterate_metadata_resolve.ts +27 -27
- package/src/factories/internal/metadata/iterate_metadata_set.ts +33 -33
- package/src/factories/internal/metadata/iterate_metadata_template.ts +38 -38
- package/src/factories/internal/metadata/iterate_metadata_tuple.ts +45 -45
- package/src/factories/internal/metadata/iterate_metadata_union.ts +59 -59
- package/src/factories/internal/protocols/ProtocolMetadataUtil.ts +81 -0
- package/src/factories/internal/protocols/emplace_protocol_object.ts +25 -0
- package/src/factories/internal/protocols/emplace_protocol_property.ts +12 -0
- package/src/factories/internal/protocols/iterate_protocol_atomic.ts +34 -0
- package/src/factories/internal/protocols/iterate_protocol_constant.ts +27 -0
- package/src/factories/internal/protocols/iterate_protocol_main.ts +19 -0
- package/src/factories/internal/protocols/iterate_protocol_map.ts +38 -0
- package/src/factories/internal/protocols/iterate_protocol_metadata.ts +76 -0
- package/src/factories/internal/protocols/iterate_protocol_native.ts +34 -0
- package/src/factories/internal/protocols/iterate_protocol_repeated.ts +25 -0
- package/src/factories/internal/protocols/iterate_protocol_tuple.ts +25 -0
- package/src/functional/$number.ts +12 -12
- package/src/functional/$proto_bytes.ts +25 -0
- package/src/functional/$proto_field.ts +30 -0
- package/src/functional/$proto_float.ts +37 -0
- package/src/functional/$proto_i32.ts +29 -0
- package/src/functional/$proto_i64.ts +37 -0
- package/src/functional/$proto_size.ts +82 -0
- package/src/functional/$proto_string.ts +24 -0
- package/src/functional/$varint.ts +130 -0
- package/src/functional/$zigzag.ts +39 -0
- package/src/messages/IProtocolMessage.ts +6 -0
- package/src/messages/IProtocolProperty.ts +11 -0
- package/src/metadata/IMetadataTag.ts +137 -122
- package/src/metadata/Metadata.ts +479 -477
- package/src/module.ts +1547 -1535
- package/src/programmers/AssertParseProgrammer.ts +55 -55
- package/src/programmers/AssertProgrammer.ts +445 -445
- package/src/programmers/AssertStringifyProgrammer.ts +65 -65
- package/src/programmers/CheckerProgrammer.ts +810 -810
- package/src/programmers/IsParseProgrammer.ts +61 -61
- package/src/programmers/IsProgrammer.ts +175 -175
- package/src/programmers/IsStringifyProgrammer.ts +69 -69
- package/src/programmers/MessageProgrammer.ts +116 -0
- package/src/programmers/StringifyProgrammer.ts +762 -762
- package/src/programmers/ValidateParseProgrammer.ts +59 -59
- package/src/programmers/ValidateProgrammer.ts +237 -237
- package/src/programmers/ValidateStringifyProgrammer.ts +80 -80
- package/src/programmers/helpers/OptionPredicator.ts +15 -15
- package/src/programmers/internal/application_default.ts +17 -17
- package/src/programmers/internal/application_object.ts +5 -5
- package/src/programmers/internal/application_schema.ts +231 -228
- package/src/programmers/internal/check_bigint.ts +85 -85
- package/src/programmers/internal/check_number.ts +175 -175
- package/src/schemas/IJsonSchema.ts +90 -90
- package/src/transformers/CallExpressionTransformer.ts +131 -124
- package/src/transformers/ITransformOptions.ts +47 -47
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +117 -119
- package/src/transformers/features/protocols/MessageTransformer.ts +32 -0
- package/src/transformers/features/stringifiers/StringifyTransformer.ts +46 -46
- package/src/utils/NameEncoder.ts +32 -0
|
@@ -1,228 +1,231 @@
|
|
|
1
|
-
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
-
import { MetadataConstant } from "../../metadata/MetadataConstant";
|
|
3
|
-
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
4
|
-
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
5
|
-
|
|
6
|
-
import { ArrayUtil } from "../../utils/ArrayUtil";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
(
|
|
26
|
-
|
|
27
|
-
(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
merged
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
(
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
$ref,
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
$recursiveRef,
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
ArrayUtil.set(output.
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
1
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
+
import { MetadataConstant } from "../../metadata/MetadataConstant";
|
|
3
|
+
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
4
|
+
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
5
|
+
|
|
6
|
+
import { ArrayUtil } from "../../utils/ArrayUtil";
|
|
7
|
+
import { NameEncoder } from "../../utils/NameEncoder";
|
|
8
|
+
|
|
9
|
+
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
10
|
+
import { AtomicPredicator } from "../helpers/AtomicPredicator";
|
|
11
|
+
import { application_array } from "./application_array";
|
|
12
|
+
import { application_boolean } from "./application_boolean";
|
|
13
|
+
import { application_constant } from "./application_constant";
|
|
14
|
+
import { application_native } from "./application_native";
|
|
15
|
+
import { application_number } from "./application_number";
|
|
16
|
+
import { application_object } from "./application_object";
|
|
17
|
+
import { application_string } from "./application_string";
|
|
18
|
+
import { application_templates } from "./application_templates";
|
|
19
|
+
import { application_tuple } from "./application_tuple";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export const application_schema =
|
|
25
|
+
(options: ApplicationProgrammer.IOptions) =>
|
|
26
|
+
(components: IJsonComponents) =>
|
|
27
|
+
<BlockNever extends boolean>(blockNever: BlockNever) =>
|
|
28
|
+
(
|
|
29
|
+
meta: Metadata,
|
|
30
|
+
attribute: IJsonSchema.IAttribute,
|
|
31
|
+
): BlockNever extends true ? IJsonSchema | null : IJsonSchema => {
|
|
32
|
+
// VULNERABLE CASE
|
|
33
|
+
if (meta.any === true) return {};
|
|
34
|
+
else if (meta.nullable && meta.empty())
|
|
35
|
+
return { type: "null", ...attribute };
|
|
36
|
+
|
|
37
|
+
//----
|
|
38
|
+
// GATHER UNION SCHEMAS
|
|
39
|
+
//----
|
|
40
|
+
const union: IJsonSchema[] = [];
|
|
41
|
+
|
|
42
|
+
// toJSON() METHOD
|
|
43
|
+
if (meta.resolved !== null) {
|
|
44
|
+
const resolved = application_schema(options)(components)(
|
|
45
|
+
blockNever,
|
|
46
|
+
)(meta.resolved, attribute);
|
|
47
|
+
if (resolved !== null) union.push(resolved);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// ATOMIC TYPES
|
|
51
|
+
if (meta.templates.length && AtomicPredicator.template(meta))
|
|
52
|
+
union.push(application_templates(meta, attribute));
|
|
53
|
+
for (const constant of meta.constants) {
|
|
54
|
+
if (constant.type === "bigint") throw new Error(NO_BIGINT);
|
|
55
|
+
else if (
|
|
56
|
+
(constant.type === "string" && meta.templates.length) ||
|
|
57
|
+
AtomicPredicator.constant(meta)(constant.type) === false
|
|
58
|
+
)
|
|
59
|
+
continue;
|
|
60
|
+
union.push(
|
|
61
|
+
application_constant(constant, meta.nullable, attribute),
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
for (const type of meta.atomics) {
|
|
65
|
+
if (type === "bigint") throw new Error(NO_BIGINT);
|
|
66
|
+
union.push(
|
|
67
|
+
type === "string"
|
|
68
|
+
? application_string(meta, attribute)
|
|
69
|
+
: type === "boolean"
|
|
70
|
+
? application_boolean(meta.nullable, attribute)
|
|
71
|
+
: application_number(meta.nullable, attribute),
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// ARRAY
|
|
76
|
+
for (const schema of meta.arrays.values())
|
|
77
|
+
union.push(
|
|
78
|
+
application_array(options)(components)(
|
|
79
|
+
schema,
|
|
80
|
+
meta.nullable,
|
|
81
|
+
attribute,
|
|
82
|
+
),
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
// TUPLE
|
|
86
|
+
for (const items of meta.tuples)
|
|
87
|
+
if (
|
|
88
|
+
options.purpose === "ajv" &&
|
|
89
|
+
items.every((i) => i.rest === null)
|
|
90
|
+
)
|
|
91
|
+
union.push(
|
|
92
|
+
application_tuple(options)(components)(
|
|
93
|
+
items,
|
|
94
|
+
meta.nullable,
|
|
95
|
+
attribute,
|
|
96
|
+
),
|
|
97
|
+
);
|
|
98
|
+
else {
|
|
99
|
+
// SWAGGER DOES NOT SUPPORT TUPLE TYPE YET
|
|
100
|
+
const merged: Metadata = items.reduce((x, y) =>
|
|
101
|
+
merge_metadata(x, y),
|
|
102
|
+
);
|
|
103
|
+
union.push(
|
|
104
|
+
application_array(options)(components)(
|
|
105
|
+
merged,
|
|
106
|
+
merged?.nullable || false,
|
|
107
|
+
attribute,
|
|
108
|
+
),
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// NATIVES
|
|
113
|
+
for (const native of meta.natives)
|
|
114
|
+
union.push(
|
|
115
|
+
application_native(options)(components)(native)(
|
|
116
|
+
meta.nullable,
|
|
117
|
+
attribute,
|
|
118
|
+
),
|
|
119
|
+
);
|
|
120
|
+
if (meta.sets.length)
|
|
121
|
+
union.push(
|
|
122
|
+
application_native(options)(components)(`Set`)(
|
|
123
|
+
meta.nullable,
|
|
124
|
+
attribute,
|
|
125
|
+
),
|
|
126
|
+
);
|
|
127
|
+
if (meta.maps.length)
|
|
128
|
+
union.push(
|
|
129
|
+
application_native(options)(components)(`Map`)(
|
|
130
|
+
meta.nullable,
|
|
131
|
+
attribute,
|
|
132
|
+
),
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
// OBJECT
|
|
136
|
+
for (const obj of meta.objects) {
|
|
137
|
+
const id: string =
|
|
138
|
+
NameEncoder.encode(obj.name) +
|
|
139
|
+
(meta.nullable ? ".Nullable" : "");
|
|
140
|
+
application_object(options)(components)(id, obj, meta.nullable);
|
|
141
|
+
union.push(
|
|
142
|
+
(options.purpose === "ajv" && obj.recursive
|
|
143
|
+
? recursive
|
|
144
|
+
: reference)(`${options.prefix}/${id}`, attribute),
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
//----
|
|
149
|
+
// RETURNS
|
|
150
|
+
//----
|
|
151
|
+
if (union.length === 0) return blockNever === true ? null! : {};
|
|
152
|
+
else if (union.length === 1) return union[0]!;
|
|
153
|
+
return { oneOf: union, ...attribute };
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @internal
|
|
158
|
+
*/
|
|
159
|
+
const reference = (
|
|
160
|
+
$ref: string,
|
|
161
|
+
attribute: IJsonSchema.IAttribute,
|
|
162
|
+
): IJsonSchema.IReference => ({
|
|
163
|
+
$ref,
|
|
164
|
+
...attribute,
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* @internal
|
|
169
|
+
*/
|
|
170
|
+
const recursive = (
|
|
171
|
+
$recursiveRef: string,
|
|
172
|
+
attribute: IJsonSchema.IAttribute,
|
|
173
|
+
): IJsonSchema.IRecursiveReference => ({
|
|
174
|
+
$recursiveRef,
|
|
175
|
+
...attribute,
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* @internal
|
|
180
|
+
* @todo: not perfect
|
|
181
|
+
*/
|
|
182
|
+
function merge_metadata(x: Metadata, y: Metadata): Metadata {
|
|
183
|
+
const output: Metadata = Metadata.create({
|
|
184
|
+
any: x.any || y.any,
|
|
185
|
+
nullable: x.nullable || y.nullable,
|
|
186
|
+
required: x.required && y.required,
|
|
187
|
+
functional: x.functional || y.functional,
|
|
188
|
+
|
|
189
|
+
resolved:
|
|
190
|
+
x.resolved !== null && y.resolved !== null
|
|
191
|
+
? merge_metadata(x.resolved, y.resolved)
|
|
192
|
+
: x.resolved || y.resolved,
|
|
193
|
+
atomics: [...new Set([...x.atomics, ...y.atomics])],
|
|
194
|
+
constants: [...x.constants],
|
|
195
|
+
templates: x.templates.slice(),
|
|
196
|
+
|
|
197
|
+
rest: null,
|
|
198
|
+
arrays: x.arrays.slice(),
|
|
199
|
+
tuples: x.tuples.slice(),
|
|
200
|
+
objects: x.objects.slice(),
|
|
201
|
+
|
|
202
|
+
natives: [...new Set([...x.natives, ...y.natives])],
|
|
203
|
+
sets: x.sets.slice(),
|
|
204
|
+
maps: x.maps.slice(),
|
|
205
|
+
});
|
|
206
|
+
for (const constant of y.constants) {
|
|
207
|
+
const target: MetadataConstant = ArrayUtil.take(
|
|
208
|
+
output.constants,
|
|
209
|
+
(elem) => elem.type === constant.type,
|
|
210
|
+
() => ({
|
|
211
|
+
type: constant.type,
|
|
212
|
+
values: [],
|
|
213
|
+
}),
|
|
214
|
+
);
|
|
215
|
+
for (const value of constant.values)
|
|
216
|
+
ArrayUtil.add(target.values, value);
|
|
217
|
+
}
|
|
218
|
+
for (const array of y.arrays)
|
|
219
|
+
ArrayUtil.set(output.arrays, array, (elem) => elem.getName());
|
|
220
|
+
for (const obj of y.objects)
|
|
221
|
+
ArrayUtil.set(output.objects, obj, (elem) => elem.name);
|
|
222
|
+
|
|
223
|
+
if (x.rest !== null)
|
|
224
|
+
ArrayUtil.set(output.arrays, x.rest, (elem) => elem.getName());
|
|
225
|
+
if (y.rest !== null)
|
|
226
|
+
ArrayUtil.set(output.arrays, y.rest, (elem) => elem.getName());
|
|
227
|
+
|
|
228
|
+
return output;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const NO_BIGINT = "Error on typia.application(): does not allow bigint type.";
|
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IMetadataTag } from "../../metadata/IMetadataTag";
|
|
4
|
-
|
|
5
|
-
export function check_bigint(input: ts.Expression, tagList: IMetadataTag[]) {
|
|
6
|
-
const caster = (value: number) =>
|
|
7
|
-
ts.factory.createIdentifier(`${Math.floor(value)}n`);
|
|
8
|
-
|
|
9
|
-
// TYPEOF STATEMENT
|
|
10
|
-
const conditions: ts.Expression[] = [
|
|
11
|
-
ts.factory.createStrictEquality(
|
|
12
|
-
ts.factory.createStringLiteral("bigint"),
|
|
13
|
-
ts.factory.createTypeOfExpression(input),
|
|
14
|
-
),
|
|
15
|
-
];
|
|
16
|
-
|
|
17
|
-
// TAG (RANGE)
|
|
18
|
-
for (const tag of tagList)
|
|
19
|
-
if (tag.kind === "multipleOf")
|
|
20
|
-
conditions.push(
|
|
21
|
-
ts.factory.createStrictEquality(
|
|
22
|
-
caster(0),
|
|
23
|
-
ts.factory.createModulo(input, caster(tag.value)),
|
|
24
|
-
),
|
|
25
|
-
);
|
|
26
|
-
else if (tag.kind === "step") {
|
|
27
|
-
const modulo = () =>
|
|
28
|
-
ts.factory.createModulo(input, caster(tag.value));
|
|
29
|
-
const minimum = (() => {
|
|
30
|
-
for (const tag of tagList)
|
|
31
|
-
if (tag.kind === "minimum") return tag.value;
|
|
32
|
-
else if (tag.kind === "exclusiveMinimum") return tag.value;
|
|
33
|
-
else if (tag.kind === "range" && tag.minimum !== undefined)
|
|
34
|
-
return tag.minimum.value;
|
|
35
|
-
return undefined;
|
|
36
|
-
})();
|
|
37
|
-
conditions.push(
|
|
38
|
-
ts.factory.createStrictEquality(
|
|
39
|
-
caster(0),
|
|
40
|
-
minimum !== undefined
|
|
41
|
-
? ts.factory.createSubtract(modulo(), caster(minimum))
|
|
42
|
-
: modulo(),
|
|
43
|
-
),
|
|
44
|
-
);
|
|
45
|
-
} else if (tag.kind === "range") {
|
|
46
|
-
if (tag.minimum !== undefined)
|
|
47
|
-
conditions.push(
|
|
48
|
-
(tag.minimum.include
|
|
49
|
-
? ts.factory.createLessThanEquals
|
|
50
|
-
: ts.factory.createLessThan)(
|
|
51
|
-
caster(tag.minimum.value),
|
|
52
|
-
input,
|
|
53
|
-
),
|
|
54
|
-
);
|
|
55
|
-
if (tag.maximum !== undefined)
|
|
56
|
-
conditions.push(
|
|
57
|
-
(tag.maximum.include
|
|
58
|
-
? ts.factory.createLessThanEquals
|
|
59
|
-
: ts.factory.createLessThan)(
|
|
60
|
-
input,
|
|
61
|
-
caster(tag.maximum.value),
|
|
62
|
-
),
|
|
63
|
-
);
|
|
64
|
-
} else if (tag.kind === "minimum")
|
|
65
|
-
conditions.push(
|
|
66
|
-
ts.factory.createLessThanEquals(caster(tag.value), input),
|
|
67
|
-
);
|
|
68
|
-
else if (tag.kind === "maximum")
|
|
69
|
-
conditions.push(
|
|
70
|
-
ts.factory.createGreaterThanEquals(caster(tag.value), input),
|
|
71
|
-
);
|
|
72
|
-
else if (tag.kind === "exclusiveMinimum")
|
|
73
|
-
conditions.push(
|
|
74
|
-
ts.factory.createLessThan(caster(tag.value), input),
|
|
75
|
-
);
|
|
76
|
-
else if (tag.kind === "exclusiveMaximum")
|
|
77
|
-
conditions.push(
|
|
78
|
-
ts.factory.createGreaterThan(caster(tag.value), input),
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
// COMBINATION
|
|
82
|
-
return conditions.length === 1
|
|
83
|
-
? conditions[0]!
|
|
84
|
-
: conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
85
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IMetadataTag } from "../../metadata/IMetadataTag";
|
|
4
|
+
|
|
5
|
+
export function check_bigint(input: ts.Expression, tagList: IMetadataTag[]) {
|
|
6
|
+
const caster = (value: number) =>
|
|
7
|
+
ts.factory.createIdentifier(`${Math.floor(value)}n`);
|
|
8
|
+
|
|
9
|
+
// TYPEOF STATEMENT
|
|
10
|
+
const conditions: ts.Expression[] = [
|
|
11
|
+
ts.factory.createStrictEquality(
|
|
12
|
+
ts.factory.createStringLiteral("bigint"),
|
|
13
|
+
ts.factory.createTypeOfExpression(input),
|
|
14
|
+
),
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
// TAG (RANGE)
|
|
18
|
+
for (const tag of tagList)
|
|
19
|
+
if (tag.kind === "multipleOf")
|
|
20
|
+
conditions.push(
|
|
21
|
+
ts.factory.createStrictEquality(
|
|
22
|
+
caster(0),
|
|
23
|
+
ts.factory.createModulo(input, caster(tag.value)),
|
|
24
|
+
),
|
|
25
|
+
);
|
|
26
|
+
else if (tag.kind === "step") {
|
|
27
|
+
const modulo = () =>
|
|
28
|
+
ts.factory.createModulo(input, caster(tag.value));
|
|
29
|
+
const minimum = (() => {
|
|
30
|
+
for (const tag of tagList)
|
|
31
|
+
if (tag.kind === "minimum") return tag.value;
|
|
32
|
+
else if (tag.kind === "exclusiveMinimum") return tag.value;
|
|
33
|
+
else if (tag.kind === "range" && tag.minimum !== undefined)
|
|
34
|
+
return tag.minimum.value;
|
|
35
|
+
return undefined;
|
|
36
|
+
})();
|
|
37
|
+
conditions.push(
|
|
38
|
+
ts.factory.createStrictEquality(
|
|
39
|
+
caster(0),
|
|
40
|
+
minimum !== undefined
|
|
41
|
+
? ts.factory.createSubtract(modulo(), caster(minimum))
|
|
42
|
+
: modulo(),
|
|
43
|
+
),
|
|
44
|
+
);
|
|
45
|
+
} else if (tag.kind === "range") {
|
|
46
|
+
if (tag.minimum !== undefined)
|
|
47
|
+
conditions.push(
|
|
48
|
+
(tag.minimum.include
|
|
49
|
+
? ts.factory.createLessThanEquals
|
|
50
|
+
: ts.factory.createLessThan)(
|
|
51
|
+
caster(tag.minimum.value),
|
|
52
|
+
input,
|
|
53
|
+
),
|
|
54
|
+
);
|
|
55
|
+
if (tag.maximum !== undefined)
|
|
56
|
+
conditions.push(
|
|
57
|
+
(tag.maximum.include
|
|
58
|
+
? ts.factory.createLessThanEquals
|
|
59
|
+
: ts.factory.createLessThan)(
|
|
60
|
+
input,
|
|
61
|
+
caster(tag.maximum.value),
|
|
62
|
+
),
|
|
63
|
+
);
|
|
64
|
+
} else if (tag.kind === "minimum")
|
|
65
|
+
conditions.push(
|
|
66
|
+
ts.factory.createLessThanEquals(caster(tag.value), input),
|
|
67
|
+
);
|
|
68
|
+
else if (tag.kind === "maximum")
|
|
69
|
+
conditions.push(
|
|
70
|
+
ts.factory.createGreaterThanEquals(caster(tag.value), input),
|
|
71
|
+
);
|
|
72
|
+
else if (tag.kind === "exclusiveMinimum")
|
|
73
|
+
conditions.push(
|
|
74
|
+
ts.factory.createLessThan(caster(tag.value), input),
|
|
75
|
+
);
|
|
76
|
+
else if (tag.kind === "exclusiveMaximum")
|
|
77
|
+
conditions.push(
|
|
78
|
+
ts.factory.createGreaterThan(caster(tag.value), input),
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
// COMBINATION
|
|
82
|
+
return conditions.length === 1
|
|
83
|
+
? conditions[0]!
|
|
84
|
+
: conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
85
|
+
}
|