rambda icon indicating copy to clipboard operation
rambda copied to clipboard

R.clone does not work with mongodb ObjectId

Open sks147 opened this issue 1 year ago • 1 comments

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.

sks147 avatar Sep 13 '22 04:09 sks147

Thanks for filling the issue. I'll try to get back to you once I have time.

selfrefactor avatar Sep 13 '22 08:09 selfrefactor

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.

selfrefactor avatar Oct 01 '22 08:10 selfrefactor

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.

selfrefactor avatar Oct 02 '22 14:10 selfrefactor