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

abstract-nosql

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

abstract-nosql - npm Package Compare versions

Comparing version 1.7.1 to 1.8.0

4

abstract-error.js

@@ -7,10 +7,6 @@ var Errors = require('abstract-object/Error')

var CloseError = createError("CanNotClose", 0x52)
var AlreadyEndError = createError("AlreadyEnd", 0x53)
var AlreadyRunError = createError("AlreadyRun", 0x54)
Errors.OpenError = OpenError
Errors.CloseError = CloseError
Errors.AlreadyEndError = AlreadyEndError
Errors.AlreadyRunError = AlreadyRunError
module.exports = Errors;

@@ -1,227 +0,7 @@

// Generated by CoffeeScript 1.8.0
(function() {
var AbstractError, AbstractIterator, AlreadyEndError, AlreadyRunError, Errors, InvalidArgumentError, NotImplementedError, inherits, isArray, util;
try {
module.exports = require('nosql-stream/lib/abstract-iterator');
} catch(e) {
console.error("type `npm install nosql-stream` to enable the feature.")
throw e
}
util = require("abstract-object/lib/util");
inherits = util.inherits;
isArray = util.isArray;
Errors = require("./abstract-error");
AbstractError = Errors.AbstractError;
NotImplementedError = Errors.NotImplementedError;
InvalidArgumentError = Errors.InvalidArgumentError;
AlreadyEndError = Errors.AlreadyEndError;
AlreadyRunError = Errors.AlreadyRunError;
module.exports = AbstractIterator = (function() {
AbstractIterator.AlreadyEndError = AlreadyEndError;
AbstractIterator.AlreadyRunError = AlreadyRunError;
function AbstractIterator(db, options) {
var isKeysIterator;
this.db = db;
this.options = options;
this._ended = false;
this._nexting = false;
isKeysIterator = options && isArray(options.range);
if (isKeysIterator) {
this._resultOfKeys = options.range;
this._indexOfKeys = -1;
}
return !isKeysIterator;
}
AbstractIterator.prototype._next = function(callback) {
var self;
self = this;
if (this._nextSync) {
return setImmediate(function() {
var e, result;
try {
result = self._nextSync();
self._nexting = false;
if (result) {
return callback(null, result[0], result[1]);
} else {
return callback();
}
} catch (_error) {
e = _error;
self._nexting = false;
return callback(e);
}
});
} else {
return setImmediate(function() {
self._nexting = false;
return callback();
});
}
};
AbstractIterator.prototype._end = function(callback) {
var self;
self = this;
if (this._endSync) {
return setImmediate(function() {
var e, result;
try {
result = self._endSync();
return callback(null, result);
} catch (_error) {
e = _error;
return callback(e);
}
});
} else {
return setImmediate(function() {
return callback();
});
}
};
AbstractIterator.prototype.nextKeysSync = function() {
var result;
this._nexting = true;
if (this._indexOfKeys === -1) {
this._resultOfKeys = this.db._mGetSync(this._resultOfKeys, this.options);
this._indexOfKeys++;
}
result = this._indexOfKeys >= 0 && this._indexOfKeys < this._resultOfKeys.length;
if (result) {
result = {
key: this._resultOfKeys[this._indexOfKeys],
value: this._resultOfKeys[++this._indexOfKeys]
};
this._indexOfKeys++;
}
this._nexting = false;
return result;
};
AbstractIterator.prototype.nextSync = function() {
var result;
if (this._ended) {
throw new AlreadyEndError("cannot call next() after end()");
}
if (this._nexting) {
throw new AlreadyRunError("cannot call next() before previous next() has completed");
}
if (this._indexOfKeys != null) {
return this.nextKeysSync();
} else if (this._nextSync) {
this._nexting = true;
result = this._nextSync();
if (result !== false) {
result = {
key: result[0],
value: result[1]
};
}
this._nexting = false;
return result;
} else {
throw new NotImplementedError();
}
};
AbstractIterator.prototype._endKeys = function() {
delete this._resultOfKeys;
this._indexOfKeys = -2;
return this._ended = true;
};
AbstractIterator.prototype.endSync = function() {
if (this._indexOfKeys != null) {
return this._endKeys();
} else if (this._endSync) {
this._ended = true;
return this._endSync();
} else {
throw new NotImplementedError();
}
};
AbstractIterator.prototype.nextKeys = function(callback) {
var result, self;
this._nexting = true;
if (this._indexOfKeys === -1) {
self = this;
this.db._mGet(this._resultOfKeys, this.options, function(err, arr) {
self._nexting = false;
if (err) {
return callback(err);
}
self._resultOfKeys = arr;
self._indexOfKeys++;
return self.next(callback);
});
return this;
} else if (this._indexOfKeys >= 0 && this._indexOfKeys < this._resultOfKeys.length) {
result = this._resultOfKeys.slice(this._indexOfKeys, this._indexOfKeys += 2);
this._nexting = false;
} else {
result = false;
}
this._nexting = false;
if (result === false) {
callback();
} else {
callback(void 0, result[0], result[1]);
}
return this;
};
AbstractIterator.prototype.next = function(callback) {
var self;
if (typeof callback !== "function") {
throw new InvalidArgumentError("next() requires a callback argument");
}
if (this._ended) {
return callback(new AlreadyEndError("cannot call next() after end()"));
}
if (this._nexting) {
return callback(new AlreadyRunError("cannot call next() before previous next() has completed"));
}
if (this._indexOfKeys != null) {
this.nextKeys(callback);
} else {
this._nexting = true;
self = this;
this._next(function() {
self._nexting = false;
return callback.apply(null, arguments);
});
}
return this;
};
AbstractIterator.prototype.end = function(callback) {
if (typeof callback !== "function") {
throw new InvalidArgumentError("end() requires a callback argument");
}
if (this._ended) {
return callback(new AlreadyEndError("end() already called on iterator"));
}
if (this._indexOfKeys != null) {
this._endKeys();
return setImmediate(callback);
} else {
this._ended = true;
return this._end(callback);
}
};
return AbstractIterator;
})();
}).call(this);

