app export gives the callable references and its connect carries the
reviewed pins and runtime value schemas.
apps/main/src/client.ts
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 aResult. Check result.ok before reading
the value or handling a refusal.
valueis what the function returned. A committed mutation also carries its commitversion. Pass it asseento read your own writes.codeis one of the function’s declaredrefusescodes, or a host code. It is typed:added.codeabove is aHostCode, sinceadddeclares norefuses; withrefuses: { EmptyNote: null }it is"EmptyNote"or aHostCode.reasonis the precise cause when the host names one.messageis the sentence the caller is entitled to read. Show it as it is.guardis the path of the guard that refused, onForbidden.
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
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.