Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Drop legacy features & runtime environments #374

Merged
merged 12 commits into from
Apr 9, 2021
Merged
26 changes: 16 additions & 10 deletions .airtap.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
providers:
- airtap-sauce
- airtap-default

browsers:
- name: chrome
version: latest
platform: Windows 10
- name: firefox
version: latest
platform: Windows 10
- name: iphone
version: '9.0'
- name: android
version: '6.0'
- name: microsoftedge
version: latest
- name: safari
version: 12..latest
- name: ios_saf
version: 12..latest
- name: chrome for android
version: 6..latest
- name: msedge

presets:
local:
browsers:
- name: default
5 changes: 0 additions & 5 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,4 @@ updates:
schedule:
interval: monthly
ignore:
- dependency-name: buffer
- dependency-name: dependency-check
- dependency-name: sinon
- dependency-name: airtap
- dependency-name: nyc
- dependency-name: standard
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ language: node_js
matrix:
fast_finish: true
include:
- node_js: 6
- node_js: 10
env: CMD=test
- node_js: 8
- node_js: 12
env: CMD=test
- node_js: 10
- node_js: 14
env: CMD=test
- node_js: stable
env: CMD=test-browsers
addons:
sauce_connect: true
hosts:
- airtap.local

Expand Down
36 changes: 15 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ FakeLevelDOWN.prototype._open = function (options, callback) {
this._store = {}

// Use nextTick to be a nice async citizen
process.nextTick(callback)
this._nextTick(callback)
}

