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.8.2 to 0.9.0

17

abstract-chained-batch.js

@@ -25,3 +25,6 @@ /* Copyright (c) 2013 Rod Vagg, MIT License */

this._operations.push({ type: 'put', key: key, value: value })
if (typeof this._put == 'function' )
this._put(key, value)
else
this._operations.push({ type: 'put', key: key, value: value })

@@ -39,3 +42,6 @@ return this

this._operations.push({ type: 'del', key: key })
if (typeof this._del == 'function' )
this._del(key)
else
this._operations.push({ type: 'del', key: key })

@@ -49,2 +55,6 @@ return this

this._operations = []
if (typeof this._clear == 'function' )
this._clear()
return this

@@ -65,2 +75,5 @@ }

if (typeof this._write == 'function' )
return this._write(callback)
if (typeof this._db._batch == 'function')

@@ -67,0 +80,0 @@ return this._db._batch(this._operations, options, callback)

5

abstract-leveldown.js

@@ -181,3 +181,4 @@ /* Copyright (c) 2013 Rod Vagg, MIT License */

module.exports.AbstractLevelDOWN = AbstractLevelDOWN
module.exports.AbstractIterator = AbstractIterator
module.exports.AbstractLevelDOWN = AbstractLevelDOWN
module.exports.AbstractIterator = AbstractIterator
module.exports.AbstractChainedBatch = AbstractChainedBatch

@@ -86,2 +86,28 @@ var db

})
test('test simultaniously get()', function (t) {
db.put('hello', 'world', function (err) {
var r = 0
, done = function () {
if (++r == 20)
t.end()
}
, i = 0
, j = 0
for (; i < 10; ++i)
db.get('hello', function(err, value) {
t.notOk(err, 'should not error')
t.equal(value.toString(), 'world')
done()
})
for (; j < 10; ++j)
db.get('not found', function(err, value) {
t.ok(err, 'should error')
t.equal(err.message, 'NotFound: ', 'should have correct error message')
done()
})
})
})
}

@@ -88,0 +114,0 @@

