andy-stack_vaultkeeper-ai/Helpers/FileTagMapping.ts
Andrew Beal 182d12173a feat: add VaultCacheService and vault monitoring capabilities
Register VaultCacheService as singleton dependency, add file event registration to VaultService for monitoring vault changes, implement listVaultContents method to retrieve all files and folders with exclusion filtering, and add comprehensive test coverage for new functionality.
2025-10-25 12:46:07 +01:00

33 lines
No EOL
1.1 KiB
TypeScript

export class FileTagMapping {
private mapping: Map<string, string[]> = new Map();
public set(key: string, value: string[]) {
this.mapping.set(key, value);
}
public updateMapping(key: string, newTags: string[]): string[] {
const oldTags = this.mapping.get(key) ?? [];
const newTagsSet = new Set(newTags);
const removedTags = oldTags.filter(tag => !newTagsSet.has(tag));
this.mapping.set(key, newTags);
return removedTags.filter(tag => !this.anyFileHasTag(tag));
}
public deleteFromMapping(key: string): string[] {
const tags = this.mapping.get(key) ?? [];
this.mapping.delete(key);
return tags.filter(tag => !this.anyFileHasTag(tag));
}
public renameKey(oldKey: string, newKey: string) {
const tags = this.mapping.get(oldKey);
if (tags) {
this.mapping.delete(oldKey);
this.mapping.set(newKey, tags);
}
}
private anyFileHasTag(tag: string): boolean {
return Array.from(this.mapping.values()).some(tags => tags.includes(tag));
}
}