fix(collectionfactory): isolate collection caching per database and add easy store replace semantics
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user