MCPcopy
hub / github.com/callumalpass/tasknotes / Vault

Class Vault

tests/__mocks__/obsidian.ts:268–342  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

266
267// Vault mock class
268export class Vault {
269 private emitter = new EventEmitter();
270
271 async create(path: string, content: string): Promise<TFile> {
272 const file = mockFileSystem.create(path, content);
273 const tFile = new TFile(file.path);
274 this.emitter.emit('create', tFile);
275 return tFile;
276 }
277
278 async modify(file: TFile, content: string): Promise<void> {
279 const mockFile = mockFileSystem.getFile(file.path);
280 if (mockFile) {
281 mockFileSystem.modify(mockFile, content);
282 this.emitter.emit('modify', file);
283 }
284 }
285
286 async delete(file: TFile): Promise<void> {
287 mockFileSystem.delete(file.path);
288 this.emitter.emit('delete', file);
289 }
290
291 async rename(file: TFile, newPath: string): Promise<void> {
292 const oldPath = file.path;
293 mockFileSystem.rename(oldPath, newPath);
294 file.path = newPath;
295 this.emitter.emit('rename', file, oldPath);
296 }
297
298 async read(file: TFile): Promise<string> {
299 return mockFileSystem.read(file.path);
300 }
301
302 async createFolder(path: string): Promise<TFolder> {
303 mockFileSystem.ensureFolderExists(path);
304 return new TFolder(path);
305 }
306
307 getAbstractFileByPath(path: string): TAbstractFile | null {
308 const normalizedPath = mockFileSystem['normalizePath'](path);
309 if (mockFileSystem.exists(normalizedPath)) {
310 return new TFile(normalizedPath);
311 }
312 return null;
313 }
314
315 getFiles(): TFile[] {
316 return mockFileSystem.getFiles().map(file => new TFile(file.path));
317 }
318
319 getMarkdownFiles(): TFile[] {
320 return mockFileSystem.getFiles()
321 .filter(file => file.extension === 'md')
322 .map(file => new TFile(file.path));
323 }
324
325 adapter = {

Callers

nothing calls this directly

Calls 1

existsMethod · 0.80

Tested by

no test coverage detected