Skip to content

Client-side DO API

createRpcServer(instance, methods?, options?)

Section titled “createRpcServer(instance, methods?, options?)”

Creates a WebSocket RPC server around a Durable Object. Forward fetch and webSocketMessage to the returned server. Restrict the exposed surface with an explicit readonly method list.

Derives the callable RPC shape from a target type while excluding lifecycle methods such as fetch.

The server helper invokes an exposed method and broadcasts its event without an incoming browser request. Use it for alarms or DO-to-DO activity that should reach subscribers.

Low-level WebSocket client factory. It manages requests, a bounded pre-connect queue, reconnects, retries, and subscriptions.

High-level transport with URL resolution per object ID:

const transport = createDOTransport<MyRpc>({
baseUrl: (id) => `wss://api.example.com/objects/${id}`,
});
transport.client(id);
transport.subscriptions(id, partialHandlers);

Builds a client and registers a complete method-handler map.

createManagedSubscriptionClient<TRpc>(client, handlers?)

Section titled “createManagedSubscriptionClient<TRpc>(client, handlers?)”

Wraps an existing realtime client with partial handlers and returns one managed session with client, setHandlers, setHandler, unsubscribe, and connection lifecycle hooks.

Builds reusable global and per-method serialization profiles for response and event result values. Configure the same profile on client and server.

Wraps a server-side Durable Object stub with method middleware and result deserialization. This is separate from DO Transforms and belongs to the Client-side DO RPC stack.

createCollectionSyncHelpers<TRpc, TRecord>(options)

Section titled “createCollectionSyncHelpers<TRpc, TRecord>(options)”

High-level builder that collocates optimistic, outbound, and inbound behavior and returns typed mutation functions.

createOptimisticActionMetadata(method, ...args)

Section titled “createOptimisticActionMetadata(method, ...args)”

Creates typed collection metadata for an optimistic RPC action.

createTanstackCollectionFromClient<TRpc, TRecord>(options)

Section titled “createTanstackCollectionFromClient<TRpc, TRecord>(options)”

Low-level builder returning TanStack DB mutation handlers and subscription handlers.

Legacy declarative CRUD client integrating TanStack DB and TanStack Query. It remains available for compatibility; prefer the focused transport and sync helpers in new code.

Clients expose:

  • onStatusChange with connecting, connected, and disconnected states.
  • onRetry for request retry diagnostics.
  • onReconnect for application-level re-bootstrap behavior.
  • subscribe and subscribeAll for method events.

Always call returned unsubscribe functions when the owning UI or service scope is disposed.