/** * Provider interface for SmartFS * All filesystem backends must implement this interface */ import type { IFileStats, IDirectoryEntry, IWatchEvent, IReadOptions, IWriteOptions, IStreamOptions, ICopyOptions, IListOptions, IWatchOptions, ITransactionOperation, } from './mod.types.js'; /** * Provider capabilities interface */ export interface IProviderCapabilities { /** * Supports file watching */ supportsWatch: boolean; /** * Supports atomic writes */ supportsAtomic: boolean; /** * Supports transactions */ supportsTransactions: boolean; /** * Supports streaming */ supportsStreaming: boolean; /** * Supports symbolic links */ supportsSymlinks: boolean; /** * Supports file permissions */ supportsPermissions: boolean; } /** * Watch callback type */ export type TWatchCallback = (event: IWatchEvent) => void | Promise; /** * Watcher handle interface */ export interface IWatcherHandle { /** * Stop watching */ stop(): Promise; } /** * Base provider interface that all filesystem backends must implement */ export interface ISmartFsProvider { /** * Provider name (e.g., 'node', 'memory', 's3') */ readonly name: string; /** * Provider capabilities */ readonly capabilities: IProviderCapabilities; // --- File Operations --- /** * Read a file */ readFile(path: string, options?: IReadOptions): Promise; /** * Write a file */ writeFile(path: string, content: string | Buffer, options?: IWriteOptions): Promise; /** * Append to a file */ appendFile(path: string, content: string | Buffer, options?: IWriteOptions): Promise; /** * Delete a file */ deleteFile(path: string): Promise; /** * Copy a file */ copyFile(from: string, to: string, options?: ICopyOptions): Promise; /** * Move a file */ moveFile(from: string, to: string, options?: ICopyOptions): Promise; /** * Check if a file exists */ fileExists(path: string): Promise; /** * Get file statistics */ fileStat(path: string): Promise; /** * Create a readable stream */ createReadStream(path: string, options?: IStreamOptions): Promise>; /** * Create a writable stream */ createWriteStream(path: string, options?: IStreamOptions): Promise>; // --- Directory Operations --- /** * List directory contents */ listDirectory(path: string, options?: IListOptions): Promise; /** * Create a directory */ createDirectory(path: string, options?: { recursive?: boolean; mode?: number }): Promise; /** * Delete a directory */ deleteDirectory(path: string, options?: { recursive?: boolean }): Promise; /** * Check if a directory exists */ directoryExists(path: string): Promise; /** * Get directory statistics */ directoryStat(path: string): Promise; // --- Watch Operations --- /** * Watch a path for changes * Returns a handle to stop watching */ watch(path: string, callback: TWatchCallback, options?: IWatchOptions): Promise; // --- Transaction Operations --- /** * Execute a transaction * Providers should implement this to support atomic multi-file operations * If not supported, should execute operations sequentially */ executeTransaction(operations: ITransactionOperation[]): Promise; /** * Prepare a transaction (create backups for rollback) * Returns prepared operations with backup data */ prepareTransaction(operations: ITransactionOperation[]): Promise; /** * Rollback a transaction using backup data */ rollbackTransaction(operations: ITransactionOperation[]): Promise; // --- Path Operations --- /** * Normalize a path according to the provider's conventions */ normalizePath(path: string): string; /** * Join path segments */ joinPath(...segments: string[]): string; }