From 25784ae1eaaf2092e0156490d3cb5568441a53bc Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Fri, 30 Jul 2021 09:43:08 +1000 Subject: [PATCH 1/3] fix: typo in 'multiformats' type defs Fixes: https://github.com/ipfs/js-ipfs/issues/3776 --- packages/ipfs-core-types/src/bitswap/index.d.ts | 2 +- packages/ipfs-core-types/src/dht/index.d.ts | 2 +- packages/ipfs-core-types/src/name/index.d.ts | 2 +- packages/ipfs-core-types/src/object/index.d.ts | 2 +- packages/ipfs-core-types/src/object/patch/index.d.ts | 2 +- packages/ipfs-core-types/src/pin/index.d.ts | 2 +- packages/ipfs-core-types/src/pin/remote/index.d.ts | 2 +- packages/ipfs-core-types/src/repo/index.d.ts | 2 +- packages/ipfs-core-types/src/utils.d.ts | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/ipfs-core-types/src/bitswap/index.d.ts b/packages/ipfs-core-types/src/bitswap/index.d.ts index 4de64c7a3b..07e069963b 100644 --- a/packages/ipfs-core-types/src/bitswap/index.d.ts +++ b/packages/ipfs-core-types/src/bitswap/index.d.ts @@ -1,4 +1,4 @@ -import type { CID } from 'multiformts/cid' +import type { CID } from 'multiformats/cid' import type { AbortOptions } from '../utils' export interface API { diff --git a/packages/ipfs-core-types/src/dht/index.d.ts b/packages/ipfs-core-types/src/dht/index.d.ts index 30b263802b..1452bb95c1 100644 --- a/packages/ipfs-core-types/src/dht/index.d.ts +++ b/packages/ipfs-core-types/src/dht/index.d.ts @@ -1,6 +1,6 @@ import type { AbortOptions } from '../utils' import type { Multiaddr } from 'multiaddr' -import type { CID } from 'multiformts/cid' +import type { CID } from 'multiformats/cid' export interface API { /** diff --git a/packages/ipfs-core-types/src/name/index.d.ts b/packages/ipfs-core-types/src/name/index.d.ts index d4c70087bf..a4f8b453ed 100644 --- a/packages/ipfs-core-types/src/name/index.d.ts +++ b/packages/ipfs-core-types/src/name/index.d.ts @@ -1,4 +1,4 @@ -import { CID } from 'multiformts/cid' +import { CID } from 'multiformats/cid' import type { AbortOptions } from '../utils' import type { API as PubsubAPI } from './pubsub' diff --git a/packages/ipfs-core-types/src/object/index.d.ts b/packages/ipfs-core-types/src/object/index.d.ts index fa830dad8b..521166291e 100644 --- a/packages/ipfs-core-types/src/object/index.d.ts +++ b/packages/ipfs-core-types/src/object/index.d.ts @@ -1,4 +1,4 @@ -import type { CID } from 'multiformts/cid' +import type { CID } from 'multiformats/cid' import type { AbortOptions, PreloadOptions } from '../utils' import type { API as PatchAPI } from './patch' import type { PBNode, PBLink } from '@ipld/dag-pb' diff --git a/packages/ipfs-core-types/src/object/patch/index.d.ts b/packages/ipfs-core-types/src/object/patch/index.d.ts index b21ddd601a..aee302a74d 100644 --- a/packages/ipfs-core-types/src/object/patch/index.d.ts +++ b/packages/ipfs-core-types/src/object/patch/index.d.ts @@ -1,4 +1,4 @@ -import type { CID } from 'multiformts/cid' +import type { CID } from 'multiformats/cid' import type { AbortOptions } from '../../utils' import type { PBLink as DAGLink } from '@ipld/dag-pb' diff --git a/packages/ipfs-core-types/src/pin/index.d.ts b/packages/ipfs-core-types/src/pin/index.d.ts index 285882f5c9..ff15758d98 100644 --- a/packages/ipfs-core-types/src/pin/index.d.ts +++ b/packages/ipfs-core-types/src/pin/index.d.ts @@ -1,5 +1,5 @@ import type { AbortOptions, AwaitIterable } from '../utils' -import type { CID } from 'multiformts/cid' +import type { CID } from 'multiformats/cid' import type { API as Remote } from './remote' export interface API { diff --git a/packages/ipfs-core-types/src/pin/remote/index.d.ts b/packages/ipfs-core-types/src/pin/remote/index.d.ts index d52af9d936..92c9d638cd 100644 --- a/packages/ipfs-core-types/src/pin/remote/index.d.ts +++ b/packages/ipfs-core-types/src/pin/remote/index.d.ts @@ -1,4 +1,4 @@ -import { CID } from 'multiformts/cid' +import { CID } from 'multiformats/cid' import { Multiaddr } from 'multiaddr' import { API as Service } from './service' import { AbortOptions } from '../../utils' diff --git a/packages/ipfs-core-types/src/repo/index.d.ts b/packages/ipfs-core-types/src/repo/index.d.ts index 84d509be77..6a803a0418 100644 --- a/packages/ipfs-core-types/src/repo/index.d.ts +++ b/packages/ipfs-core-types/src/repo/index.d.ts @@ -1,5 +1,5 @@ import type { AbortOptions } from '../utils' -import { CID } from 'multiformts/cid' +import { CID } from 'multiformats/cid' export interface API { /** diff --git a/packages/ipfs-core-types/src/utils.d.ts b/packages/ipfs-core-types/src/utils.d.ts index 1ceea70b79..cac2a120d6 100644 --- a/packages/ipfs-core-types/src/utils.d.ts +++ b/packages/ipfs-core-types/src/utils.d.ts @@ -1,4 +1,4 @@ -import { CID } from 'multiformts/cid' +import { CID } from 'multiformats/cid' import { Mtime, MtimeLike } from 'ipfs-unixfs' export type Entry|Blob> = From 55374565f2b840953d5d74b68a2ebddfb384460f Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 30 Jul 2021 11:50:46 +0100 Subject: [PATCH 2/3] chore: fix types --- packages/ipfs-core-types/src/block/index.d.ts | 2 +- packages/ipfs-core/src/components/dht.js | 13 +------------ .../ipfs-http-server/src/api/resources/object.js | 7 ++++--- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/packages/ipfs-core-types/src/block/index.d.ts b/packages/ipfs-core-types/src/block/index.d.ts index 989626302f..8a185ef3f6 100644 --- a/packages/ipfs-core-types/src/block/index.d.ts +++ b/packages/ipfs-core-types/src/block/index.d.ts @@ -78,7 +78,7 @@ export interface API { * // Logs: 3739 * ``` */ - stat: (ipfsPath: IPFSPath, options?: AbortOptions & PreloadOptions & OptionExtension) => Promise + stat: (cid: CID, options?: AbortOptions & PreloadOptions & OptionExtension) => Promise } export interface PutOptions extends AbortOptions, PreloadOptions { diff --git a/packages/ipfs-core/src/components/dht.js b/packages/ipfs-core/src/components/dht.js index 1b4a62bc02..7186cad605 100644 --- a/packages/ipfs-core/src/components/dht.js +++ b/packages/ipfs-core/src/components/dht.js @@ -65,19 +65,8 @@ module.exports = ({ network, repo }) => { */ async * provide (cids, options = { recursive: false }) { const { libp2p } = await use(network, options) - /** @type {CID[]} */ const cidArr = Array.isArray(cids) ? cids : [cids] - for (const i in cids) { - if (typeof cids[i] === 'string') { - try { - cids[i] = CID.parse(cids[i]) - } catch (err) { - throw errCode(err, 'ERR_INVALID_CID') - } - } - } - // ensure blocks are actually local const hasCids = await Promise.all(cidArr.map(cid => repo.blocks.has(cid))) const hasAll = hasCids.every(has => has) @@ -91,7 +80,7 @@ module.exports = ({ network, repo }) => { throw errCode(new Error('not implemented yet'), 'ERR_NOT_IMPLEMENTED_YET') } - for (const cid of cids) { + for (const cid of cidArr) { yield libp2p._dht.provide(cid) } }, diff --git a/packages/ipfs-http-server/src/api/resources/object.js b/packages/ipfs-http-server/src/api/resources/object.js index 6b4bbf1ee0..74f5e4f3ae 100644 --- a/packages/ipfs-http-server/src/api/resources/object.js +++ b/packages/ipfs-http-server/src/api/resources/object.js @@ -399,9 +399,10 @@ exports.stat = { const base = await ipfs.bases.getBase(cidBase) - stats.Hash = stats.Hash.toString(base.encoder) - - return h.response(stats) + return h.response({ + ...stats, + Hash: stats.Hash.toString(base.encoder) + }) } } From 3a8210ac508bd4263e5559cb96aef28616b8dccc Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 30 Jul 2021 12:10:53 +0100 Subject: [PATCH 3/3] chore: linting --- packages/ipfs-core-types/src/block/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ipfs-core-types/src/block/index.d.ts b/packages/ipfs-core-types/src/block/index.d.ts index 8a185ef3f6..46a3131291 100644 --- a/packages/ipfs-core-types/src/block/index.d.ts +++ b/packages/ipfs-core-types/src/block/index.d.ts @@ -1,4 +1,4 @@ -import { AbortOptions, PreloadOptions, IPFSPath } from '../utils' +import { AbortOptions, PreloadOptions } from '../utils' import { CID, CIDVersion } from 'multiformats/cid' export interface API {