import type { RmOptions } from 'node:fs'; import type { FileFilter, ResolvedPath, PathFilter } from './path.js'; /** * Discriminated filesystem error kinds. * * The shared error shape for `Result<{value: T}, FsError>`-returning filesystem * deps across the ecosystem. Callers branch on `kind` instead of regex-matching * `message`. The set is deliberately small — add kinds only when a caller * needs to distinguish them. */ export type FsError = { kind: 'not_found'; message: string; } | { kind: 'permission_denied'; message: string; } | { kind: 'already_exists'; message: string; } | { kind: 'io_error'; message: string; }; /** * Extends `FsError` with `invalid_json` for `read_json`-style ops where the * file exists but parse fails. Callers can distinguish missing from corrupt * (e.g. self-healing config loads) without regex-matching `message`. */ export type FsJsonError = FsError | { kind: 'invalid_json'; message: string; }; /** * Classifies a thrown filesystem error into a discriminated `FsError`. * * Reads the Node `code` property (`ENOENT`/`EACCES`/`EPERM`/`EEXIST`) — Deno * surfaces the same codes when throwing from `node:fs/promises`. Unknown codes * fall through to `io_error`. */ export declare const fs_classify_error: (error: unknown) => FsError; /** * Checks if a file or directory exists. */ export declare const fs_exists: (path: string) => Promise; /** * Empties a directory, recursively by default. If `should_remove` is provided, only entries where it returns `true` are removed. */ export declare const fs_empty_dir: (dir: string, should_remove?: (name: string) => boolean, options?: RmOptions) => Promise; export interface FsSearchOptions { /** * One or more filter functions, any of which can short-circuit the search by returning `false`. */ filter?: PathFilter | Array; /** * One or more file filter functions. Every filter must pass for a file to be included. */ file_filter?: FileFilter | Array; /** * Pass `null` or `false` to speed things up at the cost of volatile ordering. */ sort?: boolean | null | ((a: ResolvedPath, b: ResolvedPath) => number); /** * Set to `true` to include directories. Defaults to `false`. */ include_directories?: boolean; /** * Sets the cwd for `dir` unless it's an absolute path or `null`. */ cwd?: string | null; } export declare const fs_search: (dir: string, options?: FsSearchOptions) => Promise>; //# sourceMappingURL=fs.d.ts.map