Dont assume id on storage objects

This commit is contained in:
2026-02-25 14:06:34 +11:00
parent 648f186903
commit f1fa2acf17
8 changed files with 922 additions and 221 deletions

View File

@@ -20,14 +20,11 @@ export class StorageMemorySynced<T extends Record<string, any> = Record<string,
});
this.store.on('update', async (payload) => {
// For update events, we need to find and update the document in memory
// Since we don't have the filter, we'll update by key
const filter = {
id: payload.value.id,
} as unknown as Partial<T>
// Update the document in memory by ID.
await this.inMemoryCache.updateOne(filter, payload.value);
// Remove the old version and insert the new one. We use delete + insert
// rather than updateOne because the oldValue is the complete document,
// guaranteeing an exact match without assuming any particular key field.
await this.inMemoryCache.deleteOne(payload.oldValue);
await this.inMemoryCache.insertOne(payload.value);
this.emit('update', payload);
});