Skip to content
Document Authoring DA  API Docs v1.10.0
npmGitHub

TransactionCallbackNEW

TransactionCallback<T> = (context) => Promise<TransactionResult<T>>

Callback function for document transactions that provides access to a draft document for modification.

T = void

TransactionContext

Object containing the draft document to modify

Promise<TransactionResult<T>>

A TransactionResult controlling commit/rollback and optionally providing a result value

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 - A Programmatic.Document instance 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 }

Explicit commit:

const r = await doc.transaction(async ({ draft }) => {
const replacementCount = draft.replaceText(/old/g, 'new');
return { commit: true, result: replacementCount };
});