UNPKG

seroval

Version:
831 lines • 27.7 kB
//#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). */ export declare enum Feature { AggregateError = 1, /** * @deprecated Has no effect. Output always uses arrow functions. */ ArrowFunction = 2, ErrorPrototypeStack = 4, ObjectAssign = 8, BigIntTypedArray = 16, RegExp = 32, Temporal = 64 } //#endregion //#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/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/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. */ export 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; } export declare function isStream<T>(value: unknown): value is Stream<T> | LiveStream<T>; export 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; } export 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 * `instanceof`, which untrusted input cannot forge. The class is exported * because bundlers cannot drop an unexported top-level class. */ export declare class LiveStream<T> { 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. */ export 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 export declare const enum SerovalMode { Vanilla = 1, Cross = 2 } export interface PluginData { id: number; } export type PluginInfo = { [key: string]: SerovalNode; }; export 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; /** * Convert the parsed node into its runtime equivalent. */ deserialize(node: Info, ctx: DeserializePluginContext, data: PluginData): Value; } export declare function createPlugin<Value, Info extends PluginInfo>(plugin: Plugin<Value, Info>): Plugin<Value, Info>; export interface PluginAccessOptions { plugins?: Plugin<any, any>[]; } export 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`. */ export declare function getPlainObjectPlugins(plugins: Plugin<any, any>[] | undefined): Plugin<any, any>[] | undefined; //#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/cross/index.d.ts export interface CrossAssignmentOptions { /** * Only assign `$R[n]` for values that the output reads more than once, * such as shared references and cycles. The output is shorter, but later * scripts cannot read the other values from `$R`. Only use it when no * later output that shares the same references refers back to this one. */ assignSharedRefsOnly?: boolean; } export interface CrossSerializeOptions extends SyncParserContextOptions, CrossContextOptions, CrossAssignmentOptions {} export declare function crossSerialize<T>(source: T, options?: CrossSerializeOptions): string; export interface CrossSerializeAsyncOptions extends AsyncParserContextOptions, CrossContextOptions, CrossAssignmentOptions {} export declare function crossSerializeAsync<T>(source: T, options?: CrossSerializeAsyncOptions): Promise<string>; export type ToCrossJSONOptions = SyncParserContextOptions; export declare function toCrossJSON<T>(source: T, options?: ToCrossJSONOptions): SerovalNode; export type ToCrossJSONAsyncOptions = AsyncParserContextOptions; export declare function toCrossJSONAsync<T>(source: T, options?: ToCrossJSONAsyncOptions): Promise<SerovalNode>; export interface CrossSerializeStreamOptions extends Omit<StreamParserContextOptions, 'onParse'>, CrossContextOptions { /** * Receives each serialized record. Returning a promise defers the next * record, and the acceptance of the live stream event behind this one, * until the promise settles. */ onSerialize: (data: string, initial: boolean) => void | PromiseLike<void>; } export declare function crossSerializeStream<T>(source: T, options: CrossSerializeStreamOptions): (reason?: unknown) => void; export type ToCrossJSONStreamOptions = StreamParserContextOptions; export declare function toCrossJSONStream<T>(source: T, options: ToCrossJSONStreamOptions): (reason?: unknown) => void; export type FromCrossJSONOptions = CrossDeserializerContextOptions; export declare function fromCrossJSON<T>(source: SerovalNode, options: FromCrossJSONOptions): T; export interface CrossDeserializer { /** Deserializes one streamed record. Records share references. */ deserialize<T>(node: SerovalNode): T; /** Deferred values (promises, streams) created but not yet settled. */ readonly pending: number; /** Rejects pending promises and throws into open streams; idempotent. */ abort(reason: unknown): void; } export type CrossDeserializerOptions = FromCrossJSONOptions; export declare function createCrossDeserializer(options: CrossDeserializerOptions): CrossDeserializer; //#endregion //#region src/core/errors.d.ts export declare class SerovalError extends Error { cause: unknown; constructor(type: string, cause: unknown); } export declare class SerovalParserError extends SerovalError { constructor(cause: unknown); } export declare class SerovalSerializationError extends SerovalError { constructor(cause: unknown); } export declare class SerovalDeserializationError extends SerovalError { constructor(cause: unknown); } export declare class SerovalUnsupportedTypeError extends Error { value: unknown; constructor(value: unknown); } export declare class SerovalUnsupportedNodeError extends Error { constructor(node: SerovalNode); } export declare class SerovalMissingPluginError extends Error { constructor(tag: string); } export declare class SerovalMissingInstanceError extends Error { constructor(tag: string); } /** * @deprecated Not thrown by seroval. A missing `createReference` key throws * {@link SerovalMissingReferenceForIdError} instead. */ export declare class SerovalMissingReferenceError extends Error { value: unknown; constructor(value: unknown); } export declare class SerovalMissingReferenceForIdError extends Error { constructor(id: string); } export declare class SerovalUnknownTypedArrayError extends Error { constructor(name: string); } export declare class SerovalMalformedNodeError extends Error { constructor(node: SerovalNode); } export declare class SerovalConflictedNodeIdError extends Error { constructor(node: SerovalNode); } export declare class SerovalDepthLimitError extends Error { constructor(limit: number); } export declare class SerovalAbortedError extends Error { constructor(); } export type LiveStreamErrorReason = 'consumed' | 'pending' | 'reading' | 'closed'; export declare class SerovalLiveStreamError extends Error { reason: LiveStreamErrorReason; constructor(reason: LiveStreamErrorReason); } //#endregion //#region src/core/keys.d.ts export declare function getCrossReferenceHeader(id?: string): string; //#endregion //#region src/core/opaque-reference.d.ts /** * An opaque reference allows hiding values from the serializer. */ export 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 export declare function createReference<T>(id: string, value: T): T; //#endregion //#region src/core/Serializer.d.ts interface SerializerOptions extends PluginAccessOptions { globalIdentifier: string; scopeId?: string; disabledFeatures?: number; compactArrayBufferViews?: boolean; depthLimit?: number; onData: (result: string) => void; onError: (error: unknown) => void; onDone?: () => void; } declare class Serializer { private alive; private flushed; private done; private pending; private cleanups; private readonly refs; private plugins?; private options; constructor(options: SerializerOptions); keys: Set<string>; write(key: string, value: unknown): void; private finishWrite; ids: number; private getNextID; push(value: unknown): string; flush(): void; close(): void; private finish; } //#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. */ export declare class Sequence { v: unknown[]; t: number; d: number; constructor(values: unknown[], throwAt: number, doneAt: number); } //#endregion //#region src/core/tree/index.d.ts /** * Options for `serialize`. The same as the parser options, without `refs`: * the output is self-contained, so there is nothing to share between calls. */ export type SerializeOptions = Omit<BaseParserContextOptions, 'refs'>; /** Options for `serializeAsync`. */ export type SerializeAsyncOptions = Omit<BaseParserContextOptions, 'refs'>; /** Options for `toJSON`. */ export type ToJSONOptions = SerializeOptions; /** Options for `toJSONAsync`. */ export type ToJSONAsyncOptions = SerializeAsyncOptions; export declare function serialize<T>(source: T, options?: SerializeOptions): string; export declare function serializeAsync<T>(source: T, options?: SerializeAsyncOptions): Promise<string>; export declare function deserialize<T>(source: string): T; export interface SerovalJSON { t: SerovalNode; f: number; m: number[]; } export interface FromJSONOptions extends PluginAccessOptions, Pick<BaseDeserializerContextOptions, 'depthLimit' | 'maxBase64Length'> { disabledFeatures?: number; } export declare function toJSON<T>(source: T, options?: ToJSONOptions): SerovalJSON; export declare function toJSONAsync<T>(source: T, options?: ToJSONAsyncOptions): Promise<SerovalJSON>; export declare function compileJSON(source: SerovalJSON, options?: PluginAccessOptions): string; export declare function fromJSON<T>(source: SerovalJSON, options?: FromJSONOptions): T; //#endregion 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 };