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,278 +1,278 @@
1
- import ts from "typescript";
2
-
3
- import { IMetadataComponents } from "../schemas/metadata/IMetadataComponents";
4
- import { Metadata } from "../schemas/metadata/Metadata";
5
- import { MetadataAlias } from "../schemas/metadata/MetadataAlias";
6
- import { MetadataArrayType } from "../schemas/metadata/MetadataArrayType";
7
- import { MetadataObject } from "../schemas/metadata/MetadataObject";
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, MetadataObject>;
19
- private object_unions_: Map<string, MetadataObject[]>;
20
- private aliases_: Map<ts.Type, MetadataAlias>;
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(
30
- private readonly options?: Partial<MetadataCollection.IOptions>,
31
- ) {
32
- this.objects_ = new Map();
33
- this.object_unions_ = new Map();
34
- this.aliases_ = new Map();
35
- this.arrays_ = new Map();
36
- this.tuples_ = new Map();
37
-
38
- this.names_ = new Map();
39
- this.object_index_ = 0;
40
- this.recursive_array_index_ = 0;
41
- this.recursive_tuple_index_ = 0;
42
- }
43
-
44
- public clone(): MetadataCollection {
45
- const output: MetadataCollection = new MetadataCollection();
46
- output.objects_ = new Map(this.objects_);
47
- output.object_unions_ = new Map(this.object_unions_);
48
- output.aliases_ = new Map(this.aliases_);
49
- output.arrays_ = new Map(this.arrays_);
50
- output.tuples_ = new Map(this.tuples_);
51
- output.names_ = new Map(this.names_);
52
- output.object_index_ = this.object_index_;
53
- output.recursive_array_index_ = this.recursive_array_index_;
54
- output.recursive_tuple_index_ = this.recursive_tuple_index_;
55
- return output;
56
- }
57
-
58
- /* -----------------------------------------------------------
59
- ACCESSORS
60
- ----------------------------------------------------------- */
61
- public aliases(): MetadataAlias[] {
62
- return [...this.aliases_.values()];
63
- }
64
-
65
- public objects(): MetadataObject[] {
66
- return [...this.objects_.values()];
67
- }
68
-
69
- public unions(): MetadataObject[][] {
70
- return [...this.object_unions_.values()];
71
- }
72
-
73
- public arrays(): MetadataArrayType[] {
74
- return [...this.arrays_.values()];
75
- }
76
-
77
- public tuples(): MetadataTupleType[] {
78
- return [...this.tuples_.values()];
79
- }
80
-
81
- private getName(checker: ts.TypeChecker, type: ts.Type): string {
82
- const name: string = (() => {
83
- const str: string = TypeFactory.getFullName({
84
- checker,
85
- type,
86
- });
87
- return this.options?.replace ? this.options.replace(str) : str;
88
- })();
89
-
90
- const duplicates: Map<ts.Type, string> = MapUtil.take(
91
- this.names_,
92
- name,
93
- () => new Map(),
94
- );
95
- const oldbie: string | undefined = duplicates.get(type);
96
- if (oldbie !== undefined) return oldbie;
97
-
98
- const addicted: string = duplicates.size
99
- ? `${name}.o${duplicates.size}`
100
- : name;
101
- duplicates.set(type, addicted);
102
- return addicted;
103
- }
104
-
105
- /**
106
- * @internal
107
- */
108
- public getUnionIndex(meta: Metadata): number {
109
- const key: string = meta.objects.map((obj) => obj.name).join(" | ");
110
- MapUtil.take(this.object_unions_, key, () => meta.objects);
111
- return [...this.object_unions_.keys()].indexOf(key);
112
- }
113
-
114
- /* -----------------------------------------------------------
115
- INSTANCES
116
- ----------------------------------------------------------- */
117
- public emplace(
118
- checker: ts.TypeChecker,
119
- type: ts.Type,
120
- ): [MetadataObject, boolean] {
121
- const oldbie = this.objects_.get(type);
122
- if (oldbie !== undefined) return [oldbie, false];
123
-
124
- const $id: string = this.getName(checker, type);
125
- const obj: MetadataObject = MetadataObject.create({
126
- name: $id,
127
- properties: [],
128
- description:
129
- (type.aliasSymbol && CommentFactory.description(type.aliasSymbol)) ??
130
- (type.symbol && CommentFactory.description(type.symbol)) ??
131
- undefined,
132
- jsDocTags:
133
- type.aliasSymbol?.getJsDocTags() ?? type.symbol?.getJsDocTags() ?? [],
134
- validated: false,
135
- index: this.object_index_++,
136
- recursive: null!,
137
- nullables: [],
138
- });
139
- this.objects_.set(type, obj);
140
- return [obj, true];
141
- }
142
-
143
- public emplaceAlias(
144
- checker: ts.TypeChecker,
145
- type: ts.Type,
146
- symbol: ts.Symbol,
147
- ): [MetadataAlias, boolean, (meta: Metadata) => void] {
148
- const oldbie = this.aliases_.get(type);
149
- if (oldbie !== undefined) return [oldbie, false, () => {}];
150
-
151
- const $id: string = this.getName(checker, type);
152
- const alias: MetadataAlias = MetadataAlias.create({
153
- name: $id,
154
- value: null!,
155
- description: CommentFactory.description(symbol) ?? null,
156
- recursive: null!,
157
- nullables: [],
158
- jsDocTags: symbol.getJsDocTags() ?? [],
159
- });
160
- this.aliases_.set(type, alias);
161
- return [alias, true, (meta) => (Writable(alias).value = meta)];
162
- }
163
-
164
- public emplaceArray(
165
- checker: ts.TypeChecker,
166
- type: ts.Type,
167
- ): [MetadataArrayType, boolean, (meta: Metadata) => void] {
168
- const oldbie = this.arrays_.get(type);
169
- if (oldbie !== undefined) return [oldbie, false, () => {}];
170
-
171
- const $id = this.getName(checker, type);
172
- const array: MetadataArrayType = MetadataArrayType.create({
173
- name: $id,
174
- value: null!,
175
- index: null,
176
- recursive: null!,
177
- nullables: [],
178
- });
179
- this.arrays_.set(type, array);
180
- return [array, true, (meta) => (Writable(array).value = meta)];
181
- }
182
-
183
- public emplaceTuple(
184
- checker: ts.TypeChecker,
185
- type: ts.TupleType,
186
- ): [MetadataTupleType, boolean, (elements: Metadata[]) => void] {
187
- const oldbie = this.tuples_.get(type);
188
- if (oldbie !== undefined) return [oldbie, false, () => {}];
189
-
190
- const $id = this.getName(checker, type);
191
- const tuple: MetadataTupleType = MetadataTupleType.create({
192
- name: $id,
193
- elements: null!,
194
- index: null,
195
- recursive: null!,
196
- nullables: [],
197
- });
198
- this.tuples_.set(type, tuple);
199
- return [tuple, true, (elements) => (Writable(tuple).elements = elements)];
200
- }
201
-
202
- /**
203
- * @internal
204
- */
205
- public setObjectRecursive(obj: MetadataObject, recursive: boolean): void {
206
- Writable(obj).recursive = recursive;
207
- }
208
-
209
- /**
210
- * @internal
211
- */
212
- public setAliasRecursive(alias: MetadataAlias, recursive: boolean): void {
213
- Writable(alias).recursive = recursive;
214
- }
215
-
216
- /**
217
- * @internal
218
- */
219
- public setArrayRecursive(array: MetadataArrayType, recursive: boolean): void {
220
- Writable(array).recursive = recursive;
221
- if (recursive) Writable(array).index = this.recursive_array_index_++;
222
- }
223
-
224
- public setTupleRecursive(tuple: MetadataTupleType, recursive: boolean): void {
225
- Writable(tuple).recursive = recursive;
226
- if (recursive) Writable(tuple).index = this.recursive_tuple_index_++;
227
- }
228
-
229
- public toJSON(): IMetadataComponents {
230
- return {
231
- objects: this.objects().map((o) => o.toJSON()),
232
- aliases: this.aliases().map((d) => d.toJSON()),
233
- arrays: [...this.arrays_.values()].map((a) => a.toJSON()),
234
- tuples: [...this.tuples_.values()].map((t) => t.toJSON()),
235
- };
236
- }
237
- }
238
- export namespace MetadataCollection {
239
- export interface IOptions {
240
- replace?(str: string): string;
241
- }
242
-
243
- export const replace = (str: string): string => {
244
- let replaced: string = str;
245
- for (const [before] of REPLACERS)
246
- replaced = replaced.split(before).join("");
247
- if (replaced.length !== 0) return replaced;
248
-
249
- for (const [before, after] of REPLACERS)
250
- str = str.split(before).join(after);
251
- return str;
252
- };
253
-
254
- export const escape = (str: string): string => {
255
- for (const [before, after] of REPLACERS)
256
- if (after !== "") str = str.split(after).join(before);
257
- return str;
258
- };
259
- }
260
- const REPLACERS: [string, string][] = [
261
- ["$", "_dollar_"],
262
- ["&", "_and_"],
263
- ["|", "_or_"],
264
- ["{", "_blt_"],
265
- ["}", "_bgt_"],
266
- ["<", "_lt_"],
267
- [">", "_gt_"],
268
- ["[", "_alt_"],
269
- ["]", "_agt_"],
270
- [",", "_comma_"],
271
- ["`", "_backquote_"],
272
- ["'", "_singlequote_"],
273
- ['"', "_doublequote_"],
274
- [" ", "_space_"],
275
- ["?", "_question_"],
276
- [":", "_colon_"],
277
- [";", "_semicolon_"],
278
- ];
1
+ import ts from "typescript";
2
+
3
+ import { IMetadataComponents } from "../schemas/metadata/IMetadataComponents";
4
+ import { Metadata } from "../schemas/metadata/Metadata";
5
+ import { MetadataAlias } from "../schemas/metadata/MetadataAlias";
6
+ import { MetadataArrayType } from "../schemas/metadata/MetadataArrayType";
7
+ import { MetadataObject } from "../schemas/metadata/MetadataObject";
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, MetadataObject>;
19
+ private object_unions_: Map<string, MetadataObject[]>;
20
+ private aliases_: Map<ts.Type, MetadataAlias>;
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(
30
+ private readonly options?: Partial<MetadataCollection.IOptions>,
31
+ ) {
32
+ this.objects_ = new Map();
33
+ this.object_unions_ = new Map();
34
+ this.aliases_ = new Map();
35
+ this.arrays_ = new Map();
36
+ this.tuples_ = new Map();
37
+
38
+ this.names_ = new Map();
39
+ this.object_index_ = 0;
40
+ this.recursive_array_index_ = 0;
41
+ this.recursive_tuple_index_ = 0;
42
+ }
43
+
44
+ public clone(): MetadataCollection {
45
+ const output: MetadataCollection = new MetadataCollection();
46
+ output.objects_ = new Map(this.objects_);
47
+ output.object_unions_ = new Map(this.object_unions_);
48
+ output.aliases_ = new Map(this.aliases_);
49
+ output.arrays_ = new Map(this.arrays_);
50
+ output.tuples_ = new Map(this.tuples_);
51
+ output.names_ = new Map(this.names_);
52
+ output.object_index_ = this.object_index_;
53
+ output.recursive_array_index_ = this.recursive_array_index_;
54
+ output.recursive_tuple_index_ = this.recursive_tuple_index_;
55
+ return output;
56
+ }
57
+
58
+ /* -----------------------------------------------------------
59
+ ACCESSORS
60
+ ----------------------------------------------------------- */
61
+ public aliases(): MetadataAlias[] {
62
+ return [...this.aliases_.values()];
63
+ }
64
+
65
+ public objects(): MetadataObject[] {
66
+ return [...this.objects_.values()];
67
+ }
68
+
69
+ public unions(): MetadataObject[][] {
70
+ return [...this.object_unions_.values()];
71
+ }
72
+
73
+ public arrays(): MetadataArrayType[] {
74
+ return [...this.arrays_.values()];
75
+ }
76
+
77
+ public tuples(): MetadataTupleType[] {
78
+ return [...this.tuples_.values()];
79
+ }
80
+
81
+ private getName(checker: ts.TypeChecker, type: ts.Type): string {
82
+ const name: string = (() => {
83
+ const str: string = TypeFactory.getFullName({
84
+ checker,
85
+ type,
86
+ });
87
+ return this.options?.replace ? this.options.replace(str) : str;
88
+ })();
89
+
90
+ const duplicates: Map<ts.Type, string> = MapUtil.take(
91
+ this.names_,
92
+ name,
93
+ () => new Map(),
94
+ );
95
+ const oldbie: string | undefined = duplicates.get(type);
96
+ if (oldbie !== undefined) return oldbie;
97
+
98
+ const addicted: string = duplicates.size
99
+ ? `${name}.o${duplicates.size}`
100
+ : name;
101
+ duplicates.set(type, addicted);
102
+ return addicted;
103
+ }
104
+
105
+ /**
106
+ * @internal
107
+ */
108
+ public getUnionIndex(meta: Metadata): number {
109
+ const key: string = meta.objects.map((obj) => obj.name).join(" | ");
110
+ MapUtil.take(this.object_unions_, key, () => meta.objects);
111
+ return [...this.object_unions_.keys()].indexOf(key);
112
+ }
113
+
114
+ /* -----------------------------------------------------------
115
+ INSTANCES
116
+ ----------------------------------------------------------- */
117
+ public emplace(
118
+ checker: ts.TypeChecker,
119
+ type: ts.Type,
120
+ ): [MetadataObject, boolean] {
121
+ const oldbie = this.objects_.get(type);
122
+ if (oldbie !== undefined) return [oldbie, false];
123
+
124
+ const $id: string = this.getName(checker, type);
125
+ const obj: MetadataObject = MetadataObject.create({
126
+ name: $id,
127
+ properties: [],
128
+ description:
129
+ (type.aliasSymbol && CommentFactory.description(type.aliasSymbol)) ??
130
+ (type.symbol && CommentFactory.description(type.symbol)) ??
131
+ undefined,
132
+ jsDocTags:
133
+ type.aliasSymbol?.getJsDocTags() ?? type.symbol?.getJsDocTags() ?? [],
134
+ validated: false,
135
+ index: this.object_index_++,
136
+ recursive: null!,
137
+ nullables: [],
138
+ });
139
+ this.objects_.set(type, obj);
140
+ return [obj, true];
141
+ }
142
+
143
+ public emplaceAlias(
144
+ checker: ts.TypeChecker,
145
+ type: ts.Type,
146
+ symbol: ts.Symbol,
147
+ ): [MetadataAlias, boolean, (meta: Metadata) => void] {
148
+ const oldbie = this.aliases_.get(type);
149
+ if (oldbie !== undefined) return [oldbie, false, () => {}];
150
+
151
+ const $id: string = this.getName(checker, type);
152
+ const alias: MetadataAlias = MetadataAlias.create({
153
+ name: $id,
154
+ value: null!,
155
+ description: CommentFactory.description(symbol) ?? null,
156
+ recursive: null!,
157
+ nullables: [],
158
+ jsDocTags: symbol.getJsDocTags() ?? [],
159
+ });
160
+ this.aliases_.set(type, alias);
161
+ return [alias, true, (meta) => (Writable(alias).value = meta)];
162
+ }
163
+
164
+ public emplaceArray(
165
+ checker: ts.TypeChecker,
166
+ type: ts.Type,
167
+ ): [MetadataArrayType, boolean, (meta: Metadata) => void] {
168
+ const oldbie = this.arrays_.get(type);
169
+ if (oldbie !== undefined) return [oldbie, false, () => {}];
170
+
171
+ const $id = this.getName(checker, type);
172
+ const array: MetadataArrayType = MetadataArrayType.create({
173
+ name: $id,
174
+ value: null!,
175
+ index: null,
176
+ recursive: null!,
177
+ nullables: [],
178
+ });
179
+ this.arrays_.set(type, array);
180
+ return [array, true, (meta) => (Writable(array).value = meta)];
181
+ }
182
+
183
+ public emplaceTuple(
184
+ checker: ts.TypeChecker,
185
+ type: ts.TupleType,
186
+ ): [MetadataTupleType, boolean, (elements: Metadata[]) => void] {
187
+ const oldbie = this.tuples_.get(type);
188
+ if (oldbie !== undefined) return [oldbie, false, () => {}];
189
+
190
+ const $id = this.getName(checker, type);
191
+ const tuple: MetadataTupleType = MetadataTupleType.create({
192
+ name: $id,
193
+ elements: null!,
194
+ index: null,
195
+ recursive: null!,
196
+ nullables: [],
197
+ });
198
+ this.tuples_.set(type, tuple);
199
+ return [tuple, true, (elements) => (Writable(tuple).elements = elements)];
200
+ }
201
+
202
+ /**
203
+ * @internal
204
+ */
205
+ public setObjectRecursive(obj: MetadataObject, recursive: boolean): void {
206
+ Writable(obj).recursive = recursive;
207
+ }
208
+
209
+ /**
210
+ * @internal
211
+ */
212
+ public setAliasRecursive(alias: MetadataAlias, recursive: boolean): void {
213
+ Writable(alias).recursive = recursive;
214
+ }
215
+
216
+ /**
217
+ * @internal
218
+ */
219
+ public setArrayRecursive(array: MetadataArrayType, recursive: boolean): void {
220
+ Writable(array).recursive = recursive;
221
+ if (recursive) Writable(array).index = this.recursive_array_index_++;
222
+ }
223
+
224
+ public setTupleRecursive(tuple: MetadataTupleType, recursive: boolean): void {
225
+ Writable(tuple).recursive = recursive;
226
+ if (recursive) Writable(tuple).index = this.recursive_tuple_index_++;
227
+ }
228
+
229
+ public toJSON(): IMetadataComponents {
230
+ return {
231
+ objects: this.objects().map((o) => o.toJSON()),
232
+ aliases: this.aliases().map((d) => d.toJSON()),
233
+ arrays: [...this.arrays_.values()].map((a) => a.toJSON()),
234
+ tuples: [...this.tuples_.values()].map((t) => t.toJSON()),
235
+ };
236
+ }
237
+ }
238
+ export namespace MetadataCollection {
239
+ export interface IOptions {
240
+ replace?(str: string): string;
241
+ }
242
+
243
+ export const replace = (str: string): string => {
244
+ let replaced: string = str;
245
+ for (const [before] of REPLACERS)
246
+ replaced = replaced.split(before).join("");
247
+ if (replaced.length !== 0) return replaced;
248
+
249
+ for (const [before, after] of REPLACERS)
250
+ str = str.split(before).join(after);
251
+ return str;
252
+ };
253
+
254
+ export const escape = (str: string): string => {
255
+ for (const [before, after] of REPLACERS)
256
+ if (after !== "") str = str.split(after).join(before);
257
+ return str;
258
+ };
259
+ }
260
+ const REPLACERS: [string, string][] = [
261
+ ["$", "_dollar_"],
262
+ ["&", "_and_"],
263
+ ["|", "_or_"],
264
+ ["{", "_blt_"],
265
+ ["}", "_bgt_"],
266
+ ["<", "_lt_"],
267
+ [">", "_gt_"],
268
+ ["[", "_alt_"],
269
+ ["]", "_agt_"],
270
+ [",", "_comma_"],
271
+ ["`", "_backquote_"],
272
+ ["'", "_singlequote_"],
273
+ ['"', "_doublequote_"],
274
+ [" ", "_space_"],
275
+ ["?", "_question_"],
276
+ [":", "_colon_"],
277
+ [";", "_semicolon_"],
278
+ ];