749 lines
No EOL
24 KiB
TypeScript
749 lines
No EOL
24 KiB
TypeScript
import { t as Validator$1 } from "./validator-CxDhXc0k.cjs";
|
|
import * as v from "./validator.cjs";
|
|
import { Validator } from "./validator.cjs";
|
|
//#region src/core/constants.d.ts
|
|
declare const enum SerovalConstant {
|
|
Null = 0,
|
|
Undefined = 1,
|
|
True = 2,
|
|
False = 3,
|
|
NegZero = 4,
|
|
Inf = 5,
|
|
NegInf = 6,
|
|
Nan = 7
|
|
}
|
|
declare const enum SerovalNodeType {
|
|
Number = 0,
|
|
String = 1,
|
|
Constant = 2,
|
|
BigInt = 3,
|
|
IndexedValue = 4,
|
|
Date = 5,
|
|
RegExp = 6,
|
|
Set = 7,
|
|
Map = 8,
|
|
Array = 9,
|
|
Object = 10,
|
|
NullConstructor = 11,
|
|
Promise = 12,
|
|
Error = 13,
|
|
AggregateError = 14,
|
|
TypedArray = 15,
|
|
BigIntTypedArray = 16,
|
|
WKSymbol = 17,
|
|
Reference = 18,
|
|
ArrayBuffer = 19,
|
|
DataView = 20,
|
|
Boxed = 21,
|
|
PromiseConstructor = 22,
|
|
PromiseSuccess = 23,
|
|
PromiseFailure = 24,
|
|
Plugin = 25,
|
|
SpecialReference = 26,
|
|
IteratorFactory = 27,
|
|
IteratorFactoryInstance = 28,
|
|
AsyncIteratorFactory = 29,
|
|
AsyncIteratorFactoryInstance = 30,
|
|
StreamConstructor = 31,
|
|
StreamNext = 32,
|
|
StreamThrow = 33,
|
|
StreamReturn = 34,
|
|
Sequence = 35,
|
|
Temporal = 36
|
|
}
|
|
declare const enum SerovalTemporalType {
|
|
Instant = 0,
|
|
Duration = 1,
|
|
PlainDate = 2,
|
|
PlainDateTime = 3,
|
|
PlainMonthDay = 4,
|
|
PlainTime = 5,
|
|
PlainYearMonth = 6,
|
|
ZonedDateTime = 7
|
|
}
|
|
declare const enum SerovalObjectFlags {
|
|
None = 0,
|
|
NonExtensible = 1,
|
|
Sealed = 2,
|
|
Frozen = 3
|
|
}
|
|
declare const enum Symbols {
|
|
AsyncIterator = 0,
|
|
HasInstance = 1,
|
|
IsConcatSpreadable = 2,
|
|
Iterator = 3,
|
|
Match = 4,
|
|
MatchAll = 5,
|
|
Replace = 6,
|
|
Search = 7,
|
|
Species = 8,
|
|
Split = 9,
|
|
ToPrimitive = 10,
|
|
ToStringTag = 11,
|
|
Unscopables = 12
|
|
}
|
|
declare const enum ErrorConstructorTag {
|
|
Error = 0,
|
|
EvalError = 1,
|
|
RangeError = 2,
|
|
ReferenceError = 3,
|
|
SyntaxError = 4,
|
|
TypeError = 5,
|
|
URIError = 6
|
|
}
|
|
//#endregion
|
|
//#region src/core/special-reference.d.ts
|
|
declare const enum SpecialReference {
|
|
MapSentinel = 0,
|
|
PromiseConstructor = 1,
|
|
PromiseSuccess = 2,
|
|
PromiseFailure = 3,
|
|
StreamConstructor = 4,
|
|
ArrayBufferConstructor = 5
|
|
}
|
|
//#endregion
|
|
//#region src/core/types.d.ts
|
|
interface SerovalBaseNode {
|
|
t: SerovalNodeType;
|
|
i: number | undefined;
|
|
s: unknown;
|
|
c: string | SerovalTemporalType | undefined;
|
|
m: string | undefined;
|
|
p: SerovalObjectRecordNode | undefined;
|
|
e: SerovalMapRecordNode | undefined;
|
|
a: (SerovalNode | 0)[] | undefined;
|
|
f: SerovalNode | undefined;
|
|
b: number | undefined;
|
|
o: SerovalObjectFlags | undefined;
|
|
l: number | undefined;
|
|
}
|
|
type SerovalObjectRecordKey = string | SerovalNode;
|
|
interface SerovalObjectRecordNode {
|
|
k: SerovalObjectRecordKey[];
|
|
v: SerovalNode[];
|
|
}
|
|
interface SerovalMapRecordNode {
|
|
k: SerovalNode[];
|
|
v: SerovalNode[];
|
|
}
|
|
interface SerovalNumberNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.Number;
|
|
s: number;
|
|
}
|
|
interface SerovalStringNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.String;
|
|
s: string;
|
|
}
|
|
interface SerovalConstantNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.Constant;
|
|
s: SerovalConstant;
|
|
}
|
|
type SerovalPrimitiveNode = SerovalNumberNode | SerovalStringNode | SerovalConstantNode;
|
|
interface SerovalIndexedValueNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.IndexedValue;
|
|
i: number;
|
|
}
|
|
interface SerovalBigIntNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.BigInt;
|
|
s: string;
|
|
}
|
|
interface SerovalDateNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.Date;
|
|
i: number;
|
|
s: string;
|
|
}
|
|
interface SerovalRegExpNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.RegExp;
|
|
i: number;
|
|
c: string;
|
|
m: string;
|
|
}
|
|
interface SerovalArrayBufferNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.ArrayBuffer;
|
|
i: number;
|
|
s: string;
|
|
f: SerovalNodeWithID;
|
|
}
|
|
interface SerovalTypedArrayNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.TypedArray;
|
|
i: number;
|
|
c: string;
|
|
f: SerovalNode;
|
|
b: number;
|
|
l: number;
|
|
}
|
|
interface SerovalBigIntTypedArrayNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.BigIntTypedArray;
|
|
i: number;
|
|
c: string;
|
|
f: SerovalNode;
|
|
b: number;
|
|
l: number;
|
|
}
|
|
interface SerovalTemporalNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.Temporal;
|
|
i: number;
|
|
c: SerovalTemporalType;
|
|
s: string;
|
|
}
|
|
type SerovalSemiPrimitiveNode = SerovalBigIntNode | SerovalDateNode | SerovalRegExpNode | SerovalTypedArrayNode | SerovalBigIntTypedArrayNode | SerovalTemporalNode;
|
|
interface SerovalSetNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.Set;
|
|
i: number;
|
|
a: SerovalNode[];
|
|
}
|
|
interface SerovalMapNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.Map;
|
|
i: number;
|
|
e: SerovalMapRecordNode;
|
|
f: SerovalNodeWithID;
|
|
}
|
|
interface SerovalArrayNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.Array;
|
|
a: (SerovalNode | 0)[];
|
|
i: number;
|
|
o: SerovalObjectFlags;
|
|
}
|
|
interface SerovalObjectNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.Object;
|
|
p: SerovalObjectRecordNode;
|
|
i: number;
|
|
o: SerovalObjectFlags;
|
|
}
|
|
interface SerovalNullConstructorNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.NullConstructor;
|
|
p: SerovalObjectRecordNode;
|
|
i: number;
|
|
o: SerovalObjectFlags;
|
|
}
|
|
interface SerovalPromiseNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.Promise;
|
|
s: 0 | 1;
|
|
f: SerovalNode;
|
|
i: number;
|
|
}
|
|
interface SerovalErrorNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.Error;
|
|
s: ErrorConstructorTag;
|
|
m: string;
|
|
p: SerovalObjectRecordNode | undefined;
|
|
i: number;
|
|
}
|
|
interface SerovalAggregateErrorNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.AggregateError;
|
|
i: number;
|
|
m: string;
|
|
p: SerovalObjectRecordNode | undefined;
|
|
}
|
|
interface SerovalWKSymbolNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.WKSymbol;
|
|
i: number;
|
|
s: Symbols;
|
|
}
|
|
interface SerovalReferenceNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.Reference;
|
|
i: number;
|
|
s: string;
|
|
}
|
|
interface SerovalDataViewNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.DataView;
|
|
i: number;
|
|
f: SerovalNode;
|
|
b: number;
|
|
l: number;
|
|
}
|
|
interface SerovalBoxedNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.Boxed;
|
|
i: number;
|
|
f: SerovalNode;
|
|
}
|
|
interface SerovalPromiseConstructorNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.PromiseConstructor;
|
|
i: number;
|
|
s: number;
|
|
f: SerovalNodeWithID;
|
|
}
|
|
interface SerovalPromiseResolveNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.PromiseSuccess;
|
|
i: number;
|
|
a: [resolver: SerovalNodeWithID, resolved: SerovalNode];
|
|
}
|
|
interface SerovalPromiseRejectNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.PromiseFailure;
|
|
i: number;
|
|
a: [resolver: SerovalNodeWithID, resolved: SerovalNode];
|
|
}
|
|
interface SerovalPluginNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.Plugin;
|
|
i: number;
|
|
s: Record<string, SerovalNode>;
|
|
c: string;
|
|
}
|
|
/**
|
|
* Represents special values as placeholders
|
|
*/
|
|
interface SerovalSpecialReferenceNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.SpecialReference;
|
|
i: number;
|
|
s: SpecialReference;
|
|
}
|
|
interface SerovalIteratorFactoryNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.IteratorFactory;
|
|
i: number;
|
|
f: SerovalNodeWithID;
|
|
}
|
|
interface SerovalIteratorFactoryInstanceNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.IteratorFactoryInstance;
|
|
a: [instance: SerovalNodeWithID, sequence: SerovalNodeWithID];
|
|
}
|
|
interface SerovalAsyncIteratorFactoryNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.AsyncIteratorFactory;
|
|
i: number;
|
|
a: [promise: SerovalNodeWithID, symbol: SerovalNodeWithID];
|
|
}
|
|
interface SerovalAsyncIteratorFactoryInstanceNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.AsyncIteratorFactoryInstance;
|
|
a: [instance: SerovalNodeWithID, sequence: SerovalNodeWithID];
|
|
}
|
|
interface SerovalStreamConstructorNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.StreamConstructor;
|
|
i: number;
|
|
a: SerovalNode[];
|
|
f: SerovalNodeWithID;
|
|
l: 1 | undefined;
|
|
}
|
|
interface SerovalStreamNextNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.StreamNext;
|
|
i: number;
|
|
f: SerovalNode;
|
|
}
|
|
interface SerovalStreamThrowNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.StreamThrow;
|
|
i: number;
|
|
f: SerovalNode;
|
|
}
|
|
interface SerovalStreamReturnNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.StreamReturn;
|
|
i: number;
|
|
f: SerovalNode;
|
|
}
|
|
interface SerovalSequenceNode extends SerovalBaseNode {
|
|
t: SerovalNodeType.Sequence;
|
|
i: number;
|
|
s: number;
|
|
a: SerovalNode[];
|
|
l: number;
|
|
}
|
|
type SerovalSyncNode = SerovalPrimitiveNode | SerovalIndexedValueNode | SerovalSemiPrimitiveNode | SerovalSetNode | SerovalMapNode | SerovalArrayNode | SerovalObjectNode | SerovalNullConstructorNode | SerovalPromiseNode | SerovalErrorNode | SerovalAggregateErrorNode | SerovalWKSymbolNode | SerovalReferenceNode | SerovalArrayBufferNode | SerovalDataViewNode | SerovalBoxedNode | SerovalPluginNode | SerovalSpecialReferenceNode | SerovalIteratorFactoryNode | SerovalIteratorFactoryInstanceNode | SerovalAsyncIteratorFactoryNode | SerovalAsyncIteratorFactoryInstanceNode | SerovalSequenceNode;
|
|
type SerovalAsyncNode = SerovalPromiseNode | SerovalPromiseConstructorNode | SerovalPromiseResolveNode | SerovalPromiseRejectNode | SerovalStreamConstructorNode | SerovalStreamNextNode | SerovalStreamThrowNode | SerovalStreamReturnNode;
|
|
type SerovalNode = SerovalSyncNode | SerovalAsyncNode;
|
|
type SerovalNodeWithID = Extract<SerovalNode, {
|
|
i: number;
|
|
}>;
|
|
//#endregion
|
|
//#region src/core/context/parser.d.ts
|
|
interface BaseParserContextOptions extends PluginAccessOptions {
|
|
disabledFeatures?: number;
|
|
refs?: Map<unknown, number>;
|
|
depthLimit?: number;
|
|
/** Copy each typed array or DataView's visible bytes into its own buffer. */
|
|
compactArrayBufferViews?: boolean;
|
|
}
|
|
//#endregion
|
|
//#region src/core/context/async-parser.d.ts
|
|
type AsyncParserContextOptions = BaseParserContextOptions;
|
|
interface AsyncParsePluginContext {
|
|
parse<T>(current: T): Promise<SerovalNode>;
|
|
parseStreamSource(current: AsyncIterable<unknown>): Promise<SerovalNode>;
|
|
}
|
|
//#endregion
|
|
//#region src/core/context/serializer.d.ts
|
|
interface BaseSerializerContextOptions extends PluginAccessOptions {
|
|
features: number;
|
|
markedRefs: number[] | Set<number>;
|
|
assignSharedRefsOnly?: boolean;
|
|
}
|
|
interface CrossContextOptions {
|
|
scopeId?: string;
|
|
}
|
|
type VanillaSerializerContextOptions = BaseSerializerContextOptions;
|
|
interface CrossSerializerContextOptions extends BaseSerializerContextOptions, CrossContextOptions {}
|
|
interface SerializePluginContext {
|
|
serialize(node: SerovalNode): string;
|
|
}
|
|
//#endregion
|
|
//#region src/core/stream.d.ts
|
|
interface StreamListener<T> {
|
|
next(value: T): void;
|
|
throw(value: unknown): void;
|
|
return(value: T): void;
|
|
}
|
|
/**
|
|
* An internal class rather than a tagged POJO: identity is checked with
|
|
* `instanceof`, which untrusted input cannot forge. The class is exported
|
|
* because bundlers cannot drop an unexported top-level class.
|
|
*
|
|
* The behavior is intentionally duplicated from `STREAM_CONSTRUCTOR`. That
|
|
* constructor's source is embedded verbatim into the eval-based `deserialize`
|
|
* output, which has no access to this class, so the two cannot be shared. A
|
|
* stream read back through `deserialize` is therefore a plain POJO and, by
|
|
* design, is not treated as a genuine Stream on re-serialization. Keep the two
|
|
* implementations in sync.
|
|
*/
|
|
declare class Stream<T> {
|
|
private buffer;
|
|
private listeners;
|
|
private alive;
|
|
private success;
|
|
private count;
|
|
private live;
|
|
constructor(live?: number);
|
|
private flush;
|
|
private replay;
|
|
on(listener: StreamListener<T>): () => void;
|
|
/**
|
|
* Returns the events of a stream that has ended, without subscribing, so a
|
|
* live receiver is not consumed. The last value is the `return` or `throw`
|
|
* value. Returns `undefined` while the stream is open, or when a live
|
|
* receiver was already consumed and has no events left.
|
|
* @internal
|
|
*/
|
|
endedEvents(): {
|
|
values: unknown[];
|
|
success: boolean;
|
|
} | undefined;
|
|
next(value: T): void;
|
|
throw(value: unknown): void;
|
|
return(value: T): void;
|
|
}
|
|
declare function isStream<T>(value: unknown): value is Stream<T> | LiveStream<T>;
|
|
declare function createStream<T>(): Stream<T>;
|
|
//#endregion
|
|
//#region src/core/live-stream.d.ts
|
|
type LiveStreamEvent<T> = {
|
|
type: 'next';
|
|
value: T;
|
|
} | {
|
|
type: 'return';
|
|
value: T;
|
|
} | {
|
|
type: 'throw';
|
|
error: unknown;
|
|
};
|
|
interface LiveStreamDelivery<T> {
|
|
event: LiveStreamEvent<T>;
|
|
/**
|
|
* Release the event and resolve the producer operation that sent it.
|
|
* Call it only after the serialized record for the event has been
|
|
* accepted by its destination. Late or repeated calls are ignored.
|
|
*/
|
|
accept(): void;
|
|
}
|
|
interface LiveStreamConsumer<T> {
|
|
read(): Promise<LiveStreamDelivery<T>>;
|
|
cancel(reason?: unknown): void;
|
|
}
|
|
interface LiveStreamProducer<T> {
|
|
write(value: T): Promise<void>;
|
|
close(value: T): Promise<void>;
|
|
fail(error: unknown): Promise<void>;
|
|
}
|
|
/**
|
|
* Receives events from `LiveStream.pump`. Each handler gets the event value
|
|
* and the accept function for it, and returns `undefined` to keep going or
|
|
* the error that stopped the sink. `error` runs if the stream is cancelled
|
|
* while a read is pending.
|
|
*/
|
|
interface LiveStreamSink<T> {
|
|
next(value: T, accept: () => void): unknown;
|
|
throw(value: unknown, accept: () => void): unknown;
|
|
return(value: T, accept: () => void): unknown;
|
|
/** Runs once after the terminal event, or after a handler failed. */
|
|
done?(): void;
|
|
/** Runs if the stream is cancelled while a read is pending. */
|
|
error?(reason: unknown): void;
|
|
}
|
|
interface LiveStreamOptions {
|
|
onCancel?: (reason: unknown) => void;
|
|
}
|
|
declare const BRAND: unique symbol;
|
|
declare function isLiveStream<T>(value: unknown): value is LiveStream<T>;
|
|
/**
|
|
* A single-consumer stream for incremental serialization. Unlike
|
|
* `createStream`, it keeps no history: at most one event is held, and the
|
|
* producer operation that sent it settles only when the consumer accepts it.
|
|
*
|
|
* An internal class rather than a tagged POJO: identity is checked with
|
|
* `isLiveStream`, which untrusted input cannot forge. The class is exported
|
|
* because bundlers cannot drop an unexported top-level class.
|
|
*/
|
|
declare class LiveStream<T> {
|
|
private readonly [BRAND];
|
|
private pending;
|
|
private waiting;
|
|
private consumed;
|
|
private closed;
|
|
private cancelled;
|
|
private cancelReason;
|
|
private options;
|
|
constructor(options?: LiveStreamOptions);
|
|
private deliver;
|
|
/** @internal */
|
|
push(event: LiveStreamEvent<T>): Promise<void>;
|
|
private cancel;
|
|
private read;
|
|
consume(): LiveStreamConsumer<T>;
|
|
/**
|
|
* Consumes the stream through a replay-style listener, accepting each
|
|
* event as soon as it has been delivered. Use `consume` or `pump` when
|
|
* acceptance must wait for processing.
|
|
*/
|
|
on(listener: StreamListener<T>): () => void;
|
|
/**
|
|
* Consumes the stream into a sink that controls acceptance. Returns the
|
|
* cancel function.
|
|
* @internal
|
|
*/
|
|
pump(sink: LiveStreamSink<T>): (reason?: unknown) => void;
|
|
}
|
|
/**
|
|
* Creates a live stream and the producer that writes to it.
|
|
*/
|
|
declare function createLiveStream<T>(options?: LiveStreamOptions): {
|
|
stream: LiveStream<T>;
|
|
producer: LiveStreamProducer<T>;
|
|
};
|
|
//#endregion
|
|
//#region src/core/context/sync-parser.d.ts
|
|
type SyncParserContextOptions = BaseParserContextOptions;
|
|
interface SyncParsePluginContext {
|
|
parse<T>(current: T): SerovalNode;
|
|
}
|
|
interface StreamParserContextOptions extends SyncParserContextOptions {
|
|
/**
|
|
* Receives each parsed record. Returning a promise defers the next record,
|
|
* and the acceptance of the source event that produced it, until the
|
|
* promise settles.
|
|
*/
|
|
onParse: (node: SerovalNode, initial: boolean) => void | PromiseLike<void>;
|
|
onError?: (error: unknown) => void;
|
|
onDone?: () => void;
|
|
}
|
|
//#endregion
|
|
//#region src/core/context/stream-parser.d.ts
|
|
interface StreamParsePluginContext {
|
|
parse<T>(current: T): SerovalNode;
|
|
parseStreamSource(current: AsyncIterable<unknown>): SerovalNode;
|
|
parseWithError<T>(current: T): SerovalNode | undefined;
|
|
isAlive(): boolean;
|
|
pushPendingState(): void;
|
|
popPendingState(): void;
|
|
onParse(node: SerovalNode): void;
|
|
onError(error: unknown): void;
|
|
addCleanup(callback: () => void): void;
|
|
}
|
|
//#endregion
|
|
//#region src/core/plugin.d.ts
|
|
declare const enum SerovalMode {
|
|
Vanilla = 1,
|
|
Cross = 2
|
|
}
|
|
interface PluginData {
|
|
id: number;
|
|
}
|
|
type PluginInfo = {
|
|
[key: string]: SerovalNode;
|
|
};
|
|
interface Plugin<Value, Info extends PluginInfo> {
|
|
/**
|
|
* A unique string that helps idenfity the plugin
|
|
*/
|
|
tag: string;
|
|
/**
|
|
* List of dependency plugins
|
|
*/
|
|
extends?: Plugin<any, any>[];
|
|
/**
|
|
* Method to test if a value is an expected value of the plugin
|
|
* @param value
|
|
*/
|
|
test(value: unknown): boolean;
|
|
/**
|
|
* Set to `true` if `test` never returns `true` for a plain object, whose
|
|
* prototype is `Object.prototype`, such as an object literal. The parsers
|
|
* then skip this plugin for those objects. Leave it unset if unsure. A
|
|
* plugin that sets it is never applied to such objects.
|
|
*/
|
|
skipPlainObjects?: boolean;
|
|
/**
|
|
* Parsing modes
|
|
*/
|
|
parse: {
|
|
sync?: (value: Value, ctx: SyncParsePluginContext, data: PluginData) => Info;
|
|
async?: (value: Value, ctx: AsyncParsePluginContext, data: PluginData) => Promise<Info>;
|
|
stream?: (value: Value, ctx: StreamParsePluginContext, data: PluginData) => Info;
|
|
};
|
|
/**
|
|
* Convert the parsed node into a JS string
|
|
*/
|
|
serialize(node: Info, ctx: SerializePluginContext, data: PluginData): string;
|
|
/**
|
|
* Validators for the fields of a node, by field name. The fields come from
|
|
* input that may be untrusted. When `deserialize` reads a listed field with
|
|
* `ctx.deserialize`, the decoded value is checked before it is returned, and
|
|
* `SerovalPluginValidationError` is thrown if the check fails. Fields that
|
|
* are not listed, or that `deserialize` never reads, are not checked.
|
|
*
|
|
* It applies to `fromJSON`, `fromCrossJSON` and `createCrossDeserializer`.
|
|
* Build the validators from the `v` helpers, for example
|
|
* `{ type: v.string }`.
|
|
*/
|
|
validate?: { [K in keyof Info]?: Validator$1<unknown>; };
|
|
/**
|
|
* Convert the parsed node into its runtime equivalent.
|
|
*/
|
|
deserialize(node: Info, ctx: DeserializePluginContext, data: PluginData): Value;
|
|
}
|
|
declare function createPlugin<Value, Info extends PluginInfo>(plugin: Plugin<Value, Info>): Plugin<Value, Info>;
|
|
interface PluginAccessOptions {
|
|
plugins?: Plugin<any, any>[];
|
|
}
|
|
declare function resolvePlugins(plugins?: Plugin<any, any>[]): Plugin<any, any>[] | undefined;
|
|
/**
|
|
* Returns the plugins that are tested for plain objects. It is the same array
|
|
* when no plugin sets `skipPlainObjects`.
|
|
*/
|
|
declare function getPlainObjectPlugins(plugins: Plugin<any, any>[] | undefined): Plugin<any, any>[] | undefined;
|
|
//#endregion
|
|
//#region src/core/context/deserializer.d.ts
|
|
interface BaseDeserializerContextOptions extends PluginAccessOptions {
|
|
refs?: Map<number, unknown>;
|
|
features?: number;
|
|
disabledFeatures?: number;
|
|
depthLimit?: number;
|
|
/** Maximum encoded characters per ArrayBuffer. Defaults to 1,000,000. */
|
|
maxBase64Length?: number;
|
|
}
|
|
interface VanillaDeserializerContextOptions extends Omit<BaseDeserializerContextOptions, 'refs'> {
|
|
markedRefs: number[] | Set<number>;
|
|
}
|
|
type CrossDeserializerContextOptions = BaseDeserializerContextOptions;
|
|
interface DeserializePluginContext {
|
|
deserialize<T>(node: SerovalNode): T;
|
|
}
|
|
//#endregion
|
|
//#region src/core/compat.d.ts
|
|
/**
|
|
* Public feature bits for `disabledFeatures`. Stays a runtime `enum` so the
|
|
* published declaration is unchanged for consumers. Its values must match
|
|
* the internal bits (checked by test/feature.test.ts).
|
|
*/
|
|
declare enum Feature {
|
|
AggregateError = 1,
|
|
/**
|
|
* @deprecated Has no effect. Output follows the syntax of the build seroval
|
|
* runs in: arrow functions, or `function` expressions in an ES5 build.
|
|
*/
|
|
ArrowFunction = 2,
|
|
ErrorPrototypeStack = 4,
|
|
ObjectAssign = 8,
|
|
BigIntTypedArray = 16,
|
|
RegExp = 32,
|
|
Temporal = 64
|
|
}
|
|
//#endregion
|
|
//#region src/core/errors.d.ts
|
|
declare class SerovalError extends Error {
|
|
cause: unknown;
|
|
constructor(type: string, cause: unknown);
|
|
}
|
|
declare class SerovalParserError extends SerovalError {
|
|
constructor(cause: unknown);
|
|
}
|
|
declare class SerovalSerializationError extends SerovalError {
|
|
constructor(cause: unknown);
|
|
}
|
|
declare class SerovalDeserializationError extends SerovalError {
|
|
constructor(cause: unknown);
|
|
}
|
|
declare class SerovalUnsupportedTypeError extends Error {
|
|
value: unknown;
|
|
constructor(value: unknown);
|
|
}
|
|
declare class SerovalUnsupportedNodeError extends Error {
|
|
constructor(node: SerovalNode);
|
|
}
|
|
declare class SerovalMissingPluginError extends Error {
|
|
constructor(tag: string);
|
|
}
|
|
declare class SerovalPluginValidationError extends Error {
|
|
tag: string;
|
|
field: string;
|
|
constructor(tag: string, field: string);
|
|
}
|
|
declare class SerovalMissingInstanceError extends Error {
|
|
constructor(tag: string);
|
|
}
|
|
/**
|
|
* @deprecated Not thrown by seroval. A missing `createReference` key throws
|
|
* {@link SerovalMissingReferenceForIdError} instead.
|
|
*/
|
|
declare class SerovalMissingReferenceError extends Error {
|
|
value: unknown;
|
|
constructor(value: unknown);
|
|
}
|
|
declare class SerovalMissingReferenceForIdError extends Error {
|
|
constructor(id: string);
|
|
}
|
|
declare class SerovalUnknownTypedArrayError extends Error {
|
|
constructor(name: string);
|
|
}
|
|
declare class SerovalMalformedNodeError extends Error {
|
|
constructor(node: SerovalNode);
|
|
}
|
|
declare class SerovalConflictedNodeIdError extends Error {
|
|
constructor(node: SerovalNode);
|
|
}
|
|
declare class SerovalDepthLimitError extends Error {
|
|
constructor(limit: number);
|
|
}
|
|
declare class SerovalAbortedError extends Error {
|
|
constructor();
|
|
}
|
|
type LiveStreamErrorReason = 'consumed' | 'pending' | 'reading' | 'closed';
|
|
declare class SerovalLiveStreamError extends Error {
|
|
reason: LiveStreamErrorReason;
|
|
constructor(reason: LiveStreamErrorReason);
|
|
}
|
|
//#endregion
|
|
//#region src/core/opaque-reference.d.ts
|
|
/**
|
|
* An opaque reference allows hiding values from the serializer.
|
|
*/
|
|
declare class OpaqueReference<V, R = undefined> {
|
|
readonly value: V;
|
|
readonly replacement?: R | undefined;
|
|
constructor(value: V, replacement?: R | undefined);
|
|
}
|
|
//#endregion
|
|
//#region src/core/reference.d.ts
|
|
declare function createReference<T>(id: string, value: T): T;
|
|
//#endregion
|
|
//#region src/core/sequence.d.ts
|
|
/**
|
|
* An internal class rather than a tagged POJO: identity is checked with
|
|
* `instanceof`, which untrusted input cannot forge. The class is exported
|
|
* because bundlers cannot drop an unexported top-level class.
|
|
* The eval-based `deserialize` path still rebuilds a `{__SEROVAL_SEQUENCE__…}`
|
|
* POJO from embedded source - it has no access to this class - so a value read
|
|
* back through `deserialize` is not an instance and, by design, is not treated
|
|
* as a genuine Sequence on re-serialization.
|
|
*/
|
|
declare class Sequence {
|
|
v: unknown[];
|
|
t: number;
|
|
d: number;
|
|
constructor(values: unknown[], throwAt: number, doneAt: number);
|
|
}
|
|
//#endregion
|
|
export { BaseSerializerContextOptions as $, PluginAccessOptions as A, SyncParserContextOptions as B, SerovalUnsupportedTypeError as C, DeserializePluginContext as D, CrossDeserializerContextOptions as E, getPlainObjectPlugins as F, LiveStreamOptions as G, LiveStreamConsumer as H, resolvePlugins as I, isLiveStream as J, LiveStreamProducer as K, StreamParsePluginContext as L, PluginInfo as M, SerovalMode as N, VanillaDeserializerContextOptions as O, createPlugin as P, isStream as Q, StreamParserContextOptions as R, SerovalUnsupportedNodeError as S, BaseDeserializerContextOptions as T, LiveStreamDelivery as U, LiveStream as V, LiveStreamEvent as W, StreamListener as X, Stream as Y, createStream as Z, SerovalMissingReferenceForIdError as _, OpaqueReference as a, AsyncParserContextOptions as at, SerovalSerializationError as b, SerovalConflictedNodeIdError as c, SerovalError as d, CrossContextOptions as et, SerovalLiveStreamError as f, SerovalMissingReferenceError as g, SerovalMissingPluginError as h, createReference as i, AsyncParsePluginContext as it, PluginData as j, Plugin as k, SerovalDepthLimitError as l, SerovalMissingInstanceError as m, v as n, SerializePluginContext as nt, LiveStreamErrorReason as o, BaseParserContextOptions as ot, SerovalMalformedNodeError as p, createLiveStream as q, Sequence as r, VanillaSerializerContextOptions as rt, SerovalAbortedError as s, SerovalNode as st, Validator as t, CrossSerializerContextOptions as tt, SerovalDeserializationError as u, SerovalParserError as v, Feature as w, SerovalUnknownTypedArrayError as x, SerovalPluginValidationError as y, SyncParsePluginContext as z }; |