/** * Represents a message in the [Server-Sent Event protocol](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#fields) * * ```js * // All fields are optional * const message = { * comment: 'hello there', * event: 'my-event', * data: JSON.stringify({ lots: 'of', things: true }), * id: 42, * retry: 3600 * } * ``` */ export interface ServerSentEventMessage { /** Ignored by the client, can be used to prevent connections from timing out */ comment?: string; /** A string identifying the type of event described. If specified this event is triggered, otherwise a "message" will be dispatched. */ event?: string; /** The data field for the message. Split by new lines. */ data?: string; /** The event ID to set the `EventSource` object's last event ID value. */ id?: string | number; /** The reconnection time. If the connection to the server is lost, the browser will wait for the specified time before attempting to reconnect. */ retry?: number; } export declare function _assertHasNoNewline(value: string, variable: string, errPrefix: string): void; /** * Converts a server-sent message object into a string for the client. * * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#event_stream_format} */ export declare function _stringify(message: ServerSentEventMessage): string; /** * Transforms server-sent message objects into strings for the client. * [more info](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events). * * You can then write {@link ServerSentEventMessage} to that stream over time. * * ```js * const data = [{ data: "hello there" }] * * // Get a stream somehow, then pipe it through * const stream = ReadableStream.from(data) * .pipeThrough(new ServerSentEventStream()); * * const response = new Response(stream, { * headers: { * "content-type": "text/event-stream", * "cache-control": "no-cache", * }, * }); * ``` */ export declare class ServerSentEventStream extends TransformStream { constructor(); } /** @unstable */ export declare const sseHeaders: { "content-type": string; "cache-control": string; connection: string; }; //# sourceMappingURL=server-sent-events.d.ts.map