VaultTransaction
A reversible log of vault mutations. Perform mutations through its methods, then call VaultTransaction.commit on success or VaultTransaction.rollback on failure. It is await using-friendly: if neither is called, disposal rolls back.
Import:
import { VaultTransaction } from 'obsidian-dev-utils/obsidian/vault-transaction';Signature:
export class VaultTransactionConstructor
new VaultTransaction(params: VaultTransactionConstructorParams)Creates a new vault transaction.
Properties
| Property | Type | Description |
|---|---|---|
| app | App | The Obsidian application instance the transaction mutates. |
Methods
| Method | Returns | Description |
|---|---|---|
| [Symbol.asyncDispose]() | Promise<void> | Rolls back the transaction on disposal unless it was already committed or rolled back. |
| commit() | Promise<void> | Commits the transaction: finalizes soft-deletes by trashing the staged resources for real and removes the staging folder. After this the transaction can no longer be mutated or rolled back. |
| create(path, data) | Promise<TFile> | Creates a file with the given content, recording its removal as the inverse. |
| createFolder(path) | Promise<void> | Creates a folder (including missing ancestors), recording its removal as the inverse. A no-op if the folder already exists. |
| modify(pathOrFile, newContent) | Promise<void> | Replaces the content of a file, capturing the old content so it can be restored on rollback. |
| process(pathOrFile, newContentProvider) | Promise<void> | Transforms the content of a file, capturing the old content so it can be restored on rollback. |
| rename(oldPathOrFile, newPath) | Promise<string> | Renames or moves a resource, recording the reverse rename as the inverse. |
| rollback() | Promise<void> | Rolls back the transaction: undoes the completed steps in reverse order and removes the staging folder. Idempotent. |
| trash(pathOrFile) | Promise<void> | Soft-deletes a resource by moving it into the staging folder, recording the move-back as the inverse. The real trash happens on VaultTransaction.commit. A no-op if the resource does not exist. |
Links to this page: