seroval 0.15.0 → 1.0.0
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/README.md +3 -3
- package/dist/cjs/development/index.cjs +1278 -1929
- package/dist/cjs/development/index.cjs.map +3 -3
- package/dist/cjs/production/index.cjs +3 -3
- package/dist/esm/development/index.mjs +1278 -1929
- package/dist/esm/development/index.mjs.map +3 -3
- package/dist/esm/production/index.mjs +3 -3
- package/dist/types/core/Serializer.d.ts +2 -1
- package/dist/types/core/Serializer.d.ts.map +1 -1
- package/dist/types/core/UnsupportedTypeError.d.ts.map +1 -1
- package/dist/types/core/base-primitives.d.ts +6 -2
- package/dist/types/core/base-primitives.d.ts.map +1 -1
- package/dist/types/core/compat.d.ts +5 -13
- package/dist/types/core/compat.d.ts.map +1 -1
- package/dist/types/core/constants.d.ts +17 -29
- package/dist/types/core/constants.d.ts.map +1 -1
- package/dist/types/core/context/deserializer.d.ts +6 -16
- package/dist/types/core/context/deserializer.d.ts.map +1 -1
- package/dist/types/core/context/parser/async.d.ts +2 -11
- package/dist/types/core/context/parser/async.d.ts.map +1 -1
- package/dist/types/core/context/parser/stream.d.ts +10 -10
- package/dist/types/core/context/parser/stream.d.ts.map +1 -1
- package/dist/types/core/context/parser/sync.d.ts +5 -7
- package/dist/types/core/context/parser/sync.d.ts.map +1 -1
- package/dist/types/core/context/parser.d.ts +19 -4
- package/dist/types/core/context/parser.d.ts.map +1 -1
- package/dist/types/core/context/serializer.d.ts +11 -25
- package/dist/types/core/context/serializer.d.ts.map +1 -1
- package/dist/types/core/cross/async.d.ts.map +1 -1
- package/dist/types/core/cross/deserializer.d.ts.map +1 -1
- package/dist/types/core/cross/index.d.ts.map +1 -1
- package/dist/types/core/cross/parser.d.ts.map +1 -1
- package/dist/types/core/cross/serializer.d.ts +1 -1
- package/dist/types/core/cross/serializer.d.ts.map +1 -1
- package/dist/types/core/cross/stream.d.ts.map +1 -1
- package/dist/types/core/cross/sync.d.ts.map +1 -1
- package/dist/types/core/keys.d.ts.map +1 -1
- package/dist/types/core/literals.d.ts.map +1 -1
- package/dist/types/core/plugin.d.ts +21 -0
- package/dist/types/core/plugin.d.ts.map +1 -1
- package/dist/types/core/reference.d.ts.map +1 -1
- package/dist/types/core/special-reference.d.ts +4 -9
- package/dist/types/core/special-reference.d.ts.map +1 -1
- package/dist/types/core/stream.d.ts +18 -0
- package/dist/types/core/stream.d.ts.map +1 -0
- package/dist/types/core/string.d.ts.map +1 -1
- package/dist/types/core/tree/async.d.ts.map +1 -1
- package/dist/types/core/tree/deserializer.d.ts.map +1 -1
- package/dist/types/core/tree/index.d.ts +1 -1
- package/dist/types/core/tree/index.d.ts.map +1 -1
- package/dist/types/core/tree/serializer.d.ts +3 -11
- package/dist/types/core/tree/serializer.d.ts.map +1 -1
- package/dist/types/core/types.d.ts +28 -122
- package/dist/types/core/types.d.ts.map +1 -1
- package/dist/types/core/utils/deferred.d.ts +0 -7
- package/dist/types/core/utils/deferred.d.ts.map +1 -1
- package/dist/types/core/utils/error.d.ts +2 -1
- package/dist/types/core/utils/error.d.ts.map +1 -1
- package/dist/types/core/utils/get-identifier.d.ts.map +1 -1
- package/dist/types/core/utils/is-valid-identifier.d.ts.map +1 -1
- package/dist/types/core/utils/iterator-to-sequence.d.ts +0 -12
- package/dist/types/core/utils/iterator-to-sequence.d.ts.map +1 -1
- package/dist/types/core/utils/typed-array.d.ts +2 -0
- package/dist/types/core/utils/typed-array.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/core/Serializer.ts +44 -28
- package/src/core/UnsupportedTypeError.ts +2 -3
- package/src/core/base-primitives.ts +124 -38
- package/src/core/compat.ts +5 -14
- package/src/core/constants.ts +28 -39
- package/src/core/context/deserializer.ts +122 -308
- package/src/core/context/parser/async.ts +163 -375
- package/src/core/context/parser/stream.ts +109 -367
- package/src/core/context/parser/sync.ts +139 -266
- package/src/core/context/parser.ts +93 -68
- package/src/core/context/serializer.ts +370 -439
- package/src/core/cross/async.ts +1 -1
- package/src/core/cross/deserializer.ts +1 -4
- package/src/core/cross/index.ts +28 -31
- package/src/core/cross/parser.ts +1 -1
- package/src/core/cross/serializer.ts +30 -20
- package/src/core/cross/stream.ts +1 -1
- package/src/core/cross/sync.ts +1 -1
- package/src/core/keys.ts +3 -1
- package/src/core/literals.ts +22 -8
- package/src/core/plugin.ts +48 -10
- package/src/core/reference.ts +4 -5
- package/src/core/special-reference.ts +5 -15
- package/src/core/stream.ts +205 -0
- package/src/core/string.ts +53 -22
- package/src/core/tree/async.ts +1 -1
- package/src/core/tree/deserializer.ts +4 -9
- package/src/core/tree/index.ts +15 -10
- package/src/core/tree/serializer.ts +6 -50
- package/src/core/types.ts +39 -179
- package/src/core/utils/deferred.ts +0 -27
- package/src/core/utils/error.ts +26 -15
- package/src/core/utils/get-identifier.ts +5 -4
- package/src/core/utils/is-valid-identifier.ts +6 -5
- package/src/core/utils/iterator-to-sequence.ts +0 -174
- package/src/core/utils/typed-array.ts +35 -11
- package/src/index.ts +5 -12
- package/dist/types/core/utils/constructors.d.ts +0 -5
- package/dist/types/core/utils/constructors.d.ts.map +0 -1
- package/dist/types/core/web-api.d.ts +0 -8
- package/dist/types/core/web-api.d.ts.map +0 -1
- package/dist/types/types.d.ts +0 -21
- package/dist/types/types.d.ts.map +0 -1
- package/src/core/utils/constructors.ts +0 -49
- package/src/core/web-api.ts +0 -138
- package/src/example.ts +0 -25
- package/src/types.ts +0 -84
package/src/core/types.ts
CHANGED
|
@@ -22,8 +22,8 @@ export interface SerovalBaseNode {
|
|
|
22
22
|
m: string | undefined;
|
|
23
23
|
// properties (objects)
|
|
24
24
|
p: SerovalObjectRecordNode | undefined;
|
|
25
|
-
// entries (for Map,
|
|
26
|
-
e: SerovalMapRecordNode |
|
|
25
|
+
// entries (for Map, etc.)
|
|
26
|
+
e: SerovalMapRecordNode | undefined;
|
|
27
27
|
// array of nodes
|
|
28
28
|
a: (SerovalNode | undefined)[] | undefined;
|
|
29
29
|
// fulfilled node
|
|
@@ -34,15 +34,7 @@ export interface SerovalBaseNode {
|
|
|
34
34
|
o: SerovalObjectFlags | undefined;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
export type SerovalObjectRecordKey =
|
|
38
|
-
| string
|
|
39
|
-
| SerovalNode;
|
|
40
|
-
|
|
41
|
-
export interface SerovalPlainRecordNode {
|
|
42
|
-
k: string[];
|
|
43
|
-
v: SerovalNode[];
|
|
44
|
-
s: number;
|
|
45
|
-
}
|
|
37
|
+
export type SerovalObjectRecordKey = string | SerovalNode;
|
|
46
38
|
|
|
47
39
|
export interface SerovalObjectRecordNode {
|
|
48
40
|
k: SerovalObjectRecordKey[];
|
|
@@ -226,20 +218,6 @@ export interface SerovalWKSymbolNode extends SerovalBaseNode {
|
|
|
226
218
|
s: Symbols;
|
|
227
219
|
}
|
|
228
220
|
|
|
229
|
-
export interface SerovalURLNode extends SerovalBaseNode {
|
|
230
|
-
t: SerovalNodeType.URL;
|
|
231
|
-
i: number;
|
|
232
|
-
// raw URL
|
|
233
|
-
s: string;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
export interface SerovalURLSearchParamsNode extends SerovalBaseNode {
|
|
237
|
-
t: SerovalNodeType.URLSearchParams;
|
|
238
|
-
i: number;
|
|
239
|
-
// raw URL search params
|
|
240
|
-
s: string;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
221
|
export interface SerovalReferenceNode extends SerovalBaseNode {
|
|
244
222
|
t: SerovalNodeType.Reference;
|
|
245
223
|
i: number;
|
|
@@ -258,40 +236,6 @@ export interface SerovalDataViewNode extends SerovalBaseNode {
|
|
|
258
236
|
b: number;
|
|
259
237
|
}
|
|
260
238
|
|
|
261
|
-
export interface SerovalBlobNode extends SerovalBaseNode {
|
|
262
|
-
t: SerovalNodeType.Blob;
|
|
263
|
-
i: number;
|
|
264
|
-
// file type
|
|
265
|
-
c: string;
|
|
266
|
-
// reference to array buffer
|
|
267
|
-
f: SerovalNode;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
export interface SerovalFileNode extends SerovalBaseNode {
|
|
271
|
-
t: SerovalNodeType.File;
|
|
272
|
-
i: number;
|
|
273
|
-
// file type
|
|
274
|
-
c: string;
|
|
275
|
-
// file name
|
|
276
|
-
m: string;
|
|
277
|
-
// reference to array buffer
|
|
278
|
-
f: SerovalNode;
|
|
279
|
-
// last modified
|
|
280
|
-
b: number;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
export interface SerovalHeadersNode extends SerovalBaseNode {
|
|
284
|
-
t: SerovalNodeType.Headers;
|
|
285
|
-
i: number;
|
|
286
|
-
e: SerovalPlainRecordNode;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
export interface SerovalFormDataNode extends SerovalBaseNode {
|
|
290
|
-
t: SerovalNodeType.FormData;
|
|
291
|
-
i: number;
|
|
292
|
-
e: SerovalPlainRecordNode;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
239
|
export interface SerovalBoxedNode extends SerovalBaseNode {
|
|
296
240
|
t: SerovalNodeType.Boxed;
|
|
297
241
|
i: number;
|
|
@@ -307,91 +251,13 @@ export interface SerovalPromiseConstructorNode extends SerovalBaseNode {
|
|
|
307
251
|
export interface SerovalPromiseResolveNode extends SerovalBaseNode {
|
|
308
252
|
t: SerovalNodeType.PromiseResolve;
|
|
309
253
|
i: number;
|
|
310
|
-
a: [
|
|
311
|
-
resolver: SerovalNodeWithID,
|
|
312
|
-
resolved: SerovalNode,
|
|
313
|
-
];
|
|
254
|
+
a: [resolver: SerovalNodeWithID, resolved: SerovalNode];
|
|
314
255
|
}
|
|
315
256
|
|
|
316
257
|
export interface SerovalPromiseRejectNode extends SerovalBaseNode {
|
|
317
258
|
t: SerovalNodeType.PromiseReject;
|
|
318
259
|
i: number;
|
|
319
|
-
a: [
|
|
320
|
-
resolver: SerovalNodeWithID,
|
|
321
|
-
resolved: SerovalNode,
|
|
322
|
-
];
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
export interface SerovalReadableStreamConstructorNode extends SerovalBaseNode {
|
|
326
|
-
t: SerovalNodeType.ReadableStreamConstructor;
|
|
327
|
-
i: number;
|
|
328
|
-
f: SerovalNodeWithID;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
export interface SerovalReadableStreamEnqueueNode extends SerovalBaseNode {
|
|
332
|
-
t: SerovalNodeType.ReadableStreamEnqueue;
|
|
333
|
-
i: number;
|
|
334
|
-
a: [
|
|
335
|
-
resolver: SerovalNodeWithID,
|
|
336
|
-
resolved: SerovalNode,
|
|
337
|
-
];
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
export interface SerovalReadableStreamErrorNode extends SerovalBaseNode {
|
|
341
|
-
t: SerovalNodeType.ReadableStreamError;
|
|
342
|
-
i: number;
|
|
343
|
-
a: [
|
|
344
|
-
resolver: SerovalNodeWithID,
|
|
345
|
-
resolved: SerovalNode,
|
|
346
|
-
];
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
export interface SerovalReadableStreamCloseNode extends SerovalBaseNode {
|
|
350
|
-
t: SerovalNodeType.ReadableStreamClose;
|
|
351
|
-
i: number;
|
|
352
|
-
f: SerovalNodeWithID;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
export interface SerovalRequestNode extends SerovalBaseNode {
|
|
356
|
-
t: SerovalNodeType.Request;
|
|
357
|
-
i: number;
|
|
358
|
-
// Request URL
|
|
359
|
-
s: string;
|
|
360
|
-
// This is just a shortcut for serializing the option fields
|
|
361
|
-
f: SerovalNode;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
export interface SerovalResponseNode extends SerovalBaseNode {
|
|
365
|
-
t: SerovalNodeType.Response;
|
|
366
|
-
i: number;
|
|
367
|
-
// This is just a shortcut for serializing the option fields
|
|
368
|
-
a: [body: SerovalNode, options: SerovalNode];
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
export interface SerovalEventNode extends SerovalBaseNode {
|
|
372
|
-
t: SerovalNodeType.Event;
|
|
373
|
-
i: number;
|
|
374
|
-
// Event type
|
|
375
|
-
s: string;
|
|
376
|
-
// Event options
|
|
377
|
-
f: SerovalNode;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
export interface SerovalCustomEventNode extends SerovalBaseNode {
|
|
381
|
-
t: SerovalNodeType.CustomEvent;
|
|
382
|
-
i: number;
|
|
383
|
-
// Event type
|
|
384
|
-
s: string;
|
|
385
|
-
f: SerovalNode;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
export interface SerovalDOMExceptionNode extends SerovalBaseNode {
|
|
389
|
-
t: SerovalNodeType.DOMException;
|
|
390
|
-
i: number;
|
|
391
|
-
// Message
|
|
392
|
-
s: string;
|
|
393
|
-
// name
|
|
394
|
-
c: string;
|
|
260
|
+
a: [resolver: SerovalNodeWithID, resolved: SerovalNode];
|
|
395
261
|
}
|
|
396
262
|
|
|
397
263
|
export interface SerovalPluginNode extends SerovalBaseNode {
|
|
@@ -412,39 +278,49 @@ export interface SerovalSpecialReferenceNode extends SerovalBaseNode {
|
|
|
412
278
|
export interface SerovalIteratorFactoryNode extends SerovalBaseNode {
|
|
413
279
|
t: SerovalNodeType.IteratorFactory;
|
|
414
280
|
i: number;
|
|
415
|
-
f:
|
|
281
|
+
f: SerovalNodeWithID;
|
|
416
282
|
}
|
|
417
283
|
|
|
418
284
|
export interface SerovalIteratorFactoryInstanceNode extends SerovalBaseNode {
|
|
419
285
|
t: SerovalNodeType.IteratorFactoryInstance;
|
|
420
|
-
a: [
|
|
421
|
-
instance: SerovalNodeWithID,
|
|
422
|
-
sequence: SerovalNode,
|
|
423
|
-
];
|
|
286
|
+
a: [instance: SerovalNodeWithID, sequence: SerovalNode];
|
|
424
287
|
}
|
|
425
288
|
|
|
426
289
|
export interface SerovalAsyncIteratorFactoryNode extends SerovalBaseNode {
|
|
427
290
|
t: SerovalNodeType.AsyncIteratorFactory;
|
|
428
291
|
i: number;
|
|
429
|
-
|
|
430
|
-
f: SerovalNode;
|
|
292
|
+
a: [promise: SerovalNodeWithID, symbol: SerovalNodeWithID];
|
|
431
293
|
}
|
|
432
294
|
|
|
433
|
-
export interface SerovalAsyncIteratorFactoryInstanceNode
|
|
295
|
+
export interface SerovalAsyncIteratorFactoryInstanceNode
|
|
296
|
+
extends SerovalBaseNode {
|
|
434
297
|
t: SerovalNodeType.AsyncIteratorFactoryInstance;
|
|
435
|
-
a: [
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
298
|
+
a: [instance: SerovalNodeWithID, sequence: SerovalNode];
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export interface SerovalStreamConstructorNode extends SerovalBaseNode {
|
|
302
|
+
t: SerovalNodeType.StreamConstructor;
|
|
303
|
+
i: number;
|
|
304
|
+
a: SerovalNode[];
|
|
305
|
+
f: SerovalNodeWithID;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export interface SerovalStreamNextNode extends SerovalBaseNode {
|
|
309
|
+
t: SerovalNodeType.StreamNext;
|
|
310
|
+
i: number;
|
|
311
|
+
f: SerovalNode;
|
|
439
312
|
}
|
|
440
313
|
|
|
441
|
-
export interface
|
|
442
|
-
t: SerovalNodeType.
|
|
314
|
+
export interface SerovalStreamThrowNode extends SerovalBaseNode {
|
|
315
|
+
t: SerovalNodeType.StreamThrow;
|
|
443
316
|
i: number;
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
317
|
+
f: SerovalNode;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export interface SerovalStreamReturnNode extends SerovalBaseNode {
|
|
321
|
+
t: SerovalNodeType.StreamReturn;
|
|
322
|
+
i: number;
|
|
323
|
+
f: SerovalNode;
|
|
448
324
|
}
|
|
449
325
|
|
|
450
326
|
export type SerovalSyncNode =
|
|
@@ -460,19 +336,10 @@ export type SerovalSyncNode =
|
|
|
460
336
|
| SerovalErrorNode
|
|
461
337
|
| SerovalAggregateErrorNode
|
|
462
338
|
| SerovalWKSymbolNode
|
|
463
|
-
| SerovalURLNode
|
|
464
|
-
| SerovalURLSearchParamsNode
|
|
465
339
|
| SerovalReferenceNode
|
|
466
340
|
| SerovalArrayBufferNode
|
|
467
341
|
| SerovalDataViewNode
|
|
468
|
-
| SerovalBlobNode
|
|
469
|
-
| SerovalFileNode
|
|
470
|
-
| SerovalHeadersNode
|
|
471
|
-
| SerovalFormDataNode
|
|
472
342
|
| SerovalBoxedNode
|
|
473
|
-
| SerovalEventNode
|
|
474
|
-
| SerovalCustomEventNode
|
|
475
|
-
| SerovalDOMExceptionNode
|
|
476
343
|
| SerovalPluginNode
|
|
477
344
|
| SerovalSpecialReferenceNode
|
|
478
345
|
| SerovalIteratorFactoryNode
|
|
@@ -482,21 +349,14 @@ export type SerovalSyncNode =
|
|
|
482
349
|
|
|
483
350
|
export type SerovalAsyncNode =
|
|
484
351
|
| SerovalPromiseNode
|
|
485
|
-
| SerovalBlobNode
|
|
486
|
-
| SerovalFileNode
|
|
487
352
|
| SerovalPromiseConstructorNode
|
|
488
353
|
| SerovalPromiseResolveNode
|
|
489
354
|
| SerovalPromiseRejectNode
|
|
490
|
-
|
|
|
491
|
-
|
|
|
492
|
-
|
|
|
493
|
-
|
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
| SerovalReadableStreamNode;
|
|
497
|
-
|
|
498
|
-
export type SerovalNode =
|
|
499
|
-
| SerovalSyncNode
|
|
500
|
-
| SerovalAsyncNode;
|
|
355
|
+
| SerovalStreamConstructorNode
|
|
356
|
+
| SerovalStreamNextNode
|
|
357
|
+
| SerovalStreamThrowNode
|
|
358
|
+
| SerovalStreamReturnNode;
|
|
359
|
+
|
|
360
|
+
export type SerovalNode = SerovalSyncNode | SerovalAsyncNode;
|
|
501
361
|
|
|
502
362
|
export type SerovalNodeWithID = Extract<SerovalNode, { i: number }>;
|
|
@@ -20,30 +20,3 @@ export function createDeferred(): Deferred {
|
|
|
20
20
|
},
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
export interface DeferredStream {
|
|
25
|
-
stream: ReadableStream;
|
|
26
|
-
close(): void;
|
|
27
|
-
enqueue(chunk?: unknown): void;
|
|
28
|
-
error(e?: any): void;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function createDeferredStream(): DeferredStream {
|
|
32
|
-
let controller: ReadableStreamDefaultController;
|
|
33
|
-
return {
|
|
34
|
-
stream: new ReadableStream({
|
|
35
|
-
start(current): void {
|
|
36
|
-
controller = current;
|
|
37
|
-
},
|
|
38
|
-
}),
|
|
39
|
-
close(): void {
|
|
40
|
-
controller.close();
|
|
41
|
-
},
|
|
42
|
-
enqueue(data): void {
|
|
43
|
-
controller.enqueue(data);
|
|
44
|
-
},
|
|
45
|
-
error(e): void {
|
|
46
|
-
controller.error(e);
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
}
|
package/src/core/utils/error.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ErrorValue,
|
|
3
|
-
} from '../../types';
|
|
4
1
|
import { Feature } from '../compat';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import { ERROR_CONSTRUCTOR_STRING, ErrorConstructorTag } from '../constants';
|
|
3
|
+
|
|
4
|
+
type ErrorValue =
|
|
5
|
+
| Error
|
|
6
|
+
| AggregateError
|
|
7
|
+
| EvalError
|
|
8
|
+
| RangeError
|
|
9
|
+
| ReferenceError
|
|
10
|
+
| TypeError
|
|
11
|
+
| SyntaxError
|
|
12
|
+
| URIError;
|
|
9
13
|
|
|
10
14
|
export function getErrorConstructor(error: ErrorValue): ErrorConstructorTag {
|
|
11
15
|
if (error instanceof EvalError) {
|
|
@@ -29,20 +33,27 @@ export function getErrorConstructor(error: ErrorValue): ErrorConstructorTag {
|
|
|
29
33
|
return ErrorConstructorTag.Error;
|
|
30
34
|
}
|
|
31
35
|
|
|
32
|
-
|
|
36
|
+
function getInitialErrorOptions(
|
|
33
37
|
error: Error,
|
|
34
|
-
features: number,
|
|
35
38
|
): Record<string, unknown> | undefined {
|
|
36
|
-
|
|
37
|
-
const constructor = ERROR_CONSTRUCTOR_STRING[getErrorConstructor(error)];
|
|
39
|
+
const construct = ERROR_CONSTRUCTOR_STRING[getErrorConstructor(error)];
|
|
38
40
|
// Name has been modified
|
|
39
|
-
if (error.name !==
|
|
40
|
-
|
|
41
|
-
}
|
|
41
|
+
if (error.name !== construct) {
|
|
42
|
+
return { name: error.name };
|
|
43
|
+
}
|
|
44
|
+
if (error.constructor.name !== construct) {
|
|
42
45
|
// Otherwise, name is overriden because
|
|
43
46
|
// the Error class is extended
|
|
44
|
-
|
|
47
|
+
return { name: error.constructor.name };
|
|
45
48
|
}
|
|
49
|
+
return {};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function getErrorOptions(
|
|
53
|
+
error: Error,
|
|
54
|
+
features: number,
|
|
55
|
+
): Record<string, unknown> | undefined {
|
|
56
|
+
let options = getInitialErrorOptions(error);
|
|
46
57
|
const names = Object.getOwnPropertyNames(error);
|
|
47
58
|
for (let i = 0, len = names.length, name: string; i < len; i++) {
|
|
48
59
|
name = names[i];
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// Written by https://github.com/DylanPiercey and is distributed under the MIT license.
|
|
2
|
-
const REF_START_CHARS = 'hjkmoquxzABCDEFGHIJKLNPQRTUVWXYZ$_'; // Avoids chars that could evaluate to a reserved word.
|
|
3
|
-
const REF_START_CHARS_LEN = REF_START_CHARS.length;
|
|
4
|
-
const REF_CHARS =
|
|
5
|
-
|
|
2
|
+
const REF_START_CHARS = /* @__PURE__ */ 'hjkmoquxzABCDEFGHIJKLNPQRTUVWXYZ$_'; // Avoids chars that could evaluate to a reserved word.
|
|
3
|
+
const REF_START_CHARS_LEN = /* @__PURE__ */ REF_START_CHARS.length;
|
|
4
|
+
const REF_CHARS =
|
|
5
|
+
/* @__PURE__ */ 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$_';
|
|
6
|
+
const REF_CHARS_LEN = /* @__PURE__ */ REF_CHARS.length;
|
|
6
7
|
|
|
7
8
|
export default function getIdentifier(index: number): string {
|
|
8
9
|
let mod = index % REF_START_CHARS_LEN;
|
|
@@ -3,9 +3,10 @@ const IDENTIFIER_CHECK = /^[$A-Z_][0-9A-Z_$]*$/i;
|
|
|
3
3
|
export function isValidIdentifier(name: string): boolean {
|
|
4
4
|
const char = name[0];
|
|
5
5
|
return (
|
|
6
|
-
char === '$'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
(char === '$' ||
|
|
7
|
+
char === '_' ||
|
|
8
|
+
(char >= 'A' && char <= 'Z') ||
|
|
9
|
+
(char >= 'a' && char <= 'z')) &&
|
|
10
|
+
IDENTIFIER_CHECK.test(name)
|
|
11
|
+
);
|
|
11
12
|
}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import type BaseStreamParserContext from '../context/parser/stream';
|
|
2
|
-
|
|
3
|
-
/* eslint-disable no-await-in-loop */
|
|
4
1
|
export interface Sequence {
|
|
5
2
|
v: unknown[];
|
|
6
3
|
t: number;
|
|
@@ -65,174 +62,3 @@ export function sequenceToIterator<T>(
|
|
|
65
62
|
};
|
|
66
63
|
};
|
|
67
64
|
}
|
|
68
|
-
|
|
69
|
-
export async function asyncIteratorToSequence<T>(source: AsyncIterable<T>): Promise<Sequence> {
|
|
70
|
-
const values: unknown[] = [];
|
|
71
|
-
let throwsAt = -1;
|
|
72
|
-
let doneAt = -1;
|
|
73
|
-
|
|
74
|
-
const iterator = source[Symbol.asyncIterator]();
|
|
75
|
-
|
|
76
|
-
while (true) {
|
|
77
|
-
try {
|
|
78
|
-
const value = await iterator.next();
|
|
79
|
-
values.push(value.value);
|
|
80
|
-
if (value.done) {
|
|
81
|
-
doneAt = values.length - 1;
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
} catch (error) {
|
|
85
|
-
throwsAt = values.length;
|
|
86
|
-
values.push(error);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return {
|
|
91
|
-
v: values,
|
|
92
|
-
t: throwsAt,
|
|
93
|
-
d: doneAt,
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function sequenceToAsyncIterator<T>(
|
|
98
|
-
sequence: Sequence,
|
|
99
|
-
): () => AsyncIterableIterator<T> {
|
|
100
|
-
return (): AsyncIterableIterator<T> => {
|
|
101
|
-
let index = 0;
|
|
102
|
-
return {
|
|
103
|
-
[Symbol.asyncIterator](): AsyncIterableIterator<T> {
|
|
104
|
-
return this;
|
|
105
|
-
},
|
|
106
|
-
async next(): Promise<IteratorResult<T>> {
|
|
107
|
-
if (index > sequence.d) {
|
|
108
|
-
return {
|
|
109
|
-
done: true,
|
|
110
|
-
value: undefined,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
const currentIndex = index++;
|
|
114
|
-
const currentItem = sequence.v[currentIndex];
|
|
115
|
-
if (currentIndex === sequence.t) {
|
|
116
|
-
throw currentItem;
|
|
117
|
-
}
|
|
118
|
-
return Promise.resolve({
|
|
119
|
-
done: currentIndex === sequence.d,
|
|
120
|
-
value: currentItem as T,
|
|
121
|
-
});
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export function asyncIteratorToReadableStream<T>(
|
|
128
|
-
source: AsyncIterable<T>,
|
|
129
|
-
parser: BaseStreamParserContext,
|
|
130
|
-
): ReadableStream<unknown> {
|
|
131
|
-
return new ReadableStream({
|
|
132
|
-
async start(controller): Promise<void> {
|
|
133
|
-
const iterator = source[Symbol.asyncIterator]();
|
|
134
|
-
while (parser.isAlive()) {
|
|
135
|
-
try {
|
|
136
|
-
const result = await iterator.next();
|
|
137
|
-
controller.enqueue([result.done ? 2 : 0, result.value]);
|
|
138
|
-
if (result.done) {
|
|
139
|
-
controller.close();
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
} catch (error) {
|
|
143
|
-
controller.enqueue([1, error]);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
controller.close();
|
|
147
|
-
},
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
type RSNext<T> = [0, T];
|
|
152
|
-
type RSThrow = [1, any];
|
|
153
|
-
type RSReturn<T> = [2, T];
|
|
154
|
-
|
|
155
|
-
export type SerializedAsyncIteratorResult<T> = RSNext<T> | RSThrow | RSReturn<T>;
|
|
156
|
-
|
|
157
|
-
export function readableStreamToAsyncIterator<T>(
|
|
158
|
-
source: ReadableStream<SerializedAsyncIteratorResult<T>>,
|
|
159
|
-
): () => AsyncIterableIterator<T> {
|
|
160
|
-
let current = source;
|
|
161
|
-
return (): AsyncIterableIterator<T> => {
|
|
162
|
-
const [left, right] = current.tee();
|
|
163
|
-
const clone = left;
|
|
164
|
-
current = right;
|
|
165
|
-
const reader = clone.getReader();
|
|
166
|
-
return {
|
|
167
|
-
[Symbol.asyncIterator](): AsyncIterableIterator<T> {
|
|
168
|
-
return this;
|
|
169
|
-
},
|
|
170
|
-
async next(): Promise<IteratorResult<T>> {
|
|
171
|
-
const result = await reader.read();
|
|
172
|
-
if (result.done) {
|
|
173
|
-
return {
|
|
174
|
-
done: true,
|
|
175
|
-
value: undefined,
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
const [status, value] = result.value;
|
|
179
|
-
if (status === 1) {
|
|
180
|
-
throw value;
|
|
181
|
-
}
|
|
182
|
-
return {
|
|
183
|
-
done: status === 2,
|
|
184
|
-
value,
|
|
185
|
-
};
|
|
186
|
-
},
|
|
187
|
-
};
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
export async function readableStreamToSequence<T>(
|
|
192
|
-
stream: ReadableStream<T>,
|
|
193
|
-
): Promise<Sequence> {
|
|
194
|
-
const values: unknown[] = [];
|
|
195
|
-
let throwsAt = -1;
|
|
196
|
-
let doneAt = -1;
|
|
197
|
-
|
|
198
|
-
const iterator = stream.getReader();
|
|
199
|
-
|
|
200
|
-
while (true) {
|
|
201
|
-
try {
|
|
202
|
-
const value = await iterator.read();
|
|
203
|
-
values.push(value.value);
|
|
204
|
-
if (value.done) {
|
|
205
|
-
doneAt = values.length - 1;
|
|
206
|
-
break;
|
|
207
|
-
}
|
|
208
|
-
} catch (error) {
|
|
209
|
-
throwsAt = values.length;
|
|
210
|
-
doneAt = throwsAt;
|
|
211
|
-
values.push(error);
|
|
212
|
-
break;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
return {
|
|
217
|
-
v: values,
|
|
218
|
-
t: throwsAt,
|
|
219
|
-
d: doneAt,
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
export function sequenceToReadableStream<T>(
|
|
224
|
-
sequence: Sequence,
|
|
225
|
-
): ReadableStream<T> {
|
|
226
|
-
return new ReadableStream<T>({
|
|
227
|
-
start(controller): void {
|
|
228
|
-
for (let i = 0; i < sequence.d; i++) {
|
|
229
|
-
controller.enqueue(sequence.v[i] as T);
|
|
230
|
-
}
|
|
231
|
-
if (sequence.t === -1) {
|
|
232
|
-
controller.close();
|
|
233
|
-
} else {
|
|
234
|
-
controller.error(sequence.v[sequence.t] as T);
|
|
235
|
-
}
|
|
236
|
-
},
|
|
237
|
-
});
|
|
238
|
-
}
|
|
@@ -11,19 +11,43 @@ type TypedArrayConstructor =
|
|
|
11
11
|
| BigInt64ArrayConstructor
|
|
12
12
|
| BigUint64ArrayConstructor;
|
|
13
13
|
|
|
14
|
+
export type TypedArrayValue =
|
|
15
|
+
| Int8Array
|
|
16
|
+
| Int16Array
|
|
17
|
+
| Int32Array
|
|
18
|
+
| Uint8Array
|
|
19
|
+
| Uint16Array
|
|
20
|
+
| Uint32Array
|
|
21
|
+
| Uint8ClampedArray
|
|
22
|
+
| Float32Array
|
|
23
|
+
| Float64Array;
|
|
24
|
+
|
|
25
|
+
export type BigIntTypedArrayValue = BigInt64Array | BigUint64Array;
|
|
26
|
+
|
|
14
27
|
export function getTypedArrayConstructor(name: string): TypedArrayConstructor {
|
|
15
28
|
switch (name) {
|
|
16
|
-
case 'Int8Array':
|
|
17
|
-
|
|
18
|
-
case '
|
|
19
|
-
|
|
20
|
-
case '
|
|
21
|
-
|
|
22
|
-
case '
|
|
23
|
-
|
|
24
|
-
case '
|
|
25
|
-
|
|
26
|
-
case '
|
|
29
|
+
case 'Int8Array':
|
|
30
|
+
return Int8Array;
|
|
31
|
+
case 'Int16Array':
|
|
32
|
+
return Int16Array;
|
|
33
|
+
case 'Int32Array':
|
|
34
|
+
return Int32Array;
|
|
35
|
+
case 'Uint8Array':
|
|
36
|
+
return Uint8Array;
|
|
37
|
+
case 'Uint16Array':
|
|
38
|
+
return Uint16Array;
|
|
39
|
+
case 'Uint32Array':
|
|
40
|
+
return Uint32Array;
|
|
41
|
+
case 'Uint8ClampedArray':
|
|
42
|
+
return Uint8ClampedArray;
|
|
43
|
+
case 'Float32Array':
|
|
44
|
+
return Float32Array;
|
|
45
|
+
case 'Float64Array':
|
|
46
|
+
return Float64Array;
|
|
47
|
+
case 'BigInt64Array':
|
|
48
|
+
return BigInt64Array;
|
|
49
|
+
case 'BigUint64Array':
|
|
50
|
+
return BigUint64Array;
|
|
27
51
|
default:
|
|
28
52
|
throw new Error(`Unknown TypedArray "${name}"`);
|
|
29
53
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
import { serialize } from './core/tree';
|
|
2
|
-
|
|
3
|
-
export type {
|
|
4
|
-
AsyncServerValue,
|
|
5
|
-
ServerValue,
|
|
6
|
-
PrimitiveValue,
|
|
7
|
-
CommonServerValue,
|
|
8
|
-
SemiPrimitiveValue,
|
|
9
|
-
ErrorValue,
|
|
10
|
-
} from './types';
|
|
11
1
|
export { Feature } from './core/compat';
|
|
12
2
|
export { createReference } from './core/reference';
|
|
13
3
|
|
|
14
4
|
export * from './core/tree';
|
|
15
5
|
export * from './core/cross';
|
|
16
6
|
|
|
7
|
+
export { getCrossReferenceHeader } from './core/keys';
|
|
8
|
+
|
|
17
9
|
export { default as Serializer } from './core/Serializer';
|
|
18
10
|
export * from './core/plugin';
|
|
19
11
|
|
|
20
|
-
export type {
|
|
12
|
+
export type { Stream } from './core/stream';
|
|
13
|
+
export { createStream } from './core/stream';
|
|
21
14
|
|
|
22
|
-
export
|
|
15
|
+
export type { SerovalNode } from './core/types';
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export declare function createRequestOptions(current: Request, body: ArrayBuffer | ReadableStream | null): RequestInit;
|
|
2
|
-
export declare function createResponseOptions(current: Response): ResponseInit;
|
|
3
|
-
export declare function createEventOptions(current: Event): EventInit;
|
|
4
|
-
export declare function createCustomEventOptions(current: CustomEvent): CustomEventInit;
|
|
5
|
-
//# sourceMappingURL=constructors.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constructors.d.ts","sourceRoot":"","sources":["../../../../src/core/utils/constructors.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,WAAW,GAAG,cAAc,GAAG,IAAI,GACxC,WAAW,CAcb;AAED,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,QAAQ,GAChB,YAAY,CAMd;AAED,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,KAAK,GACb,SAAS,CAMX;AAED,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,WAAW,GACnB,eAAe,CAOjB"}
|