typia 7.0.0-dev.20241011 → 7.0.0-dev.20241011-2

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 (115) hide show
  1. package/lib/factories/ProtobufFactory.js +0 -10
  2. package/lib/factories/ProtobufFactory.js.map +1 -1
  3. package/lib/internal/$ProtobufSizer.js +1 -8
  4. package/lib/internal/$ProtobufSizer.js.map +1 -1
  5. package/lib/json.d.ts +1 -1
  6. package/lib/module.d.ts +1 -1
  7. package/lib/module.js +1 -1
  8. package/lib/module.js.map +1 -1
  9. package/lib/programmers/internal/llm_schema_object.js +1 -1
  10. package/lib/programmers/internal/llm_schema_object.js.map +1 -1
  11. package/lib/programmers/json/JsonSchemasProgrammer.d.ts +1 -1
  12. package/lib/schemas/json/{IJsonSchemaList.js → IJsonSchemaCollection.js} +1 -1
  13. package/lib/schemas/json/IJsonSchemaCollection.js.map +1 -0
  14. package/package.json +2 -2
  15. package/src/executable/TypiaGenerateWizard.ts +83 -83
  16. package/src/executable/TypiaSetupWizard.ts +174 -174
  17. package/src/executable/setup/ArgumentParser.ts +42 -42
  18. package/src/executable/setup/FileRetriever.ts +19 -19
  19. package/src/executable/setup/PackageManager.ts +87 -87
  20. package/src/factories/IdentifierFactory.ts +89 -89
  21. package/src/factories/MetadataCollection.ts +278 -278
  22. package/src/factories/MetadataTypeTagFactory.ts +385 -385
  23. package/src/factories/MetadataTypeTagSchemaFactory.ts +82 -82
  24. package/src/factories/NumericRangeFactory.ts +72 -72
  25. package/src/factories/ProtobufFactory.ts +0 -14
  26. package/src/factories/StatementFactory.ts +90 -90
  27. package/src/factories/TemplateFactory.ts +64 -64
  28. package/src/factories/TypeFactory.ts +140 -140
  29. package/src/factories/internal/metadata/emplace_metadata_alias.ts +32 -32
  30. package/src/factories/internal/metadata/emplace_metadata_array_type.ts +39 -39
  31. package/src/factories/internal/metadata/emplace_metadata_tuple.ts +56 -56
  32. package/src/factories/internal/metadata/explore_metadata.ts +30 -30
  33. package/src/factories/internal/metadata/iterate_metadata.ts +54 -54
  34. package/src/factories/internal/metadata/iterate_metadata_alias.ts +28 -28
  35. package/src/factories/internal/metadata/iterate_metadata_array.ts +63 -63
  36. package/src/factories/internal/metadata/iterate_metadata_atomic.ts +62 -62
  37. package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +28 -28
  38. package/src/factories/internal/metadata/iterate_metadata_constant.ts +76 -76
  39. package/src/factories/internal/metadata/iterate_metadata_escape.ts +49 -49
  40. package/src/factories/internal/metadata/iterate_metadata_intersection.ts +216 -216
  41. package/src/factories/internal/metadata/iterate_metadata_map.ts +52 -52
  42. package/src/factories/internal/metadata/iterate_metadata_native.ts +236 -236
  43. package/src/factories/internal/metadata/iterate_metadata_object.ts +27 -27
  44. package/src/factories/internal/metadata/iterate_metadata_set.ts +39 -39
  45. package/src/factories/internal/metadata/iterate_metadata_sort.ts +83 -83
  46. package/src/factories/internal/metadata/iterate_metadata_template.ts +42 -42
  47. package/src/factories/internal/metadata/iterate_metadata_tuple.ts +26 -26
  48. package/src/factories/internal/metadata/iterate_metadata_union.ts +19 -19
  49. package/src/internal/$ProtobufSizer.ts +1 -7
  50. package/src/json.ts +1 -1
  51. package/src/module.ts +1 -1
  52. package/src/programmers/functional/FunctionalIsFunctionProgrammer.ts +72 -72
  53. package/src/programmers/functional/FunctionalIsParametersProgrammer.ts +113 -113
  54. package/src/programmers/functional/FunctionalIsReturnProgrammer.ts +116 -116
  55. package/src/programmers/functional/internal/FunctionalGeneralProgrammer.ts +34 -34
  56. package/src/programmers/helpers/AtomicPredicator.ts +35 -35
  57. package/src/programmers/helpers/CloneJoiner.ts +143 -143
  58. package/src/programmers/helpers/HttpMetadataUtil.ts +21 -21
  59. package/src/programmers/helpers/NotationJoiner.ts +144 -144
  60. package/src/programmers/helpers/ProtobufUtil.ts +125 -125
  61. package/src/programmers/helpers/PruneJoiner.ts +148 -148
  62. package/src/programmers/helpers/StringifyPredicator.ts +13 -13
  63. package/src/programmers/helpers/UnionExplorer.ts +372 -372
  64. package/src/programmers/helpers/UnionPredicator.ts +77 -77
  65. package/src/programmers/internal/application_array.ts +56 -56
  66. package/src/programmers/internal/application_bigint.ts +25 -25
  67. package/src/programmers/internal/application_boolean.ts +25 -25
  68. package/src/programmers/internal/application_escaped.ts +96 -96
  69. package/src/programmers/internal/application_number.ts +25 -25
  70. package/src/programmers/internal/application_plugin.ts +19 -19
  71. package/src/programmers/internal/application_string.ts +25 -25
  72. package/src/programmers/internal/application_templates.ts +64 -64
  73. package/src/programmers/internal/application_union_discriminator.ts +35 -35
  74. package/src/programmers/internal/application_v30_alias.ts +59 -59
  75. package/src/programmers/internal/application_v30_native.ts +29 -29
  76. package/src/programmers/internal/application_v30_object.ts +165 -165
  77. package/src/programmers/internal/application_v30_schema.ts +220 -220
  78. package/src/programmers/internal/application_v30_tuple.ts +33 -33
  79. package/src/programmers/internal/application_v31_alias.ts +47 -47
  80. package/src/programmers/internal/application_v31_constant.ts +29 -29
  81. package/src/programmers/internal/application_v31_native.ts +25 -25
  82. package/src/programmers/internal/application_v31_object.ts +147 -147
  83. package/src/programmers/internal/application_v31_schema.ts +215 -215
  84. package/src/programmers/internal/application_v31_tuple.ts +22 -22
  85. package/src/programmers/internal/check_array_length.ts +46 -46
  86. package/src/programmers/internal/check_bigint.ts +49 -49
  87. package/src/programmers/internal/check_everything.ts +23 -23
  88. package/src/programmers/internal/check_native.ts +27 -27
  89. package/src/programmers/internal/check_number.ts +111 -111
  90. package/src/programmers/internal/check_string.ts +49 -49
  91. package/src/programmers/internal/check_template.ts +48 -48
  92. package/src/programmers/internal/check_union_array_like.ts +334 -334
  93. package/src/programmers/internal/decode_union_object.ts +116 -116
  94. package/src/programmers/internal/llm_schema_array.ts +22 -22
  95. package/src/programmers/internal/llm_schema_escaped.ts +84 -84
  96. package/src/programmers/internal/llm_schema_object.ts +132 -132
  97. package/src/programmers/internal/llm_schema_station.ts +190 -190
  98. package/src/programmers/internal/metadata_to_pattern.ts +42 -42
  99. package/src/programmers/internal/postfix_of_tuple.ts +5 -5
  100. package/src/programmers/internal/stringify_dynamic_properties.ts +162 -162
  101. package/src/programmers/internal/stringify_regular_properties.ts +81 -81
  102. package/src/programmers/internal/template_to_pattern.ts +23 -23
  103. package/src/programmers/internal/wrap_metadata_rest_tuple.ts +23 -23
  104. package/src/programmers/json/JsonSchemasProgrammer.ts +1 -1
  105. package/src/programmers/protobuf/ProtobufMessageProgrammer.ts +201 -201
  106. package/src/schemas/json/{IJsonSchemaList.ts → IJsonSchemaCollection.ts} +22 -22
  107. package/src/schemas/metadata/IMetadataDictionary.ts +11 -11
  108. package/src/schemas/metadata/Metadata.ts +616 -616
  109. package/src/schemas/metadata/MetadataComponents.ts +98 -98
  110. package/src/schemas/metadata/MetadataObject.ts +139 -139
  111. package/src/transformers/features/json/JsonSchemasTransformer.ts +1 -1
  112. package/src/utils/MapUtil.ts +14 -14
  113. package/src/utils/NameEncoder.ts +32 -32
  114. package/lib/schemas/json/IJsonSchemaList.js.map +0 -1
  115. /package/lib/schemas/json/{IJsonSchemaList.d.ts → IJsonSchemaCollection.d.ts} +0 -0
