forked from public/fvtt-cthulhu-eternal
Initial import with skill sheet working
This commit is contained in:
124
node_modules/abstract-level/lib/abstract-sublevel-iterator.js
generated
vendored
Normal file
124
node_modules/abstract-level/lib/abstract-sublevel-iterator.js
generated
vendored
Normal file
@ -0,0 +1,124 @@
|
||||
'use strict'
|
||||
|
||||
const { AbstractIterator, AbstractKeyIterator, AbstractValueIterator } = require('../abstract-iterator')
|
||||
|
||||
const kUnfix = Symbol('unfix')
|
||||
const kIterator = Symbol('iterator')
|
||||
const kHandleOne = Symbol('handleOne')
|
||||
const kHandleMany = Symbol('handleMany')
|
||||
const kCallback = Symbol('callback')
|
||||
|
||||
// TODO: unfix natively if db supports it
|
||||
class AbstractSublevelIterator extends AbstractIterator {
|
||||
constructor (db, options, iterator, unfix) {
|
||||
super(db, options)
|
||||
|
||||
this[kIterator] = iterator
|
||||
this[kUnfix] = unfix
|
||||
this[kHandleOne] = this[kHandleOne].bind(this)
|
||||
this[kHandleMany] = this[kHandleMany].bind(this)
|
||||
this[kCallback] = null
|
||||
}
|
||||
|
||||
[kHandleOne] (err, key, value) {
|
||||
const callback = this[kCallback]
|
||||
if (err) return callback(err)
|
||||
if (key !== undefined) key = this[kUnfix](key)
|
||||
callback(err, key, value)
|
||||
}
|
||||
|
||||
[kHandleMany] (err, entries) {
|
||||
const callback = this[kCallback]
|
||||
if (err) return callback(err)
|
||||
|
||||
for (const entry of entries) {
|
||||
const key = entry[0]
|
||||
if (key !== undefined) entry[0] = this[kUnfix](key)
|
||||
}
|
||||
|
||||
callback(err, entries)
|
||||
}
|
||||
}
|
||||
|
||||
class AbstractSublevelKeyIterator extends AbstractKeyIterator {
|
||||
constructor (db, options, iterator, unfix) {
|
||||
super(db, options)
|
||||
|
||||
this[kIterator] = iterator
|
||||
this[kUnfix] = unfix
|
||||
this[kHandleOne] = this[kHandleOne].bind(this)
|
||||
this[kHandleMany] = this[kHandleMany].bind(this)
|
||||
this[kCallback] = null
|
||||
}
|
||||
|
||||
[kHandleOne] (err, key) {
|
||||
const callback = this[kCallback]
|
||||
if (err) return callback(err)
|
||||
if (key !== undefined) key = this[kUnfix](key)
|
||||
callback(err, key)
|
||||
}
|
||||
|
||||
[kHandleMany] (err, keys) {
|
||||
const callback = this[kCallback]
|
||||
if (err) return callback(err)
|
||||
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const key = keys[i]
|
||||
if (key !== undefined) keys[i] = this[kUnfix](key)
|
||||
}
|
||||
|
||||
callback(err, keys)
|
||||
}
|
||||
}
|
||||
|
||||
class AbstractSublevelValueIterator extends AbstractValueIterator {
|
||||
constructor (db, options, iterator) {
|
||||
super(db, options)
|
||||
this[kIterator] = iterator
|
||||
}
|
||||
}
|
||||
|
||||
for (const Iterator of [AbstractSublevelIterator, AbstractSublevelKeyIterator]) {
|
||||
Iterator.prototype._next = function (callback) {
|
||||
this[kCallback] = callback
|
||||
this[kIterator].next(this[kHandleOne])
|
||||
}
|
||||
|
||||
Iterator.prototype._nextv = function (size, options, callback) {
|
||||
this[kCallback] = callback
|
||||
this[kIterator].nextv(size, options, this[kHandleMany])
|
||||
}
|
||||
|
||||
Iterator.prototype._all = function (options, callback) {
|
||||
this[kCallback] = callback
|
||||
this[kIterator].all(options, this[kHandleMany])
|
||||
}
|
||||
}
|
||||
|
||||
for (const Iterator of [AbstractSublevelValueIterator]) {
|
||||
Iterator.prototype._next = function (callback) {
|
||||
this[kIterator].next(callback)
|
||||
}
|
||||
|
||||
Iterator.prototype._nextv = function (size, options, callback) {
|
||||
this[kIterator].nextv(size, options, callback)
|
||||
}
|
||||
|
||||
Iterator.prototype._all = function (options, callback) {
|
||||
this[kIterator].all(options, callback)
|
||||
}
|
||||
}
|
||||
|
||||
for (const Iterator of [AbstractSublevelIterator, AbstractSublevelKeyIterator, AbstractSublevelValueIterator]) {
|
||||
Iterator.prototype._seek = function (target, options) {
|
||||
this[kIterator].seek(target, options)
|
||||
}
|
||||
|
||||
Iterator.prototype._close = function (callback) {
|
||||
this[kIterator].close(callback)
|
||||
}
|
||||
}
|
||||
|
||||
exports.AbstractSublevelIterator = AbstractSublevelIterator
|
||||
exports.AbstractSublevelKeyIterator = AbstractSublevelKeyIterator
|
||||
exports.AbstractSublevelValueIterator = AbstractSublevelValueIterator
|
258
node_modules/abstract-level/lib/abstract-sublevel.js
generated
vendored
Normal file
258
node_modules/abstract-level/lib/abstract-sublevel.js
generated
vendored
Normal file
@ -0,0 +1,258 @@
|
||||
'use strict'
|
||||
|
||||
const ModuleError = require('module-error')
|
||||
const { Buffer } = require('buffer') || {}
|
||||
const {
|
||||
AbstractSublevelIterator,
|
||||
AbstractSublevelKeyIterator,
|
||||
AbstractSublevelValueIterator
|
||||
} = require('./abstract-sublevel-iterator')
|
||||
|
||||
const kPrefix = Symbol('prefix')
|
||||
const kUpperBound = Symbol('upperBound')
|
||||
const kPrefixRange = Symbol('prefixRange')
|
||||
const kParent = Symbol('parent')
|
||||
const kUnfix = Symbol('unfix')
|
||||
|
||||
const textEncoder = new TextEncoder()
|
||||
const defaults = { separator: '!' }
|
||||
|
||||
// Wrapped to avoid circular dependency
|
||||
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) {
|
||||
return { ...options, separator: '!' }
|
||||
} else {
|
||||
return options
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: add autoClose option, which if true, does parent.attachResource(this)
|
||||
constructor (db, name, options) {
|
||||
// Don't forward AbstractSublevel options to AbstractLevel
|
||||
const { separator, manifest, ...forward } = AbstractSublevel.defaults(options)
|
||||
name = trim(name, separator)
|
||||
|
||||
// Reserve one character between separator and name to give us an upper bound
|
||||
const reserved = separator.charCodeAt(0) + 1
|
||||
const parent = db[kParent] || db
|
||||
|
||||
// Keys should sort like ['!a!', '!a!!a!', '!a"', '!aa!', '!b!'].
|
||||
// Use ASCII for consistent length between string, Buffer and Uint8Array
|
||||
if (!textEncoder.encode(name).every(x => x > reserved && x < 127)) {
|
||||
throw new ModuleError(`Prefix must use bytes > ${reserved} < ${127}`, {
|
||||
code: 'LEVEL_INVALID_PREFIX'
|
||||
})
|
||||
}
|
||||
|
||||
super(mergeManifests(parent, manifest), forward)
|
||||
|
||||
const prefix = (db.prefix || '') + separator + name + separator
|
||||
const upperBound = prefix.slice(0, -1) + String.fromCharCode(reserved)
|
||||
|
||||
this[kParent] = parent
|
||||
this[kPrefix] = new MultiFormat(prefix)
|
||||
this[kUpperBound] = new MultiFormat(upperBound)
|
||||
this[kUnfix] = new Unfixer()
|
||||
|
||||
this.nextTick = parent.nextTick
|
||||
}
|
||||
|
||||
prefixKey (key, keyFormat) {
|
||||
if (keyFormat === 'utf8') {
|
||||
return this[kPrefix].utf8 + key
|
||||
} else if (key.byteLength === 0) {
|
||||
// Fast path for empty key (no copy)
|
||||
return this[kPrefix][keyFormat]
|
||||
} else if (keyFormat === 'view') {
|
||||
const view = this[kPrefix].view
|
||||
const result = new Uint8Array(view.byteLength + key.byteLength)
|
||||
|
||||
result.set(view, 0)
|
||||
result.set(key, view.byteLength)
|
||||
|
||||
return result
|
||||
} else {
|
||||
const buffer = this[kPrefix].buffer
|
||||
return Buffer.concat([buffer, key], buffer.byteLength + key.byteLength)
|
||||
}
|
||||
}
|
||||
|
||||
// Not exposed for now.
|
||||
[kPrefixRange] (range, keyFormat) {
|
||||
if (range.gte !== undefined) {
|
||||
range.gte = this.prefixKey(range.gte, keyFormat)
|
||||
} else if (range.gt !== undefined) {
|
||||
range.gt = this.prefixKey(range.gt, keyFormat)
|
||||
} else {
|
||||
range.gte = this[kPrefix][keyFormat]
|
||||
}
|
||||
|
||||
if (range.lte !== undefined) {
|
||||
range.lte = this.prefixKey(range.lte, keyFormat)
|
||||
} else if (range.lt !== undefined) {
|
||||
range.lt = this.prefixKey(range.lt, keyFormat)
|
||||
} else {
|
||||
range.lte = this[kUpperBound][keyFormat]
|
||||
}
|
||||
}
|
||||
|
||||
get prefix () {
|
||||
return this[kPrefix].utf8
|
||||
}
|
||||
|
||||
get db () {
|
||||
return this[kParent]
|
||||
}
|
||||
|
||||
_open (options, callback) {
|
||||
// The parent db must open itself or be (re)opened by the user because
|
||||
// a sublevel should not initiate state changes on the rest of the db.
|
||||
this[kParent].open({ passive: true }, callback)
|
||||
}
|
||||
|
||||
_put (key, value, options, callback) {
|
||||
this[kParent].put(key, value, options, callback)
|
||||
}
|
||||
|
||||
_get (key, options, callback) {
|
||||
this[kParent].get(key, options, callback)
|
||||
}
|
||||
|
||||
_getMany (keys, options, callback) {
|
||||
this[kParent].getMany(keys, options, callback)
|
||||
}
|
||||
|
||||
_del (key, options, callback) {
|
||||
this[kParent].del(key, options, callback)
|
||||
}
|
||||
|
||||
_batch (operations, options, callback) {
|
||||
this[kParent].batch(operations, options, callback)
|
||||
}
|
||||
|
||||
_clear (options, callback) {
|
||||
// TODO (refactor): move to AbstractLevel
|
||||
this[kPrefixRange](options, options.keyEncoding)
|
||||
this[kParent].clear(options, callback)
|
||||
}
|
||||
|
||||
_iterator (options) {
|
||||
// TODO (refactor): move to AbstractLevel
|
||||
this[kPrefixRange](options, options.keyEncoding)
|
||||
const iterator = this[kParent].iterator(options)
|
||||
const unfix = this[kUnfix].get(this[kPrefix].utf8.length, options.keyEncoding)
|
||||
return new AbstractSublevelIterator(this, options, iterator, unfix)
|
||||
}
|
||||
|
||||
_keys (options) {
|
||||
this[kPrefixRange](options, options.keyEncoding)
|
||||
const iterator = this[kParent].keys(options)
|
||||
const unfix = this[kUnfix].get(this[kPrefix].utf8.length, options.keyEncoding)
|
||||
return new AbstractSublevelKeyIterator(this, options, iterator, unfix)
|
||||
}
|
||||
|
||||
_values (options) {
|
||||
this[kPrefixRange](options, options.keyEncoding)
|
||||
const iterator = this[kParent].values(options)
|
||||
return new AbstractSublevelValueIterator(this, options, iterator)
|
||||
}
|
||||
}
|
||||
|
||||
return { AbstractSublevel }
|
||||
}
|
||||
|
||||
const mergeManifests = function (parent, manifest) {
|
||||
return {
|
||||
// Inherit manifest of parent db
|
||||
...parent.supports,
|
||||
|
||||
// Disable unsupported features
|
||||
createIfMissing: false,
|
||||
errorIfExists: false,
|
||||
|
||||
// Unset additional events because we're not forwarding them
|
||||
events: {},
|
||||
|
||||
// Unset additional methods (like approximateSize) which we can't support here unless
|
||||
// the AbstractSublevel class is overridden by an implementation of `abstract-level`.
|
||||
additionalMethods: {},
|
||||
|
||||
// Inherit manifest of custom AbstractSublevel subclass. Such a class is not
|
||||
// allowed to override encodings.
|
||||
...manifest,
|
||||
|
||||
encodings: {
|
||||
utf8: supportsEncoding(parent, 'utf8'),
|
||||
buffer: supportsEncoding(parent, 'buffer'),
|
||||
view: supportsEncoding(parent, 'view')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const supportsEncoding = function (parent, encoding) {
|
||||
// Prefer a non-transcoded encoding for optimal performance
|
||||
return parent.supports.encodings[encoding]
|
||||
? parent.keyEncoding(encoding).name === encoding
|
||||
: false
|
||||
}
|
||||
|
||||
class MultiFormat {
|
||||
constructor (key) {
|
||||
this.utf8 = key
|
||||
this.view = textEncoder.encode(key)
|
||||
this.buffer = Buffer ? Buffer.from(this.view.buffer, 0, this.view.byteLength) : {}
|
||||
}
|
||||
}
|
||||
|
||||
class Unfixer {
|
||||
constructor () {
|
||||
this.cache = new Map()
|
||||
}
|
||||
|
||||
get (prefixLength, keyFormat) {
|
||||
let unfix = this.cache.get(keyFormat)
|
||||
|
||||
if (unfix === undefined) {
|
||||
if (keyFormat === 'view') {
|
||||
unfix = function (prefixLength, key) {
|
||||
// Avoid Uint8Array#slice() because it copies
|
||||
return key.subarray(prefixLength)
|
||||
}.bind(null, prefixLength)
|
||||
} else {
|
||||
unfix = function (prefixLength, key) {
|
||||
// Avoid Buffer#subarray() because it's slow
|
||||
return key.slice(prefixLength)
|
||||
}.bind(null, prefixLength)
|
||||
}
|
||||
|
||||
this.cache.set(keyFormat, unfix)
|
||||
}
|
||||
|
||||
return unfix
|
||||
}
|
||||
}
|
||||
|
||||
const trim = function (str, char) {
|
||||
let start = 0
|
||||
let end = str.length
|
||||
|
||||
while (start < end && str[start] === char) start++
|
||||
while (end > start && str[end - 1] === char) end--
|
||||
|
||||
return str.slice(start, end)
|
||||
}
|
17
node_modules/abstract-level/lib/common.js
generated
vendored
Normal file
17
node_modules/abstract-level/lib/common.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
'use strict'
|
||||
|
||||
exports.getCallback = function (options, callback) {
|
||||
return typeof options === 'function' ? options : callback
|
||||
}
|
||||
|
||||
exports.getOptions = function (options, def) {
|
||||
if (typeof options === 'object' && options !== null) {
|
||||
return options
|
||||
}
|
||||
|
||||
if (def !== undefined) {
|
||||
return def
|
||||
}
|
||||
|
||||
return {}
|
||||
}
|
41
node_modules/abstract-level/lib/default-chained-batch.js
generated
vendored
Normal file
41
node_modules/abstract-level/lib/default-chained-batch.js
generated
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
'use strict'
|
||||
|
||||
const { AbstractChainedBatch } = require('../abstract-chained-batch')
|
||||
const ModuleError = require('module-error')
|
||||
const kEncoded = Symbol('encoded')
|
||||
|
||||
// Functional default for chained batch, with support of deferred open
|
||||
class DefaultChainedBatch extends AbstractChainedBatch {
|
||||
constructor (db) {
|
||||
super(db)
|
||||
this[kEncoded] = []
|
||||
}
|
||||
|
||||
_put (key, value, options) {
|
||||
this[kEncoded].push({ ...options, type: 'put', key, value })
|
||||
}
|
||||
|
||||
_del (key, options) {
|
||||
this[kEncoded].push({ ...options, type: 'del', key })
|
||||
}
|
||||
|
||||
_clear () {
|
||||
this[kEncoded] = []
|
||||
}
|
||||
|
||||
// Assumes this[kEncoded] cannot change after write()
|
||||
_write (options, callback) {
|
||||
if (this.db.status === 'opening') {
|
||||
this.db.defer(() => this._write(options, callback))
|
||||
} else if (this.db.status === 'open') {
|
||||
if (this[kEncoded].length === 0) this.nextTick(callback)
|
||||
else this.db._batch(this[kEncoded], options, callback)
|
||||
} else {
|
||||
this.nextTick(callback, new ModuleError('Batch is not open: cannot call write() after write() or close()', {
|
||||
code: 'LEVEL_BATCH_NOT_OPEN'
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exports.DefaultChainedBatch = DefaultChainedBatch
|
72
node_modules/abstract-level/lib/default-kv-iterator.js
generated
vendored
Normal file
72
node_modules/abstract-level/lib/default-kv-iterator.js
generated
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
'use strict'
|
||||
|
||||
const { AbstractKeyIterator, AbstractValueIterator } = require('../abstract-iterator')
|
||||
|
||||
const kIterator = Symbol('iterator')
|
||||
const kCallback = Symbol('callback')
|
||||
const kHandleOne = Symbol('handleOne')
|
||||
const kHandleMany = Symbol('handleMany')
|
||||
|
||||
class DefaultKeyIterator extends AbstractKeyIterator {
|
||||
constructor (db, options) {
|
||||
super(db, options)
|
||||
|
||||
this[kIterator] = db.iterator({ ...options, keys: true, values: false })
|
||||
this[kHandleOne] = this[kHandleOne].bind(this)
|
||||
this[kHandleMany] = this[kHandleMany].bind(this)
|
||||
}
|
||||
}
|
||||
|
||||
class DefaultValueIterator extends AbstractValueIterator {
|
||||
constructor (db, options) {
|
||||
super(db, options)
|
||||
|
||||
this[kIterator] = db.iterator({ ...options, keys: false, values: true })
|
||||
this[kHandleOne] = this[kHandleOne].bind(this)
|
||||
this[kHandleMany] = this[kHandleMany].bind(this)
|
||||
}
|
||||
}
|
||||
|
||||
for (const Iterator of [DefaultKeyIterator, DefaultValueIterator]) {
|
||||
const keys = Iterator === DefaultKeyIterator
|
||||
const mapEntry = keys ? (entry) => entry[0] : (entry) => entry[1]
|
||||
|
||||
Iterator.prototype._next = function (callback) {
|
||||
this[kCallback] = callback
|
||||
this[kIterator].next(this[kHandleOne])
|
||||
}
|
||||
|
||||
Iterator.prototype[kHandleOne] = function (err, key, value) {
|
||||
const callback = this[kCallback]
|
||||
if (err) callback(err)
|
||||
else callback(null, keys ? key : value)
|
||||
}
|
||||
|
||||
Iterator.prototype._nextv = function (size, options, callback) {
|
||||
this[kCallback] = callback
|
||||
this[kIterator].nextv(size, options, this[kHandleMany])
|
||||
}
|
||||
|
||||
Iterator.prototype._all = function (options, callback) {
|
||||
this[kCallback] = callback
|
||||
this[kIterator].all(options, this[kHandleMany])
|
||||
}
|
||||
|
||||
Iterator.prototype[kHandleMany] = function (err, entries) {
|
||||
const callback = this[kCallback]
|
||||
if (err) callback(err)
|
||||
else callback(null, entries.map(mapEntry))
|
||||
}
|
||||
|
||||
Iterator.prototype._seek = function (target, options) {
|
||||
this[kIterator].seek(target, options)
|
||||
}
|
||||
|
||||
Iterator.prototype._close = function (callback) {
|
||||
this[kIterator].close(callback)
|
||||
}
|
||||
}
|
||||
|
||||
// Internal utilities, should be typed as AbstractKeyIterator and AbstractValueIterator
|
||||
exports.DefaultKeyIterator = DefaultKeyIterator
|
||||
exports.DefaultValueIterator = DefaultValueIterator
|
108
node_modules/abstract-level/lib/deferred-iterator.js
generated
vendored
Normal file
108
node_modules/abstract-level/lib/deferred-iterator.js
generated
vendored
Normal file
@ -0,0 +1,108 @@
|
||||
'use strict'
|
||||
|
||||
const { AbstractIterator, AbstractKeyIterator, AbstractValueIterator } = require('../abstract-iterator')
|
||||
const ModuleError = require('module-error')
|
||||
|
||||
const kNut = Symbol('nut')
|
||||
const kUndefer = Symbol('undefer')
|
||||
const kFactory = Symbol('factory')
|
||||
|
||||
class DeferredIterator extends AbstractIterator {
|
||||
constructor (db, options) {
|
||||
super(db, options)
|
||||
|
||||
this[kNut] = null
|
||||
this[kFactory] = () => db.iterator(options)
|
||||
|
||||
this.db.defer(() => this[kUndefer]())
|
||||
}
|
||||
}
|
||||
|
||||
class DeferredKeyIterator extends AbstractKeyIterator {
|
||||
constructor (db, options) {
|
||||
super(db, options)
|
||||
|
||||
this[kNut] = null
|
||||
this[kFactory] = () => db.keys(options)
|
||||
|
||||
this.db.defer(() => this[kUndefer]())
|
||||
}
|
||||
}
|
||||
|
||||
class DeferredValueIterator extends AbstractValueIterator {
|
||||
constructor (db, options) {
|
||||
super(db, options)
|
||||
|
||||
this[kNut] = null
|
||||
this[kFactory] = () => db.values(options)
|
||||
|
||||
this.db.defer(() => this[kUndefer]())
|
||||
}
|
||||
}
|
||||
|
||||
for (const Iterator of [DeferredIterator, DeferredKeyIterator, DeferredValueIterator]) {
|
||||
Iterator.prototype[kUndefer] = function () {
|
||||
if (this.db.status === 'open') {
|
||||
this[kNut] = this[kFactory]()
|
||||
}
|
||||
}
|
||||
|
||||
Iterator.prototype._next = function (callback) {
|
||||
if (this[kNut] !== null) {
|
||||
this[kNut].next(callback)
|
||||
} else if (this.db.status === 'opening') {
|
||||
this.db.defer(() => this._next(callback))
|
||||
} else {
|
||||
this.nextTick(callback, new ModuleError('Iterator is not open: cannot call next() after close()', {
|
||||
code: 'LEVEL_ITERATOR_NOT_OPEN'
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
Iterator.prototype._nextv = function (size, options, callback) {
|
||||
if (this[kNut] !== null) {
|
||||
this[kNut].nextv(size, options, callback)
|
||||
} else if (this.db.status === 'opening') {
|
||||
this.db.defer(() => this._nextv(size, options, callback))
|
||||
} else {
|
||||
this.nextTick(callback, new ModuleError('Iterator is not open: cannot call nextv() after close()', {
|
||||
code: 'LEVEL_ITERATOR_NOT_OPEN'
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
Iterator.prototype._all = function (options, callback) {
|
||||
if (this[kNut] !== null) {
|
||||
this[kNut].all(callback)
|
||||
} else if (this.db.status === 'opening') {
|
||||
this.db.defer(() => this._all(options, callback))
|
||||
} else {
|
||||
this.nextTick(callback, new ModuleError('Iterator is not open: cannot call all() after close()', {
|
||||
code: 'LEVEL_ITERATOR_NOT_OPEN'
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
Iterator.prototype._seek = function (target, options) {
|
||||
if (this[kNut] !== null) {
|
||||
// TODO: explain why we need _seek() rather than seek() here
|
||||
this[kNut]._seek(target, options)
|
||||
} else if (this.db.status === 'opening') {
|
||||
this.db.defer(() => this._seek(target, options))
|
||||
}
|
||||
}
|
||||
|
||||
Iterator.prototype._close = function (callback) {
|
||||
if (this[kNut] !== null) {
|
||||
this[kNut].close(callback)
|
||||
} else if (this.db.status === 'opening') {
|
||||
this.db.defer(() => this._close(callback))
|
||||
} else {
|
||||
this.nextTick(callback)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exports.DeferredIterator = DeferredIterator
|
||||
exports.DeferredKeyIterator = DeferredKeyIterator
|
||||
exports.DeferredValueIterator = DeferredValueIterator
|
11
node_modules/abstract-level/lib/next-tick-browser.js
generated
vendored
Normal file
11
node_modules/abstract-level/lib/next-tick-browser.js
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
'use strict'
|
||||
|
||||
const queueMicrotask = require('queue-microtask')
|
||||
|
||||
module.exports = function (fn, ...args) {
|
||||
if (args.length === 0) {
|
||||
queueMicrotask(fn)
|
||||
} else {
|
||||
queueMicrotask(() => fn(...args))
|
||||
}
|
||||
}
|
3
node_modules/abstract-level/lib/next-tick.js
generated
vendored
Normal file
3
node_modules/abstract-level/lib/next-tick.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = process.nextTick
|
38
node_modules/abstract-level/lib/range-options.js
generated
vendored
Normal file
38
node_modules/abstract-level/lib/range-options.js
generated
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
'use strict'
|
||||
|
||||
const ModuleError = require('module-error')
|
||||
const hasOwnProperty = Object.prototype.hasOwnProperty
|
||||
const rangeOptions = new Set(['lt', 'lte', 'gt', 'gte'])
|
||||
|
||||
module.exports = function (options, keyEncoding) {
|
||||
const result = {}
|
||||
|
||||
for (const k in options) {
|
||||
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.
|
||||
result[k] = keyEncoding.encode(options[k])
|
||||
} else {
|
||||
result[k] = options[k]
|
||||
}
|
||||
}
|
||||
|
||||
result.reverse = !!result.reverse
|
||||
result.limit = Number.isInteger(result.limit) && result.limit >= 0 ? result.limit : -1
|
||||
|
||||
return result
|
||||
}
|
Reference in New Issue
Block a user