/** * Represents a file or directory entry */ interface FileEntry { path: string; name: string; type: "file" | "directory"; size?: number; created?: Date; modified?: Date; metadata?: FileMetadata; content?: any; } /** * File statistics */ interface FileStat { path: string; size: number; type: "file" | "directory"; created: Date; modified: Date; accessed?: Date; readonly?: boolean; } /** * Custom metadata that can be attached to files */ interface FileMetadata { tags?: string[]; description?: string; [key: string]: any; } /** * Disposable pattern for cleanup */ interface Disposable { dispose(): void; } /** * File system event types */ type FSEventType = "created" | "updated" | "deleted" | "moved" | "renamed"; /** * File system event */ interface FSEvent { type: FSEventType; path: string; oldPath?: string; timestamp: Date; metadata?: Record; } /** * Capacidades e limitações de um sistema de arquivos */ interface IFileSystemCapabilities { readonly: boolean; caseSensitive: boolean; atomicRename: boolean; maxFileSize?: number; maxPathLength?: number; supportsWatch: boolean; supportsMetadata: boolean; supportsGlob: boolean; supportsTrueDirectories?: boolean; supportsAtomicOperations?: boolean; supportsMultipartUpload?: boolean; supportsPermissions?: boolean; metadataLimit?: number; description?: string; } /** * Virtual File System interface * Provides a uniform API for different storage backends */ interface IFileSystem { readFile(path: string): Promise; writeFile(path: string, content: any, metadata?: FileMetadata): Promise; deleteFile(path: string): Promise; exists(path: string): Promise; readDir(path: string): Promise; mkdir(path: string, recursive?: boolean): Promise; rmdir(path: string, recursive?: boolean): Promise; rename(oldPath: string, newPath: string): Promise; move(sourcePaths: string[], targetPath: string): Promise; copy(sourcePath: string, targetPath: string): Promise; watch(pattern: string, callback: (event: FSEvent) => void): Disposable; stat(path: string): Promise; glob(pattern: string): Promise; clear(): Promise; size(): Promise; /** * Verifica se o caminho pode ser modificado (escrita/delete) * @returns true se permitido, false se readonly ou sem permissão */ canModify(path: string): Promise; /** * Verifica se pode criar arquivos no diretório * @returns true se permitido, false se readonly ou sem permissão */ canCreateIn(parentPath: string): Promise; /** * Escreve arquivo de forma atômica (write to temp + rename) * Fallback para writeFile normal se não suportado */ writeFileAtomic?(path: string, content: any, metadata?: FileMetadata): Promise; /** * Retorna as capacidades deste file system */ readonly capabilities?: IFileSystemCapabilities; } /** * Interface for watchable file systems */ interface IWatchable { watch(pattern: string, callback: (event: FSEvent) => void): Disposable; unwatch(handle: Disposable): void; } /** * Basic event emitter interface for reactive file systems */ interface IEventEmitter { on(event: string | symbol, handler: (...args: any[]) => void): Disposable; once(event: string | symbol, handler: (...args: any[]) => void): Disposable; emit(event: string | symbol, ...args: any[]): boolean; off(event: string | symbol, handler?: (...args: any[]) => void): void; removeAllListeners(event?: string | symbol): void; } /** * Type-safe event emitter interface */ interface ITypedEventEmitter> { on(event: K, handler: (payload: T[K]) => void): Disposable; once(event: K, handler: (payload: T[K]) => void): Disposable; emit(event: K, payload: T[K]): boolean; off(event: K, handler?: (payload: T[K]) => void): void; removeAllListeners(event?: K): void; } /** * File system with optional event support for reactive patterns */ interface IReactiveFileSystem extends IFileSystem { /** * Optional event emitter for reactive patterns */ events?: IEventEmitter; /** * Optional initialization method that can emit progress events */ initialize?(): Promise; } /** * Standard file system events that implementations can emit */ declare const FileSystemEvents: { readonly INITIALIZING: "fs:initializing"; readonly INITIALIZED: "fs:initialized"; readonly INIT_PROGRESS: "fs:init:progress"; readonly INIT_ERROR: "fs:init:error"; readonly OPERATION_START: "fs:operation:start"; readonly OPERATION_END: "fs:operation:end"; readonly OPERATION_ERROR: "fs:operation:error"; readonly FILE_READING: "fs:file:reading"; readonly FILE_READ: "fs:file:read"; readonly FILE_WRITING: "fs:file:writing"; readonly FILE_WRITTEN: "fs:file:written"; readonly FILE_DELETING: "fs:file:deleting"; readonly FILE_DELETED: "fs:file:deleted"; readonly DIR_READING: "fs:dir:reading"; readonly DIR_READ: "fs:dir:read"; readonly DIR_CREATING: "fs:dir:creating"; readonly DIR_CREATED: "fs:dir:created"; readonly DIR_DELETING: "fs:dir:deleting"; readonly DIR_DELETED: "fs:dir:deleted"; readonly BATCH_START: "fs:batch:start"; readonly BATCH_PROGRESS: "fs:batch:progress"; readonly BATCH_END: "fs:batch:end"; readonly STORAGE_CLEARING: "fs:storage:clearing"; readonly STORAGE_CLEARED: "fs:storage:cleared"; readonly STORAGE_SIZE_CALCULATED: "fs:storage:size"; }; /** * Event payload types */ interface FileSystemEventPayloads { [FileSystemEvents.INITIALIZING]: void; [FileSystemEvents.INITIALIZED]: { duration: number; }; [FileSystemEvents.INIT_PROGRESS]: { loaded: number; total: number; phase?: string; }; [FileSystemEvents.INIT_ERROR]: { error: Error; }; [FileSystemEvents.OPERATION_START]: { operation: string; path?: string; id?: string; }; [FileSystemEvents.OPERATION_END]: { operation: string; path?: string; id?: string; duration: number; }; [FileSystemEvents.OPERATION_ERROR]: { operation: string; path?: string; error: Error; }; [FileSystemEvents.FILE_READING]: { path: string; }; [FileSystemEvents.FILE_READ]: { path: string; size: number; }; [FileSystemEvents.FILE_WRITING]: { path: string; size?: number; }; [FileSystemEvents.FILE_WRITTEN]: { path: string; size: number; }; [FileSystemEvents.FILE_DELETING]: { path: string; }; [FileSystemEvents.FILE_DELETED]: { path: string; }; [FileSystemEvents.DIR_READING]: { path: string; }; [FileSystemEvents.DIR_READ]: { path: string; count: number; }; [FileSystemEvents.DIR_CREATING]: { path: string; recursive: boolean; }; [FileSystemEvents.DIR_CREATED]: { path: string; }; [FileSystemEvents.DIR_DELETING]: { path: string; recursive: boolean; }; [FileSystemEvents.DIR_DELETED]: { path: string; }; [FileSystemEvents.BATCH_START]: { total: number; operation: string; }; [FileSystemEvents.BATCH_PROGRESS]: { current: number; total: number; }; [FileSystemEvents.BATCH_END]: { total: number; duration: number; }; [FileSystemEvents.STORAGE_CLEARING]: void; [FileSystemEvents.STORAGE_CLEARED]: { duration: number; }; [FileSystemEvents.STORAGE_SIZE_CALCULATED]: { size: number; }; } /** * File system event emitter type */ type FileSystemEventEmitter = ITypedEventEmitter; /** * Path utilities for virtual file systems */ /** * Normalize a path */ declare function normalizePath(path: string): string; /** * Get directory name from path */ declare function dirname(path: string): string; /** * Get base name from path */ declare function basename(path: string): string; /** * Join path segments */ declare function join(...segments: string[]): string; /** * Check if path is absolute */ declare function isAbsolute(path: string): boolean; /** * Get file extension */ declare function extname(path: string): string; /** * Simple event emitter implementation that file systems can use * Implementations are free to use their own event system */ declare class EventEmitter implements IEventEmitter { private events; on(event: string | symbol, handler: (...args: any[]) => void): Disposable; once(event: string | symbol, handler: (...args: any[]) => void): Disposable; emit(event: string | symbol, ...args: any[]): boolean; off(event: string | symbol, handler?: (...args: any[]) => void): void; removeAllListeners(event?: string | symbol): void; } /** * Typed event emitter implementation */ declare class TypedEventEmitter> implements ITypedEventEmitter { private emitter; on(event: K, handler: (payload: T[K]) => void): Disposable; once(event: K, handler: (payload: T[K]) => void): Disposable; emit(event: K, payload: T[K]): boolean; off(event: K, handler?: (payload: T[K]) => void): void; removeAllListeners(event?: K): void; } /** * Constructor type helper */ type Constructor = new (...args: any[]) => T; /** * Mixin to add event support to any file system implementation */ declare function withEvents>(Base: TBase): TBase & Constructor; /** * Classe base abstrata com implementações padrão para FileSystem * Fornece implementações padrão para os novos métodos de permissão */ declare abstract class BaseFileSystem implements IReactiveFileSystem { abstract get events(): any; abstract readFile(path: string): Promise; abstract writeFile(path: string, content: any, metadata?: FileMetadata): Promise; abstract deleteFile(path: string): Promise; abstract exists(path: string): Promise; abstract readDir(path: string): Promise; abstract mkdir(path: string, recursive?: boolean): Promise; abstract rmdir(path: string, recursive?: boolean): Promise; abstract rename(oldPath: string, newPath: string): Promise; abstract move(sourcePaths: string[], targetPath: string): Promise; abstract copy(sourcePath: string, targetPath: string): Promise; abstract watch(pattern: string, callback: (event: FSEvent) => void): Disposable; abstract stat(path: string): Promise; abstract glob(pattern: string): Promise; abstract clear(): Promise; abstract size(): Promise; /** * Por padrão, permite modificação se o arquivo existe ou se pode ser criado */ canModify(path: string): Promise; /** * Por padrão, permite criar se o diretório existe e não é readonly */ canCreateIn(parentPath: string): Promise; /** * Implementação padrão de escrita atômica usando temp + rename */ writeFileAtomic(path: string, content: any, metadata?: FileMetadata): Promise; /** * Helper para extrair diretório pai */ protected getParentPath(path: string): string; } export { BaseFileSystem, type Disposable, EventEmitter, type FSEvent, type FSEventType, type FileEntry, type FileMetadata, type FileStat, type FileSystemEventEmitter, type FileSystemEventPayloads, FileSystemEvents, type IEventEmitter, type IFileSystem, type IFileSystemCapabilities, type IReactiveFileSystem, type ITypedEventEmitter, type IWatchable, TypedEventEmitter, basename, dirname, extname, isAbsolute, join, normalizePath, withEvents };