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: add types #189

Merged
merged 7 commits into from
Apr 8, 2021
Merged

feat: add types #189

merged 7 commits into from
Apr 8, 2021

Conversation

hugomrdias
Copy link
Member

@hugomrdias hugomrdias commented Mar 31, 2021

This PR adds types, updates aegir and others deps.

BREAKING CHANGES:

  • entry point uses named exports
// before

const multiaddr = require('multiaddr')
multiaddr.resolvers
multiaddr.protocols

// after

const {multiaddr , Multiaddr, protocols, resolvers} = = require('multiaddr')
Multiaddr.resolvers
Multiaddr.protocols
  • Multiaddr is a normal class now
  • toOptions output changed to match node
// before
multiaddr('/ip4/127.0.0.1/tcp/4001').toOptions()
{ family: 'ipv4', host: '127.0.0.1', transport: 'tcp', port: 4001 }

// after
new Multiaddr('/ip4/127.0.0.1/tcp/4001').toOptions()
{ family: 4, host: '127.0.0.1', transport: 'tcp', port: 4001 }
  • fromNodeAddress and nodeAddress inputs/outputs now match
// before the family type was not the same between them
multiaddr('/ip4/127.0.0.1/tcp/4001').nodeAddress()
{family: 4, address: '127.0.0.1', port: '4001'}

multiaddr.fromNodeAddress({family: 'IPv4', address: '127.0.0.1', port: '4001'}, 'tcp')
<Multiaddr 047f000001060fa1 - /ip4/127.0.0.1/tcp/4001>

// after 
new Multiaddr('/ip4/127.0.0.1/tcp/4001').nodeAddress()
{family: 4, address: '127.0.0.1', port: 4001}

Multiaddr.fromNodeAddress({family: 4, address: '127.0.0.1', port: '4001'}, 'tcp')
<Multiaddr 047f000001060fa1 - /ip4/127.0.0.1/tcp/4001>

closes #160
closes #159

This PR also updates aegir and others deps.
@hugomrdias hugomrdias self-assigned this Mar 31, 2021
@vasco-santos vasco-santos self-requested a review April 6, 2021 11:31
Copy link
Member

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

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

Almost done, left a few comments for final details and we need to decide if we want to do a breaking change or not here, in the toOptions return type

Also, probably worth flag that we should add to the release notes a notice for deprecation of the factory to already give a heads up to users

README.md Outdated
@@ -85,7 +65,7 @@ the global namespace.
```js
$ node

> const multiaddr = require('multiaddr')
> const multiaddr } = require('multiaddr')

> const addr = multiaddr("/ip4/127.0.0.1/udp/1234")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
> const addr = multiaddr("/ip4/127.0.0.1/udp/1234")
> const addr = new Multiaddr("/ip4/127.0.0.1/udp/1234")

Copy link
Member Author

Choose a reason for hiding this comment

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

there a factory method exported

Copy link
Member

Choose a reason for hiding this comment

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

yes, but all the other code examples in jsdocs are with the constructor, why having these different? I also thought we were going to migrate into using the class instance in the future

Copy link
Member Author

Choose a reason for hiding this comment

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

the factory method returns an instance, its just an helper i will add an example of both

README.md Outdated
@@ -85,7 +65,7 @@ the global namespace.
```js
$ node

> const multiaddr = require('multiaddr')
> const multiaddr } = require('multiaddr')
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
> const { multiaddr } = require('multiaddr')
> const { Multiaddr } = require('multiaddr')

Copy link
Member Author

Choose a reason for hiding this comment

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

theres a factory method exported

Copy link
Member

Choose a reason for hiding this comment

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

yes, but all the other code examples in jsdocs are with the constructor, why having these different? I also thought we were going to migrate into using the class instance in the future

package.json Outdated Show resolved Hide resolved
src/codec.js Outdated Show resolved Hide resolved
src/codec.js Outdated Show resolved Hide resolved
src/resolvers/dns.js Outdated Show resolved Hide resolved
src/resolvers/dns.browser.js Outdated Show resolved Hide resolved
src/resolvers/index.js Show resolved Hide resolved
/** @type {MultiaddrObject} */
const opts = {}
const parsed = this.toString().split('/')
opts.family = parsed[1] === 'ip4' ? 4 : 6
Copy link
Member

Choose a reason for hiding this comment

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

This will mean a breaking change

Copy link
Member

Choose a reason for hiding this comment

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

can you add a breaking change message to the commit?

Copy link
Member

Choose a reason for hiding this comment

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

I am thinking if we really want to make a breaking change just for this change and removing the resolve static function. This will mean we need to update all the modules. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

its a breaking change already because the exports changed right ?

src/index.js Outdated Show resolved Hide resolved
@vasco-santos
Copy link
Member

@hugomrdias can you look into the CI?

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.

sgtm, for what that's worth

@hugomrdias
Copy link
Member Author

update the readme usage example with the factory function, remove the resolve test and update the PR description with detailed examples for the breaking changes

Copy link
Member

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

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

LGTM

The webworker tests have an issue though

@vasco-santos
Copy link
Member

We have an issue on firefox worker still. Can you check it?

@rvagg
Copy link
Member

rvagg commented Apr 8, 2021

Is there any chance the Firefox problem was related to the one @achingbrain had with js-ipfs which forced him to disable it? I think it was with webworkers running twice there but the output doesn't seem to suggest the same here (although there isn't much useful output, just a timeout).

@hugomrdias
Copy link
Member Author

Is there any chance the Firefox problem was related to the one @achingbrain had with js-ipfs which forced him to disable it? I think it was with webworkers running twice there but the output doesn't seem to suggest the same here (although there isn't much useful output, just a timeout).

No, i already fixed this just need to release pw-test. Double output should still happen though.

Copy link
Member

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

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

LGTM

@vasco-santos vasco-santos merged commit 7d284e4 into master Apr 8, 2021
@vasco-santos vasco-santos deleted the feat/add-types-2 branch April 8, 2021 12:32
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.

3 participants