From efa72b7caba97c85d9e85db87d5ab10fdaa1ad8b Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 27 Jan 2021 16:40:11 +0000 Subject: [PATCH 1/3] chore: upgrade to latest datastore-level BREAKING CHANGE: requires repo migration to v10 --- package.json | 4 ++-- src/config.js | 14 ++++++++++++-- src/constants.js | 2 +- src/version.js | 14 ++++++++++++-- test/repo-test.js | 4 ++-- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 9a187a95..bfa0c1ee 100644 --- a/package.json +++ b/package.json @@ -60,11 +60,11 @@ "cids": "^1.0.0", "datastore-core": "^3.0.0", "datastore-fs": "^3.0.0", - "datastore-level": "^3.0.0", + "datastore-level": "ipfs/js-datastore-level#dependabot/npm_and_yarn/level-6.0.1", "debug": "^4.1.0", "err-code": "^2.0.0", "interface-datastore": "^3.0.3", - "ipfs-repo-migrations": "^5.0.3", + "ipfs-repo-migrations": "ipfs/js-ipfs-repo-migrations#feat/migration-10", "ipfs-utils": "^6.0.0", "ipld-block": "^0.11.0", "it-map": "^1.0.2", diff --git a/src/config.js b/src/config.js index 38d25d79..146972cd 100644 --- a/src/config.js +++ b/src/config.js @@ -8,6 +8,10 @@ const errcode = require('err-code') const errors = require('./errors') const uint8ArrayToString = require('uint8arrays/to-string') const uint8ArrayFromString = require('uint8arrays/from-string') +const { + hasWithFallback, + getWithFallback +} = require('ipfs-repo-migrations/src/utils') const configKey = new Key('config') @@ -39,7 +43,10 @@ module.exports = (store) => { key = undefined } - const encodedValue = await store.get(configKey) + // level-js@5.x cannot read keys from level-js@4.x dbs so fall back to + // using IndexedDB API with string keys - only necessary until we do + // the migratiion to v10 or above + const encodedValue = await getWithFallback(configKey, store.get.bind(store), store.has.bind(store), store) if (options.signal && options.signal.aborted) { return @@ -106,7 +113,10 @@ module.exports = (store) => { * @returns {Promise} */ async exists () { // eslint-disable-line require-await - return store.has(configKey) + // level-js@5.x cannot read keys from level-js@4.x dbs so fall back to + // using IndexedDB API with string keys - only necessary until we do + // the migratiion to v10 or above + return hasWithFallback(configKey, store.has.bind(store), store) } } diff --git a/src/constants.js b/src/constants.js index 4780bcc0..05c4b03a 100644 --- a/src/constants.js +++ b/src/constants.js @@ -1,5 +1,5 @@ 'use strict' module.exports = { - repoVersion: 9 + repoVersion: 10 } diff --git a/src/version.js b/src/version.js index 8064f5fa..c4371279 100644 --- a/src/version.js +++ b/src/version.js @@ -5,6 +5,10 @@ const debug = require('debug') const log = debug('ipfs:repo:version') const uint8ArrayToString = require('uint8arrays/to-string') const uint8ArrayFromString = require('uint8arrays/from-string') +const { + hasWithFallback, + getWithFallback +} = require('ipfs-repo-migrations/src/utils') const versionKey = new Key('version') @@ -16,7 +20,10 @@ module.exports = (store) => { * @returns {Promise} */ async exists () { // eslint-disable-line require-await - return store.has(versionKey) + // level-js@5.x cannot read keys from level-js@4.x dbs so fall back to + // using IndexedDB API with string keys - only necessary until we do + // the migratiion to v10 or above + return hasWithFallback(versionKey, store.has.bind(store), store) }, /** * Get the current version. @@ -24,7 +31,10 @@ module.exports = (store) => { * @returns {Promise} */ async get () { - const buf = await store.get(versionKey) + // level-js@5.x cannot read keys from level-js@4.x dbs so fall back to + // using IndexedDB API with string keys - only necessary until we do + // the migratiion to v10 or above + const buf = await getWithFallback(versionKey, store.get.bind(store), store.has.bind(store), store) return parseInt(uint8ArrayToString(buf), 10) }, /** diff --git a/test/repo-test.js b/test/repo-test.js index f96fc30d..c86dfe21 100644 --- a/test/repo-test.js +++ b/test/repo-test.js @@ -56,12 +56,12 @@ module.exports = (repo) => { describe('version', () => { afterEach(async () => { - await repo.version.set(9) + await repo.version.set(10) }) it('get version', async () => { const version = await repo.version.get() - expect(version).to.equal(9) + expect(version).to.equal(10) }) it('set version', async () => { From 39b01683ad165f4795a668ed95bd76e6f470e9fd Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 29 Jan 2021 12:28:14 +0000 Subject: [PATCH 2/3] chore: remove gh url --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bfa0c1ee..7f80e856 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "cids": "^1.0.0", "datastore-core": "^3.0.0", "datastore-fs": "^3.0.0", - "datastore-level": "ipfs/js-datastore-level#dependabot/npm_and_yarn/level-6.0.1", + "datastore-level": "^4.0.0", "debug": "^4.1.0", "err-code": "^2.0.0", "interface-datastore": "^3.0.3", From e1e6a94fc13c8698b67627f08efc26bd6bfe3b26 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 29 Jan 2021 15:34:39 +0000 Subject: [PATCH 3/3] chore: remove gh url --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7f80e856..8bfb5767 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "debug": "^4.1.0", "err-code": "^2.0.0", "interface-datastore": "^3.0.3", - "ipfs-repo-migrations": "ipfs/js-ipfs-repo-migrations#feat/migration-10", + "ipfs-repo-migrations": "^6.0.0", "ipfs-utils": "^6.0.0", "ipld-block": "^0.11.0", "it-map": "^1.0.2",