typia 5.0.0-dev.20230823-2 → 5.0.0-dev.2023084

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 (148) hide show
  1. package/lib/factories/MetadataTagFactory.js +4 -2
  2. package/lib/factories/MetadataTagFactory.js.map +1 -1
  3. package/lib/factories/ProtobufFactory.js +2 -1
  4. package/lib/factories/ProtobufFactory.js.map +1 -1
  5. package/lib/factories/internal/metadata/emend_metadata_atomics.js +6 -6
  6. package/lib/factories/internal/metadata/emend_metadata_atomics.js.map +1 -1
  7. package/lib/factories/internal/metadata/iterate_metadata_atomic.js +1 -1
  8. package/lib/factories/internal/metadata/iterate_metadata_atomic.js.map +1 -1
  9. package/lib/programmers/CheckerProgrammer.js +6 -6
  10. package/lib/programmers/CheckerProgrammer.js.map +1 -1
  11. package/lib/programmers/RandomProgrammer.js +5 -5
  12. package/lib/programmers/RandomProgrammer.js.map +1 -1
  13. package/lib/programmers/helpers/AtomicPredicator.js +2 -2
  14. package/lib/programmers/helpers/AtomicPredicator.js.map +1 -1
  15. package/lib/programmers/helpers/ProtobufUtil.js +2 -2
  16. package/lib/programmers/helpers/ProtobufUtil.js.map +1 -1
  17. package/lib/programmers/internal/application_default_string.js +2 -2
  18. package/lib/programmers/internal/application_default_string.js.map +1 -1
  19. package/lib/programmers/internal/application_schema.js +5 -5
  20. package/lib/programmers/internal/application_schema.js.map +1 -1
  21. package/lib/programmers/internal/metadata_to_pattern.js +4 -4
  22. package/lib/programmers/internal/metadata_to_pattern.js.map +1 -1
  23. package/lib/programmers/internal/stringify_dynamic_properties.js +2 -1
  24. package/lib/programmers/internal/stringify_dynamic_properties.js.map +1 -1
  25. package/lib/programmers/json/JsonStringifyProgrammer.js +16 -10
  26. package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
  27. package/lib/programmers/misc/MiscLiteralsProgrammer.js +2 -2
  28. package/lib/programmers/misc/MiscLiteralsProgrammer.js.map +1 -1
  29. package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js +1 -1
  30. package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js.map +1 -1
  31. package/lib/schemas/metadata/IMetadata.d.ts +2 -2
  32. package/lib/schemas/metadata/IMetadataAtomic.d.ts +12 -0
  33. package/lib/schemas/metadata/IMetadataAtomic.js +3 -0
  34. package/lib/schemas/metadata/IMetadataAtomic.js.map +1 -0
  35. package/lib/schemas/metadata/Metadata.d.ts +2 -2
  36. package/lib/schemas/metadata/Metadata.js +49 -44
  37. package/lib/schemas/metadata/Metadata.js.map +1 -1
  38. package/lib/tags/ExclusiveMaximum.d.ts +8 -0
  39. package/lib/tags/ExclusiveMaximum.js +3 -0
  40. package/lib/tags/ExclusiveMaximum.js.map +1 -0
  41. package/lib/tags/ExclusiveMinimum.d.ts +8 -0
  42. package/lib/tags/ExclusiveMinimum.js +3 -0
  43. package/lib/tags/ExclusiveMinimum.js.map +1 -0
  44. package/lib/tags/Format.d.ts +8 -0
  45. package/lib/tags/Format.js +3 -0
  46. package/lib/tags/Format.js.map +1 -0
  47. package/lib/tags/MaxItems.d.ts +8 -0
  48. package/lib/tags/MaxItems.js +3 -0
  49. package/lib/tags/MaxItems.js.map +1 -0
  50. package/lib/tags/MaxLength.d.ts +8 -0
  51. package/lib/tags/MaxLength.js +3 -0
  52. package/lib/tags/MaxLength.js.map +1 -0
  53. package/lib/tags/Maximum.d.ts +8 -0
  54. package/lib/tags/Maximum.js +3 -0
  55. package/lib/tags/Maximum.js.map +1 -0
  56. package/lib/tags/MinItems.d.ts +8 -0
  57. package/lib/tags/MinItems.js +3 -0
  58. package/lib/tags/MinItems.js.map +1 -0
  59. package/lib/tags/MinLength.d.ts +8 -0
  60. package/lib/tags/MinLength.js +3 -0
  61. package/lib/tags/MinLength.js.map +1 -0
  62. package/lib/tags/Minimum.d.ts +8 -0
  63. package/lib/tags/Minimum.js +3 -0
  64. package/lib/tags/Minimum.js.map +1 -0
  65. package/lib/tags/MultipleOf.d.ts +8 -0
  66. package/lib/tags/MultipleOf.js +3 -0
  67. package/lib/tags/MultipleOf.js.map +1 -0
  68. package/lib/tags/Pattern.d.ts +8 -0
  69. package/lib/tags/Pattern.js +3 -0
  70. package/lib/tags/Pattern.js.map +1 -0
  71. package/lib/tags/TagBase.d.ts +10 -0
  72. package/lib/tags/TagBase.js +3 -0
  73. package/lib/tags/TagBase.js.map +1 -0
  74. package/lib/tags/Type.d.ts +13 -0
  75. package/lib/tags/Type.js +3 -0
  76. package/lib/tags/Type.js.map +1 -0
  77. package/lib/tags/index.d.ts +12 -0
  78. package/lib/tags/index.js +29 -0
  79. package/lib/tags/index.js.map +1 -0
  80. package/lib/transformers/features/json/JsonApplicationTransformer.js +1 -1
  81. package/lib/transformers/features/json/JsonApplicationTransformer.js.map +1 -1
  82. package/package.json +1 -1
  83. package/src/Primitive.ts +135 -135
  84. package/src/Resolved.ts +116 -116
  85. package/src/factories/MetadataFactory.ts +46 -46
  86. package/src/factories/MetadataTagFactory.ts +366 -364
  87. package/src/factories/ProtobufFactory.ts +268 -266
  88. package/src/factories/internal/metadata/emend_metadata_atomics.ts +35 -33
  89. package/src/factories/internal/metadata/explore_metadata.ts +38 -38
  90. package/src/factories/internal/metadata/iterate_metadata_atomic.ts +63 -59
  91. package/src/factories/internal/metadata/iterate_metadata_collection.ts +133 -133
  92. package/src/factories/internal/metadata/iterate_metadata_native.ts +210 -210
  93. package/src/factories/internal/metadata/iterate_metadata_resolve.ts +49 -49
  94. package/src/factories/internal/metadata/iterate_metadata_sort.ts +69 -69
  95. package/src/functional/$ProtobufWriter.ts +151 -151
  96. package/src/json.ts +648 -648
  97. package/src/misc.ts +651 -651
  98. package/src/module.ts +709 -709
  99. package/src/programmers/AssertProgrammer.ts +281 -281
  100. package/src/programmers/CheckerProgrammer.ts +1174 -1173
  101. package/src/programmers/IsProgrammer.ts +241 -241
  102. package/src/programmers/RandomProgrammer.ts +874 -874
  103. package/src/programmers/ValidateProgrammer.ts +307 -307
  104. package/src/programmers/helpers/AtomicPredicator.ts +31 -31
  105. package/src/programmers/helpers/FunctionImporeter.ts +91 -91
  106. package/src/programmers/helpers/ProtobufUtil.ts +29 -29
  107. package/src/programmers/helpers/StringifyPredicator.ts +12 -12
  108. package/src/programmers/helpers/disable_function_importer_declare.ts +32 -32
  109. package/src/programmers/internal/application_default_string.ts +37 -33
  110. package/src/programmers/internal/application_resolved.ts +55 -55
  111. package/src/programmers/internal/application_schema.ts +157 -157
  112. package/src/programmers/internal/metadata_to_pattern.ts +34 -34
  113. package/src/programmers/internal/stringify_dynamic_properties.ts +171 -171
  114. package/src/programmers/json/JsonStringifyProgrammer.ts +995 -989
  115. package/src/programmers/misc/MiscAssertCloneProgrammer.ts +71 -71
  116. package/src/programmers/misc/MiscCloneProgrammer.ts +775 -775
  117. package/src/programmers/misc/MiscIsCloneProgrammer.ts +78 -78
  118. package/src/programmers/misc/MiscLiteralsProgrammer.ts +64 -64
  119. package/src/programmers/misc/MiscPruneProgrammer.ts +544 -544
  120. package/src/programmers/misc/MiscValidateCloneProgrammer.ts +85 -85
  121. package/src/programmers/protobuf/ProtobufAssertDecodeProgrammer.ts +75 -75
  122. package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +673 -673
  123. package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +814 -814
  124. package/src/programmers/protobuf/ProtobufIsDecodeProgrammer.ts +85 -85
  125. package/src/programmers/protobuf/ProtobufValidateDecodeProgrammer.ts +75 -75
  126. package/src/protobuf.ts +881 -881
  127. package/src/schemas/metadata/IMetadata.ts +27 -28
  128. package/src/schemas/metadata/IMetadataAtomic.ts +13 -0
  129. package/src/schemas/metadata/IMetadataEscaped.ts +6 -6
  130. package/src/schemas/metadata/Metadata.ts +643 -634
  131. package/src/schemas/metadata/MetadataEscaped.ts +51 -51
  132. package/src/tags/ExclusiveMaximum.ts +8 -0
  133. package/src/tags/ExclusiveMinimum.ts +8 -0
  134. package/src/tags/Format.ts +29 -0
  135. package/src/tags/MaxItems.ts +8 -0
  136. package/src/tags/MaxLength.ts +8 -0
  137. package/src/tags/Maximum.ts +8 -0
  138. package/src/tags/MinItems.ts +8 -0
  139. package/src/tags/MinLength.ts +8 -0
  140. package/src/tags/Minimum.ts +8 -0
  141. package/src/tags/MultipleOf.ts +10 -0
  142. package/src/tags/Pattern.ts +8 -0
  143. package/src/tags/TagBase.ts +17 -0
  144. package/src/tags/Type.ts +30 -0
  145. package/src/tags/index.ts +12 -0
  146. package/src/transformers/features/json/JsonApplicationTransformer.ts +111 -111
  147. package/src/transformers/features/misc/MetadataTransformer.ts +53 -53
  148. package/src/utils/RandomGenerator.ts +83 -83
