level-sublevel
Advanced tools
Comparing version 5.2.0 to 6.0.0
95
index.js
@@ -1,90 +0,17 @@ | ||
var EventEmitter = require('events').EventEmitter | ||
var next = process.nextTick | ||
var SubDb = require('./sub') | ||
var Batch = require('./batch') | ||
var fixRange = require('level-fix-range') | ||
var Hooks = require('level-hooks') | ||
module.exports = function (_db, options) { | ||
function DB () {} | ||
DB.prototype = _db | ||
var db = new DB() | ||
var nut = require('./nut') | ||
var shell = require('./shell') //the shell surrounds the nut | ||
var precodec = require('./codec') | ||
var codec = require('levelup/lib/codec') | ||
var DeferredLevelDown = require('deferred-leveldown') | ||
// Currently this uses pull streams, | ||
// and not levelup's readstream, but in theory | ||
// I should be able pretty much just drop that in. | ||
var ReadStream = require('levelup/lib/read-stream') | ||
if (db.sublevel) return db | ||
module.exports = function (db) { | ||
options = options || {} | ||
return shell ( nut ( db, precodec, codec ), [], ReadStream, db.options) | ||
//use \xff (255) as the seperator, | ||
//so that sections of the database will sort after the regular keys | ||
var sep = options.sep = options.sep || '\xff' | ||
db._options = options | ||
Hooks(db) | ||
db.sublevels = {} | ||
db.sublevel = function (prefix, options) { | ||
if(db.sublevels[prefix]) | ||
return db.sublevels[prefix] | ||
return new SubDb(db, prefix, options || this._options) | ||
} | ||
db.methods = {} | ||
db.prefix = function (key) { | ||
return '' + (key || '') | ||
} | ||
db.pre = function (range, hook) { | ||
if(!hook) | ||
hook = range, range = { | ||
max : sep | ||
} | ||
return db.hooks.pre(range, hook) | ||
} | ||
db.post = function (range, hook) { | ||
if(!hook) | ||
hook = range, range = { | ||
max : sep | ||
} | ||
return db.hooks.post(range, hook) | ||
} | ||
function safeRange(fun) { | ||
return function (opts) { | ||
opts = opts || {} | ||
opts = fixRange(opts) | ||
if(opts.reverse) opts.start = opts.start || sep | ||
else opts.end = opts.end || sep | ||
return fun.call(db, opts) | ||
} | ||
} | ||
db.readStream = | ||
db.createReadStream = safeRange(db.createReadStream) | ||
db.keyStream = | ||
db.createKeyStream = safeRange(db.createKeyStream) | ||
db.valuesStream = | ||
db.createValueStream = safeRange(db.createValueStream) | ||
var batch = db.batch | ||
db.batch = function (changes, opts, cb) { | ||
if(!Array.isArray(changes)) | ||
return new Batch(db) | ||
changes.forEach(function (e) { | ||
if(e.prefix) { | ||
if('function' === typeof e.prefix.prefix) | ||
e.key = e.prefix.prefix(e.key) | ||
else if('string' === typeof e.prefix) | ||
e.key = e.prefix + e.key | ||
} | ||
}) | ||
batch.call(db, changes, opts, cb) | ||
} | ||
return db | ||
} | ||
{ | ||
"name": "level-sublevel", | ||
"description": "partition levelup databases", | ||
"version": "5.2.0", | ||
"version": "6.0.0", | ||
"homepage": "https://github.com/dominictarr/level-sublevel", | ||
@@ -14,15 +14,19 @@ "repository": { | ||
"level-fix-range": "2.0", | ||
"xtend": "~2.0.4" | ||
"pull-stream": "~2.21.0", | ||
"xtend": "~2.0.4", | ||
"ltgt": "~1.0.2" | ||
}, | ||
"devDependencies": { | ||
"levelup": "dominictarr/node-levelup#inject", | ||
"bytewise": "~0.7.0", | ||
"level": "~0.18.0", | ||
"level-test": ">=1.5.1 <2", | ||
"monotonic-timestamp": "0.0.8", | ||
"pull-level": "~1.1.1", | ||
"rimraf": "~2.1.4", | ||
"shasum": "0.0.2", | ||
"monotonic-timestamp": "0.0.8", | ||
"pull-stream": "~2.18.2", | ||
"pull-level": "~1.1.1", | ||
"level-test": ">=1.5.1 <2", | ||
"stream-to-pull-stream": "~1.2.0", | ||
"tape": "~1.0.4", | ||
"tape": "~2.13.3", | ||
"through": "~2.3.4", | ||
"level": "~0.15.0" | ||
"leveldown": "~0.10.2" | ||
}, | ||
@@ -34,3 +38,19 @@ "scripts": { | ||
"license": "MIT", | ||
"stability": "unstable" | ||
"stability": "unstable", | ||
"testling": { | ||
"files": "test/*.js", | ||
"browsers": [ | ||
"ie/8..latest", | ||
"firefox/17..latest", | ||
"firefox/nightly", | ||
"chrome/22..latest", | ||
"chrome/canary", | ||
"opera/12..latest", | ||
"opera/next", | ||
"safari/5.1..latest", | ||
"ipad/6.0..latest", | ||
"iphone/6.0..latest", | ||
"android-browser/4.2..latest" | ||
] | ||
} | ||
} |
@@ -6,2 +6,3 @@ # level-sublevel | ||
[![build status](https://secure.travis-ci.org/dominictarr/level-sublevel.png)](http://travis-ci.org/dominictarr/level-sublevel) | ||
[![testling badge](https://ci.testling.com/dominictarr/level-sublevel.png)](https://ci.testling.com/dominictarr/level-sublevel) | ||
@@ -8,0 +9,0 @@ This module allows you to create seperate sections of a |
@@ -22,2 +22,3 @@ var levelup = require('level-test')() | ||
t.notOk(err, 'getting object value by key has no error') | ||
console.log(value) | ||
t.equal(value.obj, 'ect', 'and returns value for that key') | ||
@@ -30,4 +31,6 @@ }) | ||
.on('data', function (d) { foodata = d }) | ||
.on('data', console.log.bind(null, '****')) | ||
.on('error', function (err) { fooerr = err }) | ||
.on('end', function () { | ||
console.log('END ***********8') | ||
t.notOk(fooerr, 'streaming string value by key emits no error') | ||
@@ -41,4 +44,5 @@ t.equal(foodata.key, 'foo1', 'streaming string value emits key') | ||
bar.createReadStream({ start: 'bar1', end: 'bar1\xff', valueEncoding: 'json' }) | ||
.on('data', console.log.bind(null, '%%%%')) | ||
.on('data', function (d) { bardata = d }) | ||
.on('error', function (err) { barerr = err }) | ||
.on('error', function (err) { throw barerr = err }) | ||
.on('end', function () { | ||
@@ -45,0 +49,0 @@ t.notOk(barerr, 'streaming object value by key emits no error') |
@@ -8,3 +8,3 @@ var levelup = require('level-test')() | ||
test('sublevel value streams emit values and sublevel key streams emit keys', function (t) { | ||
t.plan(4) | ||
t.plan(2) | ||
@@ -19,5 +19,3 @@ var foo = base.sublevel('foo') | ||
.on('data', function (d) { valdata = d }) | ||
.on('error', function (err) { valerr = err }) | ||
.on('end', function () { | ||
t.notOk(valerr, 'value stream emits no error') | ||
t.equal(valdata, 'foo1-value', 'emits value only') | ||
@@ -30,7 +28,4 @@ }) | ||
.on('data', function (d) { keydata = d }) | ||
.on('error', function (err) { keyerr = err }) | ||
.on('end', function () { | ||
t.notOk(keyerr, 'key stream emits no error') | ||
t.equal(keydata, 'foo1', 'emits fully namespaced key only') | ||
t.equal(keydata, 'foo1', 'emits fully namespaced key only') | ||
}) | ||
@@ -37,0 +32,0 @@ }) |
var level = require('level-test')() | ||
var sublevel = require('../') | ||
function sl (name) { | ||
return sublevel(level(name), {sep: '~'}) | ||
} | ||
require('tape')('sublevel', function (t) { | ||
@@ -12,3 +8,4 @@ | ||
var base = sl('test-sublevel-readstream') | ||
var db = level('test-sublevel-readstream') | ||
var base = sublevel(db) | ||
@@ -32,15 +29,14 @@ var a = base.sublevel('A') | ||
var as = a.createWriteStream() | ||
as.write({key: 'a', value: _a ='AAA_'+Math.random()}) | ||
as.write({key: 'b', value: _b = 'BBB_'+Math.random()}) | ||
as.write({key: 'c', value: _c = 'CCC_'+Math.random()}) | ||
as.end() | ||
as.on('close', function () { | ||
all(base, function (err, obj) { | ||
a.batch([ | ||
{key: 'a', value: _a ='AAA_'+Math.random(), type: 'put'}, | ||
{key: 'b', value: _b = 'BBB_'+Math.random(), type: 'put'}, | ||
{key: 'c', value: _c = 'CCC_'+Math.random(), type: 'put'}, | ||
], function (err) { | ||
if(err) throw err | ||
all(db, function (err, obj) { | ||
console.log(obj) | ||
t.deepEqual(obj, | ||
{ '~A~a': _a, | ||
'~A~b': _b, | ||
'~A~c': _c | ||
{ '!A!a': _a, | ||
'!A!b': _b, | ||
'!A!c': _c | ||
}) | ||
@@ -47,0 +43,0 @@ |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
71241
43
2129
101
0
6
12
1
1
+ Addedltgt@~1.0.2
+ Addedpull-stream@~2.21.0
+ Addedltgt@1.0.2(transitive)
+ Addedpull-core@1.0.0(transitive)
+ Addedpull-stream@2.21.0(transitive)