Skip to content

Commit bd8a930

Browse files
Jacob Heundaviddias
authored andcommitted
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 <[email protected]> * chore: add node 10 to jenkins License: MIT Signed-off-by: Jacob Heun <[email protected]> chore: use 10.0 instead of 10.1 License: MIT Signed-off-by: Jacob Heun <[email protected]> * chore: update jenkins overrides License: MIT Signed-off-by: Jacob Heun <[email protected]> * fix: keep initialized errors separate from unknowns License: MIT Signed-off-by: Jacob Heun <[email protected]> * refactor: move error code to an exported constant * chore: update deps License: MIT Signed-off-by: Jacob Heun <[email protected]> * chore: update deps
1 parent cdc5f4a commit bd8a930

File tree

6 files changed

+16
-25
lines changed

6 files changed

+16
-25
lines changed

ci/Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
javascript()
1+
javascript(['nodejs_versions': ['8.11.1','9.2.0','10.0.0']])

package.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"browser": {
88
"rimraf": false,
99
"datastore-fs": "datastore-level",
10-
"leveldown": "level-js",
1110
"./src/lock.js": "./src/lock-memory.js",
1211
"./src/default-options.js": "./src/default-options-browser.js"
1312
},
@@ -60,14 +59,12 @@
6059
"big.js": "^5.0.3",
6160
"cids": "~0.5.3",
6261
"datastore-core": "~0.4.0",
63-
"datastore-fs": "~0.4.2",
64-
"datastore-level": "~0.7.0",
62+
"datastore-fs": "~0.5.0",
63+
"datastore-level": "~0.8.0",
6564
"debug": "^3.1.0",
6665
"interface-datastore": "~0.4.2",
6766
"ipfs-block": "~0.7.1",
68-
"level-js": "timkuijsten/level.js#idbunwrapper",
69-
"leveldown": "^1.7.2",
70-
"lock-me": "^1.0.3",
67+
"lock-me": "^1.0.4",
7168
"lodash.get": "^4.4.2",
7269
"lodash.has": "^4.5.2",
7370
"lodash.set": "^4.3.2",

src/default-options-browser.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,13 @@ module.exports = {
1111
},
1212
storageBackendOptions: {
1313
root: {
14-
db: require('level-js'),
1514
extension: ''
1615
},
1716
blocks: {
18-
sharding: false,
19-
db: require('level-js')
17+
sharding: false
2018
},
2119
keys: {
22-
sharding: false,
23-
db: require('level-js')
24-
},
25-
datastore: {
26-
db: require('level-js')
20+
sharding: false
2721
}
2822
}
2923
}

src/errors/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
exports.ERR_REPO_NOT_INITIALIZED = 'ERR_REPO_NOT_INITIALIZED'

src/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const config = require('./config')
1616
const apiAddr = require('./api-addr')
1717
const blockstore = require('./blockstore')
1818
const defaultOptions = require('./default-options')
19+
const ERRORS = require('./errors')
1920

2021
const log = debug('repo')
2122

@@ -212,14 +213,14 @@ class IpfsRepo {
212213
},
213214
(err, res) => {
214215
log('init', err, res)
215-
if (err) {
216+
if (err && !res.config) {
216217
return callback(Object.assign(new Error('repo is not initialized yet'),
217218
{
218-
code: 'ERR_REPO_NOT_INITIALIZED',
219+
code: ERRORS.ERR_REPO_NOT_INITIALIZED,
219220
path: this.path
220221
}))
221222
}
222-
callback()
223+
callback(err)
223224
}
224225
)
225226
}
@@ -355,7 +356,9 @@ function ignoringAlreadyOpened (cb) {
355356
}
356357

357358
function ignoringNotFound (cb) {
358-
return ignoringIf((err) => err.message.startsWith('ENOENT'), cb)
359+
return ignoringIf((err) => {
360+
return err && (err.code === ERRORS.ERR_REPO_NOT_INITIALIZED || err.message.startsWith('ENOENT'))
361+
}, cb)
359362
}
360363

361364
function buildOptions (_options) {

test/options-test.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,9 @@ function expectedRepoOptions () {
8686
}
8787

8888
if (process.browser) {
89-
options.storageBackendOptions.root.db = require('leveldown')
90-
options.storageBackendOptions.keys.db = require('leveldown')
9189
options.storageBackendOptions.keys.sharding = false
92-
options.storageBackendOptions.blocks.db = require('leveldown')
9390
delete options.storageBackendOptions.blocks.extension
9491
options.storageBackendOptions.blocks.sharding = false
95-
options.storageBackendOptions.datastore = {
96-
db: require('leveldown')
97-
}
9892
}
9993
return options
10094
}

0 commit comments

Comments
 (0)