From 46618c795bf5363ba3186645640fb81349231db7 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Thu, 6 May 2021 14:01:05 +0100 Subject: [PATCH] fix: loosen input type for swarm.connect and swarm.disconnect (#3673) Accept peer ids as strings or multiaddrs as Multiaddrs. Fixes #3638 --- packages/ipfs-core-types/src/bitswap/index.d.ts | 2 +- packages/ipfs-core-types/src/dht/index.d.ts | 4 ++-- packages/ipfs-core-types/src/root.d.ts | 2 +- packages/ipfs-core-types/src/stats/index.d.ts | 2 +- packages/ipfs-core-types/src/swarm/index.d.ts | 10 +++++----- packages/ipfs-http-client/src/dht/find-peer.js | 3 +-- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/ipfs-core-types/src/bitswap/index.d.ts b/packages/ipfs-core-types/src/bitswap/index.d.ts index e5cf40e119..de1b2dabfa 100644 --- a/packages/ipfs-core-types/src/bitswap/index.d.ts +++ b/packages/ipfs-core-types/src/bitswap/index.d.ts @@ -24,7 +24,7 @@ export interface API { * // [ CID('QmHash') ] * ``` */ - wantlistForPeer: (peerId: CID | string, options?: AbortOptions & OptionExtension) => Promise + wantlistForPeer: (peerId: string, options?: AbortOptions & OptionExtension) => Promise /** * Removes one or more CIDs from the wantlist diff --git a/packages/ipfs-core-types/src/dht/index.d.ts b/packages/ipfs-core-types/src/dht/index.d.ts index 00c4aeaea1..91aa08c7ed 100644 --- a/packages/ipfs-core-types/src/dht/index.d.ts +++ b/packages/ipfs-core-types/src/dht/index.d.ts @@ -21,7 +21,7 @@ export interface API { * // '/ip4/147.75.94.115/tcp/4001' * ``` */ - findPeer: (peerId: CID | string, options?: AbortOptions & OptionExtension) => Promise + findPeer: (peerId: string, options?: AbortOptions & OptionExtension) => Promise /** * Find peers in the DHT that can provide a specific value, given a CID. @@ -59,7 +59,7 @@ export interface API { /** * Find the closest peers to a given `PeerId`, by querying the DHT. */ - query: (peerId: CID | string, options?: AbortOptions & OptionExtension) => AsyncIterable + query: (peerId: string, options?: AbortOptions & OptionExtension) => AsyncIterable } export interface PeerResult { diff --git a/packages/ipfs-core-types/src/root.d.ts b/packages/ipfs-core-types/src/root.d.ts index dba7e3e22f..3615811025 100644 --- a/packages/ipfs-core-types/src/root.d.ts +++ b/packages/ipfs-core-types/src/root.d.ts @@ -82,7 +82,7 @@ export interface API { * } * ``` */ - ping: (peerId: CID | string, options?: PingOptions & OptionExtension) => AsyncIterable + ping: (peerId: string, options?: PingOptions & OptionExtension) => AsyncIterable /** * Resolve the value of names to IPFS diff --git a/packages/ipfs-core-types/src/stats/index.d.ts b/packages/ipfs-core-types/src/stats/index.d.ts index 828617c950..8a2e997f21 100644 --- a/packages/ipfs-core-types/src/stats/index.d.ts +++ b/packages/ipfs-core-types/src/stats/index.d.ts @@ -14,7 +14,7 @@ export interface API { } export interface BWOptions extends AbortOptions { - peer?: CID | string + peer?: string proto?: string poll?: boolean interval?: number diff --git a/packages/ipfs-core-types/src/swarm/index.d.ts b/packages/ipfs-core-types/src/swarm/index.d.ts index 69b1ba872b..910e63271e 100644 --- a/packages/ipfs-core-types/src/swarm/index.d.ts +++ b/packages/ipfs-core-types/src/swarm/index.d.ts @@ -5,20 +5,20 @@ import type CID from 'cids' import type { Multiaddr } from 'multiaddr' export interface API { - /** + /** * List of known addresses of each peer connected */ addrs: (options?: AbortOptions & OptionExtension) => Promise /** - * Open a connection to a given address + * Open a connection to a given address or peer id */ - connect: (addr: Multiaddr, options?: AbortOptions & OptionExtension) => Promise + connect: (addr: Multiaddr | string, options?: AbortOptions & OptionExtension) => Promise /** - * Close a connection to a given address + * Close a connection to a given address or peer id */ - disconnect: (addr: Multiaddr, options?: AbortOptions & OptionExtension) => Promise + disconnect: (addr: Multiaddr | string, options?: AbortOptions & OptionExtension) => Promise /** * Local addresses this node is listening on diff --git a/packages/ipfs-http-client/src/dht/find-peer.js b/packages/ipfs-http-client/src/dht/find-peer.js index f4eabe5370..4e9880fb9e 100644 --- a/packages/ipfs-http-client/src/dht/find-peer.js +++ b/packages/ipfs-http-client/src/dht/find-peer.js @@ -1,6 +1,5 @@ 'use strict' -const CID = require('cids') const { Multiaddr } = require('multiaddr') const configure = require('../lib/configure') const toUrlSearchParams = require('../lib/to-url-search-params') @@ -20,7 +19,7 @@ module.exports = configure(api => { timeout: options.timeout, signal: options.signal, searchParams: toUrlSearchParams({ - arg: `${peerId instanceof Uint8Array ? new CID(peerId) : peerId}`, + arg: peerId, ...options }), headers: options.headers