Skip to main content
Install the CLI, then create the starter:
create writes the notes starter and installs its frontend packages with the package manager on your PATH. It ends with the one command to run next:
bijection dev starts a local deployment, with no account, and serves the page. Open the app URL it prints, add a note, and open a second tab: the list updates live in both. Anyone who opens the page reads and writes the notes, because the notes table has no label and its functions allow role.anyone. Each note lasts a day. A backend-only project uses bijection create my-backend --template bare; the CLI manages its backend toolchain.

Find the code

bijection/notes.ts declares the table, query and mutation below.
bijection/notes.ts
  • A query reads and commits nothing. A mutation runs as one transaction: its writes and its tasks commit together or not at all.
  • items.by("written").descending().first(20) is a bounded selection: the latest 20, and ctx.list reads all of it. .atMost(n) reads all of a small selection, or refuses when it holds more. A sum or count over many facts is a declared total, read with ctx.get. The table’s index serves the order; a selection that no index serves is an error naming the index to add.
  • ctx.insert(items, fact) mints the key and returns it.
  • The table’s lifetime: { hours: 24 } makes each note expire one day after acceptance.
bijection/app.ts places the module in the app tree:
bijection/app.ts
No declaration takes a string name. The table is notes.items and the functions are notes.recentNotes and notes.add. A function with allow is exposed at its path. A function without allow is internal: only the app’s own code reaches it.

Read the page

The page imports app and connect from the generated browser client. bijection dev writes it from the app’s exposed schemas and contract digests before starting the frontend. A renamed function or changed argument type shows up in the frontend’s type checking.
apps/main/src/main.tsx
useWatch holds a live watch of the query and answers a Result, or undefined while it loads. useMutation answers a function that runs the mutation and returns its Result. Every call ends as { ok: true, value } or { ok: false, code, message }. The code is an app code the function declares in refuses, or a host code such as Disallowed or Absent. An expected refusal never throws. The <Bijection client={client}> provider at the root of the page gives every hook its client. React covers the hooks in full.

Refuse an empty note

In bijection/notes.ts, make if (!text.trim()) return ctx.refuse("EmptyNote", "Write something."); the first line of add’s handler. Your editor answers Undeclared: add EmptyNote to this function's refuses, and bijection dev, which checks the source on every save, prints the same sentence at its path:line:col. Declare the code beside args:
bijection/notes.ts
ctx.refuse(code, message) ends the transaction with an app code, and the caller receives it as a Result. In the page, added.code is now "EmptyNote" or a host code, and only a host code carries a reason, its precise cause.

Call it from the terminal

The CLI speaks the same verbs at the same paths:
trial runs a call in a discarded world and reports its result, writes and tasks. Every verb takes --as (on whose behalf), --under (the label), --in (a version or branch) and --at (the valid instant). mutate prints the once it sent: if the reply is lost, run the command it prints, which asks again with the same once.

Test it

vitest.config.ts is defineConfig(vitestPreset()), and the test needs nothing else:
tests/notes.test.ts
kernel(app) runs the real kernel in memory, with one installation of the app tree. k.as("person:alice") is the client a browser signed in as alice gets, and its calls answer a Result. The kernel itself acts as the installation and holds the clock. k.advance moves past the table lifetime so the next read returns no notes. Test library covers the rest.

Protect the notes

To let only members read and write the notes, give bijection/notes.ts a label and a role, label the table and run every function under the label:
bijection/notes.ts
A labelled fact shows nothing to a caller whose role does not clear its label. under: team is the label a function runs under, so it may read and write the notes; allow: [member] lets in only callers who hold member. A labelled table is protected. The written field is stamped at acceptance, so the same newest-first selection works after the table gets a label.
bijection/bijection.lock lists every path with its allow and under, the grave acts it can perform and the guards on it. The diff names the label on the table, the new role, and under and allow on each path, and nothing else. Commit it: bijection check and bijection deploy refuse a lock that no longer matches the source. The lock is the reviewable answer to “what can a caller reach?” No one holds member yet, so the page now answers Disallowed. Protect an app adds the membership library, which grants the first owner and lets owners invite members, and signs the page in. For the local browser, select the same person you grant member to using bijection dev --as person:alice and the development client adapter.

Deploy the app

Sign in to your Bijection account, then publish the checked source to a deployment:
An installation is named <project>:<name>. Deploy installs exactly what the committed bijection/bijection.lock states, prints the table changes it makes, and refuses a stale lock. The command prints a retained request handle. If its reply is interrupted, inspect or resume that same request:
Installations covers configuration and deploys. To try code and data changes in a writable world, use a branch.

Continue

The customer workflow tutorial adds a feed from an external service, labelled customer data, roles and a rename sent to that service as a task whose result the app records.