seroval 0.4.0-alpha.12 → 0.4.0-alpha.13
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/dist/cjs/development/index.cjs +298 -329
- package/dist/cjs/development/index.cjs.map +3 -3
- package/dist/cjs/production/index.cjs +2 -2
- package/dist/esm/development/index.mjs +298 -329
- package/dist/esm/development/index.mjs.map +3 -3
- package/dist/esm/production/index.mjs +2 -2
- package/dist/types/context.d.ts +11 -11
- package/dist/types/tree/primitives.d.ts +1 -10
- package/dist/types/tree/types.d.ts +57 -38
- package/package.json +2 -2
- package/src/context.ts +37 -39
- package/src/index.ts +8 -9
- package/src/tree/async.ts +48 -111
- package/src/tree/primitives.ts +7 -143
- package/src/tree/sync.ts +45 -94
- package/src/tree/types.ts +202 -53
|
@@ -249,25 +249,33 @@ function getIdentifier(index) {
|
|
|
249
249
|
var DEFAULT_OPTIONS = {
|
|
250
250
|
target: "es2023"
|
|
251
251
|
};
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
markedRefs
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
validRefs
|
|
266
|
-
refSize
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
252
|
+
var ParserContext = class {
|
|
253
|
+
constructor(options = {}) {
|
|
254
|
+
__publicField(this, "refs", /* @__PURE__ */ new Map());
|
|
255
|
+
__publicField(this, "markedRefs", {});
|
|
256
|
+
__publicField(this, "features");
|
|
257
|
+
const result = Object.assign({}, DEFAULT_OPTIONS, options || {});
|
|
258
|
+
this.features = parseTargets(result.target);
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
var SerializationContext = class {
|
|
262
|
+
constructor(options) {
|
|
263
|
+
__publicField(this, "stack", []);
|
|
264
|
+
// Map tree refs to actual refs
|
|
265
|
+
__publicField(this, "validRefs", []);
|
|
266
|
+
__publicField(this, "refSize", 0);
|
|
267
|
+
// Variables
|
|
268
|
+
__publicField(this, "vars", []);
|
|
269
|
+
// Array of assignments to be done (used for recursion)
|
|
270
|
+
__publicField(this, "assignments", []);
|
|
271
|
+
// Supported features
|
|
272
|
+
__publicField(this, "features");
|
|
273
|
+
// Refs that are...referenced
|
|
274
|
+
__publicField(this, "markedRefs");
|
|
275
|
+
this.features = options.features;
|
|
276
|
+
this.markedRefs = options.markedRefs;
|
|
277
|
+
}
|
|
278
|
+
};
|
|
271
279
|
function markRef(ctx, current) {
|
|
272
280
|
ctx.markedRefs[current] = 1;
|
|
273
281
|
}
|
|
@@ -351,119 +359,198 @@ function quote(str) {
|
|
|
351
359
|
return `"${result}"`;
|
|
352
360
|
}
|
|
353
361
|
|
|
362
|
+
// src/tree/types.ts
|
|
363
|
+
var SerovalObjectRecordNode = class {
|
|
364
|
+
constructor(k, v, s) {
|
|
365
|
+
__publicField(this, "k");
|
|
366
|
+
__publicField(this, "v");
|
|
367
|
+
__publicField(this, "s");
|
|
368
|
+
this.k = k;
|
|
369
|
+
this.v = v;
|
|
370
|
+
this.s = s;
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
var SerovalMapRecordNode = class {
|
|
374
|
+
constructor(k, v, s) {
|
|
375
|
+
__publicField(this, "k");
|
|
376
|
+
__publicField(this, "v");
|
|
377
|
+
__publicField(this, "s");
|
|
378
|
+
this.k = k;
|
|
379
|
+
this.v = v;
|
|
380
|
+
this.s = s;
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
var SerovalPrimitiveNode = class {
|
|
384
|
+
constructor(current) {
|
|
385
|
+
__publicField(this, "t", 0 /* Primitive */);
|
|
386
|
+
__publicField(this, "s");
|
|
387
|
+
this.s = current;
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
var SerovalReferenceNode = class {
|
|
391
|
+
constructor(id) {
|
|
392
|
+
__publicField(this, "t", 2 /* Reference */);
|
|
393
|
+
__publicField(this, "i");
|
|
394
|
+
this.i = id;
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
var SerovalBigIntNode = class {
|
|
398
|
+
constructor(current) {
|
|
399
|
+
__publicField(this, "t", 1 /* BigInt */);
|
|
400
|
+
__publicField(this, "s");
|
|
401
|
+
this.s = `${current}n`;
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
var SerovalDateNode = class {
|
|
405
|
+
constructor(id, current) {
|
|
406
|
+
__publicField(this, "t", 3 /* Date */);
|
|
407
|
+
__publicField(this, "i");
|
|
408
|
+
__publicField(this, "s");
|
|
409
|
+
this.i = id;
|
|
410
|
+
this.s = current.toISOString();
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
var SerovalRegExpNode = class {
|
|
414
|
+
constructor(id, current) {
|
|
415
|
+
__publicField(this, "t", 4 /* RegExp */);
|
|
416
|
+
__publicField(this, "i");
|
|
417
|
+
__publicField(this, "s");
|
|
418
|
+
this.i = id;
|
|
419
|
+
this.s = String(current);
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
var SerovalTypedArrayNode = class {
|
|
423
|
+
constructor(id, current) {
|
|
424
|
+
__publicField(this, "t", 14 /* TypedArray */);
|
|
425
|
+
__publicField(this, "i");
|
|
426
|
+
__publicField(this, "s");
|
|
427
|
+
__publicField(this, "l");
|
|
428
|
+
__publicField(this, "c");
|
|
429
|
+
this.i = id;
|
|
430
|
+
this.s = current.toString();
|
|
431
|
+
this.l = current.byteOffset;
|
|
432
|
+
this.c = current.constructor.name;
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
var SerovalBigIntTypedArrayNode = class {
|
|
436
|
+
constructor(id, current) {
|
|
437
|
+
__publicField(this, "t", 15 /* BigIntTypedArray */);
|
|
438
|
+
__publicField(this, "i");
|
|
439
|
+
__publicField(this, "s");
|
|
440
|
+
__publicField(this, "l");
|
|
441
|
+
__publicField(this, "c");
|
|
442
|
+
let result = "";
|
|
443
|
+
const cap = current.length - 1;
|
|
444
|
+
for (let i = 0; i < cap; i++) {
|
|
445
|
+
result += `${current[i]}n,`;
|
|
446
|
+
}
|
|
447
|
+
result += `"${current[cap]}"`;
|
|
448
|
+
this.i = id;
|
|
449
|
+
this.s = result;
|
|
450
|
+
this.l = current.byteOffset;
|
|
451
|
+
this.c = current.constructor.name;
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
var SerovalSetNode = class {
|
|
455
|
+
constructor(id, a) {
|
|
456
|
+
__publicField(this, "t", 5 /* Set */);
|
|
457
|
+
__publicField(this, "i");
|
|
458
|
+
__publicField(this, "a");
|
|
459
|
+
this.i = id;
|
|
460
|
+
this.a = a;
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
var SerovalMapNode = class {
|
|
464
|
+
constructor(id, d) {
|
|
465
|
+
__publicField(this, "t", 6 /* Map */);
|
|
466
|
+
__publicField(this, "i");
|
|
467
|
+
__publicField(this, "d");
|
|
468
|
+
this.i = id;
|
|
469
|
+
this.d = d;
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
var SerovalArrayNode = class {
|
|
473
|
+
constructor(id, a) {
|
|
474
|
+
__publicField(this, "t", 7 /* Array */);
|
|
475
|
+
__publicField(this, "i");
|
|
476
|
+
__publicField(this, "a");
|
|
477
|
+
this.i = id;
|
|
478
|
+
this.a = a;
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
var SerovalObjectNode = class {
|
|
482
|
+
constructor(id, d) {
|
|
483
|
+
__publicField(this, "t", 8 /* Object */);
|
|
484
|
+
__publicField(this, "i");
|
|
485
|
+
__publicField(this, "d");
|
|
486
|
+
this.i = id;
|
|
487
|
+
this.d = d;
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
var SerovalNullConstructorNode = class {
|
|
491
|
+
constructor(id, d) {
|
|
492
|
+
__publicField(this, "t", 9 /* NullConstructor */);
|
|
493
|
+
__publicField(this, "i");
|
|
494
|
+
__publicField(this, "d");
|
|
495
|
+
this.i = id;
|
|
496
|
+
this.d = d;
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
var SerovalPromiseNode = class {
|
|
500
|
+
constructor(id, n) {
|
|
501
|
+
__publicField(this, "t", 10 /* Promise */);
|
|
502
|
+
__publicField(this, "i");
|
|
503
|
+
__publicField(this, "n");
|
|
504
|
+
this.i = id;
|
|
505
|
+
this.n = n;
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
var SerovalErrorNode = class {
|
|
509
|
+
constructor(id, c, m, d) {
|
|
510
|
+
__publicField(this, "t", 11 /* Error */);
|
|
511
|
+
__publicField(this, "i");
|
|
512
|
+
__publicField(this, "c");
|
|
513
|
+
__publicField(this, "m");
|
|
514
|
+
__publicField(this, "d");
|
|
515
|
+
this.i = id;
|
|
516
|
+
this.c = c;
|
|
517
|
+
this.m = m;
|
|
518
|
+
this.d = d;
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
var SerovalAggregateErrorNode = class {
|
|
522
|
+
constructor(id, m, d, n) {
|
|
523
|
+
__publicField(this, "t", 12 /* AggregateError */);
|
|
524
|
+
__publicField(this, "i");
|
|
525
|
+
__publicField(this, "m");
|
|
526
|
+
__publicField(this, "d");
|
|
527
|
+
__publicField(this, "n");
|
|
528
|
+
this.i = id;
|
|
529
|
+
this.m = m;
|
|
530
|
+
this.d = d;
|
|
531
|
+
this.n = n;
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
var SerovalIterableNode = class {
|
|
535
|
+
constructor(id, d, a) {
|
|
536
|
+
__publicField(this, "t", 13 /* Iterable */);
|
|
537
|
+
__publicField(this, "i");
|
|
538
|
+
__publicField(this, "d");
|
|
539
|
+
__publicField(this, "a");
|
|
540
|
+
this.i = id;
|
|
541
|
+
this.d = d;
|
|
542
|
+
this.a = a;
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
|
|
354
546
|
// src/tree/primitives.ts
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
c: void 0,
|
|
363
|
-
d: void 0,
|
|
364
|
-
a: void 0,
|
|
365
|
-
n: void 0
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
var TRUE_NODE = createPrimitiveNode("!0");
|
|
369
|
-
var FALSE_NODE = createPrimitiveNode("!1");
|
|
370
|
-
var UNDEFINED_NODE = createPrimitiveNode("void 0");
|
|
371
|
-
var NULL_NODE = createPrimitiveNode(null);
|
|
372
|
-
var NEG_ZERO_NODE = createPrimitiveNode("-0");
|
|
373
|
-
var INFINITY_NODE = createPrimitiveNode("1/0");
|
|
374
|
-
var NEG_INFINITY_NODE = createPrimitiveNode("-1/0");
|
|
375
|
-
function createBigIntNode(ctx, current) {
|
|
376
|
-
assert(ctx.features & 8 /* BigInt */, 'Unsupported type "BigInt"');
|
|
377
|
-
return {
|
|
378
|
-
t: 1 /* BigInt */,
|
|
379
|
-
i: void 0,
|
|
380
|
-
a: void 0,
|
|
381
|
-
s: `${current}n`,
|
|
382
|
-
l: void 0,
|
|
383
|
-
m: void 0,
|
|
384
|
-
c: void 0,
|
|
385
|
-
d: void 0,
|
|
386
|
-
n: void 0
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
function createReferenceNode(id) {
|
|
390
|
-
return {
|
|
391
|
-
t: 2 /* Reference */,
|
|
392
|
-
i: id,
|
|
393
|
-
a: void 0,
|
|
394
|
-
s: void 0,
|
|
395
|
-
l: void 0,
|
|
396
|
-
m: void 0,
|
|
397
|
-
c: void 0,
|
|
398
|
-
d: void 0,
|
|
399
|
-
n: void 0
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
function createDateNode(id, current) {
|
|
403
|
-
return {
|
|
404
|
-
t: 3 /* Date */,
|
|
405
|
-
i: id,
|
|
406
|
-
a: void 0,
|
|
407
|
-
s: current.toISOString(),
|
|
408
|
-
l: void 0,
|
|
409
|
-
m: void 0,
|
|
410
|
-
c: void 0,
|
|
411
|
-
d: void 0,
|
|
412
|
-
n: void 0
|
|
413
|
-
};
|
|
414
|
-
}
|
|
415
|
-
function createRegExpNode(id, current) {
|
|
416
|
-
return {
|
|
417
|
-
t: 4 /* RegExp */,
|
|
418
|
-
i: id,
|
|
419
|
-
a: void 0,
|
|
420
|
-
s: String(current),
|
|
421
|
-
l: void 0,
|
|
422
|
-
m: void 0,
|
|
423
|
-
c: void 0,
|
|
424
|
-
d: void 0,
|
|
425
|
-
n: void 0
|
|
426
|
-
};
|
|
427
|
-
}
|
|
428
|
-
function createTypedArrayNode(ctx, id, current) {
|
|
429
|
-
const constructor = current.constructor.name;
|
|
430
|
-
assert(ctx.features & 1024 /* TypedArray */, `Unsupported value type "${constructor}"`);
|
|
431
|
-
return {
|
|
432
|
-
t: 14 /* TypedArray */,
|
|
433
|
-
i: id,
|
|
434
|
-
a: void 0,
|
|
435
|
-
s: current.toString(),
|
|
436
|
-
l: current.byteOffset,
|
|
437
|
-
m: void 0,
|
|
438
|
-
c: constructor,
|
|
439
|
-
d: void 0,
|
|
440
|
-
n: void 0
|
|
441
|
-
};
|
|
442
|
-
}
|
|
443
|
-
function createBigIntTypedArrayNode(ctx, id, current) {
|
|
444
|
-
const constructor = current.constructor.name;
|
|
445
|
-
assert(
|
|
446
|
-
ctx.features & 2048 /* BigIntTypedArray */,
|
|
447
|
-
`Unsupported value type "${constructor}"`
|
|
448
|
-
);
|
|
449
|
-
let result = "";
|
|
450
|
-
const cap = current.length - 1;
|
|
451
|
-
for (let i = 0; i < cap; i++) {
|
|
452
|
-
result += `${current[i]}n,`;
|
|
453
|
-
}
|
|
454
|
-
result += `"${current[cap]}"`;
|
|
455
|
-
return {
|
|
456
|
-
t: 15 /* BigIntTypedArray */,
|
|
457
|
-
i: id,
|
|
458
|
-
a: void 0,
|
|
459
|
-
s: result,
|
|
460
|
-
l: current.byteOffset,
|
|
461
|
-
m: void 0,
|
|
462
|
-
c: constructor,
|
|
463
|
-
d: void 0,
|
|
464
|
-
n: void 0
|
|
465
|
-
};
|
|
466
|
-
}
|
|
547
|
+
var TRUE_NODE = new SerovalPrimitiveNode("!0");
|
|
548
|
+
var FALSE_NODE = new SerovalPrimitiveNode("!1");
|
|
549
|
+
var UNDEFINED_NODE = new SerovalPrimitiveNode("void 0");
|
|
550
|
+
var NULL_NODE = new SerovalPrimitiveNode(null);
|
|
551
|
+
var NEG_ZERO_NODE = new SerovalPrimitiveNode("-0");
|
|
552
|
+
var INFINITY_NODE = new SerovalPrimitiveNode("1/0");
|
|
553
|
+
var NEG_INFINITY_NODE = new SerovalPrimitiveNode("-1/0");
|
|
467
554
|
|
|
468
555
|
// src/tree/shared.ts
|
|
469
556
|
function getErrorConstructor(error) {
|
|
@@ -575,17 +662,7 @@ var AsyncParser = class {
|
|
|
575
662
|
return nodes;
|
|
576
663
|
}
|
|
577
664
|
async generateArrayNode(id, current) {
|
|
578
|
-
return
|
|
579
|
-
t: 7 /* Array */,
|
|
580
|
-
i: id,
|
|
581
|
-
a: await this.generateNodeList(current),
|
|
582
|
-
s: void 0,
|
|
583
|
-
l: void 0,
|
|
584
|
-
m: void 0,
|
|
585
|
-
c: void 0,
|
|
586
|
-
d: void 0,
|
|
587
|
-
n: void 0
|
|
588
|
-
};
|
|
665
|
+
return new SerovalArrayNode(id, await this.generateNodeList(current));
|
|
589
666
|
}
|
|
590
667
|
async generateMapNode(id, current) {
|
|
591
668
|
assert(this.ctx.features & 16 /* Map */, 'Unsupported type "Map"');
|
|
@@ -611,17 +688,7 @@ var AsyncParser = class {
|
|
|
611
688
|
keyNodes[nodeSize + i] = await this.parse(deferredKey[i]);
|
|
612
689
|
valueNodes[nodeSize + i] = await this.parse(deferredValue[i]);
|
|
613
690
|
}
|
|
614
|
-
return
|
|
615
|
-
t: 6 /* Map */,
|
|
616
|
-
i: id,
|
|
617
|
-
a: void 0,
|
|
618
|
-
s: void 0,
|
|
619
|
-
l: void 0,
|
|
620
|
-
m: void 0,
|
|
621
|
-
c: void 0,
|
|
622
|
-
d: { k: keyNodes, v: valueNodes, s: len },
|
|
623
|
-
n: void 0
|
|
624
|
-
};
|
|
691
|
+
return new SerovalMapNode(id, new SerovalMapRecordNode(keyNodes, valueNodes, len));
|
|
625
692
|
}
|
|
626
693
|
async generateSetNode(id, current) {
|
|
627
694
|
assert(this.ctx.features & 256 /* Set */, 'Unsupported type "Set"');
|
|
@@ -640,17 +707,7 @@ var AsyncParser = class {
|
|
|
640
707
|
for (let i = 0; i < deferredSize; i++) {
|
|
641
708
|
nodes[nodeSize + i] = await this.parse(deferred[i]);
|
|
642
709
|
}
|
|
643
|
-
return
|
|
644
|
-
t: 5 /* Set */,
|
|
645
|
-
i: id,
|
|
646
|
-
a: nodes,
|
|
647
|
-
s: void 0,
|
|
648
|
-
l: void 0,
|
|
649
|
-
m: void 0,
|
|
650
|
-
c: void 0,
|
|
651
|
-
d: void 0,
|
|
652
|
-
n: void 0
|
|
653
|
-
};
|
|
710
|
+
return new SerovalSetNode(id, nodes);
|
|
654
711
|
}
|
|
655
712
|
async generateProperties(properties) {
|
|
656
713
|
const keys = Object.keys(properties);
|
|
@@ -678,42 +735,21 @@ var AsyncParser = class {
|
|
|
678
735
|
keyNodes[nodesSize + i] = deferredKeys[i];
|
|
679
736
|
valueNodes[nodesSize + i] = await this.parse(deferredValues[i]);
|
|
680
737
|
}
|
|
681
|
-
return
|
|
682
|
-
k: keyNodes,
|
|
683
|
-
v: valueNodes,
|
|
684
|
-
s: size
|
|
685
|
-
};
|
|
738
|
+
return new SerovalObjectRecordNode(keyNodes, valueNodes, size);
|
|
686
739
|
}
|
|
687
740
|
async generateIterableNode(id, current) {
|
|
688
741
|
assert(this.ctx.features & 512 /* SymbolIterator */, 'Unsupported type "Iterable"');
|
|
689
742
|
const options = getIterableOptions(current);
|
|
690
|
-
return
|
|
691
|
-
|
|
692
|
-
i: id,
|
|
693
|
-
s: void 0,
|
|
694
|
-
l: void 0,
|
|
695
|
-
m: void 0,
|
|
696
|
-
c: void 0,
|
|
743
|
+
return new SerovalIterableNode(
|
|
744
|
+
id,
|
|
697
745
|
// Parse options first before the items
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
};
|
|
746
|
+
options ? await this.generateProperties(options) : void 0,
|
|
747
|
+
await this.generateNodeList(Array.from(current))
|
|
748
|
+
);
|
|
702
749
|
}
|
|
703
750
|
async generatePromiseNode(id, current) {
|
|
704
751
|
assert(this.ctx.features & 128 /* Promise */, 'Unsupported type "Promise"');
|
|
705
|
-
return current.then(async (value) => (
|
|
706
|
-
t: 10 /* Promise */,
|
|
707
|
-
i: id,
|
|
708
|
-
s: void 0,
|
|
709
|
-
l: void 0,
|
|
710
|
-
m: void 0,
|
|
711
|
-
c: void 0,
|
|
712
|
-
// Parse options first before the items
|
|
713
|
-
d: void 0,
|
|
714
|
-
a: void 0,
|
|
715
|
-
n: await this.parse(value)
|
|
716
|
-
}));
|
|
752
|
+
return current.then(async (value) => new SerovalPromiseNode(id, await this.parse(value)));
|
|
717
753
|
}
|
|
718
754
|
async generateObjectNode(id, current, empty) {
|
|
719
755
|
if (Symbol.iterator in current) {
|
|
@@ -722,47 +758,26 @@ var AsyncParser = class {
|
|
|
722
758
|
if ("then" in current && typeof current.then === "function") {
|
|
723
759
|
return this.generatePromiseNode(id, current);
|
|
724
760
|
}
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
m: void 0,
|
|
731
|
-
c: void 0,
|
|
732
|
-
d: await this.generateProperties(current),
|
|
733
|
-
a: void 0,
|
|
734
|
-
n: void 0
|
|
735
|
-
};
|
|
761
|
+
const properties = await this.generateProperties(current);
|
|
762
|
+
if (empty) {
|
|
763
|
+
return new SerovalNullConstructorNode(id, properties);
|
|
764
|
+
}
|
|
765
|
+
return new SerovalObjectNode(id, properties);
|
|
736
766
|
}
|
|
737
767
|
async generateAggregateErrorNode(id, current) {
|
|
738
768
|
const options = getErrorOptions(current);
|
|
739
769
|
const optionsNode = options ? await this.generateProperties(options) : void 0;
|
|
740
|
-
return
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
m: current.message,
|
|
747
|
-
c: void 0,
|
|
748
|
-
d: optionsNode,
|
|
749
|
-
n: await this.parse(current.errors)
|
|
750
|
-
};
|
|
770
|
+
return new SerovalAggregateErrorNode(
|
|
771
|
+
id,
|
|
772
|
+
current.message,
|
|
773
|
+
optionsNode,
|
|
774
|
+
await this.parse(current.errors)
|
|
775
|
+
);
|
|
751
776
|
}
|
|
752
777
|
async generateErrorNode(id, current) {
|
|
753
778
|
const options = getErrorOptions(current);
|
|
754
779
|
const optionsNode = options ? await this.generateProperties(options) : void 0;
|
|
755
|
-
return
|
|
756
|
-
t: 11 /* Error */,
|
|
757
|
-
i: id,
|
|
758
|
-
a: void 0,
|
|
759
|
-
s: void 0,
|
|
760
|
-
l: void 0,
|
|
761
|
-
m: current.message,
|
|
762
|
-
c: getErrorConstructor(current),
|
|
763
|
-
d: optionsNode,
|
|
764
|
-
n: void 0
|
|
765
|
-
};
|
|
780
|
+
return new SerovalErrorNode(id, getErrorConstructor(current), current.message, optionsNode);
|
|
766
781
|
}
|
|
767
782
|
async parse(current) {
|
|
768
783
|
switch (typeof current) {
|
|
@@ -771,36 +786,37 @@ var AsyncParser = class {
|
|
|
771
786
|
case "undefined":
|
|
772
787
|
return UNDEFINED_NODE;
|
|
773
788
|
case "string":
|
|
774
|
-
return
|
|
789
|
+
return new SerovalPrimitiveNode(quote(current));
|
|
775
790
|
case "number":
|
|
776
791
|
if (Object.is(current, -0)) {
|
|
777
792
|
return NEG_ZERO_NODE;
|
|
778
793
|
}
|
|
779
794
|
if (Object.is(current, Infinity)) {
|
|
780
|
-
return
|
|
795
|
+
return INFINITY_NODE;
|
|
781
796
|
}
|
|
782
797
|
if (Object.is(current, -Infinity)) {
|
|
783
|
-
return
|
|
798
|
+
return NEG_INFINITY_NODE;
|
|
784
799
|
}
|
|
785
|
-
return
|
|
800
|
+
return new SerovalPrimitiveNode(current);
|
|
786
801
|
case "bigint":
|
|
787
|
-
|
|
802
|
+
assert(this.ctx.features & 8 /* BigInt */, 'Unsupported type "BigInt"');
|
|
803
|
+
return new SerovalBigIntNode(current);
|
|
788
804
|
case "object": {
|
|
789
805
|
if (!current) {
|
|
790
806
|
return NULL_NODE;
|
|
791
807
|
}
|
|
792
808
|
const id = createRef(this.ctx, current, true);
|
|
793
809
|
if (this.ctx.markedRefs[id]) {
|
|
794
|
-
return
|
|
810
|
+
return new SerovalReferenceNode(id);
|
|
795
811
|
}
|
|
796
812
|
if (Array.isArray(current)) {
|
|
797
813
|
return this.generateArrayNode(id, current);
|
|
798
814
|
}
|
|
799
815
|
switch (current.constructor) {
|
|
800
816
|
case Date:
|
|
801
|
-
return
|
|
817
|
+
return new SerovalDateNode(id, current);
|
|
802
818
|
case RegExp:
|
|
803
|
-
return
|
|
819
|
+
return new SerovalRegExpNode(id, current);
|
|
804
820
|
case Promise:
|
|
805
821
|
return this.generatePromiseNode(id, current);
|
|
806
822
|
case Int8Array:
|
|
@@ -812,10 +828,15 @@ var AsyncParser = class {
|
|
|
812
828
|
case Uint8ClampedArray:
|
|
813
829
|
case Float32Array:
|
|
814
830
|
case Float64Array:
|
|
815
|
-
|
|
831
|
+
assert(this.ctx.features & 1024 /* TypedArray */, `Unsupported value type "${current.constructor.name}"`);
|
|
832
|
+
return new SerovalTypedArrayNode(id, current);
|
|
816
833
|
case BigInt64Array:
|
|
817
834
|
case BigUint64Array:
|
|
818
|
-
|
|
835
|
+
assert(
|
|
836
|
+
this.ctx.features & 2048 /* BigIntTypedArray */,
|
|
837
|
+
`Unsupported value type "${current.constructor.name}"`
|
|
838
|
+
);
|
|
839
|
+
return new SerovalBigIntTypedArrayNode(id, current);
|
|
819
840
|
case Map:
|
|
820
841
|
return this.generateMapNode(id, current);
|
|
821
842
|
case Set:
|
|
@@ -1278,17 +1299,7 @@ var SyncParser = class {
|
|
|
1278
1299
|
return nodes;
|
|
1279
1300
|
}
|
|
1280
1301
|
generateArrayNode(id, current) {
|
|
1281
|
-
return
|
|
1282
|
-
t: 7 /* Array */,
|
|
1283
|
-
i: id,
|
|
1284
|
-
a: this.generateNodeList(current),
|
|
1285
|
-
s: void 0,
|
|
1286
|
-
l: void 0,
|
|
1287
|
-
m: void 0,
|
|
1288
|
-
c: void 0,
|
|
1289
|
-
d: void 0,
|
|
1290
|
-
n: void 0
|
|
1291
|
-
};
|
|
1302
|
+
return new SerovalArrayNode(id, this.generateNodeList(current));
|
|
1292
1303
|
}
|
|
1293
1304
|
generateMapNode(id, current) {
|
|
1294
1305
|
assert(this.ctx.features & 16 /* Map */, 'Unsupported type "Map"');
|
|
@@ -1314,17 +1325,7 @@ var SyncParser = class {
|
|
|
1314
1325
|
keyNodes[nodeSize + i] = this.parse(deferredKey[i]);
|
|
1315
1326
|
valueNodes[nodeSize + i] = this.parse(deferredValue[i]);
|
|
1316
1327
|
}
|
|
1317
|
-
return
|
|
1318
|
-
t: 6 /* Map */,
|
|
1319
|
-
i: id,
|
|
1320
|
-
a: void 0,
|
|
1321
|
-
s: void 0,
|
|
1322
|
-
l: void 0,
|
|
1323
|
-
m: void 0,
|
|
1324
|
-
c: void 0,
|
|
1325
|
-
d: { k: keyNodes, v: valueNodes, s: len },
|
|
1326
|
-
n: void 0
|
|
1327
|
-
};
|
|
1328
|
+
return new SerovalMapNode(id, new SerovalMapRecordNode(keyNodes, valueNodes, len));
|
|
1328
1329
|
}
|
|
1329
1330
|
generateSetNode(id, current) {
|
|
1330
1331
|
assert(this.ctx.features & 256 /* Set */, 'Unsupported type "Set"');
|
|
@@ -1343,17 +1344,7 @@ var SyncParser = class {
|
|
|
1343
1344
|
for (let i = 0; i < deferredSize; i++) {
|
|
1344
1345
|
nodes[nodeSize + i] = this.parse(deferred[i]);
|
|
1345
1346
|
}
|
|
1346
|
-
return
|
|
1347
|
-
t: 5 /* Set */,
|
|
1348
|
-
i: id,
|
|
1349
|
-
a: nodes,
|
|
1350
|
-
s: void 0,
|
|
1351
|
-
l: void 0,
|
|
1352
|
-
m: void 0,
|
|
1353
|
-
c: void 0,
|
|
1354
|
-
d: void 0,
|
|
1355
|
-
n: void 0
|
|
1356
|
-
};
|
|
1347
|
+
return new SerovalSetNode(id, nodes);
|
|
1357
1348
|
}
|
|
1358
1349
|
generateProperties(properties) {
|
|
1359
1350
|
const keys = Object.keys(properties);
|
|
@@ -1390,64 +1381,36 @@ var SyncParser = class {
|
|
|
1390
1381
|
generateIterableNode(id, current) {
|
|
1391
1382
|
assert(this.ctx.features & 512 /* SymbolIterator */, 'Unsupported type "Iterable"');
|
|
1392
1383
|
const options = getIterableOptions(current);
|
|
1393
|
-
return
|
|
1394
|
-
|
|
1395
|
-
i: id,
|
|
1396
|
-
s: void 0,
|
|
1397
|
-
l: void 0,
|
|
1398
|
-
m: void 0,
|
|
1399
|
-
c: void 0,
|
|
1384
|
+
return new SerovalIterableNode(
|
|
1385
|
+
id,
|
|
1400
1386
|
// Parse options first before the items
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
};
|
|
1387
|
+
options ? this.generateProperties(options) : void 0,
|
|
1388
|
+
this.generateNodeList(Array.from(current))
|
|
1389
|
+
);
|
|
1405
1390
|
}
|
|
1406
1391
|
generateObjectNode(id, current, empty) {
|
|
1407
1392
|
if (Symbol.iterator in current) {
|
|
1408
1393
|
return this.generateIterableNode(id, current);
|
|
1409
1394
|
}
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
l: void 0,
|
|
1415
|
-
m: void 0,
|
|
1416
|
-
c: void 0,
|
|
1417
|
-
d: this.generateProperties(current),
|
|
1418
|
-
a: void 0,
|
|
1419
|
-
n: void 0
|
|
1420
|
-
};
|
|
1395
|
+
if (empty) {
|
|
1396
|
+
return new SerovalNullConstructorNode(id, this.generateProperties(current));
|
|
1397
|
+
}
|
|
1398
|
+
return new SerovalObjectNode(id, this.generateProperties(current));
|
|
1421
1399
|
}
|
|
1422
1400
|
generateAggregateErrorNode(id, current) {
|
|
1423
1401
|
const options = getErrorOptions(current);
|
|
1424
1402
|
const optionsNode = options ? this.generateProperties(options) : void 0;
|
|
1425
|
-
return
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
m: current.message,
|
|
1432
|
-
c: void 0,
|
|
1433
|
-
d: optionsNode,
|
|
1434
|
-
n: this.parse(current.errors)
|
|
1435
|
-
};
|
|
1403
|
+
return new SerovalAggregateErrorNode(
|
|
1404
|
+
id,
|
|
1405
|
+
current.message,
|
|
1406
|
+
optionsNode,
|
|
1407
|
+
this.parse(current.errors)
|
|
1408
|
+
);
|
|
1436
1409
|
}
|
|
1437
1410
|
generateErrorNode(id, current) {
|
|
1438
1411
|
const options = getErrorOptions(current);
|
|
1439
1412
|
const optionsNode = options ? this.generateProperties(options) : void 0;
|
|
1440
|
-
return
|
|
1441
|
-
t: 11 /* Error */,
|
|
1442
|
-
i: id,
|
|
1443
|
-
a: void 0,
|
|
1444
|
-
s: void 0,
|
|
1445
|
-
l: void 0,
|
|
1446
|
-
m: current.message,
|
|
1447
|
-
c: getErrorConstructor(current),
|
|
1448
|
-
d: optionsNode,
|
|
1449
|
-
n: void 0
|
|
1450
|
-
};
|
|
1413
|
+
return new SerovalErrorNode(id, getErrorConstructor(current), current.message, optionsNode);
|
|
1451
1414
|
}
|
|
1452
1415
|
parse(current) {
|
|
1453
1416
|
switch (typeof current) {
|
|
@@ -1456,36 +1419,37 @@ var SyncParser = class {
|
|
|
1456
1419
|
case "undefined":
|
|
1457
1420
|
return UNDEFINED_NODE;
|
|
1458
1421
|
case "string":
|
|
1459
|
-
return
|
|
1422
|
+
return new SerovalPrimitiveNode(quote(current));
|
|
1460
1423
|
case "number":
|
|
1461
1424
|
if (Object.is(current, -0)) {
|
|
1462
1425
|
return NEG_ZERO_NODE;
|
|
1463
1426
|
}
|
|
1464
1427
|
if (Object.is(current, Infinity)) {
|
|
1465
|
-
return
|
|
1428
|
+
return INFINITY_NODE;
|
|
1466
1429
|
}
|
|
1467
1430
|
if (Object.is(current, -Infinity)) {
|
|
1468
|
-
return
|
|
1431
|
+
return NEG_INFINITY_NODE;
|
|
1469
1432
|
}
|
|
1470
|
-
return
|
|
1433
|
+
return new SerovalPrimitiveNode(current);
|
|
1471
1434
|
case "bigint":
|
|
1472
|
-
|
|
1435
|
+
assert(this.ctx.features & 8 /* BigInt */, 'Unsupported type "BigInt"');
|
|
1436
|
+
return new SerovalBigIntNode(current);
|
|
1473
1437
|
case "object": {
|
|
1474
1438
|
if (!current) {
|
|
1475
1439
|
return NULL_NODE;
|
|
1476
1440
|
}
|
|
1477
1441
|
const id = createRef(this.ctx, current, true);
|
|
1478
1442
|
if (this.ctx.markedRefs[id]) {
|
|
1479
|
-
return
|
|
1443
|
+
return new SerovalReferenceNode(id);
|
|
1480
1444
|
}
|
|
1481
1445
|
if (Array.isArray(current)) {
|
|
1482
1446
|
return this.generateArrayNode(id, current);
|
|
1483
1447
|
}
|
|
1484
1448
|
switch (current.constructor) {
|
|
1485
1449
|
case Date:
|
|
1486
|
-
return
|
|
1450
|
+
return new SerovalDateNode(id, current);
|
|
1487
1451
|
case RegExp:
|
|
1488
|
-
return
|
|
1452
|
+
return new SerovalRegExpNode(id, current);
|
|
1489
1453
|
case Int8Array:
|
|
1490
1454
|
case Int16Array:
|
|
1491
1455
|
case Int32Array:
|
|
@@ -1495,10 +1459,15 @@ var SyncParser = class {
|
|
|
1495
1459
|
case Uint8ClampedArray:
|
|
1496
1460
|
case Float32Array:
|
|
1497
1461
|
case Float64Array:
|
|
1498
|
-
|
|
1462
|
+
assert(this.ctx.features & 1024 /* TypedArray */, `Unsupported value type "${current.constructor.name}"`);
|
|
1463
|
+
return new SerovalTypedArrayNode(id, current);
|
|
1499
1464
|
case BigInt64Array:
|
|
1500
1465
|
case BigUint64Array:
|
|
1501
|
-
|
|
1466
|
+
assert(
|
|
1467
|
+
this.ctx.features & 2048 /* BigIntTypedArray */,
|
|
1468
|
+
`Unsupported value type "${current.constructor.name}"`
|
|
1469
|
+
);
|
|
1470
|
+
return new SerovalBigIntTypedArrayNode(id, current);
|
|
1502
1471
|
case Map:
|
|
1503
1472
|
return this.generateMapNode(id, current);
|
|
1504
1473
|
case Set:
|
|
@@ -1571,16 +1540,16 @@ function finalize(ctx, rootID, isObject, result) {
|
|
|
1571
1540
|
return result;
|
|
1572
1541
|
}
|
|
1573
1542
|
function serialize(source, options) {
|
|
1574
|
-
const ctx =
|
|
1543
|
+
const ctx = new ParserContext(options);
|
|
1575
1544
|
const [tree, rootID, isObject] = parseSync(ctx, source);
|
|
1576
|
-
const serial =
|
|
1545
|
+
const serial = new SerializationContext(ctx);
|
|
1577
1546
|
const result = serializeTree(serial, tree);
|
|
1578
1547
|
return finalize(serial, rootID, isObject, result);
|
|
1579
1548
|
}
|
|
1580
1549
|
async function serializeAsync(source, options) {
|
|
1581
|
-
const ctx =
|
|
1550
|
+
const ctx = new ParserContext(options);
|
|
1582
1551
|
const [tree, rootID, isObject] = await parseAsync(ctx, source);
|
|
1583
|
-
const serial =
|
|
1552
|
+
const serial = new SerializationContext(ctx);
|
|
1584
1553
|
const result = serializeTree(serial, tree);
|
|
1585
1554
|
return finalize(serial, rootID, isObject, result);
|
|
1586
1555
|
}
|
|
@@ -1588,7 +1557,7 @@ function deserialize(source) {
|
|
|
1588
1557
|
return (0, eval)(source);
|
|
1589
1558
|
}
|
|
1590
1559
|
function toJSON(source, options) {
|
|
1591
|
-
const ctx =
|
|
1560
|
+
const ctx = new ParserContext(options);
|
|
1592
1561
|
const [tree, root, isObject] = parseSync(ctx, source);
|
|
1593
1562
|
return JSON.stringify([
|
|
1594
1563
|
tree,
|
|
@@ -1599,7 +1568,7 @@ function toJSON(source, options) {
|
|
|
1599
1568
|
]);
|
|
1600
1569
|
}
|
|
1601
1570
|
async function toJSONAsync(source, options) {
|
|
1602
|
-
const ctx =
|
|
1571
|
+
const ctx = new ParserContext(options);
|
|
1603
1572
|
const [tree, root, isObject] = await parseAsync(ctx, source);
|
|
1604
1573
|
return JSON.stringify([
|
|
1605
1574
|
tree,
|
|
@@ -1611,7 +1580,7 @@ async function toJSONAsync(source, options) {
|
|
|
1611
1580
|
}
|
|
1612
1581
|
function compileJSON(source) {
|
|
1613
1582
|
const parsed = JSON.parse(source);
|
|
1614
|
-
const serial =
|
|
1583
|
+
const serial = new SerializationContext({
|
|
1615
1584
|
features: parsed[3],
|
|
1616
1585
|
markedRefs: parsed[4]
|
|
1617
1586
|
});
|