typia 3.6.2 → 3.6.3
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 +2 -1
- package/lib/factories/internal/metadata/emplace_metadata_object.js +8 -7
- package/lib/factories/internal/metadata/emplace_metadata_object.js.map +1 -1
- package/lib/module.d.ts +2 -2
- package/package.json +1 -1
- package/src/IRandomGenerator.ts +16 -16
- package/src/IValidation.ts +21 -21
- package/src/Primitive.ts +104 -104
- package/src/TypeGuardError.ts +36 -36
- package/src/executable/TypiaGenerateWizard.ts +87 -87
- package/src/executable/TypiaSetupWizard.ts +142 -142
- package/src/executable/setup/ArgumentParser.ts +91 -91
- package/src/executable/setup/CommandExecutor.ts +8 -8
- package/src/executable/setup/FileRetriever.ts +33 -33
- package/src/executable/setup/PackageManager.ts +92 -92
- package/src/executable/setup/PluginConfigurator.ts +99 -99
- package/src/executable/typia.ts +38 -38
- package/src/factories/CommentFactory.ts +10 -10
- package/src/factories/ExpressionFactory.ts +77 -77
- package/src/factories/IdentifierFactory.ts +73 -73
- package/src/factories/LiteralFactory.ts +44 -44
- package/src/factories/MetadataCollection.ts +122 -122
- package/src/factories/MetadataFactory.ts +51 -51
- package/src/factories/MetadataTagFactory.ts +265 -265
- package/src/factories/StatementFactory.ts +60 -60
- package/src/factories/TemplateFactory.ts +56 -56
- package/src/factories/TypeFactory.ts +129 -129
- package/src/factories/TypiaFileFactory.ts +117 -117
- package/src/factories/ValueFactory.ts +12 -12
- package/src/factories/internal/metadata/MetadataHelper.ts +12 -12
- package/src/factories/internal/metadata/emplace_metadata_object.ts +142 -140
- package/src/factories/internal/metadata/explore_metadata.ts +92 -92
- package/src/factories/internal/metadata/iterate_metadata.ts +80 -80
- package/src/factories/internal/metadata/iterate_metadata_array.ts +29 -29
- package/src/factories/internal/metadata/iterate_metadata_atomic.ts +59 -59
- package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
- package/src/factories/internal/metadata/iterate_metadata_constant.ts +58 -58
- package/src/factories/internal/metadata/iterate_metadata_map.ts +41 -41
- package/src/factories/internal/metadata/iterate_metadata_native.ts +222 -222
- package/src/factories/internal/metadata/iterate_metadata_object.ts +48 -48
- package/src/factories/internal/metadata/iterate_metadata_resolve.ts +27 -27
- package/src/factories/internal/metadata/iterate_metadata_set.ts +33 -33
- package/src/factories/internal/metadata/iterate_metadata_template.ts +38 -38
- package/src/factories/internal/metadata/iterate_metadata_tuple.ts +45 -45
- package/src/factories/internal/metadata/iterate_metadata_union.ts +59 -59
- package/src/functional/$any.ts +3 -3
- package/src/functional/$every.ts +11 -11
- package/src/functional/$guard.ts +35 -35
- package/src/functional/$is_between.ts +7 -7
- package/src/functional/$is_email.ts +5 -5
- package/src/functional/$is_ipv4.ts +5 -5
- package/src/functional/$is_ipv6.ts +5 -5
- package/src/functional/$is_url.ts +5 -5
- package/src/functional/$is_uuid.ts +5 -5
- package/src/functional/$join.ts +50 -50
- package/src/functional/$number.ts +12 -12
- package/src/functional/$report.ts +15 -15
- package/src/functional/$rest.ts +3 -3
- package/src/functional/$string.ts +37 -37
- package/src/functional/$tail.ts +6 -6
- package/src/functional/Namespace.ts +121 -121
- package/src/index.ts +4 -4
- package/src/metadata/IJsDocTagInfo.ts +10 -10
- package/src/metadata/IMetadata.ts +25 -25
- package/src/metadata/IMetadataApplication.ts +7 -7
- package/src/metadata/IMetadataConstant.ts +16 -16
- package/src/metadata/IMetadataEntry.ts +6 -6
- package/src/metadata/IMetadataObject.ts +29 -29
- package/src/metadata/IMetadataProperty.ts +11 -11
- package/src/metadata/IMetadataTag.ts +113 -113
- package/src/metadata/Metadata.ts +534 -534
- package/src/metadata/MetadataConstant.ts +3 -3
- package/src/metadata/MetadataObject.ts +131 -131
- package/src/metadata/MetadataProperty.ts +64 -64
- package/src/module.ts +1946 -1946
- package/src/programmers/ApplicationProgrammer.ts +55 -55
- package/src/programmers/AssertCloneProgrammer.ts +70 -70
- package/src/programmers/AssertParseProgrammer.ts +65 -65
- package/src/programmers/AssertProgrammer.ts +232 -232
- package/src/programmers/AssertPruneProgrammer.ts +67 -67
- package/src/programmers/AssertStringifyProgrammer.ts +71 -71
- package/src/programmers/CheckerProgrammer.ts +893 -893
- package/src/programmers/CloneProgrammer.ts +386 -386
- package/src/programmers/FeatureProgrammer.ts +505 -505
- package/src/programmers/IsCloneProgrammer.ts +80 -80
- package/src/programmers/IsParseProgrammer.ts +74 -74
- package/src/programmers/IsProgrammer.ts +200 -200
- package/src/programmers/IsPruneProgrammer.ts +75 -75
- package/src/programmers/IsStringifyProgrammer.ts +81 -81
- package/src/programmers/PruneProgrammer.ts +341 -341
- package/src/programmers/RandomProgrammer.ts +391 -391
- package/src/programmers/StringifyProgrammer.ts +795 -795
- package/src/programmers/ValidateCloneProgrammer.ts +90 -90
- package/src/programmers/ValidateParseProgrammer.ts +69 -69
- package/src/programmers/ValidateProgrammer.ts +266 -266
- package/src/programmers/ValidatePruneProgrammer.ts +83 -83
- package/src/programmers/ValidateStringifyProgrammer.ts +89 -89
- package/src/programmers/helpers/AtomicPredicator.ts +31 -31
- package/src/programmers/helpers/CloneJoiner.ts +134 -134
- package/src/programmers/helpers/FunctionImporeter.ts +55 -55
- package/src/programmers/helpers/IExpressionEntry.ts +12 -12
- package/src/programmers/helpers/OptionPredicator.ts +19 -19
- package/src/programmers/helpers/PruneJoiner.ts +52 -52
- package/src/programmers/helpers/RandomJoiner.ts +149 -149
- package/src/programmers/helpers/RandomRanger.ts +216 -216
- package/src/programmers/helpers/StringifyJoinder.ts +114 -114
- package/src/programmers/helpers/StringifyPredicator.ts +18 -18
- package/src/programmers/helpers/UnionExplorer.ts +274 -274
- package/src/programmers/helpers/UnionPredicator.ts +81 -81
- package/src/programmers/internal/application_array.ts +37 -37
- package/src/programmers/internal/application_boolean.ts +17 -17
- package/src/programmers/internal/application_constant.ts +29 -29
- package/src/programmers/internal/application_default.ts +17 -17
- package/src/programmers/internal/application_default_string.ts +32 -32
- package/src/programmers/internal/application_native.ts +29 -29
- package/src/programmers/internal/application_number.ts +70 -70
- package/src/programmers/internal/application_object.ts +153 -153
- package/src/programmers/internal/application_schema.ts +184 -184
- package/src/programmers/internal/application_string.ts +41 -41
- package/src/programmers/internal/application_templates.ts +27 -27
- package/src/programmers/internal/application_tuple.ts +29 -29
- package/src/programmers/internal/check_array.ts +22 -22
- package/src/programmers/internal/check_array_length.ts +44 -44
- package/src/programmers/internal/check_bigint.ts +64 -64
- package/src/programmers/internal/check_dynamic_properties.ts +197 -197
- package/src/programmers/internal/check_everything.ts +28 -28
- package/src/programmers/internal/check_native.ts +21 -21
- package/src/programmers/internal/check_number.ts +145 -145
- package/src/programmers/internal/check_object.ts +48 -48
- package/src/programmers/internal/check_string.ts +24 -24
- package/src/programmers/internal/check_string_tags.ts +63 -63
- package/src/programmers/internal/check_template.ts +50 -50
- package/src/programmers/internal/check_union_array_like.ts +260 -260
- package/src/programmers/internal/check_union_tuple.ts +33 -33
- package/src/programmers/internal/decode_union_object.ts +73 -73
- package/src/programmers/internal/feature_object_entries.ts +59 -59
- package/src/programmers/internal/metadata_to_pattern.ts +31 -31
- package/src/programmers/internal/prune_object_properties.ts +60 -60
- package/src/programmers/internal/stringify_dynamic_properties.ts +165 -165
- package/src/programmers/internal/stringify_native.ts +8 -8
- package/src/programmers/internal/stringify_regular_properties.ts +81 -81
- package/src/programmers/internal/template_to_pattern.ts +15 -15
- package/src/schemas/IJsonApplication.ts +9 -9
- package/src/schemas/IJsonComponents.ts +26 -26
- package/src/schemas/IJsonSchema.ts +127 -127
- package/src/transform.ts +21 -21
- package/src/transformers/CallExpressionTransformer.ts +172 -172
- package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
- package/src/transformers/FileTransformer.ts +49 -49
- package/src/transformers/IProject.ts +11 -11
- package/src/transformers/ITransformOptions.ts +62 -62
- package/src/transformers/ImportTransformer.ts +60 -60
- package/src/transformers/NodeTransformer.ts +19 -19
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +120 -120
- package/src/transformers/features/miscellaneous/AssertCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/AssertPruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateAssertCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateAssertPruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateIsCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateIsPruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreatePruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateRandomGenerator.ts +42 -42
- package/src/transformers/features/miscellaneous/CreateValidateCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateValidatePruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/IsCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/IsPruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/MetadataTransformer.ts +55 -55
- package/src/transformers/features/miscellaneous/PruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/RandomTransformer.ts +48 -48
- package/src/transformers/features/miscellaneous/ValidateCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/ValidatePruneTransformer.ts +9 -9
- package/src/transformers/features/parsers/AssertParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/CreateIsParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/IsParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/ValidateParseTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +10 -10
- package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +11 -11
- package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/StringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +10 -10
- package/src/transformers/features/validators/AssertTransformer.ts +11 -11
- package/src/transformers/features/validators/CreateAssertTransformer.ts +12 -12
- package/src/transformers/features/validators/CreateIsTransformer.ts +10 -10
- package/src/transformers/features/validators/CreateValidateTransformer.ts +12 -12
- package/src/transformers/features/validators/IsTransformer.ts +10 -10
- package/src/transformers/features/validators/ValidateTransformer.ts +11 -11
- package/src/transformers/internal/GenericTransformer.ts +99 -99
- package/src/typings/Atomic.ts +17 -17
- package/src/typings/ClassProperties.ts +5 -5
- package/src/typings/OmitNever.ts +3 -3
- package/src/typings/SpecialFields.ts +3 -3
- package/src/typings/Writable.ts +11 -11
- package/src/utils/ArrayUtil.ts +49 -49
- package/src/utils/Escaper.ts +50 -50
- package/src/utils/MapUtil.ts +14 -14
- package/src/utils/PatternUtil.ts +30 -30
- package/src/utils/RandomGenerator.ts +90 -90
- package/src/utils/Singleton.ts +17 -17
package/src/metadata/Metadata.ts
CHANGED
|
@@ -1,534 +1,534 @@
|
|
|
1
|
-
import { Atomic } from "../typings/Atomic";
|
|
2
|
-
import { ClassProperties } from "../typings/ClassProperties";
|
|
3
|
-
|
|
4
|
-
import { ArrayUtil } from "../utils/ArrayUtil";
|
|
5
|
-
|
|
6
|
-
import { IMetadata } from "./IMetadata";
|
|
7
|
-
import { IMetadataObject } from "./IMetadataObject";
|
|
8
|
-
import { MetadataConstant } from "./MetadataConstant";
|
|
9
|
-
import { MetadataObject } from "./MetadataObject";
|
|
10
|
-
import { MetadataProperty } from "./MetadataProperty";
|
|
11
|
-
|
|
12
|
-
export class Metadata {
|
|
13
|
-
public readonly any: boolean;
|
|
14
|
-
public readonly required: boolean;
|
|
15
|
-
public readonly nullable: boolean;
|
|
16
|
-
public readonly functional: boolean;
|
|
17
|
-
|
|
18
|
-
public readonly resolved: Metadata | null;
|
|
19
|
-
public readonly atomics: Atomic.Literal[];
|
|
20
|
-
public readonly constants: MetadataConstant[];
|
|
21
|
-
public readonly templates: Metadata[][];
|
|
22
|
-
|
|
23
|
-
public readonly rest: Metadata | null;
|
|
24
|
-
public readonly arrays: Metadata[];
|
|
25
|
-
public readonly tuples: Metadata[][];
|
|
26
|
-
public readonly objects: MetadataObject[];
|
|
27
|
-
|
|
28
|
-
public readonly natives: string[];
|
|
29
|
-
public readonly sets: Metadata[];
|
|
30
|
-
public readonly maps: Metadata.Entry[];
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @internal
|
|
34
|
-
*/
|
|
35
|
-
private name_: string | undefined = undefined;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @internal
|
|
39
|
-
*/
|
|
40
|
-
private parent_resolved_: boolean = false;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @internal
|
|
44
|
-
*/
|
|
45
|
-
public union_index?: number;
|
|
46
|
-
|
|
47
|
-
/* -----------------------------------------------------------
|
|
48
|
-
CONSTRUCTORS
|
|
49
|
-
----------------------------------------------------------- */
|
|
50
|
-
/**
|
|
51
|
-
* @hidden
|
|
52
|
-
*/
|
|
53
|
-
private constructor(props: ClassProperties<Metadata>) {
|
|
54
|
-
this.any = props.any;
|
|
55
|
-
this.required = props.required;
|
|
56
|
-
this.nullable = props.nullable;
|
|
57
|
-
this.functional = props.functional;
|
|
58
|
-
|
|
59
|
-
this.resolved = props.resolved;
|
|
60
|
-
this.atomics = props.atomics;
|
|
61
|
-
this.constants = props.constants;
|
|
62
|
-
this.templates = props.templates;
|
|
63
|
-
|
|
64
|
-
this.rest = props.rest;
|
|
65
|
-
this.arrays = props.arrays;
|
|
66
|
-
this.tuples = props.tuples;
|
|
67
|
-
this.objects = props.objects;
|
|
68
|
-
|
|
69
|
-
this.natives = props.natives;
|
|
70
|
-
this.sets = props.sets;
|
|
71
|
-
this.maps = props.maps;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* @internal
|
|
76
|
-
*/
|
|
77
|
-
public static create(props: ClassProperties<Metadata>): Metadata {
|
|
78
|
-
return new Metadata(props);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* @internal
|
|
83
|
-
*/
|
|
84
|
-
public static initialize(parentResolved: boolean = false): Metadata {
|
|
85
|
-
const meta: Metadata = this.create({
|
|
86
|
-
any: false,
|
|
87
|
-
nullable: false,
|
|
88
|
-
required: true,
|
|
89
|
-
functional: false,
|
|
90
|
-
|
|
91
|
-
resolved: null,
|
|
92
|
-
constants: [],
|
|
93
|
-
atomics: [],
|
|
94
|
-
templates: [],
|
|
95
|
-
arrays: [],
|
|
96
|
-
tuples: [],
|
|
97
|
-
objects: [],
|
|
98
|
-
|
|
99
|
-
rest: null,
|
|
100
|
-
natives: [],
|
|
101
|
-
sets: [],
|
|
102
|
-
maps: [],
|
|
103
|
-
});
|
|
104
|
-
meta.parent_resolved_ = parentResolved;
|
|
105
|
-
return meta;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
public toJSON(): IMetadata {
|
|
109
|
-
return {
|
|
110
|
-
any: this.any,
|
|
111
|
-
required: this.required,
|
|
112
|
-
nullable: this.nullable,
|
|
113
|
-
functional: this.functional,
|
|
114
|
-
|
|
115
|
-
atomics: this.atomics.slice(),
|
|
116
|
-
constants: JSON.parse(JSON.stringify(this.constants)),
|
|
117
|
-
templates: this.templates.map((tpl) =>
|
|
118
|
-
tpl.map((meta) => meta.toJSON()),
|
|
119
|
-
),
|
|
120
|
-
resolved: this.resolved ? this.resolved.toJSON() : null,
|
|
121
|
-
|
|
122
|
-
rest: this.rest ? this.rest.toJSON() : null,
|
|
123
|
-
arrays: this.arrays.map((meta) => meta.toJSON()),
|
|
124
|
-
tuples: this.tuples.map((meta) =>
|
|
125
|
-
meta.map((meta) => meta.toJSON()),
|
|
126
|
-
),
|
|
127
|
-
objects: this.objects.map((obj) => obj.name),
|
|
128
|
-
|
|
129
|
-
natives: this.natives.slice(),
|
|
130
|
-
sets: this.sets.map((meta) => meta.toJSON()),
|
|
131
|
-
maps: this.maps.map((entry) => ({
|
|
132
|
-
key: entry.key.toJSON(),
|
|
133
|
-
value: entry.value.toJSON(),
|
|
134
|
-
})),
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
public static from(meta: IMetadata, objects: IMetadataObject[]): Metadata {
|
|
139
|
-
const dict: Map<string, MetadataObject> = new Map();
|
|
140
|
-
for (const obj of objects)
|
|
141
|
-
dict.set(obj.name, MetadataObject._From_without_properties(obj));
|
|
142
|
-
|
|
143
|
-
for (const obj of objects) {
|
|
144
|
-
const initialized = dict.get(obj.name)!;
|
|
145
|
-
initialized.properties.push(
|
|
146
|
-
...obj.properties.map((prop) =>
|
|
147
|
-
MetadataProperty._From(prop, dict),
|
|
148
|
-
),
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
return this._From(meta, dict);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* @internal
|
|
156
|
-
*/
|
|
157
|
-
public static _From(
|
|
158
|
-
meta: IMetadata,
|
|
159
|
-
objects: Map<string, MetadataObject>,
|
|
160
|
-
): Metadata {
|
|
161
|
-
return this.create({
|
|
162
|
-
any: meta.any,
|
|
163
|
-
required: meta.required,
|
|
164
|
-
nullable: meta.nullable,
|
|
165
|
-
functional: meta.functional,
|
|
166
|
-
|
|
167
|
-
constants: JSON.parse(JSON.stringify(meta.constants)),
|
|
168
|
-
atomics: meta.atomics.slice(),
|
|
169
|
-
templates: meta.templates.map((tpl) =>
|
|
170
|
-
tpl.map((meta) => this._From(meta, objects)),
|
|
171
|
-
),
|
|
172
|
-
resolved: meta.resolved ? this._From(meta.resolved, objects) : null,
|
|
173
|
-
|
|
174
|
-
rest: meta.rest ? this._From(meta.rest, objects) : null,
|
|
175
|
-
arrays: meta.arrays.map((meta) => this._From(meta, objects)),
|
|
176
|
-
tuples: meta.tuples.map((tuple) =>
|
|
177
|
-
tuple.map((meta) => this._From(meta, objects)),
|
|
178
|
-
),
|
|
179
|
-
objects: meta.objects.map((name) => {
|
|
180
|
-
const found = objects.get(name);
|
|
181
|
-
if (found === undefined)
|
|
182
|
-
throw new Error(
|
|
183
|
-
`Error on Metadata.from(): failed to find object "${name}".`,
|
|
184
|
-
);
|
|
185
|
-
return found;
|
|
186
|
-
}),
|
|
187
|
-
|
|
188
|
-
natives: meta.natives.slice(),
|
|
189
|
-
sets: meta.sets.map((meta) => this._From(meta, objects)),
|
|
190
|
-
maps: meta.maps.map((entry) => ({
|
|
191
|
-
key: this._From(entry.key, objects),
|
|
192
|
-
value: this._From(entry.value, objects),
|
|
193
|
-
})),
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/* -----------------------------------------------------------
|
|
198
|
-
ACCESSORS
|
|
199
|
-
----------------------------------------------------------- */
|
|
200
|
-
public getName(): string {
|
|
201
|
-
this.name_ ||= getName(this);
|
|
202
|
-
return this.name_;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
public empty(): boolean {
|
|
206
|
-
return this.bucket() === 0 || this.size() === 0;
|
|
207
|
-
}
|
|
208
|
-
public size(): number {
|
|
209
|
-
return (
|
|
210
|
-
(this.resolved ? 1 : 0) +
|
|
211
|
-
(this.functional ? 1 : 0) +
|
|
212
|
-
this.templates.length +
|
|
213
|
-
this.atomics.length +
|
|
214
|
-
this.constants
|
|
215
|
-
.map((c) => c.values.length)
|
|
216
|
-
.reduce((x, y) => x + y, 0) +
|
|
217
|
-
(this.rest ? this.rest.size() : 0) +
|
|
218
|
-
this.arrays.length +
|
|
219
|
-
this.tuples.length +
|
|
220
|
-
this.objects.length +
|
|
221
|
-
this.natives.length +
|
|
222
|
-
this.sets.length +
|
|
223
|
-
this.maps.length
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
public bucket(): number {
|
|
227
|
-
return (
|
|
228
|
-
(this.resolved ? 1 : 0) +
|
|
229
|
-
(this.functional ? 1 : 0) +
|
|
230
|
-
(this.templates.length ? 1 : 0) +
|
|
231
|
-
(this.atomics.length ? 1 : 0) +
|
|
232
|
-
(this.constants.length ? 1 : 0) +
|
|
233
|
-
(this.rest ? this.rest.size() : 0) +
|
|
234
|
-
(this.arrays.length ? 1 : 0) +
|
|
235
|
-
(this.tuples.length ? 1 : 0) +
|
|
236
|
-
(this.objects.length ? 1 : 0) +
|
|
237
|
-
(this.natives.length ? 1 : 0) +
|
|
238
|
-
(this.sets.length ? 1 : 0) +
|
|
239
|
-
(this.maps.length ? 1 : 0)
|
|
240
|
-
);
|
|
241
|
-
}
|
|
242
|
-
public isConstant(): boolean {
|
|
243
|
-
return this.bucket() === (this.constants.length ? 1 : 0);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* @internal
|
|
248
|
-
*/
|
|
249
|
-
public isUnionBucket(): boolean {
|
|
250
|
-
const size: number = this.bucket();
|
|
251
|
-
const emended: number = this.constants.length ? size - 1 : size;
|
|
252
|
-
return emended > 1;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* @internal
|
|
257
|
-
*/
|
|
258
|
-
public getSoleLiteral(): string | null {
|
|
259
|
-
if (
|
|
260
|
-
this.size() === 1 &&
|
|
261
|
-
this.constants.length === 1 &&
|
|
262
|
-
this.constants[0]!.type === "string" &&
|
|
263
|
-
this.constants[0]!.values.length === 1
|
|
264
|
-
)
|
|
265
|
-
return this.constants[0]!.values[0] as string;
|
|
266
|
-
else return null;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* @internal
|
|
271
|
-
*/
|
|
272
|
-
public isSoleLiteral(): boolean {
|
|
273
|
-
return this.getSoleLiteral() !== null;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* @internal
|
|
278
|
-
*/
|
|
279
|
-
public isParentResolved(): boolean {
|
|
280
|
-
return this.parent_resolved_;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
export namespace Metadata {
|
|
284
|
-
export function intersects(
|
|
285
|
-
x: Metadata,
|
|
286
|
-
y: Metadata,
|
|
287
|
-
deep: boolean,
|
|
288
|
-
): boolean {
|
|
289
|
-
// CHECK ANY & OPTIONAL
|
|
290
|
-
if (x.any || y.any) return true;
|
|
291
|
-
if (x.required === false && false === y.required) return true;
|
|
292
|
-
if (x.nullable === true && true === y.nullable) return true;
|
|
293
|
-
|
|
294
|
-
//----
|
|
295
|
-
// INSTANCES
|
|
296
|
-
//----
|
|
297
|
-
// ARRAYS AND OBJECTS
|
|
298
|
-
if (deep === true) {
|
|
299
|
-
for (const xa of x.arrays)
|
|
300
|
-
for (const ya of y.arrays)
|
|
301
|
-
if (intersects(xa, ya, deep)) {
|
|
302
|
-
return true;
|
|
303
|
-
}
|
|
304
|
-
for (const xo of x.objects)
|
|
305
|
-
for (const yo of y.objects)
|
|
306
|
-
if (MetadataObject.intersects(xo, yo)) {
|
|
307
|
-
return true;
|
|
308
|
-
}
|
|
309
|
-
} else {
|
|
310
|
-
if (x.arrays.length && y.arrays.length) return true;
|
|
311
|
-
if (x.objects.length && y.objects.length) return true;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
// TUPLES
|
|
315
|
-
for (const xt of x.tuples)
|
|
316
|
-
for (const yt of y.tuples)
|
|
317
|
-
if (xt.length === 0 || yt.length === 0)
|
|
318
|
-
return xt.length === 0 && yt.length === 0;
|
|
319
|
-
else if (
|
|
320
|
-
xt
|
|
321
|
-
.slice(0, Math.min(xt.length, yt.length))
|
|
322
|
-
.some((xv, i) => intersects(xv, yt[i]!, deep))
|
|
323
|
-
)
|
|
324
|
-
return true;
|
|
325
|
-
|
|
326
|
-
//----
|
|
327
|
-
// VALUES
|
|
328
|
-
//----
|
|
329
|
-
// ATOMICS
|
|
330
|
-
for (const atomic of x.atomics)
|
|
331
|
-
if (y.atomics.includes(atomic)) return true;
|
|
332
|
-
|
|
333
|
-
// CONSTANTS
|
|
334
|
-
for (const constant of x.constants) {
|
|
335
|
-
const opposite: MetadataConstant | undefined = y.constants.find(
|
|
336
|
-
(elem) => elem.type === constant.type,
|
|
337
|
-
);
|
|
338
|
-
if (opposite === undefined) continue;
|
|
339
|
-
|
|
340
|
-
const values: Set<any> = new Set([
|
|
341
|
-
...constant.values,
|
|
342
|
-
...opposite.values,
|
|
343
|
-
]);
|
|
344
|
-
if (values.size !== constant.values.length + opposite.values.length)
|
|
345
|
-
return true;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
// FUNCTIONAL
|
|
349
|
-
if (x.functional === true && y.functional === true) return true;
|
|
350
|
-
|
|
351
|
-
return false;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
export function covers(x: Metadata, y: Metadata): boolean {
|
|
355
|
-
// CHECK ANY
|
|
356
|
-
if (x.any) return true;
|
|
357
|
-
else if (y.any) return false;
|
|
358
|
-
|
|
359
|
-
//----
|
|
360
|
-
// INSTANCES
|
|
361
|
-
//----
|
|
362
|
-
// ARRAYS
|
|
363
|
-
for (const ya of y.arrays)
|
|
364
|
-
if (x.arrays.some((xa) => covers(xa, ya) === true) === false)
|
|
365
|
-
return false;
|
|
366
|
-
|
|
367
|
-
// OBJECTS
|
|
368
|
-
for (const yo of y.objects)
|
|
369
|
-
if (x.objects.some((xo) => MetadataObject.covers(xo, yo)) === false)
|
|
370
|
-
return false;
|
|
371
|
-
|
|
372
|
-
// TUPLES
|
|
373
|
-
for (const yt of y.tuples)
|
|
374
|
-
if (
|
|
375
|
-
yt.length !== 0 &&
|
|
376
|
-
x.tuples.some(
|
|
377
|
-
(xt) =>
|
|
378
|
-
xt.length >= yt.length &&
|
|
379
|
-
xt
|
|
380
|
-
.slice(yt.length)
|
|
381
|
-
.every((xv, i) => covers(xv, yt[i]!)),
|
|
382
|
-
) === false
|
|
383
|
-
)
|
|
384
|
-
return false;
|
|
385
|
-
|
|
386
|
-
// NATIVES
|
|
387
|
-
|
|
388
|
-
// SETS
|
|
389
|
-
for (const ys of y.sets)
|
|
390
|
-
if (x.sets.some((xs) => covers(xs, ys)) === false) return false;
|
|
391
|
-
|
|
392
|
-
//----
|
|
393
|
-
// VALUES
|
|
394
|
-
//----
|
|
395
|
-
// ATOMICS
|
|
396
|
-
if (y.atomics.some((atomic) => x.atomics.includes(atomic) === false))
|
|
397
|
-
return false;
|
|
398
|
-
|
|
399
|
-
// CONSTANTS
|
|
400
|
-
for (const yc of y.constants) {
|
|
401
|
-
const xc: MetadataConstant | undefined = x.constants.find(
|
|
402
|
-
(elem) => elem.type === yc.type,
|
|
403
|
-
);
|
|
404
|
-
if (xc === undefined) return false;
|
|
405
|
-
else if (
|
|
406
|
-
(yc.values as number[]).some(
|
|
407
|
-
(yv) => xc.values.includes(yv as never) === false,
|
|
408
|
-
)
|
|
409
|
-
)
|
|
410
|
-
return false;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
// FUNCTIONAL
|
|
414
|
-
if (x.functional === false && y.functional) return false;
|
|
415
|
-
|
|
416
|
-
// SUCCESS
|
|
417
|
-
return true;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
export function merge(x: Metadata, y: Metadata): Metadata {
|
|
421
|
-
const output: Metadata = Metadata.create({
|
|
422
|
-
any: x.any || y.any,
|
|
423
|
-
nullable: x.nullable || y.nullable,
|
|
424
|
-
required: x.required && y.required,
|
|
425
|
-
functional: x.functional || y.functional,
|
|
426
|
-
|
|
427
|
-
resolved:
|
|
428
|
-
x.resolved !== null && y.resolved !== null
|
|
429
|
-
? merge(x.resolved, y.resolved)
|
|
430
|
-
: x.resolved || y.resolved,
|
|
431
|
-
atomics: [...new Set([...x.atomics, ...y.atomics])],
|
|
432
|
-
constants: [...x.constants],
|
|
433
|
-
templates: x.templates.slice(),
|
|
434
|
-
|
|
435
|
-
rest:
|
|
436
|
-
x.rest !== null && y.rest !== null
|
|
437
|
-
? merge(x.rest, y.rest)
|
|
438
|
-
: x.rest ?? y.rest,
|
|
439
|
-
arrays: x.arrays.slice(),
|
|
440
|
-
tuples: x.tuples.slice(),
|
|
441
|
-
objects: x.objects.slice(),
|
|
442
|
-
|
|
443
|
-
natives: [...new Set([...x.natives, ...y.natives])],
|
|
444
|
-
sets: x.sets.slice(),
|
|
445
|
-
maps: x.maps.slice(),
|
|
446
|
-
});
|
|
447
|
-
for (const constant of y.constants) {
|
|
448
|
-
const target: MetadataConstant = ArrayUtil.take(
|
|
449
|
-
output.constants,
|
|
450
|
-
(elem) => elem.type === constant.type,
|
|
451
|
-
() => ({
|
|
452
|
-
type: constant.type,
|
|
453
|
-
values: [],
|
|
454
|
-
}),
|
|
455
|
-
);
|
|
456
|
-
for (const value of constant.values)
|
|
457
|
-
ArrayUtil.add(target.values, value);
|
|
458
|
-
}
|
|
459
|
-
for (const array of y.arrays)
|
|
460
|
-
ArrayUtil.set(output.arrays, array, (elem) => elem.getName());
|
|
461
|
-
for (const obj of y.objects)
|
|
462
|
-
ArrayUtil.set(output.objects, obj, (elem) => elem.name);
|
|
463
|
-
|
|
464
|
-
if (x.rest !== null)
|
|
465
|
-
ArrayUtil.set(output.arrays, x.rest, (elem) => elem.getName());
|
|
466
|
-
if (y.rest !== null)
|
|
467
|
-
ArrayUtil.set(output.arrays, y.rest, (elem) => elem.getName());
|
|
468
|
-
|
|
469
|
-
return output;
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
function getName(metadata: Metadata): string {
|
|
474
|
-
if (metadata.any === true) return "any";
|
|
475
|
-
|
|
476
|
-
const elements: string[] = [];
|
|
477
|
-
|
|
478
|
-
// OPTIONAL
|
|
479
|
-
if (metadata.nullable === true) elements.push("null");
|
|
480
|
-
if (metadata.required === false) elements.push("undefined");
|
|
481
|
-
|
|
482
|
-
// ATOMIC
|
|
483
|
-
for (const type of metadata.atomics) {
|
|
484
|
-
elements.push(type);
|
|
485
|
-
}
|
|
486
|
-
for (const constant of metadata.constants)
|
|
487
|
-
for (const value of constant.values)
|
|
488
|
-
elements.push(JSON.stringify(value));
|
|
489
|
-
for (const template of metadata.templates)
|
|
490
|
-
elements.push(
|
|
491
|
-
"`" +
|
|
492
|
-
template
|
|
493
|
-
.map((child) =>
|
|
494
|
-
child.isConstant() && child.size() === 1
|
|
495
|
-
? child.constants[0]!.values[0]!
|
|
496
|
-
: `$\{${child.getName()}\}`,
|
|
497
|
-
)
|
|
498
|
-
.join("")
|
|
499
|
-
.split("`")
|
|
500
|
-
.join("\\`") +
|
|
501
|
-
"`",
|
|
502
|
-
);
|
|
503
|
-
|
|
504
|
-
// NATIVES
|
|
505
|
-
for (const native of metadata.natives) elements.push(native);
|
|
506
|
-
for (const set of metadata.sets) elements.push(`Set<${set.getName()}>`);
|
|
507
|
-
for (const map of metadata.maps)
|
|
508
|
-
elements.push(`Map<${map.key.getName()}, ${map.value.getName()}>`);
|
|
509
|
-
|
|
510
|
-
// ARRAY
|
|
511
|
-
if (metadata.rest !== null) elements.push(`...${metadata.rest.getName()}`);
|
|
512
|
-
for (const tuple of metadata.tuples)
|
|
513
|
-
elements.push(`[${tuple.map((elem) => elem.getName()).join(", ")}]`);
|
|
514
|
-
for (const array of metadata.arrays)
|
|
515
|
-
elements.push(`Array<${array.getName()}>`);
|
|
516
|
-
|
|
517
|
-
// OBJECT
|
|
518
|
-
for (const object of metadata.objects)
|
|
519
|
-
elements.push(`Resolve<${object.name}>`);
|
|
520
|
-
if (metadata.resolved !== null) elements.push(metadata.resolved.getName());
|
|
521
|
-
|
|
522
|
-
// RETURNS
|
|
523
|
-
if (elements.length === 0) return "unknown";
|
|
524
|
-
else if (elements.length === 1) return elements[0]!;
|
|
525
|
-
|
|
526
|
-
elements.sort();
|
|
527
|
-
return `(${elements.join(" | ")})`;
|
|
528
|
-
}
|
|
529
|
-
export namespace Metadata {
|
|
530
|
-
export interface Entry {
|
|
531
|
-
key: Metadata;
|
|
532
|
-
value: Metadata;
|
|
533
|
-
}
|
|
534
|
-
}
|
|
1
|
+
import { Atomic } from "../typings/Atomic";
|
|
2
|
+
import { ClassProperties } from "../typings/ClassProperties";
|
|
3
|
+
|
|
4
|
+
import { ArrayUtil } from "../utils/ArrayUtil";
|
|
5
|
+
|
|
6
|
+
import { IMetadata } from "./IMetadata";
|
|
7
|
+
import { IMetadataObject } from "./IMetadataObject";
|
|
8
|
+
import { MetadataConstant } from "./MetadataConstant";
|
|
9
|
+
import { MetadataObject } from "./MetadataObject";
|
|
10
|
+
import { MetadataProperty } from "./MetadataProperty";
|
|
11
|
+
|
|
12
|
+
export class Metadata {
|
|
13
|
+
public readonly any: boolean;
|
|
14
|
+
public readonly required: boolean;
|
|
15
|
+
public readonly nullable: boolean;
|
|
16
|
+
public readonly functional: boolean;
|
|
17
|
+
|
|
18
|
+
public readonly resolved: Metadata | null;
|
|
19
|
+
public readonly atomics: Atomic.Literal[];
|
|
20
|
+
public readonly constants: MetadataConstant[];
|
|
21
|
+
public readonly templates: Metadata[][];
|
|
22
|
+
|
|
23
|
+
public readonly rest: Metadata | null;
|
|
24
|
+
public readonly arrays: Metadata[];
|
|
25
|
+
public readonly tuples: Metadata[][];
|
|
26
|
+
public readonly objects: MetadataObject[];
|
|
27
|
+
|
|
28
|
+
public readonly natives: string[];
|
|
29
|
+
public readonly sets: Metadata[];
|
|
30
|
+
public readonly maps: Metadata.Entry[];
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
private name_: string | undefined = undefined;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
private parent_resolved_: boolean = false;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
public union_index?: number;
|
|
46
|
+
|
|
47
|
+
/* -----------------------------------------------------------
|
|
48
|
+
CONSTRUCTORS
|
|
49
|
+
----------------------------------------------------------- */
|
|
50
|
+
/**
|
|
51
|
+
* @hidden
|
|
52
|
+
*/
|
|
53
|
+
private constructor(props: ClassProperties<Metadata>) {
|
|
54
|
+
this.any = props.any;
|
|
55
|
+
this.required = props.required;
|
|
56
|
+
this.nullable = props.nullable;
|
|
57
|
+
this.functional = props.functional;
|
|
58
|
+
|
|
59
|
+
this.resolved = props.resolved;
|
|
60
|
+
this.atomics = props.atomics;
|
|
61
|
+
this.constants = props.constants;
|
|
62
|
+
this.templates = props.templates;
|
|
63
|
+
|
|
64
|
+
this.rest = props.rest;
|
|
65
|
+
this.arrays = props.arrays;
|
|
66
|
+
this.tuples = props.tuples;
|
|
67
|
+
this.objects = props.objects;
|
|
68
|
+
|
|
69
|
+
this.natives = props.natives;
|
|
70
|
+
this.sets = props.sets;
|
|
71
|
+
this.maps = props.maps;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
public static create(props: ClassProperties<Metadata>): Metadata {
|
|
78
|
+
return new Metadata(props);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @internal
|
|
83
|
+
*/
|
|
84
|
+
public static initialize(parentResolved: boolean = false): Metadata {
|
|
85
|
+
const meta: Metadata = this.create({
|
|
86
|
+
any: false,
|
|
87
|
+
nullable: false,
|
|
88
|
+
required: true,
|
|
89
|
+
functional: false,
|
|
90
|
+
|
|
91
|
+
resolved: null,
|
|
92
|
+
constants: [],
|
|
93
|
+
atomics: [],
|
|
94
|
+
templates: [],
|
|
95
|
+
arrays: [],
|
|
96
|
+
tuples: [],
|
|
97
|
+
objects: [],
|
|
98
|
+
|
|
99
|
+
rest: null,
|
|
100
|
+
natives: [],
|
|
101
|
+
sets: [],
|
|
102
|
+
maps: [],
|
|
103
|
+
});
|
|
104
|
+
meta.parent_resolved_ = parentResolved;
|
|
105
|
+
return meta;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public toJSON(): IMetadata {
|
|
109
|
+
return {
|
|
110
|
+
any: this.any,
|
|
111
|
+
required: this.required,
|
|
112
|
+
nullable: this.nullable,
|
|
113
|
+
functional: this.functional,
|
|
114
|
+
|
|
115
|
+
atomics: this.atomics.slice(),
|
|
116
|
+
constants: JSON.parse(JSON.stringify(this.constants)),
|
|
117
|
+
templates: this.templates.map((tpl) =>
|
|
118
|
+
tpl.map((meta) => meta.toJSON()),
|
|
119
|
+
),
|
|
120
|
+
resolved: this.resolved ? this.resolved.toJSON() : null,
|
|
121
|
+
|
|
122
|
+
rest: this.rest ? this.rest.toJSON() : null,
|
|
123
|
+
arrays: this.arrays.map((meta) => meta.toJSON()),
|
|
124
|
+
tuples: this.tuples.map((meta) =>
|
|
125
|
+
meta.map((meta) => meta.toJSON()),
|
|
126
|
+
),
|
|
127
|
+
objects: this.objects.map((obj) => obj.name),
|
|
128
|
+
|
|
129
|
+
natives: this.natives.slice(),
|
|
130
|
+
sets: this.sets.map((meta) => meta.toJSON()),
|
|
131
|
+
maps: this.maps.map((entry) => ({
|
|
132
|
+
key: entry.key.toJSON(),
|
|
133
|
+
value: entry.value.toJSON(),
|
|
134
|
+
})),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
public static from(meta: IMetadata, objects: IMetadataObject[]): Metadata {
|
|
139
|
+
const dict: Map<string, MetadataObject> = new Map();
|
|
140
|
+
for (const obj of objects)
|
|
141
|
+
dict.set(obj.name, MetadataObject._From_without_properties(obj));
|
|
142
|
+
|
|
143
|
+
for (const obj of objects) {
|
|
144
|
+
const initialized = dict.get(obj.name)!;
|
|
145
|
+
initialized.properties.push(
|
|
146
|
+
...obj.properties.map((prop) =>
|
|
147
|
+
MetadataProperty._From(prop, dict),
|
|
148
|
+
),
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
return this._From(meta, dict);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* @internal
|
|
156
|
+
*/
|
|
157
|
+
public static _From(
|
|
158
|
+
meta: IMetadata,
|
|
159
|
+
objects: Map<string, MetadataObject>,
|
|
160
|
+
): Metadata {
|
|
161
|
+
return this.create({
|
|
162
|
+
any: meta.any,
|
|
163
|
+
required: meta.required,
|
|
164
|
+
nullable: meta.nullable,
|
|
165
|
+
functional: meta.functional,
|
|
166
|
+
|
|
167
|
+
constants: JSON.parse(JSON.stringify(meta.constants)),
|
|
168
|
+
atomics: meta.atomics.slice(),
|
|
169
|
+
templates: meta.templates.map((tpl) =>
|
|
170
|
+
tpl.map((meta) => this._From(meta, objects)),
|
|
171
|
+
),
|
|
172
|
+
resolved: meta.resolved ? this._From(meta.resolved, objects) : null,
|
|
173
|
+
|
|
174
|
+
rest: meta.rest ? this._From(meta.rest, objects) : null,
|
|
175
|
+
arrays: meta.arrays.map((meta) => this._From(meta, objects)),
|
|
176
|
+
tuples: meta.tuples.map((tuple) =>
|
|
177
|
+
tuple.map((meta) => this._From(meta, objects)),
|
|
178
|
+
),
|
|
179
|
+
objects: meta.objects.map((name) => {
|
|
180
|
+
const found = objects.get(name);
|
|
181
|
+
if (found === undefined)
|
|
182
|
+
throw new Error(
|
|
183
|
+
`Error on Metadata.from(): failed to find object "${name}".`,
|
|
184
|
+
);
|
|
185
|
+
return found;
|
|
186
|
+
}),
|
|
187
|
+
|
|
188
|
+
natives: meta.natives.slice(),
|
|
189
|
+
sets: meta.sets.map((meta) => this._From(meta, objects)),
|
|
190
|
+
maps: meta.maps.map((entry) => ({
|
|
191
|
+
key: this._From(entry.key, objects),
|
|
192
|
+
value: this._From(entry.value, objects),
|
|
193
|
+
})),
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/* -----------------------------------------------------------
|
|
198
|
+
ACCESSORS
|
|
199
|
+
----------------------------------------------------------- */
|
|
200
|
+
public getName(): string {
|
|
201
|
+
this.name_ ||= getName(this);
|
|
202
|
+
return this.name_;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
public empty(): boolean {
|
|
206
|
+
return this.bucket() === 0 || this.size() === 0;
|
|
207
|
+
}
|
|
208
|
+
public size(): number {
|
|
209
|
+
return (
|
|
210
|
+
(this.resolved ? 1 : 0) +
|
|
211
|
+
(this.functional ? 1 : 0) +
|
|
212
|
+
this.templates.length +
|
|
213
|
+
this.atomics.length +
|
|
214
|
+
this.constants
|
|
215
|
+
.map((c) => c.values.length)
|
|
216
|
+
.reduce((x, y) => x + y, 0) +
|
|
217
|
+
(this.rest ? this.rest.size() : 0) +
|
|
218
|
+
this.arrays.length +
|
|
219
|
+
this.tuples.length +
|
|
220
|
+
this.objects.length +
|
|
221
|
+
this.natives.length +
|
|
222
|
+
this.sets.length +
|
|
223
|
+
this.maps.length
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
public bucket(): number {
|
|
227
|
+
return (
|
|
228
|
+
(this.resolved ? 1 : 0) +
|
|
229
|
+
(this.functional ? 1 : 0) +
|
|
230
|
+
(this.templates.length ? 1 : 0) +
|
|
231
|
+
(this.atomics.length ? 1 : 0) +
|
|
232
|
+
(this.constants.length ? 1 : 0) +
|
|
233
|
+
(this.rest ? this.rest.size() : 0) +
|
|
234
|
+
(this.arrays.length ? 1 : 0) +
|
|
235
|
+
(this.tuples.length ? 1 : 0) +
|
|
236
|
+
(this.objects.length ? 1 : 0) +
|
|
237
|
+
(this.natives.length ? 1 : 0) +
|
|
238
|
+
(this.sets.length ? 1 : 0) +
|
|
239
|
+
(this.maps.length ? 1 : 0)
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
public isConstant(): boolean {
|
|
243
|
+
return this.bucket() === (this.constants.length ? 1 : 0);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* @internal
|
|
248
|
+
*/
|
|
249
|
+
public isUnionBucket(): boolean {
|
|
250
|
+
const size: number = this.bucket();
|
|
251
|
+
const emended: number = this.constants.length ? size - 1 : size;
|
|
252
|
+
return emended > 1;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* @internal
|
|
257
|
+
*/
|
|
258
|
+
public getSoleLiteral(): string | null {
|
|
259
|
+
if (
|
|
260
|
+
this.size() === 1 &&
|
|
261
|
+
this.constants.length === 1 &&
|
|
262
|
+
this.constants[0]!.type === "string" &&
|
|
263
|
+
this.constants[0]!.values.length === 1
|
|
264
|
+
)
|
|
265
|
+
return this.constants[0]!.values[0] as string;
|
|
266
|
+
else return null;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* @internal
|
|
271
|
+
*/
|
|
272
|
+
public isSoleLiteral(): boolean {
|
|
273
|
+
return this.getSoleLiteral() !== null;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* @internal
|
|
278
|
+
*/
|
|
279
|
+
public isParentResolved(): boolean {
|
|
280
|
+
return this.parent_resolved_;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
export namespace Metadata {
|
|
284
|
+
export function intersects(
|
|
285
|
+
x: Metadata,
|
|
286
|
+
y: Metadata,
|
|
287
|
+
deep: boolean,
|
|
288
|
+
): boolean {
|
|
289
|
+
// CHECK ANY & OPTIONAL
|
|
290
|
+
if (x.any || y.any) return true;
|
|
291
|
+
if (x.required === false && false === y.required) return true;
|
|
292
|
+
if (x.nullable === true && true === y.nullable) return true;
|
|
293
|
+
|
|
294
|
+
//----
|
|
295
|
+
// INSTANCES
|
|
296
|
+
//----
|
|
297
|
+
// ARRAYS AND OBJECTS
|
|
298
|
+
if (deep === true) {
|
|
299
|
+
for (const xa of x.arrays)
|
|
300
|
+
for (const ya of y.arrays)
|
|
301
|
+
if (intersects(xa, ya, deep)) {
|
|
302
|
+
return true;
|
|
303
|
+
}
|
|
304
|
+
for (const xo of x.objects)
|
|
305
|
+
for (const yo of y.objects)
|
|
306
|
+
if (MetadataObject.intersects(xo, yo)) {
|
|
307
|
+
return true;
|
|
308
|
+
}
|
|
309
|
+
} else {
|
|
310
|
+
if (x.arrays.length && y.arrays.length) return true;
|
|
311
|
+
if (x.objects.length && y.objects.length) return true;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// TUPLES
|
|
315
|
+
for (const xt of x.tuples)
|
|
316
|
+
for (const yt of y.tuples)
|
|
317
|
+
if (xt.length === 0 || yt.length === 0)
|
|
318
|
+
return xt.length === 0 && yt.length === 0;
|
|
319
|
+
else if (
|
|
320
|
+
xt
|
|
321
|
+
.slice(0, Math.min(xt.length, yt.length))
|
|
322
|
+
.some((xv, i) => intersects(xv, yt[i]!, deep))
|
|
323
|
+
)
|
|
324
|
+
return true;
|
|
325
|
+
|
|
326
|
+
//----
|
|
327
|
+
// VALUES
|
|
328
|
+
//----
|
|
329
|
+
// ATOMICS
|
|
330
|
+
for (const atomic of x.atomics)
|
|
331
|
+
if (y.atomics.includes(atomic)) return true;
|
|
332
|
+
|
|
333
|
+
// CONSTANTS
|
|
334
|
+
for (const constant of x.constants) {
|
|
335
|
+
const opposite: MetadataConstant | undefined = y.constants.find(
|
|
336
|
+
(elem) => elem.type === constant.type,
|
|
337
|
+
);
|
|
338
|
+
if (opposite === undefined) continue;
|
|
339
|
+
|
|
340
|
+
const values: Set<any> = new Set([
|
|
341
|
+
...constant.values,
|
|
342
|
+
...opposite.values,
|
|
343
|
+
]);
|
|
344
|
+
if (values.size !== constant.values.length + opposite.values.length)
|
|
345
|
+
return true;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// FUNCTIONAL
|
|
349
|
+
if (x.functional === true && y.functional === true) return true;
|
|
350
|
+
|
|
351
|
+
return false;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
export function covers(x: Metadata, y: Metadata): boolean {
|
|
355
|
+
// CHECK ANY
|
|
356
|
+
if (x.any) return true;
|
|
357
|
+
else if (y.any) return false;
|
|
358
|
+
|
|
359
|
+
//----
|
|
360
|
+
// INSTANCES
|
|
361
|
+
//----
|
|
362
|
+
// ARRAYS
|
|
363
|
+
for (const ya of y.arrays)
|
|
364
|
+
if (x.arrays.some((xa) => covers(xa, ya) === true) === false)
|
|
365
|
+
return false;
|
|
366
|
+
|
|
367
|
+
// OBJECTS
|
|
368
|
+
for (const yo of y.objects)
|
|
369
|
+
if (x.objects.some((xo) => MetadataObject.covers(xo, yo)) === false)
|
|
370
|
+
return false;
|
|
371
|
+
|
|
372
|
+
// TUPLES
|
|
373
|
+
for (const yt of y.tuples)
|
|
374
|
+
if (
|
|
375
|
+
yt.length !== 0 &&
|
|
376
|
+
x.tuples.some(
|
|
377
|
+
(xt) =>
|
|
378
|
+
xt.length >= yt.length &&
|
|
379
|
+
xt
|
|
380
|
+
.slice(yt.length)
|
|
381
|
+
.every((xv, i) => covers(xv, yt[i]!)),
|
|
382
|
+
) === false
|
|
383
|
+
)
|
|
384
|
+
return false;
|
|
385
|
+
|
|
386
|
+
// NATIVES
|
|
387
|
+
|
|
388
|
+
// SETS
|
|
389
|
+
for (const ys of y.sets)
|
|
390
|
+
if (x.sets.some((xs) => covers(xs, ys)) === false) return false;
|
|
391
|
+
|
|
392
|
+
//----
|
|
393
|
+
// VALUES
|
|
394
|
+
//----
|
|
395
|
+
// ATOMICS
|
|
396
|
+
if (y.atomics.some((atomic) => x.atomics.includes(atomic) === false))
|
|
397
|
+
return false;
|
|
398
|
+
|
|
399
|
+
// CONSTANTS
|
|
400
|
+
for (const yc of y.constants) {
|
|
401
|
+
const xc: MetadataConstant | undefined = x.constants.find(
|
|
402
|
+
(elem) => elem.type === yc.type,
|
|
403
|
+
);
|
|
404
|
+
if (xc === undefined) return false;
|
|
405
|
+
else if (
|
|
406
|
+
(yc.values as number[]).some(
|
|
407
|
+
(yv) => xc.values.includes(yv as never) === false,
|
|
408
|
+
)
|
|
409
|
+
)
|
|
410
|
+
return false;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// FUNCTIONAL
|
|
414
|
+
if (x.functional === false && y.functional) return false;
|
|
415
|
+
|
|
416
|
+
// SUCCESS
|
|
417
|
+
return true;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
export function merge(x: Metadata, y: Metadata): Metadata {
|
|
421
|
+
const output: Metadata = Metadata.create({
|
|
422
|
+
any: x.any || y.any,
|
|
423
|
+
nullable: x.nullable || y.nullable,
|
|
424
|
+
required: x.required && y.required,
|
|
425
|
+
functional: x.functional || y.functional,
|
|
426
|
+
|
|
427
|
+
resolved:
|
|
428
|
+
x.resolved !== null && y.resolved !== null
|
|
429
|
+
? merge(x.resolved, y.resolved)
|
|
430
|
+
: x.resolved || y.resolved,
|
|
431
|
+
atomics: [...new Set([...x.atomics, ...y.atomics])],
|
|
432
|
+
constants: [...x.constants],
|
|
433
|
+
templates: x.templates.slice(),
|
|
434
|
+
|
|
435
|
+
rest:
|
|
436
|
+
x.rest !== null && y.rest !== null
|
|
437
|
+
? merge(x.rest, y.rest)
|
|
438
|
+
: x.rest ?? y.rest,
|
|
439
|
+
arrays: x.arrays.slice(),
|
|
440
|
+
tuples: x.tuples.slice(),
|
|
441
|
+
objects: x.objects.slice(),
|
|
442
|
+
|
|
443
|
+
natives: [...new Set([...x.natives, ...y.natives])],
|
|
444
|
+
sets: x.sets.slice(),
|
|
445
|
+
maps: x.maps.slice(),
|
|
446
|
+
});
|
|
447
|
+
for (const constant of y.constants) {
|
|
448
|
+
const target: MetadataConstant = ArrayUtil.take(
|
|
449
|
+
output.constants,
|
|
450
|
+
(elem) => elem.type === constant.type,
|
|
451
|
+
() => ({
|
|
452
|
+
type: constant.type,
|
|
453
|
+
values: [],
|
|
454
|
+
}),
|
|
455
|
+
);
|
|
456
|
+
for (const value of constant.values)
|
|
457
|
+
ArrayUtil.add(target.values, value);
|
|
458
|
+
}
|
|
459
|
+
for (const array of y.arrays)
|
|
460
|
+
ArrayUtil.set(output.arrays, array, (elem) => elem.getName());
|
|
461
|
+
for (const obj of y.objects)
|
|
462
|
+
ArrayUtil.set(output.objects, obj, (elem) => elem.name);
|
|
463
|
+
|
|
464
|
+
if (x.rest !== null)
|
|
465
|
+
ArrayUtil.set(output.arrays, x.rest, (elem) => elem.getName());
|
|
466
|
+
if (y.rest !== null)
|
|
467
|
+
ArrayUtil.set(output.arrays, y.rest, (elem) => elem.getName());
|
|
468
|
+
|
|
469
|
+
return output;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
function getName(metadata: Metadata): string {
|
|
474
|
+
if (metadata.any === true) return "any";
|
|
475
|
+
|
|
476
|
+
const elements: string[] = [];
|
|
477
|
+
|
|
478
|
+
// OPTIONAL
|
|
479
|
+
if (metadata.nullable === true) elements.push("null");
|
|
480
|
+
if (metadata.required === false) elements.push("undefined");
|
|
481
|
+
|
|
482
|
+
// ATOMIC
|
|
483
|
+
for (const type of metadata.atomics) {
|
|
484
|
+
elements.push(type);
|
|
485
|
+
}
|
|
486
|
+
for (const constant of metadata.constants)
|
|
487
|
+
for (const value of constant.values)
|
|
488
|
+
elements.push(JSON.stringify(value));
|
|
489
|
+
for (const template of metadata.templates)
|
|
490
|
+
elements.push(
|
|
491
|
+
"`" +
|
|
492
|
+
template
|
|
493
|
+
.map((child) =>
|
|
494
|
+
child.isConstant() && child.size() === 1
|
|
495
|
+
? child.constants[0]!.values[0]!
|
|
496
|
+
: `$\{${child.getName()}\}`,
|
|
497
|
+
)
|
|
498
|
+
.join("")
|
|
499
|
+
.split("`")
|
|
500
|
+
.join("\\`") +
|
|
501
|
+
"`",
|
|
502
|
+
);
|
|
503
|
+
|
|
504
|
+
// NATIVES
|
|
505
|
+
for (const native of metadata.natives) elements.push(native);
|
|
506
|
+
for (const set of metadata.sets) elements.push(`Set<${set.getName()}>`);
|
|
507
|
+
for (const map of metadata.maps)
|
|
508
|
+
elements.push(`Map<${map.key.getName()}, ${map.value.getName()}>`);
|
|
509
|
+
|
|
510
|
+
// ARRAY
|
|
511
|
+
if (metadata.rest !== null) elements.push(`...${metadata.rest.getName()}`);
|
|
512
|
+
for (const tuple of metadata.tuples)
|
|
513
|
+
elements.push(`[${tuple.map((elem) => elem.getName()).join(", ")}]`);
|
|
514
|
+
for (const array of metadata.arrays)
|
|
515
|
+
elements.push(`Array<${array.getName()}>`);
|
|
516
|
+
|
|
517
|
+
// OBJECT
|
|
518
|
+
for (const object of metadata.objects)
|
|
519
|
+
elements.push(`Resolve<${object.name}>`);
|
|
520
|
+
if (metadata.resolved !== null) elements.push(metadata.resolved.getName());
|
|
521
|
+
|
|
522
|
+
// RETURNS
|
|
523
|
+
if (elements.length === 0) return "unknown";
|
|
524
|
+
else if (elements.length === 1) return elements[0]!;
|
|
525
|
+
|
|
526
|
+
elements.sort();
|
|
527
|
+
return `(${elements.join(" | ")})`;
|
|
528
|
+
}
|
|
529
|
+
export namespace Metadata {
|
|
530
|
+
export interface Entry {
|
|
531
|
+
key: Metadata;
|
|
532
|
+
value: Metadata;
|
|
533
|
+
}
|
|
534
|
+
}
|