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/dev/index.cjs +107 -29
- package/dist/dev/index.d.cts +8 -1
- package/dist/dev/index.d.ts +8 -1
- package/dist/dev/index.js +107 -29
- package/dist/index.cjs +107 -29
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +107 -29
- package/package.json +1 -1
package/dist/dev/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
|
|
@@ -524,7 +528,10 @@ const STREAM_CONSTRUCTOR = () => {
|
|
|
524
528
|
let count = 0;
|
|
525
529
|
const internal = {
|
|
526
530
|
flush(value, mode, x) {
|
|
527
|
-
for (x = 0; x < count; x++)
|
|
531
|
+
for (x = 0; x < count; x++) {
|
|
532
|
+
const listener = listeners[x];
|
|
533
|
+
if (listener) listener[mode](value);
|
|
534
|
+
}
|
|
528
535
|
},
|
|
529
536
|
up(listener, x, z, current) {
|
|
530
537
|
for (x = 0, z = buffer.length; x < z; x++) {
|
|
@@ -533,16 +540,20 @@ const STREAM_CONSTRUCTOR = () => {
|
|
|
533
540
|
else listener.next(current);
|
|
534
541
|
}
|
|
535
542
|
},
|
|
536
|
-
on(listener, temp) {
|
|
543
|
+
on(listener, temp = 0) {
|
|
544
|
+
let subscribed = alive;
|
|
537
545
|
if (alive) {
|
|
538
|
-
temp = count
|
|
546
|
+
for (temp = 0; temp < count; temp++) if (!listeners[temp]) break;
|
|
547
|
+
if (temp === count) count++;
|
|
539
548
|
listeners[temp] = listener;
|
|
540
549
|
}
|
|
541
550
|
internal.up(listener);
|
|
542
551
|
return () => {
|
|
543
|
-
if (alive) {
|
|
544
|
-
|
|
545
|
-
listeners[
|
|
552
|
+
if (alive && subscribed) {
|
|
553
|
+
subscribed = false;
|
|
554
|
+
listeners[temp] = void 0;
|
|
555
|
+
while (count > 0 && !listeners[count - 1]) count--;
|
|
556
|
+
listeners.length = count;
|
|
546
557
|
}
|
|
547
558
|
};
|
|
548
559
|
}
|
|
@@ -753,19 +764,35 @@ function isStream(value) {
|
|
|
753
764
|
function createStream() {
|
|
754
765
|
return STREAM_CONSTRUCTOR();
|
|
755
766
|
}
|
|
756
|
-
function createStreamFromAsyncIterable(iterable) {
|
|
767
|
+
function createStreamFromAsyncIterable(iterable, cleanups) {
|
|
757
768
|
const stream = createStream();
|
|
758
769
|
const iterator = iterable[SYM_ASYNC_ITERATOR]();
|
|
770
|
+
let cancelled = false;
|
|
771
|
+
let done = false;
|
|
772
|
+
cleanups === null || cleanups === void 0 || cleanups.push(() => {
|
|
773
|
+
if (!(done || cancelled)) {
|
|
774
|
+
cancelled = true;
|
|
775
|
+
Promise.resolve().then(() => {
|
|
776
|
+
var _iterator$return;
|
|
777
|
+
return (_iterator$return = iterator.return) === null || _iterator$return === void 0 ? void 0 : _iterator$return.call(iterator);
|
|
778
|
+
}).catch(() => {});
|
|
779
|
+
}
|
|
780
|
+
});
|
|
759
781
|
async function push() {
|
|
760
782
|
try {
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
783
|
+
while (!cancelled) {
|
|
784
|
+
const value = await iterator.next();
|
|
785
|
+
if (cancelled) return;
|
|
786
|
+
if (value.done) {
|
|
787
|
+
done = true;
|
|
788
|
+
stream.return(value.value);
|
|
789
|
+
break;
|
|
790
|
+
}
|
|
764
791
|
stream.next(value.value);
|
|
765
|
-
await push();
|
|
766
792
|
}
|
|
767
793
|
} catch (error) {
|
|
768
|
-
|
|
794
|
+
done = true;
|
|
795
|
+
if (!cancelled) stream.throw(error);
|
|
769
796
|
}
|
|
770
797
|
}
|
|
771
798
|
push().catch(() => {});
|
|
@@ -787,13 +814,15 @@ async function promiseToResult(current) {
|
|
|
787
814
|
//#endregion
|
|
788
815
|
//#region src/core/context/parser.ts
|
|
789
816
|
function createBaseParserContext(mode, options) {
|
|
817
|
+
var _options$compactArray;
|
|
790
818
|
return {
|
|
791
819
|
plugins: options.plugins,
|
|
792
820
|
mode,
|
|
793
821
|
marked: /* @__PURE__ */ new Set(),
|
|
794
822
|
features: 127 ^ (options.disabledFeatures || 0),
|
|
795
823
|
refs: options.refs || /* @__PURE__ */ new Map(),
|
|
796
|
-
depthLimit: options.depthLimit || 1e3
|
|
824
|
+
depthLimit: options.depthLimit || 1e3,
|
|
825
|
+
compactArrayBufferViews: (_options$compactArray = options.compactArrayBufferViews) !== null && _options$compactArray !== void 0 ? _options$compactArray : false
|
|
797
826
|
};
|
|
798
827
|
}
|
|
799
828
|
/**
|
|
@@ -873,11 +902,22 @@ function createMapNode(ctx, id, k, v) {
|
|
|
873
902
|
function createPromiseConstructorNode(ctx, id, resolver) {
|
|
874
903
|
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
904
|
}
|
|
876
|
-
function
|
|
905
|
+
function getArrayBufferView(ctx, current) {
|
|
906
|
+
if (!ctx.compactArrayBufferViews) return current;
|
|
907
|
+
const buffer = new Uint8Array(current.buffer, current.byteOffset, current.byteLength).slice().buffer;
|
|
908
|
+
const Constructor = current.constructor;
|
|
909
|
+
return new Constructor(buffer);
|
|
910
|
+
}
|
|
911
|
+
function encodeArrayBuffer(current) {
|
|
912
|
+
if (typeof Buffer !== "undefined") return Buffer.from(current).toString("base64");
|
|
877
913
|
const bytes = new Uint8Array(current);
|
|
914
|
+
if (typeof bytes.toBase64 === "function") return bytes.toBase64();
|
|
878
915
|
let result = "";
|
|
879
916
|
for (let i = 0, len = bytes.length; i < len; i++) result += String.fromCharCode(bytes[i]);
|
|
880
|
-
return
|
|
917
|
+
return btoa(result);
|
|
918
|
+
}
|
|
919
|
+
function createArrayBufferNode(ctx, id, current) {
|
|
920
|
+
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
921
|
}
|
|
882
922
|
//#endregion
|
|
883
923
|
//#region src/core/context/async-parser.ts
|
|
@@ -941,12 +981,15 @@ async function parseBoxed$1(ctx, depth, id, current) {
|
|
|
941
981
|
return createBoxedNode(id, await parseAsync(ctx, depth, current.valueOf()));
|
|
942
982
|
}
|
|
943
983
|
async function parseTypedArray$1(ctx, depth, id, current) {
|
|
984
|
+
current = getArrayBufferView(ctx.base, current);
|
|
944
985
|
return createTypedArrayNode(id, current, await parseAsync(ctx, depth, current.buffer));
|
|
945
986
|
}
|
|
946
987
|
async function parseBigIntTypedArray$1(ctx, depth, id, current) {
|
|
988
|
+
current = getArrayBufferView(ctx.base, current);
|
|
947
989
|
return createBigIntTypedArrayNode(id, current, await parseAsync(ctx, depth, current.buffer));
|
|
948
990
|
}
|
|
949
991
|
async function parseDataView$1(ctx, depth, id, current) {
|
|
992
|
+
current = getArrayBufferView(ctx.base, current);
|
|
950
993
|
return createDataViewNode(id, current, await parseAsync(ctx, depth, current.buffer));
|
|
951
994
|
}
|
|
952
995
|
async function parseError$1(ctx, depth, id, current) {
|
|
@@ -1191,7 +1234,8 @@ function isValidSymbol(symbol) {
|
|
|
1191
1234
|
}
|
|
1192
1235
|
//#endregion
|
|
1193
1236
|
//#region src/core/context/deserializer.ts
|
|
1194
|
-
const
|
|
1237
|
+
const DEFAULT_MAX_BASE64_LENGTH = 1e6;
|
|
1238
|
+
const MIN_NATIVE_BASE64_LENGTH = 512;
|
|
1195
1239
|
const MAX_BIGINT_LENGTH = 1e4;
|
|
1196
1240
|
const MAX_REGEXP_SOURCE_LENGTH = 2e4;
|
|
1197
1241
|
function applyObjectFlag(obj, flag) {
|
|
@@ -1204,7 +1248,9 @@ function applyObjectFlag(obj, flag) {
|
|
|
1204
1248
|
}
|
|
1205
1249
|
const DEFAULT_DEPTH_LIMIT = 1e3;
|
|
1206
1250
|
function createBaseDeserializerContext(mode, options) {
|
|
1207
|
-
var _options$features;
|
|
1251
|
+
var _options$maxBase64Len, _options$features;
|
|
1252
|
+
const maxBase64Length = (_options$maxBase64Len = options.maxBase64Length) !== null && _options$maxBase64Len !== void 0 ? _options$maxBase64Len : DEFAULT_MAX_BASE64_LENGTH;
|
|
1253
|
+
if (!Number.isSafeInteger(maxBase64Length) || maxBase64Length < 0) throw new RangeError("maxBase64Length must be a non-negative safe integer");
|
|
1208
1254
|
const refs = options.refs || /* @__PURE__ */ new Map();
|
|
1209
1255
|
if (!("types" in refs)) Object.assign(refs, { types: /* @__PURE__ */ new Map() });
|
|
1210
1256
|
return {
|
|
@@ -1212,7 +1258,8 @@ function createBaseDeserializerContext(mode, options) {
|
|
|
1212
1258
|
plugins: options.plugins,
|
|
1213
1259
|
refs,
|
|
1214
1260
|
features: (_options$features = options.features) !== null && _options$features !== void 0 ? _options$features : 127 ^ (options.disabledFeatures || 0),
|
|
1215
|
-
depthLimit: options.depthLimit || DEFAULT_DEPTH_LIMIT
|
|
1261
|
+
depthLimit: options.depthLimit || DEFAULT_DEPTH_LIMIT,
|
|
1262
|
+
maxBase64Length
|
|
1216
1263
|
};
|
|
1217
1264
|
}
|
|
1218
1265
|
function createVanillaDeserializerContext(options) {
|
|
@@ -1375,8 +1422,17 @@ function deserializeMap(ctx, depth, node) {
|
|
|
1375
1422
|
return result;
|
|
1376
1423
|
}
|
|
1377
1424
|
function deserializeArrayBuffer(ctx, node) {
|
|
1378
|
-
if (node.s
|
|
1379
|
-
|
|
1425
|
+
if (typeof node.s !== "string") throw new SerovalMalformedNodeError(node);
|
|
1426
|
+
if (node.s.length > ctx.base.maxBase64Length) throw new RangeError("ArrayBuffer exceeds maxBase64Length (" + ctx.base.maxBase64Length + ")");
|
|
1427
|
+
const source = deserializeString(node.s);
|
|
1428
|
+
let buffer;
|
|
1429
|
+
if (source.length < MIN_NATIVE_BASE64_LENGTH || typeof Buffer === "undefined") buffer = ARRAY_BUFFER_CONSTRUCTOR(source);
|
|
1430
|
+
else {
|
|
1431
|
+
const decoded = atob(source);
|
|
1432
|
+
buffer = new ArrayBuffer(decoded.length);
|
|
1433
|
+
Buffer.from(buffer).write(decoded, "latin1");
|
|
1434
|
+
}
|
|
1435
|
+
return assignIndexedValue$1(ctx, node.i, buffer);
|
|
1380
1436
|
}
|
|
1381
1437
|
function deserializeTypedArray(ctx, depth, node) {
|
|
1382
1438
|
var _node$b;
|
|
@@ -1384,7 +1440,7 @@ function deserializeTypedArray(ctx, depth, node) {
|
|
|
1384
1440
|
const source = deserialize$1(ctx, depth, node.f);
|
|
1385
1441
|
if (!(source instanceof ArrayBuffer)) throw new SerovalMalformedNodeError(node);
|
|
1386
1442
|
const offset = (_node$b = node.b) !== null && _node$b !== void 0 ? _node$b : 0;
|
|
1387
|
-
if (offset < 0 || offset > source.byteLength
|
|
1443
|
+
if (offset < 0 || offset > source.byteLength) throw new SerovalMalformedNodeError(node);
|
|
1388
1444
|
return assignIndexedValue$1(ctx, node.i, new construct(source, offset, node.l));
|
|
1389
1445
|
}
|
|
1390
1446
|
function deserializeDataView(ctx, depth, node) {
|
|
@@ -1392,7 +1448,7 @@ function deserializeDataView(ctx, depth, node) {
|
|
|
1392
1448
|
const source = deserialize$1(ctx, depth, node.f);
|
|
1393
1449
|
if (!(source instanceof ArrayBuffer)) throw new SerovalMalformedNodeError(node);
|
|
1394
1450
|
const offset = (_node$b2 = node.b) !== null && _node$b2 !== void 0 ? _node$b2 : 0;
|
|
1395
|
-
if (offset < 0 || offset > source.byteLength
|
|
1451
|
+
if (offset < 0 || offset > source.byteLength) throw new SerovalMalformedNodeError(node);
|
|
1396
1452
|
return assignIndexedValue$1(ctx, node.i, new DataView(source, offset, node.l));
|
|
1397
1453
|
}
|
|
1398
1454
|
function deserializeDictionary(ctx, depth, node, result) {
|
|
@@ -2412,7 +2468,7 @@ function parseProperties(ctx, depth, properties) {
|
|
|
2412
2468
|
}
|
|
2413
2469
|
if (SYM_ASYNC_ITERATOR in properties) {
|
|
2414
2470
|
keyNodes.push(parseWellKnownSymbol(ctx.base, SYM_ASYNC_ITERATOR));
|
|
2415
|
-
valueNodes.push(createAsyncIteratorFactoryInstanceNode(parseAsyncIteratorFactory(ctx.base), parseSOS(ctx, depth, ctx.type === 1 ? createStream() : createStreamFromAsyncIterable(properties))));
|
|
2471
|
+
valueNodes.push(createAsyncIteratorFactoryInstanceNode(parseAsyncIteratorFactory(ctx.base), parseSOS(ctx, depth, ctx.type === 1 ? createStream() : createStreamFromAsyncIterable(properties, ctx.state.cleanups))));
|
|
2416
2472
|
}
|
|
2417
2473
|
if (SYM_TO_STRING_TAG in properties) {
|
|
2418
2474
|
keyNodes.push(parseWellKnownSymbol(ctx.base, SYM_TO_STRING_TAG));
|
|
@@ -2434,12 +2490,15 @@ function parseBoxed(ctx, depth, id, current) {
|
|
|
2434
2490
|
return createBoxedNode(id, parseSOS(ctx, depth, current.valueOf()));
|
|
2435
2491
|
}
|
|
2436
2492
|
function parseTypedArray(ctx, depth, id, current) {
|
|
2493
|
+
current = getArrayBufferView(ctx.base, current);
|
|
2437
2494
|
return createTypedArrayNode(id, current, parseSOS(ctx, depth, current.buffer));
|
|
2438
2495
|
}
|
|
2439
2496
|
function parseBigIntTypedArray(ctx, depth, id, current) {
|
|
2497
|
+
current = getArrayBufferView(ctx.base, current);
|
|
2440
2498
|
return createBigIntTypedArrayNode(id, current, parseSOS(ctx, depth, current.buffer));
|
|
2441
2499
|
}
|
|
2442
2500
|
function parseDataView(ctx, depth, id, current) {
|
|
2501
|
+
current = getArrayBufferView(ctx.base, current);
|
|
2443
2502
|
return createDataViewNode(id, current, parseSOS(ctx, depth, current.buffer));
|
|
2444
2503
|
}
|
|
2445
2504
|
function parseError(ctx, depth, id, current) {
|
|
@@ -2690,6 +2749,7 @@ function destroyStreamParse(ctx) {
|
|
|
2690
2749
|
function crossSerialize(source, options = {}) {
|
|
2691
2750
|
const plugins = resolvePlugins(options.plugins);
|
|
2692
2751
|
const ctx = createSyncParserContext(2, {
|
|
2752
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2693
2753
|
plugins,
|
|
2694
2754
|
disabledFeatures: options.disabledFeatures,
|
|
2695
2755
|
refs: options.refs
|
|
@@ -2705,6 +2765,7 @@ function crossSerialize(source, options = {}) {
|
|
|
2705
2765
|
async function crossSerializeAsync(source, options = {}) {
|
|
2706
2766
|
const plugins = resolvePlugins(options.plugins);
|
|
2707
2767
|
const ctx = createAsyncParserContext(2, {
|
|
2768
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2708
2769
|
plugins,
|
|
2709
2770
|
disabledFeatures: options.disabledFeatures,
|
|
2710
2771
|
refs: options.refs
|
|
@@ -2718,15 +2779,19 @@ async function crossSerializeAsync(source, options = {}) {
|
|
|
2718
2779
|
}), tree);
|
|
2719
2780
|
}
|
|
2720
2781
|
function toCrossJSON(source, options = {}) {
|
|
2782
|
+
const plugins = resolvePlugins(options.plugins);
|
|
2721
2783
|
return parseTop(createSyncParserContext(2, {
|
|
2722
|
-
|
|
2784
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2785
|
+
plugins,
|
|
2723
2786
|
disabledFeatures: options.disabledFeatures,
|
|
2724
2787
|
refs: options.refs
|
|
2725
2788
|
}), source);
|
|
2726
2789
|
}
|
|
2727
2790
|
async function toCrossJSONAsync(source, options = {}) {
|
|
2791
|
+
const plugins = resolvePlugins(options.plugins);
|
|
2728
2792
|
return await parseTopAsync(createAsyncParserContext(2, {
|
|
2729
|
-
|
|
2793
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2794
|
+
plugins,
|
|
2730
2795
|
disabledFeatures: options.disabledFeatures,
|
|
2731
2796
|
refs: options.refs
|
|
2732
2797
|
}), source);
|
|
@@ -2734,6 +2799,7 @@ async function toCrossJSONAsync(source, options = {}) {
|
|
|
2734
2799
|
function crossSerializeStream(source, options) {
|
|
2735
2800
|
const plugins = resolvePlugins(options.plugins);
|
|
2736
2801
|
const ctx = createStreamParserContext({
|
|
2802
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2737
2803
|
plugins,
|
|
2738
2804
|
refs: options.refs,
|
|
2739
2805
|
disabledFeatures: options.disabledFeatures,
|
|
@@ -2760,8 +2826,10 @@ function crossSerializeStream(source, options) {
|
|
|
2760
2826
|
return destroyStreamParse.bind(null, ctx);
|
|
2761
2827
|
}
|
|
2762
2828
|
function toCrossJSONStream(source, options) {
|
|
2829
|
+
const plugins = resolvePlugins(options.plugins);
|
|
2763
2830
|
const ctx = createStreamParserContext({
|
|
2764
|
-
|
|
2831
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2832
|
+
plugins,
|
|
2765
2833
|
refs: options.refs,
|
|
2766
2834
|
disabledFeatures: options.disabledFeatures,
|
|
2767
2835
|
depthLimit: options.depthLimit,
|
|
@@ -2773,8 +2841,10 @@ function toCrossJSONStream(source, options) {
|
|
|
2773
2841
|
return destroyStreamParse.bind(null, ctx);
|
|
2774
2842
|
}
|
|
2775
2843
|
function fromCrossJSON(source, options) {
|
|
2844
|
+
const plugins = resolvePlugins(options.plugins);
|
|
2776
2845
|
return deserializeTop(createCrossDeserializerContext({
|
|
2777
|
-
|
|
2846
|
+
maxBase64Length: options.maxBase64Length,
|
|
2847
|
+
plugins,
|
|
2778
2848
|
refs: options.refs,
|
|
2779
2849
|
features: options.features,
|
|
2780
2850
|
disabledFeatures: options.disabledFeatures,
|
|
@@ -2805,6 +2875,7 @@ var Serializer = class {
|
|
|
2805
2875
|
scopeId: this.options.scopeId,
|
|
2806
2876
|
refs: this.refs,
|
|
2807
2877
|
disabledFeatures: this.options.disabledFeatures,
|
|
2878
|
+
compactArrayBufferViews: this.options.compactArrayBufferViews,
|
|
2808
2879
|
onError: this.options.onError,
|
|
2809
2880
|
onSerialize: (data, initial) => {
|
|
2810
2881
|
if (this.alive) this.options.onData(initial ? this.options.globalIdentifier + "[\"" + serializeString(key) + "\"]=" + data : data);
|
|
@@ -2855,6 +2926,7 @@ var Serializer = class {
|
|
|
2855
2926
|
function serialize(source, options = {}) {
|
|
2856
2927
|
const plugins = resolvePlugins(options.plugins);
|
|
2857
2928
|
const ctx = createSyncParserContext(1, {
|
|
2929
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2858
2930
|
plugins,
|
|
2859
2931
|
disabledFeatures: options.disabledFeatures
|
|
2860
2932
|
});
|
|
@@ -2868,6 +2940,7 @@ function serialize(source, options = {}) {
|
|
|
2868
2940
|
async function serializeAsync(source, options = {}) {
|
|
2869
2941
|
const plugins = resolvePlugins(options.plugins);
|
|
2870
2942
|
const ctx = createAsyncParserContext(1, {
|
|
2943
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2871
2944
|
plugins,
|
|
2872
2945
|
disabledFeatures: options.disabledFeatures
|
|
2873
2946
|
});
|
|
@@ -2882,8 +2955,10 @@ function deserialize(source) {
|
|
|
2882
2955
|
return (0, eval)(source);
|
|
2883
2956
|
}
|
|
2884
2957
|
function toJSON(source, options = {}) {
|
|
2958
|
+
const plugins = resolvePlugins(options.plugins);
|
|
2885
2959
|
const ctx = createSyncParserContext(1, {
|
|
2886
|
-
|
|
2960
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2961
|
+
plugins,
|
|
2887
2962
|
disabledFeatures: options.disabledFeatures
|
|
2888
2963
|
});
|
|
2889
2964
|
return {
|
|
@@ -2893,8 +2968,10 @@ function toJSON(source, options = {}) {
|
|
|
2893
2968
|
};
|
|
2894
2969
|
}
|
|
2895
2970
|
async function toJSONAsync(source, options = {}) {
|
|
2971
|
+
const plugins = resolvePlugins(options.plugins);
|
|
2896
2972
|
const ctx = createAsyncParserContext(1, {
|
|
2897
|
-
|
|
2973
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2974
|
+
plugins,
|
|
2898
2975
|
disabledFeatures: options.disabledFeatures
|
|
2899
2976
|
});
|
|
2900
2977
|
return {
|
|
@@ -2916,6 +2993,7 @@ function fromJSON(source, options = {}) {
|
|
|
2916
2993
|
const disabledFeatures = options.disabledFeatures || 0;
|
|
2917
2994
|
const sourceFeatures = (_source$f = source.f) !== null && _source$f !== void 0 ? _source$f : 127;
|
|
2918
2995
|
return deserializeTop(createVanillaDeserializerContext({
|
|
2996
|
+
maxBase64Length: options.maxBase64Length,
|
|
2919
2997
|
plugins,
|
|
2920
2998
|
markedRefs: source.m,
|
|
2921
2999
|
features: sourceFeatures & ~disabledFeatures,
|
package/dist/dev/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/dev/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;
|