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

protobee

v1.3.0

Published

Hyperbee over Protomux. Primary server that allows many writable clients

Downloads

19

Readme

protobee

Hyperbee over Protomux. Primary server that allows many writable clients

npm i protobee

Warning: this is experimental, and it might contain edge case bugs.

Usage

const RAM = require('random-access-memory')
const c = require('compact-encoding')
const Hypercore = require('hypercore')
const Hyperbee = require('hyperbee')
const Protobee = require('protobee')

// Server side
const core = new Hypercore(RAM)
const bee = new Hyperbee(core)

const server = new Protobee.Server(bee)
await server.ready()

// Client side
const db = new Protobee(server.key, server.clientSeed, { keyEncoding: c.any, valueEncoding: c.any })
await db.ready()

console.log(db.version) // => 1
await db.put('/a', '1')
console.log(db.version) // => 2

// Another client
const db2 = new Protobee(server.key, server.clientSeed)
await db2.ready()

console.log(db2.version) // => 2
await db2.get('/a') // => { seq, key, value }

API

const server = new Protobee.Server(bee, [options])

Creates a DHT server that handles RPC requests supporting the Hyperbee API.

bee must be a Hyperbee instance.

Available options:

{
  primaryKey, // Secret primary key used to derive server and client key pairs
  dht, // DHT instance
  bootstrap // Array of bootstrap nodes (only if you didn't pass a DHT instance)
}

await server.ready()

Wait for the server to be listening on the Hypercore key pair of the Hyperbee.

server.key

Public key of the server. Client can use it to connect to the server.

server.clientSeed

Default secret client seed. Client can use it for authentication.

const db = new Protobee(serverKey, seed, [options])

Creates a RPC client to connects to the server.

serverKey must be server.key.

seed must be server.clientSeed, it's used to generate the client key pair.

Available options:

{
  keyEncoding, // It doesn't support custom codecs, only a string from codecs or a compact-encoding method
  valueEncoding,
  dht, // DHT instance
  bootstrap // Array of bootstrap nodes (only if you didn't pass a DHT instance)
}

The rest of the API

Practically the same API as Hyperbee:

https://github.com/holepunchto/hyperbee

Warning

Differences with Hyperbee:

  • The way you create the Protobee instance is different but this is expected.
  • Errors are very different at the moment.
  • Possible bugs around the version property due core truncates (needs more debugging and testing).
  • In bee.put method the cas option is a bool, and if you pass a function it will throw.
  • In bee.del method the cas option is not supported, and it will throw if you use it.

Notes:

  • A bad client can create unlimited snapshots or sending bad requests (needs protection settings).

Current unsupported methods:

  • sub (in favor of using sub-encoder lib, but it might end up being supported)
  • watch
  • getAndWatch

License

MIT