> ## 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.

# Constraints and state machines

Declare an invariant where the host can enforce it:

* **Field types** (`t.*`) refuse a fact that breaks them with `Invalid`.
* **`unique: [["number"]]`** refuses a second fact with the same field set
  (`Exists`), and makes the set a point: `invoices({ number })`.
* **`machine: { field, initial, edge }`** names the states one field may
  hold and the edges it may change along. The host refuses any other change
  on every write. An edge with `due: "<instant field>"` is taken when that
  instant arrives, exactly once.

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

export const requests = table(
  { state: t.one("open", "approved", "lapsed"), lapsesAt: t.maybe(t.instant) },
  {
    machine: {
      field: "state",
      initial: ["open"],
      edge: {
        approve: { from: ["open"], to: ["approved"] },
        lapse: { from: ["open"], to: ["lapsed"], due: "lapsesAt" },
      },
    },
  },
);
```

For a rule that involves other facts, read what it depends on and write in
the same mutation: a strict write's assumption and every read join the read
set, so a concurrent change that falsifies them refuses or retries the
transaction. For a rule that must hold for every writer, declare a
[guard](https://docs.bijection.com/access/guards.md): `forbid(act.write(requests), { where, message })`.


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