-
Notifications
You must be signed in to change notification settings - Fork 27
Conversation
3d88eae
to
17f4031
Compare
fc35ea6
to
7a861c4
Compare
@@ -62,6 +62,9 @@ class Topology { | |||
return Boolean(other && other[topologySymbol]) | |||
} | |||
|
|||
/** | |||
* @param {any} registrar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would need to create a circular dependency to have registrar types in the interface. We can change this interaction, but I feel we should not spend a lof of time reinventing this interaction at the moment.
7a861c4
to
12bd9eb
Compare
09f867b
to
ba4b7a3
Compare
ba4b7a3
to
c34a1fb
Compare
dc8a342
to
d10b3e6
Compare
import PeerId from 'peer-id' | ||
import Multiaddr from 'multiaddr' | ||
|
||
declare class PeerRouting { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its not exported ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was doing a named import on libp2p
, but it makes sense to export this by default. I changed it here and in the other relevant types files
d1de9aa
to
5bab05b
Compare
376b50c
to
a974f8f
Compare
a974f8f
to
3b99d69
Compare
@@ -47,39 +47,43 @@ | |||
}, | |||
"homepage": "https://github.com/libp2p/js-interfaces#readme", | |||
"dependencies": { | |||
"@types/bl": "^2.1.0", | |||
"@types/bl": "4.1.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
has this lost the ^
for a reason?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, mistyped! I will PR this shortly
@@ -62,7 +63,7 @@ export type MultiaddrConnectionTimeline = { | |||
|
|||
export type MultiaddrConnection = { | |||
sink: Sink; | |||
source: () => AsyncIterable<Uint8Array>; | |||
source: AsyncIterable<Uint8Array | BufferList>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are the use-cases for returning a plain BufferList
, are we doing this as an optimisation to avoid buffer concatenation? Do our code paths actually take advantage of this or do we end up concatenating anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use BufferList
because some modules we use (example: https://github.com/bustle/streaming-iterables) also support them and it is valid from users stand point, when they create libp2p protocols. Anyway, we don't use this internally anyway for optimisation and we end up concatenating as you mention.
This is something that we can look into
@@ -1,3 +1,4 @@ | |||
import BufferList from 'bl' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So when you import 'bl'
but have @types/bl
then it automagically pulls those definitions in rather than looking for the real bl
(which isn't a dependency)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, if you are in typescript it will look into @types
namespace. You can also do this in jsdoc for specifying typedefs with import:
@typedef {import('bl')} BufferList
}, | ||
"devDependencies": { | ||
"aegir": "^29.2.0", | ||
"@types/debug": "^4.1.5", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming this is a devdep because it's an internal concern and we only want it to typecheck internal consistency and don't expose debug
to users in any way form here. Is that correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, that is correct!
declare class ContentRouting { | ||
constructor (options: Object); | ||
provide (cid: CID): Promise<void>; | ||
findProviders (cid: CID, options: Object): AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe better to define a Provider
here rather than an anonymous type for {id, multiaddrs}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is more a representation of a peer rather then a Provider. As you pointed below, findPeer also has the same. We have been discussing about potentially change the API return type of this in #85
We will probably look back into this
|
||
declare class PeerRouting { | ||
constructor (options?: Object); | ||
findPeer (peerId: PeerId, options?: Object): Promise<{ id: PeerId, multiaddrs: Multiaddr[] }>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the {id,multiaddrs}
appears twice here again, further suggests it should be it's own Provider
type
@@ -589,7 +595,7 @@ class PubsubBaseProtocol extends EventEmitter { | |||
for (const topic of message.topicIDs) { | |||
const validatorFn = this.topicValidators.get(topic) | |||
if (!validatorFn) { | |||
continue | |||
continue // eslint-disable-line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could just flip the logic here to if (validatorFn) { await validatorFn(..) }
to avoid the disable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will also update this in the follow up PR
exports.RPC = RPC | ||
exports.Message = RPC.Message | ||
exports.SubOpts = RPC.SubOpts | ||
module.exports = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out of interest: was this change forced by the type checking?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the linter, but I think this can cause problems with inferred types and some bundlers. @hugomrdias has the bigger picture here on why we should avoid this
This PR is a follow up PR for types support. It includes:
aegir
update to latest, with new types problems fixed andts
files renamed tod.ts