UNPKG

@synet/fs

Version:

Robust, battle-tested filesystem abstraction for Node.js

118 lines (117 loc) 3.2 kB
/** * Sync Filesystem Unit - Pure Synchronous Operations * * This unit provides synchronous filesystem operations with direct method access. * Only includes backends that work well synchronously: node and memory. * Cloud storage (GitHub, S3, GCS) should use the async filesystem unit. */ import { type TeachingContract, Unit, type UnitCore, type UnitProps, Capabilities, Schema, Validator } from "@synet/unit"; import type { IFileSystem } from "./filesystem.interface"; /** * Sync filesystem creation configuration */ export interface SyncFilesystemConfig { adapter: IFileSystem; } /** * Sync Filesystem Unit state */ export interface SyncFileSystemState { backend: IFileSystem; config: SyncFilesystemConfig; } /** * Sync Filesystem Unit properties following Unit Architecture */ interface SyncFileSystemProps extends UnitProps { backend: IFileSystem; config: SyncFilesystemConfig; } /** * Sync Filesystem Unit - Pure synchronous filesystem operations */ export declare class FileSystem extends Unit<SyncFileSystemProps> implements IFileSystem { protected constructor(props: SyncFileSystemProps); /** * Build consciousness trinity - creates living instances once */ protected build(): UnitCore; /** * Get capabilities consciousness - returns living instance */ capabilities(): Capabilities; /** * Get schema consciousness - returns living instance */ schema(): Schema; /** * Get validator consciousness - returns living instance */ validator(): Validator; /** * CREATE - Create a new sync Filesystem Unit */ static create(config: SyncFilesystemConfig): FileSystem; /** * Read file content synchronously */ readFileSync(path: string): string; /** * Write file content synchronously */ writeFileSync(path: string, data: string): void; /** * Check if file/directory exists synchronously */ existsSync(path: string): boolean; /** * Delete file synchronously */ deleteFileSync(path: string): void; /** * Read directory contents synchronously */ readDirSync(path: string): string[]; /** * Ensure directory exists synchronously */ ensureDirSync(path: string): void; /** * Delete directory synchronously */ deleteDirSync(path: string): void; /** * Set file permissions synchronously */ chmodSync(path: string, mode: number): void; /** * Get file statistics synchronously */ statSync(path: string): import("./filesystem.interface").FileStats; /** * Clear directory contents synchronously */ clear(dirPath: string): void; /** * TEACH - Provide filesystem capabilities to other units */ teach(): TeachingContract; whoami(): string; help(): void; /** * Get configuration */ getConfig(): { adapter: IFileSystem; }; /** * Get direct access to the backend (escape hatch) */ getBackend(): IFileSystem; isAsync(): boolean; /** * Normalize path for backend compatibility */ private normalizePath; } export {};