import type { FallbackParsedSseFrame } from './types.ts'; /** * What a framer starts a connection with. * * The Last-Event-ID cursor is stream-scoped rather than connection-scoped, so * a reconnect starts where the previous connection left the core rather than * from nothing — which is what lets an id-less frame report the cursor it * inherited instead of none at all. */ export type SseFramerOptions = { /** Last-Event-ID the connection resumed from. */ lastEventId?: string; }; /** * Incremental Server-Sent Events framer. * * Exists because the two things this package needs from a stream are not * available from a framer that models the browser's `EventSource`: * * - the **per-frame `id:`**, kept apart from the sticky Last-Event-ID cursor. * The fallback core's default version extractor reads the frame's own id, so * a framer that only reports the cursor would make every id-less frame look * like a repeat of the previous version and the version gate would drop it. * - **frame-level inspection without consuming the stream**, so raw chunks can * be passed through to the core untouched while their payloads are validated * against the contract on the side. * * Framing follows the WHATWG event-stream rules: CR, LF and CRLF all end a * line (a trailing CR is held back across chunk boundaries so CRLF is never * split into two terminators), exactly one leading space is stripped after the * colon, a line with no colon is a field with an empty value, a line starting * with a colon is a comment, `retry:` takes ASCII digits only, an `id:` * containing NUL is ignored, an empty `event:` leaves the event type at * `message`, and the reconnect cursor moves only when a frame is dispatched. */ export declare class SseFramer { /** Unterminated tail of the last chunk, including a held-back trailing CR. */ private buffer; private dataLines; private eventName; private frameId; /** * `retry:` is connection-scoped rather than per-frame, and a frame carrying * only `retry:` dispatches nothing — so the hint is held and stamped onto the * next frame that does dispatch. */ private retryHint; /** * The spec's *last event ID buffer*: whatever the most recent `id:` line * carried. Unlike the data and event-type buffers it is never reset between * frames, which is what makes the cursor sticky. */ private idBuffer; /** * The spec's *last event ID string* — the buffer's value as of the last * dispatch, which is the only place it moves. * * An `id:` in a frame the connection cut short before its terminator must * not advance it: the event that frame was carrying was never delivered, and * resuming a reconnect past it would skip it for good. */ private cursor; constructor(options?: SseFramerOptions); /** The Last-Event-ID cursor as of the last processed frame. */ get lastEventId(): string | undefined; /** * Feed decoded text and collect whatever frames it completed. * * A frame that carried no `data:` field dispatches nothing (an `id:`-only or * `retry:`-only frame updates the cursor / retry hint instead), and neither * do comment frames, matching what a consumer of parsed events can observe. */ push(chunk: string): FallbackParsedSseFrame[]; private handleLine; private dispatch; }