import { DatastarEventOptions, EventType, StreamOptions, Jsonifiable } from "../types.js"; import { ServerSentEventGenerator as AbstractSSEGenerator } from "../abstractServerSentEventGenerator.js"; import { IncomingMessage, ServerResponse } from "node:http"; /** * ServerSentEventGenerator class, responsible for initializing and handling * server-sent events (SSE) as well as reading signals sent by the client. * Cannot be instantiated directly, you must use the stream static method. */ export declare class ServerSentEventGenerator extends AbstractSSEGenerator { protected req: IncomingMessage; protected res: ServerResponse; protected constructor(req: IncomingMessage, res: ServerResponse); /** * Initializes the server-sent event generator and executes the onStart callback. * * @param req - The NodeJS request object. * @param res - The NodeJS response object. * @param onStart - A function that will be passed the initialized ServerSentEventGenerator class as it's first parameter. * @param options? - An object that can contain onError and onCancel callbacks as well as a keepalive boolean. * The onAbort callback will be called whenever the request is aborted * * The onError callback will be called whenever an error is met. If provided, the onAbort callback will also be executed. * If an onError callback is not provided, then the stream will be ended and the error will be thrown up. * * The stream is always closed after the onStart callback ends. * If onStart is non blocking, but you still need the stream to stay open after it is called, * then the keepalive option will maintain it open until the request is aborted by the client. */ static stream(req: IncomingMessage, res: ServerResponse, onStart: (stream: ServerSentEventGenerator) => Promise | void, options?: StreamOptions): Promise; protected send(event: EventType, dataLines: string[], options: DatastarEventOptions): string[]; /** * Closes the server-sent event stream. * * Ends the Node.js response stream. */ close(): void; /** * Reads client sent signals based on HTTP methods * * @params request - The NodeJS Request object. * * @returns An object containing a success boolean and either the client's signals or an error message. */ static readSignals(request: IncomingMessage): Promise<{ success: true; signals: Record; } | { success: false; error: string; }>; } //# sourceMappingURL=serverSentEventGenerator.d.ts.map