@@ -1,307 +1,307 @@
1
- import ts from "typescript";
2
-
3
- import { IdentifierFactory } from "../factories/IdentifierFactory";
4
- import { StatementFactory } from "../factories/StatementFactory";
5
- import { TypeFactory } from "../factories/TypeFactory";
6
-
7
- import { IProject } from "../transformers/IProject";
8
-
9
- import { CheckerProgrammer } from "./CheckerProgrammer";
10
- import { IsProgrammer } from "./IsProgrammer";
11
- import { FunctionImporter } from "./helpers/FunctionImporeter";
12
- import { OptionPredicator } from "./helpers/OptionPredicator";
13
- import { check_everything } from "./internal/check_everything";
14
- import { check_object } from "./internal/check_object";
15
-
16
- export namespace ValidateProgrammer {
17
- export const write =
18
- (project: IProject) =>
19
- (modulo: ts.LeftHandSideExpression) =>
20
- (equals: boolean) =>
21
- (type: ts.Type, name?: string) => {
22
- const importer: FunctionImporter = new FunctionImporter(
23
- modulo.getText(),
24
- );
25
-
26
- const is = IsProgrammer.write(project)(modulo, true)(equals)(
27
- type,
28
- name ?? TypeFactory.getFullName(project.checker)(type),
29
- );
30
- const validate: ts.ArrowFunction = CheckerProgrammer.write(project)(
31
- {
32
- prefix: "$v",
33
- path: true,
34
- trace: true,
35
- numeric: OptionPredicator.numeric(project.options),
36
- equals,
37
- atomist: (explore) => (tuple) => (input) =>
38
- [
39
- tuple.expression,
40
- ...tuple.tags.map((tag) =>
41
- ts.factory.createLogicalOr(
42
- tag.expression,
43
- create_report_call(
44
- explore.from === "top"
45
- ? ts.factory.createTrue()
46
- : ts.factory.createIdentifier(
47
- "_exceptionable",
48
- ),
49
- )(
50
- ts.factory.createIdentifier(
51
- explore.postfix
52
- ? `_path + ${explore.postfix}`
53
- : "_path",
54
- ),
55
- tag.expected,
56
- input,
57
- ),
58
- ),
59
- ),
60
- ].reduce((x, y) => ts.factory.createLogicalAnd(x, y)),
61
- combiner: combine(equals)(importer),
62
- joiner: joiner(equals)(importer),
63
- success: ts.factory.createTrue(),
64
- addition: () => importer.declare(modulo),
65
- },
66
- )(importer)(type, name);
67
-
68
- return ts.factory.createArrowFunction(
69
- undefined,
70
- undefined,
71
- [
72
- IdentifierFactory.parameter(
73
- "input",
74
- TypeFactory.keyword("any"),
75
- ),
76
- ],
77
- ts.factory.createTypeReferenceNode(
78
- `typia.IValidation<${
79
- name ?? TypeFactory.getFullName(project.checker)(type)
80
- }>`,
81
- ),
82
- undefined,
83
- ts.factory.createBlock(
84
- [
85
- StatementFactory.constant(
86
- "errors",
87
- ts.factory.createAsExpression(
88
- ts.factory.createArrayLiteralExpression([]),
89
- ts.factory.createArrayTypeNode(
90
- TypeFactory.keyword("any"),
91
- ),
92
- ),
93
- ),
94
- StatementFactory.constant("__is", is),
95
- ts.factory.createIfStatement(
96
- ts.factory.createStrictEquality(
97
- ts.factory.createFalse(),
98
- ts.factory.createCallExpression(
99
- ts.factory.createIdentifier("__is"),
100
- undefined,
101
- [ts.factory.createIdentifier("input")],
102
- ),
103
- ),
104
- ts.factory.createBlock([
105
- StatementFactory.constant(
106
- "$report",
107
- ts.factory.createCallExpression(
108
- IdentifierFactory.access(
109
- ts.factory.createParenthesizedExpression(
110
- ts.factory.createAsExpression(
111
- modulo,
112
- TypeFactory.keyword("any"),
113
- ),
114
- ),
115
- )("report"),
116
- [],
117
- [ts.factory.createIdentifier("errors")],
118
- ),
119
- ),
120
- ts.factory.createExpressionStatement(
121
- ts.factory.createCallExpression(
122
- validate,
123
- undefined,
124
- [
125
- ts.factory.createIdentifier(
126
- "input",
127
- ),
128
- ts.factory.createStringLiteral(
129
- "$input",
130
- ),
131
- ts.factory.createTrue(),
132
- ],
133
- ),
134
- ),
135
- ]),
136
- ),
137
- StatementFactory.constant(
138
- "success",
139
- ts.factory.createStrictEquality(
140
- ts.factory.createNumericLiteral(0),
141
- ts.factory.createIdentifier("errors.length"),
142
- ),
143
- ),
144
- ts.factory.createReturnStatement(
145
- ts.factory.createAsExpression(
146
- create_output(),
147
- TypeFactory.keyword("any"),
148
- ),
149
- ),
150
- ],
151
- true,
152
- ),
153
- );
154
- };
155
- }
156
-
157
- const combine =
158
- (equals: boolean) =>
159
- (importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
160
- (explore: CheckerProgrammer.IExplore) => {
161
- if (explore.tracable === false)
162
- return IsProgrammer.configure({
163
- object: validate_object(equals)(importer),
164
- numeric: true,
165
- })(importer).combiner(explore);
166
-
167
- const path: string = explore.postfix
168
- ? `_path + ${explore.postfix}`
169
- : "_path";
170
- return (logic) => (input, binaries, expected) =>
171
- logic === "and"
172
- ? binaries
173
- .map((binary) =>
174
- binary.combined
175
- ? binary.expression
176
- : ts.factory.createLogicalOr(
177
- binary.expression,
178
- create_report_call(
179
- explore.source === "top"
180
- ? ts.factory.createTrue()
181
- : ts.factory.createIdentifier(
182
- "_exceptionable",
183
- ),
184
- )(
185
- ts.factory.createIdentifier(path),
186
- expected,
187
- input,
188
- ),
189
- ),
190
- )
191
- .reduce(ts.factory.createLogicalAnd)
192
- : ts.factory.createLogicalOr(
193
- binaries
194
- .map((binary) => binary.expression)
195
- .reduce(ts.factory.createLogicalOr),
196
- create_report_call(
197
- explore.source === "top"
198
- ? ts.factory.createTrue()
199
- : ts.factory.createIdentifier("_exceptionable"),
200
- )(ts.factory.createIdentifier(path), expected, input),
201
- );
202
- };
203
-
204
- const validate_object = (equals: boolean) => (importer: FunctionImporter) =>
205
- check_object({
206
- equals,
207
- undefined: true,
208
- assert: false,
209
- reduce: ts.factory.createLogicalAnd,
210
- positive: ts.factory.createTrue(),
211
- superfluous: (value) =>
212
- create_report_call()(
213
- ts.factory.createAdd(
214
- ts.factory.createIdentifier("_path"),
215
- ts.factory.createCallExpression(
216
- importer.use("join"),
217
- undefined,
218
- [ts.factory.createIdentifier("key")],
219
- ),
220
- ),
221
- "undefined",
222
- value,
223
- ),
224
- halt: (expr) =>
225
- ts.factory.createLogicalOr(
226
- ts.factory.createStrictEquality(
227
- ts.factory.createFalse(),
228
- ts.factory.createIdentifier("_exceptionable"),
229
- ),
230
- expr,
231
- ),
232
- })(importer);
233
-
234
- const joiner =
235
- (equals: boolean) =>
236
- (importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
237
- object: validate_object(equals)(importer),
238
- array: (input, arrow) =>
239
- check_everything(
240
- ts.factory.createCallExpression(
241
- IdentifierFactory.access(input)("map"),
242
- undefined,
243
- [arrow],
244
- ),
245
- ),
246
- failure: (value, expected, explore) =>
247
- create_report_call(
248
- explore?.from === "top"
249
- ? ts.factory.createTrue()
250
- : ts.factory.createIdentifier("_exceptionable"),
251
- )(
252
- ts.factory.createIdentifier(
253
- explore?.postfix ? `_path + ${explore.postfix}` : "_path",
254
- ),
255
- expected,
256
- value,
257
- ),
258
- tuple: (binaries) =>
259
- check_everything(
260
- ts.factory.createArrayLiteralExpression(binaries, true),
261
- ),
262
- });
263
-
264
- const create_output = () =>
265
- ts.factory.createObjectLiteralExpression(
266
- [
267
- ts.factory.createShorthandPropertyAssignment("success"),
268
- ts.factory.createShorthandPropertyAssignment("errors"),
269
- ts.factory.createPropertyAssignment(
270
- "data",
271
- ts.factory.createConditionalExpression(
272
- ts.factory.createIdentifier("success"),
273
- undefined,
274
- ts.factory.createIdentifier("input"),
275
- undefined,
276
- ts.factory.createIdentifier("undefined"),
277
- ),
278
- ),
279
- ],
280
- true,
281
- );
282
-
283
- const create_report_call =
284
- (exceptionable?: ts.Expression) =>
285
- (
286
- path: ts.Expression,
287
- expected: string,
288
- value: ts.Expression,
289
- ): ts.Expression =>
290
- ts.factory.createCallExpression(
291
- ts.factory.createIdentifier("$report"),
292
- undefined,
293
- [
294
- exceptionable ?? ts.factory.createIdentifier("_exceptionable"),
295
- ts.factory.createObjectLiteralExpression(
296
- [
297
- ts.factory.createPropertyAssignment("path", path),
298
- ts.factory.createPropertyAssignment(
299
- "expected",
300
- ts.factory.createStringLiteral(expected),
301
- ),
302
- ts.factory.createPropertyAssignment("value", value),
303
- ],
304
- true,
305
- ),
306
- ],
307
- );
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "../factories/IdentifierFactory";
4
+ import { StatementFactory } from "../factories/StatementFactory";
5
+ import { TypeFactory } from "../factories/TypeFactory";
6
+
7
+ import { IProject } from "../transformers/IProject";
8
+
9
+ import { CheckerProgrammer } from "./CheckerProgrammer";
10
+ import { IsProgrammer } from "./IsProgrammer";
11
+ import { FunctionImporter } from "./helpers/FunctionImporeter";
12
+ import { OptionPredicator } from "./helpers/OptionPredicator";
13
+ import { check_everything } from "./internal/check_everything";
14
+ import { check_object } from "./internal/check_object";
15
+
16
+ export namespace ValidateProgrammer {
17
+ export const write =
18
+ (project: IProject) =>
19
+ (modulo: ts.LeftHandSideExpression) =>
20
+ (equals: boolean) =>
21
+ (type: ts.Type, name?: string) => {
22
+ const importer: FunctionImporter = new FunctionImporter(
23
+ modulo.getText(),
24
+ );
25
+
26
+ const is = IsProgrammer.write(project)(modulo, true)(equals)(
27
+ type,
28
+ name ?? TypeFactory.getFullName(project.checker)(type),
29
+ );
30
+ const validate: ts.ArrowFunction = CheckerProgrammer.write(project)(
31
+ {
32
+ prefix: "$v",
33
+ path: true,
34
+ trace: true,
35
+ numeric: OptionPredicator.numeric(project.options),
36
+ equals,
37
+ atomist: (explore) => (tuple) => (input) =>
38
+ [
39
+ tuple.expression,
40
+ ...tuple.tags.map((tag) =>
41
+ ts.factory.createLogicalOr(
42
+ tag.expression,
43
+ create_report_call(
44
+ explore.from === "top"
45
+ ? ts.factory.createTrue()
46
+ : ts.factory.createIdentifier(
47
+ "_exceptionable",
48
+ ),
49
+ )(
50
+ ts.factory.createIdentifier(
51
+ explore.postfix
52
+ ? `_path + ${explore.postfix}`
53
+ : "_path",
54
+ ),
55
+ tag.expected,
56
+ input,
57
+ ),
58
+ ),
59
+ ),
60
+ ].reduce((x, y) => ts.factory.createLogicalAnd(x, y)),
61
+ combiner: combine(equals)(importer),
62
+ joiner: joiner(equals)(importer),
63
+ success: ts.factory.createTrue(),
64
+ addition: () => importer.declare(modulo),
65
+ },
66
+ )(importer)(type, name);
67
+
68
+ return ts.factory.createArrowFunction(
69
+ undefined,
70
+ undefined,
71
+ [
72
+ IdentifierFactory.parameter(
73
+ "input",
74
+ TypeFactory.keyword("any"),
75
+ ),
76
+ ],
77
+ ts.factory.createTypeReferenceNode(
78
+ `typia.IValidation<${
79
+ name ?? TypeFactory.getFullName(project.checker)(type)
80
+ }>`,
81
+ ),
82
+ undefined,
83
+ ts.factory.createBlock(
84
+ [
85
+ StatementFactory.constant(
86
+ "errors",
87
+ ts.factory.createAsExpression(
88
+ ts.factory.createArrayLiteralExpression([]),
89
+ ts.factory.createArrayTypeNode(
90
+ TypeFactory.keyword("any"),
91
+ ),
92
+ ),
93
+ ),
94
+ StatementFactory.constant("__is", is),
95
+ ts.factory.createIfStatement(
96
+ ts.factory.createStrictEquality(
97
+ ts.factory.createFalse(),
98
+ ts.factory.createCallExpression(
99
+ ts.factory.createIdentifier("__is"),
100
+ undefined,
101
+ [ts.factory.createIdentifier("input")],
102
+ ),
103
+ ),
104
+ ts.factory.createBlock([
105
+ StatementFactory.constant(
106
+ "$report",
107
+ ts.factory.createCallExpression(
108
+ IdentifierFactory.access(
109
+ ts.factory.createParenthesizedExpression(
110
+ ts.factory.createAsExpression(
111
+ modulo,
112
+ TypeFactory.keyword("any"),
113
+ ),
114
+ ),
115
+ )("report"),
116
+ [],
117
+ [ts.factory.createIdentifier("errors")],
118
+ ),
119
+ ),
120
+ ts.factory.createExpressionStatement(
121
+ ts.factory.createCallExpression(
122
+ validate,
123
+ undefined,
124
+ [
125
+ ts.factory.createIdentifier(
126
+ "input",
127
+ ),
128
+ ts.factory.createStringLiteral(
129
+ "$input",
130
+ ),
131
+ ts.factory.createTrue(),
132
+ ],
133
+ ),
134
+ ),
135
+ ]),
136
+ ),
137
+ StatementFactory.constant(
138
+ "success",
139
+ ts.factory.createStrictEquality(
140
+ ts.factory.createNumericLiteral(0),
141
+ ts.factory.createIdentifier("errors.length"),
142
+ ),
143
+ ),
144
+ ts.factory.createReturnStatement(
145
+ ts.factory.createAsExpression(
146
+ create_output(),
147
+ TypeFactory.keyword("any"),
148
+ ),
149
+ ),
150
+ ],
151
+ true,
152
+ ),
153
+ );
154
+ };
155
+ }
156
+
157
+ const combine =
158
+ (equals: boolean) =>
159
+ (importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
160
+ (explore: CheckerProgrammer.IExplore) => {
161
+ if (explore.tracable === false)
162
+ return IsProgrammer.configure({
163
+ object: validate_object(equals)(importer),
164
+ numeric: true,
165
+ })(importer).combiner(explore);
166
+
167
+ const path: string = explore.postfix
168
+ ? `_path + ${explore.postfix}`
169
+ : "_path";
170
+ return (logic) => (input, binaries, expected) =>
171
+ logic === "and"
172
+ ? binaries
173
+ .map((binary) =>
174
+ binary.combined
175
+ ? binary.expression
176
+ : ts.factory.createLogicalOr(
177
+ binary.expression,
178
+ create_report_call(
179
+ explore.source === "top"
180
+ ? ts.factory.createTrue()
181
+ : ts.factory.createIdentifier(
182
+ "_exceptionable",
183
+ ),
184
+ )(
185
+ ts.factory.createIdentifier(path),
186
+ expected,
187
+ input,
188
+ ),
189
+ ),
190
+ )
191
+ .reduce(ts.factory.createLogicalAnd)
192
+ : ts.factory.createLogicalOr(
193
+ binaries
194
+ .map((binary) => binary.expression)
195
+ .reduce(ts.factory.createLogicalOr),
196
+ create_report_call(
197
+ explore.source === "top"
198
+ ? ts.factory.createTrue()
199
+ : ts.factory.createIdentifier("_exceptionable"),
200
+ )(ts.factory.createIdentifier(path), expected, input),
201
+ );
202
+ };
203
+
204
+ const validate_object = (equals: boolean) => (importer: FunctionImporter) =>
205
+ check_object({
206
+ equals,
207
+ undefined: true,
208
+ assert: false,
209
+ reduce: ts.factory.createLogicalAnd,
210
+ positive: ts.factory.createTrue(),
211
+ superfluous: (value) =>
212
+ create_report_call()(
213
+ ts.factory.createAdd(
214
+ ts.factory.createIdentifier("_path"),
215
+ ts.factory.createCallExpression(
216
+ importer.use("join"),
217
+ undefined,
218
+ [ts.factory.createIdentifier("key")],
219
+ ),
220
+ ),
221
+ "undefined",
222
+ value,
223
+ ),
224
+ halt: (expr) =>
225
+ ts.factory.createLogicalOr(
226
+ ts.factory.createStrictEquality(
227
+ ts.factory.createFalse(),
228
+ ts.factory.createIdentifier("_exceptionable"),
229
+ ),
230
+ expr,
231
+ ),
232
+ })(importer);
233
+
234
+ const joiner =
235
+ (equals: boolean) =>
236
+ (importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
237
+ object: validate_object(equals)(importer),
238
+ array: (input, arrow) =>
239
+ check_everything(
240
+ ts.factory.createCallExpression(
241
+ IdentifierFactory.access(input)("map"),
242
+ undefined,
243
+ [arrow],
244
+ ),
245
+ ),
246
+ failure: (value, expected, explore) =>
247
+ create_report_call(
248
+ explore?.from === "top"
249
+ ? ts.factory.createTrue()
250
+ : ts.factory.createIdentifier("_exceptionable"),
251
+ )(
252
+ ts.factory.createIdentifier(
253
+ explore?.postfix ? `_path + ${explore.postfix}` : "_path",
254
+ ),
255
+ expected,
256
+ value,
257
+ ),
258
+ tuple: (binaries) =>
259
+ check_everything(
260
+ ts.factory.createArrayLiteralExpression(binaries, true),
261
+ ),
262
+ });
263
+
264
+ const create_output = () =>
265
+ ts.factory.createObjectLiteralExpression(
266
+ [
267
+ ts.factory.createShorthandPropertyAssignment("success"),
268
+ ts.factory.createShorthandPropertyAssignment("errors"),
269
+ ts.factory.createPropertyAssignment(
270
+ "data",
271
+ ts.factory.createConditionalExpression(
272
+ ts.factory.createIdentifier("success"),
273
+ undefined,
274
+ ts.factory.createIdentifier("input"),
275
+ undefined,
276
+ ts.factory.createIdentifier("undefined"),
277
+ ),
278
+ ),
279
+ ],
280
+ true,
281
+ );
282
+
283
+ const create_report_call =
284
+ (exceptionable?: ts.Expression) =>
285
+ (
286
+ path: ts.Expression,
287
+ expected: string,
288
+ value: ts.Expression,
289
+ ): ts.Expression =>
290
+ ts.factory.createCallExpression(
291
+ ts.factory.createIdentifier("$report"),
292
+ undefined,
293
+ [
294
+ exceptionable ?? ts.factory.createIdentifier("_exceptionable"),
295
+ ts.factory.createObjectLiteralExpression(
296
+ [
297
+ ts.factory.createPropertyAssignment("path", path),
298
+ ts.factory.createPropertyAssignment(
299
+ "expected",
300
+ ts.factory.createStringLiteral(expected),
301
+ ),
302
+ ts.factory.createPropertyAssignment("value", value),
303
+ ],
304
+ true,
305
+ ),
306
+ ],
307
+ );