typia 5.2.5 → 5.2.6
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.
- package/lib/factories/ExpressionFactory.d.ts +1 -0
- package/lib/factories/ExpressionFactory.js +5 -0
- package/lib/factories/ExpressionFactory.js.map +1 -1
- package/lib/programmers/CheckerProgrammer.js +4 -4
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/programmers/RandomProgrammer.js +16 -18
- package/lib/programmers/RandomProgrammer.js.map +1 -1
- package/lib/programmers/ValidateProgrammer.js +2 -1
- package/lib/programmers/ValidateProgrammer.js.map +1 -1
- package/lib/programmers/helpers/RandomJoiner.js +4 -6
- package/lib/programmers/helpers/RandomJoiner.js.map +1 -1
- package/lib/programmers/helpers/RandomRanger.js +3 -2
- package/lib/programmers/helpers/RandomRanger.js.map +1 -1
- package/lib/programmers/http/HttpHeadersProgrammer.js +1 -1
- package/lib/programmers/http/HttpHeadersProgrammer.js.map +1 -1
- package/lib/programmers/internal/check_dynamic_properties.js +4 -3
- package/lib/programmers/internal/check_dynamic_properties.js.map +1 -1
- package/lib/programmers/internal/check_union_array_like.js +3 -2
- package/lib/programmers/internal/check_union_array_like.js.map +1 -1
- package/lib/programmers/json/JsonStringifyProgrammer.js +1 -3
- package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscCloneProgrammer.js +1 -3
- package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscLiteralsProgrammer.js +1 -1
- package/lib/programmers/misc/MiscLiteralsProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscPruneProgrammer.js +1 -3
- package/lib/programmers/misc/MiscPruneProgrammer.js.map +1 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js +1 -3
- package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js +6 -6
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js +2 -2
- package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js.map +1 -1
- package/package.json +1 -1
- package/src/Primitive.ts +135 -135
- package/src/executable/TypiaSetupWizard.ts +142 -142
- package/src/executable/setup/CommandExecutor.ts +8 -8
- package/src/factories/ExpressionFactory.ts +8 -0
- package/src/factories/JsonMetadataFactory.ts +50 -50
- package/src/factories/MetadataCollection.ts +282 -282
- package/src/factories/internal/metadata/emplace_metadata_object.ts +178 -178
- package/src/functional/$stoll.ts +8 -8
- package/src/functional/Namespace.ts +168 -168
- package/src/programmers/AssertProgrammer.ts +322 -322
- package/src/programmers/CheckerProgrammer.ts +4 -4
- package/src/programmers/IsProgrammer.ts +258 -258
- package/src/programmers/RandomProgrammer.ts +16 -17
- package/src/programmers/ValidateProgrammer.ts +350 -349
- package/src/programmers/helpers/AtomicPredicator.ts +31 -31
- package/src/programmers/helpers/RandomJoiner.ts +4 -6
- package/src/programmers/helpers/RandomRanger.ts +4 -2
- package/src/programmers/http/HttpHeadersProgrammer.ts +1 -1
- package/src/programmers/internal/check_dynamic_key.ts +178 -178
- package/src/programmers/internal/check_dynamic_properties.ts +202 -201
- package/src/programmers/internal/check_object.ts +62 -62
- package/src/programmers/internal/check_union_array_like.ts +4 -3
- package/src/programmers/json/JsonStringifyProgrammer.ts +960 -964
- package/src/programmers/misc/MiscCloneProgrammer.ts +786 -790
- package/src/programmers/misc/MiscLiteralsProgrammer.ts +1 -1
- package/src/programmers/misc/MiscPruneProgrammer.ts +548 -552
- package/src/programmers/notations/NotationGeneralProgrammer.ts +716 -720
- package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +7 -9
- package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +882 -882
- package/src/transform.ts +35 -35
|
@@ -1,322 +1,322 @@
|
|
|
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_object } from "./internal/check_object";
|
|
14
|
-
|
|
15
|
-
export namespace AssertProgrammer {
|
|
16
|
-
export const write =
|
|
17
|
-
(project: IProject) =>
|
|
18
|
-
(modulo: ts.LeftHandSideExpression) =>
|
|
19
|
-
(equals: boolean) =>
|
|
20
|
-
(type: ts.Type, name?: string) => {
|
|
21
|
-
const importer: FunctionImporter = new FunctionImporter(
|
|
22
|
-
modulo.getText(),
|
|
23
|
-
);
|
|
24
|
-
const is = IsProgrammer.write(project)(modulo, true)(equals)(
|
|
25
|
-
type,
|
|
26
|
-
name ?? TypeFactory.getFullName(project.checker)(type),
|
|
27
|
-
);
|
|
28
|
-
const assert: ts.ArrowFunction = CheckerProgrammer.write(project)({
|
|
29
|
-
prefix: "$a",
|
|
30
|
-
path: true,
|
|
31
|
-
trace: true,
|
|
32
|
-
numeric: OptionPredicator.numeric(project.options),
|
|
33
|
-
equals,
|
|
34
|
-
atomist: (explore) => (entry) => (input) =>
|
|
35
|
-
[
|
|
36
|
-
...(entry.expression ? [entry.expression] : []),
|
|
37
|
-
...(entry.conditions.length === 0
|
|
38
|
-
? []
|
|
39
|
-
: entry.conditions.length === 1
|
|
40
|
-
? entry.conditions[0]!.map((cond) =>
|
|
41
|
-
ts.factory.createLogicalOr(
|
|
42
|
-
cond.expression,
|
|
43
|
-
create_guard_call(importer)(
|
|
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
|
-
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(
|
|
68
|
-
a,
|
|
69
|
-
b,
|
|
70
|
-
),
|
|
71
|
-
),
|
|
72
|
-
)
|
|
73
|
-
.reduce((a, b) =>
|
|
74
|
-
ts.factory.createLogicalOr(a, b),
|
|
75
|
-
),
|
|
76
|
-
create_guard_call(importer)(
|
|
77
|
-
explore.from === "top"
|
|
78
|
-
? ts.factory.createTrue()
|
|
79
|
-
: ts.factory.createIdentifier(
|
|
80
|
-
"_exceptionable",
|
|
81
|
-
),
|
|
82
|
-
)(
|
|
83
|
-
ts.factory.createIdentifier(
|
|
84
|
-
explore.postfix
|
|
85
|
-
? `_path + ${explore.postfix}`
|
|
86
|
-
: "_path",
|
|
87
|
-
),
|
|
88
|
-
entry.expected,
|
|
89
|
-
input,
|
|
90
|
-
),
|
|
91
|
-
),
|
|
92
|
-
]),
|
|
93
|
-
].reduce((x, y) => ts.factory.createLogicalAnd(x, y)),
|
|
94
|
-
combiner: combiner(equals)(project)(importer),
|
|
95
|
-
joiner: joiner(equals)(project)(importer),
|
|
96
|
-
success: ts.factory.createTrue(),
|
|
97
|
-
addition: () => importer.declare(modulo),
|
|
98
|
-
})(importer)(type, name);
|
|
99
|
-
|
|
100
|
-
return ts.factory.createArrowFunction(
|
|
101
|
-
undefined,
|
|
102
|
-
undefined,
|
|
103
|
-
[
|
|
104
|
-
IdentifierFactory.parameter(
|
|
105
|
-
"input",
|
|
106
|
-
TypeFactory.keyword("any"),
|
|
107
|
-
),
|
|
108
|
-
],
|
|
109
|
-
ts.factory.createTypeReferenceNode(
|
|
110
|
-
name ?? TypeFactory.getFullName(project.checker)(type),
|
|
111
|
-
),
|
|
112
|
-
undefined,
|
|
113
|
-
ts.factory.createBlock(
|
|
114
|
-
[
|
|
115
|
-
StatementFactory.constant("__is", is),
|
|
116
|
-
ts.factory.createIfStatement(
|
|
117
|
-
ts.factory.createStrictEquality(
|
|
118
|
-
ts.factory.createFalse(),
|
|
119
|
-
ts.factory.createCallExpression(
|
|
120
|
-
ts.factory.createIdentifier("__is"),
|
|
121
|
-
undefined,
|
|
122
|
-
[ts.factory.createIdentifier("input")],
|
|
123
|
-
),
|
|
124
|
-
),
|
|
125
|
-
ts.factory.createExpressionStatement(
|
|
126
|
-
ts.factory.createCallExpression(
|
|
127
|
-
assert,
|
|
128
|
-
undefined,
|
|
129
|
-
[
|
|
130
|
-
ts.factory.createIdentifier("input"),
|
|
131
|
-
ts.factory.createStringLiteral(
|
|
132
|
-
"$input",
|
|
133
|
-
),
|
|
134
|
-
ts.factory.createTrue(),
|
|
135
|
-
],
|
|
136
|
-
),
|
|
137
|
-
),
|
|
138
|
-
undefined,
|
|
139
|
-
),
|
|
140
|
-
ts.factory.createReturnStatement(
|
|
141
|
-
ts.factory.createIdentifier(`input`),
|
|
142
|
-
),
|
|
143
|
-
],
|
|
144
|
-
true,
|
|
145
|
-
),
|
|
146
|
-
);
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
const combiner =
|
|
150
|
-
(equals: boolean) =>
|
|
151
|
-
(project: IProject) =>
|
|
152
|
-
(importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
|
|
153
|
-
(explore: CheckerProgrammer.IExplore) => {
|
|
154
|
-
if (explore.tracable === false)
|
|
155
|
-
return IsProgrammer.configure({
|
|
156
|
-
object: assert_object(equals)(project)(importer),
|
|
157
|
-
numeric: true,
|
|
158
|
-
})(project)(importer).combiner(explore);
|
|
159
|
-
|
|
160
|
-
const path: string = explore.postfix
|
|
161
|
-
? `_path + ${explore.postfix}`
|
|
162
|
-
: "_path";
|
|
163
|
-
return (logic) => (input, binaries, expected) =>
|
|
164
|
-
logic === "and"
|
|
165
|
-
? binaries
|
|
166
|
-
.map((binary) =>
|
|
167
|
-
binary.combined
|
|
168
|
-
? binary.expression
|
|
169
|
-
: ts.factory.createLogicalOr(
|
|
170
|
-
binary.expression,
|
|
171
|
-
create_guard_call(importer)(
|
|
172
|
-
explore.source === "top"
|
|
173
|
-
? ts.factory.createTrue()
|
|
174
|
-
: ts.factory.createIdentifier(
|
|
175
|
-
"_exceptionable",
|
|
176
|
-
),
|
|
177
|
-
)(
|
|
178
|
-
ts.factory.createIdentifier(path),
|
|
179
|
-
expected,
|
|
180
|
-
input,
|
|
181
|
-
),
|
|
182
|
-
),
|
|
183
|
-
)
|
|
184
|
-
.reduce(ts.factory.createLogicalAnd)
|
|
185
|
-
: ts.factory.createLogicalOr(
|
|
186
|
-
binaries
|
|
187
|
-
.map((binary) => binary.expression)
|
|
188
|
-
.reduce(ts.factory.createLogicalOr),
|
|
189
|
-
create_guard_call(importer)(
|
|
190
|
-
explore.source === "top"
|
|
191
|
-
? ts.factory.createTrue()
|
|
192
|
-
: ts.factory.createIdentifier(
|
|
193
|
-
"_exceptionable",
|
|
194
|
-
),
|
|
195
|
-
)(ts.factory.createIdentifier(path), expected, input),
|
|
196
|
-
);
|
|
197
|
-
// : (() => {
|
|
198
|
-
// const addicted = binaries.slice();
|
|
199
|
-
// if (
|
|
200
|
-
// addicted[addicted.length - 1]!.combined === false
|
|
201
|
-
// ) {
|
|
202
|
-
// addicted.push({
|
|
203
|
-
// combined: true,
|
|
204
|
-
// expression: create_guard_call(importer)(
|
|
205
|
-
// explore.source === "top"
|
|
206
|
-
// ? ts.factory.createTrue()
|
|
207
|
-
// : ts.factory.createIdentifier(
|
|
208
|
-
// "_exceptionable",
|
|
209
|
-
// ),
|
|
210
|
-
// )(
|
|
211
|
-
// ts.factory.createIdentifier(path),
|
|
212
|
-
// expected,
|
|
213
|
-
// input,
|
|
214
|
-
// ),
|
|
215
|
-
// });
|
|
216
|
-
// }
|
|
217
|
-
// return addicted
|
|
218
|
-
// .map((b) => b.expression)
|
|
219
|
-
// .reduce(ts.factory.createLogicalOr);
|
|
220
|
-
// })();
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
const assert_object =
|
|
224
|
-
(equals: boolean) =>
|
|
225
|
-
(project: IProject) =>
|
|
226
|
-
(importer: FunctionImporter) =>
|
|
227
|
-
check_object({
|
|
228
|
-
equals,
|
|
229
|
-
assert: true,
|
|
230
|
-
undefined: true,
|
|
231
|
-
reduce: ts.factory.createLogicalAnd,
|
|
232
|
-
positive: ts.factory.createTrue(),
|
|
233
|
-
superfluous: (value) =>
|
|
234
|
-
create_guard_call(importer)()(
|
|
235
|
-
ts.factory.createAdd(
|
|
236
|
-
ts.factory.createIdentifier("_path"),
|
|
237
|
-
ts.factory.createCallExpression(
|
|
238
|
-
importer.use("join"),
|
|
239
|
-
undefined,
|
|
240
|
-
[ts.factory.createIdentifier("key")],
|
|
241
|
-
),
|
|
242
|
-
),
|
|
243
|
-
"undefined",
|
|
244
|
-
value,
|
|
245
|
-
),
|
|
246
|
-
halt: (expr) =>
|
|
247
|
-
ts.factory.createLogicalOr(
|
|
248
|
-
ts.factory.createStrictEquality(
|
|
249
|
-
ts.factory.createFalse(),
|
|
250
|
-
ts.factory.createIdentifier("_exceptionable"),
|
|
251
|
-
),
|
|
252
|
-
expr,
|
|
253
|
-
),
|
|
254
|
-
})(project)(importer);
|
|
255
|
-
|
|
256
|
-
const joiner =
|
|
257
|
-
(equals: boolean) =>
|
|
258
|
-
(project: IProject) =>
|
|
259
|
-
(importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
|
|
260
|
-
object: assert_object(equals)(project)(importer),
|
|
261
|
-
array: (input, arrow) =>
|
|
262
|
-
ts.factory.createCallExpression(
|
|
263
|
-
IdentifierFactory.access(input)("every"),
|
|
264
|
-
undefined,
|
|
265
|
-
[arrow],
|
|
266
|
-
),
|
|
267
|
-
failure: (value, expected, explore) =>
|
|
268
|
-
create_guard_call(importer)(
|
|
269
|
-
explore?.from === "top"
|
|
270
|
-
? ts.factory.createTrue()
|
|
271
|
-
: ts.factory.createIdentifier("_exceptionable"),
|
|
272
|
-
)(
|
|
273
|
-
ts.factory.createIdentifier(
|
|
274
|
-
explore?.postfix
|
|
275
|
-
? `_path + ${explore.postfix}`
|
|
276
|
-
: "_path",
|
|
277
|
-
),
|
|
278
|
-
expected,
|
|
279
|
-
value,
|
|
280
|
-
),
|
|
281
|
-
full: equals
|
|
282
|
-
? undefined
|
|
283
|
-
: (condition) => (input, expected, explore) =>
|
|
284
|
-
ts.factory.createLogicalOr(
|
|
285
|
-
condition,
|
|
286
|
-
create_guard_call(importer)(
|
|
287
|
-
explore.from === "top"
|
|
288
|
-
? ts.factory.createTrue()
|
|
289
|
-
: ts.factory.createIdentifier(
|
|
290
|
-
"_exceptionable",
|
|
291
|
-
),
|
|
292
|
-
)(
|
|
293
|
-
ts.factory.createIdentifier("_path"),
|
|
294
|
-
expected,
|
|
295
|
-
input,
|
|
296
|
-
),
|
|
297
|
-
),
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
const create_guard_call =
|
|
301
|
-
(importer: FunctionImporter) =>
|
|
302
|
-
(exceptionable?: ts.Expression) =>
|
|
303
|
-
(
|
|
304
|
-
path: ts.Expression,
|
|
305
|
-
expected: string,
|
|
306
|
-
value: ts.Expression,
|
|
307
|
-
): ts.Expression =>
|
|
308
|
-
ts.factory.createCallExpression(importer.use("guard"), undefined, [
|
|
309
|
-
exceptionable ?? ts.factory.createIdentifier("_exceptionable"),
|
|
310
|
-
ts.factory.createObjectLiteralExpression(
|
|
311
|
-
[
|
|
312
|
-
ts.factory.createPropertyAssignment("path", path),
|
|
313
|
-
ts.factory.createPropertyAssignment(
|
|
314
|
-
"expected",
|
|
315
|
-
ts.factory.createStringLiteral(expected),
|
|
316
|
-
),
|
|
317
|
-
ts.factory.createPropertyAssignment("value", value),
|
|
318
|
-
],
|
|
319
|
-
true,
|
|
320
|
-
),
|
|
321
|
-
]);
|
|
322
|
-
}
|
|
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_object } from "./internal/check_object";
|
|
14
|
+
|
|
15
|
+
export namespace AssertProgrammer {
|
|
16
|
+
export const write =
|
|
17
|
+
(project: IProject) =>
|
|
18
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
19
|
+
(equals: boolean) =>
|
|
20
|
+
(type: ts.Type, name?: string) => {
|
|
21
|
+
const importer: FunctionImporter = new FunctionImporter(
|
|
22
|
+
modulo.getText(),
|
|
23
|
+
);
|
|
24
|
+
const is = IsProgrammer.write(project)(modulo, true)(equals)(
|
|
25
|
+
type,
|
|
26
|
+
name ?? TypeFactory.getFullName(project.checker)(type),
|
|
27
|
+
);
|
|
28
|
+
const assert: ts.ArrowFunction = CheckerProgrammer.write(project)({
|
|
29
|
+
prefix: "$a",
|
|
30
|
+
path: true,
|
|
31
|
+
trace: true,
|
|
32
|
+
numeric: OptionPredicator.numeric(project.options),
|
|
33
|
+
equals,
|
|
34
|
+
atomist: (explore) => (entry) => (input) =>
|
|
35
|
+
[
|
|
36
|
+
...(entry.expression ? [entry.expression] : []),
|
|
37
|
+
...(entry.conditions.length === 0
|
|
38
|
+
? []
|
|
39
|
+
: entry.conditions.length === 1
|
|
40
|
+
? entry.conditions[0]!.map((cond) =>
|
|
41
|
+
ts.factory.createLogicalOr(
|
|
42
|
+
cond.expression,
|
|
43
|
+
create_guard_call(importer)(
|
|
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
|
+
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(
|
|
68
|
+
a,
|
|
69
|
+
b,
|
|
70
|
+
),
|
|
71
|
+
),
|
|
72
|
+
)
|
|
73
|
+
.reduce((a, b) =>
|
|
74
|
+
ts.factory.createLogicalOr(a, b),
|
|
75
|
+
),
|
|
76
|
+
create_guard_call(importer)(
|
|
77
|
+
explore.from === "top"
|
|
78
|
+
? ts.factory.createTrue()
|
|
79
|
+
: ts.factory.createIdentifier(
|
|
80
|
+
"_exceptionable",
|
|
81
|
+
),
|
|
82
|
+
)(
|
|
83
|
+
ts.factory.createIdentifier(
|
|
84
|
+
explore.postfix
|
|
85
|
+
? `_path + ${explore.postfix}`
|
|
86
|
+
: "_path",
|
|
87
|
+
),
|
|
88
|
+
entry.expected,
|
|
89
|
+
input,
|
|
90
|
+
),
|
|
91
|
+
),
|
|
92
|
+
]),
|
|
93
|
+
].reduce((x, y) => ts.factory.createLogicalAnd(x, y)),
|
|
94
|
+
combiner: combiner(equals)(project)(importer),
|
|
95
|
+
joiner: joiner(equals)(project)(importer),
|
|
96
|
+
success: ts.factory.createTrue(),
|
|
97
|
+
addition: () => importer.declare(modulo),
|
|
98
|
+
})(importer)(type, name);
|
|
99
|
+
|
|
100
|
+
return ts.factory.createArrowFunction(
|
|
101
|
+
undefined,
|
|
102
|
+
undefined,
|
|
103
|
+
[
|
|
104
|
+
IdentifierFactory.parameter(
|
|
105
|
+
"input",
|
|
106
|
+
TypeFactory.keyword("any"),
|
|
107
|
+
),
|
|
108
|
+
],
|
|
109
|
+
ts.factory.createTypeReferenceNode(
|
|
110
|
+
name ?? TypeFactory.getFullName(project.checker)(type),
|
|
111
|
+
),
|
|
112
|
+
undefined,
|
|
113
|
+
ts.factory.createBlock(
|
|
114
|
+
[
|
|
115
|
+
StatementFactory.constant("__is", is),
|
|
116
|
+
ts.factory.createIfStatement(
|
|
117
|
+
ts.factory.createStrictEquality(
|
|
118
|
+
ts.factory.createFalse(),
|
|
119
|
+
ts.factory.createCallExpression(
|
|
120
|
+
ts.factory.createIdentifier("__is"),
|
|
121
|
+
undefined,
|
|
122
|
+
[ts.factory.createIdentifier("input")],
|
|
123
|
+
),
|
|
124
|
+
),
|
|
125
|
+
ts.factory.createExpressionStatement(
|
|
126
|
+
ts.factory.createCallExpression(
|
|
127
|
+
assert,
|
|
128
|
+
undefined,
|
|
129
|
+
[
|
|
130
|
+
ts.factory.createIdentifier("input"),
|
|
131
|
+
ts.factory.createStringLiteral(
|
|
132
|
+
"$input",
|
|
133
|
+
),
|
|
134
|
+
ts.factory.createTrue(),
|
|
135
|
+
],
|
|
136
|
+
),
|
|
137
|
+
),
|
|
138
|
+
undefined,
|
|
139
|
+
),
|
|
140
|
+
ts.factory.createReturnStatement(
|
|
141
|
+
ts.factory.createIdentifier(`input`),
|
|
142
|
+
),
|
|
143
|
+
],
|
|
144
|
+
true,
|
|
145
|
+
),
|
|
146
|
+
);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const combiner =
|
|
150
|
+
(equals: boolean) =>
|
|
151
|
+
(project: IProject) =>
|
|
152
|
+
(importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
|
|
153
|
+
(explore: CheckerProgrammer.IExplore) => {
|
|
154
|
+
if (explore.tracable === false)
|
|
155
|
+
return IsProgrammer.configure({
|
|
156
|
+
object: assert_object(equals)(project)(importer),
|
|
157
|
+
numeric: true,
|
|
158
|
+
})(project)(importer).combiner(explore);
|
|
159
|
+
|
|
160
|
+
const path: string = explore.postfix
|
|
161
|
+
? `_path + ${explore.postfix}`
|
|
162
|
+
: "_path";
|
|
163
|
+
return (logic) => (input, binaries, expected) =>
|
|
164
|
+
logic === "and"
|
|
165
|
+
? binaries
|
|
166
|
+
.map((binary) =>
|
|
167
|
+
binary.combined
|
|
168
|
+
? binary.expression
|
|
169
|
+
: ts.factory.createLogicalOr(
|
|
170
|
+
binary.expression,
|
|
171
|
+
create_guard_call(importer)(
|
|
172
|
+
explore.source === "top"
|
|
173
|
+
? ts.factory.createTrue()
|
|
174
|
+
: ts.factory.createIdentifier(
|
|
175
|
+
"_exceptionable",
|
|
176
|
+
),
|
|
177
|
+
)(
|
|
178
|
+
ts.factory.createIdentifier(path),
|
|
179
|
+
expected,
|
|
180
|
+
input,
|
|
181
|
+
),
|
|
182
|
+
),
|
|
183
|
+
)
|
|
184
|
+
.reduce(ts.factory.createLogicalAnd)
|
|
185
|
+
: ts.factory.createLogicalOr(
|
|
186
|
+
binaries
|
|
187
|
+
.map((binary) => binary.expression)
|
|
188
|
+
.reduce(ts.factory.createLogicalOr),
|
|
189
|
+
create_guard_call(importer)(
|
|
190
|
+
explore.source === "top"
|
|
191
|
+
? ts.factory.createTrue()
|
|
192
|
+
: ts.factory.createIdentifier(
|
|
193
|
+
"_exceptionable",
|
|
194
|
+
),
|
|
195
|
+
)(ts.factory.createIdentifier(path), expected, input),
|
|
196
|
+
);
|
|
197
|
+
// : (() => {
|
|
198
|
+
// const addicted = binaries.slice();
|
|
199
|
+
// if (
|
|
200
|
+
// addicted[addicted.length - 1]!.combined === false
|
|
201
|
+
// ) {
|
|
202
|
+
// addicted.push({
|
|
203
|
+
// combined: true,
|
|
204
|
+
// expression: create_guard_call(importer)(
|
|
205
|
+
// explore.source === "top"
|
|
206
|
+
// ? ts.factory.createTrue()
|
|
207
|
+
// : ts.factory.createIdentifier(
|
|
208
|
+
// "_exceptionable",
|
|
209
|
+
// ),
|
|
210
|
+
// )(
|
|
211
|
+
// ts.factory.createIdentifier(path),
|
|
212
|
+
// expected,
|
|
213
|
+
// input,
|
|
214
|
+
// ),
|
|
215
|
+
// });
|
|
216
|
+
// }
|
|
217
|
+
// return addicted
|
|
218
|
+
// .map((b) => b.expression)
|
|
219
|
+
// .reduce(ts.factory.createLogicalOr);
|
|
220
|
+
// })();
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
const assert_object =
|
|
224
|
+
(equals: boolean) =>
|
|
225
|
+
(project: IProject) =>
|
|
226
|
+
(importer: FunctionImporter) =>
|
|
227
|
+
check_object({
|
|
228
|
+
equals,
|
|
229
|
+
assert: true,
|
|
230
|
+
undefined: true,
|
|
231
|
+
reduce: ts.factory.createLogicalAnd,
|
|
232
|
+
positive: ts.factory.createTrue(),
|
|
233
|
+
superfluous: (value) =>
|
|
234
|
+
create_guard_call(importer)()(
|
|
235
|
+
ts.factory.createAdd(
|
|
236
|
+
ts.factory.createIdentifier("_path"),
|
|
237
|
+
ts.factory.createCallExpression(
|
|
238
|
+
importer.use("join"),
|
|
239
|
+
undefined,
|
|
240
|
+
[ts.factory.createIdentifier("key")],
|
|
241
|
+
),
|
|
242
|
+
),
|
|
243
|
+
"undefined",
|
|
244
|
+
value,
|
|
245
|
+
),
|
|
246
|
+
halt: (expr) =>
|
|
247
|
+
ts.factory.createLogicalOr(
|
|
248
|
+
ts.factory.createStrictEquality(
|
|
249
|
+
ts.factory.createFalse(),
|
|
250
|
+
ts.factory.createIdentifier("_exceptionable"),
|
|
251
|
+
),
|
|
252
|
+
expr,
|
|
253
|
+
),
|
|
254
|
+
})(project)(importer);
|
|
255
|
+
|
|
256
|
+
const joiner =
|
|
257
|
+
(equals: boolean) =>
|
|
258
|
+
(project: IProject) =>
|
|
259
|
+
(importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
|
|
260
|
+
object: assert_object(equals)(project)(importer),
|
|
261
|
+
array: (input, arrow) =>
|
|
262
|
+
ts.factory.createCallExpression(
|
|
263
|
+
IdentifierFactory.access(input)("every"),
|
|
264
|
+
undefined,
|
|
265
|
+
[arrow],
|
|
266
|
+
),
|
|
267
|
+
failure: (value, expected, explore) =>
|
|
268
|
+
create_guard_call(importer)(
|
|
269
|
+
explore?.from === "top"
|
|
270
|
+
? ts.factory.createTrue()
|
|
271
|
+
: ts.factory.createIdentifier("_exceptionable"),
|
|
272
|
+
)(
|
|
273
|
+
ts.factory.createIdentifier(
|
|
274
|
+
explore?.postfix
|
|
275
|
+
? `_path + ${explore.postfix}`
|
|
276
|
+
: "_path",
|
|
277
|
+
),
|
|
278
|
+
expected,
|
|
279
|
+
value,
|
|
280
|
+
),
|
|
281
|
+
full: equals
|
|
282
|
+
? undefined
|
|
283
|
+
: (condition) => (input, expected, explore) =>
|
|
284
|
+
ts.factory.createLogicalOr(
|
|
285
|
+
condition,
|
|
286
|
+
create_guard_call(importer)(
|
|
287
|
+
explore.from === "top"
|
|
288
|
+
? ts.factory.createTrue()
|
|
289
|
+
: ts.factory.createIdentifier(
|
|
290
|
+
"_exceptionable",
|
|
291
|
+
),
|
|
292
|
+
)(
|
|
293
|
+
ts.factory.createIdentifier("_path"),
|
|
294
|
+
expected,
|
|
295
|
+
input,
|
|
296
|
+
),
|
|
297
|
+
),
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
const create_guard_call =
|
|
301
|
+
(importer: FunctionImporter) =>
|
|
302
|
+
(exceptionable?: ts.Expression) =>
|
|
303
|
+
(
|
|
304
|
+
path: ts.Expression,
|
|
305
|
+
expected: string,
|
|
306
|
+
value: ts.Expression,
|
|
307
|
+
): ts.Expression =>
|
|
308
|
+
ts.factory.createCallExpression(importer.use("guard"), undefined, [
|
|
309
|
+
exceptionable ?? ts.factory.createIdentifier("_exceptionable"),
|
|
310
|
+
ts.factory.createObjectLiteralExpression(
|
|
311
|
+
[
|
|
312
|
+
ts.factory.createPropertyAssignment("path", path),
|
|
313
|
+
ts.factory.createPropertyAssignment(
|
|
314
|
+
"expected",
|
|
315
|
+
ts.factory.createStringLiteral(expected),
|
|
316
|
+
),
|
|
317
|
+
ts.factory.createPropertyAssignment("value", value),
|
|
318
|
+
],
|
|
319
|
+
true,
|
|
320
|
+
),
|
|
321
|
+
]);
|
|
322
|
+
}
|