seroval 1.7.10 → 1.8.1
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 +58 -3893
- package/dist/dev/index.d.cts +5 -834
- package/dist/dev/index.d.ts +5 -834
- package/dist/dev/index.js +4 -3847
- package/dist/dev/read-BgToBbWd.js +455 -0
- package/dist/dev/read-Bn_ffmiS.d.ts +14 -0
- package/dist/dev/read-CgzYPh_Q.d.cts +14 -0
- package/dist/dev/read-D4n-bxUW.cjs +478 -0
- package/dist/dev/read.cjs +45 -0
- package/dist/dev/read.d.cts +17 -0
- package/dist/dev/read.d.ts +17 -0
- package/dist/dev/read.js +3 -0
- package/dist/dev/shared-Cf-Bmoy-.js +1010 -0
- package/dist/dev/shared-DTMVoS-y.d.ts +749 -0
- package/dist/dev/shared-DWx3Bwb6.cjs +1410 -0
- package/dist/dev/shared-Dju99SLx.d.cts +749 -0
- package/dist/dev/shared.cjs +40 -0
- package/dist/dev/shared.d.cts +2 -0
- package/dist/dev/shared.d.ts +2 -0
- package/dist/dev/shared.js +1 -0
- package/dist/dev/typed-array-C3haUQv_.js +72 -0
- package/dist/dev/typed-array-DUH_YsNc.cjs +101 -0
- package/dist/dev/validator-CxDhXc0k.d.cts +28 -0
- package/dist/dev/validator-CxDhXc0k.d.ts +28 -0
- package/dist/dev/validator.cjs +54 -0
- package/dist/dev/validator.d.cts +2 -0
- package/dist/dev/validator.d.ts +2 -0
- package/dist/dev/validator.js +45 -0
- package/dist/dev/write-BKJsV31u.js +2354 -0
- package/dist/dev/write-C0KqlAXN.d.ts +86 -0
- package/dist/dev/write-DGOp2jqo.cjs +2425 -0
- package/dist/dev/write-KxJKA4_p.d.cts +86 -0
- package/dist/dev/write.cjs +54 -0
- package/dist/dev/write.d.cts +4 -0
- package/dist/dev/write.d.ts +4 -0
- package/dist/dev/write.js +3 -0
- package/dist/index.cjs +58 -3877
- package/dist/index.d.cts +5 -834
- package/dist/index.d.ts +5 -834
- package/dist/index.js +4 -3831
- package/dist/read-B0hu4YND.cjs +478 -0
- package/dist/read-BSFu4fPn.js +455 -0
- package/dist/read-Bn_ffmiS.d.ts +14 -0
- package/dist/read-CgzYPh_Q.d.cts +14 -0
- package/dist/read.cjs +45 -0
- package/dist/read.d.cts +17 -0
- package/dist/read.d.ts +17 -0
- package/dist/read.js +3 -0
- package/dist/shared-DJIVyqa9.js +994 -0
- package/dist/shared-DTMVoS-y.d.ts +749 -0
- package/dist/shared-Dju99SLx.d.cts +749 -0
- package/dist/shared-u-KYXAax.cjs +1394 -0
- package/dist/shared.cjs +40 -0
- package/dist/shared.d.cts +2 -0
- package/dist/shared.d.ts +2 -0
- package/dist/shared.js +1 -0
- package/dist/typed-array-BWH0IKxT.js +72 -0
- package/dist/typed-array-BkSwWNFI.cjs +101 -0
- package/dist/validator-CxDhXc0k.d.cts +28 -0
- package/dist/validator-CxDhXc0k.d.ts +28 -0
- package/dist/validator.cjs +54 -0
- package/dist/validator.d.cts +2 -0
- package/dist/validator.d.ts +2 -0
- package/dist/validator.js +45 -0
- package/dist/write-B_hZaAwC.js +2354 -0
- package/dist/write-C0KqlAXN.d.ts +86 -0
- package/dist/write-CMi0CxOu.cjs +2425 -0
- package/dist/write-KxJKA4_p.d.cts +86 -0
- package/dist/write.cjs +54 -0
- package/dist/write.d.cts +4 -0
- package/dist/write.d.ts +4 -0
- package/dist/write.js +3 -0
- package/package.json +97 -1
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
const require_shared = require("./shared-u-KYXAax.cjs");
|
|
2
|
+
const require_typed_array = require("./typed-array-BkSwWNFI.cjs");
|
|
3
|
+
//#region src/core/utils/valid-properties.ts
|
|
4
|
+
function isValidKey(key) {
|
|
5
|
+
switch (key) {
|
|
6
|
+
case "constructor":
|
|
7
|
+
case "__proto__":
|
|
8
|
+
case "prototype":
|
|
9
|
+
case "__defineGetter__":
|
|
10
|
+
case "__defineSetter__":
|
|
11
|
+
case "__lookupGetter__":
|
|
12
|
+
case "__lookupSetter__": return false;
|
|
13
|
+
default: return true;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function isValidSymbol(symbol) {
|
|
17
|
+
switch (symbol) {
|
|
18
|
+
case require_shared.SYM_ASYNC_ITERATOR:
|
|
19
|
+
case require_shared.SYM_IS_CONCAT_SPREADABLE:
|
|
20
|
+
case require_shared.SYM_TO_STRING_TAG:
|
|
21
|
+
case require_shared.SYM_ITERATOR: return true;
|
|
22
|
+
default: return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/core/context/deserializer.ts
|
|
27
|
+
const DEFAULT_MAX_BASE64_LENGTH = 1e6;
|
|
28
|
+
const MAX_BIGINT_LENGTH = 1e4;
|
|
29
|
+
const MAX_REGEXP_SOURCE_LENGTH = 2e4;
|
|
30
|
+
function applyObjectFlag(obj, flag) {
|
|
31
|
+
switch (flag) {
|
|
32
|
+
case 3: return Object.freeze(obj);
|
|
33
|
+
case 1: return Object.preventExtensions(obj);
|
|
34
|
+
case 2: return Object.seal(obj);
|
|
35
|
+
default: return obj;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const DEFAULT_DEPTH_LIMIT = 1e3;
|
|
39
|
+
const MAX_REGEXP_PROPERTY_ESCAPES = 32;
|
|
40
|
+
const REGEXP_PROPERTY_ESCAPE = /\\[pP]\{/g;
|
|
41
|
+
function createBaseDeserializerContext(options) {
|
|
42
|
+
const maxBase64Length = options.maxBase64Length ?? DEFAULT_MAX_BASE64_LENGTH;
|
|
43
|
+
if (!Number.isSafeInteger(maxBase64Length) || maxBase64Length < 0) throw new RangeError("maxBase64Length must be a non-negative safe integer");
|
|
44
|
+
const refs = options.refs ?? /* @__PURE__ */ new Map();
|
|
45
|
+
if (!("types" in refs)) Object.assign(refs, { types: /* @__PURE__ */ new Map() });
|
|
46
|
+
return {
|
|
47
|
+
plugins: options.plugins,
|
|
48
|
+
refs,
|
|
49
|
+
features: options.features ?? 127 ^ (options.disabledFeatures ?? 0),
|
|
50
|
+
depthLimit: options.depthLimit || DEFAULT_DEPTH_LIMIT,
|
|
51
|
+
maxBase64Length,
|
|
52
|
+
regexpPropertyEscapes: MAX_REGEXP_PROPERTY_ESCAPES
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function createVanillaDeserializerContext(options) {
|
|
56
|
+
return {
|
|
57
|
+
base: createBaseDeserializerContext(options),
|
|
58
|
+
marked: new Set(options.markedRefs)
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function createCrossDeserializerContext(options) {
|
|
62
|
+
return {
|
|
63
|
+
base: createBaseDeserializerContext(options),
|
|
64
|
+
marked: void 0
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function guardIndexedValue(ctx, id) {
|
|
68
|
+
const node = {
|
|
69
|
+
t: 4,
|
|
70
|
+
i: id
|
|
71
|
+
};
|
|
72
|
+
if (id < 0 || !Number.isInteger(id)) throw new require_shared.SerovalMalformedNodeError(node);
|
|
73
|
+
if (ctx.refs.has(id)) throw new require_shared.SerovalConflictedNodeIdError(node);
|
|
74
|
+
}
|
|
75
|
+
function isThennable(value) {
|
|
76
|
+
return !!value && (typeof value === "object" || typeof value === "function") && "then" in value && typeof value.then === "function";
|
|
77
|
+
}
|
|
78
|
+
const ignoreRejection = () => {};
|
|
79
|
+
function assignIndexedValue(ctx, id, value) {
|
|
80
|
+
guardIndexedValue(ctx.base, id);
|
|
81
|
+
if (value instanceof Promise) value.catch(ignoreRejection);
|
|
82
|
+
const marked = ctx.marked;
|
|
83
|
+
if (!marked || marked.has(id)) ctx.base.refs.set(id, value);
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
86
|
+
function deserializeKnownValue(node, record, key) {
|
|
87
|
+
if (Object.hasOwn(record, key)) return record[key];
|
|
88
|
+
throw new require_shared.SerovalMalformedNodeError(node);
|
|
89
|
+
}
|
|
90
|
+
function deserializeReference(ctx, node) {
|
|
91
|
+
return assignIndexedValue(ctx, node.i, require_shared.getReference(require_shared.deserializeString(node.s)));
|
|
92
|
+
}
|
|
93
|
+
function validateNodeList(node, list) {
|
|
94
|
+
if (!Array.isArray(list)) throw new require_shared.SerovalMalformedNodeError(node);
|
|
95
|
+
}
|
|
96
|
+
function deserializeArray(ctx, depth, node) {
|
|
97
|
+
const items = node.a;
|
|
98
|
+
validateNodeList(node, items);
|
|
99
|
+
const len = items.length;
|
|
100
|
+
const result = assignIndexedValue(ctx, node.i, new Array(len));
|
|
101
|
+
for (let i = 0, item; i < len; i++) {
|
|
102
|
+
item = items[i];
|
|
103
|
+
if (item) result[i] = deserialize$1(ctx, depth, item);
|
|
104
|
+
}
|
|
105
|
+
applyObjectFlag(result, node.o);
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
function assignStringProperty(object, key, value) {
|
|
109
|
+
if (isValidKey(key)) object[key] = value;
|
|
110
|
+
else Object.defineProperty(object, key, {
|
|
111
|
+
value,
|
|
112
|
+
configurable: true,
|
|
113
|
+
enumerable: true,
|
|
114
|
+
writable: true
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
function assignProperty(ctx, depth, object, key, value) {
|
|
118
|
+
if (typeof key === "string") assignStringProperty(object, require_shared.deserializeString(key), deserialize$1(ctx, depth, value));
|
|
119
|
+
else {
|
|
120
|
+
const actual = deserialize$1(ctx, depth, key);
|
|
121
|
+
switch (typeof actual) {
|
|
122
|
+
case "string":
|
|
123
|
+
assignStringProperty(object, actual, deserialize$1(ctx, depth, value));
|
|
124
|
+
break;
|
|
125
|
+
case "symbol":
|
|
126
|
+
if (isValidSymbol(actual)) object[actual] = deserialize$1(ctx, depth, value);
|
|
127
|
+
break;
|
|
128
|
+
default: throw new require_shared.SerovalMalformedNodeError(key);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function assignNodeType(ctx, id, type) {
|
|
133
|
+
ctx.base.refs.types.set(id, type);
|
|
134
|
+
}
|
|
135
|
+
function validateNodeType(ctx, node, id, type) {
|
|
136
|
+
if (ctx.base.refs.types.get(id) !== type) throw new require_shared.SerovalMalformedNodeError(node);
|
|
137
|
+
}
|
|
138
|
+
function deserializeProperties(ctx, depth, node, result) {
|
|
139
|
+
const keys = node.k;
|
|
140
|
+
validateNodeList(node, keys);
|
|
141
|
+
validateNodeList(node, node.v);
|
|
142
|
+
const len = keys.length;
|
|
143
|
+
if (len > 0) for (let i = 0, vals = node.v; i < len; i++) assignProperty(ctx, depth, result, keys[i], vals[i]);
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
function deserializeObject(ctx, depth, node) {
|
|
147
|
+
const result = assignIndexedValue(ctx, node.i, node.t === 10 ? {} : Object.create(null));
|
|
148
|
+
deserializeProperties(ctx, depth, node.p, result);
|
|
149
|
+
applyObjectFlag(result, node.o);
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
function deserializeDate(ctx, node) {
|
|
153
|
+
return assignIndexedValue(ctx, node.i, new Date(node.s));
|
|
154
|
+
}
|
|
155
|
+
function deserializeTemporal(ctx, node) {
|
|
156
|
+
if (!(ctx.base.features & 64)) throw new require_shared.SerovalUnsupportedNodeError(node);
|
|
157
|
+
const construct = Temporal[deserializeKnownValue(node, require_shared.TEMPORAL_TYPE_NAME, node.c)];
|
|
158
|
+
return assignIndexedValue(ctx, node.i, construct.from(node.s));
|
|
159
|
+
}
|
|
160
|
+
function deserializeRegExp(ctx, node) {
|
|
161
|
+
if (ctx.base.features & 32) {
|
|
162
|
+
const source = require_shared.deserializeString(node.c);
|
|
163
|
+
if (source.length > MAX_REGEXP_SOURCE_LENGTH) throw new require_shared.SerovalMalformedNodeError(node);
|
|
164
|
+
if (/[uv]/.test(String(node.m))) {
|
|
165
|
+
const escapes = source.match(REGEXP_PROPERTY_ESCAPE);
|
|
166
|
+
if (escapes) {
|
|
167
|
+
ctx.base.regexpPropertyEscapes -= escapes.length;
|
|
168
|
+
if (ctx.base.regexpPropertyEscapes < 0) throw new require_shared.SerovalMalformedNodeError(node);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return assignIndexedValue(ctx, node.i, new RegExp(source, node.m));
|
|
172
|
+
}
|
|
173
|
+
throw new require_shared.SerovalUnsupportedNodeError(node);
|
|
174
|
+
}
|
|
175
|
+
function deserializeSet(ctx, depth, node) {
|
|
176
|
+
const result = assignIndexedValue(ctx, node.i, /* @__PURE__ */ new Set());
|
|
177
|
+
validateNodeList(node, node.a);
|
|
178
|
+
for (let i = 0, items = node.a, len = items.length; i < len; i++) result.add(deserialize$1(ctx, depth, items[i]));
|
|
179
|
+
return result;
|
|
180
|
+
}
|
|
181
|
+
function deserializeMap(ctx, depth, node) {
|
|
182
|
+
const result = assignIndexedValue(ctx, node.i, /* @__PURE__ */ new Map());
|
|
183
|
+
validateNodeList(node, node.e.k);
|
|
184
|
+
validateNodeList(node, node.e.v);
|
|
185
|
+
for (let i = 0, keys = node.e.k, vals = node.e.v, len = keys.length; i < len; i++) result.set(deserialize$1(ctx, depth, keys[i]), deserialize$1(ctx, depth, vals[i]));
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
function deserializeArrayBuffer(ctx, node) {
|
|
189
|
+
if (typeof node.s !== "string") throw new require_shared.SerovalMalformedNodeError(node);
|
|
190
|
+
if (node.s.length > ctx.base.maxBase64Length) throw new RangeError("ArrayBuffer exceeds maxBase64Length (" + ctx.base.maxBase64Length + ")");
|
|
191
|
+
const source = require_shared.deserializeString(node.s);
|
|
192
|
+
const buffer = require_typed_array.decodeArrayBuffer(source);
|
|
193
|
+
return assignIndexedValue(ctx, node.i, buffer);
|
|
194
|
+
}
|
|
195
|
+
function deserializeView(ctx, depth, node, construct) {
|
|
196
|
+
const source = deserialize$1(ctx, depth, node.f);
|
|
197
|
+
if (!(source instanceof ArrayBuffer)) throw new require_shared.SerovalMalformedNodeError(node);
|
|
198
|
+
const offset = node.b ?? 0;
|
|
199
|
+
if (offset < 0 || offset > source.byteLength) throw new require_shared.SerovalMalformedNodeError(node);
|
|
200
|
+
return assignIndexedValue(ctx, node.i, construct ? new construct(source, offset, node.l) : new DataView(source, offset, node.l));
|
|
201
|
+
}
|
|
202
|
+
function deserializeDictionary(ctx, depth, node, result) {
|
|
203
|
+
if (node.p) {
|
|
204
|
+
const fields = deserializeProperties(ctx, depth, node.p, {});
|
|
205
|
+
Object.defineProperties(result, Object.getOwnPropertyDescriptors(fields));
|
|
206
|
+
}
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
function deserializeAggregateError(ctx, depth, node) {
|
|
210
|
+
return deserializeDictionary(ctx, depth, node, assignIndexedValue(ctx, node.i, new AggregateError([], require_shared.deserializeString(node.m))));
|
|
211
|
+
}
|
|
212
|
+
function deserializeError(ctx, depth, node) {
|
|
213
|
+
const construct = deserializeKnownValue(node, require_shared.ERROR_CONSTRUCTOR, node.s);
|
|
214
|
+
return deserializeDictionary(ctx, depth, node, assignIndexedValue(ctx, node.i, new construct(require_shared.deserializeString(node.m))));
|
|
215
|
+
}
|
|
216
|
+
function deserializePromise(ctx, depth, node) {
|
|
217
|
+
const deferred = require_shared.PROMISE_CONSTRUCTOR();
|
|
218
|
+
const result = assignIndexedValue(ctx, node.i, deferred.p);
|
|
219
|
+
const deserialized = deserialize$1(ctx, depth, node.f);
|
|
220
|
+
if (isThennable(deserialized)) throw new require_shared.SerovalMalformedNodeError(node.f);
|
|
221
|
+
if (node.s) deferred.s(deserialized);
|
|
222
|
+
else deferred.f(deserialized);
|
|
223
|
+
return result;
|
|
224
|
+
}
|
|
225
|
+
function deserializeBoxed(ctx, depth, node) {
|
|
226
|
+
return assignIndexedValue(ctx, node.i, Object(deserialize$1(ctx, depth, node.f)));
|
|
227
|
+
}
|
|
228
|
+
function getPluginFieldChecks(node, validate) {
|
|
229
|
+
const info = node.s;
|
|
230
|
+
if (info == null || typeof info !== "object") throw new require_shared.SerovalMalformedNodeError(node);
|
|
231
|
+
const checks = [];
|
|
232
|
+
for (const field of Object.keys(validate)) {
|
|
233
|
+
const check = validate[field];
|
|
234
|
+
if (check) checks.push([
|
|
235
|
+
Reflect.get(info, field),
|
|
236
|
+
field,
|
|
237
|
+
check
|
|
238
|
+
]);
|
|
239
|
+
}
|
|
240
|
+
return checks;
|
|
241
|
+
}
|
|
242
|
+
function deserializePlugin(ctx, depth, node) {
|
|
243
|
+
const currentPlugins = ctx.base.plugins;
|
|
244
|
+
if (currentPlugins) {
|
|
245
|
+
const tag = require_shared.deserializeString(node.c);
|
|
246
|
+
for (let i = 0, len = currentPlugins.length; i < len; i++) {
|
|
247
|
+
const plugin = currentPlugins[i];
|
|
248
|
+
if (plugin.tag === tag) {
|
|
249
|
+
const checks = plugin.validate ? getPluginFieldChecks(node, plugin.validate) : void 0;
|
|
250
|
+
return assignIndexedValue(ctx, node.i, plugin.deserialize(node.s, { deserialize: (current) => {
|
|
251
|
+
const value = deserialize$1(ctx, depth, current);
|
|
252
|
+
if (checks) {
|
|
253
|
+
for (const [fieldNode, field, check] of checks) if (fieldNode === current && !check(value)) throw new require_shared.SerovalPluginValidationError(tag, field);
|
|
254
|
+
}
|
|
255
|
+
return value;
|
|
256
|
+
} }, { id: node.i }));
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
throw new require_shared.SerovalMissingPluginError(node.c);
|
|
261
|
+
}
|
|
262
|
+
function deserializePromiseConstructor(ctx, node) {
|
|
263
|
+
const value = assignIndexedValue(ctx, node.i, assignIndexedValue(ctx, node.s, require_shared.PROMISE_CONSTRUCTOR()).p);
|
|
264
|
+
assignNodeType(ctx, node.s, 22);
|
|
265
|
+
ctx.base.pending?.add(node.s);
|
|
266
|
+
return value;
|
|
267
|
+
}
|
|
268
|
+
function deserializePromiseFulfill(ctx, depth, node) {
|
|
269
|
+
const deferred = ctx.base.refs.get(node.i);
|
|
270
|
+
if (deferred) {
|
|
271
|
+
validateNodeType(ctx, node, node.i, 22);
|
|
272
|
+
const deserialized = deserialize$1(ctx, depth, node.a[1]);
|
|
273
|
+
if (isThennable(deserialized)) throw new require_shared.SerovalMalformedNodeError(node.a[1]);
|
|
274
|
+
if (node.t === 23) deferred.s(deserialized);
|
|
275
|
+
else deferred.f(deserialized);
|
|
276
|
+
ctx.base.pending?.delete(node.i);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
throw new require_shared.SerovalMissingInstanceError("Promise");
|
|
280
|
+
}
|
|
281
|
+
function deserializeIteratorFactoryInstance(ctx, depth, node) {
|
|
282
|
+
deserialize$1(ctx, depth, node.a[0]);
|
|
283
|
+
const source = deserialize$1(ctx, depth, node.a[1]);
|
|
284
|
+
if (!require_shared.isSequence(source)) throw new require_shared.SerovalMalformedNodeError(node.a[1]);
|
|
285
|
+
return require_shared.sequenceToIterator(source);
|
|
286
|
+
}
|
|
287
|
+
function deserializeAsyncIteratorFactoryInstance(ctx, depth, node) {
|
|
288
|
+
deserialize$1(ctx, depth, node.a[0]);
|
|
289
|
+
const source = deserialize$1(ctx, depth, node.a[1]);
|
|
290
|
+
if (!require_shared.isStream(source)) throw new require_shared.SerovalMalformedNodeError(node.a[1]);
|
|
291
|
+
return require_shared.streamToAsyncIterable(source);
|
|
292
|
+
}
|
|
293
|
+
function deserializeStreamConstructor(ctx, depth, node) {
|
|
294
|
+
const result = assignIndexedValue(ctx, node.i, new require_shared.Stream(node.l === 1 ? 1 : void 0));
|
|
295
|
+
assignNodeType(ctx, node.i, 31);
|
|
296
|
+
ctx.base.pending?.add(node.i);
|
|
297
|
+
const items = node.a;
|
|
298
|
+
validateNodeList(node, items);
|
|
299
|
+
const len = items.length;
|
|
300
|
+
if (len) for (let i = 0; i < len; i++) deserialize$1(ctx, depth, items[i]);
|
|
301
|
+
return result;
|
|
302
|
+
}
|
|
303
|
+
function deserializeStreamCall(ctx, depth, node, method) {
|
|
304
|
+
const deferred = ctx.base.refs.get(node.i);
|
|
305
|
+
if (deferred) {
|
|
306
|
+
validateNodeType(ctx, node, node.i, 31);
|
|
307
|
+
deferred[method](deserialize$1(ctx, depth, node.f));
|
|
308
|
+
if (method !== "next") ctx.base.pending?.delete(node.i);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
throw new require_shared.SerovalMissingInstanceError("Stream");
|
|
312
|
+
}
|
|
313
|
+
function deserializeIteratorFactory(ctx, depth, node) {
|
|
314
|
+
deserialize$1(ctx, depth, node.f);
|
|
315
|
+
}
|
|
316
|
+
function deserializeAsyncIteratorFactory(ctx, depth, node) {
|
|
317
|
+
deserialize$1(ctx, depth, node.a[1]);
|
|
318
|
+
}
|
|
319
|
+
function isSequenceIndex(value, size) {
|
|
320
|
+
return Number.isInteger(value) && value >= -1 && value < size;
|
|
321
|
+
}
|
|
322
|
+
function deserializeSequence(ctx, depth, node) {
|
|
323
|
+
validateNodeList(node, node.a);
|
|
324
|
+
const size = node.a.length;
|
|
325
|
+
if (!(isSequenceIndex(node.s, size) && isSequenceIndex(node.l, size))) throw new require_shared.SerovalMalformedNodeError(node);
|
|
326
|
+
const result = assignIndexedValue(ctx, node.i, require_shared.createSequence([], node.s, node.l));
|
|
327
|
+
assignNodeType(ctx, node.i, 35);
|
|
328
|
+
for (let i = 0; i < size; i++) result.v[i] = deserialize$1(ctx, depth, node.a[i]);
|
|
329
|
+
return result;
|
|
330
|
+
}
|
|
331
|
+
function deserialize$1(ctx, depth, node) {
|
|
332
|
+
if (depth > ctx.base.depthLimit) throw new require_shared.SerovalDepthLimitError(ctx.base.depthLimit);
|
|
333
|
+
depth += 1;
|
|
334
|
+
switch (node.t) {
|
|
335
|
+
case 2: return deserializeKnownValue(node, require_shared.CONSTANT_VAL, node.s);
|
|
336
|
+
case 0: return Number(node.s);
|
|
337
|
+
case 1: return require_shared.deserializeString(String(node.s));
|
|
338
|
+
case 3:
|
|
339
|
+
if (String(node.s).length > MAX_BIGINT_LENGTH) throw new require_shared.SerovalMalformedNodeError(node);
|
|
340
|
+
return BigInt(node.s);
|
|
341
|
+
case 4: return ctx.base.refs.get(node.i);
|
|
342
|
+
case 18: return deserializeReference(ctx, node);
|
|
343
|
+
case 9: return deserializeArray(ctx, depth, node);
|
|
344
|
+
case 10:
|
|
345
|
+
case 11: return deserializeObject(ctx, depth, node);
|
|
346
|
+
case 5: return deserializeDate(ctx, node);
|
|
347
|
+
case 6: return deserializeRegExp(ctx, node);
|
|
348
|
+
case 7: return deserializeSet(ctx, depth, node);
|
|
349
|
+
case 8: return deserializeMap(ctx, depth, node);
|
|
350
|
+
case 19: return deserializeArrayBuffer(ctx, node);
|
|
351
|
+
case 16:
|
|
352
|
+
case 15: return deserializeView(ctx, depth, node, require_typed_array.getTypedArrayConstructor(node.c));
|
|
353
|
+
case 20: return deserializeView(ctx, depth, node);
|
|
354
|
+
case 14: return deserializeAggregateError(ctx, depth, node);
|
|
355
|
+
case 13: return deserializeError(ctx, depth, node);
|
|
356
|
+
case 12: return deserializePromise(ctx, depth, node);
|
|
357
|
+
case 17: return assignIndexedValue(ctx, node.i, deserializeKnownValue(node, require_shared.SYMBOL_REF, node.s));
|
|
358
|
+
case 21: return deserializeBoxed(ctx, depth, node);
|
|
359
|
+
case 25: return deserializePlugin(ctx, depth, node);
|
|
360
|
+
case 22: return deserializePromiseConstructor(ctx, node);
|
|
361
|
+
case 23:
|
|
362
|
+
case 24: return deserializePromiseFulfill(ctx, depth, node);
|
|
363
|
+
case 28: return deserializeIteratorFactoryInstance(ctx, depth, node);
|
|
364
|
+
case 30: return deserializeAsyncIteratorFactoryInstance(ctx, depth, node);
|
|
365
|
+
case 31: return deserializeStreamConstructor(ctx, depth, node);
|
|
366
|
+
case 32: return deserializeStreamCall(ctx, depth, node, "next");
|
|
367
|
+
case 33: return deserializeStreamCall(ctx, depth, node, "throw");
|
|
368
|
+
case 34: return deserializeStreamCall(ctx, depth, node, "return");
|
|
369
|
+
case 27: return deserializeIteratorFactory(ctx, depth, node);
|
|
370
|
+
case 29: return deserializeAsyncIteratorFactory(ctx, depth, node);
|
|
371
|
+
case 35: return deserializeSequence(ctx, depth, node);
|
|
372
|
+
case 36: return deserializeTemporal(ctx, node);
|
|
373
|
+
default: throw new require_shared.SerovalUnsupportedNodeError(node);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
function deserializeTop(ctx, node) {
|
|
377
|
+
ctx.base.regexpPropertyEscapes = MAX_REGEXP_PROPERTY_ESCAPES;
|
|
378
|
+
try {
|
|
379
|
+
return deserialize$1(ctx, 0, node);
|
|
380
|
+
} catch (error) {
|
|
381
|
+
throw new require_shared.SerovalDeserializationError(error);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Rejects every pending promise and throws into every open stream tracked
|
|
386
|
+
* by `ctx.base.pending`, then drops the bookkeeping so the context no longer
|
|
387
|
+
* accepts deferred values. Does nothing once the bookkeeping is gone.
|
|
388
|
+
*/
|
|
389
|
+
function abortDeferred(ctx, reason) {
|
|
390
|
+
const pending = ctx.base.pending;
|
|
391
|
+
if (pending) {
|
|
392
|
+
ctx.base.pending = void 0;
|
|
393
|
+
const refs = ctx.base.refs;
|
|
394
|
+
const errors = [];
|
|
395
|
+
for (const id of pending) try {
|
|
396
|
+
const value = refs.get(id);
|
|
397
|
+
if (refs.types.get(id) === 22) value.f(reason);
|
|
398
|
+
else value.throw(reason);
|
|
399
|
+
} catch (error) {
|
|
400
|
+
errors.push(error);
|
|
401
|
+
}
|
|
402
|
+
if (errors.length) throw errors[0];
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
//#endregion
|
|
406
|
+
//#region src/core/cross/read.ts
|
|
407
|
+
function createFromCrossJSONContext(options) {
|
|
408
|
+
return createCrossDeserializerContext({
|
|
409
|
+
maxBase64Length: options.maxBase64Length,
|
|
410
|
+
plugins: require_shared.resolvePlugins(options.plugins),
|
|
411
|
+
refs: options.refs,
|
|
412
|
+
features: options.features,
|
|
413
|
+
disabledFeatures: options.disabledFeatures,
|
|
414
|
+
depthLimit: options.depthLimit
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
function fromCrossJSON(source, options) {
|
|
418
|
+
return deserializeTop(createFromCrossJSONContext(options), source);
|
|
419
|
+
}
|
|
420
|
+
function createCrossDeserializer(options) {
|
|
421
|
+
const ctx = createFromCrossJSONContext(options);
|
|
422
|
+
ctx.base.pending = /* @__PURE__ */ new Set();
|
|
423
|
+
return {
|
|
424
|
+
deserialize(node) {
|
|
425
|
+
if (!ctx.base.pending) throw new require_shared.SerovalAbortedError();
|
|
426
|
+
return deserializeTop(ctx, node);
|
|
427
|
+
},
|
|
428
|
+
get pending() {
|
|
429
|
+
return ctx.base.pending?.size ?? 0;
|
|
430
|
+
},
|
|
431
|
+
abort(reason) {
|
|
432
|
+
abortDeferred(ctx, reason);
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
//#endregion
|
|
437
|
+
//#region src/core/tree/read.ts
|
|
438
|
+
function deserialize(source) {
|
|
439
|
+
return (0, eval)(source);
|
|
440
|
+
}
|
|
441
|
+
function fromJSON(source, options = {}) {
|
|
442
|
+
const plugins = require_shared.resolvePlugins(options.plugins);
|
|
443
|
+
const disabledFeatures = options.disabledFeatures ?? 0;
|
|
444
|
+
const sourceFeatures = source.f ?? 127;
|
|
445
|
+
return deserializeTop(createVanillaDeserializerContext({
|
|
446
|
+
depthLimit: options.depthLimit,
|
|
447
|
+
maxBase64Length: options.maxBase64Length,
|
|
448
|
+
plugins,
|
|
449
|
+
markedRefs: source.m,
|
|
450
|
+
features: sourceFeatures & ~disabledFeatures,
|
|
451
|
+
disabledFeatures
|
|
452
|
+
}), source.t);
|
|
453
|
+
}
|
|
454
|
+
//#endregion
|
|
455
|
+
Object.defineProperty(exports, "createCrossDeserializer", {
|
|
456
|
+
enumerable: true,
|
|
457
|
+
get: function() {
|
|
458
|
+
return createCrossDeserializer;
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
Object.defineProperty(exports, "deserialize", {
|
|
462
|
+
enumerable: true,
|
|
463
|
+
get: function() {
|
|
464
|
+
return deserialize;
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
Object.defineProperty(exports, "fromCrossJSON", {
|
|
468
|
+
enumerable: true,
|
|
469
|
+
get: function() {
|
|
470
|
+
return fromCrossJSON;
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
Object.defineProperty(exports, "fromJSON", {
|
|
474
|
+
enumerable: true,
|
|
475
|
+
get: function() {
|
|
476
|
+
return fromJSON;
|
|
477
|
+
}
|
|
478
|
+
});
|