/** * @file * * Mock of Obsidian's `FileSystemAdapter`, the desktop vault adapter, backed by an in-memory filesystem. */ import type { DataWriteOptions as DataWriteOptionsOriginal, FileSystemAdapter as FileSystemAdapterOriginal } from 'obsidian'; import { InMemoryAdapter } from '../internal/in-memory-adapter.mjs'; /** * Mock of Obsidian's `FileSystemAdapter`. * * File operations come from the in-memory adapter; nothing touches the real disk. The base path is only used to * build the absolute paths the desktop adapter reports. */ export declare class FileSystemAdapter extends InMemoryAdapter { /** * Creates an adapter rooted at a base path. Use {@link FileSystemAdapter.create__} from tests. * * @param basePath - The absolute path the vault is reported to live at. */ protected constructor(basePath: string); /** * Mock-only factory: creates a file system adapter, spyable via `vi.spyOn(FileSystemAdapter, 'create__')`. * * @param basePath - The absolute path the vault is reported to live at. * @returns The new file system adapter. */ static create__(basePath: string): FileSystemAdapter; /** * Mock-only: views a value typed as Obsidian's `FileSystemAdapter` as this mock. * * @param value - The value typed as the original `FileSystemAdapter`. * @returns The same object, typed as the mock. */ static fromOriginalType__(value: FileSystemAdapterOriginal): FileSystemAdapter; /** * Reads a file from anywhere on the local disk, by absolute path. * * The mock reads nothing: it resolves to an empty buffer. * * @param _path - The absolute path of the file to read. * @returns An empty `ArrayBuffer`. */ static readLocalFile(_path: string): Promise; /** * Adds text to the end of a text file, as the in-memory adapter does, except that the file's folder must already * exist: Obsidian's desktop adapter runs `fs.appendFile`, which does not create parents. * * @param normalizedPath - The vault-relative path of the file. * @param data - The text to append. * @param options - Explicit `ctime` / `mtime` to record; by default `ctime` is kept and `mtime` is now. * @throws Error `ENOENT: no such file or directory, open …` when the file's folder does not exist, and * `ENOTDIR: not a directory, open …` when a file sits where that folder would be. */ append(normalizedPath: string, data: string, options?: DataWriteOptionsOriginal): Promise; /** * Adds bytes to the end of a binary file, as the in-memory adapter does, except that the file's folder must already * exist: Obsidian's desktop adapter runs `fs.appendFile`, which does not create parents. * * @param normalizedPath - The vault-relative path of the file. * @param data - The bytes to append. * @param options - Explicit `ctime` / `mtime` to record; by default `ctime` is kept and `mtime` is now. * @throws Error `ENOENT: no such file or directory, open …` when the file's folder does not exist, and * `ENOTDIR: not a directory, open …` when a file sits where that folder would be. */ appendBinary(normalizedPath: string, data: ArrayBuffer, options?: DataWriteOptionsOriginal): Promise; /** * Mock-only: views this mock as Obsidian's `FileSystemAdapter` type. * * @returns The same object, typed as the original `FileSystemAdapter`. */ asOriginalType__(): FileSystemAdapterOriginal; /** * Mock-only construction hook, called at the end of the constructor; a no-op meant for * `vi.spyOn(FileSystemAdapter.prototype, 'constructor__')`. * * @param _basePath - The base path the adapter was created with. */ constructor__(_basePath: string): void; /** * Copies a file, or a folder together with everything under it, as the in-memory adapter does, except that a FILE * is never copied into a missing folder: Obsidian's desktop adapter copies a file with `fs.copyFile`, which does not * create parents, while it creates a copied folder with a recursive `mkdir`, which does. * * @param normalizedPath - The vault-relative path of the file or folder to copy. * @param normalizedNewPath - The vault-relative path of the copy. * @throws Error `ENOENT: no such file or directory, copyfile …` when a file's destination folder does not exist, and * whatever {@link InMemoryAdapter.copy} throws. */ copy(normalizedPath: string, normalizedNewPath: string): Promise; /** * Gets the absolute path of the vault folder on disk. * * @returns The base path the adapter was created with. */ getBasePath(): string; /** * Gets the `file://` path of a vault file. * * The mock does not build a `file://` URL: it joins the base path and the vault path with `/`. * * @param normalizedPath - The vault path of the file. * @returns The base path and `normalizedPath` joined with `/`. */ getFilePath(normalizedPath: string): string; /** * Gets the absolute on-disk path of a vault file. * * @param normalizedPath - The vault path of the file. * @returns The base path and `normalizedPath` joined with `/`. */ getFullPath(normalizedPath: string): string; /** * Removes a folder. Obsidian's desktop adapter runs `fs.rm(path, { recursive })`, so without `recursive` it * refuses ANY folder, an empty one included. A FILE at `normalizedPath` is deleted whatever `recursive` says, as * `fs.rm` deletes one. * * @param normalizedPath - The vault-relative path of the folder. * @param recursive - Whether to delete everything under the folder too. * @throws Error `ENOENT: no such file or directory, lstat …` when nothing exists at `normalizedPath`, and * `Path is a directory: rm returned EISDIR (is a directory) …` when it is a folder and `recursive` is not set. */ rmdir(normalizedPath: string, recursive: boolean): Promise; /** * Writes a text file, as the in-memory adapter does, except that the file's folder must already exist: Obsidian's * desktop adapter runs `fs.writeFile`, which does not create parents. This is what makes `Vault.create` reject a * path whose folder is missing, exactly as in the app, where the vault itself checks nothing. * * @param normalizedPath - The vault-relative path of the file. * @param data - The new content. * @param options - Explicit `ctime` / `mtime` to record; by default `ctime` is kept and `mtime` is now. * @throws Error `ENOENT: no such file or directory, open …` when the file's folder does not exist, and * `ENOTDIR: not a directory, open …` when a file sits where that folder would be. */ write(normalizedPath: string, data: string, options?: DataWriteOptionsOriginal): Promise; /** * Writes a binary file, as the in-memory adapter does, except that the file's folder must already exist: Obsidian's * desktop adapter runs `fs.writeFile`, which does not create parents. This is what makes `Vault.createBinary` reject * a path whose folder is missing, exactly as in the app, where the vault itself checks nothing. * * @param normalizedPath - The vault-relative path of the file. * @param data - The new content, stored as is without copying. * @param options - Explicit `ctime` / `mtime` to record; by default `ctime` is kept and `mtime` is now. * @throws Error `ENOENT: no such file or directory, open …` when the file's folder does not exist, and * `ENOTDIR: not a directory, open …` when a file sits where that folder would be. */ writeBinary(normalizedPath: string, data: ArrayBuffer, options?: DataWriteOptionsOriginal): Promise; private ensureParentFolderForOpen; }