/** * FileStore — generic interface for atomic JSON file persistence. * * Encapsulates the common "read JSON → modify → atomic write" pattern * used throughout core modules. Implementations handle: * - Missing file → default data * - Malformed file → default data (graceful degradation) * - Atomic writes via temp + rename */ export interface FileStore { /** Load data from file, returning defaults if missing or corrupt. */ load(): T; /** Atomically write data to file. */ save(data: T): void; /** * Read-modify-write cycle. * The mutate function receives current data and may modify it in place. * The modified data is saved automatically after fn completes. * If fn throws, the write is aborted and the file is unchanged. * * Returns the value returned by fn (useful for extracting computed results). * * NOTE: This method is NOT thread-safe. Caller must ensure no concurrent * writes to the same file — use withLock() or equivalent to serialize access. */ mutate(fn: (data: T) => R): R; } /** * JSON-backed FileStore implementation. * * Uses atomicWriteFileSync for crash-safe writes. * Handles missing/corrupt files by returning the provided default factory result. */ export declare class JsonFileStore implements FileStore { private readonly filePath; private readonly defaultFactory; constructor(filePath: string, defaultFactory: () => T); load(): T; save(data: T): void; mutate(fn: (data: T) => R): R; }