npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

p2p-db

v2.0.0

Published

an open-ended peer-to-peer database

Downloads

8

Readme

p2p-db

An open-ended peer-to-peer database.

Mad Science

I'm still figuring out what this is and how it will work. Don't rely on this for anything yet, but do file issues or ping me on IRC #ddem with your thoughts!

Semantic versioning will be respected.

Goals

  1. have a minimal api that requires no knowledge of the underlying layers (hyperdb, etc) for consumers
  2. implement all logic in pluggable API modules that offer logic and views over the append-only log data in hyperdb
  3. work in node, electron, and the browser
  4. be very very fast for document insertion, iteration, and replication

Usage

Let's create a minimal distributed OpenStreetMap database using p2p-db and p2p-db-osm:

TODO: finish making this example run!

var p2p = require('p2p-db')
var hyperdb = require('hyperdb')
var ram = require('random-access-memory')
var memdb = require('memdb')
var GeoStore = require('grid-point-store')

function createDatabase () {
  var hyper = hyperdb(ram, { valueEncoding: 'json' })
  var level = memdb()

  return p2p([
    // Base runtime dependency for p2p-db: a hyperdb instance
    p2p.provide('hyperdb', hyper),

    // API that extends the database with OpenStreetMap primitives & operations
    require('p2p-db-osm'),
    p2p.provide('leveldb', level),  // needed for p2p-db-osm
    p2p.provide('pointstore', new GeoStore(memdb())),  // needed for p2p-db-osm
  ])
}

var db = createDatabase()

db.osm.create({
  lat: 14,
  lon: 27,
  changeset: '123',
  tags: {}
}, function (err, elm) {
  console.log(err || elm)

  // sync with another p2p-db
  var db2 = createDatabase()

  var rs1 = db.replicate()
  var rs2 = db2.replicate()

  rs1.pipe(rs2).pipe(rs1).once('end', onDone)
})

function onDone () {
  console.log('replication done')

  // query data
  db2.osm.query([[-30, -30], [30, 30]], function (err, nodes) {
    console.log(err, nodes)
  })
}

outputs

replication done
{ lat: 14, lon: 27, changeset: '123', tags: {} }

API

var p2p = require('p2p-db')

var db = p2p(deps)

Creates a new p2p-db db, using the depj dependencies given. At minimum p2p-db expects a 'hyperdb'.

The included dependencies form an API, exposed through the resultant db object.

var ds = db.replicate([opts])

Creates a duplex stream ds that can be used to replicate this database with a p2p-db on the other end of another replication stream.

Valid opts include:

  • live (Boolean): if true, the duplex stream will not close on its own: new changes will continue to be sent in both directions. Defaults to false.

Implementing a p2p-db API

TODO

Install

With npm installed, run

$ npm install p2p-db

See Also

License

ISC