salesforce / akita

🚀 State Management Tailored-Made for JS Applications
https://salesforce.github.io/akita/
Apache License 2.0
3.7k stars 342 forks source link

`upsertMany` does not function correctly in class-based entity stores #1083

Open ZeevKatz opened 5 months ago

ZeevKatz commented 5 months ago

Is this a regression?

No

Description

The updateEntities function is specifically designed to manage class-based entity stores also. It ensures that any entities updated are always instances of the appropriate class, by checking against both the previous and next object classes in the entity sequence (for more details, see this comment).

On the other hand, EntityStore.upsertMany employs a different update logic which does not automatically handle the class of the previous and next entities unless a class reference is explicitly provided in the options object. Notably, the paginator plugin relies on upsertMany to load new pages and does not offer the option to specify a class reference. This oversight leads to a conversion from class objects to plain objects when existing pages are reloaded, potentially causing data integrity issues.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in

No response

Anything else?

No response

Do you want to create a pull request?

Yes