seroval 1.6.4 → 1.6.6

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.
@@ -148,6 +148,8 @@ const NEG_INFINITY_NODE = /* @__PURE__ */ createConstantNode(6);
148
148
  const NAN_NODE = /* @__PURE__ */ createConstantNode(7);
149
149
  //#endregion
150
150
  //#region src/core/string.ts
151
+ const MIN_JSON_STRINGIFY_LENGTH = 64;
152
+ const JSON_ESCAPE_DIFFERENCES = /[\x00-\x07\x0b\x0e-\x1f<\u2028\u2029\ud800-\udfff]/;
151
153
  function serializeChar(str) {
152
154
  switch (str) {
153
155
  case "\"": return "\\\"";
@@ -164,6 +166,7 @@ function serializeChar(str) {
164
166
  }
165
167
  }
166
168
  function serializeString(str) {
169
+ if (str.length >= MIN_JSON_STRINGIFY_LENGTH && !JSON_ESCAPE_DIFFERENCES.test(str)) return JSON.stringify(str).slice(1, -1);
167
170
  let result = "";
168
171
  let lastPos = 0;
169
172
  let replacement;
@@ -524,7 +527,10 @@ const STREAM_CONSTRUCTOR = () => {
524
527
  let count = 0;
525
528
  const internal = {
526
529
  flush(value, mode, x) {
527
- for (x = 0; x < count; x++) if (listeners[x]) listeners[x][mode](value);
530
+ for (x = 0; x < count; x++) {
531
+ const listener = listeners[x];
532
+ if (listener) listener[mode](value);
533
+ }
528
534
  },
529
535
  up(listener, x, z, current) {
530
536
  for (x = 0, z = buffer.length; x < z; x++) {
@@ -533,16 +539,20 @@ const STREAM_CONSTRUCTOR = () => {
533
539
  else listener.next(current);
534
540
  }
535
541
  },
536
- on(listener, temp) {
542
+ on(listener, temp = 0) {
543
+ let subscribed = alive;
537
544
  if (alive) {
538
- temp = count++;
545
+ for (temp = 0; temp < count; temp++) if (!listeners[temp]) break;
546
+ if (temp === count) count++;
539
547
  listeners[temp] = listener;
540
548
  }
541
549
  internal.up(listener);
542
550
  return () => {
543
- if (alive) {
544
- listeners[temp] = listeners[count];
545
- listeners[count--] = void 0;
551
+ if (alive && subscribed) {
552
+ subscribed = false;
553
+ listeners[temp] = void 0;
554
+ while (count > 0 && !listeners[count - 1]) count--;
555
+ listeners.length = count;
546
556
  }
547
557
  };
548
558
  }
@@ -753,19 +763,35 @@ function isStream(value) {
753
763
  function createStream() {
754
764
  return STREAM_CONSTRUCTOR();
755
765
  }
756
- function createStreamFromAsyncIterable(iterable) {
766
+ function createStreamFromAsyncIterable(iterable, cleanups) {
757
767
  const stream = createStream();
758
768
  const iterator = iterable[SYM_ASYNC_ITERATOR]();
769
+ let cancelled = false;
770
+ let done = false;
771
+ cleanups === null || cleanups === void 0 || cleanups.push(() => {
772
+ if (!(done || cancelled)) {
773
+ cancelled = true;
774
+ Promise.resolve().then(() => {
775
+ var _iterator$return;
776
+ return (_iterator$return = iterator.return) === null || _iterator$return === void 0 ? void 0 : _iterator$return.call(iterator);
777
+ }).catch(() => {});
778
+ }
779
+ });
759
780
  async function push() {
760
781
  try {
761
- const value = await iterator.next();
762
- if (value.done) stream.return(value.value);
763
- else {
782
+ while (!cancelled) {
783
+ const value = await iterator.next();
784
+ if (cancelled) return;
785
+ if (value.done) {
786
+ done = true;
787
+ stream.return(value.value);
788
+ break;
789
+ }
764
790
  stream.next(value.value);
765
- await push();
766
791
  }
767
792
  } catch (error) {
768
- stream.throw(error);
793
+ done = true;
794
+ if (!cancelled) stream.throw(error);
769
795
  }
770
796
  }
771
797
  push().catch(() => {});
@@ -787,13 +813,15 @@ async function promiseToResult(current) {
787
813
  //#endregion
788
814
  //#region src/core/context/parser.ts
789
815
  function createBaseParserContext(mode, options) {
816
+ var _options$compactArray;
790
817
  return {
791
818
  plugins: options.plugins,
792
819
  mode,
793
820
  marked: /* @__PURE__ */ new Set(),
794
821
  features: 127 ^ (options.disabledFeatures || 0),
795
822
  refs: options.refs || /* @__PURE__ */ new Map(),
796
- depthLimit: options.depthLimit || 1e3
823
+ depthLimit: options.depthLimit || 1e3,
824
+ compactArrayBufferViews: (_options$compactArray = options.compactArrayBufferViews) !== null && _options$compactArray !== void 0 ? _options$compactArray : false
797
825
  };
798
826
  }
799
827
  /**
@@ -873,11 +901,22 @@ function createMapNode(ctx, id, k, v) {
873
901
  function createPromiseConstructorNode(ctx, id, resolver) {
874
902
  return createSerovalNode(22, id, resolver, void 0, void 0, void 0, void 0, void 0, parseSpecialReference(ctx, 1), void 0, void 0, void 0);
875
903
  }
876
- function createArrayBufferNode(ctx, id, current) {
904
+ function getArrayBufferView(ctx, current) {
905
+ if (!ctx.compactArrayBufferViews) return current;
906
+ const buffer = new Uint8Array(current.buffer, current.byteOffset, current.byteLength).slice().buffer;
907
+ const Constructor = current.constructor;
908
+ return new Constructor(buffer);
909
+ }
910
+ function encodeArrayBuffer(current) {
911
+ if (typeof Buffer !== "undefined") return Buffer.from(current).toString("base64");
877
912
  const bytes = new Uint8Array(current);
913
+ if (typeof bytes.toBase64 === "function") return bytes.toBase64();
878
914
  let result = "";
879
915
  for (let i = 0, len = bytes.length; i < len; i++) result += String.fromCharCode(bytes[i]);
880
- return createSerovalNode(19, id, serializeString(btoa(result)), void 0, void 0, void 0, void 0, void 0, parseSpecialReference(ctx, 5), void 0, void 0, void 0);
916
+ return btoa(result);
917
+ }
918
+ function createArrayBufferNode(ctx, id, current) {
919
+ return createSerovalNode(19, id, encodeArrayBuffer(current), void 0, void 0, void 0, void 0, void 0, parseSpecialReference(ctx, 5), void 0, void 0, void 0);
881
920
  }
882
921
  //#endregion
883
922
  //#region src/core/context/async-parser.ts
@@ -941,12 +980,15 @@ async function parseBoxed$1(ctx, depth, id, current) {
941
980
  return createBoxedNode(id, await parseAsync(ctx, depth, current.valueOf()));
942
981
  }
943
982
  async function parseTypedArray$1(ctx, depth, id, current) {
983
+ current = getArrayBufferView(ctx.base, current);
944
984
  return createTypedArrayNode(id, current, await parseAsync(ctx, depth, current.buffer));
945
985
  }
946
986
  async function parseBigIntTypedArray$1(ctx, depth, id, current) {
987
+ current = getArrayBufferView(ctx.base, current);
947
988
  return createBigIntTypedArrayNode(id, current, await parseAsync(ctx, depth, current.buffer));
948
989
  }
949
990
  async function parseDataView$1(ctx, depth, id, current) {
991
+ current = getArrayBufferView(ctx.base, current);
950
992
  return createDataViewNode(id, current, await parseAsync(ctx, depth, current.buffer));
951
993
  }
952
994
  async function parseError$1(ctx, depth, id, current) {
@@ -1191,7 +1233,7 @@ function isValidSymbol(symbol) {
1191
1233
  }
1192
1234
  //#endregion
1193
1235
  //#region src/core/context/deserializer.ts
1194
- const MAX_BASE64_LENGTH = 1e6;
1236
+ const DEFAULT_MAX_BASE64_LENGTH = 1e6;
1195
1237
  const MAX_BIGINT_LENGTH = 1e4;
1196
1238
  const MAX_REGEXP_SOURCE_LENGTH = 2e4;
1197
1239
  function applyObjectFlag(obj, flag) {
@@ -1204,7 +1246,9 @@ function applyObjectFlag(obj, flag) {
1204
1246
  }
1205
1247
  const DEFAULT_DEPTH_LIMIT = 1e3;
1206
1248
  function createBaseDeserializerContext(mode, options) {
1207
- var _options$features;
1249
+ var _options$maxBase64Len, _options$features;
1250
+ const maxBase64Length = (_options$maxBase64Len = options.maxBase64Length) !== null && _options$maxBase64Len !== void 0 ? _options$maxBase64Len : DEFAULT_MAX_BASE64_LENGTH;
1251
+ if (!Number.isSafeInteger(maxBase64Length) || maxBase64Length < 0) throw new RangeError("maxBase64Length must be a non-negative safe integer");
1208
1252
  const refs = options.refs || /* @__PURE__ */ new Map();
1209
1253
  if (!("types" in refs)) Object.assign(refs, { types: /* @__PURE__ */ new Map() });
1210
1254
  return {
@@ -1212,7 +1256,8 @@ function createBaseDeserializerContext(mode, options) {
1212
1256
  plugins: options.plugins,
1213
1257
  refs,
1214
1258
  features: (_options$features = options.features) !== null && _options$features !== void 0 ? _options$features : 127 ^ (options.disabledFeatures || 0),
1215
- depthLimit: options.depthLimit || DEFAULT_DEPTH_LIMIT
1259
+ depthLimit: options.depthLimit || DEFAULT_DEPTH_LIMIT,
1260
+ maxBase64Length
1216
1261
  };
1217
1262
  }
1218
1263
  function createVanillaDeserializerContext(options) {
@@ -1375,7 +1420,8 @@ function deserializeMap(ctx, depth, node) {
1375
1420
  return result;
1376
1421
  }
1377
1422
  function deserializeArrayBuffer(ctx, node) {
1378
- if (node.s.length > MAX_BASE64_LENGTH) throw new SerovalMalformedNodeError(node);
1423
+ if (typeof node.s !== "string") throw new SerovalMalformedNodeError(node);
1424
+ if (node.s.length > ctx.base.maxBase64Length) throw new RangeError("ArrayBuffer exceeds maxBase64Length (" + ctx.base.maxBase64Length + ")");
1379
1425
  return assignIndexedValue$1(ctx, node.i, ARRAY_BUFFER_CONSTRUCTOR(deserializeString(node.s)));
1380
1426
  }
1381
1427
  function deserializeTypedArray(ctx, depth, node) {
@@ -1384,7 +1430,7 @@ function deserializeTypedArray(ctx, depth, node) {
1384
1430
  const source = deserialize$1(ctx, depth, node.f);
1385
1431
  if (!(source instanceof ArrayBuffer)) throw new SerovalMalformedNodeError(node);
1386
1432
  const offset = (_node$b = node.b) !== null && _node$b !== void 0 ? _node$b : 0;
1387
- if (offset < 0 || offset > source.byteLength || node.l > MAX_BASE64_LENGTH) throw new SerovalMalformedNodeError(node);
1433
+ if (offset < 0 || offset > source.byteLength || node.l > ctx.base.maxBase64Length) throw new SerovalMalformedNodeError(node);
1388
1434
  return assignIndexedValue$1(ctx, node.i, new construct(source, offset, node.l));
1389
1435
  }
1390
1436
  function deserializeDataView(ctx, depth, node) {
@@ -1392,7 +1438,7 @@ function deserializeDataView(ctx, depth, node) {
1392
1438
  const source = deserialize$1(ctx, depth, node.f);
1393
1439
  if (!(source instanceof ArrayBuffer)) throw new SerovalMalformedNodeError(node);
1394
1440
  const offset = (_node$b2 = node.b) !== null && _node$b2 !== void 0 ? _node$b2 : 0;
1395
- if (offset < 0 || offset > source.byteLength || node.l > MAX_BASE64_LENGTH) throw new SerovalMalformedNodeError(node);
1441
+ if (offset < 0 || offset > source.byteLength || node.l > ctx.base.maxBase64Length) throw new SerovalMalformedNodeError(node);
1396
1442
  return assignIndexedValue$1(ctx, node.i, new DataView(source, offset, node.l));
1397
1443
  }
1398
1444
  function deserializeDictionary(ctx, depth, node, result) {
@@ -1452,13 +1498,15 @@ function deserializePromiseFulfill(ctx, depth, node) {
1452
1498
  function deserializeIteratorFactoryInstance(ctx, depth, node) {
1453
1499
  deserialize$1(ctx, depth, node.a[0]);
1454
1500
  const source = deserialize$1(ctx, depth, node.a[1]);
1455
- if (!source || typeof source !== "object" || !isSequence(source)) throw new SerovalMalformedNodeError(node.a[1]);
1501
+ validateNodeType(ctx, node, node.a[1].i, 35);
1502
+ if (!source) throw new SerovalMalformedNodeError(node.a[1]);
1456
1503
  return sequenceToIterator(source);
1457
1504
  }
1458
1505
  function deserializeAsyncIteratorFactoryInstance(ctx, depth, node) {
1459
1506
  deserialize$1(ctx, depth, node.a[0]);
1460
1507
  const source = deserialize$1(ctx, depth, node.a[1]);
1461
- if (!source || typeof source !== "object" || !isStream(source)) throw new SerovalMalformedNodeError(node.a[1]);
1508
+ validateNodeType(ctx, node, node.a[1].i, 31);
1509
+ if (!source) throw new SerovalMalformedNodeError(node.a[1]);
1462
1510
  return streamToAsyncIterable(source);
1463
1511
  }
1464
1512
  function deserializeStreamConstructor(ctx, depth, node) {
@@ -1504,6 +1552,7 @@ function deserializeAsyncIteratorFactory(ctx, depth, node) {
1504
1552
  }
1505
1553
  function deserializeSequence(ctx, depth, node) {
1506
1554
  const result = assignIndexedValue$1(ctx, node.i, createSequence([], node.s, node.l));
1555
+ assignNodeType(ctx, node.i, 35);
1507
1556
  for (let i = 0, len = node.a.length; i < len; i++) result.v[i] = deserialize$1(ctx, depth, node.a[i]);
1508
1557
  return result;
1509
1558
  }
@@ -2409,7 +2458,7 @@ function parseProperties(ctx, depth, properties) {
2409
2458
  }
2410
2459
  if (SYM_ASYNC_ITERATOR in properties) {
2411
2460
  keyNodes.push(parseWellKnownSymbol(ctx.base, SYM_ASYNC_ITERATOR));
2412
- valueNodes.push(createAsyncIteratorFactoryInstanceNode(parseAsyncIteratorFactory(ctx.base), parseSOS(ctx, depth, ctx.type === 1 ? createStream() : createStreamFromAsyncIterable(properties))));
2461
+ valueNodes.push(createAsyncIteratorFactoryInstanceNode(parseAsyncIteratorFactory(ctx.base), parseSOS(ctx, depth, ctx.type === 1 ? createStream() : createStreamFromAsyncIterable(properties, ctx.state.cleanups))));
2413
2462
  }
2414
2463
  if (SYM_TO_STRING_TAG in properties) {
2415
2464
  keyNodes.push(parseWellKnownSymbol(ctx.base, SYM_TO_STRING_TAG));
@@ -2431,12 +2480,15 @@ function parseBoxed(ctx, depth, id, current) {
2431
2480
  return createBoxedNode(id, parseSOS(ctx, depth, current.valueOf()));
2432
2481
  }
2433
2482
  function parseTypedArray(ctx, depth, id, current) {
2483
+ current = getArrayBufferView(ctx.base, current);
2434
2484
  return createTypedArrayNode(id, current, parseSOS(ctx, depth, current.buffer));
2435
2485
  }
2436
2486
  function parseBigIntTypedArray(ctx, depth, id, current) {
2487
+ current = getArrayBufferView(ctx.base, current);
2437
2488
  return createBigIntTypedArrayNode(id, current, parseSOS(ctx, depth, current.buffer));
2438
2489
  }
2439
2490
  function parseDataView(ctx, depth, id, current) {
2491
+ current = getArrayBufferView(ctx.base, current);
2440
2492
  return createDataViewNode(id, current, parseSOS(ctx, depth, current.buffer));
2441
2493
  }
2442
2494
  function parseError(ctx, depth, id, current) {
@@ -2687,6 +2739,7 @@ function destroyStreamParse(ctx) {
2687
2739
  function crossSerialize(source, options = {}) {
2688
2740
  const plugins = resolvePlugins(options.plugins);
2689
2741
  const ctx = createSyncParserContext(2, {
2742
+ compactArrayBufferViews: options.compactArrayBufferViews,
2690
2743
  plugins,
2691
2744
  disabledFeatures: options.disabledFeatures,
2692
2745
  refs: options.refs
@@ -2702,6 +2755,7 @@ function crossSerialize(source, options = {}) {
2702
2755
  async function crossSerializeAsync(source, options = {}) {
2703
2756
  const plugins = resolvePlugins(options.plugins);
2704
2757
  const ctx = createAsyncParserContext(2, {
2758
+ compactArrayBufferViews: options.compactArrayBufferViews,
2705
2759
  plugins,
2706
2760
  disabledFeatures: options.disabledFeatures,
2707
2761
  refs: options.refs
@@ -2715,15 +2769,19 @@ async function crossSerializeAsync(source, options = {}) {
2715
2769
  }), tree);
2716
2770
  }
2717
2771
  function toCrossJSON(source, options = {}) {
2772
+ const plugins = resolvePlugins(options.plugins);
2718
2773
  return parseTop(createSyncParserContext(2, {
2719
- plugins: resolvePlugins(options.plugins),
2774
+ compactArrayBufferViews: options.compactArrayBufferViews,
2775
+ plugins,
2720
2776
  disabledFeatures: options.disabledFeatures,
2721
2777
  refs: options.refs
2722
2778
  }), source);
2723
2779
  }
2724
2780
  async function toCrossJSONAsync(source, options = {}) {
2781
+ const plugins = resolvePlugins(options.plugins);
2725
2782
  return await parseTopAsync(createAsyncParserContext(2, {
2726
- plugins: resolvePlugins(options.plugins),
2783
+ compactArrayBufferViews: options.compactArrayBufferViews,
2784
+ plugins,
2727
2785
  disabledFeatures: options.disabledFeatures,
2728
2786
  refs: options.refs
2729
2787
  }), source);
@@ -2731,6 +2789,7 @@ async function toCrossJSONAsync(source, options = {}) {
2731
2789
  function crossSerializeStream(source, options) {
2732
2790
  const plugins = resolvePlugins(options.plugins);
2733
2791
  const ctx = createStreamParserContext({
2792
+ compactArrayBufferViews: options.compactArrayBufferViews,
2734
2793
  plugins,
2735
2794
  refs: options.refs,
2736
2795
  disabledFeatures: options.disabledFeatures,
@@ -2757,8 +2816,10 @@ function crossSerializeStream(source, options) {
2757
2816
  return destroyStreamParse.bind(null, ctx);
2758
2817
  }
2759
2818
  function toCrossJSONStream(source, options) {
2819
+ const plugins = resolvePlugins(options.plugins);
2760
2820
  const ctx = createStreamParserContext({
2761
- plugins: resolvePlugins(options.plugins),
2821
+ compactArrayBufferViews: options.compactArrayBufferViews,
2822
+ plugins,
2762
2823
  refs: options.refs,
2763
2824
  disabledFeatures: options.disabledFeatures,
2764
2825
  depthLimit: options.depthLimit,
@@ -2770,8 +2831,10 @@ function toCrossJSONStream(source, options) {
2770
2831
  return destroyStreamParse.bind(null, ctx);
2771
2832
  }
2772
2833
  function fromCrossJSON(source, options) {
2834
+ const plugins = resolvePlugins(options.plugins);
2773
2835
  return deserializeTop(createCrossDeserializerContext({
2774
- plugins: resolvePlugins(options.plugins),
2836
+ maxBase64Length: options.maxBase64Length,
2837
+ plugins,
2775
2838
  refs: options.refs,
2776
2839
  features: options.features,
2777
2840
  disabledFeatures: options.disabledFeatures,
@@ -2802,6 +2865,7 @@ var Serializer = class {
2802
2865
  scopeId: this.options.scopeId,
2803
2866
  refs: this.refs,
2804
2867
  disabledFeatures: this.options.disabledFeatures,
2868
+ compactArrayBufferViews: this.options.compactArrayBufferViews,
2805
2869
  onError: this.options.onError,
2806
2870
  onSerialize: (data, initial) => {
2807
2871
  if (this.alive) this.options.onData(initial ? this.options.globalIdentifier + "[\"" + serializeString(key) + "\"]=" + data : data);
@@ -2852,6 +2916,7 @@ var Serializer = class {
2852
2916
  function serialize(source, options = {}) {
2853
2917
  const plugins = resolvePlugins(options.plugins);
2854
2918
  const ctx = createSyncParserContext(1, {
2919
+ compactArrayBufferViews: options.compactArrayBufferViews,
2855
2920
  plugins,
2856
2921
  disabledFeatures: options.disabledFeatures
2857
2922
  });
@@ -2865,6 +2930,7 @@ function serialize(source, options = {}) {
2865
2930
  async function serializeAsync(source, options = {}) {
2866
2931
  const plugins = resolvePlugins(options.plugins);
2867
2932
  const ctx = createAsyncParserContext(1, {
2933
+ compactArrayBufferViews: options.compactArrayBufferViews,
2868
2934
  plugins,
2869
2935
  disabledFeatures: options.disabledFeatures
2870
2936
  });
@@ -2879,8 +2945,10 @@ function deserialize(source) {
2879
2945
  return (0, eval)(source);
2880
2946
  }
2881
2947
  function toJSON(source, options = {}) {
2948
+ const plugins = resolvePlugins(options.plugins);
2882
2949
  const ctx = createSyncParserContext(1, {
2883
- plugins: resolvePlugins(options.plugins),
2950
+ compactArrayBufferViews: options.compactArrayBufferViews,
2951
+ plugins,
2884
2952
  disabledFeatures: options.disabledFeatures
2885
2953
  });
2886
2954
  return {
@@ -2890,8 +2958,10 @@ function toJSON(source, options = {}) {
2890
2958
  };
2891
2959
  }
2892
2960
  async function toJSONAsync(source, options = {}) {
2961
+ const plugins = resolvePlugins(options.plugins);
2893
2962
  const ctx = createAsyncParserContext(1, {
2894
- plugins: resolvePlugins(options.plugins),
2963
+ compactArrayBufferViews: options.compactArrayBufferViews,
2964
+ plugins,
2895
2965
  disabledFeatures: options.disabledFeatures
2896
2966
  });
2897
2967
  return {
@@ -2913,6 +2983,7 @@ function fromJSON(source, options = {}) {
2913
2983
  const disabledFeatures = options.disabledFeatures || 0;
2914
2984
  const sourceFeatures = (_source$f = source.f) !== null && _source$f !== void 0 ? _source$f : 127;
2915
2985
  return deserializeTop(createVanillaDeserializerContext({
2986
+ maxBase64Length: options.maxBase64Length,
2916
2987
  plugins,
2917
2988
  markedRefs: source.m,
2918
2989
  features: sourceFeatures & ~disabledFeatures,
@@ -2949,6 +3020,7 @@ exports.deserialize = deserialize;
2949
3020
  exports.fromCrossJSON = fromCrossJSON;
2950
3021
  exports.fromJSON = fromJSON;
2951
3022
  exports.getCrossReferenceHeader = getCrossReferenceHeader;
3023
+ exports.isStream = isStream;
2952
3024
  exports.resolvePlugins = resolvePlugins;
2953
3025
  exports.serialize = serialize;
2954
3026
  exports.serializeAsync = serializeAsync;
@@ -359,6 +359,8 @@ interface BaseDeserializerContextOptions extends PluginAccessOptions {
359
359
  features?: number;
360
360
  disabledFeatures?: number;
361
361
  depthLimit?: number;
362
+ /** Maximum encoded characters per ArrayBuffer. Defaults to 1,000,000. */
363
+ maxBase64Length?: number;
362
364
  }
363
365
  interface BaseDeserializerContext extends PluginAccessOptions {
364
366
  readonly mode: SerovalMode;
@@ -370,6 +372,7 @@ interface BaseDeserializerContext extends PluginAccessOptions {
370
372
  };
371
373
  features: number;
372
374
  depthLimit: number;
375
+ maxBase64Length: number;
373
376
  }
374
377
  interface VanillaDeserializerContextOptions extends Omit<BaseDeserializerContextOptions, 'refs'> {
375
378
  markedRefs: number[] | Set<number>;
@@ -494,6 +497,8 @@ interface BaseParserContextOptions extends PluginAccessOptions {
494
497
  disabledFeatures?: number;
495
498
  refs?: Map<unknown, number>;
496
499
  depthLimit?: number;
500
+ /** Copy each typed array or DataView's visible bytes into its own buffer. */
501
+ compactArrayBufferViews?: boolean;
497
502
  }
498
503
  interface BaseParserContext extends PluginAccessOptions {
499
504
  readonly mode: SerovalMode;
@@ -501,6 +506,7 @@ interface BaseParserContext extends PluginAccessOptions {
501
506
  refs: Map<unknown, number>;
502
507
  features: number;
503
508
  depthLimit: number;
509
+ compactArrayBufferViews: boolean;
504
510
  }
505
511
  //#endregion
506
512
  //#region src/core/context/sync-parser.d.ts
@@ -701,6 +707,7 @@ interface SerializerOptions extends PluginAccessOptions {
701
707
  globalIdentifier: string;
702
708
  scopeId?: string;
703
709
  disabledFeatures?: number;
710
+ compactArrayBufferViews?: boolean;
704
711
  onData: (result: string) => void;
705
712
  onError: (error: unknown) => void;
706
713
  onDone?: () => void;
@@ -737,6 +744,7 @@ interface Stream<T> {
737
744
  throw(value: unknown): void;
738
745
  return(value: T): void;
739
746
  }
747
+ declare function isStream<T>(value: object): value is Stream<T>;
740
748
  declare function createStream<T>(): Stream<T>;
741
749
  //#endregion
742
750
  //#region src/core/tree/index.d.ts
@@ -750,7 +758,7 @@ interface SerovalJSON {
750
758
  f: number;
751
759
  m: number[];
752
760
  }
753
- interface FromJSONOptions extends PluginAccessOptions {
761
+ interface FromJSONOptions extends PluginAccessOptions, Pick<BaseDeserializerContextOptions, 'maxBase64Length'> {
754
762
  disabledFeatures?: number;
755
763
  }
756
764
  declare function toJSON<T>(source: T, options?: SyncParserContextOptions$1): SerovalJSON;
@@ -758,4 +766,4 @@ declare function toJSONAsync<T>(source: T, options?: AsyncParserContextOptions$1
758
766
  declare function compileJSON(source: SerovalJSON, options?: PluginAccessOptions): string;
759
767
  declare function fromJSON<T>(source: SerovalJSON, options?: FromJSONOptions): T;
760
768
  //#endregion
761
- export { type AsyncParsePluginContext, AsyncParserContextOptions, type BaseDeserializerContextOptions, type BaseParserContextOptions, type BaseSerializerContextOptions, type CrossContextOptions, type CrossDeserializerContextOptions, CrossSerializeAsyncOptions, CrossSerializeOptions, CrossSerializeStreamOptions, type CrossSerializerContextOptions, type DeserializePluginContext, Feature, FromCrossJSONOptions, FromJSONOptions, OpaqueReference, Plugin, PluginAccessOptions, PluginData, PluginInfo, type SerializePluginContext, Serializer, SerovalConflictedNodeIdError, SerovalDepthLimitError, SerovalDeserializationError, SerovalError, SerovalJSON, SerovalMalformedNodeError, SerovalMissingInstanceError, SerovalMissingPluginError, SerovalMissingReferenceError, SerovalMissingReferenceForIdError, SerovalMode, type SerovalNode, SerovalParserError, SerovalSerializationError, SerovalUnknownTypedArrayError, SerovalUnsupportedNodeError, SerovalUnsupportedTypeError, type Stream, type StreamListener, type StreamParsePluginContext, type StreamParserContextOptions, type SyncParsePluginContext, SyncParserContextOptions, ToCrossJSONAsyncOptions, ToCrossJSONOptions, ToCrossJSONStreamOptions, type VanillaDeserializerContextOptions, type VanillaSerializerContextOptions, compileJSON, createPlugin, createReference, createStream, crossSerialize, crossSerializeAsync, crossSerializeStream, deserialize, fromCrossJSON, fromJSON, getCrossReferenceHeader, resolvePlugins, serialize, serializeAsync, toCrossJSON, toCrossJSONAsync, toCrossJSONStream, toJSON, toJSONAsync };
769
+ export { type AsyncParsePluginContext, AsyncParserContextOptions, type BaseDeserializerContextOptions, type BaseParserContextOptions, type BaseSerializerContextOptions, type CrossContextOptions, type CrossDeserializerContextOptions, CrossSerializeAsyncOptions, CrossSerializeOptions, CrossSerializeStreamOptions, type CrossSerializerContextOptions, type DeserializePluginContext, Feature, FromCrossJSONOptions, FromJSONOptions, OpaqueReference, Plugin, PluginAccessOptions, PluginData, PluginInfo, type SerializePluginContext, Serializer, SerovalConflictedNodeIdError, SerovalDepthLimitError, SerovalDeserializationError, SerovalError, SerovalJSON, SerovalMalformedNodeError, SerovalMissingInstanceError, SerovalMissingPluginError, SerovalMissingReferenceError, SerovalMissingReferenceForIdError, SerovalMode, type SerovalNode, SerovalParserError, SerovalSerializationError, SerovalUnknownTypedArrayError, SerovalUnsupportedNodeError, SerovalUnsupportedTypeError, type Stream, type StreamListener, type StreamParsePluginContext, type StreamParserContextOptions, type SyncParsePluginContext, SyncParserContextOptions, ToCrossJSONAsyncOptions, ToCrossJSONOptions, ToCrossJSONStreamOptions, type VanillaDeserializerContextOptions, type VanillaSerializerContextOptions, compileJSON, createPlugin, createReference, createStream, crossSerialize, crossSerializeAsync, crossSerializeStream, deserialize, fromCrossJSON, fromJSON, getCrossReferenceHeader, isStream, resolvePlugins, serialize, serializeAsync, toCrossJSON, toCrossJSONAsync, toCrossJSONStream, toJSON, toJSONAsync };
@@ -359,6 +359,8 @@ interface BaseDeserializerContextOptions extends PluginAccessOptions {
359
359
  features?: number;
360
360
  disabledFeatures?: number;
361
361
  depthLimit?: number;
362
+ /** Maximum encoded characters per ArrayBuffer. Defaults to 1,000,000. */
363
+ maxBase64Length?: number;
362
364
  }
363
365
  interface BaseDeserializerContext extends PluginAccessOptions {
364
366
  readonly mode: SerovalMode;
@@ -370,6 +372,7 @@ interface BaseDeserializerContext extends PluginAccessOptions {
370
372
  };
371
373
  features: number;
372
374
  depthLimit: number;
375
+ maxBase64Length: number;
373
376
  }
374
377
  interface VanillaDeserializerContextOptions extends Omit<BaseDeserializerContextOptions, 'refs'> {
375
378
  markedRefs: number[] | Set<number>;
@@ -494,6 +497,8 @@ interface BaseParserContextOptions extends PluginAccessOptions {
494
497
  disabledFeatures?: number;
495
498
  refs?: Map<unknown, number>;
496
499
  depthLimit?: number;
500
+ /** Copy each typed array or DataView's visible bytes into its own buffer. */
501
+ compactArrayBufferViews?: boolean;
497
502
  }
498
503
  interface BaseParserContext extends PluginAccessOptions {
499
504
  readonly mode: SerovalMode;
@@ -501,6 +506,7 @@ interface BaseParserContext extends PluginAccessOptions {
501
506
  refs: Map<unknown, number>;
502
507
  features: number;
503
508
  depthLimit: number;
509
+ compactArrayBufferViews: boolean;
504
510
  }
505
511
  //#endregion
506
512
  //#region src/core/context/sync-parser.d.ts
@@ -701,6 +707,7 @@ interface SerializerOptions extends PluginAccessOptions {
701
707
  globalIdentifier: string;
702
708
  scopeId?: string;
703
709
  disabledFeatures?: number;
710
+ compactArrayBufferViews?: boolean;
704
711
  onData: (result: string) => void;
705
712
  onError: (error: unknown) => void;
706
713
  onDone?: () => void;
@@ -737,6 +744,7 @@ interface Stream<T> {
737
744
  throw(value: unknown): void;
738
745
  return(value: T): void;
739
746
  }
747
+ declare function isStream<T>(value: object): value is Stream<T>;
740
748
  declare function createStream<T>(): Stream<T>;
741
749
  //#endregion
742
750
  //#region src/core/tree/index.d.ts
@@ -750,7 +758,7 @@ interface SerovalJSON {
750
758
  f: number;
751
759
  m: number[];
752
760
  }
753
- interface FromJSONOptions extends PluginAccessOptions {
761
+ interface FromJSONOptions extends PluginAccessOptions, Pick<BaseDeserializerContextOptions, 'maxBase64Length'> {
754
762
  disabledFeatures?: number;
755
763
  }
756
764
  declare function toJSON<T>(source: T, options?: SyncParserContextOptions$1): SerovalJSON;
@@ -758,4 +766,4 @@ declare function toJSONAsync<T>(source: T, options?: AsyncParserContextOptions$1
758
766
  declare function compileJSON(source: SerovalJSON, options?: PluginAccessOptions): string;
759
767
  declare function fromJSON<T>(source: SerovalJSON, options?: FromJSONOptions): T;
760
768
  //#endregion
761
- export { type AsyncParsePluginContext, AsyncParserContextOptions, type BaseDeserializerContextOptions, type BaseParserContextOptions, type BaseSerializerContextOptions, type CrossContextOptions, type CrossDeserializerContextOptions, CrossSerializeAsyncOptions, CrossSerializeOptions, CrossSerializeStreamOptions, type CrossSerializerContextOptions, type DeserializePluginContext, Feature, FromCrossJSONOptions, FromJSONOptions, OpaqueReference, Plugin, PluginAccessOptions, PluginData, PluginInfo, type SerializePluginContext, Serializer, SerovalConflictedNodeIdError, SerovalDepthLimitError, SerovalDeserializationError, SerovalError, SerovalJSON, SerovalMalformedNodeError, SerovalMissingInstanceError, SerovalMissingPluginError, SerovalMissingReferenceError, SerovalMissingReferenceForIdError, SerovalMode, type SerovalNode, SerovalParserError, SerovalSerializationError, SerovalUnknownTypedArrayError, SerovalUnsupportedNodeError, SerovalUnsupportedTypeError, type Stream, type StreamListener, type StreamParsePluginContext, type StreamParserContextOptions, type SyncParsePluginContext, SyncParserContextOptions, ToCrossJSONAsyncOptions, ToCrossJSONOptions, ToCrossJSONStreamOptions, type VanillaDeserializerContextOptions, type VanillaSerializerContextOptions, compileJSON, createPlugin, createReference, createStream, crossSerialize, crossSerializeAsync, crossSerializeStream, deserialize, fromCrossJSON, fromJSON, getCrossReferenceHeader, resolvePlugins, serialize, serializeAsync, toCrossJSON, toCrossJSONAsync, toCrossJSONStream, toJSON, toJSONAsync };
769
+ export { type AsyncParsePluginContext, AsyncParserContextOptions, type BaseDeserializerContextOptions, type BaseParserContextOptions, type BaseSerializerContextOptions, type CrossContextOptions, type CrossDeserializerContextOptions, CrossSerializeAsyncOptions, CrossSerializeOptions, CrossSerializeStreamOptions, type CrossSerializerContextOptions, type DeserializePluginContext, Feature, FromCrossJSONOptions, FromJSONOptions, OpaqueReference, Plugin, PluginAccessOptions, PluginData, PluginInfo, type SerializePluginContext, Serializer, SerovalConflictedNodeIdError, SerovalDepthLimitError, SerovalDeserializationError, SerovalError, SerovalJSON, SerovalMalformedNodeError, SerovalMissingInstanceError, SerovalMissingPluginError, SerovalMissingReferenceError, SerovalMissingReferenceForIdError, SerovalMode, type SerovalNode, SerovalParserError, SerovalSerializationError, SerovalUnknownTypedArrayError, SerovalUnsupportedNodeError, SerovalUnsupportedTypeError, type Stream, type StreamListener, type StreamParsePluginContext, type StreamParserContextOptions, type SyncParsePluginContext, SyncParserContextOptions, ToCrossJSONAsyncOptions, ToCrossJSONOptions, ToCrossJSONStreamOptions, type VanillaDeserializerContextOptions, type VanillaSerializerContextOptions, compileJSON, createPlugin, createReference, createStream, crossSerialize, crossSerializeAsync, crossSerializeStream, deserialize, fromCrossJSON, fromJSON, getCrossReferenceHeader, isStream, resolvePlugins, serialize, serializeAsync, toCrossJSON, toCrossJSONAsync, toCrossJSONStream, toJSON, toJSONAsync };