/** * Persistent Store - Debounced & Atomic File Persistence * * Provides reliable file persistence with: * - Debounced writes: Batches rapid save calls to reduce I/O * - Atomic writes: Uses temp file + rename to prevent corruption * - Type-safe serialization: Generic JSON persistence * * Usage: * const store = new PersistentStore('./data.json'); * await store.save(data); // Debounced, atomic write * const data = await store.load(); // Load from file */ /** * Get the base data directory for persistent storage. * Uses ~/.unbrowser to avoid permission issues when cwd is / (e.g., MCP servers) */ export declare function getDataDir(): string; /** * Resolve a file path for persistent storage. * Relative paths are resolved relative to ~/.unbrowser instead of cwd. * Absolute paths are used as-is. */ export declare function resolveDataPath(filePath: string): string; /** * Configuration for PersistentStore */ export interface PersistentStoreConfig { /** Debounce delay in milliseconds (default: 1000ms) */ debounceMs: number; /** Pretty-print JSON with indentation (default: true) */ prettyPrint: boolean; /** JSON indentation spaces (default: 2) */ indent: number; /** Create parent directories if they don't exist (default: true) */ createDirs: boolean; /** Component name for logging */ componentName: string; } /** * Default configuration */ export declare const DEFAULT_PERSISTENT_STORE_CONFIG: PersistentStoreConfig; /** * Statistics about store operations */ export interface PersistentStoreStats { /** Total save requests received */ saveRequests: number; /** Actual writes performed (after debouncing) */ actualWrites: number; /** Failed write attempts */ failedWrites: number; /** Writes skipped due to debouncing */ debouncedSkips: number; /** Last successful write timestamp */ lastWriteTime: number | null; /** Last error message */ lastError: string | null; } /** * PersistentStore - Debounced & Atomic JSON file persistence */ export declare class PersistentStore { private filePath; private config; private stats; private pendingData; private debounceTimer; private writePromise; constructor(filePath: string, config?: Partial); /** * Get the resolved file path */ getFilePath(): string; /** * Get store statistics */ getStats(): PersistentStoreStats; /** * Save data to file with debouncing and atomic write * * Multiple rapid calls will be batched - only the last data is written * after the debounce delay expires. */ save(data: T): Promise; /** * Save data immediately without debouncing * * Use sparingly - prefer save() for normal operations */ saveImmediate(data: T): Promise; /** * Flush any pending debounced write immediately * * Useful for graceful shutdown */ flush(): Promise; /** * Load data from file * * Returns null if file doesn't exist */ load(): Promise; /** * Check if the file exists */ exists(): Promise; /** * Delete the file */ delete(): Promise; /** * Perform atomic write: write to temp file, then rename */ private atomicWrite; /** * Cancel any pending debounced write without flushing */ cancel(): void; /** * Check if there's a pending write */ hasPendingWrite(): boolean; } /** * Create a PersistentStore instance with convenience defaults */ export declare function createPersistentStore(filePath: string, componentName: string, config?: Partial): PersistentStore; //# sourceMappingURL=persistent-store.d.ts.map