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,175 +1,175 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IMetadataTag } from "../../metadata/IMetadataTag";
|
|
4
|
-
|
|
5
|
-
import { IProject } from "../../transformers/IProject";
|
|
6
|
-
|
|
7
|
-
import { OptionPredicator } from "../helpers/OptionPredicator";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
export const check_number =
|
|
13
|
-
({ options }: IProject, numeric: boolean) =>
|
|
14
|
-
(input: ts.Expression, tagList: IMetadataTag[]) => {
|
|
15
|
-
// TYPEOF STATEMENT
|
|
16
|
-
const conditions: ts.Expression[] = [
|
|
17
|
-
ts.factory.createStrictEquality(
|
|
18
|
-
ts.factory.createStringLiteral("number"),
|
|
19
|
-
ts.factory.createTypeOfExpression(input),
|
|
20
|
-
),
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
// CHECK FINITE AND NAN
|
|
24
|
-
const finite: boolean =
|
|
25
|
-
!!tagList.find(
|
|
26
|
-
(tag) =>
|
|
27
|
-
tag.kind === "range" &&
|
|
28
|
-
tag.minimum !== undefined &&
|
|
29
|
-
tag.maximum !== undefined,
|
|
30
|
-
) ||
|
|
31
|
-
(!!tagList.find(
|
|
32
|
-
(tag) =>
|
|
33
|
-
tag.kind === "minimum" || tag.kind === "exclusiveMinimum",
|
|
34
|
-
) &&
|
|
35
|
-
!!tagList.find(
|
|
36
|
-
(tag) =>
|
|
37
|
-
tag.kind === "maximum" ||
|
|
38
|
-
tag.kind === "exclusiveMaximum",
|
|
39
|
-
)) ||
|
|
40
|
-
!!tagList.find(
|
|
41
|
-
(tag) => tag.kind === "step" || tag.kind === "multipleOf",
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
if (numeric === true && finite === false)
|
|
45
|
-
if (OptionPredicator.finite(options))
|
|
46
|
-
conditions.push(
|
|
47
|
-
ts.factory.createCallExpression(
|
|
48
|
-
ts.factory.createIdentifier("Number.isFinite"),
|
|
49
|
-
undefined,
|
|
50
|
-
[input],
|
|
51
|
-
),
|
|
52
|
-
);
|
|
53
|
-
else if (OptionPredicator.numeric(options))
|
|
54
|
-
conditions.push(
|
|
55
|
-
ts.factory.createLogicalNot(
|
|
56
|
-
ts.factory.createCallExpression(
|
|
57
|
-
ts.factory.createIdentifier("Number.isNaN"),
|
|
58
|
-
undefined,
|
|
59
|
-
[input],
|
|
60
|
-
),
|
|
61
|
-
),
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
// TAG (RANGE)
|
|
65
|
-
for (const tag of tagList)
|
|
66
|
-
if (tag.kind === "type") {
|
|
67
|
-
conditions.push(
|
|
68
|
-
ts.factory.createStrictEquality(
|
|
69
|
-
ts.factory.createCallExpression(
|
|
70
|
-
ts.factory.createIdentifier("parseInt"),
|
|
71
|
-
undefined,
|
|
72
|
-
[input],
|
|
73
|
-
),
|
|
74
|
-
input,
|
|
75
|
-
),
|
|
76
|
-
);
|
|
77
|
-
if (tag.value === "uint")
|
|
78
|
-
conditions.push(
|
|
79
|
-
ts.factory.createLessThanEquals(
|
|
80
|
-
ts.factory.createNumericLiteral(0),
|
|
81
|
-
input,
|
|
82
|
-
),
|
|
83
|
-
);
|
|
84
|
-
} else if (tag.kind === "multipleOf")
|
|
85
|
-
conditions.push(
|
|
86
|
-
ts.factory.createStrictEquality(
|
|
87
|
-
ts.factory.createNumericLiteral(0),
|
|
88
|
-
ts.factory.createModulo(
|
|
89
|
-
input,
|
|
90
|
-
ts.factory.createNumericLiteral(tag.value),
|
|
91
|
-
),
|
|
92
|
-
),
|
|
93
|
-
);
|
|
94
|
-
else if (tag.kind === "step") {
|
|
95
|
-
const modulo = () =>
|
|
96
|
-
ts.factory.createModulo(
|
|
97
|
-
input,
|
|
98
|
-
ts.factory.createNumericLiteral(tag.value),
|
|
99
|
-
);
|
|
100
|
-
const minimum = (() => {
|
|
101
|
-
for (const tag of tagList)
|
|
102
|
-
if (tag.kind === "minimum") return tag.value;
|
|
103
|
-
else if (tag.kind === "exclusiveMinimum")
|
|
104
|
-
return tag.value;
|
|
105
|
-
else if (
|
|
106
|
-
tag.kind === "range" &&
|
|
107
|
-
tag.minimum !== undefined
|
|
108
|
-
)
|
|
109
|
-
return tag.minimum.value;
|
|
110
|
-
return undefined;
|
|
111
|
-
})();
|
|
112
|
-
conditions.push(
|
|
113
|
-
ts.factory.createStrictEquality(
|
|
114
|
-
ts.factory.createNumericLiteral(0),
|
|
115
|
-
minimum !== undefined
|
|
116
|
-
? ts.factory.createSubtract(
|
|
117
|
-
modulo(),
|
|
118
|
-
ts.factory.createNumericLiteral(minimum),
|
|
119
|
-
)
|
|
120
|
-
: modulo(),
|
|
121
|
-
),
|
|
122
|
-
);
|
|
123
|
-
} else if (tag.kind === "range") {
|
|
124
|
-
if (tag.minimum !== undefined)
|
|
125
|
-
conditions.push(
|
|
126
|
-
(tag.minimum.include
|
|
127
|
-
? ts.factory.createLessThanEquals
|
|
128
|
-
: ts.factory.createLessThan)(
|
|
129
|
-
ts.factory.createNumericLiteral(tag.minimum.value),
|
|
130
|
-
input,
|
|
131
|
-
),
|
|
132
|
-
);
|
|
133
|
-
if (tag.maximum !== undefined)
|
|
134
|
-
conditions.push(
|
|
135
|
-
(tag.maximum.include
|
|
136
|
-
? ts.factory.createLessThanEquals
|
|
137
|
-
: ts.factory.createLessThan)(
|
|
138
|
-
input,
|
|
139
|
-
ts.factory.createNumericLiteral(tag.maximum.value),
|
|
140
|
-
),
|
|
141
|
-
);
|
|
142
|
-
} else if (tag.kind === "minimum")
|
|
143
|
-
conditions.push(
|
|
144
|
-
ts.factory.createLessThanEquals(
|
|
145
|
-
ts.factory.createNumericLiteral(tag.value),
|
|
146
|
-
input,
|
|
147
|
-
),
|
|
148
|
-
);
|
|
149
|
-
else if (tag.kind === "maximum")
|
|
150
|
-
conditions.push(
|
|
151
|
-
ts.factory.createGreaterThanEquals(
|
|
152
|
-
ts.factory.createNumericLiteral(tag.value),
|
|
153
|
-
input,
|
|
154
|
-
),
|
|
155
|
-
);
|
|
156
|
-
else if (tag.kind === "exclusiveMinimum")
|
|
157
|
-
conditions.push(
|
|
158
|
-
ts.factory.createLessThan(
|
|
159
|
-
ts.factory.createNumericLiteral(tag.value),
|
|
160
|
-
input,
|
|
161
|
-
),
|
|
162
|
-
);
|
|
163
|
-
else if (tag.kind === "exclusiveMaximum")
|
|
164
|
-
conditions.push(
|
|
165
|
-
ts.factory.createGreaterThan(
|
|
166
|
-
ts.factory.createNumericLiteral(tag.value),
|
|
167
|
-
input,
|
|
168
|
-
),
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
// COMBINATION
|
|
172
|
-
return conditions.length === 1
|
|
173
|
-
? conditions[0]!
|
|
174
|
-
: conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
175
|
-
};
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IMetadataTag } from "../../metadata/IMetadataTag";
|
|
4
|
+
|
|
5
|
+
import { IProject } from "../../transformers/IProject";
|
|
6
|
+
|
|
7
|
+
import { OptionPredicator } from "../helpers/OptionPredicator";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export const check_number =
|
|
13
|
+
({ options }: IProject, numeric: boolean) =>
|
|
14
|
+
(input: ts.Expression, tagList: IMetadataTag[]) => {
|
|
15
|
+
// TYPEOF STATEMENT
|
|
16
|
+
const conditions: ts.Expression[] = [
|
|
17
|
+
ts.factory.createStrictEquality(
|
|
18
|
+
ts.factory.createStringLiteral("number"),
|
|
19
|
+
ts.factory.createTypeOfExpression(input),
|
|
20
|
+
),
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
// CHECK FINITE AND NAN
|
|
24
|
+
const finite: boolean =
|
|
25
|
+
!!tagList.find(
|
|
26
|
+
(tag) =>
|
|
27
|
+
tag.kind === "range" &&
|
|
28
|
+
tag.minimum !== undefined &&
|
|
29
|
+
tag.maximum !== undefined,
|
|
30
|
+
) ||
|
|
31
|
+
(!!tagList.find(
|
|
32
|
+
(tag) =>
|
|
33
|
+
tag.kind === "minimum" || tag.kind === "exclusiveMinimum",
|
|
34
|
+
) &&
|
|
35
|
+
!!tagList.find(
|
|
36
|
+
(tag) =>
|
|
37
|
+
tag.kind === "maximum" ||
|
|
38
|
+
tag.kind === "exclusiveMaximum",
|
|
39
|
+
)) ||
|
|
40
|
+
!!tagList.find(
|
|
41
|
+
(tag) => tag.kind === "step" || tag.kind === "multipleOf",
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
if (numeric === true && finite === false)
|
|
45
|
+
if (OptionPredicator.finite(options))
|
|
46
|
+
conditions.push(
|
|
47
|
+
ts.factory.createCallExpression(
|
|
48
|
+
ts.factory.createIdentifier("Number.isFinite"),
|
|
49
|
+
undefined,
|
|
50
|
+
[input],
|
|
51
|
+
),
|
|
52
|
+
);
|
|
53
|
+
else if (OptionPredicator.numeric(options))
|
|
54
|
+
conditions.push(
|
|
55
|
+
ts.factory.createLogicalNot(
|
|
56
|
+
ts.factory.createCallExpression(
|
|
57
|
+
ts.factory.createIdentifier("Number.isNaN"),
|
|
58
|
+
undefined,
|
|
59
|
+
[input],
|
|
60
|
+
),
|
|
61
|
+
),
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
// TAG (RANGE)
|
|
65
|
+
for (const tag of tagList)
|
|
66
|
+
if (tag.kind === "type") {
|
|
67
|
+
conditions.push(
|
|
68
|
+
ts.factory.createStrictEquality(
|
|
69
|
+
ts.factory.createCallExpression(
|
|
70
|
+
ts.factory.createIdentifier("parseInt"),
|
|
71
|
+
undefined,
|
|
72
|
+
[input],
|
|
73
|
+
),
|
|
74
|
+
input,
|
|
75
|
+
),
|
|
76
|
+
);
|
|
77
|
+
if (tag.value === "uint")
|
|
78
|
+
conditions.push(
|
|
79
|
+
ts.factory.createLessThanEquals(
|
|
80
|
+
ts.factory.createNumericLiteral(0),
|
|
81
|
+
input,
|
|
82
|
+
),
|
|
83
|
+
);
|
|
84
|
+
} else if (tag.kind === "multipleOf")
|
|
85
|
+
conditions.push(
|
|
86
|
+
ts.factory.createStrictEquality(
|
|
87
|
+
ts.factory.createNumericLiteral(0),
|
|
88
|
+
ts.factory.createModulo(
|
|
89
|
+
input,
|
|
90
|
+
ts.factory.createNumericLiteral(tag.value),
|
|
91
|
+
),
|
|
92
|
+
),
|
|
93
|
+
);
|
|
94
|
+
else if (tag.kind === "step") {
|
|
95
|
+
const modulo = () =>
|
|
96
|
+
ts.factory.createModulo(
|
|
97
|
+
input,
|
|
98
|
+
ts.factory.createNumericLiteral(tag.value),
|
|
99
|
+
);
|
|
100
|
+
const minimum = (() => {
|
|
101
|
+
for (const tag of tagList)
|
|
102
|
+
if (tag.kind === "minimum") return tag.value;
|
|
103
|
+
else if (tag.kind === "exclusiveMinimum")
|
|
104
|
+
return tag.value;
|
|
105
|
+
else if (
|
|
106
|
+
tag.kind === "range" &&
|
|
107
|
+
tag.minimum !== undefined
|
|
108
|
+
)
|
|
109
|
+
return tag.minimum.value;
|
|
110
|
+
return undefined;
|
|
111
|
+
})();
|
|
112
|
+
conditions.push(
|
|
113
|
+
ts.factory.createStrictEquality(
|
|
114
|
+
ts.factory.createNumericLiteral(0),
|
|
115
|
+
minimum !== undefined
|
|
116
|
+
? ts.factory.createSubtract(
|
|
117
|
+
modulo(),
|
|
118
|
+
ts.factory.createNumericLiteral(minimum),
|
|
119
|
+
)
|
|
120
|
+
: modulo(),
|
|
121
|
+
),
|
|
122
|
+
);
|
|
123
|
+
} else if (tag.kind === "range") {
|
|
124
|
+
if (tag.minimum !== undefined)
|
|
125
|
+
conditions.push(
|
|
126
|
+
(tag.minimum.include
|
|
127
|
+
? ts.factory.createLessThanEquals
|
|
128
|
+
: ts.factory.createLessThan)(
|
|
129
|
+
ts.factory.createNumericLiteral(tag.minimum.value),
|
|
130
|
+
input,
|
|
131
|
+
),
|
|
132
|
+
);
|
|
133
|
+
if (tag.maximum !== undefined)
|
|
134
|
+
conditions.push(
|
|
135
|
+
(tag.maximum.include
|
|
136
|
+
? ts.factory.createLessThanEquals
|
|
137
|
+
: ts.factory.createLessThan)(
|
|
138
|
+
input,
|
|
139
|
+
ts.factory.createNumericLiteral(tag.maximum.value),
|
|
140
|
+
),
|
|
141
|
+
);
|
|
142
|
+
} else if (tag.kind === "minimum")
|
|
143
|
+
conditions.push(
|
|
144
|
+
ts.factory.createLessThanEquals(
|
|
145
|
+
ts.factory.createNumericLiteral(tag.value),
|
|
146
|
+
input,
|
|
147
|
+
),
|
|
148
|
+
);
|
|
149
|
+
else if (tag.kind === "maximum")
|
|
150
|
+
conditions.push(
|
|
151
|
+
ts.factory.createGreaterThanEquals(
|
|
152
|
+
ts.factory.createNumericLiteral(tag.value),
|
|
153
|
+
input,
|
|
154
|
+
),
|
|
155
|
+
);
|
|
156
|
+
else if (tag.kind === "exclusiveMinimum")
|
|
157
|
+
conditions.push(
|
|
158
|
+
ts.factory.createLessThan(
|
|
159
|
+
ts.factory.createNumericLiteral(tag.value),
|
|
160
|
+
input,
|
|
161
|
+
),
|
|
162
|
+
);
|
|
163
|
+
else if (tag.kind === "exclusiveMaximum")
|
|
164
|
+
conditions.push(
|
|
165
|
+
ts.factory.createGreaterThan(
|
|
166
|
+
ts.factory.createNumericLiteral(tag.value),
|
|
167
|
+
input,
|
|
168
|
+
),
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
// COMBINATION
|
|
172
|
+
return conditions.length === 1
|
|
173
|
+
? conditions[0]!
|
|
174
|
+
: conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
175
|
+
};
|
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
import { IJsDocTagInfo } from "../metadata/IJsDocTagInfo";
|
|
2
|
-
import { IMetadataTag } from "../metadata/IMetadataTag";
|
|
3
|
-
|
|
4
|
-
import { Atomic } from "../typings/Atomic";
|
|
5
|
-
|
|
6
|
-
export type IJsonSchema = IJsonSchema.NotUnknown | IJsonSchema.IUnknown;
|
|
7
|
-
export namespace IJsonSchema {
|
|
8
|
-
export type NotUnknown =
|
|
9
|
-
| IEnumeration<"boolean">
|
|
10
|
-
| IEnumeration<"number">
|
|
11
|
-
| IEnumeration<"string">
|
|
12
|
-
| IBoolean
|
|
13
|
-
| INumber
|
|
14
|
-
| IString
|
|
15
|
-
| IArray
|
|
16
|
-
| ITuple
|
|
17
|
-
| IOneOf
|
|
18
|
-
| IReference
|
|
19
|
-
| IRecursiveReference
|
|
20
|
-
| INullOnly;
|
|
21
|
-
|
|
22
|
-
/* -----------------------------------------------------------
|
|
23
|
-
ATOMICS
|
|
24
|
-
----------------------------------------------------------- */
|
|
25
|
-
export interface IEnumeration<
|
|
26
|
-
Literal extends Exclude<Atomic.Literal, "bigint">,
|
|
27
|
-
> extends IAtomic<Literal> {
|
|
28
|
-
enum: Array<Atomic.Mapper[Literal]>;
|
|
29
|
-
}
|
|
30
|
-
export interface IAtomic<Literal extends Exclude<Atomic.Literal, "bigint">>
|
|
31
|
-
extends ISignificant<Literal> {
|
|
32
|
-
default?: Atomic.Mapper[Literal];
|
|
33
|
-
}
|
|
34
|
-
export interface IString extends IAtomic<"string"> {
|
|
35
|
-
minLength?: number;
|
|
36
|
-
maxLength?: number;
|
|
37
|
-
pattern?: string;
|
|
38
|
-
format?: string;
|
|
39
|
-
}
|
|
40
|
-
export interface INumber extends IAtomic<"number" | "integer"> {
|
|
41
|
-
minimum?: number;
|
|
42
|
-
maximum?: number;
|
|
43
|
-
exclusiveMinimum?: number;
|
|
44
|
-
exclusiveMaximum?: number;
|
|
45
|
-
multipleOf?: number;
|
|
46
|
-
}
|
|
47
|
-
export interface IBoolean extends IAtomic<"boolean"> {}
|
|
48
|
-
|
|
49
|
-
/* -----------------------------------------------------------
|
|
50
|
-
OBJECTS
|
|
51
|
-
----------------------------------------------------------- */
|
|
52
|
-
export interface IArray extends ISignificant<"array"> {
|
|
53
|
-
items: IJsonSchema;
|
|
54
|
-
minItems?: number;
|
|
55
|
-
maxItems?: number;
|
|
56
|
-
}
|
|
57
|
-
export interface ITuple extends ISignificant<"array"> {
|
|
58
|
-
items: IJsonSchema[];
|
|
59
|
-
}
|
|
60
|
-
export interface IReference extends IAttribute {
|
|
61
|
-
$ref: string;
|
|
62
|
-
}
|
|
63
|
-
export interface IRecursiveReference extends IAttribute {
|
|
64
|
-
$recursiveRef: string;
|
|
65
|
-
}
|
|
66
|
-
export interface INullOnly extends IAttribute {
|
|
67
|
-
type: "null";
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/* -----------------------------------------------------------
|
|
71
|
-
MISCELLANEOUS
|
|
72
|
-
----------------------------------------------------------- */
|
|
73
|
-
export interface IOneOf extends IAttribute {
|
|
74
|
-
oneOf: IJsonSchema[];
|
|
75
|
-
}
|
|
76
|
-
export interface IUnknown {}
|
|
77
|
-
|
|
78
|
-
export interface ISignificant<Literal extends string> extends IAttribute {
|
|
79
|
-
type: Literal;
|
|
80
|
-
nullable: boolean;
|
|
81
|
-
}
|
|
82
|
-
export interface IAttribute {
|
|
83
|
-
deprecated?: boolean;
|
|
84
|
-
title?: string;
|
|
85
|
-
description?: string;
|
|
86
|
-
"x-typia-metaTags"?: IMetadataTag[];
|
|
87
|
-
"x-typia-jsDocTags"?: IJsDocTagInfo[];
|
|
88
|
-
"x-typia-required"?: boolean;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
1
|
+
import { IJsDocTagInfo } from "../metadata/IJsDocTagInfo";
|
|
2
|
+
import { IMetadataTag } from "../metadata/IMetadataTag";
|
|
3
|
+
|
|
4
|
+
import { Atomic } from "../typings/Atomic";
|
|
5
|
+
|
|
6
|
+
export type IJsonSchema = IJsonSchema.NotUnknown | IJsonSchema.IUnknown;
|
|
7
|
+
export namespace IJsonSchema {
|
|
8
|
+
export type NotUnknown =
|
|
9
|
+
| IEnumeration<"boolean">
|
|
10
|
+
| IEnumeration<"number">
|
|
11
|
+
| IEnumeration<"string">
|
|
12
|
+
| IBoolean
|
|
13
|
+
| INumber
|
|
14
|
+
| IString
|
|
15
|
+
| IArray
|
|
16
|
+
| ITuple
|
|
17
|
+
| IOneOf
|
|
18
|
+
| IReference
|
|
19
|
+
| IRecursiveReference
|
|
20
|
+
| INullOnly;
|
|
21
|
+
|
|
22
|
+
/* -----------------------------------------------------------
|
|
23
|
+
ATOMICS
|
|
24
|
+
----------------------------------------------------------- */
|
|
25
|
+
export interface IEnumeration<
|
|
26
|
+
Literal extends Exclude<Atomic.Literal, "bigint">,
|
|
27
|
+
> extends IAtomic<Literal> {
|
|
28
|
+
enum: Array<Atomic.Mapper[Literal]>;
|
|
29
|
+
}
|
|
30
|
+
export interface IAtomic<Literal extends Exclude<Atomic.Literal, "bigint">>
|
|
31
|
+
extends ISignificant<Literal> {
|
|
32
|
+
default?: Atomic.Mapper[Literal];
|
|
33
|
+
}
|
|
34
|
+
export interface IString extends IAtomic<"string"> {
|
|
35
|
+
minLength?: number;
|
|
36
|
+
maxLength?: number;
|
|
37
|
+
pattern?: string;
|
|
38
|
+
format?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface INumber extends IAtomic<"number" | "integer"> {
|
|
41
|
+
minimum?: number;
|
|
42
|
+
maximum?: number;
|
|
43
|
+
exclusiveMinimum?: number;
|
|
44
|
+
exclusiveMaximum?: number;
|
|
45
|
+
multipleOf?: number;
|
|
46
|
+
}
|
|
47
|
+
export interface IBoolean extends IAtomic<"boolean"> {}
|
|
48
|
+
|
|
49
|
+
/* -----------------------------------------------------------
|
|
50
|
+
OBJECTS
|
|
51
|
+
----------------------------------------------------------- */
|
|
52
|
+
export interface IArray extends ISignificant<"array"> {
|
|
53
|
+
items: IJsonSchema;
|
|
54
|
+
minItems?: number;
|
|
55
|
+
maxItems?: number;
|
|
56
|
+
}
|
|
57
|
+
export interface ITuple extends ISignificant<"array"> {
|
|
58
|
+
items: IJsonSchema[];
|
|
59
|
+
}
|
|
60
|
+
export interface IReference extends IAttribute {
|
|
61
|
+
$ref: string;
|
|
62
|
+
}
|
|
63
|
+
export interface IRecursiveReference extends IAttribute {
|
|
64
|
+
$recursiveRef: string;
|
|
65
|
+
}
|
|
66
|
+
export interface INullOnly extends IAttribute {
|
|
67
|
+
type: "null";
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* -----------------------------------------------------------
|
|
71
|
+
MISCELLANEOUS
|
|
72
|
+
----------------------------------------------------------- */
|
|
73
|
+
export interface IOneOf extends IAttribute {
|
|
74
|
+
oneOf: IJsonSchema[];
|
|
75
|
+
}
|
|
76
|
+
export interface IUnknown {}
|
|
77
|
+
|
|
78
|
+
export interface ISignificant<Literal extends string> extends IAttribute {
|
|
79
|
+
type: Literal;
|
|
80
|
+
nullable: boolean;
|
|
81
|
+
}
|
|
82
|
+
export interface IAttribute {
|
|
83
|
+
deprecated?: boolean;
|
|
84
|
+
title?: string;
|
|
85
|
+
description?: string;
|
|
86
|
+
"x-typia-metaTags"?: IMetadataTag[];
|
|
87
|
+
"x-typia-jsDocTags"?: IJsDocTagInfo[];
|
|
88
|
+
"x-typia-required"?: boolean;
|
|
89
|
+
}
|
|
90
|
+
}
|