rambda
rambda copied to clipboard
R.clone does not work with mongodb ObjectId
This is how the object looks like.
subOrder {
_id: new ObjectId("631dcbb157c64966c4aa2db3"),
After doing a deep clone. This is how it looks in console logs
subOrder {
_id: {
toHexString: [Function (anonymous)],
toString: [Function (anonymous)],
toJSON: [Function (anonymous)],
equals: [Function (anonymous)],
getTimestamp: [Function (anonymous)],
toExtendedJSON: [Function (anonymous)],
inspect: [Function (anonymous)]
},
And we get this error
Error [ERR_INTERNAL_ASSERTION]: TypeError: Cannot read properties of undefined (reading 'toString')
I have tested lodash.clonedeep and it works with mongo ObjectId.
Thanks for filling the issue. I'll try to get back to you once I have time.
Looking at the implementation of Lodash.cloneDeep, this might require a lot of work. I will still try to make it work for your case, but in any case, I will have to add more test so it is visible for which types R.clone doesn't work.
I just tested it and I am about to close the issue.
It seems that Ramda.clone also doesn't work with:
const mockObjectId = new mongoose.Types.ObjectId();
const cloned = Ramda.clone(mockObjectId)
I am keeping the issue open till I publish proper notification about the limitation of the method. Thanks for bringing this up.