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

fn-client

v0.6.4

Published

footnote rpc client & message format utilities

Downloads

17

Readme

fn-client

This library contains utilities and Node.js gRPC bindings for use with Footnote daemon.

Usage

The below usage information is a high-level overview of the library. More in-depth documentation can be found by viewing the TSDoc. The TSDoc can be generating by running npm run docs.

gRPC API

To use the gRPC API, you'll need to instantiate FootnoteClient like this:

// replace 127.0.0.1:9098 with your node's URL,
// if other than the default:
const client = new FootnoteClient('127.0.0.1:9098');

Once done, you can call any of the service methods defined on FootnoteClient.

Reading Data

fn-client includes support for reading and writing data to Footnote blobs. To read social data out of a blob, we recommend using the iterateAllEnvelopes method like this:

const blobName = 'foobar';
const client = new FootnoteClient('127.0.0.1:9098');

// creates an instance of a buffered Readable, which will read
// from the blob using gRPC and keep the data in a 1MB buffer.
const reader = new BufferedReader(new Blobreader(blobName, client), 1024 * 1024);
iterateAllEnvelopes(reader, (err, envelope) => {
  if (err) {
    console.error(err);
    return false;
  }
  if (envelope === null) {
    return false;
  }
  // do something with the envelope
  console.log(envelope.message);
  return true;
});

Writing Data

Writing data to a blob is a similar process to reading, however doing so requires the private key of the blob being written to:

const blobName = 'foobar';
const client = new FootnoteClient('127.0.0.1:9098');

// replace the below with your actual private key
const signer = SECP256k1Signer.fromHexPrivateKey('cafecafe12345');
const truncate = false;
const writer = new EnvelopeWriter(client, blobName, truncate, signer);
await writer.open();

// see TSDoc for docs on creating Envelopes
const envelope = new Envelope(...);
await writer.writeEnvelope(envelope);
await writer.commit();

Note that this will start writing from the beginning of the blob. fn-client does not keep track of last-used offsets within a blob; this is left up to applications.

A Note on Streams

fn-client uses its own internal streaming implementation. Classes that make use of streaming IO generally implement the Reader or Writer interfaces. Helper methods are provided that abstract this detail away, however more advanced use cases may need to make use of the streaming libraries directly.