fix(collectionfactory): isolate collection caching per database and add easy store replace semantics

This commit is contained in:
2026-04-07 16:24:42 +00:00
parent 97d9302e71
commit d30ce5ccc7
5 changed files with 134 additions and 6 deletions

View File

@@ -93,7 +93,9 @@ export class EasyStore<T> {
}
/**
* writes all keyValue pairs in the object argument
* merges all keyValue pairs from the object argument into the store.
* Existing keys that are not present in `keyValueObject` are preserved.
* To overwrite the entire store and drop missing keys, use `replace()`.
*/
public async writeAll(keyValueObject: Partial<T>) {
const easyStore = await this.getEasyStore();
@@ -101,6 +103,17 @@ export class EasyStore<T> {
await easyStore.save();
}
/**
* atomically replaces the entire store with the given object.
* Unlike `writeAll` (which merges), `replace` clears any keys not
* present in `keyValueObject`. Useful when you need to drop a key.
*/
public async replace(keyValueObject: Partial<T>) {
const easyStore = await this.getEasyStore();
easyStore.data = { ...keyValueObject };
await easyStore.save();
}
/**
* wipes a key value store from disk
*/