seroval 1.6.0 → 1.6.2
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 +2952 -0
- package/dist/dev/index.d.cts +761 -0
- package/dist/dev/index.d.ts +761 -0
- package/dist/dev/index.js +2915 -0
- package/dist/index.cjs +2945 -0
- package/dist/index.d.cts +761 -0
- package/dist/index.js +22 -42
- package/package.json +14 -3
package/dist/index.js
CHANGED
|
@@ -379,20 +379,6 @@ function createSequenceNode(id, sequence, throwAt, doneAt) {
|
|
|
379
379
|
//#endregion
|
|
380
380
|
//#region src/core/errors.ts
|
|
381
381
|
const { toString: objectToString } = Object.prototype;
|
|
382
|
-
function getErrorMessageDev(type, cause) {
|
|
383
|
-
if (cause instanceof Error) return `Seroval caught an error during the ${type} process.
|
|
384
|
-
|
|
385
|
-
${cause.name}
|
|
386
|
-
${cause.message}
|
|
387
|
-
|
|
388
|
-
- For more information, please check the "cause" property of this error.
|
|
389
|
-
- If you believe this is an error in Seroval, please submit an issue at https://github.com/lxsmnsyc/seroval/issues/new`;
|
|
390
|
-
return `Seroval caught an error during the ${type} process.
|
|
391
|
-
|
|
392
|
-
"${objectToString.call(cause)}"
|
|
393
|
-
|
|
394
|
-
For more information, please check the "cause" property of this error.`;
|
|
395
|
-
}
|
|
396
382
|
const STEP_ERROR_CODES = {
|
|
397
383
|
parsing: 1,
|
|
398
384
|
serialization: 2,
|
|
@@ -401,7 +387,7 @@ const STEP_ERROR_CODES = {
|
|
|
401
387
|
function getErrorMessageProd(type) {
|
|
402
388
|
return `Seroval Error (step: ${STEP_ERROR_CODES[type]})`;
|
|
403
389
|
}
|
|
404
|
-
const getErrorMessage = (type, cause) =>
|
|
390
|
+
const getErrorMessage = (type, cause) => getErrorMessageProd(type);
|
|
405
391
|
var SerovalError = class extends Error {
|
|
406
392
|
constructor(type, cause) {
|
|
407
393
|
super(getErrorMessage(type, cause));
|
|
@@ -428,58 +414,54 @@ function getSpecificErrorMessage(code) {
|
|
|
428
414
|
}
|
|
429
415
|
var SerovalUnsupportedTypeError = class extends Error {
|
|
430
416
|
constructor(value) {
|
|
431
|
-
super(
|
|
432
|
-
|
|
433
|
-
There are few workarounds for this problem:
|
|
434
|
-
- Transform the value in a way that it can be serialized.
|
|
435
|
-
- If the reference is present on multiple runtimes (isomorphic), you can use the Reference API to map the references.`);
|
|
417
|
+
super(getSpecificErrorMessage(1));
|
|
436
418
|
this.value = value;
|
|
437
419
|
}
|
|
438
420
|
};
|
|
439
421
|
var SerovalUnsupportedNodeError = class extends Error {
|
|
440
422
|
constructor(node) {
|
|
441
|
-
super(
|
|
423
|
+
super(getSpecificErrorMessage(2));
|
|
442
424
|
}
|
|
443
425
|
};
|
|
444
426
|
var SerovalMissingPluginError = class extends Error {
|
|
445
427
|
constructor(tag) {
|
|
446
|
-
super(
|
|
428
|
+
super(getSpecificErrorMessage(3));
|
|
447
429
|
}
|
|
448
430
|
};
|
|
449
431
|
var SerovalMissingInstanceError = class extends Error {
|
|
450
432
|
constructor(tag) {
|
|
451
|
-
super(
|
|
433
|
+
super(getSpecificErrorMessage(4));
|
|
452
434
|
}
|
|
453
435
|
};
|
|
454
436
|
var SerovalMissingReferenceError = class extends Error {
|
|
455
437
|
constructor(value) {
|
|
456
|
-
super(
|
|
438
|
+
super(getSpecificErrorMessage(5));
|
|
457
439
|
this.value = value;
|
|
458
440
|
}
|
|
459
441
|
};
|
|
460
442
|
var SerovalMissingReferenceForIdError = class extends Error {
|
|
461
443
|
constructor(id) {
|
|
462
|
-
super(
|
|
444
|
+
super(getSpecificErrorMessage(6));
|
|
463
445
|
}
|
|
464
446
|
};
|
|
465
447
|
var SerovalUnknownTypedArrayError = class extends Error {
|
|
466
448
|
constructor(name) {
|
|
467
|
-
super(
|
|
449
|
+
super(getSpecificErrorMessage(7));
|
|
468
450
|
}
|
|
469
451
|
};
|
|
470
452
|
var SerovalMalformedNodeError = class extends Error {
|
|
471
453
|
constructor(node) {
|
|
472
|
-
super(
|
|
454
|
+
super(getSpecificErrorMessage(8));
|
|
473
455
|
}
|
|
474
456
|
};
|
|
475
457
|
var SerovalConflictedNodeIdError = class extends Error {
|
|
476
458
|
constructor(node) {
|
|
477
|
-
super(
|
|
459
|
+
super(getSpecificErrorMessage(9));
|
|
478
460
|
}
|
|
479
461
|
};
|
|
480
462
|
var SerovalDepthLimitError = class extends Error {
|
|
481
463
|
constructor(limit) {
|
|
482
|
-
super(
|
|
464
|
+
super(getSpecificErrorMessage(9));
|
|
483
465
|
}
|
|
484
466
|
};
|
|
485
467
|
//#endregion
|
|
@@ -1253,6 +1235,9 @@ function guardIndexedValue(ctx, id) {
|
|
|
1253
1235
|
});
|
|
1254
1236
|
if (ctx.refs.has(id)) throw new Error("Conflicted ref id: " + id);
|
|
1255
1237
|
}
|
|
1238
|
+
function isThennable(value) {
|
|
1239
|
+
return !!value && typeof value === "object" && "then" in value && typeof value.then === "function";
|
|
1240
|
+
}
|
|
1256
1241
|
function assignIndexedValueVanilla(ctx, id, value) {
|
|
1257
1242
|
guardIndexedValue(ctx.base, id);
|
|
1258
1243
|
if (ctx.state.marked.has(id)) ctx.base.refs.set(id, value);
|
|
@@ -1415,6 +1400,7 @@ function deserializePromise(ctx, depth, node) {
|
|
|
1415
1400
|
const deferred = PROMISE_CONSTRUCTOR();
|
|
1416
1401
|
const result = assignIndexedValue$1(ctx, node.i, deferred.p);
|
|
1417
1402
|
const deserialized = deserialize$1(ctx, depth, node.f);
|
|
1403
|
+
if (isThennable(deserialized)) throw new SerovalMalformedNodeError(node.f);
|
|
1418
1404
|
if (node.s) deferred.s(deserialized);
|
|
1419
1405
|
else deferred.f(deserialized);
|
|
1420
1406
|
return result;
|
|
@@ -1438,20 +1424,14 @@ function deserializePromiseConstructor(ctx, node) {
|
|
|
1438
1424
|
assignNodeType(ctx, node.s, 22);
|
|
1439
1425
|
return value;
|
|
1440
1426
|
}
|
|
1441
|
-
function
|
|
1442
|
-
const deferred = ctx.base.refs.get(node.i);
|
|
1443
|
-
if (deferred) {
|
|
1444
|
-
validateNodeType(ctx, node, node.i, 22);
|
|
1445
|
-
deferred.s(deserialize$1(ctx, depth, node.a[1]));
|
|
1446
|
-
return;
|
|
1447
|
-
}
|
|
1448
|
-
throw new SerovalMissingInstanceError("Promise");
|
|
1449
|
-
}
|
|
1450
|
-
function deserializePromiseReject(ctx, depth, node) {
|
|
1427
|
+
function deserializePromiseFulfill(ctx, depth, node) {
|
|
1451
1428
|
const deferred = ctx.base.refs.get(node.i);
|
|
1452
1429
|
if (deferred) {
|
|
1453
1430
|
validateNodeType(ctx, node, node.i, 22);
|
|
1454
|
-
|
|
1431
|
+
const deserialized = deserialize$1(ctx, depth, node.a[1]);
|
|
1432
|
+
if (isThennable(deserialized)) throw new SerovalMalformedNodeError(node.a[1]);
|
|
1433
|
+
if (node.t === 23) deferred.s(deserialized);
|
|
1434
|
+
else deferred.f(deserialized);
|
|
1455
1435
|
return;
|
|
1456
1436
|
}
|
|
1457
1437
|
throw new SerovalMissingInstanceError("Promise");
|
|
@@ -1540,8 +1520,8 @@ function deserialize$1(ctx, depth, node) {
|
|
|
1540
1520
|
case 21: return deserializeBoxed(ctx, depth, node);
|
|
1541
1521
|
case 25: return deserializePlugin(ctx, depth, node);
|
|
1542
1522
|
case 22: return deserializePromiseConstructor(ctx, node);
|
|
1543
|
-
case 23:
|
|
1544
|
-
case 24: return
|
|
1523
|
+
case 23:
|
|
1524
|
+
case 24: return deserializePromiseFulfill(ctx, depth, node);
|
|
1545
1525
|
case 28: return deserializeIteratorFactoryInstance(ctx, depth, node);
|
|
1546
1526
|
case 30: return deserializeAsyncIteratorFactoryInstance(ctx, depth, node);
|
|
1547
1527
|
case 31: return deserializeStreamConstructor(ctx, depth, node);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "seroval",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.6.
|
|
4
|
+
"version": "1.6.2",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
7
7
|
],
|
|
@@ -40,14 +40,25 @@
|
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
42
|
"author": "Alexis Munsayac",
|
|
43
|
-
"types": "./dist/
|
|
43
|
+
"types": "./dist/index.d.cts",
|
|
44
44
|
"exports": {
|
|
45
|
-
".":
|
|
45
|
+
".": {
|
|
46
|
+
"development": {
|
|
47
|
+
"import": "./dist/dev/index.js",
|
|
48
|
+
"require": "./dist/dev/index.cjs",
|
|
49
|
+
"default": "./dist/dev/index.js"
|
|
50
|
+
},
|
|
51
|
+
"import": "./dist/index.js",
|
|
52
|
+
"require": "./dist/index.cjs",
|
|
53
|
+
"default": "./dist/index.js"
|
|
54
|
+
},
|
|
46
55
|
"./package.json": "./package.json"
|
|
47
56
|
},
|
|
48
57
|
"typesVersions": {
|
|
49
58
|
"*": {}
|
|
50
59
|
},
|
|
60
|
+
"main": "./dist/index.cjs",
|
|
61
|
+
"module": "./dist/index.js",
|
|
51
62
|
"scripts": {
|
|
52
63
|
"build": "tsdown",
|
|
53
64
|
"watch": "tsdown --watch",
|