typia 5.2.5 → 5.2.6-dev.20231108

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 (64) hide show
  1. package/lib/factories/ExpressionFactory.d.ts +1 -0
  2. package/lib/factories/ExpressionFactory.js +5 -0
  3. package/lib/factories/ExpressionFactory.js.map +1 -1
  4. package/lib/programmers/CheckerProgrammer.js +4 -4
  5. package/lib/programmers/CheckerProgrammer.js.map +1 -1
  6. package/lib/programmers/RandomProgrammer.js +16 -18
  7. package/lib/programmers/RandomProgrammer.js.map +1 -1
  8. package/lib/programmers/ValidateProgrammer.js +2 -1
  9. package/lib/programmers/ValidateProgrammer.js.map +1 -1
  10. package/lib/programmers/helpers/RandomJoiner.js +4 -6
  11. package/lib/programmers/helpers/RandomJoiner.js.map +1 -1
  12. package/lib/programmers/helpers/RandomRanger.js +3 -2
  13. package/lib/programmers/helpers/RandomRanger.js.map +1 -1
  14. package/lib/programmers/http/HttpHeadersProgrammer.js +1 -1
  15. package/lib/programmers/http/HttpHeadersProgrammer.js.map +1 -1
  16. package/lib/programmers/internal/check_dynamic_properties.js +4 -3
  17. package/lib/programmers/internal/check_dynamic_properties.js.map +1 -1
  18. package/lib/programmers/internal/check_union_array_like.js +3 -2
  19. package/lib/programmers/internal/check_union_array_like.js.map +1 -1
  20. package/lib/programmers/json/JsonStringifyProgrammer.js +1 -3
  21. package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
  22. package/lib/programmers/misc/MiscCloneProgrammer.js +1 -3
  23. package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
  24. package/lib/programmers/misc/MiscLiteralsProgrammer.js +1 -1
  25. package/lib/programmers/misc/MiscLiteralsProgrammer.js.map +1 -1
  26. package/lib/programmers/misc/MiscPruneProgrammer.js +1 -3
  27. package/lib/programmers/misc/MiscPruneProgrammer.js.map +1 -1
  28. package/lib/programmers/notations/NotationGeneralProgrammer.js +1 -3
  29. package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
  30. package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js +6 -6
  31. package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js.map +1 -1
  32. package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js +2 -2
  33. package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js.map +1 -1
  34. package/package.json +1 -1
  35. package/src/Primitive.ts +135 -135
  36. package/src/executable/TypiaSetupWizard.ts +142 -142
  37. package/src/executable/setup/CommandExecutor.ts +8 -8
  38. package/src/factories/ExpressionFactory.ts +8 -0
  39. package/src/factories/JsonMetadataFactory.ts +50 -50
  40. package/src/factories/MetadataCollection.ts +282 -282
  41. package/src/factories/internal/metadata/emplace_metadata_object.ts +178 -178
  42. package/src/functional/$stoll.ts +8 -8
  43. package/src/functional/Namespace.ts +168 -168
  44. package/src/programmers/AssertProgrammer.ts +322 -322
  45. package/src/programmers/CheckerProgrammer.ts +4 -4
  46. package/src/programmers/IsProgrammer.ts +258 -258
  47. package/src/programmers/RandomProgrammer.ts +16 -17
  48. package/src/programmers/ValidateProgrammer.ts +350 -349
  49. package/src/programmers/helpers/AtomicPredicator.ts +31 -31
  50. package/src/programmers/helpers/RandomJoiner.ts +4 -6
  51. package/src/programmers/helpers/RandomRanger.ts +4 -2
  52. package/src/programmers/http/HttpHeadersProgrammer.ts +1 -1
  53. package/src/programmers/internal/check_dynamic_key.ts +178 -178
  54. package/src/programmers/internal/check_dynamic_properties.ts +202 -201
  55. package/src/programmers/internal/check_object.ts +62 -62
  56. package/src/programmers/internal/check_union_array_like.ts +4 -3
  57. package/src/programmers/json/JsonStringifyProgrammer.ts +960 -964
  58. package/src/programmers/misc/MiscCloneProgrammer.ts +786 -790
  59. package/src/programmers/misc/MiscLiteralsProgrammer.ts +1 -1
  60. package/src/programmers/misc/MiscPruneProgrammer.ts +548 -552
  61. package/src/programmers/notations/NotationGeneralProgrammer.ts +716 -720
  62. package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +7 -9
  63. package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +882 -882
  64. package/src/transform.ts +35 -35
