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,444 +1,444 @@
1
- import ts from "typescript";
2
-
3
- import { IdentifierFactory } from "../factories/IdentifierFactory";
4
-
5
- // import { StatementFactory } from "../factories/StatementFactory";
6
- import { IProject } from "../transformers/IProject";
7
-
8
- import { CheckerProgrammer } from "./CheckerProgrammer";
9
- import { IsProgrammer } from "./IsProgrammer";
10
- import { FunctionImporter } from "./helpers/FunctionImporeter";
11
- import { check_object } from "./internal/check_object";
12
-
13
- // /* -----------------------------------------------------------
14
- // ASSERT V2 -> USE (NULL OR ERROR) CONDITION
15
- // ----------------------------------------------------------- */
16
- // export namespace AssertProgrammerV2 {
17
- // export const generate =
18
- // (
19
- // project: IProject,
20
- // modulo: ts.LeftHandSideExpression,
21
- // equals: boolean = false,
22
- // ) =>
23
- // (type: ts.Type) => {
24
- // const importer: FunctionImporter = new FunctionImporter();
25
- // const guardV2: ts.Expression = importer.use("guardV2");
26
-
27
- // const program: ts.ArrowFunction = CheckerProgrammer.generate(
28
- // project,
29
- // {
30
- // functors: "$ao",
31
- // unioners: "$au",
32
- // path: true,
33
- // trace: true,
34
- // numeric: !!project.options.numeric,
35
- // equals,
36
- // combiner,
37
- // joiner: joiner(equals)(importer),
38
- // success: ts.factory.createNull(),
39
- // },
40
- // importer,
41
- // )(type);
42
-
43
- // return ts.factory.createArrowFunction(
44
- // undefined,
45
- // undefined,
46
- // [IdentifierFactory.parameter("input")],
47
- // undefined,
48
- // undefined,
49
- // ts.factory.createBlock(
50
- // [
51
- // ...importer.declare(modulo),
52
- // StatementFactory.constant(
53
- // "error",
54
- // ts.factory.createCallExpression(
55
- // program,
56
- // undefined,
57
- // [
58
- // ValueFactory.INPUT(),
59
- // ts.factory.createStringLiteral("$input"),
60
- // ],
61
- // ),
62
- // ),
63
- // ts.factory.createIfStatement(
64
- // ts.factory.createStrictInequality(
65
- // ts.factory.createNull(),
66
- // ts.factory.createIdentifier("error"),
67
- // ),
68
- // ts.factory.createThrowStatement(
69
- // ts.factory.createCallExpression(
70
- // guardV2,
71
- // undefined,
72
- // [ts.factory.createIdentifier("error")],
73
- // ),
74
- // ),
75
- // ),
76
- // ts.factory.createReturnStatement(ValueFactory.INPUT()),
77
- // ],
78
- // true,
79
- // ),
80
- // );
81
- // };
82
-
83
- // const combiner: CheckerProgrammer.IConfig.Combiner = (
84
- // explore: CheckerProgrammer.IExplore,
85
- // ) => {
86
- // const path: string = explore.postfix
87
- // ? `path + ${explore.postfix}`
88
- // : "path";
89
- // return (logic) => (input, binaries, expected) =>
90
- // binaries
91
- // .map((binary) =>
92
- // binary.combined
93
- // ? binary.expression
94
- // : ts.factory.createParenthesizedExpression(
95
- // ts.factory.createConditionalExpression(
96
- // binary.expression,
97
- // undefined,
98
- // ts.factory.createNull(),
99
- // undefined,
100
- // create_exception_props(
101
- // ts.factory.createIdentifier(path),
102
- // expected,
103
- // input,
104
- // ),
105
- // ),
106
- // ),
107
- // )
108
- // .reduce(
109
- // logic === "and"
110
- // ? ts.factory.createLogicalOr
111
- // : ts.factory.createLogicalAnd,
112
- // );
113
- // };
114
-
115
- // const assert_object = (equals: boolean) => (importer: FunctionImporter) =>
116
- // check_object({
117
- // equals,
118
- // assert: true,
119
- // reduce: ts.factory.createLogicalOr,
120
- // positive: ts.factory.createNull(),
121
- // superfluous: (value) =>
122
- // create_exception_props(
123
- // ts.factory.createAdd(
124
- // ts.factory.createIdentifier("path"),
125
- // ts.factory.createCallExpression(
126
- // importer.use("join"),
127
- // undefined,
128
- // [ts.factory.createIdentifier("key")],
129
- // ),
130
- // ),
131
- // "undefined",
132
- // value,
133
- // ),
134
- // entries: importer.use("every"),
135
- // halt: (expr) =>
136
- // ts.factory.createConditionalExpression(
137
- // ts.factory.createStrictEquality(
138
- // ts.factory.createFalse(),
139
- // ts.factory.createIdentifier("exceptionable"),
140
- // ),
141
- // undefined,
142
- // ts.factory.createNull(),
143
- // undefined,
144
- // expr,
145
- // ),
146
- // });
147
-
148
- // const joiner =
149
- // (equals: boolean) =>
150
- // (importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
151
- // object: assert_object(equals)(importer),
152
- // array: (input, arrow) =>
153
- // ts.factory.createCallExpression(
154
- // importer.use("every"),
155
- // undefined,
156
- // [input, arrow],
157
- // ),
158
- // failure: (value, expected, explore) =>
159
- // create_exception_props(
160
- // ts.factory.createIdentifier(
161
- // explore?.postfix ? `path + ${explore.postfix}` : "path",
162
- // ),
163
- // expected,
164
- // value,
165
- // ),
166
- // is: (exp) =>
167
- // ts.factory.createStrictEquality(
168
- // ts.factory.createNull(),
169
- // ts.factory.createParenthesizedExpression(exp),
170
- // ),
171
- // required: (value) =>
172
- // ts.factory.createConditionalExpression(
173
- // value,
174
- // undefined,
175
- // ts.factory.createNull(),
176
- // undefined,
177
- // create_exception_props(
178
- // ts.factory.createStringLiteral(""),
179
- // "not undefined",
180
- // value,
181
- // ),
182
- // ),
183
- // full: equals
184
- // ? undefined
185
- // : (condition) => (input, expected) =>
186
- // ts.factory.createConditionalExpression(
187
- // ts.factory.createStrictEquality(
188
- // ts.factory.createNull(),
189
- // condition,
190
- // ),
191
- // undefined,
192
- // ts.factory.createNull(),
193
- // undefined,
194
- // create_exception_props(
195
- // ts.factory.createIdentifier("path"),
196
- // expected,
197
- // input,
198
- // ),
199
- // ),
200
- // });
201
-
202
- // function create_exception_props(
203
- // path: ts.Expression,
204
- // expected: string,
205
- // value: ts.Expression,
206
- // ): ts.ObjectLiteralExpression {
207
- // return ts.factory.createObjectLiteralExpression(
208
- // [
209
- // ts.factory.createPropertyAssignment("path", path),
210
- // ts.factory.createPropertyAssignment(
211
- // "expected",
212
- // ts.factory.createStringLiteral(expected),
213
- // ),
214
- // ts.factory.createPropertyAssignment("value", value),
215
- // ],
216
- // true,
217
- // );
218
- // }
219
- // }
220
-
221
- /* -----------------------------------------------------------
222
- ASSERT V3 -> (CONDITION OR THROW(exceptable): FALSE)
223
- ----------------------------------------------------------- */
224
- export namespace AssertProgrammer {
225
- export const generate =
226
- (
227
- project: IProject,
228
- modulo: ts.LeftHandSideExpression,
229
- equals: boolean = false,
230
- ) =>
231
- (type: ts.Type) => {
232
- const importer: FunctionImporter = new FunctionImporter();
233
- const program: ts.ArrowFunction = CheckerProgrammer.generate(
234
- project,
235
- {
236
- functors: "$ao",
237
- unioners: "$au",
238
- path: true,
239
- trace: true,
240
- numeric: !!project.options.numeric,
241
- equals,
242
- combiner: combiner(equals)(importer),
243
- joiner: joiner(equals)(importer),
244
- success: ts.factory.createTrue(),
245
- },
246
- importer,
247
- )(type);
248
-
249
- return ts.factory.createArrowFunction(
250
- undefined,
251
- undefined,
252
- [IdentifierFactory.parameter("input")],
253
- undefined,
254
- undefined,
255
- ts.factory.createBlock(
256
- [
257
- ...importer.declare(modulo),
258
- ts.factory.createExpressionStatement(
259
- ts.factory.createCallExpression(
260
- program,
261
- undefined,
262
- [
263
- ts.factory.createIdentifier("input"),
264
- ts.factory.createStringLiteral("$input"),
265
- ts.factory.createTrue(),
266
- ],
267
- ),
268
- ),
269
- ts.factory.createReturnStatement(
270
- ts.factory.createIdentifier("input"),
271
- ),
272
- ],
273
- true,
274
- ),
275
- );
276
- };
277
-
278
- const combiner =
279
- (equals: boolean) =>
280
- (importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
281
- (explore: CheckerProgrammer.IExplore) => {
282
- if (explore.tracable === false && explore.from !== "top")
283
- return IsProgrammer.CONFIG({
284
- object: assert_object(equals)(importer),
285
- numeric: true,
286
- }).combiner(explore);
287
-
288
- const path: string = explore.postfix
289
- ? `path + ${explore.postfix}`
290
- : "path";
291
- return (logic) => (input, binaries, expected) =>
292
- logic === "and"
293
- ? binaries
294
- .map((binary) =>
295
- binary.combined
296
- ? binary.expression
297
- : ts.factory.createLogicalOr(
298
- binary.expression,
299
- create_guard_call(importer)(
300
- explore.source === "top"
301
- ? ts.factory.createTrue()
302
- : ts.factory.createIdentifier(
303
- "exceptionable",
304
- ),
305
- )(
306
- ts.factory.createIdentifier(path),
307
- expected,
308
- input,
309
- ),
310
- ),
311
- )
312
- .reduce(ts.factory.createLogicalAnd)
313
- : (() => {
314
- const addicted = binaries.slice();
315
- if (
316
- addicted[addicted.length - 1]!.combined === false
317
- ) {
318
- addicted.push({
319
- combined: true,
320
- expression: create_guard_call(importer)(
321
- explore.source === "top"
322
- ? ts.factory.createTrue()
323
- : ts.factory.createIdentifier(
324
- "exceptionable",
325
- ),
326
- )(
327
- ts.factory.createIdentifier(path),
328
- expected,
329
- input,
330
- ),
331
- });
332
- }
333
- return addicted
334
- .map((b) => b.expression)
335
- .reduce(ts.factory.createLogicalOr);
336
- })();
337
-
338
- // ts.factory.createLogicalOr(
339
- // binaries
340
- // .map((binary) => binary.expression)
341
- // .reduce(ts.factory.createLogicalOr),
342
- // create_guard_call(importer)(
343
- // explore.source === "top"
344
- // ? ts.factory.createTrue()
345
- // : ts.factory.createIdentifier(
346
- // "exceptionable",
347
- // ),
348
- // )(ts.factory.createIdentifier(path), expected, input),
349
- // );
350
- };
351
-
352
- const assert_object = (equals: boolean) => (importer: FunctionImporter) =>
353
- check_object({
354
- equals,
355
- assert: true,
356
- reduce: ts.factory.createLogicalAnd,
357
- positive: ts.factory.createTrue(),
358
- superfluous: (value) =>
359
- create_guard_call(importer)()(
360
- ts.factory.createAdd(
361
- ts.factory.createIdentifier("path"),
362
- ts.factory.createCallExpression(
363
- importer.use("join"),
364
- undefined,
365
- [ts.factory.createIdentifier("key")],
366
- ),
367
- ),
368
- "undefined",
369
- value,
370
- ),
371
- halt: (expr) =>
372
- ts.factory.createLogicalOr(
373
- ts.factory.createStrictEquality(
374
- ts.factory.createFalse(),
375
- ts.factory.createIdentifier("exceptionable"),
376
- ),
377
- expr,
378
- ),
379
- });
380
-
381
- const joiner =
382
- (equals: boolean) =>
383
- (importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
384
- object: assert_object(equals)(importer),
385
- array: (input, arrow) =>
386
- ts.factory.createCallExpression(
387
- IdentifierFactory.join(input, "every"),
388
- undefined,
389
- [arrow],
390
- ),
391
- failure: (value, expected, explore) =>
392
- create_guard_call(importer)(
393
- explore?.from === "top"
394
- ? ts.factory.createTrue()
395
- : ts.factory.createIdentifier("exceptionable"),
396
- )(
397
- ts.factory.createIdentifier(
398
- explore?.postfix ? `path + ${explore.postfix}` : "path",
399
- ),
400
- expected,
401
- value,
402
- ),
403
- full: equals
404
- ? undefined
405
- : (condition) => (input, expected, explore) =>
406
- ts.factory.createLogicalOr(
407
- condition,
408
- create_guard_call(importer)(
409
- explore.from === "top"
410
- ? ts.factory.createTrue()
411
- : ts.factory.createIdentifier(
412
- "exceptionable",
413
- ),
414
- )(
415
- ts.factory.createIdentifier("path"),
416
- expected,
417
- input,
418
- ),
419
- ),
420
- });
421
-
422
- const create_guard_call =
423
- (importer: FunctionImporter) =>
424
- (exceptionable?: ts.Expression) =>
425
- (
426
- path: ts.Expression,
427
- expected: string,
428
- value: ts.Expression,
429
- ): ts.Expression =>
430
- ts.factory.createCallExpression(importer.use("guard"), undefined, [
431
- exceptionable || ts.factory.createIdentifier("exceptionable"),
432
- ts.factory.createObjectLiteralExpression(
433
- [
434
- ts.factory.createPropertyAssignment("path", path),
435
- ts.factory.createPropertyAssignment(
436
- "expected",
437
- ts.factory.createStringLiteral(expected),
438
- ),
439
- ts.factory.createPropertyAssignment("value", value),
440
- ],
441
- true,
442
- ),
443
- ]);
444
- }
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "../factories/IdentifierFactory";
4
+
5
+ // import { StatementFactory } from "../factories/StatementFactory";
6
+ import { IProject } from "../transformers/IProject";
7
+
8
+ import { CheckerProgrammer } from "./CheckerProgrammer";
9
+ import { IsProgrammer } from "./IsProgrammer";
10
+ import { FunctionImporter } from "./helpers/FunctionImporeter";
11
+ import { check_object } from "./internal/check_object";
12
+
13
+ // /* -----------------------------------------------------------
14
+ // ASSERT V2 -> USE (NULL OR ERROR) CONDITION
15
+ // ----------------------------------------------------------- */
16
+ // export namespace AssertProgrammerV2 {
17
+ // export const generate =
18
+ // (
19
+ // project: IProject,
20
+ // modulo: ts.LeftHandSideExpression,
21
+ // equals: boolean = false,
22
+ // ) =>
23
+ // (type: ts.Type) => {
24
+ // const importer: FunctionImporter = new FunctionImporter();
25
+ // const guardV2: ts.Expression = importer.use("guardV2");
26
+
27
+ // const program: ts.ArrowFunction = CheckerProgrammer.generate(
28
+ // project,
29
+ // {
30
+ // functors: "$ao",
31
+ // unioners: "$au",
32
+ // path: true,
33
+ // trace: true,
34
+ // numeric: !!project.options.numeric,
35
+ // equals,
36
+ // combiner,
37
+ // joiner: joiner(equals)(importer),
38
+ // success: ts.factory.createNull(),
39
+ // },
40
+ // importer,
41
+ // )(type);
42
+
43
+ // return ts.factory.createArrowFunction(
44
+ // undefined,
45
+ // undefined,
46
+ // [IdentifierFactory.parameter("input")],
47
+ // undefined,
48
+ // undefined,
49
+ // ts.factory.createBlock(
50
+ // [
51
+ // ...importer.declare(modulo),
52
+ // StatementFactory.constant(
53
+ // "error",
54
+ // ts.factory.createCallExpression(
55
+ // program,
56
+ // undefined,
57
+ // [
58
+ // ValueFactory.INPUT(),
59
+ // ts.factory.createStringLiteral("$input"),
60
+ // ],
61
+ // ),
62
+ // ),
63
+ // ts.factory.createIfStatement(
64
+ // ts.factory.createStrictInequality(
65
+ // ts.factory.createNull(),
66
+ // ts.factory.createIdentifier("error"),
67
+ // ),
68
+ // ts.factory.createThrowStatement(
69
+ // ts.factory.createCallExpression(
70
+ // guardV2,
71
+ // undefined,
72
+ // [ts.factory.createIdentifier("error")],
73
+ // ),
74
+ // ),
75
+ // ),
76
+ // ts.factory.createReturnStatement(ValueFactory.INPUT()),
77
+ // ],
78
+ // true,
79
+ // ),
80
+ // );
81
+ // };
82
+
83
+ // const combiner: CheckerProgrammer.IConfig.Combiner = (
84
+ // explore: CheckerProgrammer.IExplore,
85
+ // ) => {
86
+ // const path: string = explore.postfix
87
+ // ? `path + ${explore.postfix}`
88
+ // : "path";
89
+ // return (logic) => (input, binaries, expected) =>
90
+ // binaries
91
+ // .map((binary) =>
92
+ // binary.combined
93
+ // ? binary.expression
94
+ // : ts.factory.createParenthesizedExpression(
95
+ // ts.factory.createConditionalExpression(
96
+ // binary.expression,
97
+ // undefined,
98
+ // ts.factory.createNull(),
99
+ // undefined,
100
+ // create_exception_props(
101
+ // ts.factory.createIdentifier(path),
102
+ // expected,
103
+ // input,
104
+ // ),
105
+ // ),
106
+ // ),
107
+ // )
108
+ // .reduce(
109
+ // logic === "and"
110
+ // ? ts.factory.createLogicalOr
111
+ // : ts.factory.createLogicalAnd,
112
+ // );
113
+ // };
114
+
115
+ // const assert_object = (equals: boolean) => (importer: FunctionImporter) =>
116
+ // check_object({
117
+ // equals,
118
+ // assert: true,
119
+ // reduce: ts.factory.createLogicalOr,
120
+ // positive: ts.factory.createNull(),
121
+ // superfluous: (value) =>
122
+ // create_exception_props(
123
+ // ts.factory.createAdd(
124
+ // ts.factory.createIdentifier("path"),
125
+ // ts.factory.createCallExpression(
126
+ // importer.use("join"),
127
+ // undefined,
128
+ // [ts.factory.createIdentifier("key")],
129
+ // ),
130
+ // ),
131
+ // "undefined",
132
+ // value,
133
+ // ),
134
+ // entries: importer.use("every"),
135
+ // halt: (expr) =>
136
+ // ts.factory.createConditionalExpression(
137
+ // ts.factory.createStrictEquality(
138
+ // ts.factory.createFalse(),
139
+ // ts.factory.createIdentifier("exceptionable"),
140
+ // ),
141
+ // undefined,
142
+ // ts.factory.createNull(),
143
+ // undefined,
144
+ // expr,
145
+ // ),
146
+ // });
147
+
148
+ // const joiner =
149
+ // (equals: boolean) =>
150
+ // (importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
151
+ // object: assert_object(equals)(importer),
152
+ // array: (input, arrow) =>
153
+ // ts.factory.createCallExpression(
154
+ // importer.use("every"),
155
+ // undefined,
156
+ // [input, arrow],
157
+ // ),
158
+ // failure: (value, expected, explore) =>
159
+ // create_exception_props(
160
+ // ts.factory.createIdentifier(
161
+ // explore?.postfix ? `path + ${explore.postfix}` : "path",
162
+ // ),
163
+ // expected,
164
+ // value,
165
+ // ),
166
+ // is: (exp) =>
167
+ // ts.factory.createStrictEquality(
168
+ // ts.factory.createNull(),
169
+ // ts.factory.createParenthesizedExpression(exp),
170
+ // ),
171
+ // required: (value) =>
172
+ // ts.factory.createConditionalExpression(
173
+ // value,
174
+ // undefined,
175
+ // ts.factory.createNull(),
176
+ // undefined,
177
+ // create_exception_props(
178
+ // ts.factory.createStringLiteral(""),
179
+ // "not undefined",
180
+ // value,
181
+ // ),
182
+ // ),
183
+ // full: equals
184
+ // ? undefined
185
+ // : (condition) => (input, expected) =>
186
+ // ts.factory.createConditionalExpression(
187
+ // ts.factory.createStrictEquality(
188
+ // ts.factory.createNull(),
189
+ // condition,
190
+ // ),
191
+ // undefined,
192
+ // ts.factory.createNull(),
193
+ // undefined,
194
+ // create_exception_props(
195
+ // ts.factory.createIdentifier("path"),
196
+ // expected,
197
+ // input,
198
+ // ),
199
+ // ),
200
+ // });
201
+
202
+ // function create_exception_props(
203
+ // path: ts.Expression,
204
+ // expected: string,
205
+ // value: ts.Expression,
206
+ // ): ts.ObjectLiteralExpression {
207
+ // return ts.factory.createObjectLiteralExpression(
208
+ // [
209
+ // ts.factory.createPropertyAssignment("path", path),
210
+ // ts.factory.createPropertyAssignment(
211
+ // "expected",
212
+ // ts.factory.createStringLiteral(expected),
213
+ // ),
214
+ // ts.factory.createPropertyAssignment("value", value),
215
+ // ],
216
+ // true,
217
+ // );
218
+ // }
219
+ // }
220
+
221
+ /* -----------------------------------------------------------
222
+ ASSERT V3 -> (CONDITION OR THROW(exceptable): FALSE)
223
+ ----------------------------------------------------------- */
224
+ export namespace AssertProgrammer {
225
+ export const generate =
226
+ (
227
+ project: IProject,
228
+ modulo: ts.LeftHandSideExpression,
229
+ equals: boolean = false,
230
+ ) =>
231
+ (type: ts.Type) => {
232
+ const importer: FunctionImporter = new FunctionImporter();
233
+ const program: ts.ArrowFunction = CheckerProgrammer.generate(
234
+ project,
235
+ {
236
+ functors: "$ao",
237
+ unioners: "$au",
238
+ path: true,
239
+ trace: true,
240
+ numeric: !!project.options.numeric,
241
+ equals,
242
+ combiner: combiner(equals)(importer),
243
+ joiner: joiner(equals)(importer),
244
+ success: ts.factory.createTrue(),
245
+ },
246
+ importer,
247
+ )(type);
248
+
249
+ return ts.factory.createArrowFunction(
250
+ undefined,
251
+ undefined,
252
+ [IdentifierFactory.parameter("input")],
253
+ undefined,
254
+ undefined,
255
+ ts.factory.createBlock(
256
+ [
257
+ ...importer.declare(modulo),
258
+ ts.factory.createExpressionStatement(
259
+ ts.factory.createCallExpression(
260
+ program,
261
+ undefined,
262
+ [
263
+ ts.factory.createIdentifier("input"),
264
+ ts.factory.createStringLiteral("$input"),
265
+ ts.factory.createTrue(),
266
+ ],
267
+ ),
268
+ ),
269
+ ts.factory.createReturnStatement(
270
+ ts.factory.createIdentifier("input"),
271
+ ),
272
+ ],
273
+ true,
274
+ ),
275
+ );
276
+ };
277
+
278
+ const combiner =
279
+ (equals: boolean) =>
280
+ (importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
281
+ (explore: CheckerProgrammer.IExplore) => {
282
+ if (explore.tracable === false && explore.from !== "top")
283
+ return IsProgrammer.CONFIG({
284
+ object: assert_object(equals)(importer),
285
+ numeric: true,
286
+ }).combiner(explore);
287
+
288
+ const path: string = explore.postfix
289
+ ? `path + ${explore.postfix}`
290
+ : "path";
291
+ return (logic) => (input, binaries, expected) =>
292
+ logic === "and"
293
+ ? binaries
294
+ .map((binary) =>
295
+ binary.combined
296
+ ? binary.expression
297
+ : ts.factory.createLogicalOr(
298
+ binary.expression,
299
+ create_guard_call(importer)(
300
+ explore.source === "top"
301
+ ? ts.factory.createTrue()
302
+ : ts.factory.createIdentifier(
303
+ "exceptionable",
304
+ ),
305
+ )(
306
+ ts.factory.createIdentifier(path),
307
+ expected,
308
+ input,
309
+ ),
310
+ ),
311
+ )
312
+ .reduce(ts.factory.createLogicalAnd)
313
+ : (() => {
314
+ const addicted = binaries.slice();
315
+ if (
316
+ addicted[addicted.length - 1]!.combined === false
317
+ ) {
318
+ addicted.push({
319
+ combined: true,
320
+ expression: create_guard_call(importer)(
321
+ explore.source === "top"
322
+ ? ts.factory.createTrue()
323
+ : ts.factory.createIdentifier(
324
+ "exceptionable",
325
+ ),
326
+ )(
327
+ ts.factory.createIdentifier(path),
328
+ expected,
329
+ input,
330
+ ),
331
+ });
332
+ }
333
+ return addicted
334
+ .map((b) => b.expression)
335
+ .reduce(ts.factory.createLogicalOr);
336
+ })();
337
+
338
+ // ts.factory.createLogicalOr(
339
+ // binaries
340
+ // .map((binary) => binary.expression)
341
+ // .reduce(ts.factory.createLogicalOr),
342
+ // create_guard_call(importer)(
343
+ // explore.source === "top"
344
+ // ? ts.factory.createTrue()
345
+ // : ts.factory.createIdentifier(
346
+ // "exceptionable",
347
+ // ),
348
+ // )(ts.factory.createIdentifier(path), expected, input),
349
+ // );
350
+ };
351
+
352
+ const assert_object = (equals: boolean) => (importer: FunctionImporter) =>
353
+ check_object({
354
+ equals,
355
+ assert: true,
356
+ reduce: ts.factory.createLogicalAnd,
357
+ positive: ts.factory.createTrue(),
358
+ superfluous: (value) =>
359
+ create_guard_call(importer)()(
360
+ ts.factory.createAdd(
361
+ ts.factory.createIdentifier("path"),
362
+ ts.factory.createCallExpression(
363
+ importer.use("join"),
364
+ undefined,
365
+ [ts.factory.createIdentifier("key")],
366
+ ),
367
+ ),
368
+ "undefined",
369
+ value,
370
+ ),
371
+ halt: (expr) =>
372
+ ts.factory.createLogicalOr(
373
+ ts.factory.createStrictEquality(
374
+ ts.factory.createFalse(),
375
+ ts.factory.createIdentifier("exceptionable"),
376
+ ),
377
+ expr,
378
+ ),
379
+ });
380
+
381
+ const joiner =
382
+ (equals: boolean) =>
383
+ (importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
384
+ object: assert_object(equals)(importer),
385
+ array: (input, arrow) =>
386
+ ts.factory.createCallExpression(
387
+ IdentifierFactory.join(input, "every"),
388
+ undefined,
389
+ [arrow],
390
+ ),
391
+ failure: (value, expected, explore) =>
392
+ create_guard_call(importer)(
393
+ explore?.from === "top"
394
+ ? ts.factory.createTrue()
395
+ : ts.factory.createIdentifier("exceptionable"),
396
+ )(
397
+ ts.factory.createIdentifier(
398
+ explore?.postfix ? `path + ${explore.postfix}` : "path",
399
+ ),
400
+ expected,
401
+ value,
402
+ ),
403
+ full: equals
404
+ ? undefined
405
+ : (condition) => (input, expected, explore) =>
406
+ ts.factory.createLogicalOr(
407
+ condition,
408
+ create_guard_call(importer)(
409
+ explore.from === "top"
410
+ ? ts.factory.createTrue()
411
+ : ts.factory.createIdentifier(
412
+ "exceptionable",
413
+ ),
414
+ )(
415
+ ts.factory.createIdentifier("path"),
416
+ expected,
417
+ input,
418
+ ),
419
+ ),
420
+ });
421
+
422
+ const create_guard_call =
423
+ (importer: FunctionImporter) =>
424
+ (exceptionable?: ts.Expression) =>
425
+ (
426
+ path: ts.Expression,
427
+ expected: string,
428
+ value: ts.Expression,
429
+ ): ts.Expression =>
430
+ ts.factory.createCallExpression(importer.use("guard"), undefined, [
431
+ exceptionable || ts.factory.createIdentifier("exceptionable"),
432
+ ts.factory.createObjectLiteralExpression(
433
+ [
434
+ ts.factory.createPropertyAssignment("path", path),
435
+ ts.factory.createPropertyAssignment(
436
+ "expected",
437
+ ts.factory.createStringLiteral(expected),
438
+ ),
439
+ ts.factory.createPropertyAssignment("value", value),
440
+ ],
441
+ true,
442
+ ),
443
+ ]);
444
+ }