Skip to content

Commit

Permalink
Relax isAbstract check
Browse files Browse the repository at this point in the history
To deal with a node_modules tree that has multiple versions of
abstract-leveldown, and those versions having a different API.

Ref cabal-club/cabal-core#54
  • Loading branch information
vweevers committed Aug 18, 2019
1 parent 7ac417c commit fbbf525
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions leveldown.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,12 @@ module.exports = SubDown
function down (db, type) {
if (typeof db.down === 'function') return db.down(type)
if (type && db.type === type) return db
if (isAbstract(db.db)) return down(db.db, type)
if (isAbstract(db._db)) return down(db._db, type)
if (isLooseAbstract(db.db)) return down(db.db, type)
if (isLooseAbstract(db._db)) return down(db._db, type)
return type ? null : db
}

function isAbstract (db) {
function isLooseAbstract (db) {
if (!db || typeof db !== 'object') { return false }
return Object.keys(abstract.AbstractLevelDOWN.prototype).filter(function (name) {
return name[0] !== '_'
}).every(function (name) {
return typeof db[name] === 'function'
})
return typeof db._batch === 'function' && typeof db._iterator === 'function'
}

0 comments on commit fbbf525

Please sign in to comment.