Skip to main content

Interface: TransactionApi

Defined in: types.ts:443

Per-transaction handle passed to a transaction's work function.

tx.push(command) runs command.do ?? command.redo immediately (so the application's state mutates as the work progresses) and buffers command.redo and command.undo for the composite entry that the transaction will commit on success. tx.label(text) overrides the composite's label after the fact, which is useful when the right label depends on what the work actually changed.

The handle is closed after the surrounding transaction(...) call resolves. Calling tx.push or tx.label past that point throws.

The work function also receives an AbortSignal as its second argument (see Amnesia.transaction). The signal aborts when clear() or dispose() runs while the transaction is mid-flight. Pass it to fetch, child commands, or long-running loops so cancellation propagates through the work. A rejection thrown after signal.aborted === true is treated as a silent no-op (no onError, just rollback).

Properties

label

label: (text) => void

Defined in: types.ts:454

Override the composite entry's label. Last write wins.

Parameters

ParameterType
textstring

Returns

void


push

push: (command) => Promise<void>

Defined in: types.ts:449

Apply a command and add it to the transaction's buffer. The command's do ?? redo runs immediately. Returns a Promise that resolves once any async first-apply has settled.

Parameters

ParameterType
commandCommand

Returns

Promise<void>