Skip to content

Commit

Permalink
Remove compatibility checks for levelup & friends (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed Jan 27, 2024
1 parent d89e68e commit def791f
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 100 deletions.
2 changes: 2 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ _This is a work in progress upgrade guide for the upcoming 2.0.0 release._

The guide for this release consists of two sections. One for the public API, relevant to all consumers of `abstract-level` and implementations thereof (`level`, `classic-level`, `memory-level` et cetera) and another for the private API that only implementors should have to read.

If you're upgrading from `levelup`, `abstract-leveldown` or other old modules, it's recommended to first upgrade to `abstract-level` 1.x because that version includes compatibility checks that have since been removed.

### 1. Public API

#### 1.1. Callbacks have been removed
Expand Down
8 changes: 0 additions & 8 deletions abstract-iterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,6 @@ class IteratorDecodeError extends ModuleError {
// }
// }

// To help migrating to abstract-level
for (const k of ['_ended property', '_nexting property', '_end method']) {
Object.defineProperty(AbstractIterator.prototype, k.split(' ')[0], {
get () { throw new ModuleError(`The ${k} has been removed`, { code: 'LEVEL_LEGACY' }) },
set () { throw new ModuleError(`The ${k} has been removed`, { code: 'LEVEL_LEGACY' }) }
})
}

function assertStatus (iterator) {
if (iterator[kClosing]) {
throw new ModuleError('Iterator is not open: cannot read after close()', {
Expand Down
11 changes: 0 additions & 11 deletions lib/abstract-sublevel.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,6 @@ const defaults = { separator: '!' }
module.exports = function ({ AbstractLevel }) {
class AbstractSublevel extends AbstractLevel {
static defaults (options) {
// To help migrating from subleveldown to abstract-level
if (typeof options === 'string') {
throw new ModuleError('The subleveldown string shorthand for { separator } has been removed', {
code: 'LEVEL_LEGACY'
})
} else if (options && options.open) {
throw new ModuleError('The subleveldown open option has been removed', {
code: 'LEVEL_LEGACY'
})
}

if (options == null) {
return defaults
} else if (!options.separator) {
Expand Down
12 changes: 0 additions & 12 deletions lib/range-options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'

const ModuleError = require('module-error')
const hasOwnProperty = Object.prototype.hasOwnProperty
const rangeOptions = new Set(['lt', 'lte', 'gt', 'gte'])

Expand All @@ -11,17 +10,6 @@ module.exports = function (options, keyEncoding) {
if (!hasOwnProperty.call(options, k)) continue
if (k === 'keyEncoding' || k === 'valueEncoding') continue

if (k === 'start' || k === 'end') {
throw new ModuleError(`The legacy range option '${k}' has been removed`, {
code: 'LEVEL_LEGACY'
})
} else if (k === 'encoding') {
// To help migrating to abstract-level
throw new ModuleError("The levelup-style 'encoding' alias has been removed, use 'valueEncoding' instead", {
code: 'LEVEL_LEGACY'
})
}

if (rangeOptions.has(k)) {
// Note that we don't reject nullish and empty options here. While
// those types are invalid as keys, they are valid as range options.
Expand Down
24 changes: 0 additions & 24 deletions test/clear-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,6 @@
const isBuffer = require('is-buffer')
const { Buffer } = require('buffer')

exports.args = function (test, testCommon) {
test('clear() with legacy range options', async function (t) {
t.plan(2)

const db = testCommon.factory()
await db.open()

try {
await db.clear({ start: 'foo' })
} catch (err) {
t.is(err.code, 'LEVEL_LEGACY')
}

try {
await db.clear({ end: 'foo' })
} catch (err) {
t.is(err.code, 'LEVEL_LEGACY')
}

return db.close()
})
}

exports.clear = function (test, testCommon) {
makeTest('string', ['a', 'b'])

Expand Down Expand Up @@ -128,7 +105,6 @@ exports.events = function (test, testCommon) {
}

exports.all = function (test, testCommon) {
exports.args(test, testCommon)
exports.events(test, testCommon)
exports.clear(test, testCommon)
}
17 changes: 1 addition & 16 deletions test/self.js
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ test('rangeOptions', function (t) {
t.end()
}

t.plan(11)
t.plan(10)
t.test('setup', async (t) => db.open())

t.test('default options', function (t) {
Expand Down Expand Up @@ -859,21 +859,6 @@ test('rangeOptions', function (t) {
})
verifyOptions(t, getRangeOptions(options, db.keyEncoding('utf8')))
})

t.test('rejects legacy range and encoding options', function (t) {
t.plan(3)

for (const key of ['start', 'end', 'encoding']) {
const options = {}
options[key] = 'x'

try {
getRangeOptions(options, db.keyEncoding('utf8'))
} catch (err) {
t.is(err.code, 'LEVEL_LEGACY')
}
}
})
})

require('./self/abort-test')
Expand Down
23 changes: 0 additions & 23 deletions test/self/abstract-iterator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,26 +189,3 @@ for (const Ctor of [AbstractIterator, AbstractKeyIterator, AbstractValueIterator
await db.close()
})
}

test('AbstractIterator throws when accessing legacy properties', async function (t) {
t.plan(3 * 2)

const db = testCommon.factory()
await db.open()
const it = new AbstractIterator(db, {})

for (const k of ['_ended property', '_nexting property', '_end method']) {
try {
// eslint-disable-next-line no-unused-expressions
it[k.split(' ')[0]]
} catch (err) {
t.is(err.code, 'LEVEL_LEGACY')
}

try {
it[k.split(' ')[0]] = 123
} catch (err) {
t.is(err.code, 'LEVEL_LEGACY')
}
}
})
6 changes: 0 additions & 6 deletions test/self/sublevel-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,6 @@ test('sublevel prefix and options', function (t) {
t.end()
})

t.test('legacy sublevel(down) options', function (t) {
t.throws(() => new NoopLevel().sublevel('foo', 'bar'), (err) => err.code === 'LEVEL_LEGACY')
t.throws(() => new NoopLevel().sublevel('foo', { open: () => {} }), (err) => err.code === 'LEVEL_LEGACY')
t.end()
})

// See https://github.com/Level/subleveldown/issues/78
t.test('doubly nested sublevel has correct prefix', async function (t) {
t.plan(1)
Expand Down

0 comments on commit def791f

Please sign in to comment.