From fc001e541dbcb19aa9652a6ae86f11401188dd62 Mon Sep 17 00:00:00 2001 From: Bill Date: Sun, 19 Oct 2025 23:06:09 -0400 Subject: [PATCH] feat: add adapter interfaces for dependency injection Create IVaultAdapter, IMetadataCacheAdapter, and IFileManagerAdapter interfaces to decouple tool classes from Obsidian API dependencies. --- src/adapters/interfaces.ts | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/adapters/interfaces.ts diff --git a/src/adapters/interfaces.ts b/src/adapters/interfaces.ts new file mode 100644 index 0000000..3e5163a --- /dev/null +++ b/src/adapters/interfaces.ts @@ -0,0 +1,53 @@ +import { TAbstractFile, TFile, TFolder, CachedMetadata, DataWriteOptions } from 'obsidian'; + +/** + * Adapter interface for Obsidian Vault operations + */ +export interface IVaultAdapter { + // File reading + read(file: TFile): Promise; + + // File existence and metadata + stat(file: TAbstractFile): { ctime: number; mtime: number; size: number } | null; + + // File retrieval + getAbstractFileByPath(path: string): TAbstractFile | null; + getMarkdownFiles(): TFile[]; + + // Directory operations + getRoot(): TFolder; + + // File creation (process method) + process(file: TFile, fn: (data: string) => string, options?: DataWriteOptions): Promise; + + // Folder creation + createFolder(path: string): Promise; + + // File creation + create(path: string, data: string): Promise; +} + +/** + * Adapter interface for Obsidian MetadataCache operations + */ +export interface IMetadataCacheAdapter { + // Cache access + getFileCache(file: TFile): CachedMetadata | null; + + // Link resolution + getFirstLinkpathDest(linkpath: string, sourcePath: string): TFile | null; + + // File cache for links and metadata + resolvedLinks: Record>; + unresolvedLinks: Record>; +} + +/** + * Adapter interface for Obsidian FileManager operations + */ +export interface IFileManagerAdapter { + // File operations + renameFile(file: TAbstractFile, newPath: string): Promise; + trashFile(file: TAbstractFile): Promise; + processFrontMatter(file: TFile, fn: (frontmatter: any) => void): Promise; +} \ No newline at end of file