# `Session.applyDocument`

> Contract 2.0.0 · package sha256 `a857eca95b35921109faf997094bb4192f12527d9d0fcd4be7e97f06425bad6e` · generated from `configurator-runtime.d.ts` by `services/onsite-scripter/scripts/build-contract-docs.mjs`; edit the source, not this file.

Method of [`Session`](Session.md) · inherited by [`testing.FakeSession`](testing.FakeSession.md) · stable · since 2.0.0 · called as `session.applyDocument`

```ts
applyDocument(document: ViewerDocumentJson, options?: SignalOption): Promise<ApplyReport>;
```

Replaces the page document layer (version 2). A configuration call, not an operation: it
carries no `op` or `cause`. Resolves once applied. A layer is refused key by key: a rejected
key sets `ok: false` and is reported in [`problems`](ApplyReport.problems.md), and the other keys still land ([`applied`](ApplyReport.applied.md)
lists them). Fires 'document:applied'.
Errors: a bad layer resolves `ok: false` with 'document-error' problems; it never rejects for
content. A failure inside the runtime while applying resolves `ok: false` too, with one
'apply-failed' problem (`layer`, no `path`); it never rejects for that either.
Timing: a newer apply (yours, or the runtime's re-apply on an admin preview page) supersedes an
unfinished one. The superseded apply resolves `superseded: true` and changes nothing. Aborting
`signal` before the layer lands rejects AbortError and leaves the page layer, [`session.document`](Session.document.md)
and [`info().document`](InfoReport.document.md) as the last apply that landed. Once it has landed, an abort has no effect.

## Options

| Option | Type | Default | What it does |
| --- | --- | --- | --- |
| `signal` | `AbortSignal` | undefined | Cancels this call; the member's JSDoc says what an abort does. |

## Abort (`signal`)

This call is a write (`SignalOption.signal`, [the kinds of call](../read-this-first.md#conventions)).

> A write: before the commit point it rolls back and rejects AbortError; after it, no effect, except that a running camera move stops where the last frame drew it (`CameraMoveOptions`).
>
> Through a `tx` the commit point is the transaction's: aborting a write still loading rejects AbortError and stages nothing (catch it: unobserved, it rolls the transaction back, spec section 6.1, O6); aborting one already staged unstages it, its paths keeping the latest other write to them as after a failed savepoint (O7), and its Promise stays resolved 'staged'.

## Generic-API test (spec 3.1)

| Rule | Result |
| --- | --- |
| 1. Neutral name | pass: `applyDocument` names no product |
| 2. A precedent | pass: a correctness rule (rows `G48`) |
| 3. Two apps, or labs | pass: 28 apps (ledger: app-04c2774145, app-0c773a4ee3, app-37356bf09f, app-378d190f1b, app-4762caacdc, app-4f16d2f6da, app-4fd23bc869, app-510d750508 and 20 more; fleet cross-check: app-04c2774145, app-37356bf09f, app-4762caacdc, app-4f16d2f6da, app-4fd23bc869, app-822bb9d6aa, app-8675b3225c, app-b362a81c85 and 13 more) |
| 4. The cheaper fix first | decided per need in Appendix B: rows `G48` at tier fix, stable (a member only where no rule, data, asset or app code serves the need) |
