/** * Shared atomic single-file replacement: write a uniquely named temp file in * the target's directory, then rename it over the target. * * The temp file lives next to the target so the rename stays on one * filesystem (and therefore atomic), and is removed on any failure or * interruption. Temp names follow `.tmp.`; sweepers that * clean stale temps (e.g. the lockfile writer) rely on that prefix. * * @experimental This API is unstable and may change without notice. */ import * as Effect from "effect/Effect"; import type * as FileSystem from "effect/FileSystem"; import * as Path from "effect/Path"; import type { PlatformError } from "effect/PlatformError"; /** * Step at which an atomic write failed. `check-target` and `read-target` can * only occur with `skipIfUnchanged: "fail-on-read-error"`. * * @experimental This API is unstable and may change without notice. */ export type AtomicWriteStep = "check-target" | "read-target" | "write-temp" | "rename"; /** * Failure passed to `mapError` so each call site keeps its own error shape. * * @experimental This API is unstable and may change without notice. */ export interface AtomicWriteFailure { readonly step: AtomicWriteStep; readonly targetPath: string; readonly tempPath: string; readonly cause: PlatformError; } /** * Content-equality short-circuit mode: `fail-on-read-error` surfaces * check/read failures via `mapError`; `ignore-read-errors` treats an * unreadable target as changed and proceeds to write. * * @experimental This API is unstable and may change without notice. */ export type SkipIfUnchanged = "fail-on-read-error" | "ignore-read-errors"; /** * Options for `writeFileAtomic`. * * @experimental This API is unstable and may change without notice. */ export interface WriteFileAtomicOptions { readonly targetPath: string; readonly content: string | Uint8Array; /** When set, leave the target untouched if it already has this content. */ readonly skipIfUnchanged?: SkipIfUnchanged; /** Best-effort remove of the target before rename (Windows cannot always rename over an existing file). */ readonly removeTargetBeforeRename?: boolean; readonly mapError: (failure: AtomicWriteFailure) => E; } export declare const atomicWriteTempPrefix: (targetPath: string) => string; /** Remove only stale temp siblings belonging to one atomic-write target. */ export declare const sweepStaleAtomicWriteTemps: (fs: FileSystem.FileSystem, targetPath: string) => Effect.Effect; /** * Atomically replace `targetPath` with `content` via a same-directory temp * file and rename. Failures at each step are mapped by the caller, so error * codes, details, and suggestions stay call-site specific. * * @experimental This API is unstable and may change without notice. */ export declare const writeFileAtomic: (fs: FileSystem.FileSystem, options: WriteFileAtomicOptions) => Effect.Effect<"written" | "skipped", E>; //# sourceMappingURL=atomic-write.d.ts.map