pull-level
Advanced tools
Comparing version 1.5.2 to 2.0.0
80
index.js
@@ -1,83 +0,13 @@ | ||
var pull = require('pull-stream/pull') | ||
var Map = require('pull-stream/throughs/map') | ||
var AsyncMap = require('pull-stream/throughs/async-map') | ||
var Drain = require('pull-stream/sinks/drain') | ||
var Live = require('pull-live') | ||
var toPull = require('stream-to-pull-stream') | ||
var pushable = require('pull-pushable') | ||
var cat = require('pull-cat') | ||
var pw = require('pull-window') | ||
var post = require('level-post') | ||
exports.old = require('./old') | ||
exports.live = require('./live') | ||
function read(db, opts) { | ||
return toPull.read1(db.createReadStream(opts)) | ||
} | ||
var live = | ||
exports.live = | ||
function (db, opts) { | ||
opts = opts || {} | ||
var l = pushable(function (err) { | ||
if(opts.onAbort) opts.onAbort(err) | ||
cleanup() | ||
}) | ||
var cleanup = post(db, opts, function (ch) { | ||
if(opts.keys === false) | ||
l.push(ch.value) | ||
else if(opts.values === false) | ||
l.push(ch.key) | ||
else | ||
l.push(ch) | ||
}) | ||
return l | ||
} | ||
exports.old = read | ||
exports.read = | ||
exports.readStream = | ||
exports.createReadStream = function (db, opts) { | ||
opts = opts || {} | ||
if(!(opts.tail || opts.live)) | ||
return read(db, opts) | ||
exports.createReadStream = require('./read') | ||
//optionally notify when we switch from reading history to realtime | ||
var sync = opts.onSync && function (abort, cb) { | ||
opts.onSync(abort); cb(abort || true) | ||
} | ||
if(opts.onSync === true || opts.sync === true) | ||
sync = pull.values([{sync: true}]) | ||
return cat([read(db, opts), sync, live(db, opts)]) | ||
} | ||
exports.write = | ||
exports.writeStream = | ||
exports.createWriteStream = function (db, opts, done) { | ||
if('function' === typeof opts) | ||
done = opts, opts = null | ||
opts = opts || {} | ||
return pull( | ||
Map(function (e) { | ||
if(e.type) return e | ||
return { | ||
key : e.key, | ||
value : e.value, | ||
type : e.value == null ? 'del' : 'put' | ||
} | ||
}), | ||
pw.recent(opts.windowSize, opts.windowTime), | ||
AsyncMap(function (batch, cb) { | ||
db.batch(batch, cb) | ||
}), | ||
Drain(null, done) | ||
) | ||
} | ||
exports.createWriteStream = require('./write') |
{ | ||
"name": "pull-level", | ||
"description": "pull-stream interface to levelup", | ||
"version": "1.5.2", | ||
"version": "2.0.0", | ||
"homepage": "https://github.com/dominictarr/pull-level", | ||
@@ -13,2 +13,3 @@ "repository": { | ||
"pull-cat": "^1.1.9", | ||
"pull-live": "^1.0.1", | ||
"pull-pushable": "^2.0.0", | ||
@@ -15,0 +16,0 @@ "pull-stream": "^3.4.0", |
@@ -23,3 +23,3 @@ # pull-level | ||
pull( | ||
pl.read(db, {tail: true}), | ||
pl.read(db, {live: true}), | ||
//log data as it comes, | ||
@@ -41,3 +41,3 @@ //because tail will keep the connection open | ||
pull( | ||
pl.live(db, {tail: true}), | ||
pl.live(db, {live: true}), | ||
pull.through(console.log), | ||
@@ -44,0 +44,0 @@ pull.drain() |
@@ -13,2 +13,4 @@ | ||
function toKV (d) { return {key: d.key, value: d.value}} | ||
tape('live', function (t) { | ||
@@ -22,3 +24,3 @@ return t.end() | ||
h.timestamps(db, 10, function (err, all) { | ||
h.timestamps(db, 11, function (err, all) { | ||
@@ -28,6 +30,7 @@ var i = 0 | ||
pull( | ||
l.read(db, {live: true, onSync: function () { | ||
console.log('SYNC') | ||
sync = true | ||
}}), | ||
l.read(db, {live: true, values: false}), | ||
pull.filter(function (s) { | ||
if(s.sync) sync = true | ||
else return true | ||
}), | ||
h.exactly(20), | ||
@@ -42,5 +45,3 @@ pull.collect(function (err, ary) { | ||
t.deepEqual(ary, h.sort(ary.slice())) | ||
t.deepEqual(ary.map(function (e) { | ||
return {key: e.key, value: e.value} | ||
}), all) | ||
t.deepEqual(ary.map(toKV), all) | ||
t.ok(sync) | ||
@@ -54,3 +55,3 @@ t.end() | ||
setTimeout(function () { | ||
h.timestamps(db, 10, function (err, _all) { | ||
h.timestamps(db, 9, function (err, _all) { | ||
second = true | ||
@@ -64,3 +65,2 @@ all = all.concat(_all) | ||
tape('live2', function (t) { | ||
@@ -81,6 +81,7 @@ | ||
pull( | ||
l.read(db, {tail: true, keys: false, onSync: function () { | ||
console.log('SYNC') | ||
sync = true | ||
}}), | ||
l.read(db, {live: true}), | ||
pull.filter(function (s) { | ||
if(s.sync) sync = true | ||
else return true | ||
}), | ||
h.exactly(20), | ||
@@ -112,5 +113,3 @@ pull.collect(function (err, _ary) { | ||
var values = all.map(function (e) { return e.value }) | ||
t.deepEqual(ary, values) | ||
t.deepEqual(ary.map(toKV), all.map(toKV)) | ||
t.ok(sync) | ||
@@ -122,3 +121,2 @@ t.end() | ||
}) | ||
return | ||
@@ -132,3 +130,3 @@ tape('live, sync:true', function (t) { | ||
h.timestamps(db, 10, function (err, all) { | ||
h.timestamps(db, 11, function (err, all) { | ||
@@ -138,3 +136,3 @@ var i = 0 | ||
pull( | ||
l.read(db, {tail: true, keys: false, sync: true}), | ||
l.read(db, {live: true, sync: true}), | ||
pull.filter(function (data) { | ||
@@ -154,3 +152,3 @@ if(data.sync) sync = true | ||
setTimeout(function () { | ||
h.timestamps(db, 10, function (err, _all) { | ||
h.timestamps(db, 9, function (err, _all) { | ||
second = true | ||
@@ -162,5 +160,5 @@ all = all.concat(_all) | ||
var values = all.map(function (e) { return e.value }) | ||
// var values = all.map(toKV) | ||
t.deepEqual(ary, values) | ||
t.deepEqual(ary.map(toKV), all) | ||
t.ok(sync) | ||
@@ -173,1 +171,9 @@ t.end() | ||
}) | ||
@@ -21,15 +21,20 @@ | ||
h.random(db, 10, function (err2, all) { | ||
h.random(db, 11, function (err2, all) { | ||
if(err2) throw err2 | ||
pull( | ||
l.read(db, {live: true, onSync: function () { | ||
console.log('sync') | ||
sync = true | ||
}, onAbort: function (end) { | ||
t.ok(end) | ||
if(--n) return | ||
end() | ||
} | ||
l.read(db, {live: true}), | ||
pull.through(function (data) { | ||
console.log("DATA", data) | ||
}, function (end) { | ||
console.log("END", end) | ||
t.ok(end) | ||
if(--n) return | ||
end() | ||
}), | ||
pull.filter(function (d) { | ||
if(d.sync) return !(sync = true) | ||
return true | ||
}), | ||
h.exactly(20, err), | ||
@@ -48,3 +53,3 @@ pull.map(function (e) { | ||
h.random(db, 10, function (err, _all) { | ||
h.random(db, 9, function (err, _all) { | ||
all = h.sort(all.concat(_all)) | ||
@@ -67,1 +72,6 @@ if(--n) return | ||
}) | ||
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
15417
15
405
7
+ Addedpull-live@^1.0.1
+ Addedpull-live@1.0.1(transitive)