Skip to content

Commit 758270b

Browse files
committed
chore: fall back to indexdb with strings if necessary
1 parent f2628d6 commit 758270b

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

src/config.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ const errcode = require('err-code')
88
const errors = require('./errors')
99
const uint8ArrayToString = require('uint8arrays/to-string')
1010
const uint8ArrayFromString = require('uint8arrays/from-string')
11+
const {
12+
hasWithFallback,
13+
getWithFallback
14+
} = require('ipfs-repo-migrations/src/utils')
1115

1216
const configKey = new Key('config')
1317

@@ -39,7 +43,10 @@ module.exports = (store) => {
3943
key = undefined
4044
}
4145

42-
const encodedValue = await store.get(configKey)
46+
// level-js@5.x cannot read keys from level-js@4.x dbs so fall back to
47+
// using IndexedDB API with string keys - only necessary until we do
48+
// the migratiion to v10 or above
49+
const encodedValue = await getWithFallback(configKey, store.get.bind(store), store.has.bind(store), store)
4350

4451
if (options.signal && options.signal.aborted) {
4552
return
@@ -106,7 +113,10 @@ module.exports = (store) => {
106113
* @returns {Promise<bool>}
107114
*/
108115
async exists () { // eslint-disable-line require-await
109-
return store.has(configKey)
116+
// level-js@5.x cannot read keys from level-js@4.x dbs so fall back to
117+
// using IndexedDB API with string keys - only necessary until we do
118+
// the migratiion to v10 or above
119+
return hasWithFallback(configKey, store.has.bind(store), store)
110120
}
111121
}
112122

src/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict'
22

33
module.exports = {
4-
repoVersion: 9
4+
repoVersion: 10
55
}

src/version.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ const debug = require('debug')
55
const log = debug('ipfs:repo:version')
66
const uint8ArrayToString = require('uint8arrays/to-string')
77
const uint8ArrayFromString = require('uint8arrays/from-string')
8+
const {
9+
hasWithFallback,
10+
getWithFallback
11+
} = require('ipfs-repo-migrations/src/utils')
812

913
const versionKey = new Key('version')
1014

@@ -16,15 +20,21 @@ module.exports = (store) => {
1620
* @returns {Promise<bool>}
1721
*/
1822
async exists () { // eslint-disable-line require-await
19-
return store.has(versionKey)
23+
// level-js@5.x cannot read keys from level-js@4.x dbs so fall back to
24+
// using IndexedDB API with string keys - only necessary until we do
25+
// the migratiion to v10 or above
26+
return hasWithFallback(versionKey, store.has.bind(store), store)
2027
},
2128
/**
2229
* Get the current version.
2330
*
2431
* @returns {Promise<Integer>}
2532
*/
2633
async get () {
27-
const buf = await store.get(versionKey)
34+
// level-js@5.x cannot read keys from level-js@4.x dbs so fall back to
35+
// using IndexedDB API with string keys - only necessary until we do
36+
// the migratiion to v10 or above
37+
const buf = await getWithFallback(versionKey, store.get.bind(store), store.has.bind(store), store)
2838
return parseInt(uint8ArrayToString(buf), 10)
2939
},
3040
/**

0 commit comments

Comments
 (0)