/** * Conn: one side of a two-party Cap'n Proto RPC connection (vat-to-vat). * * Owns the four RPC tables (questions, answers, imports, exports) and the message * dispatch loop. Wraps a raw WebSocket directly, or any Transport implementation: * * // server * new Conn(ws, { main: new Calculator.Server({ ... }) }); * // client * const conn = new Conn(ws); * const calc = conn.bootstrap(Calculator); * * The bootstrap capability is supplied at construction (not post-hoc) so a Bootstrap * message can never race main registration. */ import { Payload } from "../std/rpc.capnp.js"; import { SchemaAnnotation } from "../annotations"; import { Struct } from "../serialization/pointers/struct"; import { Client, Method, ParamsInit, RemotePromiseCtor } from "./client"; import { RemotePromise } from "./remote-promise"; import { Server } from "./server"; import { Transport, WebSocketLike } from "./transport"; /** A pending incoming call; kept until the peer sends Finish. */ export declare class Answer { readonly payloadPromise: Promise; rejectPayload: (err: Error) => void; resolvePayload: (payload: Payload) => void; constructor(); } /** A pending outgoing call; resolved by the peer's Return. */ export declare class Question { readonly conn: Conn; error?: Error; readonly id: number; payload?: Payload; readonly promise: Promise; state: "pending" | "rejected" | "resolved"; private _reject; private _resolve; constructor(conn: Conn, id: number); /** A client for the capability at `transform` in this question's (resolved) answer. */ clientForTransform(transform: number[]): Client; /** A client for `transform` in this answer, callable before the answer arrives. */ pipelineClient(transform: number[]): Client; reject(err: Error): void; resolve(payload: Payload): void; } /** A Call message's target, prior to encoding. */ export type CallTarget = { importedCap: number; } | { promisedAnswer: { questionId: number; transform: number[]; }; }; export interface ConnOptions { /** The bootstrap capability offered to the remote vat. */ main?: Server; /** Called when the remote sends an Abort or the transport drops unexpectedly. */ onError?: (err: Error) => void; } /** The static surface of a generated interface class, as far as Conn is concerned. */ export interface InterfaceCtor { readonly _capnp: { annotations?: SchemaAnnotation[]; displayName: string; id: string; }; readonly Client: new (client: Client) => C; } export declare class Conn { readonly transport: Transport; private readonly answers; /** * Serializes call delivery: every incoming call begins execution in arrival order, * even when its target resolves asynchronously (E-order for the two-party case). */ private deliveryChain; private readonly exportIds; private readonly exports; /** * Import entries use WeakRef so that GC can reclaim dropped capability clients. * FinalizationRegistry sends a Release for any import whose Client was collected * without an explicit dispose() — a best-effort safety net, not a replacement * for explicit disposal. */ private readonly imports; private readonly main?; private nextExportId; private nextQuestionId; private readonly onError?; private readonly questions; private closed; /** * Fires when an import Client is garbage collected without being disposed. * Sends a Release for the import's refcount as a best-effort cleanup. */ private readonly registry; constructor(transport: Transport | WebSocketLike, opts?: ConnOptions); /** Ask the remote vat for its bootstrap capability, returning a typed client for it. */ bootstrap(InterfaceClass: InterfaceCtor): C; close(): void; /** Release one import table entry, notifying the peer. Called by Client.dispose. */ releaseImport(id: number): void; /** Send a Call for `method`; the returned RemotePromise resolves with its results. */ sendCall

>(target: CallTarget, method: Method, paramsFunc: ParamsInit

| undefined, PromiseClass: RemotePromiseCtor): A; private abort; /** Turn a received Payload's capTable into clients on the message's cap table. */ private decodeCapTable; private dispatchCall; /** Write the message's cap table out as a Payload.capTable of CapDescriptors. */ private encodeCapTable; private exportClient; private handleBootstrap; private handleCall; /** Echo a sender-loopback Disembargo back as receiver-loopback, per the spec. */ private handleDisembargo; private handleMessage; private handleRelease; private handleReturn; private importClient; private newQuestion; private send; private sendRelease; }