type MaybePromise = T | Promise; export type SseEventCallbacks = { onEvent: { [K in TEvent['type']]: (data: Extract['data']) => MaybePromise; }; onError?: (error: unknown) => MaybePromise; /** * Called once after the server closes the stream naturally (without error). Not called on * aborted streams — `onError` is the signal for those. */ onDone?: () => MaybePromise; }; /** * Consumes an SSE `AsyncIterable` (as returned by `sendByApiContract`) and dispatches * typed events to per-event callbacks. * * Iteration runs in the background. To abort early, pass an `AbortSignal` to `sendByApiContract` * and call `abort()` on its controller. * * @example * ```typescript * const controller = new AbortController() * * const { result } = await sendByApiContract(client, myContract, { * signal: controller.signal, * }) * * sseStreamToCallbacks(result.body, { * onEvent: { * 'item.updated': (data) => console.log(data), * done: (data) => console.log(data.total), * }, * onError: (err) => console.error(err), * onDone: () => console.log('stream closed'), * }) * * // later, to stop early: * controller.abort() * ``` */ export declare function sseStreamToCallbacks(stream: AsyncIterable, callbacks: SseEventCallbacks): void; export {};