seroval 1.6.5 → 1.6.7

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/index.cjs CHANGED
@@ -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;
@@ -194,6 +197,7 @@ function deserializeReplacer(str) {
194
197
  }
195
198
  }
196
199
  function deserializeString(str) {
200
+ if (typeof str === "string" && !str.includes("\\")) return str;
197
201
  return str.replace(/(\\\\|\\"|\\n|\\r|\\b|\\t|\\f|\\u2028|\\u2029|\\x3C)/g, deserializeReplacer);
198
202
  }
199
203
  //#endregion
@@ -517,7 +521,10 @@ const STREAM_CONSTRUCTOR = () => {
517
521
  let count = 0;
518
522
  const internal = {
519
523
  flush(value, mode, x) {
520
- for (x = 0; x < count; x++) if (listeners[x]) listeners[x][mode](value);
524
+ for (x = 0; x < count; x++) {
525
+ const listener = listeners[x];
526
+ if (listener) listener[mode](value);
527
+ }
521
528
  },
522
529
  up(listener, x, z, current) {
523
530
  for (x = 0, z = buffer.length; x < z; x++) {
@@ -526,16 +533,20 @@ const STREAM_CONSTRUCTOR = () => {
526
533
  else listener.next(current);
527
534
  }
528
535
  },
529
- on(listener, temp) {
536
+ on(listener, temp = 0) {
537
+ let subscribed = alive;
530
538
  if (alive) {
531
- temp = count++;
539
+ for (temp = 0; temp < count; temp++) if (!listeners[temp]) break;
540
+ if (temp === count) count++;
532
541
  listeners[temp] = listener;
533
542
  }
534
543
  internal.up(listener);
535
544
  return () => {
536
- if (alive) {
537
- listeners[temp] = listeners[count];
538
- listeners[count--] = void 0;
545
+ if (alive && subscribed) {
546
+ subscribed = false;
547
+ listeners[temp] = void 0;
548
+ while (count > 0 && !listeners[count - 1]) count--;
549
+ listeners.length = count;
539
550
  }
540
551
  };
541
552
  }
@@ -746,19 +757,35 @@ function isStream(value) {
746
757
  function createStream() {
747
758
  return STREAM_CONSTRUCTOR();
748
759
  }
749
- function createStreamFromAsyncIterable(iterable) {
760
+ function createStreamFromAsyncIterable(iterable, cleanups) {
750
761
  const stream = createStream();
751
762
  const iterator = iterable[SYM_ASYNC_ITERATOR]();
763
+ let cancelled = false;
764
+ let done = false;
765
+ cleanups === null || cleanups === void 0 || cleanups.push(() => {
766
+ if (!(done || cancelled)) {
767
+ cancelled = true;
768
+ Promise.resolve().then(() => {
769
+ var _iterator$return;
770
+ return (_iterator$return = iterator.return) === null || _iterator$return === void 0 ? void 0 : _iterator$return.call(iterator);
771
+ }).catch(() => {});
772
+ }
773
+ });
752
774
  async function push() {
753
775
  try {
754
- const value = await iterator.next();
755
- if (value.done) stream.return(value.value);
756
- else {
776
+ while (!cancelled) {
777
+ const value = await iterator.next();
778
+ if (cancelled) return;
779
+ if (value.done) {
780
+ done = true;
781
+ stream.return(value.value);
782
+ break;
783
+ }
757
784
  stream.next(value.value);
758
- await push();
759
785
  }
760
786
  } catch (error) {
761
- stream.throw(error);
787
+ done = true;
788
+ if (!cancelled) stream.throw(error);
762
789
  }
763
790
  }
764
791
  push().catch(() => {});
@@ -780,13 +807,15 @@ async function promiseToResult(current) {
780
807
  //#endregion
781
808
  //#region src/core/context/parser.ts
782
809
  function createBaseParserContext(mode, options) {
810
+ var _options$compactArray;
783
811
  return {
784
812
  plugins: options.plugins,
785
813
  mode,
786
814
  marked: /* @__PURE__ */ new Set(),
787
815
  features: 127 ^ (options.disabledFeatures || 0),
788
816
  refs: options.refs || /* @__PURE__ */ new Map(),
789
- depthLimit: options.depthLimit || 1e3
817
+ depthLimit: options.depthLimit || 1e3,
818
+ compactArrayBufferViews: (_options$compactArray = options.compactArrayBufferViews) !== null && _options$compactArray !== void 0 ? _options$compactArray : false
790
819
  };
791
820
  }
792
821
  /**
@@ -866,11 +895,22 @@ function createMapNode(ctx, id, k, v) {
866
895
  function createPromiseConstructorNode(ctx, id, resolver) {
867
896
  return createSerovalNode(22, id, resolver, void 0, void 0, void 0, void 0, void 0, parseSpecialReference(ctx, 1), void 0, void 0, void 0);
868
897
  }
869
- function createArrayBufferNode(ctx, id, current) {
898
+ function getArrayBufferView(ctx, current) {
899
+ if (!ctx.compactArrayBufferViews) return current;
900
+ const buffer = new Uint8Array(current.buffer, current.byteOffset, current.byteLength).slice().buffer;
901
+ const Constructor = current.constructor;
902
+ return new Constructor(buffer);
903
+ }
904
+ function encodeArrayBuffer(current) {
905
+ if (typeof Buffer !== "undefined") return Buffer.from(current).toString("base64");
870
906
  const bytes = new Uint8Array(current);
907
+ if (typeof bytes.toBase64 === "function") return bytes.toBase64();
871
908
  let result = "";
872
909
  for (let i = 0, len = bytes.length; i < len; i++) result += String.fromCharCode(bytes[i]);
873
- 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);
910
+ return btoa(result);
911
+ }
912
+ function createArrayBufferNode(ctx, id, current) {
913
+ 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);
874
914
  }
875
915
  //#endregion
876
916
  //#region src/core/context/async-parser.ts
@@ -934,12 +974,15 @@ async function parseBoxed$1(ctx, depth, id, current) {
934
974
  return createBoxedNode(id, await parseAsync(ctx, depth, current.valueOf()));
935
975
  }
936
976
  async function parseTypedArray$1(ctx, depth, id, current) {
977
+ current = getArrayBufferView(ctx.base, current);
937
978
  return createTypedArrayNode(id, current, await parseAsync(ctx, depth, current.buffer));
938
979
  }
939
980
  async function parseBigIntTypedArray$1(ctx, depth, id, current) {
981
+ current = getArrayBufferView(ctx.base, current);
940
982
  return createBigIntTypedArrayNode(id, current, await parseAsync(ctx, depth, current.buffer));
941
983
  }
942
984
  async function parseDataView$1(ctx, depth, id, current) {
985
+ current = getArrayBufferView(ctx.base, current);
943
986
  return createDataViewNode(id, current, await parseAsync(ctx, depth, current.buffer));
944
987
  }
945
988
  async function parseError$1(ctx, depth, id, current) {
@@ -1184,7 +1227,8 @@ function isValidSymbol(symbol) {
1184
1227
  }
1185
1228
  //#endregion
1186
1229
  //#region src/core/context/deserializer.ts
1187
- const MAX_BASE64_LENGTH = 1e6;
1230
+ const DEFAULT_MAX_BASE64_LENGTH = 1e6;
1231
+ const MIN_NATIVE_BASE64_LENGTH = 512;
1188
1232
  const MAX_BIGINT_LENGTH = 1e4;
1189
1233
  const MAX_REGEXP_SOURCE_LENGTH = 2e4;
1190
1234
  function applyObjectFlag(obj, flag) {
@@ -1197,7 +1241,9 @@ function applyObjectFlag(obj, flag) {
1197
1241
  }
1198
1242
  const DEFAULT_DEPTH_LIMIT = 1e3;
1199
1243
  function createBaseDeserializerContext(mode, options) {
1200
- var _options$features;
1244
+ var _options$maxBase64Len, _options$features;
1245
+ const maxBase64Length = (_options$maxBase64Len = options.maxBase64Length) !== null && _options$maxBase64Len !== void 0 ? _options$maxBase64Len : DEFAULT_MAX_BASE64_LENGTH;
1246
+ if (!Number.isSafeInteger(maxBase64Length) || maxBase64Length < 0) throw new RangeError("maxBase64Length must be a non-negative safe integer");
1201
1247
  const refs = options.refs || /* @__PURE__ */ new Map();
1202
1248
  if (!("types" in refs)) Object.assign(refs, { types: /* @__PURE__ */ new Map() });
1203
1249
  return {
@@ -1205,7 +1251,8 @@ function createBaseDeserializerContext(mode, options) {
1205
1251
  plugins: options.plugins,
1206
1252
  refs,
1207
1253
  features: (_options$features = options.features) !== null && _options$features !== void 0 ? _options$features : 127 ^ (options.disabledFeatures || 0),
1208
- depthLimit: options.depthLimit || DEFAULT_DEPTH_LIMIT
1254
+ depthLimit: options.depthLimit || DEFAULT_DEPTH_LIMIT,
1255
+ maxBase64Length
1209
1256
  };
1210
1257
  }
1211
1258
  function createVanillaDeserializerContext(options) {
@@ -1368,8 +1415,17 @@ function deserializeMap(ctx, depth, node) {
1368
1415
  return result;
1369
1416
  }
1370
1417
  function deserializeArrayBuffer(ctx, node) {
1371
- if (node.s.length > MAX_BASE64_LENGTH) throw new SerovalMalformedNodeError(node);
1372
- return assignIndexedValue$1(ctx, node.i, ARRAY_BUFFER_CONSTRUCTOR(deserializeString(node.s)));
1418
+ if (typeof node.s !== "string") throw new SerovalMalformedNodeError(node);
1419
+ if (node.s.length > ctx.base.maxBase64Length) throw new RangeError("ArrayBuffer exceeds maxBase64Length (" + ctx.base.maxBase64Length + ")");
1420
+ const source = deserializeString(node.s);
1421
+ let buffer;
1422
+ if (source.length < MIN_NATIVE_BASE64_LENGTH || typeof Buffer === "undefined") buffer = ARRAY_BUFFER_CONSTRUCTOR(source);
1423
+ else {
1424
+ const decoded = atob(source);
1425
+ buffer = new ArrayBuffer(decoded.length);
1426
+ Buffer.from(buffer).write(decoded, "latin1");
1427
+ }
1428
+ return assignIndexedValue$1(ctx, node.i, buffer);
1373
1429
  }
1374
1430
  function deserializeTypedArray(ctx, depth, node) {
1375
1431
  var _node$b;
@@ -1377,7 +1433,7 @@ function deserializeTypedArray(ctx, depth, node) {
1377
1433
  const source = deserialize$1(ctx, depth, node.f);
1378
1434
  if (!(source instanceof ArrayBuffer)) throw new SerovalMalformedNodeError(node);
1379
1435
  const offset = (_node$b = node.b) !== null && _node$b !== void 0 ? _node$b : 0;
1380
- if (offset < 0 || offset > source.byteLength || node.l > MAX_BASE64_LENGTH) throw new SerovalMalformedNodeError(node);
1436
+ if (offset < 0 || offset > source.byteLength) throw new SerovalMalformedNodeError(node);
1381
1437
  return assignIndexedValue$1(ctx, node.i, new construct(source, offset, node.l));
1382
1438
  }
1383
1439
  function deserializeDataView(ctx, depth, node) {
@@ -1385,7 +1441,7 @@ function deserializeDataView(ctx, depth, node) {
1385
1441
  const source = deserialize$1(ctx, depth, node.f);
1386
1442
  if (!(source instanceof ArrayBuffer)) throw new SerovalMalformedNodeError(node);
1387
1443
  const offset = (_node$b2 = node.b) !== null && _node$b2 !== void 0 ? _node$b2 : 0;
1388
- if (offset < 0 || offset > source.byteLength || node.l > MAX_BASE64_LENGTH) throw new SerovalMalformedNodeError(node);
1444
+ if (offset < 0 || offset > source.byteLength) throw new SerovalMalformedNodeError(node);
1389
1445
  return assignIndexedValue$1(ctx, node.i, new DataView(source, offset, node.l));
1390
1446
  }
1391
1447
  function deserializeDictionary(ctx, depth, node, result) {
@@ -2405,7 +2461,7 @@ function parseProperties(ctx, depth, properties) {
2405
2461
  }
2406
2462
  if (SYM_ASYNC_ITERATOR in properties) {
2407
2463
  keyNodes.push(parseWellKnownSymbol(ctx.base, SYM_ASYNC_ITERATOR));
2408
- valueNodes.push(createAsyncIteratorFactoryInstanceNode(parseAsyncIteratorFactory(ctx.base), parseSOS(ctx, depth, ctx.type === 1 ? createStream() : createStreamFromAsyncIterable(properties))));
2464
+ valueNodes.push(createAsyncIteratorFactoryInstanceNode(parseAsyncIteratorFactory(ctx.base), parseSOS(ctx, depth, ctx.type === 1 ? createStream() : createStreamFromAsyncIterable(properties, ctx.state.cleanups))));
2409
2465
  }
2410
2466
  if (SYM_TO_STRING_TAG in properties) {
2411
2467
  keyNodes.push(parseWellKnownSymbol(ctx.base, SYM_TO_STRING_TAG));
@@ -2427,12 +2483,15 @@ function parseBoxed(ctx, depth, id, current) {
2427
2483
  return createBoxedNode(id, parseSOS(ctx, depth, current.valueOf()));
2428
2484
  }
2429
2485
  function parseTypedArray(ctx, depth, id, current) {
2486
+ current = getArrayBufferView(ctx.base, current);
2430
2487
  return createTypedArrayNode(id, current, parseSOS(ctx, depth, current.buffer));
2431
2488
  }
2432
2489
  function parseBigIntTypedArray(ctx, depth, id, current) {
2490
+ current = getArrayBufferView(ctx.base, current);
2433
2491
  return createBigIntTypedArrayNode(id, current, parseSOS(ctx, depth, current.buffer));
2434
2492
  }
2435
2493
  function parseDataView(ctx, depth, id, current) {
2494
+ current = getArrayBufferView(ctx.base, current);
2436
2495
  return createDataViewNode(id, current, parseSOS(ctx, depth, current.buffer));
2437
2496
  }
2438
2497
  function parseError(ctx, depth, id, current) {
@@ -2683,6 +2742,7 @@ function destroyStreamParse(ctx) {
2683
2742
  function crossSerialize(source, options = {}) {
2684
2743
  const plugins = resolvePlugins(options.plugins);
2685
2744
  const ctx = createSyncParserContext(2, {
2745
+ compactArrayBufferViews: options.compactArrayBufferViews,
2686
2746
  plugins,
2687
2747
  disabledFeatures: options.disabledFeatures,
2688
2748
  refs: options.refs
@@ -2698,6 +2758,7 @@ function crossSerialize(source, options = {}) {
2698
2758
  async function crossSerializeAsync(source, options = {}) {
2699
2759
  const plugins = resolvePlugins(options.plugins);
2700
2760
  const ctx = createAsyncParserContext(2, {
2761
+ compactArrayBufferViews: options.compactArrayBufferViews,
2701
2762
  plugins,
2702
2763
  disabledFeatures: options.disabledFeatures,
2703
2764
  refs: options.refs
@@ -2711,15 +2772,19 @@ async function crossSerializeAsync(source, options = {}) {
2711
2772
  }), tree);
2712
2773
  }
2713
2774
  function toCrossJSON(source, options = {}) {
2775
+ const plugins = resolvePlugins(options.plugins);
2714
2776
  return parseTop(createSyncParserContext(2, {
2715
- plugins: resolvePlugins(options.plugins),
2777
+ compactArrayBufferViews: options.compactArrayBufferViews,
2778
+ plugins,
2716
2779
  disabledFeatures: options.disabledFeatures,
2717
2780
  refs: options.refs
2718
2781
  }), source);
2719
2782
  }
2720
2783
  async function toCrossJSONAsync(source, options = {}) {
2784
+ const plugins = resolvePlugins(options.plugins);
2721
2785
  return await parseTopAsync(createAsyncParserContext(2, {
2722
- plugins: resolvePlugins(options.plugins),
2786
+ compactArrayBufferViews: options.compactArrayBufferViews,
2787
+ plugins,
2723
2788
  disabledFeatures: options.disabledFeatures,
2724
2789
  refs: options.refs
2725
2790
  }), source);
@@ -2727,6 +2792,7 @@ async function toCrossJSONAsync(source, options = {}) {
2727
2792
  function crossSerializeStream(source, options) {
2728
2793
  const plugins = resolvePlugins(options.plugins);
2729
2794
  const ctx = createStreamParserContext({
2795
+ compactArrayBufferViews: options.compactArrayBufferViews,
2730
2796
  plugins,
2731
2797
  refs: options.refs,
2732
2798
  disabledFeatures: options.disabledFeatures,
@@ -2753,8 +2819,10 @@ function crossSerializeStream(source, options) {
2753
2819
  return destroyStreamParse.bind(null, ctx);
2754
2820
  }
2755
2821
  function toCrossJSONStream(source, options) {
2822
+ const plugins = resolvePlugins(options.plugins);
2756
2823
  const ctx = createStreamParserContext({
2757
- plugins: resolvePlugins(options.plugins),
2824
+ compactArrayBufferViews: options.compactArrayBufferViews,
2825
+ plugins,
2758
2826
  refs: options.refs,
2759
2827
  disabledFeatures: options.disabledFeatures,
2760
2828
  depthLimit: options.depthLimit,
@@ -2766,8 +2834,10 @@ function toCrossJSONStream(source, options) {
2766
2834
  return destroyStreamParse.bind(null, ctx);
2767
2835
  }
2768
2836
  function fromCrossJSON(source, options) {
2837
+ const plugins = resolvePlugins(options.plugins);
2769
2838
  return deserializeTop(createCrossDeserializerContext({
2770
- plugins: resolvePlugins(options.plugins),
2839
+ maxBase64Length: options.maxBase64Length,
2840
+ plugins,
2771
2841
  refs: options.refs,
2772
2842
  features: options.features,
2773
2843
  disabledFeatures: options.disabledFeatures,
@@ -2798,6 +2868,7 @@ var Serializer = class {
2798
2868
  scopeId: this.options.scopeId,
2799
2869
  refs: this.refs,
2800
2870
  disabledFeatures: this.options.disabledFeatures,
2871
+ compactArrayBufferViews: this.options.compactArrayBufferViews,
2801
2872
  onError: this.options.onError,
2802
2873
  onSerialize: (data, initial) => {
2803
2874
  if (this.alive) this.options.onData(initial ? this.options.globalIdentifier + "[\"" + serializeString(key) + "\"]=" + data : data);
@@ -2848,6 +2919,7 @@ var Serializer = class {
2848
2919
  function serialize(source, options = {}) {
2849
2920
  const plugins = resolvePlugins(options.plugins);
2850
2921
  const ctx = createSyncParserContext(1, {
2922
+ compactArrayBufferViews: options.compactArrayBufferViews,
2851
2923
  plugins,
2852
2924
  disabledFeatures: options.disabledFeatures
2853
2925
  });
@@ -2861,6 +2933,7 @@ function serialize(source, options = {}) {
2861
2933
  async function serializeAsync(source, options = {}) {
2862
2934
  const plugins = resolvePlugins(options.plugins);
2863
2935
  const ctx = createAsyncParserContext(1, {
2936
+ compactArrayBufferViews: options.compactArrayBufferViews,
2864
2937
  plugins,
2865
2938
  disabledFeatures: options.disabledFeatures
2866
2939
  });
@@ -2875,8 +2948,10 @@ function deserialize(source) {
2875
2948
  return (0, eval)(source);
2876
2949
  }
2877
2950
  function toJSON(source, options = {}) {
2951
+ const plugins = resolvePlugins(options.plugins);
2878
2952
  const ctx = createSyncParserContext(1, {
2879
- plugins: resolvePlugins(options.plugins),
2953
+ compactArrayBufferViews: options.compactArrayBufferViews,
2954
+ plugins,
2880
2955
  disabledFeatures: options.disabledFeatures
2881
2956
  });
2882
2957
  return {
@@ -2886,8 +2961,10 @@ function toJSON(source, options = {}) {
2886
2961
  };
2887
2962
  }
2888
2963
  async function toJSONAsync(source, options = {}) {
2964
+ const plugins = resolvePlugins(options.plugins);
2889
2965
  const ctx = createAsyncParserContext(1, {
2890
- plugins: resolvePlugins(options.plugins),
2966
+ compactArrayBufferViews: options.compactArrayBufferViews,
2967
+ plugins,
2891
2968
  disabledFeatures: options.disabledFeatures
2892
2969
  });
2893
2970
  return {
@@ -2909,6 +2986,7 @@ function fromJSON(source, options = {}) {
2909
2986
  const disabledFeatures = options.disabledFeatures || 0;
2910
2987
  const sourceFeatures = (_source$f = source.f) !== null && _source$f !== void 0 ? _source$f : 127;
2911
2988
  return deserializeTop(createVanillaDeserializerContext({
2989
+ maxBase64Length: options.maxBase64Length,
2912
2990
  plugins,
2913
2991
  markedRefs: source.m,
2914
2992
  features: sourceFeatures & ~disabledFeatures,
package/dist/index.d.cts CHANGED
@@ -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;
package/dist/index.d.ts CHANGED
@@ -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;