typia 7.0.0-dev.20240923 → 7.0.0-dev.20240924

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.
@@ -9,6 +9,7 @@ import { TypeFactory } from "../../factories/TypeFactory";
9
9
 
10
10
  import { Metadata } from "../../schemas/metadata/Metadata";
11
11
  import { MetadataArray } from "../../schemas/metadata/MetadataArray";
12
+ import { MetadataObject } from "../../schemas/metadata/MetadataObject";
12
13
  import { MetadataTuple } from "../../schemas/metadata/MetadataTuple";
13
14
  import { MetadataTupleType } from "../../schemas/metadata/MetadataTupleType";
14
15
 
@@ -33,7 +34,7 @@ export namespace MiscCloneProgrammer {
33
34
  type: ts.Type;
34
35
  name: string | undefined;
35
36
  }): FeatureProgrammer.IDecomposed => {
36
- const config = configure(props.context)(props.importer);
37
+ const config: FeatureProgrammer.IConfig = configure(props);
37
38
  if (props.validated === false)
38
39
  config.addition = (collection) =>
39
40
  IsProgrammer.write_function_statements(props.context)(props.importer)(
@@ -73,423 +74,468 @@ export namespace MiscCloneProgrammer {
73
74
  });
74
75
  };
75
76
 
76
- const write_array_functions =
77
- (config: FeatureProgrammer.IConfig) =>
78
- (importer: FunctionImporter) =>
79
- (collection: MetadataCollection): ts.VariableStatement[] =>
80
- collection
81
- .arrays()
82
- .filter((a) => a.recursive)
83
- .map((type, i) =>
84
- StatementFactory.constant(
85
- `${config.prefix}a${i}`,
86
- ts.factory.createArrowFunction(
87
- undefined,
88
- undefined,
89
- FeatureProgrammer.parameterDeclarations(config)(
90
- TypeFactory.keyword("any"),
91
- )(ts.factory.createIdentifier("input")),
77
+ const write_array_functions = (props: {
78
+ config: FeatureProgrammer.IConfig;
79
+ importer: FunctionImporter;
80
+ collection: MetadataCollection;
81
+ }): ts.VariableStatement[] =>
82
+ props.collection
83
+ .arrays()
84
+ .filter((a) => a.recursive)
85
+ .map((type, i) =>
86
+ StatementFactory.constant(
87
+ `${props.config.prefix}a${i}`,
88
+ ts.factory.createArrowFunction(
89
+ undefined,
90
+ undefined,
91
+ FeatureProgrammer.parameterDeclarations(props.config)(
92
92
  TypeFactory.keyword("any"),
93
- undefined,
94
- decode_array_inline(config)(importer)(
95
- ts.factory.createIdentifier("input"),
96
- MetadataArray.create({
97
- type,
98
- tags: [],
99
- }),
100
- {
101
- tracable: config.trace,
102
- source: "function",
103
- from: "array",
104
- postfix: "",
105
- },
106
- ),
107
- ),
93
+ )(ts.factory.createIdentifier("input")),
94
+ TypeFactory.keyword("any"),
95
+ undefined,
96
+ decode_array_inline({
97
+ config: props.config,
98
+ importer: props.importer,
99
+ input: ts.factory.createIdentifier("input"),
100
+ array: MetadataArray.create({
101
+ type,
102
+ tags: [],
103
+ }),
104
+ explore: {
105
+ tracable: props.config.trace,
106
+ source: "function",
107
+ from: "array",
108
+ postfix: "",
109
+ },
110
+ }),
108
111
  ),
109
- );
112
+ ),
113
+ );
110
114
 
111
- const write_tuple_functions =
112
- (project: ITypiaContext) =>
113
- (config: FeatureProgrammer.IConfig) =>
114
- (importer: FunctionImporter) =>
115
- (collection: MetadataCollection): ts.VariableStatement[] =>
116
- collection
117
- .tuples()
118
- .filter((t) => t.recursive)
119
- .map((tuple, i) =>
120
- StatementFactory.constant(
121
- `${config.prefix}t${i}`,
122
- ts.factory.createArrowFunction(
123
- undefined,
124
- undefined,
125
- FeatureProgrammer.parameterDeclarations(config)(
126
- TypeFactory.keyword("any"),
127
- )(ts.factory.createIdentifier("input")),
115
+ const write_tuple_functions = (props: {
116
+ context: ITypiaContext;
117
+ config: FeatureProgrammer.IConfig;
118
+ importer: FunctionImporter;
119
+ collection: MetadataCollection;
120
+ }): ts.VariableStatement[] =>
121
+ props.collection
122
+ .tuples()
123
+ .filter((t) => t.recursive)
124
+ .map((tuple, i) =>
125
+ StatementFactory.constant(
126
+ `${props.config.prefix}t${i}`,
127
+ ts.factory.createArrowFunction(
128
+ undefined,
129
+ undefined,
130
+ FeatureProgrammer.parameterDeclarations(props.config)(
128
131
  TypeFactory.keyword("any"),
129
- undefined,
130
- decode_tuple_inline(project)(config)(importer)(
131
- ts.factory.createIdentifier("input"),
132
- tuple,
133
- {
134
- tracable: config.trace,
135
- source: "function",
136
- from: "array",
137
- postfix: "",
138
- },
139
- ),
140
- ),
132
+ )(ts.factory.createIdentifier("input")),
133
+ TypeFactory.keyword("any"),
134
+ undefined,
135
+ decode_tuple_inline({
136
+ config: props.config,
137
+ context: props.context,
138
+ importer: props.importer,
139
+ input: ts.factory.createIdentifier("input"),
140
+ tuple,
141
+ explore: {
142
+ tracable: props.config.trace,
143
+ source: "function",
144
+ from: "array",
145
+ postfix: "",
146
+ },
147
+ }),
141
148
  ),
142
- );
149
+ ),
150
+ );
143
151
 
144
152
  /* -----------------------------------------------------------
145
153
  DECODERS
146
154
  ----------------------------------------------------------- */
147
- const decode =
148
- (project: ITypiaContext) =>
149
- (config: FeatureProgrammer.IConfig) =>
150
- (importer: FunctionImporter) =>
151
- (
152
- input: ts.Expression,
153
- meta: Metadata,
154
- explore: FeatureProgrammer.IExplore,
155
- ): ts.Expression => {
156
- // ANY TYPE
157
- if (
158
- meta.any ||
159
- meta.arrays.some((a) => a.type.value.any) ||
160
- meta.tuples.some(
161
- (t) =>
162
- !!t.type.elements.length && t.type.elements.every((e) => e.any),
163
- )
155
+ const decode = (props: {
156
+ context: ITypiaContext;
157
+ config: FeatureProgrammer.IConfig;
158
+ importer: FunctionImporter;
159
+ input: ts.Expression;
160
+ metadata: Metadata;
161
+ explore: FeatureProgrammer.IExplore;
162
+ }): ts.Expression => {
163
+ // ANY TYPE
164
+ if (
165
+ props.metadata.any ||
166
+ props.metadata.arrays.some((a) => a.type.value.any) ||
167
+ props.metadata.tuples.some(
168
+ (t) => !!t.type.elements.length && t.type.elements.every((e) => e.any),
164
169
  )
165
- return ts.factory.createCallExpression(importer.use("any"), undefined, [
166
- input,
167
- ]);
168
-
169
- interface IUnion {
170
- type: string;
171
- is: () => ts.Expression;
172
- value: () => ts.Expression;
173
- }
174
- const unions: IUnion[] = [];
175
-
176
- //----
177
- // LIST UP UNION TYPES
178
- //----
179
- // FUNCTIONAL
180
- if (meta.functions.length)
181
- unions.push({
182
- type: "functional",
183
- is: () =>
184
- ts.factory.createStrictEquality(
185
- ts.factory.createStringLiteral("function"),
186
- ts.factory.createTypeOfExpression(input),
187
- ),
188
- value: () => ts.factory.createIdentifier("undefined"),
189
- });
170
+ )
171
+ return ts.factory.createCallExpression(
172
+ props.importer.use("any"),
173
+ undefined,
174
+ [props.input],
175
+ );
190
176
 
191
- // TUPLES
192
- for (const tuple of meta.tuples)
193
- unions.push({
194
- type: "tuple",
195
- is: () =>
196
- IsProgrammer.decode(project)(importer)(
197
- input,
198
- (() => {
199
- const partial = Metadata.initialize();
200
- partial.tuples.push(tuple);
201
- return partial;
202
- })(),
203
- explore,
204
- ),
205
- value: () =>
206
- decode_tuple(project)(config)(importer)(input, tuple, explore),
207
- });
177
+ interface IUnion {
178
+ type: string;
179
+ is: () => ts.Expression;
180
+ value: () => ts.Expression;
181
+ }
182
+ const unions: IUnion[] = [];
183
+
184
+ //----
185
+ // LIST UP UNION TYPES
186
+ //----
187
+ // FUNCTIONAL
188
+ if (props.metadata.functions.length)
189
+ unions.push({
190
+ type: "functional",
191
+ is: () =>
192
+ ts.factory.createStrictEquality(
193
+ ts.factory.createStringLiteral("function"),
194
+ ts.factory.createTypeOfExpression(props.input),
195
+ ),
196
+ value: () => ts.factory.createIdentifier("undefined"),
197
+ });
208
198
 
209
- // ARRAYS
210
- if (meta.arrays.length)
211
- unions.push({
212
- type: "array",
213
- is: () => ExpressionFactory.isArray(input),
214
- value: () =>
215
- explore_arrays(project)(config)(importer)(input, meta.arrays, {
216
- ...explore,
199
+ // TUPLES
200
+ for (const tuple of props.metadata.tuples)
201
+ unions.push({
202
+ type: "tuple",
203
+ is: () =>
204
+ IsProgrammer.decode(props.context)(props.importer)(
205
+ props.input,
206
+ (() => {
207
+ const partial = Metadata.initialize();
208
+ partial.tuples.push(tuple);
209
+ return partial;
210
+ })(),
211
+ props.explore,
212
+ ),
213
+ value: () =>
214
+ decode_tuple({
215
+ ...props,
216
+ tuple,
217
+ }),
218
+ });
219
+
220
+ // ARRAYS
221
+ if (props.metadata.arrays.length)
222
+ unions.push({
223
+ type: "array",
224
+ is: () => ExpressionFactory.isArray(props.input),
225
+ value: () =>
226
+ explore_arrays({
227
+ ...props,
228
+ arrays: props.metadata.arrays,
229
+ explore: {
230
+ ...props.explore,
217
231
  from: "array",
218
- }),
219
- });
232
+ },
233
+ }),
234
+ });
220
235
 
221
- // NATIVE TYPES
222
- if (meta.sets.length)
223
- unions.push({
224
- type: "set",
225
- is: () => ExpressionFactory.isInstanceOf("Set")(input),
226
- value: () =>
227
- explore_sets(project)(config)(importer)(input, meta.sets, {
228
- ...explore,
236
+ // NATIVE TYPES
237
+ if (props.metadata.sets.length)
238
+ unions.push({
239
+ type: "set",
240
+ is: () => ExpressionFactory.isInstanceOf("Set")(props.input),
241
+ value: () =>
242
+ explore_sets({
243
+ ...props,
244
+ sets: props.metadata.sets,
245
+ explore: {
246
+ ...props.explore,
229
247
  from: "array",
230
- }),
231
- });
232
- if (meta.maps.length)
233
- unions.push({
234
- type: "map",
235
- is: () => ExpressionFactory.isInstanceOf("Map")(input),
236
- value: () =>
237
- explore_maps(project)(config)(importer)(input, meta.maps, {
238
- ...explore,
248
+ },
249
+ }),
250
+ });
251
+ if (props.metadata.maps.length)
252
+ unions.push({
253
+ type: "map",
254
+ is: () => ExpressionFactory.isInstanceOf("Map")(props.input),
255
+ value: () =>
256
+ explore_maps({
257
+ ...props,
258
+ maps: props.metadata.maps,
259
+ explore: {
260
+ ...props.explore,
239
261
  from: "array",
240
- }),
241
- });
242
- for (const native of meta.natives)
243
- unions.push({
244
- type: "native",
245
- is: () => ExpressionFactory.isInstanceOf(native)(input),
246
- value: () =>
247
- native === "Boolean" || native === "Number" || native === "String"
248
- ? ts.factory.createCallExpression(
249
- IdentifierFactory.access(input)("valueOf"),
250
- undefined,
251
- undefined,
252
- )
253
- : decode_native(native)(input),
254
- });
255
-
256
- // OBJECTS
257
- if (meta.objects.length)
258
- unions.push({
259
- type: "object",
260
- is: () =>
261
- ExpressionFactory.isObject({
262
- checkNull: true,
263
- checkArray: false,
264
- })(input),
265
- value: () =>
266
- explore_objects(config)(importer)(input, meta, {
267
- ...explore,
268
- from: "object",
269
- }),
270
- });
271
-
272
- // COMPOSITION
273
- if (unions.length === 0) return input;
274
- else if (unions.length === 1 && meta.size() === 1) {
275
- const value: ts.Expression =
276
- (meta.nullable || meta.isRequired() === false) && is_instance(meta)
277
- ? ts.factory.createConditionalExpression(
278
- input,
262
+ },
263
+ }),
264
+ });
265
+ for (const native of props.metadata.natives)
266
+ unions.push({
267
+ type: "native",
268
+ is: () => ExpressionFactory.isInstanceOf(native)(props.input),
269
+ value: () =>
270
+ native === "Boolean" || native === "Number" || native === "String"
271
+ ? ts.factory.createCallExpression(
272
+ IdentifierFactory.access(props.input)("valueOf"),
279
273
  undefined,
280
- unions[0]!.value(),
281
274
  undefined,
282
- input,
283
275
  )
284
- : unions[0]!.value();
285
- return ts.factory.createAsExpression(value, TypeFactory.keyword("any"));
286
- } else {
287
- let last: ts.Expression = input;
288
- for (const u of unions.reverse())
289
- last = ts.factory.createConditionalExpression(
290
- u.is(),
291
- undefined,
292
- u.value(),
293
- undefined,
294
- last,
295
- );
296
- return ts.factory.createAsExpression(last, TypeFactory.keyword("any"));
297
- }
298
- };
276
+ : decode_native({
277
+ type: native,
278
+ input: props.input,
279
+ }),
280
+ });
281
+
282
+ // OBJECTS
283
+ if (props.metadata.objects.length)
284
+ unions.push({
285
+ type: "object",
286
+ is: () =>
287
+ ExpressionFactory.isObject({
288
+ checkNull: true,
289
+ checkArray: false,
290
+ })(props.input),
291
+ value: () =>
292
+ explore_objects({
293
+ ...props,
294
+ explore: {
295
+ ...props.explore,
296
+ from: "object",
297
+ },
298
+ }),
299
+ });
299
300
 
300
- const decode_object = (importer: FunctionImporter) =>
301
+ // COMPOSITION
302
+ if (unions.length === 0) return props.input;
303
+ else if (unions.length === 1 && props.metadata.size() === 1) {
304
+ const value: ts.Expression =
305
+ (props.metadata.nullable || props.metadata.isRequired() === false) &&
306
+ is_instance(props.metadata)
307
+ ? ts.factory.createConditionalExpression(
308
+ props.input,
309
+ undefined,
310
+ unions[0]!.value(),
311
+ undefined,
312
+ props.input,
313
+ )
314
+ : unions[0]!.value();
315
+ return ts.factory.createAsExpression(value, TypeFactory.keyword("any"));
316
+ } else {
317
+ let last: ts.Expression = props.input;
318
+ for (const u of unions.reverse())
319
+ last = ts.factory.createConditionalExpression(
320
+ u.is(),
321
+ undefined,
322
+ u.value(),
323
+ undefined,
324
+ last,
325
+ );
326
+ return ts.factory.createAsExpression(last, TypeFactory.keyword("any"));
327
+ }
328
+ };
329
+
330
+ const decode_object = (props: {
331
+ importer: FunctionImporter;
332
+ input: ts.Expression;
333
+ object: MetadataObject;
334
+ explore: FeatureProgrammer.IExplore;
335
+ }) =>
301
336
  FeatureProgrammer.decode_object({
302
337
  trace: false,
303
338
  path: false,
304
339
  prefix: PREFIX,
305
- })(importer);
306
-
307
- const decode_array =
308
- (config: FeatureProgrammer.IConfig) =>
309
- (importer: FunctionImporter) =>
310
- (
311
- input: ts.Expression,
312
- array: MetadataArray,
313
- explore: FeatureProgrammer.IExplore,
314
- ) =>
315
- array.type.recursive
316
- ? ts.factory.createCallExpression(
317
- ts.factory.createIdentifier(
318
- importer.useLocal(`${config.prefix}a${array.type.index}`),
319
- ),
320
- undefined,
321
- FeatureProgrammer.argumentsArray(config)({
322
- ...explore,
323
- source: "function",
324
- from: "array",
325
- })(input),
326
- )
327
- : decode_array_inline(config)(importer)(input, array, explore);
328
-
329
- const decode_array_inline =
330
- (config: FeatureProgrammer.IConfig) =>
331
- (importer: FunctionImporter) =>
332
- (
333
- input: ts.Expression,
334
- array: MetadataArray,
335
- explore: FeatureProgrammer.IExplore,
336
- ) =>
337
- FeatureProgrammer.decode_array(config)(importer)(CloneJoiner.array)(
338
- input,
339
- array,
340
- explore,
341
- );
340
+ })(props.importer)(props.input, props.object, props.explore);
342
341
 
343
- const decode_tuple =
344
- (project: ITypiaContext) =>
345
- (config: FeatureProgrammer.IConfig) =>
346
- (importer: FunctionImporter) =>
347
- (
348
- input: ts.Expression,
349
- tuple: MetadataTuple,
350
- explore: FeatureProgrammer.IExplore,
351
- ): ts.Expression =>
352
- tuple.type.recursive
353
- ? ts.factory.createCallExpression(
354
- ts.factory.createIdentifier(
355
- importer.useLocal(`${config.prefix}t${tuple.type.index}`),
342
+ const decode_array = (props: {
343
+ config: FeatureProgrammer.IConfig;
344
+ importer: FunctionImporter;
345
+ input: ts.Expression;
346
+ array: MetadataArray;
347
+ explore: FeatureProgrammer.IExplore;
348
+ }) =>
349
+ props.array.type.recursive
350
+ ? ts.factory.createCallExpression(
351
+ ts.factory.createIdentifier(
352
+ props.importer.useLocal(
353
+ `${props.config.prefix}a${props.array.type.index}`,
356
354
  ),
357
- undefined,
358
- FeatureProgrammer.argumentsArray(config)({
359
- ...explore,
360
- source: "function",
361
- })(input),
362
- )
363
- : decode_tuple_inline(project)(config)(importer)(
364
- input,
365
- tuple.type,
366
- explore,
367
- );
368
-
369
- const decode_tuple_inline =
370
- (project: ITypiaContext) =>
371
- (config: FeatureProgrammer.IConfig) =>
372
- (importer: FunctionImporter) =>
373
- (
374
- input: ts.Expression,
375
- tuple: MetadataTupleType,
376
- explore: FeatureProgrammer.IExplore,
377
- ): ts.Expression => {
378
- const elements: ts.Expression[] = tuple.elements
379
- .filter((m) => m.rest === null)
380
- .map((elem, index) =>
381
- decode(project)(config)(importer)(
382
- ts.factory.createElementAccessExpression(input, index),
383
- elem,
384
- {
385
- ...explore,
386
- from: "array",
387
- postfix: explore.postfix.length
388
- ? `${postfix_of_tuple(explore.postfix)}[${index}]"`
389
- : `"[${index}]"`,
390
- },
391
355
  ),
392
- );
393
- const rest = (() => {
394
- if (tuple.elements.length === 0) return null;
395
-
396
- const last: Metadata = tuple.elements.at(-1)!;
397
- const rest: Metadata | null = last.rest;
398
- if (rest === null) return null;
356
+ undefined,
357
+ FeatureProgrammer.argumentsArray(props.config)({
358
+ ...props.explore,
359
+ source: "function",
360
+ from: "array",
361
+ })(props.input),
362
+ )
363
+ : decode_array_inline(props);
399
364
 
400
- return decode(project)(config)(importer)(
401
- ts.factory.createCallExpression(
402
- IdentifierFactory.access(input)("slice"),
403
- undefined,
404
- [ExpressionFactory.number(tuple.elements.length - 1)],
365
+ const decode_array_inline = (props: {
366
+ config: FeatureProgrammer.IConfig;
367
+ importer: FunctionImporter;
368
+ input: ts.Expression;
369
+ array: MetadataArray;
370
+ explore: FeatureProgrammer.IExplore;
371
+ }) =>
372
+ FeatureProgrammer.decode_array(props.config)(props.importer)(
373
+ CloneJoiner.array,
374
+ )(props.input, props.array, props.explore);
375
+
376
+ const decode_tuple = (props: {
377
+ context: ITypiaContext;
378
+ config: FeatureProgrammer.IConfig;
379
+ importer: FunctionImporter;
380
+ input: ts.Expression;
381
+ tuple: MetadataTuple;
382
+ explore: FeatureProgrammer.IExplore;
383
+ }): ts.Expression =>
384
+ props.tuple.type.recursive
385
+ ? ts.factory.createCallExpression(
386
+ ts.factory.createIdentifier(
387
+ props.importer.useLocal(
388
+ `${props.config.prefix}t${props.tuple.type.index}`,
389
+ ),
405
390
  ),
406
- wrap_metadata_rest_tuple(tuple.elements.at(-1)!.rest!),
407
- {
408
- ...explore,
409
- start: tuple.elements.length - 1,
391
+ undefined,
392
+ FeatureProgrammer.argumentsArray(props.config)({
393
+ ...props.explore,
394
+ source: "function",
395
+ })(props.input),
396
+ )
397
+ : decode_tuple_inline({
398
+ ...props,
399
+ tuple: props.tuple.type,
400
+ });
401
+
402
+ const decode_tuple_inline = (props: {
403
+ context: ITypiaContext;
404
+ config: FeatureProgrammer.IConfig;
405
+ importer: FunctionImporter;
406
+ input: ts.Expression;
407
+ tuple: MetadataTupleType;
408
+ explore: FeatureProgrammer.IExplore;
409
+ }): ts.Expression => {
410
+ const elements: ts.Expression[] = props.tuple.elements
411
+ .filter((m) => m.rest === null)
412
+ .map((elem, index) =>
413
+ decode({
414
+ context: props.context,
415
+ config: props.config,
416
+ importer: props.importer,
417
+ input: ts.factory.createElementAccessExpression(props.input, index),
418
+ metadata: elem,
419
+ explore: {
420
+ ...props.explore,
421
+ from: "array",
422
+ postfix: props.explore.postfix.length
423
+ ? `${postfix_of_tuple(props.explore.postfix)}[${index}]"`
424
+ : `"[${index}]"`,
410
425
  },
411
- );
412
- })();
413
- return CloneJoiner.tuple({
414
- elements,
415
- rest,
426
+ }),
427
+ );
428
+ const rest = (() => {
429
+ if (props.tuple.elements.length === 0) return null;
430
+
431
+ const last: Metadata = props.tuple.elements.at(-1)!;
432
+ const rest: Metadata | null = last.rest;
433
+ if (rest === null) return null;
434
+
435
+ return decode({
436
+ context: props.context,
437
+ config: props.config,
438
+ importer: props.importer,
439
+ input: ts.factory.createCallExpression(
440
+ IdentifierFactory.access(props.input)("slice"),
441
+ undefined,
442
+ [ExpressionFactory.number(props.tuple.elements.length - 1)],
443
+ ),
444
+ metadata: wrap_metadata_rest_tuple(props.tuple.elements.at(-1)!.rest!),
445
+ explore: {
446
+ ...props.explore,
447
+ start: props.tuple.elements.length - 1,
448
+ },
416
449
  });
417
- };
450
+ })();
451
+ return CloneJoiner.tuple({
452
+ elements,
453
+ rest,
454
+ });
455
+ };
418
456
 
419
457
  /* -----------------------------------------------------------
420
458
  NATIVE CLASSES
421
459
  ----------------------------------------------------------- */
422
- const decode_native = (type: string) => (input: ts.Expression) =>
423
- type === "Date" ||
424
- type === "Uint8Array" ||
425
- type === "Uint8ClampedArray" ||
426
- type === "Uint16Array" ||
427
- type === "Uint32Array" ||
428
- type === "BigUint64Array" ||
429
- type === "Int8Array" ||
430
- type === "Int16Array" ||
431
- type === "Int32Array" ||
432
- type === "BigInt64Array" ||
433
- type === "Float32Array" ||
434
- type === "Float64Array" ||
435
- type === "RegExp"
436
- ? decode_native_copyable(type)(input)
437
- : type === "ArrayBuffer" || type === "SharedArrayBuffer"
438
- ? decode_native_buffer(type)(input)
439
- : type === "DataView"
440
- ? decode_native_data_view(input)
460
+ const decode_native = (props: { type: string; input: ts.Expression }) =>
461
+ props.type === "Date" ||
462
+ props.type === "Uint8Array" ||
463
+ props.type === "Uint8ClampedArray" ||
464
+ props.type === "Uint16Array" ||
465
+ props.type === "Uint32Array" ||
466
+ props.type === "BigUint64Array" ||
467
+ props.type === "Int8Array" ||
468
+ props.type === "Int16Array" ||
469
+ props.type === "Int32Array" ||
470
+ props.type === "BigInt64Array" ||
471
+ props.type === "Float32Array" ||
472
+ props.type === "Float64Array" ||
473
+ props.type === "RegExp"
474
+ ? decode_native_copyable(props)
475
+ : props.type === "ArrayBuffer" || props.type === "SharedArrayBuffer"
476
+ ? decode_native_buffer({
477
+ type: props.type,
478
+ input: props.input,
479
+ })
480
+ : props.type === "DataView"
481
+ ? decode_native_data_view(props.input)
441
482
  : ts.factory.createCallExpression(
442
- ts.factory.createIdentifier(type),
483
+ ts.factory.createIdentifier(props.type),
443
484
  undefined,
444
485
  [],
445
486
  );
446
487
 
447
- const decode_native_copyable = (type: string) => (input: ts.Expression) =>
488
+ const decode_native_copyable = (props: {
489
+ type: string;
490
+ input: ts.Expression;
491
+ }) =>
448
492
  ts.factory.createNewExpression(
449
- ts.factory.createIdentifier(type),
493
+ ts.factory.createIdentifier(props.type),
450
494
  undefined,
451
- [input],
495
+ [props.input],
452
496
  );
453
497
 
454
- const decode_native_buffer =
455
- (type: "ArrayBuffer" | "SharedArrayBuffer") => (input: ts.Expression) =>
456
- ExpressionFactory.selfCall(
457
- ts.factory.createBlock(
458
- [
459
- StatementFactory.constant(
460
- "buffer",
461
- ts.factory.createNewExpression(
462
- ts.factory.createIdentifier(type),
463
- undefined,
464
- [IdentifierFactory.access(input)("byteLength")],
465
- ),
466
- ),
467
- ts.factory.createExpressionStatement(
468
- ts.factory.createCallExpression(
469
- IdentifierFactory.access(
470
- ts.factory.createNewExpression(
471
- ts.factory.createIdentifier("Uint8Array"),
472
- undefined,
473
- [ts.factory.createIdentifier("buffer")],
474
- ),
475
- )("set"),
476
- undefined,
477
- [
478
- ts.factory.createNewExpression(
479
- ts.factory.createIdentifier("Uint8Array"),
480
- undefined,
481
- [input],
482
- ),
483
- ],
484
- ),
498
+ const decode_native_buffer = (props: {
499
+ type: "ArrayBuffer" | "SharedArrayBuffer";
500
+ input: ts.Expression;
501
+ }) =>
502
+ ExpressionFactory.selfCall(
503
+ ts.factory.createBlock(
504
+ [
505
+ StatementFactory.constant(
506
+ "buffer",
507
+ ts.factory.createNewExpression(
508
+ ts.factory.createIdentifier(props.type),
509
+ undefined,
510
+ [IdentifierFactory.access(props.input)("byteLength")],
485
511
  ),
486
- ts.factory.createReturnStatement(
487
- ts.factory.createIdentifier("buffer"),
512
+ ),
513
+ ts.factory.createExpressionStatement(
514
+ ts.factory.createCallExpression(
515
+ IdentifierFactory.access(
516
+ ts.factory.createNewExpression(
517
+ ts.factory.createIdentifier("Uint8Array"),
518
+ undefined,
519
+ [ts.factory.createIdentifier("buffer")],
520
+ ),
521
+ )("set"),
522
+ undefined,
523
+ [
524
+ ts.factory.createNewExpression(
525
+ ts.factory.createIdentifier("Uint8Array"),
526
+ undefined,
527
+ [props.input],
528
+ ),
529
+ ],
488
530
  ),
489
- ],
490
- true,
491
- ),
492
- );
531
+ ),
532
+ ts.factory.createReturnStatement(
533
+ ts.factory.createIdentifier("buffer"),
534
+ ),
535
+ ],
536
+ true,
537
+ ),
538
+ );
493
539
 
494
540
  const decode_native_data_view = (input: ts.Expression) =>
495
541
  ts.factory.createNewExpression(
@@ -501,242 +547,332 @@ export namespace MiscCloneProgrammer {
501
547
  /* -----------------------------------------------------------
502
548
  EXPLORERS FOR UNION TYPES
503
549
  ----------------------------------------------------------- */
504
- const explore_sets =
505
- (project: ITypiaContext) =>
506
- (config: FeatureProgrammer.IConfig) =>
507
- (importer: FunctionImporter) =>
508
- (
509
- input: ts.Expression,
510
- sets: Metadata[],
511
- explore: FeatureProgrammer.IExplore,
512
- ): ts.Expression =>
513
- ts.factory.createCallExpression(
514
- UnionExplorer.set({
515
- checker: IsProgrammer.decode(project)(importer),
516
- decoder: (input, array, explore) =>
517
- ts.factory.createNewExpression(
518
- ts.factory.createIdentifier("Set"),
519
- [TypeFactory.keyword("any")],
520
- [decode_array(config)(importer)(input, array, explore)],
521
- ),
522
- empty: ts.factory.createNewExpression(
550
+ const explore_sets = (props: {
551
+ context: ITypiaContext;
552
+ config: FeatureProgrammer.IConfig;
553
+ importer: FunctionImporter;
554
+ input: ts.Expression;
555
+ sets: Metadata[];
556
+ explore: FeatureProgrammer.IExplore;
557
+ }): ts.Expression =>
558
+ ts.factory.createCallExpression(
559
+ UnionExplorer.set({
560
+ checker: IsProgrammer.decode(props.context)(props.importer),
561
+ decoder: (input, array, explore) =>
562
+ ts.factory.createNewExpression(
523
563
  ts.factory.createIdentifier("Set"),
524
564
  [TypeFactory.keyword("any")],
525
- [],
565
+ [
566
+ decode_array({
567
+ config: props.config,
568
+ importer: props.importer,
569
+ input,
570
+ array,
571
+ explore,
572
+ }),
573
+ ],
526
574
  ),
527
- success: ts.factory.createTrue(),
528
- failure: (input, expected) =>
529
- create_throw_error(importer)(expected)(input),
530
- })([])(input, sets, explore),
531
- undefined,
532
- undefined,
533
- );
575
+ empty: ts.factory.createNewExpression(
576
+ ts.factory.createIdentifier("Set"),
577
+ [TypeFactory.keyword("any")],
578
+ [],
579
+ ),
580
+ success: ts.factory.createTrue(),
581
+ failure: (input, expected) =>
582
+ create_throw_error({
583
+ importer: props.importer,
584
+ expected,
585
+ input,
586
+ }),
587
+ })([])(props.input, props.sets, props.explore),
588
+ undefined,
589
+ undefined,
590
+ );
534
591
 
535
- const explore_maps =
536
- (project: ITypiaContext) =>
537
- (config: FeatureProgrammer.IConfig) =>
538
- (importer: FunctionImporter) =>
539
- (
540
- input: ts.Expression,
541
- maps: Metadata.Entry[],
542
- explore: FeatureProgrammer.IExplore,
543
- ): ts.Expression =>
544
- ts.factory.createCallExpression(
545
- UnionExplorer.map({
546
- checker: (top, entry, explore) => {
547
- const func = IsProgrammer.decode(project)(importer);
548
- return ts.factory.createLogicalAnd(
549
- func(ts.factory.createElementAccessExpression(top, 0), entry[0], {
550
- ...explore,
551
- postfix: `${explore.postfix}[0]`,
552
- }),
553
- func(ts.factory.createElementAccessExpression(top, 1), entry[1], {
554
- ...explore,
555
- postfix: `${explore.postfix}[1]`,
556
- }),
557
- );
558
- },
559
- decoder: (input, array, explore) =>
560
- ts.factory.createNewExpression(
561
- ts.factory.createIdentifier("Map"),
562
- [TypeFactory.keyword("any"), TypeFactory.keyword("any")],
563
- [decode_array(config)(importer)(input, array, explore)],
564
- ),
565
- empty: ts.factory.createNewExpression(
592
+ const explore_maps = (props: {
593
+ context: ITypiaContext;
594
+ config: FeatureProgrammer.IConfig;
595
+ importer: FunctionImporter;
596
+ input: ts.Expression;
597
+ maps: Metadata.Entry[];
598
+ explore: FeatureProgrammer.IExplore;
599
+ }): ts.Expression =>
600
+ ts.factory.createCallExpression(
601
+ UnionExplorer.map({
602
+ checker: (top, entry, explore) => {
603
+ const func = IsProgrammer.decode(props.context)(props.importer);
604
+ return ts.factory.createLogicalAnd(
605
+ func(ts.factory.createElementAccessExpression(top, 0), entry[0], {
606
+ ...explore,
607
+ postfix: `${explore.postfix}[0]`,
608
+ }),
609
+ func(ts.factory.createElementAccessExpression(top, 1), entry[1], {
610
+ ...explore,
611
+ postfix: `${explore.postfix}[1]`,
612
+ }),
613
+ );
614
+ },
615
+ decoder: (input, array, explore) =>
616
+ ts.factory.createNewExpression(
566
617
  ts.factory.createIdentifier("Map"),
567
618
  [TypeFactory.keyword("any"), TypeFactory.keyword("any")],
568
- [],
619
+ [
620
+ decode_array({
621
+ config: props.config,
622
+ importer: props.importer,
623
+ input,
624
+ array,
625
+ explore,
626
+ }),
627
+ ],
569
628
  ),
570
- success: ts.factory.createTrue(),
571
- failure: (input, expected) =>
572
- create_throw_error(importer)(expected)(input),
573
- })([])(input, maps, explore),
574
- undefined,
575
- undefined,
576
- );
629
+ empty: ts.factory.createNewExpression(
630
+ ts.factory.createIdentifier("Map"),
631
+ [TypeFactory.keyword("any"), TypeFactory.keyword("any")],
632
+ [],
633
+ ),
634
+ success: ts.factory.createTrue(),
635
+ failure: (input, expected) =>
636
+ create_throw_error({
637
+ importer: props.importer,
638
+ expected,
639
+ input,
640
+ }),
641
+ })([])(props.input, props.maps, props.explore),
642
+ undefined,
643
+ undefined,
644
+ );
577
645
 
578
- const explore_objects =
579
- (config: FeatureProgrammer.IConfig) =>
580
- (importer: FunctionImporter) =>
581
- (
582
- input: ts.Expression,
583
- meta: Metadata,
584
- explore: FeatureProgrammer.IExplore,
585
- ) =>
586
- meta.objects.length === 1
587
- ? decode_object(importer)(input, meta.objects[0]!, explore)
588
- : ts.factory.createCallExpression(
589
- ts.factory.createIdentifier(
590
- importer.useLocal(`${PREFIX}u${meta.union_index!}`),
591
- ),
592
- undefined,
593
- FeatureProgrammer.argumentsArray(config)(explore)(input),
594
- );
646
+ const explore_objects = (props: {
647
+ config: FeatureProgrammer.IConfig;
648
+ importer: FunctionImporter;
649
+ input: ts.Expression;
650
+ metadata: Metadata;
651
+ explore: FeatureProgrammer.IExplore;
652
+ }) =>
653
+ props.metadata.objects.length === 1
654
+ ? decode_object({
655
+ ...props,
656
+ object: props.metadata.objects[0]!,
657
+ })
658
+ : ts.factory.createCallExpression(
659
+ ts.factory.createIdentifier(
660
+ props.importer.useLocal(`${PREFIX}u${props.metadata.union_index!}`),
661
+ ),
662
+ undefined,
663
+ FeatureProgrammer.argumentsArray(props.config)(props.explore)(
664
+ props.input,
665
+ ),
666
+ );
595
667
 
596
- const explore_arrays =
597
- (project: ITypiaContext) =>
598
- (config: FeatureProgrammer.IConfig) =>
599
- (importer: FunctionImporter) =>
600
- (
601
- input: ts.Expression,
602
- elements: MetadataArray[],
603
- explore: FeatureProgrammer.IExplore,
604
- ): ts.Expression =>
605
- explore_array_like_union_types(config)(importer)(
668
+ const explore_arrays = (props: {
669
+ context: ITypiaContext;
670
+ config: FeatureProgrammer.IConfig;
671
+ importer: FunctionImporter;
672
+ input: ts.Expression;
673
+ arrays: MetadataArray[];
674
+ explore: FeatureProgrammer.IExplore;
675
+ }): ts.Expression =>
676
+ explore_array_like_union_types({
677
+ ...props,
678
+ elements: props.arrays,
679
+ factory: (next) =>
606
680
  UnionExplorer.array({
607
- checker: IsProgrammer.decode(project)(importer),
608
- decoder: decode_array(config)(importer),
681
+ checker: IsProgrammer.decode(props.context)(props.importer),
682
+ decoder: (input, array, explore) =>
683
+ decode_array({
684
+ config: props.config,
685
+ importer: props.importer,
686
+ input,
687
+ array,
688
+ explore,
689
+ }),
609
690
  empty: ts.factory.createIdentifier("[]"),
610
691
  success: ts.factory.createTrue(),
611
692
  failure: (input, expected) =>
612
- create_throw_error(importer)(expected)(input),
693
+ create_throw_error({
694
+ importer: props.importer,
695
+ expected,
696
+ input,
697
+ }),
698
+ })(next.parameters)(next.input, next.elements, next.explore),
699
+ });
700
+
701
+ const explore_array_like_union_types = <
702
+ T extends MetadataArray | MetadataTuple,
703
+ >(props: {
704
+ config: FeatureProgrammer.IConfig;
705
+ importer: FunctionImporter;
706
+ factory: (next: {
707
+ parameters: ts.ParameterDeclaration[];
708
+ input: ts.Expression;
709
+ elements: T[];
710
+ explore: FeatureProgrammer.IExplore;
711
+ }) => ts.ArrowFunction;
712
+ input: ts.Expression;
713
+ elements: T[];
714
+ explore: FeatureProgrammer.IExplore;
715
+ }): ts.Expression => {
716
+ const arrow = (next: {
717
+ parameters: ts.ParameterDeclaration[];
718
+ explore: FeatureProgrammer.IExplore;
719
+ input: ts.Expression;
720
+ }): ts.ArrowFunction =>
721
+ props.factory({
722
+ elements: props.elements,
723
+ parameters: next.parameters,
724
+ input: next.input,
725
+ explore: next.explore,
726
+ });
727
+ if (props.elements.every((e) => e.type.recursive === false))
728
+ ts.factory.createCallExpression(
729
+ arrow({
730
+ parameters: [],
731
+ explore: props.explore,
732
+ input: props.input,
613
733
  }),
614
- )(input, elements, explore);
615
-
616
- const explore_array_like_union_types =
617
- (config: FeatureProgrammer.IConfig) =>
618
- (importer: FunctionImporter) =>
619
- <T extends MetadataArray | MetadataTuple>(
620
- factory: (
621
- parameters: ts.ParameterDeclaration[],
622
- ) => (
623
- input: ts.Expression,
624
- elements: T[],
625
- explore: FeatureProgrammer.IExplore,
626
- ) => ts.ArrowFunction,
627
- ) =>
628
- (
629
- input: ts.Expression,
630
- elements: T[],
631
- explore: FeatureProgrammer.IExplore,
632
- ): ts.Expression => {
633
- const arrow =
634
- (parameters: ts.ParameterDeclaration[]) =>
635
- (explore: FeatureProgrammer.IExplore) =>
636
- (input: ts.Expression): ts.ArrowFunction =>
637
- factory(parameters)(input, elements, explore);
638
- if (elements.every((e) => e.type.recursive === false))
639
- ts.factory.createCallExpression(
640
- arrow([])(explore)(input),
641
- undefined,
642
- [],
643
- );
734
+ undefined,
735
+ [],
736
+ );
644
737
 
645
- explore = {
646
- ...explore,
647
- source: "function",
648
- from: "array",
649
- };
650
- return ts.factory.createCallExpression(
651
- ts.factory.createIdentifier(
652
- importer.emplaceUnion(
653
- config.prefix,
654
- elements.map((e) => e.type.name).join(" | "),
655
- () =>
656
- arrow(
657
- FeatureProgrammer.parameterDeclarations(config)(
658
- TypeFactory.keyword("any"),
659
- )(ts.factory.createIdentifier("input")),
660
- )({
738
+ const explore: FeatureProgrammer.IExplore = {
739
+ ...props.explore,
740
+ source: "function",
741
+ from: "array",
742
+ };
743
+ return ts.factory.createCallExpression(
744
+ ts.factory.createIdentifier(
745
+ props.importer.emplaceUnion(
746
+ props.config.prefix,
747
+ props.elements.map((e) => e.type.name).join(" | "),
748
+ () =>
749
+ arrow({
750
+ parameters: FeatureProgrammer.parameterDeclarations(props.config)(
751
+ TypeFactory.keyword("any"),
752
+ )(ts.factory.createIdentifier("input")),
753
+ explore: {
661
754
  ...explore,
662
755
  postfix: "",
663
- })(ts.factory.createIdentifier("input")),
664
- ),
756
+ },
757
+ input: ts.factory.createIdentifier("input"),
758
+ }),
665
759
  ),
666
- undefined,
667
- FeatureProgrammer.argumentsArray(config)(explore)(input),
668
- );
669
- };
760
+ ),
761
+ undefined,
762
+ FeatureProgrammer.argumentsArray(props.config)(explore)(props.input),
763
+ );
764
+ };
670
765
 
671
766
  /* -----------------------------------------------------------
672
767
  CONFIGURATIONS
673
768
  ----------------------------------------------------------- */
674
769
  const PREFIX = "$c";
675
770
 
676
- const configure =
677
- (project: ITypiaContext) =>
678
- (importer: FunctionImporter): FeatureProgrammer.IConfig => {
679
- const config: FeatureProgrammer.IConfig = {
680
- types: {
681
- input: (type, name) =>
682
- ts.factory.createTypeReferenceNode(
683
- name ?? TypeFactory.getFullName(project.checker)(type),
771
+ const configure = (props: {
772
+ context: ITypiaContext;
773
+ importer: FunctionImporter;
774
+ }): FeatureProgrammer.IConfig => {
775
+ const config: FeatureProgrammer.IConfig = {
776
+ types: {
777
+ input: (type, name) =>
778
+ ts.factory.createTypeReferenceNode(
779
+ name ?? TypeFactory.getFullName(props.context.checker)(type),
780
+ ),
781
+ output: (type, name) =>
782
+ ts.factory.createImportTypeNode(
783
+ ts.factory.createLiteralTypeNode(
784
+ ts.factory.createStringLiteral("typia"),
684
785
  ),
685
- output: (type, name) =>
686
- ts.factory.createImportTypeNode(
687
- ts.factory.createLiteralTypeNode(
688
- ts.factory.createStringLiteral("typia"),
786
+ undefined,
787
+ ts.factory.createIdentifier("Resolved"),
788
+ [
789
+ ts.factory.createTypeReferenceNode(
790
+ name ?? TypeFactory.getFullName(props.context.checker)(type),
689
791
  ),
690
- undefined,
691
- ts.factory.createIdentifier("Resolved"),
692
- [
693
- ts.factory.createTypeReferenceNode(
694
- name ?? TypeFactory.getFullName(project.checker)(type),
695
- ),
696
- ],
697
- false,
698
- ),
699
- },
700
- prefix: PREFIX,
701
- trace: false,
702
- path: false,
703
- initializer,
704
- decoder: () => decode(project)(config)(importer),
705
- objector: {
706
- checker: () => IsProgrammer.decode(project)(importer),
707
- decoder: () => decode_object(importer),
708
- joiner: CloneJoiner.object,
709
- unionizer: decode_union_object(
710
- IsProgrammer.decode_object(project)(importer),
711
- )(decode_object(importer))((exp) => exp)((input, expected) =>
712
- create_throw_error(importer)(expected)(input),
792
+ ],
793
+ false,
713
794
  ),
714
- failure: (input, expected) =>
715
- create_throw_error(importer)(expected)(input),
716
- },
717
- generator: {
718
- arrays: () => write_array_functions(config)(importer),
719
- tuples: () => write_tuple_functions(project)(config)(importer),
720
- },
721
- };
722
- return config;
795
+ },
796
+ prefix: PREFIX,
797
+ trace: false,
798
+ path: false,
799
+ initializer,
800
+ decoder: () => (input, metadata, explore) =>
801
+ decode({
802
+ context: props.context,
803
+ importer: props.importer,
804
+ config,
805
+ input,
806
+ metadata,
807
+ explore,
808
+ }),
809
+ objector: {
810
+ checker: () => IsProgrammer.decode(props.context)(props.importer),
811
+ decoder: () => (input, object, explore) =>
812
+ decode_object({
813
+ importer: props.importer,
814
+ input,
815
+ object,
816
+ explore,
817
+ }),
818
+ joiner: CloneJoiner.object,
819
+ unionizer: decode_union_object(
820
+ IsProgrammer.decode_object(props.context)(props.importer),
821
+ )((input, object, explore) =>
822
+ decode_object({
823
+ importer: props.importer,
824
+ input,
825
+ object,
826
+ explore,
827
+ }),
828
+ )((exp) => exp)((input, expected) =>
829
+ create_throw_error({
830
+ importer: props.importer,
831
+ expected,
832
+ input,
833
+ }),
834
+ ),
835
+ failure: (input, expected) =>
836
+ create_throw_error({
837
+ importer: props.importer,
838
+ expected,
839
+ input,
840
+ }),
841
+ },
842
+ generator: {
843
+ arrays: () => (collection) =>
844
+ write_array_functions({
845
+ importer: props.importer,
846
+ config,
847
+ collection,
848
+ }),
849
+ tuples: () => (collection) =>
850
+ write_tuple_functions({
851
+ context: props.context,
852
+ importer: props.importer,
853
+ config,
854
+ collection,
855
+ }),
856
+ },
723
857
  };
858
+ return config;
859
+ };
724
860
 
725
861
  const initializer: FeatureProgrammer.IConfig["initializer"] =
726
- (project) => (importer) => (type) => {
862
+ (context) => (importer) => (type) => {
727
863
  const collection = new MetadataCollection();
728
864
  const result = MetadataFactory.analyze({
729
- checker: project.checker,
730
- transformer: project.transformer,
865
+ checker: context.checker,
866
+ transformer: context.transformer,
731
867
  options: {
732
868
  escape: false,
733
869
  constant: true,
734
870
  absorb: true,
735
- validate: (meta) => {
871
+ validate: (metadata) => {
736
872
  const output: string[] = [];
737
- if (meta.natives.some((n) => n === "WeakSet"))
873
+ if (metadata.natives.some((n) => n === "WeakSet"))
738
874
  output.push("unable to clone WeakSet");
739
- else if (meta.natives.some((n) => n === "WeakMap"))
875
+ else if (metadata.natives.some((n) => n === "WeakMap"))
740
876
  output.push("unable to clone WeakMap");
741
877
  return output;
742
878
  },
@@ -751,35 +887,36 @@ export namespace MiscCloneProgrammer {
751
887
  return [collection, result.data];
752
888
  };
753
889
 
754
- const create_throw_error =
755
- (importer: FunctionImporter) =>
756
- (expected: string) =>
757
- (value: ts.Expression) =>
758
- ts.factory.createExpressionStatement(
759
- ts.factory.createCallExpression(
760
- importer.use("throws"),
761
- [],
762
- [
763
- ts.factory.createObjectLiteralExpression(
764
- [
765
- ts.factory.createPropertyAssignment(
766
- "expected",
767
- ts.factory.createStringLiteral(expected),
768
- ),
769
- ts.factory.createPropertyAssignment("value", value),
770
- ],
771
- true,
772
- ),
773
- ],
774
- ),
775
- );
890
+ const create_throw_error = (props: {
891
+ importer: FunctionImporter;
892
+ expected: string;
893
+ input: ts.Expression;
894
+ }) =>
895
+ ts.factory.createExpressionStatement(
896
+ ts.factory.createCallExpression(
897
+ props.importer.use("throws"),
898
+ [],
899
+ [
900
+ ts.factory.createObjectLiteralExpression(
901
+ [
902
+ ts.factory.createPropertyAssignment(
903
+ "expected",
904
+ ts.factory.createStringLiteral(props.expected),
905
+ ),
906
+ ts.factory.createPropertyAssignment("value", props.input),
907
+ ],
908
+ true,
909
+ ),
910
+ ],
911
+ ),
912
+ );
776
913
 
777
- const is_instance = (meta: Metadata): boolean =>
778
- !!meta.objects.length ||
779
- !!meta.arrays.length ||
780
- !!meta.tuples.length ||
781
- !!meta.sets.length ||
782
- !!meta.maps.length ||
783
- !!meta.natives.length ||
784
- (meta.rest !== null && is_instance(meta.rest));
914
+ const is_instance = (metadata: Metadata): boolean =>
915
+ !!metadata.objects.length ||
916
+ !!metadata.arrays.length ||
917
+ !!metadata.tuples.length ||
918
+ !!metadata.sets.length ||
919
+ !!metadata.maps.length ||
920
+ !!metadata.natives.length ||
921
+ (metadata.rest !== null && is_instance(metadata.rest));
785
922
  }