import type { FilePath, UXStat } from "@/lib/src/common/types"; import type { IFileSystemAdapter, IPathAdapter, ITypeGuardAdapter, IConversionAdapter, IStorageAdapter, IVaultAdapter, } from "@/lib/src/serviceModules/adapters"; import type { TAbstractFile, TFile, TFolder, Stat, App } from "obsidian"; import { ObsidianConversionAdapter } from "./ObsidianConversionAdapter"; import { ObsidianPathAdapter } from "./ObsidianPathAdapter"; import { ObsidianStorageAdapter } from "./ObsidianStorageAdapter"; import { ObsidianTypeGuardAdapter } from "./ObsidianTypeGuardAdapter"; import { ObsidianVaultAdapter } from "./ObsidianVaultAdapter"; declare module "obsidian" { interface Vault { getAbstractFileByPathInsensitive(path: string): TAbstractFile | null; } interface DataAdapter { reconcileInternalFile?(path: string): Promise; } } /** * Complete file system adapter implementation for Obsidian */ export class ObsidianFileSystemAdapter implements IFileSystemAdapter { readonly path: IPathAdapter; readonly typeGuard: ITypeGuardAdapter; readonly conversion: IConversionAdapter; readonly storage: IStorageAdapter; readonly vault: IVaultAdapter; constructor(private app: App) { this.path = new ObsidianPathAdapter(); this.typeGuard = new ObsidianTypeGuardAdapter(); this.conversion = new ObsidianConversionAdapter(); this.storage = new ObsidianStorageAdapter(app); this.vault = new ObsidianVaultAdapter(app); } getAbstractFileByPath(path: FilePath | string): TAbstractFile | null { return this.app.vault.getAbstractFileByPath(path); } getAbstractFileByPathInsensitive(path: FilePath | string): TAbstractFile | null { return this.app.vault.getAbstractFileByPathInsensitive(path); } getFiles(): TFile[] { return this.app.vault.getFiles(); } statFromNative(file: TFile): Promise { return Promise.resolve({ ...file.stat, type: "file" }); } async reconcileInternalFile(path: string): Promise { return await Promise.resolve(this.app.vault.adapter.reconcileInternalFile?.(path)); } }