Giter Club home page Giter Club logo

ssb-conn-db's Introduction

ssb-conn-db

Module that manages a local registry of connectable peers. For use with the SSB CONN family of modules.

Visual metaphor: a shelf of binders used for archival, holding static data on peers and their previous addresses used for connections.

db.png

Usage

This 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:

API

  • new ConnDB(opts): constructor for a connDB instance, with the following options:
    • opts.path (default '~/.ssb'): path to the directory where the database will be stored
    • opts.writeTimeout (default 2000 milliseconds): interval to wait when batching database writes in the filesystem
  • connDB.set(address, data): insert or update a connectable peer by its address (string, must conform to the multiserver address convention) with data (object). If updating the data, it will merge the previous properties with the new properties. Returns the connDB instance.
  • connDB.update(address, data): update a connectable peer by its address (string, must conform to the multiserver address convention) with data (object). If the peer is not in the database, this method performs no operations and silently returns. Returns the connDB instance.
  • connDB.update(address, updater): update a connectable peer by its address (string, must conform to the multiserver address convention) 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.
  • connDB.replace(address, data): insert or update a connectable peer by its address (string, must conform to the multiserver address convention) with data (object). If updating the data, it will replace the previous properties with the new properties. Returns the connDB instance.
  • connDB.get(address): returns the data for an existing peer with the given address, or undefined if the address was not registered
  • 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
  • connDB.has(address): returns true if the given address is registered in the database, false otherwise
  • connDB.delete(address): remove an address and its associated data from the database. Returns true if the address existed and was deleted, false otherwise.
  • connDB.entries(): returns a new Iterator object that gives [address, data] pairs
  • 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'
  • connDB.loaded(): returns a Promise that resolves successfully when the initial database loading (read) occurs, and rejects if there was a failure to load.
  • connDB.close(): finishes writing any pending updates to the database, then gets ready for destroying this instance.

Notice that the API above mostly mirrors the API of the JavaScript Map.

License

MIT

ssb-conn-db's People

Contributors

staltz avatar arj03 avatar

Stargazers

glyph avatar nichoth avatar Freddie Ridell avatar Andrew Chou avatar Mikey avatar Juri Hahn avatar  avatar

Watchers

 avatar James Cloos avatar  avatar

ssb-conn-db's Issues

TypeError: Cannot read property 'entries' of null

I'm writing some tests for Oasis, but they seem to be failing when I run server.close() to exit the Secret-Stack server. I might be doing something wrong, any ideas what might be breaking here?

Oasis: Closing server
fallback to close
TypeError: Cannot read property 'entries' of null
    at ConnDB._serialize (/home/christianbundy/src/fraction/oasis/node_modules/ssb-conn-db/lib/index.js:141:46)
    at ConnDB._write (/home/christianbundy/src/fraction/oasis/node_modules/ssb-conn-db/lib/index.js:157:27)
    at Timeout._onTimeout (/home/christianbundy/src/fraction/oasis/node_modules/ssb-conn-db/lib/index.js:174:19)
    at listOnTimeout (internal/timers.js:549:17)
    at processTimers (internal/timers.js:492:7)

Update ssb-ref dependency

ssb-conn allows for ssb-ref 2.14.3 to be pulled in. This only allows up to 2.13.9 to be used. Would be nice if this could be updated to match.

Cannot read property 'toString' of undefined

TypeError: Cannot read property 'toString' of undefined
    at Object.decode (/Users/luna/checkouts/patchwork/node_modules/ssb-conn-db/lib/atomic-file-codecs.js:9:27)
    at /Users/luna/checkouts/patchwork/node_modules/ssb-conn-db/lib/index.js:89:80
    at /Users/luna/checkouts/patchwork/node_modules/atomic-file-rw/browser.js:22:12
    at intercept (/Users/luna/checkouts/patchwork/node_modules/promisize/index.js:22:15)
    at IDBRequest.request.onsuccess (/Users/luna/checkouts/patchwork/node_modules/idb-kv-store/index.js:333:7)

added a simple fix for now:

9   decode: function (input) {
10      if (!input) return {};
11      const str = input.toString();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.