/** * Hard ceiling on `.corrupt-*` files kept per store directory, oldest reaped * first. A flapping writer that corrupts its file on every boot must not be * allowed to fill the disk with forensic copies, "a handful" is enough to * look at what went wrong without becoming a leak. */ export declare const CORRUPT_QUARANTINE_MAX_FILES = 5; /** * How old a `.tmp-*` file must be before the pre-write sweep will delete * it. * * The sweep cannot tell a crash leftover from another writer's work in * progress by name alone, so it uses age: a temp file written within the last * minute may still belong to a live write (another process, or this one on a * worker thread) and is left strictly alone. One minute is far longer than any * store here takes to serialize, open, write, fsync, chmod and rename, a few * hundred kilobytes of JSON at most, so a leftover from a process that really * did die becomes eligible on the next write a minute later, while a live * writer is never robbed of its temp file. */ export declare const STALE_TEMP_FILE_MIN_AGE_MS = 60000; /** * Build the temp path for one atomic write of `filePath`. * * Unique per call, never per process: `.tmp---`. The * pid and sequence are there so a leftover file names the process and the * write that produced it when someone goes looking; the random suffix is what * guarantees two writers never collide even across pid reuse. * * Exported so a test can hold a second writer's temp file the way a real * concurrent writer does, and assert the sweep leaves it alone. */ export declare function createAtomicTempPath(filePath: string): string; export interface AtomicWriteOptions { /** * Exact mode of the resulting file. Applied with an explicit `chmod` before * the rename, so the result does not vary with the process umask. * Defaults to `0o600`. */ readonly mode?: number; } export interface AtomicJsonWriteOptions extends AtomicWriteOptions { /** `JSON.stringify` indent. `null` writes compact JSON. Defaults to `2`. */ readonly indent?: number | null; /** Append a trailing newline to the serialized JSON. Defaults to `true`. */ readonly trailingNewline?: boolean; } /** * Write `contents` to `filePath` atomically, creating parent directories as * needed. See the module docstring for the mechanics and why they matter. */ export declare function writeFileAtomic(filePath: string, contents: string, options?: AtomicWriteOptions): void; /** Serialize `value` as JSON and write it atomically via {@link writeFileAtomic}. */ export declare function writeJsonFileAtomic(filePath: string, value: unknown, options?: AtomicJsonWriteOptions): void; export interface AtomicJsonSafeWriteOptions extends AtomicJsonWriteOptions { /** * Short store name for the failure log, e.g. `'watchers/store'`. Rendered as * `[