[Pkg-javascript-commits] [node-abstract-leveldown] 01/05: Imported Upstream version 2.4.1

Felipe Sateler fsateler at moszumanska.debian.org
Sun Oct 11 15:37:36 UTC 2015


This is an automated email from the git hooks/post-receive script.

fsateler pushed a commit to branch master
in repository node-abstract-leveldown.

commit 04d1ff0885af9f79e91a5cac43ff692162120901
Author: Felipe Sateler <fsateler at debian.org>
Date:   Sun Oct 11 11:57:32 2015 -0300

    Imported Upstream version 2.4.1
---
 CHANGELOG.md                 |  67 ++++++++++++++++++
 CONTRIBUTING.md              |  27 -------
 README.md                    |  35 +++-------
 abstract-leveldown.js        |  47 ++++++++++---
 abstract/put-get-del-test.js |   4 +-
 index.js                     |   4 ++
 is-leveldown.js              |  14 ++++
 package.json                 |   4 +-
 test.js                      | 163 ++++++++++++++++++++++++++++++++++++++++---
 9 files changed, 287 insertions(+), 78 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index dece6b0..b61f7f9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,70 @@
+### 2.3.1 - May 18 2015
+
+ * [[`393c781629`](https://github.com/level/abstract-leveldown/commit/393c781629)] - document isLevelDown() (Lars-Magnus Skog)
+ * [[`fd899c49b9`](https://github.com/level/abstract-leveldown/commit/fd899c49b9)] - link to level/community (Lars-Magnus Skog)
+
+### 2.3.0 - May 18 2015
+
+ * [[`9a976428e2`](https://github.com/level/abstract-leveldown/commit/9a976428e2)] - export from index.js and factor out into is-leveldown.js (Lars-Magnus Skog)
+ * [[`8051f8f16c`](https://github.com/level/abstract-leveldown/commit/8051f8f16c)] - add isLevelDOWN() f
+unction (Lars-Magnus Skog)
+
+### 2.2.2 - May 13 2015
+
+ * [[`4ff0a9bfbb`](https://github.com/level/abstract-leveldown/commit/4ff0a9bfbb)] - ***Revert*** "Merge pull request #60 from ralphtheninja/empty-location" (Julian Gruber)
+ * [[`fab11e9e3b`](https://github.com/level/abstract-leveldown/commit/fab11e9e3b)] - use t.equal instead of t.ok(a === b) (Julian Gruber)
+
+### 2.2.1 - May 12 2015
+
+ * [[`f5051090e4`](https://github.com/level/abstract-leveldown/commit/f5051090e4)] - merge location string checks into one if-statement (Lars-Magnus Skog)
+ * [[`cd362b2b9f`](https://github.com/level/abstract-leveldown/commit/cd362b2b9f)] - empty location string throws (Lars-Magnus Skog)
+ * [[`e6d1cb80ea`](https://github.com/level/abstract-leveldown/commit/e6d1cb80ea)] - .throws is different for tape (Lars-Magnus Skog)
+ * [[`a6f29b62fa`](https://github.com/level/abstract-leveldown/commit/a6f29b62fa)] - copy paste error gave wrong test description (Lars-Magnus Skog)
+
+### 2.2.0 - May 10 2015
+
+ * [[`aa867b3760`](https://github.com/level/abstract-leveldown/commit/aa867b3760)] - Merge pull request #58 from Level/add/put-sync (Julian Gruber)
+ * [[`234de997bb`](https://github.com/level/abstract-leveldown/commit/234de997bb)] - add sync put tests (Julian Gruber)
+
+### 2.1.4 - Apr 28 2015
+
+ * [[`969116d00f`](https://github.com/level/abstract-leveldown/commit/969116d00f)] - use t.equal() with tape (Lars-Magnus Skog)
+
+### 2.1.3 - Apr 28 2015
+
+ * [[`68096e78cd`](https://github.com/level/abstract-leveldown/commit/68096e78cd)] - change from tap to tape (Lars-Magnus Skog)
+
+### 2.1.2 - Apr 27 2015
+
+ * [[`d79c060c9d`](https://github.com/level/abstract-leveldown/commit/d79c060c9d)] - convert buffer to string so we can compare (Lars-Magnus Skog)
+
+### 2.1.1 - Apr 27 2015
+
+ * [[`3881fc4290`](https://github.com/level/abstract-leveldown/commit/3881fc4290)] - **travis**: update npm so 0.8 works, add 0.12 and iojs (Lars-Magnus Skog)
+ * [[`9f451e8f74`](https://github.com/level/abstract-leveldown/commit/9f451e8f74)] - rvagg/node- -> level/ (Lars-Magnus Skog)
+ * [[`ecd41a72db`](https://github.com/level/abstract-leveldown/commit/ecd41a72db)] - fix typo (Hao-kang Den)
+ * [[`20e91fd234`](https://github.com/level/abstract-leveldown/commit/20e91fd234)] - update logo and copyright (Lars-Magnus Skog)
+ * [[`6ccf134874`](https://github.com/level/abstract-leveldown/commit/6ccf134874)] - added @watson to package.json (Rod Vagg)
+
+### 2.1.0 - Nov 9 2014
+
+ * [[`7451cd15e6`](https://github.com/level/abstract-leveldown/commit/7451cd15e6)] - added @watson (Rod Vagg)
+ * [[`f4a3346da7`](https://github.com/level/abstract-leveldown/commit/f4a3346da7)] - Use `error` test function when testing for errors (Thomas Watson Steen)
+ * [[`24668c50e0`](https://github.com/level/abstract-leveldown/commit/24668c50e0)] - Don't fail if no value is returned by _get (Thomas Watson Steen)
+ * [[`865ed9e777`](https://github.com/level/abstract-leveldown/commit/865ed9e777)] - Use `setTimeout` instead of `setImmediate`. (Alan Gutierrez)
+ * [[`9e9069faed`](https://github.com/level/abstract-leveldown/commit/9e9069faed)] - 2.0.3 (Rod Vagg)
+
+### 2.0.3 - Oct 2 2014
+
+ * [[`78052c53eb`](https://github.com/level/abstract-leveldown/commit/78052c53eb)] - add test for atomic batch operations (Calvin Metcalf)
+
+### 2.0.1 - Sep 1 2014
+
+ * [[`a0b36f6a18`](https://github.com/level/abstract-leveldown/commit/a0b36f6a18)] - Remove default options that's too LevelDOWN specific (Thomas Watson Steen)
+ * [[`1d97993d0b`](https://github.com/level/abstract-leveldown/commit/1d97993d0b)] - Allow boolean options to be falsy/truthy (Thomas Watson Steen)
+ * [[`fb3cf56da5`](https://github.com/level/abstract-leveldown/commit/fb3cf56da5)] - Set defaults for open, get, put, del and batch options (Thomas Watson Steen)
+ * [[`5c2a629e2b`](https://github.com/level/abstract-leveldown/commit/5c2a629e2b)] - Update pattern for setting default options for the iterator (Thomas Watson Steen)
+
 ### 2.0.0 - Aug 26 2014
  * Lots of stuff between 0.11.1 and now, omitted updating changelog
  * Switch to allowing writes of empty values: null, undefined, '', []
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
deleted file mode 100644
index 2641fd0..0000000
--- a/CONTRIBUTING.md
+++ /dev/null
@@ -1,27 +0,0 @@
-# LevelUP is an OPEN Open Source Project
-
------------------------------------------
-
-## What?
-
-Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.
-
-## Rules
-
-There are a few basic ground-rules for contributors:
-
-1. **No `--force` pushes** or modifying the Git history in any way.
-1. **Non-master branches** ought to be used for ongoing work.
-1. **External API changes and significant modifications** ought to be subject to an **internal pull-request** to solicit feedback from other contributors.
-1. Internal pull-requests to solicit feedback are *encouraged* for any other non-trivial contribution but left to the discretion of the contributor.
-1. Contributors should attempt to adhere to the prevailing code-style.
-
-## Releases
-
-Declaring formal releases remains the prerogative of the project maintainer.
-
-## Changes to this arrangement
-
-This is an experiment and feedback is welcome! This document may also be subject to pull-requests or changes by contributors where you believe you have something valuable to add or change.
-
------------------------------------------
diff --git a/README.md b/README.md
index 670d99d..e54847e 100644
--- a/README.md
+++ b/README.md
@@ -122,41 +122,24 @@ Provided with the current instance of `AbstractLevelDOWN` by default.
 ### AbstractChainedBatch#_clear()
 ### AbstractChainedBatch#_write(options, callback)
 
+### isLevelDown(db)
+
+Returns `true` if `db` has the same public api as `AbstractLevelDOWN`, otherwise `false`. This is a utility function and it's not part of the extensible api.
+
 <a name="contributing"></a>
 Contributing
 ------------
 
-Abstract LevelDOWN is an **OPEN Open Source Project**. This means that:
+AbstractLevelDOWN is an **OPEN Open Source Project**. This means that:
 
 > Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.
 
-See the [CONTRIBUTING.md](https://github.com/level/levelup/blob/master/CONTRIBUTING.md) file for more details.
-
-### Contributors
-
-Abstract LevelDOWN is only possible due to the excellent work of the following contributors:
-
-<table><tbody>
-<tr><th align="left">Rod Vagg</th><td><a href="https://github.com/rvagg">GitHub/rvagg</a></td><td><a href="http://twitter.com/rvagg">Twitter/@rvagg</a></td></tr>
-<tr><th align="left">John Chesley</th><td><a href="https://github.com/chesles/">GitHub/chesles</a></td><td><a href="http://twitter.com/chesles">Twitter/@chesles</a></td></tr>
-<tr><th align="left">Jake Verbaten</th><td><a href="https://github.com/raynos">GitHub/raynos</a></td><td><a href="http://twitter.com/raynos2">Twitter/@raynos2</a></td></tr>
-<tr><th align="left">Dominic Tarr</th><td><a href="https://github.com/dominictarr">GitHub/dominictarr</a></td><td><a href="http://twitter.com/dominictarr">Twitter/@dominictarr</a></td></tr>
-<tr><th align="left">Max Ogden</th><td><a href="https://github.com/maxogden">GitHub/maxogden</a></td><td><a href="http://twitter.com/maxogden">Twitter/@maxogden</a></td></tr>
-<tr><th align="left">Lars-Magnus Skog</th><td><a href="https://github.com/ralphtheninja">GitHub/ralphtheninja</a></td><td><a href="http://twitter.com/ralphtheninja">Twitter/@ralphtheninja</a></td></tr>
-<tr><th align="left">David Björklund</th><td><a href="https://github.com/kesla">GitHub/kesla</a></td><td><a href="http://twitter.com/david_bjorklund">Twitter/@david_bjorklund</a></td></tr>
-<tr><th align="left">Julian Gruber</th><td><a href="https://github.com/juliangruber">GitHub/juliangruber</a></td><td><a href="http://twitter.com/juliangruber">Twitter/@juliangruber</a></td></tr>
-<tr><th align="left">Paolo Fragomeni</th><td><a href="https://github.com/hij1nx">GitHub/hij1nx</a></td><td><a href="http://twitter.com/hij1nx">Twitter/@hij1nx</a></td></tr>
-<tr><th align="left">Anton Whalley</th><td><a href="https://github.com/No9">GitHub/No9</a></td><td><a href="https://twitter.com/antonwhalley">Twitter/@antonwhalley</a></td></tr>
-<tr><th align="left">Matteo Collina</th><td><a href="https://github.com/mcollina">GitHub/mcollina</a></td><td><a href="https://twitter.com/matteocollina">Twitter/@matteocollina</a></td></tr>
-<tr><th align="left">Pedro Teixeira</th><td><a href="https://github.com/pgte">GitHub/pgte</a></td><td><a href="https://twitter.com/pgte">Twitter/@pgte</a></td></tr>
-<tr><th align="left">James Halliday</th><td><a href="https://github.com/substack">GitHub/substack</a></td><td><a href="https://twitter.com/substack">Twitter/@substack</a></td></tr>
-<tr><th align="left">Thomas Watson Steen</th><td><a href="https://github.com/watson">GitHub/watson</a></td><td><a href="https://twitter.com/wa7son">Twitter/@wa7son</a></td></tr>
-</tbody></table>
+See the [contribution guide](https://github.com/Level/community/blob/master/CONTRIBUTING.md) for more details.
 
 <a name="license"></a>
-License & copyright
+License & Copyright
 -------------------
 
-Copyright (c) 2012-2015 Abstract LevelDOWN contributors (listed above).
+Copyright © 2012-2015 **AbstractLevelDOWN** [contributors](https://github.com/level/community#contributors).
 
-Abstract LevelDOWN is licensed under the MIT license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE.md file for more details.
+**AbstractLevelDOWN** is licensed under the MIT license. All rights not explicitly granted in the MIT license are reserved. See the included `LICENSE.md` file for more details.
diff --git a/abstract-leveldown.js b/abstract-leveldown.js
index 7936fae..fce3e2c 100644
--- a/abstract-leveldown.js
+++ b/abstract-leveldown.js
@@ -12,9 +12,13 @@ function AbstractLevelDOWN (location) {
     throw new Error('constructor requires a location string argument')
 
   this.location = location
+  this.status = 'new'
 }
 
 AbstractLevelDOWN.prototype.open = function (options, callback) {
+  var self      = this
+    , oldStatus = this.status
+
   if (typeof options == 'function')
     callback = options
 
@@ -27,20 +31,43 @@ AbstractLevelDOWN.prototype.open = function (options, callback) {
   options.createIfMissing = options.createIfMissing != false
   options.errorIfExists = !!options.errorIfExists
 
-  if (typeof this._open == 'function')
-    return this._open(options, callback)
-
-  process.nextTick(callback)
+  if (typeof this._open == 'function') {
+    this.status = 'opening'
+    this._open(options, function (err) {
+      if (err) {
+        self.status = oldStatus
+        return callback(err)
+      }
+      self.status = 'open'
+      callback()
+    })
+  } else {
+    this.status = 'open'
+    process.nextTick(callback)
+  }
 }
 
 AbstractLevelDOWN.prototype.close = function (callback) {
+  var self      = this
+    , oldStatus = this.status
+
   if (typeof callback != 'function')
     throw new Error('close() requires a callback argument')
 
-  if (typeof this._close == 'function')
-    return this._close(callback)
-
-  process.nextTick(callback)
+  if (typeof this._close == 'function') {
+    this.status = 'closing'
+    this._close(function (err) {
+      if (err) {
+        self.status = oldStatus
+        return callback(err)
+      }
+      self.status = 'closed'
+      callback()
+    })
+  } else {
+    this.status = 'closed'
+    process.nextTick(callback)
+  }
 }
 
 AbstractLevelDOWN.prototype.get = function (key, options, callback) {
@@ -242,6 +269,4 @@ AbstractLevelDOWN.prototype._checkKey = function (obj, type) {
     return new Error(type + ' cannot be an empty String')
 }
 
-module.exports.AbstractLevelDOWN    = AbstractLevelDOWN
-module.exports.AbstractIterator     = AbstractIterator
-module.exports.AbstractChainedBatch = AbstractChainedBatch
+module.exports = AbstractLevelDOWN
diff --git a/abstract/put-get-del-test.js b/abstract/put-get-del-test.js
index 843d8fd..28a9023 100644
--- a/abstract/put-get-del-test.js
+++ b/abstract/put-get-del-test.js
@@ -47,7 +47,7 @@ function makePutGetDelSuccessfulTest (type, key, value, expectedResult) {
         t.ok(Buffer.isBuffer(_value), 'is a Buffer')
         var result = _value
         if (hasExpectedResult) {
-          t.ok(result.toString() === expectedResult, 'got `' + expectedResult + '`')
+          t.equal(result.toString(), expectedResult)
         } else {
           if (result != null)
             result = _value.toString()
@@ -60,7 +60,7 @@ function makePutGetDelSuccessfulTest (type, key, value, expectedResult) {
           db.get(key, function (err,  value) {
             t.ok(err, 'entry propertly deleted')
             t.ok(verifyNotFoundError(err), 'should have correct error message')
-            t.ok(typeof value == 'undefined', 'value is undefined')
+            t.equal(typeof value, 'undefined', 'value is undefined')
             t.end()
           })
         })
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..6e99910
--- /dev/null
+++ b/index.js
@@ -0,0 +1,4 @@
+exports.AbstractLevelDOWN    = require('./abstract-leveldown')
+exports.AbstractIterator     = require('./abstract-iterator')
+exports.AbstractChainedBatch = require('./abstract-chained-batch')
+exports.isLevelDOWN          = require('./is-leveldown')
diff --git a/is-leveldown.js b/is-leveldown.js
new file mode 100644
index 0000000..e6911fb
--- /dev/null
+++ b/is-leveldown.js
@@ -0,0 +1,14 @@
+var AbstractLevelDOWN = require('./abstract-leveldown')
+
+function isLevelDOWN (db) {
+  if (!db || typeof db !== 'object')
+    return false
+  return Object.keys(AbstractLevelDOWN.prototype).filter(function (name) {
+    // TODO remove approximateSize check when method is gone
+    return name[0] != '_' && name != 'approximateSize'
+  }).every(function (name) {
+    return typeof db[name] == 'function'
+  })
+}
+
+module.exports = isLevelDOWN
diff --git a/package.json b/package.json
index 808b463..66978bb 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
 {
   "name": "abstract-leveldown",
   "description": "An abstract prototype matching the LevelDOWN API",
-  "version": "2.2.2",
+  "version": "2.4.1",
   "contributors": [
     "Rod Vagg <r at va.gg> (https://github.com/rvagg)",
     "John Chesley <john at chesl.es> (https://github.com/chesles/)",
@@ -28,7 +28,7 @@
     "leveldown",
     "levelup"
   ],
-  "main": "./abstract-leveldown.js",
+  "main": "index.js",
   "dependencies": {
     "xtend": "~4.0.0"
   },
diff --git a/test.js b/test.js
index 7aef43c..b255c3b 100644
--- a/test.js
+++ b/test.js
@@ -1,10 +1,11 @@
-const test                 = require('tape')
-    , sinon                = require('sinon')
-    , util                 = require('util')
-    , testCommon           = require('./testCommon')
-    , AbstractLevelDOWN    = require('./').AbstractLevelDOWN
-    , AbstractIterator     = require('./').AbstractIterator
-    , AbstractChainedBatch = require('./').AbstractChainedBatch
+var test                 = require('tape')
+  , sinon                = require('sinon')
+  , util                 = require('util')
+  , testCommon           = require('./testCommon')
+  , AbstractLevelDOWN    = require('./').AbstractLevelDOWN
+  , AbstractIterator     = require('./').AbstractIterator
+  , AbstractChainedBatch = require('./').AbstractChainedBatch
+  , isLevelDOWN          = require('./').isLevelDOWN
 
 function factory (location) {
   return new AbstractLevelDOWN(location)
@@ -82,7 +83,6 @@ test('test open() extensibility', function (t) {
   t.equal(spy.getCall(0).thisValue, test, '`this` on _open() was correct')
   t.equal(spy.getCall(0).args.length, 2, 'got two arguments')
   t.deepEqual(spy.getCall(0).args[0], expectedOptions, 'got default options argument')
-  t.equal(spy.getCall(0).args[1], expectedCb, 'got expected cb argument')
 
   test.open({ options: 1 }, expectedCb)
 
@@ -92,7 +92,6 @@ test('test open() extensibility', function (t) {
   t.equal(spy.getCall(1).thisValue, test, '`this` on _open() was correct')
   t.equal(spy.getCall(1).args.length, 2, 'got two arguments')
   t.deepEqual(spy.getCall(1).args[0], expectedOptions, 'got expected options argument')
-  t.equal(spy.getCall(1).args[1], expectedCb, 'got expected cb argument')
   t.end()
 })
 
@@ -115,7 +114,6 @@ test('test close() extensibility', function (t) {
   t.equal(spy.callCount, 1, 'got _close() call')
   t.equal(spy.getCall(0).thisValue, test, '`this` on _close() was correct')
   t.equal(spy.getCall(0).args.length, 1, 'got one arguments')
-  t.equal(spy.getCall(0).args[0], expectedCb, 'got expected cb argument')
   t.end()
 })
 
@@ -569,3 +567,148 @@ test('test end() extensibility', function (t) {
   t.equal(spy.getCall(0).args[0], expectedCb, 'got expected cb argument')
   t.end()
 })
+
+test('isLevelDOWN', function (t) {
+  t.notOk(isLevelDOWN(), 'is not a leveldown')
+  t.notOk(isLevelDOWN(''), 'is not a leveldown')
+  t.notOk(isLevelDOWN({}), 'is not a leveldown')
+  t.notOk(isLevelDOWN({ put: function () {} }), 'is not a leveldown')
+  t.ok(isLevelDOWN(new AbstractLevelDOWN('location')), 'IS a leveldown')
+  t.ok(isLevelDOWN({
+    open: function () {},
+    close: function () {},
+    get: function () {},
+    put: function () {},
+    del: function () {},
+    batch: function () {},
+    iterator: function () {}
+  }), 'IS a leveldown')
+  t.ok(isLevelDOWN({
+    open: function () {},
+    close: function () {},
+    get: function () {},
+    put: function () {},
+    del: function () {},
+    batch: function () {},
+    approximateSize: function () {},
+    iterator: function () {}
+  }), 'IS also a leveldown')
+  t.end()
+})
+
+test('.status', function (t) {
+  t.test('empty prototype', function (t) {
+    var test
+
+    function Test (location) {
+      AbstractLevelDOWN.call(this, location)
+    }
+
+    util.inherits(Test, AbstractLevelDOWN)
+
+    test = new Test('foobar')
+    t.equal(test.status, 'new')
+
+    test.open(function (err) {
+      t.error(err)
+      t.equal(test.status, 'open')
+
+      test.close(function (err) {
+        t.error(err)
+        t.equal(test.status, 'closed')
+        t.end()
+      })
+    })
+  })
+
+  t.test('open error', function (t) {
+    var test
+
+    function Test (location) {
+      AbstractLevelDOWN.call(this, location)
+    }
+
+    util.inherits(Test, AbstractLevelDOWN)
+
+    Test.prototype._open = function (options, cb) {
+      cb(new Error)
+    }
+
+    test = new Test('foobar')
+    test.open(function (err) {
+      t.ok(err)
+      t.equal(test.status, 'new')
+      t.end()
+    })
+  })
+
+  t.test('close error', function (t) {
+    var test
+
+    function Test (location) {
+      AbstractLevelDOWN.call(this, location)
+    }
+
+    util.inherits(Test, AbstractLevelDOWN)
+
+    Test.prototype._close = function (cb) {
+      cb(new Error)
+    }
+
+    test = new Test('foobar')
+    test.open(function () {
+      test.close(function (err) {
+        t.ok(err)
+        t.equal(test.status, 'open')
+        t.end()
+      })
+    })
+  })
+
+  t.test('open', function (t) {
+    var test
+
+    function Test (location) {
+      AbstractLevelDOWN.call(this, location)
+    }
+
+    util.inherits(Test, AbstractLevelDOWN)
+
+    Test.prototype._open = function (options, cb) {
+      process.nextTick(cb)
+    }
+
+    test = new Test('foobar')
+    test.open(function (err) {
+      t.error(err)
+      t.equal(test.status, 'open')
+      t.end()
+    })
+    t.equal(test.status, 'opening')
+  })
+
+  t.test('close', function (t) {
+    var test
+
+    function Test (location) {
+      AbstractLevelDOWN.call(this, location)
+    }
+
+    util.inherits(Test, AbstractLevelDOWN)
+
+    Test.prototype._close = function (cb) {
+      process.nextTick(cb)
+    }
+
+    test = new Test('foobar')
+    test.open(function (err) {
+      t.error(err)
+      test.close(function (err) {
+        t.error(err)
+        t.equal(test.status, 'closed')
+        t.end()
+      })
+      t.equal(test.status, 'closing')
+    })
+  })
+})

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-abstract-leveldown.git



More information about the Pkg-javascript-commits mailing list