Transactional views
A transactional view groups the objects that change together under one key.Customer with key acme holds that customer, its invoices, tickets, and notes. Reads and actions on a view instance see a consistent, up-to-date state, and an action’s edits commit together.
ontologies/crm/customer.ts
materialized: "cell" and a column named after the view key. The root table is keyed by it. An object lives in at most one view. Ontology-owned objects, like CustomerNote, belong to the view that lists them in dependsOn.
Reads
A read in a view gets the view instance asview, keyed by view.key.
readsis a hard limit. A handler sees only the objects and properties it declares.prop(Customer.internalNotes)tags an output field with its property. Callers who may not read that property get it unset. See Field masking.ctx.sqlruns read-only SQL over the view instance, with objects as tables:ctx.sql('SELECT sum(amount) AS total FROM Invoice WHERE status = ?', "open").
ctx.lake.query. It is eventually consistent, seconds behind actions. It must scope its own rows, from ctx.principal, when that matters.
AccountTeam(from_key, to_key).
Actions
An action changes one view instance in a transaction.ctx.update,ctx.create, andctx.deletechange ontology-owned objects and properties.ctx.require(condition, message)andctx.fail(message)fail the action. Nothing is written.ctx.principalsays who is asking, and which actors act for them.editsis a hard limit, likereads.- Set
idempotency: (input) => input.requestIdso a repeat with the same key, by the same caller, replays the first outcome.
Call third parties
Actions never call third parties during the transaction.ctx.deferredFetch records the request, and Tilde sends it after the action commits, with retries.
Name one of the ontology’s connections as auth. Tilde adds the account’s current credentials when it sends the request. Handlers never see them.
ctx.deferredFetch is fetch-compatible, so you can pass it to an SDK as its fetch. Its then option runs another action of the same view with the response, for example to store an id the third party assigned. Reads can make live calls with ctx.fetch(url, init, { auth: connections.github }).
Pending values
An action can’t edit a property the source owns, such as a tier in Stripe. Instead, it asks the source to change it, and marks the expected value as pending: list the property in the action’spending, and pass the value to ctx.deferredFetch. Reads show it until the change comes back through the pipeline.
Secrets and settings
Declare per-environment values inenv, with secret() and setting(default), and read them from ctx.secrets and ctx.settings. Prefer connections for third-party accounts. See Settings.
Realtime views
A realtime view is a read whose result is pushed to subscribers whenever it changes. A view-scoped one re-runs after every commit in its view instance. One withwatch runs across all data, and re-runs when a watched object changes.
ontology({ realtime }). Spaces subscribe with useRealtime. See Spaces.
List views
A list view keeps a window of rows from the top of an ordered list, such as a grid, and pushes only what changed. Give itrow, key, order, and rows instead of output and handler:
- A subscriber sends
{ query, limit, resume }, withlimitup to 1,000. - The first update holds the window (
reset). Later updates hold only the rows that entered or changed, each with its index (upserts), the keys that left (removes), whether more rows follow (more), andsummarywhen it changed. - On Postgres storage, a commit to a watched model re-reads only the keys it changed, as the subscriber, so Cedar and masking still apply. Anything else re-reads the window.
- A window that loses a row is topped up from below.
- Widening is a new subscription with the larger
limitand the last update’sresume: only the new rows arrive. - Every watched model’s key is the row’s
key.
Handlers as agent tools
Every read and action becomes an agent tool with the handler’s name,description, and input schema. A tool for a handler in a view takes { "key": "<view key>", "input": { ... } }. Other tools take { "input": { ... } }.
Write each description for the agent that calls it. Give agents a view-less read that lists keys, such as listCustomers in the project guide, so they can find the instance to act on. To connect an agent, see Give an agent the ontology.