import type { ActivityLog } from '../admin/activity-log.js'; import type { AdminConnectionSnapshot } from '../admin/types.js'; import type { AdminStore } from '../admin/admin-store.js'; import type { DwnServerConfig } from '../config.js'; import type { MessageProcessedHook } from '../message-processed-hook.js'; import type { RateLimiter } from '../rate-limiter.js'; import type { RegistrationStore } from '../registration/registration-store.js'; import type { ServerWebSocket } from 'bun'; import type { WsData } from '../http-api.js'; import type { Dwn, ProgressToken, SubscriptionListener } from '@enbox/dwn-sdk-js'; import type { JsonRpcId, JsonRpcSubscription } from '@enbox/dwn-clients'; /** Local ownership of a pending subscription; never serialized into JSON-RPC. */ export type SocketSubscription = { subscriptionHandler: SubscriptionListener; signal: AbortSignal; register: (close: JsonRpcSubscription['close']) => Promise; release: () => Promise; }; /** * SocketConnection handles a WebSocket connection to a DWN using JSON RPC. * It also manages references to the long running RPC subscriptions for the connection. * * With Bun's native WebSocket, the message/close/error events are dispatched by the * Bun.serve() websocket handlers in http-api.ts, which delegate to the public `message()` * and `close()` methods on this class. */ export declare class SocketConnection { private readonly socket; private readonly dwn; private readonly onCloseCallback?; private readonly maxInFlight; private readonly activityLog?; private readonly adminStore?; private readonly registrationStore?; private readonly serverConfig?; private readonly tenantRateLimiter?; private readonly messageProcessedHooks?; /** Unique identifier for this connection (for admin introspection). */ readonly id: string; /** Timestamp when the connection was established (for admin introspection). */ readonly connectedAt: number; private readonly heartbeatInterval; private readonly subscriptions; private isAlive; private isClosed; private closePromise?; constructor(socket: ServerWebSocket, dwn: Dwn, onCloseCallback?: () => void, maxInFlight?: number, activityLog?: ActivityLog, adminStore?: AdminStore, registrationStore?: RegistrationStore, serverConfig?: DwnServerConfig, tenantRateLimiter?: RateLimiter, messageProcessedHooks?: MessageProcessedHook[]); /** * Called when a pong is received (triggered by Bun's built-in ping/pong handling). */ pong(): void; /** * Checks to see if the incoming `JsonRpcId` is already in use for a subscription. */ hasSubscription(id: JsonRpcId): boolean; /** * Reserves an id before asynchronous validation or replay, keeping pending * and active subscriptions under the same cancellation and flow control. */ beginSubscription(id: JsonRpcId): SocketSubscription; /** * Closes and removes the reference for a given subscription from this connection. * * @param id the `JsonRpcId` of the JSON RPC subscription request. */ closeSubscription(id: JsonRpcId): Promise; private closeOwnedSubscription; /** * Acknowledges subscription events up to the given progress token, advancing * the flow-control window for the subscription. */ ackSubscription(id: JsonRpcId, cursor: ProgressToken): void; /** * Closes the existing connection and cleans up any listeners or subscriptions. */ close(): Promise; private closeConnection; /** * Log the error and close the connection. */ error(error: Error): Promise; /** * Handles a `JSON RPC 2.0` encoded message. * This is called by Bun's websocket message handler via http-api.ts. */ message(dataBuffer: Buffer): Promise; /** * Returns the number of active subscriptions on this connection. */ get subscriptionCount(): number; /** * Returns a serializable snapshot of this connection for the admin inspector. */ toSnapshot(): AdminConnectionSnapshot; /** * Sends a JSON encoded string through the WebSocket. */ private send; /** * Builds a `RequestContext` object to use with the `JSON RPC API`. */ private buildRequestContext; } //# sourceMappingURL=socket-connection.d.ts.map