diff --git a/package.json b/package.json index 9a187a95..8bfb5767 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": "^4.0.0", "debug": "^4.1.0", "err-code": "^2.0.0", "interface-datastore": "^3.0.3", - "ipfs-repo-migrations": "^5.0.3", + "ipfs-repo-migrations": "^6.0.0", "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 () => {