typia 3.4.6 → 3.4.7

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 (119) hide show
  1. package/lib/executable/typia.js +0 -0
  2. package/lib/factories/internal/iterate_metadata.js +1 -1
  3. package/lib/factories/internal/iterate_metadata.js.map +1 -1
  4. package/lib/factories/internal/iterate_metadata_tuple.d.ts +1 -1
  5. package/lib/factories/internal/iterate_metadata_tuple.js +5 -13
  6. package/lib/factories/internal/iterate_metadata_tuple.js.map +1 -1
  7. package/package.json +1 -1
  8. package/src/IValidation.ts +21 -21
  9. package/src/Primitive.ts +82 -82
  10. package/src/TypeGuardError.ts +36 -36
  11. package/src/factories/CommentFactory.ts +10 -10
  12. package/src/factories/ExpressionFactory.ts +52 -52
  13. package/src/factories/IdentifierFactory.ts +72 -72
  14. package/src/factories/LiteralFactory.ts +44 -44
  15. package/src/factories/MetadataCollection.ts +122 -122
  16. package/src/factories/MetadataFactory.ts +46 -46
  17. package/src/factories/StatementFactory.ts +60 -60
  18. package/src/factories/TemplateFactory.ts +56 -56
  19. package/src/factories/TypeFactory.ts +101 -101
  20. package/src/factories/ValueFactory.ts +12 -12
  21. package/src/factories/internal/MetadataHelper.ts +12 -12
  22. package/src/factories/internal/emplace_metadata_object.ts +140 -140
  23. package/src/factories/internal/explore_metadata.ts +91 -91
  24. package/src/factories/internal/iterate_metadata.ts +1 -2
  25. package/src/factories/internal/iterate_metadata_array.ts +29 -29
  26. package/src/factories/internal/iterate_metadata_atomic.ts +59 -59
  27. package/src/factories/internal/iterate_metadata_coalesce.ts +33 -33
  28. package/src/factories/internal/iterate_metadata_constant.ts +58 -58
  29. package/src/factories/internal/iterate_metadata_map.ts +41 -41
  30. package/src/factories/internal/iterate_metadata_object.ts +45 -45
  31. package/src/factories/internal/iterate_metadata_resolve.ts +27 -27
  32. package/src/factories/internal/iterate_metadata_set.ts +33 -33
  33. package/src/factories/internal/iterate_metadata_template.ts +38 -38
  34. package/src/factories/internal/iterate_metadata_tuple.ts +45 -51
  35. package/src/factories/internal/iterate_metadata_union.ts +59 -59
  36. package/src/functional/$every.ts +11 -11
  37. package/src/functional/$guard.ts +35 -35
  38. package/src/functional/$is_email.ts +5 -5
  39. package/src/functional/$is_ipv4.ts +5 -5
  40. package/src/functional/$is_ipv6.ts +5 -5
  41. package/src/functional/$is_url.ts +5 -5
  42. package/src/functional/$is_uuid.ts +5 -5
  43. package/src/functional/$join.ts +50 -50
  44. package/src/functional/$report.ts +15 -15
  45. package/src/functional/$rest.ts +3 -3
  46. package/src/functional/$string.ts +37 -37
  47. package/src/functional/$tail.ts +6 -6
  48. package/src/metadata/IJsDocTagInfo.ts +10 -10
  49. package/src/metadata/IMetadata.ts +25 -25
  50. package/src/metadata/IMetadataApplication.ts +7 -7
  51. package/src/metadata/IMetadataConstant.ts +16 -16
  52. package/src/metadata/IMetadataEntry.ts +6 -6
  53. package/src/metadata/IMetadataObject.ts +29 -29
  54. package/src/metadata/IMetadataProperty.ts +11 -11
  55. package/src/metadata/IMetadataTag.ts +122 -122
  56. package/src/metadata/Metadata.ts +477 -477
  57. package/src/metadata/MetadataConstant.ts +3 -3
  58. package/src/metadata/MetadataObject.ts +131 -131
  59. package/src/metadata/MetadataProperty.ts +64 -64
  60. package/src/programmers/AssertParseProgrammer.ts +45 -45
  61. package/src/programmers/AssertProgrammer.ts +444 -444
  62. package/src/programmers/AssertStringifyProgrammer.ts +45 -45
  63. package/src/programmers/CheckerProgrammer.ts +798 -798
  64. package/src/programmers/FeatureProgrammer.ts +327 -327
  65. package/src/programmers/IsParseProgrammer.ts +51 -51
  66. package/src/programmers/IsProgrammer.ts +169 -169
  67. package/src/programmers/IsStringifyProgrammer.ts +49 -49
  68. package/src/programmers/ValidateParseProgrammer.ts +49 -49
  69. package/src/programmers/ValidateProgrammer.ts +236 -236
  70. package/src/programmers/ValidateStringifyProgrammer.ts +60 -60
  71. package/src/programmers/helpers/AtomicPredicator.ts +15 -15
  72. package/src/programmers/helpers/FunctionImporeter.ts +31 -31
  73. package/src/programmers/helpers/IExpressionEntry.ts +10 -10
  74. package/src/programmers/helpers/OptionPredicator.ts +18 -18
  75. package/src/programmers/helpers/StringifyJoinder.ts +111 -111
  76. package/src/programmers/helpers/StringifyPredicator.ts +18 -18
  77. package/src/programmers/helpers/UnionExplorer.ts +437 -437
  78. package/src/programmers/helpers/UnionPredicator.ts +81 -81
  79. package/src/programmers/internal/application_boolean.ts +17 -17
  80. package/src/programmers/internal/application_constant.ts +29 -29
  81. package/src/programmers/internal/application_default_string.ts +32 -32
  82. package/src/programmers/internal/application_native.ts +29 -29
  83. package/src/programmers/internal/application_schema.ts +221 -221
  84. package/src/programmers/internal/application_templates.ts +27 -27
  85. package/src/programmers/internal/application_tuple.ts +25 -25
  86. package/src/programmers/internal/check_array.ts +44 -44
  87. package/src/programmers/internal/check_dynamic_properties.ts +146 -146
  88. package/src/programmers/internal/check_everything.ts +25 -25
  89. package/src/programmers/internal/check_length.ts +46 -46
  90. package/src/programmers/internal/check_native.ts +9 -9
  91. package/src/programmers/internal/check_number.ts +181 -181
  92. package/src/programmers/internal/check_object.ts +42 -42
  93. package/src/programmers/internal/check_string.ts +24 -24
  94. package/src/programmers/internal/check_string_tags.ts +63 -63
  95. package/src/programmers/internal/check_template.ts +50 -50
  96. package/src/programmers/internal/decode_union_object.ts +73 -73
  97. package/src/programmers/internal/feature_object_entries.ts +49 -49
  98. package/src/programmers/internal/metadata_to_pattern.ts +31 -31
  99. package/src/programmers/internal/stringify_dynamic_properties.ts +164 -164
  100. package/src/programmers/internal/stringify_native.ts +8 -8
  101. package/src/programmers/internal/stringify_regular_properties.ts +81 -81
  102. package/src/programmers/internal/template_to_pattern.ts +15 -15
  103. package/src/schemas/IJsonApplication.ts +9 -9
  104. package/src/transform.ts +20 -20
  105. package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
  106. package/src/transformers/FileTransformer.ts +49 -49
  107. package/src/transformers/IProject.ts +11 -11
  108. package/src/transformers/ITransformOptions.ts +4 -4
  109. package/src/transformers/NodeTransformer.ts +19 -19
  110. package/src/typings/Atomic.ts +17 -17
  111. package/src/typings/ClassProperties.ts +5 -5
  112. package/src/typings/OmitNever.ts +3 -3
  113. package/src/typings/SpecialFields.ts +3 -3
  114. package/src/typings/Writable.ts +11 -11
  115. package/src/utils/ArrayUtil.ts +49 -49
  116. package/src/utils/Escaper.ts +50 -50
  117. package/src/utils/MapUtil.ts +14 -14
  118. package/src/utils/PatternUtil.ts +30 -30
  119. package/src/utils/Singleton.ts +17 -17