{
"name" : "abstract-leveldown"
, "description" : "An abstract prototype matching the LevelDOWN API"
, "version" : "0.8.2"
, "version" : "0.9.0"
, "homepage" : "https://github.com/rvagg/node-abstract-leveldown"

@@ -6,0 +6,0 @@ , "contributors" : [

@@ -92,4 +92,8 @@ # Abstract LevelDOWN [![Build Status](https://secure.travis-ci.org/rvagg/node-abstract-leveldown.png)](http://travis-ci.org/rvagg/node-abstract-leveldown)

Note: At the time of writing, the LevelDOWN `batch()` API is in flux, see the 2.0-wip branch. If `batch()` is called without argument or with only an options object then it should return a `Batch` object with chainable methods. Otherwise it will invoke a classic batch operation.
If `batch()` is called without argument or with only an options object then it should return a `Batch` object with chainable methods. Otherwise it will invoke a classic batch operation.
### AbstractLevelDOWN#_chainedBatch()
By default an `batch()` operation without argument returns a blank `AbstractChainedBatch` object. The prototype is available on the main exports for you to extend. If you want to implement chainable batch operations then you should extend the `AbstractChaindBatch` and return your object in the `_chainedBatch()` method.
### AbstractLevelDOWN#_approximateSize(start, end, callback)

@@ -109,2 +113,10 @@ ### AbstractLevelDOWN#_iterator(options)

### AbstractChainedBatch
Provided with the current instance of `AbstractLevelDOWN` by default.
### AbstractChainedBatch#_put(key, value)
### AbstractChainedBatch#_del(key)
### AbstractChainedBatch#_clear()
### AbstractChainedBatch#_write(options, callback)
<a name="contributing"></a>

@@ -111,0 +123,0 @@ Contributing

@@ -1,7 +0,8 @@

const tap = require('tap')
, sinon = require('sinon')
, util = require('util')
, testCommon = require('./testCommon')
, AbstractLevelDOWN = require('./').AbstractLevelDOWN
, AbstractIterator = require('./').AbstractIterator
const tap = require('tap')
, sinon = require('sinon')
, util = require('util')
, testCommon = require('./testCommon')
, AbstractLevelDOWN = require('./').AbstractLevelDOWN
, AbstractIterator = require('./').AbstractIterator
, AbstractChainedBatch = require('./').AbstractChainedBatch

@@ -19,9 +20,9 @@ function factory (location) {

require('./abstract/del-test').setUp(factory, tap.test, testCommon)
require('./abstract/del-test').args(factory, tap.test, testCommon)
require('./abstract/del-test').args(tap.test)
require('./abstract/get-test').setUp(factory, tap.test, testCommon)
require('./abstract/get-test').args(factory, tap.test, testCommon)
require('./abstract/get-test').args(tap.test)
require('./abstract/put-test').setUp(factory, tap.test, testCommon)
require('./abstract/put-test').args(factory, tap.test, testCommon)
require('./abstract/put-test').args(tap.test)

@@ -36,3 +37,3 @@ require('./abstract/put-get-del-test').setUp(factory, tap.test, testCommon)

require('./abstract/approximate-size-test').setUp(factory, tap.test, testCommon)
require('./abstract/approximate-size-test').args(factory, tap.test, testCommon)
require('./abstract/approximate-size-test').args(tap.test)

@@ -48,4 +49,4 @@ require('./abstract/batch-test').setUp(factory, tap.test, testCommon)

require('./abstract/iterator-test').setUp(factory, tap.test, testCommon)
require('./abstract/iterator-test').args(factory, tap.test, testCommon)
require('./abstract/iterator-test').sequence(factory, tap.test, testCommon)
require('./abstract/iterator-test').args(tap.test)
require('./abstract/iterator-test').sequence(tap.test)

@@ -298,3 +299,3 @@ /*** extensibility ***/

tap.test('test chained batch() extensibility', function (t) {
tap.test('test chained batch() (array) extensibility', function (t) {
var spy = sinon.spy()

@@ -341,2 +342,140 @@ , expectedCb = function () {}

tap.test('test chained batch() (custom _chainedBatch) extensibility', function (t) {
var spy = sinon.spy()
, test
function Test (location) {
AbstractLevelDOWN.call(this, location)
}
util.inherits(Test, AbstractLevelDOWN)
Test.prototype._chainedBatch = spy
test = new Test('foobar')
test.batch()
t.equal(spy.callCount, 1, 'got _chainedBatch() call')
t.equal(spy.getCall(0).thisValue, test, '`this` on _chainedBatch() was correct')
test.batch()
t.equal(spy.callCount, 2, 'got _chainedBatch() call')
t.equal(spy.getCall(1).thisValue, test, '`this` on _chainedBatch() was correct')
t.end()
})
tap.test('test AbstractChainedBatch extensibility', function (t) {
function Test (db) {
AbstractChainedBatch.call(this, db)
t.equal(this._db, db, 'db set on `this`')
t.end()
}
util.inherits(Test, AbstractChainedBatch)
new Test('foobar')
})
tap.test('test write() extensibility', function (t) {
var spy = sinon.spy()
, spycb = sinon.spy()
, test
function Test (db) {
AbstractChainedBatch.call(this, db)
}
util.inherits(Test, AbstractChainedBatch)
Test.prototype._write = spy
test = new Test('foobar')
test.write(spycb)
t.equal(spy.callCount, 1, 'got _write() call')
t.equal(spy.getCall(0).thisValue, test, '`this` on _write() was correct')
t.equal(spy.getCall(0).args.length, 1, 'got one argument')
// awkward here cause of nextTick & an internal wrapped cb
t.type(spy.getCall(0).args[0], 'function', 'got a callback function')
t.equal(spycb.callCount, 0, 'spycb not called')
spy.getCall(0).args[0]()
t.equal(spycb.callCount, 1, 'spycb called, i.e. was our cb argument')
t.end()
})
tap.test('test put() extensibility', function (t) {
var spy = sinon.spy()
, expectedKey = 'key'
, expectedValue = 'value'
, returnValue
, test
function Test (db) {
AbstractChainedBatch.call(this, db)
}
util.inherits(Test, AbstractChainedBatch)
Test.prototype._put = spy
test = new Test(factory('foobar'))
returnValue = test.put(expectedKey, expectedValue)
t.equal(spy.callCount, 1, 'got _put call')
t.equal(spy.getCall(0).thisValue, test, '`this` on _put() was correct')
t.equal(spy.getCall(0).args.length, 2, 'got two arguments')
t.equal(spy.getCall(0).args[0], expectedKey, 'got expected key argument')
t.equal(spy.getCall(0).args[1], expectedValue, 'got expected value argument')
t.equal(returnValue, test, 'get expected return value')
t.end()
})
tap.test('test del() extensibility', function (t) {
var spy = sinon.spy()
, expectedKey = 'key'
, returnValue
, test
function Test (db) {
AbstractChainedBatch.call(this, db)
}
util.inherits(Test, AbstractChainedBatch)
Test.prototype._del = spy
test = new Test(factory('foobar'))
returnValue = test.del(expectedKey)
t.equal(spy.callCount, 1, 'got _del call')
t.equal(spy.getCall(0).thisValue, test, '`this` on _del() was correct')
t.equal(spy.getCall(0).args.length, 1, 'got one argument')
t.equal(spy.getCall(0).args[0], expectedKey, 'got expected key argument')
t.equal(returnValue, test, 'get expected return value')
t.end()
})
tap.test('test clear() extensibility', function (t) {
var spy = sinon.spy()
, returnValue
, test
function Test (db) {
AbstractChainedBatch.call(this, db)
}
util.inherits(Test, AbstractChainedBatch)
Test.prototype._clear = spy
test = new Test(factory('foobar'))
returnValue = test.clear()
t.equal(spy.callCount, 1, 'got _clear call')
t.equal(spy.getCall(0).thisValue, test, '`this` on _clear() was correct')
t.equal(spy.getCall(0).args.length, 0, 'got zero arguments')
t.equal(returnValue, test, 'get expected return value')
t.end()
})
tap.test('test iterator() extensibility', function (t) {

@@ -343,0 +482,0 @@ var spy = sinon.spy()

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