diff --git a/package.json b/package.json index b66585d5..487a1d11 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,6 @@ "test:node": "aegir test -t node -f \"./test/**/*.{node,spec}.js\"", "test:browser": "aegir test -t browser", "test:examples": "cd examples && npm run test:all", - "test:types": "aegir ts -p check", "release": "aegir release -t node -t browser", "release-minor": "aegir release --type minor -t node -t browser", "release-major": "aegir release --type major -t node -t browser", diff --git a/src/circuit/circuit/stop.js b/src/circuit/circuit/stop.js index 9f47bd67..16192ad5 100644 --- a/src/circuit/circuit/stop.js +++ b/src/circuit/circuit/stop.js @@ -12,6 +12,7 @@ const { validateAddrs } = require('./utils') /** * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection + * @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream */ /** @@ -20,9 +21,9 @@ const { validateAddrs } = require('./utils') * @private * @param {object} options * @param {Connection} options.connection - * @param {*} options.request - The CircuitRelay protobuf request (unencoded) + * @param {CircuitPB} options.request - The CircuitRelay protobuf request (unencoded) * @param {StreamHandler} options.streamHandler - * @returns {Promise<*>|void} Resolves a duplex iterable + * @returns {Promise|void} Resolves a duplex iterable */ module.exports.handleStop = function handleStop ({ connection, @@ -52,7 +53,7 @@ module.exports.handleStop = function handleStop ({ * @param {object} options * @param {Connection} options.connection * @param {CircuitPB} options.request - The CircuitRelay protobuf request (unencoded) - * @returns {Promise<*>} Resolves a duplex iterable + * @returns {Promise} Resolves a duplex iterable */ module.exports.stop = async function stop ({ connection, diff --git a/src/circuit/circuit/stream-handler.js b/src/circuit/circuit/stream-handler.js index b320706d..b63dcbff 100644 --- a/src/circuit/circuit/stream-handler.js +++ b/src/circuit/circuit/stream-handler.js @@ -47,11 +47,11 @@ class StreamHandler { /** * Encode and write array of buffers * - * @param {*} msg - An unencoded CircuitRelay protobuf message + * @param {CircuitPB} msg - An unencoded CircuitRelay protobuf message */ write (msg) { log('write message type %s', msg.type) - // @ts-ignore + // @ts-ignore lp.encode expects type type 'Buffer | BufferList', not 'Uint8Array' this.shake.write(lp.encode.single(CircuitPB.encode(msg))) } diff --git a/src/circuit/transport.js b/src/circuit/transport.js index 2f2de306..4eea0610 100644 --- a/src/circuit/transport.js +++ b/src/circuit/transport.js @@ -129,8 +129,6 @@ class Circuit { try { const virtualConnection = await hop({ connection: relayConnection, - // @ts-ignore - circuit: this, request: { type: CircuitPB.Type.HOP, srcPeer: { diff --git a/src/dialer/dial-request.js b/src/dialer/dial-request.js index bac571c1..62bab31b 100644 --- a/src/dialer/dial-request.js +++ b/src/dialer/dial-request.js @@ -1,7 +1,7 @@ 'use strict' const errCode = require('err-code') -const AbortController = require('abort-controller') +const AbortController = require('abort-controller').default const anySignal = require('any-signal') const FIFO = require('p-fifo') const pAny = require('p-any') @@ -13,9 +13,12 @@ const pAny = require('p-any') */ /** + * @typedef {Object} DialOptions + * @property {AbortSignal} signal + * * @typedef {Object} DialRequestOptions * @property {Multiaddr[]} addrs - * @property {function(Multiaddr):Promise} dialAction + * @property {(m: Multiaddr, options: DialOptions) => Promise} dialAction * @property {Dialer} dialer */ @@ -46,7 +49,7 @@ class DialRequest { * @param {AbortSignal} [options.signal] - An AbortController signal * @returns {Promise} */ - async run (options) { + async run (options = {}) { const tokens = this.dialer.getTokens(this.addrs.length) // If no tokens are available, throw if (tokens.length < 1) { @@ -55,7 +58,6 @@ class DialRequest { const tokenHolder = new FIFO() tokens.forEach(token => tokenHolder.push(token)) - // @ts-ignore const dialAbortControllers = this.addrs.map(() => new AbortController()) let completedDials = 0 @@ -65,7 +67,6 @@ class DialRequest { let conn try { const signal = dialAbortControllers[i].signal - // @ts-ignore conn = await this.dialAction(addr, { ...options, signal: anySignal([signal, options.signal]) }) // Remove the successful AbortController so it is not aborted dialAbortControllers.splice(i, 1) diff --git a/src/get-peer.js b/src/get-peer.js index 35e2f264..807c3333 100644 --- a/src/get-peer.js +++ b/src/get-peer.js @@ -14,7 +14,7 @@ const { codes } = require('./errors') * Converts the given `peer` to a `Peer` object. * If a multiaddr is received, the addressBook is updated. * - * @param {PeerId|multiaddr|string} peer + * @param {PeerId|Multiaddr|string} peer * @returns {{ id: PeerId, multiaddrs: Multiaddr[]|undefined }} */ function getPeer (peer) { diff --git a/src/identify/consts.js b/src/identify/consts.js index 9e15ef9f..1f697e5d 100644 --- a/src/identify/consts.js +++ b/src/identify/consts.js @@ -1,6 +1,6 @@ 'use strict' -// @ts-ignore +// @ts-ignore file not listed within the file list of projects const libp2pVersion = require('../../package.json').version module.exports.PROTOCOL_VERSION = 'ipfs/0.1.0' diff --git a/src/index.js b/src/index.js index 386f0161..175dd724 100644 --- a/src/index.js +++ b/src/index.js @@ -36,6 +36,8 @@ const IDENTIFY_PROTOCOLS = IdentifyService.multicodecs /** * @typedef {import('multiaddr')} Multiaddr * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection + * @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream + * @typedef {import('libp2p-interfaces/src/pubsub')} Pubsub */ /** @@ -52,9 +54,9 @@ const IDENTIFY_PROTOCOLS = IdentifyService.multicodecs * @property {import('./circuit').AutoRelayOptions} autoRelay * * @typedef {Object} Libp2pConfig - * @property {Object} [dht] dht module options + * @property {any} [dht] dht module options * @property {PeerDiscoveryOptions} [peerDiscovery] - * @property {Object} [pubsub] pubsub module options + * @property {Pubsub} [pubsub] pubsub module options * @property {RelayOptions} [relay] * @property {Object} [transport] transport options indexed by transport key * @@ -191,7 +193,7 @@ class Libp2p extends EventEmitter { }) if (this._config.relay.enabled) { - // @ts-ignore + // @ts-ignore Circuit prototype this.transportManager.add(Circuit.prototype[Symbol.toStringTag], Circuit) this.relay = new Relay(this) } @@ -205,7 +207,6 @@ class Libp2p extends EventEmitter { // Add the identify service since we can multiplex this.identifyService = new IdentifyService({ libp2p: this }) - // @ts-ignore this.handle(Object.values(IDENTIFY_PROTOCOLS), this.identifyService.handleMessage) } @@ -234,6 +235,7 @@ class Libp2p extends EventEmitter { if (this._modules.pubsub) { const Pubsub = this._modules.pubsub // using pubsub adapter with *DEPRECATED* handlers functionality + /** @type {Pubsub} */ this.pubsub = PubsubAdapter(Pubsub, this, this._config.pubsub) } @@ -258,7 +260,7 @@ class Libp2p extends EventEmitter { */ emit (eventName, ...args) { // TODO: do we still need this? - // @ts-ignore + // @ts-ignore _events does not exist in libp2p if (eventName === 'error' && !this._events.error) { log.error(args) return false @@ -466,7 +468,7 @@ class Libp2p extends EventEmitter { * Registers the `handler` for each protocol * * @param {string[]|string} protocols - * @param {({ connection: Connection, stream: any, protocol: string }) => void} handler + * @param {({ connection: Connection, stream: MuxedStream, protocol: string }) => void} handler */ handle (protocols, handler) { protocols = Array.isArray(protocols) ? protocols : [protocols] @@ -632,9 +634,9 @@ class Libp2p extends EventEmitter { // Transport modules with discovery for (const Transport of this.transportManager.getTransports()) { - // @ts-ignore + // @ts-ignore Transport interface does not include discovery if (Transport.discovery) { - // @ts-ignore + // @ts-ignore Transport interface does not include discovery setupService(Transport.discovery) } } diff --git a/src/insecure/plaintext.js b/src/insecure/plaintext.js index 92010798..07efe9f7 100644 --- a/src/insecure/plaintext.js +++ b/src/insecure/plaintext.js @@ -12,15 +12,15 @@ const { UnexpectedPeerError, InvalidCryptoExchangeError } = require('libp2p-inte const { Exchange, KeyType } = require('./proto') const protocol = '/plaintext/2.0.0' +/** + * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection + */ + function lpEncodeExchange (exchange) { const pb = Exchange.encode(exchange) return lp.encode.single(pb) } -/** - * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection - */ - /** * Encrypt connection. * diff --git a/src/metrics/old-peers.js b/src/metrics/old-peers.js index 1f38ba6e..753bdf5f 100644 --- a/src/metrics/old-peers.js +++ b/src/metrics/old-peers.js @@ -9,7 +9,7 @@ const LRU = require('hashlru') * @returns {any} */ module.exports = (maxSize) => { - // @ts-ignore + // @ts-ignore LRU expression is not callable const patched = LRU(maxSize) patched.delete = patched.remove return patched diff --git a/src/metrics/stats.js b/src/metrics/stats.js index 00470b00..e35ab311 100644 --- a/src/metrics/stats.js +++ b/src/metrics/stats.js @@ -24,7 +24,6 @@ class Stats extends EventEmitter { this._frequencyLastTime = Date.now() this._frequencyAccumulators = {} - /** @type {{}} */ this._movingAverages = {} this._update = this._update.bind(this) diff --git a/src/peer-store/address-book.js b/src/peer-store/address-book.js index a42a6b85..516d908f 100644 --- a/src/peer-store/address-book.js +++ b/src/peer-store/address-book.js @@ -23,23 +23,13 @@ const Envelope = require('../record/envelope') */ /** - * Address object - * * @typedef {Object} Address * @property {Multiaddr} multiaddr peer multiaddr. * @property {boolean} isCertified obtained from a signed peer record. - */ - -/** - * CertifiedRecord object * * @typedef {Object} CertifiedRecord * @property {Uint8Array} raw raw envelope. * @property {number} seqNumber seq counter. - */ - -/** - * Entry object for the addressBook * * @typedef {Object} Entry * @property {Address[]} addresses peer Addresses. @@ -124,7 +114,6 @@ class AddressBook extends Book { // Replace unsigned addresses by the new ones from the record // TODO: Once we have ttls for the addresses, we should merge these in. - // @ts-ignore this._setData(peerId, { addresses, record: { diff --git a/src/peer-store/book.js b/src/peer-store/book.js index becd30b7..42bb749f 100644 --- a/src/peer-store/book.js +++ b/src/peer-store/book.js @@ -90,7 +90,7 @@ class Book { * Returns `undefined` if there is no available data for the given peer. * * @param {PeerId} peerId - * @returns {T[]|undefined} + * @returns {T[]|T|undefined} */ get (peerId) { if (!PeerId.isPeerId(peerId)) { diff --git a/src/peer-store/key-book.js b/src/peer-store/key-book.js index 2326b3e9..356c8186 100644 --- a/src/peer-store/key-book.js +++ b/src/peer-store/key-book.js @@ -16,6 +16,7 @@ const { /** * @typedef {import('./')} PeerStore + * @typedef {import('libp2p-crypto').PublicKey} PublicKey */ /** @@ -49,7 +50,7 @@ class KeyBook extends Book { * * @override * @param {PeerId} peerId - * @param {any} publicKey + * @param {PublicKey} publicKey * @returns {KeyBook} */ set (peerId, publicKey) { @@ -79,7 +80,7 @@ class KeyBook extends Book { * * @override * @param {PeerId} peerId - * @returns {any} + * @returns {PublicKey | undefined} */ get (peerId) { if (!PeerId.isPeerId(peerId)) { diff --git a/src/peer-store/metadata-book.js b/src/peer-store/metadata-book.js index 38504fc0..d497bb2f 100644 --- a/src/peer-store/metadata-book.js +++ b/src/peer-store/metadata-book.js @@ -60,7 +60,7 @@ class MetadataBook extends Book { * @param {Uint8Array} value - metadata value * @returns {MetadataBook} */ - // @ts-ignore + // @ts-ignore override with more then the parameters expected in Book set (peerId, key, value) { if (!PeerId.isPeerId(peerId)) { log.error('peerId must be an instance of peer-id to store data') @@ -105,7 +105,6 @@ class MetadataBook extends Book { * @param {PeerId} peerId * @returns {Map|undefined} */ - // @ts-ignore get (peerId) { if (!PeerId.isPeerId(peerId)) { throw errcode(new Error('peerId must be an instance of peer-id'), ERR_INVALID_PARAMETERS) diff --git a/src/peer-store/persistent/index.js b/src/peer-store/persistent/index.js index e004f86a..bbab4965 100644 --- a/src/peer-store/persistent/index.js +++ b/src/peer-store/persistent/index.js @@ -346,7 +346,7 @@ class PersistentPeerStore extends PeerStore { case 'addrs': decoded = Addresses.decode(value) - // @ts-ignore + // @ts-ignore protected function this.addressBook._setData( peerId, { @@ -364,7 +364,7 @@ class PersistentPeerStore extends PeerStore { case 'keys': decoded = await PeerId.createFromPubKey(value) - // @ts-ignore + // @ts-ignore protected function this.keyBook._setData( decoded, decoded, @@ -380,7 +380,7 @@ class PersistentPeerStore extends PeerStore { case 'protos': decoded = Protocols.decode(value) - // @ts-ignore + // @ts-ignore protected function this.protoBook._setData( peerId, new Set(decoded.protocols), diff --git a/src/peer-store/proto-book.js b/src/peer-store/proto-book.js index 18529d73..5c17b137 100644 --- a/src/peer-store/proto-book.js +++ b/src/peer-store/proto-book.js @@ -83,7 +83,6 @@ class ProtoBook extends Book { return this } - // @ts-ignore this._setData(peerId, newSet) log(`stored provided protocols for ${id}`) @@ -119,7 +118,6 @@ class ProtoBook extends Book { return this } - // @ts-ignore this._setData(peerId, newSet) log(`added provided protocols for ${id}`) @@ -158,7 +156,6 @@ class ProtoBook extends Book { return this } - // @ts-ignore this._setData(peerId, newSet) log(`removed provided protocols for ${id}`) } diff --git a/src/ping/index.js b/src/ping/index.js index a242f9fb..53e3f679 100644 --- a/src/ping/index.js +++ b/src/ping/index.js @@ -28,7 +28,7 @@ const { PROTOCOL, PING_LENGTH } = require('./constants') * @returns {Promise} */ async function ping (node, peer) { - // @ts-ignore + // @ts-ignore multiaddr might not have toB58String log('dialing %s to %s', PROTOCOL, peer.toB58String ? peer.toB58String() : peer) const { stream } = await node.dialProtocol(peer, PROTOCOL) diff --git a/src/pnet/key-generator.js b/src/pnet/key-generator.js index d88f23d8..8a7a1ef5 100644 --- a/src/pnet/key-generator.js +++ b/src/pnet/key-generator.js @@ -22,7 +22,7 @@ module.exports = generate module.exports.NONCE_LENGTH = 24 module.exports.KEY_LENGTH = KEY_LENGTH -// @ts-ignore +// @ts-ignore This condition will always return 'false' since the types 'Module | undefined' if (require.main === module) { // @ts-ignore generate(process.stdout) diff --git a/src/types.ts b/src/types.ts index 9a97803d..fe58c0e5 100644 --- a/src/types.ts +++ b/src/types.ts @@ -7,16 +7,6 @@ export enum KeyType { ECDSA = 3 } -export type MessagePublicKey = { - Type: KeyType - Data: Uint8Array -} - -export type MessageExchange = { - id: Uint8Array - pubKey: MessagePublicKey -} - // Protobufs export type MessageProto = { encode(value: any): Uint8Array diff --git a/src/upgrader.js b/src/upgrader.js index 8d00cb52..d11c22b1 100644 --- a/src/upgrader.js +++ b/src/upgrader.js @@ -14,7 +14,6 @@ const mutableProxy = require('mutable-proxy') const { codes } = require('./errors') /** - * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection * @typedef {import('libp2p-interfaces/src/transport/types').MultiaddrConnection} MultiaddrConnection * @typedef {import('libp2p-interfaces/src/stream-muxer/types').Muxer} Muxer * @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream @@ -222,7 +221,7 @@ class Upgrader { let connection if (Muxer) { - // @ts-ignore Create the muxer + // Create the muxer muxer = new Muxer({ // Run anytime a remote stream is created onStream: async muxedStream => {