Skip to main content
Use the generated TypeScript client in browsers, servers, and scripts. Its app export gives the callable references and its connect carries the reviewed pins and runtime value schemas.
apps/main/src/client.ts
See Typed clients and the contract for setup.

Run a query

apps/main/src/latest.ts
client.query(fn, args) runs the query once. Leave out the arguments when the query declares none.

Watch a query

apps/main/src/follow.ts
client.watch(fn, args) runs the query and answers a new Result each time its value changes. A watch at a specified world or valid instant yields once and ends. Call stop() to end one watch or await client.close() to end all watches from the client and its framed clients.

Run a mutation

apps/main/src/add.ts
client.mutate(fn, args, { once, optimistic, seen }) runs the mutation as one transaction. Its identity is once: the same once and arguments answer the original result instead of running twice. When you give none, the client mints one for the call. See Retries and read-your-writes.

Results

Every client verb answers a Result. Check result.ok before reading the value or handling a refusal.
  • value is what the function returned. A committed mutation also carries its commit version. Pass it as seen to read your own writes.
  • code is one of the function’s declared refuses codes, or a host code. It is typed: added.code above is a HostCode, since add declares no refuses; with refuses: { EmptyNote: null } it is "EmptyNote" or a HostCode.
  • reason is the precise cause when the host names one.
  • message is the sentence the caller is entitled to read. Show it as it is.
  • guard is the path of the guard that refused, on Forbidden.
The host codes are a closed set: A function open only to role.anyone or role.signedIn is entered through the class grant the program issues at install, which clears only the public label. If its under requires more clearance, entry refuses Disallowed with reason NotCleared. Admit such a function through a role that clears the label.

Authenticate

connect(url, { token }) takes an auth adapter for a browser session, or a fixed token for a server or a script. A client without token calls as the signed-out principal.
apps/main/src/server.ts
Make one client per identity. See Connect and authenticate for the WorkOS AuthKit, Clerk and Bijection Auth adapters.

Connect options

client.connection() reports the live connection that watches and optimistic edits use: { connected, everConnected, connections, retries }, opening it if it is not open. Show it as an offline banner: connected false twice in a fact with the same connections count is a lost connection, not a reconnect. For a script that deliberately follows the serving interface, use the raw connector with contract: "discover". Pass api("orders.place") to call a path dynamically. Its answer is a decoded wire value, with stored Files represented by their keys. connect({ transport, contract: "discover" }) runs the same client over a ClientTransport you supply instead of a URL, for example inside an MCP view. A transport that sets frames: true receives each call’s frame, and one with trial serves client.trial.