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

# Design patterns

## Expose only what clients call

Give `allow` only to the functions a client calls. Everything else stays
internal: continuations, performers, reactions and helpers reached by
`ctx.call`. `bijection.lock` lists every path with its `allow`; review its diff like code.

## Keep authority in declarations

Say who may enter a function with `allow`, what it may see and write with
labels and `under`, and what the business forbids with
[guards](https://docs.bijection.com/access/guards.md). Attribute work to `ctx.frame.as.id`, the verified
principal; a principal named in the arguments is ordinary input.

## Let the write state its assumption

Pick the write by what it assumes. `insert` refuses `Exists`; `replace`,
`patch` and `delete` refuse `Absent`; `put` and `retract` assume nothing and
never refuse. A separate existence check before the write is a second read
with nothing to add.

## Share plain helpers

Keep reusable logic in ordinary functions. A helper that uses the context
takes `ctx` first: `Base` when it only reads (every function's context is
one), `MutationCtx` when it writes. Callers pass their own `ctx` without a
cast. Use `ctx.call` only when a separate function boundary is part of the
contract.

## Read time from the frame

Use `ctx.frame.now.entry` for the entry instant and `ctx.frame.at` for the valid
instant (`null` at the present). To judge the commit instant, read
`ctx.frame.now.before(t)`. For a change that must happen later, submit a task
with `due`.

## Keep outside work out of the transaction

A transaction does no outside work. Submit a task to a
[target](https://docs.bijection.com/functions/effects.md) and receive its result in a `then` continuation.
Give each submit a `once` that names the logical effect, so a retry returns the
original task.

## Commit a protected decision and a lower publication together

Enter the mutation under a label that clears every input to the decision,
using a grant that admits the entry there. Read the inputs and make the
decision in that frame. Put any lower publication in the same transaction
through a release declared by the writing function.

A reviewer enters at `review`. Approval updates the protected case and
writes the public projection in the same commit.
[Queued review](https://docs.bijection.com/functions/effects.md#submit-work-at-a-higher-label)

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

export const review = label();
export const reviewer = role({ clear: [review] });
export const cases = table(
  { request: t.string, ready: t.boolean, checked: t.boolean, approved: t.boolean },
  { key: ["request"], label: review },
);

export const approvals = table({ request: t.string, approved: t.boolean }, { key: ["request"] });
export const publishApproval = release({
  from: review,
  to: label.public,
  message: "Publish the request identifier when its review approves it.",
});

export const approveAndPublish = mutation(
  { under: review, allow: [reviewer], releases: [publishApproval], args: { request: t.string } },
  async (ctx, { request }) => {
    const record = await ctx.get(cases(request));
    if (record === null || !record.ready) return ctx.refuse("Invalid", "The case is not ready for approval.");
    await ctx.patch(cases(request), { approved: true });
    await ctx.put(approvals(request), { approved: true }, { release: publishApproval });
  },
);
```

The private read is checked when the higher transaction commits. The
reviewer sees its refusal if the case is unavailable or unready. The public
audience sees the approved projection through the named release. The
writing site's `release` right and disclosure guards govern that publication.
[Lowering effects](https://docs.bijection.com/access/disclosure.md#lowering-effects)

## Bound every read

End each listed selection in `.first(n)`, page the rest with `ctx.page`, and
let an index serve every selection. On a
[protected table](https://docs.bijection.com/database/protected-tables.md), end a partial, range or ordered
selection in `.atMost(n)` instead, or declare its index `ordered`. A watched query reruns whenever what it
read changes, so a small read is a cheap watch.


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