import { t as ReadResult } from "./read-opened-file-CxgSVMdu.js";
import { Stats } from "node:fs";
import { FileHandle } from "node:fs/promises";
import { Readable } from "node:stream";

//#region packages/fs-safe/dist/deny-mutations.d.ts
type DenyMutationPolicy = {
  paths?: readonly string[];
  prefixes?: readonly string[];
};
//#endregion
//#region packages/fs-safe/dist/types.d.ts
type PathStat = {
  dev: number;
  gid: number;
  ino: number;
  isDirectory: boolean;
  isFile: boolean;
  isSymbolicLink: boolean;
  mode: number;
  mtimeMs: number;
  nlink: number;
  size: number;
  uid: number;
};
type DirEntry = PathStat & {
  name: string;
};
//#endregion
//#region packages/fs-safe/dist/root-impl.d.ts
type OpenResult = {
  handle: FileHandle;
  realPath: string;
  stat: Stats;
  [Symbol.asyncDispose](): Promise<void>;
};
type SymlinkPolicy = "reject" | "follow-within-root";
type HardlinkPolicy = "reject" | "allow";
type WritableOpenMode = "replace" | "append" | "update";
type RootDefaults = {
  hardlinks?: HardlinkPolicy;
  maxBytes?: number;
  mkdir?: boolean;
  mode?: number;
  denyMutations?: DenyMutationPolicy;
  nonBlockingRead?: boolean;
  symlinks?: SymlinkPolicy;
};
type RootReadOptions = Pick<RootDefaults, "hardlinks" | "maxBytes" | "nonBlockingRead" | "symlinks">;
type RootOpenOptions = Omit<RootReadOptions, "maxBytes">;
type RootWriteOptions = Pick<RootDefaults, "denyMutations" | "mkdir" | "mode"> & {
  encoding?: BufferEncoding;
  overwrite?: boolean;
};
type RootOpenWritableOptions = Pick<RootDefaults, "denyMutations" | "mkdir" | "mode"> & {
  writeMode?: WritableOpenMode;
};
type RootCopyOptions = Pick<RootDefaults, "denyMutations" | "maxBytes" | "mkdir" | "mode"> & {
  sourceHardlinks?: HardlinkPolicy;
};
type RootWriteJsonOptions = RootWriteOptions & {
  replacer?: Parameters<typeof JSON.stringify>[1];
  space?: Parameters<typeof JSON.stringify>[2];
  trailingNewline?: boolean;
};
type RootCreateOptions = Omit<RootWriteOptions, "overwrite">;
type RootCreateJsonOptions = Omit<RootWriteJsonOptions, "overwrite">;
type RootAppendOptions = RootWriteOptions & {
  prependNewlineIfNeeded?: boolean;
};
type RootMoveOptions = Pick<RootDefaults, "denyMutations"> & {
  overwrite?: boolean;
};
type RootRemoveOptions = Pick<RootDefaults, "denyMutations">;
type RootMkdirOptions = Pick<RootDefaults, "denyMutations">;
interface Root {
  readonly rootDir: string;
  readonly rootReal: string;
  readonly rootWithSep: string;
  readonly defaults: RootDefaults;
  resolve(relativePath: string): Promise<string>;
  open(relativePath: string, options?: RootOpenOptions): Promise<OpenResult>;
  read(relativePath: string, options?: RootReadOptions): Promise<ReadResult>;
  readBytes(relativePath: string, options?: RootReadOptions): Promise<Buffer>;
  readText(relativePath: string, options?: RootReadOptions & {
    encoding?: BufferEncoding;
  }): Promise<string>;
  readJson<T = unknown>(relativePath: string, options?: RootReadOptions & {
    encoding?: BufferEncoding;
  }): Promise<T>;
  readAbsolute(filePath: string, options?: RootReadOptions): Promise<ReadResult>;
  reader(options?: RootReadOptions): (filePath: string) => Promise<Buffer>;
  openWritable(relativePath: string, options?: RootOpenWritableOptions): Promise<WritableOpenResult>;
  append(relativePath: string, data: string | Buffer, options?: RootAppendOptions): Promise<void>;
  remove(relativePath: string, options?: RootRemoveOptions): Promise<void>;
  mkdir(relativePath: string, options?: RootMkdirOptions): Promise<void>;
  ensureRoot(options?: RootMkdirOptions): Promise<void>;
  write(relativePath: string, data: string | Buffer, options?: RootWriteOptions): Promise<void>;
  create(relativePath: string, data: string | Buffer, options?: RootCreateOptions): Promise<void>;
  writeJson(relativePath: string, data: unknown, options?: RootWriteJsonOptions): Promise<void>;
  createJson(relativePath: string, data: unknown, options?: RootCreateJsonOptions): Promise<void>;
  copyIn(relativePath: string, sourcePath: string, options?: RootCopyOptions): Promise<void>;
  exists(relativePath: string): Promise<boolean>;
  stat(relativePath: string): Promise<PathStat>;
  list(relativePath: string, options?: {
    withFileTypes?: false;
  }): Promise<string[]>;
  list(relativePath: string, options: {
    withFileTypes: true;
  }): Promise<DirEntry[]>;
  move(fromRelative: string, toRelative: string, options?: RootMoveOptions): Promise<void>;
}
type WritableOpenResult = {
  handle: FileHandle;
  createdForWrite: boolean;
  realPath: string;
  stat: Stats;
  [Symbol.asyncDispose](): Promise<void>;
};
//#endregion
//#region packages/fs-safe/dist/sidecar-lock.d.ts
type SidecarLockRetryOptions = {
  retries?: number;
  factor?: number;
  minTimeout?: number;
  maxTimeout?: number;
  randomize?: boolean;
};
type SidecarLockStaleRecovery = "fail-closed" | "remove-if-unchanged";
//#endregion
//#region packages/fs-safe/dist/file-store-prune.d.ts
type FileStorePruneOptions = {
  ttlMs: number;
  recursive?: boolean;
  maxDepth?: number;
  pruneEmptyDirs?: boolean;
};
//#endregion
//#region packages/fs-safe/dist/file-lock.d.ts
type FileLockRetryOptions = SidecarLockRetryOptions;
//#endregion
//#region packages/fs-safe/dist/json-document-store.d.ts
type JsonStoreLockOptions = {
  staleMs?: number;
  timeoutMs?: number;
  retry?: FileLockRetryOptions;
  staleRecovery?: SidecarLockStaleRecovery;
  managerKey?: string;
};
type JsonFileStoreOptions = {
  trailingNewline?: boolean;
  lock?: boolean | JsonStoreLockOptions;
};
type JsonStore<T> = {
  readonly filePath: string;
  read(): Promise<T | undefined>;
  readOr(fallback: T): Promise<T>;
  readRequired(): Promise<T>;
  write(value: T): Promise<void>;
  update(run: (current: T | undefined) => T | Promise<T>): Promise<T>;
  updateOr(fallback: T, run: (current: T) => T | Promise<T>): Promise<T>;
};
//#endregion
//#region packages/fs-safe/dist/file-store.d.ts
type FileStoreWriteOptions = {
  dirMode?: number;
  mode?: number;
  maxBytes?: number;
  tempPrefix?: string;
};
type FileStoreReadOptions = RootReadOptions & {
  encoding?: BufferEncoding;
};
type FileStore = {
  readonly rootDir: string;
  path(relativePath: string): string;
  root(): Promise<Root>;
  write(relativePath: string, data: string | Uint8Array, options?: FileStoreWriteOptions): Promise<string>;
  writeStream(relativePath: string, stream: Readable, options?: FileStoreWriteOptions): Promise<string>;
  copyIn(relativePath: string, sourcePath: string, options?: FileStoreWriteOptions): Promise<string>;
  open(relativePath: string, options?: RootReadOptions): Promise<OpenResult>;
  read(relativePath: string, options?: RootReadOptions): Promise<ReadResult>;
  readBytes(relativePath: string, options?: RootReadOptions): Promise<Buffer>;
  readText(relativePath: string, options?: FileStoreReadOptions): Promise<string>;
  readTextIfExists(relativePath: string, options?: FileStoreReadOptions): Promise<string | null>;
  readJson<T = unknown>(relativePath: string, options?: FileStoreReadOptions): Promise<T>;
  readJsonIfExists<T = unknown>(relativePath: string, options?: FileStoreReadOptions): Promise<T | null>;
  remove(relativePath: string): Promise<void>;
  exists(relativePath: string): Promise<boolean>;
  writeText(relativePath: string, data: string | Uint8Array, options?: FileStoreWriteOptions): Promise<string>;
  writeJson(relativePath: string, data: unknown, options?: FileStoreWriteOptions & {
    trailingNewline?: boolean;
  }): Promise<string>;
  json<T = unknown>(relativePath: string, options?: JsonFileStoreOptions): JsonStore<T>;
  pruneExpired(options: FileStorePruneOptions): Promise<void>;
};
type FileStoreSync = {
  readonly rootDir: string;
  path(relativePath: string): string;
  readTextIfExists(relativePath: string, options?: {
    maxBytes?: number;
  }): string | null;
  readJsonIfExists<T = unknown>(relativePath: string, options?: {
    maxBytes?: number;
  }): T | null;
  write(relativePath: string, data: string | Uint8Array, options?: FileStoreWriteOptions): string;
  writeText(relativePath: string, data: string | Uint8Array, options?: FileStoreWriteOptions): string;
  writeJson(relativePath: string, data: unknown, options?: FileStoreWriteOptions & {
    trailingNewline?: boolean;
  }): string;
};
//#endregion
export { FileStoreSync as n, OpenResult as r, FileStore as t };