/** * Atomic file persistence helper — see docs/future/sensor-map.md §8.6. * * Contract: * - `readJsonStore` reads and parses; on any failure (missing file, * malformed JSON, unrecognized schemaVersion) it quarantines the * bad file and returns undefined. Caller starts with an empty * in-memory store. * - `writeJsonStore` writes to a unique temp file and renames. * `...tmp` naming avoids cross-process * collisions. Optional `fsync` before rename gated by env flag. * - `cleanupStaleTempFiles` removes any `.*.tmp` older than * 1 hour on startup — belt against orphaned temp files from a * crashed prior boot. * * The functions are deliberately narrow: they know about JSON and * files, nothing about sensor-map semantics. Higher-level stores * (DiscoveryStore, NoticeStore, UiStateStore) wrap these with * schema-specific validation. */ /** Clock injection point for testability. */ export interface Clock { now(): number; iso(): string; } export declare const REAL_CLOCK: Clock; /** Logger surface — a subset of Homebridge's Logger. */ export interface Logger { info(msg: string): void; warn(msg: string): void; debug(msg: string): void; } /** * Read a JSON store file. Returns the parsed object on success, or * undefined on any failure (with the file quarantined and a warn * logged). Caller supplies a validator that rejects malformed shapes * — e.g., checks `schemaVersion === 1`. */ export declare function readJsonStore(filePath: string, validator: (raw: unknown) => raw is T, log: Logger, clock?: Clock): Promise; /** * Write a JSON store atomically. The temp file is closed and renamed * over the target path in one step (on POSIX + modern Windows). * * On unsupported platforms the fallback is unlink + rename with a * warn; a brief window of "file absent" is visible to concurrent * readers. The stores are single-writer per §8 so cross-process * races are outside this function's remit. */ export declare function writeJsonStore(filePath: string, data: unknown, log: Logger): Promise; /** * Remove any `.*.tmp` in the persistence directory older than * `STALE_TEMP_AGE_MS`. Safe to run on startup — legit in-flight temps * are always well under a minute old. */ export declare function cleanupStaleTempFiles(dir: string, log: Logger, clock?: Clock): Promise; //# sourceMappingURL=atomicWrite.d.ts.map