tupleson
Version:
A hackable JSON serializer/deserializer
31 lines (28 loc) • 1.34 kB
text/typescript
import { TsonStreamInterruptedError } from './asyncErrors.mjs';
import { TsonAsyncOptions, TsonAsyncStringifierIterable } from './asyncTypes.mjs';
import '../errors.mjs';
import '../internals/esque.mjs';
import '../sync/syncTypes.mjs';
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 };