chore: fix remaining ts ignores

This commit is contained in:
Vasco Santos 2020-12-02 21:39:17 +01:00
parent 149c19a886
commit d3d6b3566a
21 changed files with 40 additions and 65 deletions

View File

@ -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",

View File

@ -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<MuxedStream>|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<MuxedStream|void>} Resolves a duplex iterable
*/
module.exports.stop = async function stop ({
connection,

View File

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

View File

@ -129,8 +129,6 @@ class Circuit {
try {
const virtualConnection = await hop({
connection: relayConnection,
// @ts-ignore
circuit: this,
request: {
type: CircuitPB.Type.HOP,
srcPeer: {

View File

@ -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<Connection>} dialAction
* @property {(m: Multiaddr, options: DialOptions) => Promise<Connection>} dialAction
* @property {Dialer} dialer
*/
@ -46,7 +49,7 @@ class DialRequest {
* @param {AbortSignal} [options.signal] - An AbortController signal
* @returns {Promise<Connection>}
*/
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)

View File

@ -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) {

View File

@ -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'

View File

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

View File

@ -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.
*

View File

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

View File

@ -24,7 +24,6 @@ class Stats extends EventEmitter {
this._frequencyLastTime = Date.now()
this._frequencyAccumulators = {}
/** @type {{}} */
this._movingAverages = {}
this._update = this._update.bind(this)

View File

@ -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: {

View File

@ -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)) {

View File

@ -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)) {

View File

@ -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<string, Uint8Array>|undefined}
*/
// @ts-ignore
get (peerId) {
if (!PeerId.isPeerId(peerId)) {
throw errcode(new Error('peerId must be an instance of peer-id'), ERR_INVALID_PARAMETERS)

View File

@ -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),

View File

@ -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}`)
}

View File

@ -28,7 +28,7 @@ const { PROTOCOL, PING_LENGTH } = require('./constants')
* @returns {Promise<number>}
*/
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)

View File

@ -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)

View File

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

View File

@ -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 => {