typia 3.5.0-dev.20230126 → 3.5.0-dev.20230212
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 +70 -70
- 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 +210 -6
- package/lib/module.js +88 -9
- 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/AssertPruneProgrammer.d.ts +5 -0
- package/lib/programmers/AssertPruneProgrammer.js +37 -0
- package/lib/programmers/AssertPruneProgrammer.js.map +1 -0
- 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/IsPruneProgrammer.d.ts +5 -0
- package/lib/programmers/IsPruneProgrammer.js +37 -0
- package/lib/programmers/IsPruneProgrammer.js.map +1 -0
- 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/ValidatePruneProgrammer.d.ts +5 -0
- package/lib/programmers/ValidatePruneProgrammer.js +37 -0
- package/lib/programmers/ValidatePruneProgrammer.js.map +1 -0
- 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 +17 -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/AssertPruneTransformer.d.ts +5 -0
- package/lib/transformers/features/miscellaneous/AssertPruneTransformer.js +23 -0
- package/lib/transformers/features/miscellaneous/AssertPruneTransformer.js.map +1 -0
- package/lib/transformers/features/miscellaneous/CreateAssertPruneTransformer.d.ts +5 -0
- package/lib/transformers/features/miscellaneous/CreateAssertPruneTransformer.js +17 -0
- package/lib/transformers/features/miscellaneous/CreateAssertPruneTransformer.js.map +1 -0
- package/lib/transformers/features/miscellaneous/CreateIsPruneTransformer.d.ts +5 -0
- package/lib/transformers/features/miscellaneous/CreateIsPruneTransformer.js +17 -0
- package/lib/transformers/features/miscellaneous/CreateIsPruneTransformer.js.map +1 -0
- 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/CreateValidatePruneTransformer.d.ts +5 -0
- package/lib/transformers/features/miscellaneous/CreateValidatePruneTransformer.js +17 -0
- package/lib/transformers/features/miscellaneous/CreateValidatePruneTransformer.js.map +1 -0
- package/lib/transformers/features/miscellaneous/IsPruneTransformer.d.ts +5 -0
- package/lib/transformers/features/miscellaneous/IsPruneTransformer.js +23 -0
- package/lib/transformers/features/miscellaneous/IsPruneTransformer.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/lib/transformers/features/miscellaneous/ValidatePruneTransformer.d.ts +5 -0
- package/lib/transformers/features/miscellaneous/ValidatePruneTransformer.js +23 -0
- package/lib/transformers/features/miscellaneous/ValidatePruneTransformer.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 +366 -19
- package/src/programmers/AssertProgrammer.ts +3 -2
- package/src/programmers/AssertPruneProgrammer.ts +59 -0
- package/src/programmers/CheckerProgrammer.ts +21 -13
- package/src/programmers/FeatureProgrammer.ts +146 -21
- package/src/programmers/IsProgrammer.ts +107 -87
- package/src/programmers/IsPruneProgrammer.ts +63 -0
- package/src/programmers/PruneProgrammer.ts +323 -0
- package/src/programmers/StringifyProgrammer.ts +51 -34
- package/src/programmers/ValidateProgrammer.ts +3 -2
- package/src/programmers/ValidatePruneProgrammer.ts +73 -0
- 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 +27 -16
- package/src/transformers/ITransformOptions.ts +15 -0
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +3 -1
- package/src/transformers/features/miscellaneous/AssertPruneTransformer.ts +38 -0
- package/src/transformers/features/miscellaneous/CreateAssertPruneTransformer.ts +32 -0
- package/src/transformers/features/{protocols/MessageTransformer.ts → miscellaneous/CreateIsPruneTransformer.ts} +6 -6
- package/src/transformers/features/miscellaneous/CreatePruneTransformer.ts +31 -0
- package/src/transformers/features/miscellaneous/CreateValidatePruneTransformer.ts +32 -0
- package/src/transformers/features/miscellaneous/IsPruneTransformer.ts +38 -0
- package/src/transformers/features/miscellaneous/PruneTransformer.ts +46 -0
- package/src/transformers/features/miscellaneous/ValidatePruneTransformer.ts +38 -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
|
@@ -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) => {
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { StatementFactory } from "../../factories/StatementFactory";
|
|
4
|
+
|
|
5
|
+
import { MetadataObject } from "../../metadata/MetadataObject";
|
|
6
|
+
|
|
7
|
+
import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export const prune_object_properties = (obj: MetadataObject) => {
|
|
13
|
+
const input: ts.Expression = ts.factory.createIdentifier("input");
|
|
14
|
+
const key: ts.Expression = ts.factory.createIdentifier("key");
|
|
15
|
+
|
|
16
|
+
const condition: ts.Expression[] = obj.properties.map((prop) => {
|
|
17
|
+
const name: string | null = prop.key.getSoleLiteral();
|
|
18
|
+
if (name !== null)
|
|
19
|
+
return ts.factory.createStrictEquality(
|
|
20
|
+
ts.factory.createStringLiteral(name),
|
|
21
|
+
ts.factory.createIdentifier("key"),
|
|
22
|
+
);
|
|
23
|
+
return ts.factory.createCallExpression(
|
|
24
|
+
ts.factory.createIdentifier(
|
|
25
|
+
`RegExp(/${metadata_to_pattern(true)(prop.key)}/).test`,
|
|
26
|
+
),
|
|
27
|
+
undefined,
|
|
28
|
+
[key],
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const statements: ts.Statement[] = [];
|
|
33
|
+
if (condition.length)
|
|
34
|
+
statements.push(
|
|
35
|
+
ts.factory.createIfStatement(
|
|
36
|
+
condition.reduce((a, b) => ts.factory.createLogicalOr(a, b)),
|
|
37
|
+
ts.factory.createContinueStatement(),
|
|
38
|
+
),
|
|
39
|
+
);
|
|
40
|
+
statements.push(
|
|
41
|
+
ts.factory.createExpressionStatement(
|
|
42
|
+
ts.factory.createDeleteExpression(
|
|
43
|
+
ts.factory.createElementAccessExpression(input, key),
|
|
44
|
+
),
|
|
45
|
+
),
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
return ts.factory.createForOfStatement(
|
|
49
|
+
undefined,
|
|
50
|
+
StatementFactory.constant("key").declarationList,
|
|
51
|
+
ts.factory.createCallExpression(
|
|
52
|
+
ts.factory.createIdentifier("Object.keys"),
|
|
53
|
+
undefined,
|
|
54
|
+
[input],
|
|
55
|
+
),
|
|
56
|
+
statements.length === 1
|
|
57
|
+
? statements[0]!
|
|
58
|
+
: ts.factory.createBlock(statements, true),
|
|
59
|
+
);
|
|
60
|
+
};
|
|
@@ -10,7 +10,7 @@ import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
|
10
10
|
* @internal
|
|
11
11
|
*/
|
|
12
12
|
export function stringify_dynamic_properties(
|
|
13
|
-
dynamic: IExpressionEntry[],
|
|
13
|
+
dynamic: IExpressionEntry<ts.Expression>[],
|
|
14
14
|
regular: string[],
|
|
15
15
|
): ts.Expression {
|
|
16
16
|
// BASIC STATMEMENT, CHECK UNDEFINED
|
|
@@ -149,7 +149,7 @@ export function stringify_dynamic_properties(
|
|
|
149
149
|
return output();
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
function stringify(entry: IExpressionEntry): ts.ReturnStatement {
|
|
152
|
+
function stringify(entry: IExpressionEntry<ts.Expression>): ts.ReturnStatement {
|
|
153
153
|
return ts.factory.createReturnStatement(
|
|
154
154
|
TemplateFactory.generate([
|
|
155
155
|
ts.factory.createCallExpression(
|
|
@@ -11,8 +11,8 @@ import { IExpressionEntry } from "../helpers/IExpressionEntry";
|
|
|
11
11
|
* @internal
|
|
12
12
|
*/
|
|
13
13
|
export function stringify_regular_properties(
|
|
14
|
-
regular: IExpressionEntry[],
|
|
15
|
-
dynamic: IExpressionEntry[],
|
|
14
|
+
regular: IExpressionEntry<ts.Expression>[],
|
|
15
|
+
dynamic: IExpressionEntry<ts.Expression>[],
|
|
16
16
|
): ts.Expression[] {
|
|
17
17
|
const output: ts.Expression[] = [];
|
|
18
18
|
|
|
@@ -3,14 +3,21 @@ import ts from "typescript";
|
|
|
3
3
|
|
|
4
4
|
import { IProject } from "./IProject";
|
|
5
5
|
import { ApplicationTransformer } from "./features/miscellaneous/ApplicationTransformer";
|
|
6
|
+
import { AssertPruneTransformer } from "./features/miscellaneous/AssertPruneTransformer";
|
|
7
|
+
import { CreateAssertPruneTransformer } from "./features/miscellaneous/CreateAssertPruneTransformer";
|
|
8
|
+
import { CreateIsPruneTransformer } from "./features/miscellaneous/CreateIsPruneTransformer";
|
|
9
|
+
import { CreatePruneTransformer } from "./features/miscellaneous/CreatePruneTransformer";
|
|
10
|
+
import { CreateValidatePruneTransformer } from "./features/miscellaneous/CreateValidatePruneTransformer";
|
|
11
|
+
import { IsPruneTransformer } from "./features/miscellaneous/IsPruneTransformer";
|
|
6
12
|
import { MetadataTransformer } from "./features/miscellaneous/MetadataTransformer";
|
|
13
|
+
import { PruneTransformer } from "./features/miscellaneous/PruneTransformer";
|
|
14
|
+
import { ValidatePruneTransformer } from "./features/miscellaneous/ValidatePruneTransformer";
|
|
7
15
|
import { AssertParseTransformer } from "./features/parsers/AssertParseTransformer";
|
|
8
16
|
import { CreateAssertParseTransformer } from "./features/parsers/CreateAssertParseTransformer";
|
|
9
17
|
import { CreateIsParseTransformer } from "./features/parsers/CreateIsParseTransformer";
|
|
10
18
|
import { CreateValidateParseTransformer } from "./features/parsers/CreateValidateParseTransformer";
|
|
11
19
|
import { IsParseTransformer } from "./features/parsers/IsParseTransformer";
|
|
12
20
|
import { ValidateParseTransformer } from "./features/parsers/ValidateParseTransformer";
|
|
13
|
-
import { MessageTransformer } from "./features/protocols/MessageTransformer";
|
|
14
21
|
import { AssertStringifyTransformer } from "./features/stringifiers/AssertStringifyTransformer";
|
|
15
22
|
import { CreateAssertStringifyTransformer } from "./features/stringifiers/CreateAssertStringifyTransformer";
|
|
16
23
|
import { CreateIsStringifyTransformer } from "./features/stringifiers/CreateIsStringifyTransformer";
|
|
@@ -70,7 +77,7 @@ const SRC_PATH = path.resolve(path.join(__dirname, "..", "module.ts"));
|
|
|
70
77
|
|
|
71
78
|
const FUNCTORS: Record<string, () => Task> = {
|
|
72
79
|
//----
|
|
73
|
-
//
|
|
80
|
+
// SINGLE FUNCTIONS
|
|
74
81
|
//----
|
|
75
82
|
// BASIC VALIDATORS
|
|
76
83
|
assert: () => AssertTransformer.transform(false),
|
|
@@ -83,18 +90,7 @@ const FUNCTORS: Record<string, () => Task> = {
|
|
|
83
90
|
equals: () => IsTransformer.transform(true),
|
|
84
91
|
validateEquals: () => ValidateTransformer.transform(true),
|
|
85
92
|
|
|
86
|
-
|
|
87
|
-
// PROTOCOL BUFFER
|
|
88
|
-
//----
|
|
89
|
-
message: () => MessageTransformer.transform,
|
|
90
|
-
|
|
91
|
-
//----
|
|
92
|
-
// JSON FUNCTIONS
|
|
93
|
-
//----
|
|
94
|
-
// SCHEMA DEFINITION
|
|
95
|
-
application: () => ApplicationTransformer.transform,
|
|
96
|
-
|
|
97
|
-
// PARSER FUNCTIONS
|
|
93
|
+
// PARSE FUNCTIONS
|
|
98
94
|
isParse: () => IsParseTransformer.transform,
|
|
99
95
|
assertParse: () => AssertParseTransformer.transform,
|
|
100
96
|
validateParse: () => ValidateParseTransformer.transform,
|
|
@@ -106,26 +102,41 @@ const FUNCTORS: Record<string, () => Task> = {
|
|
|
106
102
|
validateStringify: () => ValidateStringifyTransformer.transform,
|
|
107
103
|
|
|
108
104
|
// MISC
|
|
105
|
+
application: () => ApplicationTransformer.transform,
|
|
109
106
|
metadata: () => MetadataTransformer.transform,
|
|
107
|
+
prune: () => PruneTransformer.transform,
|
|
108
|
+
assertPrune: () => AssertPruneTransformer.transform,
|
|
109
|
+
isPrune: () => IsPruneTransformer.transform,
|
|
110
|
+
validatePrune: () => ValidatePruneTransformer.transform,
|
|
110
111
|
|
|
111
112
|
//----
|
|
112
113
|
// FACTORY FUNCTIONS
|
|
113
114
|
//----
|
|
114
|
-
// VALIDATORS
|
|
115
|
+
// BASIC VALIDATORS
|
|
115
116
|
createAssert: () => CreateAssertTransformer.transform(false),
|
|
116
117
|
createAssertType: () => CreateAssertTransformer.transform(false),
|
|
117
118
|
createIs: () => CreateIsTransformer.transform(false),
|
|
118
119
|
createValidate: () => CreateValidateTransformer.transform(false),
|
|
120
|
+
|
|
121
|
+
// STRICT VALIDATORS
|
|
119
122
|
createAssertEquals: () => CreateAssertTransformer.transform(true),
|
|
120
123
|
createEquals: () => CreateIsTransformer.transform(true),
|
|
121
124
|
createValidateEquals: () => CreateValidateTransformer.transform(true),
|
|
122
125
|
|
|
123
|
-
//
|
|
126
|
+
// PARSE FUNCTIONS
|
|
124
127
|
createIsParse: () => CreateIsParseTransformer.transform,
|
|
125
128
|
createAssertParse: () => CreateAssertParseTransformer.transform,
|
|
126
129
|
createValidateParse: () => CreateValidateParseTransformer.transform,
|
|
130
|
+
|
|
131
|
+
// STRINGIFY FUNCTIONS
|
|
127
132
|
createStringify: () => CreateStringifyTransformer.transform,
|
|
128
133
|
createAssertStringify: () => CreateAssertStringifyTransformer.transform,
|
|
129
134
|
createIsStringify: () => CreateIsStringifyTransformer.transform,
|
|
130
135
|
createValidateStringify: () => CreateValidateStringifyTransformer.transform,
|
|
136
|
+
|
|
137
|
+
// MISC
|
|
138
|
+
createPrune: () => CreatePruneTransformer.transform,
|
|
139
|
+
createAssertPrune: () => CreateAssertPruneTransformer.transform,
|
|
140
|
+
createIsPrune: () => CreateIsPruneTransformer.transform,
|
|
141
|
+
createValidatePrune: () => CreateValidatePruneTransformer.transform,
|
|
131
142
|
};
|
|
@@ -44,4 +44,19 @@ export interface ITransformOptions {
|
|
|
44
44
|
* @default false
|
|
45
45
|
*/
|
|
46
46
|
functional?: boolean;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Whether to check undefined value or not.
|
|
50
|
+
*
|
|
51
|
+
* JavaScript can assign `undefined` value to a specific property and it is an
|
|
52
|
+
* issue when validating without allowing superfluous properties. Should undefined
|
|
53
|
+
* value assigned superfluous property be allowed or not?
|
|
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
|
+
*
|
|
59
|
+
* @default true
|
|
60
|
+
*/
|
|
61
|
+
undefined?: boolean;
|
|
47
62
|
}
|
|
@@ -59,7 +59,9 @@ export namespace ApplicationTransformer {
|
|
|
59
59
|
// GENERATORS
|
|
60
60
|
//----
|
|
61
61
|
// METADATA
|
|
62
|
-
const collection: MetadataCollection = new MetadataCollection(
|
|
62
|
+
const collection: MetadataCollection = new MetadataCollection({
|
|
63
|
+
replace: MetadataCollection.replace,
|
|
64
|
+
});
|
|
63
65
|
const metadatas: Array<Metadata> = types.map((type) =>
|
|
64
66
|
MetadataFactory.generate(checker, collection, type, {
|
|
65
67
|
resolve: true,
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { AssertPruneProgrammer } from "../../../programmers/AssertPruneProgrammer";
|
|
4
|
+
|
|
5
|
+
import { IProject } from "../../IProject";
|
|
6
|
+
|
|
7
|
+
export namespace AssertPruneTransformer {
|
|
8
|
+
export function transform(
|
|
9
|
+
project: IProject,
|
|
10
|
+
modulo: ts.LeftHandSideExpression,
|
|
11
|
+
expression: ts.CallExpression,
|
|
12
|
+
): ts.Expression {
|
|
13
|
+
if (expression.arguments.length !== 1)
|
|
14
|
+
throw new Error(ErrorMessages.NO_INPUT_VALUE);
|
|
15
|
+
|
|
16
|
+
// GET TYPE INFO
|
|
17
|
+
const type: ts.Type =
|
|
18
|
+
expression.typeArguments && expression.typeArguments[0]
|
|
19
|
+
? project.checker.getTypeFromTypeNode(
|
|
20
|
+
expression.typeArguments[0],
|
|
21
|
+
)
|
|
22
|
+
: project.checker.getTypeAtLocation(expression.arguments[0]!);
|
|
23
|
+
if (type.isTypeParameter())
|
|
24
|
+
throw new Error(ErrorMessages.GENERIC_ARGUMENT);
|
|
25
|
+
|
|
26
|
+
// DO TRANSFORM
|
|
27
|
+
return ts.factory.createCallExpression(
|
|
28
|
+
AssertPruneProgrammer.generate(project, modulo)(type),
|
|
29
|
+
undefined,
|
|
30
|
+
[expression.arguments[0]!],
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const enum ErrorMessages {
|
|
36
|
+
NO_INPUT_VALUE = "Error on typia.assertPrune(): no input value.",
|
|
37
|
+
GENERIC_ARGUMENT = "Error on typia.assertPrune(): non-specified generic argument.",
|
|
38
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { AssertPruneProgrammer } from "../../../programmers/AssertPruneProgrammer";
|
|
4
|
+
|
|
5
|
+
import { IProject } from "../../IProject";
|
|
6
|
+
|
|
7
|
+
export namespace CreateAssertPruneTransformer {
|
|
8
|
+
export function transform(
|
|
9
|
+
project: IProject,
|
|
10
|
+
modulo: ts.LeftHandSideExpression,
|
|
11
|
+
expression: ts.CallExpression,
|
|
12
|
+
): ts.Expression {
|
|
13
|
+
// CHECK GENERIC ARGUMENT EXISTENCE
|
|
14
|
+
if (!expression.typeArguments || !expression.typeArguments[0])
|
|
15
|
+
throw new Error(ErrorMessages.NOT_SPECIFIED);
|
|
16
|
+
|
|
17
|
+
// GET TYPE INFO
|
|
18
|
+
const type: ts.Type = project.checker.getTypeFromTypeNode(
|
|
19
|
+
expression.typeArguments[0],
|
|
20
|
+
);
|
|
21
|
+
if (type.isTypeParameter())
|
|
22
|
+
throw new Error(ErrorMessages.GENERIC_ARGUMENT);
|
|
23
|
+
|
|
24
|
+
// DO TRANSFORM
|
|
25
|
+
return AssertPruneProgrammer.generate(project, modulo)(type);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const enum ErrorMessages {
|
|
30
|
+
NOT_SPECIFIED = "Error on typia.assertPrune(): generic argument is not specified.",
|
|
31
|
+
GENERIC_ARGUMENT = "Error on typia.assertPrune(): non-specified generic argument.",
|
|
32
|
+
}
|