{"id":15497540,"url":"https://github.com/bcomnes/level-hookdown","last_synced_at":"2026-03-05T09:03:48.878Z","repository":{"id":57144561,"uuid":"77759266","full_name":"bcomnes/level-hookdown","owner":"bcomnes","description":"Simple levelup hooks implemented using instance method override of arbitrary levelups.","archived":false,"fork":false,"pushed_at":"2020-05-25T04:10:04.000Z","size":82,"stargazers_count":16,"open_issues_count":3,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2026-01-14T15:22:07.304Z","etag":null,"topics":["level-sublevel","leveldb"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/level-hookdown","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bcomnes.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-31T23:23:48.000Z","updated_at":"2022-06-11T20:20:40.000Z","dependencies_parsed_at":"2022-09-05T07:50:20.738Z","dependency_job_id":null,"html_url":"https://github.com/bcomnes/level-hookdown","commit_stats":null,"previous_names":["hypermodules/level-hookdown"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/bcomnes/level-hookdown","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcomnes%2Flevel-hookdown","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcomnes%2Flevel-hookdown/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcomnes%2Flevel-hookdown/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcomnes%2Flevel-hookdown/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bcomnes","download_url":"https://codeload.github.com/bcomnes/level-hookdown/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcomnes%2Flevel-hookdown/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30117497,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-05T08:19:04.902Z","status":"ssl_error","status_checked_at":"2026-03-05T08:17:37.148Z","response_time":93,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["level-sublevel","leveldb"],"created_at":"2024-10-02T08:39:38.351Z","updated_at":"2026-03-05T09:03:48.844Z","avatar_url":"https://github.com/bcomnes.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# level-hookdown\n\nSimple levelup hooks implemented using instance method override of arbitrary levelups.\n\n```\nnpm install level-hookdown\n```\n\n[![level badge][level-badge]](https://github.com/level/awesome)\n[![npm][npm-image]][npm-url]\n[![Build Status](https://travis-ci.org/hypermodules/level-hookdown.svg?branch=master)](https://travis-ci.org/hypermodules/level-hookdown)\n[![dependencies Status](https://david-dm.org/hypermodules/level-hookdown/status.svg)](https://david-dm.org/hypermodules/level-hookdown)\n[![devDependencies Status](https://david-dm.org/hypermodules/level-hookdown/dev-status.svg)](https://david-dm.org/hypermodules/level-hookdown?type=dev)\n\n\u003cimg height=\"100\" src=\"hook.png\"\u003e\n\n[level-badge]: https://camo.githubusercontent.com/1bd15320a5fad1db168bba8bcedb098735f82464/68747470733a2f2f6c6576656c6a732e6f72672f696d672f62616467652e737667\n[npm-image]: https://img.shields.io/npm/v/level-hookdown.svg\n[npm-url]: https://www.npmjs.com/package/level-hookdown\n\n## Usage\n\n```js\nvar hook = require('level-hookdown')\nvar mem = require('level-mem')  // or 'level' or other levelup factory\nvar mdb = mem()\nvar db = hook(mdb)\n\nfunction prehook (operation, cb) {\n  console.log('this should run before the db operation')\n  console.log(operation)\n  cb()\n}\n\nfunction posthook (operation, cb) {\n  console.log('this should run after the db operation')\n  console.log(operation)\n  cb()\n}\n\ndb.prehooks.push(prehook)\ndb.posthooks.push(posthook)\n\ndb.put('beep', 'boop', function (err) {\n  if (err) throw err\n  db.del('beep', function (err) {\n    if (err) throw err\n    db.batch([\n      { type: 'put', key: 'father', value: 'gloop' },\n      { type: 'put', key: 'another', value: 'heep' }\n    ], function (err) {\n      if (err) throw err\n      console.log('done')\n    })\n  })\n})\n\n```\n\n## API\n\n#### `hookdb = hook(db, [options])`\n\nReturns a levelup instance that executes a series of pre and post hook functions before `put`, `del`, and `batch` method calls.  Composes well with [mafintosh/subleveldown](https://github.com/mafintosh/subleveldown). Conflicts with [dominictarr/level-sublevel](https://github.com/dominictarr/level-sublevel).\n\nThe following `options` can be set when wrapping a `level` with `hook`:\n\n```js\n{\n  type: 'parallel' | 'series' | 'limit',\n  limit: 5,\n  protectHook: false\n}\n```\n\n- The `type` determines if the hook functions are run in series, parallel or parallel-limit.  Default is `parallel`.\n- The limit option is passed to `run-parallel-limit` when `type` is set to `limit`.  The default is 5.\n- `protectHook` performs a deep copy on the operation array in batches to preserve values if the levelup mutates them (like `subleveldown` does).\n\n### Hooks\n\n#### `hookdb.prehooks`\n\nAn array of hook functions that are run before `put`, `del`, and `batch` method calls to the `hookdb` instance.  If a hook function in the prehook array returns an `err` object to its callback, the originating `put`, `del` or `batch` operation will not be run on the contained `db` that `hookdb` is wrapping.  A prehook veto convetion could be built on top of this behavior via error handling and retry.\n\n#### `hookdb.posthooks`\n\nAn array of functions that are run after sucessful `put`, `del`, and `batch` method calls on the wrapped `db` instance inside a `hookdb` instance.\n\n#### `hookFn(operation, callback)`\n\nHook functions receive an `operation` object that describes the level operation and a `callback` function.\n\n`hookdb.prehooks` and `hookdb.posthooks` are arrays that you can add, rearrange, and delete hook functions from using standard array methods like `hookdb.prehooks.push(fn)` and `hookdb.posthooks.pop(fn)`.\n\n##### `operation`\n\nThe `operation` argument can contain an object that looks like:\n\n- `{type:'put', key: 'key', value: 'value', opts}`\n- `{type: 'del', key: 'key', opts}`\n- `{type: 'batch', array: [operationArray], opts}`\n\nThe `opts` object in the level operation object are the options that get passed through to the wrapped level.\n\n## See Also\n\n- [hypermodules/level-auto-index](https://github.com/hypermodules/level-auto-index) - Automatic secondary indexing for leveldb and subleveldown leveraging `level-hookdown`.\n- [hypermodules/level-idx](https://github.com/hypermodules/level-idx) - Another high-level API for creating secondary leveldb indexes using `level-auto-index` and `level-hookdown`.\n\nThis module is basically an alternative implementation of:\n\n- [dominictarr/level-hooks](https://github.com/dominictarr/level-hooks)\n\nbut aimed at a subleveldown workflow. These were also influential:\n\n- [dominictarr/level-post](https://github.com/dominictarr/level-post)\n- [dominictarr/level-sublevel](https://github.com/dominictarr/level-sublevel)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbcomnes%2Flevel-hookdown","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbcomnes%2Flevel-hookdown","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbcomnes%2Flevel-hookdown/lists"}