@@ -1,798 +1,798 @@
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 { ValueFactory } from "../factories/ValueFactory";
8
-
9
- import { IMetadataTag } from "../metadata/IMetadataTag";
10
- import { Metadata } from "../metadata/Metadata";
11
- import { MetadataObject } from "../metadata/MetadataObject";
12
-
13
- import { IProject } from "../transformers/IProject";
14
-
15
- import { FeatureProgrammer } from "./FeatureProgrammer";
16
- import { FunctionImporter } from "./helpers/FunctionImporeter";
17
- import { IExpressionEntry } from "./helpers/IExpressionEntry";
18
- import { OptionPredicator } from "./helpers/OptionPredicator";
19
- import { UnionExplorer } from "./helpers/UnionExplorer";
20
- import { check_array } from "./internal/check_array";
21
- import { check_native } from "./internal/check_native";
22
- import { check_number } from "./internal/check_number";
23
- import { check_string } from "./internal/check_string";
24
- import { check_template } from "./internal/check_template";
25
- import { decode_union_object } from "./internal/decode_union_object";
26
-
27
- export namespace CheckerProgrammer {
28
- export interface IConfig {
29
- functors: string;
30
- unioners: string;
31
- path: boolean;
32
- trace: boolean;
33
- equals: boolean;
34
- numeric: boolean;
35
- combiner: IConfig.Combiner;
36
- decoder?: FeatureProgrammer.Decoder<Metadata>;
37
- joiner: IConfig.IJoiner;
38
- success: ts.Expression;
39
- }
40
- export namespace IConfig {
41
- export interface Combiner {
42
- (explorer: IExplore): {
43
- (logic: "and" | "or"): {
44
- (
45
- input: ts.Expression,
46
- binaries: IBinary[],
47
- expected: string,
48
- ): ts.Expression;
49
- };
50
- };
51
- }
52
- export interface IJoiner {
53
- object(entries: IExpressionEntry[]): ts.Expression;
54
- array(input: ts.Expression, arrow: ts.ArrowFunction): ts.Expression;
55
- tuple?(exprs: ts.Expression[]): ts.Expression;
56
-
57
- failure(
58
- value: ts.Expression,
59
- expected: string,
60
- explore?: FeatureProgrammer.IExplore,
61
- ): ts.Expression;
62
- is?(expression: ts.Expression): ts.Expression;
63
- required?(exp: ts.Expression): ts.Expression;
64
- full?: (
65
- condition: ts.Expression,
66
- ) => (
67
- input: ts.Expression,
68
- expected: string,
69
- explore: IExplore,
70
- ) => ts.Expression;
71
- }
72
- }
73
- export import IExplore = FeatureProgrammer.IExplore;
74
-
75
- export interface IBinary {
76
- expression: ts.Expression;
77
- combined: boolean;
78
- }
79
-
80
- /* -----------------------------------------------------------
81
- GENERATORS
82
- ----------------------------------------------------------- */
83
- export function generate(
84
- project: IProject,
85
- config: IConfig,
86
- importer: FunctionImporter,
87
- addition?: () => ts.Statement[],
88
- ) {
89
- return FeatureProgrammer.generate(
90
- project,
91
- CONFIG(project, config, importer),
92
- importer,
93
- () => (addition ? (addition ? addition() : []) : undefined),
94
- );
95
- }
96
-
97
- export const generate_functors = (
98
- project: IProject,
99
- config: IConfig,
100
- importer: FunctionImporter,
101
- ) =>
102
- FeatureProgrammer.generate_functors(
103
- CONFIG(project, config, importer),
104
- importer,
105
- );
106
-
107
- export const generate_unioners = (
108
- project: IProject,
109
- config: IConfig,
110
- importer: FunctionImporter,
111
- ) =>
112
- FeatureProgrammer.generate_unioners(
113
- CONFIG(project, { ...config, numeric: false }, importer),
114
- );
115
-
116
- function CONFIG(
117
- project: IProject,
118
- config: IConfig,
119
- importer: FunctionImporter,
120
- ): FeatureProgrammer.IConfig {
121
- const output: FeatureProgrammer.IConfig = {
122
- trace: config.trace,
123
- path: config.path,
124
- functors: config.functors,
125
- unioners: config.unioners,
126
- initializer: ({ checker }, type) => {
127
- const collection: MetadataCollection = new MetadataCollection();
128
- const meta: Metadata = MetadataFactory.generate(
129
- checker,
130
- collection,
131
- type,
132
- {
133
- resolve: false,
134
- constant: true,
135
- },
136
- );
137
- return [collection, meta];
138
- },
139
- decoder: config.decoder || decode(project, config, importer),
140
- objector: {
141
- checker: config.decoder || decode(project, config, importer),
142
- decoder: decode_object(config),
143
- joiner: config.joiner.object,
144
- unionizer: config.equals
145
- ? decode_union_object(decode_object(config))(
146
- (input, obj, explore) =>
147
- decode_object(config)(input, obj, {
148
- ...explore,
149
- tracable: true,
150
- }),
151
- )(config.joiner.is || ((expr) => expr))(
152
- (value, expected) =>
153
- ts.factory.createReturnStatement(
154
- config.joiner.failure(value, expected),
155
- ),
156
- )
157
- : (input, targets, explore) =>
158
- config.combiner(explore)("or")(
159
- input,
160
- targets.map((obj) => ({
161
- expression: decode_object(config)(
162
- input,
163
- obj,
164
- explore,
165
- ),
166
- combined: true,
167
- })),
168
- `(${targets.map((t) => t.name).join(" | ")})`,
169
- ),
170
- failure: (value, expected) =>
171
- ts.factory.createReturnStatement(
172
- config.joiner.failure(value, expected),
173
- ),
174
- is: config.joiner.is,
175
- required: config.joiner.required,
176
- full: config.joiner.full,
177
- },
178
- };
179
- if (config.numeric === true)
180
- output.generator = {
181
- unioners: FeatureProgrammer.generate_unioners(
182
- CONFIG(project, { ...config, numeric: false }, importer),
183
- ),
184
- };
185
- return output;
186
- }
187
-
188
- /* -----------------------------------------------------------
189
- DECODERS
190
- ----------------------------------------------------------- */
191
- export function decode(
192
- project: IProject,
193
- config: IConfig,
194
- importer: FunctionImporter,
195
- ): (
196
- input: ts.Expression,
197
- meta: Metadata,
198
- explore: IExplore,
199
- tags: IMetadataTag[],
200
- ) => ts.Expression;
201
-
202
- /**
203
- * @internal
204
- */
205
- export function decode(
206
- project: IProject,
207
- config: IConfig,
208
- importer: FunctionImporter,
209
- checkTupleLength: boolean,
210
- ): (
211
- input: ts.Expression,
212
- meta: Metadata,
213
- explore: IExplore,
214
- tags: IMetadataTag[],
215
- ) => ts.Expression;
216
-
217
- /**
218
- * @internal
219
- */
220
- export function decode(
221
- project: IProject,
222
- config: IConfig,
223
- importer: FunctionImporter,
224
- checkTupleLength: boolean = true,
225
- ) {
226
- return function (
227
- input: ts.Expression,
228
- meta: Metadata,
229
- explore: IExplore,
230
- tags: IMetadataTag[],
231
- ): ts.Expression {
232
- if (meta.any) return config.success;
233
-
234
- const top: IBinary[] = [];
235
- const binaries: IBinary[] = [];
236
- const add = create_add(binaries)(input);
237
- const getConstantValue = (
238
- value: number | string | bigint | boolean,
239
- ) =>
240
- typeof value === "string"
241
- ? ts.factory.createStringLiteral(value)
242
- : ts.factory.createIdentifier(value.toString());
243
-
244
- //----
245
- // CHECK OPTIONAL
246
- //----
247
- const checkOptional: boolean = meta.empty() || meta.isUnionBucket();
248
-
249
- // NULLABLE
250
- if (
251
- checkOptional ||
252
- meta.nullable
253
- // || (meta.objects.length && meta.size() !== meta.objects.length)
254
- )
255
- (meta.nullable ? add : create_add(top)(input))(
256
- meta.nullable,
257
- ValueFactory.NULL(),
258
- );
259
-
260
- // UNDEFINDABLE
261
- if (checkOptional || !meta.required)
262
- (meta.required ? create_add(top)(input) : add)(
263
- !meta.required,
264
- ValueFactory.UNDEFINED(),
265
- );
266
-
267
- // FUNCTIONAL
268
- if (meta.functional === true)
269
- if (
270
- OptionPredicator.functional(project.options) ||
271
- meta.size() !== 1
272
- )
273
- add(
274
- true,
275
- ts.factory.createStringLiteral("function"),
276
- ValueFactory.TYPEOF(input),
277
- );
278
- else
279
- binaries.push({
280
- combined: false,
281
- expression: config.success,
282
- });
283
-
284
- //----
285
- // VALUES
286
- //----
287
- // CONSTANT VALUES
288
- for (const constant of meta.constants)
289
- for (const val of constant.values)
290
- add(true, getConstantValue(val));
291
-
292
- // ATOMIC VALUES
293
- for (const type of meta.atomics)
294
- if (type === "number")
295
- binaries.push({
296
- expression: check_number(project, config.numeric)(
297
- input,
298
- tags,
299
- ),
300
- combined: false,
301
- });
302
- else if (type === "string")
303
- binaries.push({
304
- expression: check_string(importer)(input, tags),
305
- combined: false,
306
- });
307
- else
308
- add(
309
- true,
310
- ts.factory.createStringLiteral(type),
311
- ValueFactory.TYPEOF(input),
312
- );
313
-
314
- // TEMPLATE LITERAL VALUES
315
- if (meta.templates.length)
316
- binaries.push({
317
- expression: check_template(importer)(
318
- input,
319
- meta.templates,
320
- tags,
321
- ),
322
- combined: false,
323
- });
324
-
325
- //----
326
- // INSTANCES
327
- //----
328
- // TUPLE
329
- if (meta.tuples.length > 0) {
330
- const inner: ts.Expression[] = [];
331
- for (const tuple of meta.tuples)
332
- inner.push(
333
- decode_tuple(
334
- project,
335
- config,
336
- importer,
337
- checkTupleLength,
338
- )(input, tuple, explore, tags),
339
- );
340
-
341
- // ADD
342
- binaries.push({
343
- expression: config.combiner(explore)("and")(
344
- input,
345
- [
346
- ...(checkTupleLength
347
- ? [
348
- {
349
- expression:
350
- ExpressionFactory.isArray(input),
351
- combined: false,
352
- },
353
- ]
354
- : []),
355
- ...inner.map((expression) => ({
356
- expression,
357
- combined: true,
358
- })),
359
- ],
360
- meta.getName(),
361
- ),
362
- combined: true,
363
- });
364
- }
365
-
366
- // ARRAY
367
- if (meta.arrays.length > 0)
368
- if (meta.arrays.every((elem) => elem.any))
369
- binaries.push({
370
- expression: check_array(input, tags),
371
- combined: false,
372
- });
373
- else
374
- binaries.push({
375
- expression: config.combiner(explore)("and")(
376
- input,
377
- [
378
- ...(checkTupleLength
379
- ? [
380
- {
381
- expression: check_array(
382
- input,
383
- tags,
384
- ),
385
- combined: false,
386
- },
387
- ]
388
- : []),
389
- {
390
- expression: explore_array(
391
- project,
392
- config,
393
- importer,
394
- )(
395
- input,
396
- meta.arrays,
397
- {
398
- ...explore,
399
- from: "array",
400
- },
401
- tags,
402
- ),
403
- combined: true,
404
- },
405
- ],
406
- meta.getName(),
407
- ),
408
- combined: true,
409
- });
410
-
411
- // OBJECT
412
- if (meta.objects.length > 0)
413
- binaries.push({
414
- expression: config.combiner(explore)("and")(
415
- input,
416
- [
417
- {
418
- expression: ExpressionFactory.isObject(
419
- input,
420
- true,
421
- ),
422
- combined: false,
423
- },
424
- {
425
- expression: explore_objects(config)(
426
- input,
427
- meta,
428
- {
429
- ...explore,
430
- from: "object",
431
- },
432
- ),
433
- combined: true,
434
- },
435
- ],
436
- meta.getName(),
437
- ),
438
- combined: true,
439
- });
440
-
441
- // NATIVE CLASSES
442
- for (const native of meta.natives)
443
- binaries.push({
444
- expression: check_native(native)(input),
445
- combined: false,
446
- });
447
-
448
- // SETS
449
- if (meta.sets.length)
450
- if (meta.sets.every((elem) => elem.any))
451
- binaries.push({
452
- combined: false,
453
- expression: check_native("Set")(input),
454
- });
455
- else
456
- binaries.push({
457
- combined: true,
458
- expression: config.combiner(explore)("and")(
459
- input,
460
- [
461
- {
462
- combined: false,
463
- expression: check_native("Set")(input),
464
- },
465
- {
466
- combined: true,
467
- expression: explore_set(
468
- project,
469
- config,
470
- importer,
471
- )(
472
- input,
473
- meta.sets,
474
- {
475
- ...explore,
476
- from: "array",
477
- },
478
- [],
479
- ),
480
- },
481
- ],
482
- meta.getName(),
483
- ),
484
- });
485
-
486
- // MAPS
487
- if (meta.maps.length)
488
- if (meta.maps.every((elem) => elem.key.any && elem.value.any))
489
- binaries.push({
490
- expression: check_native("Map")(input),
491
- combined: false,
492
- });
493
- else
494
- binaries.push({
495
- combined: true,
496
- expression: config.combiner(explore)("and")(
497
- input,
498
- [
499
- {
500
- combined: false,
501
- expression: check_native("Map")(input),
502
- },
503
- {
504
- combined: true,
505
- expression: explore_map(
506
- project,
507
- config,
508
- importer,
509
- )(
510
- input,
511
- meta.maps.map((m) => [m.key, m.value]),
512
- {
513
- ...explore,
514
- from: "array",
515
- },
516
- [],
517
- ),
518
- },
519
- ],
520
- meta.getName(),
521
- ),
522
- });
523
-
524
- // COMBINE CONDITIONS
525
- return top.length && binaries.length
526
- ? config.combiner(explore)("and")(
527
- input,
528
- [
529
- ...top,
530
- {
531
- expression: config.combiner(explore)("or")(
532
- input,
533
- binaries,
534
- meta.getName(),
535
- ),
536
- combined: true,
537
- },
538
- ],
539
- meta.getName(),
540
- )
541
- : binaries.length
542
- ? config.combiner(explore)("or")(
543
- input,
544
- binaries,
545
- meta.getName(),
546
- )
547
- : config.success;
548
- };
549
- }
550
-
551
- function decode_tuple(
552
- project: IProject,
553
- config: IConfig,
554
- importer: FunctionImporter,
555
- checkLength: boolean,
556
- ) {
557
- return function (
558
- input: ts.Expression,
559
- tuple: Array<Metadata>,
560
- explore: IExplore,
561
- tagList: IMetadataTag[],
562
- ): ts.Expression {
563
- const binaries: ts.Expression[] = tuple
564
- .filter((meta) => meta.rest === null)
565
- .map((meta, index) =>
566
- decode(project, config, importer)(
567
- ts.factory.createElementAccessExpression(input, index),
568
- meta,
569
- {
570
- ...explore,
571
- from: "array",
572
- postfix: explore.postfix.length
573
- ? `${explore.postfix.slice(0, -1)}[${index}]"`
574
- : `[${index}]`,
575
- },
576
- tagList,
577
- ),
578
- );
579
- const rest: ts.Expression | null =
580
- tuple.length && tuple[tuple.length - 1]!.rest !== null
581
- ? decode(project, config, importer, false)(
582
- ts.factory.createCallExpression(
583
- IdentifierFactory.join(input, "slice"),
584
- undefined,
585
- [
586
- ts.factory.createNumericLiteral(
587
- tuple.length - 1,
588
- ),
589
- ],
590
- ),
591
- (() => {
592
- const wrapper: Metadata = Metadata.initialize();
593
- wrapper.arrays.push(
594
- tuple[tuple.length - 1]!.rest!,
595
- );
596
- return wrapper;
597
- })(),
598
- {
599
- ...explore,
600
- start: tuple.length - 1,
601
- },
602
- tagList,
603
- )
604
- : null;
605
-
606
- return config.combiner(explore)("and")(
607
- input,
608
- [
609
- ...(checkLength && rest === null
610
- ? [
611
- {
612
- combined: false,
613
- expression: ts.factory.createStrictEquality(
614
- ts.factory.createPropertyAccessExpression(
615
- input,
616
- "length",
617
- ),
618
- ts.factory.createNumericLiteral(
619
- tuple.length,
620
- ),
621
- ),
622
- },
623
- ]
624
- : []),
625
- ...(config.joiner.tuple
626
- ? [
627
- {
628
- expression: config.joiner.tuple(binaries),
629
- combined: true,
630
- },
631
- ]
632
- : binaries.map((expression) => ({
633
- expression,
634
- combined: true,
635
- }))),
636
- ...(rest !== null
637
- ? [
638
- {
639
- expression: rest,
640
- combined: true,
641
- },
642
- ]
643
- : []),
644
- ],
645
- `[${tuple.map((t) => t.getName()).join(", ")}]`,
646
- );
647
- };
648
- }
649
-
650
- function decode_array(
651
- project: IProject,
652
- config: IConfig,
653
- importer: FunctionImporter,
654
- checkTupleLength: boolean,
655
- ) {
656
- return FeatureProgrammer.decode_array(
657
- {
658
- trace: config.trace,
659
- path: config.path,
660
- decoder: decode(project, config, importer, checkTupleLength),
661
- },
662
- importer,
663
- config.joiner.array,
664
- );
665
- }
666
-
667
- export function decode_object(config: IConfig) {
668
- const func = FeatureProgrammer.decode_object(config);
669
- return function (
670
- input: ts.Expression,
671
- obj: MetadataObject,
672
- explore: IExplore,
673
- ) {
674
- obj.validated = true;
675
- return func(input, obj, explore);
676
- };
677
- }
678
-
679
- const explore_array = (
680
- project: IProject,
681
- config: IConfig,
682
- importer: FunctionImporter,
683
- ) =>
684
- UnionExplorer.array({
685
- checker: decode(project, config, importer),
686
- decoder: decode_array(project, config, importer, true),
687
- empty: config.success,
688
- success: config.success,
689
- failure: (input, expected, explore) =>
690
- ts.factory.createReturnStatement(
691
- config.joiner.failure(input, expected, explore),
692
- ),
693
- });
694
-
695
- const explore_set = (
696
- project: IProject,
697
- config: IConfig,
698
- importer: FunctionImporter,
699
- ) =>
700
- UnionExplorer.set({
701
- checker: decode(project, config, importer),
702
- decoder: decode_array(project, config, importer, true),
703
- empty: config.success,
704
- success: config.success,
705
- failure: (input, expected, explore) =>
706
- ts.factory.createReturnStatement(
707
- config.joiner.failure(input, expected, explore),
708
- ),
709
- });
710
-
711
- const explore_map = (
712
- project: IProject,
713
- config: IConfig,
714
- importer: FunctionImporter,
715
- ) =>
716
- UnionExplorer.map({
717
- checker: (input, entry, explore) => {
718
- const func = decode(project, config, importer);
719
- return ts.factory.createLogicalAnd(
720
- func(
721
- ts.factory.createElementAccessExpression(input, 0),
722
- entry[0],
723
- { ...explore, postfix: `${explore.postfix}[0]` },
724
- [],
725
- ),
726
- func(
727
- ts.factory.createElementAccessExpression(input, 1),
728
- entry[1],
729
- { ...explore, postfix: `${explore.postfix}[1]` },
730
- [],
731
- ),
732
- );
733
- },
734
- decoder: (input, target, explore) =>
735
- decode_array(project, config, importer, false)(
736
- input,
737
- Metadata.create({
738
- any: false,
739
- nullable: false,
740
- required: true,
741
- functional: false,
742
- resolved: null,
743
- constants: [],
744
- atomics: [],
745
- templates: [],
746
- rest: null,
747
- arrays: [],
748
- tuples: [target],
749
- objects: [],
750
- natives: [],
751
- sets: [],
752
- maps: [],
753
- }),
754
- explore,
755
- [],
756
- ),
757
- empty: config.success,
758
- success: config.success,
759
- failure: (input, expected, explore) =>
760
- ts.factory.createReturnStatement(
761
- config.joiner.failure(input, expected, explore),
762
- ),
763
- });
764
-
765
- const explore_objects = (config: IConfig) => {
766
- const objector = decode_object(config);
767
-
768
- return (input: ts.Expression, meta: Metadata, explore: IExplore) => {
769
- if (meta.objects.length === 1)
770
- return objector(input, meta.objects[0]!, explore);
771
-
772
- return ts.factory.createCallExpression(
773
- ts.factory.createIdentifier(
774
- `${config.unioners}${meta.union_index!}`,
775
- ),
776
- undefined,
777
- FeatureProgrammer.get_object_arguments(config)(explore)(input),
778
- );
779
- };
780
- };
781
- }
782
-
783
- const create_add =
784
- (binaries: CheckerProgrammer.IBinary[]) =>
785
- (defaultInput: ts.Expression) =>
786
- (
787
- exact: boolean,
788
- left: ts.Expression,
789
- right: ts.Expression = defaultInput,
790
- ) => {
791
- const factory = exact
792
- ? ts.factory.createStrictEquality
793
- : ts.factory.createStrictInequality;
794
- binaries.push({
795
- expression: factory(left, right),
796
- combined: false,
797
- });
798
- };
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 { ValueFactory } from "../factories/ValueFactory";
8
+
9
+ import { IMetadataTag } from "../metadata/IMetadataTag";
10
+ import { Metadata } from "../metadata/Metadata";
11
+ import { MetadataObject } from "../metadata/MetadataObject";
12
+
13
+ import { IProject } from "../transformers/IProject";
14
+
15
+ import { FeatureProgrammer } from "./FeatureProgrammer";
16
+ import { FunctionImporter } from "./helpers/FunctionImporeter";
17
+ import { IExpressionEntry } from "./helpers/IExpressionEntry";
18
+ import { OptionPredicator } from "./helpers/OptionPredicator";
19
+ import { UnionExplorer } from "./helpers/UnionExplorer";
20
+ import { check_array } from "./internal/check_array";
21
+ import { check_native } from "./internal/check_native";
22
+ import { check_number } from "./internal/check_number";
23
+ import { check_string } from "./internal/check_string";
24
+ import { check_template } from "./internal/check_template";
25
+ import { decode_union_object } from "./internal/decode_union_object";
26
+
27
+ export namespace CheckerProgrammer {
28
+ export interface IConfig {
29
+ functors: string;
30
+ unioners: string;
31
+ path: boolean;
32
+ trace: boolean;
33
+ equals: boolean;
34
+ numeric: boolean;
35
+ combiner: IConfig.Combiner;
36
+ decoder?: FeatureProgrammer.Decoder<Metadata>;
37
+ joiner: IConfig.IJoiner;
38
+ success: ts.Expression;
39
+ }
40
+ export namespace IConfig {
41
+ export interface Combiner {
42
+ (explorer: IExplore): {
43
+ (logic: "and" | "or"): {
44
+ (
45
+ input: ts.Expression,
46
+ binaries: IBinary[],
47
+ expected: string,
48
+ ): ts.Expression;
49
+ };
50
+ };
51
+ }
52
+ export interface IJoiner {
53
+ object(entries: IExpressionEntry[]): ts.Expression;
54
+ array(input: ts.Expression, arrow: ts.ArrowFunction): ts.Expression;
55
+ tuple?(exprs: ts.Expression[]): ts.Expression;
56
+
57
+ failure(
58
+ value: ts.Expression,
59
+ expected: string,
60
+ explore?: FeatureProgrammer.IExplore,
61
+ ): ts.Expression;
62
+ is?(expression: ts.Expression): ts.Expression;
63
+ required?(exp: ts.Expression): ts.Expression;
64
+ full?: (
65
+ condition: ts.Expression,
66
+ ) => (
67
+ input: ts.Expression,
68
+ expected: string,
69
+ explore: IExplore,
70
+ ) => ts.Expression;
71
+ }
72
+ }
73
+ export import IExplore = FeatureProgrammer.IExplore;
74
+
75
+ export interface IBinary {
76
+ expression: ts.Expression;
77
+ combined: boolean;
78
+ }
79
+
80
+ /* -----------------------------------------------------------
81
+ GENERATORS
82
+ ----------------------------------------------------------- */
83
+ export function generate(
84
+ project: IProject,
85
+ config: IConfig,
86
+ importer: FunctionImporter,
87
+ addition?: () => ts.Statement[],
88
+ ) {
89
+ return FeatureProgrammer.generate(
90
+ project,
91
+ CONFIG(project, config, importer),
92
+ importer,
93
+ () => (addition ? (addition ? addition() : []) : undefined),
94
+ );
95
+ }
96
+
97
+ export const generate_functors = (
98
+ project: IProject,
99
+ config: IConfig,
100
+ importer: FunctionImporter,
101
+ ) =>
102
+ FeatureProgrammer.generate_functors(
103
+ CONFIG(project, config, importer),
104
+ importer,
105
+ );
106
+
107
+ export const generate_unioners = (
108
+ project: IProject,
109
+ config: IConfig,
110
+ importer: FunctionImporter,
111
+ ) =>
112
+ FeatureProgrammer.generate_unioners(
113
+ CONFIG(project, { ...config, numeric: false }, importer),
114
+ );
115
+
116
+ function CONFIG(
117
+ project: IProject,
118
+ config: IConfig,
119
+ importer: FunctionImporter,
120
+ ): FeatureProgrammer.IConfig {
121
+ const output: FeatureProgrammer.IConfig = {
122
+ trace: config.trace,
123
+ path: config.path,
124
+ functors: config.functors,
125
+ unioners: config.unioners,
126
+ initializer: ({ checker }, type) => {
127
+ const collection: MetadataCollection = new MetadataCollection();
128
+ const meta: Metadata = MetadataFactory.generate(
129
+ checker,
130
+ collection,
131
+ type,
132
+ {
133
+ resolve: false,
134
+ constant: true,
135
+ },
136
+ );
137
+ return [collection, meta];
138
+ },
139
+ decoder: config.decoder || decode(project, config, importer),
140
+ objector: {
141
+ checker: config.decoder || decode(project, config, importer),
142
+ decoder: decode_object(config),
143
+ joiner: config.joiner.object,
144
+ unionizer: config.equals
145
+ ? decode_union_object(decode_object(config))(
146
+ (input, obj, explore) =>
147
+ decode_object(config)(input, obj, {
148
+ ...explore,
149
+ tracable: true,
150
+ }),
151
+ )(config.joiner.is || ((expr) => expr))(
152
+ (value, expected) =>
153
+ ts.factory.createReturnStatement(
154
+ config.joiner.failure(value, expected),
155
+ ),
156
+ )
157
+ : (input, targets, explore) =>
158
+ config.combiner(explore)("or")(
159
+ input,
160
+ targets.map((obj) => ({
161
+ expression: decode_object(config)(
162
+ input,
163
+ obj,
164
+ explore,
165
+ ),
166
+ combined: true,
167
+ })),
168
+ `(${targets.map((t) => t.name).join(" | ")})`,
169
+ ),
170
+ failure: (value, expected) =>
171
+ ts.factory.createReturnStatement(
172
+ config.joiner.failure(value, expected),
173
+ ),
174
+ is: config.joiner.is,
175
+ required: config.joiner.required,
176
+ full: config.joiner.full,
177
+ },
178
+ };
179
+ if (config.numeric === true)
180
+ output.generator = {
181
+ unioners: FeatureProgrammer.generate_unioners(
182
+ CONFIG(project, { ...config, numeric: false }, importer),
183
+ ),
184
+ };
185
+ return output;
186
+ }
187
+
188
+ /* -----------------------------------------------------------
189
+ DECODERS
190
+ ----------------------------------------------------------- */
191
+ export function decode(
192
+ project: IProject,
193
+ config: IConfig,
194
+ importer: FunctionImporter,
195
+ ): (
196
+ input: ts.Expression,
197
+ meta: Metadata,
198
+ explore: IExplore,
199
+ tags: IMetadataTag[],
200
+ ) => ts.Expression;
201
+
202
+ /**
203
+ * @internal
204
+ */
205
+ export function decode(
206
+ project: IProject,
207
+ config: IConfig,
208
+ importer: FunctionImporter,
209
+ checkTupleLength: boolean,
210
+ ): (
211
+ input: ts.Expression,
212
+ meta: Metadata,
213
+ explore: IExplore,
214
+ tags: IMetadataTag[],
215
+ ) => ts.Expression;
216
+
217
+ /**
218
+ * @internal
219
+ */
220
+ export function decode(
221
+ project: IProject,
222
+ config: IConfig,
223
+ importer: FunctionImporter,
224
+ checkTupleLength: boolean = true,
225
+ ) {
226
+ return function (
227
+ input: ts.Expression,
228
+ meta: Metadata,
229
+ explore: IExplore,
230
+ tags: IMetadataTag[],
231
+ ): ts.Expression {
232
+ if (meta.any) return config.success;
233
+
234
+ const top: IBinary[] = [];
235
+ const binaries: IBinary[] = [];
236
+ const add = create_add(binaries)(input);
237
+ const getConstantValue = (
238
+ value: number | string | bigint | boolean,
239
+ ) =>
240
+ typeof value === "string"
241
+ ? ts.factory.createStringLiteral(value)
242
+ : ts.factory.createIdentifier(value.toString());
243
+
244
+ //----
245
+ // CHECK OPTIONAL
246
+ //----
247
+ const checkOptional: boolean = meta.empty() || meta.isUnionBucket();
248
+
249
+ // NULLABLE
250
+ if (
251
+ checkOptional ||
252
+ meta.nullable
253
+ // || (meta.objects.length && meta.size() !== meta.objects.length)
254
+ )
255
+ (meta.nullable ? add : create_add(top)(input))(
256
+ meta.nullable,
257
+ ValueFactory.NULL(),
258
+ );
259
+
260
+ // UNDEFINDABLE
261
+ if (checkOptional || !meta.required)
262
+ (meta.required ? create_add(top)(input) : add)(
263
+ !meta.required,
264
+ ValueFactory.UNDEFINED(),
265
+ );
266
+
267
+ // FUNCTIONAL
268
+ if (meta.functional === true)
269
+ if (
270
+ OptionPredicator.functional(project.options) ||
271
+ meta.size() !== 1
272
+ )
273
+ add(
274
+ true,
275
+ ts.factory.createStringLiteral("function"),
276
+ ValueFactory.TYPEOF(input),
277
+ );
278
+ else
279
+ binaries.push({
280
+ combined: false,
281
+ expression: config.success,
282
+ });
283
+
284
+ //----
285
+ // VALUES
286
+ //----
287
+ // CONSTANT VALUES
288
+ for (const constant of meta.constants)
289
+ for (const val of constant.values)
290
+ add(true, getConstantValue(val));
291
+
292
+ // ATOMIC VALUES
293
+ for (const type of meta.atomics)
294
+ if (type === "number")
295
+ binaries.push({
296
+ expression: check_number(project, config.numeric)(
297
+ input,
298
+ tags,
299
+ ),
300
+ combined: false,
301
+ });
302
+ else if (type === "string")
303
+ binaries.push({
304
+ expression: check_string(importer)(input, tags),
305
+ combined: false,
306
+ });
307
+ else
308
+ add(
309
+ true,
310
+ ts.factory.createStringLiteral(type),
311
+ ValueFactory.TYPEOF(input),
312
+ );
313
+
314
+ // TEMPLATE LITERAL VALUES
315
+ if (meta.templates.length)
316
+ binaries.push({
317
+ expression: check_template(importer)(
318
+ input,
319
+ meta.templates,
320
+ tags,
321
+ ),
322
+ combined: false,
323
+ });
324
+
325
+ //----
326
+ // INSTANCES
327
+ //----
328
+ // TUPLE
329
+ if (meta.tuples.length > 0) {
330
+ const inner: ts.Expression[] = [];
331
+ for (const tuple of meta.tuples)
332
+ inner.push(
333
+ decode_tuple(
334
+ project,
335
+ config,
336
+ importer,
337
+ checkTupleLength,
338
+ )(input, tuple, explore, tags),
339
+ );
340
+
341
+ // ADD
342
+ binaries.push({
343
+ expression: config.combiner(explore)("and")(
344
+ input,
345
+ [
346
+ ...(checkTupleLength
347
+ ? [
348
+ {
349
+ expression:
350
+ ExpressionFactory.isArray(input),
351
+ combined: false,
352
+ },
353
+ ]
354
+ : []),
355
+ ...inner.map((expression) => ({
356
+ expression,
357
+ combined: true,
358
+ })),
359
+ ],
360
+ meta.getName(),
361
+ ),
362
+ combined: true,
363
+ });
364
+ }
365
+
366
+ // ARRAY
367
+ if (meta.arrays.length > 0)
368
+ if (meta.arrays.every((elem) => elem.any))
369
+ binaries.push({
370
+ expression: check_array(input, tags),
371
+ combined: false,
372
+ });
373
+ else
374
+ binaries.push({
375
+ expression: config.combiner(explore)("and")(
376
+ input,
377
+ [
378
+ ...(checkTupleLength
379
+ ? [
380
+ {
381
+ expression: check_array(
382
+ input,
383
+ tags,
384
+ ),
385
+ combined: false,
386
+ },
387
+ ]
388
+ : []),
389
+ {
390
+ expression: explore_array(
391
+ project,
392
+ config,
393
+ importer,
394
+ )(
395
+ input,
396
+ meta.arrays,
397
+ {
398
+ ...explore,
399
+ from: "array",
400
+ },
401
+ tags,
402
+ ),
403
+ combined: true,
404
+ },
405
+ ],
406
+ meta.getName(),
407
+ ),
408
+ combined: true,
409
+ });
410
+
411
+ // OBJECT
412
+ if (meta.objects.length > 0)
413
+ binaries.push({
414
+ expression: config.combiner(explore)("and")(
415
+ input,
416
+ [
417
+ {
418
+ expression: ExpressionFactory.isObject(
419
+ input,
420
+ true,
421
+ ),
422
+ combined: false,
423
+ },
424
+ {
425
+ expression: explore_objects(config)(
426
+ input,
427
+ meta,
428
+ {
429
+ ...explore,
430
+ from: "object",
431
+ },
432
+ ),
433
+ combined: true,
434
+ },
435
+ ],
436
+ meta.getName(),
437
+ ),
438
+ combined: true,
439
+ });
440
+
441
+ // NATIVE CLASSES
442
+ for (const native of meta.natives)
443
+ binaries.push({
444
+ expression: check_native(native)(input),
445
+ combined: false,
446
+ });
447
+
448
+ // SETS
449
+ if (meta.sets.length)
450
+ if (meta.sets.every((elem) => elem.any))
451
+ binaries.push({
452
+ combined: false,
453
+ expression: check_native("Set")(input),
454
+ });
455
+ else
456
+ binaries.push({
457
+ combined: true,
458
+ expression: config.combiner(explore)("and")(
459
+ input,
460
+ [
461
+ {
462
+ combined: false,
463
+ expression: check_native("Set")(input),
464
+ },
465
+ {
466
+ combined: true,
467
+ expression: explore_set(
468
+ project,
469
+ config,
470
+ importer,
471
+ )(
472
+ input,
473
+ meta.sets,
474
+ {
475
+ ...explore,
476
+ from: "array",
477
+ },
478
+ [],
479
+ ),
480
+ },
481
+ ],
482
+ meta.getName(),
483
+ ),
484
+ });
485
+
486
+ // MAPS
487
+ if (meta.maps.length)
488
+ if (meta.maps.every((elem) => elem.key.any && elem.value.any))
489
+ binaries.push({
490
+ expression: check_native("Map")(input),
491
+ combined: false,
492
+ });
493
+ else
494
+ binaries.push({
495
+ combined: true,
496
+ expression: config.combiner(explore)("and")(
497
+ input,
498
+ [
499
+ {
500
+ combined: false,
501
+ expression: check_native("Map")(input),
502
+ },
503
+ {
504
+ combined: true,
505
+ expression: explore_map(
506
+ project,
507
+ config,
508
+ importer,
509
+ )(
510
+ input,
511
+ meta.maps.map((m) => [m.key, m.value]),
512
+ {
513
+ ...explore,
514
+ from: "array",
515
+ },
516
+ [],
517
+ ),
518
+ },
519
+ ],
520
+ meta.getName(),
521
+ ),
522
+ });
523
+
524
+ // COMBINE CONDITIONS
525
+ return top.length && binaries.length
526
+ ? config.combiner(explore)("and")(
527
+ input,
528
+ [
529
+ ...top,
530
+ {
531
+ expression: config.combiner(explore)("or")(
532
+ input,
533
+ binaries,
534
+ meta.getName(),
535
+ ),
536
+ combined: true,
537
+ },
538
+ ],
539
+ meta.getName(),
540
+ )
541
+ : binaries.length
542
+ ? config.combiner(explore)("or")(
543
+ input,
544
+ binaries,
545
+ meta.getName(),
546
+ )
547
+ : config.success;
548
+ };
549
+ }
550
+
551
+ function decode_tuple(
552
+ project: IProject,
553
+ config: IConfig,
554
+ importer: FunctionImporter,
555
+ checkLength: boolean,
556
+ ) {
557
+ return function (
558
+ input: ts.Expression,
559
+ tuple: Array<Metadata>,
560
+ explore: IExplore,
561
+ tagList: IMetadataTag[],
562
+ ): ts.Expression {
563
+ const binaries: ts.Expression[] = tuple
564
+ .filter((meta) => meta.rest === null)
565
+ .map((meta, index) =>
566
+ decode(project, config, importer)(
567
+ ts.factory.createElementAccessExpression(input, index),
568
+ meta,
569
+ {
570
+ ...explore,
571
+ from: "array",
572
+ postfix: explore.postfix.length
573
+ ? `${explore.postfix.slice(0, -1)}[${index}]"`
574
+ : `[${index}]`,
575
+ },
576
+ tagList,
577
+ ),
578
+ );
579
+ const rest: ts.Expression | null =
580
+ tuple.length && tuple[tuple.length - 1]!.rest !== null
581
+ ? decode(project, config, importer, false)(
582
+ ts.factory.createCallExpression(
583
+ IdentifierFactory.join(input, "slice"),
584
+ undefined,
585
+ [
586
+ ts.factory.createNumericLiteral(
587
+ tuple.length - 1,
588
+ ),
589
+ ],
590
+ ),
591
+ (() => {
592
+ const wrapper: Metadata = Metadata.initialize();
593
+ wrapper.arrays.push(
594
+ tuple[tuple.length - 1]!.rest!,
595
+ );
596
+ return wrapper;
597
+ })(),
598
+ {
599
+ ...explore,
600
+ start: tuple.length - 1,
601
+ },
602
+ tagList,
603
+ )
604
+ : null;
605
+
606
+ return config.combiner(explore)("and")(
607
+ input,
608
+ [
609
+ ...(checkLength && rest === null
610
+ ? [
611
+ {
612
+ combined: false,
613
+ expression: ts.factory.createStrictEquality(
614
+ ts.factory.createPropertyAccessExpression(
615
+ input,
616
+ "length",
617
+ ),
618
+ ts.factory.createNumericLiteral(
619
+ tuple.length,
620
+ ),
621
+ ),
622
+ },
623
+ ]
624
+ : []),
625
+ ...(config.joiner.tuple
626
+ ? [
627
+ {
628
+ expression: config.joiner.tuple(binaries),
629
+ combined: true,
630
+ },
631
+ ]
632
+ : binaries.map((expression) => ({
633
+ expression,
634
+ combined: true,
635
+ }))),
636
+ ...(rest !== null
637
+ ? [
638
+ {
639
+ expression: rest,
640
+ combined: true,
641
+ },
642
+ ]
643
+ : []),
644
+ ],
645
+ `[${tuple.map((t) => t.getName()).join(", ")}]`,
646
+ );
647
+ };
648
+ }
649
+
650
+ function decode_array(
651
+ project: IProject,
652
+ config: IConfig,
653
+ importer: FunctionImporter,
654
+ checkTupleLength: boolean,
655
+ ) {
656
+ return FeatureProgrammer.decode_array(
657
+ {
658
+ trace: config.trace,
659
+ path: config.path,
660
+ decoder: decode(project, config, importer, checkTupleLength),
661
+ },
662
+ importer,
663
+ config.joiner.array,
664
+ );
665
+ }
666
+
667
+ export function decode_object(config: IConfig) {
668
+ const func = FeatureProgrammer.decode_object(config);
669
+ return function (
670
+ input: ts.Expression,
671
+ obj: MetadataObject,
672
+ explore: IExplore,
673
+ ) {
674
+ obj.validated = true;
675
+ return func(input, obj, explore);
676
+ };
677
+ }
678
+
679
+ const explore_array = (
680
+ project: IProject,
681
+ config: IConfig,
682
+ importer: FunctionImporter,
683
+ ) =>
684
+ UnionExplorer.array({
685
+ checker: decode(project, config, importer),
686
+ decoder: decode_array(project, config, importer, true),
687
+ empty: config.success,
688
+ success: config.success,
689
+ failure: (input, expected, explore) =>
690
+ ts.factory.createReturnStatement(
691
+ config.joiner.failure(input, expected, explore),
692
+ ),
693
+ });
694
+
695
+ const explore_set = (
696
+ project: IProject,
697
+ config: IConfig,
698
+ importer: FunctionImporter,
699
+ ) =>
700
+ UnionExplorer.set({
701
+ checker: decode(project, config, importer),
702
+ decoder: decode_array(project, config, importer, true),
703
+ empty: config.success,
704
+ success: config.success,
705
+ failure: (input, expected, explore) =>
706
+ ts.factory.createReturnStatement(
707
+ config.joiner.failure(input, expected, explore),
708
+ ),
709
+ });
710
+
711
+ const explore_map = (
712
+ project: IProject,
713
+ config: IConfig,
714
+ importer: FunctionImporter,
715
+ ) =>
716
+ UnionExplorer.map({
717
+ checker: (input, entry, explore) => {
718
+ const func = decode(project, config, importer);
719
+ return ts.factory.createLogicalAnd(
720
+ func(
721
+ ts.factory.createElementAccessExpression(input, 0),
722
+ entry[0],
723
+ { ...explore, postfix: `${explore.postfix}[0]` },
724
+ [],
725
+ ),
726
+ func(
727
+ ts.factory.createElementAccessExpression(input, 1),
728
+ entry[1],
729
+ { ...explore, postfix: `${explore.postfix}[1]` },
730
+ [],
731
+ ),
732
+ );
733
+ },
734
+ decoder: (input, target, explore) =>
735
+ decode_array(project, config, importer, false)(
736
+ input,
737
+ Metadata.create({
738
+ any: false,
739
+ nullable: false,
740
+ required: true,
741
+ functional: false,
742
+ resolved: null,
743
+ constants: [],
744
+ atomics: [],
745
+ templates: [],
746
+ rest: null,
747
+ arrays: [],
748
+ tuples: [target],
749
+ objects: [],
750
+ natives: [],
751
+ sets: [],
752
+ maps: [],
753
+ }),
754
+ explore,
755
+ [],
756
+ ),
757
+ empty: config.success,
758
+ success: config.success,
759
+ failure: (input, expected, explore) =>
760
+ ts.factory.createReturnStatement(
761
+ config.joiner.failure(input, expected, explore),
762
+ ),
763
+ });
764
+
765
+ const explore_objects = (config: IConfig) => {
766
+ const objector = decode_object(config);
767
+
768
+ return (input: ts.Expression, meta: Metadata, explore: IExplore) => {
769
+ if (meta.objects.length === 1)
770
+ return objector(input, meta.objects[0]!, explore);
771
+
772
+ return ts.factory.createCallExpression(
773
+ ts.factory.createIdentifier(
774
+ `${config.unioners}${meta.union_index!}`,
775
+ ),
776
+ undefined,
777
+ FeatureProgrammer.get_object_arguments(config)(explore)(input),
778
+ );
779
+ };
780
+ };
781
+ }
782
+
783
+ const create_add =
784
+ (binaries: CheckerProgrammer.IBinary[]) =>
785
+ (defaultInput: ts.Expression) =>
786
+ (
787
+ exact: boolean,
788
+ left: ts.Expression,
789
+ right: ts.Expression = defaultInput,
790
+ ) => {
791
+ const factory = exact
792
+ ? ts.factory.createStrictEquality
793
+ : ts.factory.createStrictInequality;
794
+ binaries.push({
795
+ expression: factory(left, right),
796
+ combined: false,
797
+ });
798
+ };