@@ -1,385 +1,385 @@
1
- import { IMetadataTypeTag } from "../schemas/metadata/IMetadataTypeTag";
2
- import { Metadata } from "../schemas/metadata/Metadata";
3
- import { MetadataObject } from "../schemas/metadata/MetadataObject";
4
- import { MetadataProperty } from "../schemas/metadata/MetadataProperty";
5
-
6
- import { MetadataFactory } from "./MetadataFactory";
7
- import { MetadataTypeTagSchemaFactory } from "./MetadataTypeTagSchemaFactory";
8
-
9
- export namespace MetadataTypeTagFactory {
10
- export const analyze = (props: {
11
- errors: MetadataFactory.IError[];
12
- type: "boolean" | "bigint" | "number" | "string" | "array";
13
- objects: MetadataObject[];
14
- explore: MetadataFactory.IExplore;
15
- }): IMetadataTypeTag[] => {
16
- const messages: string[] = [];
17
- const report = (next: {
18
- property: string | null;
19
- message: string;
20
- }): false => {
21
- messages.push(
22
- `the property ${
23
- next.property === null
24
- ? `["typia.tag"]`
25
- : `["typia.tag.${next.property}"]`
26
- } ${next.message}.`,
27
- );
28
- return false;
29
- };
30
-
31
- //----
32
- // VALIDATION PROCESS
33
- //----
34
- const filtered: MetadataObject[] = props.objects.filter((obj) => {
35
- // ONLY ONE PROPERTY
36
- if (obj.properties.length !== 1) return false;
37
-
38
- // THE TAG.TYPE PROPERTY MUST BE
39
- const top: MetadataProperty = obj.properties[0]!;
40
- if (
41
- top.key.getSoleLiteral() !== "typia.tag" ||
42
- top.value.size() !== 1 ||
43
- top.value.objects.length !== 1
44
- )
45
- return false;
46
- else if (top.value.optional === false)
47
- return report({
48
- property: null,
49
- message: "must be optional object",
50
- });
51
-
52
- // CHECK LIST OF PROPERTIES
53
- const tag: MetadataObject = top.value.objects[0]!;
54
- const statics: string[] = tag.properties
55
- .map((p) => p.key.getSoleLiteral()!)
56
- .filter((str) => str !== null);
57
- if (ESSENTIAL_FIELDS.some((f) => !statics.includes(f)))
58
- return report({
59
- property: null,
60
- message: `must have at least three properties - ${ESSENTIAL_FIELDS.map(
61
- (str) => `'${str}'`,
62
- ).join(", ")}`,
63
- });
64
-
65
- const each: boolean[] = tag.properties.map((p) => {
66
- const key: string | null = p.key.getSoleLiteral();
67
- if (key === null) return true;
68
- else if (FIELDS.includes(key) === false) return true;
69
- return validate_property({
70
- report,
71
- key,
72
- value: p.value,
73
- });
74
- });
75
- return each.every((v) => v === true);
76
- });
77
- if (filtered.length === 0) return [];
78
-
79
- //----
80
- // CONSTRUCT TYPE TAGS
81
- //----
82
- // CREATE 1ST
83
- const tagList: Array<ITypeTag | null> = filtered.map((object) =>
84
- create_metadata_type_tag({
85
- report,
86
- object,
87
- }),
88
- );
89
-
90
- const output: IMetadataTypeTag[] = [];
91
- for (const tag of tagList)
92
- if (tag !== null)
93
- output.push({
94
- target: tag.target.some((str) => str === props.type)
95
- ? props.type
96
- : null!,
97
- name: tag.name,
98
- kind: tag.kind,
99
- value: tag.value,
100
- validate: tag.validate[props.type]!,
101
- exclusive: tag.exclusive,
102
- schema: tag.schema,
103
- });
104
- validate({
105
- report,
106
- type: props.type,
107
- tags: output,
108
- });
109
-
110
- if (messages.length > 0) {
111
- props.errors.push({
112
- name: [props.type, ...props.objects.map((o) => o.name)].join(" & "),
113
- explore: props.explore,
114
- messages,
115
- });
116
- return [];
117
- }
118
- return output;
119
- };
120
-
121
- export const validate = (props: {
122
- report: (next: { property: string | null; message: string }) => false;
123
- type: "boolean" | "bigint" | "number" | "string" | "array";
124
- tags: IMetadataTypeTag[];
125
- }): boolean => {
126
- let success: boolean = true;
127
- for (const tag of props.tags)
128
- if (tag.target !== props.type) {
129
- success &&= props.report({
130
- property: null,
131
- message: `target must constains ${props.type} type`,
132
- });
133
- }
134
-
135
- props.tags.forEach((tag, i) => {
136
- if (tag.exclusive === false) return;
137
- else if (tag.exclusive === true) {
138
- const some: boolean = props.tags.some(
139
- (opposite, j) => i !== j && opposite.kind === tag.kind,
140
- );
141
- if (some === true)
142
- success &&= props.report({
143
- property: null,
144
- message: `kind '${tag.kind}' can't be duplicated`,
145
- });
146
- } else if (Array.isArray(tag.exclusive)) {
147
- const some: IMetadataTypeTag | undefined = props.tags.find(
148
- (opposite, j) =>
149
- i !== j &&
150
- opposite.kind === tag.kind &&
151
- (tag.exclusive as string[]).includes(opposite.name),
152
- );
153
- if (some !== undefined)
154
- success ??= props.report({
155
- property: null,
156
- message: `kind '${tag.kind}' can't be used with '${some.name}'`,
157
- });
158
- }
159
- });
160
- return success;
161
- };
162
-
163
- const validate_property = (props: {
164
- report: (next: { property: string | null; message: string }) => false;
165
- key: string;
166
- value: Metadata;
167
- }): boolean => {
168
- if (
169
- // TARGET
170
- props.key === "target" &&
171
- (props.value.constants.length !== 1 ||
172
- props.value.constants[0]!.values.length !== props.value.size() ||
173
- props.value.constants[0]!.values.some(
174
- (v) =>
175
- v.value !== "boolean" &&
176
- v.value !== "bigint" &&
177
- v.value !== "number" &&
178
- v.value !== "string" &&
179
- v.value !== "array",
180
- ))
181
- )
182
- return props.report({
183
- property: props.key,
184
- message: `must be one of 'boolean', 'bigint', 'number', 'string', 'array'`,
185
- });
186
- else if (
187
- // KIND
188
- props.key === "kind" &&
189
- (props.value.size() !== 1 ||
190
- props.value.constants.length !== 1 ||
191
- props.value.constants[0]!.type !== "string" ||
192
- props.value.constants[0]!.values.length !== 1)
193
- )
194
- return props.report({
195
- property: props.key,
196
- message: "must be a string literal type",
197
- });
198
- else if (
199
- // VALUE
200
- props.key === "value" &&
201
- (props.value.size() > 1 ||
202
- (props.value.size() !== 0 &&
203
- (props.value.constants.length !== 1 ||
204
- props.value.constants[0]!.values.length !== 1)))
205
- )
206
- return props.report({
207
- property: props.key,
208
- message: "must be a constant literal type or undefined value",
209
- });
210
- else if (props.key === "exclusive") return get_exclusive(props) !== null;
211
- else if (props.key === "validate") {
212
- //----
213
- // VALIDATE
214
- //----
215
- // UNDEFINED CASE
216
- if (
217
- props.value.size() === 0 &&
218
- props.value.isRequired() === false &&
219
- props.value.nullable === false
220
- )
221
- return true;
222
-
223
- // STRING CASE
224
- if (
225
- props.value.size() === 1 &&
226
- props.value.constants.length === 1 &&
227
- props.value.constants[0]!.type === "string" &&
228
- (props.value.constants[0]!.values.length === 1) === true
229
- )
230
- return true;
231
-
232
- // RECORD<TARGET, STRING>
233
- const target: string[] | undefined = props.value.objects[0]?.properties
234
- .map((p) => p.key.getSoleLiteral()!)
235
- .filter((str) => str !== null) as string[] | undefined;
236
- if (target === undefined)
237
- return props.report({
238
- property: "target",
239
- message: `must be one of 'boolean', 'bigint', 'number', 'string', 'array'`,
240
- });
241
- const variadic: boolean =
242
- props.value.size() === 1 &&
243
- props.value.objects.length === 1 &&
244
- props.value.objects[0]!.properties.every(
245
- (vp) =>
246
- vp.value.size() === 1 &&
247
- vp.value.isRequired() &&
248
- vp.value.nullable === false &&
249
- vp.value.constants.length === 1 &&
250
- vp.value.constants[0]!.type === "string" &&
251
- vp.value.constants[0]!.values.length === 1 &&
252
- target.includes(vp.key.getSoleLiteral()!),
253
- );
254
- if (variadic === false)
255
- return props.report({
256
- property: props.key,
257
- message: `must be a string literal type or Record<Target, string> type.`,
258
- });
259
- }
260
- return true;
261
- };
262
-
263
- const create_metadata_type_tag = (props: {
264
- report: (next: { property: string | null; message: string }) => false;
265
- object: MetadataObject;
266
- }): ITypeTag | null => {
267
- const find = (key: string): MetadataProperty | undefined =>
268
- props.object.properties[0]?.value.objects[0]?.properties.find(
269
- (p) => p.key.getSoleLiteral() === key,
270
- );
271
-
272
- const target = find("target")!.value.constants[0]!.values.map(
273
- (v) => v.value,
274
- ) as ITypeTag["target"];
275
- const kind: string = find("kind")!.value.constants[0]!.values[0]!
276
- .value as string;
277
- const value: boolean | bigint | number | string | undefined =
278
- find("value")?.value.constants[0]?.values[0]!.value;
279
- const exclusive: string[] | boolean | null = get_exclusive({
280
- report: props.report,
281
- key: "exclusive",
282
- value: find("exclusive")?.value,
283
- });
284
- if (exclusive === null) return null;
285
-
286
- const validate: Record<string, string> = (() => {
287
- const validate = find("validate")?.value;
288
- if (!validate || validate.size() === 0) return {};
289
- else if (validate.constants.length)
290
- return Object.fromEntries(
291
- target.map((t) => [
292
- t,
293
- validate.constants[0]!.values[0]!.value as string,
294
- ]),
295
- );
296
- return Object.fromEntries(
297
- validate.objects[0]!.properties.map((p) => [
298
- p.key.getSoleLiteral()!,
299
- p.value.constants[0]!.values[0]!.value as string,
300
- ]),
301
- );
302
- })();
303
- const schema: object | undefined = (() => {
304
- const p: Metadata | undefined = find("schema")?.value;
305
- if (p === undefined) return undefined;
306
- else if (p.size() === 0 && p.isRequired() === false) return undefined;
307
- else if (
308
- p.size() === 1 &&
309
- p.nullable === false &&
310
- p.isRequired() === true &&
311
- p.any === false
312
- )
313
- return MetadataTypeTagSchemaFactory.object({
314
- report: (message) =>
315
- props.report({
316
- property: "schema",
317
- message,
318
- }),
319
- object: p.objects[0]!,
320
- });
321
- props.report({
322
- property: "schema",
323
- message: "must be an object type",
324
- });
325
- return undefined;
326
- })();
327
- return {
328
- name: props.object.name,
329
- target,
330
- kind,
331
- value,
332
- validate,
333
- exclusive: exclusive ?? false,
334
- schema,
335
- };
336
- };
337
-
338
- const get_exclusive = (props: {
339
- report: (next: { property: string | null; message: string }) => false;
340
- key: string;
341
- value: Metadata | undefined;
342
- }): boolean | string[] | null => {
343
- if (props.value === undefined) return false;
344
- else if (
345
- props.value.size() === 1 &&
346
- props.value.constants.length === 1 &&
347
- props.value.constants[0]!.type === "boolean" &&
348
- props.value.constants[0]!.values.length === 1
349
- )
350
- return props.value.constants[0]!.values[0]!.value as boolean;
351
- else if (
352
- props.value.size() === 1 &&
353
- props.value.tuples.length === 1 &&
354
- props.value.tuples[0]!.type.elements.every(
355
- (elem) =>
356
- elem.size() === 1 &&
357
- elem.constants.length === 1 &&
358
- elem.constants[0]!.type === "string" &&
359
- elem.constants[0]!.values.length === 1,
360
- )
361
- )
362
- return props.value.tuples[0]!.type.elements.map(
363
- (elem) => elem.constants[0]!.values[0]!.value as string,
364
- );
365
- props.report({
366
- property: props.key,
367
- message:
368
- "must a boolean literal type or a tuple of string literal types.",
369
- });
370
- return null;
371
- };
372
- }
373
-
374
- interface ITypeTag {
375
- name: string;
376
- target: Array<"bigint" | "number" | "string" | "array">;
377
- kind: string;
378
- value?: undefined | boolean | bigint | number | string;
379
- validate: Record<string, string>;
380
- exclusive: boolean | string[];
381
- schema?: undefined | any;
382
- }
383
-
384
- const ESSENTIAL_FIELDS = ["target", "kind", "value"];
385
- const FIELDS = [...ESSENTIAL_FIELDS, "validate", "exclusive"];
1
+ import { IMetadataTypeTag } from "../schemas/metadata/IMetadataTypeTag";
2
+ import { Metadata } from "../schemas/metadata/Metadata";
3
+ import { MetadataObject } from "../schemas/metadata/MetadataObject";
4
+ import { MetadataProperty } from "../schemas/metadata/MetadataProperty";
5
+
6
+ import { MetadataFactory } from "./MetadataFactory";
7
+ import { MetadataTypeTagSchemaFactory } from "./MetadataTypeTagSchemaFactory";
8
+
9
+ export namespace MetadataTypeTagFactory {
10
+ export const analyze = (props: {
11
+ errors: MetadataFactory.IError[];
12
+ type: "boolean" | "bigint" | "number" | "string" | "array";
13
+ objects: MetadataObject[];
14
+ explore: MetadataFactory.IExplore;
15
+ }): IMetadataTypeTag[] => {
16
+ const messages: string[] = [];
17
+ const report = (next: {
18
+ property: string | null;
19
+ message: string;
20
+ }): false => {
21
+ messages.push(
22
+ `the property ${
23
+ next.property === null
24
+ ? `["typia.tag"]`
25
+ : `["typia.tag.${next.property}"]`
26
+ } ${next.message}.`,
27
+ );
28
+ return false;
29
+ };
30
+
31
+ //----
32
+ // VALIDATION PROCESS
33
+ //----
34
+ const filtered: MetadataObject[] = props.objects.filter((obj) => {
35
+ // ONLY ONE PROPERTY
36
+ if (obj.properties.length !== 1) return false;
37
+
38
+ // THE TAG.TYPE PROPERTY MUST BE
39
+ const top: MetadataProperty = obj.properties[0]!;
40
+ if (
41
+ top.key.getSoleLiteral() !== "typia.tag" ||
42
+ top.value.size() !== 1 ||
43
+ top.value.objects.length !== 1
44
+ )
45
+ return false;
46
+ else if (top.value.optional === false)
47
+ return report({
48
+ property: null,
49
+ message: "must be optional object",
50
+ });
51
+
52
+ // CHECK LIST OF PROPERTIES
53
+ const tag: MetadataObject = top.value.objects[0]!;
54
+ const statics: string[] = tag.properties
55
+ .map((p) => p.key.getSoleLiteral()!)
56
+ .filter((str) => str !== null);
57
+ if (ESSENTIAL_FIELDS.some((f) => !statics.includes(f)))
58
+ return report({
59
+ property: null,
60
+ message: `must have at least three properties - ${ESSENTIAL_FIELDS.map(
61
+ (str) => `'${str}'`,
62
+ ).join(", ")}`,
63
+ });
64
+
65
+ const each: boolean[] = tag.properties.map((p) => {
66
+ const key: string | null = p.key.getSoleLiteral();
67
+ if (key === null) return true;
68
+ else if (FIELDS.includes(key) === false) return true;
69
+ return validate_property({
70
+ report,
71
+ key,
72
+ value: p.value,
73
+ });
74
+ });
75
+ return each.every((v) => v === true);
76
+ });
77
+ if (filtered.length === 0) return [];
78
+
79
+ //----
80
+ // CONSTRUCT TYPE TAGS
81
+ //----
82
+ // CREATE 1ST
83
+ const tagList: Array<ITypeTag | null> = filtered.map((object) =>
84
+ create_metadata_type_tag({
85
+ report,
86
+ object,
87
+ }),
88
+ );
89
+
90
+ const output: IMetadataTypeTag[] = [];
91
+ for (const tag of tagList)
92
+ if (tag !== null)
93
+ output.push({
94
+ target: tag.target.some((str) => str === props.type)
95
+ ? props.type
96
+ : null!,
97
+ name: tag.name,
98
+ kind: tag.kind,
99
+ value: tag.value,
100
+ validate: tag.validate[props.type]!,
101
+ exclusive: tag.exclusive,
102
+ schema: tag.schema,
103
+ });
104
+ validate({
105
+ report,
106
+ type: props.type,
107
+ tags: output,
108
+ });
109
+
110
+ if (messages.length > 0) {
111
+ props.errors.push({
112
+ name: [props.type, ...props.objects.map((o) => o.name)].join(" & "),
113
+ explore: props.explore,
114
+ messages,
115
+ });
116
+ return [];
117
+ }
118
+ return output;
119
+ };
120
+
121
+ export const validate = (props: {
122
+ report: (next: { property: string | null; message: string }) => false;
123
+ type: "boolean" | "bigint" | "number" | "string" | "array";
124
+ tags: IMetadataTypeTag[];
125
+ }): boolean => {
126
+ let success: boolean = true;
127
+ for (const tag of props.tags)
128
+ if (tag.target !== props.type) {
129
+ success &&= props.report({
130
+ property: null,
131
+ message: `target must constains ${props.type} type`,
132
+ });
133
+ }
134
+
135
+ props.tags.forEach((tag, i) => {
136
+ if (tag.exclusive === false) return;
137
+ else if (tag.exclusive === true) {
138
+ const some: boolean = props.tags.some(
139
+ (opposite, j) => i !== j && opposite.kind === tag.kind,
140
+ );
141
+ if (some === true)
142
+ success &&= props.report({
143
+ property: null,
144
+ message: `kind '${tag.kind}' can't be duplicated`,
145
+ });
146
+ } else if (Array.isArray(tag.exclusive)) {
147
+ const some: IMetadataTypeTag | undefined = props.tags.find(
148
+ (opposite, j) =>
149
+ i !== j &&
150
+ opposite.kind === tag.kind &&
151
+ (tag.exclusive as string[]).includes(opposite.name),
152
+ );
153
+ if (some !== undefined)
154
+ success ??= props.report({
155
+ property: null,
156
+ message: `kind '${tag.kind}' can't be used with '${some.name}'`,
157
+ });
158
+ }
159
+ });
160
+ return success;
161
+ };
162
+
163
+ const validate_property = (props: {
164
+ report: (next: { property: string | null; message: string }) => false;
165
+ key: string;
166
+ value: Metadata;
167
+ }): boolean => {
168
+ if (
169
+ // TARGET
170
+ props.key === "target" &&
171
+ (props.value.constants.length !== 1 ||
172
+ props.value.constants[0]!.values.length !== props.value.size() ||
173
+ props.value.constants[0]!.values.some(
174
+ (v) =>
175
+ v.value !== "boolean" &&
176
+ v.value !== "bigint" &&
177
+ v.value !== "number" &&
178
+ v.value !== "string" &&
179
+ v.value !== "array",
180
+ ))
181
+ )
182
+ return props.report({
183
+ property: props.key,
184
+ message: `must be one of 'boolean', 'bigint', 'number', 'string', 'array'`,
185
+ });
186
+ else if (
187
+ // KIND
188
+ props.key === "kind" &&
189
+ (props.value.size() !== 1 ||
190
+ props.value.constants.length !== 1 ||
191
+ props.value.constants[0]!.type !== "string" ||
192
+ props.value.constants[0]!.values.length !== 1)
193
+ )
194
+ return props.report({
195
+ property: props.key,
196
+ message: "must be a string literal type",
197
+ });
198
+ else if (
199
+ // VALUE
200
+ props.key === "value" &&
201
+ (props.value.size() > 1 ||
202
+ (props.value.size() !== 0 &&
203
+ (props.value.constants.length !== 1 ||
204
+ props.value.constants[0]!.values.length !== 1)))
205
+ )
206
+ return props.report({
207
+ property: props.key,
208
+ message: "must be a constant literal type or undefined value",
209
+ });
210
+ else if (props.key === "exclusive") return get_exclusive(props) !== null;
211
+ else if (props.key === "validate") {
212
+ //----
213
+ // VALIDATE
214
+ //----
215
+ // UNDEFINED CASE
216
+ if (
217
+ props.value.size() === 0 &&
218
+ props.value.isRequired() === false &&
219
+ props.value.nullable === false
220
+ )
221
+ return true;
222
+
223
+ // STRING CASE
224
+ if (
225
+ props.value.size() === 1 &&
226
+ props.value.constants.length === 1 &&
227
+ props.value.constants[0]!.type === "string" &&
228
+ (props.value.constants[0]!.values.length === 1) === true
229
+ )
230
+ return true;
231
+
232
+ // RECORD<TARGET, STRING>
233
+ const target: string[] | undefined = props.value.objects[0]?.properties
234
+ .map((p) => p.key.getSoleLiteral()!)
235
+ .filter((str) => str !== null) as string[] | undefined;
236
+ if (target === undefined)
237
+ return props.report({
238
+ property: "target",
239
+ message: `must be one of 'boolean', 'bigint', 'number', 'string', 'array'`,
240
+ });
241
+ const variadic: boolean =
242
+ props.value.size() === 1 &&
243
+ props.value.objects.length === 1 &&
244
+ props.value.objects[0]!.properties.every(
245
+ (vp) =>
246
+ vp.value.size() === 1 &&
247
+ vp.value.isRequired() &&
248
+ vp.value.nullable === false &&
249
+ vp.value.constants.length === 1 &&
250
+ vp.value.constants[0]!.type === "string" &&
251
+ vp.value.constants[0]!.values.length === 1 &&
252
+ target.includes(vp.key.getSoleLiteral()!),
253
+ );
254
+ if (variadic === false)
255
+ return props.report({
256
+ property: props.key,
257
+ message: `must be a string literal type or Record<Target, string> type.`,
258
+ });
259
+ }
260
+ return true;
261
+ };
262
+
263
+ const create_metadata_type_tag = (props: {
264
+ report: (next: { property: string | null; message: string }) => false;
265
+ object: MetadataObject;
266
+ }): ITypeTag | null => {
267
+ const find = (key: string): MetadataProperty | undefined =>
268
+ props.object.properties[0]?.value.objects[0]?.properties.find(
269
+ (p) => p.key.getSoleLiteral() === key,
270
+ );
271
+
272
+ const target = find("target")!.value.constants[0]!.values.map(
273
+ (v) => v.value,
274
+ ) as ITypeTag["target"];
275
+ const kind: string = find("kind")!.value.constants[0]!.values[0]!
276
+ .value as string;
277
+ const value: boolean | bigint | number | string | undefined =
278
+ find("value")?.value.constants[0]?.values[0]!.value;
279
+ const exclusive: string[] | boolean | null = get_exclusive({
280
+ report: props.report,
281
+ key: "exclusive",
282
+ value: find("exclusive")?.value,
283
+ });
284
+ if (exclusive === null) return null;
285
+
286
+ const validate: Record<string, string> = (() => {
287
+ const validate = find("validate")?.value;
288
+ if (!validate || validate.size() === 0) return {};
289
+ else if (validate.constants.length)
290
+ return Object.fromEntries(
291
+ target.map((t) => [
292
+ t,
293
+ validate.constants[0]!.values[0]!.value as string,
294
+ ]),
295
+ );
296
+ return Object.fromEntries(
297
+ validate.objects[0]!.properties.map((p) => [
298
+ p.key.getSoleLiteral()!,
299
+ p.value.constants[0]!.values[0]!.value as string,
300
+ ]),
301
+ );
302
+ })();
303
+ const schema: object | undefined = (() => {
304
+ const p: Metadata | undefined = find("schema")?.value;
305
+ if (p === undefined) return undefined;
306
+ else if (p.size() === 0 && p.isRequired() === false) return undefined;
307
+ else if (
308
+ p.size() === 1 &&
309
+ p.nullable === false &&
310
+ p.isRequired() === true &&
311
+ p.any === false
312
+ )
313
+ return MetadataTypeTagSchemaFactory.object({
314
+ report: (message) =>
315
+ props.report({
316
+ property: "schema",
317
+ message,
318
+ }),
319
+ object: p.objects[0]!,
320
+ });
321
+ props.report({
322
+ property: "schema",
323
+ message: "must be an object type",
324
+ });
325
+ return undefined;
326
+ })();
327
+ return {
328
+ name: props.object.name,
329
+ target,
330
+ kind,
331
+ value,
332
+ validate,
333
+ exclusive: exclusive ?? false,
334
+ schema,
335
+ };
336
+ };
337
+
338
+ const get_exclusive = (props: {
339
+ report: (next: { property: string | null; message: string }) => false;
340
+ key: string;
341
+ value: Metadata | undefined;
342
+ }): boolean | string[] | null => {
343
+ if (props.value === undefined) return false;
344
+ else if (
345
+ props.value.size() === 1 &&
346
+ props.value.constants.length === 1 &&
347
+ props.value.constants[0]!.type === "boolean" &&
348
+ props.value.constants[0]!.values.length === 1
349
+ )
350
+ return props.value.constants[0]!.values[0]!.value as boolean;
351
+ else if (
352
+ props.value.size() === 1 &&
353
+ props.value.tuples.length === 1 &&
354
+ props.value.tuples[0]!.type.elements.every(
355
+ (elem) =>
356
+ elem.size() === 1 &&
357
+ elem.constants.length === 1 &&
358
+ elem.constants[0]!.type === "string" &&
359
+ elem.constants[0]!.values.length === 1,
360
+ )
361
+ )
362
+ return props.value.tuples[0]!.type.elements.map(
363
+ (elem) => elem.constants[0]!.values[0]!.value as string,
364
+ );
365
+ props.report({
366
+ property: props.key,
367
+ message:
368
+ "must a boolean literal type or a tuple of string literal types.",
369
+ });
370
+ return null;
371
+ };
372
+ }
373
+
374
+ interface ITypeTag {
375
+ name: string;
376
+ target: Array<"bigint" | "number" | "string" | "array">;
377
+ kind: string;
378
+ value?: undefined | boolean | bigint | number | string;
379
+ validate: Record<string, string>;
380
+ exclusive: boolean | string[];
381
+ schema?: undefined | any;
382
+ }
383
+
384
+ const ESSENTIAL_FIELDS = ["target", "kind", "value"];
385
+ const FIELDS = [...ESSENTIAL_FIELDS, "validate", "exclusive"];