import type { ChannelType } from 'ts-broadcasting'; /** * Install (or clear) the backpressure guard. Pass `null` to disable. */ export declare function setBackpressureGuard(cfg: BackpressureGuardConfig | null): void; /** * Read the currently-installed guard config (useful for tests). */ export declare function getBackpressureGuard(): Required | null; /** * Run a broadcast from a broadcast file * * @example * await runBroadcast('OrderCreated', { orderId: 123 }) */ export declare function runBroadcast(name: string, payload?: any): Promise; /** * Alias for runBroadcast. * * @example * await broadcast('OrderCreated', { orderId: 123 }) */ export declare function broadcast(name: string, payload?: any): Promise; /** * Backpressure guard config (stacksjs/stacks#1877 R-2). The default * threshold is 1 MiB of buffered-bytes per socket — above this, the * configured `onSlow` callback fires once per offending socket per * broadcast. Apps install via `setBackpressureGuard({...})`; the * default is "no guard" for backwards-compat, so existing callers * see no behavior change until they opt in. * * Why opt-in: the underlying ts-broadcasting `server.broadcast()` is * synchronous and we can't inject between message-serialize and * socket-write. The best we can do at the Stacks layer is detect * slow consumers AROUND the broadcast call and let the app decide * what to do (close socket, drop client from channel, scale up). */ export declare interface BackpressureGuardConfig { maxPerSocketBytes?: number onSlow?: (info: { channelName: string, backpressure: number, socket: unknown }) => void } export declare interface BroadcastInstance { channel?: () => string | string[] broadcastOn?: () => string | string[] event?: () => string broadcastAs?: () => string data?: () => any broadcastWith?: () => any handle?: (payload?: any) => Promise | void } /** * Stacks Broadcast class for backward compatibility * Wraps ts-broadcasting's BroadcastServer */ export declare class Broadcast { connect(): Promise; disconnect(): Promise; subscribe(channel: string, callback: (data: any) => void): void; unsubscribe(channel: string): void; broadcast(channel: string, event: string, data?: any, type?: ChannelType): void; isConnected(): boolean; }