typia 9.7.2 → 10.0.0-dev.20251107

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 (116) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +153 -153
  3. package/lib/factories/ProtobufFactory.js +1 -1
  4. package/lib/factories/ProtobufFactory.mjs +1 -1
  5. package/lib/programmers/internal/json_schema_station.d.mts +2 -2
  6. package/lib/programmers/internal/json_schema_station.d.ts +2 -2
  7. package/lib/programmers/llm/LlmApplicationProgrammer.js +5 -1
  8. package/lib/programmers/llm/LlmApplicationProgrammer.js.map +1 -1
  9. package/lib/programmers/llm/LlmApplicationProgrammer.mjs +5 -1
  10. package/lib/programmers/llm/LlmSchemaProgrammer.js +1 -4
  11. package/lib/programmers/llm/LlmSchemaProgrammer.js.map +1 -1
  12. package/lib/programmers/llm/LlmSchemaProgrammer.mjs +1 -35
  13. package/package.json +121 -121
  14. package/src/AssertionGuard.ts +41 -41
  15. package/src/CamelCase.ts +75 -75
  16. package/src/IRandomGenerator.ts +337 -337
  17. package/src/IReadableURLSearchParams.ts +9 -9
  18. package/src/PascalCase.ts +71 -71
  19. package/src/Primitive.ts +90 -90
  20. package/src/Resolved.ts +72 -72
  21. package/src/SnakeCase.ts +127 -127
  22. package/src/TypeGuardError.ts +216 -216
  23. package/src/factories/MetadataCollection.ts +270 -270
  24. package/src/factories/MetadataCommentTagFactory.ts +632 -632
  25. package/src/factories/MetadataFactory.ts +402 -402
  26. package/src/factories/ProtobufFactory.ts +873 -873
  27. package/src/functional.ts +705 -705
  28. package/src/http.ts +972 -972
  29. package/src/internal/_ProtobufReader.ts +188 -188
  30. package/src/internal/_ProtobufSizer.ts +137 -137
  31. package/src/internal/_ProtobufWriter.ts +135 -135
  32. package/src/internal/_jsonStringifyString.ts +42 -42
  33. package/src/json.ts +643 -643
  34. package/src/llm.ts +615 -615
  35. package/src/misc.ts +594 -594
  36. package/src/module.ts +889 -889
  37. package/src/notations.ts +751 -751
  38. package/src/programmers/FeatureProgrammer.ts +605 -605
  39. package/src/programmers/ImportProgrammer.ts +179 -179
  40. package/src/programmers/RandomProgrammer.ts +1195 -1195
  41. package/src/programmers/helpers/ProtobufWire.ts +34 -34
  42. package/src/programmers/internal/check_array_length.ts +43 -43
  43. package/src/programmers/internal/check_bigint.ts +46 -46
  44. package/src/programmers/internal/check_dynamic_key.ts +197 -197
  45. package/src/programmers/internal/check_dynamic_properties.ts +231 -231
  46. package/src/programmers/internal/check_everything.ts +21 -21
  47. package/src/programmers/internal/check_native.ts +23 -23
  48. package/src/programmers/internal/check_number.ts +108 -108
  49. package/src/programmers/internal/check_object.ts +72 -72
  50. package/src/programmers/internal/check_string.ts +46 -46
  51. package/src/programmers/internal/check_template.ts +46 -46
  52. package/src/programmers/internal/check_union_array_like.ts +331 -331
  53. package/src/programmers/internal/decode_union_object.ts +110 -110
  54. package/src/programmers/internal/feature_object_entries.ts +59 -59
  55. package/src/programmers/internal/json_schema_escaped.ts +78 -78
  56. package/src/programmers/internal/json_schema_object.ts +150 -150
  57. package/src/programmers/internal/json_schema_station.ts +2 -2
  58. package/src/programmers/internal/metadata_to_pattern.ts +40 -40
  59. package/src/programmers/internal/postfix_of_tuple.ts +3 -3
  60. package/src/programmers/internal/prune_object_properties.ts +69 -69
  61. package/src/programmers/internal/stringify_dynamic_properties.ts +158 -158
  62. package/src/programmers/internal/stringify_native.ts +5 -5
  63. package/src/programmers/internal/stringify_regular_properties.ts +77 -77
  64. package/src/programmers/internal/template_to_pattern.ts +21 -21
  65. package/src/programmers/internal/wrap_metadata_rest_tuple.ts +21 -21
  66. package/src/programmers/json/JsonStringifyProgrammer.ts +1124 -1124
  67. package/src/programmers/llm/LlmApplicationProgrammer.ts +10 -1
  68. package/src/programmers/llm/LlmSchemaProgrammer.ts +2 -7
  69. package/src/protobuf.ts +820 -820
  70. package/src/reflect.ts +46 -46
  71. package/src/schemas/json/IJsonApplication.ts +77 -77
  72. package/src/schemas/json/IJsonSchemaCollection.ts +212 -212
  73. package/src/schemas/json/IJsonSchemaUnit.ts +263 -263
  74. package/src/schemas/metadata/IMetadataTypeTag.ts +14 -14
  75. package/src/schemas/metadata/Metadata.ts +669 -669
  76. package/src/schemas/metadata/MetadataAliasType.ts +57 -57
  77. package/src/schemas/metadata/MetadataApplication.ts +40 -40
  78. package/src/schemas/metadata/MetadataArray.ts +47 -47
  79. package/src/schemas/metadata/MetadataArrayType.ts +51 -51
  80. package/src/schemas/metadata/MetadataAtomic.ts +85 -85
  81. package/src/schemas/metadata/MetadataEscaped.ts +45 -45
  82. package/src/schemas/metadata/MetadataFunction.ts +45 -45
  83. package/src/schemas/metadata/MetadataObject.ts +46 -46
  84. package/src/schemas/metadata/MetadataObjectType.ts +137 -137
  85. package/src/schemas/metadata/MetadataParameter.ts +52 -52
  86. package/src/schemas/metadata/MetadataProperty.ts +53 -53
  87. package/src/schemas/metadata/MetadataTemplate.ts +78 -78
  88. package/src/schemas/metadata/MetadataTuple.ts +28 -28
  89. package/src/schemas/metadata/MetadataTupleType.ts +61 -61
  90. package/src/tags/Constant.ts +47 -47
  91. package/src/tags/ContentMediaType.ts +27 -27
  92. package/src/tags/Default.ts +52 -52
  93. package/src/tags/Example.ts +56 -56
  94. package/src/tags/Examples.ts +56 -56
  95. package/src/tags/ExclusiveMaximum.ts +44 -44
  96. package/src/tags/ExclusiveMinimum.ts +44 -44
  97. package/src/tags/Format.ts +78 -78
  98. package/src/tags/JsonSchemaPlugin.ts +36 -36
  99. package/src/tags/MaxItems.ts +31 -31
  100. package/src/tags/MaxLength.ts +25 -25
  101. package/src/tags/Maximum.ts +39 -39
  102. package/src/tags/MinItems.ts +31 -31
  103. package/src/tags/MinLength.ts +25 -25
  104. package/src/tags/Minimum.ts +39 -39
  105. package/src/tags/MultipleOf.ts +42 -42
  106. package/src/tags/Pattern.ts +49 -49
  107. package/src/tags/Sequence.ts +37 -37
  108. package/src/tags/TagBase.ts +102 -102
  109. package/src/tags/Type.ts +64 -64
  110. package/src/tags/UniqueItems.ts +34 -34
  111. package/src/tags/internal/FormatCheatSheet.ts +71 -71
  112. package/src/transformers/ITransformOptions.ts +70 -70
  113. package/src/transformers/ImportTransformer.ts +253 -253
  114. package/src/transformers/NoTransformConfigurationError.ts +16 -16
  115. package/src/transformers/features/llm/LlmApplicationTransformer.ts +224 -224
  116. package/src/typings/Equal.ts +18 -18
