seroval 1.6.5 → 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) {
@@ -2412,7 +2458,7 @@ function parseProperties(ctx, depth, properties) {
2412
2458
  }
2413
2459
  if (SYM_ASYNC_ITERATOR in properties) {
2414
2460
  keyNodes.push(parseWellKnownSymbol(ctx.base, SYM_ASYNC_ITERATOR));
2415
- 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))));
2416
2462
  }
2417
2463
  if (SYM_TO_STRING_TAG in properties) {
2418
2464
  keyNodes.push(parseWellKnownSymbol(ctx.base, SYM_TO_STRING_TAG));
@@ -2434,12 +2480,15 @@ function parseBoxed(ctx, depth, id, current) {
2434
2480
  return createBoxedNode(id, parseSOS(ctx, depth, current.valueOf()));
2435
2481
  }
2436
2482
  function parseTypedArray(ctx, depth, id, current) {
2483
+ current = getArrayBufferView(ctx.base, current);
2437
2484
  return createTypedArrayNode(id, current, parseSOS(ctx, depth, current.buffer));
2438
2485
  }
2439
2486
  function parseBigIntTypedArray(ctx, depth, id, current) {
2487
+ current = getArrayBufferView(ctx.base, current);
2440
2488
  return createBigIntTypedArrayNode(id, current, parseSOS(ctx, depth, current.buffer));
2441
2489
  }
2442
2490
  function parseDataView(ctx, depth, id, current) {
2491
+ current = getArrayBufferView(ctx.base, current);
2443
2492
  return createDataViewNode(id, current, parseSOS(ctx, depth, current.buffer));
2444
2493
  }
2445
2494
  function parseError(ctx, depth, id, current) {
@@ -2690,6 +2739,7 @@ function destroyStreamParse(ctx) {
2690
2739
  function crossSerialize(source, options = {}) {
2691
2740
  const plugins = resolvePlugins(options.plugins);
2692
2741
  const ctx = createSyncParserContext(2, {
2742
+ compactArrayBufferViews: options.compactArrayBufferViews,
2693
2743
  plugins,
2694
2744
  disabledFeatures: options.disabledFeatures,
2695
2745
  refs: options.refs
@@ -2705,6 +2755,7 @@ function crossSerialize(source, options = {}) {
2705
2755
  async function crossSerializeAsync(source, options = {}) {
2706
2756
  const plugins = resolvePlugins(options.plugins);
2707
2757
  const ctx = createAsyncParserContext(2, {
2758
+ compactArrayBufferViews: options.compactArrayBufferViews,
2708
2759
  plugins,
2709
2760
  disabledFeatures: options.disabledFeatures,
2710
2761
  refs: options.refs
@@ -2718,15 +2769,19 @@ async function crossSerializeAsync(source, options = {}) {
2718
2769
  }), tree);
2719
2770
  }
2720
2771
  function toCrossJSON(source, options = {}) {
2772
+ const plugins = resolvePlugins(options.plugins);
2721
2773
  return parseTop(createSyncParserContext(2, {
2722
- plugins: resolvePlugins(options.plugins),
2774
+ compactArrayBufferViews: options.compactArrayBufferViews,
2775
+ plugins,
2723
2776
  disabledFeatures: options.disabledFeatures,
2724
2777
  refs: options.refs
2725
2778
  }), source);
2726
2779
  }
2727
2780
  async function toCrossJSONAsync(source, options = {}) {
2781
+ const plugins = resolvePlugins(options.plugins);
2728
2782
  return await parseTopAsync(createAsyncParserContext(2, {
2729
- plugins: resolvePlugins(options.plugins),
2783
+ compactArrayBufferViews: options.compactArrayBufferViews,
2784
+ plugins,
2730
2785
  disabledFeatures: options.disabledFeatures,
2731
2786
  refs: options.refs
2732
2787
  }), source);
@@ -2734,6 +2789,7 @@ async function toCrossJSONAsync(source, options = {}) {
2734
2789
  function crossSerializeStream(source, options) {
2735
2790
  const plugins = resolvePlugins(options.plugins);
2736
2791
  const ctx = createStreamParserContext({
2792
+ compactArrayBufferViews: options.compactArrayBufferViews,
2737
2793
  plugins,
2738
2794
  refs: options.refs,
2739
2795
  disabledFeatures: options.disabledFeatures,
@@ -2760,8 +2816,10 @@ function crossSerializeStream(source, options) {
2760
2816
  return destroyStreamParse.bind(null, ctx);
2761
2817
  }
2762
2818
  function toCrossJSONStream(source, options) {
2819
+ const plugins = resolvePlugins(options.plugins);
2763
2820
  const ctx = createStreamParserContext({
2764
- plugins: resolvePlugins(options.plugins),
2821
+ compactArrayBufferViews: options.compactArrayBufferViews,
2822
+ plugins,
2765
2823
  refs: options.refs,
2766
2824
  disabledFeatures: options.disabledFeatures,
2767
2825
  depthLimit: options.depthLimit,
@@ -2773,8 +2831,10 @@ function toCrossJSONStream(source, options) {
2773
2831
  return destroyStreamParse.bind(null, ctx);
2774
2832
  }
2775
2833
  function fromCrossJSON(source, options) {
2834
+ const plugins = resolvePlugins(options.plugins);
2776
2835
  return deserializeTop(createCrossDeserializerContext({
2777
- plugins: resolvePlugins(options.plugins),
2836
+ maxBase64Length: options.maxBase64Length,
2837
+ plugins,
2778
2838
  refs: options.refs,
2779
2839
  features: options.features,
2780
2840
  disabledFeatures: options.disabledFeatures,
@@ -2805,6 +2865,7 @@ var Serializer = class {
2805
2865
  scopeId: this.options.scopeId,
2806
2866
  refs: this.refs,
2807
2867
  disabledFeatures: this.options.disabledFeatures,
2868
+ compactArrayBufferViews: this.options.compactArrayBufferViews,
2808
2869
  onError: this.options.onError,
2809
2870
  onSerialize: (data, initial) => {
2810
2871
  if (this.alive) this.options.onData(initial ? this.options.globalIdentifier + "[\"" + serializeString(key) + "\"]=" + data : data);
@@ -2855,6 +2916,7 @@ var Serializer = class {
2855
2916
  function serialize(source, options = {}) {
2856
2917
  const plugins = resolvePlugins(options.plugins);
2857
2918
  const ctx = createSyncParserContext(1, {
2919
+ compactArrayBufferViews: options.compactArrayBufferViews,
2858
2920
  plugins,
2859
2921
  disabledFeatures: options.disabledFeatures
2860
2922
  });
@@ -2868,6 +2930,7 @@ function serialize(source, options = {}) {
2868
2930
  async function serializeAsync(source, options = {}) {
2869
2931
  const plugins = resolvePlugins(options.plugins);
2870
2932
  const ctx = createAsyncParserContext(1, {
2933
+ compactArrayBufferViews: options.compactArrayBufferViews,
2871
2934
  plugins,
2872
2935
  disabledFeatures: options.disabledFeatures
2873
2936
  });
@@ -2882,8 +2945,10 @@ function deserialize(source) {
2882
2945
  return (0, eval)(source);
2883
2946
  }
2884
2947
  function toJSON(source, options = {}) {
2948
+ const plugins = resolvePlugins(options.plugins);
2885
2949
  const ctx = createSyncParserContext(1, {
2886
- plugins: resolvePlugins(options.plugins),
2950
+ compactArrayBufferViews: options.compactArrayBufferViews,
2951
+ plugins,
2887
2952
  disabledFeatures: options.disabledFeatures
2888
2953
  });
2889
2954
  return {
@@ -2893,8 +2958,10 @@ function toJSON(source, options = {}) {
2893
2958
  };
2894
2959
  }
2895
2960
  async function toJSONAsync(source, options = {}) {
2961
+ const plugins = resolvePlugins(options.plugins);
2896
2962
  const ctx = createAsyncParserContext(1, {
2897
- plugins: resolvePlugins(options.plugins),
2963
+ compactArrayBufferViews: options.compactArrayBufferViews,
2964
+ plugins,
2898
2965
  disabledFeatures: options.disabledFeatures
2899
2966
  });
2900
2967
  return {
@@ -2916,6 +2983,7 @@ function fromJSON(source, options = {}) {
2916
2983
  const disabledFeatures = options.disabledFeatures || 0;
2917
2984
  const sourceFeatures = (_source$f = source.f) !== null && _source$f !== void 0 ? _source$f : 127;
2918
2985
  return deserializeTop(createVanillaDeserializerContext({
2986
+ maxBase64Length: options.maxBase64Length,
2919
2987
  plugins,
2920
2988
  markedRefs: source.m,
2921
2989
  features: sourceFeatures & ~disabledFeatures,
@@ -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;
@@ -751,7 +758,7 @@ interface SerovalJSON {
751
758
  f: number;
752
759
  m: number[];
753
760
  }
754
- interface FromJSONOptions extends PluginAccessOptions {
761
+ interface FromJSONOptions extends PluginAccessOptions, Pick<BaseDeserializerContextOptions, 'maxBase64Length'> {
755
762
  disabledFeatures?: number;
756
763
  }
757
764
  declare function toJSON<T>(source: T, options?: SyncParserContextOptions$1): SerovalJSON;
@@ -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;
@@ -751,7 +758,7 @@ interface SerovalJSON {
751
758
  f: number;
752
759
  m: number[];
753
760
  }
754
- interface FromJSONOptions extends PluginAccessOptions {
761
+ interface FromJSONOptions extends PluginAccessOptions, Pick<BaseDeserializerContextOptions, 'maxBase64Length'> {
755
762
  disabledFeatures?: number;
756
763
  }
757
764
  declare function toJSON<T>(source: T, options?: SyncParserContextOptions$1): SerovalJSON;