From 74aee8b3d78f233c3199a3e9a6c0ac628a31a433 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Mon, 16 May 2022 15:20:38 +0100 Subject: [PATCH] feat: update to libp2p 0.37.x (#4092) 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 --- .github/workflows/examples.yml | 224 +++++++++--------- .github/workflows/externals.yml | 14 +- .github/workflows/test.yml | 62 +---- 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 +- package.json | 1 - .../{.aegir.cjs => .aegir.js} | 3 +- packages/interface-ipfs-core/package.json | 62 ++--- packages/interface-ipfs-core/src/add-all.js | 44 ++-- packages/interface-ipfs-core/src/add.js | 26 +- .../interface-ipfs-core/src/bitswap/stat.js | 4 +- .../src/bitswap/transfer.js | 14 +- .../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 | 14 +- 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 | 10 +- .../interface-ipfs-core/src/dht/find-peer.js | 9 +- .../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 | 66 +++--- 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 | 25 +- .../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 | 221 +++++++++-------- .../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 | 47 ++-- .../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 | 18 +- .../src/utils/test-timeout.js | 2 +- packages/interface-ipfs-core/tsconfig.json | 4 +- packages/ipfs-cli/package.json | 72 +++--- packages/ipfs-cli/src/commands/add.js | 128 +++++----- packages/ipfs-cli/src/commands/bitswap.js | 21 +- .../ipfs-cli/src/commands/bitswap/index.js | 1 + .../ipfs-cli/src/commands/bitswap/stat.js | 34 +-- .../ipfs-cli/src/commands/bitswap/unwant.js | 30 ++- .../ipfs-cli/src/commands/bitswap/wantlist.js | 34 +-- packages/ipfs-cli/src/commands/block.js | 20 +- packages/ipfs-cli/src/commands/block/get.js | 22 +- packages/ipfs-cli/src/commands/block/index.js | 1 + packages/ipfs-cli/src/commands/block/put.js | 42 ++-- packages/ipfs-cli/src/commands/block/rm.js | 28 ++- packages/ipfs-cli/src/commands/block/stat.js | 28 ++- packages/ipfs-cli/src/commands/bootstrap.js | 20 +- .../ipfs-cli/src/commands/bootstrap/add.js | 28 ++- .../ipfs-cli/src/commands/bootstrap/index.js | 1 + .../ipfs-cli/src/commands/bootstrap/list.js | 18 +- .../ipfs-cli/src/commands/bootstrap/rm.js | 28 ++- packages/ipfs-cli/src/commands/cat.js | 28 ++- packages/ipfs-cli/src/commands/cid.js | 21 +- packages/ipfs-cli/src/commands/cid/base32.js | 18 +- packages/ipfs-cli/src/commands/cid/bases.js | 26 +- packages/ipfs-cli/src/commands/cid/codecs.js | 20 +- packages/ipfs-cli/src/commands/cid/format.js | 34 +-- packages/ipfs-cli/src/commands/cid/hashes.js | 20 +- packages/ipfs-cli/src/commands/cid/index.js | 1 + packages/ipfs-cli/src/commands/commands.js | 39 --- packages/ipfs-cli/src/commands/config.js | 49 ++-- 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 | 26 +- .../src/commands/config/profile/index.js | 1 + .../src/commands/config/profile/ls.js | 18 +- .../ipfs-cli/src/commands/config/replace.js | 20 +- packages/ipfs-cli/src/commands/config/show.js | 20 +- packages/ipfs-cli/src/commands/daemon.js | 90 +++---- packages/ipfs-cli/src/commands/dag.js | 20 +- packages/ipfs-cli/src/commands/dag/export.js | 22 +- packages/ipfs-cli/src/commands/dag/get.js | 38 +-- packages/ipfs-cli/src/commands/dag/import.js | 30 ++- packages/ipfs-cli/src/commands/dag/index.js | 1 + packages/ipfs-cli/src/commands/dag/put.js | 56 +++-- 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 | 30 ++- packages/ipfs-cli/src/commands/dht/get.js | 24 +- packages/ipfs-cli/src/commands/dht/index.js | 1 + packages/ipfs-cli/src/commands/dht/provide.js | 30 ++- packages/ipfs-cli/src/commands/dht/put.js | 24 +- packages/ipfs-cli/src/commands/dht/query.js | 53 +++-- packages/ipfs-cli/src/commands/dns.js | 24 +- packages/ipfs-cli/src/commands/files.js | 25 +- packages/ipfs-cli/src/commands/files/chmod.js | 46 ++-- packages/ipfs-cli/src/commands/files/cp.js | 42 ++-- packages/ipfs-cli/src/commands/files/flush.js | 22 +- packages/ipfs-cli/src/commands/files/index.js | 1 + packages/ipfs-cli/src/commands/files/ls.js | 28 ++- packages/ipfs-cli/src/commands/files/mkdir.js | 56 +++-- packages/ipfs-cli/src/commands/files/mv.js | 46 ++-- packages/ipfs-cli/src/commands/files/read.js | 28 ++- packages/ipfs-cli/src/commands/files/rm.js | 28 ++- packages/ipfs-cli/src/commands/files/stat.js | 40 ++-- packages/ipfs-cli/src/commands/files/touch.js | 48 ++-- packages/ipfs-cli/src/commands/files/write.js | 80 ++++--- packages/ipfs-cli/src/commands/get.js | 43 ++-- packages/ipfs-cli/src/commands/id.js | 32 ++- packages/ipfs-cli/src/commands/index.js | 3 +- packages/ipfs-cli/src/commands/init.js | 143 ++++++----- packages/ipfs-cli/src/commands/key.js | 20 +- packages/ipfs-cli/src/commands/key/export.js | 28 ++- packages/ipfs-cli/src/commands/key/gen.js | 30 ++- packages/ipfs-cli/src/commands/key/import.js | 31 +-- packages/ipfs-cli/src/commands/key/index.js | 1 + packages/ipfs-cli/src/commands/key/list.js | 18 +- packages/ipfs-cli/src/commands/key/rename.js | 22 +- packages/ipfs-cli/src/commands/key/rm.js | 20 +- packages/ipfs-cli/src/commands/ls.js | 32 +-- packages/ipfs-cli/src/commands/name.js | 15 +- packages/ipfs-cli/src/commands/name/index.js | 1 + .../ipfs-cli/src/commands/name/publish.js | 48 ++-- packages/ipfs-cli/src/commands/name/pubsub.js | 25 +- .../src/commands/name/pubsub/cancel.js | 22 +- .../src/commands/name/pubsub/index.js | 1 + .../src/commands/name/pubsub/state.js | 20 +- .../ipfs-cli/src/commands/name/pubsub/subs.js | 20 +- .../ipfs-cli/src/commands/name/resolve.js | 40 ++-- packages/ipfs-cli/src/commands/object.js | 20 +- packages/ipfs-cli/src/commands/object/data.js | 22 +- packages/ipfs-cli/src/commands/object/get.js | 34 +-- .../ipfs-cli/src/commands/object/index.js | 1 + .../ipfs-cli/src/commands/object/links.js | 28 ++- packages/ipfs-cli/src/commands/object/new.js | 26 +- .../ipfs-cli/src/commands/object/patch.js | 24 +- .../src/commands/object/patch/add-link.js | 34 +-- .../src/commands/object/patch/append-data.js | 30 ++- .../src/commands/object/patch/index.js | 1 + .../src/commands/object/patch/rm-link.js | 30 ++- .../src/commands/object/patch/set-data.js | 30 ++- packages/ipfs-cli/src/commands/object/put.js | 28 ++- packages/ipfs-cli/src/commands/object/stat.js | 22 +- packages/ipfs-cli/src/commands/pin.js | 20 +- packages/ipfs-cli/src/commands/pin/add.js | 42 ++-- packages/ipfs-cli/src/commands/pin/index.js | 1 + packages/ipfs-cli/src/commands/pin/ls.js | 36 +-- packages/ipfs-cli/src/commands/pin/rm.js | 30 ++- packages/ipfs-cli/src/commands/ping.js | 32 ++- packages/ipfs-cli/src/commands/pubsub.js | 20 +- .../ipfs-cli/src/commands/pubsub/index.js | 1 + packages/ipfs-cli/src/commands/pubsub/ls.js | 18 +- .../ipfs-cli/src/commands/pubsub/peers.js | 22 +- packages/ipfs-cli/src/commands/pubsub/pub.js | 24 +- packages/ipfs-cli/src/commands/pubsub/sub.js | 26 +- packages/ipfs-cli/src/commands/refs-local.js | 26 +- packages/ipfs-cli/src/commands/refs.js | 50 ++-- packages/ipfs-cli/src/commands/repo.js | 20 +- packages/ipfs-cli/src/commands/repo/gc.js | 33 +-- packages/ipfs-cli/src/commands/repo/index.js | 1 + packages/ipfs-cli/src/commands/repo/stat.js | 26 +- .../ipfs-cli/src/commands/repo/version.js | 18 +- packages/ipfs-cli/src/commands/resolve.js | 32 +-- 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 | 39 +-- 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 | 31 ++- .../src/commands/swarm/addrs/index.js | 1 + .../src/commands/swarm/addrs/local.js | 18 +- .../ipfs-cli/src/commands/swarm/connect.js | 22 +- .../ipfs-cli/src/commands/swarm/disconnect.js | 22 +- packages/ipfs-cli/src/commands/swarm/index.js | 1 + packages/ipfs-cli/src/commands/swarm/peers.js | 24 +- packages/ipfs-cli/src/commands/version.js | 36 +-- packages/ipfs-cli/src/index.js | 33 +-- packages/ipfs-cli/src/parser.js | 68 +++--- packages/ipfs-cli/src/types.ts | 2 +- packages/ipfs-cli/src/utils.js | 22 +- packages/ipfs-cli/test/add.spec.js | 2 +- packages/ipfs-cli/test/bitswap.spec.js | 9 +- 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 | 21 -- 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 | 18 +- 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 | 6 +- packages/ipfs-cli/test/init.spec.js | 28 +-- packages/ipfs-cli/test/key.spec.js | 8 +- 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 | 22 +- 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 | 9 +- packages/ipfs-cli/test/utils/ipfs-exec.js | 11 +- packages/ipfs-cli/test/utils/match-peer-id.js | 11 + packages/ipfs-cli/test/version.spec.js | 2 +- packages/ipfs-cli/tsconfig.json | 4 +- .../ipfs-client/{.aegir.cjs => .aegir.js} | 3 +- packages/ipfs-client/package.json | 17 +- packages/ipfs-client/src/index.js | 2 +- packages/ipfs-client/tsconfig.json | 4 +- .../{.aegir.cjs => .aegir.js} | 3 +- packages/ipfs-core-config/package.json | 54 ++--- packages/ipfs-core-config/src/dns.browser.js | 2 +- .../src/libp2p-pubsub-routers.browser.js | 15 +- .../src/libp2p-pubsub-routers.js | 22 +- .../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-config/tsconfig.json | 4 +- packages/ipfs-core-types/package.json | 35 +-- packages/ipfs-core-types/src/bitswap/index.ts | 5 +- .../ipfs-core-types/src/bootstrap/index.ts | 2 +- packages/ipfs-core-types/src/dht/index.ts | 36 +-- 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/stats/index.ts | 18 +- packages/ipfs-core-types/src/swarm/index.ts | 11 +- packages/ipfs-core-types/tsconfig.json | 3 +- .../ipfs-core-utils/{.aegir.cjs => .aegir.js} | 3 +- packages/ipfs-core-utils/package.json | 42 ++-- .../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 | 7 +- .../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-utils/tsconfig.json | 4 +- packages/ipfs-core/{.aegir.cjs => .aegir.js} | 13 +- packages/ipfs-core/package.json | 110 ++++----- 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 +- .../src/components/bootstrap/utils.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 | 4 +- .../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 | 48 ++-- 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 | 178 +++++++------- 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 | 34 +-- .../ipfs-core/src/components/stats/index.js | 2 +- packages/ipfs-core/src/components/stop.js | 2 +- packages/ipfs-core/src/components/storage.js | 69 ++++-- .../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 | 33 ++- packages/ipfs-core/src/components/version.js | 2 +- packages/ipfs-core/src/index.js | 8 - packages/ipfs-core/src/ipns/index.js | 31 +-- packages/ipfs-core/src/ipns/publisher.js | 108 ++++----- packages/ipfs-core/src/ipns/republisher.js | 50 ++-- 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 | 15 +- 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/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 | 29 ++- packages/ipfs-core/test/exports.spec.js | 19 -- packages/ipfs-core/test/init.spec.js | 35 +-- 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 | 65 ++--- packages/ipfs-core/test/preload.spec.js | 2 +- packages/ipfs-core/test/pubsub.spec.js | 2 +- packages/ipfs-core/test/utils.spec.js | 2 +- .../test/utils/mock-preload-node-utils.js | 7 +- .../ipfs-core/test/utils/mock-preload-node.js | 2 +- packages/ipfs-core/tsconfig.json | 4 +- packages/ipfs-daemon/package.json | 31 ++- packages/ipfs-daemon/src/index.js | 21 +- packages/ipfs-daemon/test/index.spec.js | 4 +- packages/ipfs-daemon/tsconfig.json | 4 +- .../{.aegir.cjs => .aegir.js} | 3 +- packages/ipfs-grpc-client/package.json | 35 ++- packages/ipfs-grpc-client/src/core-api/id.js | 2 +- .../src/core-api/pubsub/subscribe.js | 19 +- .../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/agent.js | 4 +- packages/ipfs-grpc-client/test/utils.spec.js | 2 +- packages/ipfs-grpc-client/tsconfig.json | 4 +- packages/ipfs-grpc-protocol/package.json | 17 +- packages/ipfs-grpc-protocol/src/index.js | 5 +- packages/ipfs-grpc-protocol/src/pubsub.proto | 4 +- packages/ipfs-grpc-protocol/tsconfig.json | 4 +- packages/ipfs-grpc-server/package.json | 34 ++- .../ipfs-grpc-server/src/endpoints/add.js | 2 +- packages/ipfs-grpc-server/src/endpoints/id.js | 6 +- .../src/endpoints/pubsub/subscribe.js | 24 +- .../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 | 11 +- 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 +- packages/ipfs-grpc-server/tsconfig.json | 4 +- .../{.aegir.cjs => .aegir.js} | 10 +- packages/ipfs-http-client/package.json | 30 +-- packages/ipfs-http-client/src/add-all.js | 1 - packages/ipfs-http-client/src/add.js | 2 +- packages/ipfs-http-client/src/bitswap/stat.js | 3 +- .../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 | 38 +-- 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 | 26 +- .../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-client/tsconfig.json | 4 +- packages/ipfs-http-gateway/package.json | 41 ++-- packages/ipfs-http-gateway/src/index.js | 12 +- .../src/resources/gateway.js | 6 +- packages/ipfs-http-gateway/src/types.ts | 2 +- .../ipfs-http-gateway/test/routes.spec.js | 8 +- packages/ipfs-http-gateway/tsconfig.json | 4 +- packages/ipfs-http-response/package.json | 39 +-- 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-response/tsconfig.json | 5 +- packages/ipfs-http-server/package.json | 46 ++-- .../src/api/resources/bitswap.js | 2 +- .../src/api/resources/config.js | 7 +- .../ipfs-http-server/src/api/resources/dag.js | 9 - .../ipfs-http-server/src/api/resources/dht.js | 63 ++--- .../src/api/resources/files-regular.js | 6 - .../ipfs-http-server/src/api/resources/id.js | 4 +- .../src/api/resources/object.js | 6 +- .../src/api/resources/ping.js | 4 +- .../src/api/resources/pubsub.js | 14 +- .../src/api/resources/shutdown.js | 1 - .../src/api/resources/stats.js | 2 +- .../ipfs-http-server/src/api/routes/debug.js | 6 +- packages/ipfs-http-server/src/index.js | 16 +- packages/ipfs-http-server/src/types.ts | 2 +- packages/ipfs-http-server/src/utils/joi.js | 19 +- .../src/utils/multipart-request-parser.js | 2 +- .../src/utils/stream-response.js | 4 +- packages/ipfs-http-server/test/cors.js | 2 +- .../ipfs-http-server/test/inject/bitswap.js | 11 +- .../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 | 58 +++-- 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 | 7 +- 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 | 15 +- .../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 | 7 +- .../ipfs-http-server/test/inject/swarm.js | 2 +- .../ipfs-http-server/test/inject/version.js | 2 +- .../test/utils/test-http-method.js | 2 +- packages/ipfs-http-server/tsconfig.json | 4 +- .../{.aegir.cjs => .aegir.js} | 11 +- .../ipfs-message-port-client/package.json | 21 +- .../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 - .../ipfs-message-port-client/tsconfig.json | 4 +- .../{.aegir.cjs => .aegir.js} | 3 +- .../ipfs-message-port-protocol/package.json | 31 +-- .../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 +- .../ipfs-message-port-protocol/tsconfig.json | 4 +- .../{.aegir.cjs => .aegir.js} | 3 +- .../ipfs-message-port-server/package.json | 21 +- .../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 +- .../ipfs-message-port-server/tsconfig.json | 4 +- packages/ipfs/{.aegir.cjs => .aegir.js} | 21 +- packages/ipfs/package.json | 58 ++--- packages/ipfs/src/cli.js | 14 +- packages/ipfs/src/index.js | 10 - packages/ipfs/src/package.js | 2 +- packages/ipfs/test/interface-http-go.js | 9 +- packages/ipfs/test/utils/factory.js | 3 - .../ipfs/test/utils/mock-pinning-service.js | 4 +- packages/ipfs/test/utils/mock-preload-node.js | 6 +- packages/ipfs/tsconfig.json | 4 +- 699 files changed, 4864 insertions(+), 4639 deletions(-) rename packages/interface-ipfs-core/{.aegir.cjs => .aegir.js} (73%) 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 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/.github/workflows/examples.yml b/.github/workflows/examples.yml index 8f089b6419..d876b0a7c7 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -18,119 +18,113 @@ jobs: with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - with: - build: | - npm run link - test-examples: - name: Test example ${{ matrix.example.name }} - needs: build - runs-on: ubuntu-latest - continue-on-error: true - strategy: - matrix: - example: - - name: ipfs browser add readable stream - repo: https://github.com/ipfs-examples/js-ipfs-browser-add-readable-stream.git - deps: ipfs-core@$PWD/packages/ipfs-core/dist - - name: ipfs browser angular - repo: https://github.com/ipfs-examples/js-ipfs-browser-angular.git - deps: ipfs-core@$PWD/packages/ipfs-core/dist,ipfs-core-types@$PWD/packages/ipfs-core-types/dist - - name: ipfs browser browserify - repo: https://github.com/ipfs-examples/js-ipfs-browser-browserify.git - deps: ipfs-core@$PWD/packages/ipfs-core/dist - - name: ipfs browser react - repo: https://github.com/ipfs-examples/js-ipfs-browser-create-react-app.git - deps: ipfs-core@$PWD/packages/ipfs-core/dist - - name: ipfs browser exchange files - repo: https://github.com/ipfs-examples/js-ipfs-browser-exchange-files.git - deps: ipfs-core@$PWD/packages/ipfs-core/dist,ipfs@$PWD/packages/ipfs/dist,ipfs-core-types@$PWD/packages/ipfs-core-types/dist,ipfs-http-client@$PWD/packages/ipfs-http-client/dist - - name: ipfs browser ipns publish - repo: https://github.com/ipfs-examples/js-ipfs-browser-ipns-publish.git - deps: ipfs-core@$PWD/packages/ipfs-core/dist,ipfs-http-client@$PWD/packages/ipfs-http-client/dist - - name: ipfs browser mfs - repo: https://github.com/ipfs-examples/js-ipfs-browser-mfs.git - deps: ipfs-core@$PWD/packages/ipfs-core/dist - # fails with No native build was found for platform=darwin arch=x64 runtime=node abi=93 uv=1 libc=glibc node=16.13.0 webpack=true - #- name: ipfs browser nextjs - # repo: https://github.com/ipfs-examples/js-ipfs-browser-nextjs.git - # deps: ipfs-core@$PWD/packages/ipfs-core/dist - - name: ipfs browser parceljs - repo: https://github.com/ipfs-examples/js-ipfs-browser-parceljs.git - deps: ipfs-core@$PWD/packages/ipfs-core/dist - - name: ipfs browser readable stream - repo: https://github.com/ipfs-examples/js-ipfs-browser-readablestream.git - deps: ipfs-core@$PWD/packages/ipfs-core/dist - - name: ipfs browser service worker - repo: https://github.com/ipfs-examples/js-ipfs-browser-service-worker.git - deps: ipfs-core@$PWD/packages/ipfs-core/dist,ipfs-message-port-client@$PWD/packages/ipfs-message-port-client/dist,ipfs-message-port-protocol@$PWD/packages/ipfs-message-port-protocol/dist,ipfs-message-port-server@$PWD/packages/ipfs-message-port-server/dist - - name: ipfs browser sharing across tabs - repo: https://github.com/ipfs-examples/js-ipfs-browser-sharing-node-across-tabs.git - deps: ipfs-core@$PWD/packages/ipfs-core/dist,ipfs-message-port-client@$PWD/packages/ipfs-message-port-client/dist,ipfs-message-port-server@$PWD/packages/ipfs-message-port-server/dist - - name: ipfs browser video streaming - repo: https://github.com/ipfs-examples/js-ipfs-browser-video-streaming.git - deps: ipfs-core@$PWD/packages/ipfs-core/dist - - name: ipfs browser vue - repo: https://github.com/ipfs-examples/js-ipfs-browser-vue.git - deps: ipfs-core@$PWD/packages/ipfs-core/dist - - name: ipfs browser webpack - repo: https://github.com/ipfs-examples/js-ipfs-browser-webpack.git - deps: ipfs-core@$PWD/packages/ipfs-core/dist - - name: ipfs circuit relaying - repo: https://github.com/ipfs-examples/js-ipfs-circuit-relaying.git - deps: ipfs-core@$PWD/packages/ipfs-core/dist,ipfs-http-client@$PWD/packages/ipfs-http-client/dist - - name: ipfs custom ipfs repo - repo: https://github.com/ipfs-examples/js-ipfs-custom-ipfs-repo.git - deps: ipfs-core@$PWD/packages/ipfs-core/dist - - name: ipfs custom ipld formats - repo: https://github.com/ipfs-examples/js-ipfs-custom-ipld-formats.git - deps: ipfs-core@$PWD/packages/ipfs-core/dist,ipfs-daemon@$PWD/packages/ipfs-daemon/dist,ipfs-http-client@$PWD/packages/ipfs-http-client/dist - - name: ipfs custom libp2p - repo: https://github.com/ipfs-examples/js-ipfs-custom-libp2p.git - deps: ipfs-core@$PWD/packages/ipfs-core/dist - - name: ipfs-http-client browser pubsub - repo: https://github.com/ipfs-examples/js-ipfs-http-client-browser-pubsub.git - deps: ipfs-http-client@$PWD/packages/ipfs-http-client/dist,ipfs@$PWD/packages/ipfs/dist - - name: ipfs-http-client bundle webpack - repo: https://github.com/ipfs-examples/js-ipfs-http-client-bundle-webpack.git - deps: ipfs-http-client@$PWD/packages/ipfs-http-client/dist,ipfs@$PWD/packages/ipfs/dist - - name: ipfs-http-client name api - repo: https://github.com/ipfs-examples/js-ipfs-http-client-name-api.git - deps: ipfs-http-client@$PWD/packages/ipfs-http-client/dist - - name: ipfs-http-client upload file - repo: https://github.com/ipfs-examples/js-ipfs-http-client-upload-file.git - deps: ipfs@$PWD/packages/ipfs/dist,ipfs-http-client@$PWD/packages/ipfs-http-client/dist - - name: ipfs 101 - repo: https://github.com/ipfs-examples/js-ipfs-101.git - deps: ipfs-core@$PWD/packages/ipfs-core/dist - - name: ipfs-client add files - repo: https://github.com/ipfs-examples/js-ipfs-ipfs-client-add-files.git - deps: ipfs@$PWD/packages/ipfs/dist,ipfs-client@$PWD/packages/ipfs-client/dist - - name: ipfs electron js - repo: https://github.com/ipfs-examples/js-ipfs-run-in-electron.git - deps: ipfs-core@$PWD/packages/ipfs-core/dist - - name: ipfs running multiple nodes - repo: https://github.com/ipfs-examples/js-ipfs-running-multiple-nodes.git - deps: ipfs@$PWD/packages/ipfs/dist - - name: ipfs traverse ipld graphs - repo: https://github.com/ipfs-examples/js-ipfs-traverse-ipld-graphs.git - deps: ipfs-core@$PWD/packages/ipfs-core/dist - - name: types with typescript - repo: https://github.com/ipfs-examples/js-ipfs-types-use-ipfs-from-ts.git - deps: ipfs-core@$PWD/packages/ipfs-core/dist - - name: types with typed js - repo: https://github.com/ipfs-examples/js-ipfs-types-use-ipfs-from-typed-js.git - deps: ipfs-core@$PWD/packages/ipfs-core/dist - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 - with: - node-version: lts/* - - uses: ipfs/aegir/actions/cache-node-modules@master - with: - build: | - npm run link - - uses: GabrielBB/xvfb-action@v1 - name: Run npm run test:external -- -- -- ${{ matrix.example.repo }} --deps ${{ matrix.example.deps }} - with: - run: npm run test:external -- -- -- ${{ matrix.example.repo }} --deps ${{ matrix.example.deps }} + # test-examples: + # name: Test example ${{ matrix.example.name }} + # needs: build + # runs-on: ubuntu-latest + # continue-on-error: true + # strategy: + # matrix: + # example: + # - name: ipfs browser add readable stream + # repo: https://github.com/ipfs-examples/js-ipfs-browser-add-readable-stream.git + # deps: ipfs-core@$PWD/packages/ipfs-core + # - name: ipfs browser angular + # repo: https://github.com/ipfs-examples/js-ipfs-browser-angular.git + # deps: ipfs-core@$PWD/packages/ipfs-core,ipfs-core-types@$PWD/packages/ipfs-core-types + # - name: ipfs browser browserify + # repo: https://github.com/ipfs-examples/js-ipfs-browser-browserify.git + # deps: ipfs-core@$PWD/packages/ipfs-core + # - name: ipfs browser react + # repo: https://github.com/ipfs-examples/js-ipfs-browser-create-react-app.git + # deps: ipfs-core@$PWD/packages/ipfs-core + # - name: ipfs browser exchange files + # repo: https://github.com/ipfs-examples/js-ipfs-browser-exchange-files.git + # deps: ipfs-core@$PWD/packages/ipfs-core,ipfs@$PWD/packages/ipfs,ipfs-core-types@$PWD/packages/ipfs-core-types,ipfs-http-client@$PWD/packages/ipfs-http-client + # - name: ipfs browser ipns publish + # repo: https://github.com/ipfs-examples/js-ipfs-browser-ipns-publish.git + # deps: ipfs-core@$PWD/packages/ipfs-core,ipfs-http-client@$PWD/packages/ipfs-http-client + # - name: ipfs browser mfs + # repo: https://github.com/ipfs-examples/js-ipfs-browser-mfs.git + # deps: ipfs-core@$PWD/packages/ipfs-core + # # fails with No native build was found for platform=darwin arch=x64 runtime=node abi=93 uv=1 libc=glibc node=16.13.0 webpack=true + # #- name: ipfs browser nextjs + # # repo: https://github.com/ipfs-examples/js-ipfs-browser-nextjs.git + # # deps: ipfs-core@$PWD/packages/ipfs-core + # - name: ipfs browser parceljs + # repo: https://github.com/ipfs-examples/js-ipfs-browser-parceljs.git + # deps: ipfs-core@$PWD/packages/ipfs-core + # - name: ipfs browser readable stream + # repo: https://github.com/ipfs-examples/js-ipfs-browser-readablestream.git + # deps: ipfs-core@$PWD/packages/ipfs-core + # - name: ipfs browser service worker + # repo: https://github.com/ipfs-examples/js-ipfs-browser-service-worker.git + # deps: ipfs-core@$PWD/packages/ipfs-core,ipfs-message-port-client@$PWD/packages/ipfs-message-port-client,ipfs-message-port-protocol@$PWD/packages/ipfs-message-port-protocol,ipfs-message-port-server@$PWD/packages/ipfs-message-port-server + # - name: ipfs browser sharing across tabs + # repo: https://github.com/ipfs-examples/js-ipfs-browser-sharing-node-across-tabs.git + # deps: ipfs-core@$PWD/packages/ipfs-core,ipfs-message-port-client@$PWD/packages/ipfs-message-port-client,ipfs-message-port-server@$PWD/packages/ipfs-message-port-server + # - name: ipfs browser video streaming + # repo: https://github.com/ipfs-examples/js-ipfs-browser-video-streaming.git + # deps: ipfs-core@$PWD/packages/ipfs-core + # - name: ipfs browser vue + # repo: https://github.com/ipfs-examples/js-ipfs-browser-vue.git + # deps: ipfs-core@$PWD/packages/ipfs-core + # - name: ipfs browser webpack + # repo: https://github.com/ipfs-examples/js-ipfs-browser-webpack.git + # deps: ipfs-core@$PWD/packages/ipfs-core + # - name: ipfs circuit relaying + # repo: https://github.com/ipfs-examples/js-ipfs-circuit-relaying.git + # deps: ipfs-core@$PWD/packages/ipfs-core,ipfs-http-client@$PWD/packages/ipfs-http-client + # - name: ipfs custom ipfs repo + # repo: https://github.com/ipfs-examples/js-ipfs-custom-ipfs-repo.git + # deps: ipfs-core@$PWD/packages/ipfs-core + # - name: ipfs custom ipld formats + # repo: https://github.com/ipfs-examples/js-ipfs-custom-ipld-formats.git + # deps: ipfs-core@$PWD/packages/ipfs-core,ipfs-daemon@$PWD/packages/ipfs-daemon,ipfs-http-client@$PWD/packages/ipfs-http-client + # - name: ipfs custom libp2p + # repo: https://github.com/ipfs-examples/js-ipfs-custom-libp2p.git + # deps: ipfs-core@$PWD/packages/ipfs-core + # - name: ipfs-http-client browser pubsub + # repo: https://github.com/ipfs-examples/js-ipfs-http-client-browser-pubsub.git + # deps: ipfs-http-client@$PWD/packages/ipfs-http-client,ipfs@$PWD/packages/ipfs + # - name: ipfs-http-client bundle webpack + # repo: https://github.com/ipfs-examples/js-ipfs-http-client-bundle-webpack.git + # deps: ipfs-http-client@$PWD/packages/ipfs-http-client,ipfs@$PWD/packages/ipfs + # - name: ipfs-http-client name api + # repo: https://github.com/ipfs-examples/js-ipfs-http-client-name-api.git + # deps: ipfs-http-client@$PWD/packages/ipfs-http-client + # - name: ipfs-http-client upload file + # repo: https://github.com/ipfs-examples/js-ipfs-http-client-upload-file.git + # deps: ipfs@$PWD/packages/ipfs,ipfs-http-client@$PWD/packages/ipfs-http-client + # - name: ipfs 101 + # repo: https://github.com/ipfs-examples/js-ipfs-101.git + # deps: ipfs-core@$PWD/packages/ipfs-core + # - name: ipfs-client add files + # repo: https://github.com/ipfs-examples/js-ipfs-ipfs-client-add-files.git + # deps: ipfs@$PWD/packages/ipfs,ipfs-client@$PWD/packages/ipfs-client + # - name: ipfs electron js + # repo: https://github.com/ipfs-examples/js-ipfs-run-in-electron.git + # deps: ipfs-core@$PWD/packages/ipfs-core + # - name: ipfs running multiple nodes + # repo: https://github.com/ipfs-examples/js-ipfs-running-multiple-nodes.git + # deps: ipfs@$PWD/packages/ipfs + # - name: ipfs traverse ipld graphs + # repo: https://github.com/ipfs-examples/js-ipfs-traverse-ipld-graphs.git + # deps: ipfs-core@$PWD/packages/ipfs-core + # - name: types with typescript + # repo: https://github.com/ipfs-examples/js-ipfs-types-use-ipfs-from-ts.git + # deps: ipfs-core@$PWD/packages/ipfs-core + # - name: types with typed js + # repo: https://github.com/ipfs-examples/js-ipfs-types-use-ipfs-from-typed-js.git + # deps: ipfs-core@$PWD/packages/ipfs-core + # steps: + # - uses: actions/checkout@v2 + # - uses: actions/setup-node@v2 + # with: + # node-version: lts/* + # - uses: ipfs/aegir/actions/cache-node-modules@master + # - uses: GabrielBB/xvfb-action@v1 + # name: Run npm run test:external -- -- -- ${{ matrix.example.repo }} --deps ${{ matrix.example.deps }} + # with: + # run: npm run test:external -- -- -- ${{ matrix.example.repo }} --deps ${{ matrix.example.deps }} diff --git a/.github/workflows/externals.yml b/.github/workflows/externals.yml index 45e6f69432..5ba3536c01 100644 --- a/.github/workflows/externals.yml +++ b/.github/workflows/externals.yml @@ -18,9 +18,6 @@ jobs: with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - with: - build: | - npm run link test-externals: name: Test external ${{ matrix.external.name }} @@ -31,25 +28,22 @@ jobs: external: - name: ipfs webui repo: https://github.com/ipfs-shipyard/ipfs-webui.git - deps: ipfs@$PWD/packages/ipfs/dist + deps: ipfs@$PWD/packages/ipfs - name: ipfs companion repo: https://github.com/ipfs-shipyard/ipfs-companion.git - deps: ipfs@$PWD/packages/ipfs/dist + deps: ipfs@$PWD/packages/ipfs - name: orbit-db-io repo: https://github.com/orbitdb/orbit-db-io.git - deps: ipfs@$PWD/packages/ipfs/dist + deps: ipfs@$PWD/packages/ipfs - name: ipfs-log repo: https://github.com/orbitdb/ipfs-log.git - deps: ipfs@$PWD/packages/ipfs/dist,orbit-db-io@next + deps: ipfs@$PWD/packages/ipfs,orbit-db-io@next steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: lts/* - uses: ipfs/aegir/actions/cache-node-modules@master - with: - build: | - npm run link - uses: GabrielBB/xvfb-action@v1 name: Run npm run test:external -- -- -- ${{ matrix.external.repo }} --deps ${{ matrix.external.deps }} --branch ${{ matrix.external.branch }} continue-on-error: true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9016980158..33ae4b0b82 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 @@ -167,28 +143,6 @@ jobs: with: flags: electron-main - test-electron-renderer: - name: Unit tests electron-renderer - needs: build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - uses: actions/setup-node@v2 - 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 - - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 - with: - flags: electron-renderer - test-interop: name: Interop tests ${{ matrix.project }} ${{ matrix.type }} runs-on: ubuntu-latest @@ -198,7 +152,6 @@ jobs: - node - browser #- electron-main - #- electron-renderer steps: - uses: actions/checkout@v2 with: @@ -207,13 +160,9 @@ 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 }} + - run: npm run test:interop -- --since ${{ github.event.pull_request.base.sha }} --concurrency 1 -- -- -- -t ${{ matrix.type }} --bail - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 with: flags: interop-${{ matrix.type }} @@ -227,7 +176,6 @@ jobs: - node - browser #- electron-main - #- electron-renderer suite: - test:interface:core - test:interface:client @@ -242,7 +190,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 +207,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 @@ -275,7 +219,6 @@ jobs: test-firefox, test-firefox-webworker, test-electron-main, - test-electron-renderer, test-interop, test-interface, test-interface-message-port-client @@ -298,9 +241,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 }} 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/package.json b/package.json index 038cdcc539..cbf0e34e92 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,6 @@ "test:firefox": "lerna run test:firefox", "test:firefox-webworker": "lerna run test:firefox-webworker", "test:electron-main": "lerna run test:electron-main", - "test:electron-renderer": "lerna run test:electron-renderer", "test:external": "lerna run test:external", "test:cli": "lerna run test:cli", "test:interop": "lerna run test:interop", 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 c89ebd20e3..9579c07136 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,10 +48,10 @@ "path": false }, "scripts": { - "clean": "rimraf ./dist", - "build": "aegir build && copyfiles './test/fixtures/**/*' ./dist/cjs && copyfiles './test/fixtures/**/*' ./dist/esm", - "lint": "aegir ts -p check && aegir lint", - "dep-check": "aegir dep-check -i ipfs-core-types -i rimraf -i copyfiles" + "clean": "aegir clean", + "build": "aegir build && copyfiles './test/fixtures/**/*' ./dist", + "lint": "aegir lint", + "dep-check": "aegir dep-check -i ipfs-core-types -i copyfiles" }, "repository": { "type": "git", @@ -63,9 +65,14 @@ "@ipld/car": "^4.1.0", "@ipld/dag-cbor": "^7.0.0", "@ipld/dag-pb": "^2.1.3", + "@libp2p/crypto": "^0.22.9", + "@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", - "aegir": "^36.0.1", + "aegir": "^37.0.11", "blockstore-core": "^1.0.2", "copyfiles": "^2.4.1", "dag-jose": "^1.0.0", @@ -76,7 +83,7 @@ "ipfs-unixfs": "^6.0.3", "ipfs-unixfs-importer": "^9.0.3", "ipfs-utils": "^9.0.6", - "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,27 +93,22 @@ "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-defer": "^4.0.0", + "p-map": "^5.3.0", + "p-retry": "^5.1.0", + "p-wait-for": "^4.1.0", + "pako": "^2.0.4", "readable-stream": "^3.4.0", - "sinon": "^12.0.01", + "sinon": "^13.0.1", "uint8arrays": "^3.0.0" }, - "devDependencies": { - "rimraf": "^3.0.2" - }, "contributors": [ "Alan Shaw ", "Alan Shaw ", 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..154fac2303 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,14 +23,14 @@ 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) const it = getIt(options) describe('.add', function () { - this.timeout(120 * 1000) + this.timeout(540 * 1000) /** @type {import('ipfs-core-types').IPFS} */ let ipfs @@ -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..de8d8f06ae 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,15 +16,14 @@ 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) describe('transfer blocks', function () { - this.timeout(60 * 1000) + this.timeout(540 * 1000) afterEach(() => factory.clean()) @@ -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..7b3a331819 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,13 +55,15 @@ async function createCar (blocks) { /** * @param {Factory} factory - * @param {Object} options + * @param {object} options */ export function testImport (factory, options) { const describe = getDescribe(options) const it = getIt(options) - describe('.dag.import', () => { + describe('.dag.import', function () { + this.timeout(540 * 1000) + /** @type {import('ipfs-core-types').IPFS} */ let ipfs before(async () => { @@ -76,7 +78,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 +157,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..11017a9ea8 100644 --- a/packages/interface-ipfs-core/src/dht/disabled.js +++ b/packages/interface-ipfs-core/src/dht/disabled.js @@ -1,8 +1,9 @@ /* 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 { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' /** * @typedef {import('ipfsd-ctl').Factory} Factory @@ -10,7 +11,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 +43,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.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 3101a0348d..0096358ea0 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) @@ -58,12 +59,12 @@ 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]) }) 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..456fc486a0 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 @@ -238,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']) ]) }) @@ -260,7 +256,7 @@ export function testGet (factory, options) { const output = await pipe( ipfs.get(cid), tarballed, - collect + (source) => all(source) ) // Check paths @@ -273,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']) ]) }) @@ -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 @@ -383,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']) ]) }) @@ -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..700d6f7d4e 100644 --- a/packages/interface-ipfs-core/src/ping/ping.js +++ b/packages/interface-ipfs-core/src/ping/ping.js @@ -1,11 +1,10 @@ /* 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 +12,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 +29,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() @@ -43,26 +41,17 @@ export function testPing (factory, options) { it('should send the specified number of packets', async () => { const count = 3 const responses = await all(ipfsA.ping(nodeBId.id, { count })) - responses.forEach(expectIsPingResponse) - - const pongs = responses.filter(isPong) - expect(pongs.length).to.equal(count) + expect(responses.length).to.be.ok() + expect(responses[0].success).to.be.true() }) 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..c73b3d286c 100644 --- a/packages/interface-ipfs-core/src/pubsub/subscribe.js +++ b/packages/interface-ipfs-core/src/pubsub/subscribe.js @@ -3,27 +3,29 @@ 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' +import pWaitFor from 'p-wait-for' /** * @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 +45,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 +66,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 +102,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 +131,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 +167,7 @@ export function testSubscribe (factory, options) { }) describe('multiple connected nodes', () => { - before(() => { + beforeEach(() => { if (ipfs1.pubsub.setMaxListeners) { ipfs1.pubsub.setMaxListeners(100) } @@ -188,12 +188,14 @@ 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' const topic = `floodsub-${nanoid()}` const ipfs1 = (await factory.spawn({ + test: true, ipfsOptions: { config: { Pubsub: { @@ -205,6 +207,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: { @@ -216,56 +219,56 @@ 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() - 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 Promise.all([ + waitForPeers(ipfs2, topic, [ipfs1Id.id], 30000), + waitForPeers(ipfs1, topic, [ipfs2Id.id], 30000) ]) - 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) - abort1.abort() - abort2.abort() + expect(sub2Msg.from.toString()).to.eql(ipfs2Id.id.toString()) }) 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 +280,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 +316,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 +332,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 +340,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 +360,17 @@ 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 + it.skip('should send/receive 100 messages', async function () { this.timeout(2 * 60 * 1000) const msgBase = 'msg - ' @@ -376,7 +378,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 +407,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 +432,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 +463,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()}` @@ -490,25 +490,29 @@ export function testSubscribe (factory, options) { expect(handler1).to.have.property('callCount', 0) expect(handler2).to.have.property('callCount', 0) - await ipfs1.pubsub.publish(topic, uint8ArrayFromString('hello world 1')) + // await gossipsub heartbeat to rebalance mesh + await delay(2000) - await delay(1000) + await ipfs1.pubsub.publish(topic, uint8ArrayFromString('hello world 1')) - expect(handler1).to.have.property('callCount', 1) - expect(handler2).to.have.property('callCount', 1) + // should receive message + await pWaitFor(() => { + return handler1.callCount === 1 && handler2.callCount === 1 + }) + // both handlers should be removed await ipfs2.pubsub.unsubscribe(topic) await ipfs1.pubsub.publish(topic, uint8ArrayFromString('hello world 2')) await delay(1000) + // should not have received message expect(handler1).to.have.property('callCount', 1) expect(handler2).to.have.property('callCount', 1) }) it('should unsubscribe individual handlers', async () => { - // @ts-ignore this is mocha this.timeout(2 * 60 * 1000) const topic = `topic-${Math.random()}` @@ -527,20 +531,29 @@ export function testSubscribe (factory, options) { expect(handler1).to.have.property('callCount', 0) expect(handler2).to.have.property('callCount', 0) - await ipfs1.pubsub.publish(topic, uint8ArrayFromString('hello world 1')) + // await gossipsub heartbeat to rebalance mesh + await delay(2000) - await delay(1000) + await ipfs1.pubsub.publish(topic, uint8ArrayFromString('hello world 1')) - expect(handler1).to.have.property('callCount', 1) - expect(handler2).to.have.property('callCount', 1) + // should receive message + await pWaitFor(() => { + return handler1.callCount === 1 && handler2.callCount === 1 + }) + // only one handler should be removed await ipfs2.pubsub.unsubscribe(topic, handler1) await ipfs1.pubsub.publish(topic, uint8ArrayFromString('hello world 2')) await delay(1000) + // one should receive message + await pWaitFor(() => { + return handler2.callCount === 2 + }) + + // other should not have received message expect(handler1).to.have.property('callCount', 1) - expect(handler2).to.have.property('callCount', 2) }) }) }) 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..5e1d46ed6e 100644 --- a/packages/interface-ipfs-core/src/swarm/peers.js +++ b/packages/interface-ipfs-core/src/swarm/peers.js @@ -1,23 +1,33 @@ /* 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 */ +/** + * @param {import('ipfs-core-types/src/swarm').PeersResult[]} peers + */ +function peersAreUnique (peers) { + const peerSet = new Set() + + peers.forEach(peer => { + peerSet.add(peer.peer.toString()) + }) + + expect(peerSet).to.have.lengthOf(peers.length) +} + /** * @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 +42,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 +61,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,15 +111,14 @@ 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]) await delay(1000) - const peersA = await nodeA.swarm.peers() - const peersB = await nodeB.swarm.peers() - expect(peersA).to.have.length(1) - expect(peersB).to.have.length(1) + + peersAreUnique(await nodeA.swarm.peers()) + peersAreUnique(await nodeB.swarm.peers()) }) it('should list peers only once even if they have multiple addresses', async () => { @@ -128,8 +137,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({ @@ -142,10 +150,9 @@ export function testPeers (factory, options) { await nodeB.swarm.connect(nodeAId.addresses[0]) await delay(1000) - const peersA = await nodeA.swarm.peers() - const peersB = await nodeB.swarm.peers() - expect(peersA).to.have.length(1) - expect(peersB).to.have.length(1) + + peersAreUnique(await nodeA.swarm.peers()) + peersAreUnique(await nodeB.swarm.peers()) }) }) } 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..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,19 +1,15 @@ -// @ts-expect-error no types -import WS from 'libp2p-websockets' -// @ts-expect-error no types -import filters from 'libp2p-websockets/src/filters.js' - -const transportKey = WS.prototype[Symbol.toStringTag] +import { WebSockets } from '@libp2p/websockets' +import { all } from '@libp2p/websockets/filters' export function ipfsOptionsWebsocketsFilterAll () { return { libp2p: { config: { - transport: { - [transportKey]: { - filter: filters.all - } - } + transports: [ + new WebSockets({ + filter: all + }) + ] } } } diff --git a/packages/interface-ipfs-core/src/utils/test-timeout.js b/packages/interface-ipfs-core/src/utils/test-timeout.js index 836d018c98..7123f2ffc3 100644 --- a/packages/interface-ipfs-core/src/utils/test-timeout.js +++ b/packages/interface-ipfs-core/src/utils/test-timeout.js @@ -29,7 +29,7 @@ export default function testTimeout (fn) { reject(new Error(`API call did not time out after ${timeTaken}ms, got ${JSON.stringify(result, null, 2)}`)) }, (/** @type {Error} */ err) => { - if (err.name === 'TimeoutError') { + if (err.toString().includes('Timeout')) { return resolve() } 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 bb7386ca22..447b2f21f9 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" @@ -49,10 +51,10 @@ "url": "git+https://github.com/ipfs/js-ipfs.git" }, "scripts": { - "lint": "aegir ts -p check && aegir lint", - "test": "npm run test:node", + "lint": "aegir lint", + "test": "aegir test -t node --cov", "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" }, @@ -60,53 +62,53 @@ "@ipld/dag-cbor": "^7.0.0", "@ipld/dag-json": "^8.0.1", "@ipld/dag-pb": "^2.1.3", + "@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": "^5.0.0", - "get-folder-size": "^2.0.1", + "execa": "^6.1.0", + "get-folder-size": "^3.1.0", "ipfs-core": "^0.14.3", "ipfs-core-types": "^0.10.3", "ipfs-core-utils": "^0.14.3", - "ipfs-daemon": "^0.12.3", + "ipfs-daemon": "^0.12.2", "ipfs-http-client": "^56.0.3", - "ipfs-repo": "^14.0.1", "ipfs-utils": "^9.0.6", - "it-all": "^1.0.4", "it-concat": "^2.0.0", - "it-first": "^1.0.4", - "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": { + "@libp2p/crypto": "^0.22.9", + "@types/get-folder-size": "^3.0.1", "@types/ncp": "^2.0.5", "@types/progress": "^2.0.3", - "@types/yargs": "^16.0.0", - "aegir": "^36.0.1", + "@types/rimraf": "^3.0.1", + "@types/yargs": "^17.0.10", + "aegir": "^37.0.11", + "ipfs-repo": "^14.0.1", + "it-all": "^1.0.4", + "it-first": "^1.0.4", "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..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,131 +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 - */ async handler ({ ctx: { ipfs, print, isDaemon, getStdin }, trickle, @@ -405,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 ef759d86c8..0ab8240430 100644 --- a/packages/ipfs-cli/src/commands/bitswap/stat.js +++ b/packages/ipfs-cli/src/commands/bitswap/stat.js @@ -1,37 +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 - */ - 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 }) @@ -69,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 a0ae111f40..54912a2089 100644 --- a/packages/ipfs-cli/src/commands/bitswap/unwant.js +++ b/packages/ipfs-cli/src/commands/bitswap/unwant.js @@ -1,36 +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 - */ async handler ({ ctx, key, cidBase, timeout }) { const { ipfs, print } = ctx const base = await ipfs.bases.getBase(cidBase) @@ -40,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 1263886a53..54132e31c1 100644 --- a/packages/ipfs-cli/src/commands/bitswap/wantlist.js +++ b/packages/ipfs-cli/src/commands/bitswap/wantlist.js @@ -1,34 +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 {string} argv.peer - * @param {string} argv.cidBase - * @param {number} argv.timeout - */ async handler ({ ctx, peer, cidBase, timeout }) { const { ipfs, print } = ctx const base = await ipfs.bases.getBase(cidBase) @@ -49,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 e717a898dc..73f0051fce 100644 --- a/packages/ipfs-cli/src/commands/block/get.js +++ b/packages/ipfs-cli/src/commands/block/get.js @@ -2,28 +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 - */ async handler ({ ctx, key, timeout }) { const { ipfs, print } = ctx const block = await ipfs.block.get(key, { @@ -36,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 35e1165d61..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,37 +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 - */ async handler ({ ctx: { ipfs, print, getStdin }, block, timeout, format, mhtype, mhlen, version, cidBase, pin }) { let data @@ -75,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 031052da39..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,29 +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 - */ async handler ({ ctx, hash, force, quiet, timeout }) { const { ipfs, print } = ctx @@ -61,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 3885b7ee0f..65ac9a6156 100644 --- a/packages/ipfs-cli/src/commands/block/stat.js +++ b/packages/ipfs-cli/src/commands/block/stat.js @@ -1,34 +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 - */ async handler ({ ctx, key, cidBase, timeout }) { const { ipfs, print } = ctx const stats = await ipfs.block.stat(key, { @@ -39,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 16414f4698..046ece3a5c 100644 --- a/packages/ipfs-cli/src/commands/bootstrap/add.js +++ b/packages/ipfs-cli/src/commands/bootstrap/add.js @@ -1,34 +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('multiaddr').Multiaddr} argv.peer - * @param {boolean} argv.default - * @param {number} argv.timeout - */ async handler ({ ctx: { ipfs, print }, peer, default: defaultPeers, timeout }) { let list @@ -47,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 47cae16a56..fe4efbf37d 100644 --- a/packages/ipfs-cli/src/commands/bootstrap/list.js +++ b/packages/ipfs-cli/src/commands/bootstrap/list.js @@ -1,22 +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 - */ async handler ({ ctx: { ipfs, print }, timeout }) { const list = await ipfs.bootstrap.list({ timeout @@ -24,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 71e6dd14dd..caa23962a8 100644 --- a/packages/ipfs-cli/src/commands/bootstrap/rm.js +++ b/packages/ipfs-cli/src/commands/bootstrap/rm.js @@ -1,34 +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('multiaddr').Multiaddr} argv.peer - * @param {boolean} argv.all - * @param {number} argv.timeout - */ async handler ({ ctx: { ipfs, print }, all, peer, timeout }) { let list @@ -47,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 edd03bc683..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,31 +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 - */ 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 e1a7c802e0..5cba80a1aa 100644 --- a/packages/ipfs-cli/src/commands/cid/base32.js +++ b/packages/ipfs-cli/src/commands/cid/base32.js @@ -2,16 +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] - */ async handler ({ ctx: { print, getStdin }, cids }) { let input @@ -32,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 7c79ba128e..a3c760f2c4 100644 --- a/packages/ipfs-cli/src/commands/cid/bases.js +++ b/packages/ipfs-cli/src/commands/cid/bases.js @@ -1,28 +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] - */ handler ({ ctx: { ipfs, print }, prefix, numeric }) { for (const base of ipfs.bases.listBases()) { if (prefix && numeric) { @@ -37,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 9551f3f718..85ba7758fd 100644 --- a/packages/ipfs-cli/src/commands/cid/codecs.js +++ b/packages/ipfs-cli/src/commands/cid/codecs.js @@ -1,22 +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] - */ handler ({ ctx: { ipfs, print }, numeric }) { for (const codec of ipfs.codecs.listCodecs()) { if (numeric) { @@ -27,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 730e9a86a0..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,29 +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] - */ async handler ({ ctx: { ipfs, print, getStdin }, cids, format, cidVersion, base }) { let input @@ -108,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 eb2159fda9..d201f9bf30 100644 --- a/packages/ipfs-cli/src/commands/cid/hashes.js +++ b/packages/ipfs-cli/src/commands/cid/hashes.js @@ -1,22 +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] - */ handler ({ ctx: { ipfs, print }, numeric }) { for (const codec of ipfs.hashers.listHashers()) { if (numeric) { @@ -27,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 3a2d69c1a5..0000000000 --- a/packages/ipfs-cli/src/commands/commands.js +++ /dev/null @@ -1,39 +0,0 @@ -import path, { dirname } from 'path' -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 { - command: 'commands', - - describe: 'List all available commands', - - /** - * @param {object} argv - * @param {import('../types').Context} argv.ctx - */ - 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 a707b72b82..f40e807849 100644 --- a/packages/ipfs-cli/src/commands/config.js +++ b/packages/ipfs-cli/src/commands/config.js @@ -1,43 +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 - */ async handler ({ ctx: { ipfs, print }, value, bool, json, key, timeout }) { if (!value) { // Get the value of a given key @@ -69,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 f1040b1dd5..e1cc60de96 100644 --- a/packages/ipfs-cli/src/commands/config/edit.js +++ b/packages/ipfs-cli/src/commands/config/edit.js @@ -1,22 +1,26 @@ import path from 'path' -import execa from 'execa' +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 - */ - 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 f4a5a7eb76..aab5e0d159 100644 --- a/packages/ipfs-cli/src/commands/config/profile/apply.js +++ b/packages/ipfs-cli/src/commands/config/profile/apply.js @@ -1,30 +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 - */ async handler ({ ctx, profile, dryRun, timeout }) { const { print, ipfs, isDaemon } = ctx const diff = await ipfs.config.profiles.apply(profile, { @@ -45,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 33fa0ce7e4..acae8e2a70 100644 --- a/packages/ipfs-cli/src/commands/config/profile/ls.js +++ b/packages/ipfs-cli/src/commands/config/profile/ls.js @@ -1,22 +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 - */ async handler ({ ctx: { ipfs, print }, timeout }) { for (const profile of await ipfs.config.profiles.list({ timeout @@ -25,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 1f55d4069a..73b5c6d4e9 100644 --- a/packages/ipfs-cli/src/commands/config/replace.js +++ b/packages/ipfs-cli/src/commands/config/replace.js @@ -2,24 +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 - */ handler ({ ctx: { ipfs, isDaemon }, file, timeout }) { const filePath = path.resolve(process.cwd(), file) @@ -32,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 31377cc3e5..808c82925d 100644 --- a/packages/ipfs-cli/src/commands/config/show.js +++ b/packages/ipfs-cli/src/commands/config/show.js @@ -1,26 +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 - */ 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 5f826ed1d0..ecf20e79d9 100644 --- a/packages/ipfs-cli/src/commands/daemon.js +++ b/packages/ipfs-cli/src/commands/daemon.js @@ -1,79 +1,78 @@ 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 debug from 'debug' +import { logger } from '@libp2p/logger' import { Daemon } from 'ipfs-daemon' -const log = debug('ipfs:cli:daemon') - -export default { +const log = logger('ipfs:cli:daemon') + +/** + * @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 - */ - 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) @@ -83,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 { @@ -109,7 +108,6 @@ export default { }) } - // @ts-ignore - _httpGateway is possibly undefined if (daemon._grpcServer && daemon._grpcServer) { print(`gRPC listening on ${daemon._grpcServer.info.ma}`) } @@ -122,7 +120,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) { @@ -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 bfaa61b014..15722a84fa 100644 --- a/packages/ipfs-cli/src/commands/dag/export.js +++ b/packages/ipfs-cli/src/commands/dag/export.js @@ -1,24 +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 - */ async handler ({ ctx: { ipfs, print }, rootcid, timeout }) { const options = { timeout } const cid = CID.parse(rootcid) @@ -29,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 ebcaffa0f8..69875b8734 100644 --- a/packages/ipfs-cli/src/commands/dag/get.js +++ b/packages/ipfs-cli/src/commands/dag/get.js @@ -16,42 +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 - */ async handler ({ ctx: { ipfs, print }, cidpath, dataEnc, outputCodec, localResolve, timeout }) { const options = { localResolve, @@ -101,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 d49c941627..5b86f6bcbc 100644 --- a/packages/ipfs-cli/src/commands/dag/import.js +++ b/packages/ipfs-cli/src/commands/dag/import.js @@ -1,36 +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 - */ 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) @@ -52,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 c17c096e2a..d6de5428ad 100644 --- a/packages/ipfs-cli/src/commands/dag/put.js +++ b/packages/ipfs-cli/src/commands/dag/put.js @@ -18,78 +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 - */ 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}`) @@ -125,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 4680fde036..0dd183aca8 100644 --- a/packages/ipfs-cli/src/commands/dag/resolve.js +++ b/packages/ipfs-cli/src/commands/dag/resolve.js @@ -1,26 +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 - */ async handler ({ ctx: { ipfs, print }, ref, timeout }) { const options = { timeout @@ -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() } @@ -46,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 880bbcad91..652f8ff568 100644 --- a/packages/ipfs-cli/src/commands/dht/find-peer.js +++ b/packages/ipfs-cli/src/commands/dht/find-peer.js @@ -1,26 +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 {string} argv.peerId - * @param {number} argv.timeout - */ async handler ({ ctx: { ipfs, print }, peerId, timeout }) { for await (const event of ipfs.dht.findPeer(peerId, { timeout @@ -31,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 3409f5a6b3..4990f0d8e7 100644 --- a/packages/ipfs-cli/src/commands/dht/find-providers.js +++ b/packages/ipfs-cli/src/commands/dht/find-providers.js @@ -1,35 +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 - */ async handler ({ ctx: { ipfs, print }, key, numProviders, timeout }) { const providers = new Set() @@ -53,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 58f957f1ec..7ccae08c9a 100644 --- a/packages/ipfs-cli/src/commands/dht/get.js +++ b/packages/ipfs-cli/src/commands/dht/get.js @@ -2,28 +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 - */ async handler ({ ctx: { ipfs, print }, key, timeout }) { for await (const event of await ipfs.dht.get(key.bytes, { timeout @@ -34,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 8ad7cb33bb..536fd06861 100644 --- a/packages/ipfs-cli/src/commands/dht/provide.js +++ b/packages/ipfs-cli/src/commands/dht/provide.js @@ -1,35 +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 - */ async handler ({ ctx: { ipfs }, key, recursive, timeout }) { await ipfs.dht.provide(key, { recursive, @@ -37,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 f290867226..49f18a2fd6 100644 --- a/packages/ipfs-cli/src/commands/dht/put.js +++ b/packages/ipfs-cli/src/commands/dht/put.js @@ -1,28 +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 - */ 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 b09fb5845d..bbbafd1bb7 100644 --- a/packages/ipfs-cli/src/commands/dht/query.js +++ b/packages/ipfs-cli/src/commands/dht/query.js @@ -1,42 +1,63 @@ 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: { + number: true, + default: 20 }, timeout: { - type: 'string', + string: true, coerce: parseDuration } }, - /** - * @param {object} argv - * @param {import('../../types').Context} argv.ctx - * @param {string} argv.peerId - * @param {number} argv.timeout - */ - 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 } } } } + +export default command diff --git a/packages/ipfs-cli/src/commands/dns.js b/packages/ipfs-cli/src/commands/dns.js index dd1394ed70..a8258d6b9b 100644 --- a/packages/ipfs-cli/src/commands/dns.js +++ b/packages/ipfs-cli/src/commands/dns.js @@ -3,33 +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 - */ 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 0c4d99ce06..435112b7eb 100644 --- a/packages/ipfs-cli/src/commands/files.js +++ b/packages/ipfs-cli/src/commands/files.js @@ -1,23 +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 - */ - 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 e5031ae1a8..6e568c176f 100644 --- a/packages/ipfs-cli/src/commands/files/chmod.js +++ b/packages/ipfs-cli/src/commands/files/chmod.js @@ -3,63 +3,65 @@ 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 - */ - 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, @@ -78,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 d84120c49a..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,47 +24,36 @@ 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 - */ - 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, @@ -70,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 9113070e24..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,18 +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 - */ async handler ({ ctx: { ipfs, print }, path, @@ -40,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 eb65e08123..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,29 +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 - */ async handler ({ ctx: { ipfs, print }, path, @@ -66,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 2fb5b1cefd..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,71 +31,57 @@ 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 - */ - 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, @@ -104,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 d3e6909745..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,54 +25,42 @@ 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 - */ - 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, @@ -79,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 6321514bb7..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,28 +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 - */ async handler ({ ctx: { ipfs, print }, path, @@ -46,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 0f2ee6f5a8..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,33 +20,28 @@ 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 - */ - handler ({ + async handler ({ ctx: { ipfs }, path, recursive, timeout }) { - return ipfs.files.rm(path, { + await ipfs.files.rm(path, { recursive, timeout }) } } + +export default command diff --git a/packages/ipfs-cli/src/commands/files/stat.js b/packages/ipfs-cli/src/commands/files/stat.js index 3cd1c7e0e6..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,46 +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 - */ async handler ({ ctx: { ipfs, print }, path, @@ -100,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 de422ca0fa..515620f81b 100644 --- a/packages/ipfs-cli/src/commands/files/touch.js +++ b/packages/ipfs-cli/src/commands/files/touch.js @@ -6,66 +6,68 @@ 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 - */ - 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, @@ -86,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 8e6a953f30..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,117 +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 - */ async handler ({ ctx: { ipfs, getStdin }, path, @@ -165,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 ed5ec9c09a..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,47 +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 - */ 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)) ) @@ -127,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 27ba9d5613..f9609f6c12 100644 --- a/packages/ipfs-cli/src/commands/id.js +++ b/packages/ipfs-cli/src/commands/id.js @@ -1,33 +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', - describe: 'Peer.ID of node to look up' + 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 {string} [argv.peerId] - */ async handler ({ ctx: { ipfs, print }, format, timeout, peerId }) { const id = await ipfs.id({ timeout, @@ -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) @@ -50,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 1d768f92c4..08671c7bb6 100644 --- a/packages/ipfs-cli/src/commands/init.js +++ b/packages/ipfs-cli/src/commands/init.js @@ -1,86 +1,78 @@ 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} */ +/** @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 - */ - 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) @@ -94,15 +86,14 @@ 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, - // @ts-ignore - Expects more than {} config }) } catch (/** @type {any} */ err) { @@ -113,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 ae63c8746e..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,29 +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 - */ async handler ({ ctx, name, passout, output, timeout }) { const { ipfs } = ctx const pem = await ipfs.key.export(name, passout, { @@ -45,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 55087da4c9..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,30 +27,24 @@ 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 - */ 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 }) 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 8489c4cf02..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,32 +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 - */ async handler ({ ctx: { ipfs, print }, name, input, passin, timeout }) { const key = await ipfs.key.import(name, input, passin, { timeout @@ -43,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 2177d7e499..b12c78503d 100644 --- a/packages/ipfs-cli/src/commands/key/list.js +++ b/packages/ipfs-cli/src/commands/key/list.js @@ -3,23 +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 - */ async handler ({ ctx: { ipfs, print }, timeout }) { const keys = await ipfs.key.list({ timeout @@ -27,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 4928cc823d..414def7f27 100644 --- a/packages/ipfs-cli/src/commands/key/rename.js +++ b/packages/ipfs-cli/src/commands/key/rename.js @@ -3,25 +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 - */ async handler ({ ctx: { ipfs, print }, name, newName, timeout }) { const res = await ipfs.key.rename(name, newName, { timeout @@ -29,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 259bb7ed44..ef51a61f1d 100644 --- a/packages/ipfs-cli/src/commands/key/rm.js +++ b/packages/ipfs-cli/src/commands/key/rm.js @@ -3,24 +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 - */ async handler ({ ctx: { ipfs, print }, name, timeout }) { const key = await ipfs.key.rm(name, { timeout @@ -28,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 813a52fe14..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,29 +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 - */ async handler ({ ctx: { ipfs, print }, key, headers, cidBase, timeout }) { // replace multiple slashes key = key.replace(/\/(\/+)/g, '/') @@ -105,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 9065edb637..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-ignore 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 9e50d64b19..66f35483ca 100644 --- a/packages/ipfs-cli/src/commands/name/publish.js +++ b/packages/ipfs-cli/src/commands/name/publish.js @@ -3,54 +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 - */ async handler ({ ctx: { ipfs, print }, ipfsPath, resolve, lifetime, key, ttl, timeout }) { const result = await ipfs.name.publish(ipfsPath, { resolve, @@ -62,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 db386a1083..f2cb52bea9 100644 --- a/packages/ipfs-cli/src/commands/name/pubsub/cancel.js +++ b/packages/ipfs-cli/src/commands/name/pubsub/cancel.js @@ -1,23 +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 - */ async handler ({ ctx: { ipfs, print }, name, timeout }) { const result = await ipfs.name.pubsub.cancel(name, { timeout @@ -25,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 4097a93ba4..b89d9ef8e2 100644 --- a/packages/ipfs-cli/src/commands/name/pubsub/state.js +++ b/packages/ipfs-cli/src/commands/name/pubsub/state.js @@ -1,22 +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 - */ async handler ({ ctx: { ipfs, print }, timeout }) { const result = await ipfs.name.pubsub.state({ timeout @@ -24,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 d0f708334f..5c59e6e598 100644 --- a/packages/ipfs-cli/src/commands/name/pubsub/subs.js +++ b/packages/ipfs-cli/src/commands/name/pubsub/subs.js @@ -3,23 +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 - */ async handler ({ ctx: { ipfs, print }, timeout }) { const result = await ipfs.name.pubsub.subs({ timeout @@ -27,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 b016382644..caf29895da 100644 --- a/packages/ipfs-cli/src/commands/name/resolve.js +++ b/packages/ipfs-cli/src/commands/name/resolve.js @@ -1,44 +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 - */ async handler ({ ctx: { ipfs, print }, nocache, recursive, name, stream, timeout }) { let bestValue @@ -50,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 c3d66fd84c..73047dac86 100644 --- a/packages/ipfs-cli/src/commands/object/data.js +++ b/packages/ipfs-cli/src/commands/object/data.js @@ -1,30 +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 - */ 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 00038d3ada..0e9f9982f9 100644 --- a/packages/ipfs-cli/src/commands/object/get.js +++ b/packages/ipfs-cli/src/commands/object/get.js @@ -6,39 +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 - */ 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, @@ -77,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 0dbf1edde3..bdfb1abb2e 100644 --- a/packages/ipfs-cli/src/commands/object/links.js +++ b/packages/ipfs-cli/src/commands/object/links.js @@ -4,34 +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 - */ async handler ({ ctx: { ipfs, print }, key, cidBase, timeout }) { const links = await ipfs.object.links(key, { timeout }) const base = await ipfs.bases.getBase(cidBase) @@ -42,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 eca8009337..11ff8b0e6e 100644 --- a/packages/ipfs-cli/src/commands/object/new.js +++ b/packages/ipfs-cli/src/commands/object/new.js @@ -1,29 +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 [