feat: implement concrete adapter classes

Add VaultAdapter, MetadataCacheAdapter, and FileManagerAdapter as
pass-through wrappers for Obsidian API objects.
This commit is contained in:
2025-10-19 23:14:54 -04:00
parent fc001e541d
commit e369904447
3 changed files with 81 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
import { Vault, TAbstractFile, TFile, TFolder, DataWriteOptions } from 'obsidian';
import { IVaultAdapter } from './interfaces';
export class VaultAdapter implements IVaultAdapter {
constructor(private vault: Vault) {}
async read(file: TFile): Promise<string> {
return this.vault.read(file);
}
stat(file: TAbstractFile): { ctime: number; mtime: number; size: number } | null {
if (file instanceof TFile) {
return file.stat;
}
return null;
}
getAbstractFileByPath(path: string): TAbstractFile | null {
return this.vault.getAbstractFileByPath(path);
}
getMarkdownFiles(): TFile[] {
return this.vault.getMarkdownFiles();
}
getRoot(): TFolder {
return this.vault.getRoot();
}
async process(file: TFile, fn: (data: string) => string, options?: DataWriteOptions): Promise<string> {
return this.vault.process(file, fn, options);
}
async createFolder(path: string): Promise<void> {
await this.vault.createFolder(path);
}
async create(path: string, data: string): Promise<TFile> {
return this.vault.create(path, data);
}
}