TransactionCallbackNEW
TransactionCallback<
T> = (context) =>Promise<TransactionResult<T>>
Callback function for document transactions that provides access to a draft document for modification.
Type Parameters
Section titled “Type Parameters”T = void
Parameters
Section titled “Parameters”context
Section titled “context”Object containing the draft document to modify
Returns
Section titled “Returns”A TransactionResult controlling commit/rollback and optionally providing a result value
Remarks
Section titled “Remarks”TransactionCallback is the function signature used when working with document transactions via
DocAuthDocument.transaction. The callback receives a context object containing a
draft document that can be modified, and returns a TransactionResult to control
whether changes are committed .
Key concepts:
Context parameter:
context.draft- AProgrammatic.Documentinstance representing the document in draft state- All modifications are made on this draft
- Changes are isolated until the transaction commits
Return value:
- Must return a
TransactionResult - Return
true, or{ commit: true }to commit changes - Optionally return a result value with
{ commit: boolean, result: T }
Example
Section titled “Example”Explicit commit:
const r = await doc.transaction(async ({ draft }) => { const replacementCount = draft.replaceText(/old/g, 'new');
return { commit: true, result: replacementCount };});DocAuthDocument.transactionfor running transactions with this callback type.TransactionResultfor details on return value options.