@synet/fs
Version:
Robust, battle-tested filesystem abstraction for Node.js
90 lines (89 loc) • 2.5 kB
TypeScript
import type { IAsyncFileSystem } from "./async-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 IAsyncFileSystem {
private baseFileSystem;
private fileMap;
private idMap;
private aliasMap;
constructor(baseFileSystem: IAsyncFileSystem);
/**
* 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): Promise<string>;
/**
* Get metadata for a file by its original path
*/
getMetadata(filePath: string): FileMetadata;
/**
* List all tracked files
*/
listTrackedFiles(): FileMetadata[];
exists(path: string): Promise<boolean>;
readFile(path: string): Promise<string>;
writeFile(path: string, data: string): Promise<void>;
deleteFile(path: string): Promise<void>;
deleteDir(path: string): Promise<void>;
readDir(dirPath: string): Promise<string[]>;
ensureDir(path: string): Promise<void>;
chmod(path: string, mode: number): Promise<void>;
clear?(dirPath: string): Promise<void>;
}