seroval 1.4.1 → 1.4.2

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.
Files changed (50) hide show
  1. package/dist/cjs/development/index.cjs +54 -11
  2. package/dist/cjs/development/index.cjs.map +2 -2
  3. package/dist/cjs/production/index.cjs +2 -2
  4. package/dist/esm/development/index.mjs +54 -11
  5. package/dist/esm/development/index.mjs.map +2 -2
  6. package/dist/esm/production/index.mjs +2 -2
  7. package/dist/types/core/base-primitives.d.ts.map +1 -1
  8. package/dist/types/core/context/async-parser.d.ts.map +1 -1
  9. package/dist/types/core/context/deserializer.d.ts.map +1 -1
  10. package/dist/types/core/context/parser.d.ts.map +1 -1
  11. package/dist/types/core/context/sync-parser.d.ts.map +1 -1
  12. package/dist/types/core/literals.d.ts.map +1 -1
  13. package/dist/types/core/node.d.ts +1 -1
  14. package/dist/types/core/node.d.ts.map +1 -1
  15. package/dist/types/core/types.d.ts +4 -0
  16. package/dist/types/core/types.d.ts.map +1 -1
  17. package/package.json +3 -2
  18. package/src/core/Serializer.ts +119 -0
  19. package/src/core/base-primitives.ts +514 -0
  20. package/src/core/compat.ts +23 -0
  21. package/src/core/constants.ts +201 -0
  22. package/src/core/constructors.ts +270 -0
  23. package/src/core/context/async-parser.ts +638 -0
  24. package/src/core/context/deserializer.ts +810 -0
  25. package/src/core/context/parser.ts +335 -0
  26. package/src/core/context/serializer.ts +1406 -0
  27. package/src/core/context/sync-parser.ts +907 -0
  28. package/src/core/cross/index.ts +188 -0
  29. package/src/core/errors.ts +196 -0
  30. package/src/core/function-string.ts +32 -0
  31. package/src/core/keys.ts +17 -0
  32. package/src/core/literals.ts +43 -0
  33. package/src/core/node.ts +40 -0
  34. package/src/core/opaque-reference.ts +9 -0
  35. package/src/core/plugin.ts +100 -0
  36. package/src/core/reference.ts +66 -0
  37. package/src/core/special-reference.ts +42 -0
  38. package/src/core/stream.ts +71 -0
  39. package/src/core/string.ts +86 -0
  40. package/src/core/symbols.ts +18 -0
  41. package/src/core/tree/index.ts +134 -0
  42. package/src/core/types.ts +366 -0
  43. package/src/core/utils/error.ts +73 -0
  44. package/src/core/utils/get-identifier.ts +18 -0
  45. package/src/core/utils/get-object-flag.ts +14 -0
  46. package/src/core/utils/is-valid-identifier.ts +12 -0
  47. package/src/core/utils/iterator-to-sequence.ts +44 -0
  48. package/src/core/utils/promise-to-result.ts +9 -0
  49. package/src/core/utils/typed-array.ts +56 -0
  50. package/src/index.ts +36 -0
@@ -174,7 +174,7 @@ var ERROR_CONSTRUCTOR = {
174
174
  };
175
175
 
176
176
  // src/core/node.ts
177
- function createSerovalNode(t, i, s, c, m, p, e, a, f, b, o) {
177
+ function createSerovalNode(t, i, s, c, m, p, e, a, f, b, o, l) {
178
178
  return {
179
179
  t,
180
180
  i,
@@ -186,7 +186,8 @@ function createSerovalNode(t, i, s, c, m, p, e, a, f, b, o) {
186
186
  a,
187
187
  f,
188
188
  b,
189
- o
189
+ o,
190
+ l
190
191
  };
191
192
  }
192
193
 
@@ -203,6 +204,7 @@ function createConstantNode(value) {
203
204
  NIL,
204
205
  NIL,
205
206
  NIL,
207
+ NIL,
206
208
  NIL
207
209
  );
208
210
  }
@@ -467,6 +469,7 @@ function createNumberNode(value) {
467
469
  NIL,
468
470
  NIL,
469
471
  NIL,
472
+ NIL,
470
473
  NIL
471
474
  );
472
475
  }
@@ -482,6 +485,7 @@ function createStringNode(value) {
482
485
  NIL,
483
486
  NIL,
484
487
  NIL,
488
+ NIL,
485
489
  NIL
486
490
  );
487
491
  }
@@ -497,6 +501,7 @@ function createBigIntNode(current) {
497
501
  NIL,
498
502
  NIL,
499
503
  NIL,
504
+ NIL,
500
505
  NIL
501
506
  );
502
507
  }
@@ -512,6 +517,7 @@ function createIndexedValueNode(id) {
512
517
  NIL,
513
518
  NIL,
514
519
  NIL,
520
+ NIL,
515
521
  NIL
516
522
  );
517
523
  }
@@ -528,6 +534,7 @@ function createDateNode(id, current) {
528
534
  NIL,
529
535
  NIL,
530
536
  NIL,
537
+ NIL,
531
538
  NIL
532
539
  );