FakeLevelDOWN.prototype._serializeKey = function (key) {
Expand All @@ -125,23 +125,23 @@ FakeLevelDOWN.prototype._serializeKey = function (key) {

FakeLevelDOWN.prototype._put = function (key, value, options, callback) {
this._store[key] = value
process.nextTick(callback)
this._nextTick(callback)
}

FakeLevelDOWN.prototype._get = function (key, options, callback) {
var value = this._store[key]

if (value === undefined) {
// 'NotFound' error, consistent with LevelDOWN API
return process.nextTick(callback, new Error('NotFound'))
return this._nextTick(callback, new Error('NotFound'))
}

process.nextTick(callback, null, value)
this._nextTick(callback, null, value)
}

FakeLevelDOWN.prototype._del = function (key, options, callback) {
delete this._store[key]
process.nextTick(callback)
this._nextTick(callback)
}
```

Expand All @@ -167,7 +167,7 @@ See [`memdown`](https://github.com/Level/memdown/) if you are looking for a comp

## Browser Support

[![Sauce Test Status](https://saucelabs.com/browser-matrix/abstract-leveldown.svg)](https://saucelabs.com/u/abstract-leveldown)
[![Sauce Test Status](https://app.saucelabs.com/browser-matrix/abstract-leveldown.svg)](https://app.saucelabs.com/u/abstract-leveldown)

## Public API For Consumers

Expand Down Expand Up @@ -251,11 +251,6 @@ Returns an [`iterator`](#iterator). Accepts the following range options:
- `reverse` _(boolean, default: `false`)_: iterate entries in reverse order. Beware that a reverse seek can be slower than a forward seek.
- `limit` _(number, default: `-1`)_: limit the number of entries collected by this iterator. This number represents a _maximum_ number of entries and may not be reached if you get to the end of the range first. A value of `-1` means there is no limit. When `reverse=true` the entries with the highest keys will be returned instead of the lowest keys.

Legacy options:

- `start`: instead use `gte`
- `end`: instead use `lte`.

**Note** Zero-length strings, buffers and arrays as well as `null` and `undefined` are invalid as keys, yet valid as range options. These types are significant in encodings like [`bytewise`](https://github.com/deanlandolt/bytewise) and [`charwise`](https://github.com/dominictarr/charwise) as well as some underlying stores like IndexedDB. Consumers of an implementation should assume that `{ gt: undefined }` is _not_ the same as `{}`. An implementation can choose to:

- [_Serialize_](#db_serializekeykey) or [_encode_][encoding-down] these types to make them meaningful
Expand Down Expand Up @@ -288,13 +283,13 @@ If no options are provided, all entries will be deleted. The `callback` function

### `chainedBatch`

#### `chainedBatch.put(key, value)`
#### `chainedBatch.put(key, value[, options])`

Queue a `put` operation on this batch. This may throw if `key` or `value` is invalid.
Queue a `put` operation on this batch. This may throw if `key` or `value` is invalid. There are no `options` by default but implementations may add theirs.

#### `chainedBatch.del(key)`
#### `chainedBatch.del(key[, options])`

Queue a `del` operation on this batch. This may throw if `key` is invalid.
Queue a `del` operation on this batch. This may throw if `key` is invalid. There are no `options` by default but implementations may add theirs.

#### `chainedBatch.clear()`

Expand Down Expand Up @@ -358,7 +353,7 @@ Support of other key and value types depends on the implementation as well as it

Each of these methods will receive exactly the number and order of arguments described. Optional arguments will receive sensible defaults. All callbacks are error-first and must be asynchronous.

If an operation within your implementation is synchronous, be sure to invoke the callback on a next tick using `process.nextTick` or some other means of microtask scheduling. For convenience, the prototypes of `AbstractLevelDOWN`, `AbstractIterator` and `AbstractChainedBatch` include a `_nextTick` method that is compatible with node and browsers.
If an operation within your implementation is synchronous, be sure to invoke the callback on a next tick using `queueMicrotask`, `process.nextTick` or some other means of microtask scheduling. For convenience, the prototypes of `AbstractLevelDOWN`, `AbstractIterator` and `AbstractChainedBatch` include a `_nextTick` method that is compatible with node and browsers.

### `db = AbstractLevelDOWN([manifest])`

Expand Down Expand Up @@ -499,13 +494,13 @@ The default `_end()` invokes `callback` on a next tick. Overriding is optional.

The first argument to this constructor must be an instance of your `AbstractLevelDOWN` implementation. The constructor will set `chainedBatch.db` which is used to access `db._serialize*` and ensures that `db` will not be garbage collected in case there are no other references to it.

#### `chainedBatch._put(key, value)`
#### `chainedBatch._put(key, value, options)`

Queue a `put` operation on this batch.
Queue a `put` operation on this batch. There are no default options but `options` will always be an object.

#### `chainedBatch._del(key)`
#### `chainedBatch._del(key, options)`

Queue a `del` operation on this batch.
Queue a `del` operation on this batch. There are no default options but `options` will always be an object.

#### `chainedBatch._clear()`

Expand Down Expand Up @@ -570,7 +565,6 @@ This also serves as a signal to users of your implementation. The following opti
- Reads don't operate on a [snapshot](#iterator)
- Snapshots are created asynchronously
- `createIfMissing` and `errorIfExists`: set to `false` if `db._open()` does not support these options.
- `legacyRange`: set to `false` if your iterator does not support the legacy `start` and `end` range options.

This metadata will be moved to manifests (`db.supports`) in the future.

Expand Down
30 changes: 17 additions & 13 deletions abstract-chained-batch.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var nextTick = require('./next-tick')
'use strict'

const emptyOptions = Object.freeze({})

function AbstractChainedBatch (db) {
if (typeof db !== 'object' || db === null) {
Expand All @@ -16,38 +18,38 @@ AbstractChainedBatch.prototype._checkWritten = function () {
}
}

AbstractChainedBatch.prototype.put = function (key, value) {
AbstractChainedBatch.prototype.put = function (key, value, options) {
this._checkWritten()

var err = this.db._checkKey(key) || this.db._checkValue(value)
const err = this.db._checkKey(key) || this.db._checkValue(value)
if (err) throw err

key = this.db._serializeKey(key)
value = this.db._serializeValue(value)

this._put(key, value)
this._put(key, value, options != null ? options : emptyOptions)

return this
}

AbstractChainedBatch.prototype._put = function (key, value) {
this._operations.push({ type: 'put', key: key, value: value })
AbstractChainedBatch.prototype._put = function (key, value, options) {
this._operations.push({ ...options, type: 'put', key, value })
}

AbstractChainedBatch.prototype.del = function (key) {
AbstractChainedBatch.prototype.del = function (key, options) {
this._checkWritten()

var err = this.db._checkKey(key)
const err = this.db._checkKey(key)
if (err) throw err

key = this.db._serializeKey(key)
this._del(key)
this._del(key, options != null ? options : emptyOptions)

return this
}

AbstractChainedBatch.prototype._del = function (key) {
this._operations.push({ type: 'del', key: key })
AbstractChainedBatch.prototype._del = function (key, options) {
this._operations.push({ ...options, type: 'del', key })
}

AbstractChainedBatch.prototype.clear = function () {
Expand All @@ -64,7 +66,9 @@ AbstractChainedBatch.prototype._clear = function () {
AbstractChainedBatch.prototype.write = function (options, callback) {
this._checkWritten()

if (typeof options === 'function') { callback = options }
if (typeof options === 'function') {
callback = options
}
if (typeof callback !== 'function') {
throw new Error('write() requires a callback argument')
}
Expand All @@ -81,6 +85,6 @@ AbstractChainedBatch.prototype._write = function (options, callback) {
}

// Expose browser-compatible nextTick for dependents
AbstractChainedBatch.prototype._nextTick = nextTick
AbstractChainedBatch.prototype._nextTick = require('./next-tick')

module.exports = AbstractChainedBatch
34 changes: 16 additions & 18 deletions abstract-iterator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var nextTick = require('./next-tick')
'use strict'

function AbstractIterator (db) {
if (typeof db !== 'object' || db === null) {
Expand All @@ -11,33 +11,31 @@ function AbstractIterator (db) {
}

AbstractIterator.prototype.next = function (callback) {
var self = this

if (typeof callback !== 'function') {
throw new Error('next() requires a callback argument')
}

if (self._ended) {
nextTick(callback, new Error('cannot call next() after end()'))
return self
if (this._ended) {
this._nextTick(callback, new Error('cannot call next() after end()'))
return this
}

if (self._nexting) {
nextTick(callback, new Error('cannot call next() before previous next() has completed'))
return self
if (this._nexting) {
this._nextTick(callback, new Error('cannot call next() before previous next() has completed'))
return this
}

self._nexting = true
self._next(function () {
self._nexting = false
callback.apply(null, arguments)
this._nexting = true
this._next((err, ...rest) => {
this._nexting = false
callback(err, ...rest)
})

return self
return this
}

AbstractIterator.prototype._next = function (callback) {
nextTick(callback)
this._nextTick(callback)
}

AbstractIterator.prototype.seek = function (target) {
Expand All @@ -60,18 +58,18 @@ AbstractIterator.prototype.end = function (callback) {
}

if (this._ended) {
return nextTick(callback, new Error('end() already called on iterator'))
return this._nextTick(callback, new Error('end() already called on iterator'))
}

this._ended = true
this._end(callback)
}

AbstractIterator.prototype._end = function (callback) {
nextTick(callback)
this._nextTick(callback)
}

// Expose browser-compatible nextTick for dependents
AbstractIterator.prototype._nextTick = nextTick
AbstractIterator.prototype._nextTick = require('./next-tick')

module.exports = AbstractIterator
Loading