@@ -1,720 +1,716 @@
1
- import ts from "typescript";
2
-
3
- import { ExpressionFactory } from "../../factories/ExpressionFactory";
4
- import { IdentifierFactory } from "../../factories/IdentifierFactory";
5
- import { MetadataCollection } from "../../factories/MetadataCollection";
6
- import { MetadataFactory } from "../../factories/MetadataFactory";
7
- import { StatementFactory } from "../../factories/StatementFactory";
8
- import { TypeFactory } from "../../factories/TypeFactory";
9
-
10
- import { Metadata } from "../../schemas/metadata/Metadata";
11
- import { MetadataArray } from "../../schemas/metadata/MetadataArray";
12
- import { MetadataTuple } from "../../schemas/metadata/MetadataTuple";
13
- import { MetadataTupleType } from "../../schemas/metadata/MetadataTupleType";
14
-
15
- import { IProject } from "../../transformers/IProject";
16
- import { TransformerError } from "../../transformers/TransformerError";
17
-
18
- import { StringUtil } from "../../utils/StringUtil";
19
-
20
- import { FeatureProgrammer } from "../FeatureProgrammer";
21
- import { IsProgrammer } from "../IsProgrammer";
22
- import { FunctionImporter } from "../helpers/FunctionImporeter";
23
- import { NotationJoiner } from "../helpers/NotationJoiner";
24
- import { UnionExplorer } from "../helpers/UnionExplorer";
25
- import { decode_union_object } from "../internal/decode_union_object";
26
- import { wrap_metadata_rest_tuple } from "../internal/wrap_metadata_rest_tuple";
27
-
28
- export namespace NotationGeneralProgrammer {
29
- export const returnType =
30
- (rename: (str: string) => string) => (type: string) =>
31
- `typia.${StringUtil.capitalize(rename.name)}Case<${type}>`;
32
-
33
- export const write =
34
- (rename: (str: string) => string) =>
35
- (project: IProject) =>
36
- (modulo: ts.LeftHandSideExpression) => {
37
- const importer: FunctionImporter = new FunctionImporter(
38
- modulo.getText(),
39
- );
40
- return FeatureProgrammer.write(project)({
41
- ...configure(rename)(project)(importer),
42
- addition: (collection) => [
43
- ...IsProgrammer.write_function_statements(project)(
44
- importer,
45
- )(collection),
46
- ...importer.declare(modulo),
47
- ],
48
- })(importer);
49
- };
50
-
51
- const write_array_functions =
52
- (config: FeatureProgrammer.IConfig) =>
53
- (importer: FunctionImporter) =>
54
- (collection: MetadataCollection): ts.VariableStatement[] =>
55
- collection
56
- .arrays()
57
- .filter((a) => a.recursive)
58
- .map((type, i) =>
59
- StatementFactory.constant(
60
- `${config.prefix}a${i}`,
61
- ts.factory.createArrowFunction(
62
- undefined,
63
- undefined,
64
- FeatureProgrammer.parameterDeclarations(config)(
65
- TypeFactory.keyword("any"),
66
- )(ts.factory.createIdentifier("input")),
67
- TypeFactory.keyword("any"),
68
- undefined,
69
- decode_array_inline(config)(importer)(
70
- ts.factory.createIdentifier("input"),
71
- MetadataArray.create({
72
- type,
73
- tags: [],
74
- }),
75
- {
76
- tracable: config.trace,
77
- source: "function",
78
- from: "array",
79
- postfix: "",
80
- },
81
- ),
82
- ),
83
- ),
84
- );
85
-
86
- const write_tuple_functions =
87
- (project: IProject) =>
88
- (config: FeatureProgrammer.IConfig) =>
89
- (importer: FunctionImporter) =>
90
- (collection: MetadataCollection): ts.VariableStatement[] =>
91
- collection
92
- .tuples()
93
- .filter((t) => t.recursive)
94
- .map((tuple, i) =>
95
- StatementFactory.constant(
96
- `${config.prefix}t${i}`,
97
- ts.factory.createArrowFunction(
98
- undefined,
99
- undefined,
100
- FeatureProgrammer.parameterDeclarations(config)(
101
- TypeFactory.keyword("any"),
102
- )(ts.factory.createIdentifier("input")),
103
- TypeFactory.keyword("any"),
104
- undefined,
105
- decode_tuple_inline(project)(config)(importer)(
106
- ts.factory.createIdentifier("input"),
107
- tuple,
108
- {
109
- tracable: config.trace,
110
- source: "function",
111
- from: "array",
112
- postfix: "",
113
- },
114
- ),
115
- ),
116
- ),
117
- );
118
-
119
- /* -----------------------------------------------------------
120
- DECODERS
121
- ----------------------------------------------------------- */
122
- const decode =
123
- (project: IProject) =>
124
- (config: FeatureProgrammer.IConfig) =>
125
- (importer: FunctionImporter) =>
126
- (
127
- input: ts.Expression,
128
- meta: Metadata,
129
- explore: FeatureProgrammer.IExplore,
130
- ): ts.Expression => {
131
- // ANY TYPE
132
- if (
133
- meta.any ||
134
- meta.arrays.some((a) => a.type.value.any) ||
135
- meta.tuples.some(
136
- (t) =>
137
- !!t.type.elements.length &&
138
- t.type.elements.every((e) => e.any),
139
- )
140
- )
141
- return ts.factory.createCallExpression(
142
- importer.use("any"),
143
- undefined,
144
- [input],
145
- );
146
-
147
- interface IUnion {
148
- type: string;
149
- is: () => ts.Expression;
150
- value: () => ts.Expression;
151
- }
152
- const unions: IUnion[] = [];
153
-
154
- //----
155
- // LIST UP UNION TYPES
156
- //----
157
- // FUNCTIONAL
158
- if (meta.functional)
159
- unions.push({
160
- type: "functional",
161
- is: () =>
162
- ts.factory.createStrictEquality(
163
- ts.factory.createStringLiteral("function"),
164
- ts.factory.createTypeOfExpression(input),
165
- ),
166
- value: () => ts.factory.createIdentifier("undefined"),
167
- });
168
-
169
- // TUPLES
170
- for (const tuple of meta.tuples)
171
- unions.push({
172
- type: "tuple",
173
- is: () =>
174
- IsProgrammer.decode(project)(importer)(
175
- input,
176
- (() => {
177
- const partial = Metadata.initialize();
178
- partial.tuples.push(tuple);
179
- return partial;
180
- })(),
181
- explore,
182
- ),
183
- value: () =>
184
- decode_tuple(project)(config)(importer)(
185
- input,
186
- tuple,
187
- explore,
188
- ),
189
- });
190
-
191
- // ARRAYS
192
- if (meta.arrays.length)
193
- unions.push({
194
- type: "array",
195
- is: () => ExpressionFactory.isArray(input),
196
- value: () =>
197
- explore_arrays(project)(config)(importer)(
198
- input,
199
- meta.arrays,
200
- {
201
- ...explore,
202
- from: "array",
203
- },
204
- ),
205
- });
206
-
207
- // NATIVE TYPES
208
- if (meta.sets.length)
209
- unions.push({
210
- type: "set",
211
- is: () => ExpressionFactory.isInstanceOf("Set")(input),
212
- value: () =>
213
- explore_sets(project)(config)(importer)(
214
- input,
215
- meta.sets,
216
- { ...explore, from: "array" },
217
- ),
218
- });
219
- if (meta.maps.length)
220
- unions.push({
221
- type: "map",
222
- is: () => ExpressionFactory.isInstanceOf("Map")(input),
223
- value: () =>
224
- explore_maps(project)(config)(importer)(
225
- input,
226
- meta.maps,
227
- {
228
- ...explore,
229
- from: "array",
230
- },
231
- ),
232
- });
233
- for (const native of meta.natives) {
234
- if (native === "WeakSet" || native === "WeakMap") continue;
235
- unions.push({
236
- type: "native",
237
- is: () => ExpressionFactory.isInstanceOf(native)(input),
238
- value: () =>
239
- native === "Boolean" ||
240
- native === "Number" ||
241
- native === "String"
242
- ? ts.factory.createCallExpression(
243
- IdentifierFactory.access(input)("valueOf"),
244
- undefined,
245
- undefined,
246
- )
247
- : decode_native(native)(input),
248
- });
249
- }
250
-
251
- // OBJECTS
252
- if (meta.objects.length)
253
- unions.push({
254
- type: "object",
255
- is: () =>
256
- ExpressionFactory.isObject({
257
- checkNull: true,
258
- checkArray: false,
259
- })(input),
260
- value: () =>
261
- explore_objects(config)(importer)(input, meta, {
262
- ...explore,
263
- from: "object",
264
- }),
265
- });
266
-
267
- // COMPOSITION
268
- let last: ts.Expression = input;
269
- for (const u of unions.reverse())
270
- last = ts.factory.createConditionalExpression(
271
- u.is(),
272
- undefined,
273
- u.value(),
274
- undefined,
275
- last,
276
- );
277
- return ts.factory.createAsExpression(
278
- last,
279
- TypeFactory.keyword("any"),
280
- );
281
- };
282
-
283
- const decode_object = (importer: FunctionImporter) =>
284
- FeatureProgrammer.decode_object({
285
- trace: false,
286
- path: false,
287
- prefix: PREFIX,
288
- })(importer);
289
-
290
- const decode_array =
291
- (config: FeatureProgrammer.IConfig) =>
292
- (importer: FunctionImporter) =>
293
- (
294
- input: ts.Expression,
295
- array: MetadataArray,
296
- explore: FeatureProgrammer.IExplore,
297
- ) =>
298
- array.type.recursive
299
- ? ts.factory.createCallExpression(
300
- ts.factory.createIdentifier(
301
- importer.useLocal(
302
- `${config.prefix}a${array.type.index}`,
303
- ),
304
- ),
305
- undefined,
306
- FeatureProgrammer.argumentsArray(config)({
307
- ...explore,
308
- source: "function",
309
- from: "array",
310
- })(input),
311
- )
312
- : decode_array_inline(config)(importer)(input, array, explore);
313
-
314
- const decode_array_inline =
315
- (config: FeatureProgrammer.IConfig) =>
316
- (importer: FunctionImporter) =>
317
- (
318
- input: ts.Expression,
319
- array: MetadataArray,
320
- explore: FeatureProgrammer.IExplore,
321
- ) =>
322
- FeatureProgrammer.decode_array(config)(importer)(
323
- NotationJoiner.array,
324
- )(input, array, explore);
325
-
326
- const decode_tuple =
327
- (project: IProject) =>
328
- (config: FeatureProgrammer.IConfig) =>
329
- (importer: FunctionImporter) =>
330
- (
331
- input: ts.Expression,
332
- tuple: MetadataTuple,
333
- explore: FeatureProgrammer.IExplore,
334
- ): ts.Expression =>
335
- tuple.type.recursive
336
- ? ts.factory.createCallExpression(
337
- ts.factory.createIdentifier(
338
- importer.useLocal(
339
- `${config.prefix}t${tuple.type.index}`,
340
- ),
341
- ),
342
- undefined,
343
- FeatureProgrammer.argumentsArray(config)({
344
- ...explore,
345
- source: "function",
346
- })(input),
347
- )
348
- : decode_tuple_inline(project)(config)(importer)(
349
- input,
350
- tuple.type,
351
- explore,
352
- );
353
-
354
- const decode_tuple_inline =
355
- (project: IProject) =>
356
- (config: FeatureProgrammer.IConfig) =>
357
- (importer: FunctionImporter) =>
358
- (
359
- input: ts.Expression,
360
- tuple: MetadataTupleType,
361
- explore: FeatureProgrammer.IExplore,
362
- ): ts.Expression => {
363
- const children: ts.Expression[] = tuple.elements
364
- .filter((m) => m.rest === null)
365
- .map((elem, index) =>
366
- decode(project)(config)(importer)(
367
- ts.factory.createElementAccessExpression(input, index),
368
- elem,
369
- {
370
- ...explore,
371
- from: "array",
372
- postfix: explore.postfix.length
373
- ? `${explore.postfix.slice(0, -1)}[${index}]"`
374
- : `"[${index}]"`,
375
- },
376
- ),
377
- );
378
- const rest = (() => {
379
- if (tuple.elements.length === 0) return null;
380
-
381
- const last: Metadata = tuple.elements.at(-1)!;
382
- const rest: Metadata | null = last.rest;
383
- if (rest === null) return null;
384
-
385
- return decode(project)(config)(importer)(
386
- ts.factory.createCallExpression(
387
- IdentifierFactory.access(input)("slice"),
388
- undefined,
389
- [
390
- ts.factory.createNumericLiteral(
391
- tuple.elements.length - 1,
392
- ),
393
- ],
394
- ),
395
- wrap_metadata_rest_tuple(tuple.elements.at(-1)!.rest!),
396
- {
397
- ...explore,
398
- start: tuple.elements.length - 1,
399
- },
400
- );
401
- })();
402
- return NotationJoiner.tuple(children, rest);
403
- };
404
-
405
- /* -----------------------------------------------------------
406
- NATIVE CLASSES
407
- ----------------------------------------------------------- */
408
- const decode_native = (type: string) => (input: ts.Expression) =>
409
- type === "Date"
410
- ? ts.factory.createNewExpression(
411
- ts.factory.createIdentifier(type),
412
- undefined,
413
- [input],
414
- )
415
- : input;
416
-
417
- /* -----------------------------------------------------------
418
- EXPLORERS FOR UNION TYPES
419
- ----------------------------------------------------------- */
420
- const explore_sets =
421
- (project: IProject) =>
422
- (config: FeatureProgrammer.IConfig) =>
423
- (importer: FunctionImporter) =>
424
- (
425
- input: ts.Expression,
426
- sets: Metadata[],
427
- explore: FeatureProgrammer.IExplore,
428
- ): ts.Expression =>
429
- ts.factory.createCallExpression(
430
- UnionExplorer.set({
431
- checker: IsProgrammer.decode(project)(importer),
432
- decoder: (input, array, explore) =>
433
- ts.factory.createNewExpression(
434
- ts.factory.createIdentifier("Set"),
435
- [TypeFactory.keyword("any")],
436
- [
437
- decode_array(config)(importer)(
438
- input,
439
- array,
440
- explore,
441
- ),
442
- ],
443
- ),
444
- empty: ts.factory.createNewExpression(
445
- ts.factory.createIdentifier("Set"),
446
- [TypeFactory.keyword("any")],
447
- [],
448
- ),
449
- success: ts.factory.createTrue(),
450
- failure: (input, expected) =>
451
- create_throw_error(importer)(expected)(input),
452
- })([])(input, sets, explore),
453
- undefined,
454
- undefined,
455
- );
456
-
457
- const explore_maps =
458
- (project: IProject) =>
459
- (config: FeatureProgrammer.IConfig) =>
460
- (importer: FunctionImporter) =>
461
- (
462
- input: ts.Expression,
463
- maps: Metadata.Entry[],
464
- explore: FeatureProgrammer.IExplore,
465
- ): ts.Expression =>
466
- ts.factory.createCallExpression(
467
- UnionExplorer.map({
468
- checker: (top, entry, explore) => {
469
- const func = IsProgrammer.decode(project)(importer);
470
- return ts.factory.createLogicalAnd(
471
- func(
472
- ts.factory.createElementAccessExpression(
473
- top,
474
- 0,
475
- ),
476
- entry[0],
477
- {
478
- ...explore,
479
- postfix: `${explore.postfix}[0]`,
480
- },
481
- ),
482
- func(
483
- ts.factory.createElementAccessExpression(
484
- top,
485
- 1,
486
- ),
487
- entry[1],
488
- {
489
- ...explore,
490
- postfix: `${explore.postfix}[1]`,
491
- },
492
- ),
493
- );
494
- },
495
- decoder: (input, array, explore) =>
496
- ts.factory.createNewExpression(
497
- ts.factory.createIdentifier("Map"),
498
- [
499
- TypeFactory.keyword("any"),
500
- TypeFactory.keyword("any"),
501
- ],
502
- [
503
- decode_array(config)(importer)(
504
- input,
505
- array,
506
- explore,
507
- ),
508
- ],
509
- ),
510
- empty: ts.factory.createNewExpression(
511
- ts.factory.createIdentifier("Map"),
512
- [
513
- TypeFactory.keyword("any"),
514
- TypeFactory.keyword("any"),
515
- ],
516
- [],
517
- ),
518
- success: ts.factory.createTrue(),
519
- failure: (input, expected) =>
520
- create_throw_error(importer)(expected)(input),
521
- })([])(input, maps, explore),
522
- undefined,
523
- undefined,
524
- );
525
-
526
- const explore_objects =
527
- (config: FeatureProgrammer.IConfig) =>
528
- (importer: FunctionImporter) =>
529
- (
530
- input: ts.Expression,
531
- meta: Metadata,
532
- explore: FeatureProgrammer.IExplore,
533
- ) => {
534
- if (meta.objects.length === 1)
535
- return decode_object(importer)(
536
- input,
537
- meta.objects[0]!,
538
- explore,
539
- );
540
-
541
- return ts.factory.createCallExpression(
542
- ts.factory.createIdentifier(
543
- importer.useLocal(`${PREFIX}u${meta.union_index!}`),
544
- ),
545
- undefined,
546
- FeatureProgrammer.argumentsArray(config)(explore)(input),
547
- );
548
- };
549
-
550
- const explore_arrays =
551
- (project: IProject) =>
552
- (config: FeatureProgrammer.IConfig) =>
553
- (importer: FunctionImporter) =>
554
- (
555
- input: ts.Expression,
556
- elements: MetadataArray[],
557
- explore: FeatureProgrammer.IExplore,
558
- ): ts.Expression =>
559
- explore_array_like_union_types(config)(importer)(
560
- UnionExplorer.array({
561
- checker: IsProgrammer.decode(project)(importer),
562
- decoder: decode_array(config)(importer),
563
- empty: ts.factory.createIdentifier("[]"),
564
- success: ts.factory.createTrue(),
565
- failure: (input, expected) =>
566
- create_throw_error(importer)(expected)(input),
567
- }),
568
- )(input, elements, explore);
569
-
570
- const explore_array_like_union_types =
571
- (config: FeatureProgrammer.IConfig) =>
572
- (importer: FunctionImporter) =>
573
- <T extends MetadataArray | MetadataTuple>(
574
- factory: (
575
- parameters: ts.ParameterDeclaration[],
576
- ) => (
577
- input: ts.Expression,
578
- elements: T[],
579
- explore: FeatureProgrammer.IExplore,
580
- ) => ts.ArrowFunction,
581
- ) =>
582
- (
583
- input: ts.Expression,
584
- elements: T[],
585
- explore: FeatureProgrammer.IExplore,
586
- ): ts.Expression => {
587
- const arrow =
588
- (parameters: ts.ParameterDeclaration[]) =>
589
- (explore: FeatureProgrammer.IExplore) =>
590
- (input: ts.Expression): ts.ArrowFunction =>
591
- factory(parameters)(input, elements, explore);
592
- if (elements.every((e) => e.type.recursive === false))
593
- ts.factory.createCallExpression(
594
- arrow([])(explore)(input),
595
- undefined,
596
- [],
597
- );
598
-
599
- explore = {
600
- ...explore,
601
- source: "function",
602
- from: "array",
603
- };
604
- return ts.factory.createCallExpression(
605
- ts.factory.createIdentifier(
606
- importer.emplaceUnion(
607
- config.prefix,
608
- elements.map((e) => e.type.name).join(" | "),
609
- () =>
610
- arrow(
611
- FeatureProgrammer.parameterDeclarations(config)(
612
- TypeFactory.keyword("any"),
613
- )(ts.factory.createIdentifier("input")),
614
- )({
615
- ...explore,
616
- postfix: "",
617
- })(ts.factory.createIdentifier("input")),
618
- ),
619
- ),
620
- undefined,
621
- FeatureProgrammer.argumentsArray(config)(explore)(input),
622
- );
623
- };
624
-
625
- /* -----------------------------------------------------------
626
- CONFIGURATIONS
627
- ----------------------------------------------------------- */
628
- const PREFIX = "$c";
629
-
630
- const configure =
631
- (rename: (str: string) => string) =>
632
- (project: IProject) =>
633
- (importer: FunctionImporter): FeatureProgrammer.IConfig => {
634
- const config: FeatureProgrammer.IConfig = {
635
- types: {
636
- input: (type, name) =>
637
- ts.factory.createTypeReferenceNode(
638
- name ??
639
- TypeFactory.getFullName(project.checker)(type),
640
- ),
641
- output: (type, name) =>
642
- ts.factory.createTypeReferenceNode(
643
- returnType(rename)(
644
- name ??
645
- TypeFactory.getFullName(project.checker)(
646
- type,
647
- ),
648
- ),
649
- ),
650
- },
651
- prefix: PREFIX,
652
- trace: false,
653
- path: false,
654
- initializer,
655
- decoder: () => decode(project)(config)(importer),
656
- objector: {
657
- checker: () => IsProgrammer.decode(project)(importer),
658
- decoder: () => decode_object(importer),
659
- joiner: NotationJoiner.object(rename),
660
- unionizer: decode_union_object(
661
- IsProgrammer.decode_object(project)(importer),
662
- )(decode_object(importer))((exp) => exp)(
663
- (input, expected) =>
664
- create_throw_error(importer)(expected)(input),
665
- ),
666
- failure: (input, expected) =>
667
- create_throw_error(importer)(expected)(input),
668
- },
669
- generator: {
670
- arrays: () => write_array_functions(config)(importer),
671
- tuples: () =>
672
- write_tuple_functions(project)(config)(importer),
673
- },
674
- };
675
- return config;
676
- };
677
-
678
- const initializer: FeatureProgrammer.IConfig["initializer"] =
679
- ({ checker }) =>
680
- (importer) =>
681
- (type) => {
682
- const collection = new MetadataCollection();
683
- const result = MetadataFactory.analyze(checker)({
684
- escape: false,
685
- constant: true,
686
- absorb: true,
687
- })(collection)(type);
688
- if (result.success === false)
689
- throw TransformerError.from(`typia.misc.${importer.method}`)(
690
- result.errors,
691
- );
692
- return [collection, result.data];
693
- };
694
-
695
- const create_throw_error =
696
- (importer: FunctionImporter) =>
697
- (expected: string) =>
698
- (value: ts.Expression) =>
699
- ts.factory.createExpressionStatement(
700
- ts.factory.createCallExpression(
701
- importer.use("throws"),
702
- [],
703
- [
704
- ts.factory.createObjectLiteralExpression(
705
- [
706
- ts.factory.createPropertyAssignment(
707
- "expected",
708
- ts.factory.createStringLiteral(expected),
709
- ),
710
- ts.factory.createPropertyAssignment(
711
- "value",
712
- value,
713
- ),
714
- ],
715
- true,
716
- ),
717
- ],
718
- ),
719
- );
720
- }
1
+ import ts from "typescript";
2
+
3
+ import { ExpressionFactory } from "../../factories/ExpressionFactory";
4
+ import { IdentifierFactory } from "../../factories/IdentifierFactory";
5
+ import { MetadataCollection } from "../../factories/MetadataCollection";
6
+ import { MetadataFactory } from "../../factories/MetadataFactory";
7
+ import { StatementFactory } from "../../factories/StatementFactory";
8
+ import { TypeFactory } from "../../factories/TypeFactory";
9
+
10
+ import { Metadata } from "../../schemas/metadata/Metadata";
11
+ import { MetadataArray } from "../../schemas/metadata/MetadataArray";
12
+ import { MetadataTuple } from "../../schemas/metadata/MetadataTuple";
13
+ import { MetadataTupleType } from "../../schemas/metadata/MetadataTupleType";
14
+
15
+ import { IProject } from "../../transformers/IProject";
16
+ import { TransformerError } from "../../transformers/TransformerError";
17
+
18
+ import { StringUtil } from "../../utils/StringUtil";
19
+
20
+ import { FeatureProgrammer } from "../FeatureProgrammer";
21
+ import { IsProgrammer } from "../IsProgrammer";
22
+ import { FunctionImporter } from "../helpers/FunctionImporeter";
23
+ import { NotationJoiner } from "../helpers/NotationJoiner";
24
+ import { UnionExplorer } from "../helpers/UnionExplorer";
25
+ import { decode_union_object } from "../internal/decode_union_object";
26
+ import { wrap_metadata_rest_tuple } from "../internal/wrap_metadata_rest_tuple";
27
+
28
+ export namespace NotationGeneralProgrammer {
29
+ export const returnType =
30
+ (rename: (str: string) => string) => (type: string) =>
31
+ `typia.${StringUtil.capitalize(rename.name)}Case<${type}>`;
32
+
33
+ export const write =
34
+ (rename: (str: string) => string) =>
35
+ (project: IProject) =>
36
+ (modulo: ts.LeftHandSideExpression) => {
37
+ const importer: FunctionImporter = new FunctionImporter(
38
+ modulo.getText(),
39
+ );
40
+ return FeatureProgrammer.write(project)({
41
+ ...configure(rename)(project)(importer),
42
+ addition: (collection) => [
43
+ ...IsProgrammer.write_function_statements(project)(
44
+ importer,
45
+ )(collection),
46
+ ...importer.declare(modulo),
47
+ ],
48
+ })(importer);
49
+ };
50
+
51
+ const write_array_functions =
52
+ (config: FeatureProgrammer.IConfig) =>
53
+ (importer: FunctionImporter) =>
54
+ (collection: MetadataCollection): ts.VariableStatement[] =>
55
+ collection
56
+ .arrays()
57
+ .filter((a) => a.recursive)
58
+ .map((type, i) =>
59
+ StatementFactory.constant(
60
+ `${config.prefix}a${i}`,
61
+ ts.factory.createArrowFunction(
62
+ undefined,
63
+ undefined,
64
+ FeatureProgrammer.parameterDeclarations(config)(
65
+ TypeFactory.keyword("any"),
66
+ )(ts.factory.createIdentifier("input")),
67
+ TypeFactory.keyword("any"),
68
+ undefined,
69
+ decode_array_inline(config)(importer)(
70
+ ts.factory.createIdentifier("input"),
71
+ MetadataArray.create({
72
+ type,
73
+ tags: [],
74
+ }),
75
+ {
76
+ tracable: config.trace,
77
+ source: "function",
78
+ from: "array",
79
+ postfix: "",
80
+ },
81
+ ),
82
+ ),
83
+ ),
84
+ );
85
+
86
+ const write_tuple_functions =
87
+ (project: IProject) =>
88
+ (config: FeatureProgrammer.IConfig) =>
89
+ (importer: FunctionImporter) =>
90
+ (collection: MetadataCollection): ts.VariableStatement[] =>
91
+ collection
92
+ .tuples()
93
+ .filter((t) => t.recursive)
94
+ .map((tuple, i) =>
95
+ StatementFactory.constant(
96
+ `${config.prefix}t${i}`,
97
+ ts.factory.createArrowFunction(
98
+ undefined,
99
+ undefined,
100
+ FeatureProgrammer.parameterDeclarations(config)(
101
+ TypeFactory.keyword("any"),
102
+ )(ts.factory.createIdentifier("input")),
103
+ TypeFactory.keyword("any"),
104
+ undefined,
105
+ decode_tuple_inline(project)(config)(importer)(
106
+ ts.factory.createIdentifier("input"),
107
+ tuple,
108
+ {
109
+ tracable: config.trace,
110
+ source: "function",
111
+ from: "array",
112
+ postfix: "",
113
+ },
114
+ ),
115
+ ),
116
+ ),
117
+ );
118
+
119
+ /* -----------------------------------------------------------
120
+ DECODERS
121
+ ----------------------------------------------------------- */
122
+ const decode =
123
+ (project: IProject) =>
124
+ (config: FeatureProgrammer.IConfig) =>
125
+ (importer: FunctionImporter) =>
126
+ (
127
+ input: ts.Expression,
128
+ meta: Metadata,
129
+ explore: FeatureProgrammer.IExplore,
130
+ ): ts.Expression => {
131
+ // ANY TYPE
132
+ if (
133
+ meta.any ||
134
+ meta.arrays.some((a) => a.type.value.any) ||
135
+ meta.tuples.some(
136
+ (t) =>
137
+ !!t.type.elements.length &&
138
+ t.type.elements.every((e) => e.any),
139
+ )
140
+ )
141
+ return ts.factory.createCallExpression(
142
+ importer.use("any"),
143
+ undefined,
144
+ [input],
145
+ );
146
+
147
+ interface IUnion {
148
+ type: string;
149
+ is: () => ts.Expression;
150
+ value: () => ts.Expression;
151
+ }
152
+ const unions: IUnion[] = [];
153
+
154
+ //----
155
+ // LIST UP UNION TYPES
156
+ //----
157
+ // FUNCTIONAL
158
+ if (meta.functional)
159
+ unions.push({
160
+ type: "functional",
161
+ is: () =>
162
+ ts.factory.createStrictEquality(
163
+ ts.factory.createStringLiteral("function"),
164
+ ts.factory.createTypeOfExpression(input),
165
+ ),
166
+ value: () => ts.factory.createIdentifier("undefined"),
167
+ });
168
+
169
+ // TUPLES
170
+ for (const tuple of meta.tuples)
171
+ unions.push({
172
+ type: "tuple",
173
+ is: () =>
174
+ IsProgrammer.decode(project)(importer)(
175
+ input,
176
+ (() => {
177
+ const partial = Metadata.initialize();
178
+ partial.tuples.push(tuple);
179
+ return partial;
180
+ })(),
181
+ explore,
182
+ ),
183
+ value: () =>
184
+ decode_tuple(project)(config)(importer)(
185
+ input,
186
+ tuple,
187
+ explore,
188
+ ),
189
+ });
190
+
191
+ // ARRAYS
192
+ if (meta.arrays.length)
193
+ unions.push({
194
+ type: "array",
195
+ is: () => ExpressionFactory.isArray(input),
196
+ value: () =>
197
+ explore_arrays(project)(config)(importer)(
198
+ input,
199
+ meta.arrays,
200
+ {
201
+ ...explore,
202
+ from: "array",
203
+ },
204
+ ),
205
+ });
206
+
207
+ // NATIVE TYPES
208
+ if (meta.sets.length)
209
+ unions.push({
210
+ type: "set",
211
+ is: () => ExpressionFactory.isInstanceOf("Set")(input),
212
+ value: () =>
213
+ explore_sets(project)(config)(importer)(
214
+ input,
215
+ meta.sets,
216
+ { ...explore, from: "array" },
217
+ ),
218
+ });
219
+ if (meta.maps.length)
220
+ unions.push({
221
+ type: "map",
222
+ is: () => ExpressionFactory.isInstanceOf("Map")(input),
223
+ value: () =>
224
+ explore_maps(project)(config)(importer)(
225
+ input,
226
+ meta.maps,
227
+ {
228
+ ...explore,
229
+ from: "array",
230
+ },
231
+ ),
232
+ });
233
+ for (const native of meta.natives) {
234
+ if (native === "WeakSet" || native === "WeakMap") continue;
235
+ unions.push({
236
+ type: "native",
237
+ is: () => ExpressionFactory.isInstanceOf(native)(input),
238
+ value: () =>
239
+ native === "Boolean" ||
240
+ native === "Number" ||
241
+ native === "String"
242
+ ? ts.factory.createCallExpression(
243
+ IdentifierFactory.access(input)("valueOf"),
244
+ undefined,
245
+ undefined,
246
+ )
247
+ : decode_native(native)(input),
248
+ });
249
+ }
250
+
251
+ // OBJECTS
252
+ if (meta.objects.length)
253
+ unions.push({
254
+ type: "object",
255
+ is: () =>
256
+ ExpressionFactory.isObject({
257
+ checkNull: true,
258
+ checkArray: false,
259
+ })(input),
260
+ value: () =>
261
+ explore_objects(config)(importer)(input, meta, {
262
+ ...explore,
263
+ from: "object",
264
+ }),
265
+ });
266
+
267
+ // COMPOSITION
268
+ let last: ts.Expression = input;
269
+ for (const u of unions.reverse())
270
+ last = ts.factory.createConditionalExpression(
271
+ u.is(),
272
+ undefined,
273
+ u.value(),
274
+ undefined,
275
+ last,
276
+ );
277
+ return ts.factory.createAsExpression(
278
+ last,
279
+ TypeFactory.keyword("any"),
280
+ );
281
+ };
282
+
283
+ const decode_object = (importer: FunctionImporter) =>
284
+ FeatureProgrammer.decode_object({
285
+ trace: false,
286
+ path: false,
287
+ prefix: PREFIX,
288
+ })(importer);
289
+
290
+ const decode_array =
291
+ (config: FeatureProgrammer.IConfig) =>
292
+ (importer: FunctionImporter) =>
293
+ (
294
+ input: ts.Expression,
295
+ array: MetadataArray,
296
+ explore: FeatureProgrammer.IExplore,
297
+ ) =>
298
+ array.type.recursive
299
+ ? ts.factory.createCallExpression(
300
+ ts.factory.createIdentifier(
301
+ importer.useLocal(
302
+ `${config.prefix}a${array.type.index}`,
303
+ ),
304
+ ),
305
+ undefined,
306
+ FeatureProgrammer.argumentsArray(config)({
307
+ ...explore,
308
+ source: "function",
309
+ from: "array",
310
+ })(input),
311
+ )
312
+ : decode_array_inline(config)(importer)(input, array, explore);
313
+
314
+ const decode_array_inline =
315
+ (config: FeatureProgrammer.IConfig) =>
316
+ (importer: FunctionImporter) =>
317
+ (
318
+ input: ts.Expression,
319
+ array: MetadataArray,
320
+ explore: FeatureProgrammer.IExplore,
321
+ ) =>
322
+ FeatureProgrammer.decode_array(config)(importer)(
323
+ NotationJoiner.array,
324
+ )(input, array, explore);
325
+
326
+ const decode_tuple =
327
+ (project: IProject) =>
328
+ (config: FeatureProgrammer.IConfig) =>
329
+ (importer: FunctionImporter) =>
330
+ (
331
+ input: ts.Expression,
332
+ tuple: MetadataTuple,
333
+ explore: FeatureProgrammer.IExplore,
334
+ ): ts.Expression =>
335
+ tuple.type.recursive
336
+ ? ts.factory.createCallExpression(
337
+ ts.factory.createIdentifier(
338
+ importer.useLocal(
339
+ `${config.prefix}t${tuple.type.index}`,
340
+ ),
341
+ ),
342
+ undefined,
343
+ FeatureProgrammer.argumentsArray(config)({
344
+ ...explore,
345
+ source: "function",
346
+ })(input),
347
+ )
348
+ : decode_tuple_inline(project)(config)(importer)(
349
+ input,
350
+ tuple.type,
351
+ explore,
352
+ );
353
+
354
+ const decode_tuple_inline =
355
+ (project: IProject) =>
356
+ (config: FeatureProgrammer.IConfig) =>
357
+ (importer: FunctionImporter) =>
358
+ (
359
+ input: ts.Expression,
360
+ tuple: MetadataTupleType,
361
+ explore: FeatureProgrammer.IExplore,
362
+ ): ts.Expression => {
363
+ const children: ts.Expression[] = tuple.elements
364
+ .filter((m) => m.rest === null)
365
+ .map((elem, index) =>
366
+ decode(project)(config)(importer)(
367
+ ts.factory.createElementAccessExpression(input, index),
368
+ elem,
369
+ {
370
+ ...explore,
371
+ from: "array",
372
+ postfix: explore.postfix.length
373
+ ? `${explore.postfix.slice(0, -1)}[${index}]"`
374
+ : `"[${index}]"`,
375
+ },
376
+ ),
377
+ );
378
+ const rest = (() => {
379
+ if (tuple.elements.length === 0) return null;
380
+
381
+ const last: Metadata = tuple.elements.at(-1)!;
382
+ const rest: Metadata | null = last.rest;
383
+ if (rest === null) return null;
384
+
385
+ return decode(project)(config)(importer)(
386
+ ts.factory.createCallExpression(
387
+ IdentifierFactory.access(input)("slice"),
388
+ undefined,
389
+ [ExpressionFactory.number(tuple.elements.length - 1)],
390
+ ),
391
+ wrap_metadata_rest_tuple(tuple.elements.at(-1)!.rest!),
392
+ {
393
+ ...explore,
394
+ start: tuple.elements.length - 1,
395
+ },
396
+ );
397
+ })();
398
+ return NotationJoiner.tuple(children, rest);
399
+ };
400
+
401
+ /* -----------------------------------------------------------
402
+ NATIVE CLASSES
403
+ ----------------------------------------------------------- */
404
+ const decode_native = (type: string) => (input: ts.Expression) =>
405
+ type === "Date"
406
+ ? ts.factory.createNewExpression(
407
+ ts.factory.createIdentifier(type),
408
+ undefined,
409
+ [input],
410
+ )
411
+ : input;
412
+
413
+ /* -----------------------------------------------------------
414
+ EXPLORERS FOR UNION TYPES
415
+ ----------------------------------------------------------- */
416
+ const explore_sets =
417
+ (project: IProject) =>
418
+ (config: FeatureProgrammer.IConfig) =>
419
+ (importer: FunctionImporter) =>
420
+ (
421
+ input: ts.Expression,
422
+ sets: Metadata[],
423
+ explore: FeatureProgrammer.IExplore,
424
+ ): ts.Expression =>
425
+ ts.factory.createCallExpression(
426
+ UnionExplorer.set({
427
+ checker: IsProgrammer.decode(project)(importer),
428
+ decoder: (input, array, explore) =>
429
+ ts.factory.createNewExpression(
430
+ ts.factory.createIdentifier("Set"),
431
+ [TypeFactory.keyword("any")],
432
+ [
433
+ decode_array(config)(importer)(
434
+ input,
435
+ array,
436
+ explore,
437
+ ),
438
+ ],
439
+ ),
440
+ empty: ts.factory.createNewExpression(
441
+ ts.factory.createIdentifier("Set"),
442
+ [TypeFactory.keyword("any")],
443
+ [],
444
+ ),
445
+ success: ts.factory.createTrue(),
446
+ failure: (input, expected) =>
447
+ create_throw_error(importer)(expected)(input),
448
+ })([])(input, sets, explore),
449
+ undefined,
450
+ undefined,
451
+ );
452
+
453
+ const explore_maps =
454
+ (project: IProject) =>
455
+ (config: FeatureProgrammer.IConfig) =>
456
+ (importer: FunctionImporter) =>
457
+ (
458
+ input: ts.Expression,
459
+ maps: Metadata.Entry[],
460
+ explore: FeatureProgrammer.IExplore,
461
+ ): ts.Expression =>
462
+ ts.factory.createCallExpression(
463
+ UnionExplorer.map({
464
+ checker: (top, entry, explore) => {
465
+ const func = IsProgrammer.decode(project)(importer);
466
+ return ts.factory.createLogicalAnd(
467
+ func(
468
+ ts.factory.createElementAccessExpression(
469
+ top,
470
+ 0,
471
+ ),
472
+ entry[0],
473
+ {
474
+ ...explore,
475
+ postfix: `${explore.postfix}[0]`,
476
+ },
477
+ ),
478
+ func(
479
+ ts.factory.createElementAccessExpression(
480
+ top,
481
+ 1,
482
+ ),
483
+ entry[1],
484
+ {
485
+ ...explore,
486
+ postfix: `${explore.postfix}[1]`,
487
+ },
488
+ ),
489
+ );
490
+ },
491
+ decoder: (input, array, explore) =>
492
+ ts.factory.createNewExpression(
493
+ ts.factory.createIdentifier("Map"),
494
+ [
495
+ TypeFactory.keyword("any"),
496
+ TypeFactory.keyword("any"),
497
+ ],
498
+ [
499
+ decode_array(config)(importer)(
500
+ input,
501
+ array,
502
+ explore,
503
+ ),
504
+ ],
505
+ ),
506
+ empty: ts.factory.createNewExpression(
507
+ ts.factory.createIdentifier("Map"),
508
+ [
509
+ TypeFactory.keyword("any"),
510
+ TypeFactory.keyword("any"),
511
+ ],
512
+ [],
513
+ ),
514
+ success: ts.factory.createTrue(),
515
+ failure: (input, expected) =>
516
+ create_throw_error(importer)(expected)(input),
517
+ })([])(input, maps, explore),
518
+ undefined,
519
+ undefined,
520
+ );
521
+
522
+ const explore_objects =
523
+ (config: FeatureProgrammer.IConfig) =>
524
+ (importer: FunctionImporter) =>
525
+ (
526
+ input: ts.Expression,
527
+ meta: Metadata,
528
+ explore: FeatureProgrammer.IExplore,
529
+ ) => {
530
+ if (meta.objects.length === 1)
531
+ return decode_object(importer)(
532
+ input,
533
+ meta.objects[0]!,
534
+ explore,
535
+ );
536
+
537
+ return ts.factory.createCallExpression(
538
+ ts.factory.createIdentifier(
539
+ importer.useLocal(`${PREFIX}u${meta.union_index!}`),
540
+ ),
541
+ undefined,
542
+ FeatureProgrammer.argumentsArray(config)(explore)(input),
543
+ );
544
+ };
545
+
546
+ const explore_arrays =
547
+ (project: IProject) =>
548
+ (config: FeatureProgrammer.IConfig) =>
549
+ (importer: FunctionImporter) =>
550
+ (
551
+ input: ts.Expression,
552
+ elements: MetadataArray[],
553
+ explore: FeatureProgrammer.IExplore,
554
+ ): ts.Expression =>
555
+ explore_array_like_union_types(config)(importer)(
556
+ UnionExplorer.array({
557
+ checker: IsProgrammer.decode(project)(importer),
558
+ decoder: decode_array(config)(importer),
559
+ empty: ts.factory.createIdentifier("[]"),
560
+ success: ts.factory.createTrue(),
561
+ failure: (input, expected) =>
562
+ create_throw_error(importer)(expected)(input),
563
+ }),
564
+ )(input, elements, explore);
565
+
566
+ const explore_array_like_union_types =
567
+ (config: FeatureProgrammer.IConfig) =>
568
+ (importer: FunctionImporter) =>
569
+ <T extends MetadataArray | MetadataTuple>(
570
+ factory: (
571
+ parameters: ts.ParameterDeclaration[],
572
+ ) => (
573
+ input: ts.Expression,
574
+ elements: T[],
575
+ explore: FeatureProgrammer.IExplore,
576
+ ) => ts.ArrowFunction,
577
+ ) =>
578
+ (
579
+ input: ts.Expression,
580
+ elements: T[],
581
+ explore: FeatureProgrammer.IExplore,
582
+ ): ts.Expression => {
583
+ const arrow =
584
+ (parameters: ts.ParameterDeclaration[]) =>
585
+ (explore: FeatureProgrammer.IExplore) =>
586
+ (input: ts.Expression): ts.ArrowFunction =>
587
+ factory(parameters)(input, elements, explore);
588
+ if (elements.every((e) => e.type.recursive === false))
589
+ ts.factory.createCallExpression(
590
+ arrow([])(explore)(input),
591
+ undefined,
592
+ [],
593
+ );
594
+
595
+ explore = {
596
+ ...explore,
597
+ source: "function",
598
+ from: "array",
599
+ };
600
+ return ts.factory.createCallExpression(
601
+ ts.factory.createIdentifier(
602
+ importer.emplaceUnion(
603
+ config.prefix,
604
+ elements.map((e) => e.type.name).join(" | "),
605
+ () =>
606
+ arrow(
607
+ FeatureProgrammer.parameterDeclarations(config)(
608
+ TypeFactory.keyword("any"),
609
+ )(ts.factory.createIdentifier("input")),
610
+ )({
611
+ ...explore,
612
+ postfix: "",
613
+ })(ts.factory.createIdentifier("input")),
614
+ ),
615
+ ),
616
+ undefined,
617
+ FeatureProgrammer.argumentsArray(config)(explore)(input),
618
+ );
619
+ };
620
+
621
+ /* -----------------------------------------------------------
622
+ CONFIGURATIONS
623
+ ----------------------------------------------------------- */
624
+ const PREFIX = "$c";
625
+
626
+ const configure =
627
+ (rename: (str: string) => string) =>
628
+ (project: IProject) =>
629
+ (importer: FunctionImporter): FeatureProgrammer.IConfig => {
630
+ const config: FeatureProgrammer.IConfig = {
631
+ types: {
632
+ input: (type, name) =>
633
+ ts.factory.createTypeReferenceNode(
634
+ name ??
635
+ TypeFactory.getFullName(project.checker)(type),
636
+ ),
637
+ output: (type, name) =>
638
+ ts.factory.createTypeReferenceNode(
639
+ returnType(rename)(
640
+ name ??
641
+ TypeFactory.getFullName(project.checker)(
642
+ type,
643
+ ),
644
+ ),
645
+ ),
646
+ },
647
+ prefix: PREFIX,
648
+ trace: false,
649
+ path: false,
650
+ initializer,
651
+ decoder: () => decode(project)(config)(importer),
652
+ objector: {
653
+ checker: () => IsProgrammer.decode(project)(importer),
654
+ decoder: () => decode_object(importer),
655
+ joiner: NotationJoiner.object(rename),
656
+ unionizer: decode_union_object(
657
+ IsProgrammer.decode_object(project)(importer),
658
+ )(decode_object(importer))((exp) => exp)(
659
+ (input, expected) =>
660
+ create_throw_error(importer)(expected)(input),
661
+ ),
662
+ failure: (input, expected) =>
663
+ create_throw_error(importer)(expected)(input),
664
+ },
665
+ generator: {
666
+ arrays: () => write_array_functions(config)(importer),
667
+ tuples: () =>
668
+ write_tuple_functions(project)(config)(importer),
669
+ },
670
+ };
671
+ return config;
672
+ };
673
+
674
+ const initializer: FeatureProgrammer.IConfig["initializer"] =
675
+ ({ checker }) =>
676
+ (importer) =>
677
+ (type) => {
678
+ const collection = new MetadataCollection();
679
+ const result = MetadataFactory.analyze(checker)({
680
+ escape: false,
681
+ constant: true,
682
+ absorb: true,
683
+ })(collection)(type);
684
+ if (result.success === false)
685
+ throw TransformerError.from(`typia.misc.${importer.method}`)(
686
+ result.errors,
687
+ );
688
+ return [collection, result.data];
689
+ };
690
+
691
+ const create_throw_error =
692
+ (importer: FunctionImporter) =>
693
+ (expected: string) =>
694
+ (value: ts.Expression) =>
695
+ ts.factory.createExpressionStatement(
696
+ ts.factory.createCallExpression(
697
+ importer.use("throws"),
698
+ [],
699
+ [
700
+ ts.factory.createObjectLiteralExpression(
701
+ [
702
+ ts.factory.createPropertyAssignment(
703
+ "expected",
704
+ ts.factory.createStringLiteral(expected),
705
+ ),
706
+ ts.factory.createPropertyAssignment(
707
+ "value",
708
+ value,
709
+ ),
710
+ ],
711
+ true,
712
+ ),
713
+ ],
714
+ ),
715
+ );
716
+ }