{
  "name": "ssb-conn-db",
  "description": "Module that manages a local registry of connectable peers",
  "version": "1.0.5",
  "homepage": "https://github.com/staltz/ssb-conn-db",
  "main": "lib/index.js",
  "types": "lib/index.d.ts",
  "repository": {
    "type": "git",
    "url": "git://github.com/staltz/ssb-conn-db.git"
  },
  "dependencies": {
    "atomic-file-rw": "^0.3.0",
    "debug": "^4.3.1",
    "multiserver-address": "~1.0.1",
    "pull-notify": "~0.1.2",
    "ssb-ref": ">=2.13.9"
  },
  "devDependencies": {
    "@types/node": "^11.10.4",
    "pull-stream": "^3.6.9",
    "tap-bail": "^1.0.0",
    "tap-spec": "^5.0.0",
    "tape": "^5.5.3",
    "typescript": "4.7.x"
  },
  "author": "Andre Staltz <contact@staltz.com> (http://staltz.com)",
  "license": "MIT",
  "scripts": {
    "typescript": "tsc",
    "tape": "tape test/*.js | tap-bail | tap-spec",
    "test": "npm run typescript && npm run tape"
  },
  "readme": "# ssb-conn-db\n\nModule that manages a local registry of connectable peers. For use with the [SSB CONN](https://github.com/staltz/ssb-conn) family of modules.\n\n*Visual metaphor: a shelf of binders used for archival, holding static data on peers\nand their previous addresses used for connections.*\n\n![db.png](./db.png)\n\n## Usage\n\nThis module is only used to create an SSB CONN plugin, not used directly by applications. A ConnDB instance should be available on the CONN plugin, with the following API:\n\n## API\n\n* `new ConnDB(opts)`: constructor for a connDB instance, with the following options:\n  - `opts.path` (default `'~/.ssb'`): path to the directory where the database will be stored\n  - `opts.writeTimeout` (default `2000` milliseconds): interval to wait when batching database writes in the filesystem\n* `connDB.set(address, data)`: insert or update a connectable peer by its `address` (string, must conform to the [multiserver address convention](https://github.com/dominictarr/multiserver-address)) with `data` (object). If updating the data, it will *merge* the previous properties with the new properties. Returns the `connDB` instance.\n* `connDB.update(address, data)`: update a connectable peer by its `address` (string, must conform to the [multiserver address convention](https://github.com/dominictarr/multiserver-address)) with `data` (object). If the peer is not in the database, this method performs no operations and silently returns. Returns the `connDB` instance.\n* `connDB.update(address, updater)`: update a connectable peer by its `address` (string, must conform to the [multiserver address convention](https://github.com/dominictarr/multiserver-address)) with `updater` (a function where input is the previous data object and output should be the new data object). If the peer is not in the database, this method performs no operations and silently returns. Returns the `connDB` instance.\n* `connDB.replace(address, data)`: insert or update a connectable peer by its `address` (string, must conform to the [multiserver address convention](https://github.com/dominictarr/multiserver-address)) with `data` (object). If updating the data, it will *replace* the previous properties with the new properties. Returns the `connDB` instance.\n* `connDB.get(address)`: returns the data for an existing peer with the given `address`, or `undefined` if the address was not registered\n* `connDB.getAddressForId(id)`: returns the connection address for an existing peer with the given SSB feed `id`, or `undefined` if the address does not exist\n* `connDB.has(address)`: returns `true` if the given `address` is registered in the database, `false` otherwise\n* `connDB.delete(address)`: remove an address and its associated data from the database. Returns `true` if the address existed and was deleted, `false` otherwise.\n* `connDB.entries()`: returns a new `Iterator` object that gives `[address, data]` pairs\n* `connDB.listen()`: returns a pull stream that notifies of changes made to the database, as an object `{type, address}` where `type` is either `'insert'`, `'update'`, or `'delete'`\n* `connDB.loaded()`: returns a Promise that resolves successfully when the initial database loading (read) occurs, and rejects if there was a failure to load.\n* `connDB.close()`: finishes writing any pending updates to the database, then gets ready for destroying this instance.\n\nNotice that the API above mostly mirrors the API of the JavaScript [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map).\n\n## License\n\nMIT\n"
}