import { Q as QueryResult, O as OdlaError, c as TxChain, I as InstaQLQuery, a as QueryCallback, T as TxInput, d as AggregateSpec, b as QueryOpts, A as AggregateResult } from './tx.d-Cxg-Av3i.js'; import { O as Op, J as Json } from './ops.d-D9oT7Y5m.js'; /** Snapshot persisted for offline/instant-reload (confirmed results + unacked * mutations + the durable clientId so replay stays idempotent across reloads). */ interface PersistedState { clientId: string; lastSeenTx: number; pending: Array<{ mutationId: string; ops: Op[]; }>; cache: Array<[string, QueryResult]>; /** Server sync epoch. Changes only when the app's history was rewound (PITR * restore) — on mismatch the cache/pending/watermark are discarded. */ epoch?: number; } interface PersistAdapter { load(): Promise; save(state: PersistedState): void | Promise; } /** IndexedDB-backed persistence keyed by appId. No-ops where IndexedDB is absent. */ declare function indexedDbAdapter(appId: string): PersistAdapter; interface Transport { send(data: string): void; close(): void; } interface TransportHandlers { onOpen(): void; onMessage(data: string): void; onClose(): void; } type TransportFactory = (url: string, handlers: TransportHandlers) => Transport; type ConnectionState = "dialing" | "authenticating" | "syncing" | "synced" | "backoff" | "closed"; interface ConnectionStatus { state: ConnectionState; attempt: number; changedAt: number; retryInMs?: number; errorCode?: string; } type FreshnessMode = "connecting" | "live" | "reconnecting" | "degraded" | "stale" | "closed"; /** * Content-free realtime health suitable for UI freshness indicators and * observability adapters. It never includes an app id, query, mutation, room, * user, or frame payload. */ interface ConnectionHealth { mode: FreshnessMode; transport: "websocket"; state: ConnectionState; lastConnectedAt?: number; lastEventAt?: number; staleAfterMs: number; reconnectAttempt: number; heartbeatRttMs?: number; outboxDepth: number; outboxBytes: number; lastError?: { code: string; at: number; }; } /** Low-cardinality events for forwarding client-perceived health to telemetry. */ type ClientTelemetryEvent = { type: "connection.state"; at: number; state: ConnectionState; attempt: number; retryInMs?: number; errorCode?: string; } | { type: "connection.heartbeat"; at: number; rttMs: number; } | { type: "connection.queue"; at: number; depth: number; bytes: number; overflow?: boolean; } | { type: "connection.freshness"; at: number; mode: "live" | "stale"; lastEventAt?: number; }; interface InitOptions { appId: string; endpoint?: string; getToken?: () => string | null | Promise; transport?: TransportFactory; /** Persist confirmed results + pending mutations so reloads render instantly * and survive offline. `true` uses IndexedDB (browser); pass an adapter for * custom storage (or tests). Omit to disable. */ persist?: PersistAdapter | boolean; /** Stable protocol/auth/runtime errors from the realtime connection. */ onError?: (error: OdlaError) => void; /** Connection lifecycle for honest live/reconnecting/stale UI state. */ onStatus?: (status: ConnectionStatus) => void; /** Full content-free health snapshot, including freshness and queue depth. */ onHealth?: (health: ConnectionHealth) => void; /** Optional low-cardinality sink for client-perceived connection telemetry. */ onTelemetry?: (event: ClientTelemetryEvent) => void; /** No-server-frame interval after which a synced connection is stale. * Defaults to 45 seconds. */ staleAfterMs?: number; /** Ping cadence used to measure RTT and prove the connection is still * receiving frames. Defaults to 15 seconds; set to 0 to disable. */ heartbeatIntervalMs?: number; /** Custom HTTP fetch for one-shot operations such as aggregate. */ fetch?: typeof globalThis.fetch; } /** An ephemeral room: presence + fire-and-forget events, never persisted. */ interface Room { /** Set (or update) this client's presence in the room. */ setPresence(presence: Json): void; /** Broadcast a transient event to other peers in the room. */ publish(event: Json): void; /** Subscribe to the room's full presence roster (fires on any change). */ onPresence(cb: (peers: Array<{ peerId: string; presence: Json; }>) => void): () => void; /** Subscribe to events published by other peers. */ onEvent(cb: (from: string, event: Json) => void): () => void; /** Leave the room (clears this client's presence). */ leave(): void; } interface Db { tx: Record>; subscribeQuery(query: InstaQLQuery, cb: QueryCallback): () => void; /** Synchronous cached read (confirmed ⊕ pending overlay) for a warm first * paint; null when the query has never resolved. Optional so existing * Db-shaped test doubles keep compiling. */ peekQuery?(query: InstaQLQuery): QueryResult | null; transact(input: TxInput, opts?: { mutationId?: string; }): Promise; /** One-shot aggregate (count/sum/avg/min/max) over a namespace's matching rows. */ aggregate(ns: string, spec: AggregateSpec, opts?: QueryOpts): Promise; /** Join/get an ephemeral presence room (cursors, typing, who's-online). */ room(name: string): Room; /** Current realtime lifecycle; optional for compatible Db-shaped adapters. */ connectionStatus?(): ConnectionStatus; /** Content-free realtime freshness/RTT/queue health for UI and telemetry. */ connectionHealth?(): ConnectionHealth; close(): void; id(): string; } declare function init(opts: InitOptions): Db; export { type ClientTelemetryEvent as C, type Db as D, type FreshnessMode as F, type InitOptions as I, type PersistAdapter as P, type Room as R, type Transport as T, type ConnectionHealth as a, type TransportFactory as b, type TransportHandlers as c, type PersistedState as d, indexedDbAdapter as e, init as i };