{"name":"level-hooks","description":"pre/post hooks for leveldb","version":"4.1.3","homepage":"https://github.com/dominictarr/level-hooks","repository":{"type":"git","url":"git://github.com/dominictarr/level-hooks.git"},"author":{"name":"Dominic Tarr","email":"dominic.tarr@gmail.com","url":"http://bit.ly/dominictarr"},"dependencies":{"string-range":"~1.2"},"devDependencies":{"levelup":"~0.6","rimraf":"~2.0.2","macgyver":"~1.9","range-bucket":"0.0.0"},"scripts":{"test":"set -e; for t in test/*.js; do node $t; done"},"_id":"level-hooks@4.1.3","dist":{"shasum":"97997d874314d035186b710ee6058309f811e117","tarball":"http://registry-npm.ywwl.com/level-hooks/download/level-hooks-4.1.3.tgz","integrity":"sha512-0+VA8Hbke8BxwVJdARCt7gTZKzaXgpJOxkrYbv4vkYejNfNJa3fvdcThHzxQTU74CJOeSX8FfJyEsNmK9hQD9g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEXYc0BvflFMHsDs3u4wAYiEgL23eDDwNaJG+3PtgJMiAiBqFI+4yBVUgVY9AF2fGQ2HBTo/hQcX916R+r6na9IBMA=="}],"size":5236,"noattachment":false,"key":"/level-hooks/-/level-hooks-4.1.3.tgz"},"_from":".","_npmVersion":"1.2.3","_npmUser":{"name":"dominictarr","email":"dominic.tarr@gmail.com"},"maintainers":[{"name":"dominictarr","email":"dominic.tarr@gmail.com"}],"directories":{},"readme":"# Pre/Post hooks for leveldb\n\nIntercept put/delete/batch operations on levelup.\n\n## Warning - Breaking Changes\n \nThe API for implementing pre hooks has changed.\nInstead of mutating an array at once, the prehook\nis called on each change `hook(change, add)`\nand may call `add(_change)` to add a new item into the batch.\n\nAlso, attaching hooks to leveldb is now simpler\n``` js\nvar Hooks = require('level-hooks')\nHooks(db) //previously: Hooks()(db)\n```\n\n## Example\n\n``` js\nvar levelup   = require('levelup')\nvar timestamp = require('monotonic-timestamp')\nvar hooks     = require('level-hooks')\n\nlevelup(file, {createIfMissing: true}, function (err, db) {\n\n  //install hooks onto db.\n  hooks(db)\n\n  db.hooks.pre({start: '', end: '~'}, function (change, add) {\n    //change is same pattern as the an element in the batch array.\n    //add a log to record every put operation.\n    add({type: 'put', key: '~log-'+timestamp()+'-'+change.type, value: change.key})\n  })\n\n  //add a hook that responds after an operation has completed.\n  db.hooks.post(function (ch) {\n    //{type: 'put'|'del', key: ..., value: ...}\n  })\n\n})\n```\n\nUsed by [map-reduce](https://github.com/dominictarr/map-reduce) \nto make map-reduce durable across crashes!\n\n## API\n\n### rm = db.hooks.pre (range?, hook(change, add(op), batch))\n\nIf `prefix` is a `string` or `object` that defines the range the pre-hook triggers on.\nIf `prefix' is a string, then the hook only triggers on keys that _start_ with that \nstring. If the hook is an object it must be of form `{start: START, end: END}`\n\n`hook` is a function, and will be called on each item in the batch \n(if it was a `put` or `del`, it will be called on the change)\n`op` is always of the form `{key: key, value: value, type:'put' | 'del'}`\n\nPass additional changes to `add` to add them to the batch.\nIf add is passed a string as the second argument it will prepend that prefix\nto any keys you add.\n\nYou can check what opperations are currently in the batch with the third argument.\nDo not modify the `batch` directly, instead use `add`\n\nTo veto (remove) the current change call `add(false)`.\n\n`db.hooks.pre` returns a function that will remove the hook when called.\n\n#### unsafe mode\n\nnormally, pre hooks prevent you from inserting into the hooked range\nwhen the hook is triggered. However, sometimes you do need to do this.\nIn those cases, pass in a range with `{start: START, end: END, safe: false}`\nand level-hooks will not error. If you use this option, your hook must\navoid triggering in a loop itself.\n\n### rm = db.hooks.post (range?, hook)\n\nPost hooks do not offer any chance to change the value.\nbut do take a range option, just like `pre`\n\n`db.hooks.post` returns a function that will remove the hook when called.\n\n\n## License\n\nMIT\n","publish_time":1365072756552,"_cnpm_publish_time":1365072756552,"dist-tags":{"latest":"4.5.0"}}