11

package.json
{
"name": "abstract-nosql",
"description": "An abstract prototype for nosql database with sync and streamable (LevelDOWN API)",
"version": "1.7.1",
"version": "1.8.0",
"contributors": [

@@ -49,6 +49,9 @@ "Riceball LEE <snowyu.lee@gmail.com> (https://github.com/snowyu)",

"scripts": {
"test": "node ./test.js"
,"build": "coffee -o . -c src/*.coffee"
"test": "node ./test.js",
"build": "coffee -o . -c src/*.coffee"
},
"license": "MIT"
"license": "MIT",
"optionalDependencies": {
"nosql-stream": "~1.1.0"
}
}

@@ -35,2 +35,3 @@ # Abstract NoSQL Database [![Build Status](https://secure.travis-ci.org/snowyu/node-abstract-nosql.png)](http://travis-ci.org/snowyu/node-abstract-nosql)

- Remove the AbstractIterator to [nosql-stream](https://github.com/snowyu/nosql-stream) package
+ Add the stream ability

@@ -130,10 +131,10 @@ * You should install [nosql-stream](https://github.com/snowyu/nosql-stream) package first to use this feature.

But, you should install the [nosql-stream](https://snowyu/nosql-stream) package first.
But, you should install the [nosql-stream](https://github.com/snowyu/nosql-stream) package first.
npm install nosql-stream
see [nosql-stream](https://snowyu/nosql-stream) for more details
see [nosql-stream](https://snowyu/github.com/nosql-stream) for more details
### AbstractLevelDOWN.keyStream(createKeyStream)
### AbstractNoSql.keyStream(createKeyStream)

@@ -144,3 +145,3 @@ create a readable stream.

### AbstractLevelDOWN.valueStream(createValueStream)
### AbstractNoSql.valueStream(createValueStream)

@@ -151,3 +152,3 @@ create a readable stream.

### AbstractLevelDOWN.readStream(createReadStream)
### AbstractNoSql.readStream(createReadStream)

@@ -158,4 +159,4 @@ create a readable stream.

* AbstractLevelDOWN.readStream([options])
* AbstractLevelDOWN.createReadStream
* AbstractNoSql.readStream([options])
* AbstractNoSql.createReadStream

@@ -302,11 +303,11 @@ __arguments__

### AbstractLevelDOWN(location)
### AbstractNoSql(location)
## Sync Methods
### AbstractLevelDOWN#_isExistsSync(key, options)
### AbstractNoSql#_isExistsSync(key, options)
this is an optional method for performance.
### AbstractLevelDOWN#_mGetSync(keys, options)
### AbstractNoSql#_mGetSync(keys, options)

@@ -324,7 +325,7 @@ this is an optional method for performance.

### AbstractLevelDOWN#_openSync(options)
### AbstractLevelDOWN#_getSync(key, options)
### AbstractLevelDOWN#_putSync(key, value, options)
### AbstractLevelDOWN#_delSync(key, options)
### AbstractLevelDOWN#_batchSync(array, options)
### AbstractNoSql#_openSync(options)
### AbstractNoSql#_getSync(key, options)
### AbstractNoSql#_putSync(key, value, options)
### AbstractNoSql#_delSync(key, options)
### AbstractNoSql#_batchSync(array, options)

@@ -334,7 +335,7 @@

### AbstractLevelDOWN#_isExists(key, options, callback)
### AbstractNoSql#_isExists(key, options, callback)
this is an optional method for performance.
### AbstractLevelDOWN#_mGet(keys, options, callback)
### AbstractNoSql#_mGet(keys, options, callback)

@@ -351,8 +352,8 @@ this is an optional method for performance.

### AbstractLevelDOWN#_open(options, callback)
### AbstractLevelDOWN#_close(callback)
### AbstractLevelDOWN#_get(key, options, callback)
### AbstractLevelDOWN#_put(key, value, options, callback)
### AbstractLevelDOWN#_del(key, options, callback)
### AbstractLevelDOWN#_batch(array, options, callback)
### AbstractNoSql#_open(options, callback)
### AbstractNoSql#_close(callback)
### AbstractNoSql#_get(key, options, callback)
### AbstractNoSql#_put(key, value, options, callback)
### AbstractNoSql#_del(key, options, callback)
### AbstractNoSql#_batch(array, options, callback)

@@ -380,9 +381,9 @@ 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()
### AbstractNoSql#_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)
### AbstractNoSql#_approximateSize(start, end, callback)
### AbstractLevelDOWN#IteratorClass
### AbstractNoSql#IteratorClass

@@ -392,3 +393,3 @@ You can override the `IteratorClass` to your Iterator.

### AbstractLevelDOWN#_iterator(options)
### AbstractNoSql#_iterator(options)

@@ -411,30 +412,5 @@ By default an `iterator()` operation returns a blank `AbstractIterator` object. The prototype is available on the main exports for you to extend. If you want to implement iterator operations then you should extend the `AbstractIterator` and return your object in the `_iterator(options)` method.

### AbstractIterator(db)
Provided with the current instance of `AbstractLevelDOWN` by default.
### Sync methods:
#### AbstractIterator#_nextSync()
__return__
* if any result: return a two elements of array
* the first is the key, the first element could be null or undefined if options.keys is false
* the second is the value, the second element could be null or undefined if options.values is false
* or return false, if no any data yet.
#### AbstractIterator#_endSync()
### Async methods:
#### AbstractIterator#_next(callback)
#### AbstractIterator#_end(callback)
### AbstractChainedBatch
Provided with the current instance of `AbstractLevelDOWN` by default.
Provided with the current instance of `AbstractNoSql` by default.

@@ -455,15 +431,15 @@ ### AbstractChainedBatch#_put(key, value)

var util = require('util')
, AbstractLevelDOWN = require('./').AbstractLevelDOWN
, AbstractNoSql = require('./').AbstractNoSql
// constructor, passes through the 'location' argument to the AbstractLevelDOWN constructor
function FakeLevelDOWN (location) {
AbstractLevelDOWN.call(this, location)
// constructor, passes through the 'location' argument to the AbstractNoSql constructor
function FakeNoSqlDatabase (location) {
AbstractNoSql.call(this, location)
}
// our new prototype inherits from AbstractLevelDOWN
util.inherits(FakeLevelDOWN, AbstractLevelDOWN)
// our new prototype inherits from AbstractNoSql
util.inherits(FakeNoSqlDatabase, AbstractNoSql)
// implement some methods
FakeLevelDOWN.prototype._openSync = function (options) {
FakeNoSqlDatabase.prototype._openSync = function (options) {
this._store = {}

@@ -473,3 +449,3 @@ return true

FakeLevelDOWN.prototype._putSync = function (key, value, options) {
FakeNoSqlDatabase.prototype._putSync = function (key, value, options) {
key = '_' + key // safety, to avoid key='__proto__'-type skullduggery

@@ -481,7 +457,7 @@ this._store[key] = value

//the isExists is an optional method:
FakeLevelDOWN.prototype._isExistsSync = function (key, options) {
FakeNoSqlDatabase.prototype._isExistsSync = function (key, options) {
return this._store.hasOwnProperty('_' + key)
}
FakeLevelDOWN.prototype._getSync = function (key, options) {
FakeNoSqlDatabase.prototype._getSync = function (key, options) {
var value = this._store['_' + key]

@@ -495,3 +471,3 @@ if (value === undefined) {

FakeLevelDOWN.prototype._delSync = function (key, options) {
FakeNoSqlDatabase.prototype._delSync = function (key, options) {
delete this._store['_' + key]

@@ -503,3 +479,3 @@ return true

var db = new FakeLevelDOWN()
var db = new FakeNoSqlDatabase()

@@ -528,3 +504,3 @@ //sync:

// now use it in LevelUP
// Or use it in LevelUP

@@ -535,3 +511,3 @@ var levelup = require('levelup')

// the 'db' option replaces LevelDOWN
db: function (location) { return new FakeLevelDOWN(location) }
db: function (location) { return new FakeNoSqlDatabase(location) }
})

@@ -563,15 +539,15 @@

var util = require('util')
, AbstractLevelDOWN = require('./').AbstractLevelDOWN
, AbstractNoSql = require('./').AbstractNoSql
// constructor, passes through the 'location' argument to the AbstractLevelDOWN constructor
function FakeLevelDOWN (location) {
AbstractLevelDOWN.call(this, location)
// constructor, passes through the 'location' argument to the AbstractNoSql constructor
function FakeNoSqlDatabase (location) {
AbstractNoSql.call(this, location)
}
// our new prototype inherits from AbstractLevelDOWN
util.inherits(FakeLevelDOWN, AbstractLevelDOWN)
// our new prototype inherits from AbstractNoSql
util.inherits(FakeNoSqlDatabase, AbstractNoSql)
// implement some methods
FakeLevelDOWN.prototype._open = function (options, callback) {
FakeNoSqlDatabase.prototype._open = function (options, callback) {
// initialise a memory storage object

@@ -583,3 +559,3 @@ this._store = {}

FakeLevelDOWN.prototype._put = function (key, value, options, callback) {
FakeNoSqlDatabase.prototype._put = function (key, value, options, callback) {
key = '_' + key // safety, to avoid key='__proto__'-type skullduggery

@@ -591,3 +567,3 @@ this._store[key] = value

//the isExists is an optional method:
FakeLevelDOWN.prototype._isExists = function (key, options, callback) {
FakeNoSqlDatabase.prototype._isExists = function (key, options, callback) {
var value = this._store.hasOwnProperty('_' + key)

@@ -599,3 +575,3 @@ process.nextTick(function () {

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

@@ -611,3 +587,3 @@ if (value === undefined) {

FakeLevelDOWN.prototype._del = function (key, options, callback) {
FakeNoSqlDatabase.prototype._del = function (key, options, callback) {
delete this._store['_' + key]

@@ -623,3 +599,3 @@ process.nextTick(callback)

// the 'db' option replaces LevelDOWN
db: function (location) { return new FakeLevelDOWN(location) }
db: function (location) { return new FakeNoSqlDatabase(location) }
})

@@ -626,0 +602,0 @@

@@ -172,3 +172,3 @@ const tap = require('tap')

, expectedCb = function () {}
, expectedOptions = { asBuffer: false }
, expectedOptions = { asBuffer: false, raiseError: true }
, expectedKey = ['a key']

@@ -186,3 +186,3 @@ , test

test = new Test('foobar')
test.get(expectedKey, expectedCb)
test.mGet(expectedKey, expectedCb)

@@ -194,5 +194,5 @@ t.equal(spy.callCount, 1, 'got _mGet() call')

t.deepEqual(spy.getCall(0).args[1], expectedOptions, 'got default options argument')
t.equal(spy.getCall(0).args[2], expectedCb, 'got expected cb argument')
//t.equal(spy.getCall(0).args[2], expectedCb, 'got expected cb argument')
test.get(expectedKey, { options: 1 }, expectedCb)
test.mGet(expectedKey, { options: 1 }, expectedCb)

@@ -206,3 +206,3 @@ expectedOptions.options = 1

t.deepEqual(spy.getCall(1).args[1], expectedOptions, 'got expected options argument')
t.equal(spy.getCall(1).args[2], expectedCb, 'got expected cb argument')
//t.equal(spy.getCall(1).args[2], expectedCb, 'got expected cb argument')
t.end()

@@ -209,0 +209,0 @@ })

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