/** * SmartFS - Modern pluggable filesystem module * Main entry point for filesystem operations */ import type { ISmartFsProvider } from '../interfaces/mod.provider.js'; import { SmartFsFile } from './smartfs.file.js'; import { SmartFsDirectory } from './smartfs.directory.js'; import { SmartFsTransaction } from './smartfs.transaction.js'; import { SmartFsWatcher } from './smartfs.watcher.js'; /** * SmartFS main class * Creates builder instances for fluent filesystem operations */ export class SmartFs { /** * The filesystem provider */ public provider: ISmartFsProvider; /** * Create a new SmartFS instance with a provider * @param provider - Filesystem provider to use */ constructor(provider: ISmartFsProvider) { this.provider = provider; } /** * Create a file builder for fluent file operations * @param path - Path to the file * @returns FileBuilder instance * * @example * ```typescript * const content = await fs.file('/path/to/file.txt') * .encoding('utf8') * .read() * ``` */ public file(path: string): SmartFsFile { return new SmartFsFile(this.provider, path); } /** * Create a directory builder for fluent directory operations * @param path - Path to the directory * @returns DirectoryBuilder instance * * @example * ```typescript * const files = await fs.directory('/path') * .recursive() * .list() * ``` */ public directory(path: string): SmartFsDirectory { return new SmartFsDirectory(this.provider, path); } /** * Create a transaction builder for atomic multi-file operations * @returns TransactionBuilder instance * * @example * ```typescript * await fs.transaction() * .file('/file1.txt').write('content1') * .file('/file2.txt').delete() * .commit() * ``` */ public transaction(): SmartFsTransaction { return new SmartFsTransaction(this.provider); } /** * Create a watcher builder for file system watching * @param path - Path to watch * @returns WatcherBuilder instance * * @example * ```typescript * const watcher = await fs.watch('/path') * .recursive() * .onChange(event => console.log(event)) * .start() * ``` */ public watch(path: string): SmartFsWatcher { return new SmartFsWatcher(this.provider, path); } /** * Get provider capabilities */ public getCapabilities() { return this.provider.capabilities; } /** * Get provider name */ public getProviderName(): string { return this.provider.name; } }