feat: implement concrete adapter classes
Add VaultAdapter, MetadataCacheAdapter, and FileManagerAdapter as pass-through wrappers for Obsidian API objects.
This commit is contained in:
41
src/adapters/vault-adapter.ts
Normal file
41
src/adapters/vault-adapter.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user