[Pkg-javascript-commits] [node-deferred-leveldown] 01/03: Imported Upstream version 0.2.0
Andrew Kelley
andrewrk-guest at moszumanska.debian.org
Thu Jul 3 23:59:34 UTC 2014
This is an automated email from the git hooks/post-receive script.
andrewrk-guest pushed a commit to branch master
in repository node-deferred-leveldown.
commit 73db027a017da9c2316ae3403ee69da472c7bfec
Author: Andrew Kelley <superjoe30 at gmail.com>
Date: Mon Jun 30 15:01:48 2014 +0000
Imported Upstream version 0.2.0
---
.gitignore | 1 +
.jshintrc | 59 +++++++++++++++++++++++++++++
.travis.yml | 12 ++++++
README.md | 55 +++++++++++++++++++++++++++
deferred-leveldown.js | 47 +++++++++++++++++++++++
package.json | 42 +++++++++++++++++++++
test.js | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 317 insertions(+)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c2658d7
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules/
diff --git a/.jshintrc b/.jshintrc
new file mode 100644
index 0000000..7937650
--- /dev/null
+++ b/.jshintrc
@@ -0,0 +1,59 @@
+{
+ "predef": [ ]
+ , "bitwise": false
+ , "camelcase": false
+ , "curly": false
+ , "eqeqeq": false
+ , "forin": false
+ , "immed": false
+ , "latedef": false
+ , "noarg": true
+ , "noempty": true
+ , "nonew": true
+ , "plusplus": false
+ , "quotmark": true
+ , "regexp": false
+ , "undef": true
+ , "unused": true
+ , "strict": false
+ , "trailing": true
+ , "maxlen": 120
+ , "asi": true
+ , "boss": true
+ , "debug": true
+ , "eqnull": true
+ , "esnext": true
+ , "evil": true
+ , "expr": true
+ , "funcscope": false
+ , "globalstrict": false
+ , "iterator": false
+ , "lastsemic": true
+ , "laxbreak": true
+ , "laxcomma": true
+ , "loopfunc": true
+ , "multistr": false
+ , "onecase": false
+ , "proto": false
+ , "regexdash": false
+ , "scripturl": true
+ , "smarttabs": false
+ , "shadow": false
+ , "sub": true
+ , "supernew": false
+ , "validthis": true
+ , "browser": true
+ , "couch": false
+ , "devel": false
+ , "dojo": false
+ , "mootools": false
+ , "node": true
+ , "nonstandard": true
+ , "prototypejs": false
+ , "rhino": false
+ , "worker": true
+ , "wsh": false
+ , "nomen": false
+ , "onevar": true
+ , "passfail": false
+}
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..1fec2ab
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,12 @@
+language: node_js
+node_js:
+ - "0.8"
+ - "0.10"
+ - "0.11"
+branches:
+ only:
+ - master
+notifications:
+ email:
+ - rod at vagg.org
+script: npm test
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..861b79c
--- /dev/null
+++ b/README.md
@@ -0,0 +1,55 @@
+DeferredLevelDOWN
+=================
+
+**A mock LevelDOWN implementation that queues operations while a real LevelDOWN instance is being opened.**
+
+
+
+[](http://travis-ci.org/rvagg/deferred-leveldown)
+
+[](https://nodei.co/npm/deferred-leveldown/)
+
+**DeferredLevelDOWN** implements the basic [AbstractLevelDOWN](https://github.com/rvagg/node-abstract-leveldown) API so it can be used as a drop-in replacement where LevelDOWN is needed.
+
+`put()`, `get()`, `del()` and `batch()` operations are all queued and kept in memory until a new LevelDOWN-compatible object can be supplied.
+
+The `setDb(db)` method is used to supply a new LevelDOWN object. Once received, all queued operations are replayed against that object, in order.
+
+`batch()` operations will all be replayed as the array form. Chained-batch operations are converted before being stored.
+
+Contributing
+------------
+
+DeferredLevelDOWN 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/rvagg/node-levelup/blob/master/CONTRIBUTING.md) file for more details.
+
+### Contributors
+
+DeferredLevelDOWN 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>
+</tbody></table>
+
+<a name="licence"></a>
+Licence & copyright
+-------------------
+
+Copyright (c) 2013 DeferredLevelDOWN contributors (listed above).
+
+DeferredLevelDOWN is licensed under an MIT +no-false-attribs license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.
diff --git a/deferred-leveldown.js b/deferred-leveldown.js
new file mode 100644
index 0000000..93184f3
--- /dev/null
+++ b/deferred-leveldown.js
@@ -0,0 +1,47 @@
+var util = require('util')
+ , AbstractLevelDOWN = require('abstract-leveldown').AbstractLevelDOWN
+
+function DeferredLevelDOWN (location) {
+ AbstractLevelDOWN.call(this, typeof location == 'string' ? location : '') // optional location, who cares?
+ this._db = undefined
+ this._operations = []
+}
+
+util.inherits(DeferredLevelDOWN, AbstractLevelDOWN)
+
+// called by LevelUP when we have a real DB to take its place
+DeferredLevelDOWN.prototype.setDb = function (db) {
+ this._db = db
+ this._operations.forEach(function (op) {
+ db[op.method].apply(db, op.args)
+ })
+}
+
+DeferredLevelDOWN.prototype._open = function (options, callback) {
+ return process.nextTick(callback)
+}
+
+// queue a new deferred operation
+DeferredLevelDOWN.prototype._operation = function (method, args) {
+ if (this._db)
+ return this._db[method].apply(this._db, args)
+ this._operations.push({ method: method, args: args })
+}
+
+// deferrables
+'put get del batch approximateSize'.split(' ').forEach(function (m) {
+ DeferredLevelDOWN.prototype['_' + m] = function () {
+ this._operation(m, arguments)
+ }
+})
+
+DeferredLevelDOWN.prototype._isBuffer = function (obj) {
+ return Buffer.isBuffer(obj)
+}
+
+// don't need to implement this as LevelUP's ReadStream checks for 'ready' state
+DeferredLevelDOWN.prototype._iterator = function () {
+ throw new TypeError('not implemented')
+}
+
+module.exports = DeferredLevelDOWN
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..a2f5a05
--- /dev/null
+++ b/package.json
@@ -0,0 +1,42 @@
+{
+ "name": "deferred-leveldown",
+ "description": "For handling delayed-open on LevelDOWN compatible libraries",
+ "version": "0.2.0",
+ "contributors": [
+ "Rod Vagg <r at va.gg> (https://github.com/rvagg)",
+ "John Chesley <john at chesl.es> (https://github.com/chesles/)",
+ "Jake Verbaten <raynos2 at gmail.com> (https://github.com/raynos)",
+ "Dominic Tarr <dominic.tarr at gmail.com> (https://github.com/dominictarr)",
+ "Max Ogden <max at maxogden.com> (https://github.com/maxogden)",
+ "Lars-Magnus Skog <lars.magnus.skog at gmail.com> (https://github.com/ralphtheninja)",
+ "David Björklund <david.bjorklund at gmail.com> (https://github.com/kesla)",
+ "Julian Gruber <julian at juliangruber.com> (https://github.com/juliangruber)",
+ "Paolo Fragomeni <paolo at async.ly> (https://github.com/hij1nx)",
+ "Anton Whalley <anton.whalley at nearform.com> (https://github.com/No9)",
+ "Matteo Collina <matteo.collina at gmail.com> (https://github.com/mcollina)",
+ "Pedro Teixeira <pedro.teixeira at gmail.com> (https://github.com/pgte)",
+ "James Halliday <mail at substack.net> (https://github.com/substack)"
+ ],
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/Level/deferred-leveldown.git"
+ },
+ "homepage": "https://github.com/Level/deferred-leveldown",
+ "keywords": [
+ "leveldb",
+ "level",
+ "levelup",
+ "leveldown"
+ ],
+ "main": "deferred-leveldown.js",
+ "dependencies": {
+ "abstract-leveldown": "~0.12.1"
+ },
+ "devDependencies": {
+ "tape": "~1.0.4"
+ },
+ "scripts": {
+ "test": "node test.js"
+ },
+ "license": "MIT"
+}
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..f16720c
--- /dev/null
+++ b/test.js
@@ -0,0 +1,101 @@
+var test = require('tape')
+ , DeferredLevelDOWN = require('./')
+
+test('single operation', function (t) {
+ var called = false
+ var ld = new DeferredLevelDOWN('loc')
+ ld.put('foo', 'bar', function (v) {
+ called = v
+ })
+ t.ok(called === false, 'not called')
+ ld.setDb({ put: function (key, value, options, callback) {
+ t.equal(key, 'foo', 'correct key')
+ t.equal(value, 'bar', 'correct value')
+ t.deepEqual({}, options, 'empty options')
+ callback('called')
+ }})
+
+ t.ok(called === 'called', 'function called')
+
+ t.end()
+})
+
+test('many operations', function (t) {
+ var calls = []
+ var ld = new DeferredLevelDOWN('loc')
+ , puts = 0
+ , gets = 0
+ , batches = 0
+
+ ld.put('foo1', 'bar1', function (v) { calls.push({ type: 'put', key: 'foo1', v: v }) })
+ ld.get('woo1', function (v) { calls.push({ type: 'get', key: 'woo1', v: v }) })
+ ld.put('foo2', 'bar2', function (v) { calls.push({ type: 'put', key: 'foo2', v: v }) })
+ ld.get('woo2', function (v) { calls.push({ type: 'get', key: 'woo2', v: v }) })
+ ld.del('blergh', function (v) { calls.push({ type: 'del', key: 'blergh', v: v }) })
+ ld.batch([
+ { type: 'put', key: 'k1', value: 'v1' }
+ , { type: 'put', key: 'k2', value: 'v2' }
+ ], function () { calls.push({ type: 'batch', keys: 'k1,k2' }) })
+ ld.batch().put('k3', 'v3').put('k4', 'v4').write(function () {
+ calls.push({ type: 'batch', keys: 'k3,k4' })
+ })
+
+ t.ok(calls.length === 0, 'not called')
+
+ ld.setDb({
+ put: function (key, value, options, callback) {
+ if (puts++ === 0) {
+ t.equal(key, 'foo1', 'correct key')
+ t.equal(value, 'bar1', 'correct value')
+ t.deepEqual({}, options, 'empty options')
+ } else {
+ t.equal(key, 'foo2', 'correct key')
+ t.equal(value, 'bar2', 'correct value')
+ t.deepEqual({}, options, 'empty options')
+ }
+ callback('put' + puts)
+ }
+ , get: function (key, options, callback) {
+ if (gets++ === 0) {
+ t.equal('woo1', key, 'correct key')
+ t.deepEqual({}, options, 'empty options')
+ } else {
+ t.equal('woo2', key, 'correct key')
+ t.deepEqual({}, options, 'empty options')
+ }
+ callback('gets' + gets)
+ }
+ , del: function (key, options, callback) {
+ t.equal('blergh', key, 'correct key')
+ t.deepEqual({}, options, 'empty options')
+ callback('del')
+ }
+ , batch: function (arr, options, callback) {
+ if (batches++ === 0) {
+ t.deepEqual(arr, [
+ { type: 'put', key: 'k1', value: 'v1' }
+ , { type: 'put', key: 'k2', value: 'v2' }
+ ], 'correct batch')
+ } else {
+ t.deepEqual(arr, [
+ { type: 'put', key: 'k3', value: 'v3' }
+ , { type: 'put', key: 'k4', value: 'v4' }
+ ], 'correct batch')
+ }
+ callback('batches' + batches)
+ }
+ })
+
+ t.equal(calls.length, 7, 'all functions called')
+ t.deepEqual(calls, [
+ { type: 'put', key: 'foo1', v: 'put1' }
+ , { type: 'get', key: 'woo1', v: 'gets1' }
+ , { type: 'put', key: 'foo2', v: 'put2' }
+ , { type: 'get', key: 'woo2', v: 'gets2' }
+ , { type: 'del', key: 'blergh', v: 'del' }
+ , { type: 'batch', keys: 'k1,k2' }
+ , { type: 'batch', keys: 'k3,k4' }
+ ], 'calls correctly behaved')
+
+ t.end()
+})
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-deferred-leveldown.git
More information about the Pkg-javascript-commits
mailing list