Extend the diff function with rich types not included in the base JS language.
Closed this issue · 2 comments
❗ Is your feature request related to a problem? Please describe.
We use started using microdiff
as a pre-step before doing db updates. When working with MongoDB, then use the ObjectId
data type which is exported by the bson package to keep track of documents (records) and references between data.
It can be compared in JS using the toString() (or casting it to string).
However, currently microdiff compares it as an object and because the object has no properties (only methods), it can not identify the change.
✅ Describe the solution you'd like
In order for us to solve this issue and have microdiff detect changes to properties that are ObjectId, we needed to duplicate the function to our code base and extend the rich types object with the ObjectId: true
property to have it trigger the "rich type" check and be evaluated as two strings being compared with each other.
I would recommend adding a property to the third argument of the function where cyclesFix
can be passed in. This would be an object of extended rich types which then also need to be checked while calling the diff
function.
➕ Additional context
Other data types in JS which have a compatible (to String) method of comparing them can be added to this and thus we can still use the microdiff library without having to duplicate the functionality.
I am not sure if this is within the scope of Microdiff. What is stopping you from preprocessing the object to stringify the records beforehand?
Closing due to inactivity