From c9f6836e6c17d9741c32e16b04ff735dc72e80ea Mon Sep 17 00:00:00 2001 From: achingbrain Date: Mon, 17 Oct 2022 10:09:34 +0100 Subject: [PATCH] deps!: update to new libp2p interfaces Update to new interfaces for constructor injection --- README.md | 13 ++++++++----- package.json | 13 +++++++------ test/index.spec.js | 14 +++++++------- test/utils.js | 43 ++++++++++++++++++++++++++----------------- 4 files changed, 48 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 2ca3a3b..e0fab90 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,7 @@ # datastore-pubsub -[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io) -[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) -[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs) +[![ipfs.tech](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](https://ipfs.tech) +[![Discuss](https://img.shields.io/discourse/https/discuss.ipfs.tech/posts.svg?style=flat-square)](https://discuss.ipfs.tech) [![codecov](https://img.shields.io/codecov/c/github/ipfs/js-datastore-pubsub.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-datastore-pubsub) [![CI](https://img.shields.io/github/workflow/status/ipfs/js-datastore-pubsub/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-datastore-pubsub/actions/workflows/js-test-and-release.yml) @@ -119,8 +118,12 @@ Licensed under either of ## Contribute -Feel free to join in. All welcome. Open an [issue](https://github.com/ipfs/js-ipfs-unixfs-importer/issues)! +Contributions welcome! Please check out [the issues](https://github.com/ipfs/js-datastore-pubsub/issues). -This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md). +Also see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. + +Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md). + +Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. [![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md) diff --git a/package.json b/package.json index 56cc3aa..10080f6 100644 --- a/package.json +++ b/package.json @@ -158,27 +158,28 @@ }, "dependencies": { "@libp2p/interface-dht": "^1.0.1", - "@libp2p/interface-pubsub": "^2.0.1", + "@libp2p/interface-pubsub": "^3.0.0", "@libp2p/interfaces": "^3.0.3", "@libp2p/logger": "^2.0.0", "datastore-core": "^8.0.1", "debug": "^4.2.0", "err-code": "^3.0.1", "interface-datastore": "^7.0.0", - "uint8arrays": "^3.0.0" + "uint8arrays": "^4.0.2" }, "devDependencies": { - "@libp2p/components": "^2.0.0", - "@libp2p/floodsub": "^3.0.0", + "@libp2p/floodsub": "^5.0.0", "@libp2p/interface-compliance-tests": "^3.0.2", - "@libp2p/interface-mocks": "^4.0.2", + "@libp2p/interface-mocks": "^7.0.1", + "@libp2p/interface-peer-id": "^1.0.5", + "@libp2p/interface-registrar": "^2.0.3", "@libp2p/peer-id-factory": "^1.0.9", "@libp2p/record": "^2.0.0", "@types/detect-node": "^2.0.0", "aegir": "^37.0.13", "detect-node": "^2.0.4", "install": "^0.13.0", - "ipfs-core-types": "^0.11.1", + "ipfs-core-types": "^0.12.1", "it-pair": "^2.0.2", "libp2p": "next", "npm": "^8.10.0", diff --git a/test/index.spec.js b/test/index.spec.js index 46390a4..746a6e6 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -24,7 +24,7 @@ import { stop } from '@libp2p/interfaces/startable' * @typedef {import('@libp2p/interface-peer-id').PeerId} PeerId * @typedef {import('@libp2p/interface-dht').ValidateFn} Validator * @typedef {import('../src/types').SubscriptionKeyFn} SubscriptionKeyFn - * @typedef {import('@libp2p/components').Components} Components + * @typedef {import('./utils.js').Components} Components */ // Always returning the expected values @@ -67,13 +67,13 @@ describe('datastore-pubsub', function () { await connectPubsubNodes(componentsA, componentsB) - pubsubA = componentsA.getPubSub() - datastoreA = componentsA.getDatastore() - peerIdA = componentsA.getPeerId() + pubsubA = componentsA.pubsub + datastoreA = componentsA.datastore + peerIdA = componentsA.peerId - pubsubB = componentsB.getPubSub() - datastoreB = componentsB.getDatastore() - peerIdB = componentsB.getPeerId() + pubsubB = componentsB.pubsub + datastoreB = componentsB.datastore + peerIdB = componentsB.peerId }) const value = 'value' diff --git a/test/utils.js b/test/utils.js index 7a25af1..90ed260 100644 --- a/test/utils.js +++ b/test/utils.js @@ -1,53 +1,62 @@ import pWaitFor from 'p-wait-for' -import { FloodSub, multicodec } from '@libp2p/floodsub' +import { floodsub, multicodec } from '@libp2p/floodsub' import { createEd25519PeerId } from '@libp2p/peer-id-factory' import { connectionPair, mockRegistrar, mockConnectionManager } from '@libp2p/interface-mocks' -import { Components } from '@libp2p/components' import { MemoryDatastore } from 'datastore-core' +import { start } from '@libp2p/interfaces/startable' /** * @typedef {import('@libp2p/interface-pubsub').PubSub} PubSub * @typedef {import('@libp2p/interface-peer-id').PeerId} PeerId + * @typedef {import('@libp2p/interface-registrar').Registrar} Registrar + * @typedef {import('interface-datastore').Datastore} Datastore */ /** + * @typedef {object} Components + * @property {PeerId} peerId + * @property {Registrar} registrar + * @property {Datastore} datastore + * @property {PubSub} pubsub + * * As created by libp2p * * @returns {Promise} */ export const createComponents = async () => { - const components = new Components({ + /** @type {any} */ + const components = { peerId: await createEd25519PeerId(), registrar: mockRegistrar(), - datastore: new MemoryDatastore(), - connectionManager: mockConnectionManager() - }) + datastore: new MemoryDatastore() + } - const pubsub = new FloodSub({ + components.connectionManager = mockConnectionManager(components) + + const pubsub = floodsub({ emitSelf: true - }) - pubsub.init(components) - await pubsub.start() + })(components) + await start(pubsub) - components.setPubSub(pubsub) + components.pubsub = pubsub return components } /** * - * @param {Components} componentsA - * @param {Components} componentsB + * @param {{ peerId: PeerId, registrar: Registrar }} componentsA + * @param {{ peerId: PeerId, registrar: Registrar }} componentsB */ export const connectPubsubNodes = async (componentsA, componentsB) => { // Notify peers of connection const [c0, c1] = connectionPair(componentsA, componentsB) - componentsA.getRegistrar().getTopologies(multicodec).forEach(topology => { - topology.onConnect(componentsB.getPeerId(), c0) + componentsA.registrar.getTopologies(multicodec).forEach(topology => { + topology.onConnect(componentsB.peerId, c0) }) - componentsB.getRegistrar().getTopologies(multicodec).forEach(topology => { - topology.onConnect(componentsA.getPeerId(), c1) + componentsB.registrar.getTopologies(multicodec).forEach(topology => { + topology.onConnect(componentsA.peerId, c1) }) }