seroval 1.5.1 → 1.5.3
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/cjs/development/index.cjs +30 -6
- package/dist/cjs/development/index.cjs.map +2 -2
- package/dist/cjs/production/index.cjs +3 -3
- package/dist/esm/development/index.mjs +30 -6
- package/dist/esm/development/index.mjs.map +2 -2
- package/dist/esm/production/index.mjs +3 -3
- package/dist/types/core/constructors.d.ts +1 -1
- package/dist/types/core/constructors.d.ts.map +1 -1
- package/dist/types/core/context/deserializer.d.ts +2 -0
- package/dist/types/core/context/deserializer.d.ts.map +1 -1
- package/dist/types/core/context/serializer.d.ts.map +1 -1
- package/dist/types/core/function-string.d.ts.map +1 -1
- package/dist/types/core/sequence.d.ts.map +1 -1
- package/dist/types/core/symbols.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/core/constructors.ts +1 -1
- package/src/core/context/deserializer.ts +37 -5
- package/src/core/context/serializer.ts +28 -4
- package/src/core/function-string.ts +1 -2
- package/src/core/sequence.ts +7 -3
- package/src/core/symbols.ts +4 -2
|
@@ -1973,7 +1973,8 @@ function createBaseDeserializerContext(mode, options) {
|
|
|
1973
1973
|
plugins: options.plugins,
|
|
1974
1974
|
refs: options.refs || /* @__PURE__ */ new Map(),
|
|
1975
1975
|
features: (_a = options.features) != null ? _a : ALL_ENABLED ^ (options.disabledFeatures || 0),
|
|
1976
|
-
depthLimit: options.depthLimit || DEFAULT_DEPTH_LIMIT
|
|
1976
|
+
depthLimit: options.depthLimit || DEFAULT_DEPTH_LIMIT,
|
|
1977
|
+
types: /* @__PURE__ */ new Map()
|
|
1977
1978
|
};
|
|
1978
1979
|
}
|
|
1979
1980
|
function createVanillaDeserializerContext(options) {
|
|
@@ -2097,7 +2098,11 @@ function assignStringProperty(object, key, value) {
|
|
|
2097
2098
|
}
|
|
2098
2099
|
function assignProperty(ctx, depth, object, key, value) {
|
|
2099
2100
|
if (typeof key === "string") {
|
|
2100
|
-
assignStringProperty(
|
|
2101
|
+
assignStringProperty(
|
|
2102
|
+
object,
|
|
2103
|
+
deserializeString(key),
|
|
2104
|
+
deserialize(ctx, depth, value)
|
|
2105
|
+
);
|
|
2101
2106
|
} else {
|
|
2102
2107
|
const actual = deserialize(ctx, depth, key);
|
|
2103
2108
|
switch (typeof actual) {
|
|
@@ -2114,6 +2119,14 @@ function assignProperty(ctx, depth, object, key, value) {
|
|
|
2114
2119
|
}
|
|
2115
2120
|
}
|
|
2116
2121
|
}
|
|
2122
|
+
function assignNodeType(ctx, id, type) {
|
|
2123
|
+
ctx.base.types.set(id, type);
|
|
2124
|
+
}
|
|
2125
|
+
function validateNodeType(ctx, node, id, type) {
|
|
2126
|
+
if (ctx.base.types.get(id) !== type) {
|
|
2127
|
+
throw new SerovalMalformedNodeError(node);
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2117
2130
|
function deserializeProperties(ctx, depth, node, result) {
|
|
2118
2131
|
const keys = node.k;
|
|
2119
2132
|
const len = keys.length;
|
|
@@ -2267,6 +2280,7 @@ function deserializePlugin(ctx, depth, node) {
|
|
|
2267
2280
|
throw new SerovalMissingPluginError(node.c);
|
|
2268
2281
|
}
|
|
2269
2282
|
function deserializePromiseConstructor(ctx, node) {
|
|
2283
|
+
assignNodeType(ctx, node.s, 22 /* PromiseConstructor */);
|
|
2270
2284
|
return assignIndexedValue(
|
|
2271
2285
|
ctx,
|
|
2272
2286
|
node.i,
|
|
@@ -2276,6 +2290,7 @@ function deserializePromiseConstructor(ctx, node) {
|
|
|
2276
2290
|
function deserializePromiseResolve(ctx, depth, node) {
|
|
2277
2291
|
const deferred = ctx.base.refs.get(node.i);
|
|
2278
2292
|
if (deferred) {
|
|
2293
|
+
validateNodeType(ctx, node, node.i, 22 /* PromiseConstructor */);
|
|
2279
2294
|
deferred.s(deserialize(ctx, depth, node.a[1]));
|
|
2280
2295
|
return NIL;
|
|
2281
2296
|
}
|
|
@@ -2284,6 +2299,7 @@ function deserializePromiseResolve(ctx, depth, node) {
|
|
|
2284
2299
|
function deserializePromiseReject(ctx, depth, node) {
|
|
2285
2300
|
const deferred = ctx.base.refs.get(node.i);
|
|
2286
2301
|
if (deferred) {
|
|
2302
|
+
validateNodeType(ctx, node, node.i, 22 /* PromiseConstructor */);
|
|
2287
2303
|
deferred.f(deserialize(ctx, depth, node.a[1]));
|
|
2288
2304
|
return NIL;
|
|
2289
2305
|
}
|
|
@@ -2300,6 +2316,7 @@ function deserializeAsyncIteratorFactoryInstance(ctx, depth, node) {
|
|
|
2300
2316
|
return streamToAsyncIterable(source);
|
|
2301
2317
|
}
|
|
2302
2318
|
function deserializeStreamConstructor(ctx, depth, node) {
|
|
2319
|
+
assignNodeType(ctx, node.i, 31 /* StreamConstructor */);
|
|
2303
2320
|
const result = assignIndexedValue(ctx, node.i, createStream());
|
|
2304
2321
|
const items = node.a;
|
|
2305
2322
|
const len = items.length;
|
|
@@ -2312,7 +2329,8 @@ function deserializeStreamConstructor(ctx, depth, node) {
|
|
|
2312
2329
|
}
|
|
2313
2330
|
function deserializeStreamNext(ctx, depth, node) {
|
|
2314
2331
|
const deferred = ctx.base.refs.get(node.i);
|
|
2315
|
-
if (deferred
|
|
2332
|
+
if (deferred) {
|
|
2333
|
+
validateNodeType(ctx, node, node.i, 31 /* StreamConstructor */);
|
|
2316
2334
|
deferred.next(deserialize(ctx, depth, node.f));
|
|
2317
2335
|
return NIL;
|
|
2318
2336
|
}
|
|
@@ -2320,7 +2338,8 @@ function deserializeStreamNext(ctx, depth, node) {
|
|
|
2320
2338
|
}
|
|
2321
2339
|
function deserializeStreamThrow(ctx, depth, node) {
|
|
2322
2340
|
const deferred = ctx.base.refs.get(node.i);
|
|
2323
|
-
if (deferred
|
|
2341
|
+
if (deferred) {
|
|
2342
|
+
validateNodeType(ctx, node, node.i, 31 /* StreamConstructor */);
|
|
2324
2343
|
deferred.throw(deserialize(ctx, depth, node.f));
|
|
2325
2344
|
return NIL;
|
|
2326
2345
|
}
|
|
@@ -2328,7 +2347,8 @@ function deserializeStreamThrow(ctx, depth, node) {
|
|
|
2328
2347
|
}
|
|
2329
2348
|
function deserializeStreamReturn(ctx, depth, node) {
|
|
2330
2349
|
const deferred = ctx.base.refs.get(node.i);
|
|
2331
|
-
if (deferred
|
|
2350
|
+
if (deferred) {
|
|
2351
|
+
validateNodeType(ctx, node, node.i, 31 /* StreamConstructor */);
|
|
2332
2352
|
deferred.return(deserialize(ctx, depth, node.f));
|
|
2333
2353
|
return NIL;
|
|
2334
2354
|
}
|
|
@@ -2696,7 +2716,11 @@ function createObjectAssign(ctx, ref, key, value) {
|
|
|
2696
2716
|
createAssignment(ctx.base, getRefParam(ctx, ref) + "." + key, value);
|
|
2697
2717
|
}
|
|
2698
2718
|
function createSequenceAssign(ctx, ref, index, value) {
|
|
2699
|
-
createAssignment(
|
|
2719
|
+
createAssignment(
|
|
2720
|
+
ctx.base,
|
|
2721
|
+
getRefParam(ctx, ref) + ".v[" + index + "]",
|
|
2722
|
+
value
|
|
2723
|
+
);
|
|
2700
2724
|
}
|
|
2701
2725
|
function isIndexedValueInStack(ctx, node) {
|
|
2702
2726
|
return node.t === 4 /* IndexedValue */ && ctx.stack.includes(node.i);
|