-
Notifications
You must be signed in to change notification settings - Fork 27
chore: update types #87
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,9 +22,9 @@ | |
"extends": "ipfs" | ||
}, | ||
"scripts": { | ||
"prepare": "aegir build --no-bundle", | ||
"lint": "aegir lint", | ||
"build": "aegir build", | ||
"prepare": "aegir build --no-bundle", | ||
"test": "aegir test", | ||
"test:node": "aegir test --target node", | ||
"test:browser": "aegir test --target browser", | ||
|
@@ -47,39 +47,43 @@ | |
}, | ||
"homepage": "https://github.com/libp2p/js-interfaces#readme", | ||
"dependencies": { | ||
"@types/bl": "^2.1.0", | ||
"@types/bl": "4.1.0", | ||
"abort-controller": "^3.0.0", | ||
"abortable-iterator": "^3.0.0", | ||
"chai": "^4.2.0", | ||
"chai": "^4.3.4", | ||
"chai-checkmark": "^1.0.1", | ||
"debug": "^4.3.1", | ||
"delay": "^4.4.0", | ||
"delay": "^5.0.0", | ||
"detect-node": "^2.0.4", | ||
"dirty-chai": "^2.0.1", | ||
"err-code": "^2.0.3", | ||
"err-code": "^3.0.1", | ||
"it-goodbye": "^2.0.2", | ||
"it-length-prefixed": "^3.1.0", | ||
"it-pair": "^1.0.0", | ||
"it-pipe": "^1.1.0", | ||
"it-pushable": "^1.4.0", | ||
"it-pushable": "^1.4.2", | ||
"libp2p-crypto": "^0.19.0", | ||
"libp2p-tcp": "^0.15.0", | ||
"multiaddr": "^8.1.2", | ||
"multibase": "^3.1.1", | ||
"multihashes": "^3.1.1", | ||
"multibase": "^4.0.2", | ||
"multihashes": "^4.0.2", | ||
"p-defer": "^3.0.0", | ||
"p-limit": "^3.1.0", | ||
"p-wait-for": "^3.2.0", | ||
"peer-id": "^0.14.2", | ||
"protons": "^2.0.0", | ||
"sinon": "^9.2.4", | ||
"sinon": "^10.0.0", | ||
"streaming-iterables": "^5.0.4", | ||
"uint8arrays": "^2.0.5" | ||
"uint8arrays": "^2.1.3" | ||
}, | ||
"devDependencies": { | ||
"aegir": "^29.2.0", | ||
"@types/debug": "^4.1.5", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, that is correct! |
||
"aegir": "^32.1.0", | ||
"cids": "^1.1.6", | ||
"events": "^3.3.0", | ||
"it-handshake": "^1.0.2", | ||
"rimraf": "^3.0.2" | ||
"rimraf": "^3.0.2", | ||
"util": "^0.12.3" | ||
}, | ||
"contributors": [ | ||
"Alan Shaw <[email protected]>", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// @ts-nocheck interface tests | ||
/* eslint-env mocha */ | ||
|
||
'use strict' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// @ts-nocheck interface tests | ||
/* eslint-env mocha */ | ||
|
||
'use strict' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export = ContentRouting; | ||
|
||
import PeerId from 'peer-id' | ||
import Multiaddr from 'multiaddr' | ||
import CID from 'cids' | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. maybe better to define a There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// @ts-nocheck interface tests | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// @ts-nocheck interface tests | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export = PeerDiscovery; | ||
|
||
import events from 'events'; | ||
|
||
declare class PeerDiscovery extends events.EventEmitter { | ||
constructor (options: Object); | ||
start (): Promise<void>; | ||
stop (): Promise<void>; | ||
tag: string; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export = PeerRouting; | ||
|
||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. I was doing a named import on |
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. the |
||
getClosestPeers(key: Uint8Array, options?: Object): AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,7 @@ const { pipe } = require('it-pipe') | |
|
||
const MulticodecTopology = require('../topology/multicodec-topology') | ||
const { codes } = require('./errors') | ||
/** | ||
* @type {typeof import('./message')} | ||
*/ | ||
|
||
const message = require('./message') | ||
const PeerStreams = require('./peer-streams') | ||
const { SignaturePolicy } = require('./signature-policy') | ||
|
@@ -29,9 +27,9 @@ const { | |
* @typedef {import('bl')} BufferList | ||
* @typedef {import('../stream-muxer/types').MuxedStream} MuxedStream | ||
* @typedef {import('../connection/connection')} Connection | ||
* @typedef {import('./message').RPC} RPC | ||
* @typedef {import('./message').SubOpts} RPCSubOpts | ||
* @typedef {import('./message').Message} RPCMessage | ||
* @typedef {import('./message/types').RPC} RPC | ||
* @typedef {import('./message/types').SubOpts} RPCSubOpts | ||
* @typedef {import('./message/types').Message} RPCMessage | ||
* @typedef {import('./signature-policy').SignaturePolicyType} SignaturePolicyType | ||
*/ | ||
|
||
|
@@ -44,6 +42,16 @@ const { | |
* @property {Uint8Array} data | ||
* @property {Uint8Array} [signature] | ||
* @property {Uint8Array} [key] | ||
* | ||
* @typedef {Object} PubsubProperties | ||
* @property {string} debugName - log namespace | ||
* @property {Array<string>|string} multicodecs - protocol identificers to connect | ||
* @property {Libp2p} libp2p | ||
* | ||
* @typedef {Object} PubsubOptions | ||
* @property {SignaturePolicyType} [globalSignaturePolicy = SignaturePolicy.StrictSign] - defines how signatures should be handled | ||
* @property {boolean} [canRelayMessage = false] - if can relay messages not subscribed | ||
* @property {boolean} [emitSelf = false] - if publish should emit to self, if subscribed | ||
*/ | ||
|
||
/** | ||
|
@@ -52,13 +60,7 @@ const { | |
*/ | ||
class PubsubBaseProtocol extends EventEmitter { | ||
/** | ||
* @param {Object} props | ||
* @param {string} props.debugName - log namespace | ||
* @param {Array<string>|string} props.multicodecs - protocol identificers to connect | ||
* @param {Libp2p} props.libp2p | ||
* @param {SignaturePolicyType} [props.globalSignaturePolicy = SignaturePolicy.StrictSign] - defines how signatures should be handled | ||
* @param {boolean} [props.canRelayMessage = false] - if can relay messages not subscribed | ||
* @param {boolean} [props.emitSelf = false] - if publish should emit to self, if subscribed | ||
* @param {PubsubProperties & PubsubOptions} props | ||
* @abstract | ||
*/ | ||
constructor ({ | ||
|
@@ -83,8 +85,9 @@ class PubsubBaseProtocol extends EventEmitter { | |
|
||
super() | ||
|
||
this.log = debug(debugName) | ||
this.log.err = debug(`${debugName}:error`) | ||
this.log = Object.assign(debug(debugName), { | ||
err: debug(`${debugName}:error`) | ||
}) | ||
|
||
/** | ||
* @type {Array<string>} | ||
|
@@ -122,7 +125,7 @@ class PubsubBaseProtocol extends EventEmitter { | |
|
||
// validate signature policy | ||
if (!SignaturePolicy[globalSignaturePolicy]) { | ||
throw errcode(new Error('Invalid global signature policy'), codes.ERR_INVALID_SIGUATURE_POLICY) | ||
throw errcode(new Error('Invalid global signature policy'), codes.ERR_INVALID_SIGNATURE_POLICY) | ||
} | ||
|
||
/** | ||
|
@@ -379,7 +382,9 @@ class PubsubBaseProtocol extends EventEmitter { | |
|
||
if (subs.length) { | ||
// update peer subscriptions | ||
subs.forEach((subOpt) => this._processRpcSubOpt(idB58Str, subOpt)) | ||
subs.forEach((/** @type {RPCSubOpts} */ subOpt) => { | ||
this._processRpcSubOpt(idB58Str, subOpt) | ||
}) | ||
this.emit('pubsub:subscription-change', peerStreams.id, subs) | ||
} | ||
|
||
|
@@ -389,8 +394,9 @@ class PubsubBaseProtocol extends EventEmitter { | |
} | ||
|
||
if (msgs.length) { | ||
msgs.forEach(message => { | ||
if (!(this.canRelayMessage || message.topicIDs.some((topic) => this.subscriptions.has(topic)))) { | ||
// @ts-ignore RPC message is modified | ||
msgs.forEach((message) => { | ||
if (!(this.canRelayMessage || message.topicIDs.some((/** @type {string} */ topic) => this.subscriptions.has(topic)))) { | ||
this.log('received message we didn\'t subscribe to. Dropping.') | ||
return | ||
} | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. you could just flip the logic here to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will also update this in the follow up PR |
||
} | ||
await validatorFn(topic, message) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
'use strict' | ||
|
||
// @ts-ignore protons not typed | ||
const protons = require('protons') | ||
|
||
const rpcProto = protons(require('./rpc.proto.js')) | ||
const RPC = rpcProto.RPC | ||
const topicDescriptorProto = protons(require('./topic-descriptor.proto.js')) | ||
|
||
/** | ||
* @module pubsub/message/index | ||
*/ | ||
exports = module.exports | ||
exports.rpc = rpcProto | ||
exports.td = topicDescriptorProto | ||
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 commentThe 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 commentThe 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 |
||
rpc: rpcProto, | ||
td: topicDescriptorProto, | ||
RPC, | ||
Message: RPC.Message, | ||
SubOpts: RPC.SubOpts | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { RPC, Message, SubOpts } from './types' | ||
|
||
export type RPC = RPC | ||
export type Message = Message | ||
export type SubOpts = SubOpts |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// @ts-nocheck interface tests | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// @ts-nocheck interface tests | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// @ts-nocheck interface tests | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// @ts-nocheck interface tests | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// @ts-nocheck interface tests | ||
'use strict' | ||
|
||
const { expect } = require('chai') | ||
|
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