typia 3.5.0-dev.20230126 → 3.5.0-dev.20230211
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 +64 -71
- package/lib/factories/MetadataCollection.d.ts +9 -1
- package/lib/factories/MetadataCollection.js +75 -2
- package/lib/factories/MetadataCollection.js.map +1 -1
- 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/functional/$is_between.d.ts +1 -0
- package/lib/functional/$is_between.js +8 -0
- package/lib/functional/$is_between.js.map +1 -0
- package/lib/metadata/IMetadataTag.d.ts +3 -7
- package/lib/metadata/Metadata.js +2 -2
- package/lib/metadata/Metadata.js.map +1 -1
- package/lib/module.d.ts +33 -3
- package/lib/module.js +36 -8
- package/lib/module.js.map +1 -1
- package/lib/programmers/AssertProgrammer.js +3 -2
- package/lib/programmers/AssertProgrammer.js.map +1 -1
- package/lib/programmers/CheckerProgrammer.d.ts +2 -2
- package/lib/programmers/CheckerProgrammer.js +21 -16
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/programmers/FeatureProgrammer.d.ts +114 -18
- package/lib/programmers/FeatureProgrammer.js +4 -4
- package/lib/programmers/FeatureProgrammer.js.map +1 -1
- package/lib/programmers/IsProgrammer.d.ts +4 -3
- package/lib/programmers/IsProgrammer.js +72 -61
- package/lib/programmers/IsProgrammer.js.map +1 -1
- package/lib/programmers/PruneProgrammer.d.ts +5 -0
- package/lib/programmers/PruneProgrammer.js +279 -0
- package/lib/programmers/PruneProgrammer.js.map +1 -0
- package/lib/programmers/StringifyProgrammer.js +26 -21
- package/lib/programmers/StringifyProgrammer.js.map +1 -1
- package/lib/programmers/ValidateProgrammer.js +3 -2
- 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/helpers/IExpressionEntry.d.ts +2 -2
- package/lib/programmers/helpers/OptionPredicator.d.ts +1 -0
- package/lib/programmers/helpers/OptionPredicator.js +4 -0
- package/lib/programmers/helpers/OptionPredicator.js.map +1 -1
- package/lib/programmers/helpers/PruneJoiner.d.ts +8 -0
- package/lib/programmers/helpers/PruneJoiner.js +60 -0
- package/lib/programmers/helpers/PruneJoiner.js.map +1 -0
- package/lib/programmers/helpers/StringifyJoinder.d.ts +1 -1
- package/lib/programmers/helpers/StringifyJoinder.js +2 -4
- package/lib/programmers/helpers/StringifyJoinder.js.map +1 -1
- package/lib/programmers/internal/application_object.js +11 -11
- package/lib/programmers/internal/application_object.js.map +1 -1
- package/lib/programmers/internal/application_schema.js +21 -12
- package/lib/programmers/internal/application_schema.js.map +1 -1
- package/lib/programmers/internal/check_dynamic_properties.js +34 -11
- 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/programmers/internal/check_object.d.ts +1 -0
- package/lib/programmers/internal/check_object.js +13 -9
- package/lib/programmers/internal/check_object.js.map +1 -1
- package/lib/programmers/internal/check_union_array_like.d.ts +1 -1
- package/lib/programmers/internal/check_union_array_like.js +3 -1
- package/lib/programmers/internal/check_union_array_like.js.map +1 -1
- package/lib/programmers/internal/feature_object_entries.d.ts +2 -2
- package/lib/programmers/internal/feature_object_entries.js.map +1 -1
- package/lib/programmers/internal/prune_object_properties.d.ts +1 -0
- package/lib/programmers/internal/prune_object_properties.js +28 -0
- package/lib/programmers/internal/prune_object_properties.js.map +1 -0
- package/lib/programmers/internal/stringify_dynamic_properties.js.map +1 -1
- package/lib/programmers/internal/stringify_regular_properties.js.map +1 -1
- package/lib/transformers/CallExpressionTransformer.js +5 -3
- package/lib/transformers/CallExpressionTransformer.js.map +1 -1
- package/lib/transformers/ITransformOptions.d.ts +14 -0
- package/lib/transformers/features/miscellaneous/ApplicationTransformer.js +3 -1
- package/lib/transformers/features/miscellaneous/ApplicationTransformer.js.map +1 -1
- package/lib/transformers/features/miscellaneous/CreatePruneTransformer.d.ts +5 -0
- package/lib/transformers/features/miscellaneous/CreatePruneTransformer.js +17 -0
- package/lib/transformers/features/miscellaneous/CreatePruneTransformer.js.map +1 -0
- package/lib/transformers/features/miscellaneous/PruneTransformer.d.ts +5 -0
- package/lib/transformers/features/miscellaneous/PruneTransformer.js +34 -0
- package/lib/transformers/features/miscellaneous/PruneTransformer.js.map +1 -0
- package/package.json +5 -4
- package/src/factories/MetadataCollection.ts +41 -2
- package/src/factories/internal/metadata/iterate_metadata_native.ts +0 -5
- package/src/functional/$is_between.ts +7 -0
- package/src/metadata/IMetadataTag.ts +4 -19
- package/src/metadata/Metadata.ts +3 -6
- package/src/module.ts +91 -17
- package/src/programmers/AssertProgrammer.ts +3 -2
- package/src/programmers/CheckerProgrammer.ts +21 -13
- package/src/programmers/FeatureProgrammer.ts +146 -21
- package/src/programmers/IsProgrammer.ts +107 -87
- package/src/programmers/PruneProgrammer.ts +320 -0
- package/src/programmers/StringifyProgrammer.ts +51 -34
- package/src/programmers/ValidateProgrammer.ts +3 -2
- package/src/programmers/helpers/AtomicPredicator.ts +17 -1
- package/src/programmers/helpers/IExpressionEntry.ts +4 -2
- package/src/programmers/helpers/OptionPredicator.ts +4 -0
- package/src/programmers/helpers/PruneJoiner.ts +52 -0
- package/src/programmers/helpers/StringifyJoinder.ts +7 -4
- package/src/programmers/internal/application_object.ts +5 -5
- package/src/programmers/internal/application_schema.ts +33 -27
- package/src/programmers/internal/check_dynamic_properties.ts +67 -16
- package/src/programmers/internal/check_native.ts +14 -2
- package/src/programmers/internal/check_object.ts +8 -2
- package/src/programmers/internal/check_union_array_like.ts +4 -2
- package/src/programmers/internal/feature_object_entries.ts +6 -1
- package/src/programmers/internal/prune_object_properties.ts +60 -0
- package/src/programmers/internal/stringify_dynamic_properties.ts +2 -2
- package/src/programmers/internal/stringify_regular_properties.ts +2 -2
- package/src/transformers/CallExpressionTransformer.ts +15 -16
- package/src/transformers/ITransformOptions.ts +15 -0
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +3 -1
- package/src/transformers/features/{protocols/MessageTransformer.ts → miscellaneous/CreatePruneTransformer.ts} +6 -7
- package/src/transformers/features/miscellaneous/PruneTransformer.ts +46 -0
- package/lib/factories/ProtocolFactory.d.ts +0 -8
- package/lib/factories/ProtocolFactory.js +0 -112
- package/lib/factories/ProtocolFactory.js.map +0 -1
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.d.ts +0 -16
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.js +0 -156
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.js.map +0 -1
- package/lib/factories/internal/protocols/emplace_protocol_object.d.ts +0 -3
- package/lib/factories/internal/protocols/emplace_protocol_object.js +0 -47
- package/lib/factories/internal/protocols/emplace_protocol_object.js.map +0 -1
- package/lib/factories/internal/protocols/emplace_protocol_property.d.ts +0 -4
- package/lib/factories/internal/protocols/emplace_protocol_property.js +0 -20
- package/lib/factories/internal/protocols/emplace_protocol_property.js.map +0 -1
- package/lib/factories/internal/protocols/iterate_protocol_atomic.d.ts +0 -3
- package/lib/factories/internal/protocols/iterate_protocol_atomic.js +0 -69
- package/lib/factories/internal/protocols/iterate_protocol_atomic.js.map +0 -1
- package/lib/factories/internal/protocols/iterate_protocol_constant.d.ts +0 -2
- package/lib/factories/internal/protocols/iterate_protocol_constant.js +0 -30
- package/lib/factories/internal/protocols/iterate_protocol_constant.js.map +0 -1
- package/lib/factories/internal/protocols/iterate_protocol_main.d.ts +0 -3
- package/lib/factories/internal/protocols/iterate_protocol_main.js +0 -17
- package/lib/factories/internal/protocols/iterate_protocol_main.js.map +0 -1
- package/lib/factories/internal/protocols/iterate_protocol_map.d.ts +0 -4
- package/lib/factories/internal/protocols/iterate_protocol_map.js +0 -75
- package/lib/factories/internal/protocols/iterate_protocol_map.js.map +0 -1
- package/lib/factories/internal/protocols/iterate_protocol_metadata.d.ts +0 -5
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js +0 -190
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +0 -1
- package/lib/factories/internal/protocols/iterate_protocol_native.d.ts +0 -2
- package/lib/factories/internal/protocols/iterate_protocol_native.js +0 -33
- package/lib/factories/internal/protocols/iterate_protocol_native.js.map +0 -1
- package/lib/factories/internal/protocols/iterate_protocol_never.d.ts +0 -1
- package/lib/factories/internal/protocols/iterate_protocol_never.js +0 -6
- package/lib/factories/internal/protocols/iterate_protocol_never.js.map +0 -1
- package/lib/factories/internal/protocols/iterate_protocol_object.d.ts +0 -4
- package/lib/factories/internal/protocols/iterate_protocol_object.js +0 -157
- package/lib/factories/internal/protocols/iterate_protocol_object.js.map +0 -1
- package/lib/factories/internal/protocols/iterate_protocol_repeated.d.ts +0 -5
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js +0 -25
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +0 -1
- package/lib/factories/internal/protocols/iterate_protocol_tuple.d.ts +0 -3
- package/lib/factories/internal/protocols/iterate_protocol_tuple.js +0 -46
- package/lib/factories/internal/protocols/iterate_protocol_tuple.js.map +0 -1
- package/lib/functional/$proto_bytes.d.ts +0 -2
- package/lib/functional/$proto_bytes.js +0 -37
- package/lib/functional/$proto_bytes.js.map +0 -1
- package/lib/functional/$proto_field.d.ts +0 -10
- package/lib/functional/$proto_field.js +0 -42
- package/lib/functional/$proto_field.js.map +0 -1
- package/lib/functional/$proto_float.d.ts +0 -4
- package/lib/functional/$proto_float.js +0 -28
- package/lib/functional/$proto_float.js.map +0 -1
- package/lib/functional/$proto_i32.d.ts +0 -2
- package/lib/functional/$proto_i32.js +0 -23
- package/lib/functional/$proto_i32.js.map +0 -1
- package/lib/functional/$proto_i64.d.ts +0 -2
- package/lib/functional/$proto_i64.js +0 -31
- package/lib/functional/$proto_i64.js.map +0 -1
- package/lib/functional/$proto_size.d.ts +0 -6
- package/lib/functional/$proto_size.js +0 -76
- package/lib/functional/$proto_size.js.map +0 -1
- package/lib/functional/$proto_string.d.ts +0 -2
- package/lib/functional/$proto_string.js +0 -34
- package/lib/functional/$proto_string.js.map +0 -1
- package/lib/functional/$varint.d.ts +0 -6
- package/lib/functional/$varint.js +0 -99
- package/lib/functional/$varint.js.map +0 -1
- package/lib/functional/$zigzag.d.ts +0 -4
- package/lib/functional/$zigzag.js +0 -34
- package/lib/functional/$zigzag.js.map +0 -1
- package/lib/messages/IProtocolMap.d.ts +0 -5
- package/lib/messages/IProtocolMap.js +0 -3
- package/lib/messages/IProtocolMap.js.map +0 -1
- package/lib/messages/IProtocolMessage.d.ts +0 -5
- package/lib/messages/IProtocolMessage.js +0 -3
- package/lib/messages/IProtocolMessage.js.map +0 -1
- package/lib/messages/IProtocolProperty.d.ts +0 -12
- package/lib/messages/IProtocolProperty.js +0 -3
- package/lib/messages/IProtocolProperty.js.map +0 -1
- package/lib/programmers/MessageProgrammer.d.ts +0 -5
- package/lib/programmers/MessageProgrammer.js +0 -141
- package/lib/programmers/MessageProgrammer.js.map +0 -1
- package/lib/transformers/features/protocols/MessageTransformer.d.ts +0 -5
- package/lib/transformers/features/protocols/MessageTransformer.js +0 -17
- package/lib/transformers/features/protocols/MessageTransformer.js.map +0 -1
- package/lib/utils/NameEncoder.d.ts +0 -4
- package/lib/utils/NameEncoder.js +0 -89
- package/lib/utils/NameEncoder.js.map +0 -1
- package/src/factories/ProtocolFactory.ts +0 -79
- package/src/factories/internal/protocols/ProtocolMetadataUtil.ts +0 -163
- package/src/factories/internal/protocols/emplace_protocol_object.ts +0 -25
- package/src/factories/internal/protocols/emplace_protocol_property.ts +0 -12
- package/src/factories/internal/protocols/iterate_protocol_atomic.ts +0 -34
- package/src/factories/internal/protocols/iterate_protocol_constant.ts +0 -27
- package/src/factories/internal/protocols/iterate_protocol_main.ts +0 -19
- package/src/factories/internal/protocols/iterate_protocol_map.ts +0 -58
- package/src/factories/internal/protocols/iterate_protocol_metadata.ts +0 -96
- package/src/factories/internal/protocols/iterate_protocol_native.ts +0 -34
- package/src/factories/internal/protocols/iterate_protocol_never.ts +0 -1
- package/src/factories/internal/protocols/iterate_protocol_object.ts +0 -110
- package/src/factories/internal/protocols/iterate_protocol_repeated.ts +0 -34
- package/src/factories/internal/protocols/iterate_protocol_tuple.ts +0 -29
- package/src/functional/$proto_bytes.ts +0 -25
- package/src/functional/$proto_field.ts +0 -30
- package/src/functional/$proto_float.ts +0 -37
- package/src/functional/$proto_i32.ts +0 -29
- package/src/functional/$proto_i64.ts +0 -37
- package/src/functional/$proto_size.ts +0 -82
- package/src/functional/$proto_string.ts +0 -24
- package/src/functional/$varint.ts +0 -130
- package/src/functional/$zigzag.ts +0 -39
- package/src/messages/IProtocolMap.ts +0 -5
- package/src/messages/IProtocolMessage.ts +0 -6
- package/src/messages/IProtocolProperty.ts +0 -13
- package/src/programmers/MessageProgrammer.ts +0 -126
- package/src/utils/NameEncoder.ts +0 -32
|
@@ -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
|
|
@@ -356,13 +369,16 @@ export namespace StringifyProgrammer {
|
|
|
356
369
|
meta.objects[0]!._Is_simple()
|
|
357
370
|
? (() => {
|
|
358
371
|
const obj: MetadataObject = meta.objects[0]!;
|
|
359
|
-
const entries: IExpressionEntry[] =
|
|
360
|
-
feature_object_entries({
|
|
372
|
+
const entries: IExpressionEntry<ts.Expression>[] =
|
|
373
|
+
feature_object_entries<ts.Expression>({
|
|
361
374
|
decoder: decode(project, importer),
|
|
362
375
|
trace: false,
|
|
363
376
|
path: false,
|
|
364
|
-
})(obj)(
|
|
377
|
+
})(obj)(
|
|
378
|
+
input,
|
|
379
|
+
);
|
|
365
380
|
return StringifyJoiner.object(importer)(
|
|
381
|
+
input,
|
|
366
382
|
entries,
|
|
367
383
|
);
|
|
368
384
|
})()
|
|
@@ -691,7 +707,10 @@ export namespace StringifyProgrammer {
|
|
|
691
707
|
objector: OBJECTOR(project, importer),
|
|
692
708
|
});
|
|
693
709
|
|
|
694
|
-
const initializer: FeatureProgrammer.
|
|
710
|
+
const initializer: FeatureProgrammer.IConfig["initializer"] = (
|
|
711
|
+
{ checker },
|
|
712
|
+
type,
|
|
713
|
+
) => {
|
|
695
714
|
const collection: MetadataCollection = new MetadataCollection();
|
|
696
715
|
const meta: Metadata = MetadataFactory.generate(
|
|
697
716
|
checker,
|
|
@@ -716,15 +735,13 @@ export namespace StringifyProgrammer {
|
|
|
716
735
|
checker: IsProgrammer.decode(project, importer),
|
|
717
736
|
decoder: decode_object(),
|
|
718
737
|
joiner: StringifyJoiner.object(importer),
|
|
719
|
-
unionizer: decode_union_object(IsProgrammer.decode_object())(
|
|
738
|
+
unionizer: decode_union_object(IsProgrammer.decode_object(importer))(
|
|
720
739
|
decode_object(),
|
|
721
740
|
)((exp) => exp)((value, expected) =>
|
|
722
741
|
create_throw_error(importer, value, expected),
|
|
723
742
|
),
|
|
724
743
|
failure: (input, expected) =>
|
|
725
744
|
create_throw_error(importer, input, expected),
|
|
726
|
-
is: (expr) => expr,
|
|
727
|
-
required: (expr) => expr,
|
|
728
745
|
});
|
|
729
746
|
|
|
730
747
|
function create_throw_error(
|
|
@@ -92,7 +92,7 @@ const combine =
|
|
|
92
92
|
return IsProgrammer.CONFIG({
|
|
93
93
|
object: validate_object(equals)(importer),
|
|
94
94
|
numeric: true,
|
|
95
|
-
}).combiner(explore);
|
|
95
|
+
})(importer).combiner(explore);
|
|
96
96
|
|
|
97
97
|
const path: string = explore.postfix
|
|
98
98
|
? `path + ${explore.postfix}`
|
|
@@ -134,6 +134,7 @@ const combine =
|
|
|
134
134
|
const validate_object = (equals: boolean) => (importer: FunctionImporter) =>
|
|
135
135
|
check_object({
|
|
136
136
|
equals,
|
|
137
|
+
undefined: true,
|
|
137
138
|
assert: false,
|
|
138
139
|
reduce: ts.factory.createLogicalAnd,
|
|
139
140
|
positive: ts.factory.createTrue(),
|
|
@@ -158,7 +159,7 @@ const validate_object = (equals: boolean) => (importer: FunctionImporter) =>
|
|
|
158
159
|
),
|
|
159
160
|
expr,
|
|
160
161
|
),
|
|
161
|
-
});
|
|
162
|
+
})(importer);
|
|
162
163
|
|
|
163
164
|
const joiner =
|
|
164
165
|
(equals: boolean) =>
|
|
@@ -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"]);
|
|
@@ -2,9 +2,11 @@ import ts from "typescript";
|
|
|
2
2
|
|
|
3
3
|
import { Metadata } from "../../metadata/Metadata";
|
|
4
4
|
|
|
5
|
-
export interface IExpressionEntry
|
|
5
|
+
export interface IExpressionEntry<
|
|
6
|
+
Expression extends ts.ConciseBody = ts.ConciseBody,
|
|
7
|
+
> {
|
|
6
8
|
input: ts.Expression;
|
|
7
9
|
key: Metadata;
|
|
8
10
|
meta: Metadata;
|
|
9
|
-
expression:
|
|
11
|
+
expression: Expression;
|
|
10
12
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
+
|
|
5
|
+
import { MetadataObject } from "../../metadata/MetadataObject";
|
|
6
|
+
|
|
7
|
+
import { ArrayUtil } from "../../utils/ArrayUtil";
|
|
8
|
+
|
|
9
|
+
import { prune_object_properties } from "../internal/prune_object_properties";
|
|
10
|
+
import { IExpressionEntry } from "./IExpressionEntry";
|
|
11
|
+
|
|
12
|
+
export namespace PruneJoiner {
|
|
13
|
+
export const object = (
|
|
14
|
+
_input: ts.Expression,
|
|
15
|
+
entries: IExpressionEntry[],
|
|
16
|
+
obj: MetadataObject,
|
|
17
|
+
): ts.ConciseBody => {
|
|
18
|
+
const statements: ts.Statement[] = ArrayUtil.flat(
|
|
19
|
+
entries.map((entry) =>
|
|
20
|
+
ts.isBlock(entry.expression)
|
|
21
|
+
? [...entry.expression.statements]
|
|
22
|
+
: [ts.factory.createExpressionStatement(entry.expression)],
|
|
23
|
+
),
|
|
24
|
+
);
|
|
25
|
+
statements.push(prune_object_properties(obj));
|
|
26
|
+
return ts.factory.createBlock(statements, true);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const array = (input: ts.Expression, arrow: ts.ArrowFunction) =>
|
|
30
|
+
ts.factory.createCallExpression(
|
|
31
|
+
IdentifierFactory.join(input, "forEach"),
|
|
32
|
+
undefined,
|
|
33
|
+
[arrow],
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
export const tuple = (
|
|
37
|
+
children: ts.ConciseBody[],
|
|
38
|
+
rest: ts.ConciseBody | null,
|
|
39
|
+
): ts.Block => {
|
|
40
|
+
const entire: ts.ConciseBody[] = [...children];
|
|
41
|
+
if (rest !== null) entire.push(rest);
|
|
42
|
+
|
|
43
|
+
const statements: ts.Statement[] = ArrayUtil.flat(
|
|
44
|
+
entire.map((elem) =>
|
|
45
|
+
ts.isBlock(elem)
|
|
46
|
+
? [...elem.statements]
|
|
47
|
+
: [ts.factory.createExpressionStatement(elem)],
|
|
48
|
+
),
|
|
49
|
+
);
|
|
50
|
+
return ts.factory.createBlock(statements, true);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -11,12 +11,15 @@ import { IExpressionEntry } from "./IExpressionEntry";
|
|
|
11
11
|
export namespace StringifyJoiner {
|
|
12
12
|
export const object =
|
|
13
13
|
(importer: FunctionImporter) =>
|
|
14
|
-
(
|
|
14
|
+
(
|
|
15
|
+
_input: ts.Expression,
|
|
16
|
+
entries: IExpressionEntry<ts.Expression>[],
|
|
17
|
+
): ts.Expression => {
|
|
15
18
|
// CHECK AND SORT ENTRIES
|
|
16
|
-
const regular: IExpressionEntry[] = entries.filter(
|
|
17
|
-
entry.key.isSoleLiteral(),
|
|
19
|
+
const regular: IExpressionEntry<ts.Expression>[] = entries.filter(
|
|
20
|
+
(entry) => entry.key.isSoleLiteral(),
|
|
18
21
|
);
|
|
19
|
-
const dynamic: IExpressionEntry[] = entries.filter(
|
|
22
|
+
const dynamic: IExpressionEntry<ts.Expression>[] = entries.filter(
|
|
20
23
|
(entry) => !entry.key.isSoleLiteral(),
|
|
21
24
|
);
|
|
22
25
|
if (regular.length === 0 && dynamic.length === 0)
|
|
@@ -18,10 +18,10 @@ import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
|
18
18
|
export const application_object =
|
|
19
19
|
(options: ApplicationProgrammer.IOptions) =>
|
|
20
20
|
(components: IJsonComponents) =>
|
|
21
|
-
(
|
|
21
|
+
(key: string, obj: MetadataObject, nullable: boolean): void => {
|
|
22
22
|
// TEMPORARY ASSIGNMENT
|
|
23
|
-
if (components.schemas[
|
|
24
|
-
components.schemas[
|
|
23
|
+
if (components.schemas[key] !== undefined) return;
|
|
24
|
+
components.schemas[key] = {} as any;
|
|
25
25
|
|
|
26
26
|
// ITERATE PROPERTIES
|
|
27
27
|
const properties: Record<string, any> = {};
|
|
@@ -97,7 +97,7 @@ export const application_object =
|
|
|
97
97
|
const schema: IJsonComponents.IObject = {
|
|
98
98
|
$id:
|
|
99
99
|
options.purpose === "ajv"
|
|
100
|
-
? options.prefix + "/" +
|
|
100
|
+
? options.prefix + "/" + key
|
|
101
101
|
: undefined,
|
|
102
102
|
$recursiveAnchor:
|
|
103
103
|
(options.purpose === "ajv" && obj.recursive) || undefined,
|
|
@@ -118,7 +118,7 @@ export const application_object =
|
|
|
118
118
|
join(options)(components)(extraMeta),
|
|
119
119
|
}),
|
|
120
120
|
};
|
|
121
|
-
components.schemas[
|
|
121
|
+
components.schemas[key] = schema;
|
|
122
122
|
};
|
|
123
123
|
|
|
124
124
|
const join =
|
|
@@ -2,8 +2,6 @@ import { Metadata } from "../../metadata/Metadata";
|
|
|
2
2
|
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
3
3
|
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
4
4
|
|
|
5
|
-
import { NameEncoder } from "../../utils/NameEncoder";
|
|
6
|
-
|
|
7
5
|
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
8
6
|
import { AtomicPredicator } from "../helpers/AtomicPredicator";
|
|
9
7
|
import { application_array } from "./application_array";
|
|
@@ -48,27 +46,28 @@ export const application_schema =
|
|
|
48
46
|
// ATOMIC TYPES
|
|
49
47
|
if (meta.templates.length && AtomicPredicator.template(meta))
|
|
50
48
|
union.push(application_templates(meta, attribute));
|
|
51
|
-
for (const constant of meta.constants)
|
|
49
|
+
for (const constant of meta.constants)
|
|
52
50
|
if (constant.type === "bigint") throw new Error(NO_BIGINT);
|
|
53
51
|
else if (
|
|
54
52
|
(constant.type === "string" && meta.templates.length) ||
|
|
55
53
|
AtomicPredicator.constant(meta)(constant.type) === false
|
|
56
54
|
)
|
|
57
55
|
continue;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
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)
|
|
63
61
|
if (type === "bigint") throw new Error(NO_BIGINT);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
+
);
|
|
72
71
|
|
|
73
72
|
// ARRAY
|
|
74
73
|
for (const schema of meta.arrays.values())
|
|
@@ -111,12 +110,21 @@ export const application_schema =
|
|
|
111
110
|
|
|
112
111
|
// NATIVES
|
|
113
112
|
for (const native of meta.natives)
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
+
);
|
|
120
128
|
if (meta.sets.length)
|
|
121
129
|
union.push(
|
|
122
130
|
application_native(options)(components)(`Set`)(
|
|
@@ -134,14 +142,12 @@ export const application_schema =
|
|
|
134
142
|
|
|
135
143
|
// OBJECT
|
|
136
144
|
for (const obj of meta.objects) {
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
(meta.nullable ? ".Nullable" : "");
|
|
140
|
-
application_object(options)(components)(id, obj, meta.nullable);
|
|
145
|
+
const key: string = obj.name + (meta.nullable ? ".Nullable" : "");
|
|
146
|
+
application_object(options)(components)(key, obj, meta.nullable);
|
|
141
147
|
union.push(
|
|
142
148
|
(options.purpose === "ajv" && obj.recursive
|
|
143
149
|
? recursive
|
|
144
|
-
: reference)(`${options.prefix}/${
|
|
150
|
+
: reference)(`${options.prefix}/${key}`, attribute),
|
|
145
151
|
);
|
|
146
152
|
}
|
|
147
153
|
|
|
@@ -3,6 +3,7 @@ import ts from "typescript";
|
|
|
3
3
|
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
4
|
import { StatementFactory } from "../../factories/StatementFactory";
|
|
5
5
|
|
|
6
|
+
import { FunctionImporter } from "../helpers/FunctionImporeter";
|
|
6
7
|
import { IExpressionEntry } from "../helpers/IExpressionEntry";
|
|
7
8
|
import { check_everything } from "./check_everything";
|
|
8
9
|
import { check_object } from "./check_object";
|
|
@@ -13,39 +14,87 @@ import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
|
13
14
|
*/
|
|
14
15
|
export const check_dynamic_properties =
|
|
15
16
|
(props: check_object.IProps) =>
|
|
17
|
+
(importer: FunctionImporter) =>
|
|
16
18
|
(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
input: ts.Expression,
|
|
20
|
+
regular: IExpressionEntry<ts.Expression>[],
|
|
21
|
+
dynamic: IExpressionEntry<ts.Expression>[],
|
|
19
22
|
): ts.Expression => {
|
|
23
|
+
const length = IdentifierFactory.join(
|
|
24
|
+
ts.factory.createCallExpression(
|
|
25
|
+
ts.factory.createIdentifier("Object.keys"),
|
|
26
|
+
undefined,
|
|
27
|
+
[input],
|
|
28
|
+
),
|
|
29
|
+
"length",
|
|
30
|
+
);
|
|
31
|
+
const left: ts.Expression | null =
|
|
32
|
+
props.equals === true && dynamic.length === 0
|
|
33
|
+
? props.undefined === true ||
|
|
34
|
+
regular.every((r) => r.meta.required)
|
|
35
|
+
? ts.factory.createStrictEquality(
|
|
36
|
+
ts.factory.createNumericLiteral(
|
|
37
|
+
regular.filter((r) => r.meta.required).length,
|
|
38
|
+
),
|
|
39
|
+
length,
|
|
40
|
+
)
|
|
41
|
+
: ts.factory.createCallExpression(
|
|
42
|
+
importer.use("is_between"),
|
|
43
|
+
[],
|
|
44
|
+
[
|
|
45
|
+
length,
|
|
46
|
+
ts.factory.createNumericLiteral(
|
|
47
|
+
regular.filter((r) => r.meta.required).length,
|
|
48
|
+
),
|
|
49
|
+
ts.factory.createNumericLiteral(regular.length),
|
|
50
|
+
],
|
|
51
|
+
)
|
|
52
|
+
: null;
|
|
53
|
+
if (
|
|
54
|
+
props.undefined === false &&
|
|
55
|
+
left !== null &&
|
|
56
|
+
regular.every((r) => r.meta.required)
|
|
57
|
+
)
|
|
58
|
+
return left;
|
|
59
|
+
|
|
20
60
|
const criteria = props.entries
|
|
21
61
|
? ts.factory.createCallExpression(props.entries, undefined, [
|
|
22
62
|
ts.factory.createCallExpression(
|
|
23
63
|
ts.factory.createIdentifier("Object.keys"),
|
|
24
64
|
undefined,
|
|
25
|
-
[
|
|
65
|
+
[input],
|
|
26
66
|
),
|
|
27
|
-
check_dynamic_property(props)(regular, dynamic),
|
|
67
|
+
check_dynamic_property(props)(input, regular, dynamic),
|
|
28
68
|
])
|
|
29
69
|
: ts.factory.createCallExpression(
|
|
30
70
|
IdentifierFactory.join(
|
|
31
71
|
ts.factory.createCallExpression(
|
|
32
72
|
ts.factory.createIdentifier("Object.keys"),
|
|
33
73
|
undefined,
|
|
34
|
-
[
|
|
74
|
+
[input],
|
|
35
75
|
),
|
|
36
76
|
props.assert ? "every" : "map",
|
|
37
77
|
),
|
|
38
78
|
undefined,
|
|
39
|
-
[check_dynamic_property(props)(regular, dynamic)],
|
|
79
|
+
[check_dynamic_property(props)(input, regular, dynamic)],
|
|
40
80
|
);
|
|
41
|
-
|
|
81
|
+
const right: ts.Expression = (props.halt || ((elem) => elem))(
|
|
42
82
|
props.assert ? criteria : check_everything(criteria),
|
|
43
83
|
);
|
|
84
|
+
return left
|
|
85
|
+
? (props.undefined
|
|
86
|
+
? ts.factory.createLogicalOr
|
|
87
|
+
: ts.factory.createLogicalAnd)(left, right)
|
|
88
|
+
: right;
|
|
44
89
|
};
|
|
45
90
|
|
|
46
91
|
const check_dynamic_property =
|
|
47
92
|
(props: check_object.IProps) =>
|
|
48
|
-
(
|
|
93
|
+
(
|
|
94
|
+
input: ts.Expression,
|
|
95
|
+
regular: IExpressionEntry<ts.Expression>[],
|
|
96
|
+
dynamic: IExpressionEntry<ts.Expression>[],
|
|
97
|
+
) => {
|
|
49
98
|
//----
|
|
50
99
|
// IF CONDITIONS
|
|
51
100
|
//----
|
|
@@ -68,16 +117,18 @@ const check_dynamic_property =
|
|
|
68
117
|
statements.push(
|
|
69
118
|
StatementFactory.constant(
|
|
70
119
|
"value",
|
|
71
|
-
ts.factory.
|
|
72
|
-
),
|
|
73
|
-
);
|
|
74
|
-
add(
|
|
75
|
-
ts.factory.createStrictEquality(
|
|
76
|
-
ts.factory.createIdentifier("undefined"),
|
|
77
|
-
value,
|
|
120
|
+
ts.factory.createElementAccessExpression(input, key),
|
|
78
121
|
),
|
|
79
|
-
props.positive,
|
|
80
122
|
);
|
|
123
|
+
if (props.undefined === true)
|
|
124
|
+
add(
|
|
125
|
+
ts.factory.createStrictEquality(
|
|
126
|
+
ts.factory.createIdentifier("undefined"),
|
|
127
|
+
value,
|
|
128
|
+
),
|
|
129
|
+
props.positive,
|
|
130
|
+
);
|
|
131
|
+
|
|
81
132
|
for (const entry of dynamic)
|
|
82
133
|
add(
|
|
83
134
|
ts.factory.createCallExpression(
|
|
@@ -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"]);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
|
|
3
|
+
import { FunctionImporter } from "../helpers/FunctionImporeter";
|
|
3
4
|
import { IExpressionEntry } from "../helpers/IExpressionEntry";
|
|
4
5
|
import { check_dynamic_properties } from "./check_dynamic_properties";
|
|
5
6
|
import { check_everything } from "./check_everything";
|
|
@@ -8,7 +9,9 @@ import { check_everything } from "./check_everything";
|
|
|
8
9
|
* @internal
|
|
9
10
|
*/
|
|
10
11
|
export const check_object =
|
|
11
|
-
(props: check_object.IProps) =>
|
|
12
|
+
(props: check_object.IProps) =>
|
|
13
|
+
(importer: FunctionImporter) =>
|
|
14
|
+
(input: ts.Expression, entries: IExpressionEntry<ts.Expression>[]) => {
|
|
12
15
|
// PREPARE ASSETS
|
|
13
16
|
const regular = entries.filter((entry) => entry.key.isSoleLiteral());
|
|
14
17
|
const dynamic = entries.filter((entry) => !entry.key.isSoleLiteral());
|
|
@@ -19,13 +22,16 @@ export const check_object =
|
|
|
19
22
|
return regular.length === 0 ? props.positive : reduce(props)(flags);
|
|
20
23
|
|
|
21
24
|
// CHECK DYNAMIC PROPERTIES
|
|
22
|
-
flags.push(
|
|
25
|
+
flags.push(
|
|
26
|
+
check_dynamic_properties(props)(importer)(input, regular, dynamic),
|
|
27
|
+
);
|
|
23
28
|
return reduce(props)(flags);
|
|
24
29
|
};
|
|
25
30
|
export namespace check_object {
|
|
26
31
|
export interface IProps {
|
|
27
32
|
equals: boolean;
|
|
28
33
|
assert: boolean;
|
|
34
|
+
undefined: boolean;
|
|
29
35
|
halt?: (exp: ts.Expression) => ts.Expression;
|
|
30
36
|
reduce: (a: ts.Expression, b: ts.Expression) => ts.Expression;
|
|
31
37
|
positive: ts.Expression;
|
|
@@ -180,7 +180,9 @@ export const check_union_array_like =
|
|
|
180
180
|
ts.factory.createNumericLiteral(0),
|
|
181
181
|
accessor.size(input),
|
|
182
182
|
),
|
|
183
|
-
ts.
|
|
183
|
+
ts.isReturnStatement(props.empty)
|
|
184
|
+
? props.empty
|
|
185
|
+
: ts.factory.createReturnStatement(props.empty),
|
|
184
186
|
),
|
|
185
187
|
]
|
|
186
188
|
: []),
|
|
@@ -224,7 +226,7 @@ export namespace check_union_array_like {
|
|
|
224
226
|
array: ts.Expression,
|
|
225
227
|
): ts.Expression;
|
|
226
228
|
decoder: UnionExplorer.Decoder<T>;
|
|
227
|
-
empty: ts.Expression;
|
|
229
|
+
empty: ts.ReturnStatement | ts.Expression;
|
|
228
230
|
success: ts.Expression;
|
|
229
231
|
failure(
|
|
230
232
|
input: ts.Expression,
|
|
@@ -9,7 +9,12 @@ import { Escaper } from "../../utils/Escaper";
|
|
|
9
9
|
import { FeatureProgrammer } from "../FeatureProgrammer";
|
|
10
10
|
|
|
11
11
|
export const feature_object_entries =
|
|
12
|
-
|
|
12
|
+
<Output extends ts.ConciseBody>(
|
|
13
|
+
config: Pick<
|
|
14
|
+
FeatureProgrammer.IConfig<Output>,
|
|
15
|
+
"decoder" | "path" | "trace"
|
|
16
|
+
>,
|
|
17
|
+
) =>
|
|
13
18
|
(obj: MetadataObject) =>
|
|
14
19
|
(input: ts.Expression) =>
|
|
15
20
|
obj.properties.map((prop) => {
|