pull-level
Advanced tools
Comparing version 1.1.6 to 1.1.7
36
index.js
@@ -5,3 +5,3 @@ var pull = require('pull-stream') | ||
var cat = require('pull-cat') | ||
var window = require('pull-window') | ||
var pw = require('pull-window') | ||
var fixRange = require('level-fix-range') | ||
@@ -23,6 +23,7 @@ var post = require('level-post') | ||
var cleanup = post(db, opts, function (ch) { | ||
console.log('post!', ch) | ||
l.push(ch) | ||
}) | ||
return l.pipe(pull.through(null, cleanup)) | ||
return pull(l, pull.through(null, cleanup)) | ||
@@ -41,3 +42,3 @@ } | ||
var sync = opts.onSync && function (abort, cb) { | ||
opts.onSync(); cb(true) | ||
opts.onSync(abort); cb(abort || true) | ||
} | ||
@@ -54,16 +55,19 @@ | ||
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' | ||
} | ||
}) | ||
.pipe(window(opts.windowSize, opts.windowTime)) | ||
.pipe(pull.asyncMap(function (batch, cb) { | ||
db.batch(batch, cb) | ||
})) | ||
.pipe(pull.onEnd(done)) | ||
return pull( | ||
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), | ||
pull.asyncMap(function (batch, cb) { | ||
console.log('write batch', batch) | ||
db.batch(batch, cb) | ||
}), | ||
pull.drain(null, done) | ||
) | ||
} | ||
@@ -0,5 +1,6 @@ | ||
{ | ||
"name": "pull-level", | ||
"description": "pull-stream interface to levelup", | ||
"version": "1.1.6", | ||
"version": "1.1.7", | ||
"homepage": "https://github.com/dominictarr/pull-level", | ||
@@ -12,8 +13,8 @@ "repository": { | ||
"level-fix-range": "~1.1", | ||
"pull-stream": ">=2.18 <3", | ||
"pull-stream": ">=2.20 <3", | ||
"pull-pushable": "1", | ||
"pull-window": "1", | ||
"pull-window": ">=2.1.2 <3", | ||
"pull-cat": ">=1.1 <2", | ||
"stream-to-pull-stream": "1.2", | ||
"level-post": "~1.0.1" | ||
"level-post": "~1.0.3" | ||
}, | ||
@@ -24,3 +25,3 @@ "devDependencies": { | ||
"rimraf": "~2.1.4", | ||
"level": "~0.9.0" | ||
"level": "~0.10.0" | ||
}, | ||
@@ -27,0 +28,0 @@ "scripts": { |
@@ -6,19 +6,21 @@ var pull = require('pull-stream') | ||
exports.random = | ||
function (db, n, cb) { | ||
function (db, n, cb) { | ||
var all = [] | ||
pull.infinite() | ||
.pipe(pull.map(function (e) { | ||
return { | ||
key: e.toString(), | ||
value: new Date().toString() | ||
} | ||
})) | ||
.pipe(pull.take(n)) | ||
.pipe(pull.through(function (e) { | ||
all.push({key:e.key, value: e.value}) | ||
})) | ||
.pipe(l.write(db, function (err) { | ||
pull( | ||
pull.infinite(), | ||
pull.map(function (e) { | ||
return { | ||
key: e.toString(), | ||
value: new Date().toString() | ||
} | ||
}), | ||
pull.take(n), | ||
pull.through(function (e) { | ||
all.push({key:e.key, value: e.value}) | ||
}), | ||
l.write(db, function (err) { | ||
cb(err, all) | ||
})) | ||
}) | ||
) | ||
} | ||
@@ -35,13 +37,15 @@ | ||
var all | ||
pull.values(all = [ | ||
{key: 'A', value: 'apple'}, | ||
{key: 'B', value: 'banana'}, | ||
{key: 'C', value: 'cherry'}, | ||
{key: 'D', value: 'durian'}, | ||
{key: 'E', value: 'elder-berry'}, | ||
]) | ||
.pipe(l.write(db, function (err) { | ||
console.log('ALL', err, all) | ||
cb(err, all) | ||
})) | ||
pull( | ||
pull.values(all = [ | ||
{key: 'A', value: 'apple'}, | ||
{key: 'B', value: 'banana'}, | ||
{key: 'C', value: 'cherry'}, | ||
{key: 'D', value: 'durian'}, | ||
{key: 'E', value: 'elder-berry'}, | ||
]), | ||
l.write(db, function (err) { | ||
console.log('ALL', err, all) | ||
cb(err, all) | ||
}) | ||
) | ||
} | ||
@@ -53,16 +57,18 @@ | ||
var all = [] | ||
pull.infinite() | ||
.pipe(pull.take(n)) | ||
.pipe(pull.map(function (e) { | ||
return { | ||
key : timestamp().toString(), | ||
value : e.toString() | ||
} | ||
})) | ||
.pipe(pull.through(function (e) { | ||
all.push({key:e.key, value: e.value}) | ||
})) | ||
.pipe(l.write(db, function (err) { | ||
pull( | ||
pull.infinite(), | ||
pull.take(n), | ||
pull.map(function (e) { | ||
return { | ||
key : timestamp().toString(), | ||
value : e.toString() | ||
} | ||
}), | ||
pull.through(function (e) { | ||
all.push({key:e.key, value: e.value}) | ||
}), | ||
l.write(db, function (err) { | ||
cb(err, all) | ||
})) | ||
}) | ||
) | ||
@@ -69,0 +75,0 @@ } |
@@ -23,22 +23,24 @@ | ||
var sync = false | ||
l.read(db, {tail: true, onSync: function () { | ||
console.log('SYNC') | ||
sync = true | ||
}}) | ||
.pipe(h.exactly(20)) | ||
.pipe(pull.collect(function (err, ary) { | ||
process.nextTick(function () { | ||
t.notOk(err) | ||
t.ok(second) | ||
console.log(all) | ||
t.equal(ary.length, 20) | ||
t.equal(ary.length, all.length) | ||
t.deepEqual(ary, h.sort(ary.slice())) | ||
t.deepEqual(ary.map(function (e) { | ||
return {key: e.key, value: e.value} | ||
}), all) | ||
t.ok(sync) | ||
t.end() | ||
pull( | ||
l.read(db, {tail: true, onSync: function () { | ||
console.log('SYNC') | ||
sync = true | ||
}}), | ||
h.exactly(20), | ||
pull.collect(function (err, ary) { | ||
process.nextTick(function () { | ||
t.notOk(err) | ||
t.ok(second) | ||
console.log(all) | ||
t.equal(ary.length, 20) | ||
t.equal(ary.length, all.length) | ||
t.deepEqual(ary, h.sort(ary.slice())) | ||
t.deepEqual(ary.map(function (e) { | ||
return {key: e.key, value: e.value} | ||
}), all) | ||
t.ok(sync) | ||
t.end() | ||
}) | ||
}) | ||
})) | ||
) | ||
@@ -45,0 +47,0 @@ |
@@ -21,21 +21,23 @@ | ||
l.read(db, {tail: true, onSync: function () { | ||
console.log('sync') | ||
sync = true | ||
}}) | ||
.pipe(h.exactly(20)) | ||
.pipe(pull.map(function (e) { | ||
return {key: e.key, value: e.value}//drop 'type' from live updates | ||
})) | ||
.pipe(pull.collect(function (err, ary) { | ||
t.notOk(err) | ||
t.ok(second) | ||
console.log(ary) | ||
console.log(all) | ||
console.log(ary.length, all.length) | ||
t.equal(ary.length, all.length) | ||
t.deepEqual(h.sort(ary), all) | ||
t.ok(sync) | ||
t.end() | ||
})) | ||
pull( | ||
l.read(db, {tail: true, onSync: function () { | ||
console.log('sync') | ||
sync = true | ||
}}), | ||
h.exactly(20), | ||
pull.map(function (e) { | ||
return {key: e.key, value: e.value}//drop 'type' from live updates | ||
}), | ||
pull.collect(function (err, ary) { | ||
t.notOk(err) | ||
t.ok(second) | ||
console.log(ary) | ||
console.log(all) | ||
console.log(ary.length, all.length) | ||
t.equal(ary.length, all.length) | ||
t.deepEqual(h.sort(ary), all) | ||
t.ok(sync) | ||
t.end() | ||
}) | ||
) | ||
@@ -45,5 +47,4 @@ h.random(db, 10, function (err, _all) { | ||
all = h.sort(all.concat(_all)) | ||
}) | ||
}) | ||
}) | ||
}) |
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
11278
285
+ Addedlooper@2.0.0(transitive)
+ Addedpull-window@2.1.4(transitive)
- Removedpull-window@1.0.3(transitive)
Updatedlevel-post@~1.0.3
Updatedpull-stream@>=2.20 <3
Updatedpull-window@>=2.1.2 <3