Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update repo to v10 to upgrade level-js #281

Merged
merged 3 commits into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 12 additions & 2 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -39,7 +43,10 @@ module.exports = (store) => {
key = undefined
}

const encodedValue = await store.get(configKey)
// [email protected] cannot read keys from [email protected] 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
Expand Down Expand Up @@ -106,7 +113,10 @@ module.exports = (store) => {
* @returns {Promise<bool>}
*/
async exists () { // eslint-disable-line require-await
return store.has(configKey)
// [email protected] cannot read keys from [email protected] 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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict'

module.exports = {
repoVersion: 9
repoVersion: 10
}
14 changes: 12 additions & 2 deletions src/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -16,15 +20,21 @@ module.exports = (store) => {
* @returns {Promise<bool>}
*/
async exists () { // eslint-disable-line require-await
return store.has(versionKey)
// [email protected] cannot read keys from [email protected] 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.
*
* @returns {Promise<Integer>}
*/
async get () {
const buf = await store.get(versionKey)
// [email protected] cannot read keys from [email protected] 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)
},
/**
Expand Down
4 changes: 2 additions & 2 deletions test/repo-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down