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.
- package/dist/dev/index.cjs +96 -28
- package/dist/dev/index.d.cts +8 -1
- package/dist/dev/index.d.ts +8 -1
- package/dist/dev/index.js +96 -28
- package/dist/index.cjs +96 -28
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +96 -28
- package/package.json +1 -1
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;
|
|
@@ -517,7 +520,10 @@ const STREAM_CONSTRUCTOR = () => {
|
|
|
517
520
|
let count = 0;
|
|
518
521
|
const internal = {
|
|
519
522
|
flush(value, mode, x) {
|
|
520
|
-
for (x = 0; x < count; x++)
|
|
523
|
+
for (x = 0; x < count; x++) {
|
|
524
|
+
const listener = listeners[x];
|
|
525
|
+
if (listener) listener[mode](value);
|
|
526
|
+
}
|
|
521
527
|
},
|
|
522
528
|
up(listener, x, z, current) {
|
|
523
529
|
for (x = 0, z = buffer.length; x < z; x++) {
|
|
@@ -526,16 +532,20 @@ const STREAM_CONSTRUCTOR = () => {
|
|
|
526
532
|
else listener.next(current);
|
|
527
533
|
}
|
|
528
534
|
},
|
|
529
|
-
on(listener, temp) {
|
|
535
|
+
on(listener, temp = 0) {
|
|
536
|
+
let subscribed = alive;
|
|
530
537
|
if (alive) {
|
|
531
|
-
temp = count
|
|
538
|
+
for (temp = 0; temp < count; temp++) if (!listeners[temp]) break;
|
|
539
|
+
if (temp === count) count++;
|
|
532
540
|
listeners[temp] = listener;
|
|
533
541
|
}
|
|
534
542
|
internal.up(listener);
|
|
535
543
|
return () => {
|
|
536
|
-
if (alive) {
|
|
537
|
-
|
|
538
|
-
listeners[
|
|
544
|
+
if (alive && subscribed) {
|
|
545
|
+
subscribed = false;
|
|
546
|
+
listeners[temp] = void 0;
|
|
547
|
+
while (count > 0 && !listeners[count - 1]) count--;
|
|
548
|
+
listeners.length = count;
|
|
539
549
|
}
|
|
540
550
|
};
|
|
541
551
|
}
|
|
@@ -746,19 +756,35 @@ function isStream(value) {
|
|
|
746
756
|
function createStream() {
|
|
747
757
|
return STREAM_CONSTRUCTOR();
|
|
748
758
|
}
|
|
749
|
-
function createStreamFromAsyncIterable(iterable) {
|
|
759
|
+
function createStreamFromAsyncIterable(iterable, cleanups) {
|
|
750
760
|
const stream = createStream();
|
|
751
761
|
const iterator = iterable[SYM_ASYNC_ITERATOR]();
|
|
762
|
+
let cancelled = false;
|
|
763
|
+
let done = false;
|
|
764
|
+
cleanups === null || cleanups === void 0 || cleanups.push(() => {
|
|
765
|
+
if (!(done || cancelled)) {
|
|
766
|
+
cancelled = true;
|
|
767
|
+
Promise.resolve().then(() => {
|
|
768
|
+
var _iterator$return;
|
|
769
|
+
return (_iterator$return = iterator.return) === null || _iterator$return === void 0 ? void 0 : _iterator$return.call(iterator);
|
|
770
|
+
}).catch(() => {});
|
|
771
|
+
}
|
|
772
|
+
});
|
|
752
773
|
async function push() {
|
|
753
774
|
try {
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
775
|
+
while (!cancelled) {
|
|
776
|
+
const value = await iterator.next();
|
|
777
|
+
if (cancelled) return;
|
|
778
|
+
if (value.done) {
|
|
779
|
+
done = true;
|
|
780
|
+
stream.return(value.value);
|
|
781
|
+
break;
|
|
782
|
+
}
|
|
757
783
|
stream.next(value.value);
|
|
758
|
-
await push();
|
|
759
784
|
}
|
|
760
785
|
} catch (error) {
|
|
761
|
-
|
|
786
|
+
done = true;
|
|
787
|
+
if (!cancelled) stream.throw(error);
|
|
762
788
|
}
|
|
763
789
|
}
|
|
764
790
|
push().catch(() => {});
|
|
@@ -780,13 +806,15 @@ async function promiseToResult(current) {
|
|
|
780
806
|
//#endregion
|
|
781
807
|
//#region src/core/context/parser.ts
|
|
782
808
|
function createBaseParserContext(mode, options) {
|
|
809
|
+
var _options$compactArray;
|
|
783
810
|
return {
|
|
784
811
|
plugins: options.plugins,
|
|
785
812
|
mode,
|
|
786
813
|
marked: /* @__PURE__ */ new Set(),
|
|
787
814
|
features: 127 ^ (options.disabledFeatures || 0),
|
|
788
815
|
refs: options.refs || /* @__PURE__ */ new Map(),
|
|
789
|
-
depthLimit: options.depthLimit || 1e3
|
|
816
|
+
depthLimit: options.depthLimit || 1e3,
|
|
817
|
+
compactArrayBufferViews: (_options$compactArray = options.compactArrayBufferViews) !== null && _options$compactArray !== void 0 ? _options$compactArray : false
|
|
790
818
|
};
|
|
791
819
|
}
|
|
792
820
|
/**
|
|
@@ -866,11 +894,22 @@ function createMapNode(ctx, id, k, v) {
|
|
|
866
894
|
function createPromiseConstructorNode(ctx, id, resolver) {
|
|
867
895
|
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
896
|
}
|
|
869
|
-
function
|
|
897
|
+
function getArrayBufferView(ctx, current) {
|
|
898
|
+
if (!ctx.compactArrayBufferViews) return current;
|
|
899
|
+
const buffer = new Uint8Array(current.buffer, current.byteOffset, current.byteLength).slice().buffer;
|
|
900
|
+
const Constructor = current.constructor;
|
|
901
|
+
return new Constructor(buffer);
|
|
902
|
+
}
|
|
903
|
+
function encodeArrayBuffer(current) {
|
|
904
|
+
if (typeof Buffer !== "undefined") return Buffer.from(current).toString("base64");
|
|
870
905
|
const bytes = new Uint8Array(current);
|
|
906
|
+
if (typeof bytes.toBase64 === "function") return bytes.toBase64();
|
|
871
907
|
let result = "";
|
|
872
908
|
for (let i = 0, len = bytes.length; i < len; i++) result += String.fromCharCode(bytes[i]);
|
|
873
|
-
return
|
|
909
|
+
return btoa(result);
|
|
910
|
+
}
|
|
911
|
+
function createArrayBufferNode(ctx, id, current) {
|
|
912
|
+
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
913
|
}
|
|
875
914
|
//#endregion
|
|
876
915
|
//#region src/core/context/async-parser.ts
|
|
@@ -934,12 +973,15 @@ async function parseBoxed$1(ctx, depth, id, current) {
|
|
|
934
973
|
return createBoxedNode(id, await parseAsync(ctx, depth, current.valueOf()));
|
|
935
974
|
}
|
|
936
975
|
async function parseTypedArray$1(ctx, depth, id, current) {
|
|
976
|
+
current = getArrayBufferView(ctx.base, current);
|
|
937
977
|
return createTypedArrayNode(id, current, await parseAsync(ctx, depth, current.buffer));
|
|
938
978
|
}
|
|
939
979
|
async function parseBigIntTypedArray$1(ctx, depth, id, current) {
|
|
980
|
+
current = getArrayBufferView(ctx.base, current);
|
|
940
981
|
return createBigIntTypedArrayNode(id, current, await parseAsync(ctx, depth, current.buffer));
|
|
941
982
|
}
|
|
942
983
|
async function parseDataView$1(ctx, depth, id, current) {
|
|
984
|
+
current = getArrayBufferView(ctx.base, current);
|
|
943
985
|
return createDataViewNode(id, current, await parseAsync(ctx, depth, current.buffer));
|
|
944
986
|
}
|
|
945
987
|
async function parseError$1(ctx, depth, id, current) {
|
|
@@ -1184,7 +1226,7 @@ function isValidSymbol(symbol) {
|
|
|
1184
1226
|
}
|
|
1185
1227
|
//#endregion
|
|
1186
1228
|
//#region src/core/context/deserializer.ts
|
|
1187
|
-
const
|
|
1229
|
+
const DEFAULT_MAX_BASE64_LENGTH = 1e6;
|
|
1188
1230
|
const MAX_BIGINT_LENGTH = 1e4;
|
|
1189
1231
|
const MAX_REGEXP_SOURCE_LENGTH = 2e4;
|
|
1190
1232
|
function applyObjectFlag(obj, flag) {
|
|
@@ -1197,7 +1239,9 @@ function applyObjectFlag(obj, flag) {
|
|
|
1197
1239
|
}
|
|
1198
1240
|
const DEFAULT_DEPTH_LIMIT = 1e3;
|
|
1199
1241
|
function createBaseDeserializerContext(mode, options) {
|
|
1200
|
-
var _options$features;
|
|
1242
|
+
var _options$maxBase64Len, _options$features;
|
|
1243
|
+
const maxBase64Length = (_options$maxBase64Len = options.maxBase64Length) !== null && _options$maxBase64Len !== void 0 ? _options$maxBase64Len : DEFAULT_MAX_BASE64_LENGTH;
|
|
1244
|
+
if (!Number.isSafeInteger(maxBase64Length) || maxBase64Length < 0) throw new RangeError("maxBase64Length must be a non-negative safe integer");
|
|
1201
1245
|
const refs = options.refs || /* @__PURE__ */ new Map();
|
|
1202
1246
|
if (!("types" in refs)) Object.assign(refs, { types: /* @__PURE__ */ new Map() });
|
|
1203
1247
|
return {
|
|
@@ -1205,7 +1249,8 @@ function createBaseDeserializerContext(mode, options) {
|
|
|
1205
1249
|
plugins: options.plugins,
|
|
1206
1250
|
refs,
|
|
1207
1251
|
features: (_options$features = options.features) !== null && _options$features !== void 0 ? _options$features : 127 ^ (options.disabledFeatures || 0),
|
|
1208
|
-
depthLimit: options.depthLimit || DEFAULT_DEPTH_LIMIT
|
|
1252
|
+
depthLimit: options.depthLimit || DEFAULT_DEPTH_LIMIT,
|
|
1253
|
+
maxBase64Length
|
|
1209
1254
|
};
|
|
1210
1255
|
}
|
|
1211
1256
|
function createVanillaDeserializerContext(options) {
|
|
@@ -1368,7 +1413,8 @@ function deserializeMap(ctx, depth, node) {
|
|
|
1368
1413
|
return result;
|
|
1369
1414
|
}
|
|
1370
1415
|
function deserializeArrayBuffer(ctx, node) {
|
|
1371
|
-
if (node.s
|
|
1416
|
+
if (typeof node.s !== "string") throw new SerovalMalformedNodeError(node);
|
|
1417
|
+
if (node.s.length > ctx.base.maxBase64Length) throw new RangeError("ArrayBuffer exceeds maxBase64Length (" + ctx.base.maxBase64Length + ")");
|
|
1372
1418
|
return assignIndexedValue$1(ctx, node.i, ARRAY_BUFFER_CONSTRUCTOR(deserializeString(node.s)));
|
|
1373
1419
|
}
|
|
1374
1420
|
function deserializeTypedArray(ctx, depth, node) {
|
|
@@ -1377,7 +1423,7 @@ function deserializeTypedArray(ctx, depth, node) {
|
|
|
1377
1423
|
const source = deserialize$1(ctx, depth, node.f);
|
|
1378
1424
|
if (!(source instanceof ArrayBuffer)) throw new SerovalMalformedNodeError(node);
|
|
1379
1425
|
const offset = (_node$b = node.b) !== null && _node$b !== void 0 ? _node$b : 0;
|
|
1380
|
-
if (offset < 0 || offset > source.byteLength || node.l >
|
|
1426
|
+
if (offset < 0 || offset > source.byteLength || node.l > ctx.base.maxBase64Length) throw new SerovalMalformedNodeError(node);
|
|
1381
1427
|
return assignIndexedValue$1(ctx, node.i, new construct(source, offset, node.l));
|
|
1382
1428
|
}
|
|
1383
1429
|
function deserializeDataView(ctx, depth, node) {
|
|
@@ -1385,7 +1431,7 @@ function deserializeDataView(ctx, depth, node) {
|
|
|
1385
1431
|
const source = deserialize$1(ctx, depth, node.f);
|
|
1386
1432
|
if (!(source instanceof ArrayBuffer)) throw new SerovalMalformedNodeError(node);
|
|
1387
1433
|
const offset = (_node$b2 = node.b) !== null && _node$b2 !== void 0 ? _node$b2 : 0;
|
|
1388
|
-
if (offset < 0 || offset > source.byteLength || node.l >
|
|
1434
|
+
if (offset < 0 || offset > source.byteLength || node.l > ctx.base.maxBase64Length) throw new SerovalMalformedNodeError(node);
|
|
1389
1435
|
return assignIndexedValue$1(ctx, node.i, new DataView(source, offset, node.l));
|
|
1390
1436
|
}
|
|
1391
1437
|
function deserializeDictionary(ctx, depth, node, result) {
|
|
@@ -2405,7 +2451,7 @@ function parseProperties(ctx, depth, properties) {
|
|
|
2405
2451
|
}
|
|
2406
2452
|
if (SYM_ASYNC_ITERATOR in properties) {
|
|
2407
2453
|
keyNodes.push(parseWellKnownSymbol(ctx.base, SYM_ASYNC_ITERATOR));
|
|
2408
|
-
valueNodes.push(createAsyncIteratorFactoryInstanceNode(parseAsyncIteratorFactory(ctx.base), parseSOS(ctx, depth, ctx.type === 1 ? createStream() : createStreamFromAsyncIterable(properties))));
|
|
2454
|
+
valueNodes.push(createAsyncIteratorFactoryInstanceNode(parseAsyncIteratorFactory(ctx.base), parseSOS(ctx, depth, ctx.type === 1 ? createStream() : createStreamFromAsyncIterable(properties, ctx.state.cleanups))));
|
|
2409
2455
|
}
|
|
2410
2456
|
if (SYM_TO_STRING_TAG in properties) {
|
|
2411
2457
|
keyNodes.push(parseWellKnownSymbol(ctx.base, SYM_TO_STRING_TAG));
|
|
@@ -2427,12 +2473,15 @@ function parseBoxed(ctx, depth, id, current) {
|
|
|
2427
2473
|
return createBoxedNode(id, parseSOS(ctx, depth, current.valueOf()));
|
|
2428
2474
|
}
|
|
2429
2475
|
function parseTypedArray(ctx, depth, id, current) {
|
|
2476
|
+
current = getArrayBufferView(ctx.base, current);
|
|
2430
2477
|
return createTypedArrayNode(id, current, parseSOS(ctx, depth, current.buffer));
|
|
2431
2478
|
}
|
|
2432
2479
|
function parseBigIntTypedArray(ctx, depth, id, current) {
|
|
2480
|
+
current = getArrayBufferView(ctx.base, current);
|
|
2433
2481
|
return createBigIntTypedArrayNode(id, current, parseSOS(ctx, depth, current.buffer));
|
|
2434
2482
|
}
|
|
2435
2483
|
function parseDataView(ctx, depth, id, current) {
|
|
2484
|
+
current = getArrayBufferView(ctx.base, current);
|
|
2436
2485
|
return createDataViewNode(id, current, parseSOS(ctx, depth, current.buffer));
|
|
2437
2486
|
}
|
|
2438
2487
|
function parseError(ctx, depth, id, current) {
|
|
@@ -2683,6 +2732,7 @@ function destroyStreamParse(ctx) {
|
|
|
2683
2732
|
function crossSerialize(source, options = {}) {
|
|
2684
2733
|
const plugins = resolvePlugins(options.plugins);
|
|
2685
2734
|
const ctx = createSyncParserContext(2, {
|
|
2735
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2686
2736
|
plugins,
|
|
2687
2737
|
disabledFeatures: options.disabledFeatures,
|
|
2688
2738
|
refs: options.refs
|
|
@@ -2698,6 +2748,7 @@ function crossSerialize(source, options = {}) {
|
|
|
2698
2748
|
async function crossSerializeAsync(source, options = {}) {
|
|
2699
2749
|
const plugins = resolvePlugins(options.plugins);
|
|
2700
2750
|
const ctx = createAsyncParserContext(2, {
|
|
2751
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2701
2752
|
plugins,
|
|
2702
2753
|
disabledFeatures: options.disabledFeatures,
|
|
2703
2754
|
refs: options.refs
|
|
@@ -2711,15 +2762,19 @@ async function crossSerializeAsync(source, options = {}) {
|
|
|
2711
2762
|
}), tree);
|
|
2712
2763
|
}
|
|
2713
2764
|
function toCrossJSON(source, options = {}) {
|
|
2765
|
+
const plugins = resolvePlugins(options.plugins);
|
|
2714
2766
|
return parseTop(createSyncParserContext(2, {
|
|
2715
|
-
|
|
2767
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2768
|
+
plugins,
|
|
2716
2769
|
disabledFeatures: options.disabledFeatures,
|
|
2717
2770
|
refs: options.refs
|
|
2718
2771
|
}), source);
|
|
2719
2772
|
}
|
|
2720
2773
|
async function toCrossJSONAsync(source, options = {}) {
|
|
2774
|
+
const plugins = resolvePlugins(options.plugins);
|
|
2721
2775
|
return await parseTopAsync(createAsyncParserContext(2, {
|
|
2722
|
-
|
|
2776
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2777
|
+
plugins,
|
|
2723
2778
|
disabledFeatures: options.disabledFeatures,
|
|
2724
2779
|
refs: options.refs
|
|
2725
2780
|
}), source);
|
|
@@ -2727,6 +2782,7 @@ async function toCrossJSONAsync(source, options = {}) {
|
|
|
2727
2782
|
function crossSerializeStream(source, options) {
|
|
2728
2783
|
const plugins = resolvePlugins(options.plugins);
|
|
2729
2784
|
const ctx = createStreamParserContext({
|
|
2785
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2730
2786
|
plugins,
|
|
2731
2787
|
refs: options.refs,
|
|
2732
2788
|
disabledFeatures: options.disabledFeatures,
|
|
@@ -2753,8 +2809,10 @@ function crossSerializeStream(source, options) {
|
|
|
2753
2809
|
return destroyStreamParse.bind(null, ctx);
|
|
2754
2810
|
}
|
|
2755
2811
|
function toCrossJSONStream(source, options) {
|
|
2812
|
+
const plugins = resolvePlugins(options.plugins);
|
|
2756
2813
|
const ctx = createStreamParserContext({
|
|
2757
|
-
|
|
2814
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2815
|
+
plugins,
|
|
2758
2816
|
refs: options.refs,
|
|
2759
2817
|
disabledFeatures: options.disabledFeatures,
|
|
2760
2818
|
depthLimit: options.depthLimit,
|
|
@@ -2766,8 +2824,10 @@ function toCrossJSONStream(source, options) {
|
|
|
2766
2824
|
return destroyStreamParse.bind(null, ctx);
|
|
2767
2825
|
}
|
|
2768
2826
|
function fromCrossJSON(source, options) {
|
|
2827
|
+
const plugins = resolvePlugins(options.plugins);
|
|
2769
2828
|
return deserializeTop(createCrossDeserializerContext({
|
|
2770
|
-
|
|
2829
|
+
maxBase64Length: options.maxBase64Length,
|
|
2830
|
+
plugins,
|
|
2771
2831
|
refs: options.refs,
|
|
2772
2832
|
features: options.features,
|
|
2773
2833
|
disabledFeatures: options.disabledFeatures,
|
|
@@ -2798,6 +2858,7 @@ var Serializer = class {
|
|
|
2798
2858
|
scopeId: this.options.scopeId,
|
|
2799
2859
|
refs: this.refs,
|
|
2800
2860
|
disabledFeatures: this.options.disabledFeatures,
|
|
2861
|
+
compactArrayBufferViews: this.options.compactArrayBufferViews,
|
|
2801
2862
|
onError: this.options.onError,
|
|
2802
2863
|
onSerialize: (data, initial) => {
|
|
2803
2864
|
if (this.alive) this.options.onData(initial ? this.options.globalIdentifier + "[\"" + serializeString(key) + "\"]=" + data : data);
|
|
@@ -2848,6 +2909,7 @@ var Serializer = class {
|
|
|
2848
2909
|
function serialize(source, options = {}) {
|
|
2849
2910
|
const plugins = resolvePlugins(options.plugins);
|
|
2850
2911
|
const ctx = createSyncParserContext(1, {
|
|
2912
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2851
2913
|
plugins,
|
|
2852
2914
|
disabledFeatures: options.disabledFeatures
|
|
2853
2915
|
});
|
|
@@ -2861,6 +2923,7 @@ function serialize(source, options = {}) {
|
|
|
2861
2923
|
async function serializeAsync(source, options = {}) {
|
|
2862
2924
|
const plugins = resolvePlugins(options.plugins);
|
|
2863
2925
|
const ctx = createAsyncParserContext(1, {
|
|
2926
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2864
2927
|
plugins,
|
|
2865
2928
|
disabledFeatures: options.disabledFeatures
|
|
2866
2929
|
});
|
|
@@ -2875,8 +2938,10 @@ function deserialize(source) {
|
|
|
2875
2938
|
return (0, eval)(source);
|
|
2876
2939
|
}
|
|
2877
2940
|
function toJSON(source, options = {}) {
|
|
2941
|
+
const plugins = resolvePlugins(options.plugins);
|
|
2878
2942
|
const ctx = createSyncParserContext(1, {
|
|
2879
|
-
|
|
2943
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2944
|
+
plugins,
|
|
2880
2945
|
disabledFeatures: options.disabledFeatures
|
|
2881
2946
|
});
|
|
2882
2947
|
return {
|
|
@@ -2886,8 +2951,10 @@ function toJSON(source, options = {}) {
|
|
|
2886
2951
|
};
|
|
2887
2952
|
}
|
|
2888
2953
|
async function toJSONAsync(source, options = {}) {
|
|
2954
|
+
const plugins = resolvePlugins(options.plugins);
|
|
2889
2955
|
const ctx = createAsyncParserContext(1, {
|
|
2890
|
-
|
|
2956
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2957
|
+
plugins,
|
|
2891
2958
|
disabledFeatures: options.disabledFeatures
|
|
2892
2959
|
});
|
|
2893
2960
|
return {
|
|
@@ -2909,6 +2976,7 @@ function fromJSON(source, options = {}) {
|
|
|
2909
2976
|
const disabledFeatures = options.disabledFeatures || 0;
|
|
2910
2977
|
const sourceFeatures = (_source$f = source.f) !== null && _source$f !== void 0 ? _source$f : 127;
|
|
2911
2978
|
return deserializeTop(createVanillaDeserializerContext({
|
|
2979
|
+
maxBase64Length: options.maxBase64Length,
|
|
2912
2980
|
plugins,
|
|
2913
2981
|
markedRefs: source.m,
|
|
2914
2982
|
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;
|