> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Protected tables

> A labelled, erasable or expiring table keeps only tokens of its indexed fields at the store. What it answers, what the store sees, and what it costs.

A table is **protected** when any of its facts can sit at a non-public place
or carry its own erasure unit. The store that holds a protected table sees its
structure, never its values: each index keeps a token of its fields, not the
fields. A protected table answers every lookup that fixes an index's fields by
equality. Other shapes need a bound, or a declared disclosure.

## What makes a table protected

A table is protected when it:

* carries a label other than `label.public`: a label, a label family, a
  `family.and(label)`, a fact rule (`label.field`, `family.field`) with any
  non-public outcome, or a [field label](https://docs.bijection.com/access/labels.md#field-labels) such as
  a field sealed with `label.seal(type)`;
* is `erasable`; or
* declares a `lifetime`.

A table with no label (or `label: label.public`), not erasable and with no
`lifetime` is clear. A clear table's indexes keep their fields in order at the
store, and every selection in [Indexes](https://docs.bijection.com/database/indexes.md) works on it.

## Orders that keep tokens

Every order of a protected table keeps a token instead of its fields: each
`index` entry, each `unique` set and the key. A token is a keyed hash, drawn
from a key the installation's custody holds, of the order's values. It is
scoped to the installation, the table, the index and the place the fact sits
at (its label, or its member of a family). Within one place, equal values give
equal tokens. Tokens at two places never match.

Structural fields stay clear: the fact's id, a series' `at` (and the `at` of
its marks and dirty spans), and a timeline's `validFrom` and `validTo`. An
order that leads with them keeps them clear and in order, and an order made
only of them is clear.

## What a protected table answers

```ts bijection/orders.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { label, role, t, table } from "@bijectionhq/bijection";

export const sales = label();
export const clerk = role({ clear: [sales] });

export const orders = table(
  { number: t.string, customer: t.string, total: t.decimal, placed: t.instant },
  { label: sales, unique: [["number"]], index: [["customer"], ["customer", "placed"]] },
);

export const stock = table(
  { warehouse: t.string, sku: t.string, onHand: t.number },
  { key: ["warehouse", "sku"], label: sales },
);
```

| Read | Verbs | Served by |
| - | - | - |
| `orders(key)`, `orders({ number })` | Every verb | The fact id, or an exact token lookup |
| `orders.where({ customer })`, `orders.where({ customer, placed })`: every field of an index fixed by equality | `get`, `has`, `list` with `.first(n)` or `.atMost(n)`, `page`, `count` | An exact token lookup |
| `orders.where({ customer }).by("placed")`, `orders.where({ customer, placed: { from, to } })`: a partial equality, a range or an order | `ctx.list(selection.atMost(n))` only | The kernel, opening at most `n` facts |
| The same with `.first(n)`, `ctx.page` or `ctx.count` | Refused: `ProtectedShapeUnsupported` | |
| `orders.first(n)`, `ctx.page(orders, …)`, `ctx.count(orders)`: the whole table of a minted key | Every verb | Fact ids, which are structural |
| `stock.byId()`: every fact of any table, in fact-id order | Every verb | Fact ids, which are random and structural |
| `stock.first(n)`, `ctx.page(stock, …)`, `ctx.count(stock)`: the whole table of a declared key, or `stock.where({ warehouse })` | `ctx.list(selection.atMost(n))` only | The kernel: the key's order keeps tokens |
| A series across its keys by valid time: `readings.where({ at: { from, to } })`, `readings.by("at")` | Every verb | A structural walk: the store reads the valid-time range, the kernel orders it |
| `stock({ warehouse, sku })` | Every verb | An exact token lookup |
| A declared [total](https://docs.bijection.com/database/capabilities.md#totals): `.total()` | `ctx.get` | Sealed tallies, merged in the kernel |
| `.match`, `.near`, `.region` | `ctx.list(… .first(n))` | Ranked in the kernel |

A refused shape names its three fixes:

```text theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
ProtectedShapeUnsupported: this table is protected, and its order over customer, placed keeps only a token of those fields at the store, so .first(n) cannot walk it in order. Use an order over t.accepted(), fix the protected fields by equality, use ctx.list(selection.atMost(n)), walk byId(), or use totals. For tables without erasable or lifetime facts, release: <release> on the index can disclose its ordered values.
```

`bijection check` lists the same shapes at their call sites, and the kernel
refuses them at the read. An order over `t.accepted()` merges the admitted
places at one Version, within the read's 64-place cap.
Fix the place in the frame or the selection. An index with a declared
`release:` can serve the order across places.

## Walk every fact: `byId()`

`table.byId()` selects every fact in fact-id order. Fact ids are random, so the
order discloses nothing and means nothing: the store walks it on every table,
protected or not, and `ctx.page`, `.first(n)` and `ctx.count` read it. Walk a
whole table this way to export, sweep or clear it, when the order does not
matter.

```ts bijection/sweep.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { query, t } from "@bijectionhq/bijection";
import { clerk, sales, stock } from "./orders";

export const everyStockRow = query({ under: sales, allow: [clerk], args: { cursor: t.cursor } }, (ctx, { cursor }) =>
  ctx.page(stock.byId(), { size: 100, cursor }),
);
```

Each page joins the read set like any page: a write into the range it read
conflicts with it.

## Walk by valid time: structural walks

A selection whose equality ends inside an order's leading structural fields,
and that ranges or orders by one of them next, fixes no protected field: a
**structural walk**. A series' valid-time order is `at`, then its key, so
`readings.where({ at: { from, to } })` and `readings.by("at")` select every
key's samples by valid time with every verb, a family series' within the
frame's member. The store reads the valid-time range, and the kernel opens and
orders its facts; the read set is the whole range. A selection that fixes `at` and ranges over a key field is not one: it
is the kernel's bounded evaluation.

## Read a small set whole: `.atMost(n)`

`ctx.list(selection.atMost(n))` returns every fact of the selection, filtered
and sorted, or refuses `Limit` (reason `SelectionOverBound`) when the selection
holds more than `n` facts.

```ts bijection/history.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { query, t } from "@bijectionhq/bijection";
import { clerk, orders, sales } from "./orders";

export const history = query({ under: sales, allow: [clerk], args: { customer: t.string } }, (ctx, { customer }) =>
  ctx.list(orders.where({ customer }).by("placed").descending().atMost(200)),
);
```

The kernel opens at most `n` candidate facts. It takes them from an exact
token lookup on an index whose fields are exactly the selection's equality
fields: `["customer"]` here. Without such an index, it takes them in the
table's structural order (fact id, or valid time on a series or timeline), and
refuses once it passes `n`. Every candidate joins the read set, so a write to
any of them conflicts with the read. Declare the equality-only index each
bounded selection starts from.

## Expose an order to the store

Declare `store: "clear"` with a review message on an index to let the store
page, range and sort its listed fields at their existing place. The lock records
each exposure on an `exposed` line. The deployer's live grants must clear every
label outcome of the table. App readers still need clearance for the fact's label.
Erasable and lifetime tables keep their orders sealed, as do tables placed
at members of erasable families.

```ts bijection/tickets.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { label, query, role, t, table } from "@bijectionhq/bijection";

export const ops = label();
export const agent = role({ clear: [ops] });
export const tickets = table(
  { queue: t.string, opened: t.instant, summary: t.string },
  { label: ops, index: [{ fields: ["queue", "opened"], store: "clear", message: "The store orders tickets by queue and opening time" }] },
);

export const latest = query({ under: ops, allow: [agent], args: { queue: t.string } }, (ctx, { queue }) =>
  ctx.list(tickets.where({ queue }).by("opened").descending().first(20)),
);
```

The store sees `queue` and `opened`. The fact body, including `summary`, stays sealed.
For a ranked text projection, declare `t.text({ store: "clear", message })` on
the field. The store can read the ranked copy of that field and derive postings
and corpus statistics. Other fields retain their existing protection.

For an erasable table or a table with a lifetime, the ordered values stay
sealed under each fact's unit. For a range or sort over sealed values use
`ctx.list(selection.atMost(n))`. Fully bound equality lookups and structural
walks can still use their indexes.

For tables without these per-fact erasure obligations, a table with `presence: { label: label.public, field, release }` has this copy
without declaring it. Each index whose fields are all in `presence.field`, in
the key or structural is kept as an ordered copy through `presence.release`.
That is how an index over a public presence field serves public selections
([Presence below the fact](https://docs.bijection.com/access/labels.md#presence-below-the-fact)).

On a non-closable table, the same declaration can expose a vector, a spatial
index, or a total. Use `t.vector(n, { store: "clear", message })`, the
spatial index entry with `store: "clear"` and `message`, or the same options
on a `total` entry. The lock lists what each projection discloses. Vector
projections expose the embeddings and filter values, and embeddings can
disclose their source text. Spatial projections expose geometry, location
cells, and partition values. Clear totals expose group keys and running
counts and sums. Comparing consecutive totals can disclose individual
contributions. On a protected table, the original fact body stays sealed.

## Share a unique claim: `release`

A field list such as `unique: [["email"]]` claims the tuple at the row's Place.
The object form names a specific family stem and a Release for the claim
verdict. Each judgement discloses `taken(k)` for a key a writer names at
that instant. A request with several candidate keys in one shared namespace
can learn the single verdict for the group. The verdict omits the holder,
member and failing tuple. A shared bound discloses `remaining ≥ r` for the
declared reserve it checks. The lock prints those predicates.

Cross-place uniqueness is a membership oracle. A shared bound is a
threshold oracle over the set of reserves printed in the lock.

Bound each shared claim or bound's release with a
[rate guard](https://docs.bijection.com/access/disclosure.md#guard-a-disclosure) over its disclosure
records. Each answer is one judgement at the writer's exact commit place, for
its acting principal and that release. One audit records the judgement at the
asking label. One blind record at the source names the release, outcome,
prober and asking label. The source record omits the key and reserve. Every
signed-out call is its own principal, so a guard that counts per principal
does not bound a public form's availability check: count across principals,
size the bound for the traffic, or check after sign-in. Once the guard's
window holds its limit, the request is refused `Forbidden`.

Use a registered request for a direct client or operator write that receives
the verdict. A named-world request settles its session receipt in Root at the
deciding label and advances the named world on success. A running task,
landing or unfunded inbox delivery can settle its own result as part of the
decision.
A registered reply remains tied to the original decision. A retry checks the
current claim declaration and Release, and that the function's live grants
still carry the release.
Declare the verdict Release to resolve `SharedClaimReleaseMissing`, or use
Place-local uniqueness.

```ts bijection/profiles.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { label, release, t, table } from "@bijectionhq/bijection";

export const tenants = label.family(t.string);
export const handleTaken = release({
  from: tenants.all,
  to: label.public,
  message: "A writer can test whether any handle it names is taken",
});

export const profiles = table(
  { handle: t.string, bio: t.string },
  {
    label: tenants,
    unique: [{ fields: ["handle"], scope: tenants.all, release: handleTaken }],
    index: [{ fields: ["handle"], across: tenants.all }],
  },
);
```

The index cover serves the stem-cleared handle lookup. Omit it when the
application only needs to reserve handles. Use an app-owned registry for an
installation-wide namespace.

## What the store sees

The store holding a protected table sees:

* one token per indexed tuple at each place. Equality, frequency and the
  number of facts within one place are visible; no token matches across places;
* random fact ids, commit stamps, valid-time bounds, and the partitions facts
  sit at;
* clear due instants of scheduled tasks, timed lowerings included;
* sealed fact bodies, and sealed tallies for totals;
* the clear values of a reviewed store exposure.

Unexposed orders keep their values sealed. The store also observes ciphertext
lengths and each request’s access patterns, including ranges, tokens and conflicts.
At places whose token key survives erasure, retained tokens stay equality-linkable
within their path and place until physical reclamation. The store contract places
no time bound on reclamation.

## What it costs

* **Writes.** Each indexed write draws one token from custody per order and
  place.
* **Bounded reads.** `.atMost(n)` opens up to `n` facts in the kernel, and each
  of them joins the read set.
* **Totals.** A total merges sealed per-fact contributions when it is read.
* **Rankings.** A reviewed text exposure can rank in the store. Sealed
  text, vector and spatial paths rank in the kernel.
* **Exposure.** The lock records the values disclosed by each projection.

## Choose a shape

* Fix every field of an index by equality where you can, and give each lookup
  its own index: `["customer"]` beside `["customer", "placed"]`.
* Read a small set whole with `.atMost(n)`: a customer's orders, a ticket's
  comments.
* Keep counts and sums as a declared [total](https://docs.bijection.com/database/capabilities.md#totals),
  not `ctx.count`.
* Walk a whole table with `byId()` when its order does not matter, and a
  series across its keys by valid time.
* Declare an index release only over fields you would publish: queues and times, not
  names or amounts.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.