typia 3.4.26 → 3.4.28
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/factories/internal/metadata/iterate_metadata_native.js +0 -3
- package/lib/factories/internal/metadata/iterate_metadata_native.js.map +1 -1
- package/lib/programmers/AssertProgrammer.js +71 -79
- package/lib/programmers/AssertProgrammer.js.map +1 -1
- package/lib/programmers/CheckerProgrammer.js +21 -16
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/programmers/StringifyProgrammer.js +24 -17
- package/lib/programmers/StringifyProgrammer.js.map +1 -1
- package/lib/programmers/ValidateProgrammer.js +60 -68
- package/lib/programmers/ValidateProgrammer.js.map +1 -1
- package/lib/programmers/helpers/AtomicPredicator.d.ts +2 -0
- package/lib/programmers/helpers/AtomicPredicator.js +9 -1
- package/lib/programmers/helpers/AtomicPredicator.js.map +1 -1
- package/lib/programmers/internal/application_schema.js +18 -7
- package/lib/programmers/internal/application_schema.js.map +1 -1
- package/lib/programmers/internal/check_dynamic_properties.js.map +1 -1
- package/lib/programmers/internal/check_native.js +9 -1
- package/lib/programmers/internal/check_native.js.map +1 -1
- package/lib/transformers/ITransformOptions.d.ts +4 -0
- package/package.json +3 -2
- package/src/factories/internal/metadata/iterate_metadata_native.ts +0 -5
- package/src/programmers/AssertProgrammer.ts +30 -36
- package/src/programmers/CheckerProgrammer.ts +16 -11
- package/src/programmers/StringifyProgrammer.ts +40 -27
- package/src/programmers/ValidateProgrammer.ts +30 -36
- package/src/programmers/helpers/AtomicPredicator.ts +17 -1
- package/src/programmers/internal/application_schema.ts +30 -20
- package/src/programmers/internal/check_dynamic_properties.ts +1 -0
- package/src/programmers/internal/check_native.ts +14 -2
- package/src/transformers/ITransformOptions.ts +4 -0
|
@@ -12,6 +12,8 @@ import { MetadataObject } from "../metadata/MetadataObject";
|
|
|
12
12
|
|
|
13
13
|
import { IProject } from "../transformers/IProject";
|
|
14
14
|
|
|
15
|
+
import { Atomic } from "../typings/Atomic";
|
|
16
|
+
|
|
15
17
|
import { ArrayUtil } from "../utils/ArrayUtil";
|
|
16
18
|
|
|
17
19
|
import { FeatureProgrammer } from "./FeatureProgrammer";
|
|
@@ -23,6 +25,7 @@ import { OptionPredicator } from "./helpers/OptionPredicator";
|
|
|
23
25
|
import { StringifyJoiner } from "./helpers/StringifyJoinder";
|
|
24
26
|
import { StringifyPredicator } from "./helpers/StringifyPredicator";
|
|
25
27
|
import { UnionExplorer } from "./helpers/UnionExplorer";
|
|
28
|
+
import { check_native } from "./internal/check_native";
|
|
26
29
|
import { decode_union_object } from "./internal/decode_union_object";
|
|
27
30
|
import { feature_object_entries } from "./internal/feature_object_entries";
|
|
28
31
|
|
|
@@ -177,10 +180,9 @@ export namespace StringifyProgrammer {
|
|
|
177
180
|
|
|
178
181
|
// CONSTANTS
|
|
179
182
|
for (const constant of meta.constants)
|
|
180
|
-
if (
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
)
|
|
183
|
+
if (AtomicPredicator.constant(meta)(constant.type) === false)
|
|
184
|
+
continue;
|
|
185
|
+
else if (constant.type !== "string")
|
|
184
186
|
unions.push({
|
|
185
187
|
type: "atomic",
|
|
186
188
|
is: () =>
|
|
@@ -223,28 +225,31 @@ export namespace StringifyProgrammer {
|
|
|
223
225
|
explore,
|
|
224
226
|
),
|
|
225
227
|
});
|
|
228
|
+
|
|
229
|
+
/// ATOMICS
|
|
226
230
|
for (const type of meta.atomics)
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
231
|
+
if (AtomicPredicator.atomic(meta)(type))
|
|
232
|
+
unions.push({
|
|
233
|
+
type: "atomic",
|
|
234
|
+
is: () =>
|
|
235
|
+
IsProgrammer.decode(project, importer)(
|
|
236
|
+
input,
|
|
237
|
+
(() => {
|
|
238
|
+
const partial = Metadata.initialize();
|
|
239
|
+
partial.atomics.push(type);
|
|
240
|
+
return partial;
|
|
241
|
+
})(),
|
|
242
|
+
explore,
|
|
243
|
+
[],
|
|
244
|
+
),
|
|
245
|
+
value: () =>
|
|
246
|
+
decode_atomic(project, importer)(
|
|
247
|
+
input,
|
|
248
|
+
type,
|
|
249
|
+
explore,
|
|
250
|
+
tags,
|
|
251
|
+
),
|
|
252
|
+
});
|
|
248
253
|
|
|
249
254
|
// TUPLES
|
|
250
255
|
for (const tuple of meta.tuples) {
|
|
@@ -315,8 +320,16 @@ export namespace StringifyProgrammer {
|
|
|
315
320
|
for (const native of meta.natives)
|
|
316
321
|
unions.push({
|
|
317
322
|
type: "object",
|
|
318
|
-
is: () =>
|
|
319
|
-
value: () =>
|
|
323
|
+
is: () => check_native(native)(input),
|
|
324
|
+
value: () =>
|
|
325
|
+
AtomicPredicator.native(native)
|
|
326
|
+
? decode_atomic(project, importer)(
|
|
327
|
+
input,
|
|
328
|
+
native.toLowerCase() as Atomic.Literal,
|
|
329
|
+
explore,
|
|
330
|
+
tags,
|
|
331
|
+
)
|
|
332
|
+
: ts.factory.createStringLiteral("{}"),
|
|
320
333
|
});
|
|
321
334
|
|
|
322
335
|
// SETS
|
|
@@ -4,7 +4,6 @@ import { IdentifierFactory } from "../factories/IdentifierFactory";
|
|
|
4
4
|
import { StatementFactory } from "../factories/StatementFactory";
|
|
5
5
|
|
|
6
6
|
import { IProject } from "../transformers/IProject";
|
|
7
|
-
import { ITransformOptions } from "../transformers/ITransformOptions";
|
|
8
7
|
|
|
9
8
|
import { CheckerProgrammer } from "./CheckerProgrammer";
|
|
10
9
|
import { IsProgrammer } from "./IsProgrammer";
|
|
@@ -31,8 +30,8 @@ export namespace ValidateProgrammer {
|
|
|
31
30
|
trace: true,
|
|
32
31
|
numeric: OptionPredicator.numeric(project.options),
|
|
33
32
|
equals,
|
|
34
|
-
combiner: combine(
|
|
35
|
-
joiner: joiner(
|
|
33
|
+
combiner: combine(equals)(importer),
|
|
34
|
+
joiner: joiner(equals)(importer),
|
|
36
35
|
success: ts.factory.createTrue(),
|
|
37
36
|
},
|
|
38
37
|
importer,
|
|
@@ -86,13 +85,12 @@ export namespace ValidateProgrammer {
|
|
|
86
85
|
}
|
|
87
86
|
|
|
88
87
|
const combine =
|
|
89
|
-
(options: ITransformOptions) =>
|
|
90
88
|
(equals: boolean) =>
|
|
91
89
|
(importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
|
|
92
90
|
(explore: CheckerProgrammer.IExplore) => {
|
|
93
91
|
if (explore.tracable === false)
|
|
94
92
|
return IsProgrammer.CONFIG({
|
|
95
|
-
object: validate_object(
|
|
93
|
+
object: validate_object(equals)(importer),
|
|
96
94
|
numeric: true,
|
|
97
95
|
})(importer).combiner(explore);
|
|
98
96
|
|
|
@@ -133,44 +131,40 @@ const combine =
|
|
|
133
131
|
);
|
|
134
132
|
};
|
|
135
133
|
|
|
136
|
-
const validate_object =
|
|
137
|
-
(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
ts.factory.
|
|
151
|
-
importer.use("join"),
|
|
152
|
-
undefined,
|
|
153
|
-
[ts.factory.createIdentifier("key")],
|
|
154
|
-
),
|
|
134
|
+
const validate_object = (equals: boolean) => (importer: FunctionImporter) =>
|
|
135
|
+
check_object({
|
|
136
|
+
equals,
|
|
137
|
+
undefined: true,
|
|
138
|
+
assert: false,
|
|
139
|
+
reduce: ts.factory.createLogicalAnd,
|
|
140
|
+
positive: ts.factory.createTrue(),
|
|
141
|
+
superfluous: (value) =>
|
|
142
|
+
create_report_call()(
|
|
143
|
+
ts.factory.createAdd(
|
|
144
|
+
ts.factory.createIdentifier("path"),
|
|
145
|
+
ts.factory.createCallExpression(
|
|
146
|
+
importer.use("join"),
|
|
147
|
+
undefined,
|
|
148
|
+
[ts.factory.createIdentifier("key")],
|
|
155
149
|
),
|
|
156
|
-
"undefined",
|
|
157
|
-
value,
|
|
158
150
|
),
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
151
|
+
"undefined",
|
|
152
|
+
value,
|
|
153
|
+
),
|
|
154
|
+
halt: (expr) =>
|
|
155
|
+
ts.factory.createLogicalOr(
|
|
156
|
+
ts.factory.createStrictEquality(
|
|
157
|
+
ts.factory.createFalse(),
|
|
158
|
+
ts.factory.createIdentifier("exceptionable"),
|
|
166
159
|
),
|
|
167
|
-
|
|
160
|
+
expr,
|
|
161
|
+
),
|
|
162
|
+
})(importer);
|
|
168
163
|
|
|
169
164
|
const joiner =
|
|
170
|
-
(options: ITransformOptions) =>
|
|
171
165
|
(equals: boolean) =>
|
|
172
166
|
(importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
|
|
173
|
-
object: validate_object(
|
|
167
|
+
object: validate_object(equals)(importer),
|
|
174
168
|
array: (input, arrow) =>
|
|
175
169
|
check_everything(
|
|
176
170
|
ts.factory.createCallExpression(
|
|
@@ -8,8 +8,24 @@ export namespace AtomicPredicator {
|
|
|
8
8
|
export const constant =
|
|
9
9
|
(meta: Metadata) =>
|
|
10
10
|
(name: Atomic.Literal): boolean =>
|
|
11
|
-
!ArrayUtil.has(meta.atomics, (atomic) => atomic === name)
|
|
11
|
+
!ArrayUtil.has(meta.atomics, (atomic) => atomic === name) &&
|
|
12
|
+
!ArrayUtil.has(
|
|
13
|
+
meta.natives,
|
|
14
|
+
(native) => native.toLowerCase() === name,
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
export const atomic =
|
|
18
|
+
(meta: Metadata) =>
|
|
19
|
+
(name: Atomic.Literal): boolean =>
|
|
20
|
+
!ArrayUtil.has(
|
|
21
|
+
meta.natives,
|
|
22
|
+
(native) => native.toLowerCase() === name,
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
export const native = (name: string) => LIKE.has(name.toLowerCase());
|
|
12
26
|
|
|
13
27
|
export const template = (meta: Metadata): boolean =>
|
|
14
28
|
!ArrayUtil.has(meta.atomics, (type) => type === "string");
|
|
15
29
|
}
|
|
30
|
+
|
|
31
|
+
const LIKE = new Set(["boolean", "number", "string"]);
|
|
@@ -46,27 +46,28 @@ export const application_schema =
|
|
|
46
46
|
// ATOMIC TYPES
|
|
47
47
|
if (meta.templates.length && AtomicPredicator.template(meta))
|
|
48
48
|
union.push(application_templates(meta, attribute));
|
|
49
|
-
for (const constant of meta.constants)
|
|
49
|
+
for (const constant of meta.constants)
|
|
50
50
|
if (constant.type === "bigint") throw new Error(NO_BIGINT);
|
|
51
51
|
else if (
|
|
52
52
|
(constant.type === "string" && meta.templates.length) ||
|
|
53
53
|
AtomicPredicator.constant(meta)(constant.type) === false
|
|
54
54
|
)
|
|
55
55
|
continue;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
for (const type of meta.atomics)
|
|
56
|
+
else
|
|
57
|
+
union.push(
|
|
58
|
+
application_constant(constant, meta.nullable, attribute),
|
|
59
|
+
);
|
|
60
|
+
for (const type of meta.atomics)
|
|
61
61
|
if (type === "bigint") throw new Error(NO_BIGINT);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
62
|
+
else if (AtomicPredicator.atomic(meta)(type) === false) continue;
|
|
63
|
+
else
|
|
64
|
+
union.push(
|
|
65
|
+
type === "string"
|
|
66
|
+
? application_string(meta, attribute)
|
|
67
|
+
: type === "boolean"
|
|
68
|
+
? application_boolean(meta.nullable, attribute)
|
|
69
|
+
: application_number(meta.nullable, attribute),
|
|
70
|
+
);
|
|
70
71
|
|
|
71
72
|
// ARRAY
|
|
72
73
|
for (const schema of meta.arrays.values())
|
|
@@ -109,12 +110,21 @@ export const application_schema =
|
|
|
109
110
|
|
|
110
111
|
// NATIVES
|
|
111
112
|
for (const native of meta.natives)
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
113
|
+
if (AtomicPredicator.native(native))
|
|
114
|
+
union.push(
|
|
115
|
+
native === "String"
|
|
116
|
+
? application_string(meta, attribute)
|
|
117
|
+
: native === "Boolean"
|
|
118
|
+
? application_boolean(meta.nullable, attribute)
|
|
119
|
+
: application_number(meta.nullable, attribute),
|
|
120
|
+
);
|
|
121
|
+
else
|
|
122
|
+
union.push(
|
|
123
|
+
application_native(options)(components)(native)(
|
|
124
|
+
meta.nullable,
|
|
125
|
+
attribute,
|
|
126
|
+
),
|
|
127
|
+
);
|
|
118
128
|
if (meta.sets.length)
|
|
119
129
|
union.push(
|
|
120
130
|
application_native(options)(components)(`Set`)(
|
|
@@ -5,5 +5,17 @@ import { ExpressionFactory } from "../../factories/ExpressionFactory";
|
|
|
5
5
|
/**
|
|
6
6
|
* @internal
|
|
7
7
|
*/
|
|
8
|
-
export const check_native = (type: string) => (input: ts.Expression) =>
|
|
9
|
-
ExpressionFactory.isInstanceOf(input, type);
|
|
8
|
+
export const check_native = (type: string) => (input: ts.Expression) => {
|
|
9
|
+
const instanceOf = ExpressionFactory.isInstanceOf(input, type);
|
|
10
|
+
return ATOMIC_LIKE.has(type)
|
|
11
|
+
? ts.factory.createLogicalOr(
|
|
12
|
+
ts.factory.createStrictEquality(
|
|
13
|
+
ts.factory.createStringLiteral(type.toLowerCase()),
|
|
14
|
+
ts.factory.createTypeOfExpression(input),
|
|
15
|
+
),
|
|
16
|
+
instanceOf,
|
|
17
|
+
)
|
|
18
|
+
: instanceOf;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const ATOMIC_LIKE = new Set(["Boolean", "Number", "String"]);
|
|
@@ -52,6 +52,10 @@ export interface ITransformOptions {
|
|
|
52
52
|
* issue when validating without allowing superfluous properties. Should undefined
|
|
53
53
|
* value assigned superfluous property be allowed or not?
|
|
54
54
|
*
|
|
55
|
+
* Note that, this option only works on {@link equals} function. Other function
|
|
56
|
+
* like {@link assertEquals} or {@link validateEquals} would ignore this option
|
|
57
|
+
* value and always allow the `undefined` value.
|
|
58
|
+
*
|
|
55
59
|
* @default true
|
|
56
60
|
*/
|
|
57
61
|
undefined?: boolean;
|