Sanity Library Reference Docs
    Preparing search index...
    interface InstanceSession {
        subscriptionDocuments: WatchSet;
        discardFieldPreview(target?: EditFieldTarget): void;
        editField(
            args: { mode?: EditMode; target: EditFieldTarget; value?: unknown },
        ): Promise<OperationResult>;
        evaluate(): Promise<WorkflowEvaluation>;
        fireAction(
            args: {
                action: string;
                activity: string;
                params?: Record<string, unknown>;
            },
        ): Promise<OperationResult>;
        previewField(
            args: { mode?: EditMode; target: EditFieldTarget; value?: unknown },
        ): void;
        tick(): Promise<OperationResult>;
        update(docs: LoadedDoc[]): void;
        updateDocument(doc: LoadedDoc): void;
        updateGuards(guards: readonly MutationGuardDoc[]): void;
    }
    Index

    Properties

    subscriptionDocuments: WatchSet

    The watch-set to feed via InstanceSession.update, derived from the held instance. Recompute after the instance changes (a new stage changes it).

    Methods

    • Drop staged previews for one target — or all, when omitted — reverting the projection to the held committed state on the next evaluate.

      Parameters

      Returns void

    • Edit a declared-editable field against the held content (the generic edit seam), gated on the held projection, then cascade. Stages its own optimistic preview on entry and drops the target's previews when the commit settles — success lands the reloaded value, failure reverts the projection to the held committed state.

      Parameters

      Returns Promise<OperationResult>

    • Best-effort projection against the held content + held guards. The first call resolves the caller's identity/grants from the client's token over the network (cached per client) — plus each foreign subject resource's grants through its own client, for the subject-write forecast. The held snapshot is not refetched; a guard predicate using -> reads its target through the bound engine client.

      Returns Promise<WorkflowEvaluation>

    • Fire an action against an activity, gated on the held content, then cascade.

      Parameters

      • args: { action: string; activity: string; params?: Record<string, unknown> }

      Returns Promise<OperationResult>

    • Stage an optimistic preview of a field edit: InstanceSession.evaluate projects against the held instance with staged previews applied, so field values and the advisory verdicts derived from them move instantly, while everything the engine writes (stage, activity statuses, history) stays committed by construction — previews apply field.* ops only. Set/unset replace the target's staged rows (last write wins); appends accumulate. Tolerant where commits are loud: a target that doesn't resolve in the current stage (it moved under a mounted editor), a closed edit window (a skipped activity's field), a value that doesn't fit the field's shape yet (a half-typed date), or a ref outside the declared resource surface stages an INERT preview — no echo, no throw; the commit at the semantic boundary is the loud surface. Never persisted — commit via InstanceSession.editField.

      Parameters

      Returns void

    • Advance the instance against the held content: cascade auto-transitions, deploy guards, queue effects, commit with ifRevisionId.

      Returns Promise<OperationResult>

    • Replace the held content with the current values the consumer observed (last-write-wins, scoped). A self-doc updates the held instance only when its _updatedAt is strictly newer — an older or timestamp-equal echo is ignored. Buffered if a commit is in flight; a BUFFERED push that fails validation surfaces on the NEXT update call (after that call's own docs are processed), never from the commit itself — the commit's outcome is never masked by a store echo's failure.

      Parameters

      Returns void

    • Replace one held document without rebuilding the rest of the overlay. Consumers with per-document streams use this after the initial InstanceSession.update snapshot. Self-doc recency, commit-time buffering, and deferred buffered-validation errors follow the same contract as InstanceSession.update.

      Parameters

      Returns void

    • Replace the held live guards (the consumer's guard stream, last-write-wins). Guards are a separate stream from the watch-set: InstanceSession.evaluate pre-flights the instance write against them so action verdicts surface mutation-guard-denied while a matching guard denies. Unlike InstanceSession.update, this is NOT buffered behind an in-flight commit — guards aren't part of the held-snapshot consistency story, and tick's pre-flight reads them at commit start.

      Parameters

      Returns void