Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

abstract-leveldown

Package Overview
Dependencies
Maintainers
1
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

abstract-leveldown - npm Package Compare versions

Comparing version 0.10.2 to 0.11.0

133

abstract-leveldown.js
/* Copyright (c) 2013 Rod Vagg, MIT License */
var AbstractIterator = require('./abstract-iterator')
var xtend = require('xtend')
, AbstractIterator = require('./abstract-iterator')
, AbstractChainedBatch = require('./abstract-chained-batch')

@@ -19,4 +20,6 @@

callback = options
if (typeof callback != 'function')
throw new Error('open() requires a callback argument')
if (typeof options != 'object')

@@ -42,15 +45,21 @@ options = {}

AbstractLevelDOWN.prototype.get = function (key, options, callback) {
var self = this
var err
if (typeof options == 'function')
callback = options
if (typeof callback != 'function')
throw new Error('get() requires a callback argument')
var err = self._checkKeyValue(key, 'key', self._isBuffer)
if (err) return callback(err)
if (!self._isBuffer(key)) key = String(key)
if (err = this._checkKeyValue(key, 'key', this._isBuffer))
return callback(err)
if (!this._isBuffer(key))
key = String(key)
if (typeof options != 'object')
options = {}
if (typeof self._get == 'function')
return self._get(key, options, callback)
if (typeof this._get == 'function')
return this._get(key, options, callback)

@@ -61,16 +70,27 @@ process.nextTick(function () { callback(new Error('NotFound')) })

AbstractLevelDOWN.prototype.put = function (key, value, options, callback) {
var err
if (typeof options == 'function')
callback = options
if (typeof callback != 'function')
throw new Error('put() requires a callback argument')
var err = this._checkKeyValue(key, 'key', this._isBuffer)
if (err) return callback(err)
err = this._checkKeyValue(value, 'value', this._isBuffer)
if (err) return callback(err)
if (!this._isBuffer(key)) key = String(key)
// coerce value to string in node, dont touch it in browser
if (err = this._checkKeyValue(key, 'key', this._isBuffer))
return callback(err)
if (err = this._checkKeyValue(value, 'value', this._isBuffer))
return callback(err)
if (!this._isBuffer(key))
key = String(key)
// coerce value to string in node, don't touch it in browser
// (indexeddb can store any JS type)
if (!this._isBuffer(value) && !process.browser) value = String(value)
if (!this._isBuffer(value) && !process.browser)
value = String(value)
if (typeof options != 'object')
options = {}
if (typeof this._put == 'function')

@@ -83,13 +103,19 @@ return this._put(key, value, options, callback)

AbstractLevelDOWN.prototype.del = function (key, options, callback) {
var err
if (typeof options == 'function')
callback = options
if (typeof callback != 'function')
throw new Error('del() requires a callback argument')
var err = this._checkKeyValue(key, 'key', this._isBuffer)
if (err) return callback(err)
if (!this._isBuffer(key)) key = String(key)
if (err = this._checkKeyValue(key, 'key', this._isBuffer))
return callback(err)
if (!this._isBuffer(key))
key = String(key)
if (typeof options != 'object')
options = {}
if (typeof this._del == 'function')

@@ -107,6 +133,9 @@ return this._del(key, options, callback)

callback = options
if (typeof callback != 'function')
throw new Error('batch(array) requires a callback argument')
if (!Array.isArray(array))
return callback(new Error('batch(array) requires an array argument'))
if (typeof options != 'object')

@@ -122,13 +151,14 @@ options = {}

e = array[i]
if (typeof e != 'object') continue;
if (typeof e != 'object')
continue
err = this._checkKeyValue(e.type, 'type', this._isBuffer)
if (err) return callback(err)
if (err = this._checkKeyValue(e.type, 'type', this._isBuffer))
return callback(err)
err = this._checkKeyValue(e.key, 'key', this._isBuffer)
if (err) return callback(err)
if (err = this._checkKeyValue(e.key, 'key', this._isBuffer))
return callback(err)
if (e.type == 'put') {
err = this._checkKeyValue(e.value, 'value', this._isBuffer)
if (err) return callback(err)
if (err = this._checkKeyValue(e.value, 'value', this._isBuffer))
return callback(err)
}

@@ -143,16 +173,57 @@ }

//TODO: remove from here, not a necessary primitive
AbstractLevelDOWN.prototype.approximateSize = function (start, end, callback) {
if (start == null || end == null || typeof start == 'function' || typeof end == 'function')
if ( start == null
|| end == null
|| typeof start == 'function'
|| typeof end == 'function') {
throw new Error('approximateSize() requires valid `start`, `end` and `callback` arguments')
}
if (typeof callback != 'function')
throw new Error('approximateSize() requires a callback argument')
if (!this._isBuffer(start)) start = String(start)
if (!this._isBuffer(end)) end = String(end)
if (!this._isBuffer(start))
start = String(start)
if (!this._isBuffer(end))
end = String(end)
if (typeof this._approximateSize == 'function')
return this._approximateSize(start, end, callback)
process.nextTick(function () { callback(null, 0) })
process.nextTick(function () {
callback(null, 0)
})
}
AbstractLevelDOWN.prototype._setupIteratorOptions = function (options) {
var self = this
options = xtend(options)
;[ 'start', 'end', 'gt', 'gte', 'lt', 'lte' ].forEach(function (o) {
if (options[o] && self._isBuffer(options[o]) && options[o].length === 0)
delete options[o]
})
options.reverse = !!options.reverse
// fix `start` so it takes into account gt, gte, lt, lte as appropriate
if (options.reverse && options.lt)
options.start = options.lt
if (options.reverse && options.lte)
options.start = options.lte
if (!options.reverse && options.gt)
options.start = options.gt
if (!options.reverse && options.gte)
options.start = options.gte
if ((options.reverse && options.lt && !options.lte)
|| (!options.reverse && options.gt && !options.gte))
options.exclusiveStart = true // start should *not* include matching key
return options
}
AbstractLevelDOWN.prototype.iterator = function (options) {

@@ -162,2 +233,4 @@ if (typeof options != 'object')

options = this._setupIteratorOptions(options)
if (typeof this._iterator == 'function')

@@ -180,4 +253,6 @@ return this._iterator(options)

return new Error(type + ' cannot be `null` or `undefined`')
if (obj === null || obj === undefined)
return new Error(type + ' cannot be `null` or `undefined`')
if (this._isBuffer(obj)) {

@@ -184,0 +259,0 @@ if (obj.length === 0)

@@ -0,1 +1,4 @@

### 0.11.0 - Oct 14 2013
* Introduce _setupIteratorOptions() method to fix options object prior to _iterator() call; makes working with gt/gte/lt/lte options a little easier (@rvagg)
### 0.10.2 - Sep 6 2013

@@ -2,0 +5,0 @@

{
"name" : "abstract-leveldown"
, "description" : "An abstract prototype matching the LevelDOWN API"
, "version" : "0.10.2"
, "version" : "0.11.0"
, "contributors" : [

@@ -27,3 +27,5 @@ "Rod Vagg <r@va.gg> (https://github.com/rvagg)"

, "main" : "./abstract-leveldown.js"
, "dependencies" : {}
, "dependencies" : {
"xtend" : "~2.1.1"
}
, "devDependencies" : {

@@ -30,0 +32,0 @@ "tap" : "*"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc