UNPKG

kubo-rpc-client-esm-cjs

Version:
31 lines 1.28 kB
import { multiaddr } from '@multiformats/multiaddr'; import { configure } from '../lib/configure.js'; import { toUrlSearchParams } from '../lib/to-url-search-params.js'; import { peerIdFromString } from '@libp2p/peer-id'; export const createPeers = configure(api => { /** * @type {import('../types').SwarmAPI["peers"]} */ async function peers(options = {}) { const res = await api.post('swarm/peers', { signal: options.signal, searchParams: toUrlSearchParams(options), headers: options.headers }); /** @type {{ Peers: { Peer: string, Addr: string, Muxer?: string, Latency?: string, Streams?: string[], Direction?: 0 | 1 }[] }} */ const { Peers } = await res.json(); return (Peers || []).map(peer => { return { addr: multiaddr(peer.Addr), peer: peerIdFromString(peer.Peer), muxer: peer.Muxer, latency: peer.Latency, streams: peer.Streams, // eslint-disable-next-line no-nested-ternary direction: peer.Direction == null ? undefined : peer.Direction === 0 ? 'inbound' : 'outbound' }; }); } return peers; }); //# sourceMappingURL=peers.js.map