typia 6.7.0 → 6.7.1

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 (85) hide show
  1. package/lib/programmers/AssertProgrammer.d.ts +0 -1
  2. package/lib/programmers/AssertProgrammer.js.map +1 -1
  3. package/lib/programmers/CheckerProgrammer.d.ts +1 -1
  4. package/lib/programmers/FeatureProgrammer.d.ts +1 -1
  5. package/lib/programmers/IsProgrammer.d.ts +1 -1
  6. package/lib/programmers/RandomProgrammer.d.ts +10 -1
  7. package/lib/programmers/RandomProgrammer.js +62 -37
  8. package/lib/programmers/RandomProgrammer.js.map +1 -1
  9. package/lib/programmers/ValidateProgrammer.d.ts +1 -1
  10. package/lib/programmers/json/JsonIsParseProgrammer.d.ts +1 -1
  11. package/lib/programmers/json/JsonIsStringifyProgrammer.d.ts +1 -1
  12. package/lib/programmers/json/JsonStringifyProgrammer.d.ts +1 -1
  13. package/lib/programmers/json/JsonStringifyProgrammer.js +1 -3
  14. package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
  15. package/lib/programmers/json/JsonValidateParseProgrammer.d.ts +1 -1
  16. package/lib/programmers/json/JsonValidateStringifyProgrammer.d.ts +1 -1
  17. package/lib/programmers/misc/MiscCloneProgrammer.d.ts +1 -1
  18. package/lib/programmers/misc/MiscCloneProgrammer.js +33 -14
  19. package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
  20. package/lib/programmers/misc/MiscIsCloneProgrammer.d.ts +1 -1
  21. package/lib/programmers/misc/MiscIsPruneProgrammer.d.ts +1 -1
  22. package/lib/programmers/misc/MiscPruneProgrammer.d.ts +1 -1
  23. package/lib/programmers/misc/MiscValidateCloneProgrammer.d.ts +1 -1
  24. package/lib/programmers/misc/MiscValidatePruneProgrammer.d.ts +1 -1
  25. package/lib/programmers/notations/NotationGeneralProgrammer.d.ts +1 -1
  26. package/lib/programmers/notations/NotationGeneralProgrammer.js +30 -11
  27. package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
  28. package/lib/programmers/notations/NotationValidateGeneralProgrammer.d.ts +1 -1
  29. package/package.json +1 -1
  30. package/src/programmers/AssertProgrammer.ts +397 -398
  31. package/src/programmers/CheckerProgrammer.ts +1138 -1138
  32. package/src/programmers/FeatureProgrammer.ts +549 -549
  33. package/src/programmers/IsProgrammer.ts +1 -1
  34. package/src/programmers/RandomProgrammer.ts +112 -77
  35. package/src/programmers/ValidateProgrammer.ts +382 -382
  36. package/src/programmers/functional/FunctionalAssertFunctionProgrammer.ts +141 -141
  37. package/src/programmers/functional/FunctionalAssertParametersProgrammer.ts +108 -108
  38. package/src/programmers/functional/FunctionalAssertReturnProgrammer.ts +98 -98
  39. package/src/programmers/functional/FunctionalIsFunctionProgrammer.ts +72 -72
  40. package/src/programmers/functional/FunctionalIsParametersProgrammer.ts +101 -101
  41. package/src/programmers/functional/FunctionalIsReturnProgrammer.ts +106 -106
  42. package/src/programmers/functional/FunctionalValidateFunctionProgrammer.ts +123 -123
  43. package/src/programmers/functional/FunctionalValidateParametersProgrammer.ts +267 -267
  44. package/src/programmers/functional/FunctionalValidateReturnProgrammer.ts +126 -126
  45. package/src/programmers/helpers/FunctionImporter.ts +97 -97
  46. package/src/programmers/http/HttpAssertFormDataProgrammer.ts +91 -91
  47. package/src/programmers/http/HttpAssertHeadersProgrammer.ts +91 -91
  48. package/src/programmers/http/HttpAssertQueryProgrammer.ts +93 -93
  49. package/src/programmers/http/HttpFormDataProgrammer.ts +278 -278
  50. package/src/programmers/http/HttpHeadersProgrammer.ts +347 -347
  51. package/src/programmers/http/HttpIsFormDataProgrammer.ts +102 -102
  52. package/src/programmers/http/HttpIsHeadersProgrammer.ts +102 -102
  53. package/src/programmers/http/HttpIsQueryProgrammer.ts +104 -104
  54. package/src/programmers/http/HttpQueryProgrammer.ts +298 -298
  55. package/src/programmers/http/HttpValidateFormDataProgrammer.ts +85 -85
  56. package/src/programmers/http/HttpValidateHeadersProgrammer.ts +85 -85
  57. package/src/programmers/http/HttpValidateQueryProgrammer.ts +87 -87
  58. package/src/programmers/json/JsonAssertParseProgrammer.ts +96 -96
  59. package/src/programmers/json/JsonAssertStringifyProgrammer.ts +104 -104
  60. package/src/programmers/json/JsonIsParseProgrammer.ts +110 -110
  61. package/src/programmers/json/JsonIsStringifyProgrammer.ts +102 -102
  62. package/src/programmers/json/JsonStringifyProgrammer.ts +909 -910
  63. package/src/programmers/json/JsonValidateParseProgrammer.ts +87 -87
  64. package/src/programmers/json/JsonValidateStringifyProgrammer.ts +111 -111
  65. package/src/programmers/misc/MiscAssertCloneProgrammer.ts +87 -87
  66. package/src/programmers/misc/MiscAssertPruneProgrammer.ts +87 -87
  67. package/src/programmers/misc/MiscCloneProgrammer.ts +781 -759
  68. package/src/programmers/misc/MiscIsCloneProgrammer.ts +93 -93
  69. package/src/programmers/misc/MiscIsPruneProgrammer.ts +94 -94
  70. package/src/programmers/misc/MiscPruneProgrammer.ts +560 -560
  71. package/src/programmers/misc/MiscValidateCloneProgrammer.ts +104 -104
  72. package/src/programmers/misc/MiscValidatePruneProgrammer.ts +98 -98
  73. package/src/programmers/notations/NotationAssertGeneralProgrammer.ts +91 -91
  74. package/src/programmers/notations/NotationGeneralProgrammer.ts +709 -685
  75. package/src/programmers/notations/NotationIsGeneralProgrammer.ts +97 -97
  76. package/src/programmers/notations/NotationValidateGeneralProgrammer.ts +107 -107
  77. package/src/programmers/protobuf/ProtobufAssertDecodeProgrammer.ts +91 -91
  78. package/src/programmers/protobuf/ProtobufAssertEncodeProgrammer.ts +95 -95
  79. package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +646 -646
  80. package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +852 -852
  81. package/src/programmers/protobuf/ProtobufIsDecodeProgrammer.ts +104 -104
  82. package/src/programmers/protobuf/ProtobufIsEncodeProgrammer.ts +93 -93
  83. package/src/programmers/protobuf/ProtobufValidateDecodeProgrammer.ts +85 -85
  84. package/src/programmers/protobuf/ProtobufValidateEncodeProgrammer.ts +109 -109
  85. package/src/transformers/internal/GenericTransformer.ts +104 -104
