mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-04-24 16:32:32 +00:00
feat: remove is-class that broke typings
This commit is contained in:
parent
c1cb68e043
commit
cba63941b0
@ -2,10 +2,11 @@
|
||||
|
||||
const PeerId = require('peer-id')
|
||||
const multiaddr = require('multiaddr')
|
||||
const withIs = require('class-is')
|
||||
const errCode = require('err-code')
|
||||
const Status = require('./status')
|
||||
|
||||
const connectionSymbol = Symbol.for('@libp2p/interface-connection/connection')
|
||||
|
||||
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')
|
||||
@ -138,6 +139,24 @@ class Connection {
|
||||
this.tags = []
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag] () {
|
||||
return 'Connection'
|
||||
}
|
||||
|
||||
get [connectionSymbol]() {
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given value is a `Connection` instance.
|
||||
*
|
||||
* @param {any} other
|
||||
* @returns {other is Connection}
|
||||
*/
|
||||
static isConnection(other) {
|
||||
return Boolean(other && other[connectionSymbol])
|
||||
}
|
||||
|
||||
/**
|
||||
* Get connection metadata
|
||||
* @this {Connection}
|
||||
@ -227,8 +246,5 @@ class Connection {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @module
|
||||
* @type {typeof Connection}
|
||||
*/
|
||||
module.exports = withIs(Connection, { className: 'Connection', symbolName: '@libp2p/interface-connection/connection' })
|
||||
|
||||
module.exports = Connection
|
||||
|
@ -1,13 +1,13 @@
|
||||
'use strict'
|
||||
|
||||
const withIs = require('class-is')
|
||||
const noop = () => {}
|
||||
const topologySymbol = Symbol.for('@libp2p/js-interfaces/topology')
|
||||
|
||||
class Topology {
|
||||
/**
|
||||
* @param {Object} props
|
||||
* @param {number} props.min minimum needed connections (default: 0)
|
||||
* @param {number} props.max maximum needed connections (default: Infinity)
|
||||
* @param {number} [props.min] minimum needed connections (default: 0)
|
||||
* @param {number} [props.max] maximum needed connections (default: Infinity)
|
||||
* @param {Object} [props.handlers]
|
||||
* @param {function} [props.handlers.onConnect] protocol "onConnect" handler
|
||||
* @param {function} [props.handlers.onDisconnect] protocol "onDisconnect" handler
|
||||
@ -32,6 +32,24 @@ class Topology {
|
||||
this.peers = new Set()
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag] () {
|
||||
return 'Topology'
|
||||
}
|
||||
|
||||
get [topologySymbol]() {
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given value is a Topology instance.
|
||||
*
|
||||
* @param {any} other
|
||||
* @returns {other is Topology}
|
||||
*/
|
||||
static isTopology(other) {
|
||||
return Boolean(other && other[topologySymbol])
|
||||
}
|
||||
|
||||
set registrar (registrar) {
|
||||
this._registrar = registrar
|
||||
}
|
||||
@ -51,8 +69,4 @@ class Topology {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @module
|
||||
* @type {Topology}
|
||||
*/
|
||||
module.exports = withIs(Topology, { className: 'Topology', symbolName: '@libp2p/js-interfaces/topology' })
|
||||
module.exports = Topology
|
||||
|
@ -1,14 +1,14 @@
|
||||
'use strict'
|
||||
|
||||
const withIs = require('class-is')
|
||||
|
||||
const Topology = require('./index')
|
||||
const multicodecTopologySymbol = Symbol.for('@libp2p/js-interfaces/topology/multicodec-topology')
|
||||
|
||||
|
||||
class MulticodecTopology extends Topology {
|
||||
/**
|
||||
* @param {Object} props
|
||||
* @param {number} props.min minimum needed connections (default: 0)
|
||||
* @param {number} props.max maximum needed connections (default: Infinity)
|
||||
* @param {number} [props.min] minimum needed connections (default: 0)
|
||||
* @param {number} [props.max] maximum needed connections (default: Infinity)
|
||||
* @param {Array<string>} props.multicodecs protocol multicodecs
|
||||
* @param {Object} props.handlers
|
||||
* @param {function} props.handlers.onConnect protocol "onConnect" handler
|
||||
@ -46,6 +46,24 @@ class MulticodecTopology extends Topology {
|
||||
this._onPeerConnect = this._onPeerConnect.bind(this)
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag] () {
|
||||
return 'Topology'
|
||||
}
|
||||
|
||||
get [multicodecTopologySymbol]() {
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given value is a `MulticodecTopology` instance.
|
||||
*
|
||||
* @param {any} other
|
||||
* @returns {other is MulticodecTopology}
|
||||
*/
|
||||
static isMulticodecTopology(other) {
|
||||
return Boolean(other && other[multicodecTopologySymbol])
|
||||
}
|
||||
|
||||
set registrar (registrar) {
|
||||
this._registrar = registrar
|
||||
this._registrar.peerStore.on('change:protocols', this._onProtocolChange)
|
||||
@ -120,8 +138,4 @@ class MulticodecTopology extends Topology {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @module
|
||||
* @type {MulticodecTopology}
|
||||
*/
|
||||
module.exports = withIs(MulticodecTopology, { className: 'MulticodecTopology', symbolName: '@libp2p/js-interfaces/topology/multicodec-topology' })
|
||||
module.exports = MulticodecTopology
|
||||
|
Loading…
x
Reference in New Issue
Block a user