@synet/fs
Version:
Robust, battle-tested filesystem abstraction for Node.js
90 lines (89 loc) • 2.42 kB
TypeScript
import type { IFileSystem } from "./filesystem.interface";
/**
* Supported file formats for ID-based file operations
*/
export declare enum FileFormat {
JSON = "json",
TXT = "txt",
PDF = "pdf",
MD = "md",
XML = "xml",
CSV = "csv",
LOG = "log",
CONFIG = "config"
}
/**
* File metadata containing ID and alias information
*/
export interface FileMetadata {
id: string;
alias: string;
originalPath: string;
storedPath: string;
format: FileFormat;
}
/**
* WithIdFileSystem provides deterministic IDs for files while preserving original names
* Files are stored with format: basename:filename-path-hash.ext
* Enables access by original path, ID, or alias
*/
export declare class WithIdFileSystem implements IFileSystem {
private baseFileSystem;
private fileMap;
private idMap;
private aliasMap;
constructor(baseFileSystem: IFileSystem);
/**
* Generate deterministic ID for a file path
*/
private generateId;
/**
* Generate alias from file path (readable identifier)
*/
private generateAlias;
/**
* Get file format from extension
*/
private getFileFormat;
/**
* Generate stored file path with ID format
*/
private generateStoredPath;
/**
* Get file metadata for a path, creating if necessary
*/
private getOrCreateMetadata;
/**
* Find metadata by ID or alias
*/
private findMetadata;
/**
* Get deterministic ID for a file path
*/
getId(filePath: string): string;
/**
* Get alias (readable identifier) for a file path
*/
getAlias(filePath: string): string;
/**
* Get file content by ID or alias with optional format specification
*/
getByIdOrAlias(idOrAlias: string, expectedFormat?: FileFormat): string;
/**
* Get metadata for a file by its original path
*/
getMetadata(filePath: string): FileMetadata;
/**
* List all tracked files
*/
listTrackedFiles(): FileMetadata[];
existsSync(path: string): boolean;
readFileSync(path: string): string;
writeFileSync(path: string, data: string): void;
deleteFileSync(path: string): void;
deleteDirSync(path: string): void;
readDirSync(dirPath: string): string[];
ensureDirSync(path: string): void;
chmodSync(path: string, mode: number): void;
clear?(dirPath: string): void;
}