import type { Frame, MessageFamily } from "../protocol/index.ts"; /** * A handler for one message family. `ctx` is whatever per-connection context * the hub threads through (see {@link HubConnection}); the router itself is * generic so it can be unit-tested without the hub. */ export type FamilyHandler = (frame: Frame, ctx: Ctx) => void | Promise; /** Raised when a family key outside the S0 {@link MessageFamily} set is used. */ export declare class UnknownFamilyError extends Error { readonly family: string; constructor(family: string); } /** * Raised when a second handler is registered for a family that already has one. * One family, one owning module — this guard is what stops two sibling slices * silently clobbering each other's handler. */ export declare class DuplicateFamilyHandlerError extends Error { readonly family: MessageFamily; constructor(family: MessageFamily); } /** * The derived frame→family routing table. The hub holds one of these; every * family module attaches through {@link registerFamilyHandler}. */ export declare class FamilyRouter { #private; /** * Attach the handler that owns `family`. This is the seam every family module * calls; it keys off the S0 family set and refuses a duplicate so two slices * cannot both claim one family. */ registerFamilyHandler(family: MessageFamily, handler: FamilyHandler): void; /** Set the fallback invoked for a frame whose family has no handler. */ onUnhandled(handler: FamilyHandler): void; /** Whether a handler is registered for `family`. */ has(family: MessageFamily): boolean; /** The families that currently have a handler (the derived table's keys). */ families(): MessageFamily[]; /** * Route one decoded frame to its family handler by table lookup. Returns * `true` if a family handler ran, `false` if it fell through to the unhandled * fallback (or nowhere). Any handler rejection propagates to the caller. */ route(frame: Frame, ctx: Ctx): Promise; }