Dont assume id on storage objects
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user