From 6077fb7a70bb19772c20f241edfd6d20fb2bd47b Mon Sep 17 00:00:00 2001 From: Bryan Stenson Date: Fri, 29 May 2020 03:14:48 -0700 Subject: [PATCH 01/11] chore: update contributing link (#93) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7f29389..f1be9e6 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ Feel free to join in. All welcome. Open an [issue](https://github.com/ipfs/js-ip This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md). -[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/contributing.md) +[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md) ## License From 804c5cf5d7c6723365ca4d1571f5aff69b36125c Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Wed, 5 Aug 2020 12:44:26 +0100 Subject: [PATCH 02/11] fix: replace node buffers with uint8arrays (#105) BREAKING CHANGE: - All uses of Buffers have been replaced with Uint8Arrays - The ipfs-repo this module uses only returns Uint8Arrays --- README.md | 6 ++-- package.json | 19 ++++++------ test/aborting-requests.spec.js | 5 +-- test/block-service-test.js | 56 ++++++++++++++++++---------------- 4 files changed, 44 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index f1be9e6..53925bb 100644 --- a/README.md +++ b/README.md @@ -69,12 +69,14 @@ const BlockService = require('ipfs-block-service') const Block = require('ipld-block') const multihashing = require('multihashing-async') const IPFSRepo = require('ipfs-repo') // storage repo +const uint8ArrayEquals = require('uint8arrays/equals') +const uint8ArrayFromString = require('uint8arrays/from-string') // setup a repo const repo = new IPFSRepo('example') // create a block -const data = new Buffer('hello world') +const data = uint8ArrayFromString('hello world') const multihash = await multihashing(data, 'sha2-256') const cid = new CID(multihash) @@ -87,7 +89,7 @@ const service = new BlockService(repo) await service.put(block) const result = await service.get(cid) -console.log(block.data.toString() === result.data.toString()) +console.log(uint8ArrayEquals(block.data, result.data)) // => true ``` diff --git a/package.json b/package.json index 82735f9..bb2ca5b 100644 --- a/package.json +++ b/package.json @@ -31,24 +31,23 @@ "homepage": "https://github.com/ipfs/js-ipfs-block-service#readme", "devDependencies": { "abort-controller": "^3.0.0", - "aegir": "^21.8.1", - "chai": "^4.2.0", - "chai-as-promised": "^7.1.1", - "cids": "^0.8.0", - "dirty-chai": "^2.0.1", + "aegir": "^22.0.0", + "cids": "^1.0.0", "fs-extra": "^9.0.0", - "ipfs-repo": "^2.1.0", - "ipld-block": "^0.9.1", + "ipfs-repo": "^6.0.0", + "ipld-block": "^0.10.0", + "it-drain": "^1.0.1", "lodash": "^4.17.11", - "multihashing-async": "^0.8.1" + "multihashing-async": "^2.0.1", + "uint8arrays": "^1.0.0" }, "engines": { - "node": ">=6.0.0", + "node": ">=12.0.0", "npm": ">=3.0.0" }, "dependencies": { "err-code": "^2.0.0", - "streaming-iterables": "^4.1.0" + "streaming-iterables": "^5.0.2" }, "contributors": [ "David Dias ", diff --git a/test/aborting-requests.spec.js b/test/aborting-requests.spec.js index 40b3d68..d0bfce8 100644 --- a/test/aborting-requests.spec.js +++ b/test/aborting-requests.spec.js @@ -1,10 +1,7 @@ /* eslint-env mocha */ 'use strict' -const chai = require('chai') -chai.use(require('dirty-chai')) -chai.use(require('chai-as-promised')) -const expect = chai.expect +const { expect } = require('aegir/utils/chai') const { collect } = require('streaming-iterables') const AbortController = require('abort-controller') diff --git a/test/block-service-test.js b/test/block-service-test.js index 29e7156..92f984a 100644 --- a/test/block-service-test.js +++ b/test/block-service-test.js @@ -1,15 +1,15 @@ /* eslint-env mocha */ 'use strict' -const chai = require('chai') -chai.use(require('dirty-chai')) -const expect = chai.expect +const { expect } = require('aegir/utils/chai') const Block = require('ipld-block') const _ = require('lodash') const { collect } = require('streaming-iterables') const CID = require('cids') const multihashing = require('multihashing-async') +const uint8ArrayFromString = require('uint8arrays/from-string') +const drain = require('it-drain') const BlockService = require('../src') @@ -22,10 +22,10 @@ module.exports = (repo) => { bs = new BlockService(repo) const data = [ - Buffer.from('1'), - Buffer.from('2'), - Buffer.from('3'), - Buffer.from('A random data block') + uint8ArrayFromString('1'), + uint8ArrayFromString('2'), + uint8ArrayFromString('3'), + uint8ArrayFromString('A random data block') ] testBlocks = await Promise.all(data.map(async (d) => { @@ -53,8 +53,16 @@ module.exports = (repo) => { } }) - it('store many blocks', () => { - return bs.putMany(testBlocks) + it('store many blocks', async () => { + await drain(bs.putMany(testBlocks)) + + expect( + await Promise.all( + testBlocks.map(b => bs.get(b.cid)) + ) + ).to.deep.equal( + testBlocks + ) }) it('get many blocks through .get', async () => { @@ -69,7 +77,7 @@ module.exports = (repo) => { }) it('delete a block', async () => { - const data = Buffer.from('Will not live that much') + const data = uint8ArrayFromString('Will not live that much') const hash = await multihashing(data, 'sha2-256') const b = new Block(data, new CID(hash)) @@ -81,7 +89,7 @@ module.exports = (repo) => { }) it('does not delete a block it does not have', async () => { - const data = Buffer.from('Will not live that much ' + Date.now()) + const data = uint8ArrayFromString('Will not live that much ' + Date.now()) const cid = new CID(await multihashing(data, 'sha2-256')) await bs.delete(cid) @@ -92,33 +100,29 @@ module.exports = (repo) => { }) it('deletes lots of blocks', async () => { - const data = Buffer.from('Will not live that much') + const data = uint8ArrayFromString('Will not live that much') const hash = await multihashing(data, 'sha2-256') const b = new Block(data, new CID(hash)) await bs.put(b) - await bs.deleteMany([b.cid]) + await drain(bs.deleteMany([b.cid])) const res = await bs._repo.blocks.has(b.cid) - expect(res).to.be.eql(false) + expect(res).to.be.false() }) it('does not delete a blocks it does not have', async () => { - const data = Buffer.from('Will not live that much ' + Date.now()) + const data = uint8ArrayFromString('Will not live that much ' + Date.now()) const cid = new CID(await multihashing(data, 'sha2-256')) - await bs.deleteMany([cid]) - .then( - () => expect.fail('Should have thrown'), - (err) => expect(err).to.have.property('code', 'ERR_BLOCK_NOT_FOUND') - ) + await expect(drain(bs.deleteMany([cid]))).to.eventually.be.rejected().with.property('code', 'ERR_BLOCK_NOT_FOUND') }) it('stores and gets lots of blocks', async function () { - this.timeout(8 * 1000) + this.timeout(20 * 1000) const data = _.range(1000).map((i) => { - return Buffer.from(`hello-${i}-${Math.random()}`) + return uint8ArrayFromString(`hello-${i}-${Math.random()}`) }) const blocks = await Promise.all(data.map(async (d) => { @@ -126,7 +130,7 @@ module.exports = (repo) => { return new Block(d, new CID(hash)) })) - await bs.putMany(blocks) + await drain(bs.putMany(blocks)) const res = await Promise.all(blocks.map(b => bs.get(b.cid))) expect(res).to.be.eql(blocks) @@ -155,13 +159,13 @@ module.exports = (repo) => { // returns a block with a value equal to its key const bitswap = { get (cid) { - return new Block(Buffer.from('secret'), cid) + return new Block(uint8ArrayFromString('secret'), cid) } } bs.setExchange(bitswap) - const data = Buffer.from('secret') + const data = uint8ArrayFromString('secret') const hash = await multihashing(data, 'sha2-256') const block = await bs.get(new CID(hash)) @@ -178,7 +182,7 @@ module.exports = (repo) => { } bs.setExchange(bitswap) - const data = Buffer.from('secret sauce') + const data = uint8ArrayFromString('secret sauce') const hash = await multihashing(data, 'sha2-256') await bs.put(new Block(data, new CID(hash))) From e9de4b37370cbe744a1bc2c009a3a727d42c662a Mon Sep 17 00:00:00 2001 From: Volker Mische Date: Wed, 5 Aug 2020 17:42:07 +0200 Subject: [PATCH 03/11] chore: update contributors --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index bb2ca5b..1f46d6e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ipfs-block-service", - "version": "0.17.1", + "version": "0.18.0", "description": "JavaScript Implementation of BlockService", "leadMaintainer": "Volker Mische ", "main": "src/index.js", @@ -52,11 +52,12 @@ "contributors": [ "David Dias ", "dignifiedquire ", - "Stephen Whitmore ", "Volker Mische ", + "Stephen Whitmore ", "Alex Potsides ", "Richard Schneider ", "Pedro Teixeira ", + "Bryan Stenson ", "Dirk McCormick ", "Hector Sanjuan ", "Pedro Santos ", From e05b8f10d6c8a91c1564f8078a27561686ecee0c Mon Sep 17 00:00:00 2001 From: Volker Mische Date: Wed, 5 Aug 2020 17:42:07 +0200 Subject: [PATCH 04/11] chore: release version v0.18.0 --- CHANGELOG.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a6f01b8..e433276 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,19 @@ + +# [0.18.0](https://github.com/ipfs/js-ipfs-block-service/compare/v0.17.1...v0.18.0) (2020-08-05) + + +### Bug Fixes + +* replace node buffers with uint8arrays ([#105](https://github.com/ipfs/js-ipfs-block-service/issues/105)) ([804c5cf](https://github.com/ipfs/js-ipfs-block-service/commit/804c5cf)) + + +### BREAKING CHANGES + +* - All uses of Buffers have been replaced with Uint8Arrays +- The ipfs-repo this module uses only returns Uint8Arrays + + + ## [0.17.1](https://github.com/ipfs/js-ipfs-block-service/compare/v0.17.0...v0.17.1) (2020-05-05) From d58eacc035e68a7913be3f600afc2f03cd67177d Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Fri, 5 Feb 2021 11:27:29 +0000 Subject: [PATCH 05/11] chore(deps-dev): bump uint8arrays from 1.1.0 to 2.1.2 Bumps [uint8arrays](https://github.com/achingbrain/uint8arrays) from 1.1.0 to 2.1.2. - [Release notes](https://github.com/achingbrain/uint8arrays/releases) - [Changelog](https://github.com/achingbrain/uint8arrays/blob/master/CHANGELOG.md) - [Commits](https://github.com/achingbrain/uint8arrays/compare/v1.1.0...v2.1.2) Signed-off-by: dependabot-preview[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1f46d6e..d6cc2b9 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "it-drain": "^1.0.1", "lodash": "^4.17.11", "multihashing-async": "^2.0.1", - "uint8arrays": "^1.0.0" + "uint8arrays": "^2.1.2" }, "engines": { "node": ">=12.0.0", From 52f2439cf20e6716314aadb335bb85fe83ba9952 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Fri, 5 Mar 2021 11:27:09 +0000 Subject: [PATCH 06/11] feat: add types (#136) Adds types, fixes all tsc errors, updates all deps. --- .travis.yml | 19 +++++++++++---- package.json | 28 ++++++++++++++-------- src/index.js | 44 ++++++++++++++++------------------ test/aborting-requests.spec.js | 25 +++++++++++++++---- test/block-service-test.js | 24 +++++++++++++++---- test/browser.js | 3 +++ tsconfig.json | 10 ++++++++ 7 files changed, 108 insertions(+), 45 deletions(-) create mode 100644 tsconfig.json diff --git a/.travis.yml b/.travis.yml index d0cf281..6aeb9f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,29 @@ language: node_js +dist: bionic cache: npm stages: - check - test - cov +branches: + only: + - master + - /^release\/.*$/ + node_js: - - '10' + - 'lts/*' + - 'node' os: - linux - osx - windows +before_install: + # modules with pre-built binaries may not have deployed versions for bleeding-edge node so this lets us fall back to building from source + - npm install -g @mapbox/node-pre-gyp + script: npx nyc -s npm run test:node -- --bail after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov @@ -20,7 +31,6 @@ jobs: include: - stage: check script: - - npx aegir commitlint --travis - npx aegir dep-check - npm run lint @@ -28,13 +38,14 @@ jobs: name: chrome addons: chrome: stable - script: npx aegir test -t browser -t webworker + script: + - npx aegir test -t browser -t webworker - stage: test name: firefox addons: firefox: latest - script: npx aegir test -t browser -t webworker -- --browsers FirefoxHeadless + script: npx aegir test -t browser -t webworker -- --browser firefox notifications: email: false diff --git a/package.json b/package.json index d6cc2b9..4e5d3ff 100644 --- a/package.json +++ b/package.json @@ -4,17 +4,18 @@ "description": "JavaScript Implementation of BlockService", "leadMaintainer": "Volker Mische ", "main": "src/index.js", + "types": "dist/src/index.d.ts", "scripts": { + "prepare": "aegir build --no-bundle", "lint": "aegir lint", - "build": "aegir build", + "prepublishOnly": "aegir build", "test": "aegir test", "test:node": "aegir test --target node", "test:browser": "aegir test --target browser", "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", + "coverage": "aegir test -t node --cov && nyc report --reporter=html", "docs": "aegir docs" }, "repository": { @@ -30,24 +31,31 @@ }, "homepage": "https://github.com/ipfs/js-ipfs-block-service#readme", "devDependencies": { + "@types/fs-extra": "^9.0.8", + "@types/lodash.range": "^3.2.6", "abort-controller": "^3.0.0", - "aegir": "^22.0.0", + "aegir": "^31.0.4", + "assert": "^2.0.0", "cids": "^1.0.0", + "events": "^3.3.0", "fs-extra": "^9.0.0", - "ipfs-repo": "^6.0.0", - "ipld-block": "^0.10.0", + "ipfs-repo": "^9.0.0", + "ipld-block": "^0.11.1", + "it-all": "^1.0.5", "it-drain": "^1.0.1", - "lodash": "^4.17.11", + "lodash.range": "^3.2.0", "multihashing-async": "^2.0.1", - "uint8arrays": "^2.1.2" + "native-abort-controller": "^1.0.3", + "uint8arrays": "^2.1.2", + "util": "^0.12.3" }, "engines": { "node": ">=12.0.0", "npm": ">=3.0.0" }, "dependencies": { - "err-code": "^2.0.0", - "streaming-iterables": "^5.0.2" + "err-code": "^3.0.1", + "it-map": "^1.0.5" }, "contributors": [ "David Dias ", diff --git a/src/index.js b/src/index.js index 8b5369d..2ddadc7 100644 --- a/src/index.js +++ b/src/index.js @@ -1,8 +1,14 @@ 'use strict' -const { map } = require('streaming-iterables') +const map = require('it-map') const errcode = require('err-code') +/** + * @typedef {import('ipfs-repo')} IPFSRepo + * @typedef {import('ipld-block')} Block + * @typedef {import('cids')} CID + */ + /** * BlockService is a hybrid block datastore. It stores data in a local * datastore and may retrieve data from a remote Exchange. @@ -26,8 +32,7 @@ class BlockService { * If the node is online all requests for blocks first * check locally and afterwards ask the network for the blocks. * - * @param {Bitswap} bitswap - * @returns {void} + * @param {any} bitswap */ setExchange (bitswap) { this._bitswap = bitswap @@ -35,8 +40,6 @@ class BlockService { /** * Go offline, i.e. drop the reference to bitswap. - * - * @returns {void} */ unsetExchange () { this._bitswap = null @@ -44,8 +47,6 @@ class BlockService { /** * Is the blockservice online, i.e. is bitswap present. - * - * @returns {bool} */ hasExchange () { return this._bitswap != null @@ -55,9 +56,9 @@ class BlockService { * Put a block to the underlying datastore. * * @param {Block} block - * @param {Object} [options] - Options is an object with the following properties + * @param {object} [options] - Options is an object with the following properties * @param {AbortSignal} [options.signal] - A signal that can be used to abort any long-lived operations that are started as a result of this operation - * @returns {Promise} + * @returns {Promise} */ put (block, options) { if (this.hasExchange()) { @@ -70,10 +71,10 @@ class BlockService { /** * Put a multiple blocks to the underlying datastore. * - * @param {AsyncIterator} blocks - * @param {Object} [options] - Options is an object with the following properties + * @param {AsyncIterable | Iterable} blocks + * @param {object} [options] - Options is an object with the following properties * @param {AbortSignal} [options.signal] - A signal that can be used to abort any long-lived operations that are started as a result of this operation - * @returns {Promise} + * @returns {AsyncIterable} */ putMany (blocks, options) { if (this.hasExchange()) { @@ -87,7 +88,7 @@ class BlockService { * Get a block by cid. * * @param {CID} cid - * @param {Object} [options] - Options is an object with the following properties + * @param {object} [options] - Options is an object with the following properties * @param {AbortSignal} [options.signal] - A signal that can be used to abort any long-lived operations that are started as a result of this operation * @returns {Promise} */ @@ -102,10 +103,10 @@ class BlockService { /** * Get multiple blocks back from an array of cids. * - * @param {AsyncIterator} cids - * @param {Object} [options] - Options is an object with the following properties + * @param {AsyncIterable | Iterable} cids + * @param {object} [options] - Options is an object with the following properties * @param {AbortSignal} [options.signal] - A signal that can be used to abort any long-lived operations that are started as a result of this operation - * @returns {AsyncIterator} + * @returns {AsyncIterable} */ getMany (cids, options) { if (!Array.isArray(cids)) { @@ -115,8 +116,7 @@ class BlockService { if (this.hasExchange()) { return this._bitswap.getMany(cids, options) } else { - const getRepoBlocks = map((cid) => this._repo.blocks.get(cid, options)) - return getRepoBlocks(cids) + return map(cids, (cid) => this._repo.blocks.get(cid, options)) } } @@ -124,9 +124,8 @@ class BlockService { * Delete a block from the blockstore. * * @param {CID} cid - * @param {Object} [options] - Options is an object with the following properties + * @param {object} [options] - Options is an object with the following properties * @param {AbortSignal} [options.signal] - A signal that can be used to abort any long-lived operations that are started as a result of this operation - * @returns {Promise} */ async delete (cid, options) { if (!await this._repo.blocks.has(cid)) { @@ -139,10 +138,9 @@ class BlockService { /** * Delete multiple blocks from the blockstore. * - * @param {AsyncIterator} cids - * @param {Object} [options] - Options is an object with the following properties + * @param {AsyncIterable | Iterable} cids + * @param {object} [options] - Options is an object with the following properties * @param {AbortSignal} [options.signal] - A signal that can be used to abort any long-lived operations that are started as a result of this operation - * @returns {Promise} */ deleteMany (cids, options) { const repo = this._repo diff --git a/test/aborting-requests.spec.js b/test/aborting-requests.spec.js index d0bfce8..035531b 100644 --- a/test/aborting-requests.spec.js +++ b/test/aborting-requests.spec.js @@ -3,17 +3,26 @@ const { expect } = require('aegir/utils/chai') -const { collect } = require('streaming-iterables') -const AbortController = require('abort-controller') +const all = require('it-all') +const { AbortController } = require('native-abort-controller') const BlockService = require('../src') +/** + * @typedef {import('ipfs-repo')} IPFSRepo + */ + describe('aborting requests', () => { + /** @type {Error} */ let abortedErr + /** @type {BlockService} */ let r beforeEach(() => { abortedErr = new Error('Aborted!') + /** + * @param {...any} args + */ const abortOnSignal = (...args) => { const { signal } = args[args.length - 1] @@ -24,14 +33,17 @@ describe('aborting requests', () => { }) } + /** @type {IPFSRepo} */ const repo = { blocks: { put: abortOnSignal, + // @ts-ignore should return async iterable putMany: abortOnSignal, get: abortOnSignal, delete: abortOnSignal, + // @ts-ignore should return async iterable deleteMany: abortOnSignal, - has: () => true + has: () => Promise.resolve(true) } } r = new BlockService(repo) @@ -41,6 +53,7 @@ describe('aborting requests', () => { const controller = new AbortController() setTimeout(() => controller.abort(), 1) + // @ts-expect-error does not take string await expect(r.put('block', { signal: controller.signal })).to.eventually.rejectedWith(abortedErr) @@ -50,6 +63,7 @@ describe('aborting requests', () => { const controller = new AbortController() setTimeout(() => controller.abort(), 1) + // @ts-expect-error does not take string array await expect(r.putMany(['block'], { signal: controller.signal })).to.eventually.rejectedWith(abortedErr) @@ -59,6 +73,7 @@ describe('aborting requests', () => { const controller = new AbortController() setTimeout(() => controller.abort(), 1) + // @ts-expect-error does not take string await expect(r.get('cid', { signal: controller.signal })).to.eventually.rejectedWith(abortedErr) @@ -68,7 +83,8 @@ describe('aborting requests', () => { const controller = new AbortController() setTimeout(() => controller.abort(), 1) - await expect(collect(r.getMany(['cid'], { + // @ts-expect-error does not take string array + await expect(all(r.getMany(['cid'], { signal: controller.signal }))).to.eventually.rejectedWith(abortedErr) }) @@ -77,6 +93,7 @@ describe('aborting requests', () => { const controller = new AbortController() setTimeout(() => controller.abort(), 1) + // @ts-expect-error does not take string await expect(r.delete('cid', { signal: controller.signal })).to.eventually.rejectedWith(abortedErr) diff --git a/test/block-service-test.js b/test/block-service-test.js index 92f984a..198b559 100644 --- a/test/block-service-test.js +++ b/test/block-service-test.js @@ -4,18 +4,27 @@ const { expect } = require('aegir/utils/chai') const Block = require('ipld-block') -const _ = require('lodash') -const { collect } = require('streaming-iterables') +const range = require('lodash.range') +const all = require('it-all') const CID = require('cids') const multihashing = require('multihashing-async') const uint8ArrayFromString = require('uint8arrays/from-string') const drain = require('it-drain') +/** + * @typedef {import('ipfs-repo')} IPFSRepo + */ + const BlockService = require('../src') +/** + * @param {IPFSRepo} repo + */ module.exports = (repo) => { describe('block-service', () => { + /** @type {BlockService} */ let bs + /** @type {Block[]} */ let testBlocks before(async () => { @@ -72,7 +81,7 @@ module.exports = (repo) => { it('get many blocks through .getMany', async () => { const cids = testBlocks.map(b => b.cid) - const blocks = await collect(bs.getMany(cids)) + const blocks = await all(bs.getMany(cids)) expect(blocks).to.eql(testBlocks) }) @@ -121,7 +130,7 @@ module.exports = (repo) => { it('stores and gets lots of blocks', async function () { this.timeout(20 * 1000) - const data = _.range(1000).map((i) => { + const data = range(1000).map((i) => { return uint8ArrayFromString(`hello-${i}-${Math.random()}`) }) @@ -158,6 +167,9 @@ module.exports = (repo) => { it('retrieves a block through bitswap', async () => { // returns a block with a value equal to its key const bitswap = { + /** + * @param {CID} cid + */ get (cid) { return new Block(uint8ArrayFromString('secret'), cid) } @@ -174,8 +186,12 @@ module.exports = (repo) => { }) it('puts the block through bitswap', async () => { + /** @type {Block[]} */ const puts = [] const bitswap = { + /** + * @param {Block} block + */ put (block) { puts.push(block) } diff --git a/test/browser.js b/test/browser.js index fa97598..53222af 100644 --- a/test/browser.js +++ b/test/browser.js @@ -7,8 +7,11 @@ const IPFSRepo = require('ipfs-repo') const tests = require('./block-service-test') const idb = self.indexedDB || + // @ts-ignore self.mozIndexedDB || + // @ts-ignore self.webkitIndexedDB || + // @ts-ignore self.msIndexedDB idb.deleteDatabase('ipfs') diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..7371337 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "./node_modules/aegir/src/config/tsconfig.aegir.json", + "compilerOptions": { + "outDir": "dist" + }, + "include": [ + "test", + "src" + ] +} From b731f387b05696181559502a7f57db4303663795 Mon Sep 17 00:00:00 2001 From: Volker Mische Date: Fri, 5 Mar 2021 12:34:49 +0100 Subject: [PATCH 07/11] chore: update contributors --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4e5d3ff..7bd4b6e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ipfs-block-service", - "version": "0.18.0", + "version": "0.19.0", "description": "JavaScript Implementation of BlockService", "leadMaintainer": "Volker Mische ", "main": "src/index.js", From 2980ffc8552c46e007b4e19b08dcb0e751addc42 Mon Sep 17 00:00:00 2001 From: Volker Mische Date: Fri, 5 Mar 2021 12:34:49 +0100 Subject: [PATCH 08/11] chore: release version v0.19.0 --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e433276..8901c4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# [0.19.0](https://github.com/ipfs/js-ipfs-block-service/compare/v0.18.0...v0.19.0) (2021-03-05) + + +### Features + +* add types ([#136](https://github.com/ipfs/js-ipfs-block-service/issues/136)) ([52f2439](https://github.com/ipfs/js-ipfs-block-service/commit/52f2439cf20e6716314aadb335bb85fe83ba9952)) + + + # [0.18.0](https://github.com/ipfs/js-ipfs-block-service/compare/v0.17.1...v0.18.0) (2020-08-05) From f7da02667c281557ae0b8f7aa12ac81108f0ee58 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 11 Aug 2021 17:49:50 +0100 Subject: [PATCH 09/11] chore: add deprecation notice --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 53925bb..ad80467 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +⛔️ DEPRECATED: This module has been merged into [ipfs](https://github.com/ipfs/js-ipfs) +====== + # IPFS Block Service [![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) From f3d0ab83fc196ae4680ff78b8a6821fff05e2198 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 11 Aug 2021 17:50:55 +0100 Subject: [PATCH 10/11] chore: update contributors --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 7bd4b6e..5cde6f1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ipfs-block-service", - "version": "0.19.0", + "version": "0.19.1", "description": "JavaScript Implementation of BlockService", "leadMaintainer": "Volker Mische ", "main": "src/index.js", @@ -66,12 +66,12 @@ "Richard Schneider ", "Pedro Teixeira ", "Bryan Stenson ", - "Dirk McCormick ", + "wanderer ", "Hector Sanjuan ", + "ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ ", "Pedro Santos ", "Richard Littauer ", "Vijayee Kulkaa ", - "wanderer ", - "ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ " + "Dirk McCormick " ] } From 8798c938d365bf152384c10ecd75b3c6a3da0a1a Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 11 Aug 2021 17:50:56 +0100 Subject: [PATCH 11/11] chore: release version v0.19.1 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8901c4b..2108be2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [0.19.1](https://github.com/ipfs/js-ipfs-block-service/compare/v0.19.0...v0.19.1) (2021-08-11) + + + # [0.19.0](https://github.com/ipfs/js-ipfs-block-service/compare/v0.18.0...v0.19.0) (2021-03-05)