export interface JsonRepoOptions { filePath: string; defaultValue: () => T; /** Optional migration function. Called on every disk read; use to normalise legacy shapes without zod. */ migrate?: (raw: unknown) => T; } export declare class JsonRepository { private readonly opts; private cache; private readonly mutex; /** Fires the first-call orphan sweep exactly once per instance, on the first I/O op. */ private sweepPromise; constructor(opts: JsonRepoOptions); /** * Delete any `.tmp.*` siblings of filePath. * `atomicWrite` (tmp → rename) can orphan its tmp when the process is SIGTERM'd mid-write * (e.g., daemon hot-reload landing during a long write). On next boot this sweeper clears them. * Runs lazily on the first read/mutate so repos that are constructed but never used pay nothing. */ private sweepOrphans; private ensureSwept; /** * Return the current value. * Cache hit: zero I/O. Cache miss: reads file, parses JSON, applies migrate if present. * Missing file returns and caches defaultValue(). */ read(): Promise; /** * Atomically persist `next` and update the in-memory cache. * Does not hold the mutex — callers that need serialization should use mutate(). */ write(next: T): Promise; /** * Wait until any in-flight `mutate()` has fully completed (tmp written + rename landed). * Acquire-release the mutex without doing any work; FIFO ordering guarantees that once this * resolves, every operation enqueued before flush() has finished. * Intended for graceful SIGTERM handlers to drain writes before `process.exit(0)`. */ flush(): Promise; /** * Mutex-serialized read-modify-write. * `fn` receives the current value and must return `{ next, result }`. * Returns the `result` value from `fn`. */ mutate(fn: (cur: T) => { next: T; result: R; }): Promise; /** Drop the in-memory cache so the next read() fetches from disk. */ invalidate(): void; }