seroval 1.7.6 → 1.7.8
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 +106 -66
- package/dist/dev/index.d.cts +5 -2
- package/dist/dev/index.d.ts +5 -2
- package/dist/dev/index.js +106 -66
- package/dist/index.cjs +106 -66
- package/dist/index.d.cts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +106 -66
- package/package.json +1 -1
package/dist/dev/index.cjs
CHANGED
|
@@ -8,7 +8,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
8
8
|
let Feature = /* @__PURE__ */ function(Feature) {
|
|
9
9
|
Feature[Feature["AggregateError"] = 1] = "AggregateError";
|
|
10
10
|
/**
|
|
11
|
-
* @deprecated Has no effect. Output
|
|
11
|
+
* @deprecated Has no effect. Output follows the syntax of the build seroval
|
|
12
|
+
* runs in: arrow functions, or `function` expressions in an ES5 build.
|
|
12
13
|
*/
|
|
13
14
|
Feature[Feature["ArrowFunction"] = 2] = "ArrowFunction";
|
|
14
15
|
Feature[Feature["ErrorPrototypeStack"] = 4] = "ErrorPrototypeStack";
|
|
@@ -166,7 +167,8 @@ function escapeCharCode(code) {
|
|
|
166
167
|
default: return;
|
|
167
168
|
}
|
|
168
169
|
}
|
|
169
|
-
function serializeString(
|
|
170
|
+
function serializeString(input) {
|
|
171
|
+
const str = "" + input;
|
|
170
172
|
if (!NEEDS_ESCAPE.test(str)) return str;
|
|
171
173
|
if (str.length >= MIN_JSON_STRINGIFY_LENGTH && !JSON_ESCAPE_DIFFERENCES.test(str)) {
|
|
172
174
|
let result = JSON.stringify(str).slice(1, -1);
|
|
@@ -406,6 +408,30 @@ function getTypedArrayName(value) {
|
|
|
406
408
|
if (!typedArrayNameGetter) typedArrayNameGetter = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Int8Array.prototype), Symbol.toStringTag).get;
|
|
407
409
|
return typedArrayNameGetter.call(value);
|
|
408
410
|
}
|
|
411
|
+
let typedArrayGetters;
|
|
412
|
+
let dataViewGetters;
|
|
413
|
+
function getAccessor(proto, key) {
|
|
414
|
+
return Object.getOwnPropertyDescriptor(proto, key).get;
|
|
415
|
+
}
|
|
416
|
+
function getViewGetters(proto, lengthKey) {
|
|
417
|
+
return {
|
|
418
|
+
buffer: getAccessor(proto, "buffer"),
|
|
419
|
+
byteOffset: getAccessor(proto, "byteOffset"),
|
|
420
|
+
byteLength: getAccessor(proto, "byteLength"),
|
|
421
|
+
length: getAccessor(proto, lengthKey)
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
function readArrayBufferView(value, isDataView) {
|
|
425
|
+
let getters;
|
|
426
|
+
if (isDataView) getters = dataViewGetters ?? (dataViewGetters = getViewGetters(DataView.prototype, "byteLength"));
|
|
427
|
+
else getters = typedArrayGetters ?? (typedArrayGetters = getViewGetters(Object.getPrototypeOf(Int8Array.prototype), "length"));
|
|
428
|
+
return {
|
|
429
|
+
buffer: getters.buffer.call(value),
|
|
430
|
+
byteOffset: getters.byteOffset.call(value),
|
|
431
|
+
byteLength: getters.byteLength.call(value),
|
|
432
|
+
length: getters.length.call(value)
|
|
433
|
+
};
|
|
434
|
+
}
|
|
409
435
|
//#endregion
|
|
410
436
|
//#region src/core/base-primitives.ts
|
|
411
437
|
function createNumberNode(value) {
|
|
@@ -426,12 +452,14 @@ function createBigIntNode(current) {
|
|
|
426
452
|
function createIndexedValueNode(id) {
|
|
427
453
|
return createSerovalNode(4, id);
|
|
428
454
|
}
|
|
455
|
+
const getDateTime = Date.prototype.getTime;
|
|
456
|
+
const getDateISOString = Date.prototype.toISOString;
|
|
429
457
|
function createDateNode(id, current) {
|
|
430
|
-
const timestamp =
|
|
431
|
-
return createSerovalNode(5, id, timestamp === timestamp ?
|
|
458
|
+
const timestamp = getDateTime.call(current);
|
|
459
|
+
return createSerovalNode(5, id, timestamp === timestamp ? getDateISOString.call(current) : "");
|
|
432
460
|
}
|
|
433
|
-
function createTemporalNode(id, type, current) {
|
|
434
|
-
return createSerovalNode(36, id,
|
|
461
|
+
function createTemporalNode(id, type, temporalClass, current) {
|
|
462
|
+
return createSerovalNode(36, id, temporalClass.prototype.toString.call(current), type);
|
|
435
463
|
}
|
|
436
464
|
const getRegExpSource = Object.getOwnPropertyDescriptor(RegExp.prototype, "source").get;
|
|
437
465
|
const getRegExpFlags = Object.getOwnPropertyDescriptor(RegExp.prototype, "flags").get;
|
|
@@ -454,11 +482,11 @@ function createBoxedNode(id, boxed) {
|
|
|
454
482
|
return createSerovalNode(21, id, void 0, void 0, void 0, void 0, void 0, void 0, boxed);
|
|
455
483
|
}
|
|
456
484
|
const MAX_TYPED_ARRAY_LENGTH = 1e6;
|
|
457
|
-
function createViewNode(type, id, current, buffer) {
|
|
485
|
+
function createViewNode(type, id, current, view, buffer) {
|
|
458
486
|
const isDataView = type === 20;
|
|
459
|
-
const size =
|
|
487
|
+
const size = view.length;
|
|
460
488
|
if (size > MAX_TYPED_ARRAY_LENGTH) throw new SerovalUnsupportedTypeError(current);
|
|
461
|
-
return createSerovalNode(type, id, void 0, isDataView ? void 0 : getTypedArrayName(current), void 0, void 0, void 0, void 0, buffer,
|
|
489
|
+
return createSerovalNode(type, id, void 0, isDataView ? void 0 : getTypedArrayName(current), void 0, void 0, void 0, void 0, buffer, view.byteOffset, void 0, size);
|
|
462
490
|
}
|
|
463
491
|
function createErrorNode(type, id, current, options) {
|
|
464
492
|
return createSerovalNode(type, id, getErrorConstructor(current), void 0, serializeString(current.message), options);
|
|
@@ -480,8 +508,9 @@ function createSequenceNode(id, sequence, throwAt, doneAt) {
|
|
|
480
508
|
}
|
|
481
509
|
//#endregion
|
|
482
510
|
//#region src/core/live-stream.ts
|
|
511
|
+
const BRAND = /* @__PURE__ */ Symbol("LiveStream");
|
|
483
512
|
function isLiveStream(value) {
|
|
484
|
-
return value
|
|
513
|
+
return value != null && value[BRAND] === true;
|
|
485
514
|
}
|
|
486
515
|
/**
|
|
487
516
|
* A single-consumer stream for incremental serialization. Unlike
|
|
@@ -489,11 +518,12 @@ function isLiveStream(value) {
|
|
|
489
518
|
* producer operation that sent it settles only when the consumer accepts it.
|
|
490
519
|
*
|
|
491
520
|
* An internal class rather than a tagged POJO: identity is checked with
|
|
492
|
-
* `
|
|
521
|
+
* `isLiveStream`, which untrusted input cannot forge. The class is exported
|
|
493
522
|
* because bundlers cannot drop an unexported top-level class.
|
|
494
523
|
*/
|
|
495
524
|
var LiveStream = class {
|
|
496
525
|
constructor(options) {
|
|
526
|
+
this[BRAND] = true;
|
|
497
527
|
this.consumed = false;
|
|
498
528
|
this.closed = false;
|
|
499
529
|
this.cancelled = false;
|
|
@@ -1295,12 +1325,12 @@ function getTemporalType(currentClass) {
|
|
|
1295
1325
|
}
|
|
1296
1326
|
}
|
|
1297
1327
|
function getObjectClass(current) {
|
|
1298
|
-
const
|
|
1299
|
-
if (
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
return
|
|
1328
|
+
const proto = Object.getPrototypeOf(current);
|
|
1329
|
+
if (proto === null) return void 0;
|
|
1330
|
+
if (proto === Object.prototype) return Object;
|
|
1331
|
+
const currentClass = proto.constructor;
|
|
1332
|
+
if (typeof currentClass !== "function" || currentClass === Object || currentClass.prototype === proto) return currentClass;
|
|
1333
|
+
return proto;
|
|
1304
1334
|
}
|
|
1305
1335
|
/**
|
|
1306
1336
|
* Decides how an object is parsed. Shared by the sync, stream and async
|
|
@@ -1364,10 +1394,14 @@ function createMapNode(id, sentinel, k, v) {
|
|
|
1364
1394
|
function createPromiseConstructorNode(ctx, id, resolver) {
|
|
1365
1395
|
return createSerovalNode(22, id, resolver, void 0, void 0, void 0, void 0, void 0, parseSpecialReference(ctx, 1));
|
|
1366
1396
|
}
|
|
1367
|
-
function getArrayBufferView(ctx,
|
|
1368
|
-
if (!ctx.compactArrayBufferViews) return
|
|
1369
|
-
|
|
1370
|
-
|
|
1397
|
+
function getArrayBufferView(ctx, view) {
|
|
1398
|
+
if (!ctx.compactArrayBufferViews) return view;
|
|
1399
|
+
return {
|
|
1400
|
+
buffer: new Uint8Array(view.buffer, view.byteOffset, view.byteLength).slice().buffer,
|
|
1401
|
+
byteOffset: 0,
|
|
1402
|
+
byteLength: view.byteLength,
|
|
1403
|
+
length: view.length
|
|
1404
|
+
};
|
|
1371
1405
|
}
|
|
1372
1406
|
function createArrayBufferNode(ctx, id, current) {
|
|
1373
1407
|
return createSerovalNode(19, id, encodeArrayBuffer(current), void 0, void 0, void 0, void 0, void 0, parseSpecialReference(ctx, 5));
|
|
@@ -1425,11 +1459,12 @@ async function parsePlainObject$1(ctx, depth, id, current, empty) {
|
|
|
1425
1459
|
return createObjectNode(id, current, empty, await parseProperties$1(ctx, depth, current));
|
|
1426
1460
|
}
|
|
1427
1461
|
async function parseBoxed$1(ctx, depth, id, current) {
|
|
1428
|
-
|
|
1462
|
+
const node = parseValueAsync(ctx, depth, current.valueOf());
|
|
1463
|
+
return createBoxedNode(id, node instanceof Promise ? await node : node);
|
|
1429
1464
|
}
|
|
1430
1465
|
async function parseView$1(ctx, depth, type, id, current) {
|
|
1431
|
-
|
|
1432
|
-
return createViewNode(type, id, current, await parseAsync(ctx, depth,
|
|
1466
|
+
const view = getArrayBufferView(ctx.base, readArrayBufferView(current, type === 20));
|
|
1467
|
+
return createViewNode(type, id, current, view, await parseAsync(ctx, depth, view.buffer));
|
|
1433
1468
|
}
|
|
1434
1469
|
async function parseError$1(ctx, depth, type, id, current) {
|
|
1435
1470
|
const options = getErrorOptions(current, ctx.base.features);
|
|
@@ -1534,14 +1569,13 @@ async function parseAsyncIterable$1(ctx, depth, current) {
|
|
|
1534
1569
|
const sequence = [];
|
|
1535
1570
|
for (;;) {
|
|
1536
1571
|
let result;
|
|
1572
|
+
markParserRef(ctx.base, id);
|
|
1537
1573
|
try {
|
|
1538
1574
|
result = await iterator.next();
|
|
1539
1575
|
} catch (error) {
|
|
1540
|
-
markParserRef(ctx.base, id);
|
|
1541
1576
|
sequence.push(createStreamEventNode(33, id, await parseAsync(ctx, depth, error)));
|
|
1542
1577
|
break;
|
|
1543
1578
|
}
|
|
1544
|
-
markParserRef(ctx.base, id);
|
|
1545
1579
|
let parsed;
|
|
1546
1580
|
try {
|
|
1547
1581
|
parsed = await parseAsync(ctx, depth, result.value);
|
|
@@ -1586,7 +1620,7 @@ async function parseObjectAsync(ctx, depth, id, current) {
|
|
|
1586
1620
|
case 12: return parseSet$1(ctx, depth, id, current);
|
|
1587
1621
|
case 13: return parsePromise$1(ctx, depth, id, current);
|
|
1588
1622
|
case 14: return createRegExpNode(id, current);
|
|
1589
|
-
case 15: return createTemporalNode(id, getTemporalType(currentClass), current);
|
|
1623
|
+
case 15: return createTemporalNode(id, getTemporalType(currentClass), currentClass, current);
|
|
1590
1624
|
case 16: return parsePlainObject$1(ctx, depth, id, current, !!currentClass);
|
|
1591
1625
|
default: throw new SerovalUnsupportedTypeError(current);
|
|
1592
1626
|
}
|
|
@@ -2242,10 +2276,6 @@ function createObjectAssign(ctx, ref, key, value) {
|
|
|
2242
2276
|
function createSequenceAssign(ctx, ref, index, value) {
|
|
2243
2277
|
createAssignment(ctx.base, getRefParam(ctx, ref) + ".v[" + index + "]", value);
|
|
2244
2278
|
}
|
|
2245
|
-
/**
|
|
2246
|
-
* Checks if the value is in the stack. Stack here is a reference
|
|
2247
|
-
* structure to know if a object is to be accessed in a TDZ.
|
|
2248
|
-
*/
|
|
2249
2279
|
function getKeyKind(key) {
|
|
2250
2280
|
const first = key.charCodeAt(0);
|
|
2251
2281
|
if (first >= 48 && first <= 57) {
|
|
@@ -2255,6 +2285,10 @@ function getKeyKind(key) {
|
|
|
2255
2285
|
if (key === "Infinity") return 2;
|
|
2256
2286
|
return isValidIdentifier(key) ? 1 : 0;
|
|
2257
2287
|
}
|
|
2288
|
+
/**
|
|
2289
|
+
* Checks if the value is in the stack. Stack here is a reference
|
|
2290
|
+
* structure to know if a object is to be accessed in a TDZ.
|
|
2291
|
+
*/
|
|
2258
2292
|
function isIndexedValueInStack(ctx, node) {
|
|
2259
2293
|
return node.t === 4 && ctx.stack.includes(node.i);
|
|
2260
2294
|
}
|
|
@@ -2333,8 +2367,7 @@ function serializeProperty(ctx, source, key, val) {
|
|
|
2333
2367
|
if (isIndexedValueInStack(ctx.base, val)) {
|
|
2334
2368
|
const refParam = getRefParam(ctx, val.i);
|
|
2335
2369
|
markSerializerRef(ctx.base, source.i);
|
|
2336
|
-
|
|
2337
|
-
else createArrayAssign(ctx, source.i, kind === 2 ? key : "\"" + key + "\"", refParam);
|
|
2370
|
+
createKeyAssign(ctx, source.i, kind, key, refParam);
|
|
2338
2371
|
return "";
|
|
2339
2372
|
}
|
|
2340
2373
|
if (key !== "__proto__") return (kind === 0 ? "\"" + key + "\"" : key) + ":" + serialize$1(ctx, val);
|
|
@@ -2422,10 +2455,10 @@ function serializeNullConstructor(ctx, node) {
|
|
|
2422
2455
|
return serializeDictionary(ctx, node, NULL_CONSTRUCTOR);
|
|
2423
2456
|
}
|
|
2424
2457
|
function serializeDate(node) {
|
|
2425
|
-
return "new Date(\"" + node.s + "\")";
|
|
2458
|
+
return "new Date(\"" + serializeString(node.s) + "\")";
|
|
2426
2459
|
}
|
|
2427
2460
|
function serializeTemporal(ctx, node) {
|
|
2428
|
-
if (ctx.base.features & 64) return "Temporal." + TEMPORAL_TYPE_NAME[node.c] + ".from(\"" + node.s + "\")";
|
|
2461
|
+
if (ctx.base.features & 64) return "Temporal." + TEMPORAL_TYPE_NAME[node.c] + ".from(\"" + serializeString(node.s) + "\")";
|
|
2429
2462
|
throw new SerovalUnsupportedNodeError(node);
|
|
2430
2463
|
}
|
|
2431
2464
|
function serializeRegExp(ctx, node) {
|
|
@@ -2539,7 +2572,7 @@ function serializeArrayBuffer(ctx, node) {
|
|
|
2539
2572
|
return getConstructor(ctx, node.f) + "(\"" + node.s + "\")";
|
|
2540
2573
|
}
|
|
2541
2574
|
function serializeView(ctx, node) {
|
|
2542
|
-
return "new " + (node.t === 20 ? "DataView" : node.c) + "(" + serialize$1(ctx, node.f) + "," + node.b + "," + node.l + ")";
|
|
2575
|
+
return "new " + (node.t === 20 ? "DataView" : node.c) + "(" + serialize$1(ctx, node.f) + "," + +node.b + "," + +node.l + ")";
|
|
2543
2576
|
}
|
|
2544
2577
|
function serializeAggregateError(ctx, node) {
|
|
2545
2578
|
const id = node.i;
|
|
@@ -2658,7 +2691,7 @@ function serializeSequence(ctx, node) {
|
|
|
2658
2691
|
result += (item && result && ",") + item;
|
|
2659
2692
|
}
|
|
2660
2693
|
ctx.base.stack.pop();
|
|
2661
|
-
if (result) return "{__SEROVAL_SEQUENCE__:!0,v:[" + result + "],t:" + node.s + ",d:" + node.l + "}";
|
|
2694
|
+
if (result) return "{__SEROVAL_SEQUENCE__:!0,v:[" + result + "],t:" + +node.s + ",d:" + +node.l + "}";
|
|
2662
2695
|
}
|
|
2663
2696
|
return "{__SEROVAL_SEQUENCE__:!0,v:[],t:-1,d:0}";
|
|
2664
2697
|
}
|
|
@@ -2737,19 +2770,17 @@ function serializeCross(ctx, tree) {
|
|
|
2737
2770
|
if (id == null) return result;
|
|
2738
2771
|
const patches = resolvePatches(ctx.base);
|
|
2739
2772
|
const ref = getRefParam(ctx, id);
|
|
2740
|
-
const scopeId = ctx.state.scopeId;
|
|
2741
|
-
const params = scopeId == null ? "" : "$R";
|
|
2742
2773
|
let body = result;
|
|
2743
2774
|
if (patches) {
|
|
2744
2775
|
if (!ctx.base.assignAll && !result.startsWith(ref + "=")) body = ref + "=" + result;
|
|
2745
2776
|
body = "(" + body + "," + patches + ref + ")";
|
|
2746
2777
|
}
|
|
2747
|
-
|
|
2778
|
+
const scopeId = ctx.state.scopeId;
|
|
2779
|
+
if (scopeId == null) {
|
|
2748
2780
|
if (tree.t === 10 && !patches) return "(" + body + ")";
|
|
2749
2781
|
return body;
|
|
2750
2782
|
}
|
|
2751
|
-
|
|
2752
|
-
return "(" + createFunction([params], body) + ")" + args;
|
|
2783
|
+
return "(" + createFunction(["$R"], body) + ")($R[\"" + serializeString(scopeId) + "\"])";
|
|
2753
2784
|
}
|
|
2754
2785
|
function wrapSerializationError(error) {
|
|
2755
2786
|
return error instanceof SerovalSerializationError ? error : new SerovalSerializationError(error);
|
|
@@ -2831,8 +2862,8 @@ function parseBoxed(ctx, depth, id, current) {
|
|
|
2831
2862
|
return createBoxedNode(id, parseSOS(ctx, depth, current.valueOf()));
|
|
2832
2863
|
}
|
|
2833
2864
|
function parseView(ctx, depth, type, id, current) {
|
|
2834
|
-
|
|
2835
|
-
return createViewNode(type, id, current, parseSOS(ctx, depth,
|
|
2865
|
+
const view = getArrayBufferView(ctx.base, readArrayBufferView(current, type === 20));
|
|
2866
|
+
return createViewNode(type, id, current, view, parseSOS(ctx, depth, view.buffer));
|
|
2836
2867
|
}
|
|
2837
2868
|
function parseError(ctx, depth, type, id, current) {
|
|
2838
2869
|
const options = getErrorOptions(current, ctx.base.features);
|
|
@@ -2923,14 +2954,15 @@ function parseObjectPhase2(ctx, depth, id, current, currentClass) {
|
|
|
2923
2954
|
case 12: return parseSet(ctx, depth, id, current);
|
|
2924
2955
|
case 13: return parsePromise(ctx, depth, id, current);
|
|
2925
2956
|
case 14: return createRegExpNode(id, current);
|
|
2926
|
-
case 15: return createTemporalNode(id, getTemporalType(currentClass), current);
|
|
2957
|
+
case 15: return createTemporalNode(id, getTemporalType(currentClass), currentClass, current);
|
|
2927
2958
|
case 16: return parsePlainObject(ctx, depth, id, current, !!currentClass);
|
|
2928
2959
|
default: throw new SerovalUnsupportedTypeError(current);
|
|
2929
2960
|
}
|
|
2930
2961
|
}
|
|
2931
2962
|
function parseObject(ctx, depth, id, current) {
|
|
2932
2963
|
if (Array.isArray(current)) return parseArray(ctx, depth, id, current);
|
|
2933
|
-
if (
|
|
2964
|
+
if (isLiveStream(current)) return parseLiveStream(ctx, depth, id, current);
|
|
2965
|
+
if (current instanceof Stream) return parseStream(ctx, depth, id, current);
|
|
2934
2966
|
if (isSequence(current)) return parseSequence(ctx, depth, id, current);
|
|
2935
2967
|
const currentClass = getObjectClass(current);
|
|
2936
2968
|
if (currentClass === OpaqueReference) return parseSOS(ctx, depth, current.replacement);
|
|
@@ -3110,7 +3142,7 @@ function consumeLiveStream(ctx, depth, id, current) {
|
|
|
3110
3142
|
});
|
|
3111
3143
|
}
|
|
3112
3144
|
function wrapPromiseResult(ctx, type, id, node) {
|
|
3113
|
-
return createSerovalNode(type, id, void 0, void 0, void 0, void 0, void 0, [parseSpecialReference(ctx.base, type === 23 ? 2 : 3), node]
|
|
3145
|
+
return createSerovalNode(type, id, void 0, void 0, void 0, void 0, void 0, [parseSpecialReference(ctx.base, type === 23 ? 2 : 3), node]);
|
|
3114
3146
|
}
|
|
3115
3147
|
function handlePromise(type, id, depth, data) {
|
|
3116
3148
|
if (this.state.alive) parseEvent(this, depth, data, wrapPromiseResult.bind(null, this, type, id), void 0);
|
|
@@ -3172,6 +3204,7 @@ function createStreamParserState(options) {
|
|
|
3172
3204
|
writing: false,
|
|
3173
3205
|
inFlight: void 0,
|
|
3174
3206
|
reason: void 0,
|
|
3207
|
+
starting: false,
|
|
3175
3208
|
onParse: options.onParse,
|
|
3176
3209
|
onError: options.onError,
|
|
3177
3210
|
onDone: options.onDone,
|
|
@@ -3300,25 +3333,30 @@ function startStreamParse(ctx, current) {
|
|
|
3300
3333
|
const state = ctx.state;
|
|
3301
3334
|
let parsed;
|
|
3302
3335
|
let failure;
|
|
3303
|
-
state.
|
|
3336
|
+
state.starting = true;
|
|
3304
3337
|
try {
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3338
|
+
state.parsing++;
|
|
3339
|
+
try {
|
|
3340
|
+
parsed = parseSOS(ctx, 0, current);
|
|
3341
|
+
} catch (error) {
|
|
3342
|
+
failure = { value: error };
|
|
3343
|
+
} finally {
|
|
3344
|
+
state.parsing--;
|
|
3345
|
+
if (!state.alive) releaseParserValues(ctx);
|
|
3346
|
+
}
|
|
3347
|
+
if (failure) {
|
|
3348
|
+
if (state.alive) stopStreamParse(ctx, 1, failure.value);
|
|
3349
|
+
else throw failure.value;
|
|
3350
|
+
} else if (parsed && state.alive) {
|
|
3351
|
+
state.queue.unshift({
|
|
3352
|
+
node: parsed,
|
|
3353
|
+
initial: true,
|
|
3354
|
+
accept: void 0
|
|
3355
|
+
});
|
|
3356
|
+
drainOutput(ctx);
|
|
3357
|
+
}
|
|
3308
3358
|
} finally {
|
|
3309
|
-
state.
|
|
3310
|
-
if (!state.alive) releaseParserValues(ctx);
|
|
3311
|
-
}
|
|
3312
|
-
if (failure) {
|
|
3313
|
-
if (state.alive) stopStreamParse(ctx, 1, failure.value);
|
|
3314
|
-
else throw failure.value;
|
|
3315
|
-
} else if (parsed && state.alive) {
|
|
3316
|
-
state.queue.unshift({
|
|
3317
|
-
node: parsed,
|
|
3318
|
-
initial: true,
|
|
3319
|
-
accept: void 0
|
|
3320
|
-
});
|
|
3321
|
-
drainOutput(ctx);
|
|
3359
|
+
state.starting = false;
|
|
3322
3360
|
}
|
|
3323
3361
|
}
|
|
3324
3362
|
function runCleanups(state) {
|
|
@@ -3369,7 +3407,7 @@ function stopStreamParse(ctx, mode, reason) {
|
|
|
3369
3407
|
try {
|
|
3370
3408
|
if (mode === 1) {
|
|
3371
3409
|
if (onError) onError(reason);
|
|
3372
|
-
else throw reason;
|
|
3410
|
+
else if (state.starting) throw reason;
|
|
3373
3411
|
} else if (mode === 0) onDone?.();
|
|
3374
3412
|
} catch (error) {
|
|
3375
3413
|
failure = { value: error };
|
|
@@ -3536,6 +3574,7 @@ var Serializer = class {
|
|
|
3536
3574
|
if (this.alive && !this.flushed && options) {
|
|
3537
3575
|
this.pending++;
|
|
3538
3576
|
this.keys.add(key);
|
|
3577
|
+
let starting = true;
|
|
3539
3578
|
const cleanup = crossSerializeStream(value, {
|
|
3540
3579
|
plugins: this.plugins,
|
|
3541
3580
|
scopeId: options.scopeId,
|
|
@@ -3547,7 +3586,7 @@ var Serializer = class {
|
|
|
3547
3586
|
let failure;
|
|
3548
3587
|
try {
|
|
3549
3588
|
if (options.onError) options.onError(error);
|
|
3550
|
-
else throw error instanceof SerovalParserError ? error : new SerovalParserError(error);
|
|
3589
|
+
else if (starting) throw error instanceof SerovalParserError ? error : new SerovalParserError(error);
|
|
3551
3590
|
} catch (handlerError) {
|
|
3552
3591
|
failure = { value: handlerError };
|
|
3553
3592
|
}
|
|
@@ -3566,6 +3605,7 @@ var Serializer = class {
|
|
|
3566
3605
|
this.finishWrite();
|
|
3567
3606
|
}
|
|
3568
3607
|
});
|
|
3608
|
+
starting = false;
|
|
3569
3609
|
if (this.alive) this.cleanups.push(cleanup);
|
|
3570
3610
|
else cleanup();
|
|
3571
3611
|
}
|
package/dist/dev/index.d.cts
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
export declare enum Feature {
|
|
8
8
|
AggregateError = 1,
|
|
9
9
|
/**
|
|
10
|
-
* @deprecated Has no effect. Output
|
|
10
|
+
* @deprecated Has no effect. Output follows the syntax of the build seroval
|
|
11
|
+
* runs in: arrow functions, or `function` expressions in an ES5 build.
|
|
11
12
|
*/
|
|
12
13
|
ArrowFunction = 2,
|
|
13
14
|
ErrorPrototypeStack = 4,
|
|
@@ -483,6 +484,7 @@ interface LiveStreamSink<T> {
|
|
|
483
484
|
interface LiveStreamOptions {
|
|
484
485
|
onCancel?: (reason: unknown) => void;
|
|
485
486
|
}
|
|
487
|
+
declare const BRAND: unique symbol;
|
|
486
488
|
export declare function isLiveStream<T>(value: unknown): value is LiveStream<T>;
|
|
487
489
|
/**
|
|
488
490
|
* A single-consumer stream for incremental serialization. Unlike
|
|
@@ -490,10 +492,11 @@ export declare function isLiveStream<T>(value: unknown): value is LiveStream<T>;
|
|
|
490
492
|
* producer operation that sent it settles only when the consumer accepts it.
|
|
491
493
|
*
|
|
492
494
|
* An internal class rather than a tagged POJO: identity is checked with
|
|
493
|
-
* `
|
|
495
|
+
* `isLiveStream`, which untrusted input cannot forge. The class is exported
|
|
494
496
|
* because bundlers cannot drop an unexported top-level class.
|
|
495
497
|
*/
|
|
496
498
|
export declare class LiveStream<T> {
|
|
499
|
+
private readonly [BRAND];
|
|
497
500
|
private pending;
|
|
498
501
|
private waiting;
|
|
499
502
|
private consumed;
|
package/dist/dev/index.d.ts
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
export declare enum Feature {
|
|
8
8
|
AggregateError = 1,
|
|
9
9
|
/**
|
|
10
|
-
* @deprecated Has no effect. Output
|
|
10
|
+
* @deprecated Has no effect. Output follows the syntax of the build seroval
|
|
11
|
+
* runs in: arrow functions, or `function` expressions in an ES5 build.
|
|
11
12
|
*/
|
|
12
13
|
ArrowFunction = 2,
|
|
13
14
|
ErrorPrototypeStack = 4,
|
|
@@ -483,6 +484,7 @@ interface LiveStreamSink<T> {
|
|
|
483
484
|
interface LiveStreamOptions {
|
|
484
485
|
onCancel?: (reason: unknown) => void;
|
|
485
486
|
}
|
|
487
|
+
declare const BRAND: unique symbol;
|
|
486
488
|
export declare function isLiveStream<T>(value: unknown): value is LiveStream<T>;
|
|
487
489
|
/**
|
|
488
490
|
* A single-consumer stream for incremental serialization. Unlike
|
|
@@ -490,10 +492,11 @@ export declare function isLiveStream<T>(value: unknown): value is LiveStream<T>;
|
|
|
490
492
|
* producer operation that sent it settles only when the consumer accepts it.
|
|
491
493
|
*
|
|
492
494
|
* An internal class rather than a tagged POJO: identity is checked with
|
|
493
|
-
* `
|
|
495
|
+
* `isLiveStream`, which untrusted input cannot forge. The class is exported
|
|
494
496
|
* because bundlers cannot drop an unexported top-level class.
|
|
495
497
|
*/
|
|
496
498
|
export declare class LiveStream<T> {
|
|
499
|
+
private readonly [BRAND];
|
|
497
500
|
private pending;
|
|
498
501
|
private waiting;
|
|
499
502
|
private consumed;
|