refactor: migrate NoteTools to use adapter pattern

Implements Task 10 from the implementation plan:

1. Updated NoteTools constructor to accept IVaultAdapter and IFileManagerAdapter
2. Created note-tools-factory.ts with factory function
3. Migrated all CRUD methods to use adapters:
   - readNote: uses vault.read()
   - createNote: uses vault.create(), vault.delete()
   - createParentFolders: uses vault.createFolder()
   - updateNote: uses vault.read(), vault.modify()
   - deleteNote: uses vault.trash(), vault.delete()
   - renameFile: uses fileManager.renameFile()
   - readExcalidraw: uses vault.read()
   - updateFrontmatter: uses vault.read(), vault.modify()
   - updateSections: uses vault.read(), vault.modify()
4. Extended IVaultAdapter interface with modify(), delete(), and trash() methods
5. Implemented new methods in VaultAdapter
6. Updated ToolRegistry to use factory function
7. Kept app parameter temporarily for PathUtils dependency
8. All methods now use adapters instead of direct Obsidian API calls
9. Code compiles successfully

This change enables 100% test coverage by allowing full mocking of vault operations.
This commit is contained in:
2025-10-19 23:53:48 -04:00
parent aca4d35944
commit 0185ca7d00
5 changed files with 59 additions and 19 deletions

View File

@@ -25,6 +25,13 @@ export interface IVaultAdapter {
// File creation
create(path: string, data: string): Promise<TFile>;
// File modification
modify(file: TFile, data: string): Promise<void>;
// File deletion
delete(file: TAbstractFile): Promise<void>;
trash(file: TAbstractFile, system: boolean): Promise<void>;
}
/**

View File

@@ -38,4 +38,16 @@ export class VaultAdapter implements IVaultAdapter {
async create(path: string, data: string): Promise<TFile> {
return this.vault.create(path, data);
}
async modify(file: TFile, data: string): Promise<void> {
await this.vault.modify(file, data);
}
async delete(file: TAbstractFile): Promise<void> {
await this.vault.delete(file);
}
async trash(file: TAbstractFile, system: boolean): Promise<void> {
await this.vault.trash(file, system);
}
}