-
-
Notifications
You must be signed in to change notification settings - Fork 404
Description
What is the problem this feature would solve?
Hey there, very cool project! I come from Java and got used to https://mapstruct.org/ which is a library to reduce boilerplate when you have to convert your domain objects to DTOs where many properties are exactly the same. Effect/Schema seems very similar except it doesn't have any "update" functionality out of the box, i.e. when you provide a deeply partial object (the patch) and the actual object (not partial, corresponds to the schema exactly), and then making applying the patch.
So, when developing an API, we have Create, Update, Get. Create and Get would transform from db object to DTO by the library, e.g. from { name, createdOn, createdBy, updatedOn, updatedBy, ...}
to {name}
. Plus the db object is an ORM object so I definitely don't want that part to be involved in http response as it may trigger extra fetches for no reason when traversing the object as each property is proxied by the framework. What we can also do, is also use the library for Update since the request body is actually of the exact same structure as whatever Create/Get return - the library will accept a source object and a target object and perform a deep merge with customizable steps, e.g. it will have afterMapping and beforeMapping for every nested src/dst pair that you can define, you can ignore certain paths with a dot notation, etc.
What is the feature you are proposing to solve the problem?
^
What alternatives have you considered?
https://www.reddit.com/r/javascript/comments/1mumvqj/inspired_by_javas_mapstruct_i_created_an/
See a thread about effect schema in there