@@ -1,270 +1,270 @@
1
- import ts from "typescript";
2
-
3
- import { IMetadataComponents } from "../schemas/metadata/IMetadataComponents";
4
- import { Metadata } from "../schemas/metadata/Metadata";
5
- import { MetadataAliasType } from "../schemas/metadata/MetadataAliasType";
6
- import { MetadataArrayType } from "../schemas/metadata/MetadataArrayType";
7
- import { MetadataObjectType } from "../schemas/metadata/MetadataObjectType";
8
- import { MetadataTupleType } from "../schemas/metadata/MetadataTupleType";
9
-
10
- import { Writable } from "../typings/Writable";
11
-
12
- import { MapUtil } from "../utils/MapUtil";
13
-
14
- import { CommentFactory } from "./CommentFactory";
15
- import { TypeFactory } from "./TypeFactory";
16
-
17
- export class MetadataCollection {
18
- private objects_: Map<ts.Type, MetadataObjectType>;
19
- private object_unions_: Map<string, MetadataObjectType[]>;
20
- private aliases_: Map<ts.Type, MetadataAliasType>;
21
- private arrays_: Map<ts.Type, MetadataArrayType>;
22
- private tuples_: Map<ts.Type, MetadataTupleType>;
23
-
24
- private names_: Map<string, Map<ts.Type, string>>;
25
- private object_index_: number;
26
- private recursive_array_index_: number;
27
- private recursive_tuple_index_: number;
28
-
29
- public constructor(private options?: Partial<MetadataCollection.IOptions>) {
30
- this.objects_ = new Map();
31
- this.object_unions_ = new Map();
32
- this.aliases_ = new Map();
33
- this.arrays_ = new Map();
34
- this.tuples_ = new Map();
35
-
36
- this.names_ = new Map();
37
- this.object_index_ = 0;
38
- this.recursive_array_index_ = 0;
39
- this.recursive_tuple_index_ = 0;
40
- }
41
-
42
- public clone(): MetadataCollection {
43
- const output: MetadataCollection = new MetadataCollection(this.options);
44
- output.objects_ = new Map(this.objects_);
45
- output.object_unions_ = new Map(this.object_unions_);
46
- output.aliases_ = new Map(this.aliases_);
47
- output.arrays_ = new Map(this.arrays_);
48
- output.tuples_ = new Map(this.tuples_);
49
- output.names_ = new Map(this.names_);
50
- output.object_index_ = this.object_index_;
51
- output.recursive_array_index_ = this.recursive_array_index_;
52
- output.recursive_tuple_index_ = this.recursive_tuple_index_;
53
- return output;
54
- }
55
-
56
- /* -----------------------------------------------------------
57
- ACCESSORS
58
- ----------------------------------------------------------- */
59
- public aliases(): MetadataAliasType[] {
60
- return [...this.aliases_.values()];
61
- }
62
-
63
- public objects(): MetadataObjectType[] {
64
- return [...this.objects_.values()];
65
- }
66
-
67
- public unions(): MetadataObjectType[][] {
68
- return [...this.object_unions_.values()];
69
- }
70
-
71
- public arrays(): MetadataArrayType[] {
72
- return [...this.arrays_.values()];
73
- }
74
-
75
- public tuples(): MetadataTupleType[] {
76
- return [...this.tuples_.values()];
77
- }
78
-
79
- private getName(checker: ts.TypeChecker, type: ts.Type): string {
80
- const name: string = (() => {
81
- const str: string = TypeFactory.getFullName({
82
- checker,
83
- type,
84
- });
85
- return this.options?.replace ? this.options.replace(str) : str;
86
- })();
87
-
88
- const duplicates: Map<ts.Type, string> = MapUtil.take(
89
- this.names_,
90
- name,
91
- () => new Map(),
92
- );
93
- const oldbie: string | undefined = duplicates.get(type);
94
- if (oldbie !== undefined) return oldbie;
95
-
96
- const addicted: string = duplicates.size
97
- ? `${name}.o${duplicates.size}`
98
- : name;
99
- duplicates.set(type, addicted);
100
- return addicted;
101
- }
102
-
103
- /** @internal */
104
- public getUnionIndex(meta: Metadata): number {
105
- const key: string = meta.objects.map((obj) => obj.type.name).join(" | ");
106
- MapUtil.take(this.object_unions_, key, () =>
107
- meta.objects.map((o) => o.type),
108
- );
109
- return [...this.object_unions_.keys()].indexOf(key);
110
- }
111
-
112
- /* -----------------------------------------------------------
113
- INSTANCES
114
- ----------------------------------------------------------- */
115
- public emplace(
116
- checker: ts.TypeChecker,
117
- type: ts.Type,
118
- ): [MetadataObjectType, boolean] {
119
- const oldbie = this.objects_.get(type);
120
- if (oldbie !== undefined) return [oldbie, false];
121
-
122
- const id: string = this.getName(checker, type);
123
- const obj: MetadataObjectType = MetadataObjectType.create({
124
- name: id,
125
- properties: [],
126
- description:
127
- (type.aliasSymbol && CommentFactory.description(type.aliasSymbol)) ??
128
- (type.symbol && CommentFactory.description(type.symbol)) ??
129
- undefined,
130
- jsDocTags:
131
- type.aliasSymbol?.getJsDocTags() ?? type.symbol?.getJsDocTags() ?? [],
132
- validated: false,
133
- index: this.object_index_++,
134
- recursive: null!,
135
- nullables: [],
136
- });
137
- this.objects_.set(type, obj);
138
- return [obj, true];
139
- }
140
-
141
- public emplaceAlias(
142
- checker: ts.TypeChecker,
143
- type: ts.Type,
144
- symbol: ts.Symbol,
145
- ): [MetadataAliasType, boolean, (meta: Metadata) => void] {
146
- const oldbie = this.aliases_.get(type);
147
- if (oldbie !== undefined) return [oldbie, false, () => {}];
148
-
149
- const id: string = this.getName(checker, type);
150
- const alias: MetadataAliasType = MetadataAliasType.create({
151
- name: id,
152
- value: null!,
153
- description: CommentFactory.description(symbol) ?? null,
154
- recursive: null!,
155
- nullables: [],
156
- jsDocTags: symbol.getJsDocTags() ?? [],
157
- });
158
- this.aliases_.set(type, alias);
159
- return [alias, true, (meta) => (Writable(alias).value = meta)];
160
- }
161
-
162
- public emplaceArray(
163
- checker: ts.TypeChecker,
164
- type: ts.Type,
165
- ): [MetadataArrayType, boolean, (meta: Metadata) => void] {
166
- const oldbie = this.arrays_.get(type);
167
- if (oldbie !== undefined) return [oldbie, false, () => {}];
168
-
169
- const id = this.getName(checker, type);
170
- const array: MetadataArrayType = MetadataArrayType.create({
171
- name: id,
172
- value: null!,
173
- index: null,
174
- recursive: null!,
175
- nullables: [],
176
- });
177
- this.arrays_.set(type, array);
178
- return [array, true, (meta) => (Writable(array).value = meta)];
179
- }
180
-
181
- public emplaceTuple(
182
- checker: ts.TypeChecker,
183
- type: ts.TupleType,
184
- ): [MetadataTupleType, boolean, (elements: Metadata[]) => void] {
185
- const oldbie = this.tuples_.get(type);
186
- if (oldbie !== undefined) return [oldbie, false, () => {}];
187
-
188
- const id = this.getName(checker, type);
189
- const tuple: MetadataTupleType = MetadataTupleType.create({
190
- name: id,
191
- elements: null!,
192
- index: null,
193
- recursive: null!,
194
- nullables: [],
195
- });
196
- this.tuples_.set(type, tuple);
197
- return [tuple, true, (elements) => (Writable(tuple).elements = elements)];
198
- }
199
-
200
- /** @internal */
201
- public setObjectRecursive(obj: MetadataObjectType, recursive: boolean): void {
202
- Writable(obj).recursive = recursive;
203
- }
204
-
205
- /** @internal */
206
- public setAliasRecursive(alias: MetadataAliasType, recursive: boolean): void {
207
- Writable(alias).recursive = recursive;
208
- }
209
-
210
- /** @internal */
211
- public setArrayRecursive(array: MetadataArrayType, recursive: boolean): void {
212
- Writable(array).recursive = recursive;
213
- if (recursive) Writable(array).index = this.recursive_array_index_++;
214
- }
215
-
216
- public setTupleRecursive(tuple: MetadataTupleType, recursive: boolean): void {
217
- Writable(tuple).recursive = recursive;
218
- if (recursive) Writable(tuple).index = this.recursive_tuple_index_++;
219
- }
220
-
221
- public toJSON(): IMetadataComponents {
222
- return {
223
- objects: this.objects().map((o) => o.toJSON()),
224
- aliases: this.aliases().map((d) => d.toJSON()),
225
- arrays: [...this.arrays_.values()].map((a) => a.toJSON()),
226
- tuples: [...this.tuples_.values()].map((t) => t.toJSON()),
227
- };
228
- }
229
- }
230
- export namespace MetadataCollection {
231
- export interface IOptions {
232
- replace?(str: string): string;
233
- }
234
-
235
- export const replace = (str: string): string => {
236
- let replaced: string = str;
237
- for (const [before] of REPLACERS)
238
- replaced = replaced.split(before).join("");
239
- if (replaced.length !== 0) return replaced;
240
-
241
- for (const [before, after] of REPLACERS)
242
- str = str.split(before).join(after);
243
- return str;
244
- };
245
-
246
- export const escape = (str: string): string => {
247
- for (const [before, after] of REPLACERS)
248
- if (after !== "") str = str.split(after).join(before);
249
- return str;
250
- };
251
- }
252
- const REPLACERS: [string, string][] = [
253
- ["$", "_dollar_"],
254
- ["&", "_and_"],
255
- ["|", "_or_"],
256
- ["{", "_blt_"],
257
- ["}", "_bgt_"],
258
- ["<", "_lt_"],
259
- [">", "_gt_"],
260
- ["[", "_alt_"],
261
- ["]", "_agt_"],
262
- [",", "_comma_"],
263
- ["`", "_backquote_"],
264
- ["'", "_singlequote_"],
265
- ['"', "_doublequote_"],
266
- [" ", "_space_"],
267
- ["?", "_question_"],
268
- [":", "_colon_"],
269
- [";", "_semicolon_"],
270
- ];
1
+ import ts from "typescript";
2
+
3
+ import { IMetadataComponents } from "../schemas/metadata/IMetadataComponents";
4
+ import { Metadata } from "../schemas/metadata/Metadata";
5
+ import { MetadataAliasType } from "../schemas/metadata/MetadataAliasType";
6
+ import { MetadataArrayType } from "../schemas/metadata/MetadataArrayType";
7
+ import { MetadataObjectType } from "../schemas/metadata/MetadataObjectType";
8
+ import { MetadataTupleType } from "../schemas/metadata/MetadataTupleType";
9
+
10
+ import { Writable } from "../typings/Writable";
11
+
12
+ import { MapUtil } from "../utils/MapUtil";
13
+
14
+ import { CommentFactory } from "./CommentFactory";
15
+ import { TypeFactory } from "./TypeFactory";
16
+
17
+ export class MetadataCollection {
18
+ private objects_: Map<ts.Type, MetadataObjectType>;
19
+ private object_unions_: Map<string, MetadataObjectType[]>;
20
+ private aliases_: Map<ts.Type, MetadataAliasType>;
21
+ private arrays_: Map<ts.Type, MetadataArrayType>;
22
+ private tuples_: Map<ts.Type, MetadataTupleType>;
23
+
24
+ private names_: Map<string, Map<ts.Type, string>>;
25
+ private object_index_: number;
26
+ private recursive_array_index_: number;
27
+ private recursive_tuple_index_: number;
28
+
29
+ public constructor(private options?: Partial<MetadataCollection.IOptions>) {
30
+ this.objects_ = new Map();
31
+ this.object_unions_ = new Map();
32
+ this.aliases_ = new Map();
33
+ this.arrays_ = new Map();
34
+ this.tuples_ = new Map();
35
+
36
+ this.names_ = new Map();
37
+ this.object_index_ = 0;
38
+ this.recursive_array_index_ = 0;
39
+ this.recursive_tuple_index_ = 0;
40
+ }
41
+
42
+ public clone(): MetadataCollection {
43
+ const output: MetadataCollection = new MetadataCollection(this.options);
44
+ output.objects_ = new Map(this.objects_);
45
+ output.object_unions_ = new Map(this.object_unions_);
46
+ output.aliases_ = new Map(this.aliases_);
47
+ output.arrays_ = new Map(this.arrays_);
48
+ output.tuples_ = new Map(this.tuples_);
49
+ output.names_ = new Map(this.names_);
50
+ output.object_index_ = this.object_index_;
51
+ output.recursive_array_index_ = this.recursive_array_index_;
52
+ output.recursive_tuple_index_ = this.recursive_tuple_index_;
53
+ return output;
54
+ }
55
+
56
+ /* -----------------------------------------------------------
57
+ ACCESSORS
58
+ ----------------------------------------------------------- */
59
+ public aliases(): MetadataAliasType[] {
60
+ return [...this.aliases_.values()];
61
+ }
62
+
63
+ public objects(): MetadataObjectType[] {
64
+ return [...this.objects_.values()];
65
+ }
66
+
67
+ public unions(): MetadataObjectType[][] {
68
+ return [...this.object_unions_.values()];
69
+ }
70
+
71
+ public arrays(): MetadataArrayType[] {
72
+ return [...this.arrays_.values()];
73
+ }
74
+
75
+ public tuples(): MetadataTupleType[] {
76
+ return [...this.tuples_.values()];
77
+ }
78
+
79
+ private getName(checker: ts.TypeChecker, type: ts.Type): string {
80
+ const name: string = (() => {
81
+ const str: string = TypeFactory.getFullName({
82
+ checker,
83
+ type,
84
+ });
85
+ return this.options?.replace ? this.options.replace(str) : str;
86
+ })();
87
+
88
+ const duplicates: Map<ts.Type, string> = MapUtil.take(
89
+ this.names_,
90
+ name,
91
+ () => new Map(),
92
+ );
93
+ const oldbie: string | undefined = duplicates.get(type);
94
+ if (oldbie !== undefined) return oldbie;
95
+
96
+ const addicted: string = duplicates.size
97
+ ? `${name}.o${duplicates.size}`
98
+ : name;
99
+ duplicates.set(type, addicted);
100
+ return addicted;
101
+ }
102
+
103
+ /** @internal */
104
+ public getUnionIndex(meta: Metadata): number {
105
+ const key: string = meta.objects.map((obj) => obj.type.name).join(" | ");
106
+ MapUtil.take(this.object_unions_, key, () =>
107
+ meta.objects.map((o) => o.type),
108
+ );
109
+ return [...this.object_unions_.keys()].indexOf(key);
110
+ }
111
+
112
+ /* -----------------------------------------------------------
113
+ INSTANCES
114
+ ----------------------------------------------------------- */
115
+ public emplace(
116
+ checker: ts.TypeChecker,
117
+ type: ts.Type,
118
+ ): [MetadataObjectType, boolean] {
119
+ const oldbie = this.objects_.get(type);
120
+ if (oldbie !== undefined) return [oldbie, false];
121
+
122
+ const id: string = this.getName(checker, type);
123
+ const obj: MetadataObjectType = MetadataObjectType.create({
124
+ name: id,
125
+ properties: [],
126
+ description:
127
+ (type.aliasSymbol && CommentFactory.description(type.aliasSymbol)) ??
128
+ (type.symbol && CommentFactory.description(type.symbol)) ??
129
+ undefined,
130
+ jsDocTags:
131
+ type.aliasSymbol?.getJsDocTags() ?? type.symbol?.getJsDocTags() ?? [],
132
+ validated: false,
133
+ index: this.object_index_++,
134
+ recursive: null!,
135
+ nullables: [],
136
+ });
137
+ this.objects_.set(type, obj);
138
+ return [obj, true];
139
+ }
140
+
141
+ public emplaceAlias(
142
+ checker: ts.TypeChecker,
143
+ type: ts.Type,
144
+ symbol: ts.Symbol,
145
+ ): [MetadataAliasType, boolean, (meta: Metadata) => void] {
146
+ const oldbie = this.aliases_.get(type);
147
+ if (oldbie !== undefined) return [oldbie, false, () => {}];
148
+
149
+ const id: string = this.getName(checker, type);
150
+ const alias: MetadataAliasType = MetadataAliasType.create({
151
+ name: id,
152
+ value: null!,
153
+ description: CommentFactory.description(symbol) ?? null,
154
+ recursive: null!,
155
+ nullables: [],
156
+ jsDocTags: symbol.getJsDocTags() ?? [],
157
+ });
158
+ this.aliases_.set(type, alias);
159
+ return [alias, true, (meta) => (Writable(alias).value = meta)];
160
+ }
161
+
162
+ public emplaceArray(
163
+ checker: ts.TypeChecker,
164
+ type: ts.Type,
165
+ ): [MetadataArrayType, boolean, (meta: Metadata) => void] {
166
+ const oldbie = this.arrays_.get(type);
167
+ if (oldbie !== undefined) return [oldbie, false, () => {}];
168
+
169
+ const id = this.getName(checker, type);
170
+ const array: MetadataArrayType = MetadataArrayType.create({
171
+ name: id,
172
+ value: null!,
173
+ index: null,
174
+ recursive: null!,
175
+ nullables: [],
176
+ });
177
+ this.arrays_.set(type, array);
178
+ return [array, true, (meta) => (Writable(array).value = meta)];
179
+ }
180
+
181
+ public emplaceTuple(
182
+ checker: ts.TypeChecker,
183
+ type: ts.TupleType,
184
+ ): [MetadataTupleType, boolean, (elements: Metadata[]) => void] {
185
+ const oldbie = this.tuples_.get(type);
186
+ if (oldbie !== undefined) return [oldbie, false, () => {}];
187
+
188
+ const id = this.getName(checker, type);
189
+ const tuple: MetadataTupleType = MetadataTupleType.create({
190
+ name: id,
191
+ elements: null!,
192
+ index: null,
193
+ recursive: null!,
194
+ nullables: [],
195
+ });
196
+ this.tuples_.set(type, tuple);
197
+ return [tuple, true, (elements) => (Writable(tuple).elements = elements)];
198
+ }
199
+
200
+ /** @internal */
201
+ public setObjectRecursive(obj: MetadataObjectType, recursive: boolean): void {
202
+ Writable(obj).recursive = recursive;
203
+ }
204
+
205
+ /** @internal */
206
+ public setAliasRecursive(alias: MetadataAliasType, recursive: boolean): void {
207
+ Writable(alias).recursive = recursive;
208
+ }
209
+
210
+ /** @internal */
211
+ public setArrayRecursive(array: MetadataArrayType, recursive: boolean): void {
212
+ Writable(array).recursive = recursive;
213
+ if (recursive) Writable(array).index = this.recursive_array_index_++;
214
+ }
215
+
216
+ public setTupleRecursive(tuple: MetadataTupleType, recursive: boolean): void {
217
+ Writable(tuple).recursive = recursive;
218
+ if (recursive) Writable(tuple).index = this.recursive_tuple_index_++;
219
+ }
220
+
221
+ public toJSON(): IMetadataComponents {
222
+ return {
223
+ objects: this.objects().map((o) => o.toJSON()),
224
+ aliases: this.aliases().map((d) => d.toJSON()),
225
+ arrays: [...this.arrays_.values()].map((a) => a.toJSON()),
226
+ tuples: [...this.tuples_.values()].map((t) => t.toJSON()),
227
+ };
228
+ }
229
+ }
230
+ export namespace MetadataCollection {
231
+ export interface IOptions {
232
+ replace?(str: string): string;
233
+ }
234
+
235
+ export const replace = (str: string): string => {
236
+ let replaced: string = str;
237
+ for (const [before] of REPLACERS)
238
+ replaced = replaced.split(before).join("");
239
+ if (replaced.length !== 0) return replaced;
240
+
241
+ for (const [before, after] of REPLACERS)
242
+ str = str.split(before).join(after);
243
+ return str;
244
+ };
245
+
246
+ export const escape = (str: string): string => {
247
+ for (const [before, after] of REPLACERS)
248
+ if (after !== "") str = str.split(after).join(before);
249
+ return str;
250
+ };
251
+ }
252
+ const REPLACERS: [string, string][] = [
253
+ ["$", "_dollar_"],
254
+ ["&", "_and_"],
255
+ ["|", "_or_"],
256
+ ["{", "_blt_"],
257
+ ["}", "_bgt_"],
258
+ ["<", "_lt_"],
259
+ [">", "_gt_"],
260
+ ["[", "_alt_"],
261
+ ["]", "_agt_"],
262
+ [",", "_comma_"],
263
+ ["`", "_backquote_"],
264
+ ["'", "_singlequote_"],
265
+ ['"', "_doublequote_"],
266
+ [" ", "_space_"],
267
+ ["?", "_question_"],
268
+ [":", "_colon_"],
269
+ [";", "_semicolon_"],
270
+ ];