533
540
  }
@@ -543,6 +550,7 @@ function createRegExpNode(id, current) {
543
550
  NIL,
544
551
  NIL,
545
552
  NIL,
553
+ NIL,
546
554
  NIL
547
555
  );
548
556
  }
@@ -558,6 +566,7 @@ function createWKSymbolNode(id, current) {
558
566
  NIL,
559
567
  NIL,
560
568
  NIL,
569
+ NIL,
561
570
  NIL
562
571
  );
563
572
  }
@@ -573,6 +582,7 @@ function createReferenceNode(id, ref) {
573
582
  NIL,
574
583
  NIL,
575
584
  NIL,
585
+ NIL,
576
586
  NIL
577
587
  );
578
588
  }
@@ -588,6 +598,7 @@ function createPluginNode(id, tag, value) {
588
598
  NIL,
589
599
  NIL,
590
600
  NIL,
601
+ NIL,
591
602
  NIL
592
603
  );
593
604
  }
@@ -603,7 +614,8 @@ function createArrayNode(id, current, parsedItems) {
603
614
  parsedItems,
604
615
  NIL,
605
616
  NIL,
606
- getObjectFlag(current)
617
+ getObjectFlag(current),
618
+ NIL
607
619
  );
608
620
  }
609
621
  function createBoxedNode(id, boxed) {
@@ -618,6 +630,7 @@ function createBoxedNode(id, boxed) {
618
630
  NIL,
619
631
  boxed,
620
632
  NIL,
633
+ NIL,
621
634
  NIL
622
635
  );
623
636
  }
@@ -633,7 +646,8 @@ function createTypedArrayNode(id, current, buffer) {
633
646
  NIL,
634
647
  buffer,
635
648
  current.byteOffset,
636
- NIL
649
+ NIL,
650
+ current.length
637
651
  );
638
652
  }
639
653
  function createBigIntTypedArrayNode(id, current, buffer) {
@@ -648,7 +662,8 @@ function createBigIntTypedArrayNode(id, current, buffer) {
648
662
  NIL,
649
663
  buffer,
650
664
  current.byteOffset,
651
- NIL
665
+ NIL,
666
+ current.byteLength
652
667
  );
653
668
  }
654
669
  function createDataViewNode(id, current, buffer) {
@@ -663,7 +678,8 @@ function createDataViewNode(id, current, buffer) {
663
678
  NIL,
664
679
  buffer,
665
680
  current.byteOffset,
666
- NIL
681
+ NIL,
682
+ current.byteLength
667
683
  );
668
684
  }
669
685
  function createErrorNode(id, current, options) {
@@ -678,6 +694,7 @@ function createErrorNode(id, current, options) {
678
694
  NIL,
679
695
  NIL,
680
696
  NIL,
697
+ NIL,
681
698
  NIL
682
699
  );
683
700
  }
@@ -693,6 +710,7 @@ function createAggregateErrorNode(id, current, options) {
693
710
  NIL,
694
711
  NIL,
695
712
  NIL,
713
+ NIL,
696
714
  NIL
697
715
  );
698
716
  }
@@ -708,6 +726,7 @@ function createSetNode(id, items) {
708
726
  items,
709
727
  NIL,
710
728
  NIL,
729
+ NIL,
711
730
  NIL
712
731
  );
713
732
  }
@@ -723,6 +742,7 @@ function createIteratorFactoryInstanceNode(factory, items) {
723
742
  [factory, items],
724
743
  NIL,
725
744
  NIL,
745
+ NIL,
726
746
  NIL
727
747
  );
728
748
  }
@@ -738,6 +758,7 @@ function createAsyncIteratorFactoryInstanceNode(factory, items) {
738
758
  [factory, items],
739
759
  NIL,
740
760
  NIL,
761
+ NIL,
741
762
  NIL
742
763
  );
743
764
  }
@@ -753,6 +774,7 @@ function createStreamConstructorNode(id, factory, sequence) {
753
774
  sequence,
754
775
  factory,
755
776
  NIL,
777
+ NIL,
756
778
  NIL
757
779
  );
758
780
  }
@@ -768,6 +790,7 @@ function createStreamNextNode(id, parsed) {
768
790
  NIL,
769
791
  parsed,
770
792
  NIL,
793
+ NIL,
771
794
  NIL
772
795
  );
773
796
  }
@@ -783,6 +806,7 @@ function createStreamThrowNode(id, parsed) {
783
806
  NIL,
784
807
  parsed,
785
808
  NIL,
809
+ NIL,
786
810
  NIL
787
811
  );
788
812
  }
@@ -798,6 +822,7 @@ function createStreamReturnNode(id, parsed) {
798
822
  NIL,
799
823
  parsed,
800
824
  NIL,
825
+ NIL,
801
826
  NIL
802
827
  );
803
828
  }
@@ -1306,6 +1331,7 @@ function parseSpecialReference(ctx, ref) {
1306
1331
  NIL,
1307
1332
  NIL,
1308
1333
  NIL,
1334
+ NIL,
1309
1335
  NIL
1310
1336
  );
1311
1337
  }
