From a7450337796a5bd128f6427f6bfa9da934d1cc99 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 6 May 2022 10:42:45 +0100 Subject: [PATCH 01/39] feat: update to libp2p 0.37.x Upgrades libp2p and all supporting versions to the latest version. BREAKING CHANGE: This module is now ESM only and there return types of some methods have changed --- docs/FAQ.md | 2 +- docs/MIGRATION-TO-ASYNC-AWAIT.md | 4 +- docs/MODULE.md | 2 +- docs/core-api/PUBSUB.md | 2 +- package-list.json | 2 +- .../{.aegir.cjs => .aegir.js} | 3 +- packages/interface-ipfs-core/package.json | 31 ++-- packages/interface-ipfs-core/src/add-all.js | 44 ++--- packages/interface-ipfs-core/src/add.js | 24 +-- .../interface-ipfs-core/src/bitswap/stat.js | 4 +- .../src/bitswap/transfer.js | 12 +- .../interface-ipfs-core/src/bitswap/unwant.js | 4 +- .../interface-ipfs-core/src/bitswap/utils.js | 8 +- .../src/bitswap/wantlist-for-peer.js | 6 +- .../src/bitswap/wantlist.js | 8 +- packages/interface-ipfs-core/src/block/get.js | 4 +- packages/interface-ipfs-core/src/block/put.js | 4 +- packages/interface-ipfs-core/src/block/rm.js | 4 +- .../interface-ipfs-core/src/block/stat.js | 4 +- .../interface-ipfs-core/src/bootstrap/add.js | 6 +- .../src/bootstrap/clear.js | 6 +- .../interface-ipfs-core/src/bootstrap/list.js | 6 +- .../src/bootstrap/reset.js | 6 +- .../interface-ipfs-core/src/bootstrap/rm.js | 6 +- packages/interface-ipfs-core/src/cat.js | 4 +- .../interface-ipfs-core/src/config/get.js | 4 +- .../src/config/profiles/apply.js | 4 +- .../src/config/profiles/list.js | 4 +- .../interface-ipfs-core/src/config/replace.js | 4 +- .../interface-ipfs-core/src/config/set.js | 4 +- .../interface-ipfs-core/src/dag/export.js | 10 +- packages/interface-ipfs-core/src/dag/get.js | 4 +- .../interface-ipfs-core/src/dag/import.js | 10 +- packages/interface-ipfs-core/src/dag/put.js | 4 +- .../interface-ipfs-core/src/dag/resolve.js | 4 +- .../src/dag/sharness-t0053-dag.js | 4 +- .../interface-ipfs-core/src/dht/disabled.js | 9 +- .../interface-ipfs-core/src/dht/find-peer.js | 7 +- .../interface-ipfs-core/src/dht/find-provs.js | 10 +- packages/interface-ipfs-core/src/dht/get.js | 4 +- .../interface-ipfs-core/src/dht/provide.js | 4 +- packages/interface-ipfs-core/src/dht/put.js | 6 +- packages/interface-ipfs-core/src/dht/query.js | 9 +- packages/interface-ipfs-core/src/dht/utils.js | 2 +- .../interface-ipfs-core/src/files/chmod.js | 4 +- packages/interface-ipfs-core/src/files/cp.js | 4 +- .../interface-ipfs-core/src/files/flush.js | 4 +- packages/interface-ipfs-core/src/files/ls.js | 4 +- .../interface-ipfs-core/src/files/mkdir.js | 4 +- packages/interface-ipfs-core/src/files/mv.js | 4 +- .../interface-ipfs-core/src/files/read.js | 4 +- packages/interface-ipfs-core/src/files/rm.js | 4 +- .../interface-ipfs-core/src/files/stat.js | 4 +- .../interface-ipfs-core/src/files/touch.js | 10 +- .../interface-ipfs-core/src/files/write.js | 8 +- packages/interface-ipfs-core/src/get.js | 44 ++--- packages/interface-ipfs-core/src/key/gen.js | 12 +- .../interface-ipfs-core/src/key/import.js | 6 +- packages/interface-ipfs-core/src/key/list.js | 6 +- .../interface-ipfs-core/src/key/rename.js | 6 +- packages/interface-ipfs-core/src/key/rm.js | 6 +- packages/interface-ipfs-core/src/ls.js | 4 +- .../src/miscellaneous/dns.js | 10 +- .../src/miscellaneous/id.js | 17 +- .../src/miscellaneous/resolve.js | 14 +- .../src/miscellaneous/stop.js | 4 +- .../src/miscellaneous/version.js | 4 +- .../src/name-pubsub/cancel.js | 16 +- .../src/name-pubsub/pubsub.js | 81 ++++----- .../src/name-pubsub/state.js | 6 +- .../src/name-pubsub/subs.js | 8 +- .../interface-ipfs-core/src/name/publish.js | 23 +-- .../interface-ipfs-core/src/name/resolve.js | 32 ++-- .../interface-ipfs-core/src/object/data.js | 4 +- .../interface-ipfs-core/src/object/get.js | 4 +- .../interface-ipfs-core/src/object/links.js | 4 +- .../interface-ipfs-core/src/object/new.js | 4 +- .../src/object/patch/add-link.js | 4 +- .../src/object/patch/append-data.js | 4 +- .../src/object/patch/rm-link.js | 4 +- .../src/object/patch/set-data.js | 4 +- .../interface-ipfs-core/src/object/put.js | 4 +- .../interface-ipfs-core/src/object/stat.js | 4 +- .../interface-ipfs-core/src/pin/add-all.js | 4 +- packages/interface-ipfs-core/src/pin/add.js | 12 +- packages/interface-ipfs-core/src/pin/ls.js | 4 +- .../interface-ipfs-core/src/pin/remote/add.js | 4 +- .../interface-ipfs-core/src/pin/remote/ls.js | 4 +- .../src/pin/remote/rm-all.js | 4 +- .../interface-ipfs-core/src/pin/remote/rm.js | 4 +- .../src/pin/remote/service.js | 4 +- .../interface-ipfs-core/src/pin/rm-all.js | 4 +- packages/interface-ipfs-core/src/pin/rm.js | 4 +- packages/interface-ipfs-core/src/pin/utils.js | 4 +- packages/interface-ipfs-core/src/ping/ping.js | 18 +- .../interface-ipfs-core/src/ping/utils.js | 2 +- packages/interface-ipfs-core/src/pubsub/ls.js | 4 +- .../interface-ipfs-core/src/pubsub/peers.js | 12 +- .../interface-ipfs-core/src/pubsub/publish.js | 4 +- .../src/pubsub/subscribe.js | 172 +++++++++--------- .../src/pubsub/unsubscribe.js | 5 +- .../interface-ipfs-core/src/pubsub/utils.js | 8 +- .../interface-ipfs-core/src/refs-local.js | 4 +- packages/interface-ipfs-core/src/refs.js | 10 +- packages/interface-ipfs-core/src/repo/gc.js | 4 +- packages/interface-ipfs-core/src/repo/stat.js | 2 +- .../interface-ipfs-core/src/repo/version.js | 4 +- .../interface-ipfs-core/src/stats/bitswap.js | 2 +- packages/interface-ipfs-core/src/stats/bw.js | 4 +- .../interface-ipfs-core/src/stats/repo.js | 2 +- .../interface-ipfs-core/src/stats/utils.js | 2 +- .../interface-ipfs-core/src/swarm/addrs.js | 13 +- .../interface-ipfs-core/src/swarm/connect.js | 12 +- .../src/swarm/disconnect.js | 8 +- .../src/swarm/local-addrs.js | 4 +- .../interface-ipfs-core/src/swarm/peers.js | 20 +- .../src/utils/create-sharded-directory.js | 2 +- .../src/utils/create-two-shards.js | 2 +- .../interface-ipfs-core/src/utils/index.js | 4 +- .../ipfs-options-websockets-filter-all.js | 10 +- packages/ipfs-cli/package.json | 31 ++-- packages/ipfs-cli/src/commands/add.js | 2 + .../ipfs-cli/src/commands/bitswap/stat.js | 2 + .../ipfs-cli/src/commands/bitswap/unwant.js | 2 + .../ipfs-cli/src/commands/bitswap/wantlist.js | 8 +- packages/ipfs-cli/src/commands/block/get.js | 2 + packages/ipfs-cli/src/commands/block/put.js | 2 + packages/ipfs-cli/src/commands/block/rm.js | 2 + packages/ipfs-cli/src/commands/block/stat.js | 2 + .../ipfs-cli/src/commands/bootstrap/add.js | 4 +- .../ipfs-cli/src/commands/bootstrap/list.js | 2 + .../ipfs-cli/src/commands/bootstrap/rm.js | 4 +- packages/ipfs-cli/src/commands/cat.js | 2 + packages/ipfs-cli/src/commands/cid/base32.js | 2 + packages/ipfs-cli/src/commands/cid/bases.js | 2 + packages/ipfs-cli/src/commands/cid/codecs.js | 2 + packages/ipfs-cli/src/commands/cid/format.js | 2 + packages/ipfs-cli/src/commands/cid/hashes.js | 2 + packages/ipfs-cli/src/commands/commands.js | 5 +- packages/ipfs-cli/src/commands/config.js | 2 + packages/ipfs-cli/src/commands/config/edit.js | 4 +- .../src/commands/config/profile/apply.js | 2 + .../src/commands/config/profile/ls.js | 2 + .../ipfs-cli/src/commands/config/replace.js | 2 + packages/ipfs-cli/src/commands/config/show.js | 2 + packages/ipfs-cli/src/commands/daemon.js | 7 +- packages/ipfs-cli/src/commands/dag/export.js | 2 + packages/ipfs-cli/src/commands/dag/get.js | 2 + packages/ipfs-cli/src/commands/dag/import.js | 2 + packages/ipfs-cli/src/commands/dag/put.js | 2 + packages/ipfs-cli/src/commands/dag/resolve.js | 4 +- .../ipfs-cli/src/commands/dht/find-peer.js | 8 +- .../src/commands/dht/find-providers.js | 2 + packages/ipfs-cli/src/commands/dht/get.js | 2 + packages/ipfs-cli/src/commands/dht/provide.js | 2 + packages/ipfs-cli/src/commands/dht/put.js | 2 + packages/ipfs-cli/src/commands/dht/query.js | 35 +++- packages/ipfs-cli/src/commands/dns.js | 2 + packages/ipfs-cli/src/commands/files.js | 2 + packages/ipfs-cli/src/commands/files/chmod.js | 6 +- packages/ipfs-cli/src/commands/files/cp.js | 6 +- packages/ipfs-cli/src/commands/files/flush.js | 2 + packages/ipfs-cli/src/commands/files/ls.js | 2 + packages/ipfs-cli/src/commands/files/mkdir.js | 6 +- packages/ipfs-cli/src/commands/files/mv.js | 6 +- packages/ipfs-cli/src/commands/files/read.js | 2 + packages/ipfs-cli/src/commands/files/rm.js | 6 +- packages/ipfs-cli/src/commands/files/stat.js | 2 + packages/ipfs-cli/src/commands/files/touch.js | 6 +- packages/ipfs-cli/src/commands/files/write.js | 2 + packages/ipfs-cli/src/commands/get.js | 5 +- packages/ipfs-cli/src/commands/id.js | 10 +- packages/ipfs-cli/src/commands/init.js | 7 +- packages/ipfs-cli/src/commands/key/export.js | 2 + packages/ipfs-cli/src/commands/key/gen.js | 4 +- packages/ipfs-cli/src/commands/key/import.js | 2 + packages/ipfs-cli/src/commands/key/list.js | 2 + packages/ipfs-cli/src/commands/key/rename.js | 2 + packages/ipfs-cli/src/commands/key/rm.js | 2 + packages/ipfs-cli/src/commands/ls.js | 2 + packages/ipfs-cli/src/commands/name.js | 2 +- .../ipfs-cli/src/commands/name/publish.js | 2 + .../src/commands/name/pubsub/cancel.js | 2 + .../src/commands/name/pubsub/state.js | 2 + .../ipfs-cli/src/commands/name/pubsub/subs.js | 2 + .../ipfs-cli/src/commands/name/resolve.js | 2 + packages/ipfs-cli/src/commands/object/data.js | 2 + packages/ipfs-cli/src/commands/object/get.js | 4 +- .../ipfs-cli/src/commands/object/links.js | 2 + packages/ipfs-cli/src/commands/object/new.js | 2 + .../src/commands/object/patch/add-link.js | 2 + .../src/commands/object/patch/append-data.js | 2 + .../src/commands/object/patch/rm-link.js | 2 + .../src/commands/object/patch/set-data.js | 2 + packages/ipfs-cli/src/commands/object/put.js | 2 + packages/ipfs-cli/src/commands/object/stat.js | 2 + packages/ipfs-cli/src/commands/pin/add.js | 2 + packages/ipfs-cli/src/commands/pin/ls.js | 2 + packages/ipfs-cli/src/commands/pin/rm.js | 2 + packages/ipfs-cli/src/commands/ping.js | 10 +- packages/ipfs-cli/src/commands/pubsub/ls.js | 2 + .../ipfs-cli/src/commands/pubsub/peers.js | 4 +- packages/ipfs-cli/src/commands/pubsub/pub.js | 2 + packages/ipfs-cli/src/commands/pubsub/sub.js | 8 +- packages/ipfs-cli/src/commands/refs-local.js | 2 + packages/ipfs-cli/src/commands/refs.js | 2 + packages/ipfs-cli/src/commands/repo/gc.js | 5 +- packages/ipfs-cli/src/commands/repo/stat.js | 2 + .../ipfs-cli/src/commands/repo/version.js | 2 + packages/ipfs-cli/src/commands/resolve.js | 2 + packages/ipfs-cli/src/commands/shutdown.js | 4 +- packages/ipfs-cli/src/commands/stats/bw.js | 2 + packages/ipfs-cli/src/commands/swarm/addrs.js | 2 + .../src/commands/swarm/addrs/local.js | 2 + .../ipfs-cli/src/commands/swarm/connect.js | 4 +- .../ipfs-cli/src/commands/swarm/disconnect.js | 4 +- packages/ipfs-cli/src/commands/swarm/peers.js | 8 +- packages/ipfs-cli/src/commands/version.js | 4 +- packages/ipfs-cli/src/index.js | 33 +--- packages/ipfs-cli/src/parser.js | 5 +- packages/ipfs-cli/src/types.ts | 2 +- packages/ipfs-cli/src/utils.js | 18 +- packages/ipfs-cli/test/add.spec.js | 2 +- packages/ipfs-cli/test/bitswap.spec.js | 2 +- packages/ipfs-cli/test/block.spec.js | 2 +- packages/ipfs-cli/test/bootstrap.spec.js | 4 +- packages/ipfs-cli/test/cat.spec.js | 2 +- packages/ipfs-cli/test/cid.spec.js | 2 +- packages/ipfs-cli/test/commands.spec.js | 2 +- packages/ipfs-cli/test/config.spec.js | 2 +- packages/ipfs-cli/test/daemon.spec.js | 2 +- packages/ipfs-cli/test/dag.spec.js | 2 +- packages/ipfs-cli/test/dht.spec.js | 2 +- packages/ipfs-cli/test/dns.spec.js | 2 +- packages/ipfs-cli/test/files/chmod.js | 2 +- packages/ipfs-cli/test/files/cp.js | 2 +- packages/ipfs-cli/test/files/flush.js | 2 +- packages/ipfs-cli/test/files/ls.js | 2 +- packages/ipfs-cli/test/files/mkdir.js | 2 +- packages/ipfs-cli/test/files/mv.js | 2 +- packages/ipfs-cli/test/files/read.js | 2 +- packages/ipfs-cli/test/files/rm.js | 2 +- packages/ipfs-cli/test/files/stat.js | 2 +- packages/ipfs-cli/test/files/touch.js | 2 +- packages/ipfs-cli/test/files/write.js | 2 +- packages/ipfs-cli/test/general.spec.js | 4 +- packages/ipfs-cli/test/get.spec.js | 2 +- packages/ipfs-cli/test/id.spec.js | 4 +- packages/ipfs-cli/test/init.spec.js | 13 +- packages/ipfs-cli/test/key.spec.js | 2 +- packages/ipfs-cli/test/ls.spec.js | 2 +- packages/ipfs-cli/test/name-pubsub.spec.js | 2 +- packages/ipfs-cli/test/name.spec.js | 2 +- packages/ipfs-cli/test/object.spec.js | 2 +- packages/ipfs-cli/test/pin.spec.js | 2 +- packages/ipfs-cli/test/ping.spec.js | 2 +- packages/ipfs-cli/test/progress-bar.spec.js | 2 +- packages/ipfs-cli/test/pubsub.spec.js | 2 +- packages/ipfs-cli/test/refs-local.spec.js | 2 +- packages/ipfs-cli/test/refs.spec.js | 2 +- packages/ipfs-cli/test/repo.spec.js | 2 +- packages/ipfs-cli/test/resolve.spec.js | 2 +- packages/ipfs-cli/test/swarm.spec.js | 4 +- packages/ipfs-cli/test/utils/ipfs-exec.js | 4 +- packages/ipfs-cli/test/version.spec.js | 2 +- .../ipfs-client/{.aegir.cjs => .aegir.js} | 3 +- packages/ipfs-client/package.json | 4 +- packages/ipfs-client/src/index.js | 2 +- .../{.aegir.cjs => .aegir.js} | 3 +- packages/ipfs-core-config/package.json | 28 +-- packages/ipfs-core-config/src/dns.browser.js | 2 +- .../src/libp2p-pubsub-routers.browser.js | 14 +- .../src/libp2p-pubsub-routers.js | 21 ++- .../ipfs-core-config/src/libp2p.browser.js | 75 ++------ packages/ipfs-core-config/src/libp2p.js | 79 ++------ .../ipfs-core-config/src/preload.browser.js | 8 +- packages/ipfs-core-config/src/preload.js | 8 +- packages/ipfs-core-config/src/utils/ipns.js | 17 -- .../src/utils/lru-datastore.js | 2 - packages/ipfs-core-config/src/utils/tlru.js | 2 - packages/ipfs-core-types/package.json | 6 +- packages/ipfs-core-types/src/bitswap/index.ts | 3 +- .../ipfs-core-types/src/bootstrap/index.ts | 2 +- packages/ipfs-core-types/src/dht/index.ts | 107 +---------- packages/ipfs-core-types/src/key/index.ts | 5 +- packages/ipfs-core-types/src/name/index.ts | 3 +- .../ipfs-core-types/src/pin/remote/index.ts | 2 +- packages/ipfs-core-types/src/pubsub/index.ts | 18 +- packages/ipfs-core-types/src/root.ts | 9 +- packages/ipfs-core-types/src/swarm/index.ts | 11 +- .../ipfs-core-utils/{.aegir.cjs => .aegir.js} | 3 +- packages/ipfs-core-utils/package.json | 10 +- .../src/files/normalise-candidate-multiple.js | 12 +- .../src/files/normalise-candidate-single.js | 6 +- .../ipfs-core-utils/src/multipart-request.js | 2 +- .../src/multipart-request.node.js | 6 +- .../src/pins/normalise-input.js | 12 +- packages/ipfs-core-utils/src/to-url-string.js | 2 +- .../src/with-timeout-option.js | 8 +- .../test/files/format-mode.spec.js | 2 +- .../test/files/format-mtime.spec.js | 2 +- .../files/normalise-input-multiple.spec.js | 4 +- .../test/files/normalise-input-single.spec.js | 4 +- .../test/pins/normalise-input.spec.js | 2 +- packages/ipfs-core/{.aegir.cjs => .aegir.js} | 13 +- packages/ipfs-core/package.json | 60 +++--- packages/ipfs-core/src/block-storage.js | 2 +- .../ipfs-core/src/components/add-all/index.js | 25 ++- .../ipfs-core/src/components/add-all/utils.js | 6 +- packages/ipfs-core/src/components/add.js | 4 +- .../ipfs-core/src/components/bitswap/index.js | 4 +- .../ipfs-core/src/components/bitswap/stat.js | 4 +- .../src/components/bitswap/unwant.js | 2 +- .../components/bitswap/wantlist-for-peer.js | 5 +- .../src/components/bitswap/wantlist.js | 2 +- .../ipfs-core/src/components/block/get.js | 2 +- .../ipfs-core/src/components/block/index.js | 2 +- .../ipfs-core/src/components/block/put.js | 2 +- packages/ipfs-core/src/components/block/rm.js | 2 +- .../ipfs-core/src/components/block/stat.js | 2 +- .../ipfs-core/src/components/bootstrap/add.js | 5 +- .../src/components/bootstrap/clear.js | 6 +- .../src/components/bootstrap/index.js | 2 +- .../src/components/bootstrap/list.js | 4 +- .../src/components/bootstrap/reset.js | 6 +- .../ipfs-core/src/components/bootstrap/rm.js | 4 +- packages/ipfs-core/src/components/cat.js | 2 +- .../ipfs-core/src/components/config/index.js | 11 +- .../ipfs-core/src/components/dag/export.js | 6 +- packages/ipfs-core/src/components/dag/get.js | 4 +- .../ipfs-core/src/components/dag/import.js | 12 +- .../ipfs-core/src/components/dag/index.js | 2 +- packages/ipfs-core/src/components/dag/put.js | 2 +- .../ipfs-core/src/components/dag/resolve.js | 2 +- packages/ipfs-core/src/components/dht.js | 152 +++++----------- .../ipfs-core/src/components/files/chmod.js | 9 +- packages/ipfs-core/src/components/files/cp.js | 6 +- .../ipfs-core/src/components/files/index.js | 2 - .../ipfs-core/src/components/files/mkdir.js | 4 +- .../ipfs-core/src/components/files/stat.js | 4 +- .../ipfs-core/src/components/files/touch.js | 7 +- .../src/components/files/utils/add-link.js | 4 +- .../src/components/files/utils/create-lock.js | 2 - .../src/components/files/utils/create-node.js | 1 - .../src/components/files/utils/hamt-utils.js | 6 +- .../src/components/files/utils/remove-link.js | 5 +- .../files/utils/to-async-iterator.js | 8 +- .../src/components/files/utils/to-mfs-path.js | 6 +- .../src/components/files/utils/to-trail.js | 4 +- .../components/files/utils/update-mfs-root.js | 4 +- .../src/components/files/utils/update-tree.js | 6 +- .../components/files/utils/with-mfs-root.js | 4 +- .../ipfs-core/src/components/files/write.js | 10 +- packages/ipfs-core/src/components/get.js | 6 +- packages/ipfs-core/src/components/id.js | 47 ++--- packages/ipfs-core/src/components/index.js | 16 +- packages/ipfs-core/src/components/ipns.js | 47 ++--- .../ipfs-core/src/components/is-online.js | 2 +- .../ipfs-core/src/components/key/export.js | 4 +- packages/ipfs-core/src/components/key/gen.js | 6 +- .../ipfs-core/src/components/key/import.js | 4 +- .../ipfs-core/src/components/key/index.js | 4 +- packages/ipfs-core/src/components/key/info.js | 4 +- packages/ipfs-core/src/components/key/list.js | 4 +- .../ipfs-core/src/components/key/rename.js | 4 +- packages/ipfs-core/src/components/key/rm.js | 4 +- packages/ipfs-core/src/components/libp2p.js | 172 +++++++++--------- packages/ipfs-core/src/components/ls.js | 2 +- .../ipfs-core/src/components/name/index.js | 8 +- .../ipfs-core/src/components/name/publish.js | 41 +++-- .../src/components/name/pubsub/cancel.js | 2 +- .../src/components/name/pubsub/index.js | 2 +- .../src/components/name/pubsub/state.js | 2 +- .../src/components/name/pubsub/subs.js | 2 +- .../ipfs-core/src/components/name/resolve.js | 26 +-- .../ipfs-core/src/components/name/utils.js | 2 +- packages/ipfs-core/src/components/network.js | 20 +- .../ipfs-core/src/components/object/data.js | 2 +- .../ipfs-core/src/components/object/get.js | 2 +- .../ipfs-core/src/components/object/index.js | 2 +- .../ipfs-core/src/components/object/links.js | 2 +- .../ipfs-core/src/components/object/new.js | 2 +- .../src/components/object/patch/add-link.js | 2 +- .../components/object/patch/append-data.js | 2 +- .../src/components/object/patch/index.js | 2 +- .../src/components/object/patch/rm-link.js | 2 +- .../src/components/object/patch/set-data.js | 2 +- .../ipfs-core/src/components/object/put.js | 2 +- .../ipfs-core/src/components/object/stat.js | 2 +- .../ipfs-core/src/components/pin/add-all.js | 2 +- packages/ipfs-core/src/components/pin/add.js | 4 +- .../ipfs-core/src/components/pin/index.js | 4 +- packages/ipfs-core/src/components/pin/ls.js | 4 +- .../ipfs-core/src/components/pin/rm-all.js | 2 +- packages/ipfs-core/src/components/pin/rm.js | 4 +- packages/ipfs-core/src/components/ping.js | 19 +- packages/ipfs-core/src/components/pubsub.js | 78 +++++++- .../ipfs-core/src/components/refs/index.js | 2 +- .../ipfs-core/src/components/refs/local.js | 2 +- packages/ipfs-core/src/components/repo/gc.js | 6 +- .../ipfs-core/src/components/repo/index.js | 2 +- .../ipfs-core/src/components/repo/stat.js | 2 +- .../ipfs-core/src/components/repo/version.js | 4 +- packages/ipfs-core/src/components/resolve.js | 6 +- packages/ipfs-core/src/components/start.js | 6 +- packages/ipfs-core/src/components/stats/bw.js | 25 +-- .../ipfs-core/src/components/stats/index.js | 2 +- packages/ipfs-core/src/components/stop.js | 2 +- packages/ipfs-core/src/components/storage.js | 52 ++++-- .../ipfs-core/src/components/swarm/addrs.js | 15 +- .../ipfs-core/src/components/swarm/connect.js | 6 +- .../src/components/swarm/disconnect.js | 2 +- .../ipfs-core/src/components/swarm/index.js | 2 +- .../src/components/swarm/local-addrs.js | 4 +- .../ipfs-core/src/components/swarm/peers.js | 34 +++- packages/ipfs-core/src/components/version.js | 2 +- packages/ipfs-core/src/index.js | 8 - packages/ipfs-core/src/ipns/index.js | 29 ++- packages/ipfs-core/src/ipns/publisher.js | 104 +++++------ packages/ipfs-core/src/ipns/republisher.js | 48 +++-- packages/ipfs-core/src/ipns/resolver.js | 46 +++-- packages/ipfs-core/src/ipns/routing/config.js | 15 +- .../src/ipns/routing/dht-datastore.js | 8 +- .../src/ipns/routing/offline-datastore.js | 22 +-- .../src/ipns/routing/pubsub-datastore.js | 40 ++-- packages/ipfs-core/src/mfs-preload.js | 11 +- packages/ipfs-core/src/preload.js | 9 +- packages/ipfs-core/src/types.ts | 7 +- packages/ipfs-core/src/utils.js | 2 +- packages/ipfs-core/src/utils/service.js | 2 +- packages/ipfs-core/src/utils/tlru.js | 2 - packages/ipfs-core/src/version.js | 4 +- packages/ipfs-core/test/add-all.spec.js | 2 +- packages/ipfs-core/test/block-storage.spec.js | 4 +- packages/ipfs-core/test/config.spec.js | 4 +- packages/ipfs-core/test/create-node.spec.js | 25 +-- packages/ipfs-core/test/exports.spec.js | 19 -- packages/ipfs-core/test/init.spec.js | 20 +- packages/ipfs-core/test/ipld.spec.js | 2 +- packages/ipfs-core/test/key-exchange.spec.js | 2 +- packages/ipfs-core/test/libp2p.spec.js | 71 ++++---- packages/ipfs-core/test/mfs-preload.spec.js | 4 +- packages/ipfs-core/test/name.spec.js | 37 ++-- packages/ipfs-core/test/preload.spec.js | 2 +- packages/ipfs-core/test/pubsub.spec.js | 2 +- packages/ipfs-core/test/utils.spec.js | 2 +- .../ipfs-core/test/utils/mock-preload-node.js | 2 +- packages/ipfs-daemon/package.json | 14 +- packages/ipfs-daemon/src/index.js | 21 ++- packages/ipfs-daemon/test/index.spec.js | 2 +- .../{.aegir.cjs => .aegir.js} | 3 +- packages/ipfs-grpc-client/package.json | 16 +- packages/ipfs-grpc-client/src/core-api/id.js | 2 +- .../src/core-api/pubsub/subscribe.js | 18 +- .../src/core-api/pubsub/subscriptions.js | 3 +- .../src/grpc/transport.node.js | 4 +- packages/ipfs-grpc-client/src/index.js | 6 - packages/ipfs-grpc-client/src/types.ts | 2 +- .../src/utils/bidi-to-duplex.js | 2 +- .../src/utils/load-services.js | 9 +- packages/ipfs-grpc-client/test/utils.spec.js | 2 +- packages/ipfs-grpc-protocol/package.json | 4 +- packages/ipfs-grpc-protocol/src/index.js | 5 +- packages/ipfs-grpc-protocol/src/pubsub.proto | 4 +- packages/ipfs-grpc-server/package.json | 16 +- .../ipfs-grpc-server/src/endpoints/add.js | 2 +- .../src/endpoints/pubsub/subscribe.js | 6 +- .../src/endpoints/pubsub/subscriptions.js | 4 +- packages/ipfs-grpc-server/src/index.js | 28 ++- packages/ipfs-grpc-server/src/types.ts | 2 +- .../src/utils/load-services.js | 8 +- .../src/utils/web-socket-message-channel.js | 2 +- .../src/utils/web-socket-server.js | 12 +- packages/ipfs-grpc-server/test/add.spec.js | 2 +- packages/ipfs-grpc-server/test/id.spec.js | 2 +- packages/ipfs-grpc-server/test/mfs/ls.spec.js | 2 +- .../ipfs-grpc-server/test/mfs/write.spec.js | 2 +- .../ipfs-grpc-server/test/utils/channel.js | 2 +- .../{.aegir.cjs => .aegir.js} | 10 +- packages/ipfs-http-client/package.json | 10 +- packages/ipfs-http-client/src/add-all.js | 1 - packages/ipfs-http-client/src/add.js | 2 +- .../ipfs-http-client/src/bootstrap/add.js | 2 +- .../ipfs-http-client/src/bootstrap/clear.js | 2 +- .../ipfs-http-client/src/bootstrap/list.js | 2 +- .../ipfs-http-client/src/bootstrap/reset.js | 2 +- packages/ipfs-http-client/src/bootstrap/rm.js | 2 +- packages/ipfs-http-client/src/dag/get.js | 2 +- .../ipfs-http-client/src/dht/map-event.js | 47 +++-- packages/ipfs-http-client/src/id.js | 7 +- packages/ipfs-http-client/src/index.js | 2 +- packages/ipfs-http-client/src/key/gen.js | 4 +- packages/ipfs-http-client/src/key/import.js | 2 +- packages/ipfs-http-client/src/key/list.js | 1 - packages/ipfs-http-client/src/key/rename.js | 2 +- packages/ipfs-http-client/src/key/rm.js | 2 +- packages/ipfs-http-client/src/lib/core.js | 19 +- .../src/lib/http-rpc-wire-format.js | 8 +- packages/ipfs-http-client/src/name/publish.js | 2 +- .../src/name/pubsub/cancel.js | 2 +- .../ipfs-http-client/src/name/pubsub/state.js | 2 +- .../src/object/patch/add-link.js | 4 +- .../src/object/patch/rm-link.js | 2 +- packages/ipfs-http-client/src/pin/add.js | 2 +- .../src/pin/remote/service/ls.js | 4 +- .../ipfs-http-client/src/pin/remote/utils.js | 2 +- packages/ipfs-http-client/src/pin/rm.js | 2 +- .../ipfs-http-client/src/pubsub/subscribe.js | 27 ++- .../src/pubsub/subscription-tracker.js | 5 +- packages/ipfs-http-client/src/swarm/addrs.js | 5 +- .../ipfs-http-client/src/swarm/local-addrs.js | 2 +- packages/ipfs-http-client/src/swarm/peers.js | 5 +- packages/ipfs-http-client/src/types.ts | 2 +- .../ipfs-http-client/test/commands.spec.js | 2 +- .../ipfs-http-client/test/constructor.spec.js | 4 +- packages/ipfs-http-client/test/dag.spec.js | 2 +- packages/ipfs-http-client/test/diag.spec.js | 2 +- .../test/endpoint-config.spec.js | 2 +- .../ipfs-http-client/test/exports.spec.js | 4 +- packages/ipfs-http-client/test/files.spec.js | 2 +- packages/ipfs-http-client/test/key.spec.js | 2 +- .../test/lib.error-handler.spec.js | 2 +- packages/ipfs-http-client/test/log.spec.js | 2 +- packages/ipfs-http-client/test/node/agent.js | 2 +- .../test/node/custom-headers.js | 2 +- .../ipfs-http-client/test/node/request-api.js | 2 +- packages/ipfs-http-client/test/node/swarm.js | 2 +- packages/ipfs-http-client/test/ping.spec.js | 2 +- packages/ipfs-http-client/test/pubsub.spec.js | 2 +- packages/ipfs-http-client/test/repo.spec.js | 2 +- packages/ipfs-http-client/test/stats.spec.js | 2 +- packages/ipfs-http-gateway/package.json | 11 +- packages/ipfs-http-gateway/src/index.js | 27 ++- .../src/resources/gateway.js | 6 +- packages/ipfs-http-gateway/src/types.ts | 2 +- .../ipfs-http-gateway/test/routes.spec.js | 2 +- packages/ipfs-http-response/package.json | 9 +- packages/ipfs-http-response/src/index.js | 8 +- .../src/utils/content-type.js | 47 +++-- .../ipfs-http-response/test/index.spec.js | 4 +- .../ipfs-http-response/test/resolver.spec.js | 4 +- packages/ipfs-http-server/package.json | 17 +- .../src/api/resources/config.js | 7 +- .../ipfs-http-server/src/api/resources/dag.js | 9 - .../ipfs-http-server/src/api/resources/dht.js | 6 +- .../src/api/resources/files-regular.js | 6 - .../ipfs-http-server/src/api/resources/id.js | 2 +- .../src/api/resources/object.js | 6 +- .../src/api/resources/pubsub.js | 14 +- .../src/api/resources/shutdown.js | 1 - .../ipfs-http-server/src/api/routes/debug.js | 6 +- packages/ipfs-http-server/src/index.js | 31 +++- packages/ipfs-http-server/src/types.ts | 2 +- packages/ipfs-http-server/src/utils/joi.js | 4 +- .../src/utils/multipart-request-parser.js | 2 +- .../src/utils/stream-response.js | 4 +- packages/ipfs-http-server/src/version.js | 2 +- packages/ipfs-http-server/test/cors.js | 2 +- .../ipfs-http-server/test/inject/bitswap.js | 2 +- .../ipfs-http-server/test/inject/block.js | 2 +- .../ipfs-http-server/test/inject/bootstrap.js | 2 +- .../test/inject/browser-headers.js | 2 +- .../ipfs-http-server/test/inject/config.js | 2 +- packages/ipfs-http-server/test/inject/dag.js | 2 +- packages/ipfs-http-server/test/inject/dht.js | 2 +- packages/ipfs-http-server/test/inject/dns.js | 2 +- .../ipfs-http-server/test/inject/files.js | 2 +- packages/ipfs-http-server/test/inject/id.js | 2 +- packages/ipfs-http-server/test/inject/key.js | 2 +- .../ipfs-http-server/test/inject/mfs/chmod.js | 2 +- .../ipfs-http-server/test/inject/mfs/cp.js | 2 +- .../ipfs-http-server/test/inject/mfs/flush.js | 2 +- .../ipfs-http-server/test/inject/mfs/ls.js | 2 +- .../ipfs-http-server/test/inject/mfs/mkdir.js | 2 +- .../ipfs-http-server/test/inject/mfs/mv.js | 2 +- .../ipfs-http-server/test/inject/mfs/read.js | 2 +- .../ipfs-http-server/test/inject/mfs/rm.js | 2 +- .../ipfs-http-server/test/inject/mfs/stat.js | 2 +- .../ipfs-http-server/test/inject/mfs/touch.js | 2 +- .../ipfs-http-server/test/inject/mfs/write.js | 2 +- packages/ipfs-http-server/test/inject/name.js | 2 +- .../ipfs-http-server/test/inject/object.js | 2 +- packages/ipfs-http-server/test/inject/pin.js | 2 +- packages/ipfs-http-server/test/inject/ping.js | 2 +- .../ipfs-http-server/test/inject/pubsub.js | 2 +- packages/ipfs-http-server/test/inject/repo.js | 2 +- .../ipfs-http-server/test/inject/resolve.js | 2 +- .../ipfs-http-server/test/inject/stats.js | 2 +- .../ipfs-http-server/test/inject/swarm.js | 2 +- .../ipfs-http-server/test/inject/version.js | 2 +- .../test/utils/test-http-method.js | 2 +- .../{.aegir.cjs => .aegir.js} | 11 +- .../ipfs-message-port-client/package.json | 4 +- .../ipfs-message-port-client/src/block.js | 3 +- .../ipfs-message-port-client/src/client.js | 1 + .../src/client/query.js | 4 +- .../src/client/service.js | 2 +- packages/ipfs-message-port-client/src/core.js | 2 - .../{.aegir.cjs => .aegir.js} | 3 +- .../ipfs-message-port-protocol/package.json | 4 +- .../ipfs-message-port-protocol/src/block.js | 2 +- .../ipfs-message-port-protocol/src/cid.js | 7 +- .../ipfs-message-port-protocol/src/core.js | 10 +- .../ipfs-message-port-protocol/src/dag.js | 2 +- .../ipfs-message-port-protocol/src/error.js | 4 +- .../test/block.browser.js | 2 +- .../test/cid.browser.js | 2 +- .../test/cid.spec.js | 2 +- .../test/core.browser.js | 2 +- .../test/dag.browser.js | 2 +- .../test/dag.spec.js | 2 +- .../{.aegir.cjs => .aegir.js} | 3 +- .../ipfs-message-port-server/package.json | 4 +- .../ipfs-message-port-server/src/block.js | 16 +- packages/ipfs-message-port-server/src/core.js | 8 +- packages/ipfs-message-port-server/src/dag.js | 10 +- .../ipfs-message-port-server/src/files.js | 2 +- .../ipfs-message-port-server/src/server.js | 6 +- .../test/basic.spec.js | 2 +- packages/ipfs/{.aegir.cjs => .aegir.js} | 21 ++- packages/ipfs/package.json | 17 +- packages/ipfs/src/cli.js | 14 +- packages/ipfs/src/index.js | 10 - packages/ipfs/src/package.js | 2 +- packages/ipfs/test/utils/factory.js | 3 - .../ipfs/test/utils/mock-pinning-service.js | 4 +- packages/ipfs/test/utils/mock-preload-node.js | 6 +- 627 files changed, 2394 insertions(+), 2437 deletions(-) rename packages/interface-ipfs-core/{.aegir.cjs => .aegir.js} (73%) rename packages/ipfs-client/{.aegir.cjs => .aegir.js} (73%) rename packages/ipfs-core-config/{.aegir.cjs => .aegir.js} (73%) delete mode 100644 packages/ipfs-core-config/src/utils/ipns.js rename packages/ipfs-core-utils/{.aegir.cjs => .aegir.js} (73%) rename packages/ipfs-core/{.aegir.cjs => .aegir.js} (84%) delete mode 100644 packages/ipfs-core/test/exports.spec.js rename packages/ipfs-grpc-client/{.aegir.cjs => .aegir.js} (73%) rename packages/ipfs-http-client/{.aegir.cjs => .aegir.js} (77%) rename packages/ipfs-message-port-client/{.aegir.cjs => .aegir.js} (87%) rename packages/ipfs-message-port-protocol/{.aegir.cjs => .aegir.js} (73%) rename packages/ipfs-message-port-server/{.aegir.cjs => .aegir.js} (73%) rename packages/ipfs/{.aegir.cjs => .aegir.js} (88%) diff --git a/docs/FAQ.md b/docs/FAQ.md index 8bc4ed9d07..c7b314cb5d 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -74,7 +74,7 @@ To add WebRTC support in a IPFS node instance, do: ```JavaScript import wrtc from 'wrtc' // or 'electron-webrtc' -import WebRTCStar from 'libp2p-webrtc-star' +import WebRTCStar from '@libp2p/webrtc-star' const node = await IPFS.create({ repo: 'your-repo-path', diff --git a/docs/MIGRATION-TO-ASYNC-AWAIT.md b/docs/MIGRATION-TO-ASYNC-AWAIT.md index 56fc4f6168..a30b3d8af3 100644 --- a/docs/MIGRATION-TO-ASYNC-AWAIT.md +++ b/docs/MIGRATION-TO-ASYNC-AWAIT.md @@ -100,7 +100,7 @@ const peerId = PeerId.createFromB58String(peerIdStr) You can get hold of the `PeerId` class using npm or in a script tag: ```js -import PeerId from 'peer-id' +import { PeerId } from '@libp2p/interfaces/peer-id' const peerId = PeerId.createFromB58String(peerIdStr) ``` @@ -128,7 +128,7 @@ You can get hold of the `PeerInfo` class using npm or in a script tag: ```js const PeerInfo = require('peer-info') -import PeerId from 'peer-id' +import { PeerId } from '@libp2p/interfaces/peer-id' const peerInfo = new PeerInfo(PeerId.createFromB58String(info.id)) info.addrs.forEach(addr => peerInfo.multiaddrs.add(addr)) ``` diff --git a/docs/MODULE.md b/docs/MODULE.md index 607432acae..12681bfd99 100644 --- a/docs/MODULE.md +++ b/docs/MODULE.md @@ -102,7 +102,7 @@ Instead of a boolean, you may provide an object with custom initialization optio - `privateKey` (string/PeerId) A pre-generated private key to use. Can be either a base64 string or a [PeerId](https://github.com/libp2p/js-peer-id) instance. **NOTE: This overrides `bits`.** ```js // Generating a Peer ID: - import PeerId from 'peer-id' + import { PeerId } from '@libp2p/interfaces/peer-id' // Generates a new Peer ID, complete with public/private keypair // See https://github.com/libp2p/js-peer-id const peerId = await PeerId.create({ bits: 2048 }) diff --git a/docs/core-api/PUBSUB.md b/docs/core-api/PUBSUB.md index d221b96dee..36b3ff2649 100644 --- a/docs/core-api/PUBSUB.md +++ b/docs/core-api/PUBSUB.md @@ -32,7 +32,7 @@ | Name | Type | Description | | ---- | ---- | ----------- | | topic | `String` | The topic name | -| handler | `Function<(msg) => {}>` | Event handler which will be called with a message object everytime one is received. The `msg` has the format `{from: String, seqno: Uint8Array, data: Uint8Array, topicIDs: Array}` | +| handler | `Function<(msg) => {}>` | Event handler which will be called with a message object everytime one is received. The `msg` has the format `{from: String, sequenceNumber: bigint, data: Uint8Array, topicIDs: Array}` | ### Options diff --git a/package-list.json b/package-list.json index e67150451c..e5ba50b9ef 100644 --- a/package-list.json +++ b/package-list.json @@ -53,6 +53,6 @@ "Multiformats", ["multiformats/js-multiformats", "multiformats"], ["multiformats/js-mafmt", "mafmt"], - ["multiformats/js-multiaddr", "multiaddr"] + ["multiformats/js-multiaddr", "@multiformats/multiaddr"] ] } diff --git a/packages/interface-ipfs-core/.aegir.cjs b/packages/interface-ipfs-core/.aegir.js similarity index 73% rename from packages/interface-ipfs-core/.aegir.cjs rename to packages/interface-ipfs-core/.aegir.js index 5f45288dba..3983541128 100644 --- a/packages/interface-ipfs-core/.aegir.cjs +++ b/packages/interface-ipfs-core/.aegir.js @@ -1,7 +1,6 @@ -'use strict' /** @type {import('aegir').PartialOptions} */ -module.exports = { +export default { build: { bundlesizeMax: '338kB' } diff --git a/packages/interface-ipfs-core/package.json b/packages/interface-ipfs-core/package.json index cc9a9eb387..2f1709c9b7 100644 --- a/packages/interface-ipfs-core/package.json +++ b/packages/interface-ipfs-core/package.json @@ -47,8 +47,8 @@ }, "scripts": { "clean": "rimraf ./dist", - "build": "aegir build && copyfiles './test/fixtures/**/*' ./dist/cjs && copyfiles './test/fixtures/**/*' ./dist/esm", - "lint": "aegir ts -p check && aegir lint", + "build": "aegir build && copyfiles './test/fixtures/**/*' ./dist", + "lint": "aegir lint", "dep-check": "aegir dep-check -i ipfs-core-types -i rimraf -i copyfiles" }, "repository": { @@ -60,12 +60,15 @@ ], "license": "MIT", "dependencies": { - "@ipld/car": "^3.1.6", + "@ipld/car": "^4.0.0", "@ipld/dag-cbor": "^7.0.0", "@ipld/dag-pb": "^2.1.3", + "@libp2p/crypto": "^0.22.9", + "@libp2p/websockets": "^1.0.3", + "@multiformats/multiaddr": "^10.0.0", "@types/pako": "^1.0.2", "@types/readable-stream": "^2.3.11", - "aegir": "^36.0.1", + "aegir": "^37.0.11", "blockstore-core": "^1.0.2", "copyfiles": "^2.4.1", "dag-jose": "^1.0.0", @@ -76,7 +79,7 @@ "ipfs-unixfs": "^6.0.3", "ipfs-unixfs-importer": "^9.0.3", "ipfs-utils": "^9.0.2", - "ipns": "^0.16.0", + "ipns": "^1.0.0", "is-ipfs": "^6.0.1", "iso-random-stream": "^2.0.2", "it-all": "^1.0.4", @@ -86,22 +89,18 @@ "it-first": "^1.0.4", "it-last": "^1.0.4", "it-map": "^1.0.4", - "it-pipe": "^1.1.0", - "it-pushable": "^1.4.2", - "it-tar": "^4.0.0", + "it-pipe": "^2.0.3", + "it-pushable": "^2.0.1", + "it-tar": "^5.0.0", "it-to-buffer": "^2.0.0", - "libp2p-crypto": "^0.21.1", - "libp2p-websockets": "^0.16.2", "merge-options": "^3.0.4", - "multiaddr": "^10.0.0", "multiformats": "^9.5.1", "nanoid": "^3.1.23", - "p-map": "^4.0.0", - "p-retry": "^4.5.0", - "pako": "^1.0.2", - "peer-id": "^0.16.0", + "p-map": "^5.3.0", + "p-retry": "^5.1.0", + "pako": "^2.0.4", "readable-stream": "^3.4.0", - "sinon": "^12.0.01", + "sinon": "^13.0.1", "uint8arrays": "^3.0.0" }, "devDependencies": { diff --git a/packages/interface-ipfs-core/src/add-all.js b/packages/interface-ipfs-core/src/add-all.js index fdb9d5dbff..b56c5d1445 100644 --- a/packages/interface-ipfs-core/src/add-all.js +++ b/packages/interface-ipfs-core/src/add-all.js @@ -8,13 +8,13 @@ import drain from 'it-drain' import { supportsFileReader } from 'ipfs-utils/src/supports.js' import globSource from 'ipfs-utils/src/files/glob-source.js' import { isNode } from 'ipfs-utils/src/env.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from './utils/mocha.js' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import bufferStream from 'it-buffer-stream' import * as raw from 'multiformats/codecs/raw' import * as dagPB from '@ipld/dag-pb' -import resolve from 'aegir/utils/resolve.js' +import resolve from 'aegir/resolve' import { sha256, sha512 } from 'multiformats/hashes/sha2' /** @@ -24,14 +24,14 @@ import { sha256, sha512 } from 'multiformats/hashes/sha2' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testAddAll (factory, options) { const describe = getDescribe(options) const it = getIt(options) describe('.addAll', function () { - this.timeout(120 * 1000) + this.timeout(360 * 1000) /** @type {import('ipfs-core-types').IPFS} */ let ipfs @@ -76,7 +76,7 @@ export function testAddAll (factory, options) { it('should add a File as array of tuples', async function () { if (!supportsFileReader) { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha return this.skip('skip in node') } @@ -102,7 +102,7 @@ export function testAddAll (factory, options) { it('should add array of objects with readable stream content', async function () { if (!isNode) { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.skip('Only node supports readable streams') } @@ -286,10 +286,10 @@ export function testAddAll (factory, options) { /** * @param {object} arg - * @param {string} arg.path + * @param {string} [arg.path] */ const toPath = ({ path }) => path - const nonSeqDirFilePaths = input.map(toPath).filter(p => p.includes('/a/')) + const nonSeqDirFilePaths = input.map(toPath).filter(p => p && p.includes('/a/')) const filesAddedPaths = filesAdded.map(toPath) expect(nonSeqDirFilePaths.every(p => filesAddedPaths.includes(p))).to.be.true() @@ -336,7 +336,7 @@ export function testAddAll (factory, options) { }) it('should add a directory with only-hash=true', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.slow(10 * 1000) const content = String(Math.random() + Date.now()) @@ -358,21 +358,21 @@ export function testAddAll (factory, options) { }) it('should add with mode as string', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.slow(10 * 1000) const mode = '0777' await testMode(mode, parseInt(mode, 8)) }) it('should add with mode as number', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.slow(10 * 1000) const mode = parseInt('0777', 8) await testMode(mode, mode) }) it('should add with mtime as Date', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.slow(10 * 1000) const mtime = new Date(5000) await testMtime(mtime, { @@ -382,7 +382,7 @@ export function testAddAll (factory, options) { }) it('should add with mtime as { nsecs, secs }', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.slow(10 * 1000) const mtime = { secs: 5, @@ -392,7 +392,7 @@ export function testAddAll (factory, options) { }) it('should add with mtime as timespec', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.slow(10 * 1000) await testMtime({ Seconds: 5, @@ -404,7 +404,7 @@ export function testAddAll (factory, options) { }) it('should add with mtime as hrtime', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.slow(10 * 1000) const mtime = process.hrtime() await testMtime(mtime, { @@ -414,7 +414,7 @@ export function testAddAll (factory, options) { }) it('should add a directory from the file system', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha if (!isNode) this.skip() const filesPath = resolve('test/fixtures/test-folder', 'interface-ipfs-core') @@ -423,7 +423,7 @@ export function testAddAll (factory, options) { }) it('should add a directory from the file system with an odd name', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha if (!isNode) this.skip() const filesPath = resolve('test/fixtures/weird name folder [v0]', 'interface-ipfs-core') @@ -433,7 +433,7 @@ export function testAddAll (factory, options) { }) it('should ignore a directory from the file system', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha if (!isNode) this.skip() const filesPath = resolve('test/fixtures/test-folder', 'interface-ipfs-core') @@ -443,7 +443,7 @@ export function testAddAll (factory, options) { }) it('should add a file from the file system', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha if (!isNode) this.skip() const filePath = resolve('test/fixtures/test-folder', 'interface-ipfs-core') @@ -454,7 +454,7 @@ export function testAddAll (factory, options) { }) it('should add a hidden file in a directory from the file system', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha if (!isNode) this.skip() const filesPath = resolve('test/fixtures', 'interface-ipfs-core') @@ -465,10 +465,10 @@ export function testAddAll (factory, options) { }) it('should add a file with only-hash=true', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha if (!isNode) this.skip() - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.slow(10 * 1000) const out = await all(ipfs.addAll([{ diff --git a/packages/interface-ipfs-core/src/add.js b/packages/interface-ipfs-core/src/add.js index 9ee887b120..cada9593a2 100644 --- a/packages/interface-ipfs-core/src/add.js +++ b/packages/interface-ipfs-core/src/add.js @@ -5,7 +5,7 @@ import { Readable } from 'readable-stream' import { supportsFileReader } from 'ipfs-utils/src/supports.js' import urlSource from 'ipfs-utils/src/files/url-source.js' import { isNode } from 'ipfs-utils/src/env.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from './utils/mocha.js' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import last from 'it-last' @@ -23,7 +23,7 @@ const redirectUrl = (/** @type {string} */ url) => `${process.env.ECHO_SERVER}/r /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testAdd (factory, options) { const describe = getDescribe(options) @@ -73,7 +73,7 @@ export function testAdd (factory, options) { it('should add a File', async function () { if (!supportsFileReader) { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha return this.skip('skip in node') } @@ -83,7 +83,7 @@ export function testAdd (factory, options) { it('should add a File as tuple', async function () { if (!supportsFileReader) { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha return this.skip('skip in node') } @@ -212,7 +212,7 @@ export function testAdd (factory, options) { it('should add readable stream', async function () { if (!isNode) { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.skip() } const expectedCid = 'QmVv4Wz46JaZJeH5PMV4LGbRiiMKEmszPYY3g6fjGnVXBS' @@ -264,7 +264,7 @@ export function testAdd (factory, options) { }) it('should add with only-hash=true', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.slow(10 * 1000) const content = String(Math.random() + Date.now()) @@ -292,21 +292,21 @@ export function testAdd (factory, options) { }) it('should add with mode as string', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.slow(10 * 1000) const mode = '0777' await testMode(mode, parseInt(mode, 8)) }) it('should add with mode as number', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.slow(10 * 1000) const mode = parseInt('0777', 8) await testMode(mode, mode) }) it('should add with mtime as Date', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.slow(10 * 1000) const mtime = new Date(5000) await testMtime(mtime, { @@ -316,7 +316,7 @@ export function testAdd (factory, options) { }) it('should add with mtime as { nsecs, secs }', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.slow(10 * 1000) const mtime = { secs: 5, @@ -326,7 +326,7 @@ export function testAdd (factory, options) { }) it('should add with mtime as timespec', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.slow(10 * 1000) await testMtime({ Seconds: 5, @@ -338,7 +338,7 @@ export function testAdd (factory, options) { }) it('should add with mtime as hrtime', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.slow(10 * 1000) const mtime = process.hrtime() await testMtime(mtime, { diff --git a/packages/interface-ipfs-core/src/bitswap/stat.js b/packages/interface-ipfs-core/src/bitswap/stat.js index ce05da7aca..e535c51d52 100644 --- a/packages/interface-ipfs-core/src/bitswap/stat.js +++ b/packages/interface-ipfs-core/src/bitswap/stat.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import { expectIsBitswap } from '../stats/utils.js' @@ -10,7 +10,7 @@ import { expectIsBitswap } from '../stats/utils.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testStat (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/bitswap/transfer.js b/packages/interface-ipfs-core/src/bitswap/transfer.js index de62f4de06..28808b097f 100644 --- a/packages/interface-ipfs-core/src/bitswap/transfer.js +++ b/packages/interface-ipfs-core/src/bitswap/transfer.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import { isWebWorker } from 'ipfs-utils/src/env.js' import { randomBytes } from 'iso-random-stream' @@ -8,7 +8,6 @@ import concat from 'it-concat' import { nanoid } from 'nanoid' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import pmap from 'p-map' -import { ipfsOptionsWebsocketsFilterAll } from '../utils/ipfs-options-websockets-filter-all.js' /** * @typedef {import('ipfsd-ctl').Factory} Factory @@ -17,10 +16,9 @@ import { ipfsOptionsWebsocketsFilterAll } from '../utils/ipfs-options-websockets /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testTransfer (factory, options) { - const ipfsOptions = ipfsOptionsWebsocketsFilterAll() const describe = getDescribe(options) const it = getIt(options) @@ -34,7 +32,7 @@ export function testTransfer (factory, options) { // webworkers are not dialable because webrtc is not available const remote = (await factory.spawn({ type: isWebWorker ? 'go' : undefined })).api const remoteId = await remote.id() - const local = (await factory.spawn({ type: 'proc', ipfsOptions })).api + const local = (await factory.spawn({ type: 'proc' })).api await local.swarm.connect(remoteId.addresses[0]) const data = uint8ArrayFromString(`IPFS is awesome ${nanoid()}`) @@ -50,7 +48,7 @@ export function testTransfer (factory, options) { const remote1Id = await remote1.id() const remote2 = (await factory.spawn({ type: isWebWorker ? 'go' : undefined })).api const remote2Id = await remote2.id() - const local = (await factory.spawn({ type: 'proc', ipfsOptions })).api + const local = (await factory.spawn({ type: 'proc' })).api await local.swarm.connect(remote1Id.addresses[0]) await local.swarm.connect(remote2Id.addresses[0]) await remote1.swarm.connect(remote2Id.addresses[0]) @@ -78,7 +76,7 @@ export function testTransfer (factory, options) { const content = randomBytes(1024) const remote = (await factory.spawn({ type: isWebWorker ? 'go' : undefined })).api const remoteId = await remote.id() - const local = (await factory.spawn({ type: 'proc', ipfsOptions })).api + const local = (await factory.spawn({ type: 'proc' })).api local.swarm.connect(remoteId.addresses[0]) const file = await remote.add({ path: 'awesome.txt', content }) diff --git a/packages/interface-ipfs-core/src/bitswap/unwant.js b/packages/interface-ipfs-core/src/bitswap/unwant.js index b1b4804bdf..31012856d4 100644 --- a/packages/interface-ipfs-core/src/bitswap/unwant.js +++ b/packages/interface-ipfs-core/src/bitswap/unwant.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' /** @@ -9,7 +9,7 @@ import { getDescribe, getIt } from '../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testUnwant (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/bitswap/utils.js b/packages/interface-ipfs-core/src/bitswap/utils.js index 7e3375795b..68957d217c 100644 --- a/packages/interface-ipfs-core/src/bitswap/utils.js +++ b/packages/interface-ipfs-core/src/bitswap/utils.js @@ -1,9 +1,13 @@ import delay from 'delay' +/** + * @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId + */ + /** * @param {import('ipfs-core-types').IPFS} ipfs * @param {string} key - * @param {{ timeout?: number, interval?: number, peerId?: string }} [opts] + * @param {{ timeout?: number, interval?: number, peerId?: PeerId }} [opts] */ export async function waitForWantlistKey (ipfs, key, opts = {}) { opts.timeout = opts.timeout || 10000 @@ -33,7 +37,7 @@ export async function waitForWantlistKey (ipfs, key, opts = {}) { /** * @param {import('ipfs-core-types').IPFS} ipfs * @param {string} key - * @param {{ timeout?: number, interval?: number, peerId?: string }} [opts] + * @param {{ timeout?: number, interval?: number, peerId?: PeerId }} [opts] */ export async function waitForWantlistKeyToBeRemoved (ipfs, key, opts = {}) { opts.timeout = opts.timeout || 10000 diff --git a/packages/interface-ipfs-core/src/bitswap/wantlist-for-peer.js b/packages/interface-ipfs-core/src/bitswap/wantlist-for-peer.js index 97445ae4f8..b8553190b0 100644 --- a/packages/interface-ipfs-core/src/bitswap/wantlist-for-peer.js +++ b/packages/interface-ipfs-core/src/bitswap/wantlist-for-peer.js @@ -3,7 +3,6 @@ import { getDescribe, getIt } from '../utils/mocha.js' import { waitForWantlistKey } from './utils.js' import { isWebWorker } from 'ipfs-utils/src/env.js' -import { ipfsOptionsWebsocketsFilterAll } from '../utils/ipfs-options-websockets-filter-all.js' import { CID } from 'multiformats/cid' /** @@ -12,10 +11,9 @@ import { CID } from 'multiformats/cid' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testWantlistForPeer (factory, options) { - const ipfsOptions = ipfsOptionsWebsocketsFilterAll() const describe = getDescribe(options) const it = getIt(options) @@ -29,7 +27,7 @@ export function testWantlistForPeer (factory, options) { const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR' before(async () => { - ipfsA = (await factory.spawn({ type: 'proc', ipfsOptions })).api + ipfsA = (await factory.spawn({ type: 'proc' })).api // webworkers are not dialable because webrtc is not available ipfsB = (await factory.spawn({ type: isWebWorker ? 'go' : undefined })).api // Add key to the wantlist for ipfsB diff --git a/packages/interface-ipfs-core/src/bitswap/wantlist.js b/packages/interface-ipfs-core/src/bitswap/wantlist.js index 0b810dce90..b2e3755596 100644 --- a/packages/interface-ipfs-core/src/bitswap/wantlist.js +++ b/packages/interface-ipfs-core/src/bitswap/wantlist.js @@ -1,13 +1,12 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import { waitForWantlistKey, waitForWantlistKeyToBeRemoved } from './utils.js' import { isWebWorker } from 'ipfs-utils/src/env.js' import testTimeout from '../utils/test-timeout.js' import { CID } from 'multiformats/cid' import delay from 'delay' -import { ipfsOptionsWebsocketsFilterAll } from '../utils/ipfs-options-websockets-filter-all.js' /** * @typedef {import('ipfsd-ctl').Factory} Factory @@ -15,10 +14,9 @@ import { ipfsOptionsWebsocketsFilterAll } from '../utils/ipfs-options-websockets /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testWantlist (factory, options) { - const ipfsOptions = ipfsOptionsWebsocketsFilterAll() const describe = getDescribe(options) const it = getIt(options) @@ -32,7 +30,7 @@ export function testWantlist (factory, options) { const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR' before(async () => { - ipfsA = (await factory.spawn({ type: 'proc', ipfsOptions })).api + ipfsA = (await factory.spawn({ type: 'proc' })).api // webworkers are not dialable because webrtc is not available ipfsB = (await factory.spawn({ type: isWebWorker ? 'go' : undefined })).api // Add key to the wantlist for ipfsB diff --git a/packages/interface-ipfs-core/src/block/get.js b/packages/interface-ipfs-core/src/block/get.js index a09fbf389f..815512f2e0 100644 --- a/packages/interface-ipfs-core/src/block/get.js +++ b/packages/interface-ipfs-core/src/block/get.js @@ -3,7 +3,7 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { identity } from 'multiformats/hashes/identity' import { CID } from 'multiformats/cid' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import testTimeout from '../utils/test-timeout.js' @@ -13,7 +13,7 @@ import testTimeout from '../utils/test-timeout.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testGet (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/block/put.js b/packages/interface-ipfs-core/src/block/put.js index f7bceb55ff..b39ee22d65 100644 --- a/packages/interface-ipfs-core/src/block/put.js +++ b/packages/interface-ipfs-core/src/block/put.js @@ -3,7 +3,7 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { base58btc } from 'multiformats/bases/base58' import { CID } from 'multiformats/cid' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import all from 'it-all' import * as raw from 'multiformats/codecs/raw' @@ -15,7 +15,7 @@ import { sha512 } from 'multiformats/hashes/sha2' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testPut (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/block/rm.js b/packages/interface-ipfs-core/src/block/rm.js index 15458d1bcd..5000da30ce 100644 --- a/packages/interface-ipfs-core/src/block/rm.js +++ b/packages/interface-ipfs-core/src/block/rm.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import { nanoid } from 'nanoid' import all from 'it-all' @@ -17,7 +17,7 @@ import testTimeout from '../utils/test-timeout.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testRm (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/block/stat.js b/packages/interface-ipfs-core/src/block/stat.js index 2d74d01a8b..7aa6706270 100644 --- a/packages/interface-ipfs-core/src/block/stat.js +++ b/packages/interface-ipfs-core/src/block/stat.js @@ -2,7 +2,7 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { CID } from 'multiformats/cid' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import testTimeout from '../utils/test-timeout.js' @@ -12,7 +12,7 @@ import testTimeout from '../utils/test-timeout.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testStat (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/bootstrap/add.js b/packages/interface-ipfs-core/src/bootstrap/add.js index bc7398d333..e7d26343a0 100644 --- a/packages/interface-ipfs-core/src/bootstrap/add.js +++ b/packages/interface-ipfs-core/src/bootstrap/add.js @@ -1,8 +1,8 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' -import { Multiaddr } from 'multiaddr' +import { Multiaddr } from '@multiformats/multiaddr' const invalidArg = 'this/Is/So/Invalid/' const validIp4 = new Multiaddr('/ip4/104.236.176.52/tcp/4001/p2p/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z') @@ -13,7 +13,7 @@ const validIp4 = new Multiaddr('/ip4/104.236.176.52/tcp/4001/p2p/QmSoLnSGccFuZQJ /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testAdd (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/bootstrap/clear.js b/packages/interface-ipfs-core/src/bootstrap/clear.js index 8ab21bbe13..bec9fe1d3b 100644 --- a/packages/interface-ipfs-core/src/bootstrap/clear.js +++ b/packages/interface-ipfs-core/src/bootstrap/clear.js @@ -1,8 +1,8 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' -import { Multiaddr } from 'multiaddr' +import { Multiaddr } from '@multiformats/multiaddr' /** * @typedef {import('ipfsd-ctl').Factory} Factory @@ -10,7 +10,7 @@ import { Multiaddr } from 'multiaddr' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testClear (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/bootstrap/list.js b/packages/interface-ipfs-core/src/bootstrap/list.js index 8b618c409d..b82abecde5 100644 --- a/packages/interface-ipfs-core/src/bootstrap/list.js +++ b/packages/interface-ipfs-core/src/bootstrap/list.js @@ -1,8 +1,8 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' -import { Multiaddr } from 'multiaddr' +import { Multiaddr } from '@multiformats/multiaddr' /** * @typedef {import('ipfsd-ctl').Factory} Factory @@ -10,7 +10,7 @@ import { Multiaddr } from 'multiaddr' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testList (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/bootstrap/reset.js b/packages/interface-ipfs-core/src/bootstrap/reset.js index 210349a7f8..d98f87dda8 100644 --- a/packages/interface-ipfs-core/src/bootstrap/reset.js +++ b/packages/interface-ipfs-core/src/bootstrap/reset.js @@ -1,8 +1,8 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' -import { Multiaddr } from 'multiaddr' +import { Multiaddr } from '@multiformats/multiaddr' /** * @typedef {import('ipfsd-ctl').Factory} Factory @@ -10,7 +10,7 @@ import { Multiaddr } from 'multiaddr' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testReset (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/bootstrap/rm.js b/packages/interface-ipfs-core/src/bootstrap/rm.js index 88f7171855..4768af9e66 100644 --- a/packages/interface-ipfs-core/src/bootstrap/rm.js +++ b/packages/interface-ipfs-core/src/bootstrap/rm.js @@ -1,8 +1,8 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' -import { Multiaddr } from 'multiaddr' +import { Multiaddr } from '@multiformats/multiaddr' /** * @typedef {import('ipfsd-ctl').Factory} Factory @@ -10,7 +10,7 @@ import { Multiaddr } from 'multiaddr' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testRm (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/cat.js b/packages/interface-ipfs-core/src/cat.js index fb3fb97082..50dbb786e4 100644 --- a/packages/interface-ipfs-core/src/cat.js +++ b/packages/interface-ipfs-core/src/cat.js @@ -7,7 +7,7 @@ import { fixtures } from './utils/index.js' import { CID } from 'multiformats/cid' import all from 'it-all' import drain from 'it-drain' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from './utils/mocha.js' import testTimeout from './utils/test-timeout.js' import { importer } from 'ipfs-unixfs-importer' @@ -19,7 +19,7 @@ import blockstore from './utils/blockstore-adapter.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testCat (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/config/get.js b/packages/interface-ipfs-core/src/config/get.js index 7cd966bb87..cc37f6cfd1 100644 --- a/packages/interface-ipfs-core/src/config/get.js +++ b/packages/interface-ipfs-core/src/config/get.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' /** @@ -9,7 +9,7 @@ import { getDescribe, getIt } from '../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testGet (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/config/profiles/apply.js b/packages/interface-ipfs-core/src/config/profiles/apply.js index 49173cb30f..c2c1e67d76 100644 --- a/packages/interface-ipfs-core/src/config/profiles/apply.js +++ b/packages/interface-ipfs-core/src/config/profiles/apply.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../../utils/mocha.js' /** @@ -9,7 +9,7 @@ import { getDescribe, getIt } from '../../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testApply (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/config/profiles/list.js b/packages/interface-ipfs-core/src/config/profiles/list.js index 8cb51b6212..750c228df9 100644 --- a/packages/interface-ipfs-core/src/config/profiles/list.js +++ b/packages/interface-ipfs-core/src/config/profiles/list.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../../utils/mocha.js' /** @@ -9,7 +9,7 @@ import { getDescribe, getIt } from '../../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testList (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/config/replace.js b/packages/interface-ipfs-core/src/config/replace.js index 0ab4965d2a..cbb96a5580 100644 --- a/packages/interface-ipfs-core/src/config/replace.js +++ b/packages/interface-ipfs-core/src/config/replace.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' /** @@ -9,7 +9,7 @@ import { getDescribe, getIt } from '../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testReplace (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/config/set.js b/packages/interface-ipfs-core/src/config/set.js index d7186ecffd..23436598b6 100644 --- a/packages/interface-ipfs-core/src/config/set.js +++ b/packages/interface-ipfs-core/src/config/set.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' /** @@ -10,7 +10,7 @@ import { getDescribe, getIt } from '../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testSet (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/dag/export.js b/packages/interface-ipfs-core/src/dag/export.js index a3a79d93c5..abd9ddd2dc 100644 --- a/packages/interface-ipfs-core/src/dag/export.js +++ b/packages/interface-ipfs-core/src/dag/export.js @@ -1,13 +1,13 @@ /* eslint-env mocha */ import all from 'it-all' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import { CarReader } from '@ipld/car' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import * as dagPB from '@ipld/dag-pb' import * as dagCBOR from '@ipld/dag-cbor' -import loadFixture from 'aegir/utils/fixtures.js' +import loadFixture from 'aegir/fixtures' import toBuffer from 'it-to-buffer' /** @@ -16,7 +16,7 @@ import toBuffer from 'it-to-buffer' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testExport (factory, options) { const describe = getDescribe(options) @@ -72,7 +72,7 @@ export function testExport (factory, options) { }) it('export of shuffled devnet export identical to canonical original', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(360000) const input = loadFixture('test/fixtures/car/lotus_devnet_genesis.car', 'interface-ipfs-core') @@ -83,7 +83,7 @@ export function testExport (factory, options) { }) it('export of shuffled testnet export identical to canonical original', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(360000) const input = loadFixture('test/fixtures/car/lotus_testnet_export_128.car', 'interface-ipfs-core') diff --git a/packages/interface-ipfs-core/src/dag/get.js b/packages/interface-ipfs-core/src/dag/get.js index 4bf02a56b3..2507baa480 100644 --- a/packages/interface-ipfs-core/src/dag/get.js +++ b/packages/interface-ipfs-core/src/dag/get.js @@ -11,7 +11,7 @@ import { CID } from 'multiformats/cid' import { sha256 } from 'multiformats/hashes/sha2' import { base32 } from 'multiformats/bases/base32' import { base64url } from 'multiformats/bases/base64' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import testTimeout from '../utils/test-timeout.js' import { identity } from 'multiformats/hashes/identity' @@ -24,7 +24,7 @@ import { ES256KSigner, createJWS } from 'did-jwt' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testGet (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/dag/import.js b/packages/interface-ipfs-core/src/dag/import.js index fc66c7b9d3..79eead2b34 100644 --- a/packages/interface-ipfs-core/src/dag/import.js +++ b/packages/interface-ipfs-core/src/dag/import.js @@ -4,12 +4,12 @@ import all from 'it-all' import drain from 'it-drain' import { CID } from 'multiformats/cid' import { sha256 } from 'multiformats/hashes/sha2' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import { CarWriter, CarReader } from '@ipld/car' import * as raw from 'multiformats/codecs/raw' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import loadFixture from 'aegir/utils/fixtures.js' +import loadFixture from 'aegir/fixtures' /** * @@ -55,7 +55,7 @@ async function createCar (blocks) { /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testImport (factory, options) { const describe = getDescribe(options) @@ -76,7 +76,7 @@ export function testImport (factory, options) { const result = await all(ipfs.dag.import(car)) expect(result).to.have.lengthOf(1) - // @ts-ignore chai types are messed up + // @ts-expect-error chai types are messed up expect(result).to.have.nested.deep.property('[0].root.cid', blocks[0].cid) for (const { cid } of blocks) { @@ -155,7 +155,7 @@ export function testImport (factory, options) { expect(cids[0].toString()).to.equal('bafkqaaa') const result = await all(ipfs.dag.import(async function * () { yield input }())) - // @ts-ignore chai types are messed up + // @ts-expect-error chai types are messed up expect(result).to.have.nested.deep.property('[0].root.cid', cids[0]) }) }) diff --git a/packages/interface-ipfs-core/src/dag/put.js b/packages/interface-ipfs-core/src/dag/put.js index 2f0564a442..230c0b0975 100644 --- a/packages/interface-ipfs-core/src/dag/put.js +++ b/packages/interface-ipfs-core/src/dag/put.js @@ -4,7 +4,7 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import * as dagCBOR from '@ipld/dag-cbor' import { CID } from 'multiformats/cid' import { sha256, sha512 } from 'multiformats/hashes/sha2' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' /** @@ -13,7 +13,7 @@ import { getDescribe, getIt } from '../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testPut (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/dag/resolve.js b/packages/interface-ipfs-core/src/dag/resolve.js index a45db89a1a..dd51b8e501 100644 --- a/packages/interface-ipfs-core/src/dag/resolve.js +++ b/packages/interface-ipfs-core/src/dag/resolve.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import * as dagPB from '@ipld/dag-pb' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import testTimeout from '../utils/test-timeout.js' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' @@ -12,7 +12,7 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testResolve (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/dag/sharness-t0053-dag.js b/packages/interface-ipfs-core/src/dag/sharness-t0053-dag.js index 53648ae216..190737600e 100644 --- a/packages/interface-ipfs-core/src/dag/sharness-t0053-dag.js +++ b/packages/interface-ipfs-core/src/dag/sharness-t0053-dag.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import { base64pad } from 'multiformats/bases/base64' import { base58btc } from 'multiformats/bases/base58' @@ -12,7 +12,7 @@ import { CID } from 'multiformats' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testDagSharnessT0053 (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/dht/disabled.js b/packages/interface-ipfs-core/src/dht/disabled.js index a099d24872..7611430e57 100644 --- a/packages/interface-ipfs-core/src/dht/disabled.js +++ b/packages/interface-ipfs-core/src/dht/disabled.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import all from 'it-all' @@ -10,7 +10,7 @@ import all from 'it-all' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testDisabled (factory, options) { const describe = getDescribe(options) @@ -42,9 +42,8 @@ export function testDisabled (factory, options) { after(() => factory.clean()) it('should error when DHT not available', async () => { - const events = await all(nodeA.dht.get('/ipns/12D3KooWQMSMXmsBvs5YDEQ6tXsaFv9tjuzmDmEvusaiQSFdrJdN')) - - expect(events.filter(event => event.name === 'QUERY_ERROR')).to.not.be.empty() + await expect(all(nodeA.dht.get('/ipns/12D3KooWQMSMXmsBvs5YDEQ6tXsaFv9tjuzmDmEvusaiQSFdrJdN'))) + .to.eventually.be.rejectedWith('not available') }) }) } diff --git a/packages/interface-ipfs-core/src/dht/find-peer.js b/packages/interface-ipfs-core/src/dht/find-peer.js index 3101a0348d..69708c76c4 100644 --- a/packages/interface-ipfs-core/src/dht/find-peer.js +++ b/packages/interface-ipfs-core/src/dht/find-peer.js @@ -1,11 +1,12 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import testTimeout from '../utils/test-timeout.js' import drain from 'it-drain' import all from 'it-all' import { ensureReachable } from './utils.js' +import { peerIdFromString } from '@libp2p/peer-id' /** * @typedef {import('ipfsd-ctl').Factory} Factory @@ -13,7 +14,7 @@ import { ensureReachable } from './utils.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testFindPeer (factory, options) { const describe = getDescribe(options) @@ -63,7 +64,7 @@ export function testFindPeer (factory, options) { }) it('should fail to find other peer if peer does not exist', async () => { - const events = await all(nodeA.dht.findPeer('Qmd7qZS4T7xXtsNFdRoK1trfMs5zU94EpokQ9WFtxdPxsZ')) + const events = await all(nodeA.dht.findPeer(peerIdFromString('Qmd7qZS4T7xXtsNFdRoK1trfMs5zU94EpokQ9WFtxdPxsZ'))) // no finalPeer events found expect(events.filter(event => event.name === 'FINAL_PEER')).to.be.empty() diff --git a/packages/interface-ipfs-core/src/dht/find-provs.js b/packages/interface-ipfs-core/src/dht/find-provs.js index 7554c7e98e..3f300b9a65 100644 --- a/packages/interface-ipfs-core/src/dht/find-provs.js +++ b/packages/interface-ipfs-core/src/dht/find-provs.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import all from 'it-all' import drain from 'it-drain' @@ -13,7 +13,7 @@ import { ensureReachable } from './utils.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testFindProvs (factory, options) { const describe = getDescribe(options) @@ -70,15 +70,15 @@ export function testFindProvs (factory, options) { for await (const event of nodeA.dht.findProvs(providedCid)) { if (event.name === 'PROVIDER') { - providerIds.push(...event.providers.map(prov => prov.id)) + providerIds.push(...event.providers.map(prov => prov.id.toString())) } } const nodeBId = await nodeB.id() const nodeCId = await nodeC.id() - expect(providerIds).to.include(nodeBId.id) - expect(providerIds).to.include(nodeCId.id) + expect(providerIds).to.include(nodeBId.id.toString()) + expect(providerIds).to.include(nodeCId.id.toString()) }) }) } diff --git a/packages/interface-ipfs-core/src/dht/get.js b/packages/interface-ipfs-core/src/dht/get.js index 0232d5f79c..301e6c5033 100644 --- a/packages/interface-ipfs-core/src/dht/get.js +++ b/packages/interface-ipfs-core/src/dht/get.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import testTimeout from '../utils/test-timeout.js' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' @@ -14,7 +14,7 @@ import { ensureReachable } from './utils.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testGet (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/dht/provide.js b/packages/interface-ipfs-core/src/dht/provide.js index ea4a6456b7..ca5f9ebdaf 100644 --- a/packages/interface-ipfs-core/src/dht/provide.js +++ b/packages/interface-ipfs-core/src/dht/provide.js @@ -3,7 +3,7 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { CID } from 'multiformats/cid' import all from 'it-all' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import { ensureReachable } from './utils.js' @@ -13,7 +13,7 @@ import { ensureReachable } from './utils.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testProvide (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/dht/put.js b/packages/interface-ipfs-core/src/dht/put.js index c66cf6a204..5933bdb2aa 100644 --- a/packages/interface-ipfs-core/src/dht/put.js +++ b/packages/interface-ipfs-core/src/dht/put.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import all from 'it-all' import { ensureReachable } from './utils.js' @@ -11,7 +11,7 @@ import { ensureReachable } from './utils.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testPut (factory, options) { const describe = getDescribe(options) @@ -60,7 +60,7 @@ export function testPut (factory, options) { const nodeBId = await nodeB.id() - expect(peerResponse.from).to.be.equal(nodeBId.id) + expect(peerResponse.from.toString()).to.be.equal(nodeBId.id.toString()) }) }) } diff --git a/packages/interface-ipfs-core/src/dht/query.js b/packages/interface-ipfs-core/src/dht/query.js index 103f18cacc..4636f5ad5a 100644 --- a/packages/interface-ipfs-core/src/dht/query.js +++ b/packages/interface-ipfs-core/src/dht/query.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import drain from 'it-drain' import testTimeout from '../utils/test-timeout.js' @@ -12,7 +12,7 @@ import { ensureReachable } from './utils.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testQuery (factory, options) { const describe = getDescribe(options) @@ -47,14 +47,13 @@ export function testQuery (factory, options) { /** @type {string[]} */ const peers = [] const nodeBId = await nodeB.id() - for await (const event of nodeA.dht.query(nodeBId.id)) { if (event.name === 'PEER_RESPONSE') { - peers.push(...event.closer.map(data => data.id)) + peers.push(...event.closer.map(data => data.id.toString())) } } - expect(peers).to.include(nodeBId.id) + expect(peers).to.include(nodeBId.id.toString()) }) }) } diff --git a/packages/interface-ipfs-core/src/dht/utils.js b/packages/interface-ipfs-core/src/dht/utils.js index ddff9e9884..540c39207d 100644 --- a/packages/interface-ipfs-core/src/dht/utils.js +++ b/packages/interface-ipfs-core/src/dht/utils.js @@ -27,7 +27,7 @@ export async function ensureReachable (nodeA, nodeB) { const { id } = await target.id() for await (const event of source.dht.query(id)) { - if (event.name === 'PEER_RESPONSE' && event.from === id) { + if (event.name === 'PEER_RESPONSE' && event.from.equals(id)) { return } } diff --git a/packages/interface-ipfs-core/src/files/chmod.js b/packages/interface-ipfs-core/src/files/chmod.js index 6418fe03b4..c4613a9696 100644 --- a/packages/interface-ipfs-core/src/files/chmod.js +++ b/packages/interface-ipfs-core/src/files/chmod.js @@ -2,7 +2,7 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { nanoid } from 'nanoid' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import isShardAtPath from '../utils/is-shard-at-path.js' @@ -12,7 +12,7 @@ import isShardAtPath from '../utils/is-shard-at-path.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testChmod (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/files/cp.js b/packages/interface-ipfs-core/src/files/cp.js index 101b16c1b6..4d9f0223b1 100644 --- a/packages/interface-ipfs-core/src/files/cp.js +++ b/packages/interface-ipfs-core/src/files/cp.js @@ -5,7 +5,7 @@ import { concat as uint8ArrayConcat } from 'uint8arrays/concat' import { nanoid } from 'nanoid' import all from 'it-all' import { fixtures } from '../utils/index.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import { identity } from 'multiformats/hashes/identity' import { CID } from 'multiformats/cid' @@ -19,7 +19,7 @@ import isShardAtPath from '../utils/is-shard-at-path.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testCp (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/files/flush.js b/packages/interface-ipfs-core/src/files/flush.js index bc91c46e41..ac8901ea27 100644 --- a/packages/interface-ipfs-core/src/files/flush.js +++ b/packages/interface-ipfs-core/src/files/flush.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { nanoid } from 'nanoid' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' /** @@ -10,7 +10,7 @@ import { getDescribe, getIt } from '../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testFlush (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/files/ls.js b/packages/interface-ipfs-core/src/files/ls.js index 8af8d2e791..0736b80140 100644 --- a/packages/interface-ipfs-core/src/files/ls.js +++ b/packages/interface-ipfs-core/src/files/ls.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import { CID } from 'multiformats/cid' import { createShardedDirectory } from '../utils/create-sharded-directory.js' @@ -15,7 +15,7 @@ import * as raw from 'multiformats/codecs/raw' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testLs (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/files/mkdir.js b/packages/interface-ipfs-core/src/files/mkdir.js index 17c056990a..d8459e16db 100644 --- a/packages/interface-ipfs-core/src/files/mkdir.js +++ b/packages/interface-ipfs-core/src/files/mkdir.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { nanoid } from 'nanoid' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import { sha512 } from 'multiformats/hashes/sha2' import { createShardedDirectory } from '../utils/create-sharded-directory.js' @@ -14,7 +14,7 @@ import isShardAtPath from '../utils/is-shard-at-path.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testMkdir (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/files/mv.js b/packages/interface-ipfs-core/src/files/mv.js index e7dcf20b66..8756a0e2b3 100644 --- a/packages/interface-ipfs-core/src/files/mv.js +++ b/packages/interface-ipfs-core/src/files/mv.js @@ -2,7 +2,7 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { concat as uint8ArrayConcat } from 'uint8arrays/concat' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import { createShardedDirectory } from '../utils/create-sharded-directory.js' import { randomBytes } from 'iso-random-stream' @@ -15,7 +15,7 @@ import all from 'it-all' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testMv (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/files/read.js b/packages/interface-ipfs-core/src/files/read.js index 3aabf8ace7..1212cc4165 100644 --- a/packages/interface-ipfs-core/src/files/read.js +++ b/packages/interface-ipfs-core/src/files/read.js @@ -4,7 +4,7 @@ import { concat as uint8ArrayConcat } from 'uint8arrays/concat' import drain from 'it-drain' import all from 'it-all' import { fixtures } from '../utils/index.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import { createShardedDirectory } from '../utils/create-sharded-directory.js' import { randomBytes } from 'iso-random-stream' @@ -15,7 +15,7 @@ import { randomBytes } from 'iso-random-stream' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testRead (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/files/rm.js b/packages/interface-ipfs-core/src/files/rm.js index 43d0000d84..063d773caa 100644 --- a/packages/interface-ipfs-core/src/files/rm.js +++ b/packages/interface-ipfs-core/src/files/rm.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { nanoid } from 'nanoid' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import { createShardedDirectory } from '../utils/create-sharded-directory.js' import { createTwoShards } from '../utils/create-two-shards.js' @@ -14,7 +14,7 @@ import isShardAtPath from '../utils/is-shard-at-path.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testRm (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/files/stat.js b/packages/interface-ipfs-core/src/files/stat.js index 08956b82f1..04e949764f 100644 --- a/packages/interface-ipfs-core/src/files/stat.js +++ b/packages/interface-ipfs-core/src/files/stat.js @@ -3,7 +3,7 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { nanoid } from 'nanoid' import { fixtures } from '../utils/index.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import { createShardedDirectory } from '../utils/create-sharded-directory.js' import { CID } from 'multiformats/cid' @@ -18,7 +18,7 @@ import * as raw from 'multiformats/codecs/raw' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testStat (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/files/touch.js b/packages/interface-ipfs-core/src/files/touch.js index 7dc76b80cd..614a7bb17e 100644 --- a/packages/interface-ipfs-core/src/files/touch.js +++ b/packages/interface-ipfs-core/src/files/touch.js @@ -3,7 +3,7 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { concat as uint8ArrayConcat } from 'uint8arrays/concat' import { nanoid } from 'nanoid' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import delay from 'delay' import all from 'it-all' @@ -14,7 +14,7 @@ import all from 'it-all' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testTouch (factory, options) { const describe = getDescribe(options) @@ -53,7 +53,7 @@ export function testTouch (factory, options) { after(() => factory.clean()) it('should have default mtime', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.slow(5 * 1000) const testPath = `/test-${nanoid()}` @@ -74,7 +74,7 @@ export function testTouch (factory, options) { }) it('should update file mtime', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.slow(5 * 1000) const testPath = `/test-${nanoid()}` const mtime = new Date() @@ -92,7 +92,7 @@ export function testTouch (factory, options) { }) it('should update directory mtime', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.slow(5 * 1000) const testPath = `/test-${nanoid()}` const mtime = new Date() diff --git a/packages/interface-ipfs-core/src/files/write.js b/packages/interface-ipfs-core/src/files/write.js index aab974cbf0..f3c7116ff2 100644 --- a/packages/interface-ipfs-core/src/files/write.js +++ b/packages/interface-ipfs-core/src/files/write.js @@ -3,7 +3,7 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { concat as uint8ArrayConcat } from 'uint8arrays/concat' import { nanoid } from 'nanoid' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import { isNode } from 'ipfs-utils/src/env.js' import { sha512 } from 'multiformats/hashes/sha2' @@ -22,7 +22,7 @@ import map from 'it-map' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testWrite (factory, options) { const describe = getDescribe(options) @@ -188,7 +188,7 @@ export function testWrite (factory, options) { it('writes a small file using a Node stream (Node only)', async function () { if (!isNode) { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.skip() } const filePath = `/small-file-${Math.random()}.txt` @@ -205,7 +205,7 @@ export function testWrite (factory, options) { it('writes a small file using an HTML5 Blob (Browser only)', async function () { if (!global.Blob) { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha return this.skip() } diff --git a/packages/interface-ipfs-core/src/get.js b/packages/interface-ipfs-core/src/get.js index f3088514ed..d541ff8a69 100644 --- a/packages/interface-ipfs-core/src/get.js +++ b/packages/interface-ipfs-core/src/get.js @@ -9,7 +9,7 @@ import all from 'it-all' import drain from 'it-drain' import last from 'it-last' import map from 'it-map' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from './utils/mocha.js' import testTimeout from './utils/test-timeout.js' import { importer } from 'ipfs-unixfs-importer' @@ -19,6 +19,10 @@ import { pipe } from 'it-pipe' import toBuffer from 'it-to-buffer' import Pako from 'pako' +/** + * @typedef {import('it-stream-types').Source} Source + */ + /** * @param {string} name * @param {string} [path] @@ -45,7 +49,7 @@ const emptyDir = (name) => ({ path: `test-folder/${name}` }) /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testGet (factory, options) { const describe = getDescribe(options) @@ -58,7 +62,7 @@ export function testGet (factory, options) { let ipfs /** - * @param {AsyncIterable} source + * @param {Source} source */ async function * gzipped (source) { const inflator = new Pako.Inflate() @@ -81,7 +85,7 @@ export function testGet (factory, options) { } /** - * @param {AsyncIterable} source + * @param {Source} source */ async function * tarballed (source) { yield * pipe( @@ -98,14 +102,6 @@ export function testGet (factory, options) { ) } - /** - * @template T - * @param {AsyncIterable} source - */ - async function collect (source) { - return all(source) - } - before(async () => { ipfs = (await factory.spawn()).api @@ -127,7 +123,7 @@ export function testGet (factory, options) { const output = await pipe( ipfs.get(fixtures.smallFile.cid), tarballed, - collect + (source) => all(source) ) expect(output).to.have.lengthOf(1) expect(output).to.have.nested.property('[0].header.name', fixtures.smallFile.cid.toString()) @@ -146,7 +142,7 @@ export function testGet (factory, options) { const output = await pipe( ipfs.get(cidv1), tarballed, - collect + (source) => all(source) ) expect(output).to.have.lengthOf(1) expect(output).to.have.nested.property('[0].header.name', cidv1.toString()) @@ -165,7 +161,7 @@ export function testGet (factory, options) { const output = await pipe( ipfs.get(cidv0), tarballed, - collect + (source) => all(source) ) expect(output).to.have.lengthOf(1) expect(output).to.have.nested.property('[0].header.name', cidv0.toString()) @@ -182,7 +178,7 @@ export function testGet (factory, options) { const output = await pipe( ipfs.get(cidv1), tarballed, - collect + (source) => all(source) ) expect(output).to.have.lengthOf(1) expect(output).to.have.nested.property('[0].header.name', cidv1.toString()) @@ -193,7 +189,7 @@ export function testGet (factory, options) { const output = await pipe( ipfs.get(fixtures.bigFile.cid), tarballed, - collect + (source) => all(source) ) expect(output).to.have.lengthOf(1) expect(output).to.have.nested.property('[0].header.name', fixtures.bigFile.cid.toString()) @@ -218,7 +214,7 @@ export function testGet (factory, options) { const output = await pipe( ipfs.get(cid), tarballed, - collect + (source) => all(source) ) // Check paths @@ -260,7 +256,7 @@ export function testGet (factory, options) { const output = await pipe( ipfs.get(cid), tarballed, - collect + (source) => all(source) ) // Check paths @@ -296,7 +292,7 @@ export function testGet (factory, options) { const output = await pipe( ipfs.get(`/ipfs/${fileAdded.cid}/testfile.txt`), tarballed, - collect + (source) => all(source) ) expect(output).to.be.length(1) @@ -310,7 +306,7 @@ export function testGet (factory, options) { compressionLevel: 5 }), gzipped, - collect + (source) => all(source) ) expect(uint8ArrayConcat(output)).to.equalBytes(fixtures.smallFile.data) }) @@ -324,7 +320,7 @@ export function testGet (factory, options) { }), gzipped, tarballed, - collect + (source) => all(source) ) expect(output).to.have.nested.property('[0].body').that.equalBytes(fixtures.smallFile.data) }) @@ -369,7 +365,7 @@ export function testGet (factory, options) { }), gzipped, tarballed, - collect + (source) => all(source) ) // Check paths @@ -411,7 +407,7 @@ export function testGet (factory, options) { const output = await pipe( ipfs.get(CID.parse(cid)), tarballed, - collect + (source) => all(source) ) expect(output).to.be.an('array').with.lengthOf(3) diff --git a/packages/interface-ipfs-core/src/key/gen.js b/packages/interface-ipfs-core/src/key/gen.js index aeff0d1426..f09d9346d6 100644 --- a/packages/interface-ipfs-core/src/key/gen.js +++ b/packages/interface-ipfs-core/src/key/gen.js @@ -1,11 +1,9 @@ /* eslint-env mocha */ import { nanoid } from 'nanoid' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' -import { keys } from 'libp2p-crypto' - -const { supportedKeys, import: importKey } = keys +import { supportedKeys, importKey } from '@libp2p/crypto/keys' /** * @typedef {import('ipfsd-ctl').Factory} Factory @@ -13,7 +11,7 @@ const { supportedKeys, import: importKey } = keys /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testGen (factory, options) { const describe = getDescribe(options) @@ -46,7 +44,7 @@ export function testGen (factory, options) { keyTypes.forEach((kt) => { it(`should generate a new ${kt.opts.type || 'default'} key`, async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(20 * 1000) const name = nanoid() const key = await ipfs.key.gen(name, kt.opts) @@ -63,7 +61,7 @@ export function testGen (factory, options) { } catch (/** @type {any} */ err) { if (err.code === 'ERR_NOT_IMPLEMENTED') { // key export is not exposed over the HTTP API - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.skip('Cannot verify key type') } diff --git a/packages/interface-ipfs-core/src/key/import.js b/packages/interface-ipfs-core/src/key/import.js index fd711429c4..5404ab5cd6 100644 --- a/packages/interface-ipfs-core/src/key/import.js +++ b/packages/interface-ipfs-core/src/key/import.js @@ -1,8 +1,8 @@ /* eslint-env mocha */ import { nanoid } from 'nanoid' -import { keys } from 'libp2p-crypto' -import { expect } from 'aegir/utils/chai.js' +import { keys } from '@libp2p/crypto' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' /** @@ -11,7 +11,7 @@ import { getDescribe, getIt } from '../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testImport (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/key/list.js b/packages/interface-ipfs-core/src/key/list.js index 9b4924d99a..15de84f4fe 100644 --- a/packages/interface-ipfs-core/src/key/list.js +++ b/packages/interface-ipfs-core/src/key/list.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { nanoid } from 'nanoid' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' /** @@ -10,7 +10,7 @@ import { getDescribe, getIt } from '../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testList (factory, options) { const describe = getDescribe(options) @@ -27,7 +27,7 @@ export function testList (factory, options) { after(() => factory.clean()) it('should list all the keys', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(60 * 1000) const keys = await Promise.all([1, 2, 3].map(() => ipfs.key.gen(nanoid(), { type: 'rsa', size: 2048 }))) diff --git a/packages/interface-ipfs-core/src/key/rename.js b/packages/interface-ipfs-core/src/key/rename.js index 1e0e48268c..b8f4c1bc4a 100644 --- a/packages/interface-ipfs-core/src/key/rename.js +++ b/packages/interface-ipfs-core/src/key/rename.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { nanoid } from 'nanoid' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' /** @@ -10,7 +10,7 @@ import { getDescribe, getIt } from '../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testRename (factory, options) { const describe = getDescribe(options) @@ -27,7 +27,7 @@ export function testRename (factory, options) { after(() => factory.clean()) it('should rename a key', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(30 * 1000) const oldName = nanoid() diff --git a/packages/interface-ipfs-core/src/key/rm.js b/packages/interface-ipfs-core/src/key/rm.js index cb07450c6a..5cde9bf106 100644 --- a/packages/interface-ipfs-core/src/key/rm.js +++ b/packages/interface-ipfs-core/src/key/rm.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { nanoid } from 'nanoid' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' /** @@ -10,7 +10,7 @@ import { getDescribe, getIt } from '../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testRm (factory, options) { const describe = getDescribe(options) @@ -27,7 +27,7 @@ export function testRm (factory, options) { after(() => factory.clean()) it('should rm a key', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(30 * 1000) const key = await ipfs.key.gen(nanoid(), { type: 'rsa', size: 2048 }) diff --git a/packages/interface-ipfs-core/src/ls.js b/packages/interface-ipfs-core/src/ls.js index 045145cade..2f9eb3632d 100644 --- a/packages/interface-ipfs-core/src/ls.js +++ b/packages/interface-ipfs-core/src/ls.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { fixtures } from './utils/index.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from './utils/mocha.js' import all from 'it-all' import { CID } from 'multiformats/cid' @@ -18,7 +18,7 @@ const randomName = prefix => `${prefix}${Math.round(Math.random() * 1000)}` /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testLs (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/miscellaneous/dns.js b/packages/interface-ipfs-core/src/miscellaneous/dns.js index adcb36a46a..36270e5e1d 100644 --- a/packages/interface-ipfs-core/src/miscellaneous/dns.js +++ b/packages/interface-ipfs-core/src/miscellaneous/dns.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' /** @@ -9,7 +9,7 @@ import { getDescribe, getIt } from '../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testDns (factory, options) { const describe = getDescribe(options) @@ -36,7 +36,7 @@ export function testDns (factory, options) { expect(res).to.match(/\/ipns\/.+$/) } catch (/** @type {any} */ err) { if (err.message.includes('could not resolve name')) { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha return this.skip() } @@ -52,7 +52,7 @@ export function testDns (factory, options) { expect(res).to.match(/\/ipfs\/.+$/) } catch (/** @type {any} */ err) { if (err.message.includes('could not resolve name')) { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha return this.skip() } @@ -68,7 +68,7 @@ export function testDns (factory, options) { expect(res).to.match(/\/ipfs\/.+$/) } catch (/** @type {any} */ err) { if (err.message.includes('could not resolve name')) { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha return this.skip() } diff --git a/packages/interface-ipfs-core/src/miscellaneous/id.js b/packages/interface-ipfs-core/src/miscellaneous/id.js index 6a664a9f4d..7b141bf91e 100644 --- a/packages/interface-ipfs-core/src/miscellaneous/id.js +++ b/packages/interface-ipfs-core/src/miscellaneous/id.js @@ -1,8 +1,8 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' -import { Multiaddr } from 'multiaddr' +import { Multiaddr } from '@multiformats/multiaddr' import { isWebWorker } from 'ipfs-utils/src/env.js' import retry from 'p-retry' @@ -12,14 +12,13 @@ import retry from 'p-retry' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testId (factory, options) { const describe = getDescribe(options) const it = getIt(options) describe('.id', function () { - // @ts-ignore this is mocha this.timeout(60 * 1000) /** @type {import('ipfs-core-types').IPFS} */ let ipfs @@ -32,7 +31,7 @@ export function testId (factory, options) { it('should get the node ID', async () => { const res = await ipfs.id() - expect(res).to.have.a.property('id').that.is.a('string') + expect(res).to.have.a.property('id') expect(res).to.have.a.property('publicKey') expect(res).to.have.a.property('agentVersion').that.is.a('string') expect(res).to.have.a.property('protocolVersion').that.is.a('string') @@ -66,7 +65,7 @@ export function testId (factory, options) { it('should return swarm ports opened after startup', async function () { if (isWebWorker) { // TODO: webworkers are not currently dialable - // @ts-ignore this is mocha + // @ts-expect-error this is mocha return this.skip() } @@ -76,7 +75,7 @@ export function testId (factory, options) { it('should get the id of another node in the swarm', async function () { if (isWebWorker) { // TODO: https://github.com/libp2p/js-libp2p-websockets/issues/129 - // @ts-ignore this is mocha + // @ts-expect-error this is mocha return this.skip() } @@ -90,7 +89,7 @@ export function testId (factory, options) { peerId: ipfsBId.id }) - expect(result).to.deep.equal(ipfsBId) + expect(JSON.stringify(result, null, 2)).to.deep.equal(JSON.stringify(ipfsBId, null, 2)) }, { retries: 5 }) }) @@ -101,7 +100,7 @@ export function testId (factory, options) { peerId: res.id }) - expect(result).to.deep.equal(res) + expect(JSON.stringify(res, null, 2)).to.deep.equal(JSON.stringify(result, null, 2)) }) }) } diff --git a/packages/interface-ipfs-core/src/miscellaneous/resolve.js b/packages/interface-ipfs-core/src/miscellaneous/resolve.js index 5192b24379..c013a61330 100644 --- a/packages/interface-ipfs-core/src/miscellaneous/resolve.js +++ b/packages/interface-ipfs-core/src/miscellaneous/resolve.js @@ -4,11 +4,10 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import isIpfs from 'is-ipfs' import { nanoid } from 'nanoid' import { base64url } from 'multiformats/bases/base64' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import all from 'it-all' import { isWebWorker } from 'ipfs-utils/src/env.js' -import { ipfsOptionsWebsocketsFilterAll } from '../utils/ipfs-options-websockets-filter-all.js' import merge from 'merge-options' /** @@ -17,10 +16,9 @@ import merge from 'merge-options' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testResolve (factory, options) { - const ipfsOptions = ipfsOptionsWebsocketsFilterAll() const describe = getDescribe(options) const it = getIt(options) @@ -34,7 +32,7 @@ export function testResolve (factory, options) { before(async () => { ipfs = (await factory.spawn({ type: 'proc', - ipfsOptions: merge(ipfsOptions, { + ipfsOptions: merge({ config: { Routing: { Type: 'none' @@ -96,7 +94,7 @@ export function testResolve (factory, options) { // Test resolve turns /ipns/domain.com into /ipfs/QmHash it('should resolve an IPNS DNS link', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.retries(3) const resolved = await ipfs.resolve('/ipns/ipfs.io') @@ -104,7 +102,7 @@ export function testResolve (factory, options) { }) it('should resolve IPNS link recursively by default', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(20 * 1000) // webworkers are not dialable because webrtc is not available const node = (await factory.spawn({ @@ -130,7 +128,7 @@ export function testResolve (factory, options) { }) it('should resolve IPNS link non-recursively if recursive==false', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(20 * 1000) // webworkers are not dialable because webrtc is not available const node = (await factory.spawn({ diff --git a/packages/interface-ipfs-core/src/miscellaneous/stop.js b/packages/interface-ipfs-core/src/miscellaneous/stop.js index bfc706abf9..a9c38e4431 100644 --- a/packages/interface-ipfs-core/src/miscellaneous/stop.js +++ b/packages/interface-ipfs-core/src/miscellaneous/stop.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' /** @@ -9,7 +9,7 @@ import { getDescribe, getIt } from '../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testStop (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/miscellaneous/version.js b/packages/interface-ipfs-core/src/miscellaneous/version.js index b122691487..41faeba7b9 100644 --- a/packages/interface-ipfs-core/src/miscellaneous/version.js +++ b/packages/interface-ipfs-core/src/miscellaneous/version.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' /** @@ -9,7 +9,7 @@ import { getDescribe, getIt } from '../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testVersion (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/name-pubsub/cancel.js b/packages/interface-ipfs-core/src/name-pubsub/cancel.js index fdebe1fb7f..39971ec5d8 100644 --- a/packages/interface-ipfs-core/src/name-pubsub/cancel.js +++ b/packages/interface-ipfs-core/src/name-pubsub/cancel.js @@ -1,9 +1,9 @@ /* eslint-env mocha */ -import PeerId from 'peer-id' import all from 'it-all' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' +import { createEd25519PeerId } from '@libp2p/peer-id-factory' /** * @typedef {import('ipfsd-ctl').Factory} Factory @@ -11,7 +11,7 @@ import { getDescribe, getIt } from '../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testCancel (factory, options) { const describe = getDescribe(options) @@ -26,13 +26,13 @@ export function testCancel (factory, options) { before(async () => { ipfs = (await factory.spawn()).api const peerInfo = await ipfs.id() - nodeId = peerInfo.id + nodeId = peerInfo.id.toString() }) after(() => factory.clean()) it('should return false when the name that is intended to cancel is not subscribed', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(60 * 1000) const res = await ipfs.name.pubsub.cancel(nodeId) @@ -42,11 +42,11 @@ export function testCancel (factory, options) { }) it('should cancel a subscription correctly returning true', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(300 * 1000) - const peerId = await PeerId.create({ bits: 512 }) - const id = peerId.toB58String() + const peerId = await createEd25519PeerId() + const id = peerId.toString() const ipnsPath = `/ipns/${id}` const subs = await ipfs.name.pubsub.subs() diff --git a/packages/interface-ipfs-core/src/name-pubsub/pubsub.js b/packages/interface-ipfs-core/src/name-pubsub/pubsub.js index 8a99748a2f..c003794030 100644 --- a/packages/interface-ipfs-core/src/name-pubsub/pubsub.js +++ b/packages/interface-ipfs-core/src/name-pubsub/pubsub.js @@ -1,8 +1,8 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' -import PeerId from 'peer-id' +import { peerIdFromString, peerIdFromKeys } from '@libp2p/peer-id' import { isNode } from 'ipfs-utils/src/env.js' import * as ipns from 'ipns' import delay from 'delay' @@ -10,6 +10,7 @@ import last from 'it-last' import waitFor from '../utils/wait-for.js' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' +import { ipnsValidator } from 'ipns/validator' const namespace = '/record/' const ipfsRef = '/ipfs/QmPFVLPmp9zv5Z5KUqLhe2EivAGccQW2r7M7jhVJGLZoZU' @@ -24,11 +25,13 @@ const daemonsOptions = { /** * @typedef {import('ipfsd-ctl').Factory} Factory + * @typedef {import('@libp2p/interfaces/pubsub').Message} Message + * @typedef {import('@libp2p/interfaces/events').EventHandler} EventHandler */ /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testPubsub (factory, options) { const describe = getDescribe(options) @@ -68,41 +71,25 @@ export function testPubsub (factory, options) { idB = ids[1] await nodeA.swarm.connect(idB.addresses[0]) + + await waitFor(async () => { + const res = await nodeB.swarm.peers() + + return res.map(p => p.peer.toString()).includes(idA.id.toString()) + }, { name: 'node A dialed node B' }) }) after(() => factory.clean()) it('should publish and then resolve correctly', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(80 * 1000) - let subscribed = false - - /** - * @type {import('ipfs-core-types/src/pubsub').MessageHandlerFn} - */ - function checkMessage () { - subscribed = true - } - - const alreadySubscribed = () => { - return subscribed === true - } - - const keys = ipns.getIdKeys(uint8ArrayFromString(idA.id, 'base58btc')) - const topic = `${namespace}${uint8ArrayToString(keys.routingKey.uint8Array(), 'base64url')}` - - await expect(last(nodeB.name.resolve(idA.id))) - .to.eventually.be.rejected() - .with.property('message').that.matches(/not found/) + const routingKey = ipns.peerIdToRoutingKey(idA.id) + const topic = `${namespace}${uint8ArrayToString(routingKey, 'base64url')}` - await waitFor(async () => { - const res = await nodeA.pubsub.peers(topic) - return Boolean(res && res.length) - }, { name: `node A to subscribe to ${topic}` }) - await nodeB.pubsub.subscribe(topic, checkMessage) + await nodeB.pubsub.subscribe(topic, () => {}) await nodeA.name.publish(ipfsRef, { resolve: false }) - await waitFor(alreadySubscribed) await delay(1000) // guarantee record is written const res = await last(nodeB.name.resolve(idA.id)) @@ -111,7 +98,7 @@ export function testPubsub (factory, options) { }) it('should self resolve, publish and then resolve correctly', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(6000) const emptyDirCid = '/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn' const { path } = await nodeA.add(uint8ArrayFromString('pubsub records')) @@ -119,13 +106,9 @@ export function testPubsub (factory, options) { const resolvesEmpty = await last(nodeB.name.resolve(idB.id)) expect(resolvesEmpty).to.be.eq(emptyDirCid) - await expect(last(nodeA.name.resolve(idB.id))) - .to.eventually.be.rejected() - .with.property('message').that.matches(/not found/) - const publish = await nodeB.name.publish(path) expect(publish).to.be.eql({ - name: idB.id, + name: idB.id.toString(), value: `/ipfs/${path}` }) @@ -137,20 +120,20 @@ export function testPubsub (factory, options) { }) it('should handle event on publish correctly', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(80 * 1000) const testAccountName = 'test-account' /** - * @type {import('ipfs-core-types/src/pubsub').Message} + * @type {import('@libp2p/interfaces/pubsub').Message} */ let publishedMessage /** - * @type {import('ipfs-core-types/src/pubsub').MessageHandlerFn} + * @type {EventHandler} */ - function checkMessage (msg) { + const checkMessage = (msg) => { publishedMessage = msg } @@ -165,14 +148,14 @@ export function testPubsub (factory, options) { 'ipns-base': 'b58mh' }) - const keys = ipns.getIdKeys(uint8ArrayFromString(testAccount.id, 'base58btc')) - const topic = `${namespace}${uint8ArrayToString(keys.routingKey.uint8Array(), 'base64url')}` + const routingKey = ipns.peerIdToRoutingKey(peerIdFromString(testAccount.id)) + const topic = `${namespace}${uint8ArrayToString(routingKey, 'base64url')}` await nodeB.pubsub.subscribe(topic, checkMessage) await nodeA.name.publish(ipfsRef, { resolve: false, key: testAccountName }) await waitFor(alreadySubscribed) - // @ts-ignore publishedMessage is set in handler + // @ts-expect-error publishedMessage is set in handler if (!publishedMessage) { throw new Error('Pubsub handler not invoked') } @@ -183,17 +166,17 @@ export function testPubsub (factory, options) { throw new Error('No public key found in message data') } - const messageKey = await PeerId.createFromB58String(publishedMessage.from) - const pubKeyPeerId = await PeerId.createFromPubKey(publishedMessageData.pubKey) + const messageKey = publishedMessage.from + const pubKeyPeerId = await peerIdFromKeys(publishedMessageData.pubKey) - expect(pubKeyPeerId.toB58String()).not.to.equal(messageKey.toB58String()) - expect(pubKeyPeerId.toB58String()).to.equal(testAccount.id) - expect(publishedMessage.from).to.equal(idA.id) - expect(messageKey.toB58String()).to.equal(idA.id) + expect(pubKeyPeerId.toString()).not.to.equal(messageKey.toString()) + expect(pubKeyPeerId.toString()).to.equal(testAccount.id) + expect(publishedMessage.from.toString()).to.equal(idA.id.toString()) + expect(messageKey.toString()).to.equal(idA.id.toString()) expect(uint8ArrayToString(publishedMessageData.value)).to.equal(ipfsRef) // Verify the signature - await ipns.validate(pubKeyPeerId.pubKey, publishedMessageData) + await ipnsValidator(ipns.peerIdToRoutingKey(pubKeyPeerId), publishedMessage.data) }) }) } diff --git a/packages/interface-ipfs-core/src/name-pubsub/state.js b/packages/interface-ipfs-core/src/name-pubsub/state.js index 05dbab25e8..17ab98f449 100644 --- a/packages/interface-ipfs-core/src/name-pubsub/state.js +++ b/packages/interface-ipfs-core/src/name-pubsub/state.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' /** @@ -9,7 +9,7 @@ import { getDescribe, getIt } from '../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testState (factory, options) { const describe = getDescribe(options) @@ -26,7 +26,7 @@ export function testState (factory, options) { after(() => factory.clean()) it('should get the current state of pubsub', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(50 * 1000) const res = await ipfs.name.pubsub.state() diff --git a/packages/interface-ipfs-core/src/name-pubsub/subs.js b/packages/interface-ipfs-core/src/name-pubsub/subs.js index b0441554c2..3f2d264204 100644 --- a/packages/interface-ipfs-core/src/name-pubsub/subs.js +++ b/packages/interface-ipfs-core/src/name-pubsub/subs.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import all from 'it-all' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' /** @@ -10,7 +10,7 @@ import { getDescribe, getIt } from '../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testSubs (factory, options) { const describe = getDescribe(options) @@ -27,7 +27,7 @@ export function testSubs (factory, options) { after(() => factory.clean()) it('should get an empty array as a result of subscriptions before any resolve', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(60 * 1000) const res = await ipfs.name.pubsub.subs() @@ -36,7 +36,7 @@ export function testSubs (factory, options) { }) it('should get the list of subscriptions updated after a resolve', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(300 * 1000) const id = 'QmNP1ASen5ZREtiJTtVD3jhMKhoPb1zppET1tgpjHx2NGA' diff --git a/packages/interface-ipfs-core/src/name/publish.js b/packages/interface-ipfs-core/src/name/publish.js index 6397d6d14a..6bfb01b0e1 100644 --- a/packages/interface-ipfs-core/src/name/publish.js +++ b/packages/interface-ipfs-core/src/name/publish.js @@ -3,18 +3,19 @@ import { nanoid } from 'nanoid' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { fixture } from './utils.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import last from 'it-last' -import PeerId from 'peer-id' +import { peerIdFromString } from '@libp2p/peer-id' /** * @typedef {import('ipfsd-ctl').Factory} Factory + * @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId */ /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testPublish (factory, options) { const describe = getDescribe(options) @@ -24,7 +25,7 @@ export function testPublish (factory, options) { const keyName = nanoid() /** @type {import('ipfs-core-types').IPFS} */ let ipfs - /** @type {string} */ + /** @type {PeerId} */ let nodeId before(async () => { @@ -45,7 +46,7 @@ export function testPublish (factory, options) { after(() => factory.clean()) it('should publish an IPNS record with the default params', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(50 * 1000) const value = fixture.cid @@ -59,18 +60,18 @@ export function testPublish (factory, options) { const res = await ipfs.name.publish(value, { allowOffline: true }) expect(res).to.exist() - expect(PeerId.parse(res.name).toString()).to.equal(PeerId.parse(self.id).toString()) + expect(peerIdFromString(res.name).toString()).to.equal(peerIdFromString(self.id).toString()) expect(res.value).to.equal(`/ipfs/${value}`) }) it('should publish correctly with the lifetime option and resolve', async () => { const { path } = await ipfs.add(uint8ArrayFromString('should publish correctly with the lifetime option and resolve')) await ipfs.name.publish(path, { allowOffline: true, resolve: false, lifetime: '2h' }) - expect(await last(ipfs.name.resolve(`/ipns/${nodeId}`))).to.eq(`/ipfs/${path}`) + expect(await last(ipfs.name.resolve(`/ipns/${nodeId.toString()}`))).to.eq(`/ipfs/${path}`) }) it('should publish correctly when the file was not added but resolve is disabled', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(50 * 1000) const value = 'QmPFVLPmp9zv5Z5KUqLhe2EivAGccQW2r7M7jhVJGLZoZU' @@ -91,12 +92,12 @@ export function testPublish (factory, options) { const res = await ipfs.name.publish(value, options) expect(res).to.exist() - expect(PeerId.parse(res.name).toString()).to.equal(PeerId.parse(self.id).toString()) + expect(peerIdFromString(res.name).toString()).to.equal(peerIdFromString(self.id).toString()) expect(res.value).to.equal(`/ipfs/${value}`) }) it('should publish with a key received as param, instead of using the key of the node', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(90 * 1000) const value = fixture.cid @@ -112,7 +113,7 @@ export function testPublish (factory, options) { const res = await ipfs.name.publish(value, options) expect(res).to.exist() - expect(PeerId.parse(res.name).toString()).to.equal(PeerId.parse(key.id).toString()) + expect(peerIdFromString(res.name).toString()).to.equal(peerIdFromString(key.id).toString()) expect(res.value).to.equal(`/ipfs/${value}`) }) }) diff --git a/packages/interface-ipfs-core/src/name/resolve.js b/packages/interface-ipfs-core/src/name/resolve.js index 1807b4551e..3c3c41c835 100644 --- a/packages/interface-ipfs-core/src/name/resolve.js +++ b/packages/interface-ipfs-core/src/name/resolve.js @@ -1,21 +1,21 @@ /* eslint-env mocha */ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import delay from 'delay' -import PeerId from 'peer-id' import last from 'it-last' import { CID } from 'multiformats/cid' import * as Digest from 'multiformats/hashes/digest' /** * @typedef {import('ipfsd-ctl').Factory} Factory + * @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId */ /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testResolve (factory, options) { const describe = getDescribe(options) @@ -24,7 +24,7 @@ export function testResolve (factory, options) { describe('.name.resolve offline', function () { /** @type {import('ipfs-core-types').IPFS} */ let ipfs - /** @type {string} */ + /** @type {PeerId} */ let nodeId before(async () => { @@ -44,21 +44,21 @@ export function testResolve (factory, options) { after(() => factory.clean()) it('should resolve a record default options', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(20 * 1000) const { path } = await ipfs.add(uint8ArrayFromString('should resolve a record default options')) const { id: keyId } = await ipfs.key.gen('key-name-default', { type: 'rsa', size: 2048 }) await ipfs.name.publish(path, { allowOffline: true }) - await ipfs.name.publish(`/ipns/${nodeId}`, { allowOffline: true, key: 'key-name-default' }) + await ipfs.name.publish(`/ipns/${nodeId.toString()}`, { allowOffline: true, key: 'key-name-default' }) expect(await last(ipfs.name.resolve(`/ipns/${keyId}`))) .to.eq(`/ipfs/${path}`) }) it('should resolve a record from peerid as cidv1 in base32', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(20 * 1000) const { cid } = await ipfs.add(uint8ArrayFromString('should resolve a record from cidv1b32')) const { id: peerId } = await ipfs.id() @@ -66,7 +66,7 @@ export function testResolve (factory, options) { // Represent Peer ID as CIDv1 Base32 // https://github.com/libp2p/specs/blob/master/RFC/0001-text-peerid-cid.md - const keyCid = CID.createV1(0x72, Digest.decode(PeerId.parse(peerId).toBytes())) + const keyCid = CID.createV1(0x72, Digest.decode(peerId.toBytes())) const resolvedPath = await last(ipfs.name.resolve(`/ipns/${keyCid}`)) expect(resolvedPath).to.equal(`/ipfs/${cid}`) @@ -75,33 +75,33 @@ export function testResolve (factory, options) { it('should resolve a record recursive === false', async () => { const { path } = await ipfs.add(uint8ArrayFromString('should resolve a record recursive === false')) await ipfs.name.publish(path, { allowOffline: true }) - expect(await last(ipfs.name.resolve(`/ipns/${nodeId}`, { recursive: false }))) + expect(await last(ipfs.name.resolve(`/ipns/${nodeId.toString()}`, { recursive: false }))) .to.eq(`/ipfs/${path}`) }) it('should resolve a record recursive === true', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(20 * 1000) const { path } = await ipfs.add(uint8ArrayFromString('should resolve a record recursive === true')) const { id: keyId } = await ipfs.key.gen('key-name', { type: 'rsa', size: 2048 }) await ipfs.name.publish(path, { allowOffline: true }) - await ipfs.name.publish(`/ipns/${nodeId}`, { allowOffline: true, key: 'key-name' }) + await ipfs.name.publish(`/ipns/${nodeId.toString()}`, { allowOffline: true, key: 'key-name' }) expect(await last(ipfs.name.resolve(`/ipns/${keyId}`, { recursive: true }))) .to.eq(`/ipfs/${path}`) }) it('should resolve a record default options with remainder', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(20 * 1000) const { path } = await ipfs.add(uint8ArrayFromString('should resolve a record default options with remainder')) const { id: keyId } = await ipfs.key.gen('key-name-remainder-default', { type: 'rsa', size: 2048 }) await ipfs.name.publish(path, { allowOffline: true }) - await ipfs.name.publish(`/ipns/${nodeId}`, { allowOffline: true, key: 'key-name-remainder-default' }) + await ipfs.name.publish(`/ipns/${nodeId.toString()}`, { allowOffline: true, key: 'key-name-remainder-default' }) expect(await last(ipfs.name.resolve(`/ipns/${keyId}/remainder/file.txt`))) .to.eq(`/ipfs/${path}/remainder/file.txt`) @@ -110,19 +110,19 @@ export function testResolve (factory, options) { it('should resolve a record recursive === false with remainder', async () => { const { path } = await ipfs.add(uint8ArrayFromString('should resolve a record recursive = false with remainder')) await ipfs.name.publish(path, { allowOffline: true }) - expect(await last(ipfs.name.resolve(`/ipns/${nodeId}/remainder/file.txt`, { recursive: false }))) + expect(await last(ipfs.name.resolve(`/ipns/${nodeId.toString()}/remainder/file.txt`, { recursive: false }))) .to.eq(`/ipfs/${path}/remainder/file.txt`) }) it('should resolve a record recursive === true with remainder', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(20 * 1000) const { path } = await ipfs.add(uint8ArrayFromString('should resolve a record recursive = true with remainder')) const { id: keyId } = await ipfs.key.gen('key-name-remainder', { type: 'rsa', size: 2048 }) await ipfs.name.publish(path, { allowOffline: true }) - await ipfs.name.publish(`/ipns/${nodeId}`, { allowOffline: true, key: 'key-name-remainder' }) + await ipfs.name.publish(`/ipns/${nodeId.toString()}`, { allowOffline: true, key: 'key-name-remainder' }) expect(await last(ipfs.name.resolve(`/ipns/${keyId}/remainder/file.txt`, { recursive: true }))) .to.eq(`/ipfs/${path}/remainder/file.txt`) diff --git a/packages/interface-ipfs-core/src/object/data.js b/packages/interface-ipfs-core/src/object/data.js index 1fbf77e58b..d137ac97d0 100644 --- a/packages/interface-ipfs-core/src/object/data.js +++ b/packages/interface-ipfs-core/src/object/data.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { nanoid } from 'nanoid' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' @@ -11,7 +11,7 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testData (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/object/get.js b/packages/interface-ipfs-core/src/object/get.js index af719866a1..7423ce532a 100644 --- a/packages/interface-ipfs-core/src/object/get.js +++ b/packages/interface-ipfs-core/src/object/get.js @@ -2,7 +2,7 @@ import * as dagPB from '@ipld/dag-pb' import { nanoid } from 'nanoid' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import { UnixFS } from 'ipfs-unixfs' import { randomBytes } from 'iso-random-stream' @@ -16,7 +16,7 @@ import { sha256 } from 'multiformats/hashes/sha2' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testGet (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/object/links.js b/packages/interface-ipfs-core/src/object/links.js index 0367fd7c8d..4b0b6ce86f 100644 --- a/packages/interface-ipfs-core/src/object/links.js +++ b/packages/interface-ipfs-core/src/object/links.js @@ -5,7 +5,7 @@ import * as dagPB from '@ipld/dag-pb' import { nanoid } from 'nanoid' import { CID } from 'multiformats/cid' import { sha256 } from 'multiformats/hashes/sha2' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' /** @@ -14,7 +14,7 @@ import { getDescribe, getIt } from '../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testLinks (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/object/new.js b/packages/interface-ipfs-core/src/object/new.js index 29da7743e2..ccde7fb3ba 100644 --- a/packages/interface-ipfs-core/src/object/new.js +++ b/packages/interface-ipfs-core/src/object/new.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' /** @@ -9,7 +9,7 @@ import { getDescribe, getIt } from '../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testNew (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/object/patch/add-link.js b/packages/interface-ipfs-core/src/object/patch/add-link.js index 6674274497..e2140a36fa 100644 --- a/packages/interface-ipfs-core/src/object/patch/add-link.js +++ b/packages/interface-ipfs-core/src/object/patch/add-link.js @@ -4,7 +4,7 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import * as dagPB from '@ipld/dag-pb' import { CID } from 'multiformats/cid' import { sha256 } from 'multiformats/hashes/sha2' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../../utils/mocha.js' /** @@ -13,7 +13,7 @@ import { getDescribe, getIt } from '../../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testAddLink (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/object/patch/append-data.js b/packages/interface-ipfs-core/src/object/patch/append-data.js index 3888cde54f..cf1da679ab 100644 --- a/packages/interface-ipfs-core/src/object/patch/append-data.js +++ b/packages/interface-ipfs-core/src/object/patch/append-data.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../../utils/mocha.js' /** @@ -10,7 +10,7 @@ import { getDescribe, getIt } from '../../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testAppendData (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/object/patch/rm-link.js b/packages/interface-ipfs-core/src/object/patch/rm-link.js index 700d2c2479..83146ff19e 100644 --- a/packages/interface-ipfs-core/src/object/patch/rm-link.js +++ b/packages/interface-ipfs-core/src/object/patch/rm-link.js @@ -4,7 +4,7 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import * as dagPB from '@ipld/dag-pb' import { CID } from 'multiformats/cid' import { sha256 } from 'multiformats/hashes/sha2' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../../utils/mocha.js' /** @@ -13,7 +13,7 @@ import { getDescribe, getIt } from '../../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testRmLink (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/object/patch/set-data.js b/packages/interface-ipfs-core/src/object/patch/set-data.js index 1d6299c5a3..5fafaeee7b 100644 --- a/packages/interface-ipfs-core/src/object/patch/set-data.js +++ b/packages/interface-ipfs-core/src/object/patch/set-data.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../../utils/mocha.js' /** @@ -10,7 +10,7 @@ import { getDescribe, getIt } from '../../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testSetData (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/object/put.js b/packages/interface-ipfs-core/src/object/put.js index 89d4dabd83..409fad40c4 100644 --- a/packages/interface-ipfs-core/src/object/put.js +++ b/packages/interface-ipfs-core/src/object/put.js @@ -5,7 +5,7 @@ import * as dagPB from '@ipld/dag-pb' import { nanoid } from 'nanoid' import { CID } from 'multiformats/cid' import { sha256 } from 'multiformats/hashes/sha2' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import first from 'it-first' import drain from 'it-drain' @@ -16,7 +16,7 @@ import drain from 'it-drain' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testPut (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/object/stat.js b/packages/interface-ipfs-core/src/object/stat.js index 80fdb65388..b5ed1d5e96 100644 --- a/packages/interface-ipfs-core/src/object/stat.js +++ b/packages/interface-ipfs-core/src/object/stat.js @@ -5,7 +5,7 @@ import * as dagPB from '@ipld/dag-pb' import { nanoid } from 'nanoid' import { CID } from 'multiformats/cid' import { sha256 } from 'multiformats/hashes/sha2' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' /** @@ -14,7 +14,7 @@ import { getDescribe, getIt } from '../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testStat (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/pin/add-all.js b/packages/interface-ipfs-core/src/pin/add-all.js index 56dbdcb91b..6c7001de65 100644 --- a/packages/interface-ipfs-core/src/pin/add-all.js +++ b/packages/interface-ipfs-core/src/pin/add-all.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { fixtures, clearPins } from './utils.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import all from 'it-all' import drain from 'it-drain' @@ -12,7 +12,7 @@ import drain from 'it-drain' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testAddAll (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/pin/add.js b/packages/interface-ipfs-core/src/pin/add.js index b9e397de1f..3823cbac0d 100644 --- a/packages/interface-ipfs-core/src/pin/add.js +++ b/packages/interface-ipfs-core/src/pin/add.js @@ -2,7 +2,7 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { fixtures, clearPins, expectPinned, expectNotPinned, pinTypes } from './utils.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import all from 'it-all' import drain from 'it-drain' @@ -13,7 +13,7 @@ import drain from 'it-drain' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testAdd (factory, options) { const describe = getDescribe(options) @@ -102,9 +102,9 @@ export function testAdd (factory, options) { }) it('should fail to pin a hash not in datastore', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.slow(3 * 1000) - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(5 * 1000) const falseHash = `${`${fixtures.directory.cid}`.slice(0, -2)}ss` @@ -113,9 +113,9 @@ export function testAdd (factory, options) { }) it('needs all children in datastore to pin recursively', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.slow(3 * 1000) - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(5 * 1000) await all(ipfs.block.rm(fixtures.directory.files[0].cid)) diff --git a/packages/interface-ipfs-core/src/pin/ls.js b/packages/interface-ipfs-core/src/pin/ls.js index 235686f5a7..52ef9afee3 100644 --- a/packages/interface-ipfs-core/src/pin/ls.js +++ b/packages/interface-ipfs-core/src/pin/ls.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { fixtures } from './utils.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import all from 'it-all' @@ -11,7 +11,7 @@ import all from 'it-all' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testLs (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/pin/remote/add.js b/packages/interface-ipfs-core/src/pin/remote/add.js index ab6481c8f5..ed4c975827 100644 --- a/packages/interface-ipfs-core/src/pin/remote/add.js +++ b/packages/interface-ipfs-core/src/pin/remote/add.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { fixtures, clearRemotePins, clearServices } from '../utils.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../../utils/mocha.js' /** @@ -10,7 +10,7 @@ import { getDescribe, getIt } from '../../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testAdd (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/pin/remote/ls.js b/packages/interface-ipfs-core/src/pin/remote/ls.js index b45ad4d3fe..e1f95caaf2 100644 --- a/packages/interface-ipfs-core/src/pin/remote/ls.js +++ b/packages/interface-ipfs-core/src/pin/remote/ls.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { clearRemotePins, addRemotePins, clearServices } from '../utils.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../../utils/mocha.js' import all from 'it-all' import { CID } from 'multiformats/cid' @@ -12,7 +12,7 @@ import { CID } from 'multiformats/cid' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testLs (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/pin/remote/rm-all.js b/packages/interface-ipfs-core/src/pin/remote/rm-all.js index 375f0eeed4..6adf6e27e0 100644 --- a/packages/interface-ipfs-core/src/pin/remote/rm-all.js +++ b/packages/interface-ipfs-core/src/pin/remote/rm-all.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { clearRemotePins, addRemotePins, clearServices } from '../utils.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../../utils/mocha.js' import { CID } from 'multiformats/cid' import all from 'it-all' @@ -12,7 +12,7 @@ import all from 'it-all' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testRmAll (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/pin/remote/rm.js b/packages/interface-ipfs-core/src/pin/remote/rm.js index dbb158381b..e702c2bfdc 100644 --- a/packages/interface-ipfs-core/src/pin/remote/rm.js +++ b/packages/interface-ipfs-core/src/pin/remote/rm.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { clearRemotePins, addRemotePins, clearServices } from '../utils.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../../utils/mocha.js' import { CID } from 'multiformats/cid' import all from 'it-all' @@ -12,7 +12,7 @@ import all from 'it-all' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testRm (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/pin/remote/service.js b/packages/interface-ipfs-core/src/pin/remote/service.js index 87f2a9ff29..dcf07fca12 100644 --- a/packages/interface-ipfs-core/src/pin/remote/service.js +++ b/packages/interface-ipfs-core/src/pin/remote/service.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { clearServices } from '../utils.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../../utils/mocha.js' /** @@ -10,7 +10,7 @@ import { getDescribe, getIt } from '../../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testService (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/pin/rm-all.js b/packages/interface-ipfs-core/src/pin/rm-all.js index d77a725350..8ab5ed5d7b 100644 --- a/packages/interface-ipfs-core/src/pin/rm-all.js +++ b/packages/interface-ipfs-core/src/pin/rm-all.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { fixtures, clearPins } from './utils.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import all from 'it-all' import drain from 'it-drain' @@ -12,7 +12,7 @@ import drain from 'it-drain' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testRmAll (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/pin/rm.js b/packages/interface-ipfs-core/src/pin/rm.js index 6bc771bf7e..f2245dc3b4 100644 --- a/packages/interface-ipfs-core/src/pin/rm.js +++ b/packages/interface-ipfs-core/src/pin/rm.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { fixtures, expectPinned, clearPins } from './utils.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import all from 'it-all' @@ -11,7 +11,7 @@ import all from 'it-all' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testRm (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/pin/utils.js b/packages/interface-ipfs-core/src/pin/utils.js index b098817c7a..5826087ee3 100644 --- a/packages/interface-ipfs-core/src/pin/utils.js +++ b/packages/interface-ipfs-core/src/pin/utils.js @@ -1,5 +1,5 @@ -import { expect } from 'aegir/utils/chai.js' -import loadFixture from 'aegir/utils/fixtures.js' +import { expect } from 'aegir/chai' +import loadFixture from 'aegir/fixtures' import { CID } from 'multiformats/cid' import drain from 'it-drain' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' diff --git a/packages/interface-ipfs-core/src/ping/ping.js b/packages/interface-ipfs-core/src/ping/ping.js index 6c05f1441f..bca4c53fa4 100644 --- a/packages/interface-ipfs-core/src/ping/ping.js +++ b/packages/interface-ipfs-core/src/ping/ping.js @@ -1,11 +1,11 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import { expectIsPingResponse, isPong } from './utils.js' import all from 'it-all' import { isWebWorker } from 'ipfs-utils/src/env.js' -import { ipfsOptionsWebsocketsFilterAll } from '../utils/ipfs-options-websockets-filter-all.js' +import { peerIdFromString } from '@libp2p/peer-id' /** * @typedef {import('ipfsd-ctl').Factory} Factory @@ -13,10 +13,9 @@ import { ipfsOptionsWebsocketsFilterAll } from '../utils/ipfs-options-websockets /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testPing (factory, options) { - const ipfsOptions = ipfsOptionsWebsocketsFilterAll() const describe = getDescribe(options) const it = getIt(options) @@ -31,7 +30,7 @@ export function testPing (factory, options) { let nodeBId before(async () => { - ipfsA = (await factory.spawn({ type: 'proc', ipfsOptions })).api + ipfsA = (await factory.spawn({ type: 'proc' })).api // webworkers are not dialable because webrtc is not available ipfsB = (await factory.spawn({ type: isWebWorker ? 'go' : undefined })).api nodeBId = await ipfsB.id() @@ -50,19 +49,12 @@ export function testPing (factory, options) { }) it('should fail when pinging a peer that is not available', () => { - const notAvailablePeerId = 'QmUmaEnH1uMmvckMZbh3yShaasvELPW4ZLPWnB4entMTEn' + const notAvailablePeerId = peerIdFromString('QmUmaEnH1uMmvckMZbh3yShaasvELPW4ZLPWnB4entMTEn') const count = 2 return expect(all(ipfsA.ping(notAvailablePeerId, { count }))).to.eventually.be.rejected() }) - it('should fail when pinging an invalid peer Id', () => { - const invalidPeerId = 'not a peer ID' - const count = 2 - - return expect(all(ipfsA.ping(invalidPeerId, { count }))).to.eventually.be.rejected() - }) - it('can ping without options', async () => { const res = await all(ipfsA.ping(nodeBId.id)) expect(res.length).to.be.ok() diff --git a/packages/interface-ipfs-core/src/ping/utils.js b/packages/interface-ipfs-core/src/ping/utils.js index ab8049f244..71a54eea17 100644 --- a/packages/interface-ipfs-core/src/ping/utils.js +++ b/packages/interface-ipfs-core/src/ping/utils.js @@ -1,4 +1,4 @@ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' /** * @param {*} obj diff --git a/packages/interface-ipfs-core/src/pubsub/ls.js b/packages/interface-ipfs-core/src/pubsub/ls.js index f9854ba4b3..1faea56ba4 100644 --- a/packages/interface-ipfs-core/src/pubsub/ls.js +++ b/packages/interface-ipfs-core/src/pubsub/ls.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { getTopic } from './utils.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import delay from 'delay' @@ -11,7 +11,7 @@ import delay from 'delay' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testLs (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/pubsub/peers.js b/packages/interface-ipfs-core/src/pubsub/peers.js index 53a0df84e5..cf9e891f5b 100644 --- a/packages/interface-ipfs-core/src/pubsub/peers.js +++ b/packages/interface-ipfs-core/src/pubsub/peers.js @@ -1,11 +1,10 @@ /* eslint-env mocha */ import { waitForPeers, getTopic } from './utils.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import delay from 'delay' import { isWebWorker } from 'ipfs-utils/src/env.js' -import { ipfsOptionsWebsocketsFilterAll } from '../utils/ipfs-options-websockets-filter-all.js' /** * @typedef {import('ipfsd-ctl').Factory} Factory @@ -13,10 +12,9 @@ import { ipfsOptionsWebsocketsFilterAll } from '../utils/ipfs-options-websockets /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testPeers (factory, options) { - const ipfsOptions = ipfsOptionsWebsocketsFilterAll() const describe = getDescribe(options) const it = getIt(options) @@ -37,10 +35,10 @@ export function testPeers (factory, options) { let ipfs3Id before(async () => { - ipfs1 = (await factory.spawn({ ipfsOptions })).api + ipfs1 = (await factory.spawn()).api // webworkers are not dialable because webrtc is not available - ipfs2 = (await factory.spawn({ type: isWebWorker ? 'js' : undefined, ipfsOptions })).api - ipfs3 = (await factory.spawn({ type: isWebWorker ? 'js' : undefined, ipfsOptions })).api + ipfs2 = (await factory.spawn({ type: isWebWorker ? 'js' : undefined })).api + ipfs3 = (await factory.spawn({ type: isWebWorker ? 'js' : undefined })).api ipfs2Id = await ipfs2.id() ipfs3Id = await ipfs3.id() diff --git a/packages/interface-ipfs-core/src/pubsub/publish.js b/packages/interface-ipfs-core/src/pubsub/publish.js index 7ee47cd788..3986adac4b 100644 --- a/packages/interface-ipfs-core/src/pubsub/publish.js +++ b/packages/interface-ipfs-core/src/pubsub/publish.js @@ -3,7 +3,7 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { nanoid } from 'nanoid' import { getTopic } from './utils.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' /** @@ -12,7 +12,7 @@ import { getDescribe, getIt } from '../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testPublish (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/pubsub/subscribe.js b/packages/interface-ipfs-core/src/pubsub/subscribe.js index 0109f90d04..78daa3f434 100644 --- a/packages/interface-ipfs-core/src/pubsub/subscribe.js +++ b/packages/interface-ipfs-core/src/pubsub/subscribe.js @@ -3,27 +3,28 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' import { nanoid } from 'nanoid' -import pushable from 'it-pushable' +import { pushable } from 'it-pushable' import all from 'it-all' import { waitForPeers, getTopic } from './utils.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import delay from 'delay' import { isWebWorker, isNode } from 'ipfs-utils/src/env.js' -import { ipfsOptionsWebsocketsFilterAll } from '../utils/ipfs-options-websockets-filter-all.js' -import first from 'it-first' import sinon from 'sinon' +import defer from 'p-defer' /** * @typedef {import('ipfsd-ctl').Factory} Factory + * @typedef {import('@libp2p/interfaces/pubsub').Message} Message + * @typedef {import('it-pushable').Pushable} Pushable + * @typedef {import('p-defer').DeferredPromise} DeferredMessagePromise */ /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testSubscribe (factory, options) { - const ipfsOptions = ipfsOptionsWebsocketsFilterAll() const describe = getDescribe(options) const it = getIt(options) @@ -43,17 +44,15 @@ export function testSubscribe (factory, options) { /** @type {import('ipfs-core-types/src/root').IDResult} */ let ipfs2Id - before(async () => { - ipfs1 = (await factory.spawn({ ipfsOptions })).api + beforeEach(async () => { + ipfs1 = (await factory.spawn()).api // webworkers are not dialable because webrtc is not available - ipfs2 = (await factory.spawn({ type: isWebWorker ? 'js' : undefined, ipfsOptions })).api + ipfs2 = (await factory.spawn({ type: isWebWorker ? 'js' : undefined })).api ipfs1Id = await ipfs1.id() ipfs2Id = await ipfs2.id() - }) - beforeEach(() => { topic = getTopic() subscribedTopics = [topic] }) @@ -66,28 +65,28 @@ export function testSubscribe (factory, options) { } subscribedTopics = [] await delay(100) - }) - after(() => factory.clean()) + await factory.clean() + }) describe('single node', () => { it('should subscribe to one topic', async () => { - const msgStream = pushable() + /** @type {import('p-defer').DeferredPromise} */ + const deferred = defer() await ipfs1.pubsub.subscribe(topic, msg => { - msgStream.push(msg) - msgStream.end() + deferred.resolve(msg) }) await ipfs1.pubsub.publish(topic, uint8ArrayFromString('hi')) - const msg = await first(msgStream) + const msg = await deferred.promise expect(uint8ArrayToString(msg.data)).to.equal('hi') - expect(msg).to.have.property('seqno') - expect(msg.seqno).to.be.an.instanceof(Uint8Array) - expect(msg.topicIDs[0]).to.eq(topic) - expect(msg).to.have.property('from', ipfs1Id.id) + expect(msg).to.have.property('sequenceNumber') + expect(msg.sequenceNumber).to.be.a('BigInt') + expect(msg.topic).to.eq(topic) + expect(msg.from.toString()).to.equal(ipfs1Id.id.toString()) }) it('should subscribe to one topic with options', async () => { @@ -102,26 +101,26 @@ export function testSubscribe (factory, options) { for await (const msg of msgStream) { expect(uint8ArrayToString(msg.data)).to.equal('hi') - expect(msg).to.have.property('seqno') - expect(msg.seqno).to.be.an.instanceof(Uint8Array) - expect(msg.topicIDs[0]).to.eq(topic) - expect(msg).to.have.property('from', ipfs1Id.id) + expect(msg).to.have.property('sequenceNumber') + expect(msg.sequenceNumber).to.be.a('bigint') + expect(msg.topic).to.eq(topic) + expect(msg.from.toString()).to.equal(ipfs1Id.id.toString()) } }) it('should subscribe to topic multiple times with different handlers', async () => { - const msgStream1 = pushable() - const msgStream2 = pushable() + /** @type {import('p-defer').DeferredPromise} */ + const msgStream1 = defer() + /** @type {import('p-defer').DeferredPromise} */ + const msgStream2 = defer() - /** @type {import('ipfs-core-types/src/pubsub').MessageHandlerFn} */ + /** @type {import('@libp2p/interfaces/events').EventHandler} */ const handler1 = msg => { - msgStream1.push(msg) - msgStream1.end() + msgStream1.resolve(msg) } - /** @type {import('ipfs-core-types/src/pubsub').MessageHandlerFn} */ + /** @type {import('@libp2p/interfaces/events').EventHandler} */ const handler2 = msg => { - msgStream2.push(msg) - msgStream2.end() + msgStream2.resolve(msg) } await Promise.all([ @@ -131,10 +130,10 @@ export function testSubscribe (factory, options) { await ipfs1.pubsub.publish(topic, uint8ArrayFromString('hello')) - const [handler1Msg] = await all(msgStream1) + const handler1Msg = await msgStream1.promise expect(uint8ArrayToString(handler1Msg.data)).to.eql('hello') - const [handler2Msg] = await all(msgStream2) + const handler2Msg = await msgStream2.promise expect(uint8ArrayToString(handler2Msg.data)).to.eql('hello') await ipfs1.pubsub.unsubscribe(topic, handler1) @@ -167,7 +166,7 @@ export function testSubscribe (factory, options) { }) describe('multiple connected nodes', () => { - before(() => { + beforeEach(() => { if (ipfs1.pubsub.setMaxListeners) { ipfs1.pubsub.setMaxListeners(100) } @@ -188,7 +187,7 @@ export function testSubscribe (factory, options) { it('should receive messages from a different node with floodsub', async function () { if (!isNode) { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha return this.skip() } const expectedString = 'should receive messages from a different node with floodsub' @@ -216,18 +215,18 @@ export function testSubscribe (factory, options) { const ipfs2Id = await ipfs2.id() await ipfs1.swarm.connect(ipfs2Id.addresses[0]) - const msgStream1 = pushable() - const msgStream2 = pushable() + /** @type {DeferredMessagePromise} */ + const msgStream1 = defer() + /** @type {DeferredMessagePromise} */ + const msgStream2 = defer() - /** @type {import('ipfs-core-types/src/pubsub').MessageHandlerFn} */ + /** @type {import('@libp2p/interfaces/events').EventHandler} */ const sub1 = msg => { - msgStream1.push(msg) - msgStream1.end() + msgStream1.resolve(msg) } - /** @type {import('ipfs-core-types/src/pubsub').MessageHandlerFn} */ + /** @type {import('@libp2p/interfaces/events').EventHandler} */ const sub2 = msg => { - msgStream2.push(msg) - msgStream2.end() + msgStream2.resolve(msg) } const abort1 = new AbortController() @@ -238,15 +237,17 @@ export function testSubscribe (factory, options) { ]) await waitForPeers(ipfs2, topic, [ipfs1Id.id], 30000) + await ipfs2.pubsub.publish(topic, uint8ArrayFromString(expectedString)) - const [sub1Msg] = await all(msgStream1) + const sub1Msg = await msgStream1.promise expect(uint8ArrayToString(sub1Msg.data)).to.be.eql(expectedString) - expect(sub1Msg.from).to.eql(ipfs2Id.id) + expect(sub1Msg.from.toString()).to.eql(ipfs2Id.id.toString()) - const [sub2Msg] = await all(msgStream2) + const sub2Msg = await msgStream2.promise expect(uint8ArrayToString(sub2Msg.data)).to.be.eql(expectedString) - expect(sub2Msg.from).to.eql(ipfs2Id.id) + expect(sub2Msg.from.toString()).to.eql(ipfs2Id.id.toString()) + abort1.abort() abort2.abort() }) @@ -254,18 +255,18 @@ export function testSubscribe (factory, options) { it('should receive messages from a different node', async () => { const expectedString = 'hello from the other side' - const msgStream1 = pushable() - const msgStream2 = pushable() + /** @type {DeferredMessagePromise} */ + const msgStream1 = defer() + /** @type {DeferredMessagePromise} */ + const msgStream2 = defer() - /** @type {import('ipfs-core-types/src/pubsub').MessageHandlerFn} */ + /** @type {import('@libp2p/interfaces/events').EventHandler} */ const sub1 = msg => { - msgStream1.push(msg) - msgStream1.end() + msgStream1.resolve(msg) } - /** @type {import('ipfs-core-types/src/pubsub').MessageHandlerFn} */ + /** @type {import('@libp2p/interfaces/events').EventHandler} */ const sub2 = msg => { - msgStream2.push(msg) - msgStream2.end() + msgStream2.resolve(msg) } await Promise.all([ @@ -277,31 +278,31 @@ export function testSubscribe (factory, options) { await delay(5000) // gossipsub need this delay https://github.com/libp2p/go-libp2p-pubsub/issues/331 await ipfs2.pubsub.publish(topic, uint8ArrayFromString(expectedString)) - const [sub1Msg] = await all(msgStream1) + const sub1Msg = await msgStream1.promise expect(uint8ArrayToString(sub1Msg.data)).to.be.eql(expectedString) - expect(sub1Msg.from).to.eql(ipfs2Id.id) + expect(sub1Msg.from.toString()).to.eql(ipfs2Id.id.toString()) - const [sub2Msg] = await all(msgStream2) + const sub2Msg = await msgStream2.promise expect(uint8ArrayToString(sub2Msg.data)).to.be.eql(expectedString) - expect(sub2Msg.from).to.eql(ipfs2Id.id) + expect(sub2Msg.from.toString()).to.eql(ipfs2Id.id.toString()) }) it('should round trip a non-utf8 binary buffer', async () => { const expectedHex = 'a36161636179656162830103056164a16466666666f4' const buffer = uint8ArrayFromString(expectedHex, 'base16') - const msgStream1 = pushable() - const msgStream2 = pushable() + /** @type {DeferredMessagePromise} */ + const msgStream1 = defer() + /** @type {DeferredMessagePromise} */ + const msgStream2 = defer() - /** @type {import('ipfs-core-types/src/pubsub').MessageHandlerFn} */ + /** @type {import('@libp2p/interfaces/events').EventHandler} */ const sub1 = msg => { - msgStream1.push(msg) - msgStream1.end() + msgStream1.resolve(msg) } - /** @type {import('ipfs-core-types/src/pubsub').MessageHandlerFn} */ + /** @type {import('@libp2p/interfaces/events').EventHandler} */ const sub2 = msg => { - msgStream2.push(msg) - msgStream2.end() + msgStream2.resolve(msg) } await Promise.all([ @@ -313,13 +314,13 @@ export function testSubscribe (factory, options) { await delay(5000) // gossipsub need this delay https://github.com/libp2p/go-libp2p-pubsub/issues/331 await ipfs2.pubsub.publish(topic, buffer) - const [sub1Msg] = await all(msgStream1) + const sub1Msg = await msgStream1.promise expect(uint8ArrayToString(sub1Msg.data, 'base16')).to.be.eql(expectedHex) - expect(sub1Msg.from).to.eql(ipfs2Id.id) + expect(sub1Msg.from.toString()).to.eql(ipfs2Id.id.toString()) - const [sub2Msg] = await all(msgStream2) + const sub2Msg = await msgStream2.promise expect(uint8ArrayToString(sub2Msg.data, 'base16')).to.be.eql(expectedHex) - expect(sub2Msg.from).to.eql(ipfs2Id.id) + expect(sub2Msg.from.toString()).to.eql(ipfs2Id.id.toString()) }) it('should receive multiple messages', async () => { @@ -329,7 +330,7 @@ export function testSubscribe (factory, options) { const msgStream2 = pushable() let sub1Called = 0 - /** @type {import('ipfs-core-types/src/pubsub').MessageHandlerFn} */ + /** @type {import('@libp2p/interfaces/events').EventHandler} */ const sub1 = msg => { msgStream1.push(msg) sub1Called++ @@ -337,7 +338,7 @@ export function testSubscribe (factory, options) { } let sub2Called = 0 - /** @type {import('ipfs-core-types/src/pubsub').MessageHandlerFn} */ + /** @type {import('@libp2p/interfaces/events').EventHandler} */ const sub2 = msg => { msgStream2.push(msg) sub2Called++ @@ -357,18 +358,18 @@ export function testSubscribe (factory, options) { } const sub1Msgs = await all(msgStream1) - sub1Msgs.forEach(msg => expect(msg.from).to.eql(ipfs2Id.id)) + sub1Msgs.forEach(msg => expect(msg.from.toString()).to.eql(ipfs2Id.id.toString())) const inbox1 = sub1Msgs.map(msg => uint8ArrayToString(msg.data)) expect(inbox1.sort()).to.eql(outbox.sort()) const sub2Msgs = await all(msgStream2) - sub2Msgs.forEach(msg => expect(msg.from).to.eql(ipfs2Id.id)) + sub2Msgs.forEach(msg => expect(msg.from.toString()).to.eql(ipfs2Id.id.toString())) const inbox2 = sub2Msgs.map(msg => uint8ArrayToString(msg.data)) expect(inbox2.sort()).to.eql(outbox.sort()) }) it('should send/receive 100 messages', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(2 * 60 * 1000) const msgBase = 'msg - ' @@ -376,7 +377,7 @@ export function testSubscribe (factory, options) { const msgStream = pushable() let subCalled = 0 - /** @type {import('ipfs-core-types/src/pubsub').MessageHandlerFn} */ + /** @type {import('@libp2p/interfaces/events').EventHandler} */ const sub = msg => { msgStream.push(msg) subCalled++ @@ -405,13 +406,12 @@ export function testSubscribe (factory, options) { console.log(`Send/Receive 100 messages took: ${duration} ms, ${opsPerSec} ops / s`) msgs.forEach(msg => { - expect(msg.from).to.eql(ipfs2Id.id) + expect(msg.from.toString()).to.eql(ipfs2Id.id.toString()) expect(uint8ArrayToString(msg.data).startsWith(msgBase)).to.be.true() }) }) it('should receive messages from a different node on lots of topics', async () => { - // @ts-ignore this is mocha this.timeout(5 * 60 * 1000) const numTopics = 20 @@ -431,12 +431,12 @@ export function testSubscribe (factory, options) { msgStream2 }) - /** @type {import('ipfs-core-types/src/pubsub').MessageHandlerFn} */ + /** @type {import('@libp2p/interfaces/events').EventHandler} */ const sub1 = msg => { msgStream1.push(msg) msgStream1.end() } - /** @type {import('ipfs-core-types/src/pubsub').MessageHandlerFn} */ + /** @type {import('@libp2p/interfaces/events').EventHandler} */ const sub2 = msg => { msgStream2.push(msg) msgStream2.end() @@ -462,16 +462,15 @@ export function testSubscribe (factory, options) { for (let i = 0; i < numTopics; i++) { const [sub1Msg] = await all(msgStreams[i].msgStream1) expect(uint8ArrayToString(sub1Msg.data)).to.equal(expectedStrings[i]) - expect(sub1Msg.from).to.eql(ipfs2Id.id) + expect(sub1Msg.from.toString()).to.eql(ipfs2Id.id.toString()) const [sub2Msg] = await all(msgStreams[i].msgStream2) expect(uint8ArrayToString(sub2Msg.data)).to.equal(expectedStrings[i]) - expect(sub2Msg.from).to.eql(ipfs2Id.id) + expect(sub2Msg.from.toString()).to.eql(ipfs2Id.id.toString()) } }) it('should unsubscribe multiple handlers', async () => { - // @ts-ignore this is mocha this.timeout(2 * 60 * 1000) const topic = `topic-${Math.random()}` @@ -508,7 +507,6 @@ export function testSubscribe (factory, options) { }) it('should unsubscribe individual handlers', async () => { - // @ts-ignore this is mocha this.timeout(2 * 60 * 1000) const topic = `topic-${Math.random()}` diff --git a/packages/interface-ipfs-core/src/pubsub/unsubscribe.js b/packages/interface-ipfs-core/src/pubsub/unsubscribe.js index b996cc658c..7746525414 100644 --- a/packages/interface-ipfs-core/src/pubsub/unsubscribe.js +++ b/packages/interface-ipfs-core/src/pubsub/unsubscribe.js @@ -7,11 +7,12 @@ import waitFor from '../utils/wait-for.js' /** * @typedef {import('ipfsd-ctl').Factory} Factory + * @typedef {import('@libp2p/interfaces/pubsub').Message} Message */ /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testUnsubscribe (factory, options) { const describe = getDescribe(options) @@ -34,7 +35,7 @@ export function testUnsubscribe (factory, options) { it(`should subscribe and unsubscribe ${count} times`, async () => { const someTopic = getTopic() - /** @type {import('ipfs-core-types/src/pubsub').MessageHandlerFn[]} */ + /** @type {import('@libp2p/interfaces/events').EventHandler[]} */ const handlers = Array.from(Array(count), () => msg => {}) for (let i = 0; i < count; i++) { diff --git a/packages/interface-ipfs-core/src/pubsub/utils.js b/packages/interface-ipfs-core/src/pubsub/utils.js index b5c82cab32..cdf90788d1 100644 --- a/packages/interface-ipfs-core/src/pubsub/utils.js +++ b/packages/interface-ipfs-core/src/pubsub/utils.js @@ -1,10 +1,14 @@ import { nanoid } from 'nanoid' import delay from 'delay' +/** + * @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId + */ + /** * @param {import('ipfs-core-types').IPFS} ipfs * @param {string} topic - * @param {string[]} peersToWait + * @param {PeerId[]} peersToWait * @param {number} waitForMs * @returns */ @@ -13,7 +17,7 @@ export async function waitForPeers (ipfs, topic, peersToWait, waitForMs) { while (true) { const peers = await ipfs.pubsub.peers(topic) - const everyPeerFound = peersToWait.every(p => peers.includes(p)) + const everyPeerFound = peersToWait.every(p => peers.map(p => p.toString()).includes(p.toString())) if (everyPeerFound) { return diff --git a/packages/interface-ipfs-core/src/refs-local.js b/packages/interface-ipfs-core/src/refs-local.js index cd438ebd74..7c890bca3c 100644 --- a/packages/interface-ipfs-core/src/refs-local.js +++ b/packages/interface-ipfs-core/src/refs-local.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { fixtures } from './utils/index.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from './utils/mocha.js' import all from 'it-all' import { importer } from 'ipfs-unixfs-importer' @@ -16,7 +16,7 @@ import blockstore from './utils/blockstore-adapter.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testRefsLocal (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/refs.js b/packages/interface-ipfs-core/src/refs.js index 77c3d92e90..8bea1e73e3 100644 --- a/packages/interface-ipfs-core/src/refs.js +++ b/packages/interface-ipfs-core/src/refs.js @@ -1,8 +1,8 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from './utils/mocha.js' -import loadFixture from 'aegir/utils/fixtures.js' +import loadFixture from 'aegir/fixtures' import { CID } from 'multiformats/cid' import all from 'it-all' import drain from 'it-drain' @@ -16,7 +16,7 @@ import { UnixFS } from 'ipfs-unixfs' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testRefs (factory, options) { const describe = getDescribe(options) @@ -50,7 +50,7 @@ export function testRefs (factory, options) { const { path, params, expected, expectError, expectTimeout } = options // eslint-disable-next-line no-loop-func it(name, async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(20 * 1000) // Call out to IPFS @@ -81,7 +81,7 @@ export function testRefs (factory, options) { }) it('should get refs with cbor links', async function () { - // @ts-ignore this is mocha + // @ts-expect-error this is mocha this.timeout(20 * 1000) // Call out to IPFS diff --git a/packages/interface-ipfs-core/src/repo/gc.js b/packages/interface-ipfs-core/src/repo/gc.js index e1e420e958..c8597c99b4 100644 --- a/packages/interface-ipfs-core/src/repo/gc.js +++ b/packages/interface-ipfs-core/src/repo/gc.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import all from 'it-all' import drain from 'it-drain' @@ -39,7 +39,7 @@ async function shouldNotHaveRef (ipfs, cid) { /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testGc (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/repo/stat.js b/packages/interface-ipfs-core/src/repo/stat.js index 6a669b568e..37cca933c5 100644 --- a/packages/interface-ipfs-core/src/repo/stat.js +++ b/packages/interface-ipfs-core/src/repo/stat.js @@ -9,7 +9,7 @@ import { getDescribe, getIt } from '../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testStat (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/repo/version.js b/packages/interface-ipfs-core/src/repo/version.js index 2ed9c86bb7..ace4d85a1c 100644 --- a/packages/interface-ipfs-core/src/repo/version.js +++ b/packages/interface-ipfs-core/src/repo/version.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' /** @@ -9,7 +9,7 @@ import { getDescribe, getIt } from '../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testVersion (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/stats/bitswap.js b/packages/interface-ipfs-core/src/stats/bitswap.js index 4d3a3f07e9..5d82bfbc5b 100644 --- a/packages/interface-ipfs-core/src/stats/bitswap.js +++ b/packages/interface-ipfs-core/src/stats/bitswap.js @@ -9,7 +9,7 @@ import { expectIsBitswap } from './utils.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testBitswap (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/stats/bw.js b/packages/interface-ipfs-core/src/stats/bw.js index f23e4a1587..da0f02162d 100644 --- a/packages/interface-ipfs-core/src/stats/bw.js +++ b/packages/interface-ipfs-core/src/stats/bw.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { expectIsBandwidth } from './utils.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import last from 'it-last' import all from 'it-all' @@ -12,7 +12,7 @@ import all from 'it-all' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testBw (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/stats/repo.js b/packages/interface-ipfs-core/src/stats/repo.js index 03dcd40f4c..260c0d78e9 100644 --- a/packages/interface-ipfs-core/src/stats/repo.js +++ b/packages/interface-ipfs-core/src/stats/repo.js @@ -9,7 +9,7 @@ import { getDescribe, getIt } from '../utils/mocha.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testRepo (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/stats/utils.js b/packages/interface-ipfs-core/src/stats/utils.js index fd319fff4a..6617b9dee4 100644 --- a/packages/interface-ipfs-core/src/stats/utils.js +++ b/packages/interface-ipfs-core/src/stats/utils.js @@ -1,4 +1,4 @@ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' /** * @param {any} n diff --git a/packages/interface-ipfs-core/src/swarm/addrs.js b/packages/interface-ipfs-core/src/swarm/addrs.js index b3acb6b386..6d2da0f3e4 100644 --- a/packages/interface-ipfs-core/src/swarm/addrs.js +++ b/packages/interface-ipfs-core/src/swarm/addrs.js @@ -1,11 +1,9 @@ /* eslint-env mocha */ -import PeerId from 'peer-id' -import { Multiaddr } from 'multiaddr' -import { expect } from 'aegir/utils/chai.js' +import { Multiaddr } from '@multiformats/multiaddr' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import { isWebWorker } from 'ipfs-utils/src/env.js' -import { ipfsOptionsWebsocketsFilterAll } from '../utils/ipfs-options-websockets-filter-all.js' /** * @typedef {import('ipfsd-ctl').Factory} Factory @@ -13,10 +11,9 @@ import { ipfsOptionsWebsocketsFilterAll } from '../utils/ipfs-options-websockets /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testAddrs (factory, options) { - const ipfsOptions = ipfsOptionsWebsocketsFilterAll() const describe = getDescribe(options) const it = getIt(options) @@ -31,7 +28,7 @@ export function testAddrs (factory, options) { let ipfsBId before(async () => { - ipfsA = (await factory.spawn({ type: 'proc', ipfsOptions })).api + ipfsA = (await factory.spawn({ type: 'proc' })).api // webworkers are not dialable because webrtc is not available ipfsB = (await factory.spawn({ type: isWebWorker ? 'go' : undefined })).api ipfsBId = await ipfsB.id() @@ -46,7 +43,7 @@ export function testAddrs (factory, options) { expect(peers).to.be.an('array') for (const peer of peers) { - expect(PeerId.parse(peer.id)).to.be.ok() + expect(peer.id).to.be.ok() expect(peer).to.have.a.property('addrs').that.is.an('array') for (const ma of peer.addrs) { diff --git a/packages/interface-ipfs-core/src/swarm/connect.js b/packages/interface-ipfs-core/src/swarm/connect.js index b55ac7f119..ece82f27a7 100644 --- a/packages/interface-ipfs-core/src/swarm/connect.js +++ b/packages/interface-ipfs-core/src/swarm/connect.js @@ -1,9 +1,8 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import { isWebWorker } from 'ipfs-utils/src/env.js' -import { ipfsOptionsWebsocketsFilterAll } from '../utils/ipfs-options-websockets-filter-all.js' /** * @typedef {import('ipfsd-ctl').Factory} Factory @@ -11,10 +10,9 @@ import { ipfsOptionsWebsocketsFilterAll } from '../utils/ipfs-options-websockets /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testConnect (factory, options) { - const ipfsOptions = ipfsOptionsWebsocketsFilterAll() const describe = getDescribe(options) const it = getIt(options) @@ -28,7 +26,7 @@ export function testConnect (factory, options) { let ipfsBId before(async () => { - ipfsA = (await factory.spawn({ type: 'proc', ipfsOptions })).api + ipfsA = (await factory.spawn({ type: 'proc' })).api // webworkers are not dialable because webrtc is not available ipfsB = (await factory.spawn({ type: isWebWorker ? 'go' : undefined })).api ipfsBId = await ipfsB.id() @@ -40,12 +38,12 @@ export function testConnect (factory, options) { let peers peers = await ipfsA.swarm.peers() - expect(peers).to.have.length(0) + expect(peers.map(p => p.peer.toString())).to.not.include(ipfsBId.id.toString()) await ipfsA.swarm.connect(ipfsBId.addresses[0]) peers = await ipfsA.swarm.peers() - expect(peers).to.have.length.above(0) + expect(peers.map(p => p.peer.toString())).to.include(ipfsBId.id.toString()) }) }) } diff --git a/packages/interface-ipfs-core/src/swarm/disconnect.js b/packages/interface-ipfs-core/src/swarm/disconnect.js index ba2edf7928..b1a3fc5d71 100644 --- a/packages/interface-ipfs-core/src/swarm/disconnect.js +++ b/packages/interface-ipfs-core/src/swarm/disconnect.js @@ -1,9 +1,8 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import { isWebWorker } from 'ipfs-utils/src/env.js' -import { ipfsOptionsWebsocketsFilterAll } from '../utils/ipfs-options-websockets-filter-all.js' /** * @typedef {import('ipfsd-ctl').Factory} Factory @@ -11,10 +10,9 @@ import { ipfsOptionsWebsocketsFilterAll } from '../utils/ipfs-options-websockets /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testDisconnect (factory, options) { - const ipfsOptions = ipfsOptionsWebsocketsFilterAll() const describe = getDescribe(options) const it = getIt(options) @@ -29,7 +27,7 @@ export function testDisconnect (factory, options) { let ipfsBId before(async () => { - ipfsA = (await factory.spawn({ type: 'proc', ipfsOptions })).api + ipfsA = (await factory.spawn({ type: 'proc' })).api // webworkers are not dialable because webrtc is not available ipfsB = (await factory.spawn({ type: isWebWorker ? 'go' : undefined })).api ipfsBId = await ipfsB.id() diff --git a/packages/interface-ipfs-core/src/swarm/local-addrs.js b/packages/interface-ipfs-core/src/swarm/local-addrs.js index c0b70abd56..69322210ae 100644 --- a/packages/interface-ipfs-core/src/swarm/local-addrs.js +++ b/packages/interface-ipfs-core/src/swarm/local-addrs.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import { isWebWorker } from 'ipfs-utils/src/env.js' @@ -10,7 +10,7 @@ import { isWebWorker } from 'ipfs-utils/src/env.js' /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testLocalAddrs (factory, options) { const describe = getDescribe(options) diff --git a/packages/interface-ipfs-core/src/swarm/peers.js b/packages/interface-ipfs-core/src/swarm/peers.js index 72c73d7df2..13ae652500 100644 --- a/packages/interface-ipfs-core/src/swarm/peers.js +++ b/packages/interface-ipfs-core/src/swarm/peers.js @@ -1,12 +1,10 @@ /* eslint-env mocha */ -import { Multiaddr } from 'multiaddr' -import PeerId from 'peer-id' +import { Multiaddr } from '@multiformats/multiaddr' import delay from 'delay' import { isBrowser, isWebWorker } from 'ipfs-utils/src/env.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' -import { ipfsOptionsWebsocketsFilterAll } from '../utils/ipfs-options-websockets-filter-all.js' /** * @typedef {import('ipfsd-ctl').Factory} Factory @@ -14,10 +12,9 @@ import { ipfsOptionsWebsocketsFilterAll } from '../utils/ipfs-options-websockets /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testPeers (factory, options) { - const ipfsOptions = ipfsOptionsWebsocketsFilterAll() const describe = getDescribe(options) const it = getIt(options) @@ -32,7 +29,7 @@ export function testPeers (factory, options) { let ipfsBId before(async () => { - ipfsA = (await factory.spawn({ type: 'proc', ipfsOptions })).api + ipfsA = (await factory.spawn({ type: 'proc' })).api ipfsB = (await factory.spawn({ type: isWebWorker ? 'go' : undefined })).api ipfsBId = await ipfsB.id() await ipfsA.swarm.connect(ipfsBId.addresses[0]) @@ -51,8 +48,8 @@ export function testPeers (factory, options) { expect(peer).to.have.a.property('addr') expect(Multiaddr.isMultiaddr(peer.addr)).to.equal(true) - expect(peer).to.have.a.property('peer').that.is.a('string') - expect(PeerId.parse(peer.peer)).to.be.ok() + expect(peer).to.have.a.property('peer') + expect(peer.peer).to.be.ok() expect(peer).to.not.have.a.property('latency') /* TODO: These assertions must be uncommented as soon as @@ -101,7 +98,7 @@ export function testPeers (factory, options) { } it('should list peers only once', async () => { - const nodeA = (await factory.spawn({ type: 'proc', ipfsOptions })).api + const nodeA = (await factory.spawn({ type: 'proc' })).api const nodeB = (await factory.spawn({ type: isWebWorker ? 'go' : undefined })).api const nodeBId = await nodeB.id() await nodeA.swarm.connect(nodeBId.addresses[0]) @@ -128,8 +125,7 @@ export function testPeers (factory, options) { // browser nodes have webrtc-star addresses which can't be dialled by go so make the other // peer a js-ipfs node to get a tcp address that can be dialled. Also, webworkers are not // diable so don't use a in-proc node for webworkers - type: ((isBrowser && factory.opts.type === 'go') || isWebWorker) ? 'js' : 'proc', - ipfsOptions + type: ((isBrowser && factory.opts.type === 'go') || isWebWorker) ? 'js' : 'proc' })).api const nodeAId = await nodeA.id() const nodeB = (await factory.spawn({ diff --git a/packages/interface-ipfs-core/src/utils/create-sharded-directory.js b/packages/interface-ipfs-core/src/utils/create-sharded-directory.js index f651bf2404..c0532d5807 100644 --- a/packages/interface-ipfs-core/src/utils/create-sharded-directory.js +++ b/packages/interface-ipfs-core/src/utils/create-sharded-directory.js @@ -1,4 +1,4 @@ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import isShardAtPath from './is-shard-at-path.js' import last from 'it-last' diff --git a/packages/interface-ipfs-core/src/utils/create-two-shards.js b/packages/interface-ipfs-core/src/utils/create-two-shards.js index d864e8b46a..a5d3e74260 100644 --- a/packages/interface-ipfs-core/src/utils/create-two-shards.js +++ b/packages/interface-ipfs-core/src/utils/create-two-shards.js @@ -1,4 +1,4 @@ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import isShardAtPath from './is-shard-at-path.js' import last from 'it-last' diff --git a/packages/interface-ipfs-core/src/utils/index.js b/packages/interface-ipfs-core/src/utils/index.js index 29ff357131..ff980d0dba 100644 --- a/packages/interface-ipfs-core/src/utils/index.js +++ b/packages/interface-ipfs-core/src/utils/index.js @@ -1,13 +1,13 @@ import { CID } from 'multiformats/cid' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import loadFixture from 'aegir/utils/fixtures.js' +import loadFixture from 'aegir/fixtures' const ONE_MEG = Math.pow(2, 20) export const fixtures = Object.freeze({ directory: Object.freeze({ cid: CID.parse('QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP'), - /** @type {Record} */ + /** @type {Record} */ files: Object.freeze({ 'pp.txt': loadFixture('test/fixtures/test-folder/pp.txt', 'interface-ipfs-core'), 'holmes.txt': loadFixture('test/fixtures/test-folder/holmes.txt', 'interface-ipfs-core'), diff --git a/packages/interface-ipfs-core/src/utils/ipfs-options-websockets-filter-all.js b/packages/interface-ipfs-core/src/utils/ipfs-options-websockets-filter-all.js index a806e0ec83..93be503ae0 100644 --- a/packages/interface-ipfs-core/src/utils/ipfs-options-websockets-filter-all.js +++ b/packages/interface-ipfs-core/src/utils/ipfs-options-websockets-filter-all.js @@ -1,9 +1,7 @@ -// @ts-expect-error no types -import WS from 'libp2p-websockets' -// @ts-expect-error no types -import filters from 'libp2p-websockets/src/filters.js' +import { WebSockets } from '@libp2p/websockets' +import { all } from '@libp2p/websockets/filters' -const transportKey = WS.prototype[Symbol.toStringTag] +const transportKey = WebSockets.prototype[Symbol.toStringTag] export function ipfsOptionsWebsocketsFilterAll () { return { @@ -11,7 +9,7 @@ export function ipfsOptionsWebsocketsFilterAll () { config: { transport: { [transportKey]: { - filter: filters.all + filter: all } } } diff --git a/packages/ipfs-cli/package.json b/packages/ipfs-cli/package.json index ee0f8e7647..8a590459ea 100644 --- a/packages/ipfs-cli/package.json +++ b/packages/ipfs-cli/package.json @@ -49,7 +49,7 @@ "url": "git+https://github.com/ipfs/js-ipfs.git" }, "scripts": { - "lint": "aegir ts -p check && aegir lint", + "lint": "aegir lint", "test": "npm run test:node", "test:node": "aegir test -t node --cov", "clean": "rimraf ./dist", @@ -60,11 +60,15 @@ "@ipld/dag-cbor": "^7.0.0", "@ipld/dag-json": "^8.0.1", "@ipld/dag-pb": "^2.1.3", + "@libp2p/crypto": "^0.22.9", + "@multiformats/mafmt": "^11.0.2", + "@multiformats/multiaddr": "^10.0.0", + "@multiformats/multiaddr-to-uri": "^9.0.1", "byteman": "^1.3.5", "debug": "^4.1.1", "err-code": "^3.0.1", - "execa": "^5.0.0", - "get-folder-size": "^2.0.1", + "execa": "^6.1.0", + "get-folder-size": "^3.1.0", "ipfs-core": "^0.14.2", "ipfs-core-types": "^0.10.2", "ipfs-core-utils": "^0.14.2", @@ -78,35 +82,30 @@ "it-glob": "^1.0.0", "it-map": "^1.0.5", "it-merge": "^1.0.3", - "it-pipe": "^1.1.0", + "it-pipe": "^2.0.3", "it-split": "^1.0.0", - "it-tar": "^4.0.0", + "it-tar": "^5.0.0", "jsondiffpatch": "^0.4.1", - "libp2p-crypto": "^0.21.1", - "mafmt": "^10.0.0", - "multiaddr": "^10.0.0", - "multiaddr-to-uri": "^8.0.0", "multiformats": "^9.5.1", "parse-duration": "^1.0.0", - "pretty-bytes": "^5.4.1", + "pretty-bytes": "^6.0.0", "progress": "^2.0.3", "stream-to-it": "^0.2.2", "uint8arrays": "^3.0.0", - "yargs": "^16.0.3" + "yargs": "^17.4.0" }, "devDependencies": { "@types/ncp": "^2.0.5", "@types/progress": "^2.0.3", - "@types/yargs": "^16.0.0", - "aegir": "^36.0.1", + "@types/yargs": "^17.0.10", + "aegir": "^37.0.11", "it-to-buffer": "^2.0.0", "nanoid": "^3.1.23", "ncp": "^2.0.0", "pako": "^2.0.4", - "peer-id": "^0.16.0", "rimraf": "^3.0.2", - "sinon": "^12.0.01", + "sinon": "^13.0.1", "string-argv": "^0.3.1", - "temp-write": "^4.0.0" + "temp-write": "^5.0.0" } } diff --git a/packages/ipfs-cli/src/commands/add.js b/packages/ipfs-cli/src/commands/add.js index c05657d027..c5bfdaeef1 100644 --- a/packages/ipfs-cli/src/commands/add.js +++ b/packages/ipfs-cli/src/commands/add.js @@ -254,6 +254,8 @@ export default { * @param {number} argv.mode * @param {string} argv.cidBase * @param {boolean} argv.enableShardingExperiment + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print, isDaemon, getStdin }, diff --git a/packages/ipfs-cli/src/commands/bitswap/stat.js b/packages/ipfs-cli/src/commands/bitswap/stat.js index ef759d86c8..bec871fd79 100644 --- a/packages/ipfs-cli/src/commands/bitswap/stat.js +++ b/packages/ipfs-cli/src/commands/bitswap/stat.js @@ -28,6 +28,8 @@ export default { * @param {boolean} argv.human * @param {string} argv.cidBase * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx, cidBase, human, timeout }) { const { ipfs, print } = ctx diff --git a/packages/ipfs-cli/src/commands/bitswap/unwant.js b/packages/ipfs-cli/src/commands/bitswap/unwant.js index a0ae111f40..3f7781399e 100644 --- a/packages/ipfs-cli/src/commands/bitswap/unwant.js +++ b/packages/ipfs-cli/src/commands/bitswap/unwant.js @@ -30,6 +30,8 @@ export default { * @param {import('multiformats/cid').CID} argv.key * @param {string} argv.cidBase * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx, key, cidBase, timeout }) { const { ipfs, print } = ctx diff --git a/packages/ipfs-cli/src/commands/bitswap/wantlist.js b/packages/ipfs-cli/src/commands/bitswap/wantlist.js index 1263886a53..2914a03b66 100644 --- a/packages/ipfs-cli/src/commands/bitswap/wantlist.js +++ b/packages/ipfs-cli/src/commands/bitswap/wantlist.js @@ -1,4 +1,5 @@ import parseDuration from 'parse-duration' +import { coercePeerId } from '../../utils.js' export default { command: 'wantlist [peer]', @@ -9,7 +10,8 @@ export default { peer: { alias: 'p', describe: 'Specify which peer to show wantlist for.', - type: 'string' + type: 'string', + coerce: coercePeerId }, 'cid-base': { describe: 'Number base to display CIDs in. Note: specifying a CID base for v0 CIDs will have no effect.', @@ -25,9 +27,11 @@ export default { /** * @param {object} argv * @param {import('../../types').Context} argv.ctx - * @param {string} argv.peer + * @param {import('@libp2p/interfaces/peer-id').PeerId} argv.peer * @param {string} argv.cidBase * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx, peer, cidBase, timeout }) { const { ipfs, print } = ctx diff --git a/packages/ipfs-cli/src/commands/block/get.js b/packages/ipfs-cli/src/commands/block/get.js index e717a898dc..fb7fe93a68 100644 --- a/packages/ipfs-cli/src/commands/block/get.js +++ b/packages/ipfs-cli/src/commands/block/get.js @@ -23,6 +23,8 @@ export default { * @param {import('../../types').Context} argv.ctx * @param {import('multiformats/cid').CID} argv.key * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx, key, timeout }) { const { ipfs, print } = ctx diff --git a/packages/ipfs-cli/src/commands/block/put.js b/packages/ipfs-cli/src/commands/block/put.js index 35e1165d61..cccd552973 100644 --- a/packages/ipfs-cli/src/commands/block/put.js +++ b/packages/ipfs-cli/src/commands/block/put.js @@ -53,6 +53,8 @@ export default { * @param {boolean} argv.pin * @param {string} argv.cidBase * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print, getStdin }, block, timeout, format, mhtype, mhlen, version, cidBase, pin }) { let data diff --git a/packages/ipfs-cli/src/commands/block/rm.js b/packages/ipfs-cli/src/commands/block/rm.js index 031052da39..1d06f762eb 100644 --- a/packages/ipfs-cli/src/commands/block/rm.js +++ b/packages/ipfs-cli/src/commands/block/rm.js @@ -36,6 +36,8 @@ export default { * @param {boolean} argv.force * @param {boolean} argv.quiet * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx, hash, force, quiet, timeout }) { const { ipfs, print } = ctx diff --git a/packages/ipfs-cli/src/commands/block/stat.js b/packages/ipfs-cli/src/commands/block/stat.js index 3885b7ee0f..ef9a50af79 100644 --- a/packages/ipfs-cli/src/commands/block/stat.js +++ b/packages/ipfs-cli/src/commands/block/stat.js @@ -28,6 +28,8 @@ export default { * @param {import('multiformats/cid').CID} argv.key * @param {string} argv.cidBase * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx, key, cidBase, timeout }) { const { ipfs, print } = ctx diff --git a/packages/ipfs-cli/src/commands/bootstrap/add.js b/packages/ipfs-cli/src/commands/bootstrap/add.js index 16414f4698..f7735609b5 100644 --- a/packages/ipfs-cli/src/commands/bootstrap/add.js +++ b/packages/ipfs-cli/src/commands/bootstrap/add.js @@ -25,9 +25,11 @@ export default { /** * @param {object} argv * @param {import('../../types').Context} argv.ctx - * @param {import('multiaddr').Multiaddr} argv.peer + * @param {import('@multiformats/multiaddr').Multiaddr} argv.peer * @param {boolean} argv.default * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, peer, default: defaultPeers, timeout }) { let list diff --git a/packages/ipfs-cli/src/commands/bootstrap/list.js b/packages/ipfs-cli/src/commands/bootstrap/list.js index 47cae16a56..b5e2a693a0 100644 --- a/packages/ipfs-cli/src/commands/bootstrap/list.js +++ b/packages/ipfs-cli/src/commands/bootstrap/list.js @@ -16,6 +16,8 @@ export default { * @param {object} argv * @param {import('../../types').Context} argv.ctx * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, timeout }) { const list = await ipfs.bootstrap.list({ diff --git a/packages/ipfs-cli/src/commands/bootstrap/rm.js b/packages/ipfs-cli/src/commands/bootstrap/rm.js index 71e6dd14dd..47359dcb52 100644 --- a/packages/ipfs-cli/src/commands/bootstrap/rm.js +++ b/packages/ipfs-cli/src/commands/bootstrap/rm.js @@ -25,9 +25,11 @@ export default { /** * @param {object} argv * @param {import('../../types').Context} argv.ctx - * @param {import('multiaddr').Multiaddr} argv.peer + * @param {import('@multiformats/multiaddr').Multiaddr} argv.peer * @param {boolean} argv.all * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, all, peer, timeout }) { let list diff --git a/packages/ipfs-cli/src/commands/cat.js b/packages/ipfs-cli/src/commands/cat.js index edd03bc683..94daef942e 100644 --- a/packages/ipfs-cli/src/commands/cat.js +++ b/packages/ipfs-cli/src/commands/cat.js @@ -29,6 +29,8 @@ export default { * @param {number} argv.offset * @param {number} argv.length * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, ipfsPath, offset, length, timeout }) { for await (const buf of ipfs.cat(ipfsPath, { offset, length, timeout })) { diff --git a/packages/ipfs-cli/src/commands/cid/base32.js b/packages/ipfs-cli/src/commands/cid/base32.js index e1a7c802e0..6a29f330f7 100644 --- a/packages/ipfs-cli/src/commands/cid/base32.js +++ b/packages/ipfs-cli/src/commands/cid/base32.js @@ -11,6 +11,8 @@ export default { * @param {object} argv * @param {import('../../types').Context} argv.ctx * @param {string[]} [argv.cids] + * + * @returns {Promise} */ async handler ({ ctx: { print, getStdin }, cids }) { let input diff --git a/packages/ipfs-cli/src/commands/cid/bases.js b/packages/ipfs-cli/src/commands/cid/bases.js index 7c79ba128e..222a5fa19e 100644 --- a/packages/ipfs-cli/src/commands/cid/bases.js +++ b/packages/ipfs-cli/src/commands/cid/bases.js @@ -22,6 +22,8 @@ export default { * @param {import('../../types').Context} argv.ctx * @param {boolean} [argv.prefix] * @param {boolean} [argv.numeric] + * + * @returns {void} */ handler ({ ctx: { ipfs, print }, prefix, numeric }) { for (const base of ipfs.bases.listBases()) { diff --git a/packages/ipfs-cli/src/commands/cid/codecs.js b/packages/ipfs-cli/src/commands/cid/codecs.js index 9551f3f718..2cad668e18 100644 --- a/packages/ipfs-cli/src/commands/cid/codecs.js +++ b/packages/ipfs-cli/src/commands/cid/codecs.js @@ -16,6 +16,8 @@ export default { * @param {object} argv * @param {import('../../types').Context} argv.ctx * @param {boolean} [argv.numeric] + * + * @returns {void} */ handler ({ ctx: { ipfs, print }, numeric }) { for (const codec of ipfs.codecs.listCodecs()) { diff --git a/packages/ipfs-cli/src/commands/cid/format.js b/packages/ipfs-cli/src/commands/cid/format.js index 730e9a86a0..df5348b7c3 100644 --- a/packages/ipfs-cli/src/commands/cid/format.js +++ b/packages/ipfs-cli/src/commands/cid/format.js @@ -52,6 +52,8 @@ export default { * @param {string} [argv.format] * @param {import('multiformats/cid').CIDVersion} [argv.cidVersion] * @param {string} [argv.base] + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print, getStdin }, cids, format, cidVersion, base }) { let input diff --git a/packages/ipfs-cli/src/commands/cid/hashes.js b/packages/ipfs-cli/src/commands/cid/hashes.js index eb2159fda9..51b9150323 100644 --- a/packages/ipfs-cli/src/commands/cid/hashes.js +++ b/packages/ipfs-cli/src/commands/cid/hashes.js @@ -16,6 +16,8 @@ export default { * @param {object} argv * @param {import('../../types').Context} argv.ctx * @param {boolean} [argv.numeric] + * + * @returns {void} */ handler ({ ctx: { ipfs, print }, numeric }) { for (const codec of ipfs.hashers.listHashers()) { diff --git a/packages/ipfs-cli/src/commands/commands.js b/packages/ipfs-cli/src/commands/commands.js index 3a2d69c1a5..1c0285a144 100644 --- a/packages/ipfs-cli/src/commands/commands.js +++ b/packages/ipfs-cli/src/commands/commands.js @@ -3,9 +3,6 @@ import glob from 'it-glob' import all from 'it-all' import { fileURLToPath } from 'url' -// @ts-ignore need to set module to es2020 to use import.meta.url, which we do, -// but then the "--module" setting doesn't get used by the "--build" setting -// which we use to build types from jsdoc const __dirname = dirname(fileURLToPath(import.meta.url)) export default { @@ -16,6 +13,8 @@ export default { /** * @param {object} argv * @param {import('../types').Context} argv.ctx + * + * @returns {Promise} */ async handler ({ ctx }) { const { print } = ctx diff --git a/packages/ipfs-cli/src/commands/config.js b/packages/ipfs-cli/src/commands/config.js index a707b72b82..f6a3697cf9 100644 --- a/packages/ipfs-cli/src/commands/config.js +++ b/packages/ipfs-cli/src/commands/config.js @@ -37,6 +37,8 @@ export default { * @param {boolean} argv.json * @param {string} argv.key * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, value, bool, json, key, timeout }) { if (!value) { diff --git a/packages/ipfs-cli/src/commands/config/edit.js b/packages/ipfs-cli/src/commands/config/edit.js index f1040b1dd5..b49c1f5866 100644 --- a/packages/ipfs-cli/src/commands/config/edit.js +++ b/packages/ipfs-cli/src/commands/config/edit.js @@ -1,5 +1,5 @@ import path from 'path' -import execa from 'execa' +import { execa } from 'execa' export default { command: 'edit', @@ -9,6 +9,8 @@ export default { /** * @param {object} argv * @param {import('../../types').Context} argv.ctx + * + * @returns {Promise} */ async handler (argv) { const editor = process.env.EDITOR diff --git a/packages/ipfs-cli/src/commands/config/profile/apply.js b/packages/ipfs-cli/src/commands/config/profile/apply.js index f4a5a7eb76..986389e561 100644 --- a/packages/ipfs-cli/src/commands/config/profile/apply.js +++ b/packages/ipfs-cli/src/commands/config/profile/apply.js @@ -24,6 +24,8 @@ export default { * @param {string} argv.profile * @param {boolean} argv.dryRun * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx, profile, dryRun, timeout }) { const { print, ipfs, isDaemon } = ctx diff --git a/packages/ipfs-cli/src/commands/config/profile/ls.js b/packages/ipfs-cli/src/commands/config/profile/ls.js index 33fa0ce7e4..357a1867c1 100644 --- a/packages/ipfs-cli/src/commands/config/profile/ls.js +++ b/packages/ipfs-cli/src/commands/config/profile/ls.js @@ -16,6 +16,8 @@ export default { * @param {object} argv * @param {import('../../../types').Context} argv.ctx * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, timeout }) { for (const profile of await ipfs.config.profiles.list({ diff --git a/packages/ipfs-cli/src/commands/config/replace.js b/packages/ipfs-cli/src/commands/config/replace.js index 1f55d4069a..30a2ddbbde 100644 --- a/packages/ipfs-cli/src/commands/config/replace.js +++ b/packages/ipfs-cli/src/commands/config/replace.js @@ -19,6 +19,8 @@ export default { * @param {import('../../types').Context} argv.ctx * @param {string} argv.file * @param {number} argv.timeout + * + * @returns {Promise} */ handler ({ ctx: { ipfs, isDaemon }, file, timeout }) { const filePath = path.resolve(process.cwd(), file) diff --git a/packages/ipfs-cli/src/commands/config/show.js b/packages/ipfs-cli/src/commands/config/show.js index 31377cc3e5..845cf51269 100644 --- a/packages/ipfs-cli/src/commands/config/show.js +++ b/packages/ipfs-cli/src/commands/config/show.js @@ -16,6 +16,8 @@ export default { * @param {object} argv * @param {import('../../types').Context} argv.ctx * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, timeout }) { const config = await ipfs.config.getAll({ diff --git a/packages/ipfs-cli/src/commands/daemon.js b/packages/ipfs-cli/src/commands/daemon.js index 5f826ed1d0..81ee5c0046 100644 --- a/packages/ipfs-cli/src/commands/daemon.js +++ b/packages/ipfs-cli/src/commands/daemon.js @@ -4,10 +4,10 @@ import fs from 'fs' import toUri from 'multiaddr-to-uri' import { ipfsPathHelp } from '../utils.js' import { isTest } from 'ipfs-utils/src/env.js' -import debug from 'debug' +import { logger } from '@libp2p/logger' import { Daemon } from 'ipfs-daemon' -const log = debug('ipfs:cli:daemon') +const log = logger('ipfs:cli:daemon') export default { command: 'daemon', @@ -62,6 +62,8 @@ export default { * @param {boolean} argv.silent * @param {boolean} argv.migrate * @param {string} argv.pass + * + * @returns {Promise} */ async handler (argv) { const { print, repoPath } = argv.ctx @@ -109,7 +111,6 @@ export default { }) } - // @ts-ignore - _httpGateway is possibly undefined if (daemon._grpcServer && daemon._grpcServer) { print(`gRPC listening on ${daemon._grpcServer.info.ma}`) } diff --git a/packages/ipfs-cli/src/commands/dag/export.js b/packages/ipfs-cli/src/commands/dag/export.js index bfaa61b014..66d9b7cbd7 100644 --- a/packages/ipfs-cli/src/commands/dag/export.js +++ b/packages/ipfs-cli/src/commands/dag/export.js @@ -18,6 +18,8 @@ export default { * @param {import('../../types').Context} argv.ctx * @param {string} argv.rootcid * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, rootcid, timeout }) { const options = { timeout } diff --git a/packages/ipfs-cli/src/commands/dag/get.js b/packages/ipfs-cli/src/commands/dag/get.js index ebcaffa0f8..90fe723d31 100644 --- a/packages/ipfs-cli/src/commands/dag/get.js +++ b/packages/ipfs-cli/src/commands/dag/get.js @@ -51,6 +51,8 @@ export default { * @param {'base16' | 'base64' | 'base58btc'} argv.dataEnc * @param {boolean} argv.localResolve * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, cidpath, dataEnc, outputCodec, localResolve, timeout }) { const options = { diff --git a/packages/ipfs-cli/src/commands/dag/import.js b/packages/ipfs-cli/src/commands/dag/import.js index d49c941627..b069f4eb6c 100644 --- a/packages/ipfs-cli/src/commands/dag/import.js +++ b/packages/ipfs-cli/src/commands/dag/import.js @@ -30,6 +30,8 @@ export default { * @param {boolean} argv.pinRoots * @param {number} argv.timeout * @param {string} argv.cidBase + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print, getStdin }, path, pinRoots, timeout, cidBase }) { const handleResult = async (/** @type {import('ipfs-core-types/src/dag').ImportResult} */ { root }) => { diff --git a/packages/ipfs-cli/src/commands/dag/put.js b/packages/ipfs-cli/src/commands/dag/put.js index c17c096e2a..2ba0400452 100644 --- a/packages/ipfs-cli/src/commands/dag/put.js +++ b/packages/ipfs-cli/src/commands/dag/put.js @@ -89,6 +89,8 @@ export default { * @param {boolean} argv.preload * @param {boolean} argv.onlyHash * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print, getStdin }, data, inputCodec, storeCodec, pin, hashAlg, cidVersion, cidBase, preload, onlyHash, timeout }) { if (!codecs[inputCodec]) { diff --git a/packages/ipfs-cli/src/commands/dag/resolve.js b/packages/ipfs-cli/src/commands/dag/resolve.js index 4680fde036..8c30046c43 100644 --- a/packages/ipfs-cli/src/commands/dag/resolve.js +++ b/packages/ipfs-cli/src/commands/dag/resolve.js @@ -20,6 +20,8 @@ export default { * @param {import('../../types').Context} argv.ctx * @param {string} argv.ref * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, ref, timeout }) { const options = { @@ -36,7 +38,7 @@ export default { ref = ref.substring(6) } - // @ts-ignore we will toString this so it doesn't matter + // @ts-expect-error we will toString this so it doesn't matter lastCid = ref.split('/').shift() } diff --git a/packages/ipfs-cli/src/commands/dht/find-peer.js b/packages/ipfs-cli/src/commands/dht/find-peer.js index 880bbcad91..9029bf4380 100644 --- a/packages/ipfs-cli/src/commands/dht/find-peer.js +++ b/packages/ipfs-cli/src/commands/dht/find-peer.js @@ -1,4 +1,5 @@ import parseDuration from 'parse-duration' +import { coercePeerId } from '../../utils.js' export default { command: 'findpeer ', @@ -7,7 +8,8 @@ export default { builder: { peerId: { - type: 'string' + type: 'string', + coerce: coercePeerId }, timeout: { type: 'string', @@ -18,8 +20,10 @@ export default { /** * @param {object} argv * @param {import('../../types').Context} argv.ctx - * @param {string} argv.peerId + * @param {import('@libp2p/interfaces/peer-id').PeerId} argv.peerId * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, peerId, timeout }) { for await (const event of ipfs.dht.findPeer(peerId, { diff --git a/packages/ipfs-cli/src/commands/dht/find-providers.js b/packages/ipfs-cli/src/commands/dht/find-providers.js index 3409f5a6b3..348a932ec1 100644 --- a/packages/ipfs-cli/src/commands/dht/find-providers.js +++ b/packages/ipfs-cli/src/commands/dht/find-providers.js @@ -29,6 +29,8 @@ export default { * @param {import('multiformats/cid').CID} argv.key * @param {number} argv.numProviders * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, key, numProviders, timeout }) { const providers = new Set() diff --git a/packages/ipfs-cli/src/commands/dht/get.js b/packages/ipfs-cli/src/commands/dht/get.js index 58f957f1ec..468b5e6b93 100644 --- a/packages/ipfs-cli/src/commands/dht/get.js +++ b/packages/ipfs-cli/src/commands/dht/get.js @@ -23,6 +23,8 @@ export default { * @param {import('../../types').Context} argv.ctx * @param {import('multiformats/cid').CID} argv.key * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, key, timeout }) { for await (const event of await ipfs.dht.get(key.bytes, { diff --git a/packages/ipfs-cli/src/commands/dht/provide.js b/packages/ipfs-cli/src/commands/dht/provide.js index 8ad7cb33bb..5bf232761f 100644 --- a/packages/ipfs-cli/src/commands/dht/provide.js +++ b/packages/ipfs-cli/src/commands/dht/provide.js @@ -29,6 +29,8 @@ export default { * @param {import('multiformats/cid').CID} argv.key * @param {boolean} argv.recursive * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs }, key, recursive, timeout }) { await ipfs.dht.provide(key, { diff --git a/packages/ipfs-cli/src/commands/dht/put.js b/packages/ipfs-cli/src/commands/dht/put.js index f290867226..6a93230739 100644 --- a/packages/ipfs-cli/src/commands/dht/put.js +++ b/packages/ipfs-cli/src/commands/dht/put.js @@ -19,6 +19,8 @@ export default { * @param {string} argv.key * @param {string} argv.value * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs }, key, value, timeout }) { await ipfs.dht.put(uint8ArrayFromString(key), uint8ArrayFromString(value), { diff --git a/packages/ipfs-cli/src/commands/dht/query.js b/packages/ipfs-cli/src/commands/dht/query.js index b09fb5845d..650c4b0423 100644 --- a/packages/ipfs-cli/src/commands/dht/query.js +++ b/packages/ipfs-cli/src/commands/dht/query.js @@ -1,4 +1,5 @@ import parseDuration from 'parse-duration' +import { coercePeerId } from '../../utils.js' export default { command: 'query ', @@ -7,7 +8,12 @@ export default { builder: { peerId: { - type: 'string' + type: 'string', + coerce: coercePeerId + }, + count: { + type: 'number', + default: 20 }, timeout: { type: 'string', @@ -18,24 +24,37 @@ export default { /** * @param {object} argv * @param {import('../../types').Context} argv.ctx - * @param {string} argv.peerId + * @param {import('@libp2p/interfaces/peer-id').PeerId} argv.peerId * @param {number} argv.timeout + * @param {number} argv.count + * + * @returns {Promise} */ - async handler ({ ctx: { ipfs, print }, peerId, timeout }) { + async handler ({ ctx: { ipfs, print }, peerId, timeout, count }) { const seen = new Set() for await (const event of ipfs.dht.query(peerId, { timeout })) { if (event.name === 'PEER_RESPONSE') { - event.closer.forEach(peerData => { - if (seen.has(peerData.id)) { + for (const peerData of event.closer) { + const peerId = peerData.id.toString() + + if (seen.has(peerId)) { + continue + } + + print(peerId) + seen.add(peerId) + + if (seen.size === count) { return } + } + } - print(peerData.id) - seen.add(peerData.id) - }) + if (event.name === 'FINAL_PEER') { + return } } } diff --git a/packages/ipfs-cli/src/commands/dns.js b/packages/ipfs-cli/src/commands/dns.js index dd1394ed70..1606ff3977 100644 --- a/packages/ipfs-cli/src/commands/dns.js +++ b/packages/ipfs-cli/src/commands/dns.js @@ -27,6 +27,8 @@ export default { * @param {string} argv.domain * @param {boolean} argv.recursive * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, domain, recursive, timeout }) { const path = await ipfs.dns(domain, { recursive, timeout }) diff --git a/packages/ipfs-cli/src/commands/files.js b/packages/ipfs-cli/src/commands/files.js index 0c4d99ce06..87aa218ed9 100644 --- a/packages/ipfs-cli/src/commands/files.js +++ b/packages/ipfs-cli/src/commands/files.js @@ -16,6 +16,8 @@ export default { /** * @param {object} argv * @param {import('../types').Context} argv.ctx + * + * @returns {void} */ handler (argv) { argv.ctx.print('Type `jsipfs files --help` for more instructions') diff --git a/packages/ipfs-cli/src/commands/files/chmod.js b/packages/ipfs-cli/src/commands/files/chmod.js index e5031ae1a8..0f1efe1486 100644 --- a/packages/ipfs-cli/src/commands/files/chmod.js +++ b/packages/ipfs-cli/src/commands/files/chmod.js @@ -58,8 +58,10 @@ export default { * @param {boolean} argv.flush * @param {number} argv.shardSplitThreshold * @param {number} argv.timeout + * + * @returns {Promise} */ - handler ({ + async handler ({ ctx: { ipfs }, path, mode, @@ -69,7 +71,7 @@ export default { shardSplitThreshold, timeout }) { - return ipfs.files.chmod(path, mode, { + await ipfs.files.chmod(path, mode, { recursive, hashAlg, flush, diff --git a/packages/ipfs-cli/src/commands/files/cp.js b/packages/ipfs-cli/src/commands/files/cp.js index d84120c49a..99870919d5 100644 --- a/packages/ipfs-cli/src/commands/files/cp.js +++ b/packages/ipfs-cli/src/commands/files/cp.js @@ -50,8 +50,10 @@ export default { * @param {boolean} argv.flush * @param {number} argv.shardSplitThreshold * @param {number} argv.timeout + * + * @returns {Promise} */ - handler ({ + async handler ({ ctx: { ipfs }, source, dest, @@ -61,7 +63,7 @@ export default { shardSplitThreshold, timeout }) { - return ipfs.files.cp(source, dest, { + await ipfs.files.cp(source, dest, { parents, flush, hashAlg, diff --git a/packages/ipfs-cli/src/commands/files/flush.js b/packages/ipfs-cli/src/commands/files/flush.js index 9113070e24..35874568e9 100644 --- a/packages/ipfs-cli/src/commands/files/flush.js +++ b/packages/ipfs-cli/src/commands/files/flush.js @@ -22,6 +22,8 @@ export default { * @param {string} argv.path * @param {string} argv.cidBase * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, diff --git a/packages/ipfs-cli/src/commands/files/ls.js b/packages/ipfs-cli/src/commands/files/ls.js index eb65e08123..2dfb78a772 100644 --- a/packages/ipfs-cli/src/commands/files/ls.js +++ b/packages/ipfs-cli/src/commands/files/ls.js @@ -36,6 +36,8 @@ export default { * @param {boolean} argv.long * @param {string} argv.cidBase * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, diff --git a/packages/ipfs-cli/src/commands/files/mkdir.js b/packages/ipfs-cli/src/commands/files/mkdir.js index 2fb5b1cefd..16467d25b3 100644 --- a/packages/ipfs-cli/src/commands/files/mkdir.js +++ b/packages/ipfs-cli/src/commands/files/mkdir.js @@ -78,8 +78,10 @@ export default { * @param {number} argv.mtime * @param {number} argv.mtimeNsecs * @param {number} argv.timeout + * + * @returns {Promise} */ - handler ({ + async handler ({ ctx: { ipfs }, path, parents, @@ -92,7 +94,7 @@ export default { mtimeNsecs, timeout }) { - return ipfs.files.mkdir(path, { + await ipfs.files.mkdir(path, { parents, cidVersion, hashAlg, diff --git a/packages/ipfs-cli/src/commands/files/mv.js b/packages/ipfs-cli/src/commands/files/mv.js index d3e6909745..fe329e38a2 100644 --- a/packages/ipfs-cli/src/commands/files/mv.js +++ b/packages/ipfs-cli/src/commands/files/mv.js @@ -57,8 +57,10 @@ export default { * @param {boolean} argv.flush * @param {number} argv.shardSplitThreshold * @param {number} argv.timeout + * + * @returns {Promise} */ - handler ({ + async handler ({ ctx: { ipfs }, source, dest, @@ -69,7 +71,7 @@ export default { shardSplitThreshold, timeout }) { - return ipfs.files.mv(source, dest, { + await ipfs.files.mv(source, dest, { parents, cidVersion, hashAlg, diff --git a/packages/ipfs-cli/src/commands/files/read.js b/packages/ipfs-cli/src/commands/files/read.js index 6321514bb7..8066701697 100644 --- a/packages/ipfs-cli/src/commands/files/read.js +++ b/packages/ipfs-cli/src/commands/files/read.js @@ -29,6 +29,8 @@ export default { * @param {number} argv.offset * @param {number} argv.length * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, diff --git a/packages/ipfs-cli/src/commands/files/rm.js b/packages/ipfs-cli/src/commands/files/rm.js index 0f2ee6f5a8..ae0911e3e0 100644 --- a/packages/ipfs-cli/src/commands/files/rm.js +++ b/packages/ipfs-cli/src/commands/files/rm.js @@ -28,14 +28,16 @@ export default { * @param {string} argv.path * @param {boolean} argv.recursive * @param {number} argv.timeout + * + * @returns {Promise} */ - handler ({ + async handler ({ ctx: { ipfs }, path, recursive, timeout }) { - return ipfs.files.rm(path, { + await ipfs.files.rm(path, { recursive, timeout }) diff --git a/packages/ipfs-cli/src/commands/files/stat.js b/packages/ipfs-cli/src/commands/files/stat.js index 3cd1c7e0e6..fde92b6e0b 100644 --- a/packages/ipfs-cli/src/commands/files/stat.js +++ b/packages/ipfs-cli/src/commands/files/stat.js @@ -64,6 +64,8 @@ Mtime: `, * @param {boolean} argv.withLocal * @param {string} argv.cidBase * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, diff --git a/packages/ipfs-cli/src/commands/files/touch.js b/packages/ipfs-cli/src/commands/files/touch.js index de422ca0fa..cd63687795 100644 --- a/packages/ipfs-cli/src/commands/files/touch.js +++ b/packages/ipfs-cli/src/commands/files/touch.js @@ -64,8 +64,10 @@ export default { * @param {number} argv.mtime * @param {number} argv.mtimeNsecs * @param {number} argv.timeout + * + * @returns {Promise} */ - handler ({ + async handler ({ ctx: { ipfs }, path, flush, @@ -76,7 +78,7 @@ export default { mtimeNsecs, timeout }) { - return ipfs.files.touch(path, { + await ipfs.files.touch(path, { mtime: asMtimeFromSeconds(mtime, mtimeNsecs), flush, cidVersion, diff --git a/packages/ipfs-cli/src/commands/files/write.js b/packages/ipfs-cli/src/commands/files/write.js index 8e6a953f30..31a95f6d75 100644 --- a/packages/ipfs-cli/src/commands/files/write.js +++ b/packages/ipfs-cli/src/commands/files/write.js @@ -125,6 +125,8 @@ export default { * @param {number} argv.mtime * @param {number} argv.mtimeNsecs * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, getStdin }, diff --git a/packages/ipfs-cli/src/commands/get.js b/packages/ipfs-cli/src/commands/get.js index ed5ec9c09a..a9769b7a07 100644 --- a/packages/ipfs-cli/src/commands/get.js +++ b/packages/ipfs-cli/src/commands/get.js @@ -58,6 +58,8 @@ export default { * @param {boolean} argv.archive * @param {boolean} argv.compress * @param {-1 | 0 | 1 | 2 | 3 | 4 | 5 | 6| 7 | 8| 9} argv.compressionLevel + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, ipfsPath, output, force, timeout, archive, compress, compressionLevel }) { print(`Saving file(s) ${stripControlCharacters(ipfsPath)}`) @@ -108,9 +110,6 @@ export default { await fs.promises.mkdir(path.dirname(outputPath), { recursive: true }) await pipe( body, - /** - * @param {AsyncIterable} source - */ (source) => map(source, buf => buf.slice()), toIterable.sink(fs.createWriteStream(outputPath)) ) diff --git a/packages/ipfs-cli/src/commands/id.js b/packages/ipfs-cli/src/commands/id.js index 27ba9d5613..d0fc9a5b42 100644 --- a/packages/ipfs-cli/src/commands/id.js +++ b/packages/ipfs-cli/src/commands/id.js @@ -1,4 +1,5 @@ import parseDuration from 'parse-duration' +import { coercePeerId } from '../utils.js' export default { command: 'id [peerId]', @@ -8,7 +9,8 @@ export default { builder: { peerid: { type: 'string', - describe: 'Peer.ID of node to look up' + describe: 'Peer.ID of node to look up', + coerce: coercePeerId }, format: { alias: 'f', @@ -26,7 +28,9 @@ export default { * @param {import('../types').Context} argv.ctx * @param {string} argv.format * @param {number} argv.timeout - * @param {string} [argv.peerId] + * @param {import('@libp2p/interfaces/peer-id').PeerId} [argv.peerId] + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, format, timeout, peerId }) { const id = await ipfs.id({ @@ -36,7 +40,7 @@ export default { if (format) { print(format - .replace('', id.id) + .replace('', id.id.toString()) .replace('', id.agentVersion) .replace('', id.protocolVersion) .replace('', id.publicKey) diff --git a/packages/ipfs-cli/src/commands/init.js b/packages/ipfs-cli/src/commands/init.js index 1d768f92c4..fd54510cab 100644 --- a/packages/ipfs-cli/src/commands/init.js +++ b/packages/ipfs-cli/src/commands/init.js @@ -1,9 +1,9 @@ import fs from 'fs' -import debug from 'debug' +import { logger } from '@libp2p/logger' import { ipfsPathHelp } from '../utils.js' import * as IPFS from 'ipfs-core' -const log = debug('ipfs:cli:init') +const log = logger('ipfs:cli:init') /** @type {Record} */ const keyTypes = { @@ -73,6 +73,8 @@ export default { * @param {string} argv.privateKey * @param {string[]} argv.profile * @param {string} argv.pass + * + * @returns {Promise} */ async handler (argv) { const { print, repoPath } = argv.ctx @@ -102,7 +104,6 @@ export default { }, pass: argv.pass, start: false, - // @ts-ignore - Expects more than {} config }) } catch (/** @type {any} */ err) { diff --git a/packages/ipfs-cli/src/commands/key/export.js b/packages/ipfs-cli/src/commands/key/export.js index ae63c8746e..b86cd671b0 100644 --- a/packages/ipfs-cli/src/commands/key/export.js +++ b/packages/ipfs-cli/src/commands/key/export.js @@ -32,6 +32,8 @@ export default { * @param {string} argv.passout * @param {string} argv.output * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx, name, passout, output, timeout }) { const { ipfs } = ctx diff --git a/packages/ipfs-cli/src/commands/key/gen.js b/packages/ipfs-cli/src/commands/key/gen.js index 55087da4c9..108c28de38 100644 --- a/packages/ipfs-cli/src/commands/key/gen.js +++ b/packages/ipfs-cli/src/commands/key/gen.js @@ -34,10 +34,12 @@ export default { * @param {string} argv.type * @param {number} argv.size * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, name, type, size, timeout }) { const key = await ipfs.key.gen(name, { - type, + type: type.toLowerCase() === 'rsa' ? 'RSA' : 'Ed25519', size, timeout }) diff --git a/packages/ipfs-cli/src/commands/key/import.js b/packages/ipfs-cli/src/commands/key/import.js index 8489c4cf02..b66161c8b2 100644 --- a/packages/ipfs-cli/src/commands/key/import.js +++ b/packages/ipfs-cli/src/commands/key/import.js @@ -35,6 +35,8 @@ export default { * @param {string} argv.input * @param {string} argv.passin * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, name, input, passin, timeout }) { const key = await ipfs.key.import(name, input, passin, { diff --git a/packages/ipfs-cli/src/commands/key/list.js b/packages/ipfs-cli/src/commands/key/list.js index 2177d7e499..be9ae12f40 100644 --- a/packages/ipfs-cli/src/commands/key/list.js +++ b/packages/ipfs-cli/src/commands/key/list.js @@ -19,6 +19,8 @@ export default { * @param {object} argv * @param {import('../../types').Context} argv.ctx * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, timeout }) { const keys = await ipfs.key.list({ diff --git a/packages/ipfs-cli/src/commands/key/rename.js b/packages/ipfs-cli/src/commands/key/rename.js index 4928cc823d..03cd73ee6b 100644 --- a/packages/ipfs-cli/src/commands/key/rename.js +++ b/packages/ipfs-cli/src/commands/key/rename.js @@ -21,6 +21,8 @@ export default { * @param {string} argv.name * @param {string} argv.newName * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, name, newName, timeout }) { const res = await ipfs.key.rename(name, newName, { diff --git a/packages/ipfs-cli/src/commands/key/rm.js b/packages/ipfs-cli/src/commands/key/rm.js index 259bb7ed44..ec00aca745 100644 --- a/packages/ipfs-cli/src/commands/key/rm.js +++ b/packages/ipfs-cli/src/commands/key/rm.js @@ -20,6 +20,8 @@ export default { * @param {import('../../types').Context} argv.ctx * @param {string} argv.name * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, name, timeout }) { const key = await ipfs.key.rm(name, { diff --git a/packages/ipfs-cli/src/commands/ls.js b/packages/ipfs-cli/src/commands/ls.js index 813a52fe14..80efc6d342 100644 --- a/packages/ipfs-cli/src/commands/ls.js +++ b/packages/ipfs-cli/src/commands/ls.js @@ -33,6 +33,8 @@ export default { * @param {boolean} argv.headers * @param {string} argv.cidBase * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, key, headers, cidBase, timeout }) { // replace multiple slashes diff --git a/packages/ipfs-cli/src/commands/name.js b/packages/ipfs-cli/src/commands/name.js index 9065edb637..157513cba7 100644 --- a/packages/ipfs-cli/src/commands/name.js +++ b/packages/ipfs-cli/src/commands/name.js @@ -16,7 +16,7 @@ export default { */ builder (yargs) { commands.forEach(command => { - // @ts-ignore types are wrong + // @ts-expect-error types are wrong yargs.command(command) }) diff --git a/packages/ipfs-cli/src/commands/name/publish.js b/packages/ipfs-cli/src/commands/name/publish.js index 9e50d64b19..ed6b969a2e 100644 --- a/packages/ipfs-cli/src/commands/name/publish.js +++ b/packages/ipfs-cli/src/commands/name/publish.js @@ -50,6 +50,8 @@ export default { * @param {string} argv.key * @param {string} argv.ttl * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, ipfsPath, resolve, lifetime, key, ttl, timeout }) { const result = await ipfs.name.publish(ipfsPath, { diff --git a/packages/ipfs-cli/src/commands/name/pubsub/cancel.js b/packages/ipfs-cli/src/commands/name/pubsub/cancel.js index db386a1083..80b5e69d64 100644 --- a/packages/ipfs-cli/src/commands/name/pubsub/cancel.js +++ b/packages/ipfs-cli/src/commands/name/pubsub/cancel.js @@ -17,6 +17,8 @@ export default { * @param {import('../../../types').Context} argv.ctx * @param {string} argv.name * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, name, timeout }) { const result = await ipfs.name.pubsub.cancel(name, { diff --git a/packages/ipfs-cli/src/commands/name/pubsub/state.js b/packages/ipfs-cli/src/commands/name/pubsub/state.js index 4097a93ba4..e0f1fe46d5 100644 --- a/packages/ipfs-cli/src/commands/name/pubsub/state.js +++ b/packages/ipfs-cli/src/commands/name/pubsub/state.js @@ -16,6 +16,8 @@ export default { * @param {object} argv * @param {import('../../../types').Context} argv.ctx * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, timeout }) { const result = await ipfs.name.pubsub.state({ diff --git a/packages/ipfs-cli/src/commands/name/pubsub/subs.js b/packages/ipfs-cli/src/commands/name/pubsub/subs.js index d0f708334f..0ba9f8fc28 100644 --- a/packages/ipfs-cli/src/commands/name/pubsub/subs.js +++ b/packages/ipfs-cli/src/commands/name/pubsub/subs.js @@ -19,6 +19,8 @@ export default { * @param {object} argv * @param {import('../../../types').Context} argv.ctx * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, timeout }) { const result = await ipfs.name.pubsub.subs({ diff --git a/packages/ipfs-cli/src/commands/name/resolve.js b/packages/ipfs-cli/src/commands/name/resolve.js index b016382644..e848206dbf 100644 --- a/packages/ipfs-cli/src/commands/name/resolve.js +++ b/packages/ipfs-cli/src/commands/name/resolve.js @@ -38,6 +38,8 @@ export default { * @param {boolean} argv.recursive * @param {boolean} argv.stream * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, nocache, recursive, name, stream, timeout }) { let bestValue diff --git a/packages/ipfs-cli/src/commands/object/data.js b/packages/ipfs-cli/src/commands/object/data.js index c3d66fd84c..26c401aa8c 100644 --- a/packages/ipfs-cli/src/commands/object/data.js +++ b/packages/ipfs-cli/src/commands/object/data.js @@ -22,6 +22,8 @@ export default { * @param {import('../../types').Context} argv.ctx * @param {import('multiformats/cid').CID} argv.key * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, key, timeout }) { const data = await ipfs.object.data(key, { timeout }) diff --git a/packages/ipfs-cli/src/commands/object/get.js b/packages/ipfs-cli/src/commands/object/get.js index 00038d3ada..8d06ea0dbc 100644 --- a/packages/ipfs-cli/src/commands/object/get.js +++ b/packages/ipfs-cli/src/commands/object/get.js @@ -38,6 +38,8 @@ export default { * @param {'base64' | 'text' | 'hex'} argv.dataEncoding * @param {string} argv.cidBase * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, key, dataEncoding, cidBase, timeout }) { const node = await ipfs.object.get(key, { timeout }) @@ -61,7 +63,7 @@ export default { const base = await ipfs.bases.getBase(cidBase) const answer = { - // @ts-ignore encoding type is wrong + // @ts-expect-error encoding type is wrong Data: node.Data ? uint8ArrayToString(node.Data, encoding) : '', Hash: key.toString(base.encoder), Size: buf.length, diff --git a/packages/ipfs-cli/src/commands/object/links.js b/packages/ipfs-cli/src/commands/object/links.js index 0dbf1edde3..94d945977a 100644 --- a/packages/ipfs-cli/src/commands/object/links.js +++ b/packages/ipfs-cli/src/commands/object/links.js @@ -31,6 +31,8 @@ export default { * @param {import('multiformats/cid').CID} argv.key * @param {string} argv.cidBase * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, key, cidBase, timeout }) { const links = await ipfs.object.links(key, { timeout }) diff --git a/packages/ipfs-cli/src/commands/object/new.js b/packages/ipfs-cli/src/commands/object/new.js index eca8009337..830410b056 100644 --- a/packages/ipfs-cli/src/commands/object/new.js +++ b/packages/ipfs-cli/src/commands/object/new.js @@ -23,6 +23,8 @@ export default { * @param {'unixfs-dir'} argv.template * @param {string} argv.cidBase * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, template, cidBase, timeout }) { const cid = await ipfs.object.new({ diff --git a/packages/ipfs-cli/src/commands/object/patch/add-link.js b/packages/ipfs-cli/src/commands/object/patch/add-link.js index 728ffdccc2..373eb93657 100644 --- a/packages/ipfs-cli/src/commands/object/patch/add-link.js +++ b/packages/ipfs-cli/src/commands/object/patch/add-link.js @@ -35,6 +35,8 @@ export default { * @param {import('multiformats/cid').CID} argv.ref * @param {string} argv.cidBase * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, root, name, ref, cidBase, timeout }) { const nodeA = await ipfs.object.get(ref, { timeout }) diff --git a/packages/ipfs-cli/src/commands/object/patch/append-data.js b/packages/ipfs-cli/src/commands/object/patch/append-data.js index 76b5e9abc3..b534908f5a 100644 --- a/packages/ipfs-cli/src/commands/object/patch/append-data.js +++ b/packages/ipfs-cli/src/commands/object/patch/append-data.js @@ -31,6 +31,8 @@ export default { * @param {string} argv.data * @param {string} argv.cidBase * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print, getStdin }, root, data, cidBase, timeout }) { let buf diff --git a/packages/ipfs-cli/src/commands/object/patch/rm-link.js b/packages/ipfs-cli/src/commands/object/patch/rm-link.js index 07914e26b9..7367dc4eb3 100644 --- a/packages/ipfs-cli/src/commands/object/patch/rm-link.js +++ b/packages/ipfs-cli/src/commands/object/patch/rm-link.js @@ -29,6 +29,8 @@ export default { * @param {string} argv.link * @param {string} argv.cidBase * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, root, link, cidBase, timeout }) { const cid = await ipfs.object.patch.rmLink(root, link, { diff --git a/packages/ipfs-cli/src/commands/object/patch/set-data.js b/packages/ipfs-cli/src/commands/object/patch/set-data.js index db378918da..0516779b71 100644 --- a/packages/ipfs-cli/src/commands/object/patch/set-data.js +++ b/packages/ipfs-cli/src/commands/object/patch/set-data.js @@ -31,6 +31,8 @@ export default { * @param {string} argv.data * @param {string} argv.cidBase * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print, getStdin }, root, data, cidBase, timeout }) { let buf diff --git a/packages/ipfs-cli/src/commands/object/put.js b/packages/ipfs-cli/src/commands/object/put.js index 91f6774740..969c2ad218 100644 --- a/packages/ipfs-cli/src/commands/object/put.js +++ b/packages/ipfs-cli/src/commands/object/put.js @@ -33,6 +33,8 @@ export default { * @param {'json' | 'protobuf'} argv.inputEnc * @param {string} argv.cidBase * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print, getStdin }, data, inputEnc, cidBase, timeout }) { let buf diff --git a/packages/ipfs-cli/src/commands/object/stat.js b/packages/ipfs-cli/src/commands/object/stat.js index 03de4b8a4e..14b20122b1 100644 --- a/packages/ipfs-cli/src/commands/object/stat.js +++ b/packages/ipfs-cli/src/commands/object/stat.js @@ -22,6 +22,8 @@ export default { * @param {import('../../types').Context} argv.ctx * @param {import('multiformats/cid').CID} argv.key * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, key, timeout }) { const stats = await ipfs.object.stat(key, { timeout }) diff --git a/packages/ipfs-cli/src/commands/pin/add.js b/packages/ipfs-cli/src/commands/pin/add.js index 7d7277f18f..1b1e031fd7 100644 --- a/packages/ipfs-cli/src/commands/pin/add.js +++ b/packages/ipfs-cli/src/commands/pin/add.js @@ -61,6 +61,8 @@ export default { * @param {number} argv.timeout * @param {Record} argv.metadata * @param {Record} argv.metadataJson + * + * @returns {Promise} */ async handler ({ ctx, ipfsPath, recursive, cidBase, timeout, metadata, metadataJson }) { const { ipfs, print } = ctx diff --git a/packages/ipfs-cli/src/commands/pin/ls.js b/packages/ipfs-cli/src/commands/pin/ls.js index 83af72ac04..db661bf887 100644 --- a/packages/ipfs-cli/src/commands/pin/ls.js +++ b/packages/ipfs-cli/src/commands/pin/ls.js @@ -42,6 +42,8 @@ export default { * @param {boolean} argv.quiet * @param {string} argv.cidBase * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, ipfsPath, type, quiet, cidBase, timeout }) { const base = await ipfs.bases.getBase(cidBase) diff --git a/packages/ipfs-cli/src/commands/pin/rm.js b/packages/ipfs-cli/src/commands/pin/rm.js index 7fe9598274..ebc9dfe0a1 100644 --- a/packages/ipfs-cli/src/commands/pin/rm.js +++ b/packages/ipfs-cli/src/commands/pin/rm.js @@ -30,6 +30,8 @@ export default { * @param {boolean} argv.recursive * @param {string} argv.cidBase * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx, ipfsPath, timeout, recursive, cidBase }) { const { ipfs, print } = ctx diff --git a/packages/ipfs-cli/src/commands/ping.js b/packages/ipfs-cli/src/commands/ping.js index 782ea0b94d..37a479ce65 100644 --- a/packages/ipfs-cli/src/commands/ping.js +++ b/packages/ipfs-cli/src/commands/ping.js @@ -1,4 +1,5 @@ import parseDuration from 'parse-duration' +import { coercePeerId } from '../utils.js' export default { command: 'ping ', @@ -6,6 +7,11 @@ export default { description: 'Measure the latency of a connection', builder: { + peer: { + describe: 'Specify which peer to show wantlist for.', + type: 'string', + coerce: coercePeerId + }, count: { alias: 'n', type: 'integer', @@ -21,8 +27,10 @@ export default { * @param {object} argv * @param {import('../types').Context} argv.ctx * @param {number} argv.count - * @param {string} argv.peerId + * @param {import('@libp2p/interfaces/peer-id').PeerId} argv.peerId * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, count, peerId, timeout }) { for await (const pong of ipfs.ping(peerId, { count, timeout })) { diff --git a/packages/ipfs-cli/src/commands/pubsub/ls.js b/packages/ipfs-cli/src/commands/pubsub/ls.js index 747ab1eb6b..5695b79741 100644 --- a/packages/ipfs-cli/src/commands/pubsub/ls.js +++ b/packages/ipfs-cli/src/commands/pubsub/ls.js @@ -19,6 +19,8 @@ export default { * @param {object} argv * @param {import('../../types').Context} argv.ctx * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, timeout }) { const subscriptions = await ipfs.pubsub.ls({ diff --git a/packages/ipfs-cli/src/commands/pubsub/peers.js b/packages/ipfs-cli/src/commands/pubsub/peers.js index 25080500fb..6003c442d0 100644 --- a/packages/ipfs-cli/src/commands/pubsub/peers.js +++ b/packages/ipfs-cli/src/commands/pubsub/peers.js @@ -17,11 +17,13 @@ export default { * @param {import('../../types').Context} argv.ctx * @param {string} argv.topic * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, topic, timeout }) { const peers = await ipfs.pubsub.peers(topic, { timeout }) - peers.forEach(peer => print(peer)) + peers.forEach(peer => print(peer.toString())) } } diff --git a/packages/ipfs-cli/src/commands/pubsub/pub.js b/packages/ipfs-cli/src/commands/pubsub/pub.js index c41b1bb496..11bec2ab07 100644 --- a/packages/ipfs-cli/src/commands/pubsub/pub.js +++ b/packages/ipfs-cli/src/commands/pubsub/pub.js @@ -23,6 +23,8 @@ export default { * @param {string} argv.topic * @param {Uint8Array} argv.data * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs }, topic, data, timeout }) { await ipfs.pubsub.publish(topic, data, { diff --git a/packages/ipfs-cli/src/commands/pubsub/sub.js b/packages/ipfs-cli/src/commands/pubsub/sub.js index 2c92b914cf..cd0108678d 100644 --- a/packages/ipfs-cli/src/commands/pubsub/sub.js +++ b/packages/ipfs-cli/src/commands/pubsub/sub.js @@ -1,5 +1,9 @@ import parseDuration from 'parse-duration' +/** + * @typedef {import('@libp2p/interfaces/pubsub').Message} Message + */ + export default { command: 'sub ', @@ -17,10 +21,12 @@ export default { * @param {import('../../types').Context} argv.ctx * @param {string} argv.topic * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, topic, timeout }) { /** - * @type {import('ipfs-core-types/src/pubsub').MessageHandlerFn} + * @type {import('@libp2p/interfaces/events').EventHandler} */ const handler = msg => print(msg.data.toString()) await ipfs.pubsub.subscribe(topic, handler, { diff --git a/packages/ipfs-cli/src/commands/refs-local.js b/packages/ipfs-cli/src/commands/refs-local.js index 18a7f6866f..648d6cb3f0 100644 --- a/packages/ipfs-cli/src/commands/refs-local.js +++ b/packages/ipfs-cli/src/commands/refs-local.js @@ -26,6 +26,8 @@ export default { * @param {import('../types').Context} argv.ctx * @param {boolean} argv.multihash * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, timeout, multihash }) { for await (const { ref, err } of ipfs.refs.local({ diff --git a/packages/ipfs-cli/src/commands/refs.js b/packages/ipfs-cli/src/commands/refs.js index f415ff3795..71307f76d8 100644 --- a/packages/ipfs-cli/src/commands/refs.js +++ b/packages/ipfs-cli/src/commands/refs.js @@ -50,6 +50,8 @@ export default { * @param {boolean} argv.unique * @param {number} argv.maxDepth * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, key, keys, recursive, format, edges, unique, maxDepth, timeout }) { if (maxDepth === 0) { diff --git a/packages/ipfs-cli/src/commands/repo/gc.js b/packages/ipfs-cli/src/commands/repo/gc.js index 294ef78ab4..bbaf975608 100644 --- a/packages/ipfs-cli/src/commands/repo/gc.js +++ b/packages/ipfs-cli/src/commands/repo/gc.js @@ -29,17 +29,16 @@ export default { * @param {boolean} argv.quiet * @param {boolean} argv.streamErrors * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, quiet, streamErrors, timeout }) { for await (const r of ipfs.repo.gc({ timeout })) { - // @ts-ignore cannot derive type if (r.err != null) { - // @ts-ignore cannot derive type streamErrors && print(r.err.message, true, true) } else { - // @ts-ignore cannot derive type print((quiet ? '' : 'removed ') + r.cid) } } diff --git a/packages/ipfs-cli/src/commands/repo/stat.js b/packages/ipfs-cli/src/commands/repo/stat.js index f28d9b1fce..7c3693b56f 100644 --- a/packages/ipfs-cli/src/commands/repo/stat.js +++ b/packages/ipfs-cli/src/commands/repo/stat.js @@ -29,6 +29,8 @@ export default { * @param {boolean} argv.human * @param {boolean} argv.sizeOnly * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, human, sizeOnly, timeout }) { const stats = await ipfs.repo.stat({ diff --git a/packages/ipfs-cli/src/commands/repo/version.js b/packages/ipfs-cli/src/commands/repo/version.js index fb4a382da2..c8a0af5ae6 100644 --- a/packages/ipfs-cli/src/commands/repo/version.js +++ b/packages/ipfs-cli/src/commands/repo/version.js @@ -16,6 +16,8 @@ export default { * @param {object} argv * @param {import('../../types').Context} argv.ctx * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, timeout }) { const version = await ipfs.repo.version({ diff --git a/packages/ipfs-cli/src/commands/resolve.js b/packages/ipfs-cli/src/commands/resolve.js index d14740417b..19755679c8 100644 --- a/packages/ipfs-cli/src/commands/resolve.js +++ b/packages/ipfs-cli/src/commands/resolve.js @@ -32,6 +32,8 @@ export default { * @param {boolean} argv.recursive * @param {string} argv.cidBase * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { print, ipfs }, name, recursive, cidBase, timeout }) { const res = await ipfs.resolve(name, { recursive, cidBase, timeout }) diff --git a/packages/ipfs-cli/src/commands/shutdown.js b/packages/ipfs-cli/src/commands/shutdown.js index 2e1f7b68e6..6e5dfb2eb7 100644 --- a/packages/ipfs-cli/src/commands/shutdown.js +++ b/packages/ipfs-cli/src/commands/shutdown.js @@ -16,9 +16,11 @@ export default { * @param {object} argv * @param {import('../types').Context} argv.ctx * @param {number} argv.timeout + * + * @returns {Promise} */ handler ({ ctx: { ipfs }, timeout }) { - // @ts-ignore not part of the core api + // @ts-expect-error not part of the core api return ipfs.shutdown({ timeout }) diff --git a/packages/ipfs-cli/src/commands/stats/bw.js b/packages/ipfs-cli/src/commands/stats/bw.js index 9e84f1eeb0..92214b3104 100644 --- a/packages/ipfs-cli/src/commands/stats/bw.js +++ b/packages/ipfs-cli/src/commands/stats/bw.js @@ -37,6 +37,8 @@ export default { * @param {boolean} argv.poll * @param {number} argv.interval * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, peer, proto, poll, interval, timeout }) { for await (const chunk of ipfs.stats.bw({ peer, proto, poll, interval, timeout })) { diff --git a/packages/ipfs-cli/src/commands/swarm/addrs.js b/packages/ipfs-cli/src/commands/swarm/addrs.js index 37441b47e7..2bb33fb44f 100644 --- a/packages/ipfs-cli/src/commands/swarm/addrs.js +++ b/packages/ipfs-cli/src/commands/swarm/addrs.js @@ -23,6 +23,8 @@ export default { * @param {object} argv * @param {import('../../types').Context} argv.ctx * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, print }, timeout }) { const res = await ipfs.swarm.addrs({ diff --git a/packages/ipfs-cli/src/commands/swarm/addrs/local.js b/packages/ipfs-cli/src/commands/swarm/addrs/local.js index a74c36f9bf..a24cf26539 100644 --- a/packages/ipfs-cli/src/commands/swarm/addrs/local.js +++ b/packages/ipfs-cli/src/commands/swarm/addrs/local.js @@ -16,6 +16,8 @@ export default { * @param {object} argv * @param {import('../../../types').Context} argv.ctx * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { print, ipfs, isDaemon }, timeout }) { if (!isDaemon) { diff --git a/packages/ipfs-cli/src/commands/swarm/connect.js b/packages/ipfs-cli/src/commands/swarm/connect.js index 7c7a1b1d06..7918fd25b1 100644 --- a/packages/ipfs-cli/src/commands/swarm/connect.js +++ b/packages/ipfs-cli/src/commands/swarm/connect.js @@ -22,8 +22,10 @@ export default { /** * @param {object} argv * @param {import('../../types').Context} argv.ctx - * @param {import('multiaddr').Multiaddr} argv.address + * @param {import('@multiformats/multiaddr').Multiaddr} argv.address * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, isDaemon, print }, address, timeout }) { if (!isDaemon) { diff --git a/packages/ipfs-cli/src/commands/swarm/disconnect.js b/packages/ipfs-cli/src/commands/swarm/disconnect.js index 39927071e7..9b7205a902 100644 --- a/packages/ipfs-cli/src/commands/swarm/disconnect.js +++ b/packages/ipfs-cli/src/commands/swarm/disconnect.js @@ -22,8 +22,10 @@ export default { /** * @param {object} argv * @param {import('../../types').Context} argv.ctx - * @param {import('multiaddr').Multiaddr} argv.address + * @param {import('@multiformats/multiaddr').Multiaddr} argv.address * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { ipfs, isDaemon, print }, address, timeout }) { if (!isDaemon) { diff --git a/packages/ipfs-cli/src/commands/swarm/peers.js b/packages/ipfs-cli/src/commands/swarm/peers.js index c20e83f550..b27f45a06f 100644 --- a/packages/ipfs-cli/src/commands/swarm/peers.js +++ b/packages/ipfs-cli/src/commands/swarm/peers.js @@ -1,5 +1,5 @@ -import mafmt from 'mafmt' -import { Multiaddr } from 'multiaddr' +import { IPFS } from '@multiformats/mafmt' +import { Multiaddr } from '@multiformats/multiaddr' import parseDuration from 'parse-duration' export default { @@ -18,6 +18,8 @@ export default { * @param {object} argv * @param {import('../../types').Context} argv.ctx * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { print, ipfs, isDaemon }, timeout }) { if (!isDaemon) { @@ -31,7 +33,7 @@ export default { result.forEach((item) => { let ma = new Multiaddr(`${item.addr}`) - if (!mafmt.IPFS.matches(ma)) { + if (!IPFS.matches(ma)) { ma = ma.encapsulate(`/ipfs/${item.peer}`) } diff --git a/packages/ipfs-cli/src/commands/version.js b/packages/ipfs-cli/src/commands/version.js index 36ae4a51ec..bc707d2d3a 100644 --- a/packages/ipfs-cli/src/commands/version.js +++ b/packages/ipfs-cli/src/commands/version.js @@ -42,6 +42,8 @@ export default { * @param {boolean} argv.repo * @param {boolean} argv.number * @param {number} argv.timeout + * + * @returns {Promise} */ async handler ({ ctx: { print, ipfs }, all, commit, repo, number, timeout }) { const data = await ipfs.version({ @@ -53,7 +55,7 @@ export default { if (repo) { // go-ipfs prints only the number, even without the --number flag. - // @ts-ignore version return type is implementation-specific + // @ts-expect-error version return type is implementation-specific print(data.repo) } else if (number) { print(parsedVersion) diff --git a/packages/ipfs-cli/src/index.js b/packages/ipfs-cli/src/index.js index a5856fc32b..d12e3dd64f 100644 --- a/packages/ipfs-cli/src/index.js +++ b/packages/ipfs-cli/src/index.js @@ -1,40 +1,15 @@ import parser from './parser.js' import commandAlias from './command-alias.js' -import errCode from 'err-code' /** * @param {string[]} command * @param {import('yargs').MiddlewareFunction} ctxMiddleware */ -export function cli (command, ctxMiddleware) { +export async function cli (command, ctxMiddleware) { // Apply command aliasing (eg `refs local` -> `refs-local`) command = commandAlias(command) - return new Promise((resolve, reject) => { - try { - parser - .middleware(ctxMiddleware) - .onFinishCommand((data) => { - resolve(data) - }) - .fail((msg, err, yargs) => { - // Handle yargs errors - if (msg) { - // if the error was caused by an unknown command, the use of `.parse(command)` - // below causes printing help to fail: https://github.com/yargs/yargs/issues/1419#issuecomment-527234789 - // so pass the unadulterated parser in as `yargs` in order to print help successfully - if (msg.includes('Unknown argument') || msg.includes('Please specify a command')) { - yargs = parser - } - - return reject(errCode(new Error(msg), 'ERR_YARGS', { yargs })) - } - - reject(err) - }) - .parse(command) - } catch (/** @type {any} */ err) { - return reject(err) - } - }) + await parser + .middleware(ctxMiddleware) + .parse(command) } diff --git a/packages/ipfs-cli/src/parser.js b/packages/ipfs-cli/src/parser.js index df08a9b604..b2290721f5 100644 --- a/packages/ipfs-cli/src/parser.js +++ b/packages/ipfs-cli/src/parser.js @@ -14,8 +14,7 @@ const args = yargs(process.argv.slice(2)) }) .option('pass', { desc: 'Pass phrase for the keys', - type: 'string', - default: '' + type: 'string' }) .option('migrate', { desc: 'Enable/disable automatic repo migrations', @@ -29,7 +28,7 @@ const args = yargs(process.argv.slice(2)) .epilog(ipfsPathHelp) .demandCommand(1, 'Please specify a command') .showHelpOnFail(false) - // @ts-ignore types are wrong + // @ts-expect-error types are wrong .command(commandList) .help() .strict() diff --git a/packages/ipfs-cli/src/types.ts b/packages/ipfs-cli/src/types.ts index cbf995e04c..34cdeb158e 100644 --- a/packages/ipfs-cli/src/types.ts +++ b/packages/ipfs-cli/src/types.ts @@ -1,5 +1,5 @@ import type { IPFS } from 'ipfs-core-types' -import type { Multiaddr } from 'multiaddr' +import type { Multiaddr } from '@multiformats/multiaddr' declare module '@hapi/hapi' { interface ServerInfo { diff --git a/packages/ipfs-cli/src/utils.js b/packages/ipfs-cli/src/utils.js index 0eef8d0dcd..52a92a04c8 100644 --- a/packages/ipfs-cli/src/utils.js +++ b/packages/ipfs-cli/src/utils.js @@ -1,17 +1,18 @@ import fs from 'fs' import os from 'os' import path from 'path' -import debug from 'debug' +import { logger } from '@libp2p/logger' import Progress from 'progress' // @ts-expect-error no types import byteman from 'byteman' import { create } from 'ipfs-core' import { CID } from 'multiformats/cid' -import { Multiaddr } from 'multiaddr' +import { Multiaddr } from '@multiformats/multiaddr' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { create as httpClient } from 'ipfs-http-client' +import { peerIdFromString } from '@libp2p/peer-id' -const log = debug('ipfs:cli:utils') +const log = logger('ipfs:cli:utils') export const getRepoPath = () => { return process.env.IPFS_PATH || path.join(os.homedir(), '/.jsipfs') @@ -249,6 +250,17 @@ export const coerceCIDs = (values) => { return values.map(coerceCID).filter(Boolean) } +/** + * @param {string} value + */ +export const coercePeerId = (value) => { + if (!value) { + return undefined + } + + return peerIdFromString(value) +} + /** * @param {string} value */ diff --git a/packages/ipfs-cli/test/add.spec.js b/packages/ipfs-cli/test/add.spec.js index 39bb5b1022..0d072a8e9f 100644 --- a/packages/ipfs-cli/test/add.spec.js +++ b/packages/ipfs-cli/test/add.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { CID } from 'multiformats/cid' import { base58btc } from 'multiformats/bases/base58' import { base64 } from 'multiformats/bases/base64' diff --git a/packages/ipfs-cli/test/bitswap.spec.js b/packages/ipfs-cli/test/bitswap.spec.js index 9818ff2a76..52463252ec 100644 --- a/packages/ipfs-cli/test/bitswap.spec.js +++ b/packages/ipfs-cli/test/bitswap.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { CID } from 'multiformats/cid' import { base58btc } from 'multiformats/bases/base58' import { base64 } from 'multiformats/bases/base64' diff --git a/packages/ipfs-cli/test/block.spec.js b/packages/ipfs-cli/test/block.spec.js index d750c7eba8..d483e54bfd 100644 --- a/packages/ipfs-cli/test/block.spec.js +++ b/packages/ipfs-cli/test/block.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { CID } from 'multiformats/cid' import { base58btc } from 'multiformats/bases/base58' import { base64 } from 'multiformats/bases/base64' diff --git a/packages/ipfs-cli/test/bootstrap.spec.js b/packages/ipfs-cli/test/bootstrap.spec.js index 127bf6bd67..13f1f6b96f 100644 --- a/packages/ipfs-cli/test/bootstrap.spec.js +++ b/packages/ipfs-cli/test/bootstrap.spec.js @@ -1,9 +1,9 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { cli } from './utils/cli.js' import sinon from 'sinon' -import { Multiaddr } from 'multiaddr' +import { Multiaddr } from '@multiformats/multiaddr' describe('bootstrap', () => { const peer = new Multiaddr('/ip4/111.111.111.111/tcp/1001/p2p/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD') diff --git a/packages/ipfs-cli/test/cat.spec.js b/packages/ipfs-cli/test/cat.spec.js index 995da3edbf..66996db78e 100644 --- a/packages/ipfs-cli/test/cat.spec.js +++ b/packages/ipfs-cli/test/cat.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { CID } from 'multiformats/cid' import { cli, fail } from './utils/cli.js' import sinon from 'sinon' diff --git a/packages/ipfs-cli/test/cid.spec.js b/packages/ipfs-cli/test/cid.spec.js index 6470262d9a..f6ab1ee885 100644 --- a/packages/ipfs-cli/test/cid.spec.js +++ b/packages/ipfs-cli/test/cid.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { cli } from './utils/cli.js' import sinon from 'sinon' import { base32 } from 'multiformats/bases/base32' diff --git a/packages/ipfs-cli/test/commands.spec.js b/packages/ipfs-cli/test/commands.spec.js index d2567f37f8..adb7996c1f 100644 --- a/packages/ipfs-cli/test/commands.spec.js +++ b/packages/ipfs-cli/test/commands.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { cli } from './utils/cli.js' const commandCount = 117 diff --git a/packages/ipfs-cli/test/config.spec.js b/packages/ipfs-cli/test/config.spec.js index 5c3edd8927..7573c729f7 100644 --- a/packages/ipfs-cli/test/config.spec.js +++ b/packages/ipfs-cli/test/config.spec.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ /* eslint max-nested-callbacks: ["error", 5] */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { cli, fail } from './utils/cli.js' import sinon from 'sinon' import { profiles } from 'ipfs-core/config/profiles' diff --git a/packages/ipfs-cli/test/daemon.spec.js b/packages/ipfs-cli/test/daemon.spec.js index 0c83205aeb..5301ac47b9 100644 --- a/packages/ipfs-cli/test/daemon.spec.js +++ b/packages/ipfs-cli/test/daemon.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import os from 'os' import path from 'path' import { nanoid } from 'nanoid' diff --git a/packages/ipfs-cli/test/dag.spec.js b/packages/ipfs-cli/test/dag.spec.js index 37e03a5031..44f17fb349 100644 --- a/packages/ipfs-cli/test/dag.spec.js +++ b/packages/ipfs-cli/test/dag.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { cli } from './utils/cli.js' import * as dagCBOR from '@ipld/dag-cbor' import * as dagPB from '@ipld/dag-pb' diff --git a/packages/ipfs-cli/test/dht.spec.js b/packages/ipfs-cli/test/dht.spec.js index e1a4b69984..3679b82f9d 100644 --- a/packages/ipfs-cli/test/dht.spec.js +++ b/packages/ipfs-cli/test/dht.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { cli } from './utils/cli.js' import sinon from 'sinon' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' diff --git a/packages/ipfs-cli/test/dns.spec.js b/packages/ipfs-cli/test/dns.spec.js index e123177e4b..8c7ea6f93a 100644 --- a/packages/ipfs-cli/test/dns.spec.js +++ b/packages/ipfs-cli/test/dns.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { cli } from './utils/cli.js' import sinon from 'sinon' diff --git a/packages/ipfs-cli/test/files/chmod.js b/packages/ipfs-cli/test/files/chmod.js index d833242baf..fdd39f2081 100644 --- a/packages/ipfs-cli/test/files/chmod.js +++ b/packages/ipfs-cli/test/files/chmod.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import sinon from 'sinon' import { cli } from '../utils/cli.js' diff --git a/packages/ipfs-cli/test/files/cp.js b/packages/ipfs-cli/test/files/cp.js index e6cb693cfb..ef04b53d9b 100644 --- a/packages/ipfs-cli/test/files/cp.js +++ b/packages/ipfs-cli/test/files/cp.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import sinon from 'sinon' import { cli } from '../utils/cli.js' diff --git a/packages/ipfs-cli/test/files/flush.js b/packages/ipfs-cli/test/files/flush.js index aafcfab19a..7e32eecb07 100644 --- a/packages/ipfs-cli/test/files/flush.js +++ b/packages/ipfs-cli/test/files/flush.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import sinon from 'sinon' import { CID } from 'multiformats/cid' import { base58btc } from 'multiformats/bases/base58' diff --git a/packages/ipfs-cli/test/files/ls.js b/packages/ipfs-cli/test/files/ls.js index 097f231278..de4b7eca40 100644 --- a/packages/ipfs-cli/test/files/ls.js +++ b/packages/ipfs-cli/test/files/ls.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import sinon from 'sinon' import { isNode } from 'ipfs-utils/src/env.js' import { CID } from 'multiformats/cid' diff --git a/packages/ipfs-cli/test/files/mkdir.js b/packages/ipfs-cli/test/files/mkdir.js index 7331efc794..ed0adfcfc0 100644 --- a/packages/ipfs-cli/test/files/mkdir.js +++ b/packages/ipfs-cli/test/files/mkdir.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import sinon from 'sinon' import { isNode } from 'ipfs-utils/src/env.js' import { cli } from '../utils/cli.js' diff --git a/packages/ipfs-cli/test/files/mv.js b/packages/ipfs-cli/test/files/mv.js index 337cd0bae3..5faf628d49 100644 --- a/packages/ipfs-cli/test/files/mv.js +++ b/packages/ipfs-cli/test/files/mv.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import sinon from 'sinon' import { isNode } from 'ipfs-utils/src/env.js' import { cli } from '../utils/cli.js' diff --git a/packages/ipfs-cli/test/files/read.js b/packages/ipfs-cli/test/files/read.js index 4a9ddd56f9..e2783e9890 100644 --- a/packages/ipfs-cli/test/files/read.js +++ b/packages/ipfs-cli/test/files/read.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import sinon from 'sinon' import { isNode } from 'ipfs-utils/src/env.js' import { cli } from '../utils/cli.js' diff --git a/packages/ipfs-cli/test/files/rm.js b/packages/ipfs-cli/test/files/rm.js index eb68047482..3d6805dc46 100644 --- a/packages/ipfs-cli/test/files/rm.js +++ b/packages/ipfs-cli/test/files/rm.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import sinon from 'sinon' import { isNode } from 'ipfs-utils/src/env.js' import { cli } from '../utils/cli.js' diff --git a/packages/ipfs-cli/test/files/stat.js b/packages/ipfs-cli/test/files/stat.js index ac2a8da83a..dc29930aa1 100644 --- a/packages/ipfs-cli/test/files/stat.js +++ b/packages/ipfs-cli/test/files/stat.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import sinon from 'sinon' import { isNode } from 'ipfs-utils/src/env.js' import { CID } from 'multiformats/cid' diff --git a/packages/ipfs-cli/test/files/touch.js b/packages/ipfs-cli/test/files/touch.js index 4b41937d4b..01cac4fa08 100644 --- a/packages/ipfs-cli/test/files/touch.js +++ b/packages/ipfs-cli/test/files/touch.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import sinon from 'sinon' import { isNode } from 'ipfs-utils/src/env.js' import { cli } from '../utils/cli.js' diff --git a/packages/ipfs-cli/test/files/write.js b/packages/ipfs-cli/test/files/write.js index 33f2baec91..cc56744c99 100644 --- a/packages/ipfs-cli/test/files/write.js +++ b/packages/ipfs-cli/test/files/write.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import sinon from 'sinon' import { isNode } from 'ipfs-utils/src/env.js' import { cli } from '../utils/cli.js' diff --git a/packages/ipfs-cli/test/general.spec.js b/packages/ipfs-cli/test/general.spec.js index 6195f4ee03..c00a5167c9 100644 --- a/packages/ipfs-cli/test/general.spec.js +++ b/packages/ipfs-cli/test/general.spec.js @@ -4,7 +4,7 @@ import os from 'os' import { promises as fs } from 'fs' import path, { dirname } from 'path' import { nanoid } from 'nanoid' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { promisify } from 'util' import { fail } from './utils/cli.js' import sinon from 'sinon' @@ -18,7 +18,7 @@ import { fileURLToPath } from 'url' const ncp = promisify(ncpCb) -// @ts-ignore need to set module to es2020 to use import.meta.url, which we do, +// @ts-expect-error need to set module to es2020 to use import.meta.url, which we do, // but then the "--module" setting doesn't get used by the "--build" setting // which we use to build types from jsdoc const __dirname = dirname(fileURLToPath(import.meta.url)) diff --git a/packages/ipfs-cli/test/get.spec.js b/packages/ipfs-cli/test/get.spec.js index 9fd401fb57..a3f7d22200 100644 --- a/packages/ipfs-cli/test/get.spec.js +++ b/packages/ipfs-cli/test/get.spec.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import fs from 'fs' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import path from 'path' import { CID } from 'multiformats/cid' import { cli } from './utils/cli.js' diff --git a/packages/ipfs-cli/test/id.spec.js b/packages/ipfs-cli/test/id.spec.js index 81ba55c1a3..b10f469a09 100644 --- a/packages/ipfs-cli/test/id.spec.js +++ b/packages/ipfs-cli/test/id.spec.js @@ -1,9 +1,9 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { cli } from './utils/cli.js' import sinon from 'sinon' -import PeerId from 'peer-id' +import { PeerId } from '@libp2p/interfaces/peer-id' const defaultOptions = { timeout: undefined, diff --git a/packages/ipfs-cli/test/init.spec.js b/packages/ipfs-cli/test/init.spec.js index a42a5420f2..0784f2157a 100644 --- a/packages/ipfs-cli/test/init.spec.js +++ b/packages/ipfs-cli/test/init.spec.js @@ -1,17 +1,18 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import path from 'path' import fs from 'fs' -import PeerId from 'peer-id' import { nanoid } from 'nanoid' import os from 'os' -import { supportedKeys } from 'libp2p-crypto/src/keys/index.js' +import { unmarshalPrivateKey, supportedKeys } from '@libp2p/crypto/keys' import { clean } from './utils/clean.js' import { ipfsExec } from './utils/ipfs-exec.js' import tempWrite from 'temp-write' +import { peerIdFromKeys } from '@libp2p/peer-id' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -describe.skip('init', function () { +describe('init', function () { let repoPath let ipfs @@ -51,7 +52,9 @@ describe.skip('init', function () { it('algorithm', async function () { await ipfs('init --algorithm ed25519') - const peerId = await PeerId.createFromPrivKey(repoConfSync().Identity.PrivKey) + const buf = uint8ArrayFromString(repoConfSync().Identity.PrivKey, 'base64pad') + const key = await unmarshalPrivateKey(buf) + const peerId = await peerIdFromKeys(key.public.bytes, key.bytes) expect(peerId.privKey).is.instanceOf(supportedKeys.ed25519.Ed25519PrivateKey) }) diff --git a/packages/ipfs-cli/test/key.spec.js b/packages/ipfs-cli/test/key.spec.js index 0c8b145be0..34a1b7363b 100644 --- a/packages/ipfs-cli/test/key.spec.js +++ b/packages/ipfs-cli/test/key.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { cli } from './utils/cli.js' import sinon from 'sinon' diff --git a/packages/ipfs-cli/test/ls.spec.js b/packages/ipfs-cli/test/ls.spec.js index 1d9c53873a..a1bce18f21 100644 --- a/packages/ipfs-cli/test/ls.spec.js +++ b/packages/ipfs-cli/test/ls.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { cli } from './utils/cli.js' import sinon from 'sinon' import { CID } from 'multiformats/cid' diff --git a/packages/ipfs-cli/test/name-pubsub.spec.js b/packages/ipfs-cli/test/name-pubsub.spec.js index e2ebb8929f..1b107cb28c 100644 --- a/packages/ipfs-cli/test/name-pubsub.spec.js +++ b/packages/ipfs-cli/test/name-pubsub.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { cli } from './utils/cli.js' import sinon from 'sinon' diff --git a/packages/ipfs-cli/test/name.spec.js b/packages/ipfs-cli/test/name.spec.js index e91976a0b0..8e98ad78f6 100644 --- a/packages/ipfs-cli/test/name.spec.js +++ b/packages/ipfs-cli/test/name.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { cli } from './utils/cli.js' import sinon from 'sinon' diff --git a/packages/ipfs-cli/test/object.spec.js b/packages/ipfs-cli/test/object.spec.js index 16663ba9f7..e2134879c1 100644 --- a/packages/ipfs-cli/test/object.spec.js +++ b/packages/ipfs-cli/test/object.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import fs from 'fs' import { cli } from './utils/cli.js' import sinon from 'sinon' diff --git a/packages/ipfs-cli/test/pin.spec.js b/packages/ipfs-cli/test/pin.spec.js index 3bd276088a..ef21bf79b2 100644 --- a/packages/ipfs-cli/test/pin.spec.js +++ b/packages/ipfs-cli/test/pin.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { CID } from 'multiformats/cid' import { base58btc } from 'multiformats/bases/base58' import { base64 } from 'multiformats/bases/base64' diff --git a/packages/ipfs-cli/test/ping.spec.js b/packages/ipfs-cli/test/ping.spec.js index 1842ca787e..2ec731d8ed 100644 --- a/packages/ipfs-cli/test/ping.spec.js +++ b/packages/ipfs-cli/test/ping.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { cli } from './utils/cli.js' import sinon from 'sinon' diff --git a/packages/ipfs-cli/test/progress-bar.spec.js b/packages/ipfs-cli/test/progress-bar.spec.js index c0a8c88fc4..8e8a0059cd 100644 --- a/packages/ipfs-cli/test/progress-bar.spec.js +++ b/packages/ipfs-cli/test/progress-bar.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { createProgressBar } from '../src/utils.js' describe('progress bar', () => { diff --git a/packages/ipfs-cli/test/pubsub.spec.js b/packages/ipfs-cli/test/pubsub.spec.js index 839aca18e2..77c3aaa15e 100644 --- a/packages/ipfs-cli/test/pubsub.spec.js +++ b/packages/ipfs-cli/test/pubsub.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { cli } from './utils/cli.js' import sinon from 'sinon' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' diff --git a/packages/ipfs-cli/test/refs-local.spec.js b/packages/ipfs-cli/test/refs-local.spec.js index c7d9c1ce97..590b73815d 100644 --- a/packages/ipfs-cli/test/refs-local.spec.js +++ b/packages/ipfs-cli/test/refs-local.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { cli } from './utils/cli.js' import sinon from 'sinon' import { base32 } from 'multiformats/bases/base32' diff --git a/packages/ipfs-cli/test/refs.spec.js b/packages/ipfs-cli/test/refs.spec.js index d71c11fbd0..3c1fb8de43 100644 --- a/packages/ipfs-cli/test/refs.spec.js +++ b/packages/ipfs-cli/test/refs.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { CID } from 'multiformats/cid' import { cli } from './utils/cli.js' import sinon from 'sinon' diff --git a/packages/ipfs-cli/test/repo.spec.js b/packages/ipfs-cli/test/repo.spec.js index 8ad281ee25..bd68b20977 100644 --- a/packages/ipfs-cli/test/repo.spec.js +++ b/packages/ipfs-cli/test/repo.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { cli } from './utils/cli.js' import sinon from 'sinon' import { CID } from 'multiformats/cid' diff --git a/packages/ipfs-cli/test/resolve.spec.js b/packages/ipfs-cli/test/resolve.spec.js index 261c9c93f2..efe7737d7d 100644 --- a/packages/ipfs-cli/test/resolve.spec.js +++ b/packages/ipfs-cli/test/resolve.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { CID } from 'multiformats/cid' import { cli } from './utils/cli.js' import sinon from 'sinon' diff --git a/packages/ipfs-cli/test/swarm.spec.js b/packages/ipfs-cli/test/swarm.spec.js index 70b8d6c5b1..ff2b951f52 100644 --- a/packages/ipfs-cli/test/swarm.spec.js +++ b/packages/ipfs-cli/test/swarm.spec.js @@ -1,10 +1,10 @@ /* eslint max-nested-callbacks: ["error", 8] */ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { cli, fail } from './utils/cli.js' import sinon from 'sinon' -import { Multiaddr } from 'multiaddr' +import { Multiaddr } from '@multiformats/multiaddr' describe('swarm', () => { let ipfs diff --git a/packages/ipfs-cli/test/utils/ipfs-exec.js b/packages/ipfs-cli/test/utils/ipfs-exec.js index 9b4ea15c0c..c99defb145 100644 --- a/packages/ipfs-cli/test/utils/ipfs-exec.js +++ b/packages/ipfs-cli/test/utils/ipfs-exec.js @@ -3,7 +3,7 @@ import execa from 'execa' import path, { dirname } from 'path' import { fileURLToPath } from 'url' -// @ts-ignore need to set module to es2020 to use import.meta.url, which we do, +// @ts-expect-error need to set module to es2020 to use import.meta.url, which we do, // but then the "--module" setting doesn't get used by the "--build" setting // which we use to build types from jsdoc const __dirname = dirname(fileURLToPath(import.meta.url)) @@ -80,7 +80,7 @@ export function ipfsExec (repoPath, opts) { * Expect the command passed as @param arguments to fail. * * @param {string} command - String command to run, e.g. `'pin ls'` - * @param {Object} [options] - Options to pass to `execa` + * @param {object} [options] - Options to pass to `execa` * @returns {Promise} Resolves if the command passed as @param command fails, * rejects if it was successful. */ diff --git a/packages/ipfs-cli/test/version.spec.js b/packages/ipfs-cli/test/version.spec.js index 3ebe49cf66..b834edb224 100644 --- a/packages/ipfs-cli/test/version.spec.js +++ b/packages/ipfs-cli/test/version.spec.js @@ -2,7 +2,7 @@ /* eslint-env mocha */ import os from 'os' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { cli } from './utils/cli.js' import sinon from 'sinon' diff --git a/packages/ipfs-client/.aegir.cjs b/packages/ipfs-client/.aegir.js similarity index 73% rename from packages/ipfs-client/.aegir.cjs rename to packages/ipfs-client/.aegir.js index 2f84195e71..036d836967 100644 --- a/packages/ipfs-client/.aegir.cjs +++ b/packages/ipfs-client/.aegir.js @@ -1,7 +1,6 @@ -'use strict' /** @type {import('aegir').PartialOptions} */ -module.exports = { +export default { build: { bundlesizeMax: '98kB' } diff --git a/packages/ipfs-client/package.json b/packages/ipfs-client/package.json index 1c47b6d9d1..d286088c76 100644 --- a/packages/ipfs-client/package.json +++ b/packages/ipfs-client/package.json @@ -35,7 +35,7 @@ }, "scripts": { "build": "aegir build", - "lint": "aegir ts -p check && aegir lint", + "lint": "aegir lint", "clean": "rimraf ./dist", "dep-check": "aegir dep-check -i aegir -i rimraf" }, @@ -45,7 +45,7 @@ "merge-options": "^3.0.4" }, "devDependencies": { - "aegir": "^36.0.1", + "aegir": "^37.0.11", "rimraf": "^3.0.2" } } diff --git a/packages/ipfs-client/src/index.js b/packages/ipfs-client/src/index.js index f839da278f..171f799dd8 100644 --- a/packages/ipfs-client/src/index.js +++ b/packages/ipfs-client/src/index.js @@ -7,7 +7,7 @@ const mergeOptions = mergeOpts.bind({ ignoreUndefined: true }) /** * @typedef {import('ipfs-http-client').Options} HTTPOptions * @typedef {import('ipfs-grpc-client').Options} GRPCOptions - * @typedef {string|URL|import('multiaddr').Multiaddr} Address + * @typedef {string|URL|import('@multiformats/multiaddr').Multiaddr} Address * @typedef {{http?: Address, grpc?: Address} & Partial} Options * * @param {Options} [opts] diff --git a/packages/ipfs-core-config/.aegir.cjs b/packages/ipfs-core-config/.aegir.js similarity index 73% rename from packages/ipfs-core-config/.aegir.cjs rename to packages/ipfs-core-config/.aegir.js index ef3e3aa890..3932c3dab3 100644 --- a/packages/ipfs-core-config/.aegir.cjs +++ b/packages/ipfs-core-config/.aegir.js @@ -1,7 +1,6 @@ -'use strict' /** @type {import('aegir').PartialOptions} */ -module.exports = { +export default { build: { bundlesizeMax: '540B' } diff --git a/packages/ipfs-core-config/package.json b/packages/ipfs-core-config/package.json index 403807cf2f..13a90bddb8 100644 --- a/packages/ipfs-core-config/package.json +++ b/packages/ipfs-core-config/package.json @@ -71,14 +71,22 @@ "url": "git+https://github.com/ipfs/js-ipfs.git" }, "scripts": { - "lint": "aegir ts -p check && aegir lint", + "lint": "aegir lint", "clean": "rimraf ./dist", "dep-check": "aegir dep-check -i aegir -i rimraf -i ipfs-core-utils", "build": "aegir build" }, "license": "MIT", "dependencies": { - "@chainsafe/libp2p-noise": "^5.0.1", + "@achingbrain/libp2p-gossipsub": "^0.13.6", + "@chainsafe/libp2p-noise": "^6.0.1", + "@libp2p/floodsub": "^1.0.2", + "@libp2p/kad-dht": "^1.0.3", + "@libp2p/mdns": "^1.0.3", + "@libp2p/mplex": "^1.0.2", + "@libp2p/tcp": "^1.0.6", + "@libp2p/webrtc-star": "^1.0.6", + "@libp2p/websockets": "^1.0.3", "blockstore-datastore-adapter": "^2.0.2", "datastore-core": "^7.0.0", "datastore-fs": "^7.0.0", @@ -89,24 +97,16 @@ "interface-datastore": "^6.0.2", "ipfs-repo": "^14.0.1", "ipfs-utils": "^9.0.2", - "ipns": "^0.16.0", + "ipns": "^1.0.0", "is-ipfs": "^6.0.1", "it-all": "^1.0.4", - "it-foreach": "^0.1.1", "it-drain": "^1.0.3", - "libp2p-floodsub": "^0.29.0", - "libp2p-gossipsub": "^0.13.0", - "libp2p-kad-dht": "^0.28.5", - "libp2p-mdns": "^0.18.0", - "libp2p-mplex": "^0.10.2", - "libp2p-tcp": "^0.17.1", - "libp2p-webrtc-star": "^0.25.0", - "libp2p-websockets": "^0.16.2", - "p-queue": "^6.6.1", + "it-foreach": "^0.1.1", + "p-queue": "^7.2.0", "uint8arrays": "^3.0.0" }, "devDependencies": { - "aegir": "^36.0.1", + "aegir": "^37.0.11", "ipfs-core-utils": "^0.14.2", "rimraf": "^3.0.2" } diff --git a/packages/ipfs-core-config/src/dns.browser.js b/packages/ipfs-core-config/src/dns.browser.js index aedb80b31e..43e8081189 100644 --- a/packages/ipfs-core-config/src/dns.browser.js +++ b/packages/ipfs-core-config/src/dns.browser.js @@ -37,7 +37,7 @@ export async function resolveDnslink (fqdn, opts) { // eslint-disable-line requi * @param {boolean} [opts.nocache] */ const resolve = async (fqdn, opts = {}) => { - // @ts-ignore - URLSearchParams does not take boolean options, only strings + // @ts-expect-error - URLSearchParams does not take boolean options, only strings const searchParams = new URLSearchParams(opts) searchParams.set('arg', fqdn) diff --git a/packages/ipfs-core-config/src/libp2p-pubsub-routers.browser.js b/packages/ipfs-core-config/src/libp2p-pubsub-routers.browser.js index d38c0a0b41..478e9dc36e 100644 --- a/packages/ipfs-core-config/src/libp2p-pubsub-routers.browser.js +++ b/packages/ipfs-core-config/src/libp2p-pubsub-routers.browser.js @@ -1,5 +1,11 @@ -import libp2pGossipsub from 'libp2p-gossipsub' +import { GossipSub } from '@achingbrain/libp2p-gossipsub' -export const routers = { - gossipsub: libp2pGossipsub -} +/** @typedef {import('@libp2p/interfaces/pubsub').PubSub} PubSub */ + +/** @type {() => Record}>} */ +export const routers = () => ({ + gossipsub: new GossipSub({ + allowPublishToZeroPeers: true, + emitSelf: true + }) +}) diff --git a/packages/ipfs-core-config/src/libp2p-pubsub-routers.js b/packages/ipfs-core-config/src/libp2p-pubsub-routers.js index 6065c4b45b..a36f640912 100644 --- a/packages/ipfs-core-config/src/libp2p-pubsub-routers.js +++ b/packages/ipfs-core-config/src/libp2p-pubsub-routers.js @@ -1,10 +1,15 @@ -import libp2pGossipsub from 'libp2p-gossipsub' -import libp2pFloodsub from 'libp2p-floodsub' +import { GossipSub } from '@achingbrain/libp2p-gossipsub' +import { FloodSub } from '@libp2p/floodsub' -/** @typedef {import('libp2p-interfaces/src/pubsub')} PubSub */ +/** @typedef {import('@libp2p/interfaces/pubsub').PubSub} PubSub */ -/** @type {Record} */ -export const routers = { - gossipsub: libp2pGossipsub, - floodsub: libp2pFloodsub -} +/** @type {() => Record}>} */ +export const routers = () => ({ + gossipsub: new GossipSub({ + allowPublishToZeroPeers: true, + emitSelf: true + }), + floodsub: new FloodSub({ + emitSelf: true + }) +}) diff --git a/packages/ipfs-core-config/src/libp2p.browser.js b/packages/ipfs-core-config/src/libp2p.browser.js index b540c0c8e2..59de391ffd 100644 --- a/packages/ipfs-core-config/src/libp2p.browser.js +++ b/packages/ipfs-core-config/src/libp2p.browser.js @@ -1,74 +1,27 @@ - -// @ts-expect-error - no types -import WS from 'libp2p-websockets' -// @ts-expect-error - no types -import WebRTCStar from 'libp2p-webrtc-star' -// @ts-expect-error - no types -import Multiplex from 'libp2p-mplex' -import { NOISE } from '@chainsafe/libp2p-noise' -import KadDHT from 'libp2p-kad-dht' -import GossipSub from 'libp2p-gossipsub' -import { validator, selector } from './utils/ipns.js' +import { WebRTCStar } from '@libp2p/webrtc-star' export function libp2pConfig () { + const webRtcStar = new WebRTCStar() + /** @type {import('libp2p').Libp2pOptions} */ const options = { - dialer: { + transports: [ + webRtcStar + ], + peerDiscovery: [ + webRtcStar.discovery + ], + connectionManager: { maxParallelDials: 150, // 150 total parallel multiaddr dials maxDialsPerPeer: 4, // Allow 4 multiaddrs to be dialed per peer in parallel - dialTimeout: 10e3 // 10 second dial timeout per peer dial + dialTimeout: 10e3, // 10 second dial timeout per peer dial + autoDial: true }, - modules: { - transport: [ - WS, - WebRTCStar - ], - streamMuxer: [ - Multiplex - ], - connEncryption: [ - NOISE - ], - peerDiscovery: [], - dht: KadDHT, - pubsub: GossipSub - }, - config: { - peerDiscovery: { - autoDial: true, - // [Bootstrap.tag] = 'bootstrap' - bootstrap: { - enabled: true - }, - // [WebRTCStar.discovery.tag] - webRTCStar: { - enabled: true - } - }, - dht: { - kBucketSize: 20, - enabled: true, - clientMode: true, - validators: { - ipns: validator - }, - selectors: { - ipns: selector - } - }, - pubsub: { - enabled: true, - emitSelf: true - }, - nat: { - enabled: false - } + nat: { + enabled: false }, metrics: { enabled: true - }, - peerStore: { - persistence: true } } diff --git a/packages/ipfs-core-config/src/libp2p.js b/packages/ipfs-core-config/src/libp2p.js index 74db852f38..57032303da 100644 --- a/packages/ipfs-core-config/src/libp2p.js +++ b/packages/ipfs-core-config/src/libp2p.js @@ -1,79 +1,28 @@ -import TCP from 'libp2p-tcp' -// @ts-expect-error - no types -import MulticastDNS from 'libp2p-mdns' -// @ts-expect-error - no types -import WS from 'libp2p-websockets' -import KadDHT from 'libp2p-kad-dht' -import GossipSub from 'libp2p-gossipsub' -// @ts-expect-error - no types -import Multiplex from 'libp2p-mplex' -import { NOISE } from '@chainsafe/libp2p-noise' -import { validator, selector } from './utils/ipns.js' +import { TCP } from '@libp2p/tcp' +import { MulticastDNS } from '@libp2p/mdns' import os from 'os' export function libp2pConfig () { /** @type {import('libp2p').Libp2pOptions} */ const options = { - dialer: { + transports: [ + new TCP() + ], + peerDiscovery: [ + new MulticastDNS() + ], + connectionManager: { maxParallelDials: 150, // 150 total parallel multiaddr dials maxDialsPerPeer: 4, // Allow 4 multiaddrs to be dialed per peer in parallel - dialTimeout: 10e3 // 10 second dial timeout per peer dial + dialTimeout: 10e3, // 10 second dial timeout per peer dial + autoDial: true }, - modules: { - transport: [ - TCP, - WS - ], - streamMuxer: [ - Multiplex - ], - connEncryption: [ - NOISE - ], - peerDiscovery: [ - MulticastDNS - ], - dht: KadDHT, - pubsub: GossipSub - }, - config: { - peerDiscovery: { - autoDial: true, - [MulticastDNS.tag]: { - enabled: true - }, - // Optimization - // Requiring bootstrap inline in components/libp2p to reduce the cli execution time - // [Bootstrap.tag] = 'bootstrap' - bootstrap: { - enabled: true - } - }, - dht: { - kBucketSize: 20, - enabled: true, - clientMode: true, - validators: { - ipns: validator - }, - selectors: { - ipns: selector - } - }, - pubsub: { - enabled: true, - emitSelf: true - }, - nat: { - enabled: true, - description: `ipfs@${os.hostname()}` - } + nat: { + enabled: true, + description: `ipfs@${os.hostname()}` }, metrics: { enabled: true - }, - peerStore: { - persistence: true } } diff --git a/packages/ipfs-core-config/src/preload.browser.js b/packages/ipfs-core-config/src/preload.browser.js index 0079268e83..b77ab979a3 100644 --- a/packages/ipfs-core-config/src/preload.browser.js +++ b/packages/ipfs-core-config/src/preload.browser.js @@ -1,12 +1,10 @@ /* eslint-env browser */ import HTTP from 'ipfs-utils/src/http.js' -import debug from 'debug' +import { logger } from '@libp2p/logger' import PQueue from 'p-queue' -const log = Object.assign(debug('ipfs:preload'), { - error: debug('ipfs:preload:error') -}) +const log = logger('ipfs:preload') // @ts-expect-error PQueue@6 is broken const Queue = PQueue.default ? PQueue.default : PQueue @@ -25,7 +23,7 @@ export function preload (url, options = {}) { return httpQueue.add(async () => { const res = await HTTP.post(url, { signal: options.signal }) - // @ts-ignore + // @ts-expect-error const reader = res.body.getReader() try { diff --git a/packages/ipfs-core-config/src/preload.js b/packages/ipfs-core-config/src/preload.js index a7e38f9534..fb3559f87d 100644 --- a/packages/ipfs-core-config/src/preload.js +++ b/packages/ipfs-core-config/src/preload.js @@ -1,10 +1,8 @@ import HTTP from 'ipfs-utils/src/http.js' -import debug from 'debug' +import { logger } from '@libp2p/logger' import drain from 'it-drain' -const log = Object.assign(debug('ipfs:preload'), { - error: debug('ipfs:preload:error') -}) +const log = logger('ipfs:preload') /** * @param {string} url @@ -17,7 +15,7 @@ export async function preload (url, options = {}) { if (res.body) { // Read to completion but do not cache - // @ts-ignore + // @ts-expect-error await drain(res.body) } } diff --git a/packages/ipfs-core-config/src/utils/ipns.js b/packages/ipfs-core-config/src/utils/ipns.js deleted file mode 100644 index de1644122e..0000000000 --- a/packages/ipfs-core-config/src/utils/ipns.js +++ /dev/null @@ -1,17 +0,0 @@ -import * as ipns from 'ipns' - -export const validator = { - /** - * @param {Uint8Array} key - * @param {Uint8Array} record - */ - func: (key, record) => ipns.validator.validate(record, key) -} - -/** - * @param {*} _k - * @param {Uint8Array[]} records - */ -export function selector (_k, records) { - return ipns.validator.select(records[0], records[1]) -} diff --git a/packages/ipfs-core-config/src/utils/lru-datastore.js b/packages/ipfs-core-config/src/utils/lru-datastore.js index a3153a5c90..955edefe01 100644 --- a/packages/ipfs-core-config/src/utils/lru-datastore.js +++ b/packages/ipfs-core-config/src/utils/lru-datastore.js @@ -1,5 +1,3 @@ -/** @type {typeof import('hashlru').default} */ -// @ts-ignore - hashlru has incorrect typedefs import hashlru from 'hashlru' import { BaseDatastore } from 'datastore-core/base' import each from 'it-foreach' diff --git a/packages/ipfs-core-config/src/utils/tlru.js b/packages/ipfs-core-config/src/utils/tlru.js index b5705b10c0..0286d5e738 100644 --- a/packages/ipfs-core-config/src/utils/tlru.js +++ b/packages/ipfs-core-config/src/utils/tlru.js @@ -1,5 +1,3 @@ -/** @type {typeof import('hashlru').default} */ -// @ts-ignore - hashlru has incorrect typedefs import hashlru from 'hashlru' /** diff --git a/packages/ipfs-core-types/package.json b/packages/ipfs-core-types/package.json index 7c6d87482d..7e7b1b9b44 100644 --- a/packages/ipfs-core-types/package.json +++ b/packages/ipfs-core-types/package.json @@ -7,7 +7,7 @@ "bugs": "https://github.com/ipfs/js-ipfs/issues", "scripts": { "clean": "rimraf ./dist", - "lint": "aegir ts -p check && aegir lint", + "lint": "aegir lint", "build": "aegir build && copyfiles 'src/**/*' package.json README.md CHANGELOG.md COPYRIGHT LICENSE-APACHE LICENSE-MIT dist" }, "files": [ @@ -46,11 +46,11 @@ "@ipld/dag-pb": "^2.1.3", "interface-datastore": "^6.0.2", "ipfs-unixfs": "^6.0.3", - "multiaddr": "^10.0.0", + "@multiformats/multiaddr": "^10.0.0", "multiformats": "^9.5.1" }, "devDependencies": { - "aegir": "^36.0.1", + "aegir": "^37.0.11", "copyfiles": "^2.4.1", "rimraf": "^3.0.2" }, diff --git a/packages/ipfs-core-types/src/bitswap/index.ts b/packages/ipfs-core-types/src/bitswap/index.ts index 07e069963b..c3a9b8a48f 100644 --- a/packages/ipfs-core-types/src/bitswap/index.ts +++ b/packages/ipfs-core-types/src/bitswap/index.ts @@ -1,5 +1,6 @@ import type { CID } from 'multiformats/cid' import type { AbortOptions } from '../utils' +import type { PeerId } from '@libp2p/interfaces/peer-id' export interface API { /** @@ -24,7 +25,7 @@ export interface API { * // [ CID('QmHash') ] * ``` */ - wantlistForPeer: (peerId: string, options?: AbortOptions & OptionExtension) => Promise + wantlistForPeer: (peerId: PeerId, options?: AbortOptions & OptionExtension) => Promise /** * Removes one or more CIDs from the wantlist diff --git a/packages/ipfs-core-types/src/bootstrap/index.ts b/packages/ipfs-core-types/src/bootstrap/index.ts index cc2c0a6257..eeb508a783 100644 --- a/packages/ipfs-core-types/src/bootstrap/index.ts +++ b/packages/ipfs-core-types/src/bootstrap/index.ts @@ -1,5 +1,5 @@ import type { AbortOptions } from '../utils' -import type { Multiaddr } from 'multiaddr' +import type { Multiaddr } from '@multiformats/multiaddr' export interface API { /** diff --git a/packages/ipfs-core-types/src/dht/index.ts b/packages/ipfs-core-types/src/dht/index.ts index 209dfc048b..5b9d38ab42 100644 --- a/packages/ipfs-core-types/src/dht/index.ts +++ b/packages/ipfs-core-types/src/dht/index.ts @@ -1,6 +1,7 @@ import type { AbortOptions } from '../utils' -import type { Multiaddr } from 'multiaddr' import type { CID } from 'multiformats/cid' +import type { PeerId } from '@libp2p/interfaces/peer-id' +import type { QueryEvent } from '@libp2p/interfaces/dht' export interface API { /** @@ -21,7 +22,7 @@ export interface API { * // '/ip4/147.75.94.115/tcp/4001' * ``` */ - findPeer: (peerId: string, options?: AbortOptions & OptionExtension) => AsyncIterable + findPeer: (peerId: PeerId, options?: AbortOptions & OptionExtension) => AsyncIterable /** * Find peers in the DHT that can provide a specific value, given a CID. @@ -58,109 +59,9 @@ export interface API { /** * Find the closest peers to a given `PeerId` or `CID`, by querying the DHT. */ - query: (peerId: string | CID, options?: AbortOptions & OptionExtension) => AsyncIterable -} - -export interface PeerResult { - id: string - addrs: Multiaddr[] + query: (peerId: PeerId | CID, options?: AbortOptions & OptionExtension) => AsyncIterable } export interface DHTProvideOptions extends AbortOptions { recursive?: boolean } - -export interface PeerData { - id: string - multiaddrs: Multiaddr[] -} - -export enum EventTypes { - SENDING_QUERY = 0, - PEER_RESPONSE, - FINAL_PEER, - QUERY_ERROR, - PROVIDER, - VALUE, - ADDING_PEER, - DIALING_PEER -} - -/** - * The types of messages set/received during DHT queries - */ -export enum MessageType { - PUT_VALUE = 0, - GET_VALUE, - ADD_PROVIDER, - GET_PROVIDERS, - FIND_NODE, - PING -} - -export type MessageName = keyof typeof MessageType - -export interface DHTRecord { - key: Uint8Array - value: Uint8Array - timeReceived?: Date -} - -export interface SendingQueryEvent { - to: string - type: EventTypes.SENDING_QUERY - name: 'SENDING_QUERY' -} - -export interface PeerResponseEvent { - from: string - type: EventTypes.PEER_RESPONSE - name: 'PEER_RESPONSE' - messageType: MessageType - messageName: MessageName - providers: PeerData[] - closer: PeerData[] - record?: DHTRecord -} - -export interface FinalPeerEvent { - from: string - peer: PeerData - type: EventTypes.FINAL_PEER - name: 'FINAL_PEER' -} - -export interface QueryErrorEvent { - from: string - type: EventTypes.QUERY_ERROR - name: 'QUERY_ERROR' - error: Error -} - -export interface ProviderEvent { - from: string - type: EventTypes.PROVIDER - name: 'PROVIDER' - providers: PeerData[] -} - -export interface ValueEvent { - from: string - type: EventTypes.VALUE - name: 'VALUE' - value: Uint8Array -} - -export interface AddingPeerEvent { - type: EventTypes.ADDING_PEER - name: 'ADDING_PEER' - peer: string -} - -export interface DialingPeerEvent { - peer: string - type: EventTypes.DIALING_PEER - name: 'DIALING_PEER' -} - -export type QueryEvent = SendingQueryEvent | PeerResponseEvent | FinalPeerEvent | QueryErrorEvent | ProviderEvent | ValueEvent | AddingPeerEvent | DialingPeerEvent diff --git a/packages/ipfs-core-types/src/key/index.ts b/packages/ipfs-core-types/src/key/index.ts index fa1f5f213e..a848196a8d 100644 --- a/packages/ipfs-core-types/src/key/index.ts +++ b/packages/ipfs-core-types/src/key/index.ts @@ -1,4 +1,5 @@ import type { AbortOptions } from '../utils' +import type { KeyType } from '@libp2p/interfaces/keychain' export interface API { /** @@ -109,8 +110,8 @@ export interface API { } export interface GenOptions extends AbortOptions { - type: string - size: number + type: KeyType + size?: number } export interface Key { diff --git a/packages/ipfs-core-types/src/name/index.ts b/packages/ipfs-core-types/src/name/index.ts index a3f83287c9..300c899f3c 100644 --- a/packages/ipfs-core-types/src/name/index.ts +++ b/packages/ipfs-core-types/src/name/index.ts @@ -1,6 +1,7 @@ import type { CID } from 'multiformats/cid' import type { AbortOptions } from '../utils' import type { API as PubsubAPI } from './pubsub' +import type { PeerId } from '@libp2p/interfaces/peer-id' export interface API { /** @@ -36,7 +37,7 @@ export interface API { * // Logs: /ipfs/QmQrX8hka2BtNHa8N8arAq16TCVx5qHcb46c5yPewRycLm * ``` */ - resolve: (value: string, options?: ResolveOptions & OptionExtension) => AsyncIterable + resolve: (value: PeerId | string, options?: ResolveOptions & OptionExtension) => AsyncIterable pubsub: PubsubAPI } diff --git a/packages/ipfs-core-types/src/pin/remote/index.ts b/packages/ipfs-core-types/src/pin/remote/index.ts index e5493e845d..49497b954b 100644 --- a/packages/ipfs-core-types/src/pin/remote/index.ts +++ b/packages/ipfs-core-types/src/pin/remote/index.ts @@ -1,5 +1,5 @@ import type { CID } from 'multiformats/cid' -import type { Multiaddr } from 'multiaddr' +import type { Multiaddr } from '@multiformats/multiaddr' import type { API as Service } from './service' import type { AbortOptions } from '../../utils' diff --git a/packages/ipfs-core-types/src/pubsub/index.ts b/packages/ipfs-core-types/src/pubsub/index.ts index 6acafdb718..fbac8ed74b 100644 --- a/packages/ipfs-core-types/src/pubsub/index.ts +++ b/packages/ipfs-core-types/src/pubsub/index.ts @@ -1,4 +1,7 @@ import type { AbortOptions } from '../utils' +import type { PeerId } from '@libp2p/interfaces/peer-id' +import type { Message } from '@libp2p/interfaces/pubsub' +import type { EventHandler } from '@libp2p/interfaces/events' export interface API { /** @@ -13,7 +16,7 @@ export interface API { * console.log(`subscribed to ${topic}`) * ``` */ - subscribe: (topic: string, handler: MessageHandlerFn, options?: SubscribeOptions & OptionExtension) => Promise + subscribe: (topic: string, handler: EventHandler, options?: SubscribeOptions & OptionExtension) => Promise /** * Unsubscribes from a pubsub topic @@ -38,7 +41,7 @@ export interface API { * await ipfs.pubsub.unsubscribe(topic); * ``` */ - unsubscribe: (topic: string, handler?: MessageHandlerFn, options?: AbortOptions & OptionExtension) => Promise + unsubscribe: (topic: string, handler?: EventHandler, options?: AbortOptions & OptionExtension) => Promise /** * Publish a data message to a pubsub topic @@ -71,18 +74,11 @@ export interface API { * console.log(peerIds) * ``` */ - peers: (topic: string, options?: AbortOptions & OptionExtension) => Promise + peers: (topic: string, options?: AbortOptions & OptionExtension) => Promise setMaxListeners?: (max: number) => void } -export interface Message { - from: string - seqno: Uint8Array - data: Uint8Array - topicIDs: string[] -} - export interface SubscribeOptions extends AbortOptions { /** * A callback to receive an error if one occurs during processing @@ -90,5 +86,3 @@ export interface SubscribeOptions extends AbortOptions { */ onError?: (err: Error) => void } - -export interface MessageHandlerFn { (message: Message): void } diff --git a/packages/ipfs-core-types/src/root.ts b/packages/ipfs-core-types/src/root.ts index e885c7d015..6ca27dcdc4 100644 --- a/packages/ipfs-core-types/src/root.ts +++ b/packages/ipfs-core-types/src/root.ts @@ -1,7 +1,8 @@ import type { AbortOptions, PreloadOptions, IPFSPath, ImportCandidateStream, ImportCandidate } from './utils' import type { CID, CIDVersion } from 'multiformats/cid' import type { Mtime } from 'ipfs-unixfs' -import type { Multiaddr } from 'multiaddr' +import type { Multiaddr } from '@multiformats/multiaddr' +import type { PeerId } from '@libp2p/interfaces/peer-id' export interface API { /** @@ -81,7 +82,7 @@ export interface API { * } * ``` */ - ping: (peerId: string, options?: PingOptions & OptionExtension) => AsyncIterable + ping: (peerId: PeerId, options?: PingOptions & OptionExtension) => AsyncIterable /** * Resolve the value of names to IPFS @@ -267,11 +268,11 @@ export interface ListOptions extends AbortOptions, PreloadOptions { } export interface IDOptions extends AbortOptions { - peerId?: string + peerId?: PeerId } export interface IDResult { - id: string + id: PeerId publicKey: string addresses: Multiaddr[] agentVersion: string diff --git a/packages/ipfs-core-types/src/swarm/index.ts b/packages/ipfs-core-types/src/swarm/index.ts index f174272922..48849531e6 100644 --- a/packages/ipfs-core-types/src/swarm/index.ts +++ b/packages/ipfs-core-types/src/swarm/index.ts @@ -1,5 +1,6 @@ import type { AbortOptions } from '../utils' -import type { Multiaddr } from 'multiaddr' +import type { Multiaddr } from '@multiformats/multiaddr' +import type { PeerId } from '@libp2p/interfaces/peer-id' export interface API { /** @@ -10,12 +11,12 @@ export interface API { /** * Open a connection to a given address or peer id */ - connect: (addr: Multiaddr | string, options?: AbortOptions & OptionExtension) => Promise + connect: (multiaddrOrPeerId: Multiaddr | PeerId, options?: AbortOptions & OptionExtension) => Promise /** * Close a connection to a given address or peer id */ - disconnect: (addr: Multiaddr | string, options?: AbortOptions & OptionExtension) => Promise + disconnect: (multiaddrOrPeerId: Multiaddr | PeerId, options?: AbortOptions & OptionExtension) => Promise /** * Local addresses this node is listening on @@ -29,7 +30,7 @@ export interface API { } export interface AddrsResult { - id: string + id: PeerId addrs: Multiaddr[] } @@ -42,7 +43,7 @@ export interface PeersOptions extends AbortOptions { export interface PeersResult { addr: Multiaddr - peer: string + peer: PeerId latency?: string muxer?: string streams?: string[] diff --git a/packages/ipfs-core-utils/.aegir.cjs b/packages/ipfs-core-utils/.aegir.js similarity index 73% rename from packages/ipfs-core-utils/.aegir.cjs rename to packages/ipfs-core-utils/.aegir.js index ef3e3aa890..3932c3dab3 100644 --- a/packages/ipfs-core-utils/.aegir.cjs +++ b/packages/ipfs-core-utils/.aegir.js @@ -1,7 +1,6 @@ -'use strict' /** @type {import('aegir').PartialOptions} */ -module.exports = { +export default { build: { bundlesizeMax: '540B' } diff --git a/packages/ipfs-core-utils/package.json b/packages/ipfs-core-utils/package.json index d15f863947..a87cbf6392 100644 --- a/packages/ipfs-core-utils/package.json +++ b/packages/ipfs-core-utils/package.json @@ -107,13 +107,15 @@ "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", "test:electron-main": "aegir build --esm-tests && aegir test -t electron-main -f ./dist/cjs/node-test/**/*.spec.js", "test:electron-renderer": "aegir build --esm-tests && aegir test -t electron-renderer -f ./dist/cjs/browser-test/**/*.spec.js", - "lint": "aegir ts -p check && aegir lint", + "lint": "aegir lint", "clean": "rimraf ./dist", "dep-check": "aegir dep-check -i rimraf -i ipfs-core-types", "build": "aegir build" }, "license": "MIT", "dependencies": { + "@multiformats/multiaddr": "^10.0.0", + "@multiformats/multiaddr-to-uri": "^9.0.1", "any-signal": "^3.0.0", "blob-to-it": "^1.0.1", "browser-readablestream-to-it": "^1.0.1", @@ -127,8 +129,6 @@ "it-peekable": "^1.0.2", "it-to-stream": "^1.0.0", "merge-options": "^3.0.4", - "multiaddr": "^10.0.0", - "multiaddr-to-uri": "^8.0.0", "multiformats": "^9.5.1", "nanoid": "^3.1.23", "parse-duration": "^1.0.0", @@ -136,8 +136,8 @@ "uint8arrays": "^3.0.0" }, "devDependencies": { - "@web-std/file": "^1.1.2", - "aegir": "^36.0.1", + "@web-std/file": "^3.0.2", + "aegir": "^37.0.11", "rimraf": "^3.0.2" } } diff --git a/packages/ipfs-core-utils/src/files/normalise-candidate-multiple.js b/packages/ipfs-core-utils/src/files/normalise-candidate-multiple.js index a57a61da28..8022e552aa 100644 --- a/packages/ipfs-core-utils/src/files/normalise-candidate-multiple.js +++ b/packages/ipfs-core-utils/src/files/normalise-candidate-multiple.js @@ -42,11 +42,7 @@ export async function * normaliseCandidateMultiple (input, normaliseContent) { // Iterable if (Symbol.iterator in input || Symbol.asyncIterator in input) { - /** @type {any} */ - // @ts-ignore it's (async)interable const peekable = itPeekable(input) - - /** @type {any} value **/ const { value, done } = await peekable.peek() if (done) { @@ -64,13 +60,15 @@ export async function * normaliseCandidateMultiple (input, normaliseContent) { } // (Async)Iterable + // @ts-expect-error private field if (value._readableState) { - // @ts-ignore Node fs.ReadStreams have a `.path` property so we need to pass it as the content + // @ts-expect-error Node fs.ReadStreams have a `.path` property so we need to pass it as the content yield * map(peekable, (/** @type {ImportCandidate} */ value) => toFileObject({ content: value }, normaliseContent)) return } if (isBytes(value)) { + // @ts-expect-error peekable is still an iterable of ImportCandidates yield toFileObject({ content: peekable }, normaliseContent) return } @@ -100,7 +98,7 @@ export async function * normaliseCandidateMultiple (input, normaliseContent) { * @param {(content:ToContent) => Promise>} normaliseContent */ async function toFileObject (input, normaliseContent) { - // @ts-ignore - Those properties don't exist on most input types + // @ts-expect-error - Those properties don't exist on most input types const { path, mode, mtime, content } = input /** @type {ImporterImportCandidate} */ @@ -113,7 +111,7 @@ async function toFileObject (input, normaliseContent) { if (content) { file.content = await normaliseContent(content) } else if (!path) { // Not already a file object with path or content prop - // @ts-ignore - input still can be different ToContent + // @ts-expect-error - input still can be different ToContent file.content = await normaliseContent(input) } diff --git a/packages/ipfs-core-utils/src/files/normalise-candidate-single.js b/packages/ipfs-core-utils/src/files/normalise-candidate-single.js index f66afefe00..1616cde954 100644 --- a/packages/ipfs-core-utils/src/files/normalise-candidate-single.js +++ b/packages/ipfs-core-utils/src/files/normalise-candidate-single.js @@ -49,7 +49,7 @@ export async function * normaliseCandidateSingle (input, normaliseContent) { // Iterable if (Symbol.iterator in input || Symbol.asyncIterator in input) { - // @ts-ignore it's (async)iterable + // @ts-expect-error it's (async)iterable const peekable = itPeekable(input) /** @type {any} value **/ @@ -90,7 +90,7 @@ export async function * normaliseCandidateSingle (input, normaliseContent) { * @param {(content:ToContent) => Promise>} normaliseContent */ async function toFileObject (input, normaliseContent) { - // @ts-ignore - Those properties don't exist on most input types + // @ts-expect-error - Those properties don't exist on most input types const { path, mode, mtime, content } = input /** @type {ImporterImportCandidate} */ @@ -103,7 +103,7 @@ async function toFileObject (input, normaliseContent) { if (content) { file.content = await normaliseContent(content) } else if (!path) { // Not already a file object with path or content prop - // @ts-ignore - input still can be different ToContent + // @ts-expect-error - input still can be different ToContent file.content = await normaliseContent(input) } diff --git a/packages/ipfs-core-utils/src/multipart-request.js b/packages/ipfs-core-utils/src/multipart-request.js index 2e2a503e23..2b282f2961 100644 --- a/packages/ipfs-core-utils/src/multipart-request.js +++ b/packages/ipfs-core-utils/src/multipart-request.js @@ -19,7 +19,7 @@ export async function multipartRequest (source, abortController, headers = {}, b // In electron-renderer we use native fetch and should encode body using native // form data. if (isElectronRenderer) { - // @ts-ignore types are different + // @ts-expect-error types are different req = multipartRequestBrowser } diff --git a/packages/ipfs-core-utils/src/multipart-request.node.js b/packages/ipfs-core-utils/src/multipart-request.node.js index c0d1417d09..b1bba42c08 100644 --- a/packages/ipfs-core-utils/src/multipart-request.node.js +++ b/packages/ipfs-core-utils/src/multipart-request.node.js @@ -4,11 +4,11 @@ import { modeToString } from './mode-to-string.js' import mergeOpts from 'merge-options' // @ts-expect-error no types import toStream from 'it-to-stream' -import debug from 'debug' +import { logger } from '@libp2p/logger' import itPeekable from 'it-peekable' const merge = mergeOpts.bind({ ignoreUndefined: true }) -const log = debug('ipfs:core-utils:multipart-request') +const log = logger('ipfs:core-utils:multipart-request') /** * @typedef {import('ipfs-core-types/src/utils').ImportCandidateStream} ImportCandidateStream @@ -28,7 +28,7 @@ export async function multipartRequest (source, abortController, headers = {}, b try { let index = 0 - // @ts-ignore + // @ts-expect-error for await (const { content, path, mode, mtime } of source) { let fileSuffix = '' const type = content ? 'file' : 'dir' diff --git a/packages/ipfs-core-utils/src/pins/normalise-input.js b/packages/ipfs-core-utils/src/pins/normalise-input.js index ed9faa16f1..feef80f43c 100644 --- a/packages/ipfs-core-utils/src/pins/normalise-input.js +++ b/packages/ipfs-core-utils/src/pins/normalise-input.js @@ -2,7 +2,7 @@ import errCode from 'err-code' import { CID } from 'multiformats/cid' /** - * @typedef {Object} Pinnable + * @typedef {object} Pinnable * @property {string | InstanceType | CID} [path] * @property {CID} [cid] * @property {boolean} [recursive] @@ -11,7 +11,7 @@ import { CID } from 'multiformats/cid' * @typedef {CID|string|InstanceType|Pinnable} ToPin * @typedef {ToPin|Iterable|AsyncIterable} Source * - * @typedef {Object} Pin + * @typedef {object} Pin * @property {string|CID} path * @property {boolean} recursive * @property {any} [metadata] @@ -64,15 +64,15 @@ export async function * normaliseInput (input) { } // { cid: CID recursive, metadata } - // @ts-ignore - it still could be iterable or async iterable + // @ts-expect-error - it still could be iterable or async iterable if (input.cid != null || input.path != null) { - // @ts-ignore + // @ts-expect-error return yield toPin(input) } // Iterable if (Symbol.iterator in input) { - // @ts-ignore + // @ts-expect-error const iterator = input[Symbol.iterator]() const first = iterator.next() if (first.done) return iterator @@ -100,7 +100,7 @@ export async function * normaliseInput (input) { // AsyncIterable if (Symbol.asyncIterator in input) { - // @ts-ignore + // @ts-expect-error const iterator = input[Symbol.asyncIterator]() const first = await iterator.next() if (first.done) return iterator diff --git a/packages/ipfs-core-utils/src/to-url-string.js b/packages/ipfs-core-utils/src/to-url-string.js index 8c1505c1cd..9750cc14fd 100644 --- a/packages/ipfs-core-utils/src/to-url-string.js +++ b/packages/ipfs-core-utils/src/to-url-string.js @@ -1,4 +1,4 @@ -import { Multiaddr } from 'multiaddr' +import { Multiaddr } from '@multiformats/multiaddr' // @ts-expect-error no types import multiAddrToUri from 'multiaddr-to-uri' diff --git a/packages/ipfs-core-utils/src/with-timeout-option.js b/packages/ipfs-core-utils/src/with-timeout-option.js index 550ccdcda7..46a0068027 100644 --- a/packages/ipfs-core-utils/src/with-timeout-option.js +++ b/packages/ipfs-core-utils/src/with-timeout-option.js @@ -52,11 +52,11 @@ export function withTimeoutOption (fn, optionsArgIndex) { } } - // @ts-ignore + // @ts-expect-error if (fnRes[Symbol.asyncIterator]) { - // @ts-ignore + // @ts-expect-error return (async function * () { - // @ts-ignore + // @ts-expect-error const it = fnRes[Symbol.asyncIterator]() try { @@ -85,7 +85,7 @@ export function withTimeoutOption (fn, optionsArgIndex) { })() } - // @ts-ignore + // @ts-expect-error return (async () => { try { const res = await Promise.race([fnRes, timeoutPromise]) diff --git a/packages/ipfs-core-utils/test/files/format-mode.spec.js b/packages/ipfs-core-utils/test/files/format-mode.spec.js index 65e89446d6..02bb41235d 100644 --- a/packages/ipfs-core-utils/test/files/format-mode.spec.js +++ b/packages/ipfs-core-utils/test/files/format-mode.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { formatMode } from '../../src/files/format-mode.js' describe('format-mode', function () { diff --git a/packages/ipfs-core-utils/test/files/format-mtime.spec.js b/packages/ipfs-core-utils/test/files/format-mtime.spec.js index 88cca4434c..e82eb18cb9 100644 --- a/packages/ipfs-core-utils/test/files/format-mtime.spec.js +++ b/packages/ipfs-core-utils/test/files/format-mtime.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { formatMtime } from '../../src/files/format-mtime.js' describe('format-mtime', function () { diff --git a/packages/ipfs-core-utils/test/files/normalise-input-multiple.spec.js b/packages/ipfs-core-utils/test/files/normalise-input-multiple.spec.js index 21614201e4..69bf77d5b8 100644 --- a/packages/ipfs-core-utils/test/files/normalise-input-multiple.spec.js +++ b/packages/ipfs-core-utils/test/files/normalise-input-multiple.spec.js @@ -1,13 +1,13 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import blobToIt from 'blob-to-it' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import all from 'it-all' import { File } from '@web-std/file' import { normaliseInput } from '../../src/files/normalise-input-multiple.js' import { isNode } from 'ipfs-utils/src/env.js' -import resolve from 'aegir/utils/resolve.js' +import resolve from 'aegir/resolve' const { Blob, ReadableStream } = globalThis diff --git a/packages/ipfs-core-utils/test/files/normalise-input-single.spec.js b/packages/ipfs-core-utils/test/files/normalise-input-single.spec.js index 6113e1db67..5da756ba86 100644 --- a/packages/ipfs-core-utils/test/files/normalise-input-single.spec.js +++ b/packages/ipfs-core-utils/test/files/normalise-input-single.spec.js @@ -1,13 +1,13 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import blobToIt from 'blob-to-it' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import all from 'it-all' import { File } from '@web-std/file' import { normaliseInput } from '../../src/files/normalise-input-single.js' import { isNode } from 'ipfs-utils/src/env.js' -import resolve from 'aegir/utils/resolve.js' +import resolve from 'aegir/resolve' const { Blob, ReadableStream } = globalThis diff --git a/packages/ipfs-core-utils/test/pins/normalise-input.spec.js b/packages/ipfs-core-utils/test/pins/normalise-input.spec.js index 15f3b74d6b..f4749caee0 100644 --- a/packages/ipfs-core-utils/test/pins/normalise-input.spec.js +++ b/packages/ipfs-core-utils/test/pins/normalise-input.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { normaliseInput } from '../../src/pins/normalise-input.js' import all from 'it-all' import { CID } from 'multiformats/cid' diff --git a/packages/ipfs-core/.aegir.cjs b/packages/ipfs-core/.aegir.js similarity index 84% rename from packages/ipfs-core/.aegir.cjs rename to packages/ipfs-core/.aegir.js index 1899998283..0048e202de 100644 --- a/packages/ipfs-core/.aegir.cjs +++ b/packages/ipfs-core/.aegir.js @@ -1,7 +1,8 @@ -'use strict' +import { createServer } from 'ipfsd-ctl' +import path from 'path' +import { fileURLToPath } from 'url' -const { createServer } = require('ipfsd-ctl') -const path = require('path') +const __dirname = path.dirname(fileURLToPath(import.meta.url)) /** @type {import('aegir').Options["build"]["config"]} */ const esbuild = { @@ -19,7 +20,7 @@ const esbuild = { } /** @type {import('aegir').PartialOptions} */ -module.exports = { +export default { test: { browser: { config: { @@ -38,7 +39,7 @@ module.exports = { }, { type: 'js', ipfsModule: await import('./src/index.js'), - ipfsHttpModule: await import('../ipfs-http-client/src/index.js'), + ipfsHttpModule: await import('ipfs-http-client/src'), ipfsBin: path.resolve('../ipfs/src/cli.js'), ipfsOptions: { libp2p: { @@ -49,7 +50,7 @@ module.exports = { } }, { go: { - ipfsBin: require('go-ipfs').path() + ipfsBin: (await import('go-ipfs')).default.path() } }).start() return { diff --git a/packages/ipfs-core/package.json b/packages/ipfs-core/package.json index 09ba7f322a..8344f3eb63 100644 --- a/packages/ipfs-core/package.json +++ b/packages/ipfs-core/package.json @@ -52,7 +52,7 @@ "build": "run-s build:*", "build:update-version": "node scripts/update-version.js", "build:aegir": "aegir build", - "lint": "aegir ts -p check && aegir lint", + "lint": "aegir lint", "test": "aegir test", "test:node": "aegir test -t node --cov", "test:chrome": "aegir test -t browser --cov", @@ -61,32 +61,41 @@ "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", "test:electron-main": "aegir build --esm-tests && aegir test -t electron-main -f ./dist/cjs/node-test/*.spec.js", "test:electron-renderer": "aegir build --esm-tests && aegir test -t electron-renderer -f ./dist/cjs/browser-test/*.spec.js", - "test:bootstrapers": "IPFS_TEST=bootstrapers aegir test -t browser -f test/bootstrapers.js", + "test:bootstrapers": "IPFS_TEST=bootstrapers aegir test -t browser -f test/bootstrappers.js", "clean": "rimraf ./dist", "dep-check": "aegir dep-check -i interface-ipfs-core -i ipfs-core-types -i npm-run-all --i interface-blockstore" }, "dependencies": { - "@chainsafe/libp2p-noise": "^5.0.0", - "@ipld/car": "^3.1.0", + "@chainsafe/libp2p-noise": "^6.0.1", + "@ipld/car": "^4.0.0", "@ipld/dag-cbor": "^7.0.0", "@ipld/dag-json": "^8.0.1", "@ipld/dag-pb": "^2.1.3", + "@libp2p/bootstrap": "^1.0.2", + "@libp2p/crypto": "^0.22.9", + "@libp2p/delegated-content-routing": "^1.0.2", + "@libp2p/delegated-peer-routing": "^1.0.2", + "@libp2p/peer-id": "^1.1.8", + "@libp2p/record": "^1.0.1", + "@multiformats/mafmt": "^11.0.2", + "@multiformats/multiaddr": "^10.1.8", + "@multiformats/multiaddr-to-uri": "^9.0.1", "@multiformats/murmur3": "^1.1.1", "any-signal": "^3.0.0", - "array-shuffle": "^2.0.0", + "array-shuffle": "^3.0.0", "blockstore-core": "^1.0.2", "blockstore-datastore-adapter": "^2.0.2", "dag-jose": "^1.0.0", "datastore-core": "^7.0.0", - "datastore-pubsub": "^2.0.0", + "datastore-pubsub": "^3.0.0", "debug": "^4.1.1", "dlv": "^1.1.3", "err-code": "^3.0.1", - "hamt-sharding": "^2.0.0", + "hamt-sharding": "^2.0.1", "hashlru": "^2.3.0", "interface-blockstore": "^2.0.2", "interface-datastore": "^6.0.2", - "ipfs-bitswap": "^10.0.1", + "ipfs-bitswap": "^11.0.0", "ipfs-core-config": "^0.3.2", "ipfs-core-types": "^0.10.2", "ipfs-core-utils": "^0.14.2", @@ -96,7 +105,7 @@ "ipfs-unixfs-exporter": "^7.0.3", "ipfs-unixfs-importer": "^9.0.3", "ipfs-utils": "^9.0.2", - "ipns": "^0.16.0", + "ipns": "^1.0.0", "is-domain-name": "^1.0.1", "is-ipfs": "^6.0.1", "it-all": "^1.0.4", @@ -108,46 +117,37 @@ "it-merge": "^1.0.2", "it-parallel": "^2.0.1", "it-peekable": "^1.0.2", - "it-pipe": "^1.1.0", - "it-pushable": "^1.4.2", - "it-tar": "^4.0.0", + "it-pipe": "^2.0.3", + "it-pushable": "^2.0.1", + "it-tar": "^5.0.0", "it-to-buffer": "^2.0.0", - "just-safe-set": "^2.2.1", - "libp2p": "^0.36.2", - "libp2p-bootstrap": "^0.14.0", - "libp2p-crypto": "^0.21.1", - "libp2p-delegated-content-routing": "^0.11.1", - "libp2p-delegated-peer-routing": "^0.11.0", - "libp2p-record": "^0.10.3", - "mafmt": "^10.0.0", + "just-safe-set": "^4.0.2", + "libp2p": "next", "merge-options": "^3.0.4", - "mortice": "^2.0.0", - "multiaddr": "^10.0.0", - "multiaddr-to-uri": "^8.0.0", + "mortice": "^3.0.0", "multiformats": "^9.5.1", - "pako": "^1.0.2", + "pako": "^2.0.4", "parse-duration": "^1.0.0", - "peer-id": "^0.16.0", "timeout-abort-controller": "^3.0.0", "uint8arrays": "^3.0.0" }, "devDependencies": { + "@achingbrain/libp2p-gossipsub": "^0.13.6", "@types/dlv": "^1.1.2", "@types/pako": "^1.0.2", "@types/rimraf": "^3.0.1", - "aegir": "^36.0.1", + "aegir": "^37.0.11", "delay": "^5.0.0", - "go-ipfs": "0.11.0", + "go-ipfs": "^0.12.1", "interface-blockstore-tests": "^2.0.2", "interface-ipfs-core": "^0.154.2", "ipfsd-ctl": "^10.0.4", "iso-url": "^1.0.0", - "libp2p-gossipsub": "^0.13.0", "nanoid": "^3.1.23", "npm-run-all": "^4.1.5", - "p-defer": "^3.0.0", + "p-defer": "^4.0.0", "rimraf": "^3.0.2", - "sinon": "^12.0.01" + "sinon": "^13.0.1" }, "gitHead": "" } diff --git a/packages/ipfs-core/src/block-storage.js b/packages/ipfs-core/src/block-storage.js index a958a86fd4..19f93999db 100644 --- a/packages/ipfs-core/src/block-storage.js +++ b/packages/ipfs-core/src/block-storage.js @@ -1,6 +1,6 @@ import { BaseBlockstore } from 'blockstore-core' import merge from 'it-merge' -import pushable from 'it-pushable' +import { pushable } from 'it-pushable' import filter from 'it-filter' /** diff --git a/packages/ipfs-core/src/components/add-all/index.js b/packages/ipfs-core/src/components/add-all/index.js index 2cb5a15069..d50ac38b5d 100644 --- a/packages/ipfs-core/src/components/add-all/index.js +++ b/packages/ipfs-core/src/components/add-all/index.js @@ -14,7 +14,13 @@ const mergeOptions = mergeOpts.bind({ ignoreUndefined: true }) */ /** - * @typedef {Object} Context + * @template T + * + * @typedef {import('it-stream-types').Source} Source + */ + +/** + * @typedef {object} Context * @property {import('ipfs-repo').IPFSRepo} repo * @property {import('../../types').Preload} preload * @property {Multihashes} hashers @@ -94,7 +100,7 @@ export function createAddAll ({ repo, preload, hashers, options }) { const iterator = pipe( normaliseInput(source), /** - * @param {AsyncIterable} source + * @param {Source} source */ source => importer(source, repo.blocks, { ...opts, @@ -110,10 +116,15 @@ export function createAddAll ({ repo, preload, hashers, options }) { try { for await (const added of iterator) { + const path = added.path ?? added.cid.toString() + // do not keep file totals around forever - delete totals[added.path] + delete totals[path] - yield added + yield { + ...added, + path + } } } finally { releaseLock() @@ -128,7 +139,7 @@ export function createAddAll ({ repo, preload, hashers, options }) { */ function transformFile (opts) { /** - * @param {AsyncGenerator} source + * @param {Source} source */ async function * transformFile (source) { for await (const file of source) { @@ -163,7 +174,7 @@ function transformFile (opts) { */ function preloadFile (preload, opts) { /** - * @param {AsyncGenerator} source + * @param {Source} source */ async function * maybePreloadFile (source) { for await (const file of source) { @@ -190,7 +201,7 @@ function preloadFile (preload, opts) { */ function pinFile (repo, opts) { /** - * @param {AsyncGenerator} source + * @param {Source} source */ async function * maybePinFile (source) { for await (const file of source) { diff --git a/packages/ipfs-core/src/components/add-all/utils.js b/packages/ipfs-core/src/components/add-all/utils.js index 8447221326..de9c60139e 100644 --- a/packages/ipfs-core/src/components/add-all/utils.js +++ b/packages/ipfs-core/src/components/add-all/utils.js @@ -1,9 +1,9 @@ /** - * @typedef {Object} FixedChunkerOptions + * @typedef {object} FixedChunkerOptions * @property {'fixed'} chunker * @property {number} [maxChunkSize] * - * @typedef {Object} RabinChunkerOptions + * @typedef {object} RabinChunkerOptions * @property {'rabin'} chunker * @property {number} avgChunkSize * @property {number} [minChunkSize] @@ -48,7 +48,7 @@ export const parseChunkerString = (chunker) => { } /** - * @typedef {Object} RabinChunkerSettings + * @typedef {object} RabinChunkerSettings * @property {number} avgChunkSize * @property {number} [minChunkSize] * @property {number} [maxChunkSize] diff --git a/packages/ipfs-core/src/components/add.js b/packages/ipfs-core/src/components/add.js index 836d5ab31d..e54bf3831b 100644 --- a/packages/ipfs-core/src/components/add.js +++ b/packages/ipfs-core/src/components/add.js @@ -2,7 +2,7 @@ import last from 'it-last' import { normaliseInput } from 'ipfs-core-utils/files/normalise-input-single' /** - * @param {Object} context + * @param {object} context * @param {import('ipfs-core-types/src/root').API<{}>["addAll"]} context.addAll */ export function createAdd ({ addAll }) { @@ -10,7 +10,7 @@ export function createAdd ({ addAll }) { * @type {import('ipfs-core-types/src/root').API<{}>["add"]} */ async function add (entry, options = {}) { - // @ts-ignore TODO: https://github.com/ipfs/js-ipfs/issues/3290 + // @ts-expect-error TODO: https://github.com/ipfs/js-ipfs/issues/3290 const result = await last(addAll(normaliseInput(entry), options)) // Note this should never happen as `addAll` should yield at least one item // but to satisfy type checker we perfom this check and for good measure diff --git a/packages/ipfs-core/src/components/bitswap/index.js b/packages/ipfs-core/src/components/bitswap/index.js index f388a6f57d..75e07f045e 100644 --- a/packages/ipfs-core/src/components/bitswap/index.js +++ b/packages/ipfs-core/src/components/bitswap/index.js @@ -5,14 +5,14 @@ import { createStat } from './stat.js' /** * @typedef {import('../../types').NetworkService} NetworkService - * @typedef {import('peer-id')} PeerId + * @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId * @typedef {import('multiformats/cid').CID} CID * @typedef {import('ipfs-core-types/src/utils').AbortOptions} AbortOptions */ export class BitswapAPI { /** - * @param {Object} config + * @param {object} config * @param {NetworkService} config.network */ constructor ({ network }) { diff --git a/packages/ipfs-core/src/components/bitswap/stat.js b/packages/ipfs-core/src/components/bitswap/stat.js index 4f9ecc1e46..1ab18b3d77 100644 --- a/packages/ipfs-core/src/components/bitswap/stat.js +++ b/packages/ipfs-core/src/components/bitswap/stat.js @@ -1,7 +1,7 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** - * @param {Object} config + * @param {object} config * @param {import('../../types').NetworkService} config.network */ export function createStat ({ network }) { @@ -17,7 +17,7 @@ export function createStat ({ network }) { provideBufLen: parseInt(snapshot.providesBufferLength.toString()), blocksReceived: BigInt(snapshot.blocksReceived.toString()), wantlist: Array.from(bitswap.getWantlist()).map(e => e[1].cid), - peers: bitswap.peers().map(id => id.toB58String()), + peers: bitswap.peers().map(id => id.toString()), dupBlksReceived: BigInt(snapshot.dupBlksReceived.toString()), dupDataReceived: BigInt(snapshot.dupDataReceived.toString()), dataReceived: BigInt(snapshot.dataReceived.toString()), diff --git a/packages/ipfs-core/src/components/bitswap/unwant.js b/packages/ipfs-core/src/components/bitswap/unwant.js index 3792e1c014..5fad790c38 100644 --- a/packages/ipfs-core/src/components/bitswap/unwant.js +++ b/packages/ipfs-core/src/components/bitswap/unwant.js @@ -1,7 +1,7 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** - * @param {Object} config + * @param {object} config * @param {import('../../types').NetworkService} config.network */ export function createUnwant ({ network }) { diff --git a/packages/ipfs-core/src/components/bitswap/wantlist-for-peer.js b/packages/ipfs-core/src/components/bitswap/wantlist-for-peer.js index a685d7d123..e49afdef9e 100644 --- a/packages/ipfs-core/src/components/bitswap/wantlist-for-peer.js +++ b/packages/ipfs-core/src/components/bitswap/wantlist-for-peer.js @@ -1,8 +1,7 @@ -import PeerId from 'peer-id' import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** - * @param {Object} config + * @param {object} config * @param {import('../../types').NetworkService} config.network */ export function createWantlistForPeer ({ network }) { @@ -11,7 +10,7 @@ export function createWantlistForPeer ({ network }) { */ async function wantlistForPeer (peerId, options = {}) { const { bitswap } = await network.use(options) - const list = bitswap.wantlistForPeer(PeerId.createFromB58String(peerId)) + const list = bitswap.wantlistForPeer(peerId) return Array.from(list).map(e => e[1].cid) } diff --git a/packages/ipfs-core/src/components/bitswap/wantlist.js b/packages/ipfs-core/src/components/bitswap/wantlist.js index 797d6c2d8a..91d7f60276 100644 --- a/packages/ipfs-core/src/components/bitswap/wantlist.js +++ b/packages/ipfs-core/src/components/bitswap/wantlist.js @@ -1,7 +1,7 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** - * @param {Object} config + * @param {object} config * @param {import('../../types').NetworkService} config.network */ export function createWantlist ({ network }) { diff --git a/packages/ipfs-core/src/components/block/get.js b/packages/ipfs-core/src/components/block/get.js index f6aec6a17f..86cd15aea0 100644 --- a/packages/ipfs-core/src/components/block/get.js +++ b/packages/ipfs-core/src/components/block/get.js @@ -1,7 +1,7 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** - * @param {Object} config + * @param {object} config * @param {import('../../types').Preload} config.preload * @param {import('ipfs-repo').IPFSRepo} config.repo */ diff --git a/packages/ipfs-core/src/components/block/index.js b/packages/ipfs-core/src/components/block/index.js index 06d0197c4f..b4757074de 100644 --- a/packages/ipfs-core/src/components/block/index.js +++ b/packages/ipfs-core/src/components/block/index.js @@ -9,7 +9,7 @@ import { createStat } from './stat.js' export class BlockAPI { /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-core-utils/src/multihashes').Multihashes} config.hashers * @param {import('ipfs-core-utils/src/multicodecs').Multicodecs} config.codecs * @param {Preload} config.preload diff --git a/packages/ipfs-core/src/components/block/put.js b/packages/ipfs-core/src/components/block/put.js index 2a294a4cbc..1066790f44 100644 --- a/packages/ipfs-core/src/components/block/put.js +++ b/packages/ipfs-core/src/components/block/put.js @@ -6,7 +6,7 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' */ /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-core-utils/multicodecs').Multicodecs} config.codecs * @param {import('ipfs-core-utils/multihashes').Multihashes} config.hashers * @param {import('ipfs-repo').IPFSRepo} config.repo diff --git a/packages/ipfs-core/src/components/block/rm.js b/packages/ipfs-core/src/components/block/rm.js index e8fe0498f0..4169d56f2c 100644 --- a/packages/ipfs-core/src/components/block/rm.js +++ b/packages/ipfs-core/src/components/block/rm.js @@ -9,7 +9,7 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' const BLOCK_RM_CONCURRENCY = 8 /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo */ export function createRm ({ repo }) { diff --git a/packages/ipfs-core/src/components/block/stat.js b/packages/ipfs-core/src/components/block/stat.js index 52fb6b6a30..1ba6a9c58c 100644 --- a/packages/ipfs-core/src/components/block/stat.js +++ b/packages/ipfs-core/src/components/block/stat.js @@ -2,7 +2,7 @@ import { cleanCid } from './utils.js' import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo * @param {import('../../types').Preload} config.preload */ diff --git a/packages/ipfs-core/src/components/bootstrap/add.js b/packages/ipfs-core/src/components/bootstrap/add.js index 24ad645ddd..acaf5ada42 100644 --- a/packages/ipfs-core/src/components/bootstrap/add.js +++ b/packages/ipfs-core/src/components/bootstrap/add.js @@ -2,7 +2,7 @@ import { isValidMultiaddr } from './utils.js' import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo */ export function createAdd ({ repo }) { @@ -14,10 +14,7 @@ export function createAdd ({ repo }) { throw new Error(`${multiaddr} is not a valid Multiaddr`) } - /** @type {import('ipfs-core-types/src/config').Config} */ - // @ts-ignore repo returns type unknown const config = await repo.config.getAll(options) - const boostrappers = config.Bootstrap || [] boostrappers.push(multiaddr.toString()) diff --git a/packages/ipfs-core/src/components/bootstrap/clear.js b/packages/ipfs-core/src/components/bootstrap/clear.js index b5c65f0316..e261f446c2 100644 --- a/packages/ipfs-core/src/components/bootstrap/clear.js +++ b/packages/ipfs-core/src/components/bootstrap/clear.js @@ -1,8 +1,8 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' -import { Multiaddr } from 'multiaddr' +import { Multiaddr } from '@multiformats/multiaddr' /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo */ export function createClear ({ repo }) { @@ -10,8 +10,6 @@ export function createClear ({ repo }) { * @type {import('ipfs-core-types/src/bootstrap').API<{}>["clear"]} */ async function clear (options = {}) { - /** @type {import('ipfs-core-types/src/config').Config} */ - // @ts-ignore repo returns type unknown const config = await repo.config.getAll(options) const removed = config.Bootstrap || [] config.Bootstrap = [] diff --git a/packages/ipfs-core/src/components/bootstrap/index.js b/packages/ipfs-core/src/components/bootstrap/index.js index 7fe18e7b98..c508ff60b8 100644 --- a/packages/ipfs-core/src/components/bootstrap/index.js +++ b/packages/ipfs-core/src/components/bootstrap/index.js @@ -5,7 +5,7 @@ import { createReset } from './reset.js' import { createRm } from './rm.js' export class BootstrapAPI { /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo */ constructor ({ repo }) { diff --git a/packages/ipfs-core/src/components/bootstrap/list.js b/packages/ipfs-core/src/components/bootstrap/list.js index 777ce07e11..392224cf71 100644 --- a/packages/ipfs-core/src/components/bootstrap/list.js +++ b/packages/ipfs-core/src/components/bootstrap/list.js @@ -1,8 +1,8 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' -import { Multiaddr } from 'multiaddr' +import { Multiaddr } from '@multiformats/multiaddr' /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo */ export function createList ({ repo }) { diff --git a/packages/ipfs-core/src/components/bootstrap/reset.js b/packages/ipfs-core/src/components/bootstrap/reset.js index 375837acae..6b1d3c1a88 100644 --- a/packages/ipfs-core/src/components/bootstrap/reset.js +++ b/packages/ipfs-core/src/components/bootstrap/reset.js @@ -1,9 +1,9 @@ import defaultConfig from 'ipfs-core-config/config' import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' -import { Multiaddr } from 'multiaddr' +import { Multiaddr } from '@multiformats/multiaddr' /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo */ export function createReset ({ repo }) { @@ -11,8 +11,6 @@ export function createReset ({ repo }) { * @type {import('ipfs-core-types/src/bootstrap').API<{}>["reset"]} */ async function reset (options = {}) { - /** @type {import('ipfs-core-types/src/config').Config} */ - // @ts-ignore repo returns type unknown const config = await repo.config.getAll(options) config.Bootstrap = defaultConfig().Bootstrap diff --git a/packages/ipfs-core/src/components/bootstrap/rm.js b/packages/ipfs-core/src/components/bootstrap/rm.js index b2123e327c..d0d4e0e8b4 100644 --- a/packages/ipfs-core/src/components/bootstrap/rm.js +++ b/packages/ipfs-core/src/components/bootstrap/rm.js @@ -2,7 +2,7 @@ import { isValidMultiaddr } from './utils.js' import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo */ export function createRm ({ repo }) { @@ -14,8 +14,6 @@ export function createRm ({ repo }) { throw new Error(`${multiaddr} is not a valid Multiaddr`) } - /** @type {import('ipfs-core-types/src/config').Config} */ - // @ts-ignore repo returns type unknown const config = await repo.config.getAll(options) config.Bootstrap = (config.Bootstrap || []).filter(ma => ma.toString() !== multiaddr.toString()) diff --git a/packages/ipfs-core/src/components/cat.js b/packages/ipfs-core/src/components/cat.js index f837fc59f4..6df851f992 100644 --- a/packages/ipfs-core/src/components/cat.js +++ b/packages/ipfs-core/src/components/cat.js @@ -4,7 +4,7 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' import { CID } from 'multiformats/cid' /** - * @typedef {Object} Context + * @typedef {object} Context * @property {import('ipfs-repo').IPFSRepo} repo * @property {import('../types').Preload} preload * diff --git a/packages/ipfs-core/src/components/config/index.js b/packages/ipfs-core/src/components/config/index.js index 21f5a83e8d..127a82d83b 100644 --- a/packages/ipfs-core/src/components/config/index.js +++ b/packages/ipfs-core/src/components/config/index.js @@ -1,11 +1,11 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' -import debug from 'debug' +import { logger } from '@libp2p/logger' import { profiles } from './profiles.js' -const log = debug('ipfs:core:config') +const log = logger('ipfs:core:config') /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo */ export function createConfig ({ repo }) { @@ -24,7 +24,6 @@ export function createConfig ({ repo }) { * @type {import('ipfs-core-types/src/config').API<{}>["getAll"]} */ async function getAll (options = {}) { // eslint-disable-line require-await - // @ts-ignore TODO: move config typedefs into ipfs-repo return repo.config.getAll(options) } @@ -36,7 +35,6 @@ export function createConfig ({ repo }) { return Promise.reject(new Error('key argument is required')) } - // @ts-ignore TODO: move config typedefs into ipfs-repo return repo.config.get(key, options) } @@ -76,11 +74,10 @@ export function createConfig ({ repo }) { } // Scrub private key from output - // @ts-ignore `oldCfg.Identity` maybe undefined + // @ts-expect-error `oldCfg.Identity` maybe undefined delete oldCfg.Identity.PrivKey delete newCfg.Identity.PrivKey - // @ts-ignore TODO: move config typedefs into ipfs-repo return { original: oldCfg, updated: newCfg } } catch (/** @type {any} */ err) { log(err) diff --git a/packages/ipfs-core/src/components/dag/export.js b/packages/ipfs-core/src/components/dag/export.js index 9d559bf7b5..ad37aacb8a 100644 --- a/packages/ipfs-core/src/components/dag/export.js +++ b/packages/ipfs-core/src/components/dag/export.js @@ -2,12 +2,12 @@ import { CID } from 'multiformats/cid' import { createUnsafe } from 'multiformats/block' import { CarWriter } from '@ipld/car/writer' import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' -import debug from 'debug' +import { logger } from '@libp2p/logger' import * as raw from 'multiformats/codecs/raw' import * as json from 'multiformats/codecs/json' import { walk } from 'multiformats/traversal' -const log = debug('ipfs:components:dag:import') +const log = logger('ipfs:components:dag:import') // blocks that we're OK with not inspecting for links /** @type {number[]} */ @@ -29,7 +29,7 @@ const NO_LINKS_CODECS = [ */ /** - * @param {Object} config + * @param {object} config * @param {IPFSRepo} config.repo * @param {Preload} config.preload * @param {import('ipfs-core-utils/multicodecs').Multicodecs} config.codecs diff --git a/packages/ipfs-core/src/components/dag/get.js b/packages/ipfs-core/src/components/dag/get.js index 75cee34a5d..2a69c1301c 100644 --- a/packages/ipfs-core/src/components/dag/get.js +++ b/packages/ipfs-core/src/components/dag/get.js @@ -5,7 +5,7 @@ import { resolve } from '../../utils.js' import errCode from 'err-code' /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-core-utils/multicodecs').Multicodecs} config.codecs * @param {import('ipfs-repo').IPFSRepo} config.repo * @param {import('../../types').Preload} config.preload @@ -23,7 +23,7 @@ export function createGet ({ codecs, repo, preload }) { const entry = options.localResolve ? await first(resolve(cid, options.path, codecs, repo, options)) : await last(resolve(cid, options.path, codecs, repo, options)) - /** @type {import('ipfs-core-types/src/dag').GetResult} - first and last will return undefined when empty */ + /** @type {import('ipfs-core-types/src/dag').GetResult | undefined} - first and last will return undefined when empty */ const result = (entry) if (!result) { diff --git a/packages/ipfs-core/src/components/dag/import.js b/packages/ipfs-core/src/components/dag/import.js index 6b4b852833..f6bfc4bc4a 100644 --- a/packages/ipfs-core/src/components/dag/import.js +++ b/packages/ipfs-core/src/components/dag/import.js @@ -3,8 +3,8 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' import itPeekable from 'it-peekable' import drain from 'it-drain' import map from 'it-map' -import debug from 'debug' -const log = debug('ipfs:components:dag:import') +import { logger } from '@libp2p/logger' +const log = logger('ipfs:components:dag:import') /** * @typedef {import('multiformats/cid').CID} CID @@ -14,7 +14,7 @@ const log = debug('ipfs:components:dag:import') */ /** - * @param {Object} config + * @param {object} config * @param {IPFSRepo} config.repo */ export function createImport ({ repo }) { @@ -35,7 +35,7 @@ export function createImport ({ repo }) { } if (value) { - // @ts-ignore + // @ts-expect-error peekable.push(value) } @@ -45,10 +45,10 @@ export function createImport ({ repo }) { let cars if (value instanceof Uint8Array) { - // @ts-ignore + // @ts-expect-error cars = [peekable] } else { - // @ts-ignore + // @ts-expect-error cars = peekable } diff --git a/packages/ipfs-core/src/components/dag/index.js b/packages/ipfs-core/src/components/dag/index.js index c15e3789de..4a96ad68eb 100644 --- a/packages/ipfs-core/src/components/dag/index.js +++ b/packages/ipfs-core/src/components/dag/index.js @@ -6,7 +6,7 @@ import { createResolve } from './resolve.js' export class DagAPI { /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-core-utils/multihashes').Multihashes} config.hashers * @param {import('ipfs-core-utils/multicodecs').Multicodecs} config.codecs * @param {import('../../types').Preload} config.preload diff --git a/packages/ipfs-core/src/components/dag/put.js b/packages/ipfs-core/src/components/dag/put.js index ebd0e86119..1fc49ab433 100644 --- a/packages/ipfs-core/src/components/dag/put.js +++ b/packages/ipfs-core/src/components/dag/put.js @@ -2,7 +2,7 @@ import { CID } from 'multiformats/cid' import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo * @param {import('ipfs-core-utils/multicodecs').Multicodecs} config.codecs * @param {import('ipfs-core-utils/multihashes').Multihashes} config.hashers diff --git a/packages/ipfs-core/src/components/dag/resolve.js b/packages/ipfs-core/src/components/dag/resolve.js index 0feb0bf244..d7a67866b7 100644 --- a/packages/ipfs-core/src/components/dag/resolve.js +++ b/packages/ipfs-core/src/components/dag/resolve.js @@ -3,7 +3,7 @@ import { toCidAndPath } from 'ipfs-core-utils/to-cid-and-path' import { resolvePath } from '../../utils.js' /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-core-utils/multicodecs').Multicodecs} config.codecs * @param {import('ipfs-repo').IPFSRepo} config.repo * @param {import('../../types').Preload} config.preload diff --git a/packages/ipfs-core/src/components/dht.js b/packages/ipfs-core/src/components/dht.js index e94f21f010..97add61092 100644 --- a/packages/ipfs-core/src/components/dht.js +++ b/packages/ipfs-core/src/components/dht.js @@ -1,18 +1,17 @@ -import PeerId from 'peer-id' import errCode from 'err-code' import { NotEnabledError } from '../errors.js' -import get from 'dlv' import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' -import map from 'it-map' import { CID } from 'multiformats/cid' import { base58btc } from 'multiformats/bases/base58' import { base36 } from 'multiformats/bases/base36' import { concat as uint8ArrayConcat } from 'uint8arrays/concat' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' +import { peerIdFromString } from '@libp2p/peer-id' /** - * @typedef {import('libp2p-kad-dht').QueryEvent} DHTQueryEvent - * @typedef {import('ipfs-core-types/src/dht').QueryEvent} QueryEvent + * @typedef {import('@libp2p/interfaces/dht').QueryEvent} QueryEvent + * @typedef {import('./network').Network} Network + * @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId */ const IPNS_PREFIX = '/ipns/' @@ -65,91 +64,7 @@ function toDHTKey (str) { } /** - * @param {DHTQueryEvent} event - * @returns {QueryEvent} - */ -function mapEvent (event) { - if (event.name === 'SENDING_QUERY') { - return { - type: event.type, - name: event.name, - to: event.to.toB58String() - } - } - - if (event.name === 'PEER_RESPONSE') { - return { - type: event.type, - name: event.name, - messageType: event.messageType, - messageName: event.messageName, - closer: event.closer.map(({ id, multiaddrs }) => ({ id: id.toB58String(), multiaddrs })), - providers: event.providers.map(({ id, multiaddrs }) => ({ id: id.toB58String(), multiaddrs })), - record: event.record, - from: event.from.toB58String() - } - } - - if (event.name === 'FINAL_PEER') { - return { - type: event.type, - name: event.name, - from: event.from.toB58String(), - peer: { - id: event.peer.id.toB58String(), - multiaddrs: event.peer.multiaddrs - } - } - } - - if (event.name === 'QUERY_ERROR') { - return { - type: event.type, - name: event.name, - error: event.error, - from: event.from.toB58String() - } - } - - if (event.name === 'PROVIDER') { - return { - type: event.type, - name: event.name, - providers: event.providers.map(({ id, multiaddrs }) => ({ id: id.toB58String(), multiaddrs })), - from: event.from.toB58String() - } - } - - if (event.name === 'VALUE') { - return { - type: event.type, - name: event.name, - value: event.value, - from: event.from.toB58String() - } - } - - if (event.name === 'ADDING_PEER') { - return { - type: event.type, - name: event.name, - peer: event.peer.toB58String() - } - } - - if (event.name === 'DIALING_PEER') { - return { - type: event.type, - name: event.name, - peer: event.peer.toB58String() - } - } - - throw errCode(new Error('Unknown DHT event type'), 'ERR_UNKNOWN_DHT_EVENT') -} - -/** - * @param {Object} config + * @param {object} config * @param {import('../types').NetworkService} config.network * @param {import('ipfs-repo').IPFSRepo} config.repo * @param {PeerId} config.peerId @@ -164,7 +79,11 @@ export function createDht ({ network, repo, peerId }) { const dhtKey = key instanceof Uint8Array ? key : toDHTKey(key) - yield * map(libp2p._dht.get(dhtKey, options), mapEvent) + if (libp2p.dht == null) { + throw errCode(new Error('dht not configured'), 'ERR_DHT_NOT_CONFIGURED') + } + + yield * libp2p.dht.get(dhtKey, options) }, /** @@ -175,7 +94,11 @@ export function createDht ({ network, repo, peerId }) { const dhtKey = key instanceof Uint8Array ? key : toDHTKey(key) - yield * map(libp2p._dht.put(dhtKey, value), mapEvent) + if (libp2p.dht == null) { + throw errCode(new Error('dht not configured'), 'ERR_DHT_NOT_CONFIGURED') + } + + yield * libp2p.dht.put(dhtKey, value) }, /** @@ -184,9 +107,13 @@ export function createDht ({ network, repo, peerId }) { async * findProvs (cid, options = {}) { const { libp2p } = await use(network, peerId, options) - yield * map(libp2p._dht.findProviders(cid, { + if (libp2p.dht == null) { + throw errCode(new Error('dht not configured'), 'ERR_DHT_NOT_CONFIGURED') + } + + yield * libp2p.dht.findProviders(cid, { signal: options.signal - }), mapEvent) + }) }, /** @@ -195,9 +122,13 @@ export function createDht ({ network, repo, peerId }) { async * findPeer (peerIdToFind, options = {}) { const { libp2p } = await use(network, peerId, options) - yield * map(libp2p._dht.findPeer(PeerId.parse(peerIdToFind), { + if (libp2p.dht == null) { + throw errCode(new Error('dht not configured'), 'ERR_DHT_NOT_CONFIGURED') + } + + yield * libp2p.dht.findPeer(peerIdToFind, { signal: options.signal - }), mapEvent) + }) }, /** @@ -218,7 +149,11 @@ export function createDht ({ network, repo, peerId }) { throw errCode(new Error('not implemented yet'), 'ERR_NOT_IMPLEMENTED_YET') } - yield * map(libp2p._dht.provide(cid), mapEvent) + if (libp2p.dht == null) { + throw errCode(new Error('dht not configured'), 'ERR_DHT_NOT_CONFIGURED') + } + + yield * libp2p.dht.provide(cid) }, /** @@ -232,10 +167,14 @@ export function createDht ({ network, repo, peerId }) { if (asCid != null) { bytes = asCid.multihash.bytes } else { - bytes = PeerId.parse(peerIdToQuery.toString()).toBytes() + bytes = peerIdFromString(peerIdToQuery.toString()).toBytes() + } + + if (libp2p.dht == null) { + throw errCode(new Error('dht not configured'), 'ERR_DHT_NOT_CONFIGURED') } - yield * map(libp2p._dht.getClosestPeers(bytes, options), mapEvent) + yield * libp2p.dht.getClosestPeers(bytes, options) } } @@ -253,10 +192,11 @@ export function createDht ({ network, repo, peerId }) { * @param {import('../types').NetworkService} network * @param {PeerId} peerId * @param {import('ipfs-core-types/src/utils').AbortOptions} [options] + * @returns {Promise} */ const use = async (network, peerId, options) => { const net = await network.use(options) - if (get(net.libp2p, '_config.dht.enabled', false)) { + if (net.libp2p.dht != null) { return net } else { const fn = async function * () { @@ -270,13 +210,19 @@ const use = async (network, peerId, options) => { return { libp2p: { - _dht: { + dht: { + // @ts-expect-error incomplete implementation get: fn, + // @ts-expect-error incomplete implementation put: fn, - findProvs: fn, + // @ts-expect-error incomplete implementation + findProviders: fn, + // @ts-expect-error incomplete implementation findPeer: fn, + // @ts-expect-error incomplete implementation provide: fn, - query: fn + // @ts-expect-error incomplete implementation + getClosestPeers: fn } } } diff --git a/packages/ipfs-core/src/components/files/chmod.js b/packages/ipfs-core/src/components/files/chmod.js index 0fabaca6fe..76783e3c52 100644 --- a/packages/ipfs-core/src/components/files/chmod.js +++ b/packages/ipfs-core/src/components/files/chmod.js @@ -1,6 +1,6 @@ import mergeOpts from 'merge-options' import { toMfsPath } from './utils/to-mfs-path.js' -import debug from 'debug' +import { logger } from '@libp2p/logger' import errCode from 'err-code' import { UnixFS } from 'ipfs-unixfs' import { toTrail } from './utils/to-trail.js' @@ -19,7 +19,7 @@ import { persist } from './utils/persist.js' import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' const mergeOptions = mergeOpts.bind({ ignoreUndefined: true }) -const log = debug('ipfs:mfs:touch') +const log = logger('ipfs:mfs:touch') /** * @typedef {import('multiformats/cid').CIDVersion} CIDVersion @@ -199,7 +199,6 @@ function calculateMode (mode, metadata) { if (strMode.match(/^\d+$/g)) { mode = parseInt(strMode, 8) } else { - // @ts-ignore freaks out over the curr: number, acc: string thing mode = 0 + strMode.split(',').reduce((curr, acc) => { return parseSymbolicMode(acc, curr, metadata.isDirectory()) }, metadata.mode || 0) @@ -255,7 +254,7 @@ export function createChmod (context) { } } }, - // @ts-ignore we account for the incompatible source type with our custom dag builder below + // @ts-expect-error we account for the incompatible source type with our custom dag builder below (source) => importer(source, context.repo.blocks, { ...opts, pin: false, @@ -263,7 +262,7 @@ export function createChmod (context) { for await (const entry of source) { yield async function () { /** @type {PBNode} */ - // @ts-ignore - cannot derive type + // @ts-expect-error - cannot derive type const node = entry.content const buf = dagPB.encode(node) diff --git a/packages/ipfs-core/src/components/files/cp.js b/packages/ipfs-core/src/components/files/cp.js index 694cf55d63..607156c177 100644 --- a/packages/ipfs-core/src/components/files/cp.js +++ b/packages/ipfs-core/src/components/files/cp.js @@ -1,6 +1,6 @@ import { createMkdir } from './mkdir.js' import { createStat } from './stat.js' -import debug from 'debug' +import { logger } from '@libp2p/logger' import errCode from 'err-code' import { updateTree } from './utils/update-tree.js' import { updateMfsRoot } from './utils/update-mfs-root.js' @@ -11,7 +11,7 @@ import { toTrail } from './utils/to-trail.js' import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' const mergeOptions = mergeOpts.bind({ ignoreUndefined: true }) -const log = debug('ipfs:mfs:cp') +const log = logger('ipfs:mfs:cp') /** * @typedef {import('@ipld/dag-pb').PBNode} DAGNode @@ -78,7 +78,6 @@ export function createCp (context) { if (destination.exists) { log('Destination exists') - // @ts-ignore ts seems to think `sources` will always have a length of 10 if (sources.length === 1 && !destinationIsDirectory) { throw errCode(new Error('directory already has entry by that name'), 'ERR_ALREADY_EXISTS') } @@ -117,7 +116,6 @@ export function createCp (context) { const destinationPath = isDirectory(destination) ? destination.mfsPath : destination.mfsDirectory const trail = await toTrail(context, destinationPath) - // @ts-ignore ts seems to think `sources` will always have a length of 10 if (sources.length === 1) { const source = sources.pop() diff --git a/packages/ipfs-core/src/components/files/index.js b/packages/ipfs-core/src/components/files/index.js index 6c282b864a..af502eb967 100644 --- a/packages/ipfs-core/src/components/files/index.js +++ b/packages/ipfs-core/src/components/files/index.js @@ -144,12 +144,10 @@ export function createFiles ({ repo, preload, hashers, options: constructorOptio * @param {...any} args */ const wrapped = (...args) => { - // @ts-ignore cannot derive type of arg const paths = args.filter(arg => isIpfs.ipfsPath(arg) || isIpfs.cid(arg)) if (paths.length) { const options = args[args.length - 1] - // @ts-ignore it's a PreloadOptions, honest if (options && options.preload !== false) { paths.forEach(path => preload(path)) } diff --git a/packages/ipfs-core/src/components/files/mkdir.js b/packages/ipfs-core/src/components/files/mkdir.js index 6768df14af..ec55f8e6e4 100644 --- a/packages/ipfs-core/src/components/files/mkdir.js +++ b/packages/ipfs-core/src/components/files/mkdir.js @@ -1,5 +1,5 @@ import errCode from 'err-code' -import debug from 'debug' +import { logger } from '@libp2p/logger' import { exporter } from 'ipfs-unixfs-exporter' import { createNode } from './utils/create-node.js' import { toPathComponents } from './utils/to-path-components.js' @@ -11,7 +11,7 @@ import mergeOpts from 'merge-options' import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' const mergeOptions = mergeOpts.bind({ ignoreUndefined: true }) -const log = debug('ipfs:mfs:mkdir') +const log = logger('ipfs:mfs:mkdir') /** * @typedef {import('@ipld/dag-pb').PBNode} PBNode diff --git a/packages/ipfs-core/src/components/files/stat.js b/packages/ipfs-core/src/components/files/stat.js index edeeefeaed..dab9ffbfe6 100644 --- a/packages/ipfs-core/src/components/files/stat.js +++ b/packages/ipfs-core/src/components/files/stat.js @@ -1,13 +1,13 @@ import mergeOpts from 'merge-options' import { toMfsPath } from './utils/to-mfs-path.js' import { exporter } from 'ipfs-unixfs-exporter' -import debug from 'debug' +import { logger } from '@libp2p/logger' import errCode from 'err-code' import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' import * as dagPB from '@ipld/dag-pb' const mergeOptions = mergeOpts.bind({ ignoreUndefined: true }) -const log = debug('ipfs:mfs:stat') +const log = logger('ipfs:mfs:stat') /** * @typedef {import('./').MfsContext} MfsContext diff --git a/packages/ipfs-core/src/components/files/touch.js b/packages/ipfs-core/src/components/files/touch.js index d72b055815..41d5f6fba2 100644 --- a/packages/ipfs-core/src/components/files/touch.js +++ b/packages/ipfs-core/src/components/files/touch.js @@ -1,6 +1,6 @@ import mergeOpts from 'merge-options' import { toMfsPath } from './utils/to-mfs-path.js' -import debug from 'debug' +import { logger } from '@libp2p/logger' import errCode from 'err-code' import { UnixFS } from 'ipfs-unixfs' import { toTrail } from './utils/to-trail.js' @@ -12,7 +12,7 @@ import { CID } from 'multiformats/cid' import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' const mergeOptions = mergeOpts.bind({ ignoreUndefined: true }) -const log = debug('ipfs:mfs:touch') +const log = logger('ipfs:mfs:touch') /** * @typedef {import('multiformats/cid').CIDVersion} CIDVersion @@ -70,7 +70,6 @@ export function createTouch (context) { if (!exists) { const metadata = new UnixFS({ type: 'file', - // @ts-ignore TODO: restore hrtime support to ipfs-unixfs constructor - it's in the code, just not the signature mtime: settings.mtime }) updatedBlock = dagPB.encode({ Data: metadata.marshal(), Links: [] }) @@ -98,7 +97,7 @@ export function createTouch (context) { const metadata = UnixFS.unmarshal(node.Data) - // @ts-ignore TODO: restore setting all date types as mtime - it's in the code, just not the signature + // @ts-expect-error TODO: restore setting all date types as mtime - it's in the code, just not the signature metadata.mtime = settings.mtime updatedBlock = dagPB.encode({ diff --git a/packages/ipfs-core/src/components/files/utils/add-link.js b/packages/ipfs-core/src/components/files/utils/add-link.js index 4ae0543913..60a2772aea 100644 --- a/packages/ipfs-core/src/components/files/utils/add-link.js +++ b/packages/ipfs-core/src/components/files/utils/add-link.js @@ -1,6 +1,6 @@ import * as dagPB from '@ipld/dag-pb' import { CID } from 'multiformats/cid' -import debug from 'debug' +import { logger } from '@libp2p/logger' import { UnixFS } from 'ipfs-unixfs' import { DirSharded } from './dir-sharded.js' import { @@ -14,7 +14,7 @@ import { import errCode from 'err-code' import last from 'it-last' -const log = debug('ipfs:mfs:core:utils:add-link') +const log = logger('ipfs:mfs:core:utils:add-link') /** * @typedef {import('ipfs-unixfs').Mtime} Mtime diff --git a/packages/ipfs-core/src/components/files/utils/create-lock.js b/packages/ipfs-core/src/components/files/utils/create-lock.js index 9cdfce3c7c..6c839f111e 100644 --- a/packages/ipfs-core/src/components/files/utils/create-lock.js +++ b/packages/ipfs-core/src/components/files/utils/create-lock.js @@ -1,5 +1,3 @@ - -// @ts-expect-error - no types import mortice from 'mortice' /** diff --git a/packages/ipfs-core/src/components/files/utils/create-node.js b/packages/ipfs-core/src/components/files/utils/create-node.js index 4c552f629f..09250a6e59 100644 --- a/packages/ipfs-core/src/components/files/utils/create-node.js +++ b/packages/ipfs-core/src/components/files/utils/create-node.js @@ -22,7 +22,6 @@ export async function createNode (context, type, options) { const metadata = new UnixFS({ type, mode: options.mode, - // @ts-ignore TODO: restore hrtime support to ipfs-unixfs constructor - it's in the code, just not the signature mtime: options.mtime }) diff --git a/packages/ipfs-core/src/components/files/utils/hamt-utils.js b/packages/ipfs-core/src/components/files/utils/hamt-utils.js index c05a1c84c1..f70907678d 100644 --- a/packages/ipfs-core/src/components/files/utils/hamt-utils.js +++ b/packages/ipfs-core/src/components/files/utils/hamt-utils.js @@ -4,7 +4,7 @@ import { createHAMT } from 'hamt-sharding' import { DirSharded } from './dir-sharded.js' -import debug from 'debug' +import { logger } from '@libp2p/logger' import { UnixFS } from 'ipfs-unixfs' import last from 'it-last' import { CID } from 'multiformats/cid' @@ -14,7 +14,7 @@ import { hamtBucketBits } from './hamt-constants.js' -const log = debug('ipfs:mfs:core:utils:hamt-utils') +const log = logger('ipfs:mfs:core:utils:hamt-utils') /** * @typedef {import('multiformats/cid').CIDVersion} CIDVersion @@ -198,7 +198,7 @@ export const generatePath = async (context, fileName, rootNode) => { prefix: toPrefix(currentBucket._posAtParent) }) - // @ts-ignore - only the root bucket's parent will be undefined + // @ts-expect-error - only the root bucket's parent will be undefined currentBucket = currentBucket._parent } diff --git a/packages/ipfs-core/src/components/files/utils/remove-link.js b/packages/ipfs-core/src/components/files/utils/remove-link.js index b1849b2b08..104cff1fa4 100644 --- a/packages/ipfs-core/src/components/files/utils/remove-link.js +++ b/packages/ipfs-core/src/components/files/utils/remove-link.js @@ -1,8 +1,7 @@ -// @ts-ignore - TODO vmx 2021-03-31 import * as dagPB from '@ipld/dag-pb' import { CID } from 'multiformats/cid' -import debug from 'debug' +import { logger } from '@libp2p/logger' import { UnixFS } from 'ipfs-unixfs' import { generatePath, @@ -10,7 +9,7 @@ import { } from './hamt-utils.js' import errCode from 'err-code' -const log = debug('ipfs:mfs:core:utils:remove-link') +const log = logger('ipfs:mfs:core:utils:remove-link') /** * @typedef {import('../').MfsContext} MfsContext diff --git a/packages/ipfs-core/src/components/files/utils/to-async-iterator.js b/packages/ipfs-core/src/components/files/utils/to-async-iterator.js index a7f19d0381..06f7a9ee5c 100644 --- a/packages/ipfs-core/src/components/files/utils/to-async-iterator.js +++ b/packages/ipfs-core/src/components/files/utils/to-async-iterator.js @@ -1,11 +1,11 @@ import errCode from 'err-code' -import debug from 'debug' +import { logger } from '@libp2p/logger' import { MFS_MAX_CHUNK_SIZE } from '../../../utils.js' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -const log = debug('ipfs:mfs:utils:to-async-iterator') +const log = logger('ipfs:mfs:utils:to-async-iterator') /** * @param {*} content @@ -65,7 +65,7 @@ export function toAsyncIterator (content) { * @param {{ error?: Error }} ev */ const handleLoad = (ev) => { - // @ts-ignore No overload matches this call. + // @ts-expect-error No overload matches this call. reader.removeEventListener('loadend', handleLoad, false) if (ev.error) { @@ -78,7 +78,7 @@ export function toAsyncIterator (content) { }) } - // @ts-ignore No overload matches this call. + // @ts-expect-error No overload matches this call. reader.addEventListener('loadend', handleLoad) reader.readAsArrayBuffer(chunk) }) diff --git a/packages/ipfs-core/src/components/files/utils/to-mfs-path.js b/packages/ipfs-core/src/components/files/utils/to-mfs-path.js index 79f95e841a..955d444b54 100644 --- a/packages/ipfs-core/src/components/files/utils/to-mfs-path.js +++ b/packages/ipfs-core/src/components/files/utils/to-mfs-path.js @@ -90,7 +90,7 @@ export const toMfsPath = async (context, path, options) => { const root = await loadMfsRoot(context, options) /** @type {MfsPath} */ - // @ts-ignore fields get set later + // @ts-expect-error fields get set later let output = { entryType: 'file' } @@ -134,7 +134,7 @@ export const toMfsPath = async (context, path, options) => { mfsDirectory = `/${pathComponents.slice(0, pathComponents.length - 1).join('/')}` } - // @ts-ignore fields being set + // @ts-expect-error fields being set output = { type: 'ipfs', depth: pathComponents.length - 2, @@ -150,7 +150,7 @@ export const toMfsPath = async (context, path, options) => { const mfsPath = `/${IPFS_PREFIX}/${root}${pathComponents.length ? '/' + pathComponents.join('/') : ''}` const mfsDirectory = `/${IPFS_PREFIX}/${root}/${pathComponents.slice(0, pathComponents.length - 1).join('/')}` - // @ts-ignore fields being set + // @ts-expect-error fields being set output = { type: 'mfs', depth: pathComponents.length, diff --git a/packages/ipfs-core/src/components/files/utils/to-trail.js b/packages/ipfs-core/src/components/files/utils/to-trail.js index 78e3e0eb3d..715ec9187b 100644 --- a/packages/ipfs-core/src/components/files/utils/to-trail.js +++ b/packages/ipfs-core/src/components/files/utils/to-trail.js @@ -1,7 +1,7 @@ import { walkPath } from 'ipfs-unixfs-exporter' -import debug from 'debug' +import { logger } from '@libp2p/logger' -const log = debug('ipfs:mfs:utils:to-trail') +const log = logger('ipfs:mfs:utils:to-trail') /** * @typedef {import('../').MfsContext} MfsContext diff --git a/packages/ipfs-core/src/components/files/utils/update-mfs-root.js b/packages/ipfs-core/src/components/files/utils/update-mfs-root.js index 6dc8c1820a..00be966f5d 100644 --- a/packages/ipfs-core/src/components/files/utils/update-mfs-root.js +++ b/packages/ipfs-core/src/components/files/utils/update-mfs-root.js @@ -1,10 +1,10 @@ -import debug from 'debug' +import { logger } from '@libp2p/logger' import { MFS_ROOT_KEY } from '../../../utils.js' import errCode from 'err-code' -const log = debug('ipfs:mfs:utils:update-mfs-root') +const log = logger('ipfs:mfs:utils:update-mfs-root') /** * @typedef {import('../').MfsContext} MfsContext diff --git a/packages/ipfs-core/src/components/files/utils/update-tree.js b/packages/ipfs-core/src/components/files/utils/update-tree.js index cfc1749239..26af608e75 100644 --- a/packages/ipfs-core/src/components/files/utils/update-tree.js +++ b/packages/ipfs-core/src/components/files/utils/update-tree.js @@ -1,10 +1,10 @@ -import debug from 'debug' +import { logger } from '@libp2p/logger' import { addLink } from './add-link.js' import { decode } from '@ipld/dag-pb' -const log = debug('ipfs:mfs:utils:update-tree') +const log = logger('ipfs:mfs:utils:update-tree') const defaultOptions = { shardSplitThreshold: 1000 @@ -75,7 +75,7 @@ export async function updateTree (context, trail, options) { } } - // @ts-ignore - child is possibly undefined + // @ts-expect-error - child is possibly undefined const { cid } = child log(`Final CID ${cid}`) diff --git a/packages/ipfs-core/src/components/files/utils/with-mfs-root.js b/packages/ipfs-core/src/components/files/utils/with-mfs-root.js index c94a091366..c68b586075 100644 --- a/packages/ipfs-core/src/components/files/utils/with-mfs-root.js +++ b/packages/ipfs-core/src/components/files/utils/with-mfs-root.js @@ -2,11 +2,11 @@ import { CID } from 'multiformats/cid' import { UnixFS } from 'ipfs-unixfs' import * as dagPB from '@ipld/dag-pb' import { sha256 } from 'multiformats/hashes/sha2' -import debug from 'debug' +import { logger } from '@libp2p/logger' import errCode from 'err-code' import { MFS_ROOT_KEY } from '../../../utils.js' -const log = debug('ipfs:mfs:utils:with-mfs-root') +const log = logger('ipfs:mfs:utils:with-mfs-root') /** * @typedef {import('../').MfsContext} MfsContext diff --git a/packages/ipfs-core/src/components/files/write.js b/packages/ipfs-core/src/components/files/write.js index 4ddc874aad..a1eb9e9b14 100644 --- a/packages/ipfs-core/src/components/files/write.js +++ b/packages/ipfs-core/src/components/files/write.js @@ -1,4 +1,4 @@ -import debug from 'debug' +import { logger } from '@libp2p/logger' import { importer } from 'ipfs-unixfs-importer' import { decode @@ -26,7 +26,7 @@ import { } from 'ipfs-unixfs' const mergeOptions = mergeOpts.bind({ ignoreUndefined: true }) -const log = debug('ipfs:mfs:write') +const log = logger('ipfs:mfs:write') /** * @typedef {import('multiformats/cid').CIDVersion} CIDVersion @@ -101,17 +101,17 @@ export function createWrite (context) { parent = await toMfsPath(context, destination.mfsDirectory, options) })() log('Read source, destination and parent') - // @ts-ignore - parent may be undefined + // @ts-expect-error - parent may be undefined if (!options.parents && !parent.exists) { throw errCode(new Error('directory does not exist'), 'ERR_NO_EXIST') } - // @ts-ignore + // @ts-expect-error if (source == null) { throw errCode(new Error('could not create source'), 'ERR_NO_SOURCE') } - // @ts-ignore + // @ts-expect-error if (destination == null) { throw errCode(new Error('could not create destination'), 'ERR_NO_DESTINATION') } diff --git a/packages/ipfs-core/src/components/get.js b/packages/ipfs-core/src/components/get.js index 15a6df5142..b0318dff12 100644 --- a/packages/ipfs-core/src/components/get.js +++ b/packages/ipfs-core/src/components/get.js @@ -13,7 +13,7 @@ import toBuffer from 'it-to-buffer' const DEFAULT_COMPRESSION_LEVEL = 6 /** - * @typedef {Object} Context + * @typedef {object} Context * @property {import('ipfs-repo').IPFSRepo} repo * @property {import('../types').Preload} preload * @@ -84,7 +84,7 @@ export function createGet ({ repo, preload }) { ) } - // @ts-ignore cannot derive type + // @ts-expect-error cannot derive type yield * pipe(...args) return @@ -154,7 +154,7 @@ export function createGet ({ repo, preload }) { } } - // @ts-ignore cannot derive type + // @ts-expect-error cannot derive type yield * pipe(...args) return diff --git a/packages/ipfs-core/src/components/id.js b/packages/ipfs-core/src/components/id.js index fc9c4f8d10..98732f3b81 100644 --- a/packages/ipfs-core/src/components/id.js +++ b/packages/ipfs-core/src/components/id.js @@ -1,24 +1,22 @@ import { ipfsCore as pkgversion } from '../version.js' -import { Multiaddr } from 'multiaddr' +import { Multiaddr } from '@multiformats/multiaddr' import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' -import PeerId from 'peer-id' import { NotStartedError } from '../errors.js' import errCode from 'err-code' -import debug from 'debug' +import { logger } from '@libp2p/logger' -const log = Object.assign(debug('ipfs:components:id'), { - error: debug('ipfs:components:id:error') -}) +const log = logger('ipfs:components:id') /** - * @typedef {import('libp2p')} Libp2p + * @typedef {import('libp2p').Libp2p} Libp2p * @typedef {import('ipfs-core-types/src/utils').AbortOptions} AbortOptions + * @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId */ /** - * @param {Object} config - * @param {import('peer-id')} config.peerId + * @param {object} config + * @param {import('@libp2p/interfaces/peer-id').PeerId} config.peerId * @param {import('../types').NetworkService} config.network */ export function createId ({ peerId, network }) { @@ -33,11 +31,13 @@ export function createId ({ peerId, network }) { throw new NotStartedError() } - const idStr = peerId.toB58String() + if (peerId.publicKey == null) { + throw errCode(new Error('Public key missing'), 'ERR_MISSING_PUBLIC_KEY') + } return { - id: idStr, - publicKey: uint8ArrayToString(peerId.pubKey.bytes, 'base64pad'), + id: peerId, + publicKey: uint8ArrayToString(peerId.publicKey, 'base64pad'), addresses: [], agentVersion: `js-ipfs/${pkgversion}`, protocolVersion: '9000', @@ -46,15 +46,15 @@ export function createId ({ peerId, network }) { } const { libp2p } = net - const peerIdToId = options.peerId ? PeerId.parse(options.peerId) : peerId + const peerIdToId = options.peerId ? options.peerId : peerId const peer = await findPeer(peerIdToId, libp2p, options) const agentVersion = uint8ArrayToString(peer.metadata.get('AgentVersion') || new Uint8Array()) const protocolVersion = uint8ArrayToString(peer.metadata.get('ProtocolVersion') || new Uint8Array()) - const idStr = peer.id.toB58String() - const publicKeyStr = peer.publicKey ? uint8ArrayToString(peer.publicKey.bytes, 'base64pad') : '' + const idStr = peer.id.toString() + const publicKeyStr = peer.publicKey ? uint8ArrayToString(peer.publicKey, 'base64pad') : '' return { - id: idStr, + id: peerIdToId, publicKey: publicKeyStr, addresses: (peer.addresses || []) .map(ma => { @@ -90,13 +90,13 @@ async function findPeer (peerId, libp2p, options) { peer = await findPeerOnDht(peerId, libp2p, options) } - let publicKey = peerId.pubKey ? peerId.pubKey : await libp2p.peerStore.keyBook.get(peerId) + let publicKey = peerId.publicKey ? peerId.publicKey : await libp2p.peerStore.keyBook.get(peerId) - if (!publicKey) { + if (publicKey == null) { try { - publicKey = await libp2p._dht.getPublicKey(peerId, options) + publicKey = await libp2p.getPublicKey(peerId, options) } catch (err) { - log.error('Could not load public key for', peerId.toB58String(), err) + log.error('Could not load public key for', peerId.toString(), err) } } @@ -109,13 +109,16 @@ async function findPeer (peerId, libp2p, options) { } /** - * * @param {PeerId} peerId * @param {Libp2p} libp2p * @param {AbortOptions} options */ async function findPeerOnDht (peerId, libp2p, options) { - for await (const event of libp2p._dht.findPeer(peerId, options)) { + if (libp2p.dht == null) { + throw errCode(new Error('dht not configured'), 'ERR_DHT_NOT_CONFIGURED') + } + + for await (const event of libp2p.dht.findPeer(peerId, options)) { if (event.name === 'FINAL_PEER') { break } diff --git a/packages/ipfs-core/src/components/index.js b/packages/ipfs-core/src/components/index.js index 6eaafb829c..2bba834e65 100644 --- a/packages/ipfs-core/src/components/index.js +++ b/packages/ipfs-core/src/components/index.js @@ -1,6 +1,6 @@ import mergeOpts from 'merge-options' import { isTest } from 'ipfs-utils/src/env.js' -import debug from 'debug' +import { logger } from '@libp2p/logger' import errCode from 'err-code' import { UnixFS } from 'ipfs-unixfs' import * as dagPB from '@ipld/dag-pb' @@ -50,9 +50,7 @@ import { Multihashes } from 'ipfs-core-utils/multihashes' import { Multibases } from 'ipfs-core-utils/multibases' const mergeOptions = mergeOpts.bind({ ignoreUndefined: true }) -const log = Object.assign(debug('ipfs'), { - error: debug('ipfs:error') -}) +const log = logger('ipfs') /** * @typedef {import('../types').Options} Options @@ -65,7 +63,7 @@ const log = Object.assign(debug('ipfs'), { class IPFS { /** - * @param {Object} config + * @param {object} config * @param {Print} config.print * @param {Storage} config.storage * @param {import('ipfs-core-utils/multicodecs').Multicodecs} config.codecs @@ -79,7 +77,7 @@ class IPFS { const dns = createDns() const isOnline = createIsOnline({ network }) - // @ts-ignore This type check fails as options. + // @ts-expect-error This type check fails as options. // libp2p can be a function, while IPNS router config expects libp2p config const ipns = new IPNSAPI(options) @@ -329,7 +327,11 @@ export async function create (options = {}) { log('initializing IPNS keyspace') - await ipfs.ipns.initializeKeyspace(storage.peerId.privKey, uint8ArrayFromString(`/ipfs/${cid}`)) + if (storage.peerId.publicKey == null) { + throw errCode(new Error('Public key missing'), 'ERR_MISSING_PUBLIC_KEY') + } + + await ipfs.ipns.initializeKeyspace(storage.peerId, uint8ArrayFromString(`/ipfs/${cid}`)) } if (options.start !== false) { diff --git a/packages/ipfs-core/src/components/ipns.js b/packages/ipfs-core/src/components/ipns.js index ddbf608871..54c3b364ae 100644 --- a/packages/ipfs-core/src/components/ipns.js +++ b/packages/ipfs-core/src/components/ipns.js @@ -2,25 +2,26 @@ import { IPNS } from '../ipns/index.js' import { createRouting } from '../ipns/routing/config.js' import { OfflineDatastore } from '../ipns/routing/offline-datastore.js' import { NotInitializedError, AlreadyInitializedError } from '../errors.js' -import debug from 'debug' -const log = debug('ipfs:components:ipns') +import { logger } from '@libp2p/logger' + +const log = logger('ipfs:components:ipns') /** - * @typedef {import('libp2p-crypto').PrivateKey} PrivateKey + * @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId * - * @typedef {Object} ExperimentalOptions + * @typedef {object} ExperimentalOptions * @property {boolean} [ipnsPubsub] * - * @typedef {Object} LibP2POptions + * @typedef {object} LibP2POptions * @property {DHTConfig} [config] * - * @typedef {Object} DHTConfig + * @typedef {object} DHTConfig * @property {boolean} [enabled] */ export class IPNSAPI { /** - * @param {Object} options + * @param {object} options * @param {string} options.pass * @param {boolean} [options.offline] * @param {LibP2POptions} [options.libp2p] @@ -56,30 +57,30 @@ export class IPNSAPI { * This is primarily used for offline ipns modifications, such as the * initializeKeyspace feature. * - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo - * @param {import('peer-id')} config.peerId - * @param {import('libp2p/src/keychain')} config.keychain + * @param {import('@libp2p/interfaces/peer-id').PeerId} config.peerId + * @param {import('@libp2p/interfaces/keychain').KeyChain} config.keychain */ startOffline ({ repo, peerId, keychain }) { if (this.offline != null) { throw new AlreadyInitializedError() } - log('initializing IPNS keyspace') + log('initializing IPNS keyspace (offline)') - const routing = new OfflineDatastore(repo) + const routing = new OfflineDatastore(repo.datastore) const ipns = new IPNS(routing, repo.datastore, peerId, keychain, this.options) this.offline = ipns } /** - * @param {Object} config - * @param {import('libp2p')} config.libp2p + * @param {object} config + * @param {import('libp2p').Libp2p} config.libp2p * @param {import('ipfs-repo').IPFSRepo} config.repo - * @param {import('peer-id')} config.peerId - * @param {import('libp2p/src/keychain')} config.keychain + * @param {import('@libp2p/interfaces/peer-id').PeerId} config.peerId + * @param {import('@libp2p/interfaces/keychain').KeyChain} config.keychain */ async startOnline ({ libp2p, repo, peerId, keychain }) { if (this.online != null) { @@ -87,7 +88,7 @@ export class IPNSAPI { } const routing = createRouting({ libp2p, repo, peerId, options: this.options }) - // @ts-ignore routing is a TieredDatastore which wants keys to be Keys, IPNS needs keys to be Uint8Arrays + // @ts-expect-error routing is a TieredDatastore which wants keys to be Keys, IPNS needs keys to be Uint8Arrays const ipns = new IPNS(routing, repo.datastore, peerId, keychain, this.options) await ipns.republisher.start() this.online = ipns @@ -102,12 +103,12 @@ export class IPNSAPI { } /** - * @param {PrivateKey} privKey + * @param {PeerId} peerId * @param {Uint8Array} value * @param {number} lifetime */ - publish (privKey, value, lifetime) { - return this.getIPNS().publish(privKey, value, lifetime) + publish (peerId, value, lifetime) { + return this.getIPNS().publish(peerId, value, lifetime) } /** @@ -120,10 +121,10 @@ export class IPNSAPI { } /** - * @param {PrivateKey} privKey + * @param {PeerId} peerId * @param {Uint8Array} value */ - initializeKeyspace (privKey, value) { - return this.getIPNS().initializeKeyspace(privKey, value) + initializeKeyspace (peerId, value) { + return this.getIPNS().initializeKeyspace(peerId, value) } } diff --git a/packages/ipfs-core/src/components/is-online.js b/packages/ipfs-core/src/components/is-online.js index a04c1aebbc..1cc5ec5805 100644 --- a/packages/ipfs-core/src/components/is-online.js +++ b/packages/ipfs-core/src/components/is-online.js @@ -1,6 +1,6 @@ /** - * @param {Object} config + * @param {object} config * @param {import('../types').NetworkService} config.network */ export function createIsOnline ({ network }) { diff --git a/packages/ipfs-core/src/components/key/export.js b/packages/ipfs-core/src/components/key/export.js index 42382d6fd9..4e58e9861d 100644 --- a/packages/ipfs-core/src/components/key/export.js +++ b/packages/ipfs-core/src/components/key/export.js @@ -1,8 +1,8 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** - * @param {Object} config - * @param {import('libp2p/src/keychain')} config.keychain + * @param {object} config + * @param {import('@libp2p/interfaces/keychain').KeyChain} config.keychain */ export function createExport ({ keychain }) { /** diff --git a/packages/ipfs-core/src/components/key/gen.js b/packages/ipfs-core/src/components/key/gen.js index 81d9b24047..8640fd7247 100644 --- a/packages/ipfs-core/src/components/key/gen.js +++ b/packages/ipfs-core/src/components/key/gen.js @@ -1,11 +1,11 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' -const DEFAULT_KEY_TYPE = 'ed25519' +const DEFAULT_KEY_TYPE = 'Ed25519' const DEFAULT_KEY_SIZE = 2048 /** - * @param {Object} config - * @param {import('libp2p/src/keychain')} config.keychain + * @param {object} config + * @param {import('@libp2p/interfaces/keychain').KeyChain} config.keychain */ export function createGen ({ keychain }) { /** diff --git a/packages/ipfs-core/src/components/key/import.js b/packages/ipfs-core/src/components/key/import.js index 03e80bef4f..0a5711ea40 100644 --- a/packages/ipfs-core/src/components/key/import.js +++ b/packages/ipfs-core/src/components/key/import.js @@ -1,8 +1,8 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** - * @param {Object} config - * @param {import('libp2p/src/keychain')} config.keychain + * @param {object} config + * @param {import('@libp2p/interfaces/keychain').KeyChain} config.keychain */ export function createImport ({ keychain }) { /** diff --git a/packages/ipfs-core/src/components/key/index.js b/packages/ipfs-core/src/components/key/index.js index 0dc52a2b71..c34521e838 100644 --- a/packages/ipfs-core/src/components/key/index.js +++ b/packages/ipfs-core/src/components/key/index.js @@ -7,12 +7,12 @@ import { createRename } from './rename.js' import { createRm } from './rm.js' /** - * @typedef {import('libp2p/src/keychain')} Keychain + * @typedef {import('@libp2p/interfaces/keychain').KeyChain} Keychain */ export class KeyAPI { /** - * @param {Object} config + * @param {object} config * @param {Keychain} config.keychain */ constructor ({ keychain }) { diff --git a/packages/ipfs-core/src/components/key/info.js b/packages/ipfs-core/src/components/key/info.js index c31f43c14b..0059eca793 100644 --- a/packages/ipfs-core/src/components/key/info.js +++ b/packages/ipfs-core/src/components/key/info.js @@ -1,8 +1,8 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** - * @param {Object} config - * @param {import('libp2p/src/keychain')} config.keychain + * @param {object} config + * @param {import('@libp2p/interfaces/keychain').KeyChain} config.keychain */ export function createInfo ({ keychain }) { /** diff --git a/packages/ipfs-core/src/components/key/list.js b/packages/ipfs-core/src/components/key/list.js index 90a9cb3a5f..c7f6af6af0 100644 --- a/packages/ipfs-core/src/components/key/list.js +++ b/packages/ipfs-core/src/components/key/list.js @@ -1,8 +1,8 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** - * @param {Object} config - * @param {import('libp2p/src/keychain')} config.keychain + * @param {object} config + * @param {import('@libp2p/interfaces/keychain').KeyChain} config.keychain */ export function createList ({ keychain }) { /** diff --git a/packages/ipfs-core/src/components/key/rename.js b/packages/ipfs-core/src/components/key/rename.js index fc4580accd..71ebef6d8f 100644 --- a/packages/ipfs-core/src/components/key/rename.js +++ b/packages/ipfs-core/src/components/key/rename.js @@ -1,8 +1,8 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** - * @param {Object} config - * @param {import('libp2p/src/keychain')} config.keychain + * @param {object} config + * @param {import('@libp2p/interfaces/keychain').KeyChain} config.keychain */ export function createRename ({ keychain }) { /** diff --git a/packages/ipfs-core/src/components/key/rm.js b/packages/ipfs-core/src/components/key/rm.js index 0f3fbcc25e..087eaaf2a8 100644 --- a/packages/ipfs-core/src/components/key/rm.js +++ b/packages/ipfs-core/src/components/key/rm.js @@ -1,8 +1,8 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** - * @param {Object} config - * @param {import('libp2p/src/keychain')} config.keychain + * @param {object} config + * @param {import('@libp2p/interfaces/keychain').KeyChain} config.keychain */ export function createRm ({ keychain }) { /** diff --git a/packages/ipfs-core/src/components/libp2p.js b/packages/ipfs-core/src/components/libp2p.js index 017d657602..63999425e4 100644 --- a/packages/ipfs-core/src/components/libp2p.js +++ b/packages/ipfs-core/src/components/libp2p.js @@ -2,19 +2,22 @@ import get from 'dlv' import mergeOpts from 'merge-options' import errCode from 'err-code' import { routers } from 'ipfs-core-config/libp2p-pubsub-routers' -// @ts-expect-error - no types -import DelegatedPeerRouter from 'libp2p-delegated-peer-routing' -// @ts-expect-error - no types -import DelegatedContentRouter from 'libp2p-delegated-content-routing' +import { DelegatedPeerRouting } from '@libp2p/delegated-peer-routing' +import { DelegatedContentRouting } from '@libp2p/delegated-content-routing' import { create as ipfsHttpClient } from 'ipfs-http-client' -import { Multiaddr } from 'multiaddr' +import { Multiaddr } from '@multiformats/multiaddr' import { ipfsCore as pkgversion } from '../version.js' import { libp2pConfig as getEnvLibp2pOptions } from 'ipfs-core-config/libp2p' -import bootstrap from 'libp2p-bootstrap' -import Libp2p from 'libp2p' -import * as ipns from 'ipns' +import { createLibp2p as createNode } from 'libp2p' +import { KadDHT } from '@libp2p/kad-dht' +import { Bootstrap } from '@libp2p/bootstrap' +import { ipnsValidator } from 'ipns/validator' +import { ipnsSelector } from 'ipns/selector' +import { WebSockets } from '@libp2p/websockets' +import { Mplex } from '@libp2p/mplex' +import { NOISE } from '@chainsafe/libp2p-noise' -const mergeOptions = mergeOpts.bind({ ignoreUndefined: true }) +const mergeOptions = mergeOpts.bind({ ignoreUndefined: true, concatArrays: true }) /** * @typedef {object} DekOptions @@ -23,21 +26,20 @@ const mergeOptions = mergeOpts.bind({ ignoreUndefined: true }) * @property {number} iterationCount * @property {number} keyLength * - * @typedef {Object} KeychainConfig + * @typedef {object} KeychainConfig * @property {string} [pass] * @property {DekOptions} [dek] * * @typedef {import('ipfs-repo').IPFSRepo} Repo - * @typedef {import('peer-id')} PeerId + * @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId * @typedef {import('../types').Options} IPFSOptions - * @typedef {import('libp2p')} LibP2P - * @typedef {import('libp2p').Libp2pOptions & import('libp2p').CreateOptions} Libp2pOptions - * @typedef {import('libp2p').Libp2pConfig} Libp2pConfig + * @typedef {import('libp2p').Libp2p} LibP2P + * @typedef {import('libp2p').Libp2pOptions} Libp2pOptions * @typedef {import('ipfs-core-types/src/config').Config} IPFSConfig */ /** - * @param {Object} config + * @param {object} config * @param {Repo} config.repo * @param {IPFSOptions|undefined} config.options * @param {PeerId} config.peerId @@ -53,13 +55,12 @@ export function createLibp2p ({ keychainConfig = {}, config = {} }) { - const { datastore, keys } = repo + const { datastore } = repo const libp2pOptions = getLibp2pOptions({ options, config, datastore, - keys, keychainConfig, peerId, multiaddrs @@ -69,80 +70,40 @@ export function createLibp2p ({ return options.libp2p({ libp2pOptions, options, config, datastore, peerId }) } - return Libp2p.create(libp2pOptions) + return createNode(libp2pOptions) } /** - * @param {Object} input + * @param {object} input * @param {IPFSOptions} input.options * @param {Partial} input.config * @param {Repo['datastore']} input.datastore - * @param {Repo['keys']} input.keys * @param {KeychainConfig} input.keychainConfig * @param {PeerId} input.peerId * @param {Multiaddr[]} input.multiaddrs * @returns {Libp2pOptions} */ -function getLibp2pOptions ({ options, config, datastore, keys, keychainConfig, peerId, multiaddrs }) { +function getLibp2pOptions ({ options, config, datastore, keychainConfig, peerId, multiaddrs }) { const getPubsubRouter = () => { const router = get(config, 'Pubsub.Router') || 'gossipsub' - if (!routers[router]) { + const availableRouters = routers() + + if (!availableRouters[router]) { throw errCode(new Error(`Router unavailable. Configure libp2p.modules.pubsub to use the ${router} router.`), 'ERR_NOT_SUPPORTED') } - return routers[router] + return availableRouters[router] } + /** @type {Libp2pOptions} */ const libp2pDefaults = { datastore, - peerId: peerId, - modules: {} + peerId: peerId } + /** @type {Libp2pOptions} */ const libp2pOptions = { - /** - * @type {Partial} - */ - modules: { - pubsub: getPubsubRouter(), - contentRouting: [], - peerRouting: [] - }, - config: { - peerDiscovery: { - mdns: { - enabled: get(options, 'config.Discovery.MDNS.Enabled', get(config, 'Discovery.MDNS.Enabled', true)) - }, - webRTCStar: { - enabled: get(options, 'config.Discovery.webRTCStar.Enabled', get(config, 'Discovery.webRTCStar.Enabled', true)) - }, - bootstrap: { - list: get(options, 'config.Bootstrap', get(config, 'Bootstrap', [])) - } - }, - relay: { - enabled: get(options, 'relay.enabled', get(config, 'relay.enabled', true)), - hop: { - enabled: get(options, 'relay.hop.enabled', get(config, 'relay.hop.enabled', false)), - active: get(options, 'relay.hop.active', get(config, 'relay.hop.active', false)) - } - }, - dht: { - enabled: get(config, 'Routing.Type', 'dhtclient') !== 'none', - clientMode: get(config, 'Routing.Type', 'dht') !== 'dhtserver', - kBucketSize: get(options, 'dht.kBucketSize', 20), - validators: { - ipns: ipns.validator - } - }, - pubsub: { - enabled: get(options, 'config.Pubsub.Enabled', get(config, 'Pubsub.Enabled', true)) - }, - nat: { - enabled: !get(config, 'Swarm.DisableNatPortMap', false) - } - }, addresses: { listen: multiaddrs.map(ma => ma.toString()), announce: get(options, 'addresses.announce', get(config, 'Addresses.Announce', [])), @@ -152,15 +113,61 @@ function getLibp2pOptions ({ options, config, datastore, keys, keychainConfig, p maxConnections: get(options, 'config.Swarm.ConnMgr.HighWater', get(config, 'Swarm.ConnMgr.HighWater')), minConnections: get(options, 'config.Swarm.ConnMgr.LowWater', get(config, 'Swarm.ConnMgr.LowWater')) }), - keychain: { - datastore: keys, - ...keychainConfig - }, + keychain: keychainConfig, host: { agentVersion: `js-ipfs/${pkgversion}` + }, + contentRouters: [], + peerRouters: [], + peerDiscovery: [], + transports: [ + new WebSockets() + ], + streamMuxers: [ + new Mplex() + ], + connectionEncryption: [ + NOISE + ], + relay: { + enabled: get(options, 'relay.enabled', get(config, 'relay.enabled', true)), + hop: { + enabled: get(options, 'relay.hop.enabled', get(config, 'relay.hop.enabled', false)), + active: get(options, 'relay.hop.active', get(config, 'relay.hop.active', false)) + } + }, + nat: { + enabled: !get(config, 'Swarm.DisableNatPortMap', false) } } + if (get(options, 'config.Pubsub.Enabled', get(config, 'Pubsub.Enabled', true))) { + libp2pOptions.pubsub = getPubsubRouter() + } + + if (get(config, 'Routing.Type', 'dhtclient') !== 'none') { + libp2pOptions.dht = new KadDHT({ + clientMode: get(config, 'Routing.Type', 'dht') !== 'dhtserver', + kBucketSize: get(options, 'dht.kBucketSize', 20), + validators: { + ipns: ipnsValidator + }, + selectors: { + ipns: ipnsSelector + } + }) + } + + const boostrapNodes = get(options, 'config.Bootstrap', get(config, 'Bootstrap', [])) + + if (boostrapNodes.length > 0) { + libp2pOptions.peerDiscovery?.push( + new Bootstrap({ + list: boostrapNodes + }) + ) + } + /** @type {import('libp2p').Libp2pOptions | undefined} */ let constructorOptions = get(options, 'libp2p', undefined) @@ -169,19 +176,14 @@ function getLibp2pOptions ({ options, config, datastore, keys, keychainConfig, p } // Merge defaults with Node.js/browser/other environments options and configuration - const libp2pConfig = mergeOptions( + /** @type {Libp2pOptions} */ + const libp2pFinalConfig = mergeOptions( libp2pDefaults, getEnvLibp2pOptions(), libp2pOptions, constructorOptions ) - const bootstrapList = get(libp2pConfig, 'config.peerDiscovery.bootstrap.list', []) - - if (bootstrapList.length > 0) { - libp2pConfig.modules.peerDiscovery.push(bootstrap) - } - // Set up Delegate Routing based on the presence of Delegates in the config const delegateHosts = get(options, 'config.Addresses.Delegates', get(config, 'Addresses.Delegates', []) @@ -194,19 +196,21 @@ function getLibp2pOptions ({ options, config, datastore, keys, keychainConfig, p const delegateApiOptions = { host: delegateAddr.host, // port is a string atm, so we need to convert for the check - // @ts-ignore - parseInt(input:string) => number + // @ts-expect-error - parseInt(input:string) => number protocol: parseInt(delegateAddr.port) === 443 ? 'https' : 'http', port: delegateAddr.port } const delegateHttpClient = ipfsHttpClient(delegateApiOptions) - libp2pOptions.modules.contentRouting = libp2pOptions.modules.contentRouting || [] - libp2pOptions.modules.contentRouting.push(new DelegatedContentRouter(peerId, delegateHttpClient)) + libp2pFinalConfig.contentRouters?.push(new DelegatedContentRouting(delegateHttpClient)) + libp2pFinalConfig.peerRouters?.push(new DelegatedPeerRouting(delegateHttpClient)) + } - libp2pOptions.modules.peerRouting = libp2pOptions.modules.peerRouting || [] - libp2pOptions.modules.peerRouting.push(new DelegatedPeerRouter(delegateHttpClient)) + if (!get(options, 'config.Discovery.MDNS.Enabled', get(config, 'Discovery.MDNS.Enabled', true))) { + // @ts-expect-error mdns property may not be defined + libp2pFinalConfig.peerDiscovery = libp2pFinalConfig.peerDiscovery?.filter(d => !(d?.mdns || false)) } - return libp2pConfig + return libp2pFinalConfig } diff --git a/packages/ipfs-core/src/components/ls.js b/packages/ipfs-core/src/components/ls.js index 4871c4500e..2af1a808ff 100644 --- a/packages/ipfs-core/src/components/ls.js +++ b/packages/ipfs-core/src/components/ls.js @@ -5,7 +5,7 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' import { CID } from 'multiformats/cid' /** - * @typedef {Object} Context + * @typedef {object} Context * @property {import('ipfs-repo').IPFSRepo} repo * @property {import('../types').Preload} preload * diff --git a/packages/ipfs-core/src/components/name/index.js b/packages/ipfs-core/src/components/name/index.js index 4165fc1ef0..7e998e01f8 100644 --- a/packages/ipfs-core/src/components/name/index.js +++ b/packages/ipfs-core/src/components/name/index.js @@ -4,19 +4,19 @@ import { PubSubAPI } from './pubsub/index.js' export class NameAPI { /** - * @param {Object} config + * @param {object} config * @param {import('../ipns').IPNSAPI} config.ipns - * @param {import('peer-id')} config.peerId + * @param {import('@libp2p/interfaces/peer-id').PeerId} config.peerId * @param {import('../../types').Options} config.options * @param {import('ipfs-repo').IPFSRepo} config.repo * @param {import('ipfs-core-utils/multicodecs').Multicodecs} config.codecs * @param {import('ipfs-core-types/src/root').API<{}>["isOnline"]} config.isOnline - * @param {import('libp2p/src/keychain')} config.keychain + * @param {import('@libp2p/interfaces/keychain').KeyChain} config.keychain * @param {import('ipfs-core-types/src/root').API<{}>["dns"]} config.dns */ constructor ({ dns, ipns, repo, codecs, peerId, isOnline, keychain, options }) { this.publish = createPublish({ ipns, repo, codecs, peerId, isOnline, keychain }) - this.resolve = createResolve({ dns, ipns, peerId, isOnline, options }) + this.resolve = createResolve({ dns, ipns, isOnline, options }) this.pubsub = new PubSubAPI({ ipns, options }) } } diff --git a/packages/ipfs-core/src/components/name/publish.js b/packages/ipfs-core/src/components/name/publish.js index a03e8b64a0..be940978be 100644 --- a/packages/ipfs-core/src/components/name/publish.js +++ b/packages/ipfs-core/src/components/name/publish.js @@ -1,46 +1,49 @@ -import debug from 'debug' +import { logger } from '@libp2p/logger' import parseDuration from 'parse-duration' -import crypto from 'libp2p-crypto' +import { importKey, unmarshalPrivateKey } from '@libp2p/crypto/keys' import errcode from 'err-code' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' import { OFFLINE_ERROR, normalizePath } from '../../utils.js' import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' import { resolvePath } from './utils.js' +import { peerIdFromKeys } from '@libp2p/peer-id' -const log = Object.assign(debug('ipfs:name:publish'), { - error: debug('ipfs:name:publish:error') -}) +const log = logger('ipfs:name:publish') /** * IPNS - Inter-Planetary Naming System * - * @param {Object} config + * @param {object} config * @param {import('../ipns').IPNSAPI} config.ipns * @param {import('ipfs-repo').IPFSRepo} config.repo * @param {import('ipfs-core-utils/multicodecs').Multicodecs} config.codecs - * @param {import('peer-id')} config.peerId + * @param {import('@libp2p/interfaces/peer-id').PeerId} config.peerId * @param {import('ipfs-core-types/src/root').API<{}>["isOnline"]} config.isOnline - * @param {import('libp2p/src/keychain')} config.keychain + * @param {import('@libp2p/interfaces/keychain').KeyChain} config.keychain */ export function createPublish ({ ipns, repo, codecs, peerId, isOnline, keychain }) { /** * @param {string} keyName */ const lookupKey = async keyName => { - if (keyName === 'self') { - return peerId.privKey - } + /** @type {import('@libp2p/interfaces/keys').PrivateKey} */ + let privateKey - try { - // We're exporting and immediately importing the key, so we can just use a throw away password - const pem = await keychain.exportKey(keyName, 'temp') - const privateKey = await crypto.keys.import(pem, 'temp') - return privateKey - } catch (/** @type {any} */ err) { - log.error(err) - throw errcode(err, 'ERR_CANNOT_GET_KEY') + if (keyName === 'self' && peerId.privateKey != null) { + privateKey = await unmarshalPrivateKey(peerId.privateKey) + } else { + try { + // We're exporting and immediately importing the key, so we can just use a throw away password + const pem = await keychain.exportKey(keyName, 'temp') + privateKey = await importKey(pem, 'temp') + } catch (/** @type {any} */ err) { + log.error(err) + throw errcode(err, 'ERR_CANNOT_GET_KEY') + } } + + return peerIdFromKeys(privateKey.public.bytes, privateKey.bytes) } /** diff --git a/packages/ipfs-core/src/components/name/pubsub/cancel.js b/packages/ipfs-core/src/components/name/pubsub/cancel.js index 453d53cecc..5aab204eb4 100644 --- a/packages/ipfs-core/src/components/name/pubsub/cancel.js +++ b/packages/ipfs-core/src/components/name/pubsub/cancel.js @@ -2,7 +2,7 @@ import { getPubsubRouting } from './utils.js' import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** - * @param {Object} config + * @param {object} config * @param {import('../../ipns').IPNSAPI} config.ipns * @param {import('../../../types').Options} config.options */ diff --git a/packages/ipfs-core/src/components/name/pubsub/index.js b/packages/ipfs-core/src/components/name/pubsub/index.js index b4c52282f0..d2538c895f 100644 --- a/packages/ipfs-core/src/components/name/pubsub/index.js +++ b/packages/ipfs-core/src/components/name/pubsub/index.js @@ -4,7 +4,7 @@ import { createSubs } from './subs.js' export class PubSubAPI { /** - * @param {Object} config + * @param {object} config * @param {import('../../ipns').IPNSAPI} config.ipns * @param {import('../../../types').Options} config.options */ diff --git a/packages/ipfs-core/src/components/name/pubsub/state.js b/packages/ipfs-core/src/components/name/pubsub/state.js index ffe89c2283..cc5363c973 100644 --- a/packages/ipfs-core/src/components/name/pubsub/state.js +++ b/packages/ipfs-core/src/components/name/pubsub/state.js @@ -2,7 +2,7 @@ import { getPubsubRouting } from './utils.js' import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** - * @param {Object} config + * @param {object} config * @param {import('../../ipns').IPNSAPI} config.ipns * @param {import('../../../types').Options} config.options */ diff --git a/packages/ipfs-core/src/components/name/pubsub/subs.js b/packages/ipfs-core/src/components/name/pubsub/subs.js index a395d5d41a..777220a9a0 100644 --- a/packages/ipfs-core/src/components/name/pubsub/subs.js +++ b/packages/ipfs-core/src/components/name/pubsub/subs.js @@ -2,7 +2,7 @@ import { getPubsubRouting } from './utils.js' import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** - * @param {Object} config + * @param {object} config * @param {import('../../ipns').IPNSAPI} config.ipns * @param {import('../../../types').Options} config.options */ diff --git a/packages/ipfs-core/src/components/name/resolve.js b/packages/ipfs-core/src/components/name/resolve.js index f90fdf9c59..e89f17d55e 100644 --- a/packages/ipfs-core/src/components/name/resolve.js +++ b/packages/ipfs-core/src/components/name/resolve.js @@ -1,10 +1,10 @@ -import debug from 'debug' +import { logger } from '@libp2p/logger' import errcode from 'err-code' import mergeOpts from 'merge-options' import { CID } from 'multiformats/cid' import * as Digest from 'multiformats/hashes/digest' import { base36 } from 'multiformats/bases/base36' -import PeerId from 'peer-id' +import { peerIdFromString } from '@libp2p/peer-id' // @ts-expect-error no types import isDomain from 'is-domain-name' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' @@ -12,9 +12,7 @@ import { OFFLINE_ERROR } from '../../utils.js' import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' const mergeOptions = mergeOpts.bind({ ignoreUndefined: true }) -const log = Object.assign(debug('ipfs:name:resolve'), { - error: debug('ipfs:name:resolve:error') -}) +const log = logger('ipfs:name:resolve') /** * @@ -30,14 +28,13 @@ const appendRemainder = (result, remainder) => /** * IPNS - Inter-Planetary Naming System * - * @param {Object} config + * @param {object} config * @param {import('ipfs-core-types/src/root').API<{}>["dns"]} config.dns * @param {import('../ipns').IPNSAPI} config.ipns - * @param {import('peer-id')} config.peerId * @param {import('ipfs-core-types/src/root').API<{}>["isOnline"]} config.isOnline * @param {import('../../types').Options} config.options */ -export function createResolve ({ dns, ipns, peerId, isOnline, options: { offline } }) { +export function createResolve ({ dns, ipns, isOnline, options: { offline } }) { /** * @type {import('ipfs-core-types/src/name').API<{}>["resolve"]} */ @@ -57,20 +54,17 @@ export function createResolve ({ dns, ipns, peerId, isOnline, options: { offline throw errcode(new Error(OFFLINE_ERROR), 'OFFLINE_ERROR') } - // Set node id as name for being resolved, if it is not received - if (!name) { - name = peerId.toB58String() - } + let ipnsName = name.toString() - if (!name.startsWith('/ipns/')) { - name = `/ipns/${name}` + if (!ipnsName.startsWith('/ipns/')) { + ipnsName = `/ipns/${ipnsName}` } - let [namespace, hash, ...remainder] = name.slice(1).split('/') + let [namespace, hash, ...remainder] = ipnsName.slice(1).split('/') try { if (hash.substring(0, 1) === '1') { - const id = PeerId.parse(hash) + const id = peerIdFromString(hash) const digest = Digest.decode(id.toBytes()) const libp2pKey = CID.createV1(0x72, digest) hash = libp2pKey.toString(base36) diff --git a/packages/ipfs-core/src/components/name/utils.js b/packages/ipfs-core/src/components/name/utils.js index 3be7e1dabe..b1336e6f29 100644 --- a/packages/ipfs-core/src/components/name/utils.js +++ b/packages/ipfs-core/src/components/name/utils.js @@ -7,7 +7,7 @@ import { resolve } from '../../utils.js' * resolves the given path by parsing out protocol-specific entries * (e.g. /ipns/) and then going through the /ipfs/ entries and returning the final node * - * @param {Object} context + * @param {object} context * @param {import('../ipns').IPNSAPI} context.ipns * @param {import('ipfs-repo').IPFSRepo} context.repo * @param {import('ipfs-core-utils/multicodecs').Multicodecs} context.codecs diff --git a/packages/ipfs-core/src/components/network.js b/packages/ipfs-core/src/components/network.js index 87639037e2..ab473caaee 100644 --- a/packages/ipfs-core/src/components/network.js +++ b/packages/ipfs-core/src/components/network.js @@ -1,15 +1,15 @@ import { createBitswap } from 'ipfs-bitswap' import { createLibp2p } from './libp2p.js' -import { Multiaddr } from 'multiaddr' +import { Multiaddr } from '@multiformats/multiaddr' import errCode from 'err-code' import { BlockStorage } from '../block-storage.js' /** - * @typedef {Object} Online + * @typedef {object} Online * @property {libp2p} libp2p * @property {Bitswap} bitswap * - * @typedef {Object} Options + * @typedef {object} Options * @property {PeerId} options.peerId * @property {Repo} options.repo * @property {Print} options.print @@ -20,9 +20,9 @@ import { BlockStorage } from '../block-storage.js' * @typedef {import('../types').Options} IPFSOptions * @typedef {import('ipfs-repo').IPFSRepo} Repo * @typedef {import('../types').Print} Print - * @typedef {import('libp2p')} libp2p + * @typedef {import('libp2p').Libp2p} libp2p * @typedef {import('ipfs-bitswap').IPFSBitswap} Bitswap - * @typedef {import('peer-id')} PeerId + * @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId * @typedef {import('ipfs-core-types/src/utils').AbortOptions} AbortOptions */ @@ -70,8 +70,8 @@ export class Network { await libp2p.start() - for (const ma of libp2p.multiaddrs) { - print(`Swarm listening on ${ma}/p2p/${peerId.toB58String()}`) + for (const ma of libp2p.getMultiaddrs()) { + print(`Swarm listening on ${ma.toString()}`) } const bitswap = createBitswap(libp2p, repo.blocks, { @@ -82,7 +82,7 @@ export class Network { const blockstore = new BlockStorage(repo.blocks, bitswap) repo.blocks = blockstore - // @ts-ignore private field + // @ts-expect-error private field repo.pins.blockstore = blockstore return new Network(peerId, libp2p, bitswap, repo, blockstore) @@ -93,7 +93,7 @@ export class Network { */ static async stop (network) { network.repo.blocks = network.blockstore.unwrap() - // @ts-ignore private field + // @ts-expect-error private field network.repo.pins.blockstore = network.blockstore.unwrap() await network.bitswap.stop() @@ -106,7 +106,7 @@ export class Network { * @param {IPFSConfig} config */ const readAddrs = (peerId, config) => { - const peerIdStr = peerId.toB58String() + const peerIdStr = peerId.toString() /** @type {Multiaddr[]} */ const addrs = [] const swarm = (config.Addresses && config.Addresses.Swarm) || [] diff --git a/packages/ipfs-core/src/components/object/data.js b/packages/ipfs-core/src/components/object/data.js index a3c2e5b09c..27eb35f3fc 100644 --- a/packages/ipfs-core/src/components/object/data.js +++ b/packages/ipfs-core/src/components/object/data.js @@ -2,7 +2,7 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' import { createGet } from './get.js' /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo * @param {import('../../types').Preload} config.preload */ diff --git a/packages/ipfs-core/src/components/object/get.js b/packages/ipfs-core/src/components/object/get.js index c6d4621577..7ab6df01ba 100644 --- a/packages/ipfs-core/src/components/object/get.js +++ b/packages/ipfs-core/src/components/object/get.js @@ -2,7 +2,7 @@ import * as dagPB from '@ipld/dag-pb' import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo * @param {import('../../types').Preload} config.preload */ diff --git a/packages/ipfs-core/src/components/object/index.js b/packages/ipfs-core/src/components/object/index.js index 3a7bff3560..fcf9a591e5 100644 --- a/packages/ipfs-core/src/components/object/index.js +++ b/packages/ipfs-core/src/components/object/index.js @@ -14,7 +14,7 @@ import { ObjectPatchAPI } from './patch/index.js' export class ObjectAPI { /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo * @param {import('ipfs-core-utils/multicodecs').Multicodecs} config.codecs * @param {Preload} config.preload diff --git a/packages/ipfs-core/src/components/object/links.js b/packages/ipfs-core/src/components/object/links.js index 8c2e126684..798a31f3bb 100644 --- a/packages/ipfs-core/src/components/object/links.js +++ b/packages/ipfs-core/src/components/object/links.js @@ -55,7 +55,7 @@ function findLinks (node, links = []) { } /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo * @param {import('ipfs-core-utils/multicodecs').Multicodecs} config.codecs */ diff --git a/packages/ipfs-core/src/components/object/new.js b/packages/ipfs-core/src/components/object/new.js index 28ec3c1a62..46162406c0 100644 --- a/packages/ipfs-core/src/components/object/new.js +++ b/packages/ipfs-core/src/components/object/new.js @@ -5,7 +5,7 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' import { CID } from 'multiformats/cid' /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo * @param {import('../../types').Preload} config.preload */ diff --git a/packages/ipfs-core/src/components/object/patch/add-link.js b/packages/ipfs-core/src/components/object/patch/add-link.js index 8f1e52aade..5340e64db1 100644 --- a/packages/ipfs-core/src/components/object/patch/add-link.js +++ b/packages/ipfs-core/src/components/object/patch/add-link.js @@ -3,7 +3,7 @@ import { createGet } from '../get.js' import { createPut } from '../put.js' /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo * @param {import('../../../types').Preload} config.preload */ diff --git a/packages/ipfs-core/src/components/object/patch/append-data.js b/packages/ipfs-core/src/components/object/patch/append-data.js index 24919859a3..37f5fbd461 100644 --- a/packages/ipfs-core/src/components/object/patch/append-data.js +++ b/packages/ipfs-core/src/components/object/patch/append-data.js @@ -4,7 +4,7 @@ import { createGet } from '../get.js' import { createPut } from '../put.js' /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo * @param {import('../../../types').Preload} config.preload */ diff --git a/packages/ipfs-core/src/components/object/patch/index.js b/packages/ipfs-core/src/components/object/patch/index.js index a86eaf2cc1..f2fd55ff23 100644 --- a/packages/ipfs-core/src/components/object/patch/index.js +++ b/packages/ipfs-core/src/components/object/patch/index.js @@ -9,7 +9,7 @@ import { createSetData } from './set-data.js' export class ObjectPatchAPI { /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo * @param {Preload} config.preload */ diff --git a/packages/ipfs-core/src/components/object/patch/rm-link.js b/packages/ipfs-core/src/components/object/patch/rm-link.js index 1408d95d10..3258cabf28 100644 --- a/packages/ipfs-core/src/components/object/patch/rm-link.js +++ b/packages/ipfs-core/src/components/object/patch/rm-link.js @@ -3,7 +3,7 @@ import { createGet } from '../get.js' import { createPut } from '../put.js' /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo * @param {import('../../../types').Preload} config.preload */ diff --git a/packages/ipfs-core/src/components/object/patch/set-data.js b/packages/ipfs-core/src/components/object/patch/set-data.js index 6d2bb56b6e..da0137bf04 100644 --- a/packages/ipfs-core/src/components/object/patch/set-data.js +++ b/packages/ipfs-core/src/components/object/patch/set-data.js @@ -3,7 +3,7 @@ import { createGet } from '../get.js' import { createPut } from '../put.js' /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo * @param {import('../../../types').Preload} config.preload */ diff --git a/packages/ipfs-core/src/components/object/put.js b/packages/ipfs-core/src/components/object/put.js index b9876bae76..05ba8f523b 100644 --- a/packages/ipfs-core/src/components/object/put.js +++ b/packages/ipfs-core/src/components/object/put.js @@ -4,7 +4,7 @@ import { sha256 } from 'multiformats/hashes/sha2' import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo * @param {import('../../types').Preload} config.preload */ diff --git a/packages/ipfs-core/src/components/object/stat.js b/packages/ipfs-core/src/components/object/stat.js index b247a302aa..3ba74e9678 100644 --- a/packages/ipfs-core/src/components/object/stat.js +++ b/packages/ipfs-core/src/components/object/stat.js @@ -3,7 +3,7 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' import { createGet } from './get.js' /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo * @param {import('../../types').Preload} config.preload */ diff --git a/packages/ipfs-core/src/components/pin/add-all.js b/packages/ipfs-core/src/components/pin/add-all.js index 5101e01d55..1ff70ae711 100644 --- a/packages/ipfs-core/src/components/pin/add-all.js +++ b/packages/ipfs-core/src/components/pin/add-all.js @@ -18,7 +18,7 @@ import { PinTypes } from 'ipfs-repo/pin-types' */ /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-core-utils/multicodecs').Multicodecs} config.codecs * @param {import('ipfs-repo').IPFSRepo} config.repo */ diff --git a/packages/ipfs-core/src/components/pin/add.js b/packages/ipfs-core/src/components/pin/add.js index 0beb9abfe2..1d6704422c 100644 --- a/packages/ipfs-core/src/components/pin/add.js +++ b/packages/ipfs-core/src/components/pin/add.js @@ -2,7 +2,7 @@ import last from 'it-last' import { CID } from 'multiformats/cid' /** - * @param {Object} config + * @param {object} config * @param {ReturnType} config.addAll */ export function createAdd ({ addAll }) { @@ -26,7 +26,7 @@ export function createAdd ({ addAll }) { }], options) } - // @ts-ignore return value of last can be undefined + // @ts-expect-error return value of last can be undefined return last(iter) } } diff --git a/packages/ipfs-core/src/components/pin/index.js b/packages/ipfs-core/src/components/pin/index.js index 98ccff961b..86c732f8f2 100644 --- a/packages/ipfs-core/src/components/pin/index.js +++ b/packages/ipfs-core/src/components/pin/index.js @@ -6,7 +6,7 @@ import { createRmAll } from './rm-all.js' export class PinAPI { /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-core-utils/multicodecs').Multicodecs} config.codecs * @param {import('ipfs-repo').IPFSRepo} config.repo */ @@ -28,7 +28,7 @@ export class PinAPI { service: { add: (name, credentials) => Promise.reject(new Error('Not implemented')), rm: (name, options = {}) => Promise.reject(new Error('Not implemented')), - // @ts-ignore return types seem to be broken by a recent ts release. doesn't matter here because + // @ts-expect-error return types seem to be broken by a recent ts release. doesn't matter here because // we are just throwing. Will be removed by https://github.com/protocol/web3-dev-team/pull/58 ls: (options = {}) => Promise.reject(new Error('Not implemented')) } diff --git a/packages/ipfs-core/src/components/pin/ls.js b/packages/ipfs-core/src/components/pin/ls.js index 1fe59844d8..41b7e85a8e 100644 --- a/packages/ipfs-core/src/components/pin/ls.js +++ b/packages/ipfs-core/src/components/pin/ls.js @@ -30,7 +30,7 @@ function toPin (type, cid, metadata) { } /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo * @param {import('ipfs-core-utils/multicodecs').Multicodecs} config.codecs */ @@ -88,8 +88,6 @@ export function createLs ({ repo, codecs }) { } if (type === PinTypes.indirect || type === PinTypes.all) { - // @ts-ignore - LsSettings & AbortOptions have no properties in common - // with type { preload?: boolean } for await (const cid of repo.pins.indirectKeys(options)) { yield toPin(PinTypes.indirect, cid) } diff --git a/packages/ipfs-core/src/components/pin/rm-all.js b/packages/ipfs-core/src/components/pin/rm-all.js index 1f3e0a5605..6937146bad 100644 --- a/packages/ipfs-core/src/components/pin/rm-all.js +++ b/packages/ipfs-core/src/components/pin/rm-all.js @@ -4,7 +4,7 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' import { PinTypes } from 'ipfs-repo/pin-types' /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo * @param {import('ipfs-core-utils/multicodecs').Multicodecs} config.codecs */ diff --git a/packages/ipfs-core/src/components/pin/rm.js b/packages/ipfs-core/src/components/pin/rm.js index 69f328f4aa..a627caec02 100644 --- a/packages/ipfs-core/src/components/pin/rm.js +++ b/packages/ipfs-core/src/components/pin/rm.js @@ -1,7 +1,7 @@ import last from 'it-last' /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-core-types/src/pin').API<{}>["rmAll"]} config.rmAll */ export function createRm ({ rmAll }) { @@ -9,7 +9,7 @@ export function createRm ({ rmAll }) { * @type {import('ipfs-core-types/src/pin').API<{}>["rm"]} */ async function rm (path, options = {}) { - // @ts-ignore return value of last can be undefined + // @ts-expect-error return value of last can be undefined const cid = await last(rmAll([{ path, ...options }], options)) if (!cid) { diff --git a/packages/ipfs-core/src/components/ping.js b/packages/ipfs-core/src/components/ping.js index fd88c0ea55..39a8a4a24b 100644 --- a/packages/ipfs-core/src/components/ping.js +++ b/packages/ipfs-core/src/components/ping.js @@ -1,4 +1,3 @@ -import PeerId from 'peer-id' import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** @@ -7,24 +6,24 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' * A "pong" message can be identified by a truthy success property and an empty * text property. Other ping responses are failures or status updates. * - * @typedef {Object} Pong + * @typedef {object} Pong * @property {true} success * @property {number} time * @property {''} text * - * @typedef {Object} PingFailure + * @typedef {object} PingFailure * @property {false} success * @property {number} time * @property {string} text * - * @typedef {Object} StatusUpdate + * @typedef {object} StatusUpdate * @property {true} success * @property {0} time * @property {string} text * * @typedef {PingSettings & AbortOptions} PingOptions * - * @typedef {Object} PingSettings + * @typedef {object} PingSettings * @property {number} [count=10] - The number of ping messages to send * * @typedef {import('ipfs-core-types/src/utils').AbortOptions} AbortOptions @@ -34,7 +33,7 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' const basePacket = { success: true, time: 0, text: '' } /** - * @param {Object} config + * @param {object} config * @param {import('../types').NetworkService} config.network */ export function createPing ({ network }) { @@ -45,14 +44,12 @@ export function createPing ({ network }) { const { libp2p } = await network.use() options.count = options.count || 10 - const peer = PeerId.createFromB58String(peerId) - - const storedPeer = await libp2p.peerStore.get(peer) + const storedPeer = await libp2p.peerStore.get(peerId) let id = storedPeer && storedPeer.id if (!id) { yield { ...basePacket, text: `Looking up peer ${peerId}` } - const remotePeer = await libp2p.peerRouting.findPeer(peer) + const remotePeer = await libp2p.peerRouting.findPeer(peerId) id = remotePeer && remotePeer.id } @@ -61,7 +58,7 @@ export function createPing ({ network }) { throw new Error('Peer was not found') } - yield { ...basePacket, text: `PING ${id.toB58String()}` } + yield { ...basePacket, text: `PING ${id.toString()}` } let packetCount = 0 let totalTime = 0 diff --git a/packages/ipfs-core/src/components/pubsub.js b/packages/ipfs-core/src/components/pubsub.js index 0495400dc4..ab92dc6875 100644 --- a/packages/ipfs-core/src/components/pubsub.js +++ b/packages/ipfs-core/src/components/pubsub.js @@ -4,13 +4,24 @@ import { NotEnabledError } from '../errors.js' import get from 'dlv' /** - * @param {Object} config + * @typedef {import('@libp2p/interfaces/pubsub').Message} Message + * @typedef {import('@libp2p/interfaces/events').EventHandler>} EventHandler + * @typedef {import('@libp2p/interfaces/events').EventHandler} MessageEventHandler + */ + +/** + * @param {object} config * @param {import('../types').NetworkService} config.network * @param {import('ipfs-core-types/src/config').Config} [config.config] */ export function createPubsub ({ network, config }) { const isEnabled = get(config || {}, 'Pubsub.Enabled', true) + /** @type {Record} */ + const handlers = {} + /** @type {EventHandler | undefined} */ + let onMessage + return { subscribe: isEnabled ? withTimeoutOption(subscribe) : notEnabled, unsubscribe: isEnabled ? withTimeoutOption(unsubscribe) : notEnabled, @@ -24,8 +35,39 @@ export function createPubsub ({ network, config }) { */ async function subscribe (topic, handler, options = {}) { const { libp2p } = await network.use(options) - // @ts-ignore Libp2p Pubsub is deprecating the handler, using the EventEmitter - return libp2p.pubsub.subscribe(topic, handler, options) + + libp2p.pubsub.subscribe(topic) + + // listen for 'message' events if we aren't already + if (onMessage == null) { + onMessage = (evt) => { + const msg = evt.detail + + if (handlers[msg.topic]) { + handlers[msg.topic].forEach(handler => { + if (typeof handler === 'function') { + handler(msg) + return + } + + if (handler != null && handler.handleEvent != null) { + handler.handleEvent(msg) + } + }) + } + } + + libp2p.pubsub.addEventListener('message', onMessage) + } + + // store handler for future invocation + if (handler != null) { + if (handlers[topic] == null) { + handlers[topic] = [] + } + + handlers[topic].push(handler) + } } /** @@ -33,8 +75,31 @@ export function createPubsub ({ network, config }) { */ async function unsubscribe (topic, handler, options = {}) { const { libp2p } = await network.use(options) - // @ts-ignore Libp2p Pubsub is deprecating the handler, using the EventEmitter - libp2p.pubsub.unsubscribe(topic, handler, options) + + // remove handler from local map + if (handler != null && handlers[topic] != null) { + handlers[topic] = handlers[topic].filter(h => h !== handler) + + if (handlers[topic].length === 0) { + delete handlers[topic] + } + } + + // remove all handlers + if (typeof handler !== 'function') { + delete handlers[topic] + } + + // no more handlers for this topic, unsubscribe + if (handlers[topic] == null) { + libp2p.pubsub.unsubscribe(topic) + } + + // no more pubsub handlers, remove message listener + if (Object.keys(handlers).length === 0) { + libp2p.pubsub.removeEventListener('message', onMessage) + onMessage = null + } } /** @@ -45,6 +110,7 @@ export function createPubsub ({ network, config }) { if (!data) { throw errCode(new Error('argument "data" is required'), 'ERR_ARG_REQUIRED') } + await libp2p.pubsub.publish(topic, data) } @@ -53,6 +119,7 @@ export function createPubsub ({ network, config }) { */ async function ls (options = {}) { const { libp2p } = await network.use(options) + return libp2p.pubsub.getTopics() } @@ -61,6 +128,7 @@ export function createPubsub ({ network, config }) { */ async function peers (topic, options = {}) { const { libp2p } = await network.use(options) + return libp2p.pubsub.getSubscribers(topic) } } diff --git a/packages/ipfs-core/src/components/refs/index.js b/packages/ipfs-core/src/components/refs/index.js index 6962dd7d50..90186de195 100644 --- a/packages/ipfs-core/src/components/refs/index.js +++ b/packages/ipfs-core/src/components/refs/index.js @@ -26,7 +26,7 @@ export const Format = { */ /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo * @param {import('ipfs-core-utils/multicodecs').Multicodecs} config.codecs * @param {import('ipfs-core-types/src/root').API<{}>["resolve"]} config.resolve diff --git a/packages/ipfs-core/src/components/refs/local.js b/packages/ipfs-core/src/components/refs/local.js index 594bd7e355..e999bb4650 100644 --- a/packages/ipfs-core/src/components/refs/local.js +++ b/packages/ipfs-core/src/components/refs/local.js @@ -1,7 +1,7 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo */ export function createLocal ({ repo }) { diff --git a/packages/ipfs-core/src/components/repo/gc.js b/packages/ipfs-core/src/components/repo/gc.js index ac35c3ad8e..d15a7ed038 100644 --- a/packages/ipfs-core/src/components/repo/gc.js +++ b/packages/ipfs-core/src/components/repo/gc.js @@ -1,8 +1,8 @@ -import debug from 'debug' +import { logger } from '@libp2p/logger' import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' import { loadMfsRoot } from '../files/utils/with-mfs-root.js' -const log = debug('ipfs:repo:gc') +const log = logger('ipfs:repo:gc') /** * @typedef {import('ipfs-core-types/src/pin').API} PinAPI @@ -16,7 +16,7 @@ const log = debug('ipfs:repo:gc') /** * Perform mark and sweep garbage collection * - * @param {Object} config + * @param {object} config * @param {IPFSRepo} config.repo * @param {Multihashes} config.hashers */ diff --git a/packages/ipfs-core/src/components/repo/index.js b/packages/ipfs-core/src/components/repo/index.js index 6f5694da4b..570fef02c7 100644 --- a/packages/ipfs-core/src/components/repo/index.js +++ b/packages/ipfs-core/src/components/repo/index.js @@ -9,7 +9,7 @@ import { createVersion } from './version.js' export class RepoAPI { /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo * @param {Multihashes} config.hashers */ diff --git a/packages/ipfs-core/src/components/repo/stat.js b/packages/ipfs-core/src/components/repo/stat.js index 87429f3caf..a7fda2f665 100644 --- a/packages/ipfs-core/src/components/repo/stat.js +++ b/packages/ipfs-core/src/components/repo/stat.js @@ -1,7 +1,7 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo */ export function createStat ({ repo }) { diff --git a/packages/ipfs-core/src/components/repo/version.js b/packages/ipfs-core/src/components/repo/version.js index ed9b76ffa9..cf63d87f01 100644 --- a/packages/ipfs-core/src/components/repo/version.js +++ b/packages/ipfs-core/src/components/repo/version.js @@ -2,7 +2,7 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' import { repoVersion } from 'ipfs-repo/constants' /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo */ export function createVersion ({ repo }) { @@ -11,7 +11,7 @@ export function createVersion ({ repo }) { */ async function version (options = {}) { try { - // @ts-ignore - not a public API + // @ts-expect-error - not a public API await repo._checkInitialized(options) } catch (/** @type {any} */ err) { // TODO: (dryajov) This is really hacky, there must be a better way diff --git a/packages/ipfs-core/src/components/resolve.js b/packages/ipfs-core/src/components/resolve.js index fd8ab5e06b..41a14dc0c5 100644 --- a/packages/ipfs-core/src/components/resolve.js +++ b/packages/ipfs-core/src/components/resolve.js @@ -1,11 +1,11 @@ import isIpfs from 'is-ipfs' import { CID } from 'multiformats/cid' -import PeerId from 'peer-id' +import { peerIdFromString } from '@libp2p/peer-id' import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' import { resolve as res } from '../utils.js' /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo * @param {import('ipfs-core-utils/multicodecs').Multicodecs} config.codecs * @param {import('ipfs-core-utils/src/multibases').Multibases} config.bases @@ -65,7 +65,7 @@ export function createResolve ({ repo, codecs, bases, name }) { */ function parseBytes (str) { try { - return PeerId.parse(str).toBytes() + return peerIdFromString(str).toBytes() } catch { return CID.parse(str).bytes } diff --git a/packages/ipfs-core/src/components/start.js b/packages/ipfs-core/src/components/start.js index 700d31ddab..cab8c111cf 100644 --- a/packages/ipfs-core/src/components/start.js +++ b/packages/ipfs-core/src/components/start.js @@ -1,15 +1,15 @@ import { Service } from '../utils/service.js' /** - * @param {Object} config + * @param {object} config * @param {import('../types').NetworkService} config.network - * @param {import('peer-id')} config.peerId + * @param {import('@libp2p/interfaces/peer-id').PeerId} config.peerId * @param {import('ipfs-repo').IPFSRepo} config.repo * @param {import('../types').Print} config.print * @param {import('../types').Preload} config.preload * @param {import('../types').MfsPreload} config.mfsPreload * @param {import('./ipns').IPNSAPI} config.ipns - * @param {import('libp2p/src/keychain')} config.keychain + * @param {import('@libp2p/interfaces/keychain').KeyChain} config.keychain * @param {import('ipfs-core-utils/multihashes').Multihashes} config.hashers * @param {import('../types').Options} config.options */ diff --git a/packages/ipfs-core/src/components/stats/bw.js b/packages/ipfs-core/src/components/stats/bw.js index 3bff92b1d9..90e0c5b271 100644 --- a/packages/ipfs-core/src/components/stats/bw.js +++ b/packages/ipfs-core/src/components/stats/bw.js @@ -1,22 +1,22 @@ import parseDuration from 'parse-duration' import errCode from 'err-code' import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' -import PeerId from 'peer-id' +import { peerIdFromString } from '@libp2p/peer-id' /** - * @typedef {Object} BWOptions + * @typedef {object} BWOptions * @property {string} [peer] - Specifies a peer to print bandwidth for * @property {string} [proto] - Specifies a protocol to print bandwidth for * @property {boolean} [poll] - Is used to yield bandwidth info at an interval * @property {number|string} [interval=1000] - The time interval to wait between updating output, if `poll` is `true`. * - * @typedef {Object} BandwidthInfo + * @typedef {object} BandwidthInfo * @property {bigint} totalIn * @property {bigint} totalOut * @property {number} rateIn * @property {number} rateOut * - * @typedef {import('libp2p')} libp2p + * @typedef {import('libp2p').Libp2p} libp2p * @typedef {import('multiformats/cid').CID} CID * @typedef {import('ipfs-core-types/src/utils').AbortOptions} AbortOptions */ @@ -32,11 +32,11 @@ function getBandwidthStats (libp2p, opts) { if (!libp2p.metrics) { stats = undefined } else if (opts.peer) { - stats = libp2p.metrics.forPeer(PeerId.parse(opts.peer)) + stats = libp2p.metrics.forPeer(peerIdFromString(opts.peer)) } else if (opts.proto) { stats = libp2p.metrics.forProtocol(opts.proto) } else { - stats = libp2p.metrics.global + stats = libp2p.metrics.getGlobal() } if (!stats) { @@ -48,18 +48,19 @@ function getBandwidthStats (libp2p, opts) { } } - const { movingAverages, snapshot } = stats + const movingAverages = stats.getMovingAverages() + const snapshot = stats.getSnapshot() return { - totalIn: BigInt(snapshot.dataReceived.integerValue().toString()), - totalOut: BigInt(snapshot.dataSent.integerValue().toString()), - rateIn: movingAverages.dataReceived[60000].movingAverage() / 60, - rateOut: movingAverages.dataSent[60000].movingAverage() / 60 + totalIn: snapshot.dataReceived, + totalOut: snapshot.dataSent, + rateIn: movingAverages.dataReceived[60000].movingAverage / 60, + rateOut: movingAverages.dataSent[60000].movingAverage / 60 } } /** - * @param {Object} config + * @param {object} config * @param {import('../../types').NetworkService} config.network */ export function createBw ({ network }) { diff --git a/packages/ipfs-core/src/components/stats/index.js b/packages/ipfs-core/src/components/stats/index.js index 1d0542a534..027cf3c42c 100644 --- a/packages/ipfs-core/src/components/stats/index.js +++ b/packages/ipfs-core/src/components/stats/index.js @@ -4,7 +4,7 @@ import { createStat as createBitswap } from '../bitswap/stat.js' export class StatsAPI { /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo * @param {import('../../types').NetworkService} config.network */ diff --git a/packages/ipfs-core/src/components/stop.js b/packages/ipfs-core/src/components/stop.js index f27e76b28b..8f115de92e 100644 --- a/packages/ipfs-core/src/components/stop.js +++ b/packages/ipfs-core/src/components/stop.js @@ -1,7 +1,7 @@ import { Service } from '../utils/service.js' /** - * @param {Object} config + * @param {object} config * @param {import('../types').NetworkService} config.network * @param {import('../types').Preload} config.preload * @param {import('./ipns').IPNSAPI} config.ipns diff --git a/packages/ipfs-core/src/components/storage.js b/packages/ipfs-core/src/components/storage.js index 8a3696b817..02becb928e 100644 --- a/packages/ipfs-core/src/components/storage.js +++ b/packages/ipfs-core/src/components/storage.js @@ -1,17 +1,20 @@ -import debug from 'debug' +import { logger } from '@libp2p/logger' import { createRepo } from 'ipfs-core-config/repo' import getDefaultConfig from 'ipfs-core-config/config' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' -import PeerId from 'peer-id' +import { peerIdFromKeys } from '@libp2p/peer-id' import mergeOpts from 'merge-options' import { profiles as configProfiles } from './config/profiles.js' import { NotEnabledError, NotInitializedError } from '../errors.js' import { createLibp2p } from './libp2p.js' import { ERR_REPO_NOT_INITIALIZED } from 'ipfs-repo/errors' +import { createEd25519PeerId, createRSAPeerId } from '@libp2p/peer-id-factory' +import errCode from 'err-code' +import { unmarshalPrivateKey } from '@libp2p/crypto/keys' const mergeOptions = mergeOpts.bind({ ignoreUndefined: true }) -const log = debug('ipfs:components:peer:storage') +const log = logger('ipfs:components:peer:storage') /** * @typedef {import('ipfs-repo').IPFSRepo} IPFSRepo @@ -20,7 +23,8 @@ const log = debug('ipfs:components:peer:storage') * @typedef {import('../types').Print} Print * @typedef {import('ipfs-core-types/src/config').Config} IPFSConfig * @typedef {import('libp2p-crypto').KeyType} KeyType - * @typedef {import('libp2p/src/keychain')} Keychain + * @typedef {import('@libp2p/interfaces/keychain').KeyChain} Keychain + * @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId */ export class Storage { @@ -60,7 +64,7 @@ export class Storage { const { peerId, keychain, isNew } = await loadRepo(print, repo, options) // TODO: throw error? - // @ts-ignore On start, keychain will always be available + // @ts-expect-error On start, keychain will always be available return new Storage(peerId, keychain, repo, print, isNew) } } @@ -153,6 +157,8 @@ const initRepo = async (print, repo, options) => { keychainConfig }) + /* + TODO: figure out how to do this without keeping dek around or if it's even necessary if (libp2p.keychain && libp2p.keychain.opts) { await libp2p.loadKeychain() @@ -160,6 +166,7 @@ const initRepo = async (print, repo, options) => { DEK: libp2p.keychain.opts.dek }) } + */ return { peerId, keychain: libp2p.keychain } } @@ -175,14 +182,14 @@ const decodePeerId = (peerId) => { log('using user-supplied private-key') return typeof peerId === 'object' ? peerId - : PeerId.createFromPrivKey(uint8ArrayFromString(peerId, 'base64pad')) + : peerIdFromKeys(uint8ArrayFromString(peerId, 'base64pad')) } /** * Initializes new PeerId by generating an underlying keypair. * * @param {Print} print - * @param {Object} options + * @param {object} options * @param {KeyType} [options.algorithm='Ed25519'] * @param {number} [options.bits=2048] * @returns {Promise} @@ -190,17 +197,32 @@ const decodePeerId = (peerId) => { const initPeerId = (print, { algorithm = 'Ed25519', bits = 2048 }) => { // Generate peer identity keypair + transform to desired format + add to config. print('generating %s keypair...', algorithm) - return PeerId.create({ keyType: algorithm, bits }) + + if (algorithm === 'Ed25519') { + return createEd25519PeerId() + } + + if (algorithm === 'RSA') { + return createRSAPeerId({ bits }) + } + + throw errCode(new Error('Unknown PeerId algorithm'), 'ERR_UNKNOWN_PEER_ID_ALGORITHM') } /** * @param {PeerId} peerId */ -const peerIdToIdentity = (peerId) => ({ - PeerID: peerId.toB58String(), - /** @type {string} */ - PrivKey: uint8ArrayToString(peerId.privKey.bytes, 'base64pad') -}) +const peerIdToIdentity = (peerId) => { + if (peerId.privateKey == null) { + throw errCode(new Error('Private key missing'), 'ERR_MISSING_PRIVATE_KEY') + } + + return { + PeerID: peerId.toString(), + /** @type {string} */ + PrivKey: uint8ArrayToString(peerId.privateKey, 'base64pad') + } +} /** * Applies passed `profiles` and a `config` to an open repo. @@ -224,7 +246,9 @@ const configureRepo = async (repo, options) => { throw new NotInitializedError('No private key was found in the config, please intialize the repo') } - const peerId = await PeerId.createFromPrivKey(changed.Identity.PrivKey) + const buf = uint8ArrayFromString(changed.Identity.PrivKey, 'base64pad') + const key = await unmarshalPrivateKey(buf) + const peerId = await peerIdFromKeys(key.public.bytes, key.bytes) const libp2p = await createLibp2p({ options: undefined, multiaddrs: undefined, diff --git a/packages/ipfs-core/src/components/swarm/addrs.js b/packages/ipfs-core/src/components/swarm/addrs.js index e00891c8e3..9c0988f15c 100644 --- a/packages/ipfs-core/src/components/swarm/addrs.js +++ b/packages/ipfs-core/src/components/swarm/addrs.js @@ -1,7 +1,11 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** - * @param {Object} config + * @typedef {import('ipfs-core-types/src/swarm').AddrsResult} AddrsResult + */ + +/** + * @param {object} config * @param {import('../../types').NetworkService} config.network */ export function createAddrs ({ network }) { @@ -9,14 +13,17 @@ export function createAddrs ({ network }) { * @type {import('ipfs-core-types/src/swarm').API<{}>["addrs"]} */ async function addrs (options = {}) { // eslint-disable-line require-await + /** @type {AddrsResult[]} */ const peers = [] const { libp2p } = await network.use(options) - for await (const peer of libp2p.peerStore.getPeers()) { + + await libp2p.peerStore.forEach(peer => { peers.push({ - id: peer.id.toB58String(), + id: peer.id, addrs: peer.addresses.map((mi) => mi.multiaddr) }) - } + }) + return peers } diff --git a/packages/ipfs-core/src/components/swarm/connect.js b/packages/ipfs-core/src/components/swarm/connect.js index 57ac1de509..e8d8ee21d2 100644 --- a/packages/ipfs-core/src/components/swarm/connect.js +++ b/packages/ipfs-core/src/components/swarm/connect.js @@ -1,16 +1,16 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** - * @param {Object} config + * @param {object} config * @param {import('../../types').NetworkService} config.network */ export function createConnect ({ network }) { /** * @type {import('ipfs-core-types/src/swarm').API<{}>["connect"]} */ - async function connect (addr, options = {}) { + async function connect (multiaddrOrPeerId, options = {}) { const { libp2p } = await network.use(options) - await libp2p.dial(addr, options) + await libp2p.dial(multiaddrOrPeerId, options) } return withTimeoutOption(connect) diff --git a/packages/ipfs-core/src/components/swarm/disconnect.js b/packages/ipfs-core/src/components/swarm/disconnect.js index 57fa7562da..7e74893148 100644 --- a/packages/ipfs-core/src/components/swarm/disconnect.js +++ b/packages/ipfs-core/src/components/swarm/disconnect.js @@ -1,7 +1,7 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** - * @param {Object} config + * @param {object} config * @param {import('../../types').NetworkService} config.network */ export function createDisconnect ({ network }) { diff --git a/packages/ipfs-core/src/components/swarm/index.js b/packages/ipfs-core/src/components/swarm/index.js index 5dbaaef40f..9afc9e90b3 100644 --- a/packages/ipfs-core/src/components/swarm/index.js +++ b/packages/ipfs-core/src/components/swarm/index.js @@ -6,7 +6,7 @@ import { createPeers } from './peers.js' export class SwarmAPI { /** - * @param {Object} config + * @param {object} config * @param {import('../../types').NetworkService} config.network */ constructor ({ network }) { diff --git a/packages/ipfs-core/src/components/swarm/local-addrs.js b/packages/ipfs-core/src/components/swarm/local-addrs.js index 41fbe36ccc..34a9e1febe 100644 --- a/packages/ipfs-core/src/components/swarm/local-addrs.js +++ b/packages/ipfs-core/src/components/swarm/local-addrs.js @@ -1,7 +1,7 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** - * @param {Object} config + * @param {object} config * @param {import('../../types').NetworkService} config.network */ export function createLocalAddrs ({ network }) { @@ -10,7 +10,7 @@ export function createLocalAddrs ({ network }) { */ async function localAddrs (options = {}) { const { libp2p } = await network.use(options) - return libp2p.multiaddrs + return libp2p.getMultiaddrs() } return withTimeoutOption(localAddrs) diff --git a/packages/ipfs-core/src/components/swarm/peers.js b/packages/ipfs-core/src/components/swarm/peers.js index 19e9f166f7..1e615e44ef 100644 --- a/packages/ipfs-core/src/components/swarm/peers.js +++ b/packages/ipfs-core/src/components/swarm/peers.js @@ -1,7 +1,11 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** - * @param {Object} config + * @typedef {import('ipfs-core-types/src/swarm').PeersResult} PeersResult + */ + +/** + * @param {object} config * @param {import('../../types').NetworkService} config.network */ export function createPeers ({ network }) { @@ -10,14 +14,15 @@ export function createPeers ({ network }) { */ async function peers (options = {}) { const { libp2p } = await network.use(options) - const peers = [] - for (const [peerId, connections] of libp2p.connections) { - for (const connection of connections) { - /** @type {import('ipfs-core-types/src/swarm').PeersResult} */ + if (options.verbose) { + const peers = [] + + for (const connection of libp2p.getConnections()) { + /** @type {PeersResult} */ const peer = { addr: connection.remoteAddr, - peer: peerId + peer: connection.remotePeer } if (options.verbose || options.direction) { @@ -32,9 +37,24 @@ export function createPeers ({ network }) { peers.push(peer) } + + return peers + } + + /** @type {Map} */ + const peers = new Map() + + for (const connection of libp2p.getConnections()) { + /** @type {import('ipfs-core-types/src/swarm').PeersResult} */ + const peer = { + addr: connection.remoteAddr, + peer: connection.remotePeer + } + + peers.set(connection.remoteAddr.toString(), peer) } - return peers + return Array.from(peers.values()) } return withTimeoutOption(peers) diff --git a/packages/ipfs-core/src/components/version.js b/packages/ipfs-core/src/components/version.js index efd361a211..9b54923fca 100644 --- a/packages/ipfs-core/src/components/version.js +++ b/packages/ipfs-core/src/components/version.js @@ -2,7 +2,7 @@ import { ipfsCore, interfaceIpfsCore, commit } from '../version.js' import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' /** - * @param {Object} config + * @param {object} config * @param {import('ipfs-repo').IPFSRepo} config.repo */ export function createVersion ({ repo }) { diff --git a/packages/ipfs-core/src/index.js b/packages/ipfs-core/src/index.js index a7a2b14b14..7e4686c542 100644 --- a/packages/ipfs-core/src/index.js +++ b/packages/ipfs-core/src/index.js @@ -1,7 +1,4 @@ import { create as createImport } from './components/index.js' -import cryptoImport from 'libp2p-crypto' -import isIPFSImport from 'is-ipfs' -import PeerIdImport from 'peer-id' import globSourceImport from 'ipfs-utils/src/files/glob-source.js' import urlSourceImport from 'ipfs-utils/src/files/url-source.js' @@ -23,10 +20,5 @@ import urlSourceImport from 'ipfs-utils/src/files/url-source.js' */ export const create = createImport -export const crypto = cryptoImport -export const isIPFS = isIPFSImport -export { CID } from 'multiformats/cid' -export { Multiaddr as multiaddr } from 'multiaddr' -export const PeerId = PeerIdImport export const globSource = globSourceImport export const urlSource = urlSourceImport diff --git a/packages/ipfs-core/src/ipns/index.js b/packages/ipfs-core/src/ipns/index.js index 95c0cb2f0e..65c1af89d2 100644 --- a/packages/ipfs-core/src/ipns/index.js +++ b/packages/ipfs-core/src/ipns/index.js @@ -1,21 +1,17 @@ -import { createFromPrivKey } from 'peer-id' import errcode from 'err-code' -import debug from 'debug' +import { logger } from '@libp2p/logger' import { IpnsPublisher } from './publisher.js' import { IpnsRepublisher } from './republisher.js' import { IpnsResolver } from './resolver.js' import { TLRU } from '../utils/tlru.js' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' -const log = Object.assign(debug('ipfs:ipns'), { - error: debug('ipfs:ipns:error') -}) - +const log = logger('ipfs:ipns') const defaultRecordTtl = 60 * 1000 /** * @typedef {import('libp2p-crypto').PrivateKey} PrivateKey - * @typedef {import('peer-id')} PeerId + * @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId */ export class IPNS { @@ -23,7 +19,7 @@ export class IPNS { * @param {import('ipfs-core-types/src/utils').BufferStore} routing * @param {import('interface-datastore').Datastore} datastore * @param {PeerId} peerId - * @param {import('libp2p/src/keychain')} keychain + * @param {import('@libp2p/interfaces/keychain').KeyChain} keychain * @param {object} options * @param {string} options.pass * @param {number} [options.initialBroadcastInterval] @@ -40,20 +36,19 @@ export class IPNS { /** * Publish * - * @param {PrivateKey} privKey + * @param {PeerId} peerId * @param {Uint8Array} value * @param {number} lifetime */ - async publish (privKey, value, lifetime = IpnsPublisher.defaultRecordLifetime) { + async publish (peerId, value, lifetime = IpnsPublisher.defaultRecordLifetime) { try { - const peerId = await createFromPrivKey(privKey.bytes) - await this.publisher.publishWithEOL(privKey, value, lifetime) + await this.publisher.publishWithEOL(peerId, value, lifetime) log(`IPNS value ${uint8ArrayToString(value, 'base32')} was published correctly`) // // Add to cache - const id = peerId.toB58String() - // @ts-ignore - parseFloat expects string + const id = peerId.toString() + // @ts-expect-error - parseFloat expects string const ttEol = parseFloat(lifetime) const ttl = (ttEol < defaultRecordTtl) ? ttEol : defaultRecordTtl @@ -114,10 +109,10 @@ export class IPNS { * * Sets the ipns record for the given key to point to an empty directory * - * @param {PrivateKey} privKey + * @param {PeerId} peerId * @param {Uint8Array} value */ - async initializeKeyspace (privKey, value) { // eslint-disable-line require-await - return this.publish(privKey, value, IpnsPublisher.defaultRecordLifetime) + async initializeKeyspace (peerId, value) { // eslint-disable-line require-await + return this.publish(peerId, value, IpnsPublisher.defaultRecordLifetime) } } diff --git a/packages/ipfs-core/src/ipns/publisher.js b/packages/ipfs-core/src/ipns/publisher.js index d16b70b1c1..8eb15015ae 100644 --- a/packages/ipfs-core/src/ipns/publisher.js +++ b/packages/ipfs-core/src/ipns/publisher.js @@ -1,20 +1,18 @@ -import PeerId from 'peer-id' -import { Key } from 'interface-datastore/key' +import { isPeerId } from '@libp2p/interfaces/peer-id' import { notFoundError } from 'datastore-core/errors' import errcode from 'err-code' -import debug from 'debug' +import { logger } from '@libp2p/logger' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' import { equals as uint8ArrayEquals } from 'uint8arrays/equals' import * as ipns from 'ipns' -const log = Object.assign(debug('ipfs:ipns:publisher'), { - error: debug('ipfs:ipns:publisher:error') -}) +const log = logger('ipfs:ipns:publisher') /** * @typedef {import('libp2p-crypto').PrivateKey} PrivateKey * @typedef {import('libp2p-crypto').PublicKey} PublicKey * @typedef {import('ipns').IPNSEntry} IPNSEntry + * @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId */ const ERR_NOT_FOUND = notFoundError().code @@ -34,17 +32,12 @@ export class IpnsPublisher { /** * Publish record with a eol * - * @param {PrivateKey} privKey + * @param {PeerId} peerId * @param {Uint8Array} value * @param {number} lifetime */ - async publishWithEOL (privKey, value, lifetime) { - if (!privKey || !privKey.bytes) { - throw errcode(new Error('invalid private key'), 'ERR_INVALID_PRIVATE_KEY') - } - - const peerId = await PeerId.createFromPrivKey(privKey.bytes) - const record = await this._updateOrCreateRecord(privKey, value, lifetime, peerId) + async publishWithEOL (peerId, value, lifetime) { + const record = await this._updateOrCreateRecord(peerId, value, lifetime) return this._putRecordToRouting(record, peerId) } @@ -52,67 +45,49 @@ export class IpnsPublisher { /** * Accepts a keypair, as well as a value (ipfsPath), and publishes it out to the routing system * - * @param {PrivateKey} privKey + * @param {PeerId} peerId * @param {Uint8Array} value */ - publish (privKey, value) { - return this.publishWithEOL(privKey, value, defaultRecordLifetime) + publish (peerId, value) { + return this.publishWithEOL(peerId, value, defaultRecordLifetime) } /** - * @param {IPNSEntry} record + * @param {Uint8Array} record * @param {PeerId} peerId */ async _putRecordToRouting (record, peerId) { - if (!(PeerId.isPeerId(peerId))) { + if (!(isPeerId(peerId))) { const errMsg = 'peerId received is not valid' log.error(errMsg) throw errcode(new Error(errMsg), 'ERR_INVALID_PEER_ID') } - const publicKey = peerId.pubKey - const embedPublicKeyRecord = await ipns.embedPublicKey(publicKey, record) - const keys = ipns.getIdKeys(peerId.toBytes()) + if (peerId.publicKey == null) { + throw errcode(new Error('Public key was missing'), 'ERR_MISSING_PUBLIC_KEY') + } + + const routingKey = ipns.peerIdToRoutingKey(peerId) - await this._publishEntry(keys.routingKey, embedPublicKeyRecord || record) + await this._publishEntry(routingKey, record) - return embedPublicKeyRecord || record + return record } /** - * @param {Key} key - * @param {IPNSEntry} entry + * @param {Uint8Array} key + * @param {Uint8Array} entry */ async _publishEntry (key, entry) { - const k = Key.asKey(key) - - if (!k) { - const errMsg = 'datastore key does not have a valid format' - - log.error(errMsg) - - throw errcode(new Error(errMsg), 'ERR_INVALID_DATASTORE_KEY') - } - - let entryData - try { - // Marshal record - entryData = ipns.marshal(entry) - } catch (/** @type {any} */ err) { - log.error(err) - - throw err - } - // Add record to routing (buffer key) try { - const res = await this._routing.put(k.uint8Array(), entryData) - log(`ipns record for ${uint8ArrayToString(k.uint8Array(), 'base32')} was stored in the routing`) + const res = await this._routing.put(key, entry) + log(`ipns record for ${uint8ArrayToString(key, 'base32')} was stored in the routing`) return res } catch (/** @type {any} */err) { - const errMsg = `ipns record for ${uint8ArrayToString(k.uint8Array(), 'base32')} could not be stored in the routing - ${err.stack}` + const errMsg = `ipns record for ${uint8ArrayToString(key, 'base32')} could not be stored in the routing - ${err.stack}` log.error(errMsg) log.error(err) @@ -130,7 +105,7 @@ export class IpnsPublisher { * @param {boolean} [options.checkRouting] */ async _getPublished (peerId, options = {}) { - if (!(PeerId.isPeerId(peerId))) { + if (!(isPeerId(peerId))) { const errMsg = 'peerId received is not valid' log.error(errMsg) @@ -141,13 +116,13 @@ export class IpnsPublisher { const checkRouting = options.checkRouting !== false try { - const dsVal = await this._datastore.get(ipns.getLocalKey(peerId.id)) + const dsVal = await this._datastore.get(ipns.getLocalKey(peerId.toBytes())) // unmarshal data return this._unmarshalData(dsVal) } catch (/** @type {any} */ err) { if (err.code !== ERR_NOT_FOUND) { - const errMsg = `unexpected error getting the ipns record ${peerId.id} from datastore` + const errMsg = `unexpected error getting the ipns record ${peerId.toString()} from datastore` log.error(errMsg) throw errcode(new Error(errMsg), 'ERR_UNEXPECTED_DATASTORE_RESPONSE') @@ -159,8 +134,8 @@ export class IpnsPublisher { // Try to get from routing try { - const keys = ipns.getIdKeys(peerId.toBytes()) - const res = await this._routing.get(keys.routingKey.uint8Array()) + const routingKey = ipns.peerIdToRoutingKey(peerId) + const res = await this._routing.get(routingKey) // unmarshal data return this._unmarshalData(res) @@ -184,13 +159,12 @@ export class IpnsPublisher { } /** - * @param {PrivateKey} privKey + * @param {PeerId} peerId * @param {Uint8Array} value * @param {number} lifetime - * @param {PeerId} peerId */ - async _updateOrCreateRecord (privKey, value, lifetime, peerId) { - if (!(PeerId.isPeerId(peerId))) { + async _updateOrCreateRecord (peerId, value, lifetime) { + if (!(isPeerId(peerId))) { const errMsg = 'peerId received is not valid' log.error(errMsg) @@ -201,13 +175,14 @@ export class IpnsPublisher { checkRouting: true } + /** @type {IPNSEntry | undefined} */ let record try { record = await this._getPublished(peerId, getPublishedOptions) } catch (/** @type {any} */ err) { if (err.code !== ERR_NOT_FOUND) { - const errMsg = `unexpected error when determining the last published IPNS record for ${peerId.id} ${err.stack}` + const errMsg = `unexpected error when determining the last published IPNS record for ${peerId.toString()} ${err.stack}` log.error(errMsg) throw errcode(new Error(errMsg), 'ERR_DETERMINING_PUBLISHED_RECORD') @@ -218,14 +193,16 @@ export class IpnsPublisher { let seqNumber = 0n if (record && record.sequence !== undefined) { - seqNumber = !uint8ArrayEquals(record.value, value) ? BigInt(record.sequence) + BigInt(1) : BigInt(record.sequence) + // Increment if the published value is different + seqNumber = uint8ArrayEquals(record.value, value) ? record.sequence : record.sequence + BigInt(1) } + /** @type {IPNSEntry} */ let entryData try { // Create record - entryData = await ipns.create(privKey, value, seqNumber, lifetime) + entryData = await ipns.create(peerId, value, seqNumber, lifetime) } catch (/** @type {any} */ err) { const errMsg = `ipns record for ${value} could not be created` @@ -240,11 +217,11 @@ export class IpnsPublisher { const data = ipns.marshal(entryData) // Store the new record - await this._datastore.put(ipns.getLocalKey(peerId.id), data) + await this._datastore.put(ipns.getLocalKey(peerId.toBytes()), data) log(`ipns record for ${uint8ArrayToString(value, 'base32')} was stored in the datastore`) - return entryData + return data } catch (/** @type {any} */ err) { const errMsg = `ipns record for ${value} could not be stored in the datastore` log.error(errMsg) @@ -253,4 +230,5 @@ export class IpnsPublisher { } } } + IpnsPublisher.defaultRecordLifetime = defaultRecordLifetime diff --git a/packages/ipfs-core/src/ipns/republisher.js b/packages/ipfs-core/src/ipns/republisher.js index 4e51f1e7fd..168bf9bda1 100644 --- a/packages/ipfs-core/src/ipns/republisher.js +++ b/packages/ipfs-core/src/ipns/republisher.js @@ -1,15 +1,15 @@ import * as ipns from 'ipns' -import crypto from 'libp2p-crypto' -import PeerId from 'peer-id' +import { importKey } from '@libp2p/crypto/keys' +import { isPeerId } from '@libp2p/interfaces/peer-id' import errcode from 'err-code' -import debug from 'debug' +import { logger } from '@libp2p/logger' +import { peerIdFromKeys } from '@libp2p/peer-id' -const log = Object.assign(debug('ipfs:ipns:republisher'), { - error: debug('ipfs:ipns:republisher:error') -}) +const log = logger('ipfs:ipns:republisher') /** * @typedef {import('libp2p-crypto').PrivateKey} PrivateKey + * @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId */ const minute = 60 * 1000 @@ -23,7 +23,7 @@ export class IpnsRepublisher { * @param {import('./publisher').IpnsPublisher} publisher * @param {import('interface-datastore').Datastore} datastore * @param {PeerId} peerId - * @param {import('libp2p/src/keychain')} keychain + * @param {import('@libp2p/interfaces/keychain').KeyChain} keychain * @param {object} options * @param {string} options.pass * @param {number} [options.initialBroadcastInterval] @@ -59,7 +59,7 @@ export class IpnsRepublisher { republishHandle._timeoutId = null try { - // @ts-ignore - _task could be null + // @ts-expect-error - _task could be null republishHandle._inflightTask = republishHandle._task() await republishHandle._inflightTask @@ -84,11 +84,10 @@ export class IpnsRepublisher { } } - const { privKey } = this._peerId const { pass } = this._options let firstRun = true - republishHandle._task = () => this._republishEntries(privKey, pass) + republishHandle._task = () => this._republishEntries(this._peerId, pass) republishHandle.runPeriodically(() => { if (firstRun) { @@ -115,14 +114,14 @@ export class IpnsRepublisher { } /** - * @param {PrivateKey} privateKey + * @param {PeerId} peerId * @param {string} pass */ - async _republishEntries (privateKey, pass) { + async _republishEntries (peerId, pass) { // TODO: Should use list of published entries. // We can't currently *do* that because go uses this method for now. try { - await this._republishEntry(privateKey) + await this._republishEntry(peerId) } catch (/** @type {any} */ err) { const errMsg = 'cannot republish entry for the node\'s private key' @@ -139,10 +138,12 @@ export class IpnsRepublisher { if (key.name === 'self') { continue } + const pem = await this._keychain.exportKey(key.name, pass) - const privKey = await crypto.keys.import(pem, pass) + const privKey = await importKey(pem, pass) + const peerIdKey = await peerIdFromKeys(privKey.public.bytes, privKey.bytes) - await this._republishEntry(privKey) + await this._republishEntry(peerIdKey) } } catch (/** @type {any} */ err) { log.error(err) @@ -151,17 +152,12 @@ export class IpnsRepublisher { } /** - * @param {PrivateKey} privateKey + * @param {PeerId} peerId */ - async _republishEntry (privateKey) { - if (!privateKey || !privateKey.bytes) { - throw errcode(new Error('invalid private key'), 'ERR_INVALID_PRIVATE_KEY') - } - + async _republishEntry (peerId) { try { - const peerId = await PeerId.createFromPrivKey(privateKey.bytes) const value = await this._getPreviousValue(peerId) - await this._publisher.publishWithEOL(privateKey, value, defaultRecordLifetime) + await this._publisher.publishWithEOL(peerId, value, defaultRecordLifetime) } catch (/** @type {any} */ err) { if (err.code === 'ERR_NO_ENTRY_FOUND') { return @@ -175,12 +171,12 @@ export class IpnsRepublisher { * @param {PeerId} peerId */ async _getPreviousValue (peerId) { - if (!(PeerId.isPeerId(peerId))) { + if (!(isPeerId(peerId))) { throw errcode(new Error('invalid peer ID'), 'ERR_INVALID_PEER_ID') } try { - const dsVal = await this._datastore.get(ipns.getLocalKey(peerId.id)) + const dsVal = await this._datastore.get(ipns.getLocalKey(peerId.toBytes())) if (!(dsVal instanceof Uint8Array)) { throw errcode(new Error("found ipns record that we couldn't process"), 'ERR_INVALID_IPNS_RECORD') @@ -199,7 +195,7 @@ export class IpnsRepublisher { // error handling // no need to republish if (err && err.notFound) { - throw errcode(new Error(`no previous entry for record with id: ${peerId.id}`), 'ERR_NO_ENTRY_FOUND') + throw errcode(new Error(`no previous entry for record with id: ${peerId.toString()}`), 'ERR_NO_ENTRY_FOUND') } throw err diff --git a/packages/ipfs-core/src/ipns/resolver.js b/packages/ipfs-core/src/ipns/resolver.js index 8036d96f0c..b06203b3a1 100644 --- a/packages/ipfs-core/src/ipns/resolver.js +++ b/packages/ipfs-core/src/ipns/resolver.js @@ -1,13 +1,18 @@ import * as ipns from 'ipns' -import PeerId from 'peer-id' +import { peerIdFromString } from '@libp2p/peer-id' import errcode from 'err-code' -import debug from 'debug' +import { logger } from '@libp2p/logger' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' +import { concat as uint8ArrayConcat } from 'uint8arrays/concat' import * as Errors from 'datastore-core/errors' +import { ipnsValidator } from 'ipns/validator' -const log = Object.assign(debug('ipfs:ipns:resolver'), { - error: debug('ipfs:ipns:resolver:error') -}) +/** + * @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId + */ + +const log = logger('ipfs:ipns:resolver') const ERR_NOT_FOUND = Errors.notFoundError().code @@ -88,12 +93,12 @@ export class IpnsResolver { * @param {string} name */ async _resolveName (name) { - const peerId = PeerId.parse(name) - const { routingKey } = ipns.getIdKeys(peerId.toBytes()) + const peerId = peerIdFromString(name) + const routingKey = ipns.peerIdToRoutingKey(peerId) let record try { - record = await this._routing.get(routingKey.uint8Array()) + record = await this._routing.get(routingKey) } catch (/** @type {any} */ err) { log.error('could not get record from routing', err) @@ -104,31 +109,24 @@ export class IpnsResolver { throw errcode(new Error(`unexpected error getting the ipns record ${peerId.toString()}`), 'ERR_UNEXPECTED_ERROR_GETTING_RECORD') } - // IPNS entry - let ipnsEntry - try { - ipnsEntry = ipns.unmarshal(record) - } catch (/** @type {any} */ err) { - log.error('could not unmarshal record', err) - - throw errcode(new Error('found ipns record that we couldn\'t convert to a value'), 'ERR_INVALID_RECORD_RECEIVED') - } - // We should have the public key by now (inline, or in the entry) - return this._validateRecord(peerId, ipnsEntry) + return this._validateRecord(peerId, record) } /** * Validate a resolved record * * @param {PeerId} peerId - * @param {import('ipns').IPNSEntry} ipnsEntry + * @param {Uint8Array} record */ - async _validateRecord (peerId, ipnsEntry) { - const pubKey = await ipns.extractPublicKey(peerId, ipnsEntry) - + async _validateRecord (peerId, record) { // IPNS entry validation - await ipns.validate(pubKey, ipnsEntry) + await ipnsValidator(uint8ArrayConcat([ + uint8ArrayFromString('/ipns/'), + peerId.toBytes() + ]), record) + + const ipnsEntry = ipns.unmarshal(record) return uint8ArrayToString(ipnsEntry.value) } diff --git a/packages/ipfs-core/src/ipns/routing/config.js b/packages/ipfs-core/src/ipns/routing/config.js index 0494c641b6..afcb54fb5d 100644 --- a/packages/ipfs-core/src/ipns/routing/config.js +++ b/packages/ipfs-core/src/ipns/routing/config.js @@ -10,9 +10,9 @@ import { DHTDatastore } from './dht-datastore.js' /** * @param {object} arg - * @param {import('libp2p')} arg.libp2p + * @param {import('libp2p').Libp2p} arg.libp2p * @param {import('ipfs-repo').IPFSRepo} arg.repo - * @param {import('peer-id')} arg.peerId + * @param {import('@libp2p/interfaces/peer-id').PeerId} arg.peerId * @param {object} arg.options */ export function createRouting ({ libp2p, repo, peerId, options }) { @@ -23,21 +23,18 @@ export function createRouting ({ libp2p, repo, peerId, options }) { // Add IPNS pubsub if enabled let pubsubDs if (get(options, 'EXPERIMENTAL.ipnsPubsub', false)) { - const pubsub = libp2p.pubsub - const localDatastore = repo.datastore - - pubsubDs = new IpnsPubsubDatastore(pubsub, localDatastore, peerId) + pubsubDs = new IpnsPubsubDatastore(libp2p.pubsub, repo.datastore, peerId) ipnsStores.push(pubsubDs) } // Add DHT datastore if enabled - if (!get(options, 'offline', false) && libp2p._config && libp2p._config.dht && libp2p._config.dht.enabled) { - ipnsStores.push(new DHTDatastore(libp2p._dht)) + if (!get(options, 'offline', false) && get(options, 'config.Routing.Type') !== 'none') { + ipnsStores.push(new DHTDatastore(libp2p.dht)) } // Add an offline datastore if we are offline or no other datastores are configured if (get(options, 'offline', false) || ipnsStores.length === 0) { - const offlineDatastore = new OfflineDatastore(repo) + const offlineDatastore = new OfflineDatastore(repo.datastore) ipnsStores.push(offlineDatastore) } diff --git a/packages/ipfs-core/src/ipns/routing/dht-datastore.js b/packages/ipfs-core/src/ipns/routing/dht-datastore.js index b25f48301a..e137d64c96 100644 --- a/packages/ipfs-core/src/ipns/routing/dht-datastore.js +++ b/packages/ipfs-core/src/ipns/routing/dht-datastore.js @@ -1,15 +1,13 @@ import drain from 'it-drain' import { notFoundError } from 'datastore-core/errors' -import debug from 'debug' +import { logger } from '@libp2p/logger' -const log = Object.assign(debug('ipfs:ipns:dht-datastore'), { - error: debug('ipfs:ipns:dht-datastore:error') -}) +const log = logger('ipfs:ipns:dht-datastore') export class DHTDatastore { /** * - * @param {import('libp2p-kad-dht/src/types').DHT} dht + * @param {import('@libp2p/interfaces/dht').DHT} dht */ constructor (dht) { this._dht = dht diff --git a/packages/ipfs-core/src/ipns/routing/offline-datastore.js b/packages/ipfs-core/src/ipns/routing/offline-datastore.js index 817221e026..5ec0289e9d 100644 --- a/packages/ipfs-core/src/ipns/routing/offline-datastore.js +++ b/packages/ipfs-core/src/ipns/routing/offline-datastore.js @@ -1,21 +1,19 @@ import { Key } from 'interface-datastore/key' -import { Record } from 'libp2p-record' +import { Libp2pRecord } from '@libp2p/record' import errcode from 'err-code' -import debug from 'debug' +import { logger } from '@libp2p/logger' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' -const log = Object.assign(debug('ipfs:ipns:offline-datastore'), { - error: debug('ipfs:ipns:offline-datastore:error') -}) +const log = logger('ipfs:ipns:offline-datastore') // Offline datastore aims to mimic the same encoding as routing when storing records // to the local datastore export class OfflineDatastore { /** - * @param {import('ipfs-repo').IPFSRepo} repo + * @param {import('interface-datastore').Datastore} datastore */ - constructor (repo) { - this._repo = repo + constructor (datastore) { + this._datastore = datastore /** @type {any[]} */ this.stores = [] } @@ -45,9 +43,9 @@ export class OfflineDatastore { } // Marshal to libp2p record as the DHT does - const record = new Record(key, value) + const record = new Libp2pRecord(key, value, new Date()) - return this._repo.datastore.put(routingKey, record.serialize()) + await this._datastore.put(routingKey, record.serialize()) } /** @@ -69,12 +67,12 @@ export class OfflineDatastore { throw errcode(new Error('Not possible to generate the routing key'), 'ERR_GENERATING_ROUTING_KEY') } - const res = await this._repo.datastore.get(routingKey) + const res = await this._datastore.get(routingKey) // Unmarshal libp2p record as the DHT does let record try { - record = Record.deserialize(res) + record = Libp2pRecord.deserialize(res) } catch (/** @type {any} */ err) { log.error(err) throw err diff --git a/packages/ipfs-core/src/ipns/routing/pubsub-datastore.js b/packages/ipfs-core/src/ipns/routing/pubsub-datastore.js index c82b2b4c14..2eb4999e44 100644 --- a/packages/ipfs-core/src/ipns/routing/pubsub-datastore.js +++ b/packages/ipfs-core/src/ipns/routing/pubsub-datastore.js @@ -1,21 +1,22 @@ -import * as ipns from 'ipns' +import { namespaceLength, namespace, peerIdToRoutingKey } from 'ipns' +import { ipnsValidator } from 'ipns/validator' +import { ipnsSelector } from 'ipns/selector' import { base58btc } from 'multiformats/bases/base58' -import { PubsubDatastore } from 'datastore-pubsub' +import { PubSubDatastore } from 'datastore-pubsub' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' import errcode from 'err-code' -import debug from 'debug' +import { logger } from '@libp2p/logger' +import { peerIdFromString } from '@libp2p/peer-id' -const log = Object.assign(debug('ipfs:ipns:pubsub'), { - error: debug('ipfs:ipns:pubsub:error') -}) +const log = logger('ipfs:ipns:pubsub') // Pubsub datastore aims to manage the pubsub subscriptions for IPNS export class IpnsPubsubDatastore { /** - * @param {import('libp2p-interfaces/src/pubsub')} pubsub + * @param {import('@libp2p/interfaces/pubsub').PubSub} pubsub * @param {import('interface-datastore').Datastore} localDatastore - * @param {import('peer-id')} peerId + * @param {import('@libp2p/interfaces/peer-id').PeerId} peerId */ constructor (pubsub, localDatastore, peerId) { /** @type {Record} */ @@ -24,8 +25,7 @@ export class IpnsPubsubDatastore { // Bind _handleSubscriptionKey function, which is called by PubsubDatastore. this._handleSubscriptionKey = this._handleSubscriptionKey.bind(this) - // @ts-ignore will be fixed by https://github.com/ipfs/js-datastore-pubsub/pull/74 - this._pubsubDs = new PubsubDatastore(pubsub, localDatastore, peerId, ipns.validator, this._handleSubscriptionKey) + this._pubsubDs = new PubSubDatastore(pubsub, localDatastore, peerId, ipnsValidator, ipnsSelector, this._handleSubscriptionKey) } /** @@ -36,7 +36,6 @@ export class IpnsPubsubDatastore { */ async put (key, value) { try { - // @ts-ignore datastores take Key keys, this one takes Uint8Array keys await this._pubsubDs.put(key, value) } catch (/** @type {any} */ err) { log.error(err) @@ -56,18 +55,17 @@ export class IpnsPubsubDatastore { let err try { - // @ts-ignore datastores take Key keys, this one takes Uint8Array keys res = await this._pubsubDs.get(key) } catch (/** @type {any} */ e) { err = e } // Add topic subscribed - const ns = key.slice(0, ipns.namespaceLength) + const ns = key.slice(0, namespaceLength) - if (uint8ArrayToString(ns) === ipns.namespace) { + if (uint8ArrayToString(ns) === namespace) { const stringifiedTopic = base58btc.encode(key).substring(1) - const id = base58btc.encode(key.slice(ipns.namespaceLength)).substring(1) + const id = base58btc.encode(key.slice(namespaceLength)).substring(1) this._subscriptions[stringifiedTopic] = id @@ -98,15 +96,13 @@ export class IpnsPubsubDatastore { throw errcode(new Error(`key ${key} does not correspond to a subscription`), 'ERR_INVALID_KEY') } - let keys try { - keys = ipns.getIdKeys(uint8ArrayFromString(subscriber, 'base58btc')) + const k = peerIdToRoutingKey(peerIdFromString(subscriber)) + return k } catch (/** @type {any} */ err) { log.error(err) throw err } - - return keys.routingKey.uint8Array() } /** @@ -115,7 +111,7 @@ export class IpnsPubsubDatastore { getSubscriptions () { const subscriptions = Object.values(this._subscriptions).filter(Boolean) - return subscriptions.map((sub) => `${ipns.namespace}${sub}`) + return subscriptions.map((sub) => `${namespace}${sub}`) } /** @@ -129,8 +125,8 @@ export class IpnsPubsubDatastore { } // Trim /ipns/ prefix from the name - if (name.startsWith(ipns.namespace)) { - name = name.substring(ipns.namespaceLength) + if (name.startsWith(namespace)) { + name = name.substring(namespaceLength) } const stringifiedTopic = Object.keys(this._subscriptions).find((key) => this._subscriptions[key] === name) diff --git a/packages/ipfs-core/src/mfs-preload.js b/packages/ipfs-core/src/mfs-preload.js index 15b95a9fef..c2cc8764b0 100644 --- a/packages/ipfs-core/src/mfs-preload.js +++ b/packages/ipfs-core/src/mfs-preload.js @@ -1,17 +1,16 @@ -import debug from 'debug' -const log = Object.assign(debug('ipfs:mfs-preload'), { - error: debug('ipfs:mfs-preload:error') -}) +import { logger } from '@libp2p/logger' + +const log = logger('ipfs:mfs-preload') /** * @typedef {PreloadOptions & MFSPreloadOptions} Options - * @typedef {Object} MFSPreloadOptions + * @typedef {object} MFSPreloadOptions * @property {number} [interval] * @typedef {import('./types').PreloadOptions} PreloadOptions */ /** - * @param {Object} config + * @param {object} config * @param {import('./types').Preload} config.preload * @param {import('ipfs-core-types/src/files').API} config.files * @param {Options} [config.options] diff --git a/packages/ipfs-core/src/preload.js b/packages/ipfs-core/src/preload.js index b5564011bf..1f92d20f70 100644 --- a/packages/ipfs-core/src/preload.js +++ b/packages/ipfs-core/src/preload.js @@ -1,17 +1,12 @@ // @ts-expect-error no types import toUri from 'multiaddr-to-uri' -import debug from 'debug' +import { logger } from '@libp2p/logger' import shuffle from 'array-shuffle' import { preload } from 'ipfs-core-config/preload' -/** @type {typeof import('hashlru').default} */ -// @ts-ignore - hashlru has incorrect typedefs import hashlru from 'hashlru' -const log = Object.assign( - debug('ipfs:preload'), - { error: debug('ipfs:preload:error') } -) +const log = logger('ipfs:preload') /** * @param {import('./types').PreloadOptions} [options] diff --git a/packages/ipfs-core/src/types.ts b/packages/ipfs-core/src/types.ts index 6b0ee17b22..9d09890a5e 100644 --- a/packages/ipfs-core/src/types.ts +++ b/packages/ipfs-core/src/types.ts @@ -1,8 +1,7 @@ -import type { KeyType } from 'libp2p-crypto' -import type PeerId from 'peer-id' +import type { KeyType } from '@libp2p/interfaces/keys' +import type { PeerId } from '@libp2p/interfaces/peer-id' import type { Config as IPFSConfig } from 'ipfs-core-types/src/config' -import type Libp2p from 'libp2p' -import type { Libp2pOptions } from 'libp2p' +import type { Libp2p, Libp2pOptions } from 'libp2p' import type { IPFSRepo } from 'ipfs-repo' import type { ProgressCallback as MigrationProgressCallback } from 'ipfs-repo-migrations' diff --git a/packages/ipfs-core/src/utils.js b/packages/ipfs-core/src/utils.js index 719386279d..7e473777f8 100644 --- a/packages/ipfs-core/src/utils.js +++ b/packages/ipfs-core/src/utils.js @@ -147,7 +147,7 @@ export const mapFile = (file) => { } if (file.type === 'directory') { - // @ts-ignore - TS type can't be changed from File to Directory + // @ts-expect-error - TS type can't be changed from File to Directory output.type = 'dir' } diff --git a/packages/ipfs-core/src/utils/service.js b/packages/ipfs-core/src/utils/service.js index 30ed56c0cb..e966592667 100644 --- a/packages/ipfs-core/src/utils/service.js +++ b/packages/ipfs-core/src/utils/service.js @@ -45,7 +45,7 @@ export class Service { * * @template {(options:any) => Await} T * - * @param {Object} config + * @param {object} config * @param {T} config.start * @param {(state:State) => Await} [config.stop] * @returns {Service[0], State>} diff --git a/packages/ipfs-core/src/utils/tlru.js b/packages/ipfs-core/src/utils/tlru.js index b5705b10c0..0286d5e738 100644 --- a/packages/ipfs-core/src/utils/tlru.js +++ b/packages/ipfs-core/src/utils/tlru.js @@ -1,5 +1,3 @@ -/** @type {typeof import('hashlru').default} */ -// @ts-ignore - hashlru has incorrect typedefs import hashlru from 'hashlru' /** diff --git a/packages/ipfs-core/src/version.js b/packages/ipfs-core/src/version.js index ada321b796..ebc76f0d3c 100644 --- a/packages/ipfs-core/src/version.js +++ b/packages/ipfs-core/src/version.js @@ -1,4 +1,4 @@ -export const ipfsCore = '' +export const ipfsCore = '0.14.2' export const commit = '' -export const interfaceIpfsCore = '' +export const interfaceIpfsCore = '^0.154.2' diff --git a/packages/ipfs-core/test/add-all.spec.js b/packages/ipfs-core/test/add-all.spec.js index 3c69d6d4db..8dcee75cdd 100644 --- a/packages/ipfs-core/test/add-all.spec.js +++ b/packages/ipfs-core/test/add-all.spec.js @@ -1,7 +1,7 @@ /* eslint max-nested-callbacks: ["error", 8] */ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import * as utils from '../src/components/add-all/utils.js' describe('add-all/utils', () => { diff --git a/packages/ipfs-core/test/block-storage.spec.js b/packages/ipfs-core/test/block-storage.spec.js index cd5fc60521..5549da294a 100644 --- a/packages/ipfs-core/test/block-storage.spec.js +++ b/packages/ipfs-core/test/block-storage.spec.js @@ -28,7 +28,7 @@ describe('block-storage', () => { // use the same instance to represent both const blockstore = new MockBitswap(true) - // @ts-ignore MockBitswap is missing some properties + // @ts-expect-error MockBitswap is missing some properties return new BlockStorage(blockstore, blockstore) }, teardown: () => {} @@ -42,7 +42,7 @@ describe('block-storage', () => { // use the same instance to represent both const blockstore = new MockBitswap(false) - // @ts-ignore MockBitswap is missing some properties + // @ts-expect-error MockBitswap is missing some properties return new BlockStorage(blockstore, blockstore) }, teardown: () => {} diff --git a/packages/ipfs-core/test/config.spec.js b/packages/ipfs-core/test/config.spec.js index 9ac172f136..2542aec03b 100644 --- a/packages/ipfs-core/test/config.spec.js +++ b/packages/ipfs-core/test/config.spec.js @@ -1,8 +1,8 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' -import { Multiaddr } from 'multiaddr' +import { expect } from 'aegir/chai' +import { Multiaddr } from '@multiformats/multiaddr' import { isBrowser, isWebWorker } from 'ipfs-utils/src/env.js' import createNode from './utils/create-node.js' import createConfig from 'ipfs-core-config/config' diff --git a/packages/ipfs-core/test/create-node.spec.js b/packages/ipfs-core/test/create-node.spec.js index d56c5144f5..cb7065f759 100644 --- a/packages/ipfs-core/test/create-node.spec.js +++ b/packages/ipfs-core/test/create-node.spec.js @@ -1,18 +1,18 @@ /* eslint max-nested-callbacks: ["error", 8] */ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import sinon from 'sinon' import { isNode } from 'ipfs-utils/src/env.js' import tmpDir from 'ipfs-utils/src/temp-dir.js' -import PeerId from 'peer-id' -import { keys } from 'libp2p-crypto' +import { peerIdFromKeys } from '@libp2p/peer-id' +import { unmarshalPrivateKey } from '@libp2p/crypto/keys' import * as IPFS from '../src/index.js' import defer from 'p-defer' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { createTempRepo } from './utils/create-repo.js' - -const { supportedKeys } = keys +import { createEd25519PeerId } from '@libp2p/peer-id-factory' describe('create node', function () { /** @type {import('ipfs-repo').IPFSRepo} */ @@ -71,9 +71,12 @@ describe('create node', function () { const id = await ipfs.id() const config = await ipfs.config.getAll() - const peerId = await PeerId.createFromPrivKey(`${config.Identity?.PrivKey}`) - expect(peerId.privKey).is.instanceOf(supportedKeys.ed25519.Ed25519PrivateKey) - expect(id.id).to.equal(peerId.toB58String()) + const buf = uint8ArrayFromString(`${config.Identity?.PrivKey}`, 'base64pad') + const key = await unmarshalPrivateKey(buf) + const peerId = await peerIdFromKeys(key.public.bytes, key.bytes) + + expect(peerId.type).to.equal('Ed25519') + expect(id.id.toString()).to.equal(peerId.toString()) }) it('should create and initialize but not start', async () => { @@ -298,9 +301,7 @@ describe('create node', function () { this.timeout(80 * 1000) const deferred = defer() - const id = await PeerId.create({ - bits: 512 - }) + const id = await createEd25519PeerId() // create an old-looking repo const repo = await createTempRepo({ @@ -309,7 +310,7 @@ describe('create node', function () { config: { Identity: { PeerID: id.toString(), - PrivKey: uint8ArrayToString(id.marshalPrivKey(), 'base64pad') + PrivKey: uint8ArrayToString(id.toBytes(), 'base64pad') } }, autoMigrate: true, diff --git a/packages/ipfs-core/test/exports.spec.js b/packages/ipfs-core/test/exports.spec.js deleted file mode 100644 index 9fbb5630f0..0000000000 --- a/packages/ipfs-core/test/exports.spec.js +++ /dev/null @@ -1,19 +0,0 @@ -/* eslint-env mocha */ - -import crypto from 'libp2p-crypto' -import isIPFS from 'is-ipfs' -import { CID } from 'multiformats/cid' -import { Multiaddr } from 'multiaddr' -import PeerId from 'peer-id' -import { expect } from 'aegir/utils/chai.js' -import * as Ipfs from '../src/index.js' - -describe('exports', () => { - it('should export the expected types and utilities', () => { - expect(Ipfs.crypto).to.equal(crypto) - expect(Ipfs.isIPFS).to.equal(isIPFS) - expect(Ipfs.CID).to.equal(CID) - expect(Ipfs.multiaddr).to.equal(Multiaddr) - expect(Ipfs.PeerId).to.equal(PeerId) - }) -}) diff --git a/packages/ipfs-core/test/init.spec.js b/packages/ipfs-core/test/init.spec.js index 4b0f389b66..6b32b0cad4 100644 --- a/packages/ipfs-core/test/init.spec.js +++ b/packages/ipfs-core/test/init.spec.js @@ -1,14 +1,12 @@ /* eslint max-nested-callbacks: ["error", 8] */ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { isNode } from 'ipfs-utils/src/env.js' import { CID } from 'multiformats/cid' -import PeerId from 'peer-id' -import { keys } from 'libp2p-crypto' +import { peerIdFromBytes } from '@libp2p/peer-id' import createNode from './utils/create-node.js' - -const { supportedKeys } = keys +import { fromString as uint8ArrayFromString } from 'uint8arrays' const privateKey = 'CAASqAkwggSkAgEAAoIBAQChVmiObYo6pkKrMSd3OzW1cTL+RDmX1rkETYGKWV9TPXMNgElFTYoYHqT9QZomj5RI8iUmHccjzqr4J0mV+E0NpvHHOLlmDZ82lAw2Zx7saUkeQWvC0S9Z0o3aTx2sSubZV53rSomkZgQH4fYTs4RERejV4ltzLFdzQQBwWrBvlagpPHUCxKDUCnE5oIzdbD26ltWViPBWr7TfotzC8Lyi/tceqCpHMUJGMbsVgypnlgpey07MBvs71dVh5LcRen/ztsQO6Yju4D3QgWoyD0SIUdJFvBzEwL9bSiA3QjUc/fkGd7EcdN5bebYOqAi4ZIiAMLp3i4+B8Tzq/acull43AgMBAAECggEBAIDgZE75o4SsEO9tKWht7L5OeXxxBUyMImkUfJkGQUZd/MzZIC5y/Q+9UvBW+gs5gCsw+onTGaM50Iq/32Ej4nE4XURVxIuH8BmJ86N1hlc010qK2cjajqeCsPulXT+m6XbOLYCpnv+q2idt0cL1EH/1FEPeOEztK8ION4qIdw36SoykfTx/RqtkKHtS01AwN82EOPbWk7huyQT5R5MsCZmRJXBFkpNtiL+8619BH2aVlghHO4NouF9wQjdz/ysVuyYg+3rX2cpGjuHDTZ6hVQiJD1lF6D+dua7UPyHYAG2iRQiKZmCjitt9ywzPxiRaYF/aZ02FEMWckZulR09axskCgYEAzjl6ER8WwxYHn4tHse+CrIIF2z5cscdrh7KSwd3Rse9hIIBDJ/0KkvoYd1IcWrS8ywLrRfSLIjEU9u7IN1m+IRVWJ61fXNqOHm9clAu6qNhCN6W2+JfxDkUygTwmsq0v3huO+qkiMQz+a4nAXJe8Utd36ywgPhVGxFa/7x1v1N0CgYEAyEdiYRFf1aQZcO7+B2FH+tkGJsB30VIBhcpG9EukuQUUulLHhScc/KRj+EFAACLdkTqlVI0xVYIWaaCXwoQCWKixjZ5mYPC+bBLgn4IoDS6XTdHtR7Vn3UUvGTKsM0/z4e8/0eSzGNCHoYez9IoBlPNic0sQuST4jzgS2RYnFCMCgYASWSzSLyjwTJp7CIJlg4Dl5l+tBRxsOOkJVssV8q2AnmLO6HqRKUNylkvs+eJJ88DEc0sJm1txvFo4KkCoJBT1jpduyk8szMlOTew3w99kvHEP0G+6KJKrCV8X/okW5q/WnC8ZgEjpglV0rfnugxWfbUpfIzrvKydzuqAzHzRfBQKBgQDANtKSeoxRjEbmfljLWHAure8bbgkQmfXgI7xpZdfXwqqcECpw/pLxXgycDHOSLeQcJ/7Y4RGCEXHVOk2sX+mokW6mjmmPjD4VlyCBtfcef6KzC1EBS3c9g9KqCln+fTOBmY7UsPu6SxiAzK7HeVP/Un8gS+Dm8DalrZlZQ8uJpQKBgF6mL/Xo/XUOiz2jAD18l8Y6s49bA9H2CoLpBGTV1LfY5yTFxRy4R3qnX/IzsKy567sbtkEFKJxplc/RzCQfrgbdj7k26SbKtHR3yERaFGRYq8UeAHeYC1/N19LF5BMQL4y5R4PJ1SFPeJCL/wXiMqs1maTqvKqtc4bbegNdwlxn' const edPrivateKey = 'CAESYFeZamw+9QdwHgSmcvPmfLUpmWTtYpUeycbXcfnkTnDI7OaPmE6V8i+Lw7FNB5CtYuDFKUsOS5h+AogyF/Dft4Ds5o+YTpXyL4vDsU0HkK1i4MUpSw5LmH4CiDIX8N+3gA==' @@ -93,24 +91,24 @@ describe('init', function () { await init({ init: { algorithm: 'RSA' } }) const config = await repo.config.getAll() - const peerId = await PeerId.createFromPrivKey(`${config.Identity?.PrivKey}`) - expect(peerId.privKey).is.instanceOf(supportedKeys.rsa.RsaPrivateKey) + const peerId = await peerIdFromBytes(uint8ArrayFromString(`${config.Identity?.PrivKey}`, 'base64')) + expect(peerId.type).equals('RSA') }) it('should init with a key algorithm (Ed25519)', async () => { await init({ init: { algorithm: 'Ed25519' } }) const config = await repo.config.getAll() - const peerId = await PeerId.createFromPrivKey(`${config.Identity?.PrivKey}`) - expect(peerId.privKey).is.instanceOf(supportedKeys.ed25519.Ed25519PrivateKey) + const peerId = await peerIdFromBytes(uint8ArrayFromString(`${config.Identity?.PrivKey}`, 'base64')) + expect(peerId.type).equals('Ed25519') }) it('should init with a key algorithm (secp256k1)', async () => { await init({ init: { algorithm: 'secp256k1' } }) const config = await repo.config.getAll() - const peerId = await PeerId.createFromPrivKey(`${config.Identity?.PrivKey}`) - expect(peerId.privKey).is.instanceOf(supportedKeys.secp256k1.Secp256k1PrivateKey) + const peerId = await peerIdFromBytes(uint8ArrayFromString(`${config.Identity?.PrivKey}`, 'base64')) + expect(peerId.type).equals('secp256k1') }) it('should set # of bits in key', async function () { diff --git a/packages/ipfs-core/test/ipld.spec.js b/packages/ipfs-core/test/ipld.spec.js index e34c0d5525..b1f9b01aff 100644 --- a/packages/ipfs-core/test/ipld.spec.js +++ b/packages/ipfs-core/test/ipld.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import createNode from './utils/create-node.js' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' diff --git a/packages/ipfs-core/test/key-exchange.spec.js b/packages/ipfs-core/test/key-exchange.spec.js index dcfd6d02ab..fba2dbf2c4 100644 --- a/packages/ipfs-core/test/key-exchange.spec.js +++ b/packages/ipfs-core/test/key-exchange.spec.js @@ -1,7 +1,7 @@ /* eslint max-nested-callbacks: ["error", 8] */ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { nanoid } from 'nanoid' import createNode from './utils/create-node.js' diff --git a/packages/ipfs-core/test/libp2p.spec.js b/packages/ipfs-core/test/libp2p.spec.js index 4d93830ddf..024aadc82d 100644 --- a/packages/ipfs-core/test/libp2p.spec.js +++ b/packages/ipfs-core/test/libp2p.spec.js @@ -1,17 +1,19 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { MemoryDatastore } from 'datastore-core/memory' -import PeerId from 'peer-id' -import Libp2p from 'libp2p' -import { EventEmitter } from 'events' +// import { createLibp2p } from 'libp2p' +// import { EventEmitter } from 'events' import { createLibp2p as libp2pComponent } from '../src/components/libp2p.js' -import { NOISE as Crypto } from '@chainsafe/libp2p-noise' -import gossipsub from 'libp2p-gossipsub' +// import { NOISE as Crypto } from '@chainsafe/libp2p-noise' +import { GossipSub } from '@achingbrain/libp2p-gossipsub' +import { createEd25519PeerId } from '@libp2p/peer-id-factory' /** - * @type {import('libp2p-interfaces/src/transport/types').TransportFactory} + * @type {import('@libp2p/interfaces/transport').Transport} */ + +/* class DummyTransport { get [Symbol.toStringTag] () { return 'DummyTransport' @@ -35,6 +37,7 @@ class DummyDiscovery extends EventEmitter { return Promise.resolve() } } +*/ describe('libp2p customization', function () { // Provide some extra time for ci since we're starting libp2p nodes in each test @@ -45,7 +48,7 @@ describe('libp2p customization', function () { */ let datastore /** - * @type {import('peer-id')} + * @type {import('@libp2p/interfaces/peer-id').PeerId} */ let peerId /** @@ -53,7 +56,7 @@ describe('libp2p customization', function () { */ let testConfig /** - * @type {import('libp2p') | null} + * @type {import('libp2p').Libp2p | null} */ let libp2p @@ -76,7 +79,7 @@ describe('libp2p customization', function () { } } datastore = new MemoryDatastore() - peerId = await PeerId.create() + peerId = await createEd25519PeerId() }) afterEach(async () => { @@ -85,23 +88,22 @@ describe('libp2p customization', function () { libp2p = null } }) - + /* describe('bundle', () => { it('should allow for using a libp2p bundle', async () => { libp2p = await libp2pComponent({ options: { - /** @type {import('../src/types').Libp2pFactoryFn} */ libp2p: async (opts) => { - return Libp2p.create({ + return createLibp2p({ peerId: opts.peerId, - // @ts-ignore DummyTransport is not complete implementation - modules: { transport: [DummyTransport], connEncryption: [Crypto] }, - config: { relay: { enabled: false } } + transports: [new DummyTransport()], + connectionEncryption: [Crypto], + relay: { enabled: false } }) } }, peerId, - // @ts-ignore repo is not complete implementation + // @ts-expect-error repo is not complete implementation repo: { datastore }, print: console.log, // eslint-disable-line no-console config: testConfig @@ -117,18 +119,17 @@ describe('libp2p customization', function () { it('should pass libp2p options to libp2p bundle function', async () => { libp2p = await libp2pComponent({ options: { - /** @type {import('../src/types').Libp2pFactoryFn} */ libp2p: async (opts) => { - return Libp2p.create({ + return createLibp2p({ peerId: opts.peerId, - // @ts-ignore DummyTransport is not complete implementation + // @ts-expect-error DummyTransport is not complete implementation modules: { transport: [DummyTransport], connEncryption: [Crypto] }, config: { relay: { enabled: false } } }) } }, peerId, - // @ts-ignore repo is not complete implementation + // @ts-expect-error repo is not complete implementation repo: { datastore }, print: console.log, // eslint-disable-line no-console config: testConfig @@ -146,7 +147,7 @@ describe('libp2p customization', function () { it('should use options by default', async () => { libp2p = await libp2pComponent({ peerId, - // @ts-ignore repo is not complete implementation + // @ts-expect-error repo is not complete implementation repo: { datastore }, print: console.log, // eslint-disable-line no-console config: testConfig @@ -182,19 +183,15 @@ describe('libp2p customization', function () { libp2p = await libp2pComponent({ peerId, - // @ts-ignore repo is not complete implementation + // @ts-expect-error repo is not complete implementation repo: { datastore }, print: console.log, // eslint-disable-line no-console config: testConfig, options: { libp2p: { - modules: { - // @ts-ignore DummyTransport is not complete implementation - transport: [DummyTransport], - // @ts-ignore DummyDiscovery is not complete implementation - peerDiscovery: [DummyDiscovery] - }, - config: { relay: { enabled: false } }, + transports: [new DummyTransport()], + peerDiscovery: [new DummyDiscovery()], + relay: { enabled: false }, addresses: { announce: [annAddr] } @@ -208,21 +205,21 @@ describe('libp2p customization', function () { expect(transports).to.have.length(1) expect(transports[0] instanceof DummyTransport).to.be.true() - const discoveries = Array.from(libp2p._discovery.values()) + const discoveries = Array.from(libp2p.discovery.values()) expect(discoveries).to.have.length(1) expect(discoveries[0] instanceof DummyDiscovery).to.be.true() - expect(libp2p.multiaddrs.map(m => m.toString())).to.include(annAddr) + expect(libp2p.getMultiaddrs().map(m => m.toString())).to.include(annAddr) }) }) - +*/ describe('config', () => { it('should be able to specify Announce addresses', async () => { const annAddr = '/dns4/test.ipfs.io/tcp/443/wss' libp2p = await libp2pComponent({ peerId, - // @ts-ignore repo is not complete implementation + // @ts-expect-error repo is not complete implementation repo: { datastore }, print: console.log, // eslint-disable-line no-console config: { @@ -236,13 +233,13 @@ describe('libp2p customization', function () { await libp2p.start() - expect(libp2p.multiaddrs.map(m => m.toString())).to.include(annAddr) + expect(libp2p.getMultiaddrs().map(m => m.toString())).to.include(annAddr) }) it('should select gossipsub as pubsub router', async () => { libp2p = await libp2pComponent({ peerId, - // @ts-ignore repo is not complete implementation + // @ts-expect-error repo is not complete implementation repo: { datastore }, print: console.log, // eslint-disable-line no-console config: { @@ -253,7 +250,7 @@ describe('libp2p customization', function () { await libp2p.start() - expect(libp2p._modules.pubsub).to.eql(gossipsub) + expect(libp2p.pubsub).to.be.an.instanceOf(GossipSub) }) }) }) diff --git a/packages/ipfs-core/test/mfs-preload.spec.js b/packages/ipfs-core/test/mfs-preload.spec.js index a89b0ff9a1..f00c17697c 100644 --- a/packages/ipfs-core/test/mfs-preload.spec.js +++ b/packages/ipfs-core/test/mfs-preload.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import delay from 'delay' import { sha256 } from 'multiformats/hashes/sha2' import { nanoid } from 'nanoid' @@ -52,7 +52,7 @@ describe('MFS preload', () => { updated: await fakeCid() } - // @ts-ignore not whole file api + // @ts-expect-error not whole file api mockFiles = { stat: createMockFilesStat([testCids.initial, testCids.same, testCids.same, testCids.updated]) } }) diff --git a/packages/ipfs-core/test/name.spec.js b/packages/ipfs-core/test/name.spec.js index e770f72e66..2554450414 100644 --- a/packages/ipfs-core/test/name.spec.js +++ b/packages/ipfs-core/test/name.spec.js @@ -1,9 +1,9 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import sinon from 'sinon' import delay from 'delay' -import PeerId from 'peer-id' +import { createEd25519PeerId } from '@libp2p/peer-id-factory' import errCode from 'err-code' import * as ipns from 'ipns' import { createRouting } from '../src/ipns/routing/config.js' @@ -109,7 +109,7 @@ describe('name', function () { // @ts-expect-error constructor needs args const publisher = new IpnsPublisher() const err = new Error('error') - const peerId = await PeerId.create() + const peerId = await createEd25519PeerId() sinon.stub(publisher, '_updateOrCreateRecord').rejects(err) @@ -134,7 +134,7 @@ describe('name', function () { } // @ts-expect-error routing is not complete implementation const publisher = new IpnsPublisher(routing, datastore) - const peerId = await PeerId.create() + const peerId = await createEd25519PeerId() // @ts-expect-error invalid argument await expect(publisher.publish(peerId.privKey, ipfsRef)) @@ -152,7 +152,7 @@ describe('name', function () { } // @ts-expect-error routing is not complete implementation const publisher = new IpnsPublisher(routing, datastore) - const peerId = await PeerId.create() + const peerId = await createEd25519PeerId() // @ts-expect-error invalid argument await expect(publisher.publish(peerId.privKey, ipfsRef)) @@ -163,9 +163,14 @@ describe('name', function () { describe('resolver', () => { it('should resolve an inlined public key', async () => { - const peerId = await PeerId.create({ keyType: 'Ed25519' }) - const value = `/ipfs/${peerId.toB58String()}` - const record = await ipns.create(peerId.privKey, uint8ArrayFromString(value), 1, 10e3) + const peerId = await createEd25519PeerId() + const value = `/ipfs/${peerId.toString()}` + + if (peerId.privateKey == null) { + throw new Error('Private key is missing') + } + + const record = await ipns.create(peerId, uint8ArrayFromString(value), 1, 10e3) const routing = { get: sinon.stub().returns(ipns.marshal(record)) @@ -173,7 +178,7 @@ describe('name', function () { // @ts-expect-error routing is not complete implementation const resolver = new IpnsResolver(routing) - const resolved = await resolver.resolve(`/ipns/${peerId.toB58String()}`) + const resolved = await resolver.resolve(`/ipns/${peerId.toString()}`) expect(resolved).to.equal(value) }) @@ -200,9 +205,9 @@ describe('name', function () { } // @ts-expect-error routing is not complete implementation const resolver = new IpnsResolver(routing) - const peerId = await PeerId.create() + const peerId = await createEd25519PeerId() - await expect(resolver.resolve(`/ipns/${peerId.toB58String()}`)) + await expect(resolver.resolve(`/ipns/${peerId.toString()}`)) .to.eventually.be.rejected() .with.property('code', 'ERR_UNEXPECTED_ERROR_GETTING_RECORD') }) @@ -213,9 +218,9 @@ describe('name', function () { } // @ts-expect-error routing is not complete implementation const resolver = new IpnsResolver(routing) - const peerId = await PeerId.create() + const peerId = await createEd25519PeerId() - await expect(resolver.resolve(`/ipns/${peerId.toB58String()}`)) + await expect(resolver.resolve(`/ipns/${peerId.toString()}`)) .to.eventually.be.rejected() .with.property('code', 'ERR_NO_RECORD_FOUND') }) @@ -226,9 +231,9 @@ describe('name', function () { } // @ts-expect-error routing is not complete implementation const resolver = new IpnsResolver(routing) - const peerId = await PeerId.create() + const peerId = await createEd25519PeerId() - await expect(resolver.resolve(`/ipns/${peerId.toB58String()}`)) + await expect(resolver.resolve(`/ipns/${peerId.toString()}`)) .to.eventually.be.rejected() .with.property('code', 'ERR_INVALID_RECORD_RECEIVED') }) @@ -268,7 +273,7 @@ describe('name', function () { }) it('should use the pubsub datastore if enabled', async () => { - const peerId = await PeerId.create() + const peerId = await createEd25519PeerId() const config = createRouting({ // @ts-expect-error sinon.stub() is not complete implementation diff --git a/packages/ipfs-core/test/preload.spec.js b/packages/ipfs-core/test/preload.spec.js index 7b68435b04..d21f847eae 100644 --- a/packages/ipfs-core/test/preload.spec.js +++ b/packages/ipfs-core/test/preload.spec.js @@ -2,7 +2,7 @@ import { nanoid } from 'nanoid' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import all from 'it-all' import { waitForCids, defaultAddr, clearPreloadCids } from './utils/mock-preload-node-utils.js' import createNode from './utils/create-node.js' diff --git a/packages/ipfs-core/test/pubsub.spec.js b/packages/ipfs-core/test/pubsub.spec.js index 8b4f298621..7d9308b86c 100644 --- a/packages/ipfs-core/test/pubsub.spec.js +++ b/packages/ipfs-core/test/pubsub.spec.js @@ -3,7 +3,7 @@ import { nanoid } from 'nanoid' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import createNode from './utils/create-node.js' describe('pubsub disabled', () => { diff --git a/packages/ipfs-core/test/utils.spec.js b/packages/ipfs-core/test/utils.spec.js index dd80f3eddf..25ddb2364b 100644 --- a/packages/ipfs-core/test/utils.spec.js +++ b/packages/ipfs-core/test/utils.spec.js @@ -1,7 +1,7 @@ /* eslint max-nested-callbacks: ["error", 8] */ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { resolvePath } from '../src/utils.js' import { createTempRepo } from './utils/create-repo.js' import { importer } from 'ipfs-unixfs-importer' diff --git a/packages/ipfs-core/test/utils/mock-preload-node.js b/packages/ipfs-core/test/utils/mock-preload-node.js index 9b563793cd..fc427675c2 100644 --- a/packages/ipfs-core/test/utils/mock-preload-node.js +++ b/packages/ipfs-core/test/utils/mock-preload-node.js @@ -15,7 +15,7 @@ export function createNode () { let cids = [] /** @type {ReturnType & { start: (opts?: any) => Promise, stop: () => Promise }} */ - // @ts-ignore start/stop props are added later + // @ts-expect-error start/stop props are added later const server = http.createServer((req, res) => { res.setHeader('Access-Control-Allow-Origin', '*') res.setHeader('Access-Control-Request-Method', '*') diff --git a/packages/ipfs-daemon/package.json b/packages/ipfs-daemon/package.json index b2163fc4d2..e5c687b69d 100644 --- a/packages/ipfs-daemon/package.json +++ b/packages/ipfs-daemon/package.json @@ -34,7 +34,7 @@ "url": "git+https://github.com/ipfs/js-ipfs.git" }, "scripts": { - "lint": "aegir ts -p check && aegir lint", + "lint": "aegir lint", "test": "aegir test -t node", "test:node": "aegir test -t node -- --exit", "clean": "rimraf ./dist", @@ -42,6 +42,7 @@ "build": "aegir build --no-bundle" }, "dependencies": { + "@libp2p/webrtc-star": "^1.0.6", "@mapbox/node-pre-gyp": "^1.0.5", "debug": "^4.1.1", "ipfs-core": "^0.14.2", @@ -50,14 +51,13 @@ "ipfs-http-gateway": "^0.9.2", "ipfs-http-server": "^0.11.2", "ipfs-utils": "^9.0.2", - "just-safe-set": "^2.2.1", - "libp2p": "^0.36.2", - "libp2p-webrtc-star": "^0.25.0" + "just-safe-set": "^4.0.2", + "libp2p": "next" }, "devDependencies": { - "aegir": "^36.0.1", - "node-fetch": "npm:@achingbrain/node-fetch@^2.6.4", - "ws": "^7.3.1" + "aegir": "^37.0.11", + "node-fetch": "^3.2.3", + "ws": "^8.5.0" }, "optionalDependencies": { "electron-webrtc": "^0.3.0", diff --git a/packages/ipfs-daemon/src/index.js b/packages/ipfs-daemon/src/index.js index fc469b881f..5ccbe80093 100644 --- a/packages/ipfs-daemon/src/index.js +++ b/packages/ipfs-daemon/src/index.js @@ -1,16 +1,14 @@ -import debug from 'debug' -import set from 'just-safe-set' -// @ts-expect-error - no types -import WebRTCStar from 'libp2p-webrtc-star' +import { logger } from '@libp2p/logger' +import { WebRTCStar } from '@libp2p/webrtc-star' import { create } from 'ipfs-core' import { HttpApi } from 'ipfs-http-server' import { HttpGateway } from 'ipfs-http-gateway' import { createServer as gRPCServer } from 'ipfs-grpc-server' import { isElectron } from 'ipfs-utils/src/env.js' import prometheusClient from 'prom-client' -import Libp2p from 'libp2p' +import { createLibp2p } from 'libp2p' -const log = debug('ipfs:daemon') +const log = logger('ipfs:daemon') export class Daemon { /** @@ -98,9 +96,14 @@ async function getLibp2p ({ libp2pOptions }) { if (wrtc || electronWebRTC) { log(`Using ${wrtc ? 'wrtc' : 'electron-webrtc'} for webrtc support`) - set(libp2pOptions, 'config.transport.WebRTCStar.wrtc', wrtc || electronWebRTC) - libp2pOptions.modules.transport.push(WebRTCStar) + + const transport = new WebRTCStar({ + wrtc: wrtc ?? electronWebRTC + }) + + libp2pOptions.transports = [...libp2pOptions.transports ?? [], transport] + libp2pOptions.peerDiscovery = [...libp2pOptions.peerDiscovery ?? [], transport.discovery] } - return Libp2p.create(libp2pOptions) + return createLibp2p(libp2pOptions) } diff --git a/packages/ipfs-daemon/test/index.spec.js b/packages/ipfs-daemon/test/index.spec.js index 07acaa8964..9325825ab1 100644 --- a/packages/ipfs-daemon/test/index.spec.js +++ b/packages/ipfs-daemon/test/index.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { Daemon } from '../src/index.js' import fetch from 'node-fetch' import WebSocket from 'ws' diff --git a/packages/ipfs-grpc-client/.aegir.cjs b/packages/ipfs-grpc-client/.aegir.js similarity index 73% rename from packages/ipfs-grpc-client/.aegir.cjs rename to packages/ipfs-grpc-client/.aegir.js index f205b27e57..347641bbbf 100644 --- a/packages/ipfs-grpc-client/.aegir.cjs +++ b/packages/ipfs-grpc-client/.aegir.js @@ -1,7 +1,6 @@ -'use strict' /** @type {import('aegir').PartialOptions} */ -module.exports = { +export default { build: { bundlesizeMax: '53KB' } diff --git a/packages/ipfs-grpc-client/package.json b/packages/ipfs-grpc-client/package.json index 0884c51aa7..7267f09b3a 100644 --- a/packages/ipfs-grpc-client/package.json +++ b/packages/ipfs-grpc-client/package.json @@ -47,12 +47,12 @@ "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", "test:electron-main": "aegir build --esm-tests && aegir test -t electron-main -f ./dist/cjs/node-test/*.spec.js", "test:electron-renderer": "aegir build --esm-tests && aegir test -t electron-renderer -f ./dist/cjs/browser-test/*.spec.js", - "lint": "aegir ts -p check && aegir lint", + "lint": "aegir lint", "clean": "rimraf ./dist", "dep-check": "aegir dep-check -i aegir -i rimraf -i ipfs-grpc-protocol -i ipfs-core-types" }, "dependencies": { - "@improbable-eng/grpc-web": "^0.14.0", + "@improbable-eng/grpc-web": "^0.15.0", "change-case": "^4.1.1", "debug": "^4.1.1", "err-code": "^3.0.1", @@ -61,18 +61,18 @@ "ipfs-grpc-protocol": "^0.5.5", "ipfs-unixfs": "^6.0.3", "it-first": "^1.0.4", - "it-pushable": "^1.4.2", - "multiaddr": "^10.0.0", + "it-pushable": "^2.0.1", + "@multiformats/multiaddr": "^10.0.0", "multiformats": "^9.5.1", - "p-defer": "^3.0.0", + "p-defer": "^4.0.0", "protobufjs": "^6.10.2", "wherearewe": "^1.0.0", - "ws": "^7.3.1" + "ws": "^8.5.0" }, "devDependencies": { - "aegir": "^36.0.1", + "aegir": "^37.0.11", "it-all": "^1.0.4", "rimraf": "^3.0.2", - "sinon": "^12.0.01" + "sinon": "^13.0.1" } } diff --git a/packages/ipfs-grpc-client/src/core-api/id.js b/packages/ipfs-grpc-client/src/core-api/id.js index a5446c80b6..139c4a574d 100644 --- a/packages/ipfs-grpc-client/src/core-api/id.js +++ b/packages/ipfs-grpc-client/src/core-api/id.js @@ -1,7 +1,7 @@ import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' import { toHeaders } from '../utils/to-headers.js' import { unaryToPromise } from '../utils/unary-to-promise.js' -import { Multiaddr } from 'multiaddr' +import { Multiaddr } from '@multiformats/multiaddr' /** * @param {import('@improbable-eng/grpc-web').grpc} grpc diff --git a/packages/ipfs-grpc-client/src/core-api/pubsub/subscribe.js b/packages/ipfs-grpc-client/src/core-api/pubsub/subscribe.js index a8c36acad6..4f24a7d6e8 100644 --- a/packages/ipfs-grpc-client/src/core-api/pubsub/subscribe.js +++ b/packages/ipfs-grpc-client/src/core-api/pubsub/subscribe.js @@ -34,12 +34,22 @@ export function grpcPubsubSubscribe (grpc, service, opts) { deferred.resolve() } else { - handler({ + /** @type {import('@libp2p/interfaces/pubsub').Message} */ + const msg = { from: result.from, - seqno: result.seqno, + sequenceNumber: result.sequenceNumber, data: result.data, - topicIDs: result.topicIDs - }) + topic: result.topic + } + + if (typeof handler === 'function') { + handler(msg) + continue + } + + if (handler != null && typeof handler.handleEvent === 'function') { + handler.handleEvent(msg) + } } } } catch (/** @type {any} */ err) { diff --git a/packages/ipfs-grpc-client/src/core-api/pubsub/subscriptions.js b/packages/ipfs-grpc-client/src/core-api/pubsub/subscriptions.js index 86f62d6ca9..7406f50d44 100644 --- a/packages/ipfs-grpc-client/src/core-api/pubsub/subscriptions.js +++ b/packages/ipfs-grpc-client/src/core-api/pubsub/subscriptions.js @@ -1,6 +1,7 @@ /** - * @typedef {import('ipfs-core-types/src/pubsub').MessageHandlerFn} Subscription + * @typedef {import('@libp2p/interfaces/pubsub').Message} Message + * @typedef {import('@libp2p/interfaces/events').EventHandler} Subscription */ /** @type {Map>} */ diff --git a/packages/ipfs-grpc-client/src/grpc/transport.node.js b/packages/ipfs-grpc-client/src/grpc/transport.node.js index d4b03e4577..76cae5fa32 100644 --- a/packages/ipfs-grpc-client/src/grpc/transport.node.js +++ b/packages/ipfs-grpc-client/src/grpc/transport.node.js @@ -2,9 +2,9 @@ // but uses the ws implementation of WebSockets // see: https://github.com/improbable-eng/grpc-web/issues/796 import WebSocket from 'ws' -import debug from 'debug' +import { logger } from '@libp2p/logger' -const log = debug('ipfs:grpc-client:websocket-transport') +const log = logger('ipfs:grpc-client:websocket-transport') /** * @typedef {import('http').Agent} HttpAgent diff --git a/packages/ipfs-grpc-client/src/index.js b/packages/ipfs-grpc-client/src/index.js index 48eea10903..6cf2176008 100644 --- a/packages/ipfs-grpc-client/src/index.js +++ b/packages/ipfs-grpc-client/src/index.js @@ -44,20 +44,14 @@ export function create (opts = { url: '' }) { normaliseUrls(options) const client = { - // @ts-ignore - TODO: fix after https://github.com/ipfs/js-ipfs/issues/3594 addAll: grpcAddAll(grpcWeb.grpc, service.Root.add, options), - // @ts-ignore - TODO: fix after https://github.com/ipfs/js-ipfs/issues/3594 id: grpcId(grpcWeb.grpc, service.Root.id, options), files: { - // @ts-ignore - TODO: fix after https://github.com/ipfs/js-ipfs/issues/3594 ls: grpcMfsLs(grpcWeb.grpc, service.MFS.ls, options), - // @ts-ignore - TODO: fix after https://github.com/ipfs/js-ipfs/issues/3594 write: grpcMfsWrite(grpcWeb.grpc, service.MFS.write, options) }, pubsub: { - // @ts-ignore - TODO: fix after https://github.com/ipfs/js-ipfs/issues/3594 subscribe: grpcPubsubSubscribe(grpcWeb.grpc, service.PubSub.subscribe, options), - // @ts-ignore - TODO: fix after https://github.com/ipfs/js-ipfs/issues/3594 unsubscribe: grpcPubsubUnsubscribe(grpcWeb.grpc, service.PubSub.unsubscribe, options) } } diff --git a/packages/ipfs-grpc-client/src/types.ts b/packages/ipfs-grpc-client/src/types.ts index 54148ea7c8..44828bdd08 100644 --- a/packages/ipfs-grpc-client/src/types.ts +++ b/packages/ipfs-grpc-client/src/types.ts @@ -1,6 +1,6 @@ import type { Agent as HttpAgent } from 'http' import type { Agent as HttpsAgent } from 'https' -import type { Multiaddr } from 'multiaddr' +import type { Multiaddr } from '@multiformats/multiaddr' export interface Options { url: string | URL | Multiaddr diff --git a/packages/ipfs-grpc-client/src/utils/bidi-to-duplex.js b/packages/ipfs-grpc-client/src/utils/bidi-to-duplex.js index c87e98bc0d..22e4129695 100644 --- a/packages/ipfs-grpc-client/src/utils/bidi-to-duplex.js +++ b/packages/ipfs-grpc-client/src/utils/bidi-to-duplex.js @@ -1,4 +1,4 @@ -import pushable from 'it-pushable' +import { pushable } from 'it-pushable' import errCode from 'err-code' import { toUrlString } from 'ipfs-core-utils/to-url-string' import { toHeaders } from './to-headers.js' diff --git a/packages/ipfs-grpc-client/src/utils/load-services.js b/packages/ipfs-grpc-client/src/utils/load-services.js index eb9c7a18df..9dbfc7b34d 100644 --- a/packages/ipfs-grpc-client/src/utils/load-services.js +++ b/packages/ipfs-grpc-client/src/utils/load-services.js @@ -1,5 +1,4 @@ -// @ts-ignore import protocol from 'ipfs-grpc-protocol' import protobuf from 'protobufjs/light.js' @@ -19,17 +18,17 @@ const CONVERSION_OPTS = { * service definition on both the server and the client. */ export function loadServices () { - // @ts-ignore - recent protobufjs release changed the types + // @ts-expect-error - recent protobufjs release changed the types const root = protobuf.Root.fromJSON(protocol) /** @type {Record} */ const output = {} Object - // @ts-ignore + // @ts-expect-error .keys(root.nested.ipfs) - // @ts-ignore + // @ts-expect-error .filter(key => root.nested.ipfs[key] instanceof Service) - // @ts-ignore + // @ts-expect-error .map(key => root.nested.ipfs[key]) .forEach(service => { /** @type {Record} */ diff --git a/packages/ipfs-grpc-client/test/utils.spec.js b/packages/ipfs-grpc-client/test/utils.spec.js index 82b710adfa..e1a0190c8c 100644 --- a/packages/ipfs-grpc-client/test/utils.spec.js +++ b/packages/ipfs-grpc-client/test/utils.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import all from 'it-all' import sinon from 'sinon' import { bidiToDuplex } from '../src/utils/bidi-to-duplex.js' diff --git a/packages/ipfs-grpc-protocol/package.json b/packages/ipfs-grpc-protocol/package.json index c0aaae26db..7fedf25ca5 100644 --- a/packages/ipfs-grpc-protocol/package.json +++ b/packages/ipfs-grpc-protocol/package.json @@ -36,10 +36,10 @@ "scripts": { "clean": "rimraf ./dist", "build": "npm run clean && mkdirp ./dist && pbjs ./src/*.proto -t json -o ./dist/ipfs.json && node ./scripts/update-index.js && npm run lint -- --fix && aegir build", - "lint": "aegir ts -p check && aegir lint" + "lint": "aegir lint" }, "devDependencies": { - "aegir": "^36.0.1", + "aegir": "^37.0.11", "mkdirp": "^1.0.4", "protobufjs": "^6.10.2", "rimraf": "^3.0.2" diff --git a/packages/ipfs-grpc-protocol/src/index.js b/packages/ipfs-grpc-protocol/src/index.js index 1ba60f8e4b..1886e5932c 100644 --- a/packages/ipfs-grpc-protocol/src/index.js +++ b/packages/ipfs-grpc-protocol/src/index.js @@ -109,7 +109,7 @@ export default { type: 'string', id: 2 }, - seqno: { + sequenceNumber: { type: 'bytes', id: 3 }, @@ -117,8 +117,7 @@ export default { type: 'bytes', id: 4 }, - topicIDs: { - rule: 'repeated', + topic: { type: 'string', id: 5 } diff --git a/packages/ipfs-grpc-protocol/src/pubsub.proto b/packages/ipfs-grpc-protocol/src/pubsub.proto index fd717c1c2a..438189ae63 100644 --- a/packages/ipfs-grpc-protocol/src/pubsub.proto +++ b/packages/ipfs-grpc-protocol/src/pubsub.proto @@ -16,9 +16,9 @@ message SubscribeRequest { message SubscribeResponse { string handler = 1; string from = 2; - bytes seqno = 3; + bytes sequenceNumber = 3; bytes data = 4; - repeated string topicIDs = 5; + string topic = 5; } message UnSubscribeRequest { diff --git a/packages/ipfs-grpc-server/package.json b/packages/ipfs-grpc-server/package.json index 79e71f6795..3285fe68e9 100644 --- a/packages/ipfs-grpc-server/package.json +++ b/packages/ipfs-grpc-server/package.json @@ -34,7 +34,7 @@ "url": "git+https://github.com/ipfs/js-ipfs.git" }, "scripts": { - "lint": "aegir ts -p check && aegir lint", + "lint": "aegir lint", "test": "aegir test -t node", "test:node": "aegir test -t node --cov", "clean": "rimraf ./dist", @@ -51,21 +51,21 @@ "it-first": "^1.0.4", "it-map": "^1.0.4", "it-peekable": "^1.0.2", - "it-pipe": "^1.1.0", - "it-pushable": "^1.4.2", - "multiaddr": "^10.0.0", + "it-pipe": "^2.0.3", + "it-pushable": "^2.0.1", + "@multiformats/multiaddr": "^10.0.0", "nanoid": "^3.1.23", "protobufjs": "^6.10.2", - "ws": "^7.3.1" + "ws": "^8.5.0" }, "devDependencies": { - "@types/ws": "^7.4.0", - "aegir": "^36.0.1", + "@types/ws": "^8.5.3", + "aegir": "^37.0.11", "ipfs-core": "^0.14.2", "it-all": "^1.0.4", "it-drain": "^1.0.3", "rimraf": "^3.0.2", - "sinon": "^12.0.01", + "sinon": "^13.0.1", "uint8arrays": "^3.0.0" } } diff --git a/packages/ipfs-grpc-server/src/endpoints/add.js b/packages/ipfs-grpc-server/src/endpoints/add.js index cb2e8fe497..cfbc72e61b 100644 --- a/packages/ipfs-grpc-server/src/endpoints/add.js +++ b/packages/ipfs-grpc-server/src/endpoints/add.js @@ -1,4 +1,4 @@ -import pushable from 'it-pushable' +import { pushable } from 'it-pushable' import { pipe } from 'it-pipe' import { encodeMtime } from '../utils/encode-mtime.js' diff --git a/packages/ipfs-grpc-server/src/endpoints/pubsub/subscribe.js b/packages/ipfs-grpc-server/src/endpoints/pubsub/subscribe.js index 0d6c69749d..521c2244e9 100644 --- a/packages/ipfs-grpc-server/src/endpoints/pubsub/subscribe.js +++ b/packages/ipfs-grpc-server/src/endpoints/pubsub/subscribe.js @@ -1,6 +1,10 @@ import { subscriptions } from './subscriptions.js' import { nanoid } from 'nanoid' +/** + * @typedef {import('@libp2p/interfaces/pubsub').Message} Message + */ + /** * @param {import('ipfs-core-types').IPFS} ipfs * @param {import('../../types').Options} options @@ -18,7 +22,7 @@ export function grpcPubsubSubscribe (ipfs, options = {}) { const handlerId = nanoid() const handler = { - /** @type {import('ipfs-core-types/src/pubsub').MessageHandlerFn} */ + /** @type {import('@libp2p/interfaces/events').EventHandler} */ onMessage: (message) => { sink.push(message) }, diff --git a/packages/ipfs-grpc-server/src/endpoints/pubsub/subscriptions.js b/packages/ipfs-grpc-server/src/endpoints/pubsub/subscriptions.js index 946fe6a8db..3b2a2a9559 100644 --- a/packages/ipfs-grpc-server/src/endpoints/pubsub/subscriptions.js +++ b/packages/ipfs-grpc-server/src/endpoints/pubsub/subscriptions.js @@ -1,7 +1,7 @@ - /** + * @typedef {import('@libp2p/interfaces/pubsub').Message} Message * @typedef {object} Subscription - * @property {import('ipfs-core-types/src/pubsub').MessageHandlerFn} onMessage + * @property {import('@libp2p/interfaces/events').EventHandler} onMessage * @property {() => void} onUnsubscribe */ diff --git a/packages/ipfs-grpc-server/src/index.js b/packages/ipfs-grpc-server/src/index.js index 25c09b04e3..ebfad06917 100644 --- a/packages/ipfs-grpc-server/src/index.js +++ b/packages/ipfs-grpc-server/src/index.js @@ -1,6 +1,6 @@ import grpc from '@grpc/grpc-js' import first from 'it-first' -import debug from 'debug' +import { logger } from '@libp2p/logger' import { webSocketServer } from './utils/web-socket-server.js' import { loadServices } from './utils/load-services.js' import { grpcAdd } from './endpoints/add.js' @@ -10,7 +10,7 @@ import { grpcMfsWrite } from './endpoints/mfs/write.js' import { grpcPubsubSubscribe } from './endpoints/pubsub/subscribe.js' import { grpcPubsubUnsubscribe } from './endpoints/pubsub/unsubscribe.js' -const log = debug('ipfs:grpc-server') +const log = logger('ipfs:grpc-server') const { Root, @@ -27,21 +27,21 @@ export async function createServer (ipfs, options = {}) { const server = new grpc.Server() server.addService(Root, { - // @ts-ignore - types differ because we only invoke via websockets - https://github.com/ipfs/js-ipfs/issues/3594 + // @ts-expect-error - types differ because we only invoke via websockets - https://github.com/ipfs/js-ipfs/issues/3594 add: grpcAdd(ipfs, options), - // @ts-ignore - types differ because we only invoke via websockets - https://github.com/ipfs/js-ipfs/issues/3594 + // @ts-expect-error - types differ because we only invoke via websockets - https://github.com/ipfs/js-ipfs/issues/3594 id: grpcId(ipfs, options) }) server.addService(MFS, { - // @ts-ignore - types differ because we only invoke via websockets - https://github.com/ipfs/js-ipfs/issues/3594 + // @ts-expect-error - types differ because we only invoke via websockets - https://github.com/ipfs/js-ipfs/issues/3594 ls: grpcMfsLs(ipfs, options), - // @ts-ignore - types differ because we only invoke via websockets - https://github.com/ipfs/js-ipfs/issues/3594 + // @ts-expect-error - types differ because we only invoke via websockets - https://github.com/ipfs/js-ipfs/issues/3594 write: grpcMfsWrite(ipfs, options) }) server.addService(PubSub, { - // @ts-ignore - types differ because we only invoke via websockets - https://github.com/ipfs/js-ipfs/issues/3594 + // @ts-expect-error - types differ because we only invoke via websockets - https://github.com/ipfs/js-ipfs/issues/3594 subscribe: grpcPubsubSubscribe(ipfs, options), - // @ts-ignore - types differ because we only invoke via websockets - https://github.com/ipfs/js-ipfs/issues/3594 + // @ts-expect-error - types differ because we only invoke via websockets - https://github.com/ipfs/js-ipfs/issues/3594 unsubscribe: grpcPubsubUnsubscribe(ipfs, options) }) @@ -50,7 +50,7 @@ export async function createServer (ipfs, options = {}) { socket.on('error', (error) => log(error)) socket.on('data', async ({ path, metadata, channel }) => { - // @ts-ignore - types differ because we only invoke via websockets - https://github.com/ipfs/js-ipfs/issues/3594 + // @ts-expect-error - types differ because we only invoke via websockets - https://github.com/ipfs/js-ipfs/issues/3594 const handler = server.handlers.get(path) if (!handler) { @@ -63,7 +63,7 @@ export async function createServer (ipfs, options = {}) { switch (handler.type) { case 'bidi': handler.func(channel.source, channel.sink, metadata) - // @ts-ignore - TODO: fix after https://github.com/ipfs/js-ipfs/issues/3594 + // @ts-expect-error - TODO: fix after https://github.com/ipfs/js-ipfs/issues/3594 .catch(err => { channel.end(err) }) @@ -78,7 +78,7 @@ export async function createServer (ipfs, options = {}) { break case 'unary': - // @ts-ignore - TODO: fix after https://github.com/ipfs/js-ipfs/issues/3594 + // @ts-expect-error - TODO: fix after https://github.com/ipfs/js-ipfs/issues/3594 handler.func(await first(channel.source), metadata, (err, value, metadata, flags) => { if (err) { return channel.end(err) @@ -94,7 +94,7 @@ export async function createServer (ipfs, options = {}) { }) break case 'clientStream': - // @ts-ignore - TODO: fix after https://github.com/ipfs/js-ipfs/issues/3594 + // @ts-expect-error - TODO: fix after https://github.com/ipfs/js-ipfs/issues/3594 handler.func(channel.source, metadata, (err, value, metadata, flags) => { if (err) { return channel.end(err) @@ -110,10 +110,8 @@ export async function createServer (ipfs, options = {}) { }) break case 'serverStream': - // @ts-ignore - TODO: fix after https://github.com/ipfs/js-ipfs/issues/3594 handler.func(await first(channel.source), channel.sink, metadata) - // @ts-ignore - TODO: fix after https://github.com/ipfs/js-ipfs/issues/3594 - .catch(err => { + .catch((/** @type {any} **/ err) => { channel.end(err) }) diff --git a/packages/ipfs-grpc-server/src/types.ts b/packages/ipfs-grpc-server/src/types.ts index e0a48a2b19..23e3b099c7 100644 --- a/packages/ipfs-grpc-server/src/types.ts +++ b/packages/ipfs-grpc-server/src/types.ts @@ -1,6 +1,6 @@ import type { Pushable } from 'it-pushable' import type { EventEmitter } from 'events' -import type { Multiaddr } from 'multiaddr' +import type { Multiaddr } from '@multiformats/multiaddr' export interface Options { socket?: WebsocketServer diff --git a/packages/ipfs-grpc-server/src/utils/load-services.js b/packages/ipfs-grpc-server/src/utils/load-services.js index 3831394f28..db2cae2837 100644 --- a/packages/ipfs-grpc-server/src/utils/load-services.js +++ b/packages/ipfs-grpc-server/src/utils/load-services.js @@ -12,18 +12,18 @@ const CONVERSION_OPTS = { } export function loadServices () { - // @ts-ignore - recent protobufjs release changed the types + // @ts-expect-error - recent protobufjs release changed the types const root = protobuf.Root.fromJSON(protocol) /** @type {Record} */ const output = {} Object - // @ts-ignore + // @ts-expect-error .keys(root.nested.ipfs) - // @ts-ignore + // @ts-expect-error .filter(key => root.nested.ipfs[key] instanceof Service) - // @ts-ignore + // @ts-expect-error .map(key => root.nested.ipfs[key]) .forEach(service => { /** @type {Record} */ diff --git a/packages/ipfs-grpc-server/src/utils/web-socket-message-channel.js b/packages/ipfs-grpc-server/src/utils/web-socket-message-channel.js index 97de8cb95f..d2ca764e96 100644 --- a/packages/ipfs-grpc-server/src/utils/web-socket-message-channel.js +++ b/packages/ipfs-grpc-server/src/utils/web-socket-message-channel.js @@ -1,4 +1,4 @@ -import pushable from 'it-pushable' +import { pushable } from 'it-pushable' import { paramCase } from 'change-case' const WebsocketSignal = { diff --git a/packages/ipfs-grpc-server/src/utils/web-socket-server.js b/packages/ipfs-grpc-server/src/utils/web-socket-server.js index 16533a30d4..6d475117ce 100644 --- a/packages/ipfs-grpc-server/src/utils/web-socket-server.js +++ b/packages/ipfs-grpc-server/src/utils/web-socket-server.js @@ -1,13 +1,13 @@ -import WS from 'ws' +import { WebSocketServer } from 'ws' import { EventEmitter } from 'events' import { WebSocketMessageChannel } from './web-socket-message-channel.js' -import debug from 'debug' +import { logger } from '@libp2p/logger' // @ts-expect-error - no types import coerce from 'coercer' import { camelCase } from 'change-case' -import { Multiaddr } from 'multiaddr' +import { Multiaddr } from '@multiformats/multiaddr' -const log = debug('ipfs:grpc-server:utils:web-socket-server') +const log = logger('ipfs:grpc-server:utils:web-socket-server') /** * @param {import('ws').Data} buf - e.g. `Buffer.from('foo-bar: baz\r\n')` @@ -31,7 +31,7 @@ const fromHeaders = (buf) => { class Messages extends EventEmitter { /** - * @param {WS.Server} wss + * @param {WebSocketServer} wss */ constructor (wss) { super() @@ -119,7 +119,7 @@ export async function webSocketServer (ipfs, options = {}) { log(`starting ws server on ${host}:${port}`) - const wss = new WS.Server({ + const wss = new WebSocketServer({ host, port: parseInt(port, 10) }) diff --git a/packages/ipfs-grpc-server/test/add.spec.js b/packages/ipfs-grpc-server/test/add.spec.js index f8e279d163..adf98df491 100644 --- a/packages/ipfs-grpc-server/test/add.spec.js +++ b/packages/ipfs-grpc-server/test/add.spec.js @@ -2,7 +2,7 @@ import sinon from 'sinon' import { server } from './utils/server.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import all from 'it-all' import drain from 'it-drain' diff --git a/packages/ipfs-grpc-server/test/id.spec.js b/packages/ipfs-grpc-server/test/id.spec.js index 1740dd99a7..a691e5a9d8 100644 --- a/packages/ipfs-grpc-server/test/id.spec.js +++ b/packages/ipfs-grpc-server/test/id.spec.js @@ -2,7 +2,7 @@ import sinon from 'sinon' import { server } from './utils/server.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import all from 'it-all' import drain from 'it-drain' diff --git a/packages/ipfs-grpc-server/test/mfs/ls.spec.js b/packages/ipfs-grpc-server/test/mfs/ls.spec.js index e192a83cf8..f04a9a786f 100644 --- a/packages/ipfs-grpc-server/test/mfs/ls.spec.js +++ b/packages/ipfs-grpc-server/test/mfs/ls.spec.js @@ -2,7 +2,7 @@ import sinon from 'sinon' import { server } from '../utils/server.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import all from 'it-all' import drain from 'it-drain' diff --git a/packages/ipfs-grpc-server/test/mfs/write.spec.js b/packages/ipfs-grpc-server/test/mfs/write.spec.js index d638044580..faf20736fe 100644 --- a/packages/ipfs-grpc-server/test/mfs/write.spec.js +++ b/packages/ipfs-grpc-server/test/mfs/write.spec.js @@ -2,7 +2,7 @@ import sinon from 'sinon' import { server } from '../utils/server.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import drain from 'it-drain' describe('MFS.write', () => { diff --git a/packages/ipfs-grpc-server/test/utils/channel.js b/packages/ipfs-grpc-server/test/utils/channel.js index 5ec10e8a32..95463b2006 100644 --- a/packages/ipfs-grpc-server/test/utils/channel.js +++ b/packages/ipfs-grpc-server/test/utils/channel.js @@ -1,5 +1,5 @@ -import pushable from 'it-pushable' +import { pushable } from 'it-pushable' class MessageChannel { constructor () { diff --git a/packages/ipfs-http-client/.aegir.cjs b/packages/ipfs-http-client/.aegir.js similarity index 77% rename from packages/ipfs-http-client/.aegir.cjs rename to packages/ipfs-http-client/.aegir.js index 352ef70c2f..d2fdbb42db 100644 --- a/packages/ipfs-http-client/.aegir.cjs +++ b/packages/ipfs-http-client/.aegir.js @@ -1,10 +1,8 @@ -'use strict' - -const { createServer } = require('ipfsd-ctl') -const getPort = require('aegir/utils/get-port') +import { createServer } from 'ipfsd-ctl' +import getPort from 'aegir/get-port' /** @type {import('aegir').PartialOptions} */ -module.exports = { +export default { build: { bundlesizeMax: '66KB' }, @@ -17,7 +15,7 @@ module.exports = { }, { type: 'go', ipfsHttpModule: await import('./src/index.js'), - ipfsBin: require('go-ipfs').path() + ipfsBin: (await import('go-ipfs')).default.path() }) await server.start() diff --git a/packages/ipfs-http-client/package.json b/packages/ipfs-http-client/package.json index c922bf02aa..fc2286014b 100644 --- a/packages/ipfs-http-client/package.json +++ b/packages/ipfs-http-client/package.json @@ -49,7 +49,7 @@ "test:firefox": "aegir test -t browser -- --browser firefox", "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", "test:electron-renderer": "aegir build --esm-tests && aegir test -t electron-renderer -f ./dist/cjs/browser-test/*.spec.js", - "lint": "aegir ts -p check && aegir lint", + "lint": "aegir lint", "clean": "rimraf ./dist", "dep-check": "aegir dep-check -i ipfs-core -i rimraf -i ipfs-core-types" }, @@ -67,21 +67,21 @@ "it-first": "^1.0.6", "it-last": "^1.0.4", "merge-options": "^3.0.4", - "multiaddr": "^10.0.0", + "@multiformats/multiaddr": "^10.0.0", "multiformats": "^9.5.1", "parse-duration": "^1.0.0", "stream-to-it": "^0.2.2", "uint8arrays": "^3.0.0" }, "devDependencies": { - "aegir": "^36.0.1", + "aegir": "^37.0.11", "delay": "^5.0.0", - "go-ipfs": "0.11.0", + "go-ipfs": "^0.12.1", "ipfsd-ctl": "^10.0.4", "it-all": "^1.0.4", "it-first": "^1.0.4", "nock": "^13.0.2", - "p-defer": "^3.0.0", + "p-defer": "^4.0.0", "rimraf": "^3.0.2" }, "engines": { diff --git a/packages/ipfs-http-client/src/add-all.js b/packages/ipfs-http-client/src/add-all.js index 3c40b20c5f..bb48bdcc66 100644 --- a/packages/ipfs-http-client/src/add-all.js +++ b/packages/ipfs-http-client/src/add-all.js @@ -30,7 +30,6 @@ export const createAddAll = configure((api) => { // `{ total, loaded}` passed to `onUploadProgress` and `multipart.total` // in which case we disable progress updates to be written out. const [progressFn, onUploadProgress] = typeof options.progress === 'function' - // @ts-ignore tsc picks up the node codepath ? createProgressHandler(total, parts, options.progress) : [undefined, undefined] diff --git a/packages/ipfs-http-client/src/add.js b/packages/ipfs-http-client/src/add.js index 979fc9a35d..3ae7497ff8 100644 --- a/packages/ipfs-http-client/src/add.js +++ b/packages/ipfs-http-client/src/add.js @@ -18,7 +18,7 @@ export function createAdd (options) { * @type {RootAPI["add"]} */ async function add (input, options = {}) { - // @ts-ignore - last may return undefined if source is empty + // @ts-expect-error - last may return undefined if source is empty return await last(all(normaliseInput(input), options)) } return add diff --git a/packages/ipfs-http-client/src/bootstrap/add.js b/packages/ipfs-http-client/src/bootstrap/add.js index 168e74af70..7c07e48d35 100644 --- a/packages/ipfs-http-client/src/bootstrap/add.js +++ b/packages/ipfs-http-client/src/bootstrap/add.js @@ -1,6 +1,6 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -import { Multiaddr } from 'multiaddr' +import { Multiaddr } from '@multiformats/multiaddr' /** * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions diff --git a/packages/ipfs-http-client/src/bootstrap/clear.js b/packages/ipfs-http-client/src/bootstrap/clear.js index 425d66be3f..e029343caf 100644 --- a/packages/ipfs-http-client/src/bootstrap/clear.js +++ b/packages/ipfs-http-client/src/bootstrap/clear.js @@ -1,6 +1,6 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -import { Multiaddr } from 'multiaddr' +import { Multiaddr } from '@multiformats/multiaddr' /** * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions diff --git a/packages/ipfs-http-client/src/bootstrap/list.js b/packages/ipfs-http-client/src/bootstrap/list.js index 7913370dcb..79be9211f5 100644 --- a/packages/ipfs-http-client/src/bootstrap/list.js +++ b/packages/ipfs-http-client/src/bootstrap/list.js @@ -1,6 +1,6 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -import { Multiaddr } from 'multiaddr' +import { Multiaddr } from '@multiformats/multiaddr' /** * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions diff --git a/packages/ipfs-http-client/src/bootstrap/reset.js b/packages/ipfs-http-client/src/bootstrap/reset.js index 3f70473f1f..30ac170330 100644 --- a/packages/ipfs-http-client/src/bootstrap/reset.js +++ b/packages/ipfs-http-client/src/bootstrap/reset.js @@ -1,6 +1,6 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -import { Multiaddr } from 'multiaddr' +import { Multiaddr } from '@multiformats/multiaddr' /** * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions diff --git a/packages/ipfs-http-client/src/bootstrap/rm.js b/packages/ipfs-http-client/src/bootstrap/rm.js index 8073232919..d84b23d3dd 100644 --- a/packages/ipfs-http-client/src/bootstrap/rm.js +++ b/packages/ipfs-http-client/src/bootstrap/rm.js @@ -1,6 +1,6 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -import { Multiaddr } from 'multiaddr' +import { Multiaddr } from '@multiformats/multiaddr' /** * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions diff --git a/packages/ipfs-http-client/src/dag/get.js b/packages/ipfs-http-client/src/dag/get.js index 6d2def0b05..5a4026bbb3 100644 --- a/packages/ipfs-http-client/src/dag/get.js +++ b/packages/ipfs-http-client/src/dag/get.js @@ -26,7 +26,7 @@ export const createGet = (codecs, options) => { const entry = options.localResolve ? await first(resolve(cid, options.path, codecs, getBlock, options)) : await last(resolve(cid, options.path, codecs, getBlock, options)) - /** @type {import('ipfs-core-types/src/dag').GetResult} - first and last will return undefined when empty */ + /** @type {import('ipfs-core-types/src/dag').GetResult | undefined} - first and last will return undefined when empty */ const result = (entry) if (!result) { diff --git a/packages/ipfs-http-client/src/dht/map-event.js b/packages/ipfs-http-client/src/dht/map-event.js index af641d0421..1505f448d9 100644 --- a/packages/ipfs-http-client/src/dht/map-event.js +++ b/packages/ipfs-http-client/src/dht/map-event.js @@ -9,34 +9,39 @@ import { AddingPeer, DialingPeer } from './response-types.js' -import { Multiaddr } from 'multiaddr' +import { Multiaddr } from '@multiformats/multiaddr' +import { peerIdFromString } from '@libp2p/peer-id' + +/** + * @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId + */ /** * @param {{Type: number, ID: string, Extra: string, Responses: {ID: string, Addrs: string[]}[]}} event - * @returns {import('ipfs-core-types/src/dht').QueryEvent} + * @returns {import('@libp2p/interfaces/dht').QueryEvent} */ export const mapEvent = (event) => { - // console.info(JSON.stringify(event, null, 2)) - if (event.Type === SendingQuery) { return { - to: event.ID, + to: peerIdFromString(event.ID), name: 'SENDING_QUERY', - type: event.Type + type: event.Type, + messageName: 'PUT_VALUE', + messageType: 0 } } if (event.Type === PeerResponse) { return { - from: event.ID, + from: peerIdFromString(event.ID), name: 'PEER_RESPONSE', type: event.Type, // TODO: how to infer this from the go-ipfs response messageType: 0, // TODO: how to infer this from the go-ipfs response messageName: 'PUT_VALUE', - closer: (event.Responses || []).map(({ ID, Addrs }) => ({ id: ID, multiaddrs: Addrs.map(addr => new Multiaddr(addr)) })), - providers: (event.Responses || []).map(({ ID, Addrs }) => ({ id: ID, multiaddrs: Addrs.map(addr => new Multiaddr(addr)) })) + closer: (event.Responses || []).map(({ ID, Addrs }) => ({ id: peerIdFromString(ID), multiaddrs: Addrs.map(addr => new Multiaddr(addr)), protocols: [] })), + providers: (event.Responses || []).map(({ ID, Addrs }) => ({ id: peerIdFromString(ID), multiaddrs: Addrs.map(addr => new Multiaddr(addr)), protocols: [] })) // TODO: how to infer this from the go-ipfs response // record: ??? } @@ -45,21 +50,23 @@ export const mapEvent = (event) => { if (event.Type === FinalPeer) { // dht.query ends with a FinalPeer event with no Responses let peer = { - id: event.ID, + id: peerIdFromString(event.ID), /** @type {Multiaddr[]} */ - multiaddrs: [] + multiaddrs: [], + protocols: [] } if (event.Responses && event.Responses.length) { // dht.findPeer has the result in the Responses field peer = { - id: event.Responses[0].ID, - multiaddrs: event.Responses[0].Addrs.map(addr => new Multiaddr(addr)) + id: peerIdFromString(event.Responses[0].ID), + multiaddrs: event.Responses[0].Addrs.map(addr => new Multiaddr(addr)), + protocols: [] } } return { - from: event.ID, + from: peerIdFromString(event.ID), name: 'FINAL_PEER', type: event.Type, peer @@ -68,7 +75,7 @@ export const mapEvent = (event) => { if (event.Type === QueryError) { return { - from: event.ID, + from: peerIdFromString(event.ID), name: 'QUERY_ERROR', type: event.Type, error: new Error(event.Extra) @@ -77,16 +84,16 @@ export const mapEvent = (event) => { if (event.Type === Provider) { return { - from: event.ID, + from: peerIdFromString(event.ID), name: 'PROVIDER', type: event.Type, - providers: event.Responses.map(({ ID, Addrs }) => ({ id: ID, multiaddrs: Addrs.map(addr => new Multiaddr(addr)) })) + providers: event.Responses.map(({ ID, Addrs }) => ({ id: peerIdFromString(ID), multiaddrs: Addrs.map(addr => new Multiaddr(addr)), protocols: [] })) } } if (event.Type === Value) { return { - from: event.ID, + from: peerIdFromString(event.ID), name: 'VALUE', type: event.Type, value: uint8ArrayFromString(event.Extra, 'base64pad') @@ -94,7 +101,7 @@ export const mapEvent = (event) => { } if (event.Type === AddingPeer) { - const peers = event.Responses.map(({ ID }) => ID) + const peers = event.Responses.map(({ ID }) => peerIdFromString(ID)) if (!peers.length) { throw new Error('No peer found') @@ -111,7 +118,7 @@ export const mapEvent = (event) => { return { name: 'DIALING_PEER', type: event.Type, - peer: event.ID + peer: peerIdFromString(event.ID) } } diff --git a/packages/ipfs-http-client/src/id.js b/packages/ipfs-http-client/src/id.js index 3a350380f8..00375d710e 100644 --- a/packages/ipfs-http-client/src/id.js +++ b/packages/ipfs-http-client/src/id.js @@ -1,7 +1,8 @@ import { objectToCamel } from './lib/object-to-camel.js' -import { Multiaddr } from 'multiaddr' +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' /** * @typedef {import('./types').HTTPClientExtraOptions} HTTPClientExtraOptions @@ -27,11 +28,13 @@ export const createId = configure(api => { ...objectToCamel(data) } + output.id = peerIdFromString(output.id) + if (output.addresses) { output.addresses = output.addresses.map((/** @type {string} */ ma) => new Multiaddr(ma)) } - // @ts-ignore server output is not typed + // @ts-expect-error server output is not typed return output } return id diff --git a/packages/ipfs-http-client/src/index.js b/packages/ipfs-http-client/src/index.js index 389b03119d..38e5d9d859 100644 --- a/packages/ipfs-http-client/src/index.js +++ b/packages/ipfs-http-client/src/index.js @@ -143,6 +143,6 @@ export function create (options = {}) { } export { CID } from 'multiformats/cid' -export { Multiaddr as multiaddr } from 'multiaddr' +export { Multiaddr as multiaddr } from '@multiformats/multiaddr' export { default as urlSource } from 'ipfs-utils/src/files/url-source.js' export const globSource = globSourceImport diff --git a/packages/ipfs-http-client/src/key/gen.js b/packages/ipfs-http-client/src/key/gen.js index d6c50d21f2..50a5e634fc 100644 --- a/packages/ipfs-http-client/src/key/gen.js +++ b/packages/ipfs-http-client/src/key/gen.js @@ -11,7 +11,7 @@ export const createGen = configure(api => { /** * @type {KeyAPI["gen"]} */ - async function gen (name, options = { type: 'rsa', size: 2048 }) { + async function gen (name, options = { type: 'Ed25519' }) { const res = await api.post('key/gen', { signal: options.signal, searchParams: toUrlSearchParams({ @@ -22,7 +22,7 @@ export const createGen = configure(api => { }) const data = await res.json() - // @ts-ignore server output is not typed + // @ts-expect-error server output is not typed return objectToCamel(data) } return gen diff --git a/packages/ipfs-http-client/src/key/import.js b/packages/ipfs-http-client/src/key/import.js index fa745f2900..e5aa9477ce 100644 --- a/packages/ipfs-http-client/src/key/import.js +++ b/packages/ipfs-http-client/src/key/import.js @@ -24,7 +24,7 @@ export const createImport = configure(api => { }) const data = await res.json() - // @ts-ignore server output is not typed + // @ts-expect-error server output is not typed return objectToCamel(data) } return importKey diff --git a/packages/ipfs-http-client/src/key/list.js b/packages/ipfs-http-client/src/key/list.js index 9d5ba864e3..3b53092b5f 100644 --- a/packages/ipfs-http-client/src/key/list.js +++ b/packages/ipfs-http-client/src/key/list.js @@ -19,7 +19,6 @@ export const createList = configure(api => { }) const data = await res.json() - // @ts-ignore server output is not typed return (data.Keys || []).map((/** @type {any} **/ k) => objectToCamel(k)) } return list diff --git a/packages/ipfs-http-client/src/key/rename.js b/packages/ipfs-http-client/src/key/rename.js index 2dcdd995ec..61b2f83799 100644 --- a/packages/ipfs-http-client/src/key/rename.js +++ b/packages/ipfs-http-client/src/key/rename.js @@ -24,7 +24,7 @@ export const createRename = configure(api => { headers: options.headers }) - // @ts-ignore server output is not typed + // @ts-expect-error server output is not typed return objectToCamel(await res.json()) } return rename diff --git a/packages/ipfs-http-client/src/key/rm.js b/packages/ipfs-http-client/src/key/rm.js index 3a51313fbc..4278167c31 100644 --- a/packages/ipfs-http-client/src/key/rm.js +++ b/packages/ipfs-http-client/src/key/rm.js @@ -22,7 +22,7 @@ export const createRm = configure(api => { }) const data = await res.json() - // @ts-ignore server output is not typed + // @ts-expect-error server output is not typed return objectToCamel(data.Keys[0]) } return rm diff --git a/packages/ipfs-http-client/src/lib/core.js b/packages/ipfs-http-client/src/lib/core.js index 79e5539c1b..326fcbf6e3 100644 --- a/packages/ipfs-http-client/src/lib/core.js +++ b/packages/ipfs-http-client/src/lib/core.js @@ -1,16 +1,16 @@ /* eslint-env browser */ -import { Multiaddr } from 'multiaddr' +import { Multiaddr } from '@multiformats/multiaddr' import { isBrowser, isWebWorker, isNode } from 'ipfs-utils/src/env.js' import parseDuration from 'parse-duration' -import debug from 'debug' +import { logger } from '@libp2p/logger' import HTTP from 'ipfs-utils/src/http.js' import mergeOpts from 'merge-options' import { toUrlString } from 'ipfs-core-utils/to-url-string' import getAgent from 'ipfs-core-utils/agent' -const log = debug('ipfs-http-client:lib:error-handler') +const log = logger('ipfs-http-client:lib:error-handler') const merge = mergeOpts.bind({ ignoreUndefined: true }) const DEFAULT_PROTOCOL = isBrowser || isWebWorker ? location.protocol : 'http' @@ -160,7 +160,6 @@ export class Client extends HTTP { transformSearchParams: (search) => { const out = new URLSearchParams() - // @ts-ignore https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams for (const [key, value] of search) { if ( value !== 'undefined' && @@ -170,7 +169,7 @@ export class Client extends HTTP { out.append(kebabCase(key), value) } - // @ts-ignore server timeouts are strings + // @ts-expect-error server timeouts are strings if (key === 'timeout' && !isNaN(value)) { out.append(kebabCase(key), value) } @@ -178,17 +177,17 @@ export class Client extends HTTP { return out }, - // @ts-ignore this can be a https agent or a http agent + // @ts-expect-error this can be a https agent or a http agent agent: opts.agent }) - // @ts-ignore - cannot delete no-optional fields + // @ts-expect-error - cannot delete no-optional fields delete this.get - // @ts-ignore - cannot delete no-optional fields + // @ts-expect-error - cannot delete no-optional fields delete this.put - // @ts-ignore - cannot delete no-optional fields + // @ts-expect-error - cannot delete no-optional fields delete this.delete - // @ts-ignore - cannot delete no-optional fields + // @ts-expect-error - cannot delete no-optional fields delete this.options const fetch = this.fetch diff --git a/packages/ipfs-http-client/src/lib/http-rpc-wire-format.js b/packages/ipfs-http-client/src/lib/http-rpc-wire-format.js index 6e28747d1a..b5de24598b 100644 --- a/packages/ipfs-http-client/src/lib/http-rpc-wire-format.js +++ b/packages/ipfs-http-client/src/lib/http-rpc-wire-format.js @@ -32,10 +32,16 @@ const rpcToText = mb => uint8ArrayToString(rpcToBytes(mb)) */ const rpcToBytes = mb => base64url.decode(mb) +/** + * @param {string} mb + * @returns {bigint} + */ +const rpcToBigInt = mb => BigInt(mb) + /** * @param {string} text * @returns {string} */ const textToUrlSafeRpc = text => base64url.encode(uint8ArrayFromString(text)) -export { rpcArrayToTextArray, rpcToText, rpcToBytes, textToUrlSafeRpc } +export { rpcArrayToTextArray, rpcToText, rpcToBytes, rpcToBigInt, textToUrlSafeRpc } diff --git a/packages/ipfs-http-client/src/name/publish.js b/packages/ipfs-http-client/src/name/publish.js index dba180da64..a8361f96a1 100644 --- a/packages/ipfs-http-client/src/name/publish.js +++ b/packages/ipfs-http-client/src/name/publish.js @@ -21,7 +21,7 @@ export const createPublish = configure(api => { headers: options.headers }) - // @ts-ignore server output is not typed + // @ts-expect-error server output is not typed return objectToCamel(await res.json()) } return publish diff --git a/packages/ipfs-http-client/src/name/pubsub/cancel.js b/packages/ipfs-http-client/src/name/pubsub/cancel.js index e2e0bb73dd..74bf85b5f0 100644 --- a/packages/ipfs-http-client/src/name/pubsub/cancel.js +++ b/packages/ipfs-http-client/src/name/pubsub/cancel.js @@ -21,7 +21,7 @@ export const createCancel = configure(api => { headers: options.headers }) - // @ts-ignore server output is not typed + // @ts-expect-error server output is not typed return objectToCamel(await res.json()) } return cancel diff --git a/packages/ipfs-http-client/src/name/pubsub/state.js b/packages/ipfs-http-client/src/name/pubsub/state.js index db6d374771..136b89381c 100644 --- a/packages/ipfs-http-client/src/name/pubsub/state.js +++ b/packages/ipfs-http-client/src/name/pubsub/state.js @@ -18,7 +18,7 @@ export const createState = configure(api => { headers: options.headers }) - // @ts-ignore server output is not typed + // @ts-expect-error server output is not typed return objectToCamel(await res.json()) } return state diff --git a/packages/ipfs-http-client/src/object/patch/add-link.js b/packages/ipfs-http-client/src/object/patch/add-link.js index cebaf42e18..652916d2a4 100644 --- a/packages/ipfs-http-client/src/object/patch/add-link.js +++ b/packages/ipfs-http-client/src/object/patch/add-link.js @@ -17,9 +17,9 @@ export const createAddLink = configure(api => { searchParams: toUrlSearchParams({ arg: [ `${cid}`, - // @ts-ignore loose types + // @ts-expect-error loose types dLink.Name || dLink.name || '', - // @ts-ignore loose types + // @ts-expect-error loose types (dLink.Hash || dLink.cid || '').toString() || null ], ...options diff --git a/packages/ipfs-http-client/src/object/patch/rm-link.js b/packages/ipfs-http-client/src/object/patch/rm-link.js index f3b1d76ced..7ea075709f 100644 --- a/packages/ipfs-http-client/src/object/patch/rm-link.js +++ b/packages/ipfs-http-client/src/object/patch/rm-link.js @@ -17,7 +17,7 @@ export const createRmLink = configure(api => { searchParams: toUrlSearchParams({ arg: [ `${cid}`, - // @ts-ignore loose types + // @ts-expect-error loose types dLink.Name || dLink.name || null ], ...options diff --git a/packages/ipfs-http-client/src/pin/add.js b/packages/ipfs-http-client/src/pin/add.js index 3b4dbf99e9..32a41d6afa 100644 --- a/packages/ipfs-http-client/src/pin/add.js +++ b/packages/ipfs-http-client/src/pin/add.js @@ -18,7 +18,7 @@ export function createAdd (config) { * @type {PinAPI["add"]} */ async function add (path, options = {}) { - // @ts-ignore last can return undefined + // @ts-expect-error last can return undefined return last(all([{ path, ...options diff --git a/packages/ipfs-http-client/src/pin/remote/service/ls.js b/packages/ipfs-http-client/src/pin/remote/service/ls.js index 528774181a..830f4b9a88 100644 --- a/packages/ipfs-http-client/src/pin/remote/service/ls.js +++ b/packages/ipfs-http-client/src/pin/remote/service/ls.js @@ -14,7 +14,7 @@ export function createLs (client) { * @type {RemotePiningServiceAPI["ls"]} */ async function ls (options = {}) { - // @ts-ignore cannot derive option type from typedef + // @ts-expect-error cannot derive option type from typedef const { stat, headers, timeout, signal } = options const response = await client.post('pin/remote/service/ls', { @@ -24,7 +24,7 @@ export function createLs (client) { searchParams: stat === true ? toUrlSearchParams({ stat }) : undefined }) - /** @type {{RemoteServices: Object[]}} */ + /** @type {{RemoteServices: object[]}} */ const { RemoteServices } = await response.json() return RemoteServices.map(decodeRemoteService) diff --git a/packages/ipfs-http-client/src/pin/remote/utils.js b/packages/ipfs-http-client/src/pin/remote/utils.js index 0c874f781b..b67238c048 100644 --- a/packages/ipfs-http-client/src/pin/remote/utils.js +++ b/packages/ipfs-http-client/src/pin/remote/utils.js @@ -10,7 +10,7 @@ import { toUrlSearchParams } from '../../lib/to-url-search-params.js' */ /** - * @param {Object} json + * @param {object} json * @param {string} json.Name * @param {string} json.Cid * @param {Status} json.Status diff --git a/packages/ipfs-http-client/src/pin/rm.js b/packages/ipfs-http-client/src/pin/rm.js index b966be7129..bf275c9ffb 100644 --- a/packages/ipfs-http-client/src/pin/rm.js +++ b/packages/ipfs-http-client/src/pin/rm.js @@ -18,7 +18,7 @@ export const createRm = (config) => { * @type {PinAPI["rm"]} */ async function rm (path, options = {}) { - // @ts-ignore last can return undefined + // @ts-expect-error last can return undefined return last(all([{ path, ...options diff --git a/packages/ipfs-http-client/src/pubsub/subscribe.js b/packages/ipfs-http-client/src/pubsub/subscribe.js index 468206ead4..cb7ab4908b 100644 --- a/packages/ipfs-http-client/src/pubsub/subscribe.js +++ b/packages/ipfs-http-client/src/pubsub/subscribe.js @@ -1,12 +1,12 @@ -import debug from 'debug' +import { logger } from '@libp2p/logger' import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -import { textToUrlSafeRpc, rpcArrayToTextArray, rpcToBytes } from '../lib/http-rpc-wire-format.js' -const log = debug('ipfs-http-client:pubsub:subscribe') +import { textToUrlSafeRpc, rpcToText, rpcToBytes, rpcToBigInt } from '../lib/http-rpc-wire-format.js' +const log = logger('ipfs-http-client:pubsub:subscribe') /** * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/pubsub').Message} Message + * @typedef {import('@libp2p/interfaces/pubsub').Message} Message * @typedef {(err: Error, fatal: boolean, msg?: Message) => void} ErrorHandlerFn * @typedef {import('ipfs-core-types/src/pubsub').API} PubsubAPI * @typedef {import('../types').Options} Options @@ -62,7 +62,20 @@ export const createSubscribe = (options, subsTracker) => { } readMessages(response, { - onMessage: handler, + onMessage: (message) => { + if (!handler) { + return + } + + if (typeof handler === 'function') { + handler(message) + return + } + + if (typeof handler.handleEvent === 'function') { + handler.handleEvent(message) + } + }, onEnd: () => subsTracker.unsubscribe(topic, handler), onError: options.onError }) @@ -96,8 +109,8 @@ async function readMessages (response, { onMessage, onEnd, onError }) { onMessage({ from: msg.from, data: rpcToBytes(msg.data), - seqno: rpcToBytes(msg.seqno), - topicIDs: rpcArrayToTextArray(msg.topicIDs) + sequenceNumber: rpcToBigInt(msg.sequenceNumber), + topic: rpcToText(msg.topic) }) } catch (/** @type {any} */ err) { err.message = `Failed to parse pubsub message: ${err.message}` diff --git a/packages/ipfs-http-client/src/pubsub/subscription-tracker.js b/packages/ipfs-http-client/src/pubsub/subscription-tracker.js index b2ef51ee8b..3cc0dd5a0c 100644 --- a/packages/ipfs-http-client/src/pubsub/subscription-tracker.js +++ b/packages/ipfs-http-client/src/pubsub/subscription-tracker.js @@ -1,8 +1,9 @@ /** - * @typedef {import('ipfs-core-types/src/pubsub').MessageHandlerFn} MessageHandlerFn + * @typedef {import('@libp2p/interfaces/pubsub').Message} Message + * @typedef {import('@libp2p/interfaces/events').EventHandler} MessageHandlerFn * - * @typedef {Object} Subscription + * @typedef {object} Subscription * @property {MessageHandlerFn} handler * @property {AbortController} controller */ diff --git a/packages/ipfs-http-client/src/swarm/addrs.js b/packages/ipfs-http-client/src/swarm/addrs.js index 94d3e1f298..468b6c95e4 100644 --- a/packages/ipfs-http-client/src/swarm/addrs.js +++ b/packages/ipfs-http-client/src/swarm/addrs.js @@ -1,6 +1,7 @@ -import { Multiaddr } from 'multiaddr' +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' /** * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions @@ -22,7 +23,7 @@ export const createAddrs = configure(api => { const { Addrs } = await res.json() return Object.keys(Addrs).map(id => ({ - id, + id: peerIdFromString(id), addrs: (Addrs[id] || []).map(a => new Multiaddr(a)) })) } diff --git a/packages/ipfs-http-client/src/swarm/local-addrs.js b/packages/ipfs-http-client/src/swarm/local-addrs.js index c25a5771f8..aaac2e6278 100644 --- a/packages/ipfs-http-client/src/swarm/local-addrs.js +++ b/packages/ipfs-http-client/src/swarm/local-addrs.js @@ -1,4 +1,4 @@ -import { Multiaddr } from 'multiaddr' +import { Multiaddr } from '@multiformats/multiaddr' import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' diff --git a/packages/ipfs-http-client/src/swarm/peers.js b/packages/ipfs-http-client/src/swarm/peers.js index 446269f9c1..836bfa08c2 100644 --- a/packages/ipfs-http-client/src/swarm/peers.js +++ b/packages/ipfs-http-client/src/swarm/peers.js @@ -1,6 +1,7 @@ -import { Multiaddr } from 'multiaddr' +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' /** * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions @@ -24,7 +25,7 @@ export const createPeers = configure(api => { return (Peers || []).map(peer => { return { addr: new Multiaddr(peer.Addr), - peer: peer.Peer, + peer: peerIdFromString(peer.Peer), muxer: peer.Muxer, latency: peer.Latency, streams: peer.Streams, diff --git a/packages/ipfs-http-client/src/types.ts b/packages/ipfs-http-client/src/types.ts index 776ac4a9b5..5385a20ad9 100644 --- a/packages/ipfs-http-client/src/types.ts +++ b/packages/ipfs-http-client/src/types.ts @@ -1,6 +1,6 @@ import type { Agent as HttpAgent } from 'http' import type { Agent as HttpsAgent } from 'https' -import type { Multiaddr } from 'multiaddr' +import type { Multiaddr } from '@multiformats/multiaddr' import type { BlockCodec } from 'multiformats/codecs/interface' import type { MultihashHasher } from 'multiformats/hashes/interface' import type { MultibaseCodec } from 'multiformats/bases/interface' diff --git a/packages/ipfs-http-client/test/commands.spec.js b/packages/ipfs-http-client/test/commands.spec.js index 2ed1a8b7e2..42b3dec457 100644 --- a/packages/ipfs-http-client/test/commands.spec.js +++ b/packages/ipfs-http-client/test/commands.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { factory } from './utils/factory.js' const f = factory() diff --git a/packages/ipfs-http-client/test/constructor.spec.js b/packages/ipfs-http-client/test/constructor.spec.js index 74b1ca8c4e..67525804fd 100644 --- a/packages/ipfs-http-client/test/constructor.spec.js +++ b/packages/ipfs-http-client/test/constructor.spec.js @@ -1,7 +1,7 @@ /* eslint-env mocha, browser */ -import { Multiaddr } from 'multiaddr' -import { expect } from 'aegir/utils/chai.js' +import { Multiaddr } from '@multiformats/multiaddr' +import { expect } from 'aegir/chai' import { factory } from './utils/factory.js' import { create as ipfsClient } from '../src/index.js' import { isBrowser } from 'ipfs-utils/src/env.js' diff --git a/packages/ipfs-http-client/test/dag.spec.js b/packages/ipfs-http-client/test/dag.spec.js index 346828fdc0..de8054d364 100644 --- a/packages/ipfs-http-client/test/dag.spec.js +++ b/packages/ipfs-http-client/test/dag.spec.js @@ -2,7 +2,7 @@ /* eslint max-nested-callbacks: ["error", 8] */ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import * as dagPB from '@ipld/dag-pb' import * as dagCBOR from '@ipld/dag-cbor' import * as raw from 'multiformats/codecs/raw' diff --git a/packages/ipfs-http-client/test/diag.spec.js b/packages/ipfs-http-client/test/diag.spec.js index 223fcfdd0c..e29636ed22 100644 --- a/packages/ipfs-http-client/test/diag.spec.js +++ b/packages/ipfs-http-client/test/diag.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { factory } from './utils/factory.js' const f = factory() diff --git a/packages/ipfs-http-client/test/endpoint-config.spec.js b/packages/ipfs-http-client/test/endpoint-config.spec.js index 11fda84c3f..ec8c8016cd 100644 --- a/packages/ipfs-http-client/test/endpoint-config.spec.js +++ b/packages/ipfs-http-client/test/endpoint-config.spec.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ /* eslint max-nested-callbacks: ["error", 8] */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { create as httpClient } from '../src/index.js' describe('.getEndpointConfig', () => { diff --git a/packages/ipfs-http-client/test/exports.spec.js b/packages/ipfs-http-client/test/exports.spec.js index 9f9cbbb345..1f9791dd11 100644 --- a/packages/ipfs-http-client/test/exports.spec.js +++ b/packages/ipfs-http-client/test/exports.spec.js @@ -1,8 +1,8 @@ /* eslint-env mocha, browser */ import { CID } from 'multiformats/cid' -import { Multiaddr } from 'multiaddr' -import { expect } from 'aegir/utils/chai.js' +import { Multiaddr } from '@multiformats/multiaddr' +import { expect } from 'aegir/chai' import * as IpfsHttpClient from '../src/index.js' describe('exports', () => { diff --git a/packages/ipfs-http-client/test/files.spec.js b/packages/ipfs-http-client/test/files.spec.js index c8602ddf24..6f06c3efc5 100644 --- a/packages/ipfs-http-client/test/files.spec.js +++ b/packages/ipfs-http-client/test/files.spec.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import * as dagPB from '@ipld/dag-pb' import { factory } from './utils/factory.js' const f = factory() diff --git a/packages/ipfs-http-client/test/key.spec.js b/packages/ipfs-http-client/test/key.spec.js index e5931d44bf..25daa23092 100644 --- a/packages/ipfs-http-client/test/key.spec.js +++ b/packages/ipfs-http-client/test/key.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { factory } from './utils/factory.js' const f = factory() diff --git a/packages/ipfs-http-client/test/lib.error-handler.spec.js b/packages/ipfs-http-client/test/lib.error-handler.spec.js index d7ef3de56c..0ec2805641 100644 --- a/packages/ipfs-http-client/test/lib.error-handler.spec.js +++ b/packages/ipfs-http-client/test/lib.error-handler.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { throwsAsync } from './utils/throws-async.js' import { errorHandler, HTTPError } from '../src/lib/core.js' diff --git a/packages/ipfs-http-client/test/log.spec.js b/packages/ipfs-http-client/test/log.spec.js index 05b973b0fc..c71a9173c4 100644 --- a/packages/ipfs-http-client/test/log.spec.js +++ b/packages/ipfs-http-client/test/log.spec.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ /* eslint max-nested-callbacks: ["error", 8] */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import first from 'it-first' import { factory } from './utils/factory.js' diff --git a/packages/ipfs-http-client/test/node/agent.js b/packages/ipfs-http-client/test/node/agent.js index 678f3e7ab2..dee25e52f1 100644 --- a/packages/ipfs-http-client/test/node/agent.js +++ b/packages/ipfs-http-client/test/node/agent.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import delay from 'delay' import { create as httpClient } from '../../src/index.js' import http, { Agent } from 'http' diff --git a/packages/ipfs-http-client/test/node/custom-headers.js b/packages/ipfs-http-client/test/node/custom-headers.js index 6d17166791..0932d6523b 100644 --- a/packages/ipfs-http-client/test/node/custom-headers.js +++ b/packages/ipfs-http-client/test/node/custom-headers.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ import { isNode } from 'ipfs-utils/src/env.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { create as httpClient } from '../../src/index.js' import http from 'http' diff --git a/packages/ipfs-http-client/test/node/request-api.js b/packages/ipfs-http-client/test/node/request-api.js index 47d9b53859..e67f19da25 100644 --- a/packages/ipfs-http-client/test/node/request-api.js +++ b/packages/ipfs-http-client/test/node/request-api.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { create as httpClient } from '../../src/index.js' import http from 'http' diff --git a/packages/ipfs-http-client/test/node/swarm.js b/packages/ipfs-http-client/test/node/swarm.js index 7aa5219ec9..5191ccad5a 100644 --- a/packages/ipfs-http-client/test/node/swarm.js +++ b/packages/ipfs-http-client/test/node/swarm.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import nock from 'nock' import { create as httpClient } from '../../src/index.js' diff --git a/packages/ipfs-http-client/test/ping.spec.js b/packages/ipfs-http-client/test/ping.spec.js index 3e5ad28a69..dc71f5da94 100644 --- a/packages/ipfs-http-client/test/ping.spec.js +++ b/packages/ipfs-http-client/test/ping.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import all from 'it-all' import { factory } from './utils/factory.js' diff --git a/packages/ipfs-http-client/test/pubsub.spec.js b/packages/ipfs-http-client/test/pubsub.spec.js index 81d54db985..f85851b815 100644 --- a/packages/ipfs-http-client/test/pubsub.spec.js +++ b/packages/ipfs-http-client/test/pubsub.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import defer from 'p-defer' import { factory } from './utils/factory.js' diff --git a/packages/ipfs-http-client/test/repo.spec.js b/packages/ipfs-http-client/test/repo.spec.js index 4209ebf52b..04a0f86e93 100644 --- a/packages/ipfs-http-client/test/repo.spec.js +++ b/packages/ipfs-http-client/test/repo.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { factory } from './utils/factory.js' const f = factory() diff --git a/packages/ipfs-http-client/test/stats.spec.js b/packages/ipfs-http-client/test/stats.spec.js index a1627a05d6..2635df6196 100644 --- a/packages/ipfs-http-client/test/stats.spec.js +++ b/packages/ipfs-http-client/test/stats.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import all from 'it-all' import { factory } from './utils/factory.js' const f = factory() diff --git a/packages/ipfs-http-gateway/package.json b/packages/ipfs-http-gateway/package.json index 1f84e3c633..7b621ed41b 100644 --- a/packages/ipfs-http-gateway/package.json +++ b/packages/ipfs-http-gateway/package.json @@ -49,7 +49,7 @@ "url": "git+https://github.com/ipfs/js-ipfs.git" }, "scripts": { - "lint": "aegir ts -p check && aegir lint", + "lint": "aegir lint", "test": "aegir test -t node", "test:node": "aegir test -t node --cov", "clean": "rimraf ./dist", @@ -61,7 +61,7 @@ "@hapi/boom": "^9.1.0", "@hapi/hapi": "^20.0.0", "debug": "^4.1.1", - "hapi-pino": "^8.3.0", + "hapi-pino": "^9.3.0", "ipfs-core-types": "^0.10.2", "ipfs-http-response": "^2.0.2", "is-ipfs": "^6.0.1", @@ -69,15 +69,16 @@ "it-to-stream": "^1.0.0", "joi": "^17.2.1", "multiformats": "^9.5.1", + "pino-pretty": "^7.6.1", "uint8arrays": "^3.0.0", "uri-to-multiaddr": "^6.0.0" }, "devDependencies": { "@types/hapi-pino": "^8.0.1", "@types/hapi__hapi": "^20.0.5", - "aegir": "^36.0.1", - "file-type": "^16.0.0", + "aegir": "^37.0.11", + "file-type": "^17.1.1", "rimraf": "^3.0.2", - "sinon": "^12.0.01" + "sinon": "^13.0.1" } } diff --git a/packages/ipfs-http-gateway/src/index.js b/packages/ipfs-http-gateway/src/index.js index 8a69ef5ecc..ab6482624a 100644 --- a/packages/ipfs-http-gateway/src/index.js +++ b/packages/ipfs-http-gateway/src/index.js @@ -1,6 +1,6 @@ import Hapi from '@hapi/hapi' import Pino from 'hapi-pino' -import debug from 'debug' +import { logger, enabled } from '@libp2p/logger' // @ts-expect-error no types import toMultiaddr from 'uri-to-multiaddr' import routes from './routes/index.js' @@ -57,9 +57,7 @@ export class HttpGateway { */ constructor (ipfs) { this._ipfs = ipfs - this._log = Object.assign(debug(LOG), { - error: debug(LOG_ERROR) - }) + this._log = logger(LOG) /** @type {Server[]} */ this._gatewayServers = [] } @@ -68,8 +66,6 @@ export class HttpGateway { this._log('starting') const ipfs = this._ipfs - - // @ts-ignore TODO: move config typedefs to repo const config = await ipfs.config.getAll() const addresses = config.Addresses || { Swarm: [], Gateway: [] } const gatewayAddrs = addresses?.Gateway || [] @@ -100,9 +96,24 @@ export class HttpGateway { await server.register({ plugin: Pino, options: { - prettyPrint: Boolean(debug.enabled(LOG)), logEvents: ['onPostStart', 'onPostStop', 'response', 'request-error'], - level: debug.enabled(LOG) ? 'debug' : (debug.enabled(LOG_ERROR) ? 'error' : 'fatal') + level: enabled(LOG) ? 'debug' : (enabled(LOG_ERROR) ? 'error' : 'fatal'), + transport: process.env.NODE_ENV !== 'production' + ? { + target: 'pino-pretty', + options: { + colorize: true, + minimumLevel: 'info', + levelFirst: true, + messageFormat: true, + timestampKey: 'time', + translateTime: true, + singleLine: false, + mkdir: true, + append: true + } + } + : undefined } }) diff --git a/packages/ipfs-http-gateway/src/resources/gateway.js b/packages/ipfs-http-gateway/src/resources/gateway.js index e805fc155e..cfd2883c6b 100644 --- a/packages/ipfs-http-gateway/src/resources/gateway.js +++ b/packages/ipfs-http-gateway/src/resources/gateway.js @@ -1,4 +1,4 @@ -import debug from 'debug' +import { logger } from '@libp2p/logger' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import Boom from '@hapi/boom' import Ammo from '@hapi/ammo' @@ -13,9 +13,7 @@ import * as PathUtils from '../utils/path.js' const { detectContentType } = utils -const log = Object.assign(debug('ipfs:http-gateway'), { - error: debug('ipfs:http-gateway:error') -}) +const log = logger('ipfs:http-gateway') export const Gateway = { diff --git a/packages/ipfs-http-gateway/src/types.ts b/packages/ipfs-http-gateway/src/types.ts index 46715f6625..0e63e0dec3 100644 --- a/packages/ipfs-http-gateway/src/types.ts +++ b/packages/ipfs-http-gateway/src/types.ts @@ -1,6 +1,6 @@ import type { IPFS } from 'ipfs-core-types' import type { Request, Server } from '@hapi/hapi' -import type { Multiaddr } from 'multiaddr' +import type { Multiaddr } from '@multiformats/multiaddr' declare module '@hapi/hapi' { interface ServerApplicationState { diff --git a/packages/ipfs-http-gateway/test/routes.spec.js b/packages/ipfs-http-gateway/test/routes.spec.js index 93440b0e60..489ffbdeb4 100644 --- a/packages/ipfs-http-gateway/test/routes.spec.js +++ b/packages/ipfs-http-gateway/test/routes.spec.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ /* eslint dot-notation: 0, dot-notation: 0, quote-props: 0 */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import FileType from 'file-type' import { CID } from 'multiformats/cid' diff --git a/packages/ipfs-http-response/package.json b/packages/ipfs-http-response/package.json index 7becf12bf5..22fbc6d8e0 100644 --- a/packages/ipfs-http-response/package.json +++ b/packages/ipfs-http-response/package.json @@ -33,7 +33,7 @@ "directory": "dist" }, "scripts": { - "lint": "aegir ts -p check && aegir lint", + "lint": "aegir lint", "clean": "rimraf ./dist", "build": "aegir build --no-bundle", "pretest": "aegir build --esm-tests", @@ -63,18 +63,19 @@ "dependencies": { "debug": "^4.3.1", "ejs": "^3.1.6", - "file-type": "^16.0.0", + "file-type": "^17.1.1", "filesize": "^8.0.0", "it-buffer": "^0.1.1", "it-concat": "^2.0.0", - "it-reader": "^3.0.0", + "it-reader": "^5.0.1", "it-to-stream": "^1.0.0", "mime-types": "^2.1.30", "p-try-each": "^1.0.1" }, "devDependencies": { "@types/ejs": "^3.1.0", - "aegir": "^36.0.1", + "@types/mime-types": "^2.1.1", + "aegir": "^37.0.11", "get-stream": "^6.0.0", "global": "^4.4.0", "ipfs-core": "^0.14.2", diff --git a/packages/ipfs-http-response/src/index.js b/packages/ipfs-http-response/src/index.js index e0661970c1..821dbaa202 100644 --- a/packages/ipfs-http-response/src/index.js +++ b/packages/ipfs-http-response/src/index.js @@ -1,16 +1,16 @@ /* global Response, Blob */ -// @ts-ignore no types +// @ts-expect-error no types import toStream from 'it-to-stream' import concat from 'it-concat' -// @ts-ignore no types +// @ts-expect-error no types import toBuffer from 'it-buffer' -import debug from 'debug' +import { logger } from '@libp2p/logger' import * as ipfsResolver from './resolver.js' import * as pathUtils from './utils/path.js' import { detectContentType } from './utils/content-type.js' -const log = debug('ipfs:http:response') +const log = logger('ipfs:http:response') // TODO: pass path and add Etag and X-Ipfs-Path + tests const getHeader = (status = 200, statusText = 'OK', headers = {}) => ({ diff --git a/packages/ipfs-http-response/src/utils/content-type.js b/packages/ipfs-http-response/src/utils/content-type.js index e7836f1ab6..0b5f7b2814 100644 --- a/packages/ipfs-http-response/src/utils/content-type.js +++ b/packages/ipfs-http-response/src/utils/content-type.js @@ -1,11 +1,14 @@ -import fileType from 'file-type' -// @ts-ignore no types +import { fileTypeFromBuffer } from 'file-type' import mime from 'mime-types' -// @ts-ignore no types -import Reader from 'it-reader' +import { reader } from 'it-reader' +import map from 'it-map' const minimumBytes = 4100 +/** + * @typedef {import('uint8arraylist').Uint8ArrayList} Uint8ArrayList + */ + /** * @param {string} path * @param {AsyncIterable} source @@ -13,27 +16,33 @@ const minimumBytes = 4100 */ export const detectContentType = async (path, source) => { let fileSignature + /** @type {AsyncIterable | undefined} */ + let output // try to guess the filetype based on the first bytes // note that `file-type` doesn't support svgs, therefore we assume it's a svg if path looks like it if (!path.endsWith('.svg')) { try { - const reader = Reader(source) - const { value, done } = await reader.next(minimumBytes) + const stream = reader(source) + const { value, done } = await stream.next(minimumBytes) - if (done) return { source: reader } + if (done) { + return { + source: map(stream, (buf) => buf.slice()) + } + } - fileSignature = await fileType.fromBuffer(value.slice()) + fileSignature = await fileTypeFromBuffer(value.slice()) - source = (async function * () { // eslint-disable-line require-await + output = (async function * () { // eslint-disable-line require-await yield value - yield * reader + yield * stream })() } catch (/** @type {any} */ err) { if (err.code !== 'ERR_UNDER_READ') throw err // not enough bytes for sniffing, just yield the data - source = (async function * () { // eslint-disable-line require-await + output = (async function * () { // eslint-disable-line require-await yield err.buffer // these are the bytes that were read (if any) })() } @@ -42,5 +51,19 @@ export const detectContentType = async (path, source) => { // if we were unable to, fallback to the `path` which might contain the extension const mimeType = mime.lookup(fileSignature ? fileSignature.ext : path) - return { source, contentType: mime.contentType(mimeType) } + let contentType + + if (mimeType !== false) { + contentType = mime.contentType(mimeType) + + if (contentType === false) { + contentType = undefined + } + } + + if (output != null) { + return { source: map(output, (buf) => buf.slice()), contentType } + } + + return { source, contentType } } diff --git a/packages/ipfs-http-response/test/index.spec.js b/packages/ipfs-http-response/test/index.spec.js index a82b8de583..ae6f4d6b6d 100644 --- a/packages/ipfs-http-response/test/index.spec.js +++ b/packages/ipfs-http-response/test/index.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' -import loadFixture from 'aegir/utils/fixtures.js' +import { expect } from 'aegir/chai' +import loadFixture from 'aegir/fixtures' import { createFactory } from 'ipfsd-ctl' import getStream from 'get-stream' import all from 'it-all' diff --git a/packages/ipfs-http-response/test/resolver.spec.js b/packages/ipfs-http-response/test/resolver.spec.js index e7b2118294..b8d3bd3156 100644 --- a/packages/ipfs-http-response/test/resolver.spec.js +++ b/packages/ipfs-http-response/test/resolver.spec.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' -import loadFixture from 'aegir/utils/fixtures.js' +import { expect } from 'aegir/chai' +import loadFixture from 'aegir/fixtures' import { createFactory } from 'ipfsd-ctl' import all from 'it-all' import * as ipfsResolver from '../src/resolver.js' diff --git a/packages/ipfs-http-server/package.json b/packages/ipfs-http-server/package.json index 0ce7d014b5..14669518e7 100644 --- a/packages/ipfs-http-server/package.json +++ b/packages/ipfs-http-server/package.json @@ -34,7 +34,7 @@ "url": "git+https://github.com/ipfs/js-ipfs.git" }, "scripts": { - "lint": "aegir ts -p check && aegir lint", + "lint": "aegir lint", "test": "aegir test -t node", "test:node": "aegir test -t node --cov", "clean": "rimraf ./dist", @@ -52,7 +52,7 @@ "debug": "^4.1.1", "dlv": "^1.1.3", "err-code": "^3.0.1", - "hapi-pino": "^8.3.0", + "hapi-pino": "^9.3.0", "ipfs-core-types": "^0.10.2", "ipfs-core-utils": "^0.14.2", "ipfs-http-gateway": "^0.9.2", @@ -65,14 +65,15 @@ "it-map": "^1.0.4", "it-merge": "^1.0.2", "it-multipart": "^2.0.0", - "it-pipe": "^1.1.0", - "it-pushable": "^1.4.2", + "it-pipe": "^2.0.3", + "it-pushable": "^2.0.1", "it-reduce": "^1.0.5", "joi": "^17.2.1", - "just-safe-set": "^2.2.1", - "multiaddr": "^10.0.0", + "just-safe-set": "^4.0.2", + "@multiformats/multiaddr": "^10.0.0", "multiformats": "^9.5.1", "parse-duration": "^1.0.0", + "pino-pretty": "^7.6.1", "stream-to-it": "^0.2.2", "timeout-abort-controller": "^3.0.0", "uint8arrays": "^3.0.0", @@ -81,7 +82,7 @@ "devDependencies": { "@types/hapi-pino": "^8.0.1", "@types/hapi__hapi": "^20.0.5", - "aegir": "^36.0.1", + "aegir": "^37.0.11", "form-data": "^4.0.0", "ipfs-http-client": "^56.0.2", "iso-random-stream": "^2.0.2", @@ -89,7 +90,7 @@ "npm-run-all": "^4.1.5", "qs": "^6.9.4", "rimraf": "^3.0.2", - "sinon": "^12.0.01", + "sinon": "^13.0.1", "stream-to-promise": "^3.0.0" }, "optionalDependencies": { diff --git a/packages/ipfs-http-server/src/api/resources/config.js b/packages/ipfs-http-server/src/api/resources/config.js index 05f1c58fdd..7ca109a9cd 100644 --- a/packages/ipfs-http-server/src/api/resources/config.js +++ b/packages/ipfs-http-server/src/api/resources/config.js @@ -1,13 +1,12 @@ -import debug from 'debug' +import { logger } from '@libp2p/logger' import get from 'dlv' import set from 'just-safe-set' import { multipartRequestParser } from '../../utils/multipart-request-parser.js' import Boom from '@hapi/boom' import Joi from '../../utils/joi.js' import all from 'it-all' -const log = Object.assign(debug('ipfs:http-api:config'), { - error: debug('ipfs:http-api:config:error') -}) + +const log = logger('ipfs:http-api:config') export const getOrSetResource = { options: { diff --git a/packages/ipfs-http-server/src/api/resources/dag.js b/packages/ipfs-http-server/src/api/resources/dag.js index e25834effb..fb4b578190 100644 --- a/packages/ipfs-http-server/src/api/resources/dag.js +++ b/packages/ipfs-http-server/src/api/resources/dag.js @@ -402,9 +402,6 @@ export const importResource = { return streamResponse(request, h, () => pipe( multipartRequestParser(request.raw.req), - /** - * @param {AsyncIterable} source - */ async function * (source) { for await (const entry of source) { if (entry.type !== 'file') { @@ -415,9 +412,6 @@ export const importResource = { yield entry.content } }, - /** - * @param {AsyncIterable>} source - */ async function * (source) { yield * ipfs.dag.import(source, { pinRoots, @@ -425,9 +419,6 @@ export const importResource = { signal }) }, - /** - * @param {AsyncIterable} source - */ async function * (source) { for await (const res of source) { yield { diff --git a/packages/ipfs-http-server/src/api/resources/dht.js b/packages/ipfs-http-server/src/api/resources/dht.js index 3f31a0e31a..ad862518d5 100644 --- a/packages/ipfs-http-server/src/api/resources/dht.js +++ b/packages/ipfs-http-server/src/api/resources/dht.js @@ -8,12 +8,12 @@ import all from 'it-all' import Boom from '@hapi/boom' /** - * @typedef {import('ipfs-core-types/src/dht').QueryEvent} QueryEvent - * @typedef {import('peer-id')} PeerId + * @typedef {import('@libp2p/interfaces/dht').QueryEvent} QueryEvent + * @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId */ /** - * @param {string} id + * @param {PeerId} id * @param {QueryEvent} event */ function mapQueryEvent (id, event) { diff --git a/packages/ipfs-http-server/src/api/resources/files-regular.js b/packages/ipfs-http-server/src/api/resources/files-regular.js index 808e8b27a8..308eeb3633 100644 --- a/packages/ipfs-http-server/src/api/resources/files-regular.js +++ b/packages/ipfs-http-server/src/api/resources/files-regular.js @@ -233,9 +233,6 @@ export const addResource = { return streamResponse(request, h, () => pipe( multipartRequestParser(request.raw.req), - /** - * @param {AsyncIterable} source - */ async function * (source) { for await (const entry of source) { if (entry.type === 'file') { @@ -260,9 +257,6 @@ export const addResource = { } } }, - /** - * @param {import('ipfs-core-types/src/utils').ImportCandidateStream} source - */ async function * (source) { const progressStream = new PassThrough({ objectMode: true diff --git a/packages/ipfs-http-server/src/api/resources/id.js b/packages/ipfs-http-server/src/api/resources/id.js index f2642f6c4e..b36306b077 100644 --- a/packages/ipfs-http-server/src/api/resources/id.js +++ b/packages/ipfs-http-server/src/api/resources/id.js @@ -43,7 +43,7 @@ export const idResource = { peerId }) return h.response({ - ID: id.id, + ID: id.id.toString(), PublicKey: id.publicKey, Addresses: id.addresses, AgentVersion: id.agentVersion, diff --git a/packages/ipfs-http-server/src/api/resources/object.js b/packages/ipfs-http-server/src/api/resources/object.js index 850b9901a7..f985f7acca 100644 --- a/packages/ipfs-http-server/src/api/resources/object.js +++ b/packages/ipfs-http-server/src/api/resources/object.js @@ -5,14 +5,12 @@ import Joi from '../../utils/joi.js' import Boom from '@hapi/boom' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' -import debug from 'debug' +import { logger } from '@libp2p/logger' import { CID } from 'multiformats/cid' import { base64pad } from 'multiformats/bases/base64' import { base16 } from 'multiformats/bases/base16' -const log = Object.assign(debug('ipfs:http-api:object'), { - error: debug('ipfs:http-api:object:error') -}) +const log = logger('ipfs:http-api:object') /** * @type {Record Uint8Array>} diff --git a/packages/ipfs-http-server/src/api/resources/pubsub.js b/packages/ipfs-http-server/src/api/resources/pubsub.js index ec9a0282e7..ada2fcc1a7 100644 --- a/packages/ipfs-http-server/src/api/resources/pubsub.js +++ b/packages/ipfs-http-server/src/api/resources/pubsub.js @@ -5,9 +5,13 @@ import Boom from '@hapi/boom' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' import { streamResponse } from '../../utils/stream-response.js' -import pushable from 'it-pushable' +import { pushable } from 'it-pushable' import { base64url } from 'multiformats/bases/base64' +/** + * @typedef {import('@libp2p/interfaces/pubsub').Message} Message + */ + const preDecodeTopicFromHttpRpc = { assign: 'topic', /** @@ -70,14 +74,14 @@ export const subscribeResource = { const output = pushable() /** - * @type {import('ipfs-core-types/src/pubsub').MessageHandlerFn} + * @type {import('@libp2p/interfaces/events').EventHandler} */ const handler = (msg) => { output.push({ - from: msg.from, // TODO: switch to PeerId.parse(msg.from).toString() when go-ipfs defaults to CIDv1 + from: msg.from, // TODO: switch to peerIdFromString(msg.from).toString() when go-ipfs defaults to CIDv1 data: base64url.encode(msg.data), - seqno: base64url.encode(msg.seqno), - topicIDs: msg.topicIDs.map(t => base64url.encode(uint8ArrayFromString(t))) + sequenceNumber: msg.sequenceNumber?.toString(), + topic: base64url.encode(uint8ArrayFromString(msg.topic)) }) } diff --git a/packages/ipfs-http-server/src/api/resources/shutdown.js b/packages/ipfs-http-server/src/api/resources/shutdown.js index 35f0222a71..0114d8a22f 100644 --- a/packages/ipfs-http-server/src/api/resources/shutdown.js +++ b/packages/ipfs-http-server/src/api/resources/shutdown.js @@ -11,7 +11,6 @@ export const shutdownResource = { * @param {import('@hapi/hapi').ResponseToolkit} h */ handler: (_request, h) => { - // @ts-ignore - TS expects second argument setImmediate(() => process.emit('SIGTERM')) return h.response() } diff --git a/packages/ipfs-http-server/src/api/routes/debug.js b/packages/ipfs-http-server/src/api/routes/debug.js index 0840d5d471..023dcc9dde 100644 --- a/packages/ipfs-http-server/src/api/routes/debug.js +++ b/packages/ipfs-http-server/src/api/routes/debug.js @@ -1,6 +1,6 @@ import client from 'prom-client' import Boom from '@hapi/boom' -import debug from 'debug' +import { disable, enable } from '@libp2p/logger' // Clear the register to make sure we're not registering multiple ones client.register.clear() @@ -57,9 +57,9 @@ export default [{ } if (!request.query.debug) { - debug.disable() + disable() } else { - debug.enable(request.query.debug) + enable(request.query.debug) } return h.response() diff --git a/packages/ipfs-http-server/src/index.js b/packages/ipfs-http-server/src/index.js index 96c4a21f74..a8cf4ce702 100644 --- a/packages/ipfs-http-server/src/index.js +++ b/packages/ipfs-http-server/src/index.js @@ -1,7 +1,7 @@ import Hapi from '@hapi/hapi' import Pino from 'hapi-pino' -import debug from 'debug' -import { Multiaddr } from 'multiaddr' +import { logger, enabled } from '@libp2p/logger' +import { Multiaddr } from '@multiformats/multiaddr' // @ts-expect-error no types import toMultiaddr from 'uri-to-multiaddr' import Boom from '@hapi/boom' @@ -15,7 +15,7 @@ const LOG_ERROR = 'ipfs:http-api:error' /** * @typedef {import('ipfs-core-types').IPFS} IPFS * @typedef {import('./types').Server} Server - * @typedef {import('libp2p')} libp2p + * @typedef {import('libp2p').Libp2p} libp2p */ /** @@ -93,9 +93,7 @@ export class HttpApi { */ constructor (ipfs) { this._ipfs = ipfs - this._log = Object.assign(debug(LOG), { - error: debug(LOG_ERROR) - }) + this._log = logger(LOG) /** @type {Server[]} */ this._apiServers = [] } @@ -118,7 +116,7 @@ export class HttpApi { }) // for the CLI to know the whereabouts of the API - // @ts-ignore - ipfs.repo.setApiAddr is not part of the core api + // @ts-expect-error - ipfs.repo.setApiAddr is not part of the core api await ipfs.repo.setApiAddr(this._apiServers[0].info.ma) this._log('started') @@ -158,9 +156,24 @@ export class HttpApi { await server.register({ plugin: Pino, options: { - prettyPrint: process.env.NODE_ENV !== 'production', logEvents: ['onPostStart', 'onPostStop', 'response', 'request-error'], - level: debug.enabled(LOG) ? 'debug' : (debug.enabled(LOG_ERROR) ? 'error' : 'fatal') + level: enabled(LOG) ? 'debug' : (enabled(LOG_ERROR) ? 'error' : 'fatal'), + transport: process.env.NODE_ENV !== 'production' + ? { + target: 'pino-pretty', + options: { + colorize: true, + minimumLevel: 'info', + levelFirst: true, + messageFormat: true, + timestampKey: 'time', + translateTime: true, + singleLine: false, + mkdir: true, + append: true + } + } + : undefined } }) diff --git a/packages/ipfs-http-server/src/types.ts b/packages/ipfs-http-server/src/types.ts index 465dc949fb..4566d8150a 100644 --- a/packages/ipfs-http-server/src/types.ts +++ b/packages/ipfs-http-server/src/types.ts @@ -1,6 +1,6 @@ import type { IPFS } from 'ipfs-core-types' import type { Request, Server } from '@hapi/hapi' -import type { Multiaddr } from 'multiaddr' +import type { Multiaddr } from '@multiformats/multiaddr' import type { Mtime } from 'ipfs-unixfs' declare module '@hapi/hapi' { diff --git a/packages/ipfs-http-server/src/utils/joi.js b/packages/ipfs-http-server/src/utils/joi.js index 3b62532ba9..f848350654 100644 --- a/packages/ipfs-http-server/src/utils/joi.js +++ b/packages/ipfs-http-server/src/utils/joi.js @@ -1,6 +1,6 @@ import { CID } from 'multiformats/cid' import parseDuration from 'parse-duration' -import { Multiaddr } from 'multiaddr' +import { Multiaddr } from '@multiformats/multiaddr' import { toCidAndPath } from 'ipfs-core-utils/to-cid-and-path' import Joi from 'joi' @@ -52,7 +52,7 @@ const requireIfRequired = (value, helpers) => { export default Joi .extend( - // @ts-ignore - according to typedefs coerce should always return + // @ts-expect-error - according to typedefs coerce should always return // { errors?: ErrorReport[], value?: any } (joi) => { return { diff --git a/packages/ipfs-http-server/src/utils/multipart-request-parser.js b/packages/ipfs-http-server/src/utils/multipart-request-parser.js index 5c8b6ac9cf..0bd99c9658 100644 --- a/packages/ipfs-http-server/src/utils/multipart-request-parser.js +++ b/packages/ipfs-http-server/src/utils/multipart-request-parser.js @@ -57,7 +57,7 @@ const collect = async (stream) => { } /** - * @typedef {Object} MultipartUpload + * @typedef {object} MultipartUpload * @property {'file' | 'directory' | 'symlink'} type * @property {string} name * @property {AsyncIterable} body diff --git a/packages/ipfs-http-server/src/utils/stream-response.js b/packages/ipfs-http-server/src/utils/stream-response.js index 0ab77733cc..b157b7ab8e 100644 --- a/packages/ipfs-http-server/src/utils/stream-response.js +++ b/packages/ipfs-http-server/src/utils/stream-response.js @@ -1,10 +1,10 @@ import { PassThrough } from 'stream' import { pipe } from 'it-pipe' -import debug from 'debug' +import { logger } from '@libp2p/logger' // @ts-expect-error no types import toIterable from 'stream-to-it' -const log = debug('ipfs:http-api:utils:stream-response') +const log = logger('ipfs:http-api:utils:stream-response') const ERROR_TRAILER = 'X-Stream-Error' /** diff --git a/packages/ipfs-http-server/src/version.js b/packages/ipfs-http-server/src/version.js index d0dd88b07a..19e8dd5ada 100644 --- a/packages/ipfs-http-server/src/version.js +++ b/packages/ipfs-http-server/src/version.js @@ -1,2 +1,2 @@ -export const ipfsHttpClient = '' +export const ipfsHttpClient = '^56.0.2' diff --git a/packages/ipfs-http-server/test/cors.js b/packages/ipfs-http-server/test/cors.js index 1808921211..7356baa92b 100644 --- a/packages/ipfs-http-server/test/cors.js +++ b/packages/ipfs-http-server/test/cors.js @@ -1,7 +1,7 @@ /* eslint max-nested-callbacks: ["error", 8] */ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { http } from './utils/http.js' import sinon from 'sinon' diff --git a/packages/ipfs-http-server/test/inject/bitswap.js b/packages/ipfs-http-server/test/inject/bitswap.js index 2c3ae4e2e6..c0baceb503 100644 --- a/packages/ipfs-http-server/test/inject/bitswap.js +++ b/packages/ipfs-http-server/test/inject/bitswap.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { CID } from 'multiformats/cid' import sinon from 'sinon' import { testHttpMethod } from '../utils/test-http-method.js' diff --git a/packages/ipfs-http-server/test/inject/block.js b/packages/ipfs-http-server/test/inject/block.js index f57b8faf5a..9cd422301f 100644 --- a/packages/ipfs-http-server/test/inject/block.js +++ b/packages/ipfs-http-server/test/inject/block.js @@ -1,7 +1,7 @@ /* eslint max-nested-callbacks: ["error", 8] */ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import FormData from 'form-data' import streamToPromise from 'stream-to-promise' import { testHttpMethod } from '../utils/test-http-method.js' diff --git a/packages/ipfs-http-server/test/inject/bootstrap.js b/packages/ipfs-http-server/test/inject/bootstrap.js index dfd915973e..9dfe2c94b5 100644 --- a/packages/ipfs-http-server/test/inject/bootstrap.js +++ b/packages/ipfs-http-server/test/inject/bootstrap.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import qs from 'qs' import { testHttpMethod } from '../utils/test-http-method.js' import { http } from '../utils/http.js' diff --git a/packages/ipfs-http-server/test/inject/browser-headers.js b/packages/ipfs-http-server/test/inject/browser-headers.js index 711e78f8a0..e5f3112356 100644 --- a/packages/ipfs-http-server/test/inject/browser-headers.js +++ b/packages/ipfs-http-server/test/inject/browser-headers.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import sinon from 'sinon' import { http } from '../utils/http.js' diff --git a/packages/ipfs-http-server/test/inject/config.js b/packages/ipfs-http-server/test/inject/config.js index bc9a0386d3..8cef1a0e25 100644 --- a/packages/ipfs-http-server/test/inject/config.js +++ b/packages/ipfs-http-server/test/inject/config.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import fs from 'fs' import FormData from 'form-data' import streamToPromise from 'stream-to-promise' diff --git a/packages/ipfs-http-server/test/inject/dag.js b/packages/ipfs-http-server/test/inject/dag.js index 73f3c8f128..b112442db7 100644 --- a/packages/ipfs-http-server/test/inject/dag.js +++ b/packages/ipfs-http-server/test/inject/dag.js @@ -1,7 +1,7 @@ /* eslint max-nested-callbacks: ["error", 8] */ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { Readable } from 'stream' import FormData from 'form-data' import streamToPromise from 'stream-to-promise' diff --git a/packages/ipfs-http-server/test/inject/dht.js b/packages/ipfs-http-server/test/inject/dht.js index 772bd416c0..416c4b423c 100644 --- a/packages/ipfs-http-server/test/inject/dht.js +++ b/packages/ipfs-http-server/test/inject/dht.js @@ -1,7 +1,7 @@ /* eslint max-nested-callbacks: ["error", 8] */ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { testHttpMethod } from '../utils/test-http-method.js' import { http } from '../utils/http.js' import sinon from 'sinon' diff --git a/packages/ipfs-http-server/test/inject/dns.js b/packages/ipfs-http-server/test/inject/dns.js index 322376a0c3..63da376aef 100644 --- a/packages/ipfs-http-server/test/inject/dns.js +++ b/packages/ipfs-http-server/test/inject/dns.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { testHttpMethod } from '../utils/test-http-method.js' import { http } from '../utils/http.js' import sinon from 'sinon' diff --git a/packages/ipfs-http-server/test/inject/files.js b/packages/ipfs-http-server/test/inject/files.js index 5cf7c801ed..55c33e90c9 100644 --- a/packages/ipfs-http-server/test/inject/files.js +++ b/packages/ipfs-http-server/test/inject/files.js @@ -2,7 +2,7 @@ /* eslint-env mocha */ import { randomBytes } from 'iso-random-stream' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import FormData from 'form-data' import streamToPromise from 'stream-to-promise' import { testHttpMethod } from '../utils/test-http-method.js' diff --git a/packages/ipfs-http-server/test/inject/id.js b/packages/ipfs-http-server/test/inject/id.js index 1e9a8c1dc7..4f0a8ea877 100644 --- a/packages/ipfs-http-server/test/inject/id.js +++ b/packages/ipfs-http-server/test/inject/id.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { testHttpMethod } from '../utils/test-http-method.js' import { http } from '../utils/http.js' import sinon from 'sinon' diff --git a/packages/ipfs-http-server/test/inject/key.js b/packages/ipfs-http-server/test/inject/key.js index f487a639ab..0bbeb72759 100644 --- a/packages/ipfs-http-server/test/inject/key.js +++ b/packages/ipfs-http-server/test/inject/key.js @@ -1,7 +1,7 @@ /* eslint max-nested-callbacks: ["error", 8] */ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { testHttpMethod } from '../utils/test-http-method.js' import { http } from '../utils/http.js' import sinon from 'sinon' diff --git a/packages/ipfs-http-server/test/inject/mfs/chmod.js b/packages/ipfs-http-server/test/inject/mfs/chmod.js index 2b7c6dfc4d..7c463fe81d 100644 --- a/packages/ipfs-http-server/test/inject/mfs/chmod.js +++ b/packages/ipfs-http-server/test/inject/mfs/chmod.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { http } from '../../utils/http.js' import sinon from 'sinon' import { testHttpMethod } from '../../utils/test-http-method.js' diff --git a/packages/ipfs-http-server/test/inject/mfs/cp.js b/packages/ipfs-http-server/test/inject/mfs/cp.js index 022f2ba07c..b8f1332eb0 100644 --- a/packages/ipfs-http-server/test/inject/mfs/cp.js +++ b/packages/ipfs-http-server/test/inject/mfs/cp.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { http } from '../../utils/http.js' import sinon from 'sinon' import { testHttpMethod } from '../../utils/test-http-method.js' diff --git a/packages/ipfs-http-server/test/inject/mfs/flush.js b/packages/ipfs-http-server/test/inject/mfs/flush.js index 875eeb0770..0f0f501248 100644 --- a/packages/ipfs-http-server/test/inject/mfs/flush.js +++ b/packages/ipfs-http-server/test/inject/mfs/flush.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { http } from '../../utils/http.js' import sinon from 'sinon' import { CID } from 'multiformats/cid' diff --git a/packages/ipfs-http-server/test/inject/mfs/ls.js b/packages/ipfs-http-server/test/inject/mfs/ls.js index cafaf41ce6..2ad0528e65 100644 --- a/packages/ipfs-http-server/test/inject/mfs/ls.js +++ b/packages/ipfs-http-server/test/inject/mfs/ls.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { http } from '../../utils/http.js' import sinon from 'sinon' import { CID } from 'multiformats/cid' diff --git a/packages/ipfs-http-server/test/inject/mfs/mkdir.js b/packages/ipfs-http-server/test/inject/mfs/mkdir.js index ad93c9a5db..fcad05a192 100644 --- a/packages/ipfs-http-server/test/inject/mfs/mkdir.js +++ b/packages/ipfs-http-server/test/inject/mfs/mkdir.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { http } from '../../utils/http.js' import sinon from 'sinon' import { testHttpMethod } from '../../utils/test-http-method.js' diff --git a/packages/ipfs-http-server/test/inject/mfs/mv.js b/packages/ipfs-http-server/test/inject/mfs/mv.js index 25ca841ebb..27c058267c 100644 --- a/packages/ipfs-http-server/test/inject/mfs/mv.js +++ b/packages/ipfs-http-server/test/inject/mfs/mv.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { http } from '../../utils/http.js' import sinon from 'sinon' import { testHttpMethod } from '../../utils/test-http-method.js' diff --git a/packages/ipfs-http-server/test/inject/mfs/read.js b/packages/ipfs-http-server/test/inject/mfs/read.js index d295655278..bc1c0702e7 100644 --- a/packages/ipfs-http-server/test/inject/mfs/read.js +++ b/packages/ipfs-http-server/test/inject/mfs/read.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { http } from '../../utils/http.js' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import sinon from 'sinon' diff --git a/packages/ipfs-http-server/test/inject/mfs/rm.js b/packages/ipfs-http-server/test/inject/mfs/rm.js index 2f318f81d0..0040fc9bf4 100644 --- a/packages/ipfs-http-server/test/inject/mfs/rm.js +++ b/packages/ipfs-http-server/test/inject/mfs/rm.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { http } from '../../utils/http.js' import sinon from 'sinon' import { testHttpMethod } from '../../utils/test-http-method.js' diff --git a/packages/ipfs-http-server/test/inject/mfs/stat.js b/packages/ipfs-http-server/test/inject/mfs/stat.js index 07d20790fa..5f6817971a 100644 --- a/packages/ipfs-http-server/test/inject/mfs/stat.js +++ b/packages/ipfs-http-server/test/inject/mfs/stat.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { http } from '../../utils/http.js' import sinon from 'sinon' import { CID } from 'multiformats/cid' diff --git a/packages/ipfs-http-server/test/inject/mfs/touch.js b/packages/ipfs-http-server/test/inject/mfs/touch.js index 11ab4986b1..f7b6b52b03 100644 --- a/packages/ipfs-http-server/test/inject/mfs/touch.js +++ b/packages/ipfs-http-server/test/inject/mfs/touch.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { http } from '../../utils/http.js' import sinon from 'sinon' import { testHttpMethod } from '../../utils/test-http-method.js' diff --git a/packages/ipfs-http-server/test/inject/mfs/write.js b/packages/ipfs-http-server/test/inject/mfs/write.js index 1c9c2d08c0..c6f0d5a08d 100644 --- a/packages/ipfs-http-server/test/inject/mfs/write.js +++ b/packages/ipfs-http-server/test/inject/mfs/write.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { http } from '../../utils/http.js' import { matchIterable } from '../../utils/match-iterable.js' import sinon from 'sinon' diff --git a/packages/ipfs-http-server/test/inject/name.js b/packages/ipfs-http-server/test/inject/name.js index 26b3a6d09a..5a9fda7075 100644 --- a/packages/ipfs-http-server/test/inject/name.js +++ b/packages/ipfs-http-server/test/inject/name.js @@ -2,7 +2,7 @@ /* eslint-env mocha */ import { CID } from 'multiformats/cid' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { testHttpMethod } from '../utils/test-http-method.js' import { http } from '../utils/http.js' import sinon from 'sinon' diff --git a/packages/ipfs-http-server/test/inject/object.js b/packages/ipfs-http-server/test/inject/object.js index 0a3b079bd2..d1c77bcf6a 100644 --- a/packages/ipfs-http-server/test/inject/object.js +++ b/packages/ipfs-http-server/test/inject/object.js @@ -1,7 +1,7 @@ /* eslint max-nested-callbacks: ["error", 8] */ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import fs from 'fs' import FormData from 'form-data' import streamToPromise from 'stream-to-promise' diff --git a/packages/ipfs-http-server/test/inject/pin.js b/packages/ipfs-http-server/test/inject/pin.js index e954265302..c08d26309b 100644 --- a/packages/ipfs-http-server/test/inject/pin.js +++ b/packages/ipfs-http-server/test/inject/pin.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ /* eslint max-nested-callbacks: ["error", 8] */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { testHttpMethod } from '../utils/test-http-method.js' import { http } from '../utils/http.js' import sinon from 'sinon' diff --git a/packages/ipfs-http-server/test/inject/ping.js b/packages/ipfs-http-server/test/inject/ping.js index b490835d9f..2368f3003a 100644 --- a/packages/ipfs-http-server/test/inject/ping.js +++ b/packages/ipfs-http-server/test/inject/ping.js @@ -1,7 +1,7 @@ /* eslint max-nested-callbacks: ["error", 8] */ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { testHttpMethod } from '../utils/test-http-method.js' import { http } from '../utils/http.js' import sinon from 'sinon' diff --git a/packages/ipfs-http-server/test/inject/pubsub.js b/packages/ipfs-http-server/test/inject/pubsub.js index ad5d845003..c0baf67428 100644 --- a/packages/ipfs-http-server/test/inject/pubsub.js +++ b/packages/ipfs-http-server/test/inject/pubsub.js @@ -1,7 +1,7 @@ /* eslint max-nested-callbacks: ["error", 8] */ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { testHttpMethod } from '../utils/test-http-method.js' import { http } from '../utils/http.js' import FormData from 'form-data' diff --git a/packages/ipfs-http-server/test/inject/repo.js b/packages/ipfs-http-server/test/inject/repo.js index 466253b64d..a0cb3199a5 100644 --- a/packages/ipfs-http-server/test/inject/repo.js +++ b/packages/ipfs-http-server/test/inject/repo.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { testHttpMethod } from '../utils/test-http-method.js' import { http } from '../utils/http.js' import sinon from 'sinon' diff --git a/packages/ipfs-http-server/test/inject/resolve.js b/packages/ipfs-http-server/test/inject/resolve.js index 153856a28a..81bae019ff 100644 --- a/packages/ipfs-http-server/test/inject/resolve.js +++ b/packages/ipfs-http-server/test/inject/resolve.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { testHttpMethod } from '../utils/test-http-method.js' import { http } from '../utils/http.js' import sinon from 'sinon' diff --git a/packages/ipfs-http-server/test/inject/stats.js b/packages/ipfs-http-server/test/inject/stats.js index 6f0ccc2aae..7c9836a9b4 100644 --- a/packages/ipfs-http-server/test/inject/stats.js +++ b/packages/ipfs-http-server/test/inject/stats.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { testHttpMethod } from '../utils/test-http-method.js' import { http } from '../utils/http.js' import sinon from 'sinon' diff --git a/packages/ipfs-http-server/test/inject/swarm.js b/packages/ipfs-http-server/test/inject/swarm.js index 68af7d1344..1683348001 100644 --- a/packages/ipfs-http-server/test/inject/swarm.js +++ b/packages/ipfs-http-server/test/inject/swarm.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { testHttpMethod } from '../utils/test-http-method.js' import { http } from '../utils/http.js' import sinon from 'sinon' diff --git a/packages/ipfs-http-server/test/inject/version.js b/packages/ipfs-http-server/test/inject/version.js index 3196a3afc8..51c714da9e 100644 --- a/packages/ipfs-http-server/test/inject/version.js +++ b/packages/ipfs-http-server/test/inject/version.js @@ -1,6 +1,6 @@ /* eslint-env mocha */ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { testHttpMethod } from '../utils/test-http-method.js' import { http } from '../utils/http.js' import sinon from 'sinon' diff --git a/packages/ipfs-http-server/test/utils/test-http-method.js b/packages/ipfs-http-server/test/utils/test-http-method.js index be613228c4..ed3f672f92 100644 --- a/packages/ipfs-http-server/test/utils/test-http-method.js +++ b/packages/ipfs-http-server/test/utils/test-http-method.js @@ -1,5 +1,5 @@ -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { http } from './http.js' const METHODS = [ diff --git a/packages/ipfs-message-port-client/.aegir.cjs b/packages/ipfs-message-port-client/.aegir.js similarity index 87% rename from packages/ipfs-message-port-client/.aegir.cjs rename to packages/ipfs-message-port-client/.aegir.js index 9651d6d0fc..5f0ca24907 100644 --- a/packages/ipfs-message-port-client/.aegir.cjs +++ b/packages/ipfs-message-port-client/.aegir.js @@ -1,8 +1,9 @@ -'use strict' +import path from 'path' +import esbuild from 'esbuild' +import EchoServer from 'aegir/echo-server' +import { fileURLToPath } from 'url' -const path = require('path') -const esbuild = require('esbuild') -const EchoServer = require('aegir/utils/echo-server') +const __dirname = path.dirname(fileURLToPath(import.meta.url)) /** @type {import('aegir').Options["build"]["config"]} */ const buildConfig = { @@ -20,7 +21,7 @@ const buildConfig = { } /** @type {import('aegir').PartialOptions} */ -module.exports = { +export default { build: { bundlesizeMax: '32KB', config: buildConfig diff --git a/packages/ipfs-message-port-client/package.json b/packages/ipfs-message-port-client/package.json index a9b154b28f..df90f156ae 100644 --- a/packages/ipfs-message-port-client/package.json +++ b/packages/ipfs-message-port-client/package.json @@ -39,7 +39,7 @@ "scripts": { "build": "aegir build", "test:interface:message-port-client": "aegir test -t browser --bail -f ./test/interface-message-port-client.js", - "lint": "aegir ts -p check && aegir lint", + "lint": "aegir lint", "clean": "rimraf ./dist", "dep-check": "aegir dep-check -i ipfs-core -i rimraf -i ipfs-core-types -i esbuild" }, @@ -53,7 +53,7 @@ "multiformats": "^9.5.1" }, "devDependencies": { - "aegir": "^36.0.1", + "aegir": "^37.0.11", "interface-ipfs-core": "^0.154.2", "ipfs-core": "^0.14.2", "ipfs-message-port-server": "^0.11.2", diff --git a/packages/ipfs-message-port-client/src/block.js b/packages/ipfs-message-port-client/src/block.js index 78aad6837e..73738ee363 100644 --- a/packages/ipfs-message-port-client/src/block.js +++ b/packages/ipfs-message-port-client/src/block.js @@ -40,12 +40,11 @@ BlockClient.prototype.get = async function get (cid, options = {}) { */ BlockClient.prototype.put = async function put (block, options = {}) { const { transfer } = options - // @ts-ignore - ipfs-unixfs-importer passes `progress` which causing errors + // @ts-expect-error - ipfs-unixfs-importer passes `progress` which causing errors // because functions can't be transferred. delete options.progress const result = await this.remote.put({ ...options, - // @ts-ignore PutOptions requires CID, we send EncodedCID block: block instanceof Uint8Array ? block : encodeBlock(block, transfer) }) return decodeCID(result.cid) diff --git a/packages/ipfs-message-port-client/src/client.js b/packages/ipfs-message-port-client/src/client.js index 9c98f8d507..4521186ee3 100644 --- a/packages/ipfs-message-port-client/src/client.js +++ b/packages/ipfs-message-port-client/src/client.js @@ -44,6 +44,7 @@ export class Client { */ constructor (namespace, methods, transport) { /** @type {RemoteService} */ + // @ts-expect-error types again this.remote = (new Service(namespace, methods, transport)) } } diff --git a/packages/ipfs-message-port-client/src/client/query.js b/packages/ipfs-message-port-client/src/client/query.js index 8f4369bb74..9f65324799 100644 --- a/packages/ipfs-message-port-client/src/client/query.js +++ b/packages/ipfs-message-port-client/src/client/query.js @@ -1,5 +1,5 @@ /** - * @typedef {Object} QueryOptions + * @typedef {object} QueryOptions * @property {AbortSignal} [signal] * @property {number} [timeout] * @property {Set} [transfer] @@ -40,7 +40,7 @@ export class Query { /** * Data that will be structure cloned over message channel. * - * @returns {Object} + * @returns {object} */ toJSON () { return this.input diff --git a/packages/ipfs-message-port-client/src/client/service.js b/packages/ipfs-message-port-client/src/client/service.js index 0548cdd97f..f0b97ce1ce 100644 --- a/packages/ipfs-message-port-client/src/client/service.js +++ b/packages/ipfs-message-port-client/src/client/service.js @@ -24,7 +24,7 @@ export class Service { this.transport = transport // Type script does not like using classes as some dicitionaries, so // we explicitly type it as dictionary. - /** @type {Object., Function>} */ + /** @type {Object, Function>} */ const api = this for (const method of methods) { /** diff --git a/packages/ipfs-message-port-client/src/core.js b/packages/ipfs-message-port-client/src/core.js index d49ae0e3c7..0719580658 100644 --- a/packages/ipfs-message-port-client/src/core.js +++ b/packages/ipfs-message-port-client/src/core.js @@ -10,7 +10,6 @@ import { encodeCallback } from 'ipfs-message-port-protocol/core' /** @type {(stream:ReadableStream) => AsyncIterable} */ -// @ts-ignore - browser-stream-to-it has no types import iterateReadableStream from 'browser-readablestream-to-it' import { parseMode, @@ -461,7 +460,6 @@ const asFileObject = (input) => { * @returns {Promise | Iterable>} */ const ensureIsByteStream = async (input) => { - // @ts-ignore it's (async)iterable const peekable = itPeekable(input) /** @type {any} value **/ diff --git a/packages/ipfs-message-port-protocol/.aegir.cjs b/packages/ipfs-message-port-protocol/.aegir.js similarity index 73% rename from packages/ipfs-message-port-protocol/.aegir.cjs rename to packages/ipfs-message-port-protocol/.aegir.js index 2c09cac6a8..673bfd2f4a 100644 --- a/packages/ipfs-message-port-protocol/.aegir.cjs +++ b/packages/ipfs-message-port-protocol/.aegir.js @@ -1,7 +1,6 @@ -'use strict' /** @type {import('aegir').PartialOptions} */ -module.exports = { +export default { build: { bundlesizeMax: '547B' } diff --git a/packages/ipfs-message-port-protocol/package.json b/packages/ipfs-message-port-protocol/package.json index 5589ae10cd..8a589c2911 100644 --- a/packages/ipfs-message-port-protocol/package.json +++ b/packages/ipfs-message-port-protocol/package.json @@ -69,7 +69,7 @@ "test:chrome-webworker": "aegir test -t webworker", "test:firefox": "aegir test -t browser -- --browser firefox", "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", - "lint": "aegir ts -p check && aegir lint", + "lint": "aegir lint", "clean": "rimraf ./dist", "dep-check": "aegir dep-check -i rimraf -i ipfs-core-types" }, @@ -78,7 +78,7 @@ "multiformats": "^9.5.1" }, "devDependencies": { - "aegir": "^36.0.1", + "aegir": "^37.0.11", "rimraf": "^3.0.2", "uint8arrays": "^3.0.0" }, diff --git a/packages/ipfs-message-port-protocol/src/block.js b/packages/ipfs-message-port-protocol/src/block.js index f4ee247cb4..791e58ba5b 100644 --- a/packages/ipfs-message-port-protocol/src/block.js +++ b/packages/ipfs-message-port-protocol/src/block.js @@ -2,7 +2,7 @@ * @typedef {import('./error').EncodedError} EncodedError * @typedef {import('./cid').EncodedCID} EncodedCID * - * @typedef {Object} EncodedRmResult + * @typedef {object} EncodedRmResult * @property {EncodedCID} cid * @property {EncodedError|undefined} [error] */ diff --git a/packages/ipfs-message-port-protocol/src/cid.js b/packages/ipfs-message-port-protocol/src/cid.js index a13cc23329..584dfcd238 100644 --- a/packages/ipfs-message-port-protocol/src/cid.js +++ b/packages/ipfs-message-port-protocol/src/cid.js @@ -1,7 +1,7 @@ import { CID } from 'multiformats/cid' /** - * @typedef {Object} EncodedCID + * @typedef {object} EncodedCID * @property {number} code * @property {object} multihash * @property {Uint8Array} multihash.digest @@ -33,16 +33,17 @@ export const encodeCID = (cid, transfer) => { */ export const decodeCID = encodedCID => { /** @type {CID} */ + // @ts-expect-error we are converting this into an object compatible with the CID class const cid = (encodedCID) - // @ts-ignore non-enumerable field that doesn't always get transferred + // @ts-expect-error non-enumerable field that doesn't always get transferred if (!cid._baseCache) { Object.defineProperty(cid, '_baseCache', { value: new Map() }) } - // @ts-ignore non-enumerable field that doesn't always get transferred + // @ts-expect-error non-enumerable field that doesn't always get transferred if (!cid.asCID) { Object.defineProperty(cid, 'asCID', { get: () => cid diff --git a/packages/ipfs-message-port-protocol/src/core.js b/packages/ipfs-message-port-protocol/src/core.js index 6d536b7b5e..a60bb325d7 100644 --- a/packages/ipfs-message-port-protocol/src/core.js +++ b/packages/ipfs-message-port-protocol/src/core.js @@ -4,20 +4,20 @@ import { encodeError, decodeError } from './error.js' /** * @template T - * @typedef {Object} RemoteIterable + * @typedef {object} RemoteIterable * @property {'RemoteIterable'} type * @property {MessagePort} port */ /** - * @typedef {Object} RemoteCallback + * @typedef {object} RemoteCallback * @property {'RemoteCallback'} type * @property {MessagePort} port */ /** * @template T - * @typedef {Object} RemoteYield + * @typedef {object} RemoteYield * @property {false} done * @property {T} value * @property {void} error @@ -25,7 +25,7 @@ import { encodeError, decodeError } from './error.js' /** * @template T - * @typedef {Object} RemoteDone + * @typedef {object} RemoteDone * @property {true} done * @property {T|void} value * @property {void} error @@ -33,7 +33,7 @@ import { encodeError, decodeError } from './error.js' /** * @typedef {import('./error').EncodedError} EncodedError - * @typedef {Object} RemoteError + * @typedef {object} RemoteError * @property {true} done * @property {void} value * @property {EncodedError} error diff --git a/packages/ipfs-message-port-protocol/src/dag.js b/packages/ipfs-message-port-protocol/src/dag.js index c375796edc..ae630c46eb 100644 --- a/packages/ipfs-message-port-protocol/src/dag.js +++ b/packages/ipfs-message-port-protocol/src/dag.js @@ -12,7 +12,7 @@ import { encodeCID, decodeCID } from './cid.js' /** * @typedef {JSONValue} DAGNode - * @typedef {Object} EncodedDAGNode + * @typedef {object} EncodedDAGNode * @property {DAGNode} dagNode * @property {CID[]} cids */ diff --git a/packages/ipfs-message-port-protocol/src/error.js b/packages/ipfs-message-port-protocol/src/error.js index 9b9a2e9967..1dae11a524 100644 --- a/packages/ipfs-message-port-protocol/src/error.js +++ b/packages/ipfs-message-port-protocol/src/error.js @@ -5,7 +5,7 @@ * @typedef {Error|ErrorData} EncodedError * * Properties added by err-code library - * @typedef {Object} ErrorExtension + * @typedef {object} ErrorExtension * @property {string} [code] * @property {string} [detail] */ @@ -15,7 +15,7 @@ */ /** - * @typedef {Object} ErrorData + * @typedef {object} ErrorData * @property {string} name * @property {string} message * @property {string|undefined} stack diff --git a/packages/ipfs-message-port-protocol/test/block.browser.js b/packages/ipfs-message-port-protocol/test/block.browser.js index b7477d40bf..af06a402a7 100644 --- a/packages/ipfs-message-port-protocol/test/block.browser.js +++ b/packages/ipfs-message-port-protocol/test/block.browser.js @@ -3,7 +3,7 @@ import { encodeBlock } from '../src/block.js' import { ipc } from './util.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' describe('block (browser)', function () { diff --git a/packages/ipfs-message-port-protocol/test/cid.browser.js b/packages/ipfs-message-port-protocol/test/cid.browser.js index 95e69b096a..bc21cfe64f 100644 --- a/packages/ipfs-message-port-protocol/test/cid.browser.js +++ b/packages/ipfs-message-port-protocol/test/cid.browser.js @@ -4,7 +4,7 @@ import { CID } from 'multiformats/cid' import { encodeCID, decodeCID } from '../src/cid.js' import { ipc } from './util.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' describe('cid (browser)', function () { this.timeout(10 * 1000) diff --git a/packages/ipfs-message-port-protocol/test/cid.spec.js b/packages/ipfs-message-port-protocol/test/cid.spec.js index 788873e535..4d273e08c2 100644 --- a/packages/ipfs-message-port-protocol/test/cid.spec.js +++ b/packages/ipfs-message-port-protocol/test/cid.spec.js @@ -3,7 +3,7 @@ import { CID } from 'multiformats/cid' import { encodeCID, decodeCID } from '../src/cid.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' describe('cid', function () { this.timeout(10 * 1000) diff --git a/packages/ipfs-message-port-protocol/test/core.browser.js b/packages/ipfs-message-port-protocol/test/core.browser.js index 8eba3c61c1..fc24095b37 100644 --- a/packages/ipfs-message-port-protocol/test/core.browser.js +++ b/packages/ipfs-message-port-protocol/test/core.browser.js @@ -8,7 +8,7 @@ import { decodeIterable } from '../src/core.js' import { ipc } from './util.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' describe('core', function () { diff --git a/packages/ipfs-message-port-protocol/test/dag.browser.js b/packages/ipfs-message-port-protocol/test/dag.browser.js index 1b78c3d92c..3277858ec4 100644 --- a/packages/ipfs-message-port-protocol/test/dag.browser.js +++ b/packages/ipfs-message-port-protocol/test/dag.browser.js @@ -4,7 +4,7 @@ import { CID } from 'multiformats/cid' import { encodeNode, decodeNode } from '../src/dag.js' import { ipc } from './util.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' describe('dag (browser)', function () { diff --git a/packages/ipfs-message-port-protocol/test/dag.spec.js b/packages/ipfs-message-port-protocol/test/dag.spec.js index 110a6e841e..facc96a9bf 100644 --- a/packages/ipfs-message-port-protocol/test/dag.spec.js +++ b/packages/ipfs-message-port-protocol/test/dag.spec.js @@ -3,7 +3,7 @@ import { CID } from 'multiformats/cid' import { encodeNode } from '../src/dag.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' describe('dag', function () { diff --git a/packages/ipfs-message-port-server/.aegir.cjs b/packages/ipfs-message-port-server/.aegir.js similarity index 73% rename from packages/ipfs-message-port-server/.aegir.cjs rename to packages/ipfs-message-port-server/.aegir.js index 8f801e3b0e..a671283701 100644 --- a/packages/ipfs-message-port-server/.aegir.cjs +++ b/packages/ipfs-message-port-server/.aegir.js @@ -1,7 +1,6 @@ -'use strict' /** @type {import('aegir').PartialOptions} */ -module.exports = { +export default { build: { bundlesizeMax: '8KB' } diff --git a/packages/ipfs-message-port-server/package.json b/packages/ipfs-message-port-server/package.json index d3df5dde8d..25ea56a380 100644 --- a/packages/ipfs-message-port-server/package.json +++ b/packages/ipfs-message-port-server/package.json @@ -63,7 +63,7 @@ "test:chrome-webworker": "aegir test -t webworker", "test:firefox": "aegir test -t browser -- --browser firefox", "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", - "lint": "aegir ts -p check && aegir lint", + "lint": "aegir lint", "clean": "rimraf ./dist", "dep-check": "aegir dep-check -i rimraf -i ipfs-core-types" }, @@ -74,7 +74,7 @@ "multiformats": "^9.5.1" }, "devDependencies": { - "aegir": "^36.0.1", + "aegir": "^37.0.11", "rimraf": "^3.0.2" }, "engines": { diff --git a/packages/ipfs-message-port-server/src/block.js b/packages/ipfs-message-port-server/src/block.js index 6f6115090d..15fa4f5840 100644 --- a/packages/ipfs-message-port-server/src/block.js +++ b/packages/ipfs-message-port-server/src/block.js @@ -21,11 +21,11 @@ export class BlockService { } /** - * @typedef {Object} GetResult + * @typedef {object} GetResult * @property {Uint8Array} block * @property {Set} transfer * - * @typedef {Object} GetQuery + * @typedef {object} GetQuery * @property {EncodedCID} cid * @property {number} [timeout] * @property {AbortSignal} [query.signal] @@ -42,11 +42,11 @@ export class BlockService { } /** - * @typedef {Object} PutResult + * @typedef {object} PutResult * @property {EncodedCID} cid * @property {Set} transfer * - * @typedef {Object} PutQuery + * @typedef {object} PutQuery * @property {Uint8Array} block * @property {EncodedCID|undefined} [cid] * @@ -65,7 +65,7 @@ export class BlockService { } /** - * @typedef {Object} RmQuery + * @typedef {object} RmQuery * @property {EncodedCID[]} cids * @property {boolean} [force] * @property {boolean} [quiet] @@ -87,12 +87,12 @@ export class BlockService { } /** - * @typedef {Object} StatQuery + * @typedef {object} StatQuery * @property {EncodedCID} cid * @property {number} [timeout] * @property {AbortSignal} [signal] * - * @typedef {Object} EncodedStatResult + * @typedef {object} EncodedStatResult * @property {EncodedCID} cid * @property {number} size * @@ -109,7 +109,7 @@ export class BlockService { } /** - * @param {Object} entry + * @param {object} entry * @param {CID} entry.cid * @param {Error|void} [entry.error] * @param {Set} transfer diff --git a/packages/ipfs-message-port-server/src/core.js b/packages/ipfs-message-port-server/src/core.js index 65f27ef387..50c8aa618e 100644 --- a/packages/ipfs-message-port-server/src/core.js +++ b/packages/ipfs-message-port-server/src/core.js @@ -34,11 +34,11 @@ import { decodeCID, encodeCID } from 'ipfs-message-port-protocol/cid' */ /** - * @typedef {Object} AddAllInput + * @typedef {object} AddAllInput * @property {EncodedAddAllInput} input * @property {RemoteCallback} [progressCallback] * - * @typedef {Object} AddInput + * @typedef {object} AddInput * @property {EncodedAddInput} input * @property {RemoteCallback} [progressCallback] * @@ -151,7 +151,7 @@ export class CoreService { } /** - * @typedef {Object} CatQuery + * @typedef {object} CatQuery * @property {string|EncodedCID} path * @property {number} [offset] * @property {number} [length] @@ -168,7 +168,7 @@ export class CoreService { } /** - * @typedef {Object} LsQuery + * @typedef {object} LsQuery * @property {string|EncodedCID} path * @property {boolean} [preload] * @property {boolean} [recursive] diff --git a/packages/ipfs-message-port-server/src/dag.js b/packages/ipfs-message-port-server/src/dag.js index 6ddc340c26..1f5e8b488b 100644 --- a/packages/ipfs-message-port-server/src/dag.js +++ b/packages/ipfs-message-port-server/src/dag.js @@ -18,7 +18,7 @@ export class DAGService { } /** - * @typedef {Object} PutDag + * @typedef {object} PutDag * @property {EncodedDAGNode} dagNode * @property {EncodedCID} [encodedCid] * @@ -33,12 +33,12 @@ export class DAGService { } /** - * @typedef {Object} EncodedGetResult + * @typedef {object} EncodedGetResult * @property {Set} transfer * @property {string} [remainderPath] * @property {EncodedDAGNode} value * - * @typedef {Object} GetDAG + * @typedef {object} GetDAG * @property {EncodedCID} cid * @property {string} [path] * @property {boolean} [localResolve] @@ -66,13 +66,13 @@ export class DAGService { } /** - * @typedef {Object} ResolveQuery + * @typedef {object} ResolveQuery * @property {EncodedCID|string} cid * @property {string} [path] * @property {number} [timeout] * @property {AbortSignal} [signal] * - * @typedef {Object} EncodedResolveResult + * @typedef {object} EncodedResolveResult * @property {EncodedCID} cid * @property {string} [remainderPath] * diff --git a/packages/ipfs-message-port-server/src/files.js b/packages/ipfs-message-port-server/src/files.js index 77dbb1510b..59135de745 100644 --- a/packages/ipfs-message-port-server/src/files.js +++ b/packages/ipfs-message-port-server/src/files.js @@ -19,7 +19,7 @@ export class FilesService { } /** - * @typedef {Object} StatQuery + * @typedef {object} StatQuery * @property {string} path * * @param {StatOptions & StatQuery} input diff --git a/packages/ipfs-message-port-server/src/server.js b/packages/ipfs-message-port-server/src/server.js index 785568c047..af42aae972 100644 --- a/packages/ipfs-message-port-server/src/server.js +++ b/packages/ipfs-message-port-server/src/server.js @@ -54,7 +54,7 @@ import { encodeError } from 'ipfs-message-port-protocol/error' /** * @template T - * @typedef {Object} QueryMessage + * @typedef {object} QueryMessage * @property {'query'} type * @property {Namespace} namespace * @property {Method} method @@ -63,13 +63,13 @@ import { encodeError } from 'ipfs-message-port-protocol/error' */ /** - * @typedef {Object} AbortMessage + * @typedef {object} AbortMessage * @property {'abort'} type * @property {string} id */ /** - * @typedef {Object} TransferOptions + * @typedef {object} TransferOptions * @property {Set} [transfer] */ diff --git a/packages/ipfs-message-port-server/test/basic.spec.js b/packages/ipfs-message-port-server/test/basic.spec.js index 2ab4257776..c04f87d495 100644 --- a/packages/ipfs-message-port-server/test/basic.spec.js +++ b/packages/ipfs-message-port-server/test/basic.spec.js @@ -3,7 +3,7 @@ import { Server } from '../src/server.js' import { IPFSService } from '../src/index.js' -import { expect } from 'aegir/utils/chai.js' +import { expect } from 'aegir/chai' describe('dag', function () { this.timeout(10 * 1000) diff --git a/packages/ipfs/.aegir.cjs b/packages/ipfs/.aegir.js similarity index 88% rename from packages/ipfs/.aegir.cjs rename to packages/ipfs/.aegir.js index c6cb492d46..4d424964be 100644 --- a/packages/ipfs/.aegir.cjs +++ b/packages/ipfs/.aegir.js @@ -1,10 +1,11 @@ -'use strict' +import getPort from 'aegir/get-port' +import { createServer } from 'ipfsd-ctl' +import EchoServer from 'aegir/echo-server' +import { sigServer } from '@libp2p/webrtc-star-signalling-server' +import path from 'path' +import { fileURLToPath } from 'url' -const getPort = require('aegir/utils/get-port') -const { createServer } = require('ipfsd-ctl') -const EchoServer = require('aegir/utils/echo-server') -const webRTCStarSigServer = require('libp2p-webrtc-star-signalling-server') -const path = require('path') +const __dirname = path.dirname(fileURLToPath(import.meta.url)) /** @type {import('aegir').Options["build"]["config"]} */ const esbuild = { @@ -22,7 +23,7 @@ const esbuild = { } /** @type {import('aegir').PartialOptions} */ -module.exports = { +export default { test: { browser: { config: { @@ -47,13 +48,13 @@ module.exports = { const ipfsdPort = await getPort() const signalAPort = await getPort() const signalBPort = await getPort() - const sigServerA = await webRTCStarSigServer.start({ + const sigServerA = await sigServer({ host: '127.0.0.1', port: signalAPort, metrics: false }) // the second signalling server is needed for the interface test 'should list peers only once even if they have multiple addresses' - const sigServerB = await webRTCStarSigServer.start({ + const sigServerB = await sigServer({ host: '127.0.0.1', port: signalBPort, metrics: false @@ -75,7 +76,7 @@ module.exports = { } }, { go: { - ipfsBin: require('go-ipfs').path() + ipfsBin: (await import('go-ipfs')).default.path() }, js: { ipfsClientModule: { diff --git a/packages/ipfs/package.json b/packages/ipfs/package.json index 0d71c0bdd4..2c8cf9d846 100644 --- a/packages/ipfs/package.json +++ b/packages/ipfs/package.json @@ -53,12 +53,9 @@ "url": "git+https://github.com/ipfs/js-ipfs.git" }, "scripts": { - "build": "run-s build:*", - "build:update-version": "node scripts/update-version.js", - "build:aegir": "aegir build", - "build:copy-cli": "copyfiles ./src/cli.js ./src/package.js ./dist", - "build:copy-package": "copyfiles ./dist/esm/package.json ./dist/src -u 2", - "lint": "aegir ts -p check && aegir lint", + "build": "aegir build", + "prepublishOnly": "node scripts/update-version.js", + "lint": "aegir lint", "test:interface:core": "aegir test -f test/interface-core.js", "test:interface:client": "aegir test -f test/interface-client.js", "test:interface:http-js": "aegir test -f test/interface-http-js.js", @@ -76,14 +73,15 @@ "update-notifier": "^5.0.0" }, "devDependencies": { + "@libp2p/webrtc-star-signalling-server": "^1.0.3", "@types/semver": "^7.3.4", "@types/update-notifier": "^5.0.0", - "aegir": "^36.0.1", + "aegir": "^37.0.11", "assert": "^2.0.0", "copyfiles": "^2.4.1", "cross-env": "^7.0.0", "electron-webrtc": "^0.3.0", - "go-ipfs": "0.11.0", + "go-ipfs": "^0.12.1", "interface-ipfs-core": "^0.154.2", "ipfs-client": "^0.7.8", "ipfs-core-types": "^0.10.2", @@ -92,9 +90,8 @@ "ipfs-utils": "^9.0.2", "ipfsd-ctl": "^10.0.4", "iso-url": "^1.0.0", - "libp2p-webrtc-star-signalling-server": "^0.1.1", "merge-options": "^3.0.4", - "mock-ipfs-pinning-service": "^0.1.2", + "mock-ipfs-pinning-service": "^0.4.1", "npm-run-all": "^4.1.5", "rimraf": "^3.0.2", "url": "^0.11.0", diff --git a/packages/ipfs/src/cli.js b/packages/ipfs/src/cli.js index b63e7ff2cd..a76d82fecd 100755 --- a/packages/ipfs/src/cli.js +++ b/packages/ipfs/src/cli.js @@ -10,7 +10,7 @@ */ import semver from 'semver' import * as pkg from './package.js' -import debug from 'debug' +import { logger } from '@libp2p/logger' import { print, getIpfs, getRepoPath } from 'ipfs-cli/utils' import { cli } from 'ipfs-cli' @@ -47,7 +47,7 @@ if (process.env.DEBUG) { }) } -const log = debug('ipfs:cli') +const log = logger('ipfs:cli') process.title = pkg.name @@ -81,9 +81,9 @@ async function main (argv) { const command = argv.slice(2) try { - const data = await cli(command, async (argv) => { + await cli(command, async (argv) => { if (!['daemon', 'init'].includes(command[0])) { - // @ts-ignore argv as no properties in common + // @ts-expect-error argv as no properties in common const { ipfs, isDaemon, cleanup } = await getIpfs(argv) ctx = { @@ -95,13 +95,7 @@ async function main (argv) { } argv.ctx = ctx - - return argv }) - - if (data) { - print(data) - } } catch (/** @type {any} */ err) { // TODO: export errors from ipfs-repo to use .code constants if (err.code === 'ERR_INVALID_REPO_VERSION') { diff --git a/packages/ipfs/src/index.js b/packages/ipfs/src/index.js index 8db9fd1321..2d103fbe65 100644 --- a/packages/ipfs/src/index.js +++ b/packages/ipfs/src/index.js @@ -1,10 +1,5 @@ import { create as createImport, - crypto as cryptoImport, - isIPFS as isIPFSImport, - CID as CIDImport, - multiaddr as multiaddrImport, - PeerId as PeerIdImport, globSource as globSourceImport, urlSource as urlSourceImport } from 'ipfs-core' @@ -17,11 +12,6 @@ import { */ export const create = createImport -export const crypto = cryptoImport -export const isIPFS = isIPFSImport -export const CID = CIDImport -export const multiaddr = multiaddrImport -export const PeerId = PeerIdImport export const globSource = globSourceImport export const urlSource = urlSourceImport export const path = pathImport diff --git a/packages/ipfs/src/package.js b/packages/ipfs/src/package.js index caf3e2eeb6..185472f743 100644 --- a/packages/ipfs/src/package.js +++ b/packages/ipfs/src/package.js @@ -1,4 +1,4 @@ export const name = 'ipfs' -export const version = '' +export const version = '0.62.2' export const node = '>=15.0.0' diff --git a/packages/ipfs/test/utils/factory.js b/packages/ipfs/test/utils/factory.js index 8162ba4436..f2a7385533 100644 --- a/packages/ipfs/test/utils/factory.js +++ b/packages/ipfs/test/utils/factory.js @@ -12,9 +12,6 @@ const merge = mergeOpts.bind({ ignoreUndefined: true }) let __dirname = '' if (isNode) { - // @ts-ignore need to set module to es2020 to use import.meta.url, which we do, - // but then the "--module" setting doesn't get used by the "--build" setting - // which we use to build types from jsdoc __dirname = dirname(fileURLToPath(import.meta.url)) } diff --git a/packages/ipfs/test/utils/mock-pinning-service.js b/packages/ipfs/test/utils/mock-pinning-service.js index c562531879..b931ee3fbe 100644 --- a/packages/ipfs/test/utils/mock-pinning-service.js +++ b/packages/ipfs/test/utils/mock-pinning-service.js @@ -2,14 +2,14 @@ import http from 'http' // @ts-expect-error no types import { setup } from 'mock-ipfs-pinning-service' -import getPort from 'aegir/utils/get-port.js' +import getPort from 'aegir/get-port' const defaultPort = 1139 const defaultToken = 'secret' export class PinningService { /** - * @param {Object} options + * @param {object} options * @param {number} [options.port] * @param {string|null} [options.token] * @returns {Promise} diff --git a/packages/ipfs/test/utils/mock-preload-node.js b/packages/ipfs/test/utils/mock-preload-node.js index 61add3802f..aaa9df6050 100644 --- a/packages/ipfs/test/utils/mock-preload-node.js +++ b/packages/ipfs/test/utils/mock-preload-node.js @@ -2,7 +2,7 @@ import http from 'http' import { URL } from 'iso-url' -import getPort from 'aegir/utils/get-port.js' +import getPort from 'aegir/get-port' export const defaultPort = 1138 export const defaultAddr = `/dnsaddr/localhost/tcp/${defaultPort}` @@ -46,7 +46,7 @@ export function createNode () { res.end() }) - // @ts-ignore + // @ts-expect-error server.start = async () => { const port = await getPort(defaultPort) return new Promise((resolve, reject) => { @@ -58,7 +58,7 @@ export function createNode () { }) }) } - // @ts-ignore + // @ts-expect-error server.stop = () => new Promise(resolve => server.close(resolve)) return server From e378a2874aa43e0a172b5bb61faf925aff58d160 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 6 May 2022 11:00:01 +0100 Subject: [PATCH 02/39] chore: update deps --- packages/interface-ipfs-core/package.json | 7 +------ packages/ipfs-cli/package.json | 8 ++++---- packages/ipfs-core-config/package.json | 2 +- packages/ipfs-core/package.json | 8 ++++---- packages/ipfs-core/src/version.js | 4 ++-- packages/ipfs-daemon/package.json | 6 +++--- packages/ipfs-grpc-server/package.json | 2 +- packages/ipfs-http-gateway/package.json | 2 +- packages/ipfs-http-server/package.json | 9 ++------- packages/ipfs-http-server/src/version.js | 2 +- packages/ipfs-message-port-client/package.json | 2 +- packages/ipfs/package.json | 4 ++-- 12 files changed, 23 insertions(+), 33 deletions(-) diff --git a/packages/interface-ipfs-core/package.json b/packages/interface-ipfs-core/package.json index c0eb992d65..81faf2c6e8 100644 --- a/packages/interface-ipfs-core/package.json +++ b/packages/interface-ipfs-core/package.json @@ -78,13 +78,8 @@ "ipfs-core-types": "^0.10.3", "ipfs-unixfs": "^6.0.3", "ipfs-unixfs-importer": "^9.0.3", -<<<<<<< HEAD - "ipfs-utils": "^9.0.2", - "ipns": "^1.0.0", -======= "ipfs-utils": "^9.0.6", - "ipns": "^0.16.0", ->>>>>>> origin/master + "ipns": "^1.0.0", "is-ipfs": "^6.0.1", "iso-random-stream": "^2.0.2", "it-all": "^1.0.4", diff --git a/packages/ipfs-cli/package.json b/packages/ipfs-cli/package.json index 7b90c14c87..44786d01a6 100644 --- a/packages/ipfs-cli/package.json +++ b/packages/ipfs-cli/package.json @@ -69,11 +69,11 @@ "err-code": "^3.0.1", "execa": "^6.1.0", "get-folder-size": "^3.1.0", - "ipfs-core": "^0.14.2", - "ipfs-core-types": "^0.10.2", - "ipfs-core-utils": "^0.14.2", + "ipfs-core": "^0.14.3", + "ipfs-core-types": "^0.10.3", + "ipfs-core-utils": "^0.14.3", "ipfs-daemon": "^0.12.2", - "ipfs-http-client": "^56.0.2", + "ipfs-http-client": "^56.0.3", "ipfs-repo": "^14.0.1", "ipfs-utils": "^9.0.6", "it-all": "^1.0.4", diff --git a/packages/ipfs-core-config/package.json b/packages/ipfs-core-config/package.json index b7f25767e3..3883a54db1 100644 --- a/packages/ipfs-core-config/package.json +++ b/packages/ipfs-core-config/package.json @@ -107,7 +107,7 @@ }, "devDependencies": { "aegir": "^37.0.11", - "ipfs-core-utils": "^0.14.2", + "ipfs-core-utils": "^0.14.3", "rimraf": "^3.0.2" } } diff --git a/packages/ipfs-core/package.json b/packages/ipfs-core/package.json index 6712d34121..f74535896d 100644 --- a/packages/ipfs-core/package.json +++ b/packages/ipfs-core/package.json @@ -97,14 +97,14 @@ "interface-datastore": "^6.0.2", "ipfs-bitswap": "^11.0.0", "ipfs-core-config": "^0.3.2", - "ipfs-core-types": "^0.10.2", - "ipfs-core-utils": "^0.14.2", - "ipfs-http-client": "^56.0.2", + "ipfs-core-types": "^0.10.3", + "ipfs-core-utils": "^0.14.3", + "ipfs-http-client": "^56.0.3", "ipfs-repo": "^14.0.1", "ipfs-unixfs": "^6.0.3", "ipfs-unixfs-exporter": "^7.0.3", "ipfs-unixfs-importer": "^9.0.3", - "ipfs-utils": "^9.0.2", + "ipfs-utils": "^9.0.6", "ipns": "^1.0.0", "is-domain-name": "^1.0.1", "is-ipfs": "^6.0.1", diff --git a/packages/ipfs-core/src/version.js b/packages/ipfs-core/src/version.js index ebc76f0d3c..1fbef2dbc2 100644 --- a/packages/ipfs-core/src/version.js +++ b/packages/ipfs-core/src/version.js @@ -1,4 +1,4 @@ -export const ipfsCore = '0.14.2' +export const ipfsCore = '0.14.3' export const commit = '' -export const interfaceIpfsCore = '^0.154.2' +export const interfaceIpfsCore = '^0.154.3' diff --git a/packages/ipfs-daemon/package.json b/packages/ipfs-daemon/package.json index 1ac2b43338..f1fb0b04c4 100644 --- a/packages/ipfs-daemon/package.json +++ b/packages/ipfs-daemon/package.json @@ -45,12 +45,12 @@ "@libp2p/webrtc-star": "^1.0.6", "@mapbox/node-pre-gyp": "^1.0.5", "debug": "^4.1.1", - "ipfs-core": "^0.14.2", - "ipfs-core-types": "^0.10.2", + "ipfs-core": "^0.14.3", + "ipfs-core-types": "^0.10.3", "ipfs-grpc-server": "^0.8.3", "ipfs-http-gateway": "^0.9.2", "ipfs-http-server": "^0.11.2", - "ipfs-utils": "^9.0.2", + "ipfs-utils": "^9.0.6", "just-safe-set": "^4.0.2", "libp2p": "next" }, diff --git a/packages/ipfs-grpc-server/package.json b/packages/ipfs-grpc-server/package.json index b1d2dcea75..68b93ff697 100644 --- a/packages/ipfs-grpc-server/package.json +++ b/packages/ipfs-grpc-server/package.json @@ -61,7 +61,7 @@ "devDependencies": { "@types/ws": "^8.5.3", "aegir": "^37.0.11", - "ipfs-core": "^0.14.2", + "ipfs-core": "^0.14.3", "it-all": "^1.0.4", "it-drain": "^1.0.3", "rimraf": "^3.0.2", diff --git a/packages/ipfs-http-gateway/package.json b/packages/ipfs-http-gateway/package.json index af8df3dff2..8800f52204 100644 --- a/packages/ipfs-http-gateway/package.json +++ b/packages/ipfs-http-gateway/package.json @@ -62,7 +62,7 @@ "@hapi/hapi": "^20.0.0", "debug": "^4.1.1", "hapi-pino": "^9.3.0", - "ipfs-core-types": "^0.10.2", + "ipfs-core-types": "^0.10.3", "ipfs-http-response": "^2.0.2", "is-ipfs": "^6.0.1", "it-last": "^1.0.4", diff --git a/packages/ipfs-http-server/package.json b/packages/ipfs-http-server/package.json index f3b8d1d205..8593b84565 100644 --- a/packages/ipfs-http-server/package.json +++ b/packages/ipfs-http-server/package.json @@ -53,8 +53,8 @@ "dlv": "^1.1.3", "err-code": "^3.0.1", "hapi-pino": "^9.3.0", - "ipfs-core-types": "^0.10.2", - "ipfs-core-utils": "^0.14.2", + "ipfs-core-types": "^0.10.3", + "ipfs-core-utils": "^0.14.3", "ipfs-http-gateway": "^0.9.2", "ipfs-unixfs": "^6.0.3", "it-all": "^1.0.4", @@ -82,12 +82,7 @@ "devDependencies": { "@types/hapi-pino": "^8.0.1", "@types/hapi__hapi": "^20.0.5", -<<<<<<< HEAD "aegir": "^37.0.11", -======= - "@types/node": "^17.0.23", - "aegir": "^36.0.1", ->>>>>>> origin/master "form-data": "^4.0.0", "ipfs-http-client": "^56.0.3", "iso-random-stream": "^2.0.2", diff --git a/packages/ipfs-http-server/src/version.js b/packages/ipfs-http-server/src/version.js index 19e8dd5ada..185e04611c 100644 --- a/packages/ipfs-http-server/src/version.js +++ b/packages/ipfs-http-server/src/version.js @@ -1,2 +1,2 @@ -export const ipfsHttpClient = '^56.0.2' +export const ipfsHttpClient = '^56.0.3' diff --git a/packages/ipfs-message-port-client/package.json b/packages/ipfs-message-port-client/package.json index 800e1f3086..4bf7741f32 100644 --- a/packages/ipfs-message-port-client/package.json +++ b/packages/ipfs-message-port-client/package.json @@ -55,7 +55,7 @@ "devDependencies": { "aegir": "^37.0.11", "interface-ipfs-core": "^0.154.2", - "ipfs-core": "^0.14.2", + "ipfs-core": "^0.14.3", "ipfs-message-port-server": "^0.11.2", "rimraf": "^3.0.2" }, diff --git a/packages/ipfs/package.json b/packages/ipfs/package.json index a167a47022..dcad39a89d 100644 --- a/packages/ipfs/package.json +++ b/packages/ipfs/package.json @@ -84,8 +84,8 @@ "go-ipfs": "^0.12.1", "interface-ipfs-core": "^0.154.2", "ipfs-client": "^0.7.8", - "ipfs-core-types": "^0.10.2", - "ipfs-http-client": "^56.0.2", + "ipfs-core-types": "^0.10.3", + "ipfs-http-client": "^56.0.3", "ipfs-interop": "^8.0.10", "ipfs-utils": "^9.0.6", "ipfsd-ctl": "^10.0.4", From d0a7873a430b4f0baa459c554bd4d9ae68a73844 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 6 May 2022 11:11:44 +0100 Subject: [PATCH 03/39] chore: remove link step in ci --- .github/workflows/test.yml | 38 -------------------------------------- 1 file changed, 38 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9016980158..19b7a1cf22 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,9 +18,6 @@ jobs: with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - with: - build: | - npm run link check: name: Check @@ -32,9 +29,6 @@ jobs: with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - with: - build: | - npm run link - run: | npm run lint npm run dep-check -- -- -- -p @@ -56,9 +50,6 @@ jobs: with: node-version: ${{ matrix.node }} - uses: ipfs/aegir/actions/cache-node-modules@master - with: - build: | - npm run link - run: npm run test:node -- --since ${{ github.event.pull_request.base.sha }} --concurrency 1 - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 with: @@ -76,9 +67,6 @@ jobs: with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - with: - build: | - npm run link - run: npm run test:chrome -- --since ${{ github.event.pull_request.base.sha }} --concurrency 1 - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 with: @@ -96,9 +84,6 @@ jobs: with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - with: - build: | - npm run link - run: npm run test:chrome-webworker -- --since ${{ github.event.pull_request.base.sha }} --concurrency 1 - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 with: @@ -116,9 +101,6 @@ jobs: with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - with: - build: | - npm run link - run: npm run test:firefox -- --since ${{ github.event.pull_request.base.sha }} --concurrency 1 - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 with: @@ -136,9 +118,6 @@ jobs: with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - with: - build: | - npm run link - run: npx playwright install --with-deps - run: npm run test:firefox-webworker -- --since ${{ github.event.pull_request.base.sha }} --concurrency 1 - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 @@ -157,9 +136,6 @@ jobs: with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - with: - build: | - npm run link - uses: GabrielBB/xvfb-action@v1 with: run: npm run test:electron-main -- --since ${{ github.event.pull_request.base.sha }} --concurrency 1 -- -- --bail @@ -179,9 +155,6 @@ jobs: with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - with: - build: | - npm run link - uses: GabrielBB/xvfb-action@v1 with: run: npm run test:electron-renderer -- --since ${{ github.event.pull_request.base.sha }} --concurrency 1 -- -- --bail @@ -207,12 +180,8 @@ jobs: with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - with: - build: | - npm run link - run: npm install - run: npm run build - - run: npm run link - run: npm run test:interop -- --since ${{ github.event.pull_request.base.sha }} --concurrency 1 -- -- -- -t ${{ matrix.type }} - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 with: @@ -242,7 +211,6 @@ jobs: node-version: lts/* - run: npm install - run: npm run build - - run: npm run link - run: npm run ${{ matrix.suite }} -- --since ${{ github.event.pull_request.base.sha }} --concurrency 1 -- -- -t ${{ matrix.type }} - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 with: @@ -260,9 +228,6 @@ jobs: with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - with: - build: | - npm run link - run: npx playwright install --with-deps - run: npm run test:interface:message-port-client -- --since ${{ github.event.pull_request.base.sha }} --concurrency 1 @@ -298,9 +263,6 @@ jobs: node-version: lts/* registry-url: 'https://registry.npmjs.org' - uses: ipfs/aegir/actions/cache-node-modules@master - with: - build: | - npm run link - uses: ipfs/aegir/actions/docker-login@master with: docker-token: ${{ secrets.DOCKER_TOKEN }} From c7b5ae15af8f21855d26c11b41e1c3ad1f61daf2 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 10 May 2022 17:24:02 +0100 Subject: [PATCH 04/39] chore: fix more tests --- packages/interface-ipfs-core/package.json | 24 ++--- .../interface-ipfs-core/src/dht/disabled.js | 5 +- .../interface-ipfs-core/src/dht/find-peer.js | 2 +- packages/interface-ipfs-core/src/get.js | 22 ++--- packages/interface-ipfs-core/src/ping/ping.js | 2 +- .../src/pubsub/subscribe.js | 17 ++-- .../ipfs-options-websockets-filter-all.js | 10 +-- packages/interface-ipfs-core/tsconfig.json | 4 +- packages/ipfs-cli/package.json | 24 ++--- packages/ipfs-cli/src/commands/daemon.js | 5 +- packages/ipfs-cli/tsconfig.json | 4 +- packages/ipfs-client/package.json | 10 +-- packages/ipfs-client/tsconfig.json | 4 +- packages/ipfs-core-config/package.json | 24 ++--- .../src/libp2p-pubsub-routers.browser.js | 1 + .../src/libp2p-pubsub-routers.js | 1 + packages/ipfs-core-config/tsconfig.json | 4 +- packages/ipfs-core-types/package.json | 25 +++--- packages/ipfs-core-types/src/dht/index.ts | 87 ++++++++++++++++++- packages/ipfs-core-types/tsconfig.json | 3 +- packages/ipfs-core-utils/package.json | 28 +++--- packages/ipfs-core-utils/src/to-url-string.js | 5 +- packages/ipfs-core-utils/tsconfig.json | 4 +- packages/ipfs-core/package.json | 30 ++++--- packages/ipfs-core/src/components/libp2p.js | 10 ++- packages/ipfs-core/src/preload.js | 6 +- .../test/utils/mock-preload-node-utils.js | 7 +- packages/ipfs-core/tsconfig.json | 4 +- packages/ipfs-daemon/package.json | 10 +-- packages/ipfs-daemon/tsconfig.json | 4 +- packages/ipfs-grpc-client/package.json | 14 ++- packages/ipfs-grpc-client/tsconfig.json | 4 +- packages/ipfs-grpc-protocol/package.json | 10 +-- packages/ipfs-grpc-protocol/tsconfig.json | 4 +- packages/ipfs-grpc-server/package.json | 10 +-- packages/ipfs-grpc-server/tsconfig.json | 4 +- packages/ipfs-http-client/package.json | 15 ++-- .../ipfs-http-client/src/dht/map-event.js | 15 ++-- .../src/lib/http-rpc-wire-format.js | 2 +- .../ipfs-http-client/src/pubsub/subscribe.js | 4 +- packages/ipfs-http-client/tsconfig.json | 4 +- packages/ipfs-http-gateway/package.json | 24 ++--- packages/ipfs-http-gateway/tsconfig.json | 4 +- packages/ipfs-http-response/package.json | 25 +++--- packages/ipfs-http-response/tsconfig.json | 5 +- packages/ipfs-http-server/package.json | 10 +-- .../ipfs-http-server/src/api/resources/dht.js | 63 +++----------- .../src/api/resources/pubsub.js | 4 +- packages/ipfs-http-server/src/utils/joi.js | 15 ++++ packages/ipfs-http-server/tsconfig.json | 4 +- .../ipfs-message-port-client/package.json | 10 +-- .../ipfs-message-port-client/tsconfig.json | 4 +- .../ipfs-message-port-protocol/package.json | 24 ++--- .../ipfs-message-port-protocol/tsconfig.json | 4 +- .../ipfs-message-port-server/package.json | 10 +-- .../ipfs-message-port-server/tsconfig.json | 4 +- packages/ipfs/package.json | 31 +++---- packages/ipfs/test/interface-http-go.js | 9 +- packages/ipfs/tsconfig.json | 4 +- 59 files changed, 397 insertions(+), 329 deletions(-) diff --git a/packages/interface-ipfs-core/package.json b/packages/interface-ipfs-core/package.json index 81faf2c6e8..c1f797cf52 100644 --- a/packages/interface-ipfs-core/package.json +++ b/packages/interface-ipfs-core/package.json @@ -4,21 +4,26 @@ "description": "A test suite and interface you can use to implement a IPFS core interface.", "type": "module", "main": "src/index.js", - "types": "types/src/index.d.ts", + "types": "dist/src/index.d.ts", "typesVersions": { "*": { "*": [ - "types/*", - "types/src/*" + "*", + "dist/*", + "dist/src/*", + "dist/src/*/index" ], - "types/*": [ - "types/*", - "types/src/*" + "src/*": [ + "*", + "dist/*", + "dist/src/*", + "dist/src/*/index" ] } }, "files": [ - "*", + "dist", + "src", "!**/*.tsbuildinfo" ], "eslintConfig": { @@ -30,9 +35,6 @@ "test/fixtures/*" ] }, - "publishConfig": { - "directory": "dist" - }, "exports": { ".": { "import": "./src/index.js" @@ -46,7 +48,7 @@ "path": false }, "scripts": { - "clean": "rimraf ./dist", + "clean": "aegir clean", "build": "aegir build && copyfiles './test/fixtures/**/*' ./dist", "lint": "aegir lint", "dep-check": "aegir dep-check -i ipfs-core-types -i rimraf -i copyfiles" diff --git a/packages/interface-ipfs-core/src/dht/disabled.js b/packages/interface-ipfs-core/src/dht/disabled.js index 7611430e57..11017a9ea8 100644 --- a/packages/interface-ipfs-core/src/dht/disabled.js +++ b/packages/interface-ipfs-core/src/dht/disabled.js @@ -3,6 +3,7 @@ import { expect } from 'aegir/chai' import { getDescribe, getIt } from '../utils/mocha.js' import all from 'it-all' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' /** * @typedef {import('ipfsd-ctl').Factory} Factory @@ -42,8 +43,8 @@ export function testDisabled (factory, options) { after(() => factory.clean()) it('should error when DHT not available', async () => { - await expect(all(nodeA.dht.get('/ipns/12D3KooWQMSMXmsBvs5YDEQ6tXsaFv9tjuzmDmEvusaiQSFdrJdN'))) - .to.eventually.be.rejectedWith('not available') + await expect(all(nodeA.dht.put('/ipns/12D3KooWBD9zgsogrYf1dum1TwTwe6k5xT8acGZ5PNeYmKf72qz2', uint8ArrayFromString('hello'), { verbose: true }))) + .to.eventually.be.rejected() }) }) } diff --git a/packages/interface-ipfs-core/src/dht/find-peer.js b/packages/interface-ipfs-core/src/dht/find-peer.js index 69708c76c4..0096358ea0 100644 --- a/packages/interface-ipfs-core/src/dht/find-peer.js +++ b/packages/interface-ipfs-core/src/dht/find-peer.js @@ -59,7 +59,7 @@ export function testFindPeer (factory, options) { const nodeAddresses = nodeBId.addresses.map((addr) => addr.nodeAddress()) const peerAddresses = finalPeer.peer.multiaddrs.map(ma => ma.nodeAddress()) - expect(id).to.equal(nodeBId.id) + expect(id.toString()).to.equal(nodeBId.id.toString()) expect(peerAddresses).to.deep.include(nodeAddresses[0]) }) diff --git a/packages/interface-ipfs-core/src/get.js b/packages/interface-ipfs-core/src/get.js index d541ff8a69..456fc486a0 100644 --- a/packages/interface-ipfs-core/src/get.js +++ b/packages/interface-ipfs-core/src/get.js @@ -234,12 +234,12 @@ export function testGet (factory, options) { // Check contents expect(output.map(f => uint8ArrayToString(f.body))).to.include.members([ - fixtures.directory.files['alice.txt'].toString(), - fixtures.directory.files['files/hello.txt'].toString(), - fixtures.directory.files['files/ipfs.txt'].toString(), - fixtures.directory.files['holmes.txt'].toString(), - fixtures.directory.files['jungle.txt'].toString(), - fixtures.directory.files['pp.txt'].toString() + uint8ArrayToString(fixtures.directory.files['alice.txt']), + uint8ArrayToString(fixtures.directory.files['files/hello.txt']), + uint8ArrayToString(fixtures.directory.files['files/ipfs.txt']), + uint8ArrayToString(fixtures.directory.files['holmes.txt']), + uint8ArrayToString(fixtures.directory.files['jungle.txt']), + uint8ArrayToString(fixtures.directory.files['pp.txt']) ]) }) @@ -269,9 +269,9 @@ export function testGet (factory, options) { // Check contents expect(output.map(f => uint8ArrayToString(f.body))).to.include.members([ - fixtures.directory.files['pp.txt'].toString(), - fixtures.directory.files['holmes.txt'].toString(), - fixtures.directory.files['jungle.txt'].toString() + uint8ArrayToString(fixtures.directory.files['pp.txt']), + uint8ArrayToString(fixtures.directory.files['holmes.txt']), + uint8ArrayToString(fixtures.directory.files['jungle.txt']) ]) }) @@ -379,8 +379,8 @@ export function testGet (factory, options) { // Check contents expect(output.map(f => uint8ArrayToString(f.body))).to.include.members([ - fixtures.directory.files['files/hello.txt'].toString(), - fixtures.directory.files['pp.txt'].toString() + uint8ArrayToString(fixtures.directory.files['files/hello.txt']), + uint8ArrayToString(fixtures.directory.files['pp.txt']) ]) }) diff --git a/packages/interface-ipfs-core/src/ping/ping.js b/packages/interface-ipfs-core/src/ping/ping.js index bca4c53fa4..c57fee2549 100644 --- a/packages/interface-ipfs-core/src/ping/ping.js +++ b/packages/interface-ipfs-core/src/ping/ping.js @@ -45,7 +45,7 @@ export function testPing (factory, options) { responses.forEach(expectIsPingResponse) const pongs = responses.filter(isPong) - expect(pongs.length).to.equal(count) + expect(pongs).to.have.lengthOf(count) }) it('should fail when pinging a peer that is not available', () => { diff --git a/packages/interface-ipfs-core/src/pubsub/subscribe.js b/packages/interface-ipfs-core/src/pubsub/subscribe.js index 78daa3f434..4ea7fd51a3 100644 --- a/packages/interface-ipfs-core/src/pubsub/subscribe.js +++ b/packages/interface-ipfs-core/src/pubsub/subscribe.js @@ -190,9 +190,11 @@ export function testSubscribe (factory, options) { // @ts-expect-error this is mocha return this.skip() } + const expectedString = 'should receive messages from a different node with floodsub' const topic = `floodsub-${nanoid()}` const ipfs1 = (await factory.spawn({ + test: true, ipfsOptions: { config: { Pubsub: { @@ -204,6 +206,7 @@ export function testSubscribe (factory, options) { const ipfs1Id = await ipfs1.id() const ipfs2 = (await factory.spawn({ type: isWebWorker ? 'go' : undefined, + test: true, ipfsOptions: { config: { Pubsub: { @@ -229,14 +232,15 @@ export function testSubscribe (factory, options) { msgStream2.resolve(msg) } - const abort1 = new AbortController() - const abort2 = new AbortController() await Promise.all([ - ipfs1.pubsub.subscribe(topic, sub1, { signal: abort1.signal }), - ipfs2.pubsub.subscribe(topic, sub2, { signal: abort2.signal }) + ipfs1.pubsub.subscribe(topic, sub1), + ipfs2.pubsub.subscribe(topic, sub2) ]) - await waitForPeers(ipfs2, topic, [ipfs1Id.id], 30000) + await Promise.all([ + waitForPeers(ipfs2, topic, [ipfs1Id.id], 30000), + waitForPeers(ipfs1, topic, [ipfs2Id.id], 30000) + ]) await ipfs2.pubsub.publish(topic, uint8ArrayFromString(expectedString)) @@ -247,9 +251,6 @@ export function testSubscribe (factory, options) { const sub2Msg = await msgStream2.promise expect(uint8ArrayToString(sub2Msg.data)).to.be.eql(expectedString) expect(sub2Msg.from.toString()).to.eql(ipfs2Id.id.toString()) - - abort1.abort() - abort2.abort() }) it('should receive messages from a different node', async () => { diff --git a/packages/interface-ipfs-core/src/utils/ipfs-options-websockets-filter-all.js b/packages/interface-ipfs-core/src/utils/ipfs-options-websockets-filter-all.js index 93be503ae0..88bc5c0ac1 100644 --- a/packages/interface-ipfs-core/src/utils/ipfs-options-websockets-filter-all.js +++ b/packages/interface-ipfs-core/src/utils/ipfs-options-websockets-filter-all.js @@ -1,17 +1,15 @@ import { WebSockets } from '@libp2p/websockets' import { all } from '@libp2p/websockets/filters' -const transportKey = WebSockets.prototype[Symbol.toStringTag] - export function ipfsOptionsWebsocketsFilterAll () { return { libp2p: { config: { - transport: { - [transportKey]: { + transports: [ + new WebSockets({ filter: all - } - } + }) + ] } } } diff --git a/packages/interface-ipfs-core/tsconfig.json b/packages/interface-ipfs-core/tsconfig.json index eb0c88b40c..d19e572e31 100644 --- a/packages/interface-ipfs-core/tsconfig.json +++ b/packages/interface-ipfs-core/tsconfig.json @@ -1,8 +1,8 @@ { "extends": "aegir/src/config/tsconfig.aegir.json", "compilerOptions": { - "outDir": "types", - "module": "es2020" + "outDir": "dist", + "emitDeclarationOnly": true }, "include": [ "src", diff --git a/packages/ipfs-cli/package.json b/packages/ipfs-cli/package.json index 44786d01a6..0d507c067c 100644 --- a/packages/ipfs-cli/package.json +++ b/packages/ipfs-cli/package.json @@ -10,21 +10,26 @@ "license": "(Apache-2.0 OR MIT)", "type": "module", "main": "src/index.js", - "types": "types/src/index.d.ts", + "types": "dist/src/index.d.ts", "typesVersions": { "*": { "*": [ - "types/*", - "types/src/*" + "*", + "dist/*", + "dist/src/*", + "dist/src/*/index" ], - "types/*": [ - "types/*", - "types/src/*" + "src/*": [ + "*", + "dist/*", + "dist/src/*", + "dist/src/*/index" ] } }, "files": [ - "*", + "dist", + "src", "!**/*.tsbuildinfo" ], "eslintConfig": { @@ -33,9 +38,6 @@ "sourceType": "module" } }, - "publishConfig": { - "directory": "dist" - }, "exports": { ".": { "import": "./src/index.js" @@ -52,7 +54,7 @@ "lint": "aegir lint", "test": "npm run test:node", "test:node": "aegir test -t node --cov", - "clean": "rimraf ./dist", + "clean": "aegir clean", "dep-check": "aegir dep-check -i ipfs-core-types", "build": "aegir build --no-bundle" }, diff --git a/packages/ipfs-cli/src/commands/daemon.js b/packages/ipfs-cli/src/commands/daemon.js index 81ee5c0046..b152186f26 100644 --- a/packages/ipfs-cli/src/commands/daemon.js +++ b/packages/ipfs-cli/src/commands/daemon.js @@ -1,7 +1,6 @@ import os from 'os' import fs from 'fs' -// @ts-expect-error no types -import toUri from 'multiaddr-to-uri' +import { multiaddrToUri } from '@multiformats/multiaddr-to-uri' import { ipfsPathHelp } from '../utils.js' import { isTest } from 'ipfs-utils/src/env.js' import { logger } from '@libp2p/logger' @@ -123,7 +122,7 @@ export default { if (daemon._httpApi && daemon._httpApi._apiServers) { daemon._httpApi._apiServers.forEach(apiServer => { - print(`Web UI available at ${toUri(apiServer.info.ma)}/webui`) + print(`Web UI available at ${multiaddrToUri(apiServer.info.ma)}/webui`) }) } } catch (/** @type {any} */ err) { diff --git a/packages/ipfs-cli/tsconfig.json b/packages/ipfs-cli/tsconfig.json index 852a79cbc1..9b1013e7b9 100644 --- a/packages/ipfs-cli/tsconfig.json +++ b/packages/ipfs-cli/tsconfig.json @@ -1,8 +1,8 @@ { "extends": "aegir/src/config/tsconfig.aegir.json", "compilerOptions": { - "outDir": "types", - "module": "es2020" + "outDir": "dist", + "emitDeclarationOnly": true }, "include": [ "src", diff --git a/packages/ipfs-client/package.json b/packages/ipfs-client/package.json index b86856c653..f94fd9c941 100644 --- a/packages/ipfs-client/package.json +++ b/packages/ipfs-client/package.json @@ -10,9 +10,10 @@ "license": "(Apache-2.0 OR MIT)", "type": "module", "main": "src/index.js", - "types": "types/src/index.d.ts", + "types": "dist/src/index.d.ts", "files": [ - "*", + "dist", + "src", "!**/*.tsbuildinfo" ], "eslintConfig": { @@ -21,9 +22,6 @@ "sourceType": "module" } }, - "publishConfig": { - "directory": "dist" - }, "exports": { ".": { "import": "./src/index.js" @@ -36,7 +34,7 @@ "scripts": { "build": "aegir build", "lint": "aegir lint", - "clean": "rimraf ./dist", + "clean": "aegir clean", "dep-check": "aegir dep-check -i aegir -i rimraf" }, "dependencies": { diff --git a/packages/ipfs-client/tsconfig.json b/packages/ipfs-client/tsconfig.json index 2c813c87c6..e6c324da5b 100644 --- a/packages/ipfs-client/tsconfig.json +++ b/packages/ipfs-client/tsconfig.json @@ -1,8 +1,8 @@ { "extends": "aegir/src/config/tsconfig.aegir.json", "compilerOptions": { - "outDir": "types", - "module": "es2020" + "outDir": "dist", + "emitDeclarationOnly": true }, "include": [ "src" diff --git a/packages/ipfs-core-config/package.json b/packages/ipfs-core-config/package.json index 3883a54db1..35680854f7 100644 --- a/packages/ipfs-core-config/package.json +++ b/packages/ipfs-core-config/package.json @@ -7,21 +7,26 @@ "bugs": "https://github.com/ipfs/js-ipfs/issues", "type": "module", "main": "src/index.js", - "types": "types/src/index.d.ts", + "types": "dist/src/index.d.ts", "typesVersions": { "*": { "*": [ - "types/*", - "types/src/*" + "*", + "dist/*", + "dist/src/*", + "dist/src/*/index" ], - "types/*": [ - "types/*", - "types/src/*" + "src/*": [ + "*", + "dist/*", + "dist/src/*", + "dist/src/*/index" ] } }, "files": [ - "*", + "dist", + "src", "!**/*.tsbuildinfo" ], "eslintConfig": { @@ -30,9 +35,6 @@ "sourceType": "module" } }, - "publishConfig": { - "directory": "dist" - }, "exports": { ".": { "import": "./src/index.js" @@ -72,7 +74,7 @@ }, "scripts": { "lint": "aegir lint", - "clean": "rimraf ./dist", + "clean": "aegir clean", "dep-check": "aegir dep-check -i aegir -i rimraf -i ipfs-core-utils", "build": "aegir build" }, diff --git a/packages/ipfs-core-config/src/libp2p-pubsub-routers.browser.js b/packages/ipfs-core-config/src/libp2p-pubsub-routers.browser.js index 478e9dc36e..b5390e67b4 100644 --- a/packages/ipfs-core-config/src/libp2p-pubsub-routers.browser.js +++ b/packages/ipfs-core-config/src/libp2p-pubsub-routers.browser.js @@ -6,6 +6,7 @@ import { GossipSub } from '@achingbrain/libp2p-gossipsub' export const routers = () => ({ gossipsub: new GossipSub({ allowPublishToZeroPeers: true, + fallbackToFloodsub: true, emitSelf: true }) }) diff --git a/packages/ipfs-core-config/src/libp2p-pubsub-routers.js b/packages/ipfs-core-config/src/libp2p-pubsub-routers.js index a36f640912..6e5217d8c3 100644 --- a/packages/ipfs-core-config/src/libp2p-pubsub-routers.js +++ b/packages/ipfs-core-config/src/libp2p-pubsub-routers.js @@ -7,6 +7,7 @@ import { FloodSub } from '@libp2p/floodsub' export const routers = () => ({ gossipsub: new GossipSub({ allowPublishToZeroPeers: true, + fallbackToFloodsub: true, emitSelf: true }), floodsub: new FloodSub({ diff --git a/packages/ipfs-core-config/tsconfig.json b/packages/ipfs-core-config/tsconfig.json index bb1385ef48..b3e9d0eb46 100644 --- a/packages/ipfs-core-config/tsconfig.json +++ b/packages/ipfs-core-config/tsconfig.json @@ -1,8 +1,8 @@ { "extends": "aegir/src/config/tsconfig.aegir.json", "compilerOptions": { - "outDir": "types", - "module": "es2020" + "outDir": "dist", + "emitDeclarationOnly": true }, "include": [ "src", diff --git a/packages/ipfs-core-types/package.json b/packages/ipfs-core-types/package.json index 597a1a4855..38f05c436c 100644 --- a/packages/ipfs-core-types/package.json +++ b/packages/ipfs-core-types/package.json @@ -2,35 +2,38 @@ "name": "ipfs-core-types", "version": "0.10.3", "description": "IPFS interface definitions used by implementations for API compatibility.", - "types": "types/src/index.d.ts", + "types": "dist/src/index.d.ts", "homepage": "https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-core-types#readme", "bugs": "https://github.com/ipfs/js-ipfs/issues", "scripts": { - "clean": "rimraf ./dist", + "clean": "aegir clean", "lint": "aegir lint", "build": "aegir build && copyfiles 'src/**/*' package.json README.md CHANGELOG.md COPYRIGHT LICENSE-APACHE LICENSE-MIT dist" }, "files": [ - "*", + "dist", + "src", "!**/*.tsbuildinfo" ], "typesVersions": { "*": { - "src/*": [ - "types/src/*", - "types/src/*/index" + "*": [ + "*", + "dist/*", + "dist/src/*", + "dist/src/*/index" ], - "src/": [ - "types/src/index" + "src/*": [ + "*", + "dist/*", + "dist/src/*", + "dist/src/*/index" ] } }, "eslintConfig": { "extends": "ipfs" }, - "publishConfig": { - "directory": "dist" - }, "repository": { "type": "git", "url": "git+https://github.com/ipfs/js-ipfs.git" diff --git a/packages/ipfs-core-types/src/dht/index.ts b/packages/ipfs-core-types/src/dht/index.ts index 5b9d38ab42..fa25233fd2 100644 --- a/packages/ipfs-core-types/src/dht/index.ts +++ b/packages/ipfs-core-types/src/dht/index.ts @@ -1,7 +1,7 @@ import type { AbortOptions } from '../utils' import type { CID } from 'multiformats/cid' import type { PeerId } from '@libp2p/interfaces/peer-id' -import type { QueryEvent } from '@libp2p/interfaces/dht' +import type { PeerInfo } from '@libp2p/interfaces/peer-info' export interface API { /** @@ -65,3 +65,88 @@ export interface API { export interface DHTProvideOptions extends AbortOptions { recursive?: boolean } + +export enum EventTypes { + SENDING_QUERY = 0, + PEER_RESPONSE, + FINAL_PEER, + QUERY_ERROR, + PROVIDER, + VALUE, + ADDING_PEER, + DIALING_PEER +} + +/** + * The types of messages set/received during DHT queries + */ +export enum MessageType { + PUT_VALUE = 0, + GET_VALUE, + ADD_PROVIDER, + GET_PROVIDERS, + FIND_NODE, + PING +} + +export type MessageName = keyof typeof MessageType + +export interface DHTRecord { + key: Uint8Array + value: Uint8Array + timeReceived?: Date +} + +export interface SendingQueryEvent { + type: EventTypes.SENDING_QUERY + name: 'SENDING_QUERY' +} + +export interface PeerResponseEvent { + from: PeerId + type: EventTypes.PEER_RESPONSE + name: 'PEER_RESPONSE' + messageType: MessageType + messageName: MessageName + providers: PeerInfo[] + closer: PeerInfo[] + record?: DHTRecord +} + +export interface FinalPeerEvent { + peer: PeerInfo + type: EventTypes.FINAL_PEER + name: 'FINAL_PEER' +} + +export interface QueryErrorEvent { + type: EventTypes.QUERY_ERROR + name: 'QUERY_ERROR' + error: Error +} + +export interface ProviderEvent { + type: EventTypes.PROVIDER + name: 'PROVIDER' + providers: PeerInfo[] +} + +export interface ValueEvent { + type: EventTypes.VALUE + name: 'VALUE' + value: Uint8Array +} + +export interface AddingPeerEvent { + type: EventTypes.ADDING_PEER + name: 'ADDING_PEER' + peer: PeerId +} + +export interface DialingPeerEvent { + peer: PeerId + type: EventTypes.DIALING_PEER + name: 'DIALING_PEER' +} + +export type QueryEvent = SendingQueryEvent | PeerResponseEvent | FinalPeerEvent | QueryErrorEvent | ProviderEvent | ValueEvent | AddingPeerEvent | DialingPeerEvent diff --git a/packages/ipfs-core-types/tsconfig.json b/packages/ipfs-core-types/tsconfig.json index 9445510450..8988b1e0a2 100644 --- a/packages/ipfs-core-types/tsconfig.json +++ b/packages/ipfs-core-types/tsconfig.json @@ -1,7 +1,8 @@ { "extends": "aegir/src/config/tsconfig.aegir.json", "compilerOptions": { - "outDir": "types" + "outDir": "dist", + "emitDeclarationOnly": true }, "include": [ "src" diff --git a/packages/ipfs-core-utils/package.json b/packages/ipfs-core-utils/package.json index 2af346df06..7977875b84 100644 --- a/packages/ipfs-core-utils/package.json +++ b/packages/ipfs-core-utils/package.json @@ -7,21 +7,26 @@ "bugs": "https://github.com/ipfs/js-ipfs/issues", "type": "module", "main": "src/index.js", - "types": "types/src/index.d.ts", + "types": "dist/src/index.d.ts", "typesVersions": { "*": { "*": [ - "types/*", - "types/src/*" + "*", + "dist/*", + "dist/src/*", + "dist/src/*/index" ], - "types/*": [ - "types/*", - "types/src/*" + "src/*": [ + "*", + "dist/*", + "dist/src/*", + "dist/src/*/index" ] } }, "files": [ - "*", + "dist", + "src", "!**/*.tsbuildinfo" ], "eslintConfig": { @@ -30,9 +35,6 @@ "sourceType": "module" } }, - "publishConfig": { - "directory": "dist" - }, "exports": { ".": { "import": "./src/index.js" @@ -105,10 +107,10 @@ "test:chrome-webworker": "aegir test -t webworker", "test:firefox": "aegir test -t browser -- --browser firefox", "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", - "test:electron-main": "aegir build --esm-tests && aegir test -t electron-main -f ./dist/cjs/node-test/**/*.spec.js", - "test:electron-renderer": "aegir build --esm-tests && aegir test -t electron-renderer -f ./dist/cjs/browser-test/**/*.spec.js", + "test:electron-main": "aegir build && aegir test -t electron-main -f ./dist/cjs/node-test/**/*.spec.js", + "test:electron-renderer": "aegir build && aegir test -t electron-renderer -f ./dist/cjs/browser-test/**/*.spec.js", "lint": "aegir lint", - "clean": "rimraf ./dist", + "clean": "aegir clean", "dep-check": "aegir dep-check -i rimraf -i ipfs-core-types", "build": "aegir build" }, diff --git a/packages/ipfs-core-utils/src/to-url-string.js b/packages/ipfs-core-utils/src/to-url-string.js index 9750cc14fd..088ad0a0fa 100644 --- a/packages/ipfs-core-utils/src/to-url-string.js +++ b/packages/ipfs-core-utils/src/to-url-string.js @@ -1,6 +1,5 @@ import { Multiaddr } from '@multiformats/multiaddr' -// @ts-expect-error no types -import multiAddrToUri from 'multiaddr-to-uri' +import { multiaddrToUri } from '@multiformats/multiaddr-to-uri' /** * @param {string|Multiaddr|URL} url - A string, multiaddr or URL to convert to a url string @@ -9,7 +8,7 @@ import multiAddrToUri from 'multiaddr-to-uri' export function toUrlString (url) { try { // @ts-expect-error - url = multiAddrToUri(new Multiaddr(url)) + url = multiaddrToUri(new Multiaddr(url)) } catch (/** @type {any} */ err) { } url = url.toString() diff --git a/packages/ipfs-core-utils/tsconfig.json b/packages/ipfs-core-utils/tsconfig.json index bb1385ef48..b3e9d0eb46 100644 --- a/packages/ipfs-core-utils/tsconfig.json +++ b/packages/ipfs-core-utils/tsconfig.json @@ -1,8 +1,8 @@ { "extends": "aegir/src/config/tsconfig.aegir.json", "compilerOptions": { - "outDir": "types", - "module": "es2020" + "outDir": "dist", + "emitDeclarationOnly": true }, "include": [ "src", diff --git a/packages/ipfs-core/package.json b/packages/ipfs-core/package.json index f74535896d..c9ee8cde70 100644 --- a/packages/ipfs-core/package.json +++ b/packages/ipfs-core/package.json @@ -10,21 +10,26 @@ "license": "(Apache-2.0 OR MIT)", "type": "module", "main": "src/index.js", - "types": "types/src/index.d.ts", + "types": "dist/src/index.d.ts", "typesVersions": { "*": { "*": [ - "types/*", - "types/src/*" + "*", + "dist/*", + "dist/src/*", + "dist/src/*/index" ], - "types/*": [ - "types/*", - "types/src/*" + "src/*": [ + "*", + "dist/*", + "dist/src/*", + "dist/src/*/index" ] } }, "files": [ - "*", + "dist", + "src", "!**/*.tsbuildinfo" ], "eslintConfig": { @@ -33,9 +38,6 @@ "sourceType": "module" } }, - "publishConfig": { - "directory": "dist" - }, "exports": { ".": { "import": "./src/index.js" @@ -59,10 +61,10 @@ "test:chrome-webworker": "aegir test -t webworker", "test:firefox": "aegir test -t browser -- --browser firefox", "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", - "test:electron-main": "aegir build --esm-tests && aegir test -t electron-main -f ./dist/cjs/node-test/*.spec.js", - "test:electron-renderer": "aegir build --esm-tests && aegir test -t electron-renderer -f ./dist/cjs/browser-test/*.spec.js", + "test:electron-main": "aegir build && aegir test -t electron-main -f ./dist/cjs/node-test/*.spec.js", + "test:electron-renderer": "aegir build && aegir test -t electron-renderer -f ./dist/cjs/browser-test/*.spec.js", "test:bootstrapers": "IPFS_TEST=bootstrapers aegir test -t browser -f test/bootstrappers.js", - "clean": "rimraf ./dist", + "clean": "aegir clean", "dep-check": "aegir dep-check -i interface-ipfs-core -i ipfs-core-types -i npm-run-all --i interface-blockstore" }, "dependencies": { @@ -141,7 +143,7 @@ "go-ipfs": "^0.12.1", "interface-blockstore-tests": "^2.0.2", "interface-ipfs-core": "^0.154.3", - "ipfsd-ctl": "^10.0.4", + "ipfsd-ctl": "^11.0.0", "iso-url": "^1.0.0", "nanoid": "^3.1.23", "npm-run-all": "^4.1.5", diff --git a/packages/ipfs-core/src/components/libp2p.js b/packages/ipfs-core/src/components/libp2p.js index 63999425e4..d6590467b0 100644 --- a/packages/ipfs-core/src/components/libp2p.js +++ b/packages/ipfs-core/src/components/libp2p.js @@ -14,6 +14,7 @@ import { Bootstrap } from '@libp2p/bootstrap' import { ipnsValidator } from 'ipns/validator' import { ipnsSelector } from 'ipns/selector' import { WebSockets } from '@libp2p/websockets' +import * as WebSocketsFilters from '@libp2p/websockets/filters' import { Mplex } from '@libp2p/mplex' import { NOISE } from '@chainsafe/libp2p-noise' @@ -121,7 +122,9 @@ function getLibp2pOptions ({ options, config, datastore, keychainConfig, peerId, peerRouters: [], peerDiscovery: [], transports: [ - new WebSockets() + new WebSockets({ + filter: WebSocketsFilters.all + }) ], streamMuxers: [ new Mplex() @@ -208,8 +211,9 @@ function getLibp2pOptions ({ options, config, datastore, keychainConfig, peerId, } if (!get(options, 'config.Discovery.MDNS.Enabled', get(config, 'Discovery.MDNS.Enabled', true))) { - // @ts-expect-error mdns property may not be defined - libp2pFinalConfig.peerDiscovery = libp2pFinalConfig.peerDiscovery?.filter(d => !(d?.mdns || false)) + libp2pFinalConfig.peerDiscovery = libp2pFinalConfig.peerDiscovery?.filter(d => { + return d != null && d[Symbol.toStringTag] !== '@libp2p/mdns' + }) } return libp2pFinalConfig diff --git a/packages/ipfs-core/src/preload.js b/packages/ipfs-core/src/preload.js index 1f92d20f70..8279be08f5 100644 --- a/packages/ipfs-core/src/preload.js +++ b/packages/ipfs-core/src/preload.js @@ -1,6 +1,4 @@ - -// @ts-expect-error no types -import toUri from 'multiaddr-to-uri' +import { multiaddrToUri } from '@multiformats/multiaddr-to-uri' import { logger } from '@libp2p/logger' import shuffle from 'array-shuffle' import { preload } from 'ipfs-core-config/preload' @@ -28,7 +26,7 @@ export function createPreloader (options = {}) { let stopped = true /** @type {AbortController[]} */ let requests = [] - const apiUris = options.addresses.map(toUri) + const apiUris = options.addresses.map((str) => multiaddrToUri(str)) // Avoid preloading the same CID over and over again const cache = hashlru(options.cache) diff --git a/packages/ipfs-core/test/utils/mock-preload-node-utils.js b/packages/ipfs-core/test/utils/mock-preload-node-utils.js index b9fc354794..bf271307a9 100644 --- a/packages/ipfs-core/test/utils/mock-preload-node-utils.js +++ b/packages/ipfs-core/test/utils/mock-preload-node-utils.js @@ -1,7 +1,6 @@ /* eslint-env browser */ -// @ts-expect-error no types -import toUri from 'multiaddr-to-uri' +import { multiaddrToUri } from '@multiformats/multiaddr-to-uri' import errCode from 'err-code' import HTTP from 'ipfs-utils/src/http.js' import { waitFor } from './wait-for.js' @@ -20,7 +19,7 @@ export const defaultAddr = `/dnsaddr/localhost/tcp/${defaultPort}` * @returns {Promise} */ export async function getPreloadCids (addr) { - const res = await HTTP.get(`${toUri(addr || defaultAddr)}/cids`) + const res = await HTTP.get(`${multiaddrToUri(addr || defaultAddr)}/cids`) return res.json() } @@ -30,7 +29,7 @@ export async function getPreloadCids (addr) { * @param {string} [addr] */ export function clearPreloadCids (addr) { - return HTTP.delete(`${toUri(addr || defaultAddr)}/cids`) + return HTTP.delete(`${multiaddrToUri(addr || defaultAddr)}/cids`) } /** diff --git a/packages/ipfs-core/tsconfig.json b/packages/ipfs-core/tsconfig.json index 42ecc54835..cace6261fa 100644 --- a/packages/ipfs-core/tsconfig.json +++ b/packages/ipfs-core/tsconfig.json @@ -1,8 +1,8 @@ { "extends": "aegir/src/config/tsconfig.aegir.json", "compilerOptions": { - "outDir": "types", - "module": "es2020" + "outDir": "dist", + "emitDeclarationOnly": true }, "include": [ "src", diff --git a/packages/ipfs-daemon/package.json b/packages/ipfs-daemon/package.json index f1fb0b04c4..2187e04a08 100644 --- a/packages/ipfs-daemon/package.json +++ b/packages/ipfs-daemon/package.json @@ -10,9 +10,10 @@ "license": "(Apache-2.0 OR MIT)", "type": "module", "main": "src/index.js", - "types": "types/src/index.d.ts", + "types": "dist/src/index.d.ts", "files": [ - "*", + "dist", + "src", "!**/*.tsbuildinfo" ], "exports": { @@ -26,9 +27,6 @@ "sourceType": "module" } }, - "publishConfig": { - "directory": "dist" - }, "repository": { "type": "git", "url": "git+https://github.com/ipfs/js-ipfs.git" @@ -37,7 +35,7 @@ "lint": "aegir lint", "test": "aegir test -t node", "test:node": "aegir test -t node -- --exit", - "clean": "rimraf ./dist", + "clean": "aegir clean", "dep-check": "aegir dep-check -i ipfs-core-types -i @mapbox/node-pre-gyp", "build": "aegir build --no-bundle" }, diff --git a/packages/ipfs-daemon/tsconfig.json b/packages/ipfs-daemon/tsconfig.json index 72874ac404..c6846f69fd 100644 --- a/packages/ipfs-daemon/tsconfig.json +++ b/packages/ipfs-daemon/tsconfig.json @@ -1,8 +1,8 @@ { "extends": "aegir/src/config/tsconfig.aegir.json", "compilerOptions": { - "outDir": "types", - "module": "es2020" + "outDir": "dist", + "emitDeclarationOnly": true }, "include": [ "src" diff --git a/packages/ipfs-grpc-client/package.json b/packages/ipfs-grpc-client/package.json index 5268f57425..7b5feed6f2 100644 --- a/packages/ipfs-grpc-client/package.json +++ b/packages/ipfs-grpc-client/package.json @@ -10,9 +10,10 @@ "license": "(Apache-2.0 OR MIT)", "type": "module", "main": "src/index.js", - "types": "types/src/index.d.ts", + "types": "dist/src/index.d.ts", "files": [ - "*", + "dist", + "src", "!**/*.tsbuildinfo" ], "exports": { @@ -26,9 +27,6 @@ "sourceType": "module" } }, - "publishConfig": { - "directory": "dist" - }, "browser": { "./src/grpc/transport.js": "./src/grpc/transport.browser.js", "./src/grpc/transport.node.js": "./src/grpc/transport.browser.js" @@ -45,10 +43,10 @@ "test:chrome-webworker": "aegir test -t webworker", "test:firefox": "aegir test -t browser -- --browser firefox", "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", - "test:electron-main": "aegir build --esm-tests && aegir test -t electron-main -f ./dist/cjs/node-test/*.spec.js", - "test:electron-renderer": "aegir build --esm-tests && aegir test -t electron-renderer -f ./dist/cjs/browser-test/*.spec.js", + "test:electron-main": "aegir build && aegir test -t electron-main -f ./dist/cjs/node-test/*.spec.js", + "test:electron-renderer": "aegir build && aegir test -t electron-renderer -f ./dist/cjs/browser-test/*.spec.js", "lint": "aegir lint", - "clean": "rimraf ./dist", + "clean": "aegir clean", "dep-check": "aegir dep-check -i aegir -i rimraf -i ipfs-grpc-protocol -i ipfs-core-types" }, "dependencies": { diff --git a/packages/ipfs-grpc-client/tsconfig.json b/packages/ipfs-grpc-client/tsconfig.json index 61d324e57a..c90cd3a743 100644 --- a/packages/ipfs-grpc-client/tsconfig.json +++ b/packages/ipfs-grpc-client/tsconfig.json @@ -1,8 +1,8 @@ { "extends": "aegir/src/config/tsconfig.aegir.json", "compilerOptions": { - "outDir": "types", - "module": "es2020" + "outDir": "dist", + "emitDeclarationOnly": true }, "include": [ "src" diff --git a/packages/ipfs-grpc-protocol/package.json b/packages/ipfs-grpc-protocol/package.json index 7fedf25ca5..84fdeecfb8 100644 --- a/packages/ipfs-grpc-protocol/package.json +++ b/packages/ipfs-grpc-protocol/package.json @@ -7,9 +7,10 @@ ], "type": "module", "main": "src/index.js", - "types": "types/src/index.d.ts", + "types": "dist/src/index.d.ts", "files": [ - "*", + "dist", + "src", "!**/*.tsbuildinfo" ], "eslintConfig": { @@ -18,9 +19,6 @@ "sourceType": "module" } }, - "publishConfig": { - "directory": "dist" - }, "exports": { ".": { "import": "./src/index.js" @@ -34,7 +32,7 @@ "url": "git+https://github.com/ipfs/js-ipfs.git" }, "scripts": { - "clean": "rimraf ./dist", + "clean": "aegir clean", "build": "npm run clean && mkdirp ./dist && pbjs ./src/*.proto -t json -o ./dist/ipfs.json && node ./scripts/update-index.js && npm run lint -- --fix && aegir build", "lint": "aegir lint" }, diff --git a/packages/ipfs-grpc-protocol/tsconfig.json b/packages/ipfs-grpc-protocol/tsconfig.json index 1a643a9338..8988b1e0a2 100644 --- a/packages/ipfs-grpc-protocol/tsconfig.json +++ b/packages/ipfs-grpc-protocol/tsconfig.json @@ -1,8 +1,8 @@ { "extends": "aegir/src/config/tsconfig.aegir.json", "compilerOptions": { - "outDir": "types", - "module": "es2020" + "outDir": "dist", + "emitDeclarationOnly": true }, "include": [ "src" diff --git a/packages/ipfs-grpc-server/package.json b/packages/ipfs-grpc-server/package.json index 68b93ff697..6ec45d4562 100644 --- a/packages/ipfs-grpc-server/package.json +++ b/packages/ipfs-grpc-server/package.json @@ -10,9 +10,10 @@ "license": "(Apache-2.0 OR MIT)", "type": "module", "main": "src/index.js", - "types": "types/src/index.d.ts", + "types": "dist/src/index.d.ts", "files": [ - "*", + "dist", + "src", "!**/*.tsbuildinfo" ], "exports": { @@ -26,9 +27,6 @@ "sourceType": "module" } }, - "publishConfig": { - "directory": "dist" - }, "repository": { "type": "git", "url": "git+https://github.com/ipfs/js-ipfs.git" @@ -37,7 +35,7 @@ "lint": "aegir lint", "test": "aegir test -t node", "test:node": "aegir test -t node --cov", - "clean": "rimraf ./dist", + "clean": "aegir clean", "dep-check": "aegir dep-check -i ipfs-grpc-protocol -i aegir -i ipfs-core -i rimraf -i ipfs-core-types", "build": "aegir build --no-bundle" }, diff --git a/packages/ipfs-grpc-server/tsconfig.json b/packages/ipfs-grpc-server/tsconfig.json index deb60942bd..5b011ba049 100644 --- a/packages/ipfs-grpc-server/tsconfig.json +++ b/packages/ipfs-grpc-server/tsconfig.json @@ -1,8 +1,8 @@ { "extends": "aegir/src/config/tsconfig.aegir.json", "compilerOptions": { - "outDir": "types", - "module": "es2020" + "outDir": "dist", + "emitDeclarationOnly": true }, "include": [ "src" diff --git a/packages/ipfs-http-client/package.json b/packages/ipfs-http-client/package.json index a5bd9a5836..190f553aee 100644 --- a/packages/ipfs-http-client/package.json +++ b/packages/ipfs-http-client/package.json @@ -9,10 +9,10 @@ "bugs": "https://github.com/ipfs/js-ipfs/issues", "license": "(Apache-2.0 OR MIT)", "type": "module", - "main": "src/index.js", - "types": "types/src/index.d.ts", + "types": "dist/src/index.d.ts", "files": [ - "*", + "dist", + "src", "!**/*.tsbuildinfo" ], "exports": { @@ -26,9 +26,6 @@ "sourceType": "module" } }, - "publishConfig": { - "directory": "dist" - }, "browser": { "ipfs-utils/src/files/glob-source": false, "go-ipfs": false, @@ -48,9 +45,9 @@ "test:chrome-webworker": "aegir test -t webworker", "test:firefox": "aegir test -t browser -- --browser firefox", "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", - "test:electron-renderer": "aegir build --esm-tests && aegir test -t electron-renderer -f ./dist/cjs/browser-test/*.spec.js", + "test:electron-renderer": "aegir build && aegir test -t electron-renderer -f ./dist/cjs/browser-test/*.spec.js", "lint": "aegir lint", - "clean": "rimraf ./dist", + "clean": "aegir clean", "dep-check": "aegir dep-check -i ipfs-core -i rimraf -i ipfs-core-types" }, "dependencies": { @@ -77,7 +74,7 @@ "aegir": "^37.0.11", "delay": "^5.0.0", "go-ipfs": "^0.12.1", - "ipfsd-ctl": "^10.0.4", + "ipfsd-ctl": "^11.0.0", "it-all": "^1.0.4", "it-first": "^1.0.4", "nock": "^13.0.2", diff --git a/packages/ipfs-http-client/src/dht/map-event.js b/packages/ipfs-http-client/src/dht/map-event.js index 1505f448d9..7a8777759a 100644 --- a/packages/ipfs-http-client/src/dht/map-event.js +++ b/packages/ipfs-http-client/src/dht/map-event.js @@ -18,16 +18,13 @@ import { peerIdFromString } from '@libp2p/peer-id' /** * @param {{Type: number, ID: string, Extra: string, Responses: {ID: string, Addrs: string[]}[]}} event - * @returns {import('@libp2p/interfaces/dht').QueryEvent} + * @returns {import('ipfs-core-types/src/dht').QueryEvent} */ export const mapEvent = (event) => { if (event.Type === SendingQuery) { return { - to: peerIdFromString(event.ID), name: 'SENDING_QUERY', - type: event.Type, - messageName: 'PUT_VALUE', - messageType: 0 + type: event.Type } } @@ -49,8 +46,10 @@ export const mapEvent = (event) => { if (event.Type === FinalPeer) { // dht.query ends with a FinalPeer event with no Responses + /** @type {import('@libp2p/interfaces/peer-info').PeerInfo} */ let peer = { - id: peerIdFromString(event.ID), + // @ts-expect-error go-ipfs does not return this + id: event.ID ?? peerIdFromString(event.ID), /** @type {Multiaddr[]} */ multiaddrs: [], protocols: [] @@ -66,7 +65,6 @@ export const mapEvent = (event) => { } return { - from: peerIdFromString(event.ID), name: 'FINAL_PEER', type: event.Type, peer @@ -75,7 +73,6 @@ export const mapEvent = (event) => { if (event.Type === QueryError) { return { - from: peerIdFromString(event.ID), name: 'QUERY_ERROR', type: event.Type, error: new Error(event.Extra) @@ -84,7 +81,6 @@ export const mapEvent = (event) => { if (event.Type === Provider) { return { - from: peerIdFromString(event.ID), name: 'PROVIDER', type: event.Type, providers: event.Responses.map(({ ID, Addrs }) => ({ id: peerIdFromString(ID), multiaddrs: Addrs.map(addr => new Multiaddr(addr)), protocols: [] })) @@ -93,7 +89,6 @@ export const mapEvent = (event) => { if (event.Type === Value) { return { - from: peerIdFromString(event.ID), name: 'VALUE', type: event.Type, value: uint8ArrayFromString(event.Extra, 'base64pad') diff --git a/packages/ipfs-http-client/src/lib/http-rpc-wire-format.js b/packages/ipfs-http-client/src/lib/http-rpc-wire-format.js index b5de24598b..1f48ead5f2 100644 --- a/packages/ipfs-http-client/src/lib/http-rpc-wire-format.js +++ b/packages/ipfs-http-client/src/lib/http-rpc-wire-format.js @@ -36,7 +36,7 @@ const rpcToBytes = mb => base64url.decode(mb) * @param {string} mb * @returns {bigint} */ -const rpcToBigInt = mb => BigInt(mb) +const rpcToBigInt = mb => BigInt(`0x${uint8ArrayToString(base64url.decode(mb), 'base16')}`) /** * @param {string} text diff --git a/packages/ipfs-http-client/src/pubsub/subscribe.js b/packages/ipfs-http-client/src/pubsub/subscribe.js index cb7ab4908b..853c47d4e0 100644 --- a/packages/ipfs-http-client/src/pubsub/subscribe.js +++ b/packages/ipfs-http-client/src/pubsub/subscribe.js @@ -109,8 +109,8 @@ async function readMessages (response, { onMessage, onEnd, onError }) { onMessage({ from: msg.from, data: rpcToBytes(msg.data), - sequenceNumber: rpcToBigInt(msg.sequenceNumber), - topic: rpcToText(msg.topic) + sequenceNumber: rpcToBigInt(msg.seqno), + topic: rpcToText(msg.topicIDs[0]) }) } catch (/** @type {any} */ err) { err.message = `Failed to parse pubsub message: ${err.message}` diff --git a/packages/ipfs-http-client/tsconfig.json b/packages/ipfs-http-client/tsconfig.json index b49e60562f..24385459e1 100644 --- a/packages/ipfs-http-client/tsconfig.json +++ b/packages/ipfs-http-client/tsconfig.json @@ -1,8 +1,8 @@ { "extends": "aegir/src/config/tsconfig.aegir.json", "compilerOptions": { - "outDir": "types", - "module": "es2020" + "outDir": "dist", + "emitDeclarationOnly": true }, "include": [ "src", diff --git a/packages/ipfs-http-gateway/package.json b/packages/ipfs-http-gateway/package.json index 8800f52204..78d2bd81e7 100644 --- a/packages/ipfs-http-gateway/package.json +++ b/packages/ipfs-http-gateway/package.json @@ -10,21 +10,26 @@ "license": "(Apache-2.0 OR MIT)", "type": "module", "main": "src/index.js", - "types": "types/src/index.d.ts", + "types": "dist/src/index.d.ts", "typesVersions": { "*": { "*": [ - "types/*", - "types/src/*" + "*", + "dist/*", + "dist/src/*", + "dist/src/*/index" ], - "types/*": [ - "types/*", - "types/src/*" + "src/*": [ + "*", + "dist/*", + "dist/src/*", + "dist/src/*/index" ] } }, "files": [ - "*", + "dist", + "src", "!**/*.tsbuildinfo" ], "exports": { @@ -41,9 +46,6 @@ "sourceType": "module" } }, - "publishConfig": { - "directory": "dist" - }, "repository": { "type": "git", "url": "git+https://github.com/ipfs/js-ipfs.git" @@ -52,7 +54,7 @@ "lint": "aegir lint", "test": "aegir test -t node", "test:node": "aegir test -t node --cov", - "clean": "rimraf ./dist", + "clean": "aegir clean", "dep-check": "aegir dep-check -i rimraf -i ipfs-core-types", "build": "aegir build --no-bundle" }, diff --git a/packages/ipfs-http-gateway/tsconfig.json b/packages/ipfs-http-gateway/tsconfig.json index deb60942bd..5b011ba049 100644 --- a/packages/ipfs-http-gateway/tsconfig.json +++ b/packages/ipfs-http-gateway/tsconfig.json @@ -1,8 +1,8 @@ { "extends": "aegir/src/config/tsconfig.aegir.json", "compilerOptions": { - "outDir": "types", - "module": "es2020" + "outDir": "dist", + "emitDeclarationOnly": true }, "include": [ "src" diff --git a/packages/ipfs-http-response/package.json b/packages/ipfs-http-response/package.json index 1da444083a..c1303d6e44 100644 --- a/packages/ipfs-http-response/package.json +++ b/packages/ipfs-http-response/package.json @@ -4,16 +4,20 @@ "description": "Creates an HTTP response from an IPFS Hash", "leadMaintainer": "Vasco Santos ", "main": "src/index.js", - "types": "types/src/index.d.ts", + "types": "dist/src/index.d.ts", "typesVersions": { "*": { "*": [ - "types/*", - "types/src/*" + "*", + "dist/*", + "dist/src/*", + "dist/src/*/index" ], - "types/*": [ - "types/*", - "types/src/*" + "src/*": [ + "*", + "dist/*", + "dist/src/*", + "dist/src/*/index" ] } }, @@ -29,14 +33,11 @@ "import": "./src/index.js" } }, - "publishConfig": { - "directory": "dist" - }, "scripts": { "lint": "aegir lint", - "clean": "rimraf ./dist", + "clean": "aegir clean", "build": "aegir build --no-bundle", - "pretest": "aegir build --esm-tests", + "pretest": "aegir build", "test": "aegir test -t node", "test:node": "aegir test -t node --cov", "dep-check": "aegir dep-check -i rimraf -i global" @@ -79,7 +80,7 @@ "get-stream": "^6.0.0", "global": "^4.4.0", "ipfs-core": "^0.14.3", - "ipfsd-ctl": "^10.0.4", + "ipfsd-ctl": "^11.0.0", "it-all": "^1.0.4", "rimraf": "^3.0.2", "uint8arrays": "^3.0.0" diff --git a/packages/ipfs-http-response/tsconfig.json b/packages/ipfs-http-response/tsconfig.json index 38425e4035..448e187c8c 100644 --- a/packages/ipfs-http-response/tsconfig.json +++ b/packages/ipfs-http-response/tsconfig.json @@ -1,9 +1,8 @@ { "extends": "aegir/src/config/tsconfig.aegir.json", "compilerOptions": { - "outDir": "types", - "module": "es2020", - "importsNotUsedAsValues": "preserve" + "outDir": "dist", + "emitDeclarationOnly": true }, "include": [ "src", diff --git a/packages/ipfs-http-server/package.json b/packages/ipfs-http-server/package.json index 8593b84565..36fbc6b21f 100644 --- a/packages/ipfs-http-server/package.json +++ b/packages/ipfs-http-server/package.json @@ -10,9 +10,10 @@ "license": "(Apache-2.0 OR MIT)", "type": "module", "main": "src/index.js", - "types": "types/src/index.d.ts", + "types": "dist/src/index.d.ts", "files": [ - "*", + "dist", + "src", "!**/*.tsbuildinfo" ], "exports": { @@ -26,9 +27,6 @@ "sourceType": "module" } }, - "publishConfig": { - "directory": "dist" - }, "repository": { "type": "git", "url": "git+https://github.com/ipfs/js-ipfs.git" @@ -37,7 +35,7 @@ "lint": "aegir lint", "test": "aegir test -t node", "test:node": "aegir test -t node --cov", - "clean": "rimraf ./dist", + "clean": "aegir clean", "dep-check": "aegir dep-check -i ipfs-http-client -i rimraf -i ipfs-core-types -i npm-run-all", "build": "run-s build:*", "build:update-version": "node scripts/update-version.js", diff --git a/packages/ipfs-http-server/src/api/resources/dht.js b/packages/ipfs-http-server/src/api/resources/dht.js index ad862518d5..08a120565d 100644 --- a/packages/ipfs-http-server/src/api/resources/dht.js +++ b/packages/ipfs-http-server/src/api/resources/dht.js @@ -8,38 +8,33 @@ import all from 'it-all' import Boom from '@hapi/boom' /** - * @typedef {import('@libp2p/interfaces/dht').QueryEvent} QueryEvent + * @typedef {import('ipfs-core-types/src/dht').QueryEvent} QueryEvent * @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId */ /** - * @param {PeerId} id * @param {QueryEvent} event */ -function mapQueryEvent (id, event) { +function mapQueryEvent (event) { + let id = '' let extra = '' const type = event.type let responses = null - if (event.name === 'SENDING_QUERY') { - id = event.to - } else if (event.name === 'PEER_RESPONSE') { - id = event.from + if (event.name === 'PEER_RESPONSE') { + id = event.from.toString() responses = event.closer.map(peerData => ({ ID: peerData.id, Addrs: peerData.multiaddrs })) } else if (event.name === 'QUERY_ERROR') { - id = event.from extra = event.error.message } else if (event.name === 'PROVIDER') { - id = event.from responses = event.providers.map(peerData => ({ ID: peerData.id, Addrs: peerData.multiaddrs })) } else if (event.name === 'VALUE') { - id = event.from extra = uint8ArrayToString(event.value, 'base64pad') } else if (event.name === 'ADDING_PEER') { responses = [{ @@ -47,9 +42,9 @@ function mapQueryEvent (id, event) { Addrs: [] }] } else if (event.name === 'DIALING_PEER') { - id = event.peer + id = event.peer.toString() } else if (event.name === 'FINAL_PEER') { - id = event.peer.id + id = event.peer.id.toString() responses = [{ ID: event.peer.id, Addrs: event.peer.multiaddrs @@ -72,7 +67,7 @@ export const findPeerResource = { stripUnknown: true }, query: Joi.object().keys({ - peerId: Joi.string().required(), + peerId: Joi.peerId().required(), timeout: Joi.timeout() }) .rename('arg', 'peerId', { @@ -111,17 +106,12 @@ export const findPeerResource = { signals.push(timeoutController.signal) } - const id = await ipfs.id({ - signal, - timeout - }) - return streamResponse(request, h, () => { return (async function * () { for await (const event of ipfs.dht.findPeer(peerId, { signal: anySignal(signals) })) { - yield mapQueryEvent(id.id, event) + yield mapQueryEvent(event) } if (timeoutController) { @@ -185,11 +175,6 @@ export const findProvsResource = { signals.push(timeoutController.signal) } - const id = await ipfs.id({ - signal, - timeout - }) - const providers = new Set() return streamResponse(request, h, () => { @@ -203,7 +188,7 @@ export const findProvsResource = { }) } - yield mapQueryEvent(id.id, event) + yield mapQueryEvent(event) if (providers.size >= numProviders) { break @@ -265,17 +250,12 @@ export const getResource = { signals.push(timeoutController.signal) } - const id = await ipfs.id({ - signal, - timeout - }) - return streamResponse(request, h, () => { return (async function * () { for await (const event of ipfs.dht.get(key, { signal: anySignal(signals) })) { - yield mapQueryEvent(id.id, event) + yield mapQueryEvent(event) } if (timeoutController) { @@ -333,17 +313,12 @@ export const provideResource = { signals.push(timeoutController.signal) } - const id = await ipfs.id({ - signal, - timeout - }) - return streamResponse(request, h, () => { return (async function * () { for await (const event of ipfs.dht.provide(cid, { signal: anySignal(signals) })) { - yield mapQueryEvent(id.id, event) + yield mapQueryEvent(event) } if (timeoutController) { @@ -442,17 +417,12 @@ export const putResource = { signals.push(timeoutController.signal) } - const id = await ipfs.id({ - signal, - timeout - }) - return streamResponse(request, h, () => { return (async function * () { for await (const event of ipfs.dht.put(key, value, { signal: anySignal(signals) })) { - yield mapQueryEvent(id.id, event) + yield mapQueryEvent(event) } if (timeoutController) { @@ -510,17 +480,12 @@ export const queryResource = { signals.push(timeoutController.signal) } - const id = await ipfs.id({ - signal, - timeout - }) - return streamResponse(request, h, () => { return (async function * () { for await (const event of ipfs.dht.query(key, { signal: anySignal(signals) })) { - yield mapQueryEvent(id.id, event) + yield mapQueryEvent(event) } if (timeoutController) { diff --git a/packages/ipfs-http-server/src/api/resources/pubsub.js b/packages/ipfs-http-server/src/api/resources/pubsub.js index ada2fcc1a7..b19de749e4 100644 --- a/packages/ipfs-http-server/src/api/resources/pubsub.js +++ b/packages/ipfs-http-server/src/api/resources/pubsub.js @@ -80,8 +80,8 @@ export const subscribeResource = { output.push({ from: msg.from, // TODO: switch to peerIdFromString(msg.from).toString() when go-ipfs defaults to CIDv1 data: base64url.encode(msg.data), - sequenceNumber: msg.sequenceNumber?.toString(), - topic: base64url.encode(uint8ArrayFromString(msg.topic)) + seqno: msg.sequenceNumber != null ? base64url.encode(uint8ArrayFromString(msg.sequenceNumber.toString(16), 'base16')) : undefined, + topicIDs: [base64url.encode(uint8ArrayFromString(msg.topic))] }) } diff --git a/packages/ipfs-http-server/src/utils/joi.js b/packages/ipfs-http-server/src/utils/joi.js index f848350654..a7371d86e3 100644 --- a/packages/ipfs-http-server/src/utils/joi.js +++ b/packages/ipfs-http-server/src/utils/joi.js @@ -3,6 +3,7 @@ import parseDuration from 'parse-duration' import { Multiaddr } from '@multiformats/multiaddr' import { toCidAndPath } from 'ipfs-core-utils/to-cid-and-path' import Joi from 'joi' +import { peerIdFromString } from '@libp2p/peer-id' /** * @param {*} value @@ -68,6 +69,20 @@ export default Joi } } }, + (joi) => { + return { + type: 'peerId', + base: joi.any(), + validate: requireIfRequired, + coerce (value, _helpers) { + if (!value) { + return + } + + return { value: peerIdFromString(value) } + } + } + }, (joi) => { return { type: 'ipfsPath', diff --git a/packages/ipfs-http-server/tsconfig.json b/packages/ipfs-http-server/tsconfig.json index 14b5f006f1..e6f92ccfd4 100644 --- a/packages/ipfs-http-server/tsconfig.json +++ b/packages/ipfs-http-server/tsconfig.json @@ -1,8 +1,8 @@ { "extends": "aegir/src/config/tsconfig.aegir.json", "compilerOptions": { - "outDir": "types", - "module": "es2020" + "outDir": "dist", + "emitDeclarationOnly": true }, "include": [ "src", diff --git a/packages/ipfs-message-port-client/package.json b/packages/ipfs-message-port-client/package.json index 4bf7741f32..7f197d03fe 100644 --- a/packages/ipfs-message-port-client/package.json +++ b/packages/ipfs-message-port-client/package.json @@ -12,9 +12,10 @@ "license": "(Apache-2.0 OR MIT)", "type": "module", "main": "src/index.js", - "types": "types/src/index.d.ts", + "types": "dist/src/index.d.ts", "files": [ - "*", + "dist", + "src", "!**/*.tsbuildinfo" ], "exports": { @@ -28,9 +29,6 @@ "sourceType": "module" } }, - "publishConfig": { - "directory": "dist" - }, "browser": {}, "repository": { "type": "git", @@ -40,7 +38,7 @@ "build": "aegir build", "test:interface:message-port-client": "aegir test -t browser --bail -f ./test/interface-message-port-client.js", "lint": "aegir lint", - "clean": "rimraf ./dist", + "clean": "aegir clean", "dep-check": "aegir dep-check -i ipfs-core -i rimraf -i ipfs-core-types -i esbuild" }, "dependencies": { diff --git a/packages/ipfs-message-port-client/tsconfig.json b/packages/ipfs-message-port-client/tsconfig.json index 0a1dc5e8de..d95a1d29d4 100644 --- a/packages/ipfs-message-port-client/tsconfig.json +++ b/packages/ipfs-message-port-client/tsconfig.json @@ -1,8 +1,8 @@ { "extends": "aegir/src/config/tsconfig.aegir.json", "compilerOptions": { - "outDir": "types", - "module": "es2020" + "outDir": "dist", + "emitDeclarationOnly": true }, "include": [ "src" diff --git a/packages/ipfs-message-port-protocol/package.json b/packages/ipfs-message-port-protocol/package.json index b117b3b6dd..baf38778a9 100644 --- a/packages/ipfs-message-port-protocol/package.json +++ b/packages/ipfs-message-port-protocol/package.json @@ -10,21 +10,26 @@ "license": "(Apache-2.0 OR MIT)", "type": "module", "main": "src/index.js", - "types": "types/src/index.d.ts", + "types": "dist/src/index.d.ts", "typesVersions": { "*": { "*": [ - "types/*", - "types/src/*" + "*", + "dist/*", + "dist/src/*", + "dist/src/*/index" ], - "types/*": [ - "types/*", - "types/src/*" + "src/*": [ + "*", + "dist/*", + "dist/src/*", + "dist/src/*/index" ] } }, "files": [ - "*", + "dist", + "src", "!**/*.tsbuildinfo" ], "eslintConfig": { @@ -33,9 +38,6 @@ "sourceType": "module" } }, - "publishConfig": { - "directory": "dist" - }, "exports": { ".": { "import": "./src/index.js" @@ -70,7 +72,7 @@ "test:firefox": "aegir test -t browser -- --browser firefox", "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", "lint": "aegir lint", - "clean": "rimraf ./dist", + "clean": "aegir clean", "dep-check": "aegir dep-check -i rimraf -i ipfs-core-types" }, "dependencies": { diff --git a/packages/ipfs-message-port-protocol/tsconfig.json b/packages/ipfs-message-port-protocol/tsconfig.json index deb60942bd..5b011ba049 100644 --- a/packages/ipfs-message-port-protocol/tsconfig.json +++ b/packages/ipfs-message-port-protocol/tsconfig.json @@ -1,8 +1,8 @@ { "extends": "aegir/src/config/tsconfig.aegir.json", "compilerOptions": { - "outDir": "types", - "module": "es2020" + "outDir": "dist", + "emitDeclarationOnly": true }, "include": [ "src" diff --git a/packages/ipfs-message-port-server/package.json b/packages/ipfs-message-port-server/package.json index d1bed4e0ec..0bcdd2ab9d 100644 --- a/packages/ipfs-message-port-server/package.json +++ b/packages/ipfs-message-port-server/package.json @@ -12,9 +12,10 @@ "license": "(Apache-2.0 OR MIT)", "type": "module", "main": "src/index.js", - "types": "types/src/index.d.ts", + "types": "dist/src/index.d.ts", "files": [ - "*", + "dist", + "src", "!**/*.tsbuildinfo" ], "exports": { @@ -46,9 +47,6 @@ "sourceType": "module" } }, - "publishConfig": { - "directory": "dist" - }, "browser": { "worker_threads": false }, @@ -64,7 +62,7 @@ "test:firefox": "aegir test -t browser -- --browser firefox", "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", "lint": "aegir lint", - "clean": "rimraf ./dist", + "clean": "aegir clean", "dep-check": "aegir dep-check -i rimraf -i ipfs-core-types" }, "dependencies": { diff --git a/packages/ipfs-message-port-server/tsconfig.json b/packages/ipfs-message-port-server/tsconfig.json index 133d3d71ce..cdc3856cfe 100644 --- a/packages/ipfs-message-port-server/tsconfig.json +++ b/packages/ipfs-message-port-server/tsconfig.json @@ -1,8 +1,8 @@ { "extends": "aegir/src/config/tsconfig.aegir.json", "compilerOptions": { - "outDir": "types", - "module": "es2020" + "outDir": "dist", + "emitDeclarationOnly": true }, "include": [ "src" diff --git a/packages/ipfs/package.json b/packages/ipfs/package.json index dcad39a89d..d012664c6f 100644 --- a/packages/ipfs/package.json +++ b/packages/ipfs/package.json @@ -9,22 +9,26 @@ "bugs": "https://github.com/ipfs/js-ipfs/issues", "license": "(Apache-2.0 OR MIT)", "type": "module", - "main": "src/index.js", - "types": "types/src/index.d.ts", + "types": "dist/src/index.d.ts", "typesVersions": { "*": { "*": [ - "types/*", - "types/src/*" + "*", + "dist/*", + "dist/src/*", + "dist/src/*/index" ], - "types/*": [ - "types/*", - "types/src/*" + "src/*": [ + "*", + "dist/*", + "dist/src/*", + "dist/src/*/index" ] } }, "files": [ - "*", + "dist", + "src", "!**/*.tsbuildinfo" ], "eslintConfig": { @@ -33,9 +37,6 @@ "sourceType": "module" } }, - "publishConfig": { - "directory": "dist" - }, "exports": { ".": { "import": "./src/index.js" @@ -60,9 +61,9 @@ "test:interface:client": "aegir test -f test/interface-client.js", "test:interface:http-js": "aegir test -f test/interface-http-js.js", "test:interface:http-go": "aegir test -f test/interface-http-go.js", - "test:interop": "cross-env DEBUG=$DEBUG IPFS_LOGGING=$IPFS_LOGGING IPFS_JS_EXEC=$PWD/src/cli.js IPFS_JS_MODULE=$PWD/dist IPFS_JS_HTTP_MODULE=$PWD/node_modules/ipfs-http-client LIBP2P_TCP_REUSEPORT=false ipfs-interop", + "test:interop": "cross-env DEBUG=$DEBUG IPFS_LOGGING=$IPFS_LOGGING IPFS_JS_EXEC=$PWD/src/cli.js LIBP2P_TCP_REUSEPORT=false ipfs-interop", "test:external": "aegir test-dependant", - "clean": "rimraf ./dist", + "clean": "aegir clean", "dep-check": "aegir dep-check -i ipfs-core-types -i @types/* -i npm-run-all -i copyfiles" }, "dependencies": { @@ -86,9 +87,9 @@ "ipfs-client": "^0.7.8", "ipfs-core-types": "^0.10.3", "ipfs-http-client": "^56.0.3", - "ipfs-interop": "^8.0.10", + "ipfs-interop": "ipfs/interop#feat/upgrade-to-esm-libp2p", "ipfs-utils": "^9.0.6", - "ipfsd-ctl": "^10.0.4", + "ipfsd-ctl": "^11.0.0", "iso-url": "^1.0.0", "merge-options": "^3.0.4", "mock-ipfs-pinning-service": "^0.4.2", diff --git a/packages/ipfs/test/interface-http-go.js b/packages/ipfs/test/interface-http-go.js index 45c38564f0..59f5e180e8 100644 --- a/packages/ipfs/test/interface-http-go.js +++ b/packages/ipfs/test/interface-http-go.js @@ -129,7 +129,14 @@ describe('interface-ipfs-core over ipfs-http-client tests against go-ipfs', () = ] }) - tests.dht(commonFactory) + tests.dht(commonFactory, { + skip: [ + { + name: 'should error when DHT not available', + reason: 'go returns a query error' + } + ] + }) tests.files(commonFactory, { skip: [ diff --git a/packages/ipfs/tsconfig.json b/packages/ipfs/tsconfig.json index 2f035740af..2e5e453229 100644 --- a/packages/ipfs/tsconfig.json +++ b/packages/ipfs/tsconfig.json @@ -1,8 +1,8 @@ { "extends": "aegir/src/config/tsconfig.aegir.json", "compilerOptions": { - "outDir": "types", - "module": "es2020" + "outDir": "dist", + "emitDeclarationOnly": true }, "include": [ "src", From 9f1591ed36f3c8ec773e5a22c4c6e2b1e370be9f Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 10 May 2022 17:31:00 +0100 Subject: [PATCH 05/39] chore: update typedef imports --- packages/ipfs-cli/src/commands/init.js | 2 +- packages/ipfs-core/src/components/storage.js | 2 +- packages/ipfs-core/src/ipns/index.js | 2 +- packages/ipfs-core/src/ipns/publisher.js | 4 ++-- packages/ipfs-core/src/ipns/republisher.js | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/ipfs-cli/src/commands/init.js b/packages/ipfs-cli/src/commands/init.js index fd54510cab..b19f94a2eb 100644 --- a/packages/ipfs-cli/src/commands/init.js +++ b/packages/ipfs-cli/src/commands/init.js @@ -5,7 +5,7 @@ import * as IPFS from 'ipfs-core' const log = logger('ipfs:cli:init') -/** @type {Record} */ +/** @type {Record} */ const keyTypes = { ed25519: 'Ed25519', rsa: 'RSA', diff --git a/packages/ipfs-core/src/components/storage.js b/packages/ipfs-core/src/components/storage.js index 02becb928e..034797ee9c 100644 --- a/packages/ipfs-core/src/components/storage.js +++ b/packages/ipfs-core/src/components/storage.js @@ -22,7 +22,7 @@ const log = logger('ipfs:components:peer:storage') * @typedef {import('../types').InitOptions} InitOptions * @typedef {import('../types').Print} Print * @typedef {import('ipfs-core-types/src/config').Config} IPFSConfig - * @typedef {import('libp2p-crypto').KeyType} KeyType + * @typedef {import('@libp2p/crypto/keys').KeyTypes} KeyType * @typedef {import('@libp2p/interfaces/keychain').KeyChain} Keychain * @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId */ diff --git a/packages/ipfs-core/src/ipns/index.js b/packages/ipfs-core/src/ipns/index.js index 65c1af89d2..c851cd0d0a 100644 --- a/packages/ipfs-core/src/ipns/index.js +++ b/packages/ipfs-core/src/ipns/index.js @@ -10,7 +10,7 @@ const log = logger('ipfs:ipns') const defaultRecordTtl = 60 * 1000 /** - * @typedef {import('libp2p-crypto').PrivateKey} PrivateKey + * @typedef {import('@libp2p/interfaces/keys').PrivateKey} PrivateKey * @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId */ diff --git a/packages/ipfs-core/src/ipns/publisher.js b/packages/ipfs-core/src/ipns/publisher.js index 8eb15015ae..64706cf92b 100644 --- a/packages/ipfs-core/src/ipns/publisher.js +++ b/packages/ipfs-core/src/ipns/publisher.js @@ -9,8 +9,8 @@ import * as ipns from 'ipns' const log = logger('ipfs:ipns:publisher') /** - * @typedef {import('libp2p-crypto').PrivateKey} PrivateKey - * @typedef {import('libp2p-crypto').PublicKey} PublicKey + * @typedef {import('@libp2p/interfaces/keys').PrivateKey} PrivateKey + * @typedef {import('@libp2p/interfaces/keys').PublicKey} PublicKey * @typedef {import('ipns').IPNSEntry} IPNSEntry * @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId */ diff --git a/packages/ipfs-core/src/ipns/republisher.js b/packages/ipfs-core/src/ipns/republisher.js index 168bf9bda1..a64162cea6 100644 --- a/packages/ipfs-core/src/ipns/republisher.js +++ b/packages/ipfs-core/src/ipns/republisher.js @@ -8,7 +8,7 @@ import { peerIdFromKeys } from '@libp2p/peer-id' const log = logger('ipfs:ipns:republisher') /** - * @typedef {import('libp2p-crypto').PrivateKey} PrivateKey + * @typedef {import('@libp2p/interfaces/keys').PrivateKey} PrivateKey * @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId */ From d81ef2ab339be32bcd9d257c59b3058a3a092a94 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 10 May 2022 18:24:12 +0100 Subject: [PATCH 06/39] chore: fix more tests --- package.json | 5 ++++- packages/ipfs-cli/src/commands/stats/bw.js | 5 +++-- packages/ipfs-core-types/package.json | 3 +-- packages/ipfs-core-types/src/bitswap/index.ts | 2 +- packages/ipfs-core-types/src/stats/index.ts | 18 +++++++++++++++++- .../ipfs-core/src/components/bitswap/stat.js | 2 +- packages/ipfs-core/src/components/stats/bw.js | 17 +++-------------- packages/ipfs-http-client/src/bitswap/stat.js | 3 ++- .../src/api/resources/bitswap.js | 2 +- .../ipfs-http-server/src/api/resources/id.js | 2 +- .../ipfs-http-server/src/api/resources/ping.js | 4 ++-- .../src/api/resources/stats.js | 2 +- 12 files changed, 37 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index 038cdcc539..f7aa1d9da4 100644 --- a/package.json +++ b/package.json @@ -308,5 +308,8 @@ "Jacob Karlsson ", "Jorropo ", "João Santos " - ] + ], + "dependencies": { + "import-meta-resolve": "^1.1.1" + } } diff --git a/packages/ipfs-cli/src/commands/stats/bw.js b/packages/ipfs-cli/src/commands/stats/bw.js index 92214b3104..f69630c869 100644 --- a/packages/ipfs-cli/src/commands/stats/bw.js +++ b/packages/ipfs-cli/src/commands/stats/bw.js @@ -1,4 +1,5 @@ import parseDuration from 'parse-duration' +import { coercePeerId } from '../../utils.js' export default { command: 'bw', @@ -8,7 +9,7 @@ export default { builder: { peer: { type: 'string', - default: '' + coerce: coercePeerId }, proto: { type: 'string', @@ -32,7 +33,7 @@ export default { /** * @param {object} argv * @param {import('../../types').Context} argv.ctx - * @param {string} argv.peer + * @param {import('@libp2p/interfaces/peer-id').PeerId} argv.peer * @param {string} argv.proto * @param {boolean} argv.poll * @param {number} argv.interval diff --git a/packages/ipfs-core-types/package.json b/packages/ipfs-core-types/package.json index 38f05c436c..c49ea33030 100644 --- a/packages/ipfs-core-types/package.json +++ b/packages/ipfs-core-types/package.json @@ -8,7 +8,7 @@ "scripts": { "clean": "aegir clean", "lint": "aegir lint", - "build": "aegir build && copyfiles 'src/**/*' package.json README.md CHANGELOG.md COPYRIGHT LICENSE-APACHE LICENSE-MIT dist" + "build": "aegir build" }, "files": [ "dist", @@ -54,7 +54,6 @@ }, "devDependencies": { "aegir": "^37.0.11", - "copyfiles": "^2.4.1", "rimraf": "^3.0.2" }, "contributors": [ diff --git a/packages/ipfs-core-types/src/bitswap/index.ts b/packages/ipfs-core-types/src/bitswap/index.ts index c3a9b8a48f..b239fac72e 100644 --- a/packages/ipfs-core-types/src/bitswap/index.ts +++ b/packages/ipfs-core-types/src/bitswap/index.ts @@ -61,7 +61,7 @@ export interface API { export interface Stats { provideBufLen: number wantlist: CID[] - peers: string[] + peers: PeerId[] blocksReceived: bigint dataReceived: bigint blocksSent: bigint diff --git a/packages/ipfs-core-types/src/stats/index.ts b/packages/ipfs-core-types/src/stats/index.ts index dfd300b2c5..43f69ce1e4 100644 --- a/packages/ipfs-core-types/src/stats/index.ts +++ b/packages/ipfs-core-types/src/stats/index.ts @@ -1,6 +1,7 @@ import type { AbortOptions } from '../utils' import type { API as BitswapAPI } from '../bitswap' import type { API as RepoAPI } from '../repo' +import type { PeerId } from '@libp2p/interfaces/peer-id' export interface API { bitswap: BitswapAPI['stat'] @@ -13,9 +14,24 @@ export interface API { } export interface BWOptions extends AbortOptions { - peer?: string + /** + * Specifies a peer to print bandwidth for + */ + peer?: PeerId + + /** + * Specifies a protocol to print bandwidth for + */ proto?: string + + /** + * Is used to yield bandwidth info at an interval + */ poll?: boolean + + /** + * The time interval to wait between updating output, if `poll` is `true`. + */ interval?: number | string } diff --git a/packages/ipfs-core/src/components/bitswap/stat.js b/packages/ipfs-core/src/components/bitswap/stat.js index 1ab18b3d77..7132824c69 100644 --- a/packages/ipfs-core/src/components/bitswap/stat.js +++ b/packages/ipfs-core/src/components/bitswap/stat.js @@ -17,7 +17,7 @@ export function createStat ({ network }) { provideBufLen: parseInt(snapshot.providesBufferLength.toString()), blocksReceived: BigInt(snapshot.blocksReceived.toString()), wantlist: Array.from(bitswap.getWantlist()).map(e => e[1].cid), - peers: bitswap.peers().map(id => id.toString()), + peers: bitswap.peers(), dupBlksReceived: BigInt(snapshot.dupBlksReceived.toString()), dupDataReceived: BigInt(snapshot.dupDataReceived.toString()), dataReceived: BigInt(snapshot.dataReceived.toString()), diff --git a/packages/ipfs-core/src/components/stats/bw.js b/packages/ipfs-core/src/components/stats/bw.js index 90e0c5b271..01d97044d8 100644 --- a/packages/ipfs-core/src/components/stats/bw.js +++ b/packages/ipfs-core/src/components/stats/bw.js @@ -1,21 +1,10 @@ import parseDuration from 'parse-duration' import errCode from 'err-code' import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' -import { peerIdFromString } from '@libp2p/peer-id' /** - * @typedef {object} BWOptions - * @property {string} [peer] - Specifies a peer to print bandwidth for - * @property {string} [proto] - Specifies a protocol to print bandwidth for - * @property {boolean} [poll] - Is used to yield bandwidth info at an interval - * @property {number|string} [interval=1000] - The time interval to wait between updating output, if `poll` is `true`. - * - * @typedef {object} BandwidthInfo - * @property {bigint} totalIn - * @property {bigint} totalOut - * @property {number} rateIn - * @property {number} rateOut - * + * @typedef {import('ipfs-core-types/src/stats').BWOptions} BWOptions + * @typedef {import('ipfs-core-types/src/stats').BWResult} BandwidthInfo * @typedef {import('libp2p').Libp2p} libp2p * @typedef {import('multiformats/cid').CID} CID * @typedef {import('ipfs-core-types/src/utils').AbortOptions} AbortOptions @@ -32,7 +21,7 @@ function getBandwidthStats (libp2p, opts) { if (!libp2p.metrics) { stats = undefined } else if (opts.peer) { - stats = libp2p.metrics.forPeer(peerIdFromString(opts.peer)) + stats = libp2p.metrics.forPeer(opts.peer) } else if (opts.proto) { stats = libp2p.metrics.forProtocol(opts.proto) } else { diff --git a/packages/ipfs-http-client/src/bitswap/stat.js b/packages/ipfs-http-client/src/bitswap/stat.js index fd5fff6659..eca5d98042 100644 --- a/packages/ipfs-http-client/src/bitswap/stat.js +++ b/packages/ipfs-http-client/src/bitswap/stat.js @@ -1,6 +1,7 @@ import { CID } from 'multiformats/cid' import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' +import { peerIdFromString } from '@libp2p/peer-id' /** * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions @@ -30,7 +31,7 @@ function toCoreInterface (res) { return { provideBufLen: res.ProvideBufLen, wantlist: (res.Wantlist || []).map((/** @type {{ '/': string }} */ k) => CID.parse(k['/'])), - peers: (res.Peers || []), + peers: (res.Peers || []).map((/** @type {string} */ str) => peerIdFromString(str)), blocksReceived: BigInt(res.BlocksReceived), dataReceived: BigInt(res.DataReceived), blocksSent: BigInt(res.BlocksSent), diff --git a/packages/ipfs-http-server/src/api/resources/bitswap.js b/packages/ipfs-http-server/src/api/resources/bitswap.js index e25cc77b41..ebfa855b4d 100644 --- a/packages/ipfs-http-server/src/api/resources/bitswap.js +++ b/packages/ipfs-http-server/src/api/resources/bitswap.js @@ -8,7 +8,7 @@ export const wantlistResource = { stripUnknown: true }, query: Joi.object().keys({ - peer: Joi.string(), + peer: Joi.peerId(), cidBase: Joi.string().default('base58btc'), timeout: Joi.timeout() }) diff --git a/packages/ipfs-http-server/src/api/resources/id.js b/packages/ipfs-http-server/src/api/resources/id.js index b36306b077..c572ad3d5a 100644 --- a/packages/ipfs-http-server/src/api/resources/id.js +++ b/packages/ipfs-http-server/src/api/resources/id.js @@ -9,7 +9,7 @@ export const idResource = { }, query: Joi.object().keys({ timeout: Joi.timeout(), - peerId: Joi.string() + peerId: Joi.peerId() }) .rename('arg', 'peerId', { override: true, diff --git a/packages/ipfs-http-server/src/api/resources/ping.js b/packages/ipfs-http-server/src/api/resources/ping.js index 6c2120aec7..4f03631145 100644 --- a/packages/ipfs-http-server/src/api/resources/ping.js +++ b/packages/ipfs-http-server/src/api/resources/ping.js @@ -12,7 +12,7 @@ export const pingResource = { }, query: Joi.object().keys({ count: Joi.number().integer().greater(0).default(10), - peerId: Joi.string().required(), + peerId: Joi.peerId().required(), timeout: Joi.timeout() }) .rename('arg', 'peerId', { @@ -47,7 +47,7 @@ export const pingResource = { } = request return streamResponse(request, h, () => pipe( - ipfs.ping(peerId.toString(), { + ipfs.ping(peerId, { count, signal, timeout diff --git a/packages/ipfs-http-server/src/api/resources/stats.js b/packages/ipfs-http-server/src/api/resources/stats.js index 195cfd17ba..d80bf9e83e 100644 --- a/packages/ipfs-http-server/src/api/resources/stats.js +++ b/packages/ipfs-http-server/src/api/resources/stats.js @@ -15,7 +15,7 @@ export const bwResource = { stripUnknown: true }, query: Joi.object().keys({ - peer: Joi.string(), + peer: Joi.peerId(), proto: Joi.string(), poll: Joi.boolean().default(false), interval: Joi.string().default('1s'), From 652adb7756a50885dd66ef390a31b25815d41228 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 11 May 2022 17:33:54 +0100 Subject: [PATCH 07/39] chore: fix node tests --- package.json | 5 +- packages/interface-ipfs-core/package.json | 5 +- packages/ipfs-cli/package.json | 6 +- packages/ipfs-cli/src/commands/add.js | 130 ++++++++--------- packages/ipfs-cli/src/commands/bitswap.js | 21 ++- .../ipfs-cli/src/commands/bitswap/index.js | 1 + .../ipfs-cli/src/commands/bitswap/stat.js | 36 ++--- .../ipfs-cli/src/commands/bitswap/unwant.js | 32 ++-- .../ipfs-cli/src/commands/bitswap/wantlist.js | 34 +++-- packages/ipfs-cli/src/commands/block.js | 20 ++- packages/ipfs-cli/src/commands/block/get.js | 24 +-- packages/ipfs-cli/src/commands/block/index.js | 1 + packages/ipfs-cli/src/commands/block/put.js | 44 +++--- packages/ipfs-cli/src/commands/block/rm.js | 30 ++-- packages/ipfs-cli/src/commands/block/stat.js | 30 ++-- packages/ipfs-cli/src/commands/bootstrap.js | 20 ++- .../ipfs-cli/src/commands/bootstrap/add.js | 30 ++-- .../ipfs-cli/src/commands/bootstrap/index.js | 1 + .../ipfs-cli/src/commands/bootstrap/list.js | 20 +-- .../ipfs-cli/src/commands/bootstrap/rm.js | 30 ++-- packages/ipfs-cli/src/commands/cat.js | 30 ++-- packages/ipfs-cli/src/commands/cid.js | 21 ++- packages/ipfs-cli/src/commands/cid/base32.js | 20 +-- packages/ipfs-cli/src/commands/cid/bases.js | 28 ++-- packages/ipfs-cli/src/commands/cid/codecs.js | 22 +-- packages/ipfs-cli/src/commands/cid/format.js | 36 ++--- packages/ipfs-cli/src/commands/cid/hashes.js | 22 +-- packages/ipfs-cli/src/commands/cid/index.js | 1 + packages/ipfs-cli/src/commands/commands.js | 38 ----- packages/ipfs-cli/src/commands/config.js | 51 ++++--- packages/ipfs-cli/src/commands/config/edit.js | 20 +-- .../ipfs-cli/src/commands/config/index.js | 1 + .../ipfs-cli/src/commands/config/profile.js | 18 ++- .../src/commands/config/profile/apply.js | 28 ++-- .../src/commands/config/profile/index.js | 1 + .../src/commands/config/profile/ls.js | 20 +-- .../ipfs-cli/src/commands/config/replace.js | 22 +-- packages/ipfs-cli/src/commands/config/show.js | 22 +-- packages/ipfs-cli/src/commands/daemon.js | 80 +++++----- packages/ipfs-cli/src/commands/dag.js | 20 ++- packages/ipfs-cli/src/commands/dag/export.js | 24 +-- packages/ipfs-cli/src/commands/dag/get.js | 40 ++--- packages/ipfs-cli/src/commands/dag/import.js | 32 ++-- packages/ipfs-cli/src/commands/dag/index.js | 1 + packages/ipfs-cli/src/commands/dag/put.js | 58 ++++---- packages/ipfs-cli/src/commands/dag/resolve.js | 24 +-- packages/ipfs-cli/src/commands/dht.js | 21 ++- .../ipfs-cli/src/commands/dht/find-peer.js | 26 ++-- .../src/commands/dht/find-providers.js | 32 ++-- packages/ipfs-cli/src/commands/dht/get.js | 26 ++-- packages/ipfs-cli/src/commands/dht/index.js | 1 + packages/ipfs-cli/src/commands/dht/provide.js | 32 ++-- packages/ipfs-cli/src/commands/dht/put.js | 26 ++-- packages/ipfs-cli/src/commands/dht/query.js | 30 ++-- packages/ipfs-cli/src/commands/dns.js | 26 ++-- packages/ipfs-cli/src/commands/files.js | 27 ++-- packages/ipfs-cli/src/commands/files/chmod.js | 44 +++--- packages/ipfs-cli/src/commands/files/cp.js | 40 ++--- packages/ipfs-cli/src/commands/files/flush.js | 24 +-- packages/ipfs-cli/src/commands/files/index.js | 1 + packages/ipfs-cli/src/commands/files/ls.js | 30 ++-- packages/ipfs-cli/src/commands/files/mkdir.js | 54 +++---- packages/ipfs-cli/src/commands/files/mv.js | 44 +++--- packages/ipfs-cli/src/commands/files/read.js | 30 ++-- packages/ipfs-cli/src/commands/files/rm.js | 26 ++-- packages/ipfs-cli/src/commands/files/stat.js | 42 +++--- packages/ipfs-cli/src/commands/files/touch.js | 46 +++--- packages/ipfs-cli/src/commands/files/write.js | 82 ++++++----- packages/ipfs-cli/src/commands/get.js | 42 +++--- packages/ipfs-cli/src/commands/id.js | 28 ++-- packages/ipfs-cli/src/commands/index.js | 3 +- packages/ipfs-cli/src/commands/init.js | 138 +++++++++--------- packages/ipfs-cli/src/commands/key.js | 20 ++- packages/ipfs-cli/src/commands/key/export.js | 30 ++-- packages/ipfs-cli/src/commands/key/gen.js | 30 ++-- packages/ipfs-cli/src/commands/key/import.js | 33 ++--- packages/ipfs-cli/src/commands/key/index.js | 1 + packages/ipfs-cli/src/commands/key/list.js | 20 +-- packages/ipfs-cli/src/commands/key/rename.js | 24 +-- packages/ipfs-cli/src/commands/key/rm.js | 22 +-- packages/ipfs-cli/src/commands/ls.js | 34 +++-- packages/ipfs-cli/src/commands/name.js | 15 +- packages/ipfs-cli/src/commands/name/index.js | 1 + .../ipfs-cli/src/commands/name/publish.js | 50 ++++--- packages/ipfs-cli/src/commands/name/pubsub.js | 25 +++- .../src/commands/name/pubsub/cancel.js | 24 +-- .../src/commands/name/pubsub/index.js | 1 + .../src/commands/name/pubsub/state.js | 22 +-- .../ipfs-cli/src/commands/name/pubsub/subs.js | 22 +-- .../ipfs-cli/src/commands/name/resolve.js | 42 +++--- packages/ipfs-cli/src/commands/object.js | 20 ++- packages/ipfs-cli/src/commands/object/data.js | 24 +-- packages/ipfs-cli/src/commands/object/get.js | 34 +++-- .../ipfs-cli/src/commands/object/index.js | 1 + .../ipfs-cli/src/commands/object/links.js | 30 ++-- packages/ipfs-cli/src/commands/object/new.js | 28 ++-- .../ipfs-cli/src/commands/object/patch.js | 24 ++- .../src/commands/object/patch/add-link.js | 36 ++--- .../src/commands/object/patch/append-data.js | 32 ++-- .../src/commands/object/patch/index.js | 1 + .../src/commands/object/patch/rm-link.js | 32 ++-- .../src/commands/object/patch/set-data.js | 32 ++-- packages/ipfs-cli/src/commands/object/put.js | 30 ++-- packages/ipfs-cli/src/commands/object/stat.js | 24 +-- packages/ipfs-cli/src/commands/pin.js | 20 ++- packages/ipfs-cli/src/commands/pin/add.js | 44 +++--- packages/ipfs-cli/src/commands/pin/index.js | 1 + packages/ipfs-cli/src/commands/pin/ls.js | 38 ++--- packages/ipfs-cli/src/commands/pin/rm.js | 32 ++-- packages/ipfs-cli/src/commands/ping.js | 34 +++-- packages/ipfs-cli/src/commands/pubsub.js | 20 ++- .../ipfs-cli/src/commands/pubsub/index.js | 1 + packages/ipfs-cli/src/commands/pubsub/ls.js | 20 +-- .../ipfs-cli/src/commands/pubsub/peers.js | 22 +-- packages/ipfs-cli/src/commands/pubsub/pub.js | 26 ++-- packages/ipfs-cli/src/commands/pubsub/sub.js | 22 +-- packages/ipfs-cli/src/commands/refs-local.js | 28 ++-- packages/ipfs-cli/src/commands/refs.js | 52 +++---- packages/ipfs-cli/src/commands/repo.js | 20 ++- packages/ipfs-cli/src/commands/repo/gc.js | 32 ++-- packages/ipfs-cli/src/commands/repo/index.js | 1 + packages/ipfs-cli/src/commands/repo/stat.js | 28 ++-- .../ipfs-cli/src/commands/repo/version.js | 20 +-- packages/ipfs-cli/src/commands/resolve.js | 34 +++-- packages/ipfs-cli/src/commands/shutdown.js | 20 +-- packages/ipfs-cli/src/commands/stats.js | 21 ++- .../ipfs-cli/src/commands/stats/bitswap.js | 5 +- packages/ipfs-cli/src/commands/stats/bw.js | 38 ++--- packages/ipfs-cli/src/commands/stats/index.js | 1 + packages/ipfs-cli/src/commands/stats/repo.js | 5 +- packages/ipfs-cli/src/commands/swarm.js | 20 ++- packages/ipfs-cli/src/commands/swarm/addrs.js | 33 +++-- .../src/commands/swarm/addrs/index.js | 1 + .../src/commands/swarm/addrs/local.js | 20 +-- .../ipfs-cli/src/commands/swarm/connect.js | 24 +-- .../ipfs-cli/src/commands/swarm/disconnect.js | 24 +-- packages/ipfs-cli/src/commands/swarm/index.js | 1 + packages/ipfs-cli/src/commands/swarm/peers.js | 20 +-- packages/ipfs-cli/src/commands/version.js | 36 ++--- packages/ipfs-cli/src/index.js | 2 +- packages/ipfs-cli/src/parser.js | 67 +++++---- packages/ipfs-cli/src/utils.js | 6 +- packages/ipfs-cli/test/bitswap.spec.js | 7 +- packages/ipfs-cli/test/commands.spec.js | 21 --- packages/ipfs-cli/test/dht.spec.js | 16 +- packages/ipfs-cli/test/id.spec.js | 4 +- packages/ipfs-cli/test/init.spec.js | 15 +- packages/ipfs-cli/test/key.spec.js | 6 +- packages/ipfs-cli/test/ping.spec.js | 20 +-- packages/ipfs-cli/test/swarm.spec.js | 5 +- packages/ipfs-cli/test/utils/ipfs-exec.js | 7 +- packages/ipfs-cli/test/utils/match-peer-id.js | 11 ++ packages/ipfs-core-config/package.json | 8 +- .../src/libp2p-pubsub-routers.browser.js | 2 +- .../src/libp2p-pubsub-routers.js | 2 +- packages/ipfs-core-utils/package.json | 2 +- packages/ipfs-core/.aegir.js | 2 +- packages/ipfs-core/package.json | 15 +- .../src/components/bootstrap/utils.js | 4 +- packages/ipfs-core/src/components/storage.js | 23 +-- packages/ipfs-core/src/ipns/routing/config.js | 2 +- packages/ipfs-core/test/create-node.spec.js | 6 +- packages/ipfs-core/test/init.spec.js | 23 ++- packages/ipfs-core/test/libp2p.spec.js | 4 +- packages/ipfs-core/test/name.spec.js | 28 ++-- packages/ipfs-daemon/package.json | 2 +- packages/ipfs-daemon/test/index.spec.js | 2 +- packages/ipfs-grpc-client/package.json | 2 +- packages/ipfs-grpc-client/test/agent.js | 4 +- packages/ipfs-grpc-server/package.json | 2 +- packages/ipfs-http-client/package.json | 3 +- packages/ipfs-http-client/test/node/agent.js | 24 ++- packages/ipfs-http-gateway/package.json | 4 +- packages/ipfs-http-gateway/src/index.js | 19 +-- .../ipfs-http-gateway/test/routes.spec.js | 6 +- packages/ipfs-http-response/package.json | 3 +- packages/ipfs-http-server/package.json | 6 +- .../ipfs-http-server/src/api/resources/dht.js | 2 +- packages/ipfs-http-server/src/index.js | 19 +-- .../ipfs-http-server/test/inject/bitswap.js | 9 +- packages/ipfs-http-server/test/inject/dht.js | 56 ++++--- packages/ipfs-http-server/test/inject/id.js | 5 +- packages/ipfs-http-server/test/inject/ping.js | 13 +- .../ipfs-http-server/test/inject/stats.js | 5 +- packages/ipfs/package.json | 2 +- 185 files changed, 2198 insertions(+), 1947 deletions(-) delete mode 100644 packages/ipfs-cli/src/commands/commands.js delete mode 100644 packages/ipfs-cli/test/commands.spec.js create mode 100644 packages/ipfs-cli/test/utils/match-peer-id.js diff --git a/package.json b/package.json index f7aa1d9da4..038cdcc539 100644 --- a/package.json +++ b/package.json @@ -308,8 +308,5 @@ "Jacob Karlsson ", "Jorropo ", "João Santos " - ], - "dependencies": { - "import-meta-resolve": "^1.1.1" - } + ] } diff --git a/packages/interface-ipfs-core/package.json b/packages/interface-ipfs-core/package.json index c1f797cf52..49fe3bc4c5 100644 --- a/packages/interface-ipfs-core/package.json +++ b/packages/interface-ipfs-core/package.json @@ -66,7 +66,9 @@ "@ipld/dag-cbor": "^7.0.0", "@ipld/dag-pb": "^2.1.3", "@libp2p/crypto": "^0.22.9", - "@libp2p/websockets": "^1.0.3", + "@libp2p/peer-id": "^1.1.10", + "@libp2p/peer-id-factory": "^1.0.10", + "@libp2p/websockets": "^1.0.8", "@multiformats/multiaddr": "^10.0.0", "@types/pako": "^1.0.2", "@types/readable-stream": "^2.3.11", @@ -98,6 +100,7 @@ "merge-options": "^3.0.4", "multiformats": "^9.5.1", "nanoid": "^3.1.23", + "p-defer": "^4.0.0", "p-map": "^5.3.0", "p-retry": "^5.1.0", "pako": "^2.0.4", diff --git a/packages/ipfs-cli/package.json b/packages/ipfs-cli/package.json index 0d507c067c..3a0837c133 100644 --- a/packages/ipfs-cli/package.json +++ b/packages/ipfs-cli/package.json @@ -52,7 +52,7 @@ }, "scripts": { "lint": "aegir lint", - "test": "npm run test:node", + "test": "aegir test -t node --cov", "test:node": "aegir test -t node --cov", "clean": "aegir clean", "dep-check": "aegir dep-check -i ipfs-core-types", @@ -63,11 +63,12 @@ "@ipld/dag-json": "^8.0.1", "@ipld/dag-pb": "^2.1.3", "@libp2p/crypto": "^0.22.9", + "@libp2p/logger": "^1.1.4", + "@libp2p/peer-id": "^1.1.10", "@multiformats/mafmt": "^11.0.2", "@multiformats/multiaddr": "^10.0.0", "@multiformats/multiaddr-to-uri": "^9.0.1", "byteman": "^1.3.5", - "debug": "^4.1.1", "err-code": "^3.0.1", "execa": "^6.1.0", "get-folder-size": "^3.1.0", @@ -97,6 +98,7 @@ "yargs": "^17.4.0" }, "devDependencies": { + "@types/get-folder-size": "^3.0.1", "@types/ncp": "^2.0.5", "@types/progress": "^2.0.3", "@types/yargs": "^17.0.10", diff --git a/packages/ipfs-cli/src/commands/add.js b/packages/ipfs-cli/src/commands/add.js index c5bfdaeef1..e5c2434ae6 100644 --- a/packages/ipfs-cli/src/commands/add.js +++ b/packages/ipfs-cli/src/commands/add.js @@ -1,8 +1,6 @@ /* eslint-disable complexity */ -import { promisify } from 'util' -// @ts-expect-error no types -import getFolderSizeCb from 'get-folder-size' +import getFolderSize from 'get-folder-size' // @ts-expect-error no types import byteman from 'byteman' import { @@ -17,14 +15,12 @@ import merge from 'it-merge' import fs from 'fs' import path from 'path' -const getFolderSize = promisify(getFolderSizeCb) - /** * @param {string[]} paths */ async function getTotalBytes (paths) { const sizes = await Promise.all(paths.map(p => getFolderSize(p))) - return sizes.reduce((total, size) => total + size, 0) + return sizes.reduce((total, { size }) => total + size, 0) } /** @@ -85,7 +81,40 @@ async function * getSource (target, options = {}) { } } -export default { +/** + * @typedef {object} Argv + * @property {import('../types').Context} Argv.ctx + * @property {boolean} Argv.trickle + * @property {number} Argv.shardSplitThreshold + * @property {import('multiformats/cid').CIDVersion} Argv.cidVersion + * @property {boolean} Argv.rawLeaves + * @property {boolean} Argv.onlyHash + * @property {string} Argv.hash + * @property {boolean} Argv.wrapWithDirectory + * @property {boolean} Argv.pin + * @property {string} Argv.chunker + * @property {boolean} Argv.preload + * @property {number} Argv.fileImportConcurrency + * @property {number} Argv.blockWriteConcurrency + * @property {number} Argv.timeout + * @property {boolean} Argv.quieter + * @property {boolean} Argv.quiet + * @property {boolean} Argv.silent + * @property {boolean} Argv.progress + * @property {string[]} Argv.file + * @property {number} Argv.mtime + * @property {number} Argv.mtimeNsecs + * @property {boolean} Argv.recursive + * @property {boolean} Argv.hidden + * @property {boolean} Argv.preserveMode + * @property {boolean} Argv.preserveMtime + * @property {number} Argv.mode + * @property {string} Argv.cidBase + * @property {boolean} Argv.enableShardingExperiment + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'add [file...]', describe: 'Add a file to IPFS using the UnixFS data format', @@ -93,35 +122,35 @@ export default { builder: { progress: { alias: 'p', - type: 'boolean', + boolean: true, default: true, describe: 'Stream progress data' }, recursive: { alias: 'r', - type: 'boolean', + boolean: true, default: false }, trickle: { alias: 't', - type: 'boolean', + boolean: true, default: false, describe: 'Use the trickle DAG builder' }, 'wrap-with-directory': { alias: 'w', - type: 'boolean', + boolean: true, default: false, describe: 'Add a wrapping node' }, 'only-hash': { alias: 'n', - type: 'boolean', + boolean: true, default: false, describe: 'Only chunk and hash, do not write' }, 'block-write-concurrency': { - type: 'integer', + number: true, default: 10, describe: 'After a file has been chunked, this controls how many chunks to hash and add to the block store concurrently' }, @@ -130,133 +159,100 @@ export default { describe: 'Chunking algorithm to use, formatted like [size-{size}, rabin, rabin-{avg}, rabin-{min}-{avg}-{max}]' }, 'file-import-concurrency': { - type: 'integer', + number: true, default: 50, describe: 'How many files to import at once' }, 'enable-sharding-experiment': { - type: 'boolean', + boolean: true, default: false }, 'shard-split-threshold': { - type: 'integer', + number: true, default: 1000 }, 'raw-leaves': { - type: 'boolean', + boolean: true, describe: 'Use raw blocks for leaf nodes. (experimental)' }, 'cid-version': { - type: 'integer', + number: true, describe: 'CID version. Defaults to 0 unless an option that depends on CIDv1 is passed. (experimental)', default: 0 }, 'cid-base': { - describe: 'Number base to display CIDs in.', - type: 'string', + describe: 'Number base to display CIDs in', + string: true, default: 'base58btc' }, hash: { - type: 'string', + string: true, describe: 'Hash function to use. Will set CID version to 1 if used. (experimental)', default: 'sha2-256' }, quiet: { alias: 'q', - type: 'boolean', + boolean: true, default: false, describe: 'Write minimal output' }, quieter: { alias: 'Q', - type: 'boolean', + boolean: true, default: false, describe: 'Write only final hash' }, silent: { - type: 'boolean', + boolean: true, default: false, describe: 'Write no output' }, pin: { - type: 'boolean', + boolean: true, default: true, describe: 'Pin this object when adding' }, preload: { - type: 'boolean', + boolean: true, default: true, describe: 'Preload this object when adding' }, hidden: { alias: 'H', - type: 'boolean', + boolean: true, default: false, describe: 'Include files that are hidden. Only takes effect on recursive add.' }, 'preserve-mode': { - type: 'boolean', + boolean: true, default: false, describe: 'Apply permissions to created UnixFS entries' }, 'preserve-mtime': { - type: 'boolean', + boolean: true, default: false, describe: 'Apply modification time to created UnixFS entries' }, mode: { - type: 'string', + string: true, describe: 'File mode to apply to created UnixFS entries' }, mtime: { - type: 'number', + number: true, coerce: coerceMtime, describe: 'Modification time in seconds before or since the Unix Epoch to apply to created UnixFS entries' }, 'mtime-nsecs': { - type: 'number', + number: true, coerce: coerceMtimeNsecs, describe: 'Modification time fraction in nanoseconds' }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../types').Context} argv.ctx - * @param {boolean} argv.trickle - * @param {number} argv.shardSplitThreshold - * @param {import('multiformats/cid').CIDVersion} argv.cidVersion - * @param {boolean} argv.rawLeaves - * @param {boolean} argv.onlyHash - * @param {string} argv.hash - * @param {boolean} argv.wrapWithDirectory - * @param {boolean} argv.pin - * @param {string} argv.chunker - * @param {boolean} argv.preload - * @param {number} argv.fileImportConcurrency - * @param {number} argv.blockWriteConcurrency - * @param {number} argv.timeout - * @param {boolean} argv.quieter - * @param {boolean} argv.quiet - * @param {boolean} argv.silent - * @param {boolean} argv.progress - * @param {string[]} argv.file - * @param {number} argv.mtime - * @param {number} argv.mtimeNsecs - * @param {boolean} argv.recursive - * @param {boolean} argv.hidden - * @param {boolean} argv.preserveMode - * @param {boolean} argv.preserveMtime - * @param {number} argv.mode - * @param {string} argv.cidBase - * @param {boolean} argv.enableShardingExperiment - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print, isDaemon, getStdin }, trickle, @@ -407,3 +403,5 @@ export default { } } } + +export default command diff --git a/packages/ipfs-cli/src/commands/bitswap.js b/packages/ipfs-cli/src/commands/bitswap.js index 51d6b98623..58138f381b 100644 --- a/packages/ipfs-cli/src/commands/bitswap.js +++ b/packages/ipfs-cli/src/commands/bitswap.js @@ -1,15 +1,22 @@ import { commands } from './bitswap/index.js' -export default { +/** @type {import('yargs').CommandModule} */ +const command = { command: 'bitswap ', - description: 'Interact with the bitswap agent.', + describe: 'Interact with the bitswap agent', - /** - * @param {import('yargs').Argv} yargs - */ builder (yargs) { - // @ts-expect-error types are wrong - return yargs.command(commands) + commands.forEach(command => { + yargs.command(command) + }) + + return yargs + }, + + handler () { + } } + +export default command diff --git a/packages/ipfs-cli/src/commands/bitswap/index.js b/packages/ipfs-cli/src/commands/bitswap/index.js index 3386f2ca06..766dfc3fac 100644 --- a/packages/ipfs-cli/src/commands/bitswap/index.js +++ b/packages/ipfs-cli/src/commands/bitswap/index.js @@ -2,6 +2,7 @@ import bitswapStat from './stat.js' import bitswapUnwant from './unwant.js' import bitswapWantlist from './wantlist.js' +/** @type {import('yargs').CommandModule[]} */ export const commands = [ bitswapStat, bitswapUnwant, diff --git a/packages/ipfs-cli/src/commands/bitswap/stat.js b/packages/ipfs-cli/src/commands/bitswap/stat.js index bec871fd79..0ab8240430 100644 --- a/packages/ipfs-cli/src/commands/bitswap/stat.js +++ b/packages/ipfs-cli/src/commands/bitswap/stat.js @@ -1,39 +1,37 @@ import prettyBytes from 'pretty-bytes' import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {boolean} Argv.human + * @property {string} Argv.cidBase + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'stat', - describe: 'Show some diagnostic information on the bitswap agent.', + describe: 'Show some diagnostic information on the bitswap agent', builder: { 'cid-base': { - describe: 'Number base to display CIDs in. Note: specifying a CID base for v0 CIDs will have no effect.', - type: 'string', + describe: 'Number base to display CIDs in. Note: specifying a CID base for v0 CIDs will have no effect', + string: true, default: 'base58btc' }, human: { - type: 'boolean', + boolean: true, default: false }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {boolean} argv.human - * @param {string} argv.cidBase - * @param {number} argv.timeout - * - * @returns {Promise} - */ - async handler ({ ctx, cidBase, human, timeout }) { - const { ipfs, print } = ctx - + async handler ({ ctx: { ipfs, print }, cidBase, human, timeout }) { const stats = await ipfs.bitswap.stat({ timeout }) @@ -71,3 +69,5 @@ export default { partners [${stats.peers.length}]`) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/bitswap/unwant.js b/packages/ipfs-cli/src/commands/bitswap/unwant.js index 3f7781399e..54912a2089 100644 --- a/packages/ipfs-cli/src/commands/bitswap/unwant.js +++ b/packages/ipfs-cli/src/commands/bitswap/unwant.js @@ -1,38 +1,38 @@ import parseDuration from 'parse-duration' import { coerceCID } from '../../utils.js' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {import('multiformats/cid').CID} Argv.key + * @property {string} Argv.cidBase + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'unwant ', - describe: 'Removes a given block from your wantlist.', + describe: 'Removes a given block from your wantlist', builder: { key: { alias: 'k', describe: 'Key to remove from your wantlist', - type: 'string', + string: true, coerce: coerceCID }, 'cid-base': { - describe: 'Number base to display CIDs in. Note: specifying a CID base for v0 CIDs will have no effect.', - type: 'string', + describe: 'Number base to display CIDs in. Note: specifying a CID base for v0 CIDs will have no effect', + string: true, default: 'base58btc' }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {import('multiformats/cid').CID} argv.key - * @param {string} argv.cidBase - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx, key, cidBase, timeout }) { const { ipfs, print } = ctx const base = await ipfs.bases.getBase(cidBase) @@ -42,3 +42,5 @@ export default { print(`Key ${key.toString(base.encoder)} removed from wantlist`) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/bitswap/wantlist.js b/packages/ipfs-cli/src/commands/bitswap/wantlist.js index 2914a03b66..54132e31c1 100644 --- a/packages/ipfs-cli/src/commands/bitswap/wantlist.js +++ b/packages/ipfs-cli/src/commands/bitswap/wantlist.js @@ -1,38 +1,38 @@ import parseDuration from 'parse-duration' import { coercePeerId } from '../../utils.js' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {import('@libp2p/interfaces/peer-id').PeerId} Argv.peer + * @property {string} Argv.cidBase + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'wantlist [peer]', - describe: 'Print out all blocks currently on the bitswap wantlist for the local peer.', + describe: 'Print out all blocks currently on the bitswap wantlist for the local peer', builder: { peer: { alias: 'p', - describe: 'Specify which peer to show wantlist for.', - type: 'string', + describe: 'Specify which peer to show wantlist for', + string: true, coerce: coercePeerId }, 'cid-base': { - describe: 'Number base to display CIDs in. Note: specifying a CID base for v0 CIDs will have no effect.', - type: 'string', + describe: 'Number base to display CIDs in. Note: specifying a CID base for v0 CIDs will have no effect', + string: true, default: 'base58btc' }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {import('@libp2p/interfaces/peer-id').PeerId} argv.peer - * @param {string} argv.cidBase - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx, peer, cidBase, timeout }) { const { ipfs, print } = ctx const base = await ipfs.bases.getBase(cidBase) @@ -53,3 +53,5 @@ export default { list.forEach(cid => print(cid.toString(base.encoder))) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/block.js b/packages/ipfs-cli/src/commands/block.js index 601f5eeda1..129122d319 100644 --- a/packages/ipfs-cli/src/commands/block.js +++ b/packages/ipfs-cli/src/commands/block.js @@ -1,16 +1,22 @@ import { commands } from './block/index.js' -export default { +/** @type {import('yargs').CommandModule} */ +const command = { command: 'block ', - description: 'Manipulate raw IPFS blocks.', + describe: 'Manipulate raw IPFS blocks', - /** - * @param {import('yargs').Argv} yargs - */ builder (yargs) { + commands.forEach(command => { + yargs.command(command) + }) + return yargs - // @ts-expect-error types are wrong - .command(commands) + }, + + handler () { + } } + +export default command diff --git a/packages/ipfs-cli/src/commands/block/get.js b/packages/ipfs-cli/src/commands/block/get.js index fb7fe93a68..73f0051fce 100644 --- a/packages/ipfs-cli/src/commands/block/get.js +++ b/packages/ipfs-cli/src/commands/block/get.js @@ -2,30 +2,30 @@ import parseDuration from 'parse-duration' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' import { coerceCID } from '../../utils.js' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {import('multiformats/cid').CID} Argv.key + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'get ', describe: 'Get a raw IPFS block', builder: { key: { - type: 'string', + string: true, coerce: coerceCID }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {import('multiformats/cid').CID} argv.key - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx, key, timeout }) { const { ipfs, print } = ctx const block = await ipfs.block.get(key, { @@ -38,3 +38,5 @@ export default { } } } + +export default command diff --git a/packages/ipfs-cli/src/commands/block/index.js b/packages/ipfs-cli/src/commands/block/index.js index cf263e4ea7..e255088a53 100644 --- a/packages/ipfs-cli/src/commands/block/index.js +++ b/packages/ipfs-cli/src/commands/block/index.js @@ -3,6 +3,7 @@ import blockPut from './put.js' import blockRm from './rm.js' import blockStat from './stat.js' +/** @type {import('yargs').CommandModule[]} */ export const commands = [ blockGet, blockPut, diff --git a/packages/ipfs-cli/src/commands/block/put.js b/packages/ipfs-cli/src/commands/block/put.js index cccd552973..2f4b1607dc 100644 --- a/packages/ipfs-cli/src/commands/block/put.js +++ b/packages/ipfs-cli/src/commands/block/put.js @@ -2,7 +2,21 @@ import fs from 'fs' import concat from 'it-concat' import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {string} Argv.block + * @property {string} Argv.format + * @property {string} Argv.mhtype + * @property {number} Argv.mhlen + * @property {import('multiformats/cid').CIDVersion} Argv.version + * @property {boolean} Argv.pin + * @property {string} Argv.cidBase + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'put [block]', describe: 'Stores input as an IPFS block', @@ -10,7 +24,7 @@ export default { builder: { format: { alias: 'f', - describe: 'cid format for blocks to be created with.', + describe: 'cid format for blocks to be created with', default: 'dag-pb' }, mhtype: { @@ -23,39 +37,25 @@ export default { }, version: { describe: 'cid version', - type: 'number', + number: true, default: 0 }, 'cid-base': { - describe: 'Number base to display CIDs in.', - type: 'string', + describe: 'Number base to display CIDs in', + string: true, default: 'base58btc' }, pin: { describe: 'Pin this block recursively', - type: 'boolean', + boolean: true, default: false }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {string} argv.block - * @param {string} argv.format - * @param {string} argv.mhtype - * @param {number} argv.mhlen - * @param {import('multiformats/cid').CIDVersion} argv.version - * @param {boolean} argv.pin - * @param {string} argv.cidBase - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print, getStdin }, block, timeout, format, mhtype, mhlen, version, cidBase, pin }) { let data @@ -77,3 +77,5 @@ export default { print(cid.toString(base.encoder)) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/block/rm.js b/packages/ipfs-cli/src/commands/block/rm.js index 1d06f762eb..3c102c03b9 100644 --- a/packages/ipfs-cli/src/commands/block/rm.js +++ b/packages/ipfs-cli/src/commands/block/rm.js @@ -1,7 +1,17 @@ import parseDuration from 'parse-duration' import { coerceCIDs } from '../../utils.js' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {import('multiformats/cid').CID[]} Argv.hash + * @property {boolean} Argv.force + * @property {boolean} Argv.quiet + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'rm ', describe: 'Remove IPFS block(s)', @@ -14,31 +24,21 @@ export default { force: { alias: 'f', describe: 'Ignore nonexistent blocks', - type: 'boolean', + boolean: true, default: false }, quiet: { alias: 'q', describe: 'Write minimal output', - type: 'boolean', + boolean: true, default: false }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {import('multiformats/cid').CID[]} argv.hash - * @param {boolean} argv.force - * @param {boolean} argv.quiet - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx, hash, force, quiet, timeout }) { const { ipfs, print } = ctx @@ -63,3 +63,5 @@ export default { } } } + +export default command diff --git a/packages/ipfs-cli/src/commands/block/stat.js b/packages/ipfs-cli/src/commands/block/stat.js index ef9a50af79..65ac9a6156 100644 --- a/packages/ipfs-cli/src/commands/block/stat.js +++ b/packages/ipfs-cli/src/commands/block/stat.js @@ -1,36 +1,36 @@ import parseDuration from 'parse-duration' import { coerceCID } from '../../utils.js' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {import('multiformats/cid').CID} Argv.key + * @property {string} Argv.cidBase + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'stat ', describe: 'Print information of a raw IPFS block', builder: { key: { - type: 'string', + string: true, coerce: coerceCID }, 'cid-base': { - describe: 'Number base to display CIDs in.', - type: 'string', + describe: 'Number base to display CIDs in', + string: true, default: 'base58btc' }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {import('multiformats/cid').CID} argv.key - * @param {string} argv.cidBase - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx, key, cidBase, timeout }) { const { ipfs, print } = ctx const stats = await ipfs.block.stat(key, { @@ -41,3 +41,5 @@ export default { print('Size: ' + stats.size) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/bootstrap.js b/packages/ipfs-cli/src/commands/bootstrap.js index 01dc17fdf8..c7aec7c586 100644 --- a/packages/ipfs-cli/src/commands/bootstrap.js +++ b/packages/ipfs-cli/src/commands/bootstrap.js @@ -1,16 +1,22 @@ import { commands } from './bootstrap/index.js' -export default { +/** @type {import('yargs').CommandModule} */ +const command = { command: 'bootstrap ', - description: 'Show or edit the list of bootstrap peers.', + describe: 'Show or edit the list of bootstrap peers', - /** - * @param {import('yargs').Argv} yargs - */ builder (yargs) { + commands.forEach(command => { + yargs.command(command) + }) + return yargs - // @ts-expect-error types are wrong - .command(commands) + }, + + handler () { + } } + +export default command diff --git a/packages/ipfs-cli/src/commands/bootstrap/add.js b/packages/ipfs-cli/src/commands/bootstrap/add.js index f7735609b5..046ece3a5c 100644 --- a/packages/ipfs-cli/src/commands/bootstrap/add.js +++ b/packages/ipfs-cli/src/commands/bootstrap/add.js @@ -1,36 +1,36 @@ import parseDuration from 'parse-duration' import { coerceMultiaddr } from '../../utils.js' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {import('@multiformats/multiaddr').Multiaddr} Argv.peer + * @property {boolean} Argv.default + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'add []', describe: 'Add peers to the bootstrap list', builder: { peer: { - type: 'string', + string: true, coerce: coerceMultiaddr }, default: { - describe: 'Add default bootstrap nodes.', - type: 'boolean', + describe: 'Add default bootstrap nodes', + boolean: true, default: false }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {import('@multiformats/multiaddr').Multiaddr} argv.peer - * @param {boolean} argv.default - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, peer, default: defaultPeers, timeout }) { let list @@ -49,3 +49,5 @@ export default { list.Peers.forEach((peer) => print(peer.toString())) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/bootstrap/index.js b/packages/ipfs-cli/src/commands/bootstrap/index.js index b36eb3b042..386666001f 100644 --- a/packages/ipfs-cli/src/commands/bootstrap/index.js +++ b/packages/ipfs-cli/src/commands/bootstrap/index.js @@ -2,6 +2,7 @@ import bootstrapAdd from './add.js' import bootstrapList from './list.js' import bootstrapRm from './rm.js' +/** @type {import('yargs').CommandModule[]} */ export const commands = [ bootstrapAdd, bootstrapList, diff --git a/packages/ipfs-cli/src/commands/bootstrap/list.js b/packages/ipfs-cli/src/commands/bootstrap/list.js index b5e2a693a0..fe4efbf37d 100644 --- a/packages/ipfs-cli/src/commands/bootstrap/list.js +++ b/packages/ipfs-cli/src/commands/bootstrap/list.js @@ -1,24 +1,24 @@ import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'list', describe: 'Show peers in the bootstrap list', builder: { timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, timeout }) { const list = await ipfs.bootstrap.list({ timeout @@ -26,3 +26,5 @@ export default { list.Peers.forEach((node) => print(node.toString())) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/bootstrap/rm.js b/packages/ipfs-cli/src/commands/bootstrap/rm.js index 47359dcb52..caa23962a8 100644 --- a/packages/ipfs-cli/src/commands/bootstrap/rm.js +++ b/packages/ipfs-cli/src/commands/bootstrap/rm.js @@ -1,36 +1,36 @@ import parseDuration from 'parse-duration' import { coerceMultiaddr } from '../../utils.js' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {import('@multiformats/multiaddr').Multiaddr} Argv.peer + * @property {boolean} Argv.all + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'rm []', describe: 'Removes peers from the bootstrap list', builder: { peer: { - type: 'string', + string: true, coerce: coerceMultiaddr }, all: { - type: 'boolean', - describe: 'Remove all bootstrap peers.', + boolean: true, + describe: 'Remove all bootstrap peers', default: false }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {import('@multiformats/multiaddr').Multiaddr} argv.peer - * @param {boolean} argv.all - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, all, peer, timeout }) { let list @@ -49,3 +49,5 @@ export default { list.Peers.forEach((peer) => print(peer.toString())) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/cat.js b/packages/ipfs-cli/src/commands/cat.js index 94daef942e..befdfd5105 100644 --- a/packages/ipfs-cli/src/commands/cat.js +++ b/packages/ipfs-cli/src/commands/cat.js @@ -1,6 +1,16 @@ import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../types').Context} Argv.ctx + * @property {string} Argv.ipfsPath + * @property {number} Argv.offset + * @property {number} Argv.length + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'cat ', describe: 'Fetch and cat an IPFS path referencing a file', @@ -8,33 +18,25 @@ export default { builder: { offset: { alias: 'o', - type: 'integer', + number: true, describe: 'Byte offset to begin reading from' }, length: { alias: ['n', 'count'], - type: 'integer', + number: true, describe: 'Maximum number of bytes to read' }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../types').Context} argv.ctx - * @param {string} argv.ipfsPath - * @param {number} argv.offset - * @param {number} argv.length - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, ipfsPath, offset, length, timeout }) { for await (const buf of ipfs.cat(ipfsPath, { offset, length, timeout })) { print.write(buf) } } } + +export default command diff --git a/packages/ipfs-cli/src/commands/cid.js b/packages/ipfs-cli/src/commands/cid.js index bd03bfb601..6d6b68b674 100644 --- a/packages/ipfs-cli/src/commands/cid.js +++ b/packages/ipfs-cli/src/commands/cid.js @@ -1,15 +1,22 @@ import { commands } from './cid/index.js' -export default { +/** @type {import('yargs').CommandModule} */ +const command = { command: 'cid ', - description: 'Convert, format and discover properties of CIDs.', + describe: 'Convert, format and discover properties of CIDs', - /** - * @param {import('yargs').Argv} yargs - */ builder (yargs) { - // @ts-expect-error types are wrong - return yargs.command(commands) + commands.forEach(command => { + yargs.command(command) + }) + + return yargs + }, + + handler () { + } } + +export default command diff --git a/packages/ipfs-cli/src/commands/cid/base32.js b/packages/ipfs-cli/src/commands/cid/base32.js index 6a29f330f7..5cba80a1aa 100644 --- a/packages/ipfs-cli/src/commands/cid/base32.js +++ b/packages/ipfs-cli/src/commands/cid/base32.js @@ -2,18 +2,18 @@ import split from 'it-split' import { CID } from 'multiformats/cid' import { base32 } from 'multiformats/bases/base32' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {string[]} [Argv.cids] + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'base32 [cids...]', - describe: 'Convert CIDs to base 32 CID version 1.', + describe: 'Convert CIDs to base 32 CID version 1', - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {string[]} [argv.cids] - * - * @returns {Promise} - */ async handler ({ ctx: { print, getStdin }, cids }) { let input @@ -34,3 +34,5 @@ export default { } } } + +export default command diff --git a/packages/ipfs-cli/src/commands/cid/bases.js b/packages/ipfs-cli/src/commands/cid/bases.js index 222a5fa19e..a3c760f2c4 100644 --- a/packages/ipfs-cli/src/commands/cid/bases.js +++ b/packages/ipfs-cli/src/commands/cid/bases.js @@ -1,30 +1,30 @@ -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {boolean} [Argv.prefix] + * @property {boolean} [Argv.numeric] + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'bases', - describe: 'List available multibase encoding names.', + describe: 'List available multibase encoding names', builder: { prefix: { - describe: 'Display the single letter encoding codes as well as the encoding name.', - type: 'boolean', + describe: 'Display the single letter encoding codes as well as the encoding name', + boolean: true, default: false }, numeric: { describe: 'Display the numeric encoding code as well as the encoding name', - type: 'boolean', + boolean: true, default: false } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {boolean} [argv.prefix] - * @param {boolean} [argv.numeric] - * - * @returns {void} - */ handler ({ ctx: { ipfs, print }, prefix, numeric }) { for (const base of ipfs.bases.listBases()) { if (prefix && numeric) { @@ -39,3 +39,5 @@ export default { } } } + +export default command diff --git a/packages/ipfs-cli/src/commands/cid/codecs.js b/packages/ipfs-cli/src/commands/cid/codecs.js index 2cad668e18..85ba7758fd 100644 --- a/packages/ipfs-cli/src/commands/cid/codecs.js +++ b/packages/ipfs-cli/src/commands/cid/codecs.js @@ -1,24 +1,24 @@ -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {boolean} [Argv.numeric] + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'codecs', - describe: 'List available CID codec names.', + describe: 'List available CID codec names', builder: { numeric: { describe: 'Display the numeric code as well as the codec name', - type: 'boolean', + boolean: true, default: false } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {boolean} [argv.numeric] - * - * @returns {void} - */ handler ({ ctx: { ipfs, print }, numeric }) { for (const codec of ipfs.codecs.listCodecs()) { if (numeric) { @@ -29,3 +29,5 @@ export default { } } } + +export default command diff --git a/packages/ipfs-cli/src/commands/cid/format.js b/packages/ipfs-cli/src/commands/cid/format.js index df5348b7c3..9e680d6bef 100644 --- a/packages/ipfs-cli/src/commands/cid/format.js +++ b/packages/ipfs-cli/src/commands/cid/format.js @@ -1,10 +1,20 @@ import split from 'it-split' import { CID } from 'multiformats/cid' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {string[]} [Argv.cids] + * @property {string} [Argv.format] + * @property {import('multiformats/cid').CIDVersion} [Argv.cidVersion] + * @property {string} [Argv.base] + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'format [cids...]', - describe: 'Format and convert a CID in various useful ways.', + describe: 'Format and convert a CID in various useful ways', builder: { format: { @@ -30,31 +40,21 @@ export default { (1) For CID version 0 the multibase must be base58btc and no prefix is used. For Cid version 1 the multibase prefix is included.`, alias: 'f', - type: 'string', + string: true, default: '%s' }, 'cid-version': { - describe: 'CID version to convert to.', + describe: 'CID version to convert to', alias: 'v', - type: 'number' + number: true }, base: { - describe: 'Multibase to display output in.', + describe: 'Multibase to display output in', alias: 'b', - type: 'string' + string: true } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {string[]} [argv.cids] - * @param {string} [argv.format] - * @param {import('multiformats/cid').CIDVersion} [argv.cidVersion] - * @param {string} [argv.base] - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print, getStdin }, cids, format, cidVersion, base }) { let input @@ -110,6 +110,8 @@ export default { } } +export default command + /** * @param {CID} cid * @param {import('multiformats/bases/interface').MultibaseCodec} base diff --git a/packages/ipfs-cli/src/commands/cid/hashes.js b/packages/ipfs-cli/src/commands/cid/hashes.js index 51b9150323..d201f9bf30 100644 --- a/packages/ipfs-cli/src/commands/cid/hashes.js +++ b/packages/ipfs-cli/src/commands/cid/hashes.js @@ -1,24 +1,24 @@ -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {boolean} [Argv.numeric] + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'hashes', - describe: 'List available multihash hashing algorithm names.', + describe: 'List available multihash hashing algorithm names', builder: { numeric: { describe: 'Display the numeric code as well as the hashing algorithm name', - type: 'boolean', + boolean: true, default: false } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {boolean} [argv.numeric] - * - * @returns {void} - */ handler ({ ctx: { ipfs, print }, numeric }) { for (const codec of ipfs.hashers.listHashers()) { if (numeric) { @@ -29,3 +29,5 @@ export default { } } } + +export default command diff --git a/packages/ipfs-cli/src/commands/cid/index.js b/packages/ipfs-cli/src/commands/cid/index.js index 53c1de4cf5..1abd0cbe0e 100644 --- a/packages/ipfs-cli/src/commands/cid/index.js +++ b/packages/ipfs-cli/src/commands/cid/index.js @@ -4,6 +4,7 @@ import cidCodecs from './codecs.js' import cidFormat from './format.js' import cidHashes from './hashes.js' +/** @type {import('yargs').CommandModule[]} */ export const commands = [ cidBase32, cidBases, diff --git a/packages/ipfs-cli/src/commands/commands.js b/packages/ipfs-cli/src/commands/commands.js deleted file mode 100644 index 1c0285a144..0000000000 --- a/packages/ipfs-cli/src/commands/commands.js +++ /dev/null @@ -1,38 +0,0 @@ -import path, { dirname } from 'path' -import glob from 'it-glob' -import all from 'it-all' -import { fileURLToPath } from 'url' - -const __dirname = dirname(fileURLToPath(import.meta.url)) - -export default { - command: 'commands', - - describe: 'List all available commands', - - /** - * @param {object} argv - * @param {import('../types').Context} argv.ctx - * - * @returns {Promise} - */ - async handler ({ ctx }) { - const { print } = ctx - - const commandsPath = path.resolve(__dirname, '..', 'commands') - - // modelled after https://github.com/vdemedes/ronin/blob/master/lib/program.js#L78 - const files = await all(glob(commandsPath, '**/*.js')) - const cmds = files.map((p) => { - return p - .replace(/\\/g, '/') - .replace(/\//g, ' ') - .replace('.js', '') - }) - .filter(cmd => !cmd.endsWith('index')) - .sort() - .map((cmd) => `ipfs ${cmd}`) - - print(['ipfs'].concat(cmds).join('\n')) - } -} diff --git a/packages/ipfs-cli/src/commands/config.js b/packages/ipfs-cli/src/commands/config.js index f6a3697cf9..f40e807849 100644 --- a/packages/ipfs-cli/src/commands/config.js +++ b/packages/ipfs-cli/src/commands/config.js @@ -1,45 +1,46 @@ import { commands } from './config/index.js' import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../types').Context} Argv.ctx + * @property {any} Argv.value + * @property {boolean} Argv.bool + * @property {boolean} Argv.json + * @property {string} Argv.key + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'config [value]', - description: 'Get and set IPFS config values.', + describe: 'Get and set IPFS config values', - /** - * @param {import('yargs').Argv} yargs - */ builder: (yargs) => { - return yargs - // @ts-expect-error types are wrong - .command(commands) + commands.forEach(command => { + yargs.command(command) + }) + + yargs .option('bool', { - type: 'boolean', - describe: 'Set a boolean value.', + boolean: true, + describe: 'Set a boolean value', default: false }) .option('json', { - type: 'boolean', - describe: 'Parse stringified JSON.', + boolean: true, + describe: 'Parse stringified JSON', default: false }) .option('timeout', { - type: 'string', + string: true, coerce: parseDuration }) + + return yargs }, - /** - * @param {object} argv - * @param {import('../types').Context} argv.ctx - * @param {any} argv.value - * @param {boolean} argv.bool - * @param {boolean} argv.json - * @param {string} argv.key - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, value, bool, json, key, timeout }) { if (!value) { // Get the value of a given key @@ -71,3 +72,5 @@ export default { } } } + +export default command diff --git a/packages/ipfs-cli/src/commands/config/edit.js b/packages/ipfs-cli/src/commands/config/edit.js index b49c1f5866..e1cc60de96 100644 --- a/packages/ipfs-cli/src/commands/config/edit.js +++ b/packages/ipfs-cli/src/commands/config/edit.js @@ -1,24 +1,26 @@ import path from 'path' import { execa } from 'execa' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'edit', describe: 'Opens the config file for editing in $EDITOR', - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * - * @returns {Promise} - */ - async handler (argv) { + async handler ({ ctx: { repoPath } }) { const editor = process.env.EDITOR if (!editor) { throw new Error('ENV variable $EDITOR not set') } - await execa(editor, [path.join(argv.ctx.repoPath, 'config')]) + await execa(editor, [path.join(repoPath, 'config')]) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/config/index.js b/packages/ipfs-cli/src/commands/config/index.js index e39245c720..bafa5be2f0 100644 --- a/packages/ipfs-cli/src/commands/config/index.js +++ b/packages/ipfs-cli/src/commands/config/index.js @@ -3,6 +3,7 @@ import configProfile from './profile.js' import configReplace from './replace.js' import configShow from './show.js' +/** @type {import('yargs').CommandModule[]} */ export const commands = [ configEdit, configProfile, diff --git a/packages/ipfs-cli/src/commands/config/profile.js b/packages/ipfs-cli/src/commands/config/profile.js index 2b4752e4d9..328543bbbb 100644 --- a/packages/ipfs-cli/src/commands/config/profile.js +++ b/packages/ipfs-cli/src/commands/config/profile.js @@ -1,16 +1,24 @@ import { commands } from './profile/index.js' -export default { +/** + * @typedef {import('yargs').Argv<{}>} Argv + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'profile ', - description: 'Interact with config profiles.', + describe: 'Interact with config profiles', - /** - * @param {import('yargs').Argv} yargs - */ builder (yargs) { return yargs // @ts-expect-error types are wrong .command(commands) + }, + + handler () { + } } + +export default command diff --git a/packages/ipfs-cli/src/commands/config/profile/apply.js b/packages/ipfs-cli/src/commands/config/profile/apply.js index 986389e561..aab5e0d159 100644 --- a/packages/ipfs-cli/src/commands/config/profile/apply.js +++ b/packages/ipfs-cli/src/commands/config/profile/apply.js @@ -1,32 +1,32 @@ import JSONDiff from 'jsondiffpatch' import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../../../types').Context} Argv.ctx + * @property {string} Argv.profile + * @property {boolean} Argv.dryRun + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'apply ', describe: 'Apply profile to config', builder: { 'dry-run': { - type: 'boolean', - describe: 'print difference between the current config and the config that would be generated.', + boolean: true, + describe: 'print difference between the current config and the config that would be generated', default: false }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../../types').Context} argv.ctx - * @param {string} argv.profile - * @param {boolean} argv.dryRun - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx, profile, dryRun, timeout }) { const { print, ipfs, isDaemon } = ctx const diff = await ipfs.config.profiles.apply(profile, { @@ -47,3 +47,5 @@ export default { } } } + +export default command diff --git a/packages/ipfs-cli/src/commands/config/profile/index.js b/packages/ipfs-cli/src/commands/config/profile/index.js index 08e80b4835..dd6bffb5a9 100644 --- a/packages/ipfs-cli/src/commands/config/profile/index.js +++ b/packages/ipfs-cli/src/commands/config/profile/index.js @@ -1,6 +1,7 @@ import configProfileApply from './apply.js' import configProfileLs from './ls.js' +/** @type {import('yargs').CommandModule[]} */ export const commands = [ configProfileApply, configProfileLs diff --git a/packages/ipfs-cli/src/commands/config/profile/ls.js b/packages/ipfs-cli/src/commands/config/profile/ls.js index 357a1867c1..acae8e2a70 100644 --- a/packages/ipfs-cli/src/commands/config/profile/ls.js +++ b/packages/ipfs-cli/src/commands/config/profile/ls.js @@ -1,24 +1,24 @@ import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../../../types').Context} Argv.ctx + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'ls', describe: 'List available config profiles', builder: { timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../../types').Context} argv.ctx - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, timeout }) { for (const profile of await ipfs.config.profiles.list({ timeout @@ -27,3 +27,5 @@ export default { } } } + +export default command diff --git a/packages/ipfs-cli/src/commands/config/replace.js b/packages/ipfs-cli/src/commands/config/replace.js index 30a2ddbbde..73b5c6d4e9 100644 --- a/packages/ipfs-cli/src/commands/config/replace.js +++ b/packages/ipfs-cli/src/commands/config/replace.js @@ -2,26 +2,26 @@ import path from 'path' import fs from 'fs' import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {string} Argv.file + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'replace ', describe: 'Replaces the config with ', builder: { timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {string} argv.file - * @param {number} argv.timeout - * - * @returns {Promise} - */ handler ({ ctx: { ipfs, isDaemon }, file, timeout }) { const filePath = path.resolve(process.cwd(), file) @@ -34,3 +34,5 @@ export default { }) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/config/show.js b/packages/ipfs-cli/src/commands/config/show.js index 845cf51269..808c82925d 100644 --- a/packages/ipfs-cli/src/commands/config/show.js +++ b/packages/ipfs-cli/src/commands/config/show.js @@ -1,28 +1,30 @@ import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'show', describe: 'Outputs the content of the config file', builder: { timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, timeout }) { const config = await ipfs.config.getAll({ timeout }) - print(JSON.stringify(config, null, 4)) + print(JSON.stringify(config, null, 2)) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/daemon.js b/packages/ipfs-cli/src/commands/daemon.js index b152186f26..ecf20e79d9 100644 --- a/packages/ipfs-cli/src/commands/daemon.js +++ b/packages/ipfs-cli/src/commands/daemon.js @@ -8,73 +8,71 @@ import { Daemon } from 'ipfs-daemon' const log = logger('ipfs:cli:daemon') -export default { +/** + * @typedef {object} Argv + * @property {import('../types').Context} Argv.ctx + * @property {string} [Argv.initConfig] + * @property {string[]} [Argv.initProfile] + * @property {boolean} Argv.enableShardingExperiment + * @property {boolean} Argv.offline + * @property {boolean} Argv.enableNamesysPubsub + * @property {boolean} Argv.enablePreload + * @property {boolean} Argv.silent + * @property {boolean} Argv.migrate + * @property {string} Argv.pass + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'daemon', describe: 'Start a long-running daemon process', - /** - * @param {import('yargs').Argv} yargs - */ builder (yargs) { - return yargs + yargs .epilog(ipfsPathHelp) .option('init-config', { - type: 'string', + string: true, desc: 'Path to existing configuration file to be loaded during --init.' }) .option('init-profile', { - type: 'string', - desc: 'Configuration profiles to apply for --init. See ipfs init --help for more.', + string: true, + desc: 'Configuration profiles to apply for --init. See ipfs init --help for more', coerce: (value) => { return (value || '').split(',') } }) .option('enable-sharding-experiment', { - type: 'boolean', + boolean: true, default: false }) .option('offline', { - type: 'boolean', - desc: 'Run offline. Do not connect to the rest of the network but provide local API.', + boolean: true, + desc: 'Run offline. Do not connect to the rest of the network but provide local API', default: false }) .option('enable-namesys-pubsub', { - type: 'boolean', + boolean: true, default: false }) .option('enable-preload', { - type: 'boolean', + boolean: true, default: !isTest // preload by default, unless in test env }) + + return yargs }, - /** - * @param {object} argv - * @param {import('../types').Context} argv.ctx - * @param {string} [argv.initConfig] - * @param {string[]} [argv.initProfile] - * @param {boolean} argv.enableShardingExperiment - * @param {boolean} argv.offline - * @param {boolean} argv.enableNamesysPubsub - * @param {boolean} argv.enablePreload - * @param {boolean} argv.silent - * @param {boolean} argv.migrate - * @param {string} argv.pass - * - * @returns {Promise} - */ - async handler (argv) { - const { print, repoPath } = argv.ctx + async handler ({ ctx: { print, repoPath }, initConfig, silent, migrate, offline, pass, enablePreload, enableNamesysPubsub, enableShardingExperiment, initProfile }) { print('Initializing IPFS daemon...') print(`System version: ${os.arch()}/${os.platform()}`) print(`Node.js version: ${process.versions.node}`) let config = {} // read and parse config file - if (argv.initConfig) { + if (initConfig) { try { - const raw = fs.readFileSync(argv.initConfig, { encoding: 'utf8' }) + const raw = fs.readFileSync(initConfig, { encoding: 'utf8' }) config = JSON.parse(raw) } catch (/** @type {any} */ error) { log(error) @@ -84,17 +82,17 @@ export default { const daemon = new Daemon({ config, - silent: argv.silent, + silent: silent, repo: process.env.IPFS_PATH, - repoAutoMigrate: argv.migrate, - offline: argv.offline, - pass: argv.pass, - preload: { enabled: argv.enablePreload }, + repoAutoMigrate: migrate, + offline: offline, + pass: pass, + preload: { enabled: enablePreload }, EXPERIMENTAL: { - ipnsPubsub: argv.enableNamesysPubsub, - sharding: argv.enableShardingExperiment + ipnsPubsub: enableNamesysPubsub, + sharding: enableShardingExperiment }, - init: argv.initProfile ? { profiles: argv.initProfile } : undefined + init: initProfile ? { profiles: initProfile } : undefined }) try { @@ -146,3 +144,5 @@ export default { process.on('SIGHUP', cleanup) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/dag.js b/packages/ipfs-cli/src/commands/dag.js index a30cbdc7dd..974bf2482d 100644 --- a/packages/ipfs-cli/src/commands/dag.js +++ b/packages/ipfs-cli/src/commands/dag.js @@ -1,16 +1,22 @@ import { commands } from './dag/index.js' -export default { +/** @type {import('yargs').CommandModule} */ +const command = { command: 'dag ', - description: 'Interact with ipld dag objects.', + describe: 'Interact with ipld dag objects', - /** - * @param {import('yargs').Argv} yargs - */ builder (yargs) { + commands.forEach(command => { + yargs.command(command) + }) + return yargs - // @ts-expect-error types are wrong - .command(commands) + }, + + handler () { + } } + +export default command diff --git a/packages/ipfs-cli/src/commands/dag/export.js b/packages/ipfs-cli/src/commands/dag/export.js index 66d9b7cbd7..15722a84fa 100644 --- a/packages/ipfs-cli/src/commands/dag/export.js +++ b/packages/ipfs-cli/src/commands/dag/export.js @@ -1,26 +1,26 @@ import parseDuration from 'parse-duration' import { CID } from 'multiformats/cid' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {string} Argv.rootcid + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'export ', - describe: 'Streams the DAG beginning at the given root CID as a CAR stream on stdout.', + describe: 'Streams the DAG beginning at the given root CID as a CAR stream on stdout', builder: { timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {string} argv.rootcid - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, rootcid, timeout }) { const options = { timeout } const cid = CID.parse(rootcid) @@ -31,3 +31,5 @@ export default { } } } + +export default command diff --git a/packages/ipfs-cli/src/commands/dag/get.js b/packages/ipfs-cli/src/commands/dag/get.js index 90fe723d31..69875b8734 100644 --- a/packages/ipfs-cli/src/commands/dag/get.js +++ b/packages/ipfs-cli/src/commands/dag/get.js @@ -16,44 +16,44 @@ const codecs = [dagCBOR, dagJSON, dagPB, raw].reduce((/** @type {Record>} */ {}) -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {string} Argv.cidpath + * @property {'dag-json' | 'dag-cbor' | 'dag-pb' | 'raw'} Argv.outputCodec + * @property {'base16' | 'base64' | 'base58btc'} Argv.dataEnc + * @property {boolean} Argv.localResolve + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'get ', - describe: 'Get a dag node or value from ipfs.', + describe: 'Get a dag node or value from ipfs', builder: { 'local-resolve': { - type: 'boolean', + boolean: true, default: false }, 'output-codec': { - describe: 'Codec to encode data in before displaying.', - type: 'string', + describe: 'Codec to encode data in before displaying', + string: true, choices: ['dag-json', 'dag-cbor', 'dag-pb', 'raw'], default: 'dag-json' }, 'data-enc': { - describe: 'String encoding to display raw node data in if using "raw" output-codec.', - type: 'string', + describe: 'String encoding to display raw node data in if using "raw" output-codec', + string: true, choices: ['base16', 'base64', 'base58btc'] }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {string} argv.cidpath - * @param {'dag-json' | 'dag-cbor' | 'dag-pb' | 'raw'} argv.outputCodec - * @param {'base16' | 'base64' | 'base58btc'} argv.dataEnc - * @param {boolean} argv.localResolve - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, cidpath, dataEnc, outputCodec, localResolve, timeout }) { const options = { localResolve, @@ -103,3 +103,5 @@ export default { } } } + +export default command diff --git a/packages/ipfs-cli/src/commands/dag/import.js b/packages/ipfs-cli/src/commands/dag/import.js index b069f4eb6c..5b86f6bcbc 100644 --- a/packages/ipfs-cli/src/commands/dag/import.js +++ b/packages/ipfs-cli/src/commands/dag/import.js @@ -1,38 +1,38 @@ import fs from 'fs' import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {string[]} Argv.path + * @property {boolean} Argv.pinRoots + * @property {number} Argv.timeout + * @property {string} Argv.cidBase + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'import [path...]', describe: 'Import the contents of one or more CARs from files or stdin', builder: { 'pin-roots': { - type: 'boolean', + boolean: true, default: true, describe: 'Pin optional roots listed in the CAR headers after importing.' }, 'cid-base': { - describe: 'Number base to display CIDs in.', - type: 'string', + describe: 'Number base to display CIDs in', + string: true, default: 'base58btc' }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {string[]} argv.path - * @param {boolean} argv.pinRoots - * @param {number} argv.timeout - * @param {string} argv.cidBase - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print, getStdin }, path, pinRoots, timeout, cidBase }) { const handleResult = async (/** @type {import('ipfs-core-types/src/dag').ImportResult} */ { root }) => { const base = await ipfs.bases.getBase(cidBase) @@ -54,6 +54,8 @@ export default { } } +export default command + /** * @param {import('../../types').Context["print"]} print * @param {string[]} paths diff --git a/packages/ipfs-cli/src/commands/dag/index.js b/packages/ipfs-cli/src/commands/dag/index.js index 673144ca90..3e40aa97ce 100644 --- a/packages/ipfs-cli/src/commands/dag/index.js +++ b/packages/ipfs-cli/src/commands/dag/index.js @@ -4,6 +4,7 @@ import dagImport from './import.js' import dagPut from './put.js' import dagResolve from './resolve.js' +/** @type {import('yargs').CommandModule[]} */ export const commands = [ dagExport, dagGet, diff --git a/packages/ipfs-cli/src/commands/dag/put.js b/packages/ipfs-cli/src/commands/dag/put.js index 2ba0400452..d6de5428ad 100644 --- a/packages/ipfs-cli/src/commands/dag/put.js +++ b/packages/ipfs-cli/src/commands/dag/put.js @@ -18,80 +18,80 @@ const codecs = [dagCBOR, dagJSON, dagPB, raw].reduce((/** @type {Record>} */ {}) -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {string} Argv.data + * @property {'dag-cbor' | 'dag-json' | 'dag-pb' | 'raw'} Argv.inputCodec + * @property {'dag-cbor' | 'dag-json' | 'dag-pb' | 'raw'} Argv.storeCodec + * @property {import('multiformats/cid').CIDVersion} Argv.cidVersion + * @property {boolean} Argv.pin + * @property {string} Argv.hashAlg + * @property {string} Argv.cidBase + * @property {boolean} Argv.preload + * @property {boolean} Argv.onlyHash + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'put [data]', describe: 'accepts input from a file or stdin and parses it into an object of the specified format', builder: { data: { - type: 'string' + string: true }, 'store-codec': { - type: 'string', + string: true, default: 'dag-cbor', describe: 'The codec that the stored object will be encoded with', choices: ['dag-cbor', 'dag-json', 'dag-pb', 'raw'] }, 'input-codec': { - type: 'string', + string: true, default: 'dag-json', describe: 'The codec that the input object is encoded with', choices: ['dag-cbor', 'dag-json', 'dag-pb', 'raw'] }, pin: { - type: 'boolean', + boolean: true, default: true, describe: 'Pin this object when adding' }, 'hash-alg': { - type: 'string', + string: true, alias: 'hash', default: 'sha2-256', describe: 'Hash function to use' }, 'cid-version': { - type: 'integer', + number: true, describe: 'CID version. Defaults to 0 unless an option that depends on CIDv1 is passed', default: 0 }, 'cid-base': { - describe: 'Number base to display CIDs in.', - type: 'string', + describe: 'Number base to display CIDs in', + string: true, default: 'base58btc' }, preload: { - type: 'boolean', + boolean: true, default: true, describe: 'Preload this object when adding' }, 'only-hash': { - type: 'boolean', + boolean: true, default: false, describe: 'Only hash the content, do not write to the underlying block store' }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {string} argv.data - * @param {'dag-cbor' | 'dag-json' | 'dag-pb' | 'raw'} argv.inputCodec - * @param {'dag-cbor' | 'dag-json' | 'dag-pb' | 'raw'} argv.storeCodec - * @param {import('multiformats/cid').CIDVersion} argv.cidVersion - * @param {boolean} argv.pin - * @param {string} argv.hashAlg - * @param {string} argv.cidBase - * @param {boolean} argv.preload - * @param {boolean} argv.onlyHash - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print, getStdin }, data, inputCodec, storeCodec, pin, hashAlg, cidVersion, cidBase, preload, onlyHash, timeout }) { if (!codecs[inputCodec]) { throw new Error(`Unknown input-codec ${inputCodec}`) @@ -127,3 +127,5 @@ export default { print(cid.toString(base.encoder)) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/dag/resolve.js b/packages/ipfs-cli/src/commands/dag/resolve.js index 8c30046c43..0dd183aca8 100644 --- a/packages/ipfs-cli/src/commands/dag/resolve.js +++ b/packages/ipfs-cli/src/commands/dag/resolve.js @@ -1,28 +1,28 @@ import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {string} Argv.ref + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'resolve ', describe: 'fetches a dag node from ipfs, prints its address and remaining path', builder: { ref: { - type: 'string' + string: true }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {string} argv.ref - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, ref, timeout }) { const options = { timeout @@ -48,3 +48,5 @@ export default { } } } + +export default command diff --git a/packages/ipfs-cli/src/commands/dht.js b/packages/ipfs-cli/src/commands/dht.js index ff1081b2ae..d83ce9892a 100644 --- a/packages/ipfs-cli/src/commands/dht.js +++ b/packages/ipfs-cli/src/commands/dht.js @@ -1,15 +1,22 @@ import { commands } from './dht/index.js' -export default { +/** @type {import('yargs').CommandModule} */ +const command = { command: 'dht ', - description: 'Issue commands directly through the DHT.', + describe: 'Issue commands directly through the DHT', - /** - * @param {import('yargs').Argv} yargs - */ builder (yargs) { - // @ts-expect-error types are wrong - return yargs.command(commands) + commands.forEach(command => { + yargs.command(command) + }) + + return yargs + }, + + handler () { + } } + +export default command diff --git a/packages/ipfs-cli/src/commands/dht/find-peer.js b/packages/ipfs-cli/src/commands/dht/find-peer.js index 9029bf4380..652f8ff568 100644 --- a/packages/ipfs-cli/src/commands/dht/find-peer.js +++ b/packages/ipfs-cli/src/commands/dht/find-peer.js @@ -1,30 +1,30 @@ import parseDuration from 'parse-duration' import { coercePeerId } from '../../utils.js' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {import('@libp2p/interfaces/peer-id').PeerId} Argv.peerId + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'findpeer ', - describe: 'Find the multiaddresses associated with a Peer ID.', + describe: 'Find the multiaddresses associated with a Peer ID', builder: { peerId: { - type: 'string', + string: true, coerce: coercePeerId }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {import('@libp2p/interfaces/peer-id').PeerId} argv.peerId - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, peerId, timeout }) { for await (const event of ipfs.dht.findPeer(peerId, { timeout @@ -35,3 +35,5 @@ export default { } } } + +export default command diff --git a/packages/ipfs-cli/src/commands/dht/find-providers.js b/packages/ipfs-cli/src/commands/dht/find-providers.js index 348a932ec1..4990f0d8e7 100644 --- a/packages/ipfs-cli/src/commands/dht/find-providers.js +++ b/packages/ipfs-cli/src/commands/dht/find-providers.js @@ -1,37 +1,37 @@ import parseDuration from 'parse-duration' import { coerceCID } from '../../utils.js' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {import('multiformats/cid').CID} Argv.key + * @property {number} Argv.numProviders + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'findprovs ', - describe: 'Find peers that can provide a specific value, given a key.', + describe: 'Find peers that can provide a specific value, given a key', builder: { key: { - type: 'string', + string: true, coerce: coerceCID }, 'num-providers': { alias: 'n', - describe: 'The number of providers to find. Default: 20.', + describe: 'The number of providers to find. Default: 20', default: 20, - type: 'number' + number: true }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {import('multiformats/cid').CID} argv.key - * @param {number} argv.numProviders - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, key, numProviders, timeout }) { const providers = new Set() @@ -55,3 +55,5 @@ export default { } } } + +export default command diff --git a/packages/ipfs-cli/src/commands/dht/get.js b/packages/ipfs-cli/src/commands/dht/get.js index 468b5e6b93..7ccae08c9a 100644 --- a/packages/ipfs-cli/src/commands/dht/get.js +++ b/packages/ipfs-cli/src/commands/dht/get.js @@ -2,30 +2,30 @@ import parseDuration from 'parse-duration' import { coerceCID } from '../../utils.js' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {import('multiformats/cid').CID} Argv.key + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'get ', - describe: 'Given a key, query the routing system for its best value.', + describe: 'Given a key, query the routing system for its best value', builder: { key: { - type: 'string', + string: true, coerce: coerceCID }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {import('multiformats/cid').CID} argv.key - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, key, timeout }) { for await (const event of await ipfs.dht.get(key.bytes, { timeout @@ -36,3 +36,5 @@ export default { } } } + +export default command diff --git a/packages/ipfs-cli/src/commands/dht/index.js b/packages/ipfs-cli/src/commands/dht/index.js index 5eb20b4f45..861203cefd 100644 --- a/packages/ipfs-cli/src/commands/dht/index.js +++ b/packages/ipfs-cli/src/commands/dht/index.js @@ -5,6 +5,7 @@ import dhtProvide from './provide.js' import dhtPut from './put.js' import dhtQuery from './query.js' +/** @type {import('yargs').CommandModule[]} */ export const commands = [ dhtFindPeer, dhtFindProviders, diff --git a/packages/ipfs-cli/src/commands/dht/provide.js b/packages/ipfs-cli/src/commands/dht/provide.js index 5bf232761f..536fd06861 100644 --- a/packages/ipfs-cli/src/commands/dht/provide.js +++ b/packages/ipfs-cli/src/commands/dht/provide.js @@ -1,37 +1,37 @@ import parseDuration from 'parse-duration' import { coerceCID } from '../../utils.js' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {import('multiformats/cid').CID} Argv.key + * @property {boolean} Argv.recursive + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'provide ', - describe: 'Announce to the network that you are providing given values.', + describe: 'Announce to the network that you are providing given values', builder: { key: { - type: 'string', + string: true, coerce: coerceCID }, recursive: { alias: 'r', - recursive: 'Recursively provide entire graph.', + describe: 'Recursively provide entire graph', default: false, - type: 'boolean' + boolean: true }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {import('multiformats/cid').CID} argv.key - * @param {boolean} argv.recursive - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs }, key, recursive, timeout }) { await ipfs.dht.provide(key, { recursive, @@ -39,3 +39,5 @@ export default { }) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/dht/put.js b/packages/ipfs-cli/src/commands/dht/put.js index 6a93230739..49f18a2fd6 100644 --- a/packages/ipfs-cli/src/commands/dht/put.js +++ b/packages/ipfs-cli/src/commands/dht/put.js @@ -1,30 +1,32 @@ import parseDuration from 'parse-duration' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {string} Argv.key + * @property {string} Argv.value + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'put ', - describe: 'Write a key/value pair to the routing system.', + describe: 'Write a key/value pair to the routing system', builder: { timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {string} argv.key - * @param {string} argv.value - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs }, key, value, timeout }) { await ipfs.dht.put(uint8ArrayFromString(key), uint8ArrayFromString(value), { timeout }) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/dht/query.js b/packages/ipfs-cli/src/commands/dht/query.js index 650c4b0423..bbbafd1bb7 100644 --- a/packages/ipfs-cli/src/commands/dht/query.js +++ b/packages/ipfs-cli/src/commands/dht/query.js @@ -1,35 +1,35 @@ import parseDuration from 'parse-duration' import { coercePeerId } from '../../utils.js' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {import('@libp2p/interfaces/peer-id').PeerId} Argv.peerId + * @property {number} Argv.timeout + * @property {number} Argv.count + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'query ', - describe: 'Find the closest Peer IDs to a given Peer ID by querying the DHT.', + describe: 'Find the closest Peer IDs to a given Peer ID by querying the DHT', builder: { peerId: { - type: 'string', + string: true, coerce: coercePeerId }, count: { - type: 'number', + number: true, default: 20 }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {import('@libp2p/interfaces/peer-id').PeerId} argv.peerId - * @param {number} argv.timeout - * @param {number} argv.count - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, peerId, timeout, count }) { const seen = new Set() @@ -59,3 +59,5 @@ export default { } } } + +export default command diff --git a/packages/ipfs-cli/src/commands/dns.js b/packages/ipfs-cli/src/commands/dns.js index 1606ff3977..a8258d6b9b 100644 --- a/packages/ipfs-cli/src/commands/dns.js +++ b/packages/ipfs-cli/src/commands/dns.js @@ -3,35 +3,37 @@ import { stripControlCharacters } from '../utils.js' -export default { +/** + * @typedef {object} Argv + * @property {import('../types').Context} Argv.ctx + * @property {string} Argv.domain + * @property {boolean} Argv.recursive + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'dns ', describe: 'Resolve DNS links', builder: { recursive: { - type: 'boolean', + boolean: true, default: true, alias: 'r', desc: 'Resolve until the result is not a DNS link' }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../types').Context} argv.ctx - * @param {string} argv.domain - * @param {boolean} argv.recursive - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, domain, recursive, timeout }) { const path = await ipfs.dns(domain, { recursive, timeout }) print(stripControlCharacters(path)) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/files.js b/packages/ipfs-cli/src/commands/files.js index 87aa218ed9..435112b7eb 100644 --- a/packages/ipfs-cli/src/commands/files.js +++ b/packages/ipfs-cli/src/commands/files.js @@ -1,25 +1,22 @@ import { commands } from './files/index.js' -export default { +/** @type {import('yargs').CommandModule} */ +const command = { command: 'files ', - description: 'Operations over mfs files (ls, mkdir, rm, etc)', + describe: 'Operations over mfs files (ls, mkdir, rm, etc)', - /** - * @param {import('yargs').Argv} yargs - */ builder (yargs) { - // @ts-expect-error types are wrong - return yargs.command(commands) + commands.forEach(command => { + yargs.command(command) + }) + + return yargs }, - /** - * @param {object} argv - * @param {import('../types').Context} argv.ctx - * - * @returns {void} - */ - handler (argv) { - argv.ctx.print('Type `jsipfs files --help` for more instructions') + handler ({ ctx: { print } }) { + print('Type `jsipfs files --help` for more instructions') } } + +export default command diff --git a/packages/ipfs-cli/src/commands/files/chmod.js b/packages/ipfs-cli/src/commands/files/chmod.js index 0f1efe1486..6e568c176f 100644 --- a/packages/ipfs-cli/src/commands/files/chmod.js +++ b/packages/ipfs-cli/src/commands/files/chmod.js @@ -3,64 +3,64 @@ import { } from '../../utils.js' import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {string} Argv.path + * @property {number} Argv.mode + * @property {boolean} Argv.recursive + * @property {string} Argv.hashAlg + * @property {boolean} Argv.flush + * @property {number} Argv.shardSplitThreshold + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'chmod [mode] [path]', describe: 'Change file modes', builder: { path: { - type: 'string', + string: true, describe: 'The MFS path to change the mode of' }, mode: { - type: 'string', + string: true, describe: 'The mode to use' }, recursive: { alias: 'r', - type: 'boolean', + boolean: true, default: false, coerce: asBoolean, describe: 'Whether to change modes recursively' }, 'hash-alg': { alias: 'h', - type: 'string', + string: true, default: 'sha2-256', describe: 'Hash function to use. Will set CID version to 1 if used' }, flush: { alias: 'f', - type: 'boolean', + boolean: true, default: true, coerce: asBoolean, describe: 'Flush the changes to disk immediately' }, 'shard-split-threshold': { - type: 'number', + number: true, default: 1000, describe: 'If a directory has more links than this, it will be transformed into a hamt-sharded-directory' }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {string} argv.path - * @param {number} argv.mode - * @param {boolean} argv.recursive - * @param {string} argv.hashAlg - * @param {boolean} argv.flush - * @param {number} argv.shardSplitThreshold - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs }, path, @@ -80,3 +80,5 @@ export default { }) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/files/cp.js b/packages/ipfs-cli/src/commands/files/cp.js index 99870919d5..2914cd278e 100644 --- a/packages/ipfs-cli/src/commands/files/cp.js +++ b/packages/ipfs-cli/src/commands/files/cp.js @@ -3,7 +3,20 @@ import { } from '../../utils.js' import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {string} Argv.source + * @property {string} Argv.dest + * @property {boolean} Argv.parents + * @property {string} Argv.hashAlg + * @property {boolean} Argv.flush + * @property {number} Argv.shardSplitThreshold + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'cp ', describe: 'Copy files between locations in the mfs', @@ -11,48 +24,35 @@ export default { builder: { parents: { alias: 'p', - type: 'boolean', + boolean: true, default: false, coerce: asBoolean, describe: 'Create any non-existent intermediate directories' }, 'hash-alg': { alias: 'h', - type: 'string', + string: true, default: 'sha2-256', describe: 'Hash function to use. Will set CID version to 1 if used' }, flush: { alias: 'f', - type: 'boolean', + boolean: true, default: true, coerce: asBoolean, describe: 'Flush the changes to disk immediately' }, 'shard-split-threshold': { - type: 'number', + number: true, default: 1000, describe: 'If a directory has more links than this, it will be transformed into a hamt-sharded-directory' }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {string} argv.source - * @param {string} argv.dest - * @param {boolean} argv.parents - * @param {string} argv.hashAlg - * @param {boolean} argv.flush - * @param {number} argv.shardSplitThreshold - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs }, source, @@ -72,3 +72,5 @@ export default { }) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/files/flush.js b/packages/ipfs-cli/src/commands/files/flush.js index 35874568e9..d4b0718c56 100644 --- a/packages/ipfs-cli/src/commands/files/flush.js +++ b/packages/ipfs-cli/src/commands/files/flush.js @@ -1,6 +1,15 @@ import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {string} Argv.path + * @property {string} Argv.cidBase + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'flush [path]', describe: ' Flush a given path\'s data to disk', @@ -11,20 +20,11 @@ export default { default: 'base58btc' }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {string} argv.path - * @param {string} argv.cidBase - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, path, @@ -42,3 +42,5 @@ export default { })) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/files/index.js b/packages/ipfs-cli/src/commands/files/index.js index b285551bd5..33d980c82d 100644 --- a/packages/ipfs-cli/src/commands/files/index.js +++ b/packages/ipfs-cli/src/commands/files/index.js @@ -10,6 +10,7 @@ import filesStat from './stat.js' import filesTouch from './touch.js' import filesWrite from './write.js' +/** @type {import('yargs').CommandModule[]} */ export const commands = [ filesChmod, filesCp, diff --git a/packages/ipfs-cli/src/commands/files/ls.js b/packages/ipfs-cli/src/commands/files/ls.js index 2dfb78a772..43b54f11c6 100644 --- a/packages/ipfs-cli/src/commands/files/ls.js +++ b/packages/ipfs-cli/src/commands/files/ls.js @@ -6,7 +6,17 @@ import { formatMode } from 'ipfs-core-utils/files/format-mode' import { formatMtime } from 'ipfs-core-utils/files/format-mtime' import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {string} Argv.path + * @property {boolean} Argv.long + * @property {string} Argv.cidBase + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'ls [path]', describe: 'List mfs directories', @@ -14,31 +24,21 @@ export default { builder: { long: { alias: 'l', - type: 'boolean', + boolean: true, default: false, coerce: asBoolean, describe: 'Use long listing format.' }, 'cid-base': { - describe: 'CID base to use.', + describe: 'CID base to use', default: 'base58btc' }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {string} argv.path - * @param {boolean} argv.long - * @param {string} argv.cidBase - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, path, @@ -68,3 +68,5 @@ export default { } } } + +export default command diff --git a/packages/ipfs-cli/src/commands/files/mkdir.js b/packages/ipfs-cli/src/commands/files/mkdir.js index 16467d25b3..86dd3fed08 100644 --- a/packages/ipfs-cli/src/commands/files/mkdir.js +++ b/packages/ipfs-cli/src/commands/files/mkdir.js @@ -7,7 +7,23 @@ import { } from '../../utils.js' import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {string} Argv.path + * @property {boolean} Argv.parents + * @property {import('multiformats/cid').CIDVersion} Argv.cidVersion + * @property {string} Argv.hashAlg + * @property {boolean} Argv.flush + * @property {number} Argv.shardSplitThreshold + * @property {number} Argv.mode + * @property {number} Argv.mtime + * @property {number} Argv.mtimeNsecs + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'mkdir ', describe: 'Make mfs directories', @@ -15,72 +31,56 @@ export default { builder: { parents: { alias: 'p', - type: 'boolean', + boolean: true, default: false, coerce: asBoolean, describe: 'No error if existing, make parent directories as needed.' }, 'cid-version': { alias: ['cid-ver'], - type: 'number', + number: true, default: 0, describe: 'Cid version to use. (experimental).' }, 'hash-alg': { alias: 'h', - type: 'string', + string: true, default: 'sha2-256', describe: 'Hash function to use. Will set CID version to 1 if used' }, flush: { alias: 'f', - type: 'boolean', + boolean: true, default: true, coerce: asBoolean, describe: 'Flush the changes to disk immediately' }, 'shard-split-threshold': { - type: 'number', + number: true, default: 1000, describe: 'If a directory has more links than this, it will be transformed into a hamt-sharded-directory' }, mode: { - type: 'number', + number: true, coerce: asOctal, describe: 'Mode to apply to the new directory' }, mtime: { - type: 'number', + number: true, coerce: coerceMtime, describe: 'Modification time in seconds before or since the Unix Epoch to apply to created UnixFS entries' }, 'mtime-nsecs': { - type: 'number', + number: true, coerce: coerceMtimeNsecs, describe: 'Modification time fraction in nanoseconds' }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {string} argv.path - * @param {boolean} argv.parents - * @param {import('multiformats/cid').CIDVersion} argv.cidVersion - * @param {string} argv.hashAlg - * @param {boolean} argv.flush - * @param {number} argv.shardSplitThreshold - * @param {number} argv.mode - * @param {number} argv.mtime - * @param {number} argv.mtimeNsecs - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs }, path, @@ -106,3 +106,5 @@ export default { }) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/files/mv.js b/packages/ipfs-cli/src/commands/files/mv.js index fe329e38a2..7e5fc8b884 100644 --- a/packages/ipfs-cli/src/commands/files/mv.js +++ b/packages/ipfs-cli/src/commands/files/mv.js @@ -3,7 +3,21 @@ import { } from '../../utils.js' import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {string} Argv.source + * @property {string} Argv.dest + * @property {boolean} Argv.parents + * @property {import('multiformats/cid').CIDVersion} Argv.cidVersion + * @property {string} Argv.hashAlg + * @property {boolean} Argv.flush + * @property {number} Argv.shardSplitThreshold + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'mv ', describe: 'Move mfs files around', @@ -11,55 +25,41 @@ export default { builder: { parents: { alias: 'p', - type: 'boolean', + boolean: true, default: false, coerce: asBoolean, describe: 'Create any non-existent intermediate directories' }, 'cid-version': { alias: ['cid-ver'], - type: 'number', + number: true, default: 0, describe: 'Cid version to use. (experimental).' }, 'hash-alg': { alias: 'h', - type: 'string', + string: true, default: 'sha2-256', describe: 'Hash function to use. Will set CID version to 1 if used' }, flush: { alias: 'f', - type: 'boolean', + boolean: true, default: true, coerce: asBoolean, describe: 'Flush the changes to disk immediately' }, 'shard-split-threshold': { - type: 'number', + number: true, default: 1000, describe: 'If a directory has more links than this, it will be transformed into a hamt-sharded-directory' }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {string} argv.source - * @param {string} argv.dest - * @param {boolean} argv.parents - * @param {import('multiformats/cid').CIDVersion} argv.cidVersion - * @param {string} argv.hashAlg - * @param {boolean} argv.flush - * @param {number} argv.shardSplitThreshold - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs }, source, @@ -81,3 +81,5 @@ export default { }) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/files/read.js b/packages/ipfs-cli/src/commands/files/read.js index 8066701697..7023f8c808 100644 --- a/packages/ipfs-cli/src/commands/files/read.js +++ b/packages/ipfs-cli/src/commands/files/read.js @@ -1,6 +1,16 @@ import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {string} Argv.path + * @property {number} Argv.offset + * @property {number} Argv.length + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'read ', describe: 'Read an mfs file', @@ -8,30 +18,20 @@ export default { builder: { offset: { alias: 'o', - type: 'number', + number: true, describe: 'Start writing at this offset' }, length: { alias: 'l', - type: 'number', + number: true, describe: 'Write only this number of bytes' }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {string} argv.path - * @param {number} argv.offset - * @param {number} argv.length - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, path, @@ -48,3 +48,5 @@ export default { } } } + +export default command diff --git a/packages/ipfs-cli/src/commands/files/rm.js b/packages/ipfs-cli/src/commands/files/rm.js index ae0911e3e0..dde49a68c1 100644 --- a/packages/ipfs-cli/src/commands/files/rm.js +++ b/packages/ipfs-cli/src/commands/files/rm.js @@ -3,7 +3,16 @@ import { } from '../../utils.js' import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {string} Argv.path + * @property {boolean} Argv.recursive + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'rm ', describe: 'Remove an mfs file or directory', @@ -11,26 +20,17 @@ export default { builder: { recursive: { alias: 'r', - type: 'boolean', + boolean: true, default: false, coerce: asBoolean, describe: 'Remove directories recursively' }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {string} argv.path - * @param {boolean} argv.recursive - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs }, path, @@ -43,3 +43,5 @@ export default { }) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/files/stat.js b/packages/ipfs-cli/src/commands/files/stat.js index fde92b6e0b..affd430714 100644 --- a/packages/ipfs-cli/src/commands/files/stat.js +++ b/packages/ipfs-cli/src/commands/files/stat.js @@ -5,7 +5,20 @@ import { formatMode } from 'ipfs-core-utils/files/format-mode' import { formatMtime } from 'ipfs-core-utils/files/format-mtime' import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {string} Argv.path + * @property {string} Argv.format + * @property {boolean} Argv.hash + * @property {boolean} Argv.size + * @property {boolean} Argv.withLocal + * @property {string} Argv.cidBase + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'stat [path]', describe: 'Display file/directory status', @@ -13,7 +26,7 @@ export default { builder: { format: { alias: 'f', - type: 'string', + string: true, default: ` Size: CumulativeSize: @@ -25,48 +38,35 @@ Mtime: `, }, hash: { alias: 'h', - type: 'boolean', + boolean: true, default: false, coerce: asBoolean, describe: 'Print only hash. Implies \'--format=\'. Conflicts with other format options.' }, size: { alias: 's', - type: 'boolean', + boolean: true, default: false, coerce: asBoolean, describe: 'Print only size. Implies \'--format=\'. Conflicts with other format options.' }, 'with-local': { alias: 'l', - type: 'boolean', + boolean: true, default: false, coerce: asBoolean, describe: 'Compute the amount of the dag that is local, and if possible the total size' }, 'cid-base': { - describe: 'CID base to use.', + describe: 'CID base to use', default: 'base58btc' }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {string} argv.path - * @param {string} argv.format - * @param {boolean} argv.hash - * @param {boolean} argv.size - * @param {boolean} argv.withLocal - * @param {string} argv.cidBase - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, path, @@ -102,3 +102,5 @@ Mtime: `, ) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/files/touch.js b/packages/ipfs-cli/src/commands/files/touch.js index cd63687795..515620f81b 100644 --- a/packages/ipfs-cli/src/commands/files/touch.js +++ b/packages/ipfs-cli/src/commands/files/touch.js @@ -6,67 +6,67 @@ import { } from '../../utils.js' import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {string} Argv.path + * @property {boolean} Argv.flush + * @property {import('multiformats/cid').CIDVersion} Argv.cidVersion + * @property {string} Argv.hashAlg + * @property {number} Argv.shardSplitThreshold + * @property {number} Argv.mtime + * @property {number} Argv.mtimeNsecs + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'touch [path]', describe: 'change file modification times', builder: { mtime: { - type: 'number', + number: true, alias: 'm', coerce: coerceMtime, describe: 'Modification time in seconds before or since the Unix Epoch to apply to created UnixFS entries' }, 'mtime-nsecs': { - type: 'number', + number: true, coerce: coerceMtimeNsecs, describe: 'Modification time fraction in nanoseconds' }, flush: { alias: 'f', - type: 'boolean', + boolean: true, default: true, coerce: asBoolean, describe: 'Flush the changes to disk immediately' }, 'cid-version': { alias: ['cid-ver'], - type: 'number', + number: true, default: 0, describe: 'Cid version to use. (experimental).' }, 'hash-alg': { alias: 'h', - type: 'string', + string: true, default: 'sha2-256', describe: 'Hash function to use. Will set CID version to 1 if used' }, 'shard-split-threshold': { - type: 'number', + number: true, default: 1000, describe: 'If a directory has more links than this, it will be transformed into a hamt-sharded-directory' }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {string} argv.path - * @param {boolean} argv.flush - * @param {import('multiformats/cid').CIDVersion} argv.cidVersion - * @param {string} argv.hashAlg - * @param {number} argv.shardSplitThreshold - * @param {number} argv.mtime - * @param {number} argv.mtimeNsecs - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs }, path, @@ -88,3 +88,5 @@ export default { }) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/files/write.js b/packages/ipfs-cli/src/commands/files/write.js index 31a95f6d75..e69afd1bb9 100644 --- a/packages/ipfs-cli/src/commands/files/write.js +++ b/packages/ipfs-cli/src/commands/files/write.js @@ -7,7 +7,30 @@ import { } from '../../utils.js' import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {string} Argv.path + * @property {number} Argv.offset + * @property {number} Argv.length + * @property {boolean} Argv.create + * @property {boolean} Argv.truncate + * @property {boolean} Argv.rawLeaves + * @property {boolean} Argv.reduceSingleLeafToSelf + * @property {import('multiformats/cid').CIDVersion} Argv.cidVersion + * @property {string} Argv.hashAlg + * @property {boolean} Argv.parents + * @property {'trickle' | 'balanced'} Argv.strategy + * @property {boolean} Argv.flush + * @property {number} Argv.shardSplitThreshold + * @property {number} Argv.mode + * @property {number} Argv.mtime + * @property {number} Argv.mtimeNsecs + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'write ', describe: 'Write to mfs files', @@ -15,119 +38,96 @@ export default { builder: { parents: { alias: 'p', - type: 'boolean', + boolean: true, default: false, describe: 'Create any non-existent intermediate directories' }, create: { alias: 'e', - type: 'boolean', + boolean: true, default: false, coerce: asBoolean, describe: 'Create the file if it does not exist' }, offset: { alias: 'o', - type: 'number', + number: true, describe: 'Start writing at this offset' }, length: { alias: 'l', - type: 'number', + number: true, describe: 'Write only this number of bytes' }, truncate: { alias: 't', - type: 'boolean', + boolean: true, default: false, coerce: asBoolean, describe: 'Truncate the file after writing' }, 'raw-leaves': { alias: 'r', - type: 'boolean', + boolean: true, default: false, coerce: asBoolean, describe: 'Whether to write leaf nodes as raw UnixFS nodes' }, 'reduce-single-leaf-to-self': { - type: 'boolean', + boolean: true, default: false, coerce: asBoolean, describe: 'If a file can fit in one DAGNode, only use one DAGNode instead of storing the data in a child' }, flush: { alias: 'f', - type: 'boolean', + boolean: true, default: true, coerce: asBoolean, describe: 'Flush the changes to disk immediately' }, strategy: { alias: 's', - type: 'string', + string: true, default: 'balanced' }, 'cid-version': { alias: ['cid-ver'], - type: 'number', + number: true, default: 0, describe: 'Cid version to use' }, 'hash-alg': { alias: 'h', - type: 'string', + string: true, default: 'sha2-256' }, 'shard-split-threshold': { - type: 'number', + number: true, default: 1000, describe: 'If a directory has more links than this, it will be transformed into a hamt-sharded-directory' }, mode: { - type: 'int', + number: true, coerce: asOctal, describe: 'The mode to use' }, mtime: { - type: 'number', + number: true, coerce: coerceMtime, describe: 'Modification time in seconds before or since the Unix Epoch to apply to created UnixFS entries' }, 'mtime-nsecs': { - type: 'number', + number: true, coerce: coerceMtimeNsecs, describe: 'Modification time fraction in nanoseconds' }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {string} argv.path - * @param {number} argv.offset - * @param {number} argv.length - * @param {boolean} argv.create - * @param {boolean} argv.truncate - * @param {boolean} argv.rawLeaves - * @param {boolean} argv.reduceSingleLeafToSelf - * @param {import('multiformats/cid').CIDVersion} argv.cidVersion - * @param {string} argv.hashAlg - * @param {boolean} argv.parents - * @param {'trickle' | 'balanced'} argv.strategy - * @param {boolean} argv.flush - * @param {number} argv.shardSplitThreshold - * @param {number} argv.mode - * @param {number} argv.mtime - * @param {number} argv.mtimeNsecs - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, getStdin }, path, @@ -167,3 +167,5 @@ export default { }) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/get.js b/packages/ipfs-cli/src/commands/get.js index a9769b7a07..9e344e4f40 100644 --- a/packages/ipfs-cli/src/commands/get.js +++ b/packages/ipfs-cli/src/commands/get.js @@ -10,7 +10,20 @@ import { import { extract } from 'it-tar' import map from 'it-map' -export default { +/** + * @typedef {object} Argv + * @property {import('../types').Context} Argv.ctx + * @property {string} Argv.ipfsPath + * @property {string} Argv.output + * @property {boolean} Argv.force + * @property {number} Argv.timeout + * @property {boolean} Argv.archive + * @property {boolean} Argv.compress + * @property {-1 | 0 | 1 | 2 | 3 | 4 | 5 | 6| 7 | 8| 9} Argv.compressionLevel + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'get ', describe: 'Download IPFS objects', @@ -18,49 +31,36 @@ export default { builder: { output: { alias: 'o', - type: 'string', + string: true, default: process.cwd() }, force: { alias: 'f', - type: 'boolean', + boolean: true, default: false }, timeout: { - type: 'string', + string: true, coerce: parseDuration }, archive: { alias: 'a', - type: 'boolean', + boolean: true, desc: 'Output a TAR archive' }, compress: { alias: 'C', - type: 'boolean', + boolean: true, desc: 'Compress the output with GZIP compression' }, compressionLevel: { alias: ['l', 'compression-level'], - type: 'number', + number: true, desc: 'The level of compression (-1-9)', default: 6 } }, - /** - * @param {object} argv - * @param {import('../types').Context} argv.ctx - * @param {string} argv.ipfsPath - * @param {string} argv.output - * @param {boolean} argv.force - * @param {number} argv.timeout - * @param {boolean} argv.archive - * @param {boolean} argv.compress - * @param {-1 | 0 | 1 | 2 | 3 | 4 | 5 | 6| 7 | 8| 9} argv.compressionLevel - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, ipfsPath, output, force, timeout, archive, compress, compressionLevel }) { print(`Saving file(s) ${stripControlCharacters(ipfsPath)}`) @@ -126,3 +126,5 @@ export default { ) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/id.js b/packages/ipfs-cli/src/commands/id.js index d0fc9a5b42..f9609f6c12 100644 --- a/packages/ipfs-cli/src/commands/id.js +++ b/packages/ipfs-cli/src/commands/id.js @@ -1,37 +1,37 @@ import parseDuration from 'parse-duration' import { coercePeerId } from '../utils.js' -export default { +/** + * @typedef {object} Argv + * @property {import('../types').Context} Argv.ctx + * @property {string} Argv.format + * @property {number} Argv.timeout + * @property {import('@libp2p/interfaces/peer-id').PeerId} [Argv.peerId] + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'id [peerId]', describe: 'Shows IPFS Node ID info', builder: { peerid: { - type: 'string', + string: true, describe: 'Peer.ID of node to look up', coerce: coercePeerId }, format: { alias: 'f', - type: 'string', + string: true, describe: 'Print Node ID info in the given format. Allowed tokens: ' }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../types').Context} argv.ctx - * @param {string} argv.format - * @param {number} argv.timeout - * @param {import('@libp2p/interfaces/peer-id').PeerId} [argv.peerId] - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, format, timeout, peerId }) { const id = await ipfs.id({ timeout, @@ -54,3 +54,5 @@ export default { print(JSON.stringify(id, null, 2)) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/index.js b/packages/ipfs-cli/src/commands/index.js index bc85b4481b..eedc4dd185 100644 --- a/packages/ipfs-cli/src/commands/index.js +++ b/packages/ipfs-cli/src/commands/index.js @@ -4,7 +4,6 @@ import block from './block.js' import bootstrap from './bootstrap.js' import cat from './cat.js' import cid from './cid.js' -import commands from './commands.js' import config from './config.js' import daemon from './daemon.js' import dag from './dag.js' @@ -30,6 +29,7 @@ import stats from './stats.js' import swarm from './swarm.js' import version from './version.js' +/** @type {import('yargs').CommandModule[]} */ export const commandList = [ add, bitswap, @@ -37,7 +37,6 @@ export const commandList = [ bootstrap, cat, cid, - commands, config, daemon, dag, diff --git a/packages/ipfs-cli/src/commands/init.js b/packages/ipfs-cli/src/commands/init.js index b19f94a2eb..08671c7bb6 100644 --- a/packages/ipfs-cli/src/commands/init.js +++ b/packages/ipfs-cli/src/commands/init.js @@ -8,81 +8,71 @@ const log = logger('ipfs:cli:init') /** @type {Record} */ const keyTypes = { ed25519: 'Ed25519', - rsa: 'RSA', - secp256k1: 'secp256k1' + rsa: 'RSA' } -export default { - command: 'init [default-config] [options]', - describe: 'Initialize a local IPFS node\n\n' + - 'If you are going to run IPFS in a server environment, you may want to ' + - 'initialize it using the \'server\' profile.\n\n' + - 'For the list of available profiles run `jsipfs config profile ls`', +/** + * @typedef {object} Argv + * @property {import('../types').Context} Argv.ctx + * @property {string} Argv.defaultConfig + * @property {'rsa' | 'ed25519' | 'secp256k1'} Argv.algorithm + * @property {number} Argv.bits + * @property {boolean} Argv.emptyRepo + * @property {string} Argv.privateKey + * @property {string[]} Argv.profile + * @property {string} Argv.pass + */ - /** - * @param {import('yargs').Argv} yargs - */ - builder (yargs) { - return yargs - .epilog(ipfsPathHelp) - .positional('default-config', { - describe: 'Node config, this should be a path to a file or JSON and will be merged with the default config. See https://github.com/ipfs/js-ipfs#optionsconfig', - type: 'string' - }) - .option('algorithm', { - type: 'string', - choices: Object.keys(keyTypes), - alias: 'a', - default: 'ed25519', - describe: 'Cryptographic algorithm to use for key generation' - }) - .option('bits', { - type: 'number', - alias: 'b', - default: '2048', - describe: 'Number of bits to use if the generated private key is RSA (defaults to 2048)', - coerce: Number - }) - .option('empty-repo', { - alias: 'e', - type: 'boolean', - describe: "Don't add and pin help files to the local storage" - }) - .option('private-key', { - alias: 'k', - type: 'string', - describe: 'Pre-generated private key to use for the repo' - }) - .option('profile', { - alias: 'p', - type: 'string', - describe: 'Apply profile settings to config. Multiple profiles can be separated by \',\'', - coerce: (value) => { - return (value || '').split(',') - } - }) +/** @type {import('yargs').CommandModule} */ +const command = { + command: 'init [defaultConfig]', + describe: 'Initialize a local IPFS node. If you are going to run IPFS in a server environment, you may want to initialize it using the \'server\' profile. For the list of available profiles run `jsipfs config profile ls`. ' + ipfsPathHelp, + + builder: { + defaultConfig: { + describe: 'Node config, this should be a path to a file or JSON and will be merged with the default config. See https://github.com/ipfs/js-ipfs#optionsconfig', + string: true + }, + algorithm: { + string: true, + choices: Object.keys(keyTypes), + alias: 'a', + default: 'ed25519', + describe: 'Cryptographic algorithm to use for key generation' + }, + bits: { + number: true, + alias: 'b', + default: '2048', + describe: 'Number of bits to use if the generated private key is RSA (defaults to 2048)', + coerce: Number + }, + emptyRepo: { + alias: 'e', + boolean: true, + describe: "Don't add and pin help files to the local storage" + }, + privateKey: { + alias: 'k', + string: true, + describe: 'Pre-generated private key to use for the repo' + }, + profile: { + alias: 'p', + string: true, + describe: 'Apply profile settings to config. Multiple profiles can be separated by \',\'', + coerce: (value) => { + return (value || '').split(',') + } + } }, - /** - * @param {object} argv - * @param {import('../types').Context} argv.ctx - * @param {string} argv.defaultConfig - * @param {'rsa' | 'ed25519' | 'secp256k1'} argv.algorithm - * @param {number} argv.bits - * @param {boolean} argv.emptyRepo - * @param {string} argv.privateKey - * @param {string[]} argv.profile - * @param {string} argv.pass - * - * @returns {Promise} - */ - async handler (argv) { - const { print, repoPath } = argv.ctx + async handler ({ ctx: { print, repoPath }, defaultConfig, algorithm, bits, privateKey, emptyRepo, profile, pass }) { let config = {} // read and parse config file - if (argv.defaultConfig) { + if (defaultConfig) { try { - const raw = fs.readFileSync(argv.defaultConfig, { encoding: 'utf8' }) + const raw = fs.readFileSync(defaultConfig, { encoding: 'utf8' }) config = JSON.parse(raw) } catch (/** @type {any} */ error) { log(error) @@ -96,13 +86,13 @@ export default { await IPFS.create({ repo: repoPath, init: { - algorithm: keyTypes[argv.algorithm], - bits: argv.bits, - privateKey: argv.privateKey, - emptyRepo: argv.emptyRepo, - profiles: argv.profile + algorithm: keyTypes[algorithm], + bits: bits, + privateKey: privateKey, + emptyRepo: emptyRepo, + profiles: profile }, - pass: argv.pass, + pass: pass, start: false, config }) @@ -114,3 +104,5 @@ export default { } } } + +export default command diff --git a/packages/ipfs-cli/src/commands/key.js b/packages/ipfs-cli/src/commands/key.js index cb63fa191b..232450a517 100644 --- a/packages/ipfs-cli/src/commands/key.js +++ b/packages/ipfs-cli/src/commands/key.js @@ -1,16 +1,22 @@ import { commands } from './key/index.js' -export default { +/** @type {import('yargs').CommandModule} */ +const command = { command: 'key ', - description: 'Manage your keys', + describe: 'Manage your keys', - /** - * @param {import('yargs').Argv} yargs - */ builder (yargs) { + commands.forEach(command => { + yargs.command(command) + }) + return yargs - // @ts-expect-error types are wrong - .command(commands) + }, + + handler () { + } } + +export default command diff --git a/packages/ipfs-cli/src/commands/key/export.js b/packages/ipfs-cli/src/commands/key/export.js index b86cd671b0..eec1e0fb19 100644 --- a/packages/ipfs-cli/src/commands/key/export.js +++ b/packages/ipfs-cli/src/commands/key/export.js @@ -1,7 +1,17 @@ import fs from 'fs' import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {string} Argv.name + * @property {string} Argv.passout + * @property {string} Argv.output + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'export ', describe: 'Export the key as a password protected PKCS #8 PEM file', @@ -10,31 +20,21 @@ export default { passout: { alias: 'p', describe: 'Password for the PEM', - type: 'string', + string: true, demandOption: true }, output: { alias: 'o', describe: 'Output file', - type: 'string', + string: true, default: 'stdout' }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {string} argv.name - * @param {string} argv.passout - * @param {string} argv.output - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx, name, passout, output, timeout }) { const { ipfs } = ctx const pem = await ipfs.key.export(name, passout, { @@ -47,3 +47,5 @@ export default { } } } + +export default command diff --git a/packages/ipfs-cli/src/commands/key/gen.js b/packages/ipfs-cli/src/commands/key/gen.js index 108c28de38..e8177c2a4a 100644 --- a/packages/ipfs-cli/src/commands/key/gen.js +++ b/packages/ipfs-cli/src/commands/key/gen.js @@ -3,7 +3,17 @@ import { stripControlCharacters } from '../../utils.js' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {string} Argv.name + * @property {string} Argv.type + * @property {number} Argv.size + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'gen ', describe: 'Create a new key', @@ -17,26 +27,16 @@ export default { }, size: { alias: 's', - describe: 'size of the key to generate.', + describe: 'size of the key to generate', default: 2048, - type: 'number' + number: true }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {string} argv.name - * @param {string} argv.type - * @param {number} argv.size - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, name, type, size, timeout }) { const key = await ipfs.key.gen(name, { type: type.toLowerCase() === 'rsa' ? 'RSA' : 'Ed25519', @@ -46,3 +46,5 @@ export default { print(`generated ${key.id} ${stripControlCharacters(key.name)}`) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/key/import.js b/packages/ipfs-cli/src/commands/key/import.js index b66161c8b2..2b9c81265c 100644 --- a/packages/ipfs-cli/src/commands/key/import.js +++ b/packages/ipfs-cli/src/commands/key/import.js @@ -1,7 +1,17 @@ import fs from 'fs' import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {string} Argv.name + * @property {string} Argv.input + * @property {string} Argv.passin + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'import ', describe: 'Import the key from a PKCS #8 PEM file', @@ -10,34 +20,21 @@ export default { passin: { alias: 'p', describe: 'Password for the PEM', - type: 'string' + string: true }, input: { alias: 'i', describe: 'Input PEM file', - type: 'string', + string: true, demandOption: true, - /** - * @param {string} input - */ coerce: input => fs.readFileSync(input, 'utf8') }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {string} argv.name - * @param {string} argv.input - * @param {string} argv.passin - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, name, input, passin, timeout }) { const key = await ipfs.key.import(name, input, passin, { timeout @@ -45,3 +42,5 @@ export default { print(`imported ${key.id} ${key.name}`) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/key/index.js b/packages/ipfs-cli/src/commands/key/index.js index 5b378b1ab7..c5dfc6e21e 100644 --- a/packages/ipfs-cli/src/commands/key/index.js +++ b/packages/ipfs-cli/src/commands/key/index.js @@ -5,6 +5,7 @@ import keyList from './list.js' import keyRename from './rename.js' import keyRm from './rm.js' +/** @type {import('yargs').CommandModule[]} */ export const commands = [ keyExport, keyGen, diff --git a/packages/ipfs-cli/src/commands/key/list.js b/packages/ipfs-cli/src/commands/key/list.js index be9ae12f40..b12c78503d 100644 --- a/packages/ipfs-cli/src/commands/key/list.js +++ b/packages/ipfs-cli/src/commands/key/list.js @@ -3,25 +3,25 @@ import { stripControlCharacters } from '../../utils.js' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'list', describe: 'List all local keys', builder: { timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, timeout }) { const keys = await ipfs.key.list({ timeout @@ -29,3 +29,5 @@ export default { keys.forEach((ki) => print(`${ki.id} ${stripControlCharacters(ki.name)}`)) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/key/rename.js b/packages/ipfs-cli/src/commands/key/rename.js index 03cd73ee6b..414def7f27 100644 --- a/packages/ipfs-cli/src/commands/key/rename.js +++ b/packages/ipfs-cli/src/commands/key/rename.js @@ -3,27 +3,27 @@ import { stripControlCharacters } from '../../utils.js' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {string} Argv.name + * @property {string} Argv.newName + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'rename ', describe: 'Rename a key', builder: { timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {string} argv.name - * @param {string} argv.newName - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, name, newName, timeout }) { const res = await ipfs.key.rename(name, newName, { timeout @@ -31,3 +31,5 @@ export default { print(`renamed to ${res.id} ${stripControlCharacters(res.now)}`) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/key/rm.js b/packages/ipfs-cli/src/commands/key/rm.js index ec00aca745..ef51a61f1d 100644 --- a/packages/ipfs-cli/src/commands/key/rm.js +++ b/packages/ipfs-cli/src/commands/key/rm.js @@ -3,26 +3,26 @@ import { stripControlCharacters } from '../../utils.js' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {string} Argv.name + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'rm ', describe: 'Remove a key', builder: { timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {string} argv.name - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, name, timeout }) { const key = await ipfs.key.rm(name, { timeout @@ -30,3 +30,5 @@ export default { print(`${key.id} ${stripControlCharacters(key.name)}`) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/ls.js b/packages/ipfs-cli/src/commands/ls.js index 80efc6d342..e4cb3f67ee 100644 --- a/packages/ipfs-cli/src/commands/ls.js +++ b/packages/ipfs-cli/src/commands/ls.js @@ -3,7 +3,17 @@ import { formatMode } from 'ipfs-core-utils/files/format-mode' import { formatMtime } from 'ipfs-core-utils/files/format-mtime' import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../types').Context} Argv.ctx + * @property {string} Argv.key + * @property {boolean} Argv.headers + * @property {string} Argv.cidBase + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'ls ', describe: 'List files for the given directory', @@ -11,31 +21,21 @@ export default { builder: { v: { alias: 'headers', - desc: 'Print table headers (Hash, Size, Name).', - type: 'boolean', + desc: 'Print table headers (Hash, Size, Name)', + boolean: true, default: false }, 'cid-base': { - describe: 'Number base to display CIDs in.', - type: 'string', + describe: 'Number base to display CIDs in', + string: true, default: 'base58btc' }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../types').Context} argv.ctx - * @param {string} argv.key - * @param {boolean} argv.headers - * @param {string} argv.cidBase - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, key, headers, cidBase, timeout }) { // replace multiple slashes key = key.replace(/\/(\/+)/g, '/') @@ -107,3 +107,5 @@ export default { } } } + +export default command diff --git a/packages/ipfs-cli/src/commands/name.js b/packages/ipfs-cli/src/commands/name.js index 157513cba7..c5f85b7f89 100644 --- a/packages/ipfs-cli/src/commands/name.js +++ b/packages/ipfs-cli/src/commands/name.js @@ -6,20 +6,23 @@ the private key enables publishing new (signed) values. In both publish and resolve, the default name used is the node's own PeerID, which is the hash of its public key. */ -export default { +/** @type {import('yargs').CommandModule} */ +const command = { command: 'name ', - description: 'Publish and resolve IPNS names.', + describe: 'Publish and resolve IPNS names', - /** - * @param {import('yargs').Argv} yargs - */ builder (yargs) { commands.forEach(command => { - // @ts-expect-error types are wrong yargs.command(command) }) return yargs + }, + + handler () { + } } + +export default command diff --git a/packages/ipfs-cli/src/commands/name/index.js b/packages/ipfs-cli/src/commands/name/index.js index 135e4af336..eb6c3c8b31 100644 --- a/packages/ipfs-cli/src/commands/name/index.js +++ b/packages/ipfs-cli/src/commands/name/index.js @@ -2,6 +2,7 @@ import namePublish from './publish.js' import namePubsub from './pubsub.js' import nameResolve from './resolve.js' +/** @type {import('yargs').CommandModule[]} */ export const commands = [ namePublish, namePubsub, diff --git a/packages/ipfs-cli/src/commands/name/publish.js b/packages/ipfs-cli/src/commands/name/publish.js index ed6b969a2e..66f35483ca 100644 --- a/packages/ipfs-cli/src/commands/name/publish.js +++ b/packages/ipfs-cli/src/commands/name/publish.js @@ -3,56 +3,56 @@ import { stripControlCharacters } from '../../utils.js' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {import('multiformats/cid').CID} Argv.ipfsPath + * @property {boolean} Argv.resolve + * @property {string} Argv.lifetime + * @property {string} Argv.key + * @property {string} Argv.ttl + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'publish ', - describe: 'Publish IPNS names.', + describe: 'Publish IPNS names', builder: { ipfsPath: { - type: 'string' + string: true }, resolve: { alias: 'r', - describe: 'Resolve given path before publishing. Default: true.', + describe: 'Resolve given path before publishing. Default: true', default: true, - type: 'boolean' + boolean: true }, lifetime: { alias: 't', - describe: 'Time duration that the record will be valid for. Default: 24h.', + describe: 'Time duration that the record will be valid for. Default: 24h', default: '24h', - type: 'string' + string: true }, key: { alias: 'k', - describe: 'Name of the key to be used, as listed by "ipfs key list -l". Default: self.', + describe: 'Name of the key to be used, as listed by "ipfs key list -l". Default: self', default: 'self', - type: 'string' + string: true }, ttl: { - describe: 'Time duration this record should be cached for (caution: experimental).', + describe: 'Time duration this record should be cached for (caution: experimental)', default: '', - type: 'string' + string: true }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {import('multiformats/cid').CID} argv.ipfsPath - * @param {boolean} argv.resolve - * @param {string} argv.lifetime - * @param {string} argv.key - * @param {string} argv.ttl - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, ipfsPath, resolve, lifetime, key, ttl, timeout }) { const result = await ipfs.name.publish(ipfsPath, { resolve, @@ -64,3 +64,5 @@ export default { print(`Published to ${stripControlCharacters(result.name)}: ${result.value}`) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/name/pubsub.js b/packages/ipfs-cli/src/commands/name/pubsub.js index 3e324b6e8b..8106bebc17 100644 --- a/packages/ipfs-cli/src/commands/name/pubsub.js +++ b/packages/ipfs-cli/src/commands/name/pubsub.js @@ -1,19 +1,30 @@ import { commands } from './pubsub/index.js' +/** + * @typedef {import('yargs').Argv} Argv + */ + /* Manage and inspect the state of the IPNS pubsub resolver. Note: this command is experimental and subject to change as the system is refined. */ -export default { +/** @type {import('yargs').CommandModule} */ +const command = { command: 'pubsub', - description: 'IPNS pubsub management.', + describe: 'IPNS pubsub management', - /** - * @param {import('yargs').Argv} yargs - */ builder (yargs) { - // @ts-expect-error types are wrong - return yargs.command(commands) + commands.forEach(command => { + yargs.command(command) + }) + + return yargs + }, + + handler () { + } } + +export default command diff --git a/packages/ipfs-cli/src/commands/name/pubsub/cancel.js b/packages/ipfs-cli/src/commands/name/pubsub/cancel.js index 80b5e69d64..f2cb52bea9 100644 --- a/packages/ipfs-cli/src/commands/name/pubsub/cancel.js +++ b/packages/ipfs-cli/src/commands/name/pubsub/cancel.js @@ -1,25 +1,25 @@ import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../../../types').Context} Argv.ctx + * @property {string} Argv.name + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'cancel ', - describe: 'Cancel a name subscription.', + describe: 'Cancel a name subscription', builder: { timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../../types').Context} argv.ctx - * @param {string} argv.name - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, name, timeout }) { const result = await ipfs.name.pubsub.cancel(name, { timeout @@ -27,3 +27,5 @@ export default { print(result.canceled ? 'canceled' : 'no subscription') } } + +export default command diff --git a/packages/ipfs-cli/src/commands/name/pubsub/index.js b/packages/ipfs-cli/src/commands/name/pubsub/index.js index b22f1c2153..e46ebb62c0 100644 --- a/packages/ipfs-cli/src/commands/name/pubsub/index.js +++ b/packages/ipfs-cli/src/commands/name/pubsub/index.js @@ -2,6 +2,7 @@ import namePubsubCancel from './cancel.js' import namePubsubState from './state.js' import namePubsubSubs from './subs.js' +/** @type {import('yargs').CommandModule[]} */ export const commands = [ namePubsubCancel, namePubsubState, diff --git a/packages/ipfs-cli/src/commands/name/pubsub/state.js b/packages/ipfs-cli/src/commands/name/pubsub/state.js index e0f1fe46d5..b89d9ef8e2 100644 --- a/packages/ipfs-cli/src/commands/name/pubsub/state.js +++ b/packages/ipfs-cli/src/commands/name/pubsub/state.js @@ -1,24 +1,24 @@ import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../../../types').Context} Argv.ctx + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'state', - describe: 'Query the state of IPNS pubsub.', + describe: 'Query the state of IPNS pubsub', builder: { timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../../types').Context} argv.ctx - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, timeout }) { const result = await ipfs.name.pubsub.state({ timeout @@ -26,3 +26,5 @@ export default { print(result.enabled ? 'enabled' : 'disabled') } } + +export default command diff --git a/packages/ipfs-cli/src/commands/name/pubsub/subs.js b/packages/ipfs-cli/src/commands/name/pubsub/subs.js index 0ba9f8fc28..5c59e6e598 100644 --- a/packages/ipfs-cli/src/commands/name/pubsub/subs.js +++ b/packages/ipfs-cli/src/commands/name/pubsub/subs.js @@ -3,25 +3,25 @@ import { stripControlCharacters } from '../../../utils.js' -export default { +/** + * @typedef {object} Argv + * @property {import('../../../types').Context} Argv.ctx + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'subs', - describe: 'Show current name subscriptions.', + describe: 'Show current name subscriptions', builder: { timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../../types').Context} argv.ctx - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, timeout }) { const result = await ipfs.name.pubsub.subs({ timeout @@ -29,3 +29,5 @@ export default { result.forEach(s => print(stripControlCharacters(s))) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/name/resolve.js b/packages/ipfs-cli/src/commands/name/resolve.js index e848206dbf..caf29895da 100644 --- a/packages/ipfs-cli/src/commands/name/resolve.js +++ b/packages/ipfs-cli/src/commands/name/resolve.js @@ -1,46 +1,46 @@ import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {string} Argv.name + * @property {boolean} Argv.nocache + * @property {boolean} Argv.recursive + * @property {boolean} Argv.stream + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'resolve ', - describe: 'Resolve IPNS names.', + describe: 'Resolve IPNS names', builder: { nocache: { - type: 'boolean', + boolean: true, alias: 'n', - describe: 'Do not use cached entries. Default: false.', + describe: 'Do not use cached entries. Default: false', default: false }, recursive: { - type: 'boolean', + boolean: true, alias: 'r', - describe: 'Resolve until the result is not an IPNS name. Default: true.', + describe: 'Resolve until the result is not an IPNS name. Default: true', default: true }, stream: { - type: 'boolean', + boolean: true, alias: 's', - describe: 'Stream entries as they are found.', + describe: 'Stream entries as they are found', default: false }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {string} argv.name - * @param {boolean} argv.nocache - * @param {boolean} argv.recursive - * @param {boolean} argv.stream - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, nocache, recursive, name, stream, timeout }) { let bestValue @@ -52,3 +52,5 @@ export default { if (!stream) print(bestValue || '') } } + +export default command diff --git a/packages/ipfs-cli/src/commands/object.js b/packages/ipfs-cli/src/commands/object.js index de1a5dfe4f..ce3676fea8 100644 --- a/packages/ipfs-cli/src/commands/object.js +++ b/packages/ipfs-cli/src/commands/object.js @@ -1,16 +1,22 @@ import { commands } from './object/index.js' -export default { +/** @type {import('yargs').CommandModule} */ +const command = { command: 'object ', - description: 'Interact with ipfs objects.', + describe: 'Interact with ipfs objects', - /** - * @param {import('yargs').Argv} yargs - */ builder (yargs) { + commands.forEach(command => { + yargs.command(command) + }) + return yargs - // @ts-expect-error types are wrong - .command(commands) + }, + + handler () { + } } + +export default command diff --git a/packages/ipfs-cli/src/commands/object/data.js b/packages/ipfs-cli/src/commands/object/data.js index 26c401aa8c..73047dac86 100644 --- a/packages/ipfs-cli/src/commands/object/data.js +++ b/packages/ipfs-cli/src/commands/object/data.js @@ -1,32 +1,34 @@ import parseDuration from 'parse-duration' import { coerceCID } from '../../utils.js' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {import('multiformats/cid').CID} Argv.key + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'data ', describe: 'Outputs the raw bytes in an IPFS object', builder: { key: { - type: 'string', + string: true, coerce: coerceCID }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {import('multiformats/cid').CID} argv.key - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, key, timeout }) { const data = await ipfs.object.data(key, { timeout }) print(data, false) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/object/get.js b/packages/ipfs-cli/src/commands/object/get.js index 8d06ea0dbc..0e9f9982f9 100644 --- a/packages/ipfs-cli/src/commands/object/get.js +++ b/packages/ipfs-cli/src/commands/object/get.js @@ -6,41 +6,41 @@ import { coerceCID } from '../../utils.js' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {import('multiformats/cid').CID} Argv.key + * @property {'base64' | 'text' | 'hex'} Argv.dataEncoding + * @property {string} Argv.cidBase + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'get ', describe: 'Get and serialize the DAG node named by ', builder: { key: { - type: 'string', + string: true, coerce: coerceCID }, 'data-encoding': { - type: 'string', + string: true, default: 'base64' }, 'cid-base': { - describe: 'Number base to display CIDs in. Note: specifying a CID base for v0 CIDs will have no effect.', - type: 'string', + describe: 'Number base to display CIDs in. Note: specifying a CID base for v0 CIDs will have no effect', + string: true, default: 'base58btc' }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {import('multiformats/cid').CID} argv.key - * @param {'base64' | 'text' | 'hex'} argv.dataEncoding - * @param {string} argv.cidBase - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, key, dataEncoding, cidBase, timeout }) { const node = await ipfs.object.get(key, { timeout }) @@ -79,3 +79,5 @@ export default { print(JSON.stringify(answer)) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/object/index.js b/packages/ipfs-cli/src/commands/object/index.js index d1a79b3f79..775e604a72 100644 --- a/packages/ipfs-cli/src/commands/object/index.js +++ b/packages/ipfs-cli/src/commands/object/index.js @@ -6,6 +6,7 @@ import objectPatch from './patch.js' import objectPut from './put.js' import objectStat from './stat.js' +/** @type {import('yargs').CommandModule[]} */ export const commands = [ objectData, objectGet, diff --git a/packages/ipfs-cli/src/commands/object/links.js b/packages/ipfs-cli/src/commands/object/links.js index 94d945977a..bdfb1abb2e 100644 --- a/packages/ipfs-cli/src/commands/object/links.js +++ b/packages/ipfs-cli/src/commands/object/links.js @@ -4,36 +4,36 @@ import { coerceCID } from '../../utils.js' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {import('multiformats/cid').CID} Argv.key + * @property {string} Argv.cidBase + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'links ', describe: 'Outputs the links pointed to by the specified object', builder: { key: { - type: 'string', + string: true, coerce: coerceCID }, 'cid-base': { - describe: 'Number base to display CIDs in. Note: specifying a CID base for v0 CIDs will have no effect.', - type: 'string', + describe: 'Number base to display CIDs in. Note: specifying a CID base for v0 CIDs will have no effect', + string: true, default: 'base58btc' }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {import('multiformats/cid').CID} argv.key - * @param {string} argv.cidBase - * @param {number} argv.timeout - * - * @returns {Promise} - */ async handler ({ ctx: { ipfs, print }, key, cidBase, timeout }) { const links = await ipfs.object.links(key, { timeout }) const base = await ipfs.bases.getBase(cidBase) @@ -44,3 +44,5 @@ export default { }) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/object/new.js b/packages/ipfs-cli/src/commands/object/new.js index 830410b056..11ff8b0e6e 100644 --- a/packages/ipfs-cli/src/commands/object/new.js +++ b/packages/ipfs-cli/src/commands/object/new.js @@ -1,31 +1,31 @@ import parseDuration from 'parse-duration' -export default { +/** + * @typedef {object} Argv + * @property {import('../../types').Context} Argv.ctx + * @property {'unixfs-dir'} Argv.template + * @property {string} Argv.cidBase + * @property {number} Argv.timeout + */ + +/** @type {import('yargs').CommandModule} */ +const command = { command: 'new [