From a5e5191df2ac5634c03dcb3552517d5cfaf0d802 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Mon, 12 Apr 2021 13:15:47 +0200 Subject: [PATCH] chore: update interfaces and add types --- .github/workflows/main.yml | 8 ++++---- package.json | 15 +++++++++------ src/config.js | 6 +++--- src/index.js | 13 ++++++++++--- tsconfig.json | 10 ++++++++++ 5 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 tsconfig.json diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5256ece..98aa69b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,8 +14,8 @@ jobs: - uses: actions/checkout@v2 - run: npm install - run: npx aegir lint - - run: npx aegir dep-check -- -i wrtc -i electron-webrtc - - run: npx aegir build --no-types + - run: npx aegir dep-check + - run: npx aegir build test-node: needs: check runs-on: ${{ matrix.os }} @@ -30,7 +30,7 @@ jobs: with: node-version: ${{ matrix.node }} - run: npm install - - run: npx nyc --reporter=lcov aegir test -t node -- --bail + - run: npx aegir test -t node --cov --bail - uses: codecov/codecov-action@v1 test-chrome: needs: check @@ -45,7 +45,7 @@ jobs: steps: - uses: actions/checkout@v2 - run: npm install - - run: npx aegir test -t browser -t webworker --bail -- --browsers FirefoxHeadless + - run: npx aegir test -t browser -t webworker --bail -- --browser firefox test-webkit: needs: check runs-on: ubuntu-latest diff --git a/package.json b/package.json index 038895d..1ef7c04 100644 --- a/package.json +++ b/package.json @@ -4,16 +4,17 @@ "description": "libp2p-floodsub, also known as pubsub-flood or just dumbsub, this implementation of pubsub focused on delivering an API for Publish/Subscribe, but with no CastTree Forming (it just floods the network).", "leadMaintainer": "Vasco Santos ", "main": "src/index.js", + "types": "dist/src/index.d.ts", "scripts": { "lint": "aegir lint", "test": "aegir test", "test:node": "aegir test -t node", "test:browser": "aegir test -t browser", - "build": "aegir build --no-types", + "build": "aegir build", "docs": "aegir-docs", - "release": "aegir release --docs --no-types", - "release-minor": "aegir release --no-types --type minor --docs", - "release-major": "aegir release --no-types --type major --docs", + "release": "aegir release --docs", + "release-minor": "aegir release --type minor --docs", + "release-major": "aegir release --type major --docs", "coverage": "aegir coverage", "coverage-publish": "aegir coverage --provider coveralls" }, @@ -42,15 +43,17 @@ }, "homepage": "https://github.com/libp2p/js-libp2p-floodsub#readme", "devDependencies": { + "@types/debug": "^4.1.5", "aegir": "^33.0.0", "benchmark": "^2.1.4", + "buffer": "^6.0.3", "chai": "^4.3.4", "ipfs-utils": "^6.0.6", "it-pair": "^1.0.0", "libp2p": "^0.30.0", "libp2p-mplex": "^0.10.1", "libp2p-noise": "^2.0.1", - "libp2p-websockets": "^0.15.4", + "libp2p-websockets": "^0.15.5", "multiaddr": "^9.0.1", "os": "^0.1.1", "p-wait-for": "^3.1.0", @@ -59,7 +62,7 @@ }, "dependencies": { "debug": "^4.2.0", - "libp2p-interfaces": "libp2p/js-libp2p-interfaces#chore/update-pubsub-interface", + "libp2p-interfaces": "^0.10.0", "time-cache": "^0.3.0", "uint8arrays": "^2.1.4" }, diff --git a/src/config.js b/src/config.js index 0891e2e..c997a65 100644 --- a/src/config.js +++ b/src/config.js @@ -1,9 +1,9 @@ 'use strict' const debug = require('debug') - -const log = debug('libp2p:floodsub') -log.err = debug('libp2p:floodsub:error') +const log = Object.assign(debug('libp2p:floodsub'), { + error: debug('libp2p:floodsub:err') +}) module.exports = { log: log, diff --git a/src/index.js b/src/index.js index 7018e49..956c5a6 100644 --- a/src/index.js +++ b/src/index.js @@ -2,6 +2,7 @@ const debugName = 'libp2p:floodsub' +// @ts-ignore time-cache does not export types const TimeCache = require('time-cache') const toString = require('uint8arrays/to-string') const BaseProtocol = require('libp2p-interfaces/src/pubsub') @@ -9,6 +10,11 @@ const { utils } = require('libp2p-interfaces/src/pubsub') const { multicodec } = require('./config') +/** + * @typedef {import('libp2p-interfaces/src/pubsub').InMessage} InMessage + * @typedef {import('libp2p-interfaces/src/pubsub').RPCMessage} RPCMessage + */ + /** * FloodSub (aka dumbsub is an implementation of pubsub focused on * delivering an API for Publish/Subscribe, but with no CastTree Forming @@ -16,9 +22,9 @@ const { multicodec } = require('./config') */ class FloodSub extends BaseProtocol { /** - * @param {Libp2p} libp2p - instance of libp2p + * @param {import('libp2p')} libp2p - instance of libp2p * @param {Object} [options] - * @param {boolean} options.emitSelf - if publish should emit to self, if subscribed, defaults to false + * @param {boolean} [options.emitSelf] - if publish should emit to self, if subscribed, defaults to false * @class */ constructor (libp2p, options = {}) { @@ -64,10 +70,11 @@ class FloodSub extends BaseProtocol { * * @override * @param {InMessage} message - * @returns {void} + * @returns {Promise} */ _publish (message) { this._forwardMessage(message) + return Promise.resolve() } /** diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..ec163b1 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "aegir/src/config/tsconfig.aegir.json", + "compilerOptions": { + "outDir": "dist" + }, + "include": [ + "src", + "test" + ] +} \ No newline at end of file