typia 7.0.0-dev.20240928 → 7.0.0-dev.20240930
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/internal/metadata/emplace_metadata_object.js +2 -1
- package/lib/factories/internal/metadata/emplace_metadata_object.js.map +1 -1
- package/lib/programmers/AssertProgrammer.js +14 -10
- package/lib/programmers/AssertProgrammer.js.map +1 -1
- package/lib/programmers/CheckerProgrammer.d.ts +5 -1
- package/lib/programmers/CheckerProgrammer.js +161 -135
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/programmers/FeatureProgrammer.d.ts +91 -28
- package/lib/programmers/FeatureProgrammer.js +158 -139
- package/lib/programmers/FeatureProgrammer.js.map +1 -1
- package/lib/programmers/IsProgrammer.d.ts +5 -1
- package/lib/programmers/IsProgrammer.js +70 -67
- package/lib/programmers/IsProgrammer.js.map +1 -1
- package/lib/programmers/ValidateProgrammer.js +7 -3
- package/lib/programmers/ValidateProgrammer.js.map +1 -1
- package/lib/programmers/helpers/UnionExplorer.js +31 -6
- package/lib/programmers/helpers/UnionExplorer.js.map +1 -1
- package/lib/programmers/internal/feature_object_entries.js +18 -14
- package/lib/programmers/internal/feature_object_entries.js.map +1 -1
- package/lib/programmers/json/JsonStringifyProgrammer.js +101 -62
- package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscCloneProgrammer.js +101 -62
- package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscPruneProgrammer.js +97 -62
- package/lib/programmers/misc/MiscPruneProgrammer.js.map +1 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js +118 -60
- package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
- package/package.json +1 -1
- package/src/factories/internal/metadata/emplace_metadata_object.ts +2 -1
- package/src/programmers/AssertProgrammer.ts +14 -10
- package/src/programmers/CheckerProgrammer.ts +139 -134
- package/src/programmers/FeatureProgrammer.ts +324 -266
- package/src/programmers/IsProgrammer.ts +80 -77
- package/src/programmers/ValidateProgrammer.ts +7 -3
- package/src/programmers/helpers/UnionExplorer.ts +33 -12
- package/src/programmers/internal/feature_object_entries.ts +18 -15
- package/src/programmers/json/JsonStringifyProgrammer.ts +103 -76
- package/src/programmers/misc/MiscCloneProgrammer.ts +122 -95
- package/src/programmers/misc/MiscPruneProgrammer.ts +111 -90
- package/src/programmers/notations/NotationGeneralProgrammer.ts +138 -91
|
@@ -20,8 +20,8 @@ import { feature_object_entries } from "./internal/feature_object_entries";
|
|
|
20
20
|
|
|
21
21
|
export namespace FeatureProgrammer {
|
|
22
22
|
/* -----------------------------------------------------------
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
PARAMETERS
|
|
24
|
+
----------------------------------------------------------- */
|
|
25
25
|
export interface IConfig<Output extends ts.ConciseBody = ts.ConciseBody> {
|
|
26
26
|
types: IConfig.ITypes;
|
|
27
27
|
|
|
@@ -45,16 +45,20 @@ export namespace FeatureProgrammer {
|
|
|
45
45
|
/**
|
|
46
46
|
* Initializer of metadata.
|
|
47
47
|
*/
|
|
48
|
-
initializer: (
|
|
49
|
-
context: ITypiaContext
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
) =>
|
|
48
|
+
initializer: (props: {
|
|
49
|
+
context: ITypiaContext;
|
|
50
|
+
importer: FunctionImporter;
|
|
51
|
+
type: ts.Type;
|
|
52
|
+
}) => [MetadataCollection, Metadata];
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
55
|
* Decoder, station of every types.
|
|
56
56
|
*/
|
|
57
|
-
decoder: (
|
|
57
|
+
decoder: (props: {
|
|
58
|
+
metadata: Metadata;
|
|
59
|
+
input: ts.Expression;
|
|
60
|
+
explore: IExplore;
|
|
61
|
+
}) => Output;
|
|
58
62
|
|
|
59
63
|
/**
|
|
60
64
|
* Object configurator.
|
|
@@ -76,12 +80,20 @@ export namespace FeatureProgrammer {
|
|
|
76
80
|
/**
|
|
77
81
|
* Type checker when union object type comes.
|
|
78
82
|
*/
|
|
79
|
-
checker: (
|
|
83
|
+
checker: (props: {
|
|
84
|
+
metadata: Metadata;
|
|
85
|
+
input: ts.Expression;
|
|
86
|
+
explore: IExplore;
|
|
87
|
+
}) => ts.Expression;
|
|
80
88
|
|
|
81
89
|
/**
|
|
82
90
|
* Decoder, function call expression generator of specific typed objects.
|
|
83
91
|
*/
|
|
84
|
-
decoder: (
|
|
92
|
+
decoder: (props: {
|
|
93
|
+
input: ts.Expression;
|
|
94
|
+
object: MetadataObject;
|
|
95
|
+
explore: IExplore;
|
|
96
|
+
}) => ts.Expression;
|
|
85
97
|
|
|
86
98
|
/**
|
|
87
99
|
* Joiner of expressions from properties.
|
|
@@ -98,21 +110,23 @@ export namespace FeatureProgrammer {
|
|
|
98
110
|
* Expression of an algorithm specifying object type and calling
|
|
99
111
|
* the `decoder` function of the specified object type.
|
|
100
112
|
*/
|
|
101
|
-
unionizer:
|
|
113
|
+
unionizer: (props: {
|
|
114
|
+
objects: MetadataObject[];
|
|
115
|
+
input: ts.Expression;
|
|
116
|
+
explore: IExplore;
|
|
117
|
+
}) => ts.Expression;
|
|
102
118
|
|
|
103
119
|
/**
|
|
104
120
|
* Handler of union type specification failure.
|
|
105
121
|
*
|
|
106
|
-
* @param
|
|
107
|
-
* @param expected Expected type name
|
|
108
|
-
* @param explore Exploration info
|
|
122
|
+
* @param props Properties of failure
|
|
109
123
|
* @returns Statement of failure
|
|
110
124
|
*/
|
|
111
|
-
failure(
|
|
112
|
-
|
|
113
|
-
expected: string
|
|
114
|
-
explore?: undefined | IExplore
|
|
115
|
-
): ts.Statement;
|
|
125
|
+
failure(props: {
|
|
126
|
+
input: ts.Expression;
|
|
127
|
+
expected: string;
|
|
128
|
+
explore?: undefined | IExplore;
|
|
129
|
+
}): ts.Statement;
|
|
116
130
|
|
|
117
131
|
/**
|
|
118
132
|
* Transformer of type checking expression by discrimination.
|
|
@@ -153,18 +167,17 @@ export namespace FeatureProgrammer {
|
|
|
153
167
|
* iteration type checking would be happend. In such circumstance, you
|
|
154
168
|
* can wrap the condition with additional function.
|
|
155
169
|
*
|
|
156
|
-
* @param
|
|
157
|
-
* @returns
|
|
170
|
+
* @param props Properties of condition
|
|
171
|
+
* @returns The wrapper expression
|
|
158
172
|
*/
|
|
159
173
|
full?:
|
|
160
174
|
| undefined
|
|
161
|
-
| ((
|
|
162
|
-
condition: ts.Expression
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
) => ts.Expression);
|
|
175
|
+
| ((props: {
|
|
176
|
+
condition: ts.Expression;
|
|
177
|
+
input: ts.Expression;
|
|
178
|
+
expected: string;
|
|
179
|
+
explore: IExplore;
|
|
180
|
+
}) => ts.Expression);
|
|
168
181
|
|
|
169
182
|
/**
|
|
170
183
|
* Return type.
|
|
@@ -174,12 +187,12 @@ export namespace FeatureProgrammer {
|
|
|
174
187
|
export interface IGenerator {
|
|
175
188
|
objects?:
|
|
176
189
|
| undefined
|
|
177
|
-
| ((
|
|
190
|
+
| ((collection: MetadataCollection) => ts.VariableStatement[]);
|
|
178
191
|
unions?:
|
|
179
192
|
| undefined
|
|
180
|
-
| ((
|
|
181
|
-
arrays
|
|
182
|
-
tuples
|
|
193
|
+
| ((collection: MetadataCollection) => ts.VariableStatement[]);
|
|
194
|
+
arrays: (collection: MetadataCollection) => ts.VariableStatement[];
|
|
195
|
+
tuples: (collection: MetadataCollection) => ts.VariableStatement[];
|
|
183
196
|
}
|
|
184
197
|
}
|
|
185
198
|
|
|
@@ -191,9 +204,14 @@ export namespace FeatureProgrammer {
|
|
|
191
204
|
start?: undefined | number;
|
|
192
205
|
}
|
|
193
206
|
|
|
194
|
-
export
|
|
195
|
-
|
|
196
|
-
|
|
207
|
+
export type Decoder<
|
|
208
|
+
T,
|
|
209
|
+
Output extends ts.ConciseBody = ts.ConciseBody,
|
|
210
|
+
> = (props: {
|
|
211
|
+
input: ts.Expression;
|
|
212
|
+
definition: T;
|
|
213
|
+
explore: IExplore;
|
|
214
|
+
}) => Output;
|
|
197
215
|
|
|
198
216
|
/* -----------------------------------------------------------
|
|
199
217
|
GENERATORS
|
|
@@ -218,15 +236,17 @@ export namespace FeatureProgrammer {
|
|
|
218
236
|
type: ts.Type;
|
|
219
237
|
name: string | undefined;
|
|
220
238
|
}): IComposed => {
|
|
221
|
-
const [collection,
|
|
222
|
-
props.importer,
|
|
223
|
-
)(props.type);
|
|
239
|
+
const [collection, metadata] = props.config.initializer(props);
|
|
224
240
|
return {
|
|
225
|
-
body: props.config.decoder(
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
241
|
+
body: props.config.decoder({
|
|
242
|
+
input: ValueFactory.INPUT(),
|
|
243
|
+
metadata,
|
|
244
|
+
explore: {
|
|
245
|
+
tracable: props.config.path || props.config.trace,
|
|
246
|
+
source: "top",
|
|
247
|
+
from: "top",
|
|
248
|
+
postfix: '""',
|
|
249
|
+
},
|
|
230
250
|
}),
|
|
231
251
|
statements: props.config.addition
|
|
232
252
|
? props.config.addition(collection)
|
|
@@ -234,7 +254,7 @@ export namespace FeatureProgrammer {
|
|
|
234
254
|
functions: {
|
|
235
255
|
...Object.fromEntries(
|
|
236
256
|
(
|
|
237
|
-
props.config.generator.objects?.(
|
|
257
|
+
props.config.generator.objects?.(collection) ??
|
|
238
258
|
write_object_functions({
|
|
239
259
|
...props,
|
|
240
260
|
collection,
|
|
@@ -243,24 +263,29 @@ export namespace FeatureProgrammer {
|
|
|
243
263
|
),
|
|
244
264
|
...Object.fromEntries(
|
|
245
265
|
(
|
|
246
|
-
props.config.generator.unions?.() ??
|
|
247
|
-
write_union_functions(
|
|
248
|
-
|
|
266
|
+
props.config.generator.unions?.(collection) ??
|
|
267
|
+
write_union_functions({
|
|
268
|
+
config: props.config,
|
|
269
|
+
collection,
|
|
270
|
+
})
|
|
271
|
+
).map((v, i) => [`${props.config.prefix}u${i}`, v]),
|
|
249
272
|
),
|
|
250
273
|
...Object.fromEntries(
|
|
251
274
|
props.config.generator
|
|
252
|
-
.arrays(
|
|
275
|
+
.arrays(collection)
|
|
253
276
|
.map((v, i) => [`${props.config.prefix}a${i}`, v]),
|
|
254
277
|
),
|
|
255
278
|
...Object.fromEntries(
|
|
256
279
|
props.config.generator
|
|
257
|
-
.tuples(
|
|
280
|
+
.tuples(collection)
|
|
258
281
|
.map((v, i) => [`${props.config.prefix}t${i}`, v]),
|
|
259
282
|
),
|
|
260
283
|
},
|
|
261
|
-
parameters: parameterDeclarations(
|
|
262
|
-
|
|
263
|
-
|
|
284
|
+
parameters: parameterDeclarations({
|
|
285
|
+
config: props.config,
|
|
286
|
+
type: props.config.types.input(props.type, props.name),
|
|
287
|
+
input: ValueFactory.INPUT(),
|
|
288
|
+
}),
|
|
264
289
|
response: props.config.types.output(props.type, props.name),
|
|
265
290
|
};
|
|
266
291
|
};
|
|
@@ -290,73 +315,81 @@ export namespace FeatureProgrammer {
|
|
|
290
315
|
undefined,
|
|
291
316
|
);
|
|
292
317
|
|
|
293
|
-
export const write =
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}),
|
|
321
|
-
unions: (config.generator.unions?.() ?? write_union_functions(config))(
|
|
318
|
+
export const write = (props: {
|
|
319
|
+
context: ITypiaContext;
|
|
320
|
+
config: IConfig;
|
|
321
|
+
importer: FunctionImporter;
|
|
322
|
+
type: ts.Type;
|
|
323
|
+
name?: string | undefined;
|
|
324
|
+
}): ts.ArrowFunction => {
|
|
325
|
+
// ITERATE OVER ALL METADATA
|
|
326
|
+
const [collection, metadata] = props.config.initializer(props);
|
|
327
|
+
const output: ts.ConciseBody = props.config.decoder({
|
|
328
|
+
metadata,
|
|
329
|
+
input: ValueFactory.INPUT(),
|
|
330
|
+
explore: {
|
|
331
|
+
tracable: props.config.path || props.config.trace,
|
|
332
|
+
source: "top",
|
|
333
|
+
from: "top",
|
|
334
|
+
postfix: '""',
|
|
335
|
+
},
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
// RETURNS THE OPTIMAL ARROW FUNCTION
|
|
339
|
+
const functions = {
|
|
340
|
+
objects:
|
|
341
|
+
props.config.generator.objects?.(collection) ??
|
|
342
|
+
write_object_functions({
|
|
343
|
+
config: props.config,
|
|
344
|
+
importer: props.importer,
|
|
322
345
|
collection,
|
|
323
|
-
),
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
parameterDeclarations(config)(config.types.input(type, name))(
|
|
333
|
-
ValueFactory.INPUT(),
|
|
334
|
-
),
|
|
335
|
-
config.types.output(type, name),
|
|
336
|
-
undefined,
|
|
337
|
-
ts.factory.createBlock(
|
|
338
|
-
[
|
|
339
|
-
...added,
|
|
340
|
-
...functions.objects.filter((_, i) =>
|
|
341
|
-
importer.hasLocal(`${config.prefix}o${i}`),
|
|
342
|
-
),
|
|
343
|
-
...functions.unions.filter((_, i) =>
|
|
344
|
-
importer.hasLocal(`${config.prefix}u${i}`),
|
|
345
|
-
),
|
|
346
|
-
...functions.arrays.filter((_, i) =>
|
|
347
|
-
importer.hasLocal(`${config.prefix}a${i}`),
|
|
348
|
-
),
|
|
349
|
-
...functions.tuples.filter((_, i) =>
|
|
350
|
-
importer.hasLocal(`${config.prefix}t${i}`),
|
|
351
|
-
),
|
|
352
|
-
...(ts.isBlock(output)
|
|
353
|
-
? output.statements
|
|
354
|
-
: [ts.factory.createReturnStatement(output)]),
|
|
355
|
-
],
|
|
356
|
-
true,
|
|
357
|
-
),
|
|
358
|
-
);
|
|
346
|
+
}),
|
|
347
|
+
unions:
|
|
348
|
+
props.config.generator.unions?.(collection) ??
|
|
349
|
+
write_union_functions({
|
|
350
|
+
config: props.config,
|
|
351
|
+
collection,
|
|
352
|
+
}),
|
|
353
|
+
arrays: props.config.generator.arrays(collection),
|
|
354
|
+
tuples: props.config.generator.tuples(collection),
|
|
359
355
|
};
|
|
356
|
+
const added: ts.Statement[] = (props.config.addition ?? (() => []))(
|
|
357
|
+
collection,
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
return ts.factory.createArrowFunction(
|
|
361
|
+
undefined,
|
|
362
|
+
undefined,
|
|
363
|
+
parameterDeclarations({
|
|
364
|
+
config: props.config,
|
|
365
|
+
type: props.config.types.input(props.type, props.name),
|
|
366
|
+
input: ValueFactory.INPUT(),
|
|
367
|
+
}),
|
|
368
|
+
props.config.types.output(props.type, props.name),
|
|
369
|
+
undefined,
|
|
370
|
+
ts.factory.createBlock(
|
|
371
|
+
[
|
|
372
|
+
...added,
|
|
373
|
+
...functions.objects.filter((_, i) =>
|
|
374
|
+
props.importer.hasLocal(`${props.config.prefix}o${i}`),
|
|
375
|
+
),
|
|
376
|
+
...functions.unions.filter((_, i) =>
|
|
377
|
+
props.importer.hasLocal(`${props.config.prefix}u${i}`),
|
|
378
|
+
),
|
|
379
|
+
...functions.arrays.filter((_, i) =>
|
|
380
|
+
props.importer.hasLocal(`${props.config.prefix}a${i}`),
|
|
381
|
+
),
|
|
382
|
+
...functions.tuples.filter((_, i) =>
|
|
383
|
+
props.importer.hasLocal(`${props.config.prefix}t${i}`),
|
|
384
|
+
),
|
|
385
|
+
...(ts.isBlock(output)
|
|
386
|
+
? output.statements
|
|
387
|
+
: [ts.factory.createReturnStatement(output)]),
|
|
388
|
+
],
|
|
389
|
+
true,
|
|
390
|
+
),
|
|
391
|
+
);
|
|
392
|
+
};
|
|
360
393
|
|
|
361
394
|
export const write_object_functions = (props: {
|
|
362
395
|
config: IConfig;
|
|
@@ -369,9 +402,11 @@ export namespace FeatureProgrammer {
|
|
|
369
402
|
ts.factory.createArrowFunction(
|
|
370
403
|
undefined,
|
|
371
404
|
undefined,
|
|
372
|
-
parameterDeclarations(
|
|
373
|
-
|
|
374
|
-
|
|
405
|
+
parameterDeclarations({
|
|
406
|
+
config: props.config,
|
|
407
|
+
type: TypeFactory.keyword("any"),
|
|
408
|
+
input: ValueFactory.INPUT(),
|
|
409
|
+
}),
|
|
375
410
|
props.config.objector.type ?? TypeFactory.keyword("any"),
|
|
376
411
|
undefined,
|
|
377
412
|
props.config.objector.joiner({
|
|
@@ -385,172 +420,195 @@ export namespace FeatureProgrammer {
|
|
|
385
420
|
),
|
|
386
421
|
);
|
|
387
422
|
|
|
388
|
-
export const write_union_functions =
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
423
|
+
export const write_union_functions = (props: {
|
|
424
|
+
config: IConfig;
|
|
425
|
+
collection: MetadataCollection;
|
|
426
|
+
}) =>
|
|
427
|
+
props.collection.unions().map((union, i) =>
|
|
428
|
+
StatementFactory.constant(
|
|
429
|
+
`${props.config.prefix}u${i}`,
|
|
430
|
+
write_union({
|
|
431
|
+
config: props.config,
|
|
432
|
+
objects: union,
|
|
433
|
+
}),
|
|
434
|
+
),
|
|
435
|
+
);
|
|
398
436
|
|
|
399
|
-
const write_union = (
|
|
400
|
-
|
|
437
|
+
const write_union = (props: {
|
|
438
|
+
config: IConfig;
|
|
439
|
+
objects: MetadataObject[];
|
|
440
|
+
}) => {
|
|
441
|
+
const explorer = UnionExplorer.object(props.config);
|
|
401
442
|
const input = ValueFactory.INPUT();
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
443
|
+
return ts.factory.createArrowFunction(
|
|
444
|
+
undefined,
|
|
445
|
+
undefined,
|
|
446
|
+
parameterDeclarations({
|
|
447
|
+
config: props.config,
|
|
448
|
+
type: TypeFactory.keyword("any"),
|
|
449
|
+
input: ValueFactory.INPUT(),
|
|
450
|
+
}),
|
|
451
|
+
TypeFactory.keyword("any"),
|
|
452
|
+
undefined,
|
|
453
|
+
explorer(input, props.objects, {
|
|
454
|
+
tracable: props.config.path || props.config.trace,
|
|
455
|
+
source: "function",
|
|
456
|
+
from: "object",
|
|
457
|
+
postfix: "",
|
|
458
|
+
}),
|
|
459
|
+
);
|
|
419
460
|
};
|
|
420
461
|
|
|
421
462
|
/* -----------------------------------------------------------
|
|
422
463
|
DECODERS
|
|
423
464
|
----------------------------------------------------------- */
|
|
424
|
-
export const decode_array =
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
(
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
465
|
+
export const decode_array = (props: {
|
|
466
|
+
config: Pick<IConfig, "trace" | "path" | "decoder" | "prefix">;
|
|
467
|
+
importer: FunctionImporter;
|
|
468
|
+
combiner: (next: {
|
|
469
|
+
input: ts.Expression;
|
|
470
|
+
arrow: ts.ArrowFunction;
|
|
471
|
+
}) => ts.Expression;
|
|
472
|
+
array: MetadataArray;
|
|
473
|
+
input: ts.Expression;
|
|
474
|
+
explore: IExplore;
|
|
475
|
+
}) => {
|
|
476
|
+
const rand: string = props.importer.increment().toString();
|
|
477
|
+
const tail =
|
|
478
|
+
props.config.path || props.config.trace
|
|
479
|
+
? [
|
|
480
|
+
IdentifierFactory.parameter(
|
|
481
|
+
"_index" + rand,
|
|
482
|
+
TypeFactory.keyword("number"),
|
|
483
|
+
),
|
|
484
|
+
]
|
|
485
|
+
: [];
|
|
486
|
+
const arrow: ts.ArrowFunction = ts.factory.createArrowFunction(
|
|
487
|
+
undefined,
|
|
488
|
+
undefined,
|
|
489
|
+
[
|
|
490
|
+
IdentifierFactory.parameter("elem", TypeFactory.keyword("any")),
|
|
491
|
+
...tail,
|
|
492
|
+
],
|
|
493
|
+
undefined,
|
|
494
|
+
undefined,
|
|
495
|
+
props.config.decoder({
|
|
496
|
+
input: ValueFactory.INPUT("elem"),
|
|
497
|
+
metadata: props.array.type.value,
|
|
498
|
+
explore: {
|
|
499
|
+
tracable: props.explore.tracable,
|
|
500
|
+
source: props.explore.source,
|
|
501
|
+
from: "array",
|
|
502
|
+
postfix: index({
|
|
503
|
+
start: props.explore.start ?? null,
|
|
504
|
+
postfix: props.explore.postfix,
|
|
505
|
+
rand,
|
|
462
506
|
}),
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
};
|
|
507
|
+
},
|
|
508
|
+
}),
|
|
509
|
+
);
|
|
510
|
+
return props.combiner({
|
|
511
|
+
input: props.input,
|
|
512
|
+
arrow,
|
|
513
|
+
});
|
|
514
|
+
};
|
|
470
515
|
|
|
471
|
-
export const decode_object =
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
)
|
|
516
|
+
export const decode_object = (props: {
|
|
517
|
+
config: Pick<IConfig, "trace" | "path" | "prefix">;
|
|
518
|
+
importer: FunctionImporter;
|
|
519
|
+
object: MetadataObject;
|
|
520
|
+
input: ts.Expression;
|
|
521
|
+
explore: IExplore;
|
|
522
|
+
}) =>
|
|
523
|
+
ts.factory.createCallExpression(
|
|
524
|
+
ts.factory.createIdentifier(
|
|
525
|
+
props.importer.useLocal(`${props.config.prefix}o${props.object.index}`),
|
|
526
|
+
),
|
|
527
|
+
undefined,
|
|
528
|
+
argumentsArray(props),
|
|
529
|
+
);
|
|
482
530
|
|
|
483
531
|
/* -----------------------------------------------------------
|
|
484
532
|
UTILITIES FOR INTERNAL FUNCTIONS
|
|
485
533
|
----------------------------------------------------------- */
|
|
486
|
-
export const index =
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
534
|
+
export const index = (props: {
|
|
535
|
+
start: number | null;
|
|
536
|
+
postfix: string;
|
|
537
|
+
rand: string;
|
|
538
|
+
}) => {
|
|
539
|
+
const tail: string =
|
|
540
|
+
props.start !== null
|
|
541
|
+
? `"[" + (${props.start} + _index${props.rand}) + "]"`
|
|
542
|
+
: `"[" + _index${props.rand} + "]"`;
|
|
543
|
+
if (props.postfix === "") return tail;
|
|
544
|
+
else if (props.postfix[props.postfix.length - 1] === `"`)
|
|
545
|
+
return (
|
|
546
|
+
props.postfix.substring(0, props.postfix.length - 1) + tail.substring(1)
|
|
547
|
+
);
|
|
548
|
+
return props.postfix + ` + ${tail}`;
|
|
549
|
+
};
|
|
497
550
|
|
|
498
|
-
export const argumentsArray =
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
551
|
+
export const argumentsArray = (props: {
|
|
552
|
+
config: Pick<IConfig, "path" | "trace">;
|
|
553
|
+
input: ts.Expression;
|
|
554
|
+
explore: FeatureProgrammer.IExplore;
|
|
555
|
+
}) => {
|
|
556
|
+
const tail: ts.Expression[] =
|
|
557
|
+
props.config.path === false && props.config.trace === false
|
|
558
|
+
? []
|
|
559
|
+
: props.config.path === true && props.config.trace === true
|
|
560
|
+
? [
|
|
561
|
+
ts.factory.createIdentifier(
|
|
562
|
+
props.explore.postfix
|
|
563
|
+
? `_path + ${props.explore.postfix}`
|
|
564
|
+
: "_path",
|
|
565
|
+
),
|
|
566
|
+
props.explore.source === "function"
|
|
567
|
+
? ts.factory.createIdentifier(
|
|
568
|
+
`${props.explore.tracable} && _exceptionable`,
|
|
569
|
+
)
|
|
570
|
+
: props.explore.tracable
|
|
571
|
+
? ts.factory.createTrue()
|
|
572
|
+
: ts.factory.createFalse(),
|
|
573
|
+
]
|
|
574
|
+
: props.config.path === true
|
|
505
575
|
? [
|
|
506
576
|
ts.factory.createIdentifier(
|
|
507
|
-
|
|
577
|
+
props.explore.postfix
|
|
578
|
+
? `_path + ${props.explore.postfix}`
|
|
579
|
+
: "_path",
|
|
508
580
|
),
|
|
509
|
-
|
|
581
|
+
]
|
|
582
|
+
: [
|
|
583
|
+
props.explore.source === "function"
|
|
510
584
|
? ts.factory.createIdentifier(
|
|
511
|
-
`${explore.tracable} && _exceptionable`,
|
|
585
|
+
`${props.explore.tracable} && _exceptionable`,
|
|
512
586
|
)
|
|
513
|
-
: explore.tracable
|
|
587
|
+
: props.explore.tracable
|
|
514
588
|
? ts.factory.createTrue()
|
|
515
589
|
: ts.factory.createFalse(),
|
|
516
|
-
]
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
ts.factory.createIdentifier(
|
|
520
|
-
explore.postfix ? `_path + ${explore.postfix}` : "_path",
|
|
521
|
-
),
|
|
522
|
-
]
|
|
523
|
-
: [
|
|
524
|
-
explore.source === "function"
|
|
525
|
-
? ts.factory.createIdentifier(
|
|
526
|
-
`${explore.tracable} && _exceptionable`,
|
|
527
|
-
)
|
|
528
|
-
: explore.tracable
|
|
529
|
-
? ts.factory.createTrue()
|
|
530
|
-
: ts.factory.createFalse(),
|
|
531
|
-
];
|
|
532
|
-
return (input: ts.Expression) => [input, ...tail];
|
|
533
|
-
};
|
|
590
|
+
];
|
|
591
|
+
return [props.input, ...tail];
|
|
592
|
+
};
|
|
534
593
|
|
|
535
|
-
export const parameterDeclarations =
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
),
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
};
|
|
594
|
+
export const parameterDeclarations = (props: {
|
|
595
|
+
config: Pick<CheckerProgrammer.IConfig, "path" | "trace">;
|
|
596
|
+
type: ts.TypeNode;
|
|
597
|
+
input: ts.Identifier;
|
|
598
|
+
}) => {
|
|
599
|
+
const tail: ts.ParameterDeclaration[] = [];
|
|
600
|
+
if (props.config.path)
|
|
601
|
+
tail.push(
|
|
602
|
+
IdentifierFactory.parameter("_path", TypeFactory.keyword("string")),
|
|
603
|
+
);
|
|
604
|
+
if (props.config.trace)
|
|
605
|
+
tail.push(
|
|
606
|
+
IdentifierFactory.parameter(
|
|
607
|
+
"_exceptionable",
|
|
608
|
+
TypeFactory.keyword("boolean"),
|
|
609
|
+
ts.factory.createTrue(),
|
|
610
|
+
),
|
|
611
|
+
);
|
|
612
|
+
return [IdentifierFactory.parameter(props.input, props.type), ...tail];
|
|
613
|
+
};
|
|
556
614
|
}
|