import type { RequiredKeys } from 'utilium'; import type { CaseFold, FileSystem } from '../internal/filesystem.js'; type OptionType = 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function' | string | ((arg: any) => boolean) | { [Symbol.hasInstance](instance: any): boolean; toString(): string; }; /** * Resolves the type of Backend.options from the options interface * @category Backends and Configuration */ export type OptionsConfig = { [K in Exclude]: { /** * The type of the option. Can be a: * - string given by `typeof` * - string that is the name of the class (e.g. `'Map'`) * - object with a `Symbol.hasInstance` property * - function that returns a boolean */ type: OptionType | readonly OptionType[]; /** * Whether or not the option is required (optional can be set to null or undefined). Defaults to false. */ required: K extends RequiredKeys ? true : false; }; }; /** * Configuration options shared by backends and `Configuration` * @category Backends and Configuration */ export interface SharedConfig { /** * If set, disables the sync cache and sync operations on async file systems. */ disableAsyncCache?: boolean; /** * If set, sets case folding for the file system(s). */ caseFold?: CaseFold; } /** * A backend * @category Backends and Configuration */ export interface Backend { /** * Create a new instance of the backend */ create(options: TOptions & Partial): FS | Promise; /** * A name to identify the backend. */ name: string; /** * Describes all of the options available for this backend. */ options: OptionsConfig; /** * Whether the backend is available in the current environment. * It supports checking synchronously and asynchronously * * Returns 'true' if this backend is available in the current * environment. For example, a backend using a browser API will return * 'false' if the API is unavailable * */ isAvailable?(config: TOptions): boolean | Promise; } /** * Gets the options type of a backend * @category Backends and Configuration * @internal */ export type OptionsOf = T extends Backend ? TOptions : never; /** * Gets the FileSystem type for a backend * @category Backends and Configuration * @internal */ export type FilesystemOf = T extends Backend ? FS : never; /** * @category Backends and Configuration * @internal */ export declare function isBackend(arg: unknown): arg is Backend; /** * Use a function as the type of an option, but don't treat it as a class. * * Optionally sets the name of a function, useful for error messages. * @category Backends and Configuration * @internal */ export declare function _fnOpt(name: string | null | undefined, fn: (arg: T) => boolean): (arg: T) => boolean; /** * Checks that `options` object is valid for the file system options. * @category Backends and Configuration * @internal */ export declare function checkOptions(backend: T, options: Record): void; /** * Specifies a file system backend type and its options. * * Individual options can recursively contain BackendConfiguration objects for values that require file systems. * * The configuration for each file system corresponds to that file system's option object passed to its `create()` method. * * @category Backends and Configuration */ export type BackendConfiguration = OptionsOf & Partial & { backend: T; }; /** * @internal * @category Backends and Configuration */ export declare function isBackendConfig(arg: unknown): arg is BackendConfiguration; export {};