diff --git a/.gitignore b/.gitignore
index f21fe31..1531bdf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,66 +1,6 @@
-dist/
-docs/
-
-# Logs
-logs
-*.log
-npm-debug.log*
-yarn-debug.log*
-yarn-error.log*
-
-# Runtime data
-pids
-*.pid
-*.seed
-*.pid.lock
-
-# Directory for instrumented libs generated by jscoverage/JSCover
-lib-cov
-
-# Coverage directory used by tools like istanbul
-coverage
-
-# nyc test coverage
-.nyc_output
-
-# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
-.grunt
-
-# Bower dependency directory (https://bower.io/)
-bower_components
-
-# node-waf configuration
-.lock-wscript
-
-# Compiled binary addons (http://nodejs.org/api/addons.html)
-build/Release
-
-# Dependency directories
-node_modules/
-jspm_packages/
-
-# Typescript v1 declaration files
-typings/
-
-# Optional npm cache directory
-.npm
-
-# Optional eslint cache
-.eslintcache
-
-# Optional REPL history
-.node_repl_history
-
-# Output of 'npm pack'
-*.tgz
-
-# Yarn Integrity file
-.yarn-integrity
-
-# dotenv environment variables file
-.env
-
-# while testing npm5
+node_modules
+dist
+.docs
+.coverage
package-lock.json
yarn.lock
-types
diff --git a/README.md b/README.md
index e0fab90..55468fa 100644
--- a/README.md
+++ b/README.md
@@ -3,13 +3,14 @@
[](https://ipfs.tech)
[](https://discuss.ipfs.tech)
[](https://codecov.io/gh/ipfs/js-datastore-pubsub)
-[](https://github.com/ipfs/js-datastore-pubsub/actions/workflows/js-test-and-release.yml)
+[](https://github.com/ipfs/js-datastore-pubsub/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)
> Responsible for providing an interface-datastore compliant api to pubsub
## Table of contents
- [Install](#install)
+ - [Browser `
+```
+
## Usage
```js
@@ -109,6 +119,10 @@ This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/c
[](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)
+## API Docs
+
+-
+
## License
Licensed under either of
diff --git a/package.json b/package.json
index 39b307c..c26d68a 100644
--- a/package.json
+++ b/package.json
@@ -154,39 +154,27 @@
"test:firefox": "aegir test -t browser -- --browser firefox",
"test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
"test:electron-main": "aegir test -t electron-main",
- "dep-check": "aegir dep-check -i rimraf"
+ "dep-check": "aegir dep-check",
+ "docs": "aegir docs"
},
"dependencies": {
- "@libp2p/interface-dht": "^1.0.1",
+ "@libp2p/interface-dht": "^2.0.0",
"@libp2p/interface-pubsub": "^3.0.0",
- "@libp2p/interfaces": "^3.0.3",
+ "@libp2p/interfaces": "^3.2.0",
"@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": "^4.0.2"
},
"devDependencies": {
- "@libp2p/floodsub": "^5.0.0",
- "@libp2p/interface-compliance-tests": "^3.0.2",
- "@libp2p/interface-mocks": "^7.0.1",
- "@libp2p/interface-peer-id": "^1.0.5",
+ "@libp2p/floodsub": "^6.0.0",
+ "@libp2p/interface-mocks": "^9.0.0",
+ "@libp2p/interface-peer-id": "^2.0.0",
"@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.12.1",
- "it-pair": "^2.0.2",
- "libp2p": "next",
- "npm": "^8.10.0",
+ "@libp2p/peer-id-factory": "^2.0.0",
+ "@libp2p/record": "^3.0.0",
+ "aegir": "^37.10.0",
"p-wait-for": "^5.0.0",
- "peer-id": "^0.16.0",
- "rimraf": "^3.0.2",
- "sinon": "^14.0.0",
- "util": "^0.12.4"
+ "sinon": "^15.0.1"
}
}
diff --git a/src/index.js b/src/index.js
index 5e41194..4fdd8d0 100644
--- a/src/index.js
+++ b/src/index.js
@@ -2,7 +2,7 @@ import { Key } from 'interface-datastore'
import { BaseDatastore } from 'datastore-core'
import { encodeBase32, keyToTopic, topicToKey } from './utils.js'
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
-import errcode from 'err-code'
+import { CodeError } from '@libp2p/interfaces/errors'
import { logger } from '@libp2p/logger'
const log = logger('datastore-pubsub:publisher')
@@ -32,19 +32,19 @@ export class PubSubDatastore extends BaseDatastore {
super()
if (!validator) {
- throw errcode(new TypeError('missing validator'), 'ERR_INVALID_PARAMETERS')
+ throw new CodeError('missing validator', 'ERR_INVALID_PARAMETERS')
}
if (typeof validator !== 'function') {
- throw errcode(new TypeError('missing validate function'), 'ERR_INVALID_PARAMETERS')
+ throw new CodeError('missing validate function', 'ERR_INVALID_PARAMETERS')
}
if (typeof selector !== 'function') {
- throw errcode(new TypeError('missing select function'), 'ERR_INVALID_PARAMETERS')
+ throw new CodeError('missing select function', 'ERR_INVALID_PARAMETERS')
}
if (subscriptionKeyFn && typeof subscriptionKeyFn !== 'function') {
- throw errcode(new TypeError('invalid subscriptionKeyFn received'), 'ERR_INVALID_PARAMETERS')
+ throw new CodeError('invalid subscriptionKeyFn received', 'ERR_INVALID_PARAMETERS')
}
this._pubsub = pubsub
@@ -72,14 +72,14 @@ export class PubSubDatastore extends BaseDatastore {
const errMsg = 'datastore key does not have a valid format'
log.error(errMsg)
- throw errcode(new Error(errMsg), 'ERR_INVALID_DATASTORE_KEY')
+ throw new CodeError(errMsg, 'ERR_INVALID_DATASTORE_KEY')
}
if (!(val instanceof Uint8Array)) {
const errMsg = 'received value is not a Uint8Array'
log.error(errMsg)
- throw errcode(new Error(errMsg), 'ERR_INVALID_VALUE_RECEIVED')
+ throw new CodeError(errMsg, 'ERR_INVALID_VALUE_RECEIVED')
}
const stringifiedTopic = keyToTopic(key)
@@ -102,7 +102,7 @@ export class PubSubDatastore extends BaseDatastore {
const errMsg = 'datastore key does not have a valid format'
log.error(errMsg)
- throw errcode(new Error(errMsg), 'ERR_INVALID_DATASTORE_KEY')
+ throw new CodeError(errMsg, 'ERR_INVALID_DATASTORE_KEY')
}
const stringifiedTopic = keyToTopic(key)
@@ -120,7 +120,7 @@ export class PubSubDatastore extends BaseDatastore {
const errMsg = `cannot subscribe topic ${stringifiedTopic}`
log.error(errMsg)
- throw errcode(new Error(errMsg), 'ERR_SUBSCRIBING_TOPIC')
+ throw new CodeError(errMsg, 'ERR_SUBSCRIBING_TOPIC')
}
log(`subscribed values for key ${stringifiedTopic}`)
@@ -158,19 +158,19 @@ export class PubSubDatastore extends BaseDatastore {
const errMsg = `unexpected error getting the ipns record for ${routingKey.toString()}`
log.error(errMsg)
- throw errcode(new Error(errMsg), 'ERR_UNEXPECTED_ERROR_GETTING_RECORD')
+ throw new CodeError(errMsg, 'ERR_UNEXPECTED_ERROR_GETTING_RECORD')
}
const errMsg = `local record requested was not found for ${routingKey.toString()}`
log.error(errMsg)
- throw errcode(new Error(errMsg), 'ERR_NOT_FOUND')
+ throw new CodeError(errMsg, 'ERR_NOT_FOUND')
}
if (!(dsVal instanceof Uint8Array)) {
const errMsg = 'found record that we couldn\'t convert to a value'
log.error(errMsg)
- throw errcode(new Error(errMsg), 'ERR_INVALID_RECORD_RECEIVED')
+ throw new CodeError(errMsg, 'ERR_INVALID_RECORD_RECEIVED')
}
return dsVal
@@ -286,7 +286,7 @@ export class PubSubDatastore extends BaseDatastore {
const errMsg = 'record received through pubsub is not valid'
log.error(errMsg)
- throw errcode(new Error(errMsg), 'ERR_NOT_VALID_RECORD')
+ throw new CodeError(errMsg, 'ERR_NOT_VALID_RECORD')
}
// Get Local record
diff --git a/src/utils.js b/src/utils.js
index 39b4152..b7c452d 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -1,4 +1,4 @@
-import errcode from 'err-code'
+import { CodeError } from '@libp2p/interfaces/errors'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
@@ -39,7 +39,7 @@ export function keyToTopic (key) {
*/
export function topicToKey (topic) {
if (topic.substring(0, namespace.length) !== namespace) {
- throw errcode(new Error('topic received is not from a record'), 'ERR_TOPIC_IS_NOT_FROM_RECORD_NAMESPACE')
+ throw new CodeError('topic received is not from a record', 'ERR_TOPIC_IS_NOT_FROM_RECORD_NAMESPACE')
}
const key = topic.substring(namespace.length)
diff --git a/test/index.spec.js b/test/index.spec.js
index 746a6e6..7bdb2a5 100644
--- a/test/index.spec.js
+++ b/test/index.spec.js
@@ -2,8 +2,8 @@
import { expect } from 'aegir/chai'
import sinon from 'sinon'
-import errcode from 'err-code'
-import isNode from 'detect-node'
+import { CodeError } from '@libp2p/interfaces/errors'
+import { isNode } from 'aegir/env'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { PubSubDatastore } from '../src/index.js'
@@ -505,7 +505,7 @@ describe('datastore-pubsub', function () {
it('should handle a unexpected error properly when getting from the datastore', async () => {
const dsPubsubA = new PubSubDatastore(pubsubA, datastoreA, peerIdA, smoothValidator, smoothSelector)
- const stub = sinon.stub(dsPubsubA._datastore, 'get').throws(errcode(new Error('Wut'), 'RANDOM_ERR'))
+ const stub = sinon.stub(dsPubsubA._datastore, 'get').throws(new CodeError('Wut', 'RANDOM_ERR'))
// causes pubsub b to become subscribed to the topic
await expect(dsPubsubA.get(key)).to.eventually.be.rejected().with.property('code', 'ERR_UNEXPECTED_ERROR_GETTING_RECORD')