chore: update types (#87)

This commit is contained in:
Vasco Santos 2021-04-07 09:39:48 +02:00 committed by GitHub
parent b948972c5b
commit 64a478d313
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
43 changed files with 169 additions and 67 deletions

View File

@ -27,7 +27,7 @@ jobs:
strategy: strategy:
matrix: matrix:
os: [windows-latest, ubuntu-latest, macos-latest] os: [windows-latest, ubuntu-latest, macos-latest]
node: [12, 14] node: [14, 15]
fail-fast: true fail-fast: true
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2

View File

@ -22,9 +22,9 @@
"extends": "ipfs" "extends": "ipfs"
}, },
"scripts": { "scripts": {
"prepare": "aegir build --no-bundle",
"lint": "aegir lint", "lint": "aegir lint",
"build": "aegir build", "build": "aegir build",
"prepare": "aegir build --no-bundle",
"test": "aegir test", "test": "aegir test",
"test:node": "aegir test --target node", "test:node": "aegir test --target node",
"test:browser": "aegir test --target browser", "test:browser": "aegir test --target browser",
@ -47,39 +47,43 @@
}, },
"homepage": "https://github.com/libp2p/js-interfaces#readme", "homepage": "https://github.com/libp2p/js-interfaces#readme",
"dependencies": { "dependencies": {
"@types/bl": "^2.1.0", "@types/bl": "4.1.0",
"abort-controller": "^3.0.0", "abort-controller": "^3.0.0",
"abortable-iterator": "^3.0.0", "abortable-iterator": "^3.0.0",
"chai": "^4.2.0", "chai": "^4.3.4",
"chai-checkmark": "^1.0.1", "chai-checkmark": "^1.0.1",
"debug": "^4.3.1", "debug": "^4.3.1",
"delay": "^4.4.0", "delay": "^5.0.0",
"detect-node": "^2.0.4", "detect-node": "^2.0.4",
"dirty-chai": "^2.0.1", "dirty-chai": "^2.0.1",
"err-code": "^2.0.3", "err-code": "^3.0.1",
"it-goodbye": "^2.0.2", "it-goodbye": "^2.0.2",
"it-length-prefixed": "^3.1.0", "it-length-prefixed": "^3.1.0",
"it-pair": "^1.0.0", "it-pair": "^1.0.0",
"it-pipe": "^1.1.0", "it-pipe": "^1.1.0",
"it-pushable": "^1.4.0", "it-pushable": "^1.4.2",
"libp2p-crypto": "^0.19.0", "libp2p-crypto": "^0.19.0",
"libp2p-tcp": "^0.15.0", "libp2p-tcp": "^0.15.0",
"multiaddr": "^8.1.2", "multiaddr": "^8.1.2",
"multibase": "^3.1.1", "multibase": "^4.0.2",
"multihashes": "^3.1.1", "multihashes": "^4.0.2",
"p-defer": "^3.0.0", "p-defer": "^3.0.0",
"p-limit": "^3.1.0", "p-limit": "^3.1.0",
"p-wait-for": "^3.2.0", "p-wait-for": "^3.2.0",
"peer-id": "^0.14.2", "peer-id": "^0.14.2",
"protons": "^2.0.0", "protons": "^2.0.0",
"sinon": "^9.2.4", "sinon": "^10.0.0",
"streaming-iterables": "^5.0.4", "streaming-iterables": "^5.0.4",
"uint8arrays": "^2.0.5" "uint8arrays": "^2.1.3"
}, },
"devDependencies": { "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", "it-handshake": "^1.0.2",
"rimraf": "^3.0.2" "rimraf": "^3.0.2",
"util": "^0.12.3"
}, },
"contributors": [ "contributors": [
"Alan Shaw <alan.shaw@protocol.ai>", "Alan Shaw <alan.shaw@protocol.ai>",

View File

@ -230,6 +230,15 @@ class Connection {
module.exports = 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<void>} 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) { function validateArgs (localAddr, localPeer, remotePeer, newStream, close, getStreams, stat) {
if (localAddr && !multiaddr.isMultiaddr(localAddr)) { if (localAddr && !multiaddr.isMultiaddr(localAddr)) {
throw errCode(new Error('localAddr must be an instance of multiaddr'), 'ERR_INVALID_PARAMETERS') throw errCode(new Error('localAddr must be an instance of multiaddr'), 'ERR_INVALID_PARAMETERS')

View File

@ -1,3 +1,4 @@
// @ts-nocheck interface tests
/* eslint-env mocha */ /* eslint-env mocha */
'use strict' 'use strict'

View File

@ -1,3 +1,4 @@
// @ts-nocheck interface tests
/* eslint-env mocha */ /* eslint-env mocha */
'use strict' 'use strict'

11
src/content-routing/types.d.ts vendored Normal file
View File

@ -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[] }>;
}

View File

@ -1,3 +1,4 @@
// @ts-nocheck interface tests
/* eslint-env mocha */ /* eslint-env mocha */
'use strict' 'use strict'

View File

@ -1,3 +1,4 @@
// @ts-nocheck interface tests
/* eslint-env mocha */ /* eslint-env mocha */
'use strict' 'use strict'

10
src/peer-discovery/types.d.ts vendored Normal file
View File

@ -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;
}

10
src/peer-routing/types.d.ts vendored Normal file
View File

@ -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[] }>;
}

