diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c11e0d0..c5002ce 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,7 +27,7 @@ jobs: strategy: matrix: os: [windows-latest, ubuntu-latest, macos-latest] - node: [12, 14] + node: [14, 15] fail-fast: true steps: - uses: actions/checkout@v2 diff --git a/package.json b/package.json index 95683e7..7eb0644 100644 --- a/package.json +++ b/package.json @@ -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", + "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 ", diff --git a/src/connection/connection.js b/src/connection/connection.js index be59f0c..afe06c8 100644 --- a/src/connection/connection.js +++ b/src/connection/connection.js @@ -230,6 +230,15 @@ class Connection { module.exports = Connection +/** + * @param {multiaddr|undefined} localAddr + * @param {PeerId} localPeer + * @param {PeerId} remotePeer + * @param {(protocols: string | string[]) => Promise<{ stream: import("../stream-muxer/types").MuxedStream; protocol: string; }>} newStream + * @param {() => Promise} close + * @param {() => import("../stream-muxer/types").MuxedStream[]} getStreams + * @param {{ direction: any; timeline: any; multiplexer?: string | undefined; encryption?: string | undefined; }} stat + */ function validateArgs (localAddr, localPeer, remotePeer, newStream, close, getStreams, stat) { if (localAddr && !multiaddr.isMultiaddr(localAddr)) { throw errCode(new Error('localAddr must be an instance of multiaddr'), 'ERR_INVALID_PARAMETERS') diff --git a/src/connection/tests/connection.js b/src/connection/tests/connection.js index 83df518..30e0327 100644 --- a/src/connection/tests/connection.js +++ b/src/connection/tests/connection.js @@ -1,3 +1,4 @@ +// @ts-nocheck interface tests /* eslint-env mocha */ 'use strict' diff --git a/src/connection/tests/index.js b/src/connection/tests/index.js index d008297..f159b5b 100644 --- a/src/connection/tests/index.js +++ b/src/connection/tests/index.js @@ -1,3 +1,4 @@ +// @ts-nocheck interface tests /* eslint-env mocha */ 'use strict' diff --git a/src/content-routing/types.d.ts b/src/content-routing/types.d.ts new file mode 100644 index 0000000..85c549c --- /dev/null +++ b/src/content-routing/types.d.ts @@ -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; + findProviders (cid: CID, options: Object): AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>; +} diff --git a/src/content-routing/types.ts b/src/content-routing/types.ts deleted file mode 100644 index e69de29..0000000 diff --git a/src/crypto/tests/index.js b/src/crypto/tests/index.js index d04b0f9..7ff2bc0 100644 --- a/src/crypto/tests/index.js +++ b/src/crypto/tests/index.js @@ -1,3 +1,4 @@ +// @ts-nocheck interface tests /* eslint-env mocha */ 'use strict' diff --git a/src/crypto/types.ts b/src/crypto/types.d.ts similarity index 100% rename from src/crypto/types.ts rename to src/crypto/types.d.ts diff --git a/src/peer-discovery/tests/index.js b/src/peer-discovery/tests/index.js index 55dbee7..7283899 100644 --- a/src/peer-discovery/tests/index.js +++ b/src/peer-discovery/tests/index.js @@ -1,3 +1,4 @@ +// @ts-nocheck interface tests /* eslint-env mocha */ 'use strict' diff --git a/src/peer-discovery/types.d.ts b/src/peer-discovery/types.d.ts new file mode 100644 index 0000000..db383cb --- /dev/null +++ b/src/peer-discovery/types.d.ts @@ -0,0 +1,10 @@ +export = PeerDiscovery; + +import events from 'events'; + +declare class PeerDiscovery extends events.EventEmitter { + constructor (options: Object); + start (): Promise; + stop (): Promise; + tag: string; +} diff --git a/src/peer-routing/types.d.ts b/src/peer-routing/types.d.ts new file mode 100644 index 0000000..58ea7a7 --- /dev/null +++ b/src/peer-routing/types.d.ts @@ -0,0 +1,10 @@ +export = PeerRouting; + +import PeerId from 'peer-id' +import Multiaddr from 'multiaddr' + +declare class PeerRouting { + constructor (options?: Object); + findPeer (peerId: PeerId, options?: Object): Promise<{ id: PeerId, multiaddrs: Multiaddr[] }>; + getClosestPeers(key: Uint8Array, options?: Object): AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>; +} diff --git a/src/pubsub/index.js b/src/pubsub/index.js index 4fd93c1..f7338ca 100644 --- a/src/pubsub/index.js +++ b/src/pubsub/index.js @@ -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} 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} 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} @@ -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 } await validatorFn(topic, message) } diff --git a/src/pubsub/message/index.js b/src/pubsub/message/index.js index c5e6329..2a30183 100644 --- a/src/pubsub/message/index.js +++ b/src/pubsub/message/index.js @@ -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 = { + rpc: rpcProto, + td: topicDescriptorProto, + RPC, + Message: RPC.Message, + SubOpts: RPC.SubOpts +} diff --git a/src/pubsub/message/types.d.ts b/src/pubsub/message/types.d.ts new file mode 100644 index 0000000..7e8c363 --- /dev/null +++ b/src/pubsub/message/types.d.ts @@ -0,0 +1,5 @@ +import { RPC, Message, SubOpts } from './types' + +export type RPC = RPC +export type Message = Message +export type SubOpts = SubOpts diff --git a/src/pubsub/peer-streams.js b/src/pubsub/peer-streams.js index 837870f..5a5886e 100644 --- a/src/pubsub/peer-streams.js +++ b/src/pubsub/peer-streams.js @@ -1,5 +1,10 @@ 'use strict' +const debug = require('debug') +const log = Object.assign(debug('libp2p-pubsub:peer-streams'), { + error: debug('libp2p-pubsub:peer-streams:err') +}) + /** @typedef {import('../types').EventEmitterFactory} Events */ /** @type Events */ const EventEmitter = require('events') @@ -10,10 +15,6 @@ const pushable = require('it-pushable') const { pipe } = require('it-pipe') const { source: abortable } = require('abortable-iterator') const AbortController = require('abort-controller').default -const debug = require('debug') - -const log = debug('libp2p-pubsub:peer-streams') -log.error = debug('libp2p-pubsub:peer-streams:error') /** * @typedef {import('../stream-muxer/types').MuxedStream} MuxedStream @@ -168,7 +169,7 @@ class PeerStreams extends EventEmitter { this.outboundStream, lp.encode(), this._rawOutboundStream - ).catch(err => { + ).catch(/** @param {Error} err */ err => { log.error(err) }) diff --git a/src/pubsub/tests/api.js b/src/pubsub/tests/api.js index 2de0cf7..e9a3147 100644 --- a/src/pubsub/tests/api.js +++ b/src/pubsub/tests/api.js @@ -1,3 +1,4 @@ +// @ts-nocheck interface tests /* eslint-env mocha */ 'use strict' diff --git a/src/pubsub/tests/emit-self.js b/src/pubsub/tests/emit-self.js index a2a063e..a596e0e 100644 --- a/src/pubsub/tests/emit-self.js +++ b/src/pubsub/tests/emit-self.js @@ -1,3 +1,4 @@ +// @ts-nocheck interface tests /* eslint-env mocha */ 'use strict' diff --git a/src/pubsub/tests/index.js b/src/pubsub/tests/index.js index 1b1414b..f089f5a 100644 --- a/src/pubsub/tests/index.js +++ b/src/pubsub/tests/index.js @@ -1,3 +1,4 @@ +// @ts-nocheck interface tests /* eslint-env mocha */ 'use strict' diff --git a/src/pubsub/tests/messages.js b/src/pubsub/tests/messages.js index f827710..7c7ed44 100644 --- a/src/pubsub/tests/messages.js +++ b/src/pubsub/tests/messages.js @@ -1,3 +1,4 @@ +// @ts-nocheck interface tests /* eslint-env mocha */ 'use strict' diff --git a/src/pubsub/tests/multiple-nodes.js b/src/pubsub/tests/multiple-nodes.js index 41cc9b4..0204c43 100644 --- a/src/pubsub/tests/multiple-nodes.js +++ b/src/pubsub/tests/multiple-nodes.js @@ -1,3 +1,4 @@ +// @ts-nocheck interface tests /* eslint-env mocha */ /* eslint max-nested-callbacks: ["error", 6] */ 'use strict' diff --git a/src/pubsub/tests/two-nodes.js b/src/pubsub/tests/two-nodes.js index 028e0aa..18b6b8d 100644 --- a/src/pubsub/tests/two-nodes.js +++ b/src/pubsub/tests/two-nodes.js @@ -1,3 +1,4 @@ +// @ts-nocheck interface tests /* eslint-env mocha */ /* eslint max-nested-callbacks: ["error", 6] */ 'use strict' diff --git a/src/pubsub/tests/utils.js b/src/pubsub/tests/utils.js index 7d16ac4..99b1c75 100644 --- a/src/pubsub/tests/utils.js +++ b/src/pubsub/tests/utils.js @@ -1,3 +1,4 @@ +// @ts-nocheck interface tests 'use strict' const { expect } = require('chai') diff --git a/src/pubsub/utils.js b/src/pubsub/utils.js index 255ccf3..8dc0367 100644 --- a/src/pubsub/utils.js +++ b/src/pubsub/utils.js @@ -1,11 +1,11 @@ 'use strict' +// @ts-ignore libp2p crypto has no types const randomBytes = require('libp2p-crypto/src/random-bytes') const uint8ArrayToString = require('uint8arrays/to-string') const uint8ArrayFromString = require('uint8arrays/from-string') const PeerId = require('peer-id') const multihash = require('multihashes') -exports = module.exports /** * Generatea random sequence number. @@ -13,7 +13,7 @@ exports = module.exports * @returns {Uint8Array} * @private */ -exports.randomSeqno = () => { +const randomSeqno = () => { return randomBytes(8) } @@ -25,7 +25,7 @@ exports.randomSeqno = () => { * @returns {Uint8Array} * @private */ -exports.msgId = (from, seqno) => { +const msgId = (from, seqno) => { const fromBytes = PeerId.createFromB58String(from).id const msgId = new Uint8Array(fromBytes.length + seqno.length) msgId.set(fromBytes, 0) @@ -40,22 +40,28 @@ exports.msgId = (from, seqno) => { * @returns {Uint8Array} * @private */ -exports.noSignMsgId = (data) => multihash.encode(data, 'sha2-256') +const noSignMsgId = (data) => multihash.encode(data, 'sha2-256') /** * Check if any member of the first set is also a member * of the second set. * - * @param {Set|Array} a - * @param {Set|Array} b + * @param {Set|Array} a + * @param {Set|Array} b * @returns {boolean} * @private */ -exports.anyMatch = (a, b) => { +const anyMatch = (a, b) => { let bHas if (Array.isArray(b)) { + /** + * @param {number} val + */ bHas = (val) => b.indexOf(val) > -1 } else { + /** + * @param {number} val + */ bHas = (val) => b.has(val) } @@ -76,7 +82,7 @@ exports.anyMatch = (a, b) => { * @returns {T[]} * @private */ -exports.ensureArray = (maybeArray) => { +const ensureArray = (maybeArray) => { if (!Array.isArray(maybeArray)) { return [maybeArray] } @@ -92,7 +98,7 @@ exports.ensureArray = (maybeArray) => { * @param {string} [peerId] * @returns {T & {from?: string, peerId?: string }} */ -exports.normalizeInRpcMessage = (message, peerId) => { +const normalizeInRpcMessage = (message, peerId) => { const m = Object.assign({}, message) if (message.from instanceof Uint8Array) { m.from = uint8ArrayToString(message.from, 'base58btc') @@ -109,7 +115,7 @@ exports.normalizeInRpcMessage = (message, peerId) => { * @param {T} message * @returns {T & {from?: Uint8Array, data?: Uint8Array}} */ -exports.normalizeOutRpcMessage = (message) => { +const normalizeOutRpcMessage = (message) => { const m = Object.assign({}, message) if (typeof message.from === 'string') { m.from = uint8ArrayFromString(message.from, 'base58btc') @@ -119,3 +125,13 @@ exports.normalizeOutRpcMessage = (message) => { } return m } + +module.exports = { + randomSeqno, + msgId, + noSignMsgId, + anyMatch, + ensureArray, + normalizeInRpcMessage, + normalizeOutRpcMessage +} diff --git a/src/record/tests/index.js b/src/record/tests/index.js index 2879002..f15b5f9 100644 --- a/src/record/tests/index.js +++ b/src/record/tests/index.js @@ -1,3 +1,4 @@ +// @ts-nocheck interface tests /* eslint-env mocha */ 'use strict' diff --git a/src/record/types.ts b/src/record/types.d.ts similarity index 100% rename from src/record/types.ts rename to src/record/types.d.ts diff --git a/src/stream-muxer/tests/base-test.js b/src/stream-muxer/tests/base-test.js index 064cf02..ce983f0 100644 --- a/src/stream-muxer/tests/base-test.js +++ b/src/stream-muxer/tests/base-test.js @@ -1,3 +1,4 @@ +// @ts-nocheck interface tests /* eslint-env mocha */ 'use strict' diff --git a/src/stream-muxer/tests/close-test.js b/src/stream-muxer/tests/close-test.js index 2f212c4..e70dc56 100644 --- a/src/stream-muxer/tests/close-test.js +++ b/src/stream-muxer/tests/close-test.js @@ -1,3 +1,4 @@ +// @ts-nocheck interface tests /* eslint-env mocha */ /* eslint max-nested-callbacks: ["error", 8] */ 'use strict' diff --git a/src/stream-muxer/tests/index.js b/src/stream-muxer/tests/index.js index 9006539..d8c9cdc 100644 --- a/src/stream-muxer/tests/index.js +++ b/src/stream-muxer/tests/index.js @@ -1,3 +1,4 @@ +// @ts-nocheck interface tests /* eslint-env mocha */ 'use strict' diff --git a/src/stream-muxer/tests/mega-stress-test.js b/src/stream-muxer/tests/mega-stress-test.js index b012ea1..c7b81ab 100644 --- a/src/stream-muxer/tests/mega-stress-test.js +++ b/src/stream-muxer/tests/mega-stress-test.js @@ -1,3 +1,4 @@ +// @ts-nocheck interface tests /* eslint-env mocha */ 'use strict' diff --git a/src/stream-muxer/tests/spawner.js b/src/stream-muxer/tests/spawner.js index 2b2dc2e..b79ec06 100644 --- a/src/stream-muxer/tests/spawner.js +++ b/src/stream-muxer/tests/spawner.js @@ -1,3 +1,4 @@ +// @ts-nocheck interface tests 'use strict' const { expect } = require('chai') diff --git a/src/stream-muxer/tests/stress-test.js b/src/stream-muxer/tests/stress-test.js index f32307b..9903122 100644 --- a/src/stream-muxer/tests/stress-test.js +++ b/src/stream-muxer/tests/stress-test.js @@ -1,3 +1,4 @@ +// @ts-nocheck interface tests /* eslint-env mocha */ 'use strict' diff --git a/src/stream-muxer/types.ts b/src/stream-muxer/types.d.ts similarity index 89% rename from src/stream-muxer/types.ts rename to src/stream-muxer/types.d.ts index 6d525a8..cf0c6f4 100644 --- a/src/stream-muxer/types.ts +++ b/src/stream-muxer/types.d.ts @@ -43,9 +43,9 @@ export interface MuxedStream extends AsyncIterable { abort: () => void; reset: () => void; sink: Sink; - source: () => AsyncIterable; + source: AsyncIterable; timeline: MuxedTimeline; id: string; } -export type Sink = (source: Uint8Array) => Promise; +export type Sink = (source: Uint8Array) => Promise; diff --git a/src/topology/index.js b/src/topology/index.js index e73b036..85e72db 100644 --- a/src/topology/index.js +++ b/src/topology/index.js @@ -62,6 +62,9 @@ class Topology { return Boolean(other && other[topologySymbol]) } + /** + * @param {any} registrar + */ set registrar (registrar) { // eslint-disable-line this._registrar = registrar } diff --git a/src/topology/multicodec-topology.js b/src/topology/multicodec-topology.js index 2b1cb9d..02e739e 100644 --- a/src/topology/multicodec-topology.js +++ b/src/topology/multicodec-topology.js @@ -56,6 +56,9 @@ class MulticodecTopology extends Topology { return Boolean(other && other[multicodecTopologySymbol]) } + /** + * @param {any} registrar + */ set registrar (registrar) { // eslint-disable-line this._registrar = registrar this._registrar.peerStore.on('change:protocols', this._onProtocolChange) diff --git a/src/topology/tests/multicodec-topology.js b/src/topology/tests/multicodec-topology.js index 747ad1a..0e824e2 100644 --- a/src/topology/tests/multicodec-topology.js +++ b/src/topology/tests/multicodec-topology.js @@ -1,3 +1,4 @@ +// @ts-nocheck interface tests /* eslint-env mocha */ 'use strict' diff --git a/src/topology/tests/topology.js b/src/topology/tests/topology.js index 89f28d7..e551af6 100644 --- a/src/topology/tests/topology.js +++ b/src/topology/tests/topology.js @@ -1,3 +1,4 @@ +// @ts-nocheck interface tests /* eslint-env mocha */ 'use strict' diff --git a/src/transport/tests/dial-test.js b/src/transport/tests/dial-test.js index 671365b..bfb01e5 100644 --- a/src/transport/tests/dial-test.js +++ b/src/transport/tests/dial-test.js @@ -1,3 +1,4 @@ +// @ts-nocheck interface tests /* eslint-env mocha */ 'use strict' diff --git a/src/transport/tests/filter-test.js b/src/transport/tests/filter-test.js index 09c53a3..f4de22e 100644 --- a/src/transport/tests/filter-test.js +++ b/src/transport/tests/filter-test.js @@ -1,3 +1,4 @@ +// @ts-nocheck interface tests /* eslint-env mocha */ 'use strict' diff --git a/src/transport/tests/index.js b/src/transport/tests/index.js index 0d43233..35b8272 100644 --- a/src/transport/tests/index.js +++ b/src/transport/tests/index.js @@ -1,3 +1,4 @@ +// @ts-nocheck interface tests /* eslint-env mocha */ 'use strict' diff --git a/src/transport/tests/listen-test.js b/src/transport/tests/listen-test.js index cff92a7..5aaa030 100644 --- a/src/transport/tests/listen-test.js +++ b/src/transport/tests/listen-test.js @@ -1,3 +1,4 @@ +// @ts-nocheck interface tests /* eslint max-nested-callbacks: ["error", 8] */ /* eslint-env mocha */ 'use strict' diff --git a/src/transport/types.ts b/src/transport/types.d.ts similarity index 95% rename from src/transport/types.ts rename to src/transport/types.d.ts index af5df59..f1e19eb 100644 --- a/src/transport/types.ts +++ b/src/transport/types.d.ts @@ -1,3 +1,4 @@ +import BufferList from 'bl' import events from 'events' import Multiaddr from 'multiaddr' import Connection from '../connection/connection' @@ -62,7 +63,7 @@ export type MultiaddrConnectionTimeline = { export type MultiaddrConnection = { sink: Sink; - source: () => AsyncIterable; + source: AsyncIterable; close: (err?: Error) => Promise; conn: unknown; remoteAddr: Multiaddr; diff --git a/src/types.ts b/src/types.d.ts similarity index 78% rename from src/types.ts rename to src/types.d.ts index 554dfdf..2bfc046 100644 --- a/src/types.ts +++ b/src/types.d.ts @@ -3,13 +3,13 @@ export interface EventEmitterFactory { } export interface EventEmitter { - addListener(event: string | symbol, listener: (...args: any[]) => void); - on(event: string | symbol, listener: (...args: any[]) => void); - once(event: string | symbol, listener: (...args: any[]) => void); - removeListener(event: string | symbol, listener: (...args: any[]) => void); - off(event: string | symbol, listener: (...args: any[]) => void); - removeAllListeners(event?: string | symbol); - setMaxListeners(n: number); + addListener(event: string | symbol, listener: (...args: any[]) => void): EventEmitter; + on(event: string | symbol, listener: (...args: any[]) => void): EventEmitter; + once(event: string | symbol, listener: (...args: any[]) => void): EventEmitter; + removeListener(event: string | symbol, listener: (...args: any[]) => void): EventEmitter; + off(event: string | symbol, listener: (...args: any[]) => void): EventEmitter; + removeAllListeners(event?: string | symbol): EventEmitter; + setMaxListeners(n: number): EventEmitter; getMaxListeners(): number; listeners(event: string | symbol): Function[]; // eslint-disable-line @typescript-eslint/ban-types rawListeners(event: string | symbol): Function[]; // eslint-disable-line @typescript-eslint/ban-types