seroval 1.6.12 → 1.7.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 +10 -3
- package/dist/dev/index.cjs +1572 -1039
- package/dist/dev/index.d.cts +285 -251
- package/dist/dev/index.d.ts +285 -251
- package/dist/dev/index.js +1564 -1040
- package/dist/index.cjs +1562 -1038
- package/dist/index.d.cts +285 -251
- package/dist/index.d.ts +285 -251
- package/dist/index.js +1554 -1039
- package/package.json +19 -11
package/dist/index.d.cts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
//#region src/core/compat.d.ts
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* Public feature bits for `disabledFeatures`. Stays a runtime `enum` so the
|
|
4
|
+
* published declaration is unchanged for consumers. Its values must match
|
|
5
|
+
* the internal bits (checked by test/feature.test.ts).
|
|
6
6
|
*/
|
|
7
|
-
declare enum Feature {
|
|
7
|
+
export declare enum Feature {
|
|
8
8
|
AggregateError = 1,
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Has no effect. Output always uses arrow functions.
|
|
11
|
+
*/
|
|
9
12
|
ArrowFunction = 2,
|
|
10
13
|
ErrorPrototypeStack = 4,
|
|
11
14
|
ObjectAssign = 8,
|
|
@@ -323,6 +326,7 @@ interface SerovalStreamConstructorNode extends SerovalBaseNode {
|
|
|
323
326
|
i: number;
|
|
324
327
|
a: SerovalNode[];
|
|
325
328
|
f: SerovalNodeWithID;
|
|
329
|
+
l: 1 | undefined;
|
|
326
330
|
}
|
|
327
331
|
interface SerovalStreamNextNode extends SerovalBaseNode {
|
|
328
332
|
t: SerovalNodeType.StreamNext;
|
|
@@ -362,185 +366,178 @@ interface BaseDeserializerContextOptions extends PluginAccessOptions {
|
|
|
362
366
|
/** Maximum encoded characters per ArrayBuffer. Defaults to 1,000,000. */
|
|
363
367
|
maxBase64Length?: number;
|
|
364
368
|
}
|
|
365
|
-
interface BaseDeserializerContext extends PluginAccessOptions {
|
|
366
|
-
readonly mode: SerovalMode;
|
|
367
|
-
/**
|
|
368
|
-
* Mapping ids to values
|
|
369
|
-
*/
|
|
370
|
-
refs: Map<number, unknown> & {
|
|
371
|
-
types: Map<number, SerovalNodeType>;
|
|
372
|
-
};
|
|
373
|
-
features: number;
|
|
374
|
-
depthLimit: number;
|
|
375
|
-
maxBase64Length: number;
|
|
376
|
-
}
|
|
377
369
|
interface VanillaDeserializerContextOptions extends Omit<BaseDeserializerContextOptions, 'refs'> {
|
|
378
370
|
markedRefs: number[] | Set<number>;
|
|
379
371
|
}
|
|
380
|
-
interface VanillaDeserializerState {
|
|
381
|
-
marked: Set<number>;
|
|
382
|
-
}
|
|
383
|
-
interface VanillaDeserializerContext {
|
|
384
|
-
mode: SerovalMode.Vanilla;
|
|
385
|
-
base: BaseDeserializerContext;
|
|
386
|
-
child: DeserializePluginContext | undefined;
|
|
387
|
-
state: VanillaDeserializerState;
|
|
388
|
-
}
|
|
389
|
-
interface CrossDeserializerContext {
|
|
390
|
-
mode: SerovalMode.Cross;
|
|
391
|
-
base: BaseDeserializerContext;
|
|
392
|
-
child: DeserializePluginContext | undefined;
|
|
393
|
-
}
|
|
394
372
|
type CrossDeserializerContextOptions = BaseDeserializerContextOptions;
|
|
395
|
-
|
|
396
|
-
declare class DeserializePluginContext {
|
|
397
|
-
private _p;
|
|
398
|
-
private depth;
|
|
399
|
-
constructor(_p: DeserializerContext, depth: number);
|
|
373
|
+
interface DeserializePluginContext {
|
|
400
374
|
deserialize<T>(node: SerovalNode): T;
|
|
401
375
|
}
|
|
402
376
|
//#endregion
|
|
403
377
|
//#region src/core/context/serializer.d.ts
|
|
404
|
-
declare const enum AssignmentType {
|
|
405
|
-
Index = 0,
|
|
406
|
-
Add = 1,
|
|
407
|
-
Set = 2,
|
|
408
|
-
Delete = 3,
|
|
409
|
-
Define = 4
|
|
410
|
-
}
|
|
411
|
-
interface IndexAssignment {
|
|
412
|
-
t: AssignmentType.Index;
|
|
413
|
-
s: string;
|
|
414
|
-
k: undefined;
|
|
415
|
-
v: string;
|
|
416
|
-
}
|
|
417
|
-
interface SetAssignment {
|
|
418
|
-
t: AssignmentType.Set;
|
|
419
|
-
s: string;
|
|
420
|
-
k: string;
|
|
421
|
-
v: string;
|
|
422
|
-
}
|
|
423
|
-
interface AddAssignment {
|
|
424
|
-
t: AssignmentType.Add;
|
|
425
|
-
s: string;
|
|
426
|
-
k: undefined;
|
|
427
|
-
v: string;
|
|
428
|
-
}
|
|
429
|
-
interface DeleteAssignment {
|
|
430
|
-
t: AssignmentType.Delete;
|
|
431
|
-
s: string;
|
|
432
|
-
k: string;
|
|
433
|
-
v: undefined;
|
|
434
|
-
}
|
|
435
|
-
interface DefineAssignment {
|
|
436
|
-
t: AssignmentType.Define;
|
|
437
|
-
s: string;
|
|
438
|
-
k: string;
|
|
439
|
-
v: undefined;
|
|
440
|
-
}
|
|
441
|
-
type Assignment = IndexAssignment | AddAssignment | SetAssignment | DeleteAssignment | DefineAssignment;
|
|
442
|
-
interface FlaggedObject {
|
|
443
|
-
type: SerovalObjectFlags;
|
|
444
|
-
value: string;
|
|
445
|
-
}
|
|
446
378
|
interface BaseSerializerContextOptions extends PluginAccessOptions {
|
|
447
379
|
features: number;
|
|
448
380
|
markedRefs: number[] | Set<number>;
|
|
449
|
-
|
|
450
|
-
interface BaseSerializerContext extends PluginAccessOptions {
|
|
451
|
-
readonly mode: SerovalMode;
|
|
452
|
-
features: number;
|
|
453
|
-
stack: number[];
|
|
454
|
-
/**
|
|
455
|
-
* Array of object mutations
|
|
456
|
-
*/
|
|
457
|
-
flags: FlaggedObject[];
|
|
458
|
-
/**
|
|
459
|
-
* Array of assignments to be done (used for recursion)
|
|
460
|
-
*/
|
|
461
|
-
assignments: Assignment[];
|
|
462
|
-
/**
|
|
463
|
-
* Refs that are...referenced
|
|
464
|
-
*/
|
|
465
|
-
marked: Set<number>;
|
|
381
|
+
assignSharedRefsOnly?: boolean;
|
|
466
382
|
}
|
|
467
383
|
interface CrossContextOptions {
|
|
468
384
|
scopeId?: string;
|
|
469
385
|
}
|
|
470
|
-
interface VanillaSerializerState {
|
|
471
|
-
valid: Map<number, number>;
|
|
472
|
-
vars: string[];
|
|
473
|
-
}
|
|
474
|
-
interface VanillaSerializerContext {
|
|
475
|
-
mode: SerovalMode.Vanilla;
|
|
476
|
-
base: BaseSerializerContext;
|
|
477
|
-
state: VanillaSerializerState;
|
|
478
|
-
child: SerializePluginContext | undefined;
|
|
479
|
-
}
|
|
480
386
|
type VanillaSerializerContextOptions = BaseSerializerContextOptions;
|
|
481
|
-
interface CrossSerializerContext {
|
|
482
|
-
mode: SerovalMode.Cross;
|
|
483
|
-
base: BaseSerializerContext;
|
|
484
|
-
state: CrossContextOptions;
|
|
485
|
-
child: SerializePluginContext | undefined;
|
|
486
|
-
}
|
|
487
387
|
interface CrossSerializerContextOptions extends BaseSerializerContextOptions, CrossContextOptions {}
|
|
488
|
-
|
|
489
|
-
declare class SerializePluginContext {
|
|
490
|
-
private _p;
|
|
491
|
-
constructor(_p: SerializerContext);
|
|
388
|
+
interface SerializePluginContext {
|
|
492
389
|
serialize(node: SerovalNode): string;
|
|
493
390
|
}
|
|
494
391
|
//#endregion
|
|
495
|
-
//#region src/core/
|
|
496
|
-
interface
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
/** Copy each typed array or DataView's visible bytes into its own buffer. */
|
|
501
|
-
compactArrayBufferViews?: boolean;
|
|
392
|
+
//#region src/core/stream.d.ts
|
|
393
|
+
interface StreamListener<T> {
|
|
394
|
+
next(value: T): void;
|
|
395
|
+
throw(value: unknown): void;
|
|
396
|
+
return(value: T): void;
|
|
502
397
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
398
|
+
/**
|
|
399
|
+
* An internal class rather than a tagged POJO: identity is checked with
|
|
400
|
+
* `instanceof`, which untrusted input cannot forge. The class is exported
|
|
401
|
+
* because bundlers cannot drop an unexported top-level class.
|
|
402
|
+
*
|
|
403
|
+
* The behavior is intentionally duplicated from `STREAM_CONSTRUCTOR`. That
|
|
404
|
+
* constructor's source is embedded verbatim into the eval-based `deserialize`
|
|
405
|
+
* output, which has no access to this class, so the two cannot be shared. A
|
|
406
|
+
* stream read back through `deserialize` is therefore a plain POJO and, by
|
|
407
|
+
* design, is not treated as a genuine Stream on re-serialization. Keep the two
|
|
408
|
+
* implementations in sync.
|
|
409
|
+
*/
|
|
410
|
+
export declare class Stream<T> {
|
|
411
|
+
private buffer;
|
|
412
|
+
private listeners;
|
|
413
|
+
private alive;
|
|
414
|
+
private success;
|
|
415
|
+
private count;
|
|
416
|
+
private live;
|
|
417
|
+
constructor(live?: number);
|
|
418
|
+
private flush;
|
|
419
|
+
private replay;
|
|
420
|
+
on(listener: StreamListener<T>): () => void;
|
|
421
|
+
next(value: T): void;
|
|
422
|
+
throw(value: unknown): void;
|
|
423
|
+
return(value: T): void;
|
|
510
424
|
}
|
|
425
|
+
export declare function isStream<T>(value: unknown): value is Stream<T> | LiveStream<T>;
|
|
426
|
+
export declare function createStream<T>(): Stream<T>;
|
|
427
|
+
//#endregion
|
|
428
|
+
//#region src/core/live-stream.d.ts
|
|
429
|
+
type LiveStreamEvent<T> = {
|
|
430
|
+
type: 'next';
|
|
431
|
+
value: T;
|
|
432
|
+
} | {
|
|
433
|
+
type: 'return';
|
|
434
|
+
value: T;
|
|
435
|
+
} | {
|
|
436
|
+
type: 'throw';
|
|
437
|
+
error: unknown;
|
|
438
|
+
};
|
|
439
|
+
interface LiveStreamDelivery<T> {
|
|
440
|
+
event: LiveStreamEvent<T>;
|
|
441
|
+
/**
|
|
442
|
+
* Release the event and resolve the producer operation that sent it.
|
|
443
|
+
* Call it only after the serialized record for the event has been
|
|
444
|
+
* accepted by its destination. Late or repeated calls are ignored.
|
|
445
|
+
*/
|
|
446
|
+
accept(): void;
|
|
447
|
+
}
|
|
448
|
+
interface LiveStreamConsumer<T> {
|
|
449
|
+
read(): Promise<LiveStreamDelivery<T>>;
|
|
450
|
+
cancel(reason?: unknown): void;
|
|
451
|
+
}
|
|
452
|
+
interface LiveStreamProducer<T> {
|
|
453
|
+
write(value: T): Promise<void>;
|
|
454
|
+
close(value: T): Promise<void>;
|
|
455
|
+
fail(error: unknown): Promise<void>;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Receives events from `LiveStream.pump`. Each handler gets the event value
|
|
459
|
+
* and the accept function for it, and returns `undefined` to keep going or
|
|
460
|
+
* the error that stopped the sink. `error` runs if the stream is cancelled
|
|
461
|
+
* while a read is pending.
|
|
462
|
+
*/
|
|
463
|
+
interface LiveStreamSink<T> {
|
|
464
|
+
next(value: T, accept: () => void): unknown;
|
|
465
|
+
throw(value: unknown, accept: () => void): unknown;
|
|
466
|
+
return(value: T, accept: () => void): unknown;
|
|
467
|
+
/** Runs once after the terminal event, or after a handler failed. */
|
|
468
|
+
done?(): void;
|
|
469
|
+
/** Runs if the stream is cancelled while a read is pending. */
|
|
470
|
+
error?(reason: unknown): void;
|
|
471
|
+
}
|
|
472
|
+
interface LiveStreamOptions {
|
|
473
|
+
onCancel?: (reason: unknown) => void;
|
|
474
|
+
}
|
|
475
|
+
export declare function isLiveStream<T>(value: unknown): value is LiveStream<T>;
|
|
476
|
+
/**
|
|
477
|
+
* A single-consumer stream for incremental serialization. Unlike
|
|
478
|
+
* `createStream`, it keeps no history: at most one event is held, and the
|
|
479
|
+
* producer operation that sent it settles only when the consumer accepts it.
|
|
480
|
+
*
|
|
481
|
+
* An internal class rather than a tagged POJO: identity is checked with
|
|
482
|
+
* `instanceof`, which untrusted input cannot forge. The class is exported
|
|
483
|
+
* because bundlers cannot drop an unexported top-level class.
|
|
484
|
+
*/
|
|
485
|
+
export declare class LiveStream<T> {
|
|
486
|
+
private pending;
|
|
487
|
+
private waiting;
|
|
488
|
+
private consumed;
|
|
489
|
+
private closed;
|
|
490
|
+
private cancelled;
|
|
491
|
+
private cancelReason;
|
|
492
|
+
private options;
|
|
493
|
+
constructor(options?: LiveStreamOptions);
|
|
494
|
+
private deliver;
|
|
495
|
+
/** @internal */
|
|
496
|
+
push(event: LiveStreamEvent<T>): Promise<void>;
|
|
497
|
+
private cancel;
|
|
498
|
+
private read;
|
|
499
|
+
consume(): LiveStreamConsumer<T>;
|
|
500
|
+
/**
|
|
501
|
+
* Consumes the stream through a replay-style listener, accepting each
|
|
502
|
+
* event as soon as it has been delivered. Use `consume` or `pump` when
|
|
503
|
+
* acceptance must wait for processing.
|
|
504
|
+
*/
|
|
505
|
+
on(listener: StreamListener<T>): () => void;
|
|
506
|
+
/**
|
|
507
|
+
* Consumes the stream into a sink that controls acceptance. Returns the
|
|
508
|
+
* cancel function.
|
|
509
|
+
* @internal
|
|
510
|
+
*/
|
|
511
|
+
pump(sink: LiveStreamSink<T>): (reason?: unknown) => void;
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Creates a live stream and the producer that writes to it.
|
|
515
|
+
*/
|
|
516
|
+
export declare function createLiveStream<T>(options?: LiveStreamOptions): {
|
|
517
|
+
stream: LiveStream<T>;
|
|
518
|
+
producer: LiveStreamProducer<T>;
|
|
519
|
+
};
|
|
511
520
|
//#endregion
|
|
512
521
|
//#region src/core/context/sync-parser.d.ts
|
|
513
522
|
type SyncParserContextOptions = BaseParserContextOptions;
|
|
514
|
-
|
|
515
|
-
Sync = 1,
|
|
516
|
-
Stream = 2
|
|
517
|
-
}
|
|
518
|
-
interface SyncParserContext {
|
|
519
|
-
type: ParserMode.Sync;
|
|
520
|
-
base: BaseParserContext;
|
|
521
|
-
child: SyncParsePluginContext | undefined;
|
|
522
|
-
}
|
|
523
|
-
declare class SyncParsePluginContext {
|
|
524
|
-
private _p;
|
|
525
|
-
private depth;
|
|
526
|
-
constructor(_p: SyncParserContext, depth: number);
|
|
523
|
+
interface SyncParsePluginContext {
|
|
527
524
|
parse<T>(current: T): SerovalNode;
|
|
528
525
|
}
|
|
529
526
|
interface StreamParserContextOptions extends SyncParserContextOptions {
|
|
530
|
-
|
|
527
|
+
/**
|
|
528
|
+
* Receives each parsed record. Returning a promise defers the next record,
|
|
529
|
+
* and the acceptance of the source event that produced it, until the
|
|
530
|
+
* promise settles.
|
|
531
|
+
*/
|
|
532
|
+
onParse: (node: SerovalNode, initial: boolean) => void | PromiseLike<void>;
|
|
531
533
|
onError?: (error: unknown) => void;
|
|
532
534
|
onDone?: () => void;
|
|
533
535
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
state: StreamParserState;
|
|
538
|
-
}
|
|
539
|
-
declare class StreamParsePluginContext {
|
|
540
|
-
private _p;
|
|
541
|
-
private depth;
|
|
542
|
-
constructor(_p: StreamParserContext, depth: number);
|
|
536
|
+
//#endregion
|
|
537
|
+
//#region src/core/context/stream-parser.d.ts
|
|
538
|
+
interface StreamParsePluginContext {
|
|
543
539
|
parse<T>(current: T): SerovalNode;
|
|
540
|
+
parseStreamSource(current: AsyncIterable<unknown>): SerovalNode;
|
|
544
541
|
parseWithError<T>(current: T): SerovalNode | undefined;
|
|
545
542
|
isAlive(): boolean;
|
|
546
543
|
pushPendingState(): void;
|
|
@@ -549,29 +546,19 @@ declare class StreamParsePluginContext {
|
|
|
549
546
|
onError(error: unknown): void;
|
|
550
547
|
addCleanup(callback: () => void): void;
|
|
551
548
|
}
|
|
552
|
-
interface StreamParserState {
|
|
553
|
-
alive: boolean;
|
|
554
|
-
pending: number;
|
|
555
|
-
initial: boolean;
|
|
556
|
-
buffer: SerovalNode[];
|
|
557
|
-
onParse: (node: SerovalNode, initial: boolean) => void;
|
|
558
|
-
onError?: (error: unknown) => void;
|
|
559
|
-
onDone?: () => void;
|
|
560
|
-
cleanups: (() => void)[];
|
|
561
|
-
}
|
|
562
549
|
//#endregion
|
|
563
550
|
//#region src/core/plugin.d.ts
|
|
564
|
-
declare const enum SerovalMode {
|
|
551
|
+
export declare const enum SerovalMode {
|
|
565
552
|
Vanilla = 1,
|
|
566
553
|
Cross = 2
|
|
567
554
|
}
|
|
568
|
-
interface PluginData {
|
|
555
|
+
export interface PluginData {
|
|
569
556
|
id: number;
|
|
570
557
|
}
|
|
571
|
-
type PluginInfo = {
|
|
558
|
+
export type PluginInfo = {
|
|
572
559
|
[key: string]: SerovalNode;
|
|
573
560
|
};
|
|
574
|
-
interface Plugin<Value, Info extends PluginInfo> {
|
|
561
|
+
export interface Plugin<Value, Info extends PluginInfo> {
|
|
575
562
|
/**
|
|
576
563
|
* A unique string that helps idenfity the plugin
|
|
577
564
|
*/
|
|
@@ -585,6 +572,13 @@ interface Plugin<Value, Info extends PluginInfo> {
|
|
|
585
572
|
* @param value
|
|
586
573
|
*/
|
|
587
574
|
test(value: unknown): boolean;
|
|
575
|
+
/**
|
|
576
|
+
* Set to `true` if `test` never returns `true` for a plain object, whose
|
|
577
|
+
* prototype is `Object.prototype`, such as an object literal. The parsers
|
|
578
|
+
* then skip this plugin for those objects. Leave it unset if unsure. A
|
|
579
|
+
* plugin that sets it is never applied to such objects.
|
|
580
|
+
*/
|
|
581
|
+
skipPlainObjects?: boolean;
|
|
588
582
|
/**
|
|
589
583
|
* Parsing modes
|
|
590
584
|
*/
|
|
@@ -602,105 +596,149 @@ interface Plugin<Value, Info extends PluginInfo> {
|
|
|
602
596
|
*/
|
|
603
597
|
deserialize(node: Info, ctx: DeserializePluginContext, data: PluginData): Value;
|
|
604
598
|
}
|
|
605
|
-
declare function createPlugin<Value, Info extends PluginInfo>(plugin: Plugin<Value, Info>): Plugin<Value, Info>;
|
|
606
|
-
interface PluginAccessOptions {
|
|
599
|
+
export declare function createPlugin<Value, Info extends PluginInfo>(plugin: Plugin<Value, Info>): Plugin<Value, Info>;
|
|
600
|
+
export interface PluginAccessOptions {
|
|
607
601
|
plugins?: Plugin<any, any>[];
|
|
608
602
|
}
|
|
609
|
-
declare function resolvePlugins(plugins?: Plugin<any, any>[]): Plugin<any, any>[] | undefined;
|
|
603
|
+
export declare function resolvePlugins(plugins?: Plugin<any, any>[]): Plugin<any, any>[] | undefined;
|
|
604
|
+
/**
|
|
605
|
+
* Returns the plugins that are tested for plain objects. It is the same array
|
|
606
|
+
* when no plugin sets `skipPlainObjects`.
|
|
607
|
+
*/
|
|
608
|
+
export declare function getPlainObjectPlugins(plugins: Plugin<any, any>[] | undefined): Plugin<any, any>[] | undefined;
|
|
609
|
+
//#endregion
|
|
610
|
+
//#region src/core/context/parser.d.ts
|
|
611
|
+
interface BaseParserContextOptions extends PluginAccessOptions {
|
|
612
|
+
disabledFeatures?: number;
|
|
613
|
+
refs?: Map<unknown, number>;
|
|
614
|
+
depthLimit?: number;
|
|
615
|
+
/** Copy each typed array or DataView's visible bytes into its own buffer. */
|
|
616
|
+
compactArrayBufferViews?: boolean;
|
|
617
|
+
}
|
|
610
618
|
//#endregion
|
|
611
619
|
//#region src/core/context/async-parser.d.ts
|
|
612
620
|
type AsyncParserContextOptions = BaseParserContextOptions;
|
|
613
|
-
interface
|
|
614
|
-
base: BaseParserContext;
|
|
615
|
-
child: AsyncParsePluginContext | undefined;
|
|
616
|
-
}
|
|
617
|
-
declare class AsyncParsePluginContext {
|
|
618
|
-
private _p;
|
|
619
|
-
private depth;
|
|
620
|
-
constructor(_p: AsyncParserContext, depth: number);
|
|
621
|
+
interface AsyncParsePluginContext {
|
|
621
622
|
parse<T>(current: T): Promise<SerovalNode>;
|
|
623
|
+
parseStreamSource(current: AsyncIterable<unknown>): Promise<SerovalNode>;
|
|
622
624
|
}
|
|
623
625
|
//#endregion
|
|
624
626
|
//#region src/core/cross/index.d.ts
|
|
625
|
-
interface
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
627
|
+
export interface CrossAssignmentOptions {
|
|
628
|
+
/**
|
|
629
|
+
* Only assign `$R[n]` for values that the output reads more than once,
|
|
630
|
+
* such as shared references and cycles. The output is shorter, but later
|
|
631
|
+
* scripts cannot read the other values from `$R`. Only use it when no
|
|
632
|
+
* later output that shares the same references refers back to this one.
|
|
633
|
+
*/
|
|
634
|
+
assignSharedRefsOnly?: boolean;
|
|
635
|
+
}
|
|
636
|
+
export interface CrossSerializeOptions extends SyncParserContextOptions, CrossContextOptions, CrossAssignmentOptions {}
|
|
637
|
+
export declare function crossSerialize<T>(source: T, options?: CrossSerializeOptions): string;
|
|
638
|
+
export interface CrossSerializeAsyncOptions extends AsyncParserContextOptions, CrossContextOptions, CrossAssignmentOptions {}
|
|
639
|
+
export declare function crossSerializeAsync<T>(source: T, options?: CrossSerializeAsyncOptions): Promise<string>;
|
|
640
|
+
export type ToCrossJSONOptions = SyncParserContextOptions;
|
|
641
|
+
export declare function toCrossJSON<T>(source: T, options?: ToCrossJSONOptions): SerovalNode;
|
|
642
|
+
export type ToCrossJSONAsyncOptions = AsyncParserContextOptions;
|
|
643
|
+
export declare function toCrossJSONAsync<T>(source: T, options?: ToCrossJSONAsyncOptions): Promise<SerovalNode>;
|
|
644
|
+
export interface CrossSerializeStreamOptions extends Omit<StreamParserContextOptions, 'onParse'>, CrossContextOptions {
|
|
645
|
+
/**
|
|
646
|
+
* Receives each serialized record. Returning a promise defers the next
|
|
647
|
+
* record, and the acceptance of the live stream event behind this one,
|
|
648
|
+
* until the promise settles.
|
|
649
|
+
*/
|
|
650
|
+
onSerialize: (data: string, initial: boolean) => void | PromiseLike<void>;
|
|
651
|
+
}
|
|
652
|
+
export declare function crossSerializeStream<T>(source: T, options: CrossSerializeStreamOptions): (reason?: unknown) => void;
|
|
653
|
+
export type ToCrossJSONStreamOptions = StreamParserContextOptions;
|
|
654
|
+
export declare function toCrossJSONStream<T>(source: T, options: ToCrossJSONStreamOptions): (reason?: unknown) => void;
|
|
655
|
+
export type FromCrossJSONOptions = CrossDeserializerContextOptions;
|
|
656
|
+
export declare function fromCrossJSON<T>(source: SerovalNode, options: FromCrossJSONOptions): T;
|
|
657
|
+
export interface CrossDeserializer {
|
|
658
|
+
/** Deserializes one streamed record. Records share references. */
|
|
659
|
+
deserialize<T>(node: SerovalNode): T;
|
|
660
|
+
/** Deferred values (promises, streams) created but not yet settled. */
|
|
661
|
+
readonly pending: number;
|
|
662
|
+
/** Rejects pending promises and throws into open streams; idempotent. */
|
|
663
|
+
abort(reason: unknown): void;
|
|
664
|
+
}
|
|
665
|
+
export type CrossDeserializerOptions = FromCrossJSONOptions;
|
|
666
|
+
export declare function createCrossDeserializer(options: CrossDeserializerOptions): CrossDeserializer;
|
|
641
667
|
//#endregion
|
|
642
668
|
//#region src/core/errors.d.ts
|
|
643
|
-
declare class SerovalError extends Error {
|
|
669
|
+
export declare class SerovalError extends Error {
|
|
644
670
|
cause: unknown;
|
|
645
671
|
constructor(type: string, cause: unknown);
|
|
646
672
|
}
|
|
647
|
-
declare class SerovalParserError extends SerovalError {
|
|
673
|
+
export declare class SerovalParserError extends SerovalError {
|
|
648
674
|
constructor(cause: unknown);
|
|
649
675
|
}
|
|
650
|
-
declare class SerovalSerializationError extends SerovalError {
|
|
676
|
+
export declare class SerovalSerializationError extends SerovalError {
|
|
651
677
|
constructor(cause: unknown);
|
|
652
678
|
}
|
|
653
|
-
declare class SerovalDeserializationError extends SerovalError {
|
|
679
|
+
export declare class SerovalDeserializationError extends SerovalError {
|
|
654
680
|
constructor(cause: unknown);
|
|
655
681
|
}
|
|
656
|
-
declare class SerovalUnsupportedTypeError extends Error {
|
|
682
|
+
export declare class SerovalUnsupportedTypeError extends Error {
|
|
657
683
|
value: unknown;
|
|
658
684
|
constructor(value: unknown);
|
|
659
685
|
}
|
|
660
|
-
declare class SerovalUnsupportedNodeError extends Error {
|
|
686
|
+
export declare class SerovalUnsupportedNodeError extends Error {
|
|
661
687
|
constructor(node: SerovalNode);
|
|
662
688
|
}
|
|
663
|
-
declare class SerovalMissingPluginError extends Error {
|
|
689
|
+
export declare class SerovalMissingPluginError extends Error {
|
|
664
690
|
constructor(tag: string);
|
|
665
691
|
}
|
|
666
|
-
declare class SerovalMissingInstanceError extends Error {
|
|
692
|
+
export declare class SerovalMissingInstanceError extends Error {
|
|
667
693
|
constructor(tag: string);
|
|
668
694
|
}
|
|
669
|
-
|
|
695
|
+
/**
|
|
696
|
+
* @deprecated Not thrown by seroval. A missing `createReference` key throws
|
|
697
|
+
* {@link SerovalMissingReferenceForIdError} instead.
|
|
698
|
+
*/
|
|
699
|
+
export declare class SerovalMissingReferenceError extends Error {
|
|
670
700
|
value: unknown;
|
|
671
701
|
constructor(value: unknown);
|
|
672
702
|
}
|
|
673
|
-
declare class SerovalMissingReferenceForIdError extends Error {
|
|
703
|
+
export declare class SerovalMissingReferenceForIdError extends Error {
|
|
674
704
|
constructor(id: string);
|
|
675
705
|
}
|
|
676
|
-
declare class SerovalUnknownTypedArrayError extends Error {
|
|
706
|
+
export declare class SerovalUnknownTypedArrayError extends Error {
|
|
677
707
|
constructor(name: string);
|
|
678
708
|
}
|
|
679
|
-
declare class SerovalMalformedNodeError extends Error {
|
|
709
|
+
export declare class SerovalMalformedNodeError extends Error {
|
|
680
710
|
constructor(node: SerovalNode);
|
|
681
711
|
}
|
|
682
|
-
declare class SerovalConflictedNodeIdError extends Error {
|
|
712
|
+
export declare class SerovalConflictedNodeIdError extends Error {
|
|
683
713
|
constructor(node: SerovalNode);
|
|
684
714
|
}
|
|
685
|
-
declare class SerovalDepthLimitError extends Error {
|
|
715
|
+
export declare class SerovalDepthLimitError extends Error {
|
|
686
716
|
constructor(limit: number);
|
|
687
717
|
}
|
|
718
|
+
export declare class SerovalAbortedError extends Error {
|
|
719
|
+
constructor();
|
|
720
|
+
}
|
|
721
|
+
export type LiveStreamErrorReason = 'consumed' | 'pending' | 'reading' | 'closed';
|
|
722
|
+
export declare class SerovalLiveStreamError extends Error {
|
|
723
|
+
reason: LiveStreamErrorReason;
|
|
724
|
+
constructor(reason: LiveStreamErrorReason);
|
|
725
|
+
}
|
|
688
726
|
//#endregion
|
|
689
727
|
//#region src/core/keys.d.ts
|
|
690
|
-
declare function getCrossReferenceHeader(id?: string): string;
|
|
728
|
+
export declare function getCrossReferenceHeader(id?: string): string;
|
|
691
729
|
//#endregion
|
|
692
730
|
//#region src/core/opaque-reference.d.ts
|
|
693
731
|
/**
|
|
694
732
|
* An opaque reference allows hiding values from the serializer.
|
|
695
733
|
*/
|
|
696
|
-
declare class OpaqueReference<V, R = undefined> {
|
|
734
|
+
export declare class OpaqueReference<V, R = undefined> {
|
|
697
735
|
readonly value: V;
|
|
698
736
|
readonly replacement?: R | undefined;
|
|
699
737
|
constructor(value: V, replacement?: R | undefined);
|
|
700
738
|
}
|
|
701
739
|
//#endregion
|
|
702
740
|
//#region src/core/reference.d.ts
|
|
703
|
-
declare function createReference<T>(id: string, value: T): T;
|
|
741
|
+
export declare function createReference<T>(id: string, value: T): T;
|
|
704
742
|
//#endregion
|
|
705
743
|
//#region src/core/Serializer.d.ts
|
|
706
744
|
interface SerializerOptions extends PluginAccessOptions {
|
|
@@ -708,79 +746,75 @@ interface SerializerOptions extends PluginAccessOptions {
|
|
|
708
746
|
scopeId?: string;
|
|
709
747
|
disabledFeatures?: number;
|
|
710
748
|
compactArrayBufferViews?: boolean;
|
|
749
|
+
depthLimit?: number;
|
|
711
750
|
onData: (result: string) => void;
|
|
712
751
|
onError: (error: unknown) => void;
|
|
713
752
|
onDone?: () => void;
|
|
714
753
|
}
|
|
715
754
|
declare class Serializer {
|
|
716
|
-
private options;
|
|
717
755
|
private alive;
|
|
718
756
|
private flushed;
|
|
719
757
|
private done;
|
|
720
758
|
private pending;
|
|
721
759
|
private cleanups;
|
|
722
|
-
private refs;
|
|
760
|
+
private readonly refs;
|
|
723
761
|
private plugins?;
|
|
762
|
+
private options;
|
|
724
763
|
constructor(options: SerializerOptions);
|
|
725
764
|
keys: Set<string>;
|
|
726
765
|
write(key: string, value: unknown): void;
|
|
766
|
+
private finishWrite;
|
|
727
767
|
ids: number;
|
|
728
768
|
private getNextID;
|
|
729
769
|
push(value: unknown): string;
|
|
730
770
|
flush(): void;
|
|
731
771
|
close(): void;
|
|
772
|
+
private finish;
|
|
732
773
|
}
|
|
733
774
|
//#endregion
|
|
734
|
-
//#region src/core/
|
|
735
|
-
interface StreamListener<T> {
|
|
736
|
-
next(value: T): void;
|
|
737
|
-
throw(value: unknown): void;
|
|
738
|
-
return(value: T): void;
|
|
739
|
-
}
|
|
775
|
+
//#region src/core/sequence.d.ts
|
|
740
776
|
/**
|
|
741
777
|
* An internal class rather than a tagged POJO: identity is checked with
|
|
742
|
-
* `instanceof`, which untrusted input cannot forge
|
|
743
|
-
*
|
|
744
|
-
* The
|
|
745
|
-
*
|
|
746
|
-
*
|
|
747
|
-
*
|
|
748
|
-
* design, is not treated as a genuine Stream on re-serialization. Keep the two
|
|
749
|
-
* implementations in sync.
|
|
778
|
+
* `instanceof`, which untrusted input cannot forge. The class is exported
|
|
779
|
+
* because bundlers cannot drop an unexported top-level class.
|
|
780
|
+
* The eval-based `deserialize` path still rebuilds a `{__SEROVAL_SEQUENCE__…}`
|
|
781
|
+
* POJO from embedded source - it has no access to this class - so a value read
|
|
782
|
+
* back through `deserialize` is not an instance and, by design, is not treated
|
|
783
|
+
* as a genuine Sequence on re-serialization.
|
|
750
784
|
*/
|
|
751
|
-
declare class
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
private count;
|
|
757
|
-
private flush;
|
|
758
|
-
private replay;
|
|
759
|
-
on(listener: StreamListener<T>): () => void;
|
|
760
|
-
next(value: T): void;
|
|
761
|
-
throw(value: unknown): void;
|
|
762
|
-
return(value: T): void;
|
|
785
|
+
export declare class Sequence {
|
|
786
|
+
v: unknown[];
|
|
787
|
+
t: number;
|
|
788
|
+
d: number;
|
|
789
|
+
constructor(values: unknown[], throwAt: number, doneAt: number);
|
|
763
790
|
}
|
|
764
|
-
declare function isStream<T>(value: unknown): value is Stream<T>;
|
|
765
|
-
declare function createStream<T>(): Stream<T>;
|
|
766
791
|
//#endregion
|
|
767
792
|
//#region src/core/tree/index.d.ts
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
793
|
+
/**
|
|
794
|
+
* Options for `serialize`. The same as the parser options, without `refs`:
|
|
795
|
+
* the output is self-contained, so there is nothing to share between calls.
|
|
796
|
+
*/
|
|
797
|
+
export type SerializeOptions = Omit<BaseParserContextOptions, 'refs'>;
|
|
798
|
+
/** Options for `serializeAsync`. */
|
|
799
|
+
export type SerializeAsyncOptions = Omit<BaseParserContextOptions, 'refs'>;
|
|
800
|
+
/** Options for `toJSON`. */
|
|
801
|
+
export type ToJSONOptions = SerializeOptions;
|
|
802
|
+
/** Options for `toJSONAsync`. */
|
|
803
|
+
export type ToJSONAsyncOptions = SerializeAsyncOptions;
|
|
804
|
+
export declare function serialize<T>(source: T, options?: SerializeOptions): string;
|
|
805
|
+
export declare function serializeAsync<T>(source: T, options?: SerializeAsyncOptions): Promise<string>;
|
|
806
|
+
export declare function deserialize<T>(source: string): T;
|
|
807
|
+
export interface SerovalJSON {
|
|
774
808
|
t: SerovalNode;
|
|
775
809
|
f: number;
|
|
776
810
|
m: number[];
|
|
777
811
|
}
|
|
778
|
-
interface FromJSONOptions extends PluginAccessOptions, Pick<BaseDeserializerContextOptions, 'maxBase64Length'> {
|
|
812
|
+
export interface FromJSONOptions extends PluginAccessOptions, Pick<BaseDeserializerContextOptions, 'depthLimit' | 'maxBase64Length'> {
|
|
779
813
|
disabledFeatures?: number;
|
|
780
814
|
}
|
|
781
|
-
declare function toJSON<T>(source: T, options?:
|
|
782
|
-
declare function toJSONAsync<T>(source: T, options?:
|
|
783
|
-
declare function compileJSON(source: SerovalJSON, options?: PluginAccessOptions): string;
|
|
784
|
-
declare function fromJSON<T>(source: SerovalJSON, options?: FromJSONOptions): T;
|
|
815
|
+
export declare function toJSON<T>(source: T, options?: ToJSONOptions): SerovalJSON;
|
|
816
|
+
export declare function toJSONAsync<T>(source: T, options?: ToJSONAsyncOptions): Promise<SerovalJSON>;
|
|
817
|
+
export declare function compileJSON(source: SerovalJSON, options?: PluginAccessOptions): string;
|
|
818
|
+
export declare function fromJSON<T>(source: SerovalJSON, options?: FromJSONOptions): T;
|
|
785
819
|
//#endregion
|
|
786
|
-
export { type AsyncParsePluginContext, AsyncParserContextOptions, type BaseDeserializerContextOptions, type BaseParserContextOptions, type BaseSerializerContextOptions, type CrossContextOptions, type CrossDeserializerContextOptions,
|
|
820
|
+
export { type AsyncParsePluginContext, type AsyncParserContextOptions, type BaseDeserializerContextOptions, type BaseParserContextOptions, type BaseSerializerContextOptions, type CrossContextOptions, type CrossDeserializerContextOptions, type CrossSerializerContextOptions, type DeserializePluginContext, type LiveStreamConsumer, type LiveStreamDelivery, type LiveStreamEvent, type LiveStreamOptions, type LiveStreamProducer, type SerializePluginContext, Serializer, type SerovalNode, type StreamListener, type StreamParsePluginContext, type StreamParserContextOptions, type SyncParsePluginContext, type SyncParserContextOptions, type VanillaDeserializerContextOptions, type VanillaSerializerContextOptions };
|