mirror of
https://github.com/andy-stack/vaultkeeper-ai.git
synced 2026-07-22 06:42:03 +00:00
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.
33 lines
No EOL
1.1 KiB
TypeScript
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));
|
|
}
|
|
} |