level-mirror
Advanced tools
+32
| var test = require('tape'); | ||
| var level = require('level-test')(); | ||
| var sub = require('level-sublevel'); | ||
| var mirror = require('..'); | ||
| test('drop', function(t) { | ||
| t.plan(2); | ||
| var db = sub(level('mirror', { | ||
| valueEncoding: 'json' | ||
| })); | ||
| mirror(db.sublevel('posts'), db.sublevel('home'), function() { | ||
| return; | ||
| }); | ||
| var id = '1337'; | ||
| var post = { | ||
| title: 'A post', | ||
| slug: 'a-post', | ||
| text: 'Food truck laborum minim Pinterest tempor, elit Blue Bottle cliche tofu deep v officia. Sartorial consectetur cillum, in nesciunt McSweeney\'s consequat adipisicing +1 fanny pack letterpress PBR elit. Church-key Banksy actually, retro squid bicycle rights pork belly accusamus. Sed irure Schlitz Helvetica freegan vegan, pork belly sriracha pug synth consectetur laboris +1 bespoke. Ut sapiente American Apparel, do eu swag dolore 90\'s PBR seitan scenester umami blog. Fashion axe ut occaecat vinyl sunt. Chillwave proident consequat ugh commodo American Apparel YOLO, PBR Carles adipisicing culpa.' | ||
| }; | ||
| db.sublevel('posts').put(id, post, function(err) { | ||
| t.error(err); | ||
| db.sublevel('home').get(id, function(err, _post) { | ||
| t.ok(err); | ||
| }); | ||
| }); | ||
| }); | ||
+1
-0
@@ -17,2 +17,3 @@ module.exports = mirror; | ||
| change.value = transform(change.value); | ||
| if (change.value === undefined) return; | ||
| } | ||
@@ -19,0 +20,0 @@ |
+1
-1
| { | ||
| "name": "level-mirror", | ||
| "description": "Mirror and optionally transform data from one sublevel into another.", | ||
| "version": "1.0.0", | ||
| "version": "1.1.0", | ||
| "repository": { | ||
@@ -6,0 +6,0 @@ "type": "git", |
+6
-3
@@ -52,6 +52,9 @@ | ||
| From the point you call `mirror` on, all operations performed on sublevel `a` | ||
| will be mirrored onto sublevel `b`, and their values optinally transformed on | ||
| the fly by the `transform` function, that receives the current value and is to | ||
| expected to return the potentially modified value. | ||
| will be mirrored onto sublevel `b`. | ||
| If you pass in `transform`, the changes' values will be transformed on | ||
| the fly by the function. It receives the current value and is expected to | ||
| return the potentially modified value. If it returns `undefined`, the change | ||
| will be dropped. | ||
| `transform` can also be an array, in which case it limits values to the keys | ||
@@ -58,0 +61,0 @@ contained in it. |
10765
13.65%10
11.11%163
20.74%93
3.33%