@@ -1325,6 +1351,7 @@ function parseIteratorFactory(ctx) {
1325
1351
  NIL,
1326
1352
  parseWellKnownSymbol(ctx, SYM_ITERATOR),
1327
1353
  NIL,
1354
+ NIL,
1328
1355
  NIL
1329
1356
  );
1330
1357
  }
@@ -1347,6 +1374,7 @@ function parseAsyncIteratorFactory(ctx) {
1347
1374
  ],
1348
1375
  NIL,
1349
1376
  NIL,
1377
+ NIL,
1350
1378
  NIL
1351
1379
  );
1352
1380
  }
@@ -1362,7 +1390,8 @@ function createObjectNode(id, current, empty, record) {
1362
1390
  NIL,
1363
1391
  NIL,
1364
1392
  NIL,
1365
- getObjectFlag(current)
1393
+ getObjectFlag(current),
1394
+ NIL
1366
1395
  );
1367
1396
  }
1368
1397
  function createMapNode(ctx, id, k, v) {
@@ -1377,6 +1406,7 @@ function createMapNode(ctx, id, k, v) {
1377
1406
  NIL,
1378
1407
  parseSpecialReference(ctx, 0 /* MapSentinel */),
1379
1408
  NIL,
1409
+ NIL,
1380
1410
  NIL
1381
1411
  );
1382
1412
  }
@@ -1392,6 +1422,7 @@ function createPromiseConstructorNode(ctx, id, resolver) {
1392
1422
  NIL,
1393
1423
  parseSpecialReference(ctx, 1 /* PromiseConstructor */),
1394
1424
  NIL,
1425
+ NIL,
1395
1426
  NIL
1396
1427
  );
1397
1428
  }
@@ -1412,6 +1443,7 @@ function createArrayBufferNode(ctx, id, current) {
1412
1443
  NIL,
1413
1444
  parseSpecialReference(ctx, 5 /* ArrayBufferConstructor */),
1414
1445
  NIL,
1446
+ NIL,
1415
1447
  NIL
1416
1448
  );
1417
1449
  }
@@ -1596,6 +1628,7 @@ async function parsePromise(ctx, depth, id, current) {
1596
1628
  NIL,
1597
1629
  await parseAsync(ctx, depth, result),
1598
1630
  NIL,
1631
+ NIL,
1599
1632
  NIL
1600
1633
  );
1601
1634
  }
@@ -2115,7 +2148,11 @@ function deserializeTypedArray(ctx, depth, node) {
2115
2148
  if (offset < 0 || offset > source.byteLength) {
2116
2149
  throw new SerovalMalformedNodeError(node);
2117
2150
  }
2118
- const result = assignIndexedValue(ctx, node.i, new construct(source, offset));
2151
+ const result = assignIndexedValue(
2152
+ ctx,
2153
+ node.i,
2154
+ new construct(source, offset, node.l)
2155
+ );
2119
2156
  return result;
2120
2157
  }
2121
2158
  function deserializeDataView(ctx, depth, node) {
@@ -2125,7 +2162,11 @@ function deserializeDataView(ctx, depth, node) {
2125
2162
  if (offset < 0 || offset > source.byteLength) {
2126
2163
  throw new SerovalMalformedNodeError(node);
2127
2164
  }
2128
- const result = assignIndexedValue(ctx, node.i, new DataView(source, offset));
2165
+ const result = assignIndexedValue(
2166
+ ctx,
2167
+ node.i,
2168
+ new DataView(source, offset, node.l)
2169
+ );
2129
2170
  return result;
2130
2171
  }
2131
2172
  function deserializeDictionary(ctx, depth, node, result) {
@@ -2917,10 +2958,10 @@ function serializeArrayBuffer(ctx, node) {
2917
2958
  return getConstructor(ctx, node.f) + '("' + node.s + '")';
2918
2959
  }
2919
2960
  function serializeTypedArray(ctx, node) {
2920
- return "new " + node.c + "(" + serialize(ctx, node.f) + "," + node.b + ")";
2961
+ return "new " + node.c + "(" + serialize(ctx, node.f) + "," + node.b + "," + node.l + ")";
2921
2962
  }
2922
2963
  function serializeDataView(ctx, node) {
2923
- return "new DataView(" + serialize(ctx, node.f) + "," + node.b + ")";
2964
+ return "new DataView(" + serialize(ctx, node.f) + "," + node.b + "," + node.l + ")";
2924
2965
  }
2925
2966
  function serializeAggregateError(ctx, node) {
2926
2967
  const id = node.i;
@@ -3448,6 +3489,7 @@ function handlePromiseSuccess(id, depth, data) {
3448
3489
  ],
3449
3490
  NIL,
3450
3491
  NIL,
3492
+ NIL,
3451
3493
  NIL
3452
3494
  )
3453
3495
  );
@@ -3475,6 +3517,7 @@ function handlePromiseFailure(id, depth, data) {
3475
3517
  ],
3476
3518
  NIL,
3477
3519
  NIL,
3520
+ NIL,
3478
3521
  NIL
3479
3522
  )
3480
3523
  );