Skip to main content
A label is an audience: who may know a fact. A table’s label is its facts’ audience. A function’s under is the label it runs under: a query answers under it, and a mutation commits under it. A frame may read a fact only if its clearance covers the fact’s label, and its writes carry the data they read to a label at or above under.

Declare a label

bijection/access.ts
label() takes no name: its name is its path in the app tree (access.finance). label.public is the label every principal may know; a table without label is public. a.and(b) is the audience that clears both a and b. A role’s clear lists the labels its holders may read and run under. A grant of the role holds under one label, and clears exactly that label for the frames it admits (see Roles and grants). Your code needs the clearance too: a frame clears a label only when both the caller’s grants and the function’s grants clear it.

One audience per key: families

label.family(keyType) declares one label per key. Members are erasable by default. Use label.family(keyType, { erasable: false }) for members that should be retired and have their facts deleted through ordinary writes. The table’s history horizon governs the retention of its deleted facts. Keep any personal data that must support erasure in an erasable table. Use family.of(key) with a literal or run-time key.
bijection/tenancy.ts
bijection/orders.ts
A family has no fixed size. Registering a member, ctx.register(tenant), mints a random, opaque tag <family>:<id> and gives the member capacity of its own (see System tables). The app keeps its own table from business keys to ids, and names the member tenant.of(id). Founding a member is the register right for the family, held by both the caller and the code (Found a family member). A founding runs at the public label and registers the member in its own step. A family’s options set how many and who owns each new member:
  • members: n caps how many are registered at once, charged at the public label. Past it a registration refuses Limit.
  • keyed: true also indexes members by a business key, ctx.register(family, { key }), at the family’s stem. The tag stays random, a fresh registration of a taken key refuses Exists, and erasing the member deletes the index entry. A keyed family declares presence: "public": whether a key is taken is a public fact.
  • founder: admin issues admin to the registrant under the new member in the same commit as registration (Initial owner).
A table labelled with a family keeps each fact at one member. It has no member column: the member is the frame’s. A function under: tenant takes its member from the caller’s frame, so a client picks the member it acts in:
A clerk is admitted in acme only through a grant held under tenant.of("acme"): ctx.grant(clerk, { to, under: tenant.of("acme") }). tenant.and(finance) joins the member with another label, both as a function’s under and as a table’s label. To read or write another member’s facts explicitly, address them with orders.of(tenant.of(key)); the read needs a frame that clears that member.

Share with a named person

Every principal clears its own member of the built-in label.principals family, with no role. A fact labelled by a field holding a principal is known to that principal alone: label.principals.field(name) labels each fact at the member its field names.
bijection/shares.ts
share runs at the public label and writes up into the named reader’s member with a blind put; mine runs under the caller’s own member, so a reader sees only what was shared with them. The key fields stay known at the public label. To share a whole function’s data with a person, grant them a role under their member: ctx.grant(viewer, { to: person, under: label.principals.of(person) }).

Choose the label by a field

label.field(name, cases, { otherwise, release }) labels each fact by the case its field holds, and family.field(name) by the family member its field names. Both combine with .and and .or. The field is a presence field, and a write that moves a fact to a lower case needs the release:

Field labels

A field can carry its own label, above or below its fact’s. Every read of the field is judged at the field’s label, like a fact.

Seal one field

A sealed field is a field labelled above its fact. label.seal(type) declares a field whose values carry the label:
A frame that clears the fact but not finance reads the fact with margin as a Sealed<Decimal>. ctx.open(sealed) sees the value inside a frame that clears its label; it moves nothing. Lowering a sealed value to a wider audience is a disclosure, through a release.

Presence below the fact

A field labelled below its fact is known to a wider audience than the fact itself. presence declares that lower label for the fact’s existence, its key and the listed fields:
ctx.has(salaries(employee)) answers at the presence label, so any frame learns whether the employee is listed, and an index over employee serves public selections. amount stays at salary. The fields listed in field stand under the standing release, whose from covers the fact label and whose to is within the presence label. salaries is a protected table: its orders keep tokens of their fields at the store. Under a public presence label with a release, a declared index whose fields are all presence or key fields (index: [["employee"]]) is kept clear and in order instead, as if it declared release: roster, so it serves every selection. The key’s own order answers exact lookups, salaries(employee). An index over amount would keep tokens: exact lookups, and ctx.list(selection.atMost(n)) for any other shape.

Label flow

Every read stays at or below the frame’s clearance, and every write goes up: it carries what the transaction read to a label at or above the function’s under. These checks live in one place. bijection check reports each one at its path:line:col with a sentence that says how to fix it, and the host enforces every one of them again at the act. Editors see them as check diagnostics; the TypeScript types check shape only (verbs, spec keys, value types, indexes), never flow. Any direct or runtime-assembled frame exceeding 64 root places also refuses CoverTooWide at entry before any store lookup. For example:
A commit selector can declare a maximum arity. Use teams.field("teamIds", { atMost: 16 }) for member arguments. The host checks the length before it joins the labels. Exceeding it refuses Invalid with reason ArityExceeded. The lock prints the read-place bound when the selector’s arity bounds it.

Eventual labels and timed lowering

To publish a fact at an instant, label it by a field and let a scheduled task change that field through a release. labelSwitch from @bijectionhq/library-label-switch builds this from a task and the release you name:
bijection/press.ts
  • Place embargo in the app tree: it holds embargo.lower, the mutation the task runs. embargo.at(ctx, key, instant) submits that task for one fact, due at the instant, and answers the task. Withdraw the task to cancel the lowering.
  • When the task runs, it moves stage from embargoed to published through lift. That one write is all it does, at the fact’s own place, and the use of lift is recorded as a disclosure. A fact no longer embargoed is left as it is.
  • The task decides through the scheduler’s grants that are still live when it runs. If the editor’s grant was revoked or expired in between, the lowering refuses and the story stays embargoed.
  • Nothing runs at the instant: the task can first commit at its due instant, and its wakeup resumes after a restart. List pending lowerings with sys.tasks.where({ target: embargo.lower }).
  • A task lowers a fact written in a branch within that branch.
  • If the lowering refuses, for example because the fact’s unique key is already taken at the lower label or the destination has no capacity left, the task settles with that refusal and the fact stays at its earlier label. Resolve the constraint, then schedule it again.
The lowering is an ordinary write, so it needs a commit and may complete after its scheduled instant. At any place and instant, at most one fact holds each unique key. Until the task commits, an observer who cannot clear editorial learns nothing of the fact beyond what its presence fields declare.

Reads validated by what they revealed

A transaction’s reads are validated at commit by the values they revealed. A change entirely above a reader’s label never aborts that reader, so a writer at a higher label cannot signal through conflicts. See How an act is decided.