markmv - v1.41.7
    Preparing search index...

    Class TransactionManager

    Manages atomic file operations with full rollback capability.

    Provides transactional semantics for file system operations, ensuring that either all operations complete successfully or all changes are rolled back. Supports automatic backups and retry logic.

    Transactional file operations

    const transaction = new TransactionManager({
    createBackups: true,
    continueOnError: false
    });

    // Add operations to the transaction
    transaction.addFileMove('old.md', 'new.md');
    transaction.addContentUpdate('target.md', newContent);

    try {
    const result = await transaction.execute();
    if (result.success) {
    console.log('All operations completed successfully');
    } else {
    console.log('Transaction failed, all changes rolled back');
    }
    } catch (error) {
    console.error('Transaction error:', error);
    }
    Index
    • Queues replacing the content of a file, creating parent directories as needed. Execution remembers the previous content if the file exists. Rollback restores it, or deletes the file when it did not exist before.

      Parameters

      • filePath: string

        File to write.

      • newContent: string

        The full new content.

      • Optionaldescription: string

        Overrides the generated description.

      Returns void

    • Queues creating a new file, with parent directories created as needed. Execution fails if the file already exists. Rollback deletes the file.

      Parameters

      • filePath: string

        File to create.

      • content: string

        Content to write.

      • Optionaldescription: string

        Overrides the generated description.

      Returns void

    • Queues deleting a file. Execution does nothing when the file is already absent, and otherwise remembers its content. Rollback writes that content back, recreating parent directories, if the file had existed.

      Parameters

      • filePath: string

        File to delete.

      • Optionaldescription: string

        Overrides the generated description.

      Returns void

    • Queues a move of a file. Execution backs up the source when backups are enabled, creates the destination's parent directories and refuses to overwrite an existing destination. Rollback removes the destination and restores the source from the backup.

      Parameters

      • sourcePath: string

        File to move.

      • destinationPath: string

        Where to move it to.

      • Optionaldescription: string

        Overrides the generated description.

      Returns void

    • Runs the queued steps in order, retrying a failing step up to maxRetries times with exponential backoff starting at one second. Unless continueOnError is set, a step that exhausts its retries rolls back every executed step and removes leftover backups. Backups are removed after a successful run.

      Returns Promise<
          {
              changes: OperationChange[];
              completedSteps: number;
              errors: string[];
              success: boolean;
          },
      >

      The outcome. On a rolled-back failure changes is empty.

    • Lists the queued steps, in order, without executing anything.

      Returns { description: string; type: string }[]

      One entry per step.

      • description: string

        The step's description.

      • type: string

        The step's kind, such as file-move.

    • Rolls back every executed step in reverse order and forgets them. A step whose rollback throws is reported in a single warning and does not stop the others.

      Returns Promise<void>