import { StateCache } from "./state-cache.js"; import type { BroadcastState, PatchMessage, Subscriber } from "./types.js"; export declare class BroadcastChannel { private channels; private state_cache; /** * @param options.cacheSize - Max number of stream states kept in the LRU * cache (default 50). */ private on_subscriber_error; private on_overlay_miss; constructor(options?: { cacheSize?: number; /** * Called when `overlay()` finds no cached baseline for the stream, so * the update cannot be broadcast. Live subscribers receive nothing and * have no way to notice — a host that cares should raise `cacheSize`, * re-`publish` the stream, or push the viewers to refetch. Defaults to a * no-op so existing behavior is unchanged apart from being observable. */ onOverlayMiss?: (streamId: string) => void; /** * Called when a subscriber callback throws. The frame is still delivered * to every other subscriber and the publish still returns normally — a * bad consumer must not break the publisher (#1423). Defaults to the * framework's `log()` port, so it lands wherever the host already * routes framework logs. */ onSubscriberError?: (error: unknown, streamId: string) => void; /** * Deprecated alias of `cacheSize` — removal in the next major. When * both are given, `cacheSize` wins. * @deprecated use `cacheSize` */ cache_size?: number; }); /** * Publish domain patches from a commit. * patches[i] corresponds to version baseV + i + 1. * * @param streamId - The event store stream ID * @param state - Full state with `_v` set from `snap.event.version` * @param patches - Array of domain patches, one per emitted event */ publish(streamId: string, state: S, patches?: Partial[]): PatchMessage; /** * Publish a state update that doesn't change the event version * (e.g. presence overlay, computed field refresh). * Uses the same version as the cached state, single entry. */ overlay(streamId: string, overlay_patch: Partial): PatchMessage | undefined; /** * Subscribe to broadcast messages for a stream. * Returns a cleanup function that removes the subscription. */ subscribe(streamId: string, cb: Subscriber): () => void; /** Get the number of subscribers for a stream. */ subscriberCount(streamId: string): number; /** Get the cached state for a stream (for reconnects / initial SSE yield). */ state(streamId: string): S | undefined; /** @deprecated use `overlay` — removal in the next major */ publish_overlay(streamId: string, overlay_patch: Partial): PatchMessage | undefined; /** @deprecated use `subscriberCount` — removal in the next major */ get_subscriber_count(streamId: string): number; /** @deprecated use `state` — removal in the next major */ get_state(streamId: string): S | undefined; /** Direct access to the state cache (for app-specific reads like presence). */ get cache(): StateCache; } //# sourceMappingURL=broadcast.d.ts.map