seroval 1.6.4 → 1.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dev/index.cjs +102 -30
- package/dist/dev/index.d.cts +10 -2
- package/dist/dev/index.d.ts +10 -2
- package/dist/dev/index.js +102 -31
- package/dist/index.cjs +102 -30
- package/dist/index.d.cts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +102 -31
- 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) {
|
|
@@ -1445,13 +1491,15 @@ function deserializePromiseFulfill(ctx, depth, node) {
|
|
|
1445
1491
|
function deserializeIteratorFactoryInstance(ctx, depth, node) {
|
|
1446
1492
|
deserialize$1(ctx, depth, node.a[0]);
|
|
1447
1493
|
const source = deserialize$1(ctx, depth, node.a[1]);
|
|
1448
|
-
|
|
1494
|
+
validateNodeType(ctx, node, node.a[1].i, 35);
|
|
1495
|
+
if (!source) throw new SerovalMalformedNodeError(node.a[1]);
|
|
1449
1496
|
return sequenceToIterator(source);
|
|
1450
1497
|
}
|
|
1451
1498
|
function deserializeAsyncIteratorFactoryInstance(ctx, depth, node) {
|
|
1452
1499
|
deserialize$1(ctx, depth, node.a[0]);
|
|
1453
1500
|
const source = deserialize$1(ctx, depth, node.a[1]);
|
|
1454
|
-
|
|
1501
|
+
validateNodeType(ctx, node, node.a[1].i, 31);
|
|
1502
|
+
if (!source) throw new SerovalMalformedNodeError(node.a[1]);
|
|
1455
1503
|
return streamToAsyncIterable(source);
|
|
1456
1504
|
}
|
|
1457
1505
|
function deserializeStreamConstructor(ctx, depth, node) {
|
|
@@ -1497,6 +1545,7 @@ function deserializeAsyncIteratorFactory(ctx, depth, node) {
|
|
|
1497
1545
|
}
|
|
1498
1546
|
function deserializeSequence(ctx, depth, node) {
|
|
1499
1547
|
const result = assignIndexedValue$1(ctx, node.i, createSequence([], node.s, node.l));
|
|
1548
|
+
assignNodeType(ctx, node.i, 35);
|
|
1500
1549
|
for (let i = 0, len = node.a.length; i < len; i++) result.v[i] = deserialize$1(ctx, depth, node.a[i]);
|
|
1501
1550
|
return result;
|
|
1502
1551
|
}
|
|
@@ -2402,7 +2451,7 @@ function parseProperties(ctx, depth, properties) {
|
|
|
2402
2451
|
}
|
|
2403
2452
|
if (SYM_ASYNC_ITERATOR in properties) {
|
|
2404
2453
|
keyNodes.push(parseWellKnownSymbol(ctx.base, SYM_ASYNC_ITERATOR));
|
|
2405
|
-
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))));
|
|
2406
2455
|
}
|
|
2407
2456
|
if (SYM_TO_STRING_TAG in properties) {
|
|
2408
2457
|
keyNodes.push(parseWellKnownSymbol(ctx.base, SYM_TO_STRING_TAG));
|
|
@@ -2424,12 +2473,15 @@ function parseBoxed(ctx, depth, id, current) {
|
|
|
2424
2473
|
return createBoxedNode(id, parseSOS(ctx, depth, current.valueOf()));
|
|
2425
2474
|
}
|
|
2426
2475
|
function parseTypedArray(ctx, depth, id, current) {
|
|
2476
|
+
current = getArrayBufferView(ctx.base, current);
|
|
2427
2477
|
return createTypedArrayNode(id, current, parseSOS(ctx, depth, current.buffer));
|
|
2428
2478
|
}
|
|
2429
2479
|
function parseBigIntTypedArray(ctx, depth, id, current) {
|
|
2480
|
+
current = getArrayBufferView(ctx.base, current);
|
|
2430
2481
|
return createBigIntTypedArrayNode(id, current, parseSOS(ctx, depth, current.buffer));
|
|
2431
2482
|
}
|
|
2432
2483
|
function parseDataView(ctx, depth, id, current) {
|
|
2484
|
+
current = getArrayBufferView(ctx.base, current);
|
|
2433
2485
|
return createDataViewNode(id, current, parseSOS(ctx, depth, current.buffer));
|
|
2434
2486
|
}
|
|
2435
2487
|
function parseError(ctx, depth, id, current) {
|
|
@@ -2680,6 +2732,7 @@ function destroyStreamParse(ctx) {
|
|
|
2680
2732
|
function crossSerialize(source, options = {}) {
|
|
2681
2733
|
const plugins = resolvePlugins(options.plugins);
|
|
2682
2734
|
const ctx = createSyncParserContext(2, {
|
|
2735
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2683
2736
|
plugins,
|
|
2684
2737
|
disabledFeatures: options.disabledFeatures,
|
|
2685
2738
|
refs: options.refs
|
|
@@ -2695,6 +2748,7 @@ function crossSerialize(source, options = {}) {
|
|
|
2695
2748
|
async function crossSerializeAsync(source, options = {}) {
|
|
2696
2749
|
const plugins = resolvePlugins(options.plugins);
|
|
2697
2750
|
const ctx = createAsyncParserContext(2, {
|
|
2751
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2698
2752
|
plugins,
|
|
2699
2753
|
disabledFeatures: options.disabledFeatures,
|
|
2700
2754
|
refs: options.refs
|
|
@@ -2708,15 +2762,19 @@ async function crossSerializeAsync(source, options = {}) {
|
|
|
2708
2762
|
}), tree);
|
|
2709
2763
|
}
|
|
2710
2764
|
function toCrossJSON(source, options = {}) {
|
|
2765
|
+
const plugins = resolvePlugins(options.plugins);
|
|
2711
2766
|
return parseTop(createSyncParserContext(2, {
|
|
2712
|
-
|
|
2767
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2768
|
+
plugins,
|
|
2713
2769
|
disabledFeatures: options.disabledFeatures,
|
|
2714
2770
|
refs: options.refs
|
|
2715
2771
|
}), source);
|
|
2716
2772
|
}
|
|
2717
2773
|
async function toCrossJSONAsync(source, options = {}) {
|
|
2774
|
+
const plugins = resolvePlugins(options.plugins);
|
|
2718
2775
|
return await parseTopAsync(createAsyncParserContext(2, {
|
|
2719
|
-
|
|
2776
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2777
|
+
plugins,
|
|
2720
2778
|
disabledFeatures: options.disabledFeatures,
|
|
2721
2779
|
refs: options.refs
|
|
2722
2780
|
}), source);
|
|
@@ -2724,6 +2782,7 @@ async function toCrossJSONAsync(source, options = {}) {
|
|
|
2724
2782
|
function crossSerializeStream(source, options) {
|
|
2725
2783
|
const plugins = resolvePlugins(options.plugins);
|
|
2726
2784
|
const ctx = createStreamParserContext({
|
|
2785
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2727
2786
|
plugins,
|
|
2728
2787
|
refs: options.refs,
|
|
2729
2788
|
disabledFeatures: options.disabledFeatures,
|
|
@@ -2750,8 +2809,10 @@ function crossSerializeStream(source, options) {
|
|
|
2750
2809
|
return destroyStreamParse.bind(null, ctx);
|
|
2751
2810
|
}
|
|
2752
2811
|
function toCrossJSONStream(source, options) {
|
|
2812
|
+
const plugins = resolvePlugins(options.plugins);
|
|
2753
2813
|
const ctx = createStreamParserContext({
|
|
2754
|
-
|
|
2814
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2815
|
+
plugins,
|
|
2755
2816
|
refs: options.refs,
|
|
2756
2817
|
disabledFeatures: options.disabledFeatures,
|
|
2757
2818
|
depthLimit: options.depthLimit,
|
|
@@ -2763,8 +2824,10 @@ function toCrossJSONStream(source, options) {
|
|
|
2763
2824
|
return destroyStreamParse.bind(null, ctx);
|
|
2764
2825
|
}
|
|
2765
2826
|
function fromCrossJSON(source, options) {
|
|
2827
|
+
const plugins = resolvePlugins(options.plugins);
|
|
2766
2828
|
return deserializeTop(createCrossDeserializerContext({
|
|
2767
|
-
|
|
2829
|
+
maxBase64Length: options.maxBase64Length,
|
|
2830
|
+
plugins,
|
|
2768
2831
|
refs: options.refs,
|
|
2769
2832
|
features: options.features,
|
|
2770
2833
|
disabledFeatures: options.disabledFeatures,
|
|
@@ -2795,6 +2858,7 @@ var Serializer = class {
|
|
|
2795
2858
|
scopeId: this.options.scopeId,
|
|
2796
2859
|
refs: this.refs,
|
|
2797
2860
|
disabledFeatures: this.options.disabledFeatures,
|
|
2861
|
+
compactArrayBufferViews: this.options.compactArrayBufferViews,
|
|
2798
2862
|
onError: this.options.onError,
|
|
2799
2863
|
onSerialize: (data, initial) => {
|
|
2800
2864
|
if (this.alive) this.options.onData(initial ? this.options.globalIdentifier + "[\"" + serializeString(key) + "\"]=" + data : data);
|
|
@@ -2845,6 +2909,7 @@ var Serializer = class {
|
|
|
2845
2909
|
function serialize(source, options = {}) {
|
|
2846
2910
|
const plugins = resolvePlugins(options.plugins);
|
|
2847
2911
|
const ctx = createSyncParserContext(1, {
|
|
2912
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2848
2913
|
plugins,
|
|
2849
2914
|
disabledFeatures: options.disabledFeatures
|
|
2850
2915
|
});
|
|
@@ -2858,6 +2923,7 @@ function serialize(source, options = {}) {
|
|
|
2858
2923
|
async function serializeAsync(source, options = {}) {
|
|
2859
2924
|
const plugins = resolvePlugins(options.plugins);
|
|
2860
2925
|
const ctx = createAsyncParserContext(1, {
|
|
2926
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2861
2927
|
plugins,
|
|
2862
2928
|
disabledFeatures: options.disabledFeatures
|
|
2863
2929
|
});
|
|
@@ -2872,8 +2938,10 @@ function deserialize(source) {
|
|
|
2872
2938
|
return (0, eval)(source);
|
|
2873
2939
|
}
|
|
2874
2940
|
function toJSON(source, options = {}) {
|
|
2941
|
+
const plugins = resolvePlugins(options.plugins);
|
|
2875
2942
|
const ctx = createSyncParserContext(1, {
|
|
2876
|
-
|
|
2943
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2944
|
+
plugins,
|
|
2877
2945
|
disabledFeatures: options.disabledFeatures
|
|
2878
2946
|
});
|
|
2879
2947
|
return {
|
|
@@ -2883,8 +2951,10 @@ function toJSON(source, options = {}) {
|
|
|
2883
2951
|
};
|
|
2884
2952
|
}
|
|
2885
2953
|
async function toJSONAsync(source, options = {}) {
|
|
2954
|
+
const plugins = resolvePlugins(options.plugins);
|
|
2886
2955
|
const ctx = createAsyncParserContext(1, {
|
|
2887
|
-
|
|
2956
|
+
compactArrayBufferViews: options.compactArrayBufferViews,
|
|
2957
|
+
plugins,
|
|
2888
2958
|
disabledFeatures: options.disabledFeatures
|
|
2889
2959
|
});
|
|
2890
2960
|
return {
|
|
@@ -2906,6 +2976,7 @@ function fromJSON(source, options = {}) {
|
|
|
2906
2976
|
const disabledFeatures = options.disabledFeatures || 0;
|
|
2907
2977
|
const sourceFeatures = (_source$f = source.f) !== null && _source$f !== void 0 ? _source$f : 127;
|
|
2908
2978
|
return deserializeTop(createVanillaDeserializerContext({
|
|
2979
|
+
maxBase64Length: options.maxBase64Length,
|
|
2909
2980
|
plugins,
|
|
2910
2981
|
markedRefs: source.m,
|
|
2911
2982
|
features: sourceFeatures & ~disabledFeatures,
|
|
@@ -2942,6 +3013,7 @@ exports.deserialize = deserialize;
|
|
|
2942
3013
|
exports.fromCrossJSON = fromCrossJSON;
|
|
2943
3014
|
exports.fromJSON = fromJSON;
|
|
2944
3015
|
exports.getCrossReferenceHeader = getCrossReferenceHeader;
|
|
3016
|
+
exports.isStream = isStream;
|
|
2945
3017
|
exports.resolvePlugins = resolvePlugins;
|
|
2946
3018
|
exports.serialize = serialize;
|
|
2947
3019
|
exports.serializeAsync = serializeAsync;
|
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;
|
|
@@ -737,6 +744,7 @@ interface Stream<T> {
|
|
|
737
744
|
throw(value: unknown): void;
|
|
738
745
|
return(value: T): void;
|
|
739
746
|
}
|
|
747
|
+
declare function isStream<T>(value: object): value is Stream<T>;
|
|
740
748
|
declare function createStream<T>(): Stream<T>;
|
|
741
749
|
//#endregion
|
|
742
750
|
//#region src/core/tree/index.d.ts
|
|
@@ -750,7 +758,7 @@ interface SerovalJSON {
|
|
|
750
758
|
f: number;
|
|
751
759
|
m: number[];
|
|
752
760
|
}
|
|
753
|
-
interface FromJSONOptions extends PluginAccessOptions {
|
|
761
|
+
interface FromJSONOptions extends PluginAccessOptions, Pick<BaseDeserializerContextOptions, 'maxBase64Length'> {
|
|
754
762
|
disabledFeatures?: number;
|
|
755
763
|
}
|
|
756
764
|
declare function toJSON<T>(source: T, options?: SyncParserContextOptions$1): SerovalJSON;
|
|
@@ -758,4 +766,4 @@ declare function toJSONAsync<T>(source: T, options?: AsyncParserContextOptions$1
|
|
|
758
766
|
declare function compileJSON(source: SerovalJSON, options?: PluginAccessOptions): string;
|
|
759
767
|
declare function fromJSON<T>(source: SerovalJSON, options?: FromJSONOptions): T;
|
|
760
768
|
//#endregion
|
|
761
|
-
export { type AsyncParsePluginContext, AsyncParserContextOptions, type BaseDeserializerContextOptions, type BaseParserContextOptions, type BaseSerializerContextOptions, type CrossContextOptions, type CrossDeserializerContextOptions, CrossSerializeAsyncOptions, CrossSerializeOptions, CrossSerializeStreamOptions, type CrossSerializerContextOptions, type DeserializePluginContext, Feature, FromCrossJSONOptions, FromJSONOptions, OpaqueReference, Plugin, PluginAccessOptions, PluginData, PluginInfo, type SerializePluginContext, Serializer, SerovalConflictedNodeIdError, SerovalDepthLimitError, SerovalDeserializationError, SerovalError, SerovalJSON, SerovalMalformedNodeError, SerovalMissingInstanceError, SerovalMissingPluginError, SerovalMissingReferenceError, SerovalMissingReferenceForIdError, SerovalMode, type SerovalNode, SerovalParserError, SerovalSerializationError, SerovalUnknownTypedArrayError, SerovalUnsupportedNodeError, SerovalUnsupportedTypeError, type Stream, type StreamListener, type StreamParsePluginContext, type StreamParserContextOptions, type SyncParsePluginContext, SyncParserContextOptions, ToCrossJSONAsyncOptions, ToCrossJSONOptions, ToCrossJSONStreamOptions, type VanillaDeserializerContextOptions, type VanillaSerializerContextOptions, compileJSON, createPlugin, createReference, createStream, crossSerialize, crossSerializeAsync, crossSerializeStream, deserialize, fromCrossJSON, fromJSON, getCrossReferenceHeader, resolvePlugins, serialize, serializeAsync, toCrossJSON, toCrossJSONAsync, toCrossJSONStream, toJSON, toJSONAsync };
|
|
769
|
+
export { type AsyncParsePluginContext, AsyncParserContextOptions, type BaseDeserializerContextOptions, type BaseParserContextOptions, type BaseSerializerContextOptions, type CrossContextOptions, type CrossDeserializerContextOptions, CrossSerializeAsyncOptions, CrossSerializeOptions, CrossSerializeStreamOptions, type CrossSerializerContextOptions, type DeserializePluginContext, Feature, FromCrossJSONOptions, FromJSONOptions, OpaqueReference, Plugin, PluginAccessOptions, PluginData, PluginInfo, type SerializePluginContext, Serializer, SerovalConflictedNodeIdError, SerovalDepthLimitError, SerovalDeserializationError, SerovalError, SerovalJSON, SerovalMalformedNodeError, SerovalMissingInstanceError, SerovalMissingPluginError, SerovalMissingReferenceError, SerovalMissingReferenceForIdError, SerovalMode, type SerovalNode, SerovalParserError, SerovalSerializationError, SerovalUnknownTypedArrayError, SerovalUnsupportedNodeError, SerovalUnsupportedTypeError, type Stream, type StreamListener, type StreamParsePluginContext, type StreamParserContextOptions, type SyncParsePluginContext, SyncParserContextOptions, ToCrossJSONAsyncOptions, ToCrossJSONOptions, ToCrossJSONStreamOptions, type VanillaDeserializerContextOptions, type VanillaSerializerContextOptions, compileJSON, createPlugin, createReference, createStream, crossSerialize, crossSerializeAsync, crossSerializeStream, deserialize, fromCrossJSON, fromJSON, getCrossReferenceHeader, isStream, resolvePlugins, serialize, serializeAsync, toCrossJSON, toCrossJSONAsync, toCrossJSONStream, toJSON, toJSONAsync };
|
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;
|
|
@@ -737,6 +744,7 @@ interface Stream<T> {
|
|
|
737
744
|
throw(value: unknown): void;
|
|
738
745
|
return(value: T): void;
|
|
739
746
|
}
|
|
747
|
+
declare function isStream<T>(value: object): value is Stream<T>;
|
|
740
748
|
declare function createStream<T>(): Stream<T>;
|
|
741
749
|
//#endregion
|
|
742
750
|
//#region src/core/tree/index.d.ts
|
|
@@ -750,7 +758,7 @@ interface SerovalJSON {
|
|
|
750
758
|
f: number;
|
|
751
759
|
m: number[];
|
|
752
760
|
}
|
|
753
|
-
interface FromJSONOptions extends PluginAccessOptions {
|
|
761
|
+
interface FromJSONOptions extends PluginAccessOptions, Pick<BaseDeserializerContextOptions, 'maxBase64Length'> {
|
|
754
762
|
disabledFeatures?: number;
|
|
755
763
|
}
|
|
756
764
|
declare function toJSON<T>(source: T, options?: SyncParserContextOptions$1): SerovalJSON;
|
|
@@ -758,4 +766,4 @@ declare function toJSONAsync<T>(source: T, options?: AsyncParserContextOptions$1
|
|
|
758
766
|
declare function compileJSON(source: SerovalJSON, options?: PluginAccessOptions): string;
|
|
759
767
|
declare function fromJSON<T>(source: SerovalJSON, options?: FromJSONOptions): T;
|
|
760
768
|
//#endregion
|
|
761
|
-
export { type AsyncParsePluginContext, AsyncParserContextOptions, type BaseDeserializerContextOptions, type BaseParserContextOptions, type BaseSerializerContextOptions, type CrossContextOptions, type CrossDeserializerContextOptions, CrossSerializeAsyncOptions, CrossSerializeOptions, CrossSerializeStreamOptions, type CrossSerializerContextOptions, type DeserializePluginContext, Feature, FromCrossJSONOptions, FromJSONOptions, OpaqueReference, Plugin, PluginAccessOptions, PluginData, PluginInfo, type SerializePluginContext, Serializer, SerovalConflictedNodeIdError, SerovalDepthLimitError, SerovalDeserializationError, SerovalError, SerovalJSON, SerovalMalformedNodeError, SerovalMissingInstanceError, SerovalMissingPluginError, SerovalMissingReferenceError, SerovalMissingReferenceForIdError, SerovalMode, type SerovalNode, SerovalParserError, SerovalSerializationError, SerovalUnknownTypedArrayError, SerovalUnsupportedNodeError, SerovalUnsupportedTypeError, type Stream, type StreamListener, type StreamParsePluginContext, type StreamParserContextOptions, type SyncParsePluginContext, SyncParserContextOptions, ToCrossJSONAsyncOptions, ToCrossJSONOptions, ToCrossJSONStreamOptions, type VanillaDeserializerContextOptions, type VanillaSerializerContextOptions, compileJSON, createPlugin, createReference, createStream, crossSerialize, crossSerializeAsync, crossSerializeStream, deserialize, fromCrossJSON, fromJSON, getCrossReferenceHeader, resolvePlugins, serialize, serializeAsync, toCrossJSON, toCrossJSONAsync, toCrossJSONStream, toJSON, toJSONAsync };
|
|
769
|
+
export { type AsyncParsePluginContext, AsyncParserContextOptions, type BaseDeserializerContextOptions, type BaseParserContextOptions, type BaseSerializerContextOptions, type CrossContextOptions, type CrossDeserializerContextOptions, CrossSerializeAsyncOptions, CrossSerializeOptions, CrossSerializeStreamOptions, type CrossSerializerContextOptions, type DeserializePluginContext, Feature, FromCrossJSONOptions, FromJSONOptions, OpaqueReference, Plugin, PluginAccessOptions, PluginData, PluginInfo, type SerializePluginContext, Serializer, SerovalConflictedNodeIdError, SerovalDepthLimitError, SerovalDeserializationError, SerovalError, SerovalJSON, SerovalMalformedNodeError, SerovalMissingInstanceError, SerovalMissingPluginError, SerovalMissingReferenceError, SerovalMissingReferenceForIdError, SerovalMode, type SerovalNode, SerovalParserError, SerovalSerializationError, SerovalUnknownTypedArrayError, SerovalUnsupportedNodeError, SerovalUnsupportedTypeError, type Stream, type StreamListener, type StreamParsePluginContext, type StreamParserContextOptions, type SyncParsePluginContext, SyncParserContextOptions, ToCrossJSONAsyncOptions, ToCrossJSONOptions, ToCrossJSONStreamOptions, type VanillaDeserializerContextOptions, type VanillaSerializerContextOptions, compileJSON, createPlugin, createReference, createStream, crossSerialize, crossSerializeAsync, crossSerializeStream, deserialize, fromCrossJSON, fromJSON, getCrossReferenceHeader, isStream, resolvePlugins, serialize, serializeAsync, toCrossJSON, toCrossJSONAsync, toCrossJSONStream, toJSON, toJSONAsync };
|