@@ -1,382 +1,382 @@
1
- import ts from "typescript";
2
-
3
- import { ExpressionFactory } from "../factories/ExpressionFactory";
4
- import { IdentifierFactory } from "../factories/IdentifierFactory";
5
- import { StatementFactory } from "../factories/StatementFactory";
6
- import { TypeFactory } from "../factories/TypeFactory";
7
-
8
- import { IProject } from "../transformers/IProject";
9
-
10
- import { CheckerProgrammer } from "./CheckerProgrammer";
11
- import { FeatureProgrammer } from "./FeatureProgrammer";
12
- import { IsProgrammer } from "./IsProgrammer";
13
- import { FunctionImporter } from "./helpers/FunctionImporter";
14
- import { OptionPredicator } from "./helpers/OptionPredicator";
15
- import { check_everything } from "./internal/check_everything";
16
- import { check_object } from "./internal/check_object";
17
-
18
- export namespace ValidateProgrammer {
19
- export const decompose = (props: {
20
- project: IProject;
21
- modulo: ts.LeftHandSideExpression;
22
- importer: FunctionImporter;
23
- equals: boolean;
24
- type: ts.Type;
25
- name?: string;
26
- }): FeatureProgrammer.IDecomposed => {
27
- const is: FeatureProgrammer.IDecomposed = IsProgrammer.decompose(props);
28
- const composed: FeatureProgrammer.IComposed = CheckerProgrammer.compose({
29
- ...props,
30
- config: {
31
- prefix: "$v",
32
- path: true,
33
- trace: true,
34
- numeric: OptionPredicator.numeric(props.project.options),
35
- equals: props.equals,
36
- atomist: (explore) => (entry) => (input) =>
37
- [
38
- ...(entry.expression ? [entry.expression] : []),
39
- ...(entry.conditions.length === 0
40
- ? []
41
- : entry.conditions.length === 1
42
- ? entry.conditions[0]!.map((cond) =>
43
- ts.factory.createLogicalOr(
44
- cond.expression,
45
- create_report_call(
46
- explore.from === "top"
47
- ? ts.factory.createTrue()
48
- : ts.factory.createIdentifier("_exceptionable"),
49
- )(
50
- ts.factory.createIdentifier(
51
- explore.postfix
52
- ? `_path + ${explore.postfix}`
53
- : "_path",
54
- ),
55
- cond.expected,
56
- input,
57
- ),
58
- ),
59
- )
60
- : [
61
- ts.factory.createLogicalOr(
62
- entry.conditions
63
- .map((set) =>
64
- set
65
- .map((s) => s.expression)
66
- .reduce((a, b) =>
67
- ts.factory.createLogicalAnd(a, b),
68
- ),
69
- )
70
- .reduce((a, b) => ts.factory.createLogicalOr(a, b)),
71
- create_report_call(
72
- explore.from === "top"
73
- ? ts.factory.createTrue()
74
- : ts.factory.createIdentifier("_exceptionable"),
75
- )(
76
- ts.factory.createIdentifier(
77
- explore.postfix
78
- ? `_path + ${explore.postfix}`
79
- : "_path",
80
- ),
81
- entry.expected,
82
- input,
83
- ),
84
- ),
85
- ]),
86
- ].reduce((x, y) => ts.factory.createLogicalAnd(x, y)),
87
- combiner: combine(props.equals)(props.project)(props.importer),
88
- joiner: joiner(props.equals)(props.project)(props.importer),
89
- success: ts.factory.createTrue(),
90
- },
91
- });
92
- const arrow: ts.ArrowFunction = ts.factory.createArrowFunction(
93
- undefined,
94
- undefined,
95
- [IdentifierFactory.parameter("input", TypeFactory.keyword("any"))],
96
- ts.factory.createTypeReferenceNode(
97
- `typia.IValidation<${
98
- props.name ??
99
- TypeFactory.getFullName(props.project.checker)(props.type)
100
- }>`,
101
- ),
102
- undefined,
103
- ts.factory.createBlock(
104
- [
105
- // validate when false === is<T>(input)
106
- ts.factory.createIfStatement(
107
- ts.factory.createStrictEquality(
108
- ts.factory.createFalse(),
109
- ts.factory.createCallExpression(
110
- ts.factory.createIdentifier("__is"),
111
- undefined,
112
- [ts.factory.createIdentifier("input")],
113
- ),
114
- ),
115
- ts.factory.createBlock([
116
- // prepare errors
117
- ts.factory.createExpressionStatement(
118
- ts.factory.createBinaryExpression(
119
- ts.factory.createIdentifier("errors"),
120
- ts.factory.createToken(ts.SyntaxKind.EqualsToken),
121
- ts.factory.createArrayLiteralExpression([]),
122
- ),
123
- ),
124
- ts.factory.createExpressionStatement(
125
- ts.factory.createBinaryExpression(
126
- ts.factory.createIdentifier("$report"),
127
- ts.factory.createToken(ts.SyntaxKind.EqualsToken),
128
- ts.factory.createCallExpression(
129
- IdentifierFactory.access(
130
- ts.factory.createParenthesizedExpression(
131
- ts.factory.createAsExpression(
132
- props.modulo,
133
- TypeFactory.keyword("any"),
134
- ),
135
- ),
136
- )("report"),
137
- [],
138
- [ts.factory.createIdentifier("errors")],
139
- ),
140
- ),
141
- ),
142
- ts.factory.createExpressionStatement(
143
- ts.factory.createCallExpression(
144
- ts.factory.createArrowFunction(
145
- undefined,
146
- undefined,
147
- composed.parameters,
148
- undefined,
149
- undefined,
150
- composed.body,
151
- ),
152
- undefined,
153
- [
154
- ts.factory.createIdentifier("input"),
155
- ts.factory.createStringLiteral("$input"),
156
- ts.factory.createTrue(),
157
- ],
158
- ),
159
- ),
160
- StatementFactory.constant(
161
- "success",
162
- ts.factory.createStrictEquality(
163
- ExpressionFactory.number(0),
164
- ts.factory.createIdentifier("errors.length"),
165
- ),
166
- ),
167
- ts.factory.createReturnStatement(
168
- ts.factory.createAsExpression(
169
- create_output(),
170
- TypeFactory.keyword("any"),
171
- ),
172
- ),
173
- ]),
174
- ),
175
- ts.factory.createReturnStatement(
176
- ts.factory.createAsExpression(
177
- ts.factory.createObjectLiteralExpression(
178
- [
179
- ts.factory.createPropertyAssignment(
180
- "success",
181
- ts.factory.createTrue(),
182
- ),
183
- ts.factory.createPropertyAssignment(
184
- "errors",
185
- ts.factory.createArrayLiteralExpression([]),
186
- ),
187
- ts.factory.createPropertyAssignment(
188
- "data",
189
- ts.factory.createIdentifier("input"),
190
- ),
191
- ],
192
- true,
193
- ),
194
- TypeFactory.keyword("any"),
195
- ),
196
- ),
197
- ],
198
- true,
199
- ),
200
- );
201
- return {
202
- functions: {
203
- ...is.functions,
204
- ...composed.functions,
205
- },
206
- statements: [
207
- ...is.statements,
208
- ...composed.statements,
209
- StatementFactory.constant("__is", is.arrow),
210
- StatementFactory.mut("errors"),
211
- StatementFactory.mut("$report"),
212
- ],
213
- arrow,
214
- };
215
- };
216
-
217
- export const write =
218
- (project: IProject) =>
219
- (modulo: ts.LeftHandSideExpression) =>
220
- (equals: boolean) =>
221
- (type: ts.Type, name?: string) => {
222
- const importer: FunctionImporter = new FunctionImporter(modulo.getText());
223
- const result: FeatureProgrammer.IDecomposed = decompose({
224
- equals,
225
- project,
226
- modulo,
227
- importer,
228
- type,
229
- name,
230
- });
231
- return FeatureProgrammer.writeDecomposed({
232
- modulo,
233
- importer,
234
- result,
235
- });
236
- };
237
- }
238
-
239
- const combine =
240
- (equals: boolean) =>
241
- (project: IProject) =>
242
- (importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
243
- (explore: CheckerProgrammer.IExplore) => {
244
- if (explore.tracable === false)
245
- return IsProgrammer.configure({
246
- object: validate_object(equals)(project)(importer),
247
- numeric: true,
248
- })(project)(importer).combiner(explore);
249
-
250
- const path: string = explore.postfix
251
- ? `_path + ${explore.postfix}`
252
- : "_path";
253
- return (logic) => (input, binaries, expected) =>
254
- logic === "and"
255
- ? binaries
256
- .map((binary) =>
257
- binary.combined
258
- ? binary.expression
259
- : ts.factory.createLogicalOr(
260
- binary.expression,
261
- create_report_call(
262
- explore.source === "top"
263
- ? ts.factory.createTrue()
264
- : ts.factory.createIdentifier("_exceptionable"),
265
- )(ts.factory.createIdentifier(path), expected, input),
266
- ),
267
- )
268
- .reduce(ts.factory.createLogicalAnd)
269
- : ts.factory.createLogicalOr(
270
- binaries
271
- .map((binary) => binary.expression)
272
- .reduce(ts.factory.createLogicalOr),
273
- create_report_call(
274
- explore.source === "top"
275
- ? ts.factory.createTrue()
276
- : ts.factory.createIdentifier("_exceptionable"),
277
- )(ts.factory.createIdentifier(path), expected, input),
278
- );
279
- };
280
-
281
- const validate_object =
282
- (equals: boolean) => (project: IProject) => (importer: FunctionImporter) =>
283
- check_object({
284
- equals,
285
- undefined: true,
286
- assert: false,
287
- reduce: ts.factory.createLogicalAnd,
288
- positive: ts.factory.createTrue(),
289
- superfluous: (value) =>
290
- create_report_call()(
291
- ts.factory.createAdd(
292
- ts.factory.createIdentifier("_path"),
293
- ts.factory.createCallExpression(importer.use("join"), undefined, [
294
- ts.factory.createIdentifier("key"),
295
- ]),
296
- ),
297
- "undefined",
298
- value,
299
- ),
300
- halt: (expr) =>
301
- ts.factory.createLogicalOr(
302
- ts.factory.createStrictEquality(
303
- ts.factory.createFalse(),
304
- ts.factory.createIdentifier("_exceptionable"),
305
- ),
306
- expr,
307
- ),
308
- })(project)(importer);
309
-
310
- const joiner =
311
- (equals: boolean) =>
312
- (project: IProject) =>
313
- (importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
314
- object: validate_object(equals)(project)(importer),
315
- array: (input, arrow) =>
316
- check_everything(
317
- ts.factory.createCallExpression(
318
- IdentifierFactory.access(input)("map"),
319
- undefined,
320
- [arrow],
321
- ),
322
- ),
323
- failure: (value, expected, explore) =>
324
- create_report_call(
325
- explore?.from === "top"
326
- ? ts.factory.createTrue()
327
- : ts.factory.createIdentifier("_exceptionable"),
328
- )(
329
- ts.factory.createIdentifier(
330
- explore?.postfix ? `_path + ${explore.postfix}` : "_path",
331
- ),
332
- expected,
333
- value,
334
- ),
335
- tuple: (binaries) =>
336
- check_everything(ts.factory.createArrayLiteralExpression(binaries, true)),
337
- });
338
-
339
- const create_output = () =>
340
- ts.factory.createObjectLiteralExpression(
341
- [
342
- ts.factory.createShorthandPropertyAssignment("success"),
343
- ts.factory.createShorthandPropertyAssignment("errors"),
344
- ts.factory.createPropertyAssignment(
345
- "data",
346
- ts.factory.createConditionalExpression(
347
- ts.factory.createIdentifier("success"),
348
- undefined,
349
- ts.factory.createIdentifier("input"),
350
- undefined,
351
- ts.factory.createIdentifier("undefined"),
352
- ),
353
- ),
354
- ],
355
- true,
356
- );
357
-
358
- const create_report_call =
359
- (exceptionable?: ts.Expression) =>
360
- (
361
- path: ts.Expression,
362
- expected: string,
363
- value: ts.Expression,
364
- ): ts.Expression =>
365
- ts.factory.createCallExpression(
366
- ts.factory.createIdentifier("$report"),
367
- undefined,
368
- [
369
- exceptionable ?? ts.factory.createIdentifier("_exceptionable"),
370
- ts.factory.createObjectLiteralExpression(
371
- [
372
- ts.factory.createPropertyAssignment("path", path),
373
- ts.factory.createPropertyAssignment(
374
- "expected",
375
- ts.factory.createStringLiteral(expected),
376
- ),
377
- ts.factory.createPropertyAssignment("value", value),
378
- ],
379
- true,
380
- ),
381
- ],
382
- );
1
+ import ts from "typescript";
2
+
3
+ import { ExpressionFactory } from "../factories/ExpressionFactory";
4
+ import { IdentifierFactory } from "../factories/IdentifierFactory";
5
+ import { StatementFactory } from "../factories/StatementFactory";
6
+ import { TypeFactory } from "../factories/TypeFactory";
7
+
8
+ import { IProject } from "../transformers/IProject";
9
+
10
+ import { CheckerProgrammer } from "./CheckerProgrammer";
11
+ import { FeatureProgrammer } from "./FeatureProgrammer";
12
+ import { IsProgrammer } from "./IsProgrammer";
13
+ import { FunctionImporter } from "./helpers/FunctionImporter";
14
+ import { OptionPredicator } from "./helpers/OptionPredicator";
15
+ import { check_everything } from "./internal/check_everything";
16
+ import { check_object } from "./internal/check_object";
17
+
18
+ export namespace ValidateProgrammer {
19
+ export const decompose = (props: {
20
+ project: IProject;
21
+ modulo: ts.LeftHandSideExpression;
22
+ importer: FunctionImporter;
23
+ equals: boolean;
24
+ type: ts.Type;
25
+ name: string | undefined;
26
+ }): FeatureProgrammer.IDecomposed => {
27
+ const is: FeatureProgrammer.IDecomposed = IsProgrammer.decompose(props);
28
+ const composed: FeatureProgrammer.IComposed = CheckerProgrammer.compose({
29
+ ...props,
30
+ config: {
31
+ prefix: "$v",
32
+ path: true,
33
+ trace: true,
34
+ numeric: OptionPredicator.numeric(props.project.options),
35
+ equals: props.equals,
36
+ atomist: (explore) => (entry) => (input) =>
37
+ [
38
+ ...(entry.expression ? [entry.expression] : []),
39
+ ...(entry.conditions.length === 0
40
+ ? []
41
+ : entry.conditions.length === 1
42
+ ? entry.conditions[0]!.map((cond) =>
43
+ ts.factory.createLogicalOr(
44
+ cond.expression,
45
+ create_report_call(
46
+ explore.from === "top"
47
+ ? ts.factory.createTrue()
48
+ : ts.factory.createIdentifier("_exceptionable"),
49
+ )(
50
+ ts.factory.createIdentifier(
51
+ explore.postfix
52
+ ? `_path + ${explore.postfix}`
53
+ : "_path",
54
+ ),
55
+ cond.expected,
56
+ input,
57
+ ),
58
+ ),
59
+ )
60
+ : [
61
+ ts.factory.createLogicalOr(
62
+ entry.conditions
63
+ .map((set) =>
64
+ set
65
+ .map((s) => s.expression)
66
+ .reduce((a, b) =>
67
+ ts.factory.createLogicalAnd(a, b),
68
+ ),
69
+ )
70
+ .reduce((a, b) => ts.factory.createLogicalOr(a, b)),
71
+ create_report_call(
72
+ explore.from === "top"
73
+ ? ts.factory.createTrue()
74
+ : ts.factory.createIdentifier("_exceptionable"),
75
+ )(
76
+ ts.factory.createIdentifier(
77
+ explore.postfix
78
+ ? `_path + ${explore.postfix}`
79
+ : "_path",
80
+ ),
81
+ entry.expected,
82
+ input,
83
+ ),
84
+ ),
85
+ ]),
86
+ ].reduce((x, y) => ts.factory.createLogicalAnd(x, y)),
87
+ combiner: combine(props.equals)(props.project)(props.importer),
88
+ joiner: joiner(props.equals)(props.project)(props.importer),
89
+ success: ts.factory.createTrue(),
90
+ },
91
+ });
92
+ const arrow: ts.ArrowFunction = ts.factory.createArrowFunction(
93
+ undefined,
94
+ undefined,
95
+ [IdentifierFactory.parameter("input", TypeFactory.keyword("any"))],
96
+ ts.factory.createTypeReferenceNode(
97
+ `typia.IValidation<${
98
+ props.name ??
99
+ TypeFactory.getFullName(props.project.checker)(props.type)
100
+ }>`,
101
+ ),
102
+ undefined,
103
+ ts.factory.createBlock(
104
+ [
105
+ // validate when false === is<T>(input)
106
+ ts.factory.createIfStatement(
107
+ ts.factory.createStrictEquality(
108
+ ts.factory.createFalse(),
109
+ ts.factory.createCallExpression(
110
+ ts.factory.createIdentifier("__is"),
111
+ undefined,
112
+ [ts.factory.createIdentifier("input")],
113
+ ),
114
+ ),
115
+ ts.factory.createBlock([
116
+ // prepare errors
117
+ ts.factory.createExpressionStatement(
118
+ ts.factory.createBinaryExpression(
119
+ ts.factory.createIdentifier("errors"),
120
+ ts.factory.createToken(ts.SyntaxKind.EqualsToken),
121
+ ts.factory.createArrayLiteralExpression([]),
122
+ ),
123
+ ),
124
+ ts.factory.createExpressionStatement(
125
+ ts.factory.createBinaryExpression(
126
+ ts.factory.createIdentifier("$report"),
127
+ ts.factory.createToken(ts.SyntaxKind.EqualsToken),
128
+ ts.factory.createCallExpression(
129
+ IdentifierFactory.access(
130
+ ts.factory.createParenthesizedExpression(
131
+ ts.factory.createAsExpression(
132
+ props.modulo,
133
+ TypeFactory.keyword("any"),
134
+ ),
135
+ ),
136
+ )("report"),
137
+ [],
138
+ [ts.factory.createIdentifier("errors")],
139
+ ),
140
+ ),
141
+ ),
142
+ ts.factory.createExpressionStatement(
143
+ ts.factory.createCallExpression(
144
+ ts.factory.createArrowFunction(
145
+ undefined,
146
+ undefined,
147
+ composed.parameters,
148
+ undefined,
149
+ undefined,
150
+ composed.body,
151
+ ),
152
+ undefined,
153
+ [
154
+ ts.factory.createIdentifier("input"),
155
+ ts.factory.createStringLiteral("$input"),
156
+ ts.factory.createTrue(),
157
+ ],
158
+ ),
159
+ ),
160
+ StatementFactory.constant(
161
+ "success",
162
+ ts.factory.createStrictEquality(
163
+ ExpressionFactory.number(0),
164
+ ts.factory.createIdentifier("errors.length"),
165
+ ),
166
+ ),
167
+ ts.factory.createReturnStatement(
168
+ ts.factory.createAsExpression(
169
+ create_output(),
170
+ TypeFactory.keyword("any"),
171
+ ),
172
+ ),
173
+ ]),
174
+ ),
175
+ ts.factory.createReturnStatement(
176
+ ts.factory.createAsExpression(
177
+ ts.factory.createObjectLiteralExpression(
178
+ [
179
+ ts.factory.createPropertyAssignment(
180
+ "success",
181
+ ts.factory.createTrue(),
182
+ ),
183
+ ts.factory.createPropertyAssignment(
184
+ "errors",
185
+ ts.factory.createArrayLiteralExpression([]),
186
+ ),
187
+ ts.factory.createPropertyAssignment(
188
+ "data",
189
+ ts.factory.createIdentifier("input"),
190
+ ),
191
+ ],
192
+ true,
193
+ ),
194
+ TypeFactory.keyword("any"),
195
+ ),
196
+ ),
197
+ ],
198
+ true,
199
+ ),
200
+ );
201
+ return {
202
+ functions: {
203
+ ...is.functions,
204
+ ...composed.functions,
205
+ },
206
+ statements: [
207
+ ...is.statements,
208
+ ...composed.statements,
209
+ StatementFactory.constant("__is", is.arrow),
210
+ StatementFactory.mut("errors"),
211
+ StatementFactory.mut("$report"),
212
+ ],
213
+ arrow,
214
+ };
215
+ };
216
+
217
+ export const write =
218
+ (project: IProject) =>
219
+ (modulo: ts.LeftHandSideExpression) =>
220
+ (equals: boolean) =>
221
+ (type: ts.Type, name?: string) => {
222
+ const importer: FunctionImporter = new FunctionImporter(modulo.getText());
223
+ const result: FeatureProgrammer.IDecomposed = decompose({
224
+ equals,
225
+ project,
226
+ modulo,
227
+ importer,
228
+ type,
229
+ name,
230
+ });
231
+ return FeatureProgrammer.writeDecomposed({
232
+ modulo,
233
+ importer,
234
+ result,
235
+ });
236
+ };
237
+ }
238
+
239
+ const combine =
240
+ (equals: boolean) =>
241
+ (project: IProject) =>
242
+ (importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
243
+ (explore: CheckerProgrammer.IExplore) => {
244
+ if (explore.tracable === false)
245
+ return IsProgrammer.configure({
246
+ object: validate_object(equals)(project)(importer),
247
+ numeric: true,
248
+ })(project)(importer).combiner(explore);
249
+
250
+ const path: string = explore.postfix
251
+ ? `_path + ${explore.postfix}`
252
+ : "_path";
253
+ return (logic) => (input, binaries, expected) =>
254
+ logic === "and"
255
+ ? binaries
256
+ .map((binary) =>
257
+ binary.combined
258
+ ? binary.expression
259
+ : ts.factory.createLogicalOr(
260
+ binary.expression,
261
+ create_report_call(
262
+ explore.source === "top"
263
+ ? ts.factory.createTrue()
264
+ : ts.factory.createIdentifier("_exceptionable"),
265
+ )(ts.factory.createIdentifier(path), expected, input),
266
+ ),
267
+ )
268
+ .reduce(ts.factory.createLogicalAnd)
269
+ : ts.factory.createLogicalOr(
270
+ binaries
271
+ .map((binary) => binary.expression)
272
+ .reduce(ts.factory.createLogicalOr),
273
+ create_report_call(
274
+ explore.source === "top"
275
+ ? ts.factory.createTrue()
276
+ : ts.factory.createIdentifier("_exceptionable"),
277
+ )(ts.factory.createIdentifier(path), expected, input),
278
+ );
279
+ };
280
+
281
+ const validate_object =
282
+ (equals: boolean) => (project: IProject) => (importer: FunctionImporter) =>
283
+ check_object({
284
+ equals,
285
+ undefined: true,
286
+ assert: false,
287
+ reduce: ts.factory.createLogicalAnd,
288
+ positive: ts.factory.createTrue(),
289
+ superfluous: (value) =>
290
+ create_report_call()(
291
+ ts.factory.createAdd(
292
+ ts.factory.createIdentifier("_path"),
293
+ ts.factory.createCallExpression(importer.use("join"), undefined, [
294
+ ts.factory.createIdentifier("key"),
295
+ ]),
296
+ ),
297
+ "undefined",
298
+ value,
299
+ ),
300
+ halt: (expr) =>
301
+ ts.factory.createLogicalOr(
302
+ ts.factory.createStrictEquality(
303
+ ts.factory.createFalse(),
304
+ ts.factory.createIdentifier("_exceptionable"),
305
+ ),
306
+ expr,
307
+ ),
308
+ })(project)(importer);
309
+
310
+ const joiner =
311
+ (equals: boolean) =>
312
+ (project: IProject) =>
313
+ (importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
314
+ object: validate_object(equals)(project)(importer),
315
+ array: (input, arrow) =>
316
+ check_everything(
317
+ ts.factory.createCallExpression(
318
+ IdentifierFactory.access(input)("map"),
319
+ undefined,
320
+ [arrow],
321
+ ),
322
+ ),
323
+ failure: (value, expected, explore) =>
324
+ create_report_call(
325
+ explore?.from === "top"
326
+ ? ts.factory.createTrue()
327
+ : ts.factory.createIdentifier("_exceptionable"),
328
+ )(
329
+ ts.factory.createIdentifier(
330
+ explore?.postfix ? `_path + ${explore.postfix}` : "_path",
331
+ ),
332
+ expected,
333
+ value,
334
+ ),
335
+ tuple: (binaries) =>
336
+ check_everything(ts.factory.createArrayLiteralExpression(binaries, true)),
337
+ });
338
+
339
+ const create_output = () =>
340
+ ts.factory.createObjectLiteralExpression(
341
+ [
342
+ ts.factory.createShorthandPropertyAssignment("success"),
343
+ ts.factory.createShorthandPropertyAssignment("errors"),
344
+ ts.factory.createPropertyAssignment(
345
+ "data",
346
+ ts.factory.createConditionalExpression(
347
+ ts.factory.createIdentifier("success"),
348
+ undefined,
349
+ ts.factory.createIdentifier("input"),
350
+ undefined,
351
+ ts.factory.createIdentifier("undefined"),
352
+ ),
353
+ ),
354
+ ],
355
+ true,
356
+ );
357
+
358
+ const create_report_call =
359
+ (exceptionable?: ts.Expression) =>
360
+ (
361
+ path: ts.Expression,
362
+ expected: string,
363
+ value: ts.Expression,
364
+ ): ts.Expression =>
365
+ ts.factory.createCallExpression(
366
+ ts.factory.createIdentifier("$report"),
367
+ undefined,
368
+ [
369
+ exceptionable ?? ts.factory.createIdentifier("_exceptionable"),
370
+ ts.factory.createObjectLiteralExpression(
371
+ [
372
+ ts.factory.createPropertyAssignment("path", path),
373
+ ts.factory.createPropertyAssignment(
374
+ "expected",
375
+ ts.factory.createStringLiteral(expected),
376
+ ),
377
+ ts.factory.createPropertyAssignment("value", value),
378
+ ],
379
+ true,
380
+ ),
381
+ ],
382
+ );