typia 4.1.2-dev.20230630 → 4.1.3-dev.20230704

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