history

history.transaction

transaction(label: string, fn: () => T | Promise<T>): Promise<T>

Group all commands issued inside fn into a single named undo step.

Wraps beginTransaction / endTransaction with try/finally so the transaction is always closed even if fn throws. If fn is async the transaction remains open across awaits; the auto-commit timer is paused for the duration (Phase 1 hardens this behaviour).

Emits "history:changed" once when the outermost transaction commits.

labelstringHuman-readable label shown in the undo-stack inspector.
fn() => T | Promise<T>Synchronous or asynchronous callback containing the grouped operations.

Returns: Promise<T>

Example

await api.history.transaction("Bulk import", async () => {
  await api.nodes.add(nodes);
  await api.edges.add(edges);
});