{"id":13832238,"url":"https://github.com/hypercore-protocol/hypertrie","last_synced_at":"2026-01-11T17:35:46.223Z","repository":{"id":46726872,"uuid":"136758254","full_name":"hypercore-protocol/hypertrie","owner":"hypercore-protocol","description":"Distributed single writer key/value store","archived":false,"fork":false,"pushed_at":"2024-02-27T13:14:48.000Z","size":142,"stargazers_count":316,"open_issues_count":8,"forks_count":30,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-10-04T10:55:51.444Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/hypercore-protocol.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-09T21:08:57.000Z","updated_at":"2025-09-23T07:50:34.000Z","dependencies_parsed_at":"2024-06-18T15:36:36.387Z","dependency_job_id":"13b4c4d9-9989-49e7-9bbe-ef2529475283","html_url":"https://github.com/hypercore-protocol/hypertrie","commit_stats":null,"previous_names":["mafintosh/hypertrie"],"tags_count":46,"template":false,"template_full_name":null,"purl":"pkg:github/hypercore-protocol/hypertrie","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypercore-protocol%2Fhypertrie","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypercore-protocol%2Fhypertrie/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypercore-protocol%2Fhypertrie/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypercore-protocol%2Fhypertrie/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hypercore-protocol","download_url":"https://codeload.github.com/hypercore-protocol/hypertrie/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypercore-protocol%2Fhypertrie/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28315879,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T14:58:17.114Z","status":"ssl_error","status_checked_at":"2026-01-11T14:55:53.580Z","response_time":60,"last_error":"SSL_read: 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":[],"created_at":"2024-08-04T10:01:56.606Z","updated_at":"2026-01-11T17:35:46.207Z","avatar_url":"https://github.com/hypercore-protocol.png","language":"JavaScript","readme":"# hypertrie\n\nDistributed single writer key/value store\n\n```\nnpm install hypertrie\n```\n\n[![Build Status](https://travis-ci.org/mafintosh/hypertrie.svg?branch=master)](https://travis-ci.org/mafintosh/hypertrie)\n\nUses a rolling hash array mapped trie to index key/value data on top of a [hypercore](https://github.com/mafintosh/hypercore).\n\nUseful if you just want a straight forward single writer kv store or if you are looking for a building block for building more complex multiwriter databases on top.\n\n## Usage\n\n```js\nconst hypertrie = require('hypertrie')\nconst db = hypertrie('./trie.db', {valueEncoding: 'json'})\n\ndb.put('hello', 'world', function () {\n  db.get('hello', console.log)\n})\n```\n\n## API\n\n#### `db = hypertrie(storage, [key], [options])`\n\nCreate a new database. Options include:\n\n```\n{\n  feed: aHypercore, // use this feed instead of loading storage\n  valueEncoding: 'json', // set value encoding\n  subtype: undefined, // set subtype in the header message at feed.get(0) \n  alwaysUpdate: true // perform an ifAvailable update prior to every head operation\n}\n```\n\nIf you set `options.feed` then you can set `storage` to null.\n\n#### `db.get(key, [options], callback)`\n\nLookup a key. Returns a result node if found or `null` otherwise.\nOptions are passed through to hypercore's get method.\n\n#### `db.put(key, value, [options], [callback])`\n\nInsert a value.\n\nOptions can include:\n```\n{\n  condition: function (oldNode, newNode, cb(err, bool)) { ... } \n}\n```\nThe optional `condition` function provides atomic compare-and-swap semantics, allowing you to optionally abort a put based on the current and intended node values.\nThe condition callback should be used as follows:\n1. `cb(new Error(...))`: Abort with an error that will be forwarded through the `put`.\n2. `cb(null, false)`: Abort the put, but do not produce an error.\n3. `cb(null, true)`: Proceed with the put.\n\n#### `db.del(key, [options], [callback])`\n\nDelete a key from the database.\n\nOptions can include:\n```\n{\n  condition: function (oldNode, cb(err, bool)) { ... }\n}\n```\nThe optional `condition` function behaves the same as the one in `put`, minus the `newNode` parameter.\n\n#### `db.batch(batch, [callback])`\n\nInsert/delete multiple values atomically.\nThe batch objects should look like this:\n\n```js\n{\n  type: 'put' | 'del',\n  key: 'key/we/are/updating',\n  value: optionalValue\n}\n```\n\n#### `const watcher = db.watch(prefix, [onchange])`\n\nWatch a prefix of the db and get notified when it changes.\n\nWhen there is a change `watcher.on('change')` is emitted.\nUse `watcher.destroy()` to stop watching.\n\n#### `db.on('ready')`\n\nEmitted when the db has loaded it's internal state.\n\nYou do not need to wait for this unless noted in the docs.\n\n#### `db.version`\n\nReturns the current version of the db (an incrementing integer).\n\nOnly available after `ready` has been emitted.\n\n#### `db.key`\n\nReturns the db public key. You need to pass this to other instances\nyou want to replicate with.\n\nOnly available after `ready` has been emitted.\n\n#### `db.discoveryKey`\n\nReturns the db discovery key. Can be used to find other db peers.\n\nOnly available after `ready` has been emitted.\n\n#### `checkoutDb = db.checkout(version)`\n\nReturns a new db instance checked out at the version specified.\n\n#### `checkoutDb = db.snapshot()`\n\nSame as checkout but just returns the latest version as a checkout.\n\n#### `stream = db.replicate(isInitiator, [options])`\n\nReturns a hypercore replication stream for the db. Pipe this together with another hypertrie instance.\n\nReplicate takes an `isInitiator` boolean which is used to indicate if this replication stream is the passive/active replicator.\n\nAll options are forwarded to hypercores replicate method.\n\n#### `ite = db.iterator(prefix, [options])`\n\nReturns a [nanoiterator](https://github.com/mafintosh/nanoiterator) that iterates\nthe latest values in the prefix specified.\n\nOptions include:\n\n```js\n{\n  recursive: true,\n  random: false // does a random order iteration\n}\n```\n\nIf you set `recursive: false` it will only iterate the immediate children (similar to readdir)\n\nAdditional options are passed through to hypercore's get method.\n\n#### `stream = db.createReadStream(prefix, [options])`\n\nSame as above but as a stream\n\n#### `db.list(prefix, [options], callback)`\n\nCreates an iterator for the prefix with the specified options and buffers it into an array that is passed to the callback.\n\n#### `stream = db.createWriteStream()`\n\nA writable stream you can write batch objects to, to update the db.\n\n#### `ite = db.history([options])`\n\nReturns a [nanoiterator](https://github.com/mafintosh/nanoiterator) that iterates over the feed in causal order.\n\nOptions include:\n\n```js\n{\n  gt: seq,\n  lt: seq,\n  gte: seq,\n  lte: seq,\n  reverse: false,\n  live: false // set to true to keep iterating forever\n}\n```\n\n#### `stream = db.createHistoryStream([options])`\n\nSame as above but as a stream\n\n#### `ite = db.diff(version, [prefix], [options])`\n\nReturns a [nanoiterator](https://github.com/mafintosh/nanoiterator) that iterates the diff between the current db and the version you specifiy. The objects returned look like this\n\n```js\n{\n  key: 'node-key-that-is-updated',\n  left: \u003cnode\u003e,\n  right: \u003cnode\u003e\n}\n```\n\nIf a node is in the current db but not in the version you are diffing against\n`left` will be set to the current node and `right` will be null and vice versa.\n\nOptions include:\n\n```js\n{\n  skipLeftNull: false,\n  skipRightNull: false,\n  hidden: false, // set to true to diff the hidden keyspace\n  checkpoint: \u003ccheckpoint\u003e\n}\n```\n\nThe order of messages emitted for a specific diff is predictable (ordered by key hash). It is possible to resume a diff at any position. To do so, call the `.checkpoint` method on the diff iterator. It returns a serialized buffer of the current position within the diff. To resume, create a new diff between the same versions and pass the checkpoint buffer as an option.\n\n#### `stream = db.createDiffStream(version, [prefix])`\n\nSame as above but as a stream\n\n## License\n\nMIT\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhypercore-protocol%2Fhypertrie","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhypercore-protocol%2Fhypertrie","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhypercore-protocol%2Fhypertrie/lists"}