typia 7.0.0-dev.20240920 → 7.0.0-dev.20240922
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/programmers/RandomProgrammer.js +557 -493
- package/lib/programmers/RandomProgrammer.js.map +1 -1
- package/lib/programmers/helpers/RandomJoiner.d.ts +17 -3
- package/lib/programmers/helpers/RandomJoiner.js +53 -63
- package/lib/programmers/helpers/RandomJoiner.js.map +1 -1
- package/lib/programmers/helpers/RandomRanger.d.ts +11 -2
- package/lib/programmers/helpers/RandomRanger.js +134 -113
- package/lib/programmers/helpers/RandomRanger.js.map +1 -1
- package/lib/programmers/helpers/StringifyJoinder.d.ts +2 -1
- package/lib/programmers/helpers/StringifyJoinder.js +27 -31
- package/lib/programmers/helpers/StringifyJoinder.js.map +1 -1
- package/lib/programmers/json/JsonStringifyProgrammer.js +33 -27
- package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js +355 -369
- package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js +264 -239
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js +424 -368
- package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufMessageProgrammer.js +106 -85
- package/lib/programmers/protobuf/ProtobufMessageProgrammer.js.map +1 -1
- package/package.json +1 -1
- package/src/programmers/RandomProgrammer.ts +758 -595
- package/src/programmers/helpers/RandomJoiner.ts +121 -110
- package/src/programmers/helpers/RandomRanger.ts +160 -113
- package/src/programmers/helpers/StringifyJoinder.ts +45 -43
- package/src/programmers/json/JsonStringifyProgrammer.ts +67 -58
- package/src/programmers/notations/NotationGeneralProgrammer.ts +610 -528
- package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +421 -358
- package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +752 -613
- package/src/programmers/protobuf/ProtobufMessageProgrammer.ts +96 -63
|
@@ -75,18 +75,18 @@ export namespace RandomProgrammer {
|
|
|
75
75
|
|
|
76
76
|
// GENERATE FUNCTION
|
|
77
77
|
const functions: Record<string, ts.VariableStatement> = Object.fromEntries([
|
|
78
|
-
...write_object_functions(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
]),
|
|
82
|
-
...write_array_functions(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
]),
|
|
86
|
-
...write_tuple_functions(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
]),
|
|
78
|
+
...write_object_functions({
|
|
79
|
+
importer: props.importer,
|
|
80
|
+
collection,
|
|
81
|
+
}).map((v, i) => [Prefix.object(i), v]),
|
|
82
|
+
...write_array_functions({
|
|
83
|
+
importer: props.importer,
|
|
84
|
+
collection,
|
|
85
|
+
}).map((v, i) => [Prefix.array(i), v]),
|
|
86
|
+
...write_tuple_functions({
|
|
87
|
+
importer: props.importer,
|
|
88
|
+
collection,
|
|
89
|
+
}).map((v, i) => [Prefix.tuple(i), v]),
|
|
90
90
|
]);
|
|
91
91
|
const arrow: ts.ArrowFunction = ts.factory.createArrowFunction(
|
|
92
92
|
undefined,
|
|
@@ -123,10 +123,14 @@ export namespace RandomProgrammer {
|
|
|
123
123
|
),
|
|
124
124
|
),
|
|
125
125
|
ts.factory.createReturnStatement(
|
|
126
|
-
decode(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
126
|
+
decode({
|
|
127
|
+
importer: props.importer,
|
|
128
|
+
explore: {
|
|
129
|
+
function: false,
|
|
130
|
+
recursive: false,
|
|
131
|
+
},
|
|
132
|
+
metadata: result.data,
|
|
133
|
+
}),
|
|
130
134
|
),
|
|
131
135
|
],
|
|
132
136
|
true,
|
|
@@ -154,20 +158,73 @@ export namespace RandomProgrammer {
|
|
|
154
158
|
});
|
|
155
159
|
};
|
|
156
160
|
|
|
157
|
-
const write_object_functions =
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
+
const write_object_functions = (props: {
|
|
162
|
+
importer: FunctionImporter;
|
|
163
|
+
collection: MetadataCollection;
|
|
164
|
+
}): ts.VariableStatement[] =>
|
|
165
|
+
props.collection.objects().map((obj, i) =>
|
|
166
|
+
StatementFactory.constant(
|
|
167
|
+
Prefix.object(i),
|
|
168
|
+
ts.factory.createArrowFunction(
|
|
169
|
+
undefined,
|
|
170
|
+
undefined,
|
|
171
|
+
[
|
|
172
|
+
IdentifierFactory.parameter(
|
|
173
|
+
"_recursive",
|
|
174
|
+
TypeFactory.keyword("boolean"),
|
|
175
|
+
ts.factory.createIdentifier(String(obj.recursive)),
|
|
176
|
+
),
|
|
177
|
+
IdentifierFactory.parameter(
|
|
178
|
+
"_depth",
|
|
179
|
+
TypeFactory.keyword("number"),
|
|
180
|
+
ExpressionFactory.number(0),
|
|
181
|
+
),
|
|
182
|
+
],
|
|
183
|
+
TypeFactory.keyword("any"),
|
|
184
|
+
undefined,
|
|
185
|
+
RandomJoiner.object({
|
|
186
|
+
coalesce: coalesce(props.importer),
|
|
187
|
+
decode: (metadata) =>
|
|
188
|
+
decode({
|
|
189
|
+
importer: props.importer,
|
|
190
|
+
explore: {
|
|
191
|
+
recursive: obj.recursive,
|
|
192
|
+
function: true,
|
|
193
|
+
},
|
|
194
|
+
metadata,
|
|
195
|
+
}),
|
|
196
|
+
object: obj,
|
|
197
|
+
}),
|
|
198
|
+
),
|
|
199
|
+
),
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
const write_array_functions = (props: {
|
|
203
|
+
importer: FunctionImporter;
|
|
204
|
+
collection: MetadataCollection;
|
|
205
|
+
}): ts.VariableStatement[] =>
|
|
206
|
+
props.collection
|
|
207
|
+
.arrays()
|
|
208
|
+
.filter((a) => a.recursive)
|
|
209
|
+
.map((array, i) =>
|
|
161
210
|
StatementFactory.constant(
|
|
162
|
-
Prefix.
|
|
211
|
+
Prefix.array(i),
|
|
163
212
|
ts.factory.createArrowFunction(
|
|
164
213
|
undefined,
|
|
165
214
|
undefined,
|
|
166
215
|
[
|
|
216
|
+
IdentifierFactory.parameter(
|
|
217
|
+
"length",
|
|
218
|
+
TypeFactory.keyword("number"),
|
|
219
|
+
),
|
|
220
|
+
IdentifierFactory.parameter(
|
|
221
|
+
"unique",
|
|
222
|
+
TypeFactory.keyword("boolean"),
|
|
223
|
+
),
|
|
167
224
|
IdentifierFactory.parameter(
|
|
168
225
|
"_recursive",
|
|
169
226
|
TypeFactory.keyword("boolean"),
|
|
170
|
-
ts.factory.
|
|
227
|
+
ts.factory.createTrue(),
|
|
171
228
|
),
|
|
172
229
|
IdentifierFactory.parameter(
|
|
173
230
|
"_depth",
|
|
@@ -177,178 +234,208 @@ export namespace RandomProgrammer {
|
|
|
177
234
|
],
|
|
178
235
|
TypeFactory.keyword("any"),
|
|
179
236
|
undefined,
|
|
180
|
-
RandomJoiner.
|
|
181
|
-
|
|
182
|
-
|
|
237
|
+
RandomJoiner.array({
|
|
238
|
+
coalesce: coalesce(props.importer),
|
|
239
|
+
decode: (metadata) =>
|
|
240
|
+
decode({
|
|
241
|
+
importer: props.importer,
|
|
242
|
+
explore: {
|
|
243
|
+
recursive: true,
|
|
244
|
+
function: true,
|
|
245
|
+
},
|
|
246
|
+
metadata,
|
|
247
|
+
}),
|
|
248
|
+
explore: {
|
|
249
|
+
recursive: true,
|
|
183
250
|
function: true,
|
|
184
|
-
}
|
|
185
|
-
|
|
251
|
+
},
|
|
252
|
+
length: ts.factory.createIdentifier("length"),
|
|
253
|
+
unique: ts.factory.createIdentifier("unique"),
|
|
254
|
+
metadata: array.value,
|
|
255
|
+
}),
|
|
186
256
|
),
|
|
187
257
|
),
|
|
188
258
|
);
|
|
189
259
|
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
),
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
recursive: true,
|
|
227
|
-
function: true,
|
|
260
|
+
const write_tuple_functions = (props: {
|
|
261
|
+
importer: FunctionImporter;
|
|
262
|
+
collection: MetadataCollection;
|
|
263
|
+
}): ts.VariableStatement[] =>
|
|
264
|
+
props.collection
|
|
265
|
+
.tuples()
|
|
266
|
+
.filter((a) => a.recursive)
|
|
267
|
+
.map((tuple, i) =>
|
|
268
|
+
StatementFactory.constant(
|
|
269
|
+
Prefix.tuple(i),
|
|
270
|
+
ts.factory.createArrowFunction(
|
|
271
|
+
undefined,
|
|
272
|
+
undefined,
|
|
273
|
+
[
|
|
274
|
+
IdentifierFactory.parameter(
|
|
275
|
+
"_recursive",
|
|
276
|
+
TypeFactory.keyword("boolean"),
|
|
277
|
+
ts.factory.createTrue(),
|
|
278
|
+
),
|
|
279
|
+
IdentifierFactory.parameter(
|
|
280
|
+
"_depth",
|
|
281
|
+
TypeFactory.keyword("number"),
|
|
282
|
+
ExpressionFactory.number(0),
|
|
283
|
+
),
|
|
284
|
+
],
|
|
285
|
+
TypeFactory.keyword("any"),
|
|
286
|
+
undefined,
|
|
287
|
+
RandomJoiner.tuple({
|
|
288
|
+
decode: (metadata) =>
|
|
289
|
+
decode({
|
|
290
|
+
importer: props.importer,
|
|
291
|
+
explore: {
|
|
292
|
+
function: true,
|
|
293
|
+
recursive: true,
|
|
294
|
+
},
|
|
295
|
+
metadata,
|
|
228
296
|
}),
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
function: true,
|
|
232
|
-
})(
|
|
233
|
-
ts.factory.createIdentifier("length"),
|
|
234
|
-
ts.factory.createIdentifier("unique"),
|
|
235
|
-
)(array.value),
|
|
236
|
-
),
|
|
297
|
+
elements: tuple.elements,
|
|
298
|
+
}),
|
|
237
299
|
),
|
|
300
|
+
),
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
/* -----------------------------------------------------------
|
|
304
|
+
DECODERS
|
|
305
|
+
----------------------------------------------------------- */
|
|
306
|
+
const decode = (props: {
|
|
307
|
+
importer: FunctionImporter;
|
|
308
|
+
explore: IExplore;
|
|
309
|
+
metadata: Metadata;
|
|
310
|
+
}): ts.Expression => {
|
|
311
|
+
const expressions: ts.Expression[] = [];
|
|
312
|
+
if (props.metadata.any === true)
|
|
313
|
+
expressions.push(ts.factory.createStringLiteral("any type used..."));
|
|
314
|
+
|
|
315
|
+
// NULL COALESCING
|
|
316
|
+
if (
|
|
317
|
+
props.metadata.isRequired() === false ||
|
|
318
|
+
props.metadata.functions.length !== 0
|
|
319
|
+
)
|
|
320
|
+
expressions.push(ts.factory.createIdentifier("undefined"));
|
|
321
|
+
if (props.metadata.nullable === true)
|
|
322
|
+
expressions.push(ts.factory.createNull());
|
|
323
|
+
|
|
324
|
+
// CONSTANT TYPES
|
|
325
|
+
for (const constant of props.metadata.constants)
|
|
326
|
+
for (const { value } of constant.values)
|
|
327
|
+
expressions.push(decode_atomic(value));
|
|
328
|
+
|
|
329
|
+
// ATOMIC VARIABLES
|
|
330
|
+
for (const template of props.metadata.templates)
|
|
331
|
+
expressions.push(
|
|
332
|
+
decode_template({
|
|
333
|
+
...props,
|
|
334
|
+
template,
|
|
335
|
+
}),
|
|
336
|
+
);
|
|
337
|
+
for (const atomic of props.metadata.atomics)
|
|
338
|
+
if (atomic.type === "boolean")
|
|
339
|
+
expressions.push(decode_boolean(props.importer));
|
|
340
|
+
else if (atomic.type === "number")
|
|
341
|
+
expressions.push(
|
|
342
|
+
...decode_number({
|
|
343
|
+
importer: props.importer,
|
|
344
|
+
atomic,
|
|
345
|
+
}),
|
|
346
|
+
);
|
|
347
|
+
else if (atomic.type === "string")
|
|
348
|
+
expressions.push(
|
|
349
|
+
...decode_string({
|
|
350
|
+
importer: props.importer,
|
|
351
|
+
atomic,
|
|
352
|
+
}),
|
|
353
|
+
);
|
|
354
|
+
else if (atomic.type === "bigint")
|
|
355
|
+
expressions.push(
|
|
356
|
+
...decode_bigint({
|
|
357
|
+
importer: props.importer,
|
|
358
|
+
atomic,
|
|
359
|
+
}),
|
|
238
360
|
);
|
|
239
361
|
|
|
240
|
-
|
|
241
|
-
(
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
362
|
+
// INSTANCE TYPES
|
|
363
|
+
if (props.metadata.escaped)
|
|
364
|
+
expressions.push(
|
|
365
|
+
decode({
|
|
366
|
+
...props,
|
|
367
|
+
metadata: props.metadata.escaped.returns,
|
|
368
|
+
}),
|
|
369
|
+
);
|
|
370
|
+
for (const array of props.metadata.arrays)
|
|
371
|
+
expressions.push(
|
|
372
|
+
...decode_array({
|
|
373
|
+
...props,
|
|
374
|
+
array,
|
|
375
|
+
}),
|
|
376
|
+
);
|
|
377
|
+
for (const tuple of props.metadata.tuples)
|
|
378
|
+
expressions.push(
|
|
379
|
+
decode_tuple({
|
|
380
|
+
...props,
|
|
381
|
+
tuple,
|
|
382
|
+
}),
|
|
383
|
+
);
|
|
384
|
+
for (const object of props.metadata.objects)
|
|
385
|
+
expressions.push(
|
|
386
|
+
decode_object({
|
|
387
|
+
...props,
|
|
388
|
+
object,
|
|
389
|
+
}),
|
|
390
|
+
);
|
|
391
|
+
for (const name of props.metadata.natives)
|
|
392
|
+
expressions.push(
|
|
393
|
+
decode_native({
|
|
394
|
+
importer: props.importer,
|
|
395
|
+
name,
|
|
396
|
+
}),
|
|
397
|
+
);
|
|
398
|
+
for (const metadata of props.metadata.sets)
|
|
399
|
+
expressions.push(
|
|
400
|
+
decode_set({
|
|
401
|
+
...props,
|
|
402
|
+
metadata,
|
|
403
|
+
}),
|
|
404
|
+
);
|
|
405
|
+
for (const entry of props.metadata.maps)
|
|
406
|
+
expressions.push(
|
|
407
|
+
decode_map({
|
|
408
|
+
...props,
|
|
409
|
+
entry,
|
|
410
|
+
}),
|
|
411
|
+
);
|
|
412
|
+
|
|
413
|
+
// PICK UP A TYPE
|
|
414
|
+
if (expressions.length === 1) return expressions[0]!;
|
|
415
|
+
return ts.factory.createCallExpression(
|
|
416
|
+
ts.factory.createCallExpression(props.importer.use("pick"), undefined, [
|
|
417
|
+
ts.factory.createArrayLiteralExpression(
|
|
418
|
+
expressions.map((expr) =>
|
|
249
419
|
ts.factory.createArrowFunction(
|
|
250
420
|
undefined,
|
|
251
421
|
undefined,
|
|
252
|
-
[
|
|
253
|
-
IdentifierFactory.parameter(
|
|
254
|
-
"_recursive",
|
|
255
|
-
TypeFactory.keyword("boolean"),
|
|
256
|
-
ts.factory.createTrue(),
|
|
257
|
-
),
|
|
258
|
-
IdentifierFactory.parameter(
|
|
259
|
-
"_depth",
|
|
260
|
-
TypeFactory.keyword("number"),
|
|
261
|
-
ExpressionFactory.number(0),
|
|
262
|
-
),
|
|
263
|
-
],
|
|
264
|
-
TypeFactory.keyword("any"),
|
|
422
|
+
[],
|
|
265
423
|
undefined,
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
function: true,
|
|
269
|
-
recursive: true,
|
|
270
|
-
}),
|
|
271
|
-
)(tuple.elements),
|
|
272
|
-
),
|
|
273
|
-
),
|
|
274
|
-
);
|
|
275
|
-
|
|
276
|
-
/* -----------------------------------------------------------
|
|
277
|
-
DECODERS
|
|
278
|
-
----------------------------------------------------------- */
|
|
279
|
-
const decode =
|
|
280
|
-
(importer: FunctionImporter) =>
|
|
281
|
-
(explore: IExplore) =>
|
|
282
|
-
(meta: Metadata): ts.Expression => {
|
|
283
|
-
const expressions: ts.Expression[] = [];
|
|
284
|
-
if (meta.any)
|
|
285
|
-
expressions.push(ts.factory.createStringLiteral("any type used..."));
|
|
286
|
-
|
|
287
|
-
// NULL COALESCING
|
|
288
|
-
if (meta.isRequired() === false || meta.functions.length)
|
|
289
|
-
expressions.push(ts.factory.createIdentifier("undefined"));
|
|
290
|
-
if (meta.nullable === true) expressions.push(ts.factory.createNull());
|
|
291
|
-
|
|
292
|
-
// CONSTANT TYPES
|
|
293
|
-
for (const constant of meta.constants)
|
|
294
|
-
for (const { value } of constant.values)
|
|
295
|
-
expressions.push(decode_atomic(value));
|
|
296
|
-
|
|
297
|
-
// ATOMIC VARIABLES
|
|
298
|
-
for (const template of meta.templates)
|
|
299
|
-
expressions.push(decode_template(importer)(explore)(template));
|
|
300
|
-
for (const atomic of meta.atomics)
|
|
301
|
-
if (atomic.type === "boolean")
|
|
302
|
-
expressions.push(decode_boolean(importer));
|
|
303
|
-
else if (atomic.type === "number")
|
|
304
|
-
expressions.push(...decode_number(importer)(atomic));
|
|
305
|
-
else if (atomic.type === "string")
|
|
306
|
-
expressions.push(...decode_string(importer)(atomic));
|
|
307
|
-
else if (atomic.type === "bigint")
|
|
308
|
-
expressions.push(...decode_bigint(importer)(atomic));
|
|
309
|
-
|
|
310
|
-
// INSTANCE TYPES
|
|
311
|
-
if (meta.escaped)
|
|
312
|
-
expressions.push(decode(importer)(explore)(meta.escaped.returns));
|
|
313
|
-
for (const array of meta.arrays)
|
|
314
|
-
expressions.push(...decode_array(importer)(explore)(array));
|
|
315
|
-
for (const tuple of meta.tuples)
|
|
316
|
-
expressions.push(decode_tuple(importer)(explore)(tuple));
|
|
317
|
-
for (const o of meta.objects)
|
|
318
|
-
expressions.push(decode_object(importer)(explore)(o));
|
|
319
|
-
for (const native of meta.natives)
|
|
320
|
-
expressions.push(decode_native(importer)(native));
|
|
321
|
-
for (const set of meta.sets)
|
|
322
|
-
expressions.push(decode_set(importer)(explore)(set));
|
|
323
|
-
for (const map of meta.maps)
|
|
324
|
-
expressions.push(decode_map(importer)(explore)(map));
|
|
325
|
-
|
|
326
|
-
// PICK UP A TYPE
|
|
327
|
-
if (expressions.length === 1) return expressions[0]!;
|
|
328
|
-
return ts.factory.createCallExpression(
|
|
329
|
-
ts.factory.createCallExpression(importer.use("pick"), undefined, [
|
|
330
|
-
ts.factory.createArrayLiteralExpression(
|
|
331
|
-
expressions.map((expr) =>
|
|
332
|
-
ts.factory.createArrowFunction(
|
|
333
|
-
undefined,
|
|
334
|
-
undefined,
|
|
335
|
-
[],
|
|
336
|
-
undefined,
|
|
337
|
-
undefined,
|
|
338
|
-
expr,
|
|
339
|
-
),
|
|
424
|
+
undefined,
|
|
425
|
+
expr,
|
|
340
426
|
),
|
|
341
|
-
true,
|
|
342
427
|
),
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
428
|
+
true,
|
|
429
|
+
),
|
|
430
|
+
]),
|
|
431
|
+
undefined,
|
|
432
|
+
undefined,
|
|
433
|
+
);
|
|
434
|
+
};
|
|
348
435
|
|
|
349
436
|
const decode_boolean = (importer: FunctionImporter) =>
|
|
350
437
|
ts.factory.createCallExpression(
|
|
351
|
-
|
|
438
|
+
coalesce(importer)("boolean"),
|
|
352
439
|
undefined,
|
|
353
440
|
undefined,
|
|
354
441
|
);
|
|
@@ -362,57 +449,70 @@ export namespace RandomProgrammer {
|
|
|
362
449
|
? ts.factory.createStringLiteral(value)
|
|
363
450
|
: ExpressionFactory.bigint(Number(value));
|
|
364
451
|
|
|
365
|
-
const decode_template =
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
)
|
|
452
|
+
const decode_template = (props: {
|
|
453
|
+
importer: FunctionImporter;
|
|
454
|
+
explore: IExplore;
|
|
455
|
+
template: MetadataTemplate;
|
|
456
|
+
}) =>
|
|
457
|
+
TemplateFactory.generate(
|
|
458
|
+
props.template.row.map((metadata) =>
|
|
459
|
+
decode({
|
|
460
|
+
...props,
|
|
461
|
+
metadata,
|
|
462
|
+
}),
|
|
463
|
+
),
|
|
464
|
+
);
|
|
372
465
|
|
|
373
|
-
const decode_number =
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
466
|
+
const decode_number = (props: {
|
|
467
|
+
importer: FunctionImporter;
|
|
468
|
+
atomic: MetadataAtomic;
|
|
469
|
+
}): ts.Expression[] =>
|
|
470
|
+
(props.atomic.tags.length ? props.atomic.tags : [[]]).map((tags) => {
|
|
471
|
+
const type = tags.find(
|
|
472
|
+
(t) =>
|
|
473
|
+
t.kind === "type" && (t.value === "int32" || t.value === "int64"),
|
|
474
|
+
)
|
|
475
|
+
? "int"
|
|
476
|
+
: tags.find(
|
|
477
|
+
(t) =>
|
|
478
|
+
t.kind === "type" &&
|
|
479
|
+
(t.value === "uint32" || t.value === "uint64"),
|
|
480
|
+
)
|
|
481
|
+
? "uint"
|
|
482
|
+
: "double";
|
|
483
|
+
const multiply = tags.find((t) => t.kind === "multipleOf");
|
|
484
|
+
return random_custom(coalesce(props.importer))("number")(tags)(
|
|
485
|
+
RandomRanger.number({
|
|
486
|
+
config: {
|
|
392
487
|
type,
|
|
393
488
|
transform: (value) => ExpressionFactory.number(value),
|
|
394
489
|
setter: (args) =>
|
|
395
490
|
ts.factory.createCallExpression(
|
|
396
491
|
type !== "double" || multiply !== undefined
|
|
397
|
-
?
|
|
398
|
-
:
|
|
492
|
+
? coalesce(props.importer)("integer")
|
|
493
|
+
: coalesce(props.importer)("number"),
|
|
399
494
|
undefined,
|
|
400
495
|
args.map((val) => ExpressionFactory.number(val)),
|
|
401
496
|
),
|
|
402
|
-
}
|
|
497
|
+
},
|
|
498
|
+
defaults: {
|
|
403
499
|
minimum: 0,
|
|
404
500
|
maximum: 100,
|
|
405
501
|
gap: 10,
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
|
|
502
|
+
},
|
|
503
|
+
tags,
|
|
504
|
+
}),
|
|
505
|
+
);
|
|
506
|
+
});
|
|
409
507
|
|
|
410
|
-
const decode_bigint =
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
508
|
+
const decode_bigint = (props: {
|
|
509
|
+
importer: FunctionImporter;
|
|
510
|
+
atomic: MetadataAtomic;
|
|
511
|
+
}): ts.Expression[] =>
|
|
512
|
+
(props.atomic.tags.length ? props.atomic.tags : [[]]).map((tags) =>
|
|
513
|
+
random_custom(coalesce(props.importer))("bigint")(tags)(
|
|
514
|
+
RandomRanger.number({
|
|
515
|
+
config: {
|
|
416
516
|
type: tags.find(
|
|
417
517
|
(t) =>
|
|
418
518
|
t.kind === "type" &&
|
|
@@ -423,74 +523,88 @@ export namespace RandomProgrammer {
|
|
|
423
523
|
transform: (value) => ExpressionFactory.bigint(value),
|
|
424
524
|
setter: (args) =>
|
|
425
525
|
ts.factory.createCallExpression(
|
|
426
|
-
|
|
526
|
+
coalesce(props.importer)("bigint"),
|
|
427
527
|
undefined,
|
|
428
528
|
args.map((value) => ExpressionFactory.bigint(value)),
|
|
429
529
|
),
|
|
430
|
-
}
|
|
530
|
+
},
|
|
531
|
+
defaults: {
|
|
431
532
|
minimum: 0,
|
|
432
533
|
maximum: 100,
|
|
433
534
|
gap: 10,
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
|
|
535
|
+
},
|
|
536
|
+
tags,
|
|
537
|
+
}),
|
|
538
|
+
),
|
|
539
|
+
);
|
|
437
540
|
|
|
438
|
-
const decode_string =
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
)
|
|
459
|
-
|
|
460
|
-
|
|
541
|
+
const decode_string = (props: {
|
|
542
|
+
importer: FunctionImporter;
|
|
543
|
+
atomic: MetadataAtomic;
|
|
544
|
+
}): ts.Expression[] =>
|
|
545
|
+
(props.atomic.tags.length ? props.atomic.tags : [[]]).map((tags) =>
|
|
546
|
+
random_custom(coalesce(props.importer))("string")(tags)(
|
|
547
|
+
(() => {
|
|
548
|
+
for (const t of tags)
|
|
549
|
+
if (t.kind === "format")
|
|
550
|
+
return ts.factory.createCallExpression(
|
|
551
|
+
coalesce(props.importer)(emendFormat(t.value)),
|
|
552
|
+
undefined,
|
|
553
|
+
undefined,
|
|
554
|
+
);
|
|
555
|
+
else if (t.kind === "pattern")
|
|
556
|
+
return ts.factory.createCallExpression(
|
|
557
|
+
coalesce(props.importer)("pattern"),
|
|
558
|
+
undefined,
|
|
559
|
+
[
|
|
560
|
+
ts.factory.createIdentifier(
|
|
561
|
+
`RegExp(${JSON.stringify(t.value)})`,
|
|
562
|
+
),
|
|
563
|
+
],
|
|
564
|
+
);
|
|
461
565
|
|
|
462
|
-
|
|
566
|
+
const tail = RandomRanger.length({
|
|
567
|
+
coalesce: coalesce(props.importer),
|
|
568
|
+
defaults: {
|
|
463
569
|
minimum: 5,
|
|
464
570
|
maximum: 25,
|
|
465
571
|
gap: 5,
|
|
466
|
-
}
|
|
572
|
+
},
|
|
573
|
+
accessors: {
|
|
467
574
|
minimum: "minLength",
|
|
468
575
|
maximum: "maxLength",
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
576
|
+
},
|
|
577
|
+
tags,
|
|
578
|
+
});
|
|
579
|
+
return ts.factory.createCallExpression(
|
|
580
|
+
coalesce(props.importer)("string"),
|
|
581
|
+
undefined,
|
|
582
|
+
tail ? [tail] : undefined,
|
|
583
|
+
);
|
|
584
|
+
})(),
|
|
585
|
+
),
|
|
586
|
+
);
|
|
478
587
|
|
|
479
|
-
const decode_array =
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
RandomRanger.length(
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
588
|
+
const decode_array = (props: {
|
|
589
|
+
importer: FunctionImporter;
|
|
590
|
+
explore: IExplore;
|
|
591
|
+
array: MetadataArray;
|
|
592
|
+
}): ts.Expression[] => {
|
|
593
|
+
const fixed: Array<[ts.Expression | undefined, ts.Expression | undefined]> =
|
|
594
|
+
(props.array.tags.length ? props.array.tags : [[]]).map((tags) => [
|
|
595
|
+
RandomRanger.length({
|
|
596
|
+
coalesce: coalesce(props.importer),
|
|
597
|
+
defaults: {
|
|
598
|
+
minimum: 0,
|
|
599
|
+
maximum: 3,
|
|
600
|
+
gap: 3,
|
|
601
|
+
},
|
|
602
|
+
accessors: {
|
|
603
|
+
minimum: "minItems",
|
|
604
|
+
maximum: "maxItems",
|
|
605
|
+
},
|
|
606
|
+
tags,
|
|
607
|
+
}),
|
|
494
608
|
(() => {
|
|
495
609
|
const uniqueItems = tags.find((t) => t.kind === "uniqueItems");
|
|
496
610
|
return uniqueItems === undefined
|
|
@@ -500,212 +614,243 @@ export namespace RandomProgrammer {
|
|
|
500
614
|
: ts.factory.createTrue();
|
|
501
615
|
})(),
|
|
502
616
|
]);
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
),
|
|
509
|
-
undefined,
|
|
510
|
-
[
|
|
511
|
-
len ?? COALESCE(importer)("length"),
|
|
512
|
-
unique ?? ts.factory.createFalse(),
|
|
513
|
-
ts.factory.createTrue(),
|
|
514
|
-
explore.recursive
|
|
515
|
-
? ts.factory.createAdd(
|
|
516
|
-
ExpressionFactory.number(1),
|
|
517
|
-
ts.factory.createIdentifier("_depth"),
|
|
518
|
-
)
|
|
519
|
-
: ExpressionFactory.number(0),
|
|
520
|
-
],
|
|
617
|
+
if (props.array.type.recursive)
|
|
618
|
+
return fixed.map(([len, unique]) =>
|
|
619
|
+
ts.factory.createCallExpression(
|
|
620
|
+
ts.factory.createIdentifier(
|
|
621
|
+
props.importer.useLocal(Prefix.array(props.array.type.index!)),
|
|
521
622
|
),
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
return explore.recursive
|
|
531
|
-
? ts.factory.createConditionalExpression(
|
|
532
|
-
ts.factory.createLogicalAnd(
|
|
533
|
-
ts.factory.createIdentifier("_recursive"),
|
|
534
|
-
ts.factory.createLessThan(
|
|
535
|
-
ExpressionFactory.number(5),
|
|
623
|
+
undefined,
|
|
624
|
+
[
|
|
625
|
+
len ?? coalesce(props.importer)("length"),
|
|
626
|
+
unique ?? ts.factory.createFalse(),
|
|
627
|
+
ts.factory.createTrue(),
|
|
628
|
+
props.explore.recursive
|
|
629
|
+
? ts.factory.createAdd(
|
|
630
|
+
ExpressionFactory.number(1),
|
|
536
631
|
ts.factory.createIdentifier("_depth"),
|
|
537
|
-
)
|
|
538
|
-
),
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
632
|
+
)
|
|
633
|
+
: ExpressionFactory.number(0),
|
|
634
|
+
],
|
|
635
|
+
),
|
|
636
|
+
);
|
|
637
|
+
return fixed.map(([len, unique]) => {
|
|
638
|
+
const expr: ts.Expression = RandomJoiner.array({
|
|
639
|
+
coalesce: coalesce(props.importer),
|
|
640
|
+
decode: (metadata) =>
|
|
641
|
+
decode({
|
|
642
|
+
...props,
|
|
643
|
+
metadata,
|
|
644
|
+
}),
|
|
645
|
+
explore: props.explore,
|
|
646
|
+
length: len,
|
|
647
|
+
unique,
|
|
648
|
+
metadata: props.array.type.value,
|
|
545
649
|
});
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
ts.factory.createIdentifier(
|
|
555
|
-
importer.useLocal(Prefix.tuple(tuple.type.index!)),
|
|
650
|
+
return props.explore.recursive
|
|
651
|
+
? ts.factory.createConditionalExpression(
|
|
652
|
+
ts.factory.createLogicalAnd(
|
|
653
|
+
ts.factory.createIdentifier("_recursive"),
|
|
654
|
+
ts.factory.createLessThan(
|
|
655
|
+
ExpressionFactory.number(5),
|
|
656
|
+
ts.factory.createIdentifier("_depth"),
|
|
657
|
+
),
|
|
556
658
|
),
|
|
557
659
|
undefined,
|
|
558
|
-
[
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
? ts.factory.createAdd(
|
|
562
|
-
ExpressionFactory.number(1),
|
|
563
|
-
ts.factory.createIdentifier("_depth"),
|
|
564
|
-
)
|
|
565
|
-
: ExpressionFactory.number(0),
|
|
566
|
-
],
|
|
660
|
+
ts.factory.createIdentifier("[]"),
|
|
661
|
+
undefined,
|
|
662
|
+
expr,
|
|
567
663
|
)
|
|
568
|
-
:
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
ts.factory.createAdd(
|
|
664
|
+
: expr;
|
|
665
|
+
});
|
|
666
|
+
};
|
|
667
|
+
|
|
668
|
+
const decode_tuple = (props: {
|
|
669
|
+
importer: FunctionImporter;
|
|
670
|
+
explore: IExplore;
|
|
671
|
+
tuple: MetadataTuple;
|
|
672
|
+
}): ts.Expression =>
|
|
673
|
+
props.tuple.type.recursive
|
|
674
|
+
? ts.factory.createCallExpression(
|
|
675
|
+
ts.factory.createIdentifier(
|
|
676
|
+
props.importer.useLocal(Prefix.tuple(props.tuple.type.index!)),
|
|
677
|
+
),
|
|
678
|
+
undefined,
|
|
679
|
+
[
|
|
680
|
+
ts.factory.createTrue(),
|
|
681
|
+
props.explore.recursive
|
|
682
|
+
? ts.factory.createAdd(
|
|
588
683
|
ExpressionFactory.number(1),
|
|
589
684
|
ts.factory.createIdentifier("_depth"),
|
|
590
|
-
)
|
|
591
|
-
|
|
685
|
+
)
|
|
686
|
+
: ExpressionFactory.number(0),
|
|
687
|
+
],
|
|
688
|
+
)
|
|
689
|
+
: RandomJoiner.tuple({
|
|
690
|
+
decode: (metadata) =>
|
|
691
|
+
decode({
|
|
692
|
+
...props,
|
|
693
|
+
metadata,
|
|
694
|
+
}),
|
|
695
|
+
elements: props.tuple.type.elements,
|
|
696
|
+
});
|
|
697
|
+
|
|
698
|
+
const decode_object = (props: {
|
|
699
|
+
importer: FunctionImporter;
|
|
700
|
+
explore: IExplore;
|
|
701
|
+
object: MetadataObject;
|
|
702
|
+
}) =>
|
|
703
|
+
ts.factory.createCallExpression(
|
|
704
|
+
ts.factory.createIdentifier(
|
|
705
|
+
props.importer.useLocal(Prefix.object(props.object.index)),
|
|
706
|
+
),
|
|
707
|
+
undefined,
|
|
708
|
+
props.explore.function
|
|
709
|
+
? [
|
|
710
|
+
props.explore.recursive
|
|
711
|
+
? ts.factory.createTrue()
|
|
712
|
+
: ts.factory.createIdentifier("_recursive"),
|
|
713
|
+
ts.factory.createConditionalExpression(
|
|
714
|
+
ts.factory.createIdentifier("_recursive"),
|
|
715
|
+
undefined,
|
|
716
|
+
ts.factory.createAdd(
|
|
717
|
+
ExpressionFactory.number(1),
|
|
592
718
|
ts.factory.createIdentifier("_depth"),
|
|
593
719
|
),
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
720
|
+
undefined,
|
|
721
|
+
ts.factory.createIdentifier("_depth"),
|
|
722
|
+
),
|
|
723
|
+
]
|
|
724
|
+
: undefined,
|
|
725
|
+
);
|
|
597
726
|
|
|
598
727
|
/* -----------------------------------------------------------
|
|
599
728
|
NATIVE CLASSES
|
|
600
729
|
----------------------------------------------------------- */
|
|
601
|
-
const decode_set =
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
730
|
+
const decode_set = (props: {
|
|
731
|
+
importer: FunctionImporter;
|
|
732
|
+
explore: IExplore;
|
|
733
|
+
metadata: Metadata;
|
|
734
|
+
}) =>
|
|
735
|
+
ts.factory.createNewExpression(
|
|
736
|
+
ts.factory.createIdentifier("Set"),
|
|
737
|
+
undefined,
|
|
738
|
+
[
|
|
739
|
+
decode_array({
|
|
740
|
+
...props,
|
|
741
|
+
array: MetadataArray.create({
|
|
742
|
+
tags: [],
|
|
743
|
+
type: MetadataArrayType.create({
|
|
744
|
+
value: props.metadata,
|
|
745
|
+
recursive: false,
|
|
746
|
+
index: null,
|
|
747
|
+
nullables: [],
|
|
748
|
+
name: `Set<${props.metadata.getName()}>`,
|
|
617
749
|
}),
|
|
618
|
-
)
|
|
619
|
-
]
|
|
620
|
-
|
|
750
|
+
}),
|
|
751
|
+
})[0]!,
|
|
752
|
+
],
|
|
753
|
+
);
|
|
621
754
|
|
|
622
|
-
const decode_map =
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
755
|
+
const decode_map = (props: {
|
|
756
|
+
importer: FunctionImporter;
|
|
757
|
+
explore: IExplore;
|
|
758
|
+
entry: Metadata.Entry;
|
|
759
|
+
}) =>
|
|
760
|
+
ts.factory.createNewExpression(
|
|
761
|
+
ts.factory.createIdentifier("Map"),
|
|
762
|
+
undefined,
|
|
763
|
+
[
|
|
764
|
+
decode_array({
|
|
765
|
+
...props,
|
|
766
|
+
array: MetadataArray.create({
|
|
767
|
+
tags: [],
|
|
768
|
+
type: MetadataArrayType.create({
|
|
769
|
+
name: `Map<${props.entry.key.getName()}, ${props.entry.value.getName()}>`,
|
|
770
|
+
index: null,
|
|
771
|
+
recursive: false,
|
|
772
|
+
nullables: [],
|
|
773
|
+
value: Metadata.create({
|
|
774
|
+
...Metadata.initialize(),
|
|
775
|
+
tuples: [
|
|
776
|
+
(() => {
|
|
777
|
+
const type = MetadataTupleType.create({
|
|
778
|
+
name: `[${props.entry.key.getName()}, ${props.entry.value.getName()}]`,
|
|
779
|
+
index: null,
|
|
780
|
+
recursive: false,
|
|
781
|
+
nullables: [],
|
|
782
|
+
elements: [props.entry.key, props.entry.value],
|
|
783
|
+
});
|
|
784
|
+
type.of_map = true;
|
|
785
|
+
return MetadataTuple.create({
|
|
786
|
+
type,
|
|
787
|
+
tags: [],
|
|
788
|
+
});
|
|
789
|
+
})(),
|
|
790
|
+
],
|
|
657
791
|
}),
|
|
658
792
|
}),
|
|
659
|
-
)[0]!,
|
|
660
|
-
],
|
|
661
|
-
);
|
|
662
|
-
|
|
663
|
-
const decode_native =
|
|
664
|
-
(importer: FunctionImporter) =>
|
|
665
|
-
(type: string): ts.Expression => {
|
|
666
|
-
if (type === "Boolean") return decode_boolean(importer);
|
|
667
|
-
else if (type === "Number")
|
|
668
|
-
return decode_number(importer)(
|
|
669
|
-
MetadataAtomic.create({
|
|
670
|
-
type: "number",
|
|
671
|
-
tags: [],
|
|
672
|
-
}),
|
|
673
|
-
)[0]!;
|
|
674
|
-
else if (type === "String")
|
|
675
|
-
return decode_string(importer)(
|
|
676
|
-
MetadataAtomic.create({
|
|
677
|
-
type: "string",
|
|
678
|
-
tags: [],
|
|
679
793
|
}),
|
|
680
|
-
)[0]
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
794
|
+
})[0]!,
|
|
795
|
+
],
|
|
796
|
+
);
|
|
797
|
+
|
|
798
|
+
const decode_native = (props: {
|
|
799
|
+
importer: FunctionImporter;
|
|
800
|
+
name: string;
|
|
801
|
+
}): ts.Expression => {
|
|
802
|
+
if (props.name === "Boolean") return decode_boolean(props.importer);
|
|
803
|
+
else if (props.name === "Number")
|
|
804
|
+
return decode_number({
|
|
805
|
+
importer: props.importer,
|
|
806
|
+
atomic: MetadataAtomic.create({
|
|
807
|
+
type: "number",
|
|
808
|
+
tags: [],
|
|
809
|
+
}),
|
|
810
|
+
})[0]!;
|
|
811
|
+
else if (props.name === "String")
|
|
812
|
+
return decode_string({
|
|
813
|
+
importer: props.importer,
|
|
814
|
+
atomic: MetadataAtomic.create({
|
|
815
|
+
type: "string",
|
|
816
|
+
tags: [],
|
|
817
|
+
}),
|
|
818
|
+
})[0]!;
|
|
819
|
+
else if (props.name === "Date") return decode_native_date(props.importer);
|
|
820
|
+
else if (
|
|
821
|
+
props.name === "Uint8Array" ||
|
|
822
|
+
props.name === "Uint8ClampedArray" ||
|
|
823
|
+
props.name === "Uint16Array" ||
|
|
824
|
+
props.name === "Uint32Array" ||
|
|
825
|
+
props.name === "BigUint64Array" ||
|
|
826
|
+
props.name === "Int8Array" ||
|
|
827
|
+
props.name === "Int16Array" ||
|
|
828
|
+
props.name === "Int32Array" ||
|
|
829
|
+
props.name === "BigInt64Array" ||
|
|
830
|
+
props.name === "Float32Array" ||
|
|
831
|
+
props.name === "Float64Array"
|
|
832
|
+
)
|
|
833
|
+
return decode_native_byte_array({
|
|
834
|
+
...props,
|
|
835
|
+
name: props.name,
|
|
836
|
+
});
|
|
837
|
+
else if (props.name === "ArrayBuffer" || props.name === "SharedArrayBuffer")
|
|
838
|
+
return decode_native_array_buffer({
|
|
839
|
+
...props,
|
|
840
|
+
name: props.name,
|
|
841
|
+
});
|
|
842
|
+
else if (props.name === "DataView")
|
|
843
|
+
return decode_native_data_view(props.importer);
|
|
844
|
+
else if (props.name === "Blob") return decode_native_blob(props.importer);
|
|
845
|
+
else if (props.name === "File") return decode_native_file(props.importer);
|
|
846
|
+
else if (props.name === "RegExp") return decode_regexp();
|
|
847
|
+
else
|
|
848
|
+
return ts.factory.createNewExpression(
|
|
849
|
+
ts.factory.createIdentifier(props.name),
|
|
850
|
+
undefined,
|
|
851
|
+
[],
|
|
852
|
+
);
|
|
853
|
+
};
|
|
709
854
|
|
|
710
855
|
const decode_native_date = (importer: FunctionImporter) =>
|
|
711
856
|
ts.factory.createNewExpression(
|
|
@@ -713,80 +858,81 @@ export namespace RandomProgrammer {
|
|
|
713
858
|
undefined,
|
|
714
859
|
[
|
|
715
860
|
ts.factory.createCallExpression(
|
|
716
|
-
|
|
861
|
+
coalesce(importer)("datetime"),
|
|
717
862
|
undefined,
|
|
718
863
|
[],
|
|
719
864
|
),
|
|
720
865
|
],
|
|
721
866
|
);
|
|
722
867
|
|
|
723
|
-
const decode_native_byte_array =
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
)
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
undefined,
|
|
782
|
-
[literal(minimum), literal(maximum)],
|
|
868
|
+
const decode_native_byte_array = (props: {
|
|
869
|
+
importer: FunctionImporter;
|
|
870
|
+
name:
|
|
871
|
+
| "Uint8Array"
|
|
872
|
+
| "Uint8ClampedArray"
|
|
873
|
+
| "Uint16Array"
|
|
874
|
+
| "Uint32Array"
|
|
875
|
+
| "BigUint64Array"
|
|
876
|
+
| "Int8Array"
|
|
877
|
+
| "Int16Array"
|
|
878
|
+
| "Int32Array"
|
|
879
|
+
| "BigInt64Array"
|
|
880
|
+
| "Float32Array"
|
|
881
|
+
| "Float64Array";
|
|
882
|
+
}): ts.Expression => {
|
|
883
|
+
new BigInt64Array();
|
|
884
|
+
const [minimum, maximum]: [number, number] = (() => {
|
|
885
|
+
if (props.name === "Uint8Array" || props.name === "Uint8ClampedArray")
|
|
886
|
+
return [0, 255];
|
|
887
|
+
else if (props.name === "Uint16Array") return [0, 65535];
|
|
888
|
+
else if (props.name === "Uint32Array") return [0, 4294967295];
|
|
889
|
+
else if (props.name === "BigUint64Array")
|
|
890
|
+
return [0, 18446744073709551615];
|
|
891
|
+
else if (props.name === "Int8Array") return [-128, 127];
|
|
892
|
+
else if (props.name === "Int16Array") return [-32768, 32767];
|
|
893
|
+
else if (props.name === "Int32Array") return [-2147483648, 2147483647];
|
|
894
|
+
else if (props.name === "BigInt64Array")
|
|
895
|
+
return [-9223372036854775808, 9223372036854775807];
|
|
896
|
+
else if (props.name === "Float32Array")
|
|
897
|
+
return [-1.175494351e38, 3.4028235e38];
|
|
898
|
+
return [Number.MIN_VALUE, Number.MAX_VALUE];
|
|
899
|
+
})();
|
|
900
|
+
const literal =
|
|
901
|
+
props.name === "BigInt64Array" || props.name === "BigUint64Array"
|
|
902
|
+
? ExpressionFactory.bigint
|
|
903
|
+
: ExpressionFactory.number;
|
|
904
|
+
return ts.factory.createNewExpression(
|
|
905
|
+
ts.factory.createIdentifier(props.name),
|
|
906
|
+
[],
|
|
907
|
+
[
|
|
908
|
+
ts.factory.createCallExpression(
|
|
909
|
+
coalesce(props.importer)("array"),
|
|
910
|
+
undefined,
|
|
911
|
+
[
|
|
912
|
+
ts.factory.createArrowFunction(
|
|
913
|
+
undefined,
|
|
914
|
+
undefined,
|
|
915
|
+
[],
|
|
916
|
+
TypeFactory.keyword("any"),
|
|
917
|
+
undefined,
|
|
918
|
+
ts.factory.createCallExpression(
|
|
919
|
+
coalesce(props.importer)(
|
|
920
|
+
props.name === "Float32Array" || props.name === "Float64Array"
|
|
921
|
+
? "number"
|
|
922
|
+
: props.name === "BigInt64Array" ||
|
|
923
|
+
props.name === "BigUint64Array"
|
|
924
|
+
? "bigint"
|
|
925
|
+
: "integer",
|
|
783
926
|
),
|
|
927
|
+
undefined,
|
|
928
|
+
[literal(minimum), literal(maximum)],
|
|
784
929
|
),
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
930
|
+
),
|
|
931
|
+
],
|
|
932
|
+
),
|
|
933
|
+
],
|
|
934
|
+
);
|
|
935
|
+
};
|
|
790
936
|
|
|
791
937
|
const decode_native_blob = (importer: FunctionImporter) =>
|
|
792
938
|
ts.factory.createNewExpression(
|
|
@@ -794,7 +940,12 @@ export namespace RandomProgrammer {
|
|
|
794
940
|
undefined,
|
|
795
941
|
[
|
|
796
942
|
ts.factory.createArrayLiteralExpression(
|
|
797
|
-
[
|
|
943
|
+
[
|
|
944
|
+
decode_native_byte_array({
|
|
945
|
+
importer,
|
|
946
|
+
name: "Uint8Array",
|
|
947
|
+
}),
|
|
948
|
+
],
|
|
798
949
|
true,
|
|
799
950
|
),
|
|
800
951
|
],
|
|
@@ -806,13 +957,18 @@ export namespace RandomProgrammer {
|
|
|
806
957
|
undefined,
|
|
807
958
|
[
|
|
808
959
|
ts.factory.createArrayLiteralExpression(
|
|
809
|
-
[
|
|
960
|
+
[
|
|
961
|
+
decode_native_byte_array({
|
|
962
|
+
importer,
|
|
963
|
+
name: "Uint8Array",
|
|
964
|
+
}),
|
|
965
|
+
],
|
|
810
966
|
true,
|
|
811
967
|
),
|
|
812
968
|
ts.factory.createTemplateExpression(ts.factory.createTemplateHead(""), [
|
|
813
969
|
ts.factory.createTemplateSpan(
|
|
814
970
|
ts.factory.createCallExpression(
|
|
815
|
-
|
|
971
|
+
coalesce(importer)("string"),
|
|
816
972
|
undefined,
|
|
817
973
|
[ts.factory.createNumericLiteral(8)],
|
|
818
974
|
),
|
|
@@ -820,7 +976,7 @@ export namespace RandomProgrammer {
|
|
|
820
976
|
),
|
|
821
977
|
ts.factory.createTemplateSpan(
|
|
822
978
|
ts.factory.createCallExpression(
|
|
823
|
-
|
|
979
|
+
coalesce(importer)("string"),
|
|
824
980
|
undefined,
|
|
825
981
|
[ts.factory.createNumericLiteral(3)],
|
|
826
982
|
),
|
|
@@ -830,80 +986,84 @@ export namespace RandomProgrammer {
|
|
|
830
986
|
],
|
|
831
987
|
);
|
|
832
988
|
|
|
833
|
-
const decode_native_array_buffer =
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
989
|
+
const decode_native_array_buffer = (props: {
|
|
990
|
+
importer: FunctionImporter;
|
|
991
|
+
name: "ArrayBuffer" | "SharedArrayBuffer";
|
|
992
|
+
}): ts.Expression =>
|
|
993
|
+
props.name === "ArrayBuffer"
|
|
994
|
+
? IdentifierFactory.access(
|
|
995
|
+
decode_native_byte_array({
|
|
996
|
+
importer: props.importer,
|
|
997
|
+
name: "Uint8Array",
|
|
998
|
+
}),
|
|
999
|
+
)("buffer")
|
|
1000
|
+
: ExpressionFactory.selfCall(
|
|
1001
|
+
ts.factory.createBlock(
|
|
1002
|
+
[
|
|
1003
|
+
StatementFactory.constant(
|
|
1004
|
+
"length",
|
|
1005
|
+
ts.factory.createCallExpression(
|
|
1006
|
+
coalesce(props.importer)("integer"),
|
|
1007
|
+
undefined,
|
|
1008
|
+
[],
|
|
850
1009
|
),
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
),
|
|
1010
|
+
),
|
|
1011
|
+
StatementFactory.constant(
|
|
1012
|
+
"buffer",
|
|
1013
|
+
ts.factory.createNewExpression(
|
|
1014
|
+
ts.factory.createIdentifier("SharedArrayBuffer"),
|
|
1015
|
+
[],
|
|
1016
|
+
[ts.factory.createIdentifier("length")],
|
|
858
1017
|
),
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
),
|
|
1018
|
+
),
|
|
1019
|
+
StatementFactory.constant(
|
|
1020
|
+
"bytes",
|
|
1021
|
+
ts.factory.createNewExpression(
|
|
1022
|
+
ts.factory.createIdentifier("Uint8Array"),
|
|
1023
|
+
[],
|
|
1024
|
+
[ts.factory.createIdentifier("buffer")],
|
|
866
1025
|
),
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
1026
|
+
),
|
|
1027
|
+
ts.factory.createExpressionStatement(
|
|
1028
|
+
ts.factory.createCallExpression(
|
|
1029
|
+
IdentifierFactory.access(
|
|
1030
|
+
ts.factory.createIdentifier("bytes"),
|
|
1031
|
+
)("set"),
|
|
1032
|
+
undefined,
|
|
1033
|
+
[
|
|
1034
|
+
ts.factory.createCallExpression(
|
|
1035
|
+
coalesce(props.importer)("array"),
|
|
1036
|
+
undefined,
|
|
1037
|
+
[
|
|
1038
|
+
ts.factory.createArrowFunction(
|
|
1039
|
+
undefined,
|
|
1040
|
+
undefined,
|
|
1041
|
+
[],
|
|
1042
|
+
TypeFactory.keyword("any"),
|
|
1043
|
+
undefined,
|
|
1044
|
+
ts.factory.createCallExpression(
|
|
1045
|
+
coalesce(props.importer)("integer"),
|
|
883
1046
|
undefined,
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
ExpressionFactory.number(0),
|
|
889
|
-
ExpressionFactory.number(255),
|
|
890
|
-
],
|
|
891
|
-
),
|
|
1047
|
+
[
|
|
1048
|
+
ExpressionFactory.number(0),
|
|
1049
|
+
ExpressionFactory.number(255),
|
|
1050
|
+
],
|
|
892
1051
|
),
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
),
|
|
900
|
-
ts.factory.createReturnStatement(
|
|
901
|
-
ts.factory.createIdentifier("buffer"),
|
|
1052
|
+
),
|
|
1053
|
+
ts.factory.createIdentifier("length"),
|
|
1054
|
+
],
|
|
1055
|
+
),
|
|
1056
|
+
ExpressionFactory.number(0),
|
|
1057
|
+
],
|
|
902
1058
|
),
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
1059
|
+
),
|
|
1060
|
+
ts.factory.createReturnStatement(
|
|
1061
|
+
ts.factory.createIdentifier("buffer"),
|
|
1062
|
+
),
|
|
1063
|
+
],
|
|
1064
|
+
true,
|
|
1065
|
+
),
|
|
1066
|
+
);
|
|
907
1067
|
|
|
908
1068
|
const decode_native_data_view = (importer: FunctionImporter) =>
|
|
909
1069
|
ts.factory.createNewExpression(
|
|
@@ -911,7 +1071,10 @@ export namespace RandomProgrammer {
|
|
|
911
1071
|
[],
|
|
912
1072
|
[
|
|
913
1073
|
IdentifierFactory.access(
|
|
914
|
-
decode_native_byte_array(
|
|
1074
|
+
decode_native_byte_array({
|
|
1075
|
+
importer,
|
|
1076
|
+
name: "Uint8Array",
|
|
1077
|
+
}),
|
|
915
1078
|
)("buffer"),
|
|
916
1079
|
],
|
|
917
1080
|
);
|
|
@@ -936,7 +1099,7 @@ const Prefix = {
|
|
|
936
1099
|
tuple: (i: number) => `$rt${i}`,
|
|
937
1100
|
};
|
|
938
1101
|
|
|
939
|
-
const
|
|
1102
|
+
const coalesce = (importer: FunctionImporter) => (name: string) =>
|
|
940
1103
|
ExpressionFactory.coalesce(
|
|
941
1104
|
Escaper.variable(name)
|
|
942
1105
|
? ts.factory.createPropertyAccessChain(
|