Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: asCID property self reference #18

Merged
merged 1 commit into from
Jul 16, 2020
Merged

feat: asCID property self reference #18

merged 1 commit into from
Jul 16, 2020

Conversation

mikeal
Copy link
Contributor

@mikeal mikeal commented Jun 16, 2020

This came up in a conversation I had with @Gozala

This feature is nice for a few reasons.

  1. it’s a relatively unique property you can check that doesn’t rely on symbols.
  2. this makes the toJSON() representation serializable through a Worker but, since it includes a circular reference, can still be understood as a CID instead of just a regular object.
  3. this breaks CID serialization and causes an exception when you try to naively encode them as objects.

However, if we take this change it will require some updates to our codecs. In both dag-cbor and in dag-json we do an isCircular check before encoding an object and that runs through a relatively naive third party library that will now throw. But it’s already in my mental backlog to get rid of is-circular so it’s probably fine.

@mikeal mikeal requested review from rvagg and vmx June 16, 2020 17:49
@Gozala
Copy link
Contributor

Gozala commented Jun 16, 2020

Looks good to me! I also have sketched what we discussed in the call here
multiformats/js-cid#111 (comment)

@mikeal
Copy link
Contributor Author

mikeal commented Jun 16, 2020

Is it confusing to use the same property name for the instance and static class method?

@Gozala
Copy link
Contributor

Gozala commented Jun 16, 2020

Is it confusing to use the same property name for the instance and static class method?

I don't think so, as property is mostly for static method to recognize CID. That being said I really could not care less about property or static method name. Mostly went with asCID as it's one char different from isCID :)

Copy link
Member

@rvagg rvagg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess so ... it's pretty user-hostile though to be doing this in toJSON(), what does that look like if someone's using JSON.stringify() on a parent object for debugging?

@mikeal
Copy link
Contributor Author

mikeal commented Jun 16, 2020

I guess so ... it's pretty user-hostile though to be doing this in toJSON(), what does that look like if someone's using JSON.stringify() on a parent object for debugging?

That’s a good point.

Maybe we leave it out of toJSON() and just leave it enumerable. Most encoders probably enumerate the properties rather than using toJSON().

@jacobheun
Copy link

Should this be merged or do we need resolution on toJSON? It's been approved and sitting for a while.

@jacobheun
Copy link

Also, is the plan to replace the cids module everywhere? If so, is there a rollout plan for that?

@mikeal
Copy link
Contributor Author

mikeal commented Jul 9, 2020

Should this be merged or do we need resolution on toJSON? It's been approved and sitting for a while.

I’ll be returning to it eventually, other priorities have been getting in the way. I started this PR to fully consider the interface and I don’t feel like I’ve really had the time to do that yet.

Also, is the plan to replace the cids module everywhere? If so, is there a rollout plan for that?

Yes, some day, but not today :)

For js-ipfs this shouldn’t get adopted any time too soon, and should be part of a much larger change migrating to all the new Block and multiformats interfaces. But it’s premature to consider that given that we haven’t even updated our own stack to these changes.

I’ll join the IPFS implementations call on Monday to discuss these changes in more detail.

@vmx
Copy link
Member

vmx commented Jul 10, 2020

I'm strongly against breaking toJSON().

@mikeal
Copy link
Contributor Author

mikeal commented Jul 10, 2020

I'm strongly against breaking toJSON().

Ya, we won’t be, if this lands it’ll land without the toJSON() break.

Copy link
Member

@vmx vmx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please give the commit message a better header and a bit more context.

@mikeal mikeal merged commit 5a7ac96 into master Jul 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants