import { type ChunkEnvelope, type ChunkOptions, Reassembler } from "./chunking.js"; import { type ParseGroupNameOptions, type ParsedGroup } from "./groups.js"; /** * The Web PubSub subprotocol used by every consumer of this transport. All * framing is text-frame JSON. */ export declare const RELIABLE_JSON_SUBPROTOCOL = "json.reliable.webpubsub.azure.v1"; /** * Web PubSub `sendToGroup` command on the outbound wire. `ackId` is a monotonic * per-publisher counter scoped to the connection. */ export interface SendToGroupCommand { readonly type: "sendToGroup"; readonly group: string; readonly ackId: number; readonly dataType: "json"; readonly noEcho: true; readonly data: ChunkEnvelope; } /** * Web PubSub group-message envelope on the inbound wire. The `from: 'group'` * discriminant distinguishes group-fanout messages from service-level events. */ export interface GroupMessage { readonly type: "message"; readonly from: "group"; readonly group: string; readonly dataType: "json"; readonly data: ChunkEnvelope; readonly fromUserId?: string; readonly sequenceId?: number; } /** Options accepted by {@link buildPublish}. */ export interface BuildPublishOptions { /** Target group name (must be a valid {@link parseGroupName} input). */ readonly group: string; /** Source of monotonic `ackId` values for the publishing connection. */ readonly nextAckId: () => number; /** Inner application payload. */ readonly payload: unknown; /** Forwarded to {@link chunk}. */ readonly chunkOptions?: ChunkOptions; /** Opaque host-side connection identity; absent for client-originated frames. */ readonly generation?: number; } /** * Build the list of {@link SendToGroupCommand}s to publish for a single * application payload. An oversized payload chunks into multiple envelopes, * each carried by its own frame with its own `ackId`. */ export declare function buildPublish(options: BuildPublishOptions): SendToGroupCommand[]; /** * Result of {@link parseInbound}. * * - `kind: 'payload'` — a complete inner application payload is ready. * - `kind: 'pending'` — a chunk segment was accepted; reassembly continues. * - `kind: 'ignored'` — the frame was not a group-fanout message. */ export type InboundResult = { readonly kind: "payload"; readonly group: ParsedGroup; readonly payload: unknown; readonly generation?: number; } | { readonly kind: "batch"; readonly group: ParsedGroup; readonly payloads: readonly unknown[]; readonly generation?: number; } | { readonly kind: "closed"; readonly group: ParsedGroup; readonly generation?: number; } | { readonly kind: "capabilities"; readonly group: ParsedGroup; readonly accepts: readonly string[]; } | { readonly kind: "hostOffline"; readonly group: ParsedGroup; } | { readonly kind: "pending"; readonly group: ParsedGroup; } | { readonly kind: "ignored"; }; /** * Error thrown by {@link parseInbound} when a frame is definitely a * group-fanout message but the receive envelope itself is malformed. */ export declare class FramingError extends Error { constructor(message: string); } /** Options accepted by {@link parseInbound}. */ export interface ParseInboundOptions { /** Reassembler instance for this subscriber connection. */ readonly reassembler: Reassembler; /** Forwarded to {@link parseGroupName}. */ readonly groupValidation?: ParseGroupNameOptions; } /** * Decode one inbound Web PubSub frame (already JSON-parsed) into a structured * {@link InboundResult}. Non group-fanout frames are `kind: 'ignored'`; * malformed group-fanout frames raise a {@link FramingError}. */ export declare function parseInbound(frame: unknown, options: ParseInboundOptions): InboundResult;