/** * State Store - Atomic JSON file persistence * * Features: * - Atomic writes (write to temp file, then rename) * - Checksum validation for corruption detection * - Debounced saves to avoid excessive I/O * - Graceful degradation on errors * - Backup file for recovery from corruption */ import { PersistedState } from './state-schema.js'; /** * Configuration options for the StateStore. */ export interface StateStoreConfig { /** Directory for state files (default: .hari-seldon/) */ stateDir: string; /** State file name (default: state.json) */ filename: string; /** Debounce interval in milliseconds (default: 1000) */ debounceMs: number; /** Enable checksum validation (default: true) */ enableChecksum: boolean; } /** * Manages persisted state with atomic writes and corruption detection. * * @example * ```typescript * const store = new StateStore({ stateDir: '.hari-seldon' }); * await store.initialize('/path/to/repo'); * * store.updateState((state) => { * state.tasks.push({ taskId: '123', ... }); * }); * * await store.shutdown('/path/to/repo'); * ``` */ export declare class StateStore { private config; private state; private saveTimer; private dirty; private saving; private repoPath; constructor(config?: Partial); /** * Get the relative path to the state file. */ get statePath(): string; /** * Get the relative path to the temp file (used during atomic writes). */ get tempPath(): string; /** * Get the relative path to the backup file. */ get backupPath(): string; /** * Initialize the state store - load existing state or create new. * * @param repoPath - Absolute path to the repository root */ initialize(repoPath: string): Promise; /** * Load state from backup file. */ private loadBackup; /** * Migrate state from an older version to current. */ private migrateState; /** * Compute a checksum for state data. */ private computeChecksum; /** * Get current state (read-only copy). */ getState(): Readonly; /** * Update state and schedule save. * * @param updater - Function that modifies the state in-place */ updateState(updater: (state: PersistedState) => void): void; /** * Schedule a debounced save. */ private scheduleSave; /** * Force immediate save (bypasses debounce). * * @param repoPath - Optional repo path (uses cached path if not provided) */ saveNow(repoPath?: string): Promise; /** * Perform atomic save. * * @param repoPath - Optional repo path (uses cached path if not provided) */ private save; /** * Shutdown - ensure final save. * * @param repoPath - Path to the repository root */ shutdown(repoPath: string): Promise; } //# sourceMappingURL=state-store.d.ts.map