tupleson
Version:
A hackable JSON serializer/deserializer
31 lines (28 loc) • 1.34 kB
TypeScript
import { TsonStreamInterruptedError } from './asyncErrors.js';
import { TsonAsyncOptions, TsonAsyncStringifierIterable } from './asyncTypes.js';
import '../errors.js';
import '../internals/esque.js';
import '../sync/syncTypes.js';
interface TsonParseAsyncOptions {
/**
* Event handler for when the stream reconnects
* You can use this to do extra actions to ensure no messages were lost
*/
onReconnect?: () => void;
/**
* On stream error
*/
onStreamError?: (err: TsonStreamInterruptedError) => void;
/**
* Allow reconnecting to the stream if it's interrupted
* @default false
*/
reconnect?: boolean;
}
type TsonParseAsync = <TValue>(string: AsyncIterable<string> | TsonAsyncStringifierIterable<TValue>, opts?: TsonParseAsyncOptions) => Promise<TValue>;
declare function createTsonParseAsync(opts: TsonAsyncOptions): TsonParseAsync;
declare function createTsonParseEventSource(opts: TsonAsyncOptions): <TValue = unknown>(url: string, parseOpts?: TsonParseAsyncOptions & {
signal?: AbortSignal;
}) => Promise<TValue>;
declare function createTsonParseJsonStreamResponse(opts: TsonAsyncOptions): <TValue = unknown>(response: Response) => Promise<TValue>;
export { TsonParseAsyncOptions, createTsonParseAsync, createTsonParseEventSource, createTsonParseJsonStreamResponse };