markmv
Version:
TypeScript CLI for markdown file operations with intelligent link refactoring
103 lines • 3.46 kB
TypeScript
import type { OperationChange } from '../types/operations.js';
/**
* Represents a single atomic operation within a transaction.
*
* Each step can be executed and rolled back independently, providing the foundation for
* transactional file operations with full rollback capability.
*
* @category Utilities
*/
export interface TransactionStep {
id: string;
type: 'file-move' | 'file-copy' | 'file-delete' | 'file-create' | 'content-update';
description: string;
execute: () => Promise<void>;
rollback: () => Promise<void>;
completed: boolean;
}
/**
* Configuration options for transaction management.
*
* Controls transaction behavior including backup creation, error handling, and retry logic for
* robust file operations.
*
* @category Utilities
*/
export interface TransactionOptions {
/** Create backups before destructive operations */
createBackups?: boolean;
/** Continue on non-critical errors */
continueOnError?: boolean;
/** Maximum number of retry attempts */
maxRetries?: number;
}
/**
* 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.
*
* @category Utilities
*
* @example
* Transactional file operations
* ```typescript
* 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);
* }
* ```
*/
export declare class TransactionManager {
private steps;
private executedSteps;
private backups;
private options;
constructor(options?: TransactionOptions);
/** Add a file move operation to the transaction */
addFileMove(sourcePath: string, destinationPath: string, description?: string): void;
/** Add a content update operation to the transaction */
addContentUpdate(filePath: string, newContent: string, description?: string): void;
/** Add a file creation operation to the transaction */
addFileCreate(filePath: string, content: string, description?: string): void;
/** Add a file deletion operation to the transaction */
addFileDelete(filePath: string, description?: string): void;
/** Execute all steps in the transaction */
execute(): Promise<{
success: boolean;
completedSteps: number;
errors: string[];
changes: OperationChange[];
}>;
/** Rollback all executed steps */
rollback(): Promise<void>;
/** Get a preview of all planned operations */
getPreview(): Array<{
description: string;
type: string;
}>;
/** Clear all planned operations */
clear(): void;
/** Get the number of planned operations */
getStepCount(): number;
private cleanupBackups;
private mapStepTypeToChangeType;
private extractFilePathFromDescription;
}
//# sourceMappingURL=transaction-manager.d.ts.map