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

# Frames and trials

> Call as a principal, under a label, in another world or at a valid instant, and try a call without committing it

Every call runs in a frame: who acts (`as`), the label it happens under
(`under`), the world it reads (`in`) and the valid instant (`at`). A client's
frame methods return a new client in that frame and share the original
connection setup. Get refs from `api<typeof App>()`. The client that runs the
call, or the nearest `<Bijection>` for a hook, supplies the frame.

| Method | Frame field | Takes |
| - | - | - |
| `client.under(label)` | `under` | A label reference, or one member of a family: `app.tenant.of("acme")`. |
| `client.in(world)` | `in` | A `Branch` or a `Version`, as a query's value gave it. |
| `client.at(instant)` | `at` | A `Temporal.Instant`. The default is now. |

The methods chain: `client.in(version).at(instant)`.

## Under a family member

A function declared `under: tenant`, where `tenant` is a `label.family`,
takes its member from the caller's frame. Choose the member on the client:

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { api, connect } from "@bijectionhq/bijection/client";
import type App from "../../../bijection/app";

const app = api<typeof App>();
const client = connect(import.meta.env.VITE_BIJECTION_URL, { contract: "discover", token: auth });
const acme = client.under(app.tenant.of("acme"));

const invoices = await acme.query(app.billing.open);
```

`under` narrows what the call may read and commit. It never adds authority:
the caller's grants must clear `tenant.of("acme")`, or the call refuses
`Disallowed`. The member reference is built from its family path and member key.

## Read related queries at one version

Two queries run separately may answer from different states. Read them at
one version to compare them:

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
const pinned = client.in(version);
const [inventory, shipments] = await Promise.all([
  pinned.query(app.inventory.summary),
  pinned.query(app.shipments.summary),
]);
```

A query reads `ctx.frame.version` and can return it as a `t.version` value.
A read in an older version still needs the caller's current grants, and the
version must still be readable: within the table's `history`, or pinned.

## In a branch

`client.in(branch)` reads and writes a branch: a writable world over a
version, made by `ctx.branch` in a mutation. Only the head is watched live: a watch
with `in` or `at` answers once, for the world and instant it names. Landing the branch is `ctx.land`, a grave act inside a mutation; see
[Branches](https://docs.bijection.com/branches).

In React, nest a framed client for the subtree that works in the branch:

```tsx theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
<Bijection client={client.in(branch)}>
  <Proposal />
</Bijection>
```

## At a valid instant

`client.at(instant)` reads series and timelines at that instant, as
`.at(instant)` does inside a function. A function reads it as
`ctx.frame.at`, which is `null` for a call at the present.

## Try a call: `trial`

`client.trial(fn, args)` runs a query or a mutation in a discarded world on
hosted and standalone installations. It answers what the call would have done:

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
const tried = await client.trial(app.orders.place, { sku, quantity: 2 });

tried.result;     // the Result the call would have answered
tried.writes;     // [{ verb, table, key, before, after }]
tried.tasks;      // [{ target, args, due }]
tried.validUntil; // the instant the answer is valid until, or null

if (!tried.result.ok && tried.result.code === "Forbidden") {
  console.log(`refused by the guard ${tried.result.guard}: ${tried.result.message}`);
}
```

A trial uses the presented credential's admitted authority and the call's
`allow`, grants, labels and guards. To preview with delegated authority,
present the agent's bearer. A trial's answer is labelled by everything it
read. A later real call is decided again against the state it then reads.
[Agent bearers](https://docs.bijection.com/operate/installations/credentials.md#agent-bearers-for-delegated-calls)

`validUntil` is the first instant at which time alone could change the
answer: a grant's `until`, a task's `due`, the next boundary of a fact read
at the present. A call at the same version whose commit lands before it is
decided as the trial was. It is `null` when nothing time-dependent bounds the
answer.


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