Client-side DO API
Server
Section titled “Server”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.
RpcFromTarget<T, Excluded>
Section titled “RpcFromTarget<T, Excluded>”Derives the callable RPC shape from a target type while excluding lifecycle methods such as fetch.
callAndEmit(method, args)
Section titled “callAndEmit(method, args)”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.
Browser transport
Section titled “Browser transport”createDOClient<TRpc>(options)
Section titled “createDOClient<TRpc>(options)”Low-level WebSocket client factory. It manages requests, a bounded pre-connect queue, reconnects, retries, and subscriptions.
createDOTransport<TRpc>(options)
Section titled “createDOTransport<TRpc>(options)”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);createSubscriptionClient<TRpc>(options)
Section titled “createSubscriptionClient<TRpc>(options)”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.
Result transforms
Section titled “Result transforms”createRpcTransforms<TRpc>()
Section titled “createRpcTransforms<TRpc>()”Builds reusable global and per-method serialization profiles for response and event result values. Configure the same profile on client and server.
createStub(rawStub, options)
Section titled “createStub(rawStub, options)”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.
Collections
Section titled “Collections”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.
createDeclarativeDoCollectionClient(...)
Section titled “createDeclarativeDoCollectionClient(...)”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.
Connection lifecycle
Section titled “Connection lifecycle”Clients expose:
onStatusChangewithconnecting,connected, anddisconnectedstates.onRetryfor request retry diagnostics.onReconnectfor application-level re-bootstrap behavior.subscribeandsubscribeAllfor method events.
Always call returned unsubscribe functions when the owning UI or service scope is disposed.