/** One Server-Sent Event. `data` is sent verbatim if a string, else JSON. */ export interface SseEvent { /** Payload — a string is sent as-is; anything else is JSON-serialized. */ data: unknown; /** Event name (the client's `addEventListener(name, …)`). */ event?: string; /** Event id (echoed as `Last-Event-ID` on reconnect). */ id?: string; /** Reconnect delay the client should use, in milliseconds; floored to an integer on the wire. Sets the browser's retry timer (default ~3s until an event changes it). */ retry?: number; } /** Options for {@link sse}. */ export interface SseOptions { /** Interval in milliseconds for emitting a `: keep-alive` comment line, holding the stream open through proxies that drop idle connections. Omit to send no heartbeat. */ keepAlive?: number; /** Extra response headers, merged onto the stream response. `content-type`, `cache-control`, and `connection` are set by {@link sse} and cannot be overridden here. */ headers?: HeadersInit; } /** * Build a streaming `text/event-stream` `Response` from an async source — * return it straight from a route handler. The source is an async iterable (or * a function returning one), so an async generator that `yield`s events is the * usual shape; drive a push-style stream with an {@link SseChannel}. Iteration * stops when the source completes or the client disconnects. * * ```ts * @get('/events') * events() { * return sse(async function* () { * yield { event: 'tick', data: { n: 1 } } * yield { data: 'done' } * }) * } * ``` * * @param source - the events to stream: an async iterable, or a function returning one (invoked synchronously as soon as `sse()` is called, before the `Response` exists) * @param options - keep-alive interval and extra response headers; see {@link SseOptions} * @returns a streaming `text/event-stream` `Response` to return from a handler */ export declare function sse(source: AsyncIterable | (() => AsyncIterable), options?: SseOptions): Response; /** * A push-driven async event source for {@link sse}. `push` events from anywhere * (an event bus, a subscription) and `close` when done; the stream drains any * queued events before ending. * * ```ts * const channel = new SseChannel() * bus.on('notice', (n) => channel.push({ event: 'notice', data: n })) * return sse(channel) * ``` */ export declare class SseChannel implements AsyncIterable { private readonly queue; private readonly waiters; private closed; /** * Enqueue an event (ignored once closed). * * @param event - the event to deliver; handed straight to a waiting consumer, otherwise buffered in FIFO order until one arrives */ push(event: SseEvent): void; /** End the stream once queued events have drained. */ close(): void; /** Async-iterate events: drains queued events, then awaits pushes until closed. */ [Symbol.asyncIterator](): AsyncIterator; } //# sourceMappingURL=sse.d.ts.map