Sanity Library Reference Docs
    Preparing search index...
    interface WorkflowTransaction {
        commit: (options?: { tag?: string }) => Promise<unknown>;
        create: <T extends { _id: string; _type: string }>(
            doc: T,
        ) => WorkflowTransaction;
        delete: (id: string) => WorkflowTransaction;
        patch: (patch: any) => WorkflowTransaction;
    }
    Index

    Properties

    commit: (options?: { tag?: string }) => Promise<unknown>

    Commit the batch. The options bag carries only the request tag (WorkflowFetchOptions.tag — attribution, not the deployment tag). Deliberately no visibility: a transaction rides the client's default visibility'sync' in @sanity/client (so a post-spawn listInstances GROQ sees freshly-created children), immediate in the in-memory test fake. This is a standing engine assumption — a consumer that configured an async default would make spawn read-backs racy. Single-document writes state 'sync' explicitly via WorkflowCommitOptions.

    create: <T extends { _id: string; _type: string }>(
        doc: T,
    ) => WorkflowTransaction

    Queue a create mutation. Fails the transaction on _id collision, same as client.create.

    delete: (id: string) => WorkflowTransaction

    Queue a document delete. Deliberately a transaction-only capability — the top-level client surface stays delete-free so no engine code path can casually remove documents. Engine-side consumers are guard retraction and deleteDefinition housekeeping; outside the engine the CLI's nuke reset deletes raw engine-owned docs through it. Both the real @sanity/client Transaction and the test fake's TransactionHandle carry this shape.

    patch: (patch: any) => WorkflowTransaction

    Queue a patch. Expected argument is a WorkflowPatch handle built via client.patch(id).set(…).ifRevisionId(rev) — pass it without calling .commit().

    Typed any so the test-client's TransactionHandle.patch(string | PatchHandle, …) and @sanity/client's Transaction.patch(Patch | string, …) both satisfy the field entry under strictFunctionTypes. The engine call site always passes a WorkflowPatch; both underlying clients drain it structurally.