import type { BroadcastState, PatchMessage } from "./types.js"; /** * Result of applying a patch message to cached client state. */ export type ApplyResult = { ok: true; state: S; } | { ok: false; reason: "stale" | "behind"; }; /** * Apply a version-keyed patch message to the client's cached state. * * ## Version logic * * - All patches older than cached → "stale" (client already ahead) * - Gap between cached version and first patch → "behind" (client missed versions, must resync) * - Contiguous from cached version → apply in order * - No baseline (fresh client) → the genesis patch (version 0) folds onto init * state; a first patch at version ≥ 1 is "behind" (can't build from init) * - Overlay frame ({@link PatchMessage._overlay}) at the current version → * merged on top of cached state, `_v` unchanged (presence / computed * fields reach caught-up clients instead of being dropped as stale) * * ## Usage (React Query) * * ```typescript * onData: (msg) => { * const cached = utils.get_state.get_data({ streamId }); * const result = applyPatchMessage(msg, cached); * if (result.ok) { * utils.get_state.setData({ streamId }, result.state); * } else if (result.reason === "behind") { * utils.get_state.invalidate({ streamId }); // trigger full refetch * } * // "stale" → no-op, client already has newer state * } * ``` */ export declare function applyPatchMessage(msg: PatchMessage, cached: S | null | undefined): ApplyResult; //# sourceMappingURL=apply-patch.d.ts.map