seroval 0.11.0 → 0.11.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.
@@ -439,8 +439,7 @@ function createStringNode(value) {
439
439
  o: void 0
440
440
  };
441
441
  }
442
- function createBigIntNode(ctx, current) {
443
- assert(ctx.features & 8 /* BigInt */, new UnsupportedTypeError(current));
442
+ function createBigIntNode(current) {
444
443
  return {
445
444
  t: 3 /* BigInt */,
446
445
  i: void 0,
@@ -526,8 +525,7 @@ function createArrayBufferNode(id, current) {
526
525
  o: void 0
527
526
  };
528
527
  }
529
- function createWKSymbolNode(ctx, id, current) {
530
- assert(ctx.features & 1024 /* Symbol */, new UnsupportedTypeError(current));
528
+ function createWKSymbolNode(id, current) {
531
529
  assert(current in INV_SYMBOL_REF, new Error("Only well-known symbols are supported."));
532
530
  return {
533
531
  t: 17 /* WKSymbol */,
@@ -625,7 +623,7 @@ function createSymbolNode(ctx, current) {
625
623
  if (hasReferenceID(current)) {
626
624
  return createReferenceNode(id, current);
627
625
  }
628
- return createWKSymbolNode(ctx, id, current);
626
+ return createWKSymbolNode(id, current);
629
627
  }
630
628
  function createFunctionNode(ctx, current) {
631
629
  assert(hasReferenceID(current), new Error("Cannot serialize function without reference ID."));
@@ -702,30 +700,53 @@ function getErrorOptions(ctx, error) {
702
700
  }
703
701
  return options;
704
702
  }
705
- function isIterable(value) {
703
+ function isIterable(ctx, value) {
706
704
  if (!value || typeof value !== "object") {
707
705
  return false;
708
706
  }
709
707
  if (Array.isArray(value)) {
710
708
  return false;
711
709
  }
712
- switch (value.constructor) {
713
- case Map:
714
- case Set:
715
- case Int8Array:
716
- case Int16Array:
717
- case Int32Array:
718
- case Uint8Array:
719
- case Uint16Array:
720
- case Uint32Array:
721
- case Uint8ClampedArray:
722
- case Float32Array:
723
- case Float64Array:
724
- case BigInt64Array:
725
- case BigUint64Array:
726
- return false;
727
- default:
728
- break;
710
+ const currentClass = value.constructor;
711
+ if (ctx.features & 2048 /* TypedArray */) {
712
+ switch (currentClass) {
713
+ case Int8Array:
714
+ case Int16Array:
715
+ case Int32Array:
716
+ case Uint8Array:
717
+ case Uint16Array:
718
+ case Uint32Array:
719
+ case Uint8ClampedArray:
720
+ case Float32Array:
721
+ case Float64Array:
722
+ return false;
723
+ default:
724
+ break;
725
+ }
726
+ }
727
+ if ((ctx.features & BIGINT_FLAG) === BIGINT_FLAG) {
728
+ switch (currentClass) {
729
+ case BigInt64Array:
730
+ case BigUint64Array:
731
+ return false;
732
+ default:
733
+ break;
734
+ }
735
+ }
736
+ if (ctx.features & 32 /* Map */ && currentClass === Map) {
737
+ return false;
738
+ }
739
+ if (ctx.features & 512 /* Set */ && currentClass === Set) {
740
+ return false;
741
+ }
742
+ if (ctx.features & 8192 /* WebAPI */) {
743
+ switch (currentClass) {
744
+ case Headers:
745
+ case File:
746
+ return false;
747
+ default:
748
+ break;
749
+ }
729
750
  }
730
751
  return Symbol.iterator in value;
731
752
  }
@@ -777,7 +798,6 @@ function getObjectFlag(obj) {
777
798
 
778
799
  // src/core/tree/web-api.ts
779
800
  async function createBlobNode(ctx, id, current) {
780
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
781
801
  return {
782
802
  t: 23 /* Blob */,
783
803
  i: id,
@@ -794,7 +814,6 @@ async function createBlobNode(ctx, id, current) {
794
814
  };
795
815
  }
796
816
  async function createFileNode(ctx, id, current) {
797
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
798
817
  return {
799
818
  t: 24 /* File */,
800
819
  i: id,
@@ -918,7 +937,7 @@ async function generateNodeList(ctx, current) {
918
937
  for (let i = 0; i < size; i++) {
919
938
  if (i in current) {
920
939
  item = current[i];
921
- if (isIterable(item)) {
940
+ if (isIterable(ctx, item)) {
922
941
  deferred[i] = item;
923
942
  } else {
924
943
  nodes[i] = await parseAsync(ctx, item);
@@ -957,7 +976,7 @@ async function generateMapNode(ctx, id, current) {
957
976
  let deferredSize = 0;
958
977
  let nodeSize = 0;
959
978
  for (const [key, value] of current.entries()) {
960
- if (isIterable(key) || isIterable(value)) {
979
+ if (isIterable(ctx, key) || isIterable(ctx, value)) {
961
980
  deferredKey[deferredSize] = key;
962
981
  deferredValue[deferredSize] = value;
963
982
  deferredSize++;
@@ -993,7 +1012,7 @@ async function generateSetNode(ctx, id, current) {
993
1012
  let deferredSize = 0;
994
1013
  let nodeSize = 0;
995
1014
  for (const item of current.keys()) {
996
- if (isIterable(item)) {
1015
+ if (isIterable(ctx, item)) {
997
1016
  deferred[deferredSize++] = item;
998
1017
  } else {
999
1018
  nodes[nodeSize++] = await parseAsync(ctx, item);
@@ -1031,7 +1050,7 @@ async function generateProperties(ctx, properties) {
1031
1050
  for (const key of keys) {
1032
1051
  item = properties[key];
1033
1052
  escaped = serializeString(key);
1034
- if (isIterable(item)) {
1053
+ if (isIterable(ctx, item)) {
1035
1054
  deferredKeys[deferredSize] = escaped;
1036
1055
  deferredValues[deferredSize] = item;
1037
1056
  deferredSize++;
@@ -1077,7 +1096,7 @@ async function generatePlainProperties(ctx, properties) {
1077
1096
  for (const key of keys) {
1078
1097
  item = properties[key];
1079
1098
  escaped = serializeString(key);
1080
- if (isIterable(item)) {
1099
+ if (isIterable(ctx, item)) {
1081
1100
  deferredKeys[deferredSize] = escaped;
1082
1101
  deferredValues[deferredSize] = item;
1083
1102
  deferredSize++;
@@ -1430,7 +1449,7 @@ async function parseObject(ctx, current) {
1430
1449
  async function parseAsync(ctx, current) {
1431
1450
  const t = typeof current;
1432
1451
  if (ctx.features & 8 /* BigInt */ && t === "bigint") {
1433
- return createBigIntNode(ctx, current);
1452
+ return createBigIntNode(current);
1434
1453
  }
1435
1454
  switch (t) {
1436
1455
  case "boolean":
@@ -2476,7 +2495,7 @@ function generateNodeList2(ctx, current) {
2476
2495
  for (let i = 0; i < size; i++) {
2477
2496
  if (i in current) {
2478
2497
  item = current[i];
2479
- if (isIterable(item)) {
2498
+ if (isIterable(ctx, item)) {
2480
2499
  deferred[i] = item;
2481
2500
  } else {
2482
2501
  nodes[i] = parseSync(ctx, item);
@@ -2515,7 +2534,7 @@ function generateMapNode2(ctx, id, current) {
2515
2534
  let deferredSize = 0;
2516
2535
  let nodeSize = 0;
2517
2536
  for (const [key, value] of current.entries()) {
2518
- if (isIterable(key) || isIterable(value)) {
2537
+ if (isIterable(ctx, key) || isIterable(ctx, value)) {
2519
2538
  deferredKey[deferredSize] = key;
2520
2539
  deferredValue[deferredSize] = value;
2521
2540
  deferredSize++;
@@ -2551,7 +2570,7 @@ function generateSetNode2(ctx, id, current) {
2551
2570
  let deferredSize = 0;
2552
2571
  let nodeSize = 0;
2553
2572
  for (const item of current.keys()) {
2554
- if (isIterable(item)) {
2573
+ if (isIterable(ctx, item)) {
2555
2574
  deferred[deferredSize++] = item;
2556
2575
  } else {
2557
2576
  nodes[nodeSize++] = parseSync(ctx, item);
@@ -2589,7 +2608,7 @@ function generateProperties2(ctx, properties) {
2589
2608
  for (const key of keys) {
2590
2609
  item = properties[key];
2591
2610
  escaped = serializeString(key);
2592
- if (isIterable(item)) {
2611
+ if (isIterable(ctx, item)) {
2593
2612
  deferredKeys[deferredSize] = escaped;
2594
2613
  deferredValues[deferredSize] = item;
2595
2614
  deferredSize++;
@@ -2632,7 +2651,7 @@ function generatePlainProperties2(ctx, properties) {
2632
2651
  for (const key of keys) {
2633
2652
  item = properties[key];
2634
2653
  escaped = serializeString(key);
2635
- if (isIterable(item)) {
2654
+ if (isIterable(ctx, item)) {
2636
2655
  deferredKeys[deferredSize] = escaped;
2637
2656
  deferredValues[deferredSize] = item;
2638
2657
  deferredSize++;
@@ -2911,7 +2930,7 @@ function parseObject2(ctx, current) {
2911
2930
  function parseSync(ctx, current) {
2912
2931
  const t = typeof current;
2913
2932
  if (ctx.features & 8 /* BigInt */ && t === "bigint") {
2914
- return createBigIntNode(ctx, current);
2933
+ return createBigIntNode(current);
2915
2934
  }
2916
2935
  switch (t) {
2917
2936
  case "boolean":
@@ -3081,7 +3100,6 @@ function serializeArrayBuffer3(ctx, current) {
3081
3100
  return createArrayBufferNode(newID, current);
3082
3101
  }
3083
3102
  function createTypedArrayNode2(ctx, id, current) {
3084
- assert(ctx.features & 2048 /* TypedArray */, new UnsupportedTypeError(current));
3085
3103
  return {
3086
3104
  t: 15 /* TypedArray */,
3087
3105
  i: id,
@@ -3097,12 +3115,7 @@ function createTypedArrayNode2(ctx, id, current) {
3097
3115
  o: void 0
3098
3116
  };
3099
3117
  }
3100
- var BIGINT_FLAG2 = 4096 /* BigIntTypedArray */ | 8 /* BigInt */;
3101
3118
  function createBigIntTypedArrayNode2(ctx, id, current) {
3102
- assert(
3103
- (ctx.features & BIGINT_FLAG2) === BIGINT_FLAG2,
3104
- new UnsupportedTypeError(current)
3105
- );
3106
3119
  return {
3107
3120
  t: 16 /* BigIntTypedArray */,
3108
3121
  i: id,
@@ -3144,7 +3157,7 @@ function createSymbolNode2(ctx, current) {
3144
3157
  if (hasReferenceID(current)) {
3145
3158
  return createReferenceNode(newID, current);
3146
3159
  }
3147
- return createWKSymbolNode(ctx, newID, current);
3160
+ return createWKSymbolNode(newID, current);
3148
3161
  }
3149
3162
  function createFunctionNode2(ctx, current) {
3150
3163
  assert(hasReferenceID(current), new Error("Cannot serialize function without reference ID."));
@@ -3159,7 +3172,6 @@ function createFunctionNode2(ctx, current) {
3159
3172
 
3160
3173
  // src/core/cross/web-api.ts
3161
3174
  async function createBlobNode2(ctx, id, current) {
3162
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
3163
3175
  return {
3164
3176
  t: 23 /* Blob */,
3165
3177
  i: id,
@@ -3176,7 +3188,6 @@ async function createBlobNode2(ctx, id, current) {
3176
3188
  };
3177
3189
  }
3178
3190
  async function createFileNode2(ctx, id, current) {
3179
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
3180
3191
  return {
3181
3192
  t: 24 /* File */,
3182
3193
  i: id,
@@ -3202,7 +3213,7 @@ async function generateNodeList3(ctx, current) {
3202
3213
  for (let i = 0; i < size; i++) {
3203
3214
  if (i in current) {
3204
3215
  item = current[i];
3205
- if (isIterable(item)) {
3216
+ if (isIterable(ctx, item)) {
3206
3217
  deferred[i] = item;
3207
3218
  } else {
3208
3219
  nodes[i] = await crossParseAsync(ctx, item);
@@ -3241,7 +3252,7 @@ async function generateMapNode3(ctx, id, current) {
3241
3252
  let deferredSize = 0;
3242
3253
  let nodeSize = 0;
3243
3254
  for (const [key, value] of current.entries()) {
3244
- if (isIterable(key) || isIterable(value)) {
3255
+ if (isIterable(ctx, key) || isIterable(ctx, value)) {
3245
3256
  deferredKey[deferredSize] = key;
3246
3257
  deferredValue[deferredSize] = value;
3247
3258
  deferredSize++;
@@ -3277,7 +3288,7 @@ async function generateSetNode3(ctx, id, current) {
3277
3288
  let deferredSize = 0;
3278
3289
  let nodeSize = 0;
3279
3290
  for (const item of current.keys()) {
3280
- if (isIterable(item)) {
3291
+ if (isIterable(ctx, item)) {
3281
3292
  deferred[deferredSize++] = item;
3282
3293
  } else {
3283
3294
  nodes[nodeSize++] = await crossParseAsync(ctx, item);
@@ -3315,7 +3326,7 @@ async function generateProperties3(ctx, properties) {
3315
3326
  for (const key of keys) {
3316
3327
  item = properties[key];
3317
3328
  escaped = serializeString(key);
3318
- if (isIterable(item)) {
3329
+ if (isIterable(ctx, item)) {
3319
3330
  deferredKeys[deferredSize] = escaped;
3320
3331
  deferredValues[deferredSize] = item;
3321
3332
  deferredSize++;
@@ -3361,7 +3372,7 @@ async function generatePlainProperties3(ctx, properties) {
3361
3372
  for (const key of keys) {
3362
3373
  item = properties[key];
3363
3374
  escaped = serializeString(key);
3364
- if (isIterable(item)) {
3375
+ if (isIterable(ctx, item)) {
3365
3376
  deferredKeys[deferredSize] = escaped;
3366
3377
  deferredValues[deferredSize] = item;
3367
3378
  deferredSize++;
@@ -3716,7 +3727,7 @@ async function parseObject3(ctx, current) {
3716
3727
  async function crossParseAsync(ctx, current) {
3717
3728
  const t = typeof current;
3718
3729
  if (ctx.features & 8 /* BigInt */ && t === "bigint") {
3719
- return createBigIntNode(ctx, current);
3730
+ return createBigIntNode(current);
3720
3731
  }
3721
3732
  switch (t) {
3722
3733
  case "boolean":
@@ -4328,7 +4339,7 @@ function generateNodeList4(ctx, current) {
4328
4339
  for (let i = 0; i < size; i++) {
4329
4340
  if (i in current) {
4330
4341
  item = current[i];
4331
- if (isIterable(item)) {
4342
+ if (isIterable(ctx, item)) {
4332
4343
  deferred[i] = item;
4333
4344
  } else {
4334
4345
  nodes[i] = crossParseStream(ctx, item);
@@ -4367,7 +4378,7 @@ function generateMapNode4(ctx, id, current) {
4367
4378
  let deferredSize = 0;
4368
4379
  let nodeSize = 0;
4369
4380
  for (const [key, value] of current.entries()) {
4370
- if (isIterable(key) || isIterable(value)) {
4381
+ if (isIterable(ctx, key) || isIterable(ctx, value)) {
4371
4382
  deferredKey[deferredSize] = key;
4372
4383
  deferredValue[deferredSize] = value;
4373
4384
  deferredSize++;
@@ -4403,7 +4414,7 @@ function generateSetNode4(ctx, id, current) {
4403
4414
  let deferredSize = 0;
4404
4415
  let nodeSize = 0;
4405
4416
  for (const item of current.keys()) {
4406
- if (isIterable(item)) {
4417
+ if (isIterable(ctx, item)) {
4407
4418
  deferred[deferredSize++] = item;
4408
4419
  } else {
4409
4420
  nodes[nodeSize++] = crossParseStream(ctx, item);
@@ -4441,7 +4452,7 @@ function generateProperties4(ctx, properties) {
4441
4452
  for (const key of keys) {
4442
4453
  item = properties[key];
4443
4454
  escaped = serializeString(key);
4444
- if (isIterable(item)) {
4455
+ if (isIterable(ctx, item)) {
4445
4456
  deferredKeys[deferredSize] = escaped;
4446
4457
  deferredValues[deferredSize] = item;
4447
4458
  deferredSize++;
@@ -4487,7 +4498,7 @@ function generatePlainProperties4(ctx, properties) {
4487
4498
  for (const key of keys) {
4488
4499
  item = properties[key];
4489
4500
  escaped = serializeString(key);
4490
- if (isIterable(item)) {
4501
+ if (isIterable(ctx, item)) {
4491
4502
  deferredKeys[deferredSize] = escaped;
4492
4503
  deferredValues[deferredSize] = item;
4493
4504
  deferredSize++;
@@ -4672,52 +4683,13 @@ function generateBoxedNode4(ctx, id, current) {
4672
4683
  o: void 0
4673
4684
  };
4674
4685
  }
4675
- function generateReadableStreamNode(ctx, id, current) {
4676
- const reader = current.getReader();
4677
- pushPendingState(ctx);
4678
- function push() {
4679
- reader.read().then(
4680
- (data) => {
4681
- if (ctx.alive) {
4682
- if (data.done) {
4683
- ctx.onParse({
4684
- t: 33 /* ReadableStreamClose */,
4685
- i: id,
4686
- s: void 0,
4687
- l: void 0,
4688
- c: void 0,
4689
- m: void 0,
4690
- p: void 0,
4691
- e: void 0,
4692
- a: void 0,
4693
- f: void 0,
4694
- b: void 0,
4695
- o: void 0
4696
- }, false);
4697
- popPendingState(ctx);
4698
- } else {
4699
- ctx.onParse({
4700
- t: 32 /* ReadableStreamEnqueue */,
4701
- i: id,
4702
- s: void 0,
4703
- l: void 0,
4704
- c: void 0,
4705
- m: void 0,
4706
- p: void 0,
4707
- e: void 0,
4708
- a: void 0,
4709
- f: crossParseStream(ctx, data.value),
4710
- b: void 0,
4711
- o: void 0
4712
- }, false);
4713
- push();
4714
- }
4715
- }
4716
- },
4717
- (value) => {
4718
- if (ctx.alive) {
4686
+ function pushReadableStreamState(ctx, id, reader) {
4687
+ reader.read().then(
4688
+ (data) => {
4689
+ if (ctx.alive) {
4690
+ if (data.done) {
4719
4691
  ctx.onParse({
4720
- t: 34 /* ReadableStreamError */,
4692
+ t: 33 /* ReadableStreamClose */,
4721
4693
  i: id,
4722
4694
  s: void 0,
4723
4695
  l: void 0,
@@ -4726,16 +4698,54 @@ function generateReadableStreamNode(ctx, id, current) {
4726
4698
  p: void 0,
4727
4699
  e: void 0,
4728
4700
  a: void 0,
4729
- f: crossParseStream(ctx, value),
4701
+ f: void 0,
4730
4702
  b: void 0,
4731
4703
  o: void 0
4732
4704
  }, false);
4733
4705
  popPendingState(ctx);
4706
+ } else {
4707
+ ctx.onParse({
4708
+ t: 32 /* ReadableStreamEnqueue */,
4709
+ i: id,
4710
+ s: void 0,
4711
+ l: void 0,
4712
+ c: void 0,
4713
+ m: void 0,
4714
+ p: void 0,
4715
+ e: void 0,
4716
+ a: void 0,
4717
+ f: crossParseStream(ctx, data.value),
4718
+ b: void 0,
4719
+ o: void 0
4720
+ }, false);
4721
+ pushReadableStreamState(ctx, id, reader);
4734
4722
  }
4735
4723
  }
4736
- );
4737
- }
4738
- push();
4724
+ },
4725
+ (value) => {
4726
+ if (ctx.alive) {
4727
+ ctx.onParse({
4728
+ t: 34 /* ReadableStreamError */,
4729
+ i: id,
4730
+ s: void 0,
4731
+ l: void 0,
4732
+ c: void 0,
4733
+ m: void 0,
4734
+ p: void 0,
4735
+ e: void 0,
4736
+ a: void 0,
4737
+ f: crossParseStream(ctx, value),
4738
+ b: void 0,
4739
+ o: void 0
4740
+ }, false);
4741
+ popPendingState(ctx);
4742
+ }
4743
+ }
4744
+ );
4745
+ }
4746
+ function generateReadableStreamNode(ctx, id, current) {
4747
+ pushPendingState(ctx);
4748
+ pushReadableStreamState(ctx, id, current.getReader());
4739
4749
  return {
4740
4750
  t: 31 /* ReadableStreamConstructor */,
4741
4751
  i: id,
@@ -4953,7 +4963,7 @@ function parseObject4(ctx, current) {
4953
4963
  function crossParseStream(ctx, current) {
4954
4964
  const t = typeof current;
4955
4965
  if (ctx.features & 8 /* BigInt */ && t === "bigint") {
4956
- return createBigIntNode(ctx, current);
4966
+ return createBigIntNode(current);
4957
4967
  }
4958
4968
  switch (t) {
4959
4969
  case "boolean":
@@ -4984,7 +4994,7 @@ function generateNodeList5(ctx, current) {
4984
4994
  for (let i = 0; i < size; i++) {
4985
4995
  if (i in current) {
4986
4996
  item = current[i];
4987
- if (isIterable(item)) {
4997
+ if (isIterable(ctx, item)) {
4988
4998
  deferred[i] = item;
4989
4999
  } else {
4990
5000
  nodes[i] = crossParseSync(ctx, item);
@@ -5023,7 +5033,7 @@ function generateMapNode5(ctx, id, current) {
5023
5033
  let deferredSize = 0;
5024
5034
  let nodeSize = 0;
5025
5035
  for (const [key, value] of current.entries()) {
5026
- if (isIterable(key) || isIterable(value)) {
5036
+ if (isIterable(ctx, key) || isIterable(ctx, value)) {
5027
5037
  deferredKey[deferredSize] = key;
5028
5038
  deferredValue[deferredSize] = value;
5029
5039
  deferredSize++;
@@ -5059,7 +5069,7 @@ function generateSetNode5(ctx, id, current) {
5059
5069
  let deferredSize = 0;
5060
5070
  let nodeSize = 0;
5061
5071
  for (const item of current.keys()) {
5062
- if (isIterable(item)) {
5072
+ if (isIterable(ctx, item)) {
5063
5073
  deferred[deferredSize++] = item;
5064
5074
  } else {
5065
5075
  nodes[nodeSize++] = crossParseSync(ctx, item);
@@ -5097,7 +5107,7 @@ function generateProperties5(ctx, properties) {
5097
5107
  for (const key of keys) {
5098
5108
  item = properties[key];
5099
5109
  escaped = serializeString(key);
5100
- if (isIterable(item)) {
5110
+ if (isIterable(ctx, item)) {
5101
5111
  deferredKeys[deferredSize] = escaped;
5102
5112
  deferredValues[deferredSize] = item;
5103
5113
  deferredSize++;
@@ -5139,7 +5149,7 @@ function generatePlainProperties5(ctx, properties) {
5139
5149
  for (const key of keys) {
5140
5150
  item = properties[key];
5141
5151
  escaped = serializeString(key);
5142
- if (isIterable(item)) {
5152
+ if (isIterable(ctx, item)) {
5143
5153
  deferredKeys[deferredSize] = escaped;
5144
5154
  deferredValues[deferredSize] = item;
5145
5155
  deferredSize++;
@@ -5420,7 +5430,7 @@ function parseObject5(ctx, current) {
5420
5430
  function crossParseSync(ctx, current) {
5421
5431
  const t = typeof current;
5422
5432
  if (ctx.features & 8 /* BigInt */ && t === "bigint") {
5423
- return createBigIntNode(ctx, current);
5433
+ return createBigIntNode(current);
5424
5434
  }
5425
5435
  switch (t) {
5426
5436
  case "boolean":