import { r as ConnectionKey } from "./connection-key-CvX95c4J.js"; import { n as SseClientLifecycleEvents, r as SseClientState, t as DisconnectReason } from "./types-EGPx1Oeh.js"; import { Program, StateTransition, StateTransition as StateTransition$1, TransitionListener, TransitionListener as TransitionListener$1 } from "@kyneta/machine"; import { EstablishedChannel, GeneratedChannel, ReconnectOptions, Transport } from "@kyneta/transport"; //#region src/post-retry.d.ts interface PostRetryOptions { /** Total attempts, including the first. */ maxAttempts: number; baseDelay: number; maxDelay: number; /** One attempt is abandoned, and counts as failed, after this many ms. */ attemptTimeoutMs: number; } //#endregion //#region src/client-transport.d.ts /** * Options for the SSE client transport. */ interface SseClientOptions { /** URL for POST requests (client→server). */ postUrl: string; /** URL for SSE EventSource (server→client). */ eventSourceUrl: string; /** Reconnection options for EventSource. */ reconnect?: Partial; /** * Longest an attempt may take, from opening the stream until the exchange * establishes the channel, through the key event and the handshake. * Default: `DEFAULT_HANDSHAKE_TIMEOUT_MS`. */ connectTimeoutMs?: number; /** POST retry options. */ postRetry?: Partial; /** * Longest `flush()`, and so `exchange.shutdown()`, waits for in-flight * POSTs, in ms. Default: 2000. */ flushTimeoutMs?: number; /** Fragment threshold in characters. Default: 60000 (60K chars). */ fragmentThreshold?: number; /** * Largest inbound message payload, in code points. Default: * `DEFAULT_MAX_MESSAGE_SIZE`. */ maxMessageSize?: number; /** Lifecycle event callbacks. */ lifecycle?: SseClientLifecycleEvents; } /** * State transition event for SSE client states. */ type SseClientStateTransition = StateTransition$1; /** * SSE client transport for @kyneta/exchange. * * Uses two HTTP channels: * - **EventSource** (GET, long-lived) for server→client text frames * - **fetch POST** for client→server binary frames * * Internally, the connection lifecycle is a `Program` — * a pure Mealy machine whose transitions are deterministically testable. * This class is the imperative shell that interprets data effects as I/O. * * @example * ```typescript * import { createSseClient } from "@kyneta/sse-transport/client" * * const exchange = new Exchange({ * principal: "browser-client", * transports: [createSseClient({ * postUrl: "/sync", * eventSourceUrl: "/events", * reconnect: { enabled: true }, * })], * }) * ``` */ declare class SseClientTransport extends Transport { #private; constructor(options: SseClientOptions); /** * Get the current connection state. */ getState(): SseClientState; /** * Subscribe to state transitions. */ subscribeToTransitions(listener: TransitionListener$1): () => void; /** * Wait for a specific state. */ waitForState(predicate: (state: SseClientState) => boolean, options?: { timeoutMs?: number; }): Promise; /** * Wait for a specific status. */ waitForStatus(status: SseClientState["status"], options?: { timeoutMs?: number; }): Promise; /** Whether the exchange has established this client's channel. */ get isEstablished(): boolean; protected generate(key: ConnectionKey): GeneratedChannel; protected onChannelEstablished(channel: EstablishedChannel): void; onStart(): Promise; onStop(): Promise; } /** * Create an SSE client transport for browser-to-server connections. * * @example * ```typescript * import { createSseClient } from "@kyneta/sse-transport/client" * * const exchange = new Exchange({ * transports: [createSseClient({ * postUrl: "/sync", * eventSourceUrl: "/events", * reconnect: { enabled: true }, * })], * }) * ``` */ declare function createSseClient(options: SseClientOptions): SseClientTransport; //#endregion //#region src/client-program.d.ts type SseClientMsg = { type: "start"; } | { type: "connection-keyed"; key: ConnectionKey; } | { type: "event-source-error"; } | { type: "channel-established"; } | { type: "refused"; } | { type: "connect-timed-out"; attempt: number; } | { type: "reconnect-timer-fired"; } | { type: "stop"; }; type SseClientEffect = { type: "create-event-source"; url: string; attempt: number; } | { type: "close-event-source"; } | { type: "add-channel-and-establish"; key: ConnectionKey; } | { type: "remove-channel"; } | { type: "start-connect-timer"; attempt: number; delayMs: number; } | { type: "cancel-connect-timer"; } | { type: "start-reconnect-timer"; delayMs: number; } | { type: "cancel-reconnect-timer"; } | { type: "abort-pending-posts"; }; interface SseClientProgramOptions { url: string; reconnect?: Partial; /** * Longest an attempt may take, from opening the stream until the exchange * establishes the channel. Default: `DEFAULT_HANDSHAKE_TIMEOUT_MS`. */ connectTimeoutMs?: number; /** Source of `[0, 1)` random values for jitter. Default: `Math.random` */ randomFn?: () => number; } /** * Create the SSE client connection lifecycle program — a pure Mealy machine. * * The returned `Program` * encodes every state transition and effect as inspectable data. The imperative * shell interprets `SseClientEffect` as actual I/O. */ declare function createSseClientProgram(options: SseClientProgramOptions): Program; //#endregion export { type ConnectionKey, type DisconnectReason, type SseClientEffect, type SseClientLifecycleEvents, type SseClientMsg, type SseClientOptions, type SseClientProgramOptions, type SseClientState, type SseClientStateTransition, SseClientTransport, type StateTransition, type TransitionListener, createSseClient, createSseClientProgram }; //# sourceMappingURL=client.d.ts.map