View File

@ -10,9 +10,7 @@ const { pipe } = require('it-pipe')
const MulticodecTopology = require('../topology/multicodec-topology') const MulticodecTopology = require('../topology/multicodec-topology')
const { codes } = require('./errors') const { codes } = require('./errors')
/**
* @type {typeof import('./message')}
*/
const message = require('./message') const message = require('./message')
const PeerStreams = require('./peer-streams') const PeerStreams = require('./peer-streams')
const { SignaturePolicy } = require('./signature-policy') const { SignaturePolicy } = require('./signature-policy')
@ -29,9 +27,9 @@ const {
* @typedef {import('bl')} BufferList * @typedef {import('bl')} BufferList
* @typedef {import('../stream-muxer/types').MuxedStream} MuxedStream * @typedef {import('../stream-muxer/types').MuxedStream} MuxedStream
* @typedef {import('../connection/connection')} Connection * @typedef {import('../connection/connection')} Connection
* @typedef {import('./message').RPC} RPC * @typedef {import('./message/types').RPC} RPC
* @typedef {import('./message').SubOpts} RPCSubOpts * @typedef {import('./message/types').SubOpts} RPCSubOpts
* @typedef {import('./message').Message} RPCMessage * @typedef {import('./message/types').Message} RPCMessage
* @typedef {import('./signature-policy').SignaturePolicyType} SignaturePolicyType * @typedef {import('./signature-policy').SignaturePolicyType} SignaturePolicyType
*/ */
@ -44,6 +42,16 @@ const {
* @property {Uint8Array} data * @property {Uint8Array} data
* @property {Uint8Array} [signature] * @property {Uint8Array} [signature]
* @property {Uint8Array} [key] * @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 { class PubsubBaseProtocol extends EventEmitter {
/** /**
* @param {Object} props * @param {PubsubProperties & PubsubOptions} 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
* @abstract * @abstract
*/ */
constructor ({ constructor ({
@ -83,8 +85,9 @@ class PubsubBaseProtocol extends EventEmitter {
super() super()
this.log = debug(debugName) this.log = Object.assign(debug(debugName), {
this.log.err = debug(`${debugName}:error`) err: debug(`${debugName}:error`)
})
/** /**
* @type {Array<string>} * @type {Array<string>}
@ -122,7 +125,7 @@ class PubsubBaseProtocol extends EventEmitter {
// validate signature policy // validate signature policy
if (!SignaturePolicy[globalSignaturePolicy]) { 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) { if (subs.length) {
// update peer subscriptions // 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) this.emit('pubsub:subscription-change', peerStreams.id, subs)
} }
@ -389,8 +394,9 @@ class PubsubBaseProtocol extends EventEmitter {
} }
if (msgs.length) { if (msgs.length) {
msgs.forEach(message => { // @ts-ignore RPC message is modified
if (!(this.canRelayMessage || message.topicIDs.some((topic) => this.subscriptions.has(topic)))) { 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.') this.log('received message we didn\'t subscribe to. Dropping.')
return return
} }
@ -589,7 +595,7 @@ class PubsubBaseProtocol extends EventEmitter {
for (const topic of message.topicIDs) { for (const topic of message.topicIDs) {
const validatorFn = this.topicValidators.get(topic) const validatorFn = this.topicValidators.get(topic)
if (!validatorFn) { if (!validatorFn) {
continue continue // eslint-disable-line
} }
await validatorFn(topic, message) await validatorFn(topic, message)
} }

View File

@ -1,17 +1,16 @@
'use strict' 'use strict'
// @ts-ignore protons not typed
const protons = require('protons') const protons = require('protons')
const rpcProto = protons(require('./rpc.proto.js')) const rpcProto = protons(require('./rpc.proto.js'))
const RPC = rpcProto.RPC const RPC = rpcProto.RPC
const topicDescriptorProto = protons(require('./topic-descriptor.proto.js')) const topicDescriptorProto = protons(require('./topic-descriptor.proto.js'))
/** module.exports = {
* @module pubsub/message/index rpc: rpcProto,
*/ td: topicDescriptorProto,
exports = module.exports RPC,
exports.rpc = rpcProto Message: RPC.Message,
exports.td = topicDescriptorProto SubOpts: RPC.SubOpts
exports.RPC = RPC }
exports.Message = RPC.Message
exports.SubOpts = RPC.SubOpts

5
src/pubsub/message/types.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
import { RPC, Message, SubOpts } from './types'
export type RPC = RPC
export type Message = Message
export type SubOpts = SubOpts

View File

@ -1,5 +1,10 @@
'use strict' '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 */ /** @typedef {import('../types').EventEmitterFactory} Events */
/** @type Events */ /** @type Events */
const EventEmitter = require('events') const EventEmitter = require('events')
@ -10,10 +15,6 @@ const pushable = require('it-pushable')
const { pipe } = require('it-pipe') const { pipe } = require('it-pipe')
const { source: abortable } = require('abortable-iterator') const { source: abortable } = require('abortable-iterator')
const AbortController = require('abort-controller').default 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 * @typedef {import('../stream-muxer/types').MuxedStream} MuxedStream
@ -168,7 +169,7 @@ class PeerStreams extends EventEmitter {
this.outboundStream, this.outboundStream,
lp.encode(), lp.encode(),
this._rawOutboundStream this._rawOutboundStream
).catch(err => { ).catch(/** @param {Error} err */ err => {
log.error(err) log.error(err)
}) })

View File

@ -1,3 +1,4 @@
// @ts-nocheck interface tests
/* eslint-env mocha */ /* eslint-env mocha */
'use strict' 'use strict'

View File

@ -1,3 +1,4 @@
// @ts-nocheck interface tests
/* eslint-env mocha */ /* eslint-env mocha */
'use strict' 'use strict'

View File

@ -1,3 +1,4 @@
// @ts-nocheck interface tests
/* eslint-env mocha */ /* eslint-env mocha */
'use strict' 'use strict'

View File

@ -1,3 +1,4 @@
// @ts-nocheck interface tests
/* eslint-env mocha */ /* eslint-env mocha */
'use strict' 'use strict'

View File

@ -1,3 +1,4 @@
// @ts-nocheck interface tests
/* eslint-env mocha */ /* eslint-env mocha */
/* eslint max-nested-callbacks: ["error", 6] */ /* eslint max-nested-callbacks: ["error", 6] */
'use strict' 'use strict'

View File

@ -1,3 +1,4 @@
// @ts-nocheck interface tests
/* eslint-env mocha */ /* eslint-env mocha */
/* eslint max-nested-callbacks: ["error", 6] */ /* eslint max-nested-callbacks: ["error", 6] */
'use strict' 'use strict'

View File

@ -1,3 +1,4 @@
// @ts-nocheck interface tests
'use strict' 'use strict'
const { expect } = require('chai') const { expect } = require('chai')

View File

@ -1,11 +1,11 @@
'use strict' 'use strict'
// @ts-ignore libp2p crypto has no types
const randomBytes = require('libp2p-crypto/src/random-bytes') const randomBytes = require('libp2p-crypto/src/random-bytes')
const uint8ArrayToString = require('uint8arrays/to-string') const uint8ArrayToString = require('uint8arrays/to-string')
const uint8ArrayFromString = require('uint8arrays/from-string') const uint8ArrayFromString = require('uint8arrays/from-string')
const PeerId = require('peer-id') const PeerId = require('peer-id')
const multihash = require('multihashes') const multihash = require('multihashes')
exports = module.exports
/** /**
* Generatea random sequence number. * Generatea random sequence number.
@ -13,7 +13,7 @@ exports = module.exports
* @returns {Uint8Array} * @returns {Uint8Array}
* @private * @private
*/ */
exports.randomSeqno = () => { const randomSeqno = () => {
return randomBytes(8) return randomBytes(8)
} }
@ -25,7 +25,7 @@ exports.randomSeqno = () => {
* @returns {Uint8Array} * @returns {Uint8Array}
* @private * @private
*/ */
exports.msgId = (from, seqno) => { const msgId = (from, seqno) => {
const fromBytes = PeerId.createFromB58String(from).id const fromBytes = PeerId.createFromB58String(from).id
const msgId = new Uint8Array(fromBytes.length + seqno.length) const msgId = new Uint8Array(fromBytes.length + seqno.length)
msgId.set(fromBytes, 0) msgId.set(fromBytes, 0)
@ -40,22 +40,28 @@ exports.msgId = (from, seqno) => {
* @returns {Uint8Array} * @returns {Uint8Array}
* @private * @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 * Check if any member of the first set is also a member
* of the second set. * of the second set.
* *
* @param {Set|Array} a * @param {Set<number>|Array<number>} a
* @param {Set|Array} b * @param {Set<number>|Array<number>} b
* @returns {boolean} * @returns {boolean}
* @private * @private
*/ */
exports.anyMatch = (a, b) => { const anyMatch = (a, b) => {
let bHas let bHas
if (Array.isArray(b)) { if (Array.isArray(b)) {
/**
* @param {number} val
*/
bHas = (val) => b.indexOf(val) > -1 bHas = (val) => b.indexOf(val) > -1
} else { } else {
/**
* @param {number} val
*/
bHas = (val) => b.has(val) bHas = (val) => b.has(val)
} }
@ -76,7 +82,7 @@ exports.anyMatch = (a, b) => {
* @returns {T[]} * @returns {T[]}
* @private * @private
*/ */
exports.ensureArray = (maybeArray) => { const ensureArray = (maybeArray) => {
if (!Array.isArray(maybeArray)) { if (!Array.isArray(maybeArray)) {
return [maybeArray] return [maybeArray]
} }
@ -92,7 +98,7 @@ exports.ensureArray = (maybeArray) => {
* @param {string} [peerId] * @param {string} [peerId]
* @returns {T & {from?: string, peerId?: string }} * @returns {T & {from?: string, peerId?: string }}
*/ */
exports.normalizeInRpcMessage = (message, peerId) => { const normalizeInRpcMessage = (message, peerId) => {
const m = Object.assign({}, message) const m = Object.assign({}, message)
if (message.from instanceof Uint8Array) { if (message.from instanceof Uint8Array) {
m.from = uint8ArrayToString(message.from, 'base58btc') m.from = uint8ArrayToString(message.from, 'base58btc')
@ -109,7 +115,7 @@ exports.normalizeInRpcMessage = (message, peerId) => {
* @param {T} message * @param {T} message
* @returns {T & {from?: Uint8Array, data?: Uint8Array}} * @returns {T & {from?: Uint8Array, data?: Uint8Array}}
*/ */
exports.normalizeOutRpcMessage = (message) => { const normalizeOutRpcMessage = (message) => {
const m = Object.assign({}, message) const m = Object.assign({}, message)
if (typeof message.from === 'string') { if (typeof message.from === 'string') {
m.from = uint8ArrayFromString(message.from, 'base58btc') m.from = uint8ArrayFromString(message.from, 'base58btc')
@ -119,3 +125,13 @@ exports.normalizeOutRpcMessage = (message) => {
} }
return m return m
} }
module.exports = {
randomSeqno,
msgId,
noSignMsgId,
anyMatch,
ensureArray,
normalizeInRpcMessage,
normalizeOutRpcMessage
}

View File

@ -1,3 +1,4 @@
// @ts-nocheck interface tests
/* eslint-env mocha */ /* eslint-env mocha */
'use strict' 'use strict'

View File

@ -1,3 +1,4 @@
// @ts-nocheck interface tests
/* eslint-env mocha */ /* eslint-env mocha */
'use strict' 'use strict'

View File

@ -1,3 +1,4 @@
// @ts-nocheck interface tests
/* eslint-env mocha */ /* eslint-env mocha */
/* eslint max-nested-callbacks: ["error", 8] */ /* eslint max-nested-callbacks: ["error", 8] */
'use strict' 'use strict'

View File

@ -1,3 +1,4 @@
// @ts-nocheck interface tests
/* eslint-env mocha */ /* eslint-env mocha */
'use strict' 'use strict'

View File

@ -1,3 +1,4 @@
// @ts-nocheck interface tests
/* eslint-env mocha */ /* eslint-env mocha */
'use strict' 'use strict'

View File

@ -1,3 +1,4 @@
// @ts-nocheck interface tests
'use strict' 'use strict'
const { expect } = require('chai') const { expect } = require('chai')

View File

@ -1,3 +1,4 @@
// @ts-nocheck interface tests
/* eslint-env mocha */ /* eslint-env mocha */
'use strict' 'use strict'

View File

@ -43,9 +43,9 @@ export interface MuxedStream extends AsyncIterable<Uint8Array | BufferList> {
abort: () => void; abort: () => void;
reset: () => void; reset: () => void;
sink: Sink; sink: Sink;
source: () => AsyncIterable<Uint8Array | BufferList>; source: AsyncIterable<Uint8Array | BufferList>;
timeline: MuxedTimeline; timeline: MuxedTimeline;
id: string; id: string;
} }
export type Sink = (source: Uint8Array) => Promise<Uint8Array>; export type Sink = (source: Uint8Array) => Promise<void>;

View File

@ -62,6 +62,9 @@ class Topology {
return Boolean(other && other[topologySymbol]) return Boolean(other && other[topologySymbol])
} }
/**
* @param {any} registrar
*/
set registrar (registrar) { // eslint-disable-line set registrar (registrar) { // eslint-disable-line
this._registrar = registrar this._registrar = registrar
} }

View File

@ -56,6 +56,9 @@ class MulticodecTopology extends Topology {
return Boolean(other && other[multicodecTopologySymbol]) return Boolean(other && other[multicodecTopologySymbol])
} }
/**
* @param {any} registrar
*/
set registrar (registrar) { // eslint-disable-line set registrar (registrar) { // eslint-disable-line
this._registrar = registrar this._registrar = registrar
this._registrar.peerStore.on('change:protocols', this._onProtocolChange) this._registrar.peerStore.on('change:protocols', this._onProtocolChange)

View File

@ -1,3 +1,4 @@
// @ts-nocheck interface tests
/* eslint-env mocha */ /* eslint-env mocha */
'use strict' 'use strict'

View File

@ -1,3 +1,4 @@
// @ts-nocheck interface tests
/* eslint-env mocha */ /* eslint-env mocha */
'use strict' 'use strict'

View File

@ -1,3 +1,4 @@
// @ts-nocheck interface tests
/* eslint-env mocha */ /* eslint-env mocha */
'use strict' 'use strict'

View File

@ -1,3 +1,4 @@
// @ts-nocheck interface tests
/* eslint-env mocha */ /* eslint-env mocha */
'use strict' 'use strict'

View File

@ -1,3 +1,4 @@
// @ts-nocheck interface tests
/* eslint-env mocha */ /* eslint-env mocha */
'use strict' 'use strict'

View File

@ -1,3 +1,4 @@
// @ts-nocheck interface tests
/* eslint max-nested-callbacks: ["error", 8] */ /* eslint max-nested-callbacks: ["error", 8] */
/* eslint-env mocha */ /* eslint-env mocha */
'use strict' 'use strict'

View File

@ -1,3 +1,4 @@
import BufferList from 'bl'
import events from 'events' import events from 'events'
import Multiaddr from 'multiaddr' import Multiaddr from 'multiaddr'
import Connection from '../connection/connection' import Connection from '../connection/connection'
@ -62,7 +63,7 @@ export type MultiaddrConnectionTimeline = {
export type MultiaddrConnection = { export type MultiaddrConnection = {
sink: Sink; sink: Sink;
source: () => AsyncIterable<Uint8Array>; source: AsyncIterable<Uint8Array | BufferList>;
close: (err?: Error) => Promise<void>; close: (err?: Error) => Promise<void>;
conn: unknown; conn: unknown;
remoteAddr: Multiaddr; remoteAddr: Multiaddr;

View File

@ -3,13 +3,13 @@ export interface EventEmitterFactory {
} }
export interface EventEmitter { export interface EventEmitter {
addListener(event: string | symbol, listener: (...args: any[]) => void); addListener(event: string | symbol, listener: (...args: any[]) => void): EventEmitter;
on(event: string | symbol, listener: (...args: any[]) => void); on(event: string | symbol, listener: (...args: any[]) => void): EventEmitter;
once(event: string | symbol, listener: (...args: any[]) => void); once(event: string | symbol, listener: (...args: any[]) => void): EventEmitter;
removeListener(event: string | symbol, listener: (...args: any[]) => void); removeListener(event: string | symbol, listener: (...args: any[]) => void): EventEmitter;
off(event: string | symbol, listener: (...args: any[]) => void); off(event: string | symbol, listener: (...args: any[]) => void): EventEmitter;
removeAllListeners(event?: string | symbol); removeAllListeners(event?: string | symbol): EventEmitter;
setMaxListeners(n: number); setMaxListeners(n: number): EventEmitter;
getMaxListeners(): number; getMaxListeners(): number;
listeners(event: string | symbol): Function[]; // eslint-disable-line @typescript-eslint/ban-types listeners(event: string | symbol): Function[]; // eslint-disable-line @typescript-eslint/ban-types
rawListeners(event: string | symbol): Function[]; // eslint-disable-line @typescript-eslint/ban-types rawListeners(event: string | symbol): Function[]; // eslint-disable-line @typescript-eslint/ban-types