level-hooks
Advanced tools
Comparing version 4.4.5 to 4.5.0
@@ -49,3 +49,7 @@ var ranges = require('string-range') | ||
if(!hook) hook = prefix, prefix = '' | ||
var h = {test: ranges.checker(prefix), hook: hook} | ||
var h = { | ||
test: ranges.checker(prefix), | ||
hook: hook, | ||
safe: false !== prefix.safe | ||
} | ||
prehooks.push(h) | ||
@@ -107,3 +111,3 @@ return remover(prehooks, h) | ||
ch.key = prefix + ch.key | ||
if(h.test(String(ch.key))) { | ||
if(h.safe && h.test(String(ch.key))) { | ||
//this usually means a stack overflow. | ||
@@ -110,0 +114,0 @@ throw new Error('prehook cannot insert into own range') |
{ | ||
"name": "level-hooks", | ||
"description": "pre/post hooks for leveldb", | ||
"version": "4.4.5", | ||
"version": "4.5.0", | ||
"homepage": "https://github.com/dominictarr/level-hooks", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -70,2 +70,10 @@ # Pre/Post hooks for leveldb | ||
#### unsafe mode | ||
normally, pre hooks prevent you from inserting into the hooked range | ||
when the hook is triggered. However, sometimes you do need to do this. | ||
In those cases, pass in a range with `{start: START, end: END, safe: false}` | ||
and level-hooks will not error. If you use this option, your hook must | ||
avoid triggering in a loop itself. | ||
### rm = db.hooks.post (range?, hook) | ||
@@ -78,4 +86,5 @@ | ||
## License | ||
MIT |
16400
14
406
89