From bd8a930acb6430f7313605d3bc37ba490d60ded9 Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Tue, 29 May 2018 17:19:29 +0200 Subject: [PATCH] fix: upgrade datastores for node 10 (#168) * fix: upgrade datastores for node 10 move the responsibility of levelup browser support to datastore-level License: MIT Signed-off-by: Jacob Heun * chore: add node 10 to jenkins License: MIT Signed-off-by: Jacob Heun chore: use 10.0 instead of 10.1 License: MIT Signed-off-by: Jacob Heun * chore: update jenkins overrides License: MIT Signed-off-by: Jacob Heun * fix: keep initialized errors separate from unknowns License: MIT Signed-off-by: Jacob Heun * refactor: move error code to an exported constant * chore: update deps License: MIT Signed-off-by: Jacob Heun * chore: update deps --- ci/Jenkinsfile | 2 +- package.json | 9 +++------ src/default-options-browser.js | 10 ++-------- src/errors/index.js | 3 +++ src/index.js | 11 +++++++---- test/options-test.js | 6 ------ 6 files changed, 16 insertions(+), 25 deletions(-) create mode 100644 src/errors/index.js diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index c1e3f2cd..2ad674e5 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -1 +1 @@ -javascript() +javascript(['nodejs_versions': ['8.11.1','9.2.0','10.0.0']]) diff --git a/package.json b/package.json index 5c43faca..aedb942c 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,6 @@ "browser": { "rimraf": false, "datastore-fs": "datastore-level", - "leveldown": "level-js", "./src/lock.js": "./src/lock-memory.js", "./src/default-options.js": "./src/default-options-browser.js" }, @@ -60,14 +59,12 @@ "big.js": "^5.0.3", "cids": "~0.5.3", "datastore-core": "~0.4.0", - "datastore-fs": "~0.4.2", - "datastore-level": "~0.7.0", + "datastore-fs": "~0.5.0", + "datastore-level": "~0.8.0", "debug": "^3.1.0", "interface-datastore": "~0.4.2", "ipfs-block": "~0.7.1", - "level-js": "timkuijsten/level.js#idbunwrapper", - "leveldown": "^1.7.2", - "lock-me": "^1.0.3", + "lock-me": "^1.0.4", "lodash.get": "^4.4.2", "lodash.has": "^4.5.2", "lodash.set": "^4.3.2", diff --git a/src/default-options-browser.js b/src/default-options-browser.js index c9c85b1f..9a848d4b 100644 --- a/src/default-options-browser.js +++ b/src/default-options-browser.js @@ -11,19 +11,13 @@ module.exports = { }, storageBackendOptions: { root: { - db: require('level-js'), extension: '' }, blocks: { - sharding: false, - db: require('level-js') + sharding: false }, keys: { - sharding: false, - db: require('level-js') - }, - datastore: { - db: require('level-js') + sharding: false } } } diff --git a/src/errors/index.js b/src/errors/index.js new file mode 100644 index 00000000..3e0f3647 --- /dev/null +++ b/src/errors/index.js @@ -0,0 +1,3 @@ +'use strict' + +exports.ERR_REPO_NOT_INITIALIZED = 'ERR_REPO_NOT_INITIALIZED' diff --git a/src/index.js b/src/index.js index a7096078..c7fcba72 100644 --- a/src/index.js +++ b/src/index.js @@ -16,6 +16,7 @@ const config = require('./config') const apiAddr = require('./api-addr') const blockstore = require('./blockstore') const defaultOptions = require('./default-options') +const ERRORS = require('./errors') const log = debug('repo') @@ -212,14 +213,14 @@ class IpfsRepo { }, (err, res) => { log('init', err, res) - if (err) { + if (err && !res.config) { return callback(Object.assign(new Error('repo is not initialized yet'), { - code: 'ERR_REPO_NOT_INITIALIZED', + code: ERRORS.ERR_REPO_NOT_INITIALIZED, path: this.path })) } - callback() + callback(err) } ) } @@ -355,7 +356,9 @@ function ignoringAlreadyOpened (cb) { } function ignoringNotFound (cb) { - return ignoringIf((err) => err.message.startsWith('ENOENT'), cb) + return ignoringIf((err) => { + return err && (err.code === ERRORS.ERR_REPO_NOT_INITIALIZED || err.message.startsWith('ENOENT')) + }, cb) } function buildOptions (_options) { diff --git a/test/options-test.js b/test/options-test.js index 6598210f..b7afb606 100644 --- a/test/options-test.js +++ b/test/options-test.js @@ -86,15 +86,9 @@ function expectedRepoOptions () { } if (process.browser) { - options.storageBackendOptions.root.db = require('leveldown') - options.storageBackendOptions.keys.db = require('leveldown') options.storageBackendOptions.keys.sharding = false - options.storageBackendOptions.blocks.db = require('leveldown') delete options.storageBackendOptions.blocks.extension options.storageBackendOptions.blocks.sharding = false - options.storageBackendOptions.datastore = { - db: require('leveldown') - } } return options }