typia 3.6.2 → 3.6.4
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/README.md +2 -1
- package/lib/factories/internal/metadata/emplace_metadata_object.js +8 -7
- package/lib/factories/internal/metadata/emplace_metadata_object.js.map +1 -1
- package/lib/functional/$is_uuid.js +1 -1
- package/lib/functional/$is_uuid.js.map +1 -1
- package/lib/module.d.ts +2 -2
- package/package.json +1 -1
- package/src/executable/setup/ArgumentParser.ts +91 -91
- package/src/executable/setup/FileRetriever.ts +33 -33
- package/src/executable/setup/PackageManager.ts +92 -92
- package/src/executable/setup/PluginConfigurator.ts +99 -99
- package/src/factories/internal/metadata/emplace_metadata_object.ts +142 -140
- package/src/functional/$is_uuid.ts +1 -2
- package/src/module.ts +1946 -1946
- package/src/programmers/AssertCloneProgrammer.ts +70 -70
- package/src/programmers/AssertParseProgrammer.ts +65 -65
- package/src/programmers/AssertProgrammer.ts +232 -232
- package/src/programmers/AssertPruneProgrammer.ts +67 -67
- package/src/programmers/AssertStringifyProgrammer.ts +71 -71
- package/src/programmers/CheckerProgrammer.ts +893 -893
- package/src/programmers/CloneProgrammer.ts +386 -386
- package/src/programmers/FeatureProgrammer.ts +505 -505
- package/src/programmers/IsCloneProgrammer.ts +80 -80
- package/src/programmers/IsParseProgrammer.ts +74 -74
- package/src/programmers/IsPruneProgrammer.ts +75 -75
- package/src/programmers/IsStringifyProgrammer.ts +81 -81
- package/src/programmers/PruneProgrammer.ts +341 -341
- package/src/programmers/RandomProgrammer.ts +391 -391
- package/src/programmers/StringifyProgrammer.ts +795 -795
- package/src/programmers/ValidateCloneProgrammer.ts +90 -90
- package/src/programmers/ValidateParseProgrammer.ts +69 -69
- package/src/programmers/ValidateProgrammer.ts +266 -266
- package/src/programmers/ValidatePruneProgrammer.ts +83 -83
- package/src/programmers/ValidateStringifyProgrammer.ts +89 -89
- package/src/transformers/features/miscellaneous/AssertCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/AssertPruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateAssertCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateAssertPruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateIsCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateIsPruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreatePruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateRandomGenerator.ts +42 -42
- package/src/transformers/features/miscellaneous/CreateValidateCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateValidatePruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/IsCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/IsPruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/PruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/RandomTransformer.ts +48 -48
- package/src/transformers/features/miscellaneous/ValidateCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/ValidatePruneTransformer.ts +9 -9
- package/src/transformers/features/parsers/AssertParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/CreateIsParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/IsParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/ValidateParseTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +10 -10
- package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +11 -11
- package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/StringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +10 -10
- package/src/transformers/features/validators/AssertTransformer.ts +11 -11
- package/src/transformers/features/validators/CreateAssertTransformer.ts +12 -12
- package/src/transformers/features/validators/CreateIsTransformer.ts +10 -10
- package/src/transformers/features/validators/CreateValidateTransformer.ts +12 -12
- package/src/transformers/features/validators/IsTransformer.ts +10 -10
- package/src/transformers/features/validators/ValidateTransformer.ts +11 -11
- package/src/transformers/internal/GenericTransformer.ts +99 -99
|
@@ -1,341 +1,341 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { ExpressionFactory } from "../factories/ExpressionFactory";
|
|
4
|
-
import { IdentifierFactory } from "../factories/IdentifierFactory";
|
|
5
|
-
import { MetadataCollection } from "../factories/MetadataCollection";
|
|
6
|
-
import { MetadataFactory } from "../factories/MetadataFactory";
|
|
7
|
-
import { TypeFactory } from "../factories/TypeFactory";
|
|
8
|
-
|
|
9
|
-
import { Metadata } from "../metadata/Metadata";
|
|
10
|
-
|
|
11
|
-
import { IProject } from "../transformers/IProject";
|
|
12
|
-
|
|
13
|
-
import { FeatureProgrammer } from "./FeatureProgrammer";
|
|
14
|
-
import { IsProgrammer } from "./IsProgrammer";
|
|
15
|
-
import { FunctionImporter } from "./helpers/FunctionImporeter";
|
|
16
|
-
import { PruneJoiner } from "./helpers/PruneJoiner";
|
|
17
|
-
import { UnionExplorer } from "./helpers/UnionExplorer";
|
|
18
|
-
import { decode_union_object } from "./internal/decode_union_object";
|
|
19
|
-
|
|
20
|
-
export namespace PruneProgrammer {
|
|
21
|
-
export function generate(
|
|
22
|
-
project: IProject,
|
|
23
|
-
modulo: ts.LeftHandSideExpression,
|
|
24
|
-
) {
|
|
25
|
-
const importer: FunctionImporter = new FunctionImporter();
|
|
26
|
-
return FeatureProgrammer.generate(
|
|
27
|
-
project,
|
|
28
|
-
CONFIG(project, importer),
|
|
29
|
-
importer,
|
|
30
|
-
(collection) => {
|
|
31
|
-
const isFunctors = IsProgrammer.generate_functors(
|
|
32
|
-
project,
|
|
33
|
-
importer,
|
|
34
|
-
)(collection);
|
|
35
|
-
const isUnioners = IsProgrammer.generate_unioners(
|
|
36
|
-
project,
|
|
37
|
-
importer,
|
|
38
|
-
)(collection);
|
|
39
|
-
|
|
40
|
-
return [
|
|
41
|
-
...importer.declare(modulo),
|
|
42
|
-
...isFunctors.filter((_, i) =>
|
|
43
|
-
importer.hasLocal(`$io${i}`),
|
|
44
|
-
),
|
|
45
|
-
...isUnioners.filter((_, i) =>
|
|
46
|
-
importer.hasLocal(`$iu${i}`),
|
|
47
|
-
),
|
|
48
|
-
];
|
|
49
|
-
},
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/* -----------------------------------------------------------
|
|
54
|
-
DECODERS
|
|
55
|
-
----------------------------------------------------------- */
|
|
56
|
-
const decode =
|
|
57
|
-
(project: IProject, importer: FunctionImporter) =>
|
|
58
|
-
(
|
|
59
|
-
input: ts.Expression,
|
|
60
|
-
meta: Metadata,
|
|
61
|
-
explore: FeatureProgrammer.IExplore,
|
|
62
|
-
): ts.ConciseBody => {
|
|
63
|
-
if (filter(meta) === false) return ts.factory.createBlock([]);
|
|
64
|
-
|
|
65
|
-
interface IUnion {
|
|
66
|
-
type: string;
|
|
67
|
-
is: () => ts.Expression;
|
|
68
|
-
value: () => ts.Expression | ts.Block | ts.ReturnStatement;
|
|
69
|
-
}
|
|
70
|
-
const unions: IUnion[] = [];
|
|
71
|
-
|
|
72
|
-
//----
|
|
73
|
-
// LIST UP UNION TYPES
|
|
74
|
-
//----
|
|
75
|
-
// TUPLES
|
|
76
|
-
for (const tuple of meta.tuples.filter((t) =>
|
|
77
|
-
t.some((e) => filter(e.rest ?? e)),
|
|
78
|
-
))
|
|
79
|
-
unions.push({
|
|
80
|
-
type: "tuple",
|
|
81
|
-
is: () =>
|
|
82
|
-
IsProgrammer.decode(project, importer)(
|
|
83
|
-
input,
|
|
84
|
-
(() => {
|
|
85
|
-
const partial = Metadata.initialize();
|
|
86
|
-
partial.tuples.push(tuple);
|
|
87
|
-
return partial;
|
|
88
|
-
})(),
|
|
89
|
-
explore,
|
|
90
|
-
[],
|
|
91
|
-
),
|
|
92
|
-
value: () =>
|
|
93
|
-
decode_tuple(project, importer)(input, tuple, explore),
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
// ARRAYS
|
|
97
|
-
if (meta.arrays.filter(filter).length)
|
|
98
|
-
unions.push({
|
|
99
|
-
type: "array",
|
|
100
|
-
is: () => ExpressionFactory.isArray(input),
|
|
101
|
-
value: () =>
|
|
102
|
-
explore_arrays(project, importer)(
|
|
103
|
-
input,
|
|
104
|
-
meta.arrays,
|
|
105
|
-
{
|
|
106
|
-
...explore,
|
|
107
|
-
from: "array",
|
|
108
|
-
},
|
|
109
|
-
[],
|
|
110
|
-
),
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
// BUILT-IN CLASSES
|
|
114
|
-
if (meta.natives.length)
|
|
115
|
-
for (const native of meta.natives)
|
|
116
|
-
unions.push({
|
|
117
|
-
type: "native",
|
|
118
|
-
is: () => ExpressionFactory.isInstanceOf(input, native),
|
|
119
|
-
value: () => ts.factory.createReturnStatement(),
|
|
120
|
-
});
|
|
121
|
-
if (meta.sets.length)
|
|
122
|
-
unions.push({
|
|
123
|
-
type: "set",
|
|
124
|
-
is: () => ExpressionFactory.isInstanceOf(input, "Set"),
|
|
125
|
-
value: () => ts.factory.createReturnStatement(),
|
|
126
|
-
});
|
|
127
|
-
if (meta.maps.length)
|
|
128
|
-
unions.push({
|
|
129
|
-
type: "map",
|
|
130
|
-
is: () => ExpressionFactory.isInstanceOf(input, "Map"),
|
|
131
|
-
value: () => ts.factory.createReturnStatement(),
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
// OBJECTS
|
|
135
|
-
if (meta.objects.length)
|
|
136
|
-
unions.push({
|
|
137
|
-
type: "object",
|
|
138
|
-
is: () =>
|
|
139
|
-
ExpressionFactory.isObject(input, {
|
|
140
|
-
checkNull: true,
|
|
141
|
-
checkArray: false,
|
|
142
|
-
}),
|
|
143
|
-
value: () =>
|
|
144
|
-
explore_objects(importer)(input, meta, {
|
|
145
|
-
...explore,
|
|
146
|
-
from: "object",
|
|
147
|
-
}),
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
//----
|
|
151
|
-
// STATEMENTS
|
|
152
|
-
//----
|
|
153
|
-
const converter = (
|
|
154
|
-
v: ts.Expression | ts.Block | ts.ReturnStatement,
|
|
155
|
-
) =>
|
|
156
|
-
ts.isReturnStatement(v) || ts.isBlock(v)
|
|
157
|
-
? v
|
|
158
|
-
: ts.factory.createExpressionStatement(v);
|
|
159
|
-
|
|
160
|
-
const statements: ts.Statement[] = unions.map((u) =>
|
|
161
|
-
ts.factory.createIfStatement(u.is(), converter(u.value())),
|
|
162
|
-
);
|
|
163
|
-
return ts.factory.createBlock(statements, true);
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
const decode_tuple =
|
|
167
|
-
(project: IProject, importer: FunctionImporter) =>
|
|
168
|
-
(
|
|
169
|
-
input: ts.Expression,
|
|
170
|
-
tuple: Metadata[],
|
|
171
|
-
explore: FeatureProgrammer.IExplore,
|
|
172
|
-
): ts.Block => {
|
|
173
|
-
const children: ts.ConciseBody[] = tuple
|
|
174
|
-
.map((elem, index) => [elem, index] as const)
|
|
175
|
-
.filter(([elem]) => filter(elem) && elem.rest === null)
|
|
176
|
-
.map(([elem, index]) =>
|
|
177
|
-
decode(project, importer)(
|
|
178
|
-
ts.factory.createElementAccessExpression(input, index),
|
|
179
|
-
elem,
|
|
180
|
-
{
|
|
181
|
-
...explore,
|
|
182
|
-
from: "array",
|
|
183
|
-
},
|
|
184
|
-
),
|
|
185
|
-
);
|
|
186
|
-
const rest = (() => {
|
|
187
|
-
if (tuple.length === 0) return null;
|
|
188
|
-
|
|
189
|
-
const last: Metadata = tuple[tuple.length - 1]!;
|
|
190
|
-
const rest: Metadata | null = last.rest;
|
|
191
|
-
if (rest === null || filter(rest) === false) return null;
|
|
192
|
-
|
|
193
|
-
return decode(project, importer)(
|
|
194
|
-
ts.factory.createCallExpression(
|
|
195
|
-
IdentifierFactory.join(input, "slice"),
|
|
196
|
-
undefined,
|
|
197
|
-
[ts.factory.createNumericLiteral(tuple.length - 1)],
|
|
198
|
-
),
|
|
199
|
-
(() => {
|
|
200
|
-
const wrapper: Metadata = Metadata.initialize();
|
|
201
|
-
wrapper.arrays.push(rest);
|
|
202
|
-
return wrapper;
|
|
203
|
-
})(),
|
|
204
|
-
{
|
|
205
|
-
...explore,
|
|
206
|
-
start: tuple.length - 1,
|
|
207
|
-
},
|
|
208
|
-
);
|
|
209
|
-
})();
|
|
210
|
-
return PruneJoiner.tuple(children, rest);
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
const decode_array = (project: IProject, importer: FunctionImporter) =>
|
|
214
|
-
FeatureProgrammer.decode_array(
|
|
215
|
-
CONFIG(project, importer),
|
|
216
|
-
importer,
|
|
217
|
-
PruneJoiner.array,
|
|
218
|
-
);
|
|
219
|
-
|
|
220
|
-
const decode_object = (importer: FunctionImporter) =>
|
|
221
|
-
FeatureProgrammer.decode_object({
|
|
222
|
-
trace: false,
|
|
223
|
-
path: false,
|
|
224
|
-
functors: FUNCTORS,
|
|
225
|
-
})(importer);
|
|
226
|
-
|
|
227
|
-
const explore_arrays = (project: IProject, importer: FunctionImporter) =>
|
|
228
|
-
UnionExplorer.array({
|
|
229
|
-
checker: IsProgrammer.decode(project, importer),
|
|
230
|
-
decoder: decode_array(project, importer),
|
|
231
|
-
empty: ts.factory.createReturnStatement(),
|
|
232
|
-
success: ts.factory.createTrue(),
|
|
233
|
-
failure: (input, expected) =>
|
|
234
|
-
create_throw_error(importer, input, expected),
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
const explore_objects =
|
|
238
|
-
(importer: FunctionImporter) =>
|
|
239
|
-
(
|
|
240
|
-
input: ts.Expression,
|
|
241
|
-
meta: Metadata,
|
|
242
|
-
explore: FeatureProgrammer.IExplore,
|
|
243
|
-
) => {
|
|
244
|
-
if (meta.objects.length === 1)
|
|
245
|
-
return decode_object(importer)(
|
|
246
|
-
input,
|
|
247
|
-
meta.objects[0]!,
|
|
248
|
-
explore,
|
|
249
|
-
);
|
|
250
|
-
|
|
251
|
-
return ts.factory.createCallExpression(
|
|
252
|
-
ts.factory.createIdentifier(`${UNIONERS}${meta.union_index!}`),
|
|
253
|
-
undefined,
|
|
254
|
-
[input],
|
|
255
|
-
);
|
|
256
|
-
};
|
|
257
|
-
|
|
258
|
-
const filter = (meta: Metadata): boolean =>
|
|
259
|
-
meta.any === false &&
|
|
260
|
-
(meta.objects.length !== 0 ||
|
|
261
|
-
meta.tuples.some((t) => t.some((e) => filter(e.rest ?? e))) ||
|
|
262
|
-
meta.arrays.some((e) => filter(e)));
|
|
263
|
-
|
|
264
|
-
/* -----------------------------------------------------------
|
|
265
|
-
CONFIGURATIONS
|
|
266
|
-
----------------------------------------------------------- */
|
|
267
|
-
const FUNCTORS = "$po";
|
|
268
|
-
const UNIONERS = "$pu";
|
|
269
|
-
|
|
270
|
-
const CONFIG = (
|
|
271
|
-
project: IProject,
|
|
272
|
-
importer: FunctionImporter,
|
|
273
|
-
): FeatureProgrammer.IConfig => ({
|
|
274
|
-
types: {
|
|
275
|
-
input: (type, name) =>
|
|
276
|
-
ts.factory.createTypeReferenceNode(
|
|
277
|
-
name ?? TypeFactory.getFullName(project.checker, type),
|
|
278
|
-
),
|
|
279
|
-
output: () => TypeFactory.keyword("void"),
|
|
280
|
-
},
|
|
281
|
-
functors: FUNCTORS,
|
|
282
|
-
unioners: UNIONERS,
|
|
283
|
-
trace: false,
|
|
284
|
-
path: false,
|
|
285
|
-
initializer,
|
|
286
|
-
decoder: decode(project, importer),
|
|
287
|
-
objector: OBJECTOR(project, importer),
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
const OBJECTOR = (
|
|
291
|
-
project: IProject,
|
|
292
|
-
importer: FunctionImporter,
|
|
293
|
-
): FeatureProgrammer.IConfig.IObjector => ({
|
|
294
|
-
checker: IsProgrammer.decode(project, importer),
|
|
295
|
-
decoder: decode_object(importer),
|
|
296
|
-
joiner: PruneJoiner.object,
|
|
297
|
-
unionizer: decode_union_object(IsProgrammer.decode_object(importer))(
|
|
298
|
-
decode_object(importer),
|
|
299
|
-
)((exp) => exp)((value, expected) =>
|
|
300
|
-
create_throw_error(importer, value, expected),
|
|
301
|
-
),
|
|
302
|
-
failure: (input, expected) =>
|
|
303
|
-
create_throw_error(importer, input, expected),
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
const initializer: FeatureProgrammer.IConfig["initializer"] = (
|
|
307
|
-
{ checker },
|
|
308
|
-
type,
|
|
309
|
-
) => {
|
|
310
|
-
const collection = new MetadataCollection();
|
|
311
|
-
const meta = MetadataFactory.generate(checker, collection, type, {
|
|
312
|
-
resolve: false,
|
|
313
|
-
constant: true,
|
|
314
|
-
});
|
|
315
|
-
return [collection, meta];
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
const create_throw_error = (
|
|
319
|
-
importer: FunctionImporter,
|
|
320
|
-
value: ts.Expression,
|
|
321
|
-
expected: string,
|
|
322
|
-
) =>
|
|
323
|
-
ts.factory.createExpressionStatement(
|
|
324
|
-
ts.factory.createCallExpression(
|
|
325
|
-
importer.use("throws"),
|
|
326
|
-
[],
|
|
327
|
-
[
|
|
328
|
-
ts.factory.createObjectLiteralExpression(
|
|
329
|
-
[
|
|
330
|
-
ts.factory.createPropertyAssignment(
|
|
331
|
-
"expected",
|
|
332
|
-
ts.factory.createStringLiteral(expected),
|
|
333
|
-
),
|
|
334
|
-
ts.factory.createPropertyAssignment("value", value),
|
|
335
|
-
],
|
|
336
|
-
true,
|
|
337
|
-
),
|
|
338
|
-
],
|
|
339
|
-
),
|
|
340
|
-
);
|
|
341
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { ExpressionFactory } from "../factories/ExpressionFactory";
|
|
4
|
+
import { IdentifierFactory } from "../factories/IdentifierFactory";
|
|
5
|
+
import { MetadataCollection } from "../factories/MetadataCollection";
|
|
6
|
+
import { MetadataFactory } from "../factories/MetadataFactory";
|
|
7
|
+
import { TypeFactory } from "../factories/TypeFactory";
|
|
8
|
+
|
|
9
|
+
import { Metadata } from "../metadata/Metadata";
|
|
10
|
+
|
|
11
|
+
import { IProject } from "../transformers/IProject";
|
|
12
|
+
|
|
13
|
+
import { FeatureProgrammer } from "./FeatureProgrammer";
|
|
14
|
+
import { IsProgrammer } from "./IsProgrammer";
|
|
15
|
+
import { FunctionImporter } from "./helpers/FunctionImporeter";
|
|
16
|
+
import { PruneJoiner } from "./helpers/PruneJoiner";
|
|
17
|
+
import { UnionExplorer } from "./helpers/UnionExplorer";
|
|
18
|
+
import { decode_union_object } from "./internal/decode_union_object";
|
|
19
|
+
|
|
20
|
+
export namespace PruneProgrammer {
|
|
21
|
+
export function generate(
|
|
22
|
+
project: IProject,
|
|
23
|
+
modulo: ts.LeftHandSideExpression,
|
|
24
|
+
) {
|
|
25
|
+
const importer: FunctionImporter = new FunctionImporter();
|
|
26
|
+
return FeatureProgrammer.generate(
|
|
27
|
+
project,
|
|
28
|
+
CONFIG(project, importer),
|
|
29
|
+
importer,
|
|
30
|
+
(collection) => {
|
|
31
|
+
const isFunctors = IsProgrammer.generate_functors(
|
|
32
|
+
project,
|
|
33
|
+
importer,
|
|
34
|
+
)(collection);
|
|
35
|
+
const isUnioners = IsProgrammer.generate_unioners(
|
|
36
|
+
project,
|
|
37
|
+
importer,
|
|
38
|
+
)(collection);
|
|
39
|
+
|
|
40
|
+
return [
|
|
41
|
+
...importer.declare(modulo),
|
|
42
|
+
...isFunctors.filter((_, i) =>
|
|
43
|
+
importer.hasLocal(`$io${i}`),
|
|
44
|
+
),
|
|
45
|
+
...isUnioners.filter((_, i) =>
|
|
46
|
+
importer.hasLocal(`$iu${i}`),
|
|
47
|
+
),
|
|
48
|
+
];
|
|
49
|
+
},
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/* -----------------------------------------------------------
|
|
54
|
+
DECODERS
|
|
55
|
+
----------------------------------------------------------- */
|
|
56
|
+
const decode =
|
|
57
|
+
(project: IProject, importer: FunctionImporter) =>
|
|
58
|
+
(
|
|
59
|
+
input: ts.Expression,
|
|
60
|
+
meta: Metadata,
|
|
61
|
+
explore: FeatureProgrammer.IExplore,
|
|
62
|
+
): ts.ConciseBody => {
|
|
63
|
+
if (filter(meta) === false) return ts.factory.createBlock([]);
|
|
64
|
+
|
|
65
|
+
interface IUnion {
|
|
66
|
+
type: string;
|
|
67
|
+
is: () => ts.Expression;
|
|
68
|
+
value: () => ts.Expression | ts.Block | ts.ReturnStatement;
|
|
69
|
+
}
|
|
70
|
+
const unions: IUnion[] = [];
|
|
71
|
+
|
|
72
|
+
//----
|
|
73
|
+
// LIST UP UNION TYPES
|
|
74
|
+
//----
|
|
75
|
+
// TUPLES
|
|
76
|
+
for (const tuple of meta.tuples.filter((t) =>
|
|
77
|
+
t.some((e) => filter(e.rest ?? e)),
|
|
78
|
+
))
|
|
79
|
+
unions.push({
|
|
80
|
+
type: "tuple",
|
|
81
|
+
is: () =>
|
|
82
|
+
IsProgrammer.decode(project, importer)(
|
|
83
|
+
input,
|
|
84
|
+
(() => {
|
|
85
|
+
const partial = Metadata.initialize();
|
|
86
|
+
partial.tuples.push(tuple);
|
|
87
|
+
return partial;
|
|
88
|
+
})(),
|
|
89
|
+
explore,
|
|
90
|
+
[],
|
|
91
|
+
),
|
|
92
|
+
value: () =>
|
|
93
|
+
decode_tuple(project, importer)(input, tuple, explore),
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// ARRAYS
|
|
97
|
+
if (meta.arrays.filter(filter).length)
|
|
98
|
+
unions.push({
|
|
99
|
+
type: "array",
|
|
100
|
+
is: () => ExpressionFactory.isArray(input),
|
|
101
|
+
value: () =>
|
|
102
|
+
explore_arrays(project, importer)(
|
|
103
|
+
input,
|
|
104
|
+
meta.arrays,
|
|
105
|
+
{
|
|
106
|
+
...explore,
|
|
107
|
+
from: "array",
|
|
108
|
+
},
|
|
109
|
+
[],
|
|
110
|
+
),
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// BUILT-IN CLASSES
|
|
114
|
+
if (meta.natives.length)
|
|
115
|
+
for (const native of meta.natives)
|
|
116
|
+
unions.push({
|
|
117
|
+
type: "native",
|
|
118
|
+
is: () => ExpressionFactory.isInstanceOf(input, native),
|
|
119
|
+
value: () => ts.factory.createReturnStatement(),
|
|
120
|
+
});
|
|
121
|
+
if (meta.sets.length)
|
|
122
|
+
unions.push({
|
|
123
|
+
type: "set",
|
|
124
|
+
is: () => ExpressionFactory.isInstanceOf(input, "Set"),
|
|
125
|
+
value: () => ts.factory.createReturnStatement(),
|
|
126
|
+
});
|
|
127
|
+
if (meta.maps.length)
|
|
128
|
+
unions.push({
|
|
129
|
+
type: "map",
|
|
130
|
+
is: () => ExpressionFactory.isInstanceOf(input, "Map"),
|
|
131
|
+
value: () => ts.factory.createReturnStatement(),
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// OBJECTS
|
|
135
|
+
if (meta.objects.length)
|
|
136
|
+
unions.push({
|
|
137
|
+
type: "object",
|
|
138
|
+
is: () =>
|
|
139
|
+
ExpressionFactory.isObject(input, {
|
|
140
|
+
checkNull: true,
|
|
141
|
+
checkArray: false,
|
|
142
|
+
}),
|
|
143
|
+
value: () =>
|
|
144
|
+
explore_objects(importer)(input, meta, {
|
|
145
|
+
...explore,
|
|
146
|
+
from: "object",
|
|
147
|
+
}),
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
//----
|
|
151
|
+
// STATEMENTS
|
|
152
|
+
//----
|
|
153
|
+
const converter = (
|
|
154
|
+
v: ts.Expression | ts.Block | ts.ReturnStatement,
|
|
155
|
+
) =>
|
|
156
|
+
ts.isReturnStatement(v) || ts.isBlock(v)
|
|
157
|
+
? v
|
|
158
|
+
: ts.factory.createExpressionStatement(v);
|
|
159
|
+
|
|
160
|
+
const statements: ts.Statement[] = unions.map((u) =>
|
|
161
|
+
ts.factory.createIfStatement(u.is(), converter(u.value())),
|
|
162
|
+
);
|
|
163
|
+
return ts.factory.createBlock(statements, true);
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const decode_tuple =
|
|
167
|
+
(project: IProject, importer: FunctionImporter) =>
|
|
168
|
+
(
|
|
169
|
+
input: ts.Expression,
|
|
170
|
+
tuple: Metadata[],
|
|
171
|
+
explore: FeatureProgrammer.IExplore,
|
|
172
|
+
): ts.Block => {
|
|
173
|
+
const children: ts.ConciseBody[] = tuple
|
|
174
|
+
.map((elem, index) => [elem, index] as const)
|
|
175
|
+
.filter(([elem]) => filter(elem) && elem.rest === null)
|
|
176
|
+
.map(([elem, index]) =>
|
|
177
|
+
decode(project, importer)(
|
|
178
|
+
ts.factory.createElementAccessExpression(input, index),
|
|
179
|
+
elem,
|
|
180
|
+
{
|
|
181
|
+
...explore,
|
|
182
|
+
from: "array",
|
|
183
|
+
},
|
|
184
|
+
),
|
|
185
|
+
);
|
|
186
|
+
const rest = (() => {
|
|
187
|
+
if (tuple.length === 0) return null;
|
|
188
|
+
|
|
189
|
+
const last: Metadata = tuple[tuple.length - 1]!;
|
|
190
|
+
const rest: Metadata | null = last.rest;
|
|
191
|
+
if (rest === null || filter(rest) === false) return null;
|
|
192
|
+
|
|
193
|
+
return decode(project, importer)(
|
|
194
|
+
ts.factory.createCallExpression(
|
|
195
|
+
IdentifierFactory.join(input, "slice"),
|
|
196
|
+
undefined,
|
|
197
|
+
[ts.factory.createNumericLiteral(tuple.length - 1)],
|
|
198
|
+
),
|
|
199
|
+
(() => {
|
|
200
|
+
const wrapper: Metadata = Metadata.initialize();
|
|
201
|
+
wrapper.arrays.push(rest);
|
|
202
|
+
return wrapper;
|
|
203
|
+
})(),
|
|
204
|
+
{
|
|
205
|
+
...explore,
|
|
206
|
+
start: tuple.length - 1,
|
|
207
|
+
},
|
|
208
|
+
);
|
|
209
|
+
})();
|
|
210
|
+
return PruneJoiner.tuple(children, rest);
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
const decode_array = (project: IProject, importer: FunctionImporter) =>
|
|
214
|
+
FeatureProgrammer.decode_array(
|
|
215
|
+
CONFIG(project, importer),
|
|
216
|
+
importer,
|
|
217
|
+
PruneJoiner.array,
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
const decode_object = (importer: FunctionImporter) =>
|
|
221
|
+
FeatureProgrammer.decode_object({
|
|
222
|
+
trace: false,
|
|
223
|
+
path: false,
|
|
224
|
+
functors: FUNCTORS,
|
|
225
|
+
})(importer);
|
|
226
|
+
|
|
227
|
+
const explore_arrays = (project: IProject, importer: FunctionImporter) =>
|
|
228
|
+
UnionExplorer.array({
|
|
229
|
+
checker: IsProgrammer.decode(project, importer),
|
|
230
|
+
decoder: decode_array(project, importer),
|
|
231
|
+
empty: ts.factory.createReturnStatement(),
|
|
232
|
+
success: ts.factory.createTrue(),
|
|
233
|
+
failure: (input, expected) =>
|
|
234
|
+
create_throw_error(importer, input, expected),
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
const explore_objects =
|
|
238
|
+
(importer: FunctionImporter) =>
|
|
239
|
+
(
|
|
240
|
+
input: ts.Expression,
|
|
241
|
+
meta: Metadata,
|
|
242
|
+
explore: FeatureProgrammer.IExplore,
|
|
243
|
+
) => {
|
|
244
|
+
if (meta.objects.length === 1)
|
|
245
|
+
return decode_object(importer)(
|
|
246
|
+
input,
|
|
247
|
+
meta.objects[0]!,
|
|
248
|
+
explore,
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
return ts.factory.createCallExpression(
|
|
252
|
+
ts.factory.createIdentifier(`${UNIONERS}${meta.union_index!}`),
|
|
253
|
+
undefined,
|
|
254
|
+
[input],
|
|
255
|
+
);
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
const filter = (meta: Metadata): boolean =>
|
|
259
|
+
meta.any === false &&
|
|
260
|
+
(meta.objects.length !== 0 ||
|
|
261
|
+
meta.tuples.some((t) => t.some((e) => filter(e.rest ?? e))) ||
|
|
262
|
+
meta.arrays.some((e) => filter(e)));
|
|
263
|
+
|
|
264
|
+
/* -----------------------------------------------------------
|
|
265
|
+
CONFIGURATIONS
|
|
266
|
+
----------------------------------------------------------- */
|
|
267
|
+
const FUNCTORS = "$po";
|
|
268
|
+
const UNIONERS = "$pu";
|
|
269
|
+
|
|
270
|
+
const CONFIG = (
|
|
271
|
+
project: IProject,
|
|
272
|
+
importer: FunctionImporter,
|
|
273
|
+
): FeatureProgrammer.IConfig => ({
|
|
274
|
+
types: {
|
|
275
|
+
input: (type, name) =>
|
|
276
|
+
ts.factory.createTypeReferenceNode(
|
|
277
|
+
name ?? TypeFactory.getFullName(project.checker, type),
|
|
278
|
+
),
|
|
279
|
+
output: () => TypeFactory.keyword("void"),
|
|
280
|
+
},
|
|
281
|
+
functors: FUNCTORS,
|
|
282
|
+
unioners: UNIONERS,
|
|
283
|
+
trace: false,
|
|
284
|
+
path: false,
|
|
285
|
+
initializer,
|
|
286
|
+
decoder: decode(project, importer),
|
|
287
|
+
objector: OBJECTOR(project, importer),
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
const OBJECTOR = (
|
|
291
|
+
project: IProject,
|
|
292
|
+
importer: FunctionImporter,
|
|
293
|
+
): FeatureProgrammer.IConfig.IObjector => ({
|
|
294
|
+
checker: IsProgrammer.decode(project, importer),
|
|
295
|
+
decoder: decode_object(importer),
|
|
296
|
+
joiner: PruneJoiner.object,
|
|
297
|
+
unionizer: decode_union_object(IsProgrammer.decode_object(importer))(
|
|
298
|
+
decode_object(importer),
|
|
299
|
+
)((exp) => exp)((value, expected) =>
|
|
300
|
+
create_throw_error(importer, value, expected),
|
|
301
|
+
),
|
|
302
|
+
failure: (input, expected) =>
|
|
303
|
+
create_throw_error(importer, input, expected),
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
const initializer: FeatureProgrammer.IConfig["initializer"] = (
|
|
307
|
+
{ checker },
|
|
308
|
+
type,
|
|
309
|
+
) => {
|
|
310
|
+
const collection = new MetadataCollection();
|
|
311
|
+
const meta = MetadataFactory.generate(checker, collection, type, {
|
|
312
|
+
resolve: false,
|
|
313
|
+
constant: true,
|
|
314
|
+
});
|
|
315
|
+
return [collection, meta];
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
const create_throw_error = (
|
|
319
|
+
importer: FunctionImporter,
|
|
320
|
+
value: ts.Expression,
|
|
321
|
+
expected: string,
|
|
322
|
+
) =>
|
|
323
|
+
ts.factory.createExpressionStatement(
|
|
324
|
+
ts.factory.createCallExpression(
|
|
325
|
+
importer.use("throws"),
|
|
326
|
+
[],
|
|
327
|
+
[
|
|
328
|
+
ts.factory.createObjectLiteralExpression(
|
|
329
|
+
[
|
|
330
|
+
ts.factory.createPropertyAssignment(
|
|
331
|
+
"expected",
|
|
332
|
+
ts.factory.createStringLiteral(expected),
|
|
333
|
+
),
|
|
334
|
+
ts.factory.createPropertyAssignment("value", value),
|
|
335
|
+
],
|
|
336
|
+
true,
|
|
337
|
+
),
|
|
338
|
+
],
|
|
339
|
+
),
|
|
340
|
+
);
|
|
341
|
+
}
|