abstract-leveldown
Advanced tools
Comparing version 1.0.0 to 2.0.0
@@ -17,6 +17,5 @@ /* Copyright (c) 2013 Rod Vagg, MIT License */ | ||
var err = this._db._checkKeyValue(key, 'key', this._db._isBuffer) | ||
if (err) throw err | ||
err = this._db._checkKeyValue(value, 'value', this._db._isBuffer) | ||
if (err) throw err | ||
var err = this._db._checkKey(key, 'key', this._db._isBuffer) | ||
if (err) | ||
throw err | ||
@@ -37,3 +36,3 @@ if (!this._db._isBuffer(key)) key = String(key) | ||
var err = this._db._checkKeyValue(key, 'key', this._db._isBuffer) | ||
var err = this._db._checkKey(key, 'key', this._db._isBuffer) | ||
if (err) throw err | ||
@@ -40,0 +39,0 @@ |
@@ -52,3 +52,3 @@ /* Copyright (c) 2013 Rod Vagg, MIT License */ | ||
if (err = this._checkKeyValue(key, 'key', this._isBuffer)) | ||
if (err = this._checkKey(key, 'key', this._isBuffer)) | ||
return callback(err) | ||
@@ -77,8 +77,5 @@ | ||
if (err = this._checkKeyValue(key, 'key', this._isBuffer)) | ||
if (err = this._checkKey(key, 'key', this._isBuffer)) | ||
return callback(err) | ||
if (err = this._checkKeyValue(value, 'value', this._isBuffer)) | ||
return callback(err) | ||
if (!this._isBuffer(key)) | ||
@@ -89,3 +86,3 @@ key = String(key) | ||
// (indexeddb can store any JS type) | ||
if (!this._isBuffer(value) && !process.browser) | ||
if (value != null && !this._isBuffer(value) && !process.browser) | ||
value = String(value) | ||
@@ -111,3 +108,3 @@ | ||
if (err = this._checkKeyValue(key, 'key', this._isBuffer)) | ||
if (err = this._checkKey(key, 'key', this._isBuffer)) | ||
return callback(err) | ||
@@ -156,12 +153,7 @@ | ||
if (err = this._checkKeyValue(e.type, 'type', this._isBuffer)) | ||
if (err = this._checkKey(e.type, 'type', this._isBuffer)) | ||
return callback(err) | ||
if (err = this._checkKeyValue(e.key, 'key', this._isBuffer)) | ||
if (err = this._checkKey(e.key, 'key', this._isBuffer)) | ||
return callback(err) | ||
if (e.type == 'put') { | ||
if (err = this._checkKeyValue(e.value, 'value', this._isBuffer)) | ||
return callback(err) | ||
} | ||
} | ||
@@ -242,3 +234,3 @@ | ||
AbstractLevelDOWN.prototype._checkKeyValue = function (obj, type) { | ||
AbstractLevelDOWN.prototype._checkKey = function (obj, type) { | ||
@@ -245,0 +237,0 @@ if (obj === null || obj === undefined) |
@@ -21,3 +21,3 @@ var db | ||
db.batch([{ type: 'put', key: 'foo1' }], function (err) { | ||
t.equal(err.message, 'value cannot be `null` or `undefined`', 'correct error message') | ||
t.notOk(err, 'no error') | ||
t.end() | ||
@@ -29,3 +29,3 @@ }) | ||
db.batch([{ type: 'put', key: 'foo1', value: null }], function (err) { | ||
t.equal(err.message, 'value cannot be `null` or `undefined`', 'correct error message') | ||
t.notOk(err, 'no error') | ||
t.end() | ||
@@ -37,2 +37,3 @@ }) | ||
db.batch([{ type: 'put', value: 'foo1' }], function (err) { | ||
t.ok(err, 'got error') | ||
t.equal(err.message, 'key cannot be `null` or `undefined`', 'correct error message') | ||
@@ -45,2 +46,3 @@ t.end() | ||
db.batch([{ type: 'put', key: null, value: 'foo1' }], function (err) { | ||
t.ok(err, 'got error') | ||
t.equal(err.message, 'key cannot be `null` or `undefined`', 'correct error message') | ||
@@ -53,2 +55,3 @@ t.end() | ||
db.batch([{ type: 'put' }], function (err) { | ||
t.ok(err, 'got error') | ||
t.equal(err.message, 'key cannot be `null` or `undefined`', 'correct error message') | ||
@@ -61,2 +64,3 @@ t.end() | ||
db.batch(function (err) { | ||
t.ok(err, 'got error') | ||
t.equal(err.message, 'batch(array) requires an array argument', 'correct error message') | ||
@@ -69,2 +73,3 @@ t.end() | ||
db.batch(void 0, function (err) { | ||
t.ok(err, 'got error') | ||
t.equal(err.message, 'batch(array) requires an array argument', 'correct error message') | ||
@@ -77,2 +82,3 @@ t.end() | ||
db.batch(null, function (err) { | ||
t.ok(err, 'got error') | ||
t.equal(err.message, 'batch(array) requires an array argument', 'correct error message') | ||
@@ -79,0 +85,0 @@ t.end() |
@@ -13,9 +13,3 @@ var db | ||
test('test batch#put() with missing `value`', function (t) { | ||
try { | ||
db.batch().put('foo1') | ||
} catch (err) { | ||
t.equal(err.message, 'value cannot be `null` or `undefined`', 'correct error message') | ||
return t.end() | ||
} | ||
t.fail('should have thrown') | ||
db.batch().put('foo1') | ||
t.end() | ||
@@ -25,9 +19,3 @@ }) | ||
test('test batch#put() with null `value`', function (t) { | ||
try { | ||
db.batch().put('foo1', null) | ||
} catch (err) { | ||
t.equal(err.message, 'value cannot be `null` or `undefined`', 'correct error message') | ||
return t.end() | ||
} | ||
t.fail('should have thrown') | ||
db.batch().put('foo1', null) | ||
t.end() | ||
@@ -34,0 +22,0 @@ }) |
@@ -8,3 +8,2 @@ /**** SETUP & UTILITY STUFF ****/ | ||
, verifyNotFoundError = require('./util').verifyNotFoundError | ||
, isTypedArray = require('./util').isTypedArray | ||
@@ -42,14 +41,22 @@ function makeGetDelErrorTests (type, key, expectedError) { | ||
function makePutGetDelSuccessfulTest (type, key, value) { | ||
function makePutGetDelSuccessfulTest (type, key, value, expectedResult) { | ||
var hasExpectedResult = arguments.length == 4 | ||
test('test put()/get()/del() with ' + type, function (t) { | ||
db.put(key, value, function (err) { | ||
t.notOk(err, 'no error') | ||
t.error(err) | ||
db.get(key, function (err, _value) { | ||
t.notOk(err, 'no error, has key/value for `' + key + '`') | ||
t.notOk(err, 'no error, has key/value for `' + type + '`') | ||
t.ok(Buffer.isBuffer(_value), 'is a Buffer') | ||
var result = _value.toString() | ||
value = value.toString() | ||
t.equals(result, value) | ||
var result = _value | ||
if (hasExpectedResult) { | ||
t.ok(result === expectedResult, 'got `' + expectedResult + '`') | ||
} else { | ||
if (result != null) | ||
result = _value.toString() | ||
if (value != null) | ||
value = value.toString() | ||
t.equals(result, value) | ||
} | ||
db.del(key, function (err) { | ||
t.notOk(err, 'no error, deleted key/value for `' + key + '`') | ||
t.notOk(err, 'no error, deleted key/value for `' + type + '`') | ||
db.get(key, function (err, value) { | ||
@@ -85,3 +92,4 @@ t.ok(err, 'entry propertly deleted') | ||
module.exports.errorKeys = function (testFunc, BufferType) { | ||
if (!BufferType) BufferType = Buffer | ||
if (!BufferType) | ||
BufferType = Buffer | ||
test = testFunc | ||
@@ -122,13 +130,7 @@ makeErrorKeyTest('null key', null, /key cannot be `null` or `undefined`/) | ||
module.exports.errorValues = function (testFunc, BufferType) { | ||
if (!BufferType) BufferType = Buffer | ||
test = testFunc | ||
makePutErrorTest('null value', 'foo', null, /value cannot be `null` or `undefined`/) | ||
makePutErrorTest('undefined value', 'foo', undefined, /value cannot be `null` or `undefined`/) | ||
makePutErrorTest('empty String value', 'foo', '', /value cannot be an empty String/) | ||
makePutErrorTest('empty Buffer value', 'foo', new BufferType(0), /value cannot be an empty \w*Buffer/) | ||
makePutErrorTest('empty Array value', 'foo', [], /value cannot be an empty String/) | ||
module.exports.errorValues = function () { | ||
} | ||
module.exports.nonErrorKeys = function (testFunc) { | ||
module.exports.nonErrorValues = function (testFunc, BufferType) { | ||
if (!BufferType) BufferType = Buffer | ||
// valid falsey values | ||
@@ -140,2 +142,10 @@ test = testFunc | ||
// all of the following result in an empty-string value: | ||
makePutGetDelSuccessfulTest('`null` value', 'foo null', null, '') | ||
makePutGetDelSuccessfulTest('`undefined` value', 'foo undefined', undefined, '') | ||
makePutGetDelSuccessfulTest('empty String value', 'foo', '', '') | ||
makePutGetDelSuccessfulTest('empty Buffer value', 'foo', new BufferType(0), '') | ||
makePutGetDelSuccessfulTest('empty Array value', 'foo', [], '') | ||
// standard String value | ||
@@ -142,0 +152,0 @@ makePutGetDelSuccessfulTest( |
{ | ||
"name": "abstract-leveldown", | ||
"description": "An abstract prototype matching the LevelDOWN API", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"contributors": [ | ||
@@ -6,0 +6,0 @@ "Rod Vagg <r@va.gg> (https://github.com/rvagg)", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
114053
2611