Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
chore: update interfaces and add types
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Apr 12, 2021
1 parent a474cf4 commit a5e5191
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 16 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
Expand All @@ -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
Expand Down
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <vasco.santos@moxy.studio>",
"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"
},
Expand Down Expand Up @@ -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",
Expand All @@ -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"
},
Expand Down
6 changes: 3 additions & 3 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
13 changes: 10 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,29 @@

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')
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
* (it just floods the network).
*/
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 = {}) {
Expand Down Expand Up @@ -64,10 +70,11 @@ class FloodSub extends BaseProtocol {
*
* @override
* @param {InMessage} message
* @returns {void}
* @returns {Promise<void>}
*/
_publish (message) {
this._forwardMessage(message)
return Promise.resolve()
}

/**
Expand Down
10 changes: 10 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "aegir/src/config/tsconfig.aegir.json",
"compilerOptions": {
"outDir": "dist"
},
"include": [
"src",
"test"
]
}

0 comments on commit a5e5191

Please sign in to comment.