/** * MemoryIndexFile - Persistent _index.json manager with debounced writes. * * On server restart the MemoryStorageLayer can load cached metadata from * _index.json instead of re-scanning every memory file on disk. This class * handles reading, writing (with validation), and debounced scheduling of * index persistence to avoid excessive I/O during rapid mutations. */ import type { FileOperationsService } from '../services/FileOperationsService.js'; import type { ElementIndexEntry } from './types.js'; export interface MemoryIndexData { version: 1; generatedAt: string; entryCount: number; entries: Record; } export interface MemoryIndexFileOptions { debounceMs?: number; } export declare class MemoryIndexFile { private readonly indexPath; private readonly fileOps; private readonly debounceMs; private pendingEntries; private debounceTimer; constructor(indexPath: string, fileOps: FileOperationsService, options?: MemoryIndexFileOptions); /** * Read the index from disk. * Returns null when the file is missing, corrupt, has a version mismatch, * or the entryCount doesn't match the actual number of entries. */ read(): Promise; /** * Handle a corrupt or malformed index file: log a warning and delete it * so the next scan builds a clean index from disk. */ private handleCorruptIndex; /** * Write the index to disk immediately. * Converts the entries array to a Record keyed by `entry.filePath`. * Catches ENOSPC gracefully (logs warning, does not throw). */ write(entries: ElementIndexEntry[]): Promise; /** * Schedule a debounced write. Multiple calls within the debounce window * coalesce into a single write using the most recent entries. */ scheduleWrite(entries: ElementIndexEntry[]): void; /** * If there are pending entries, write immediately and clear the timer. */ flush(): Promise; /** * Cancel any pending timer. Does NOT flush (fire-and-forget cleanup). */ dispose(): void; } //# sourceMappingURL=MemoryIndexFile.d.ts.map