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

ssb-social-index

v1.1.1

Published

scuttlebot plugin for getting reduced state based on the author's social graph

Downloads

84

Readme

ssb-social-index

scuttlebot plugin for indexing reduced state based on the author's social graph.

Usage

This module exports a function that takes some options as an argument. It then returns a plugin that provides certain indexes determined by those options (see the API section below).

const Server = require('scuttlebot')
const config = { ... } // needs options

// Install the plugin
Server
  .use(require('ssb-backlinks')) // required if not using ssb-db2
  .use(require('ssb-social-index')({
    namespace: 'edits',
    type: 'update',
    destField: 'root'
  }))

// Start the server
const server = Server(config)

In this fictional example, we'd pick up messages of form:

{
  type: 'update',
  root: '%aleq2po323j12j3s1l2j3s123z',
  update: {
    title: 'Scuttle Camp ~~One~~ Two'
  }
}

and provide social index methods at server.edits[METHOD]

API

The function exported by this module takes an option object with three mandatory fields:

{
  namespace: 'foo',
  type: 'bar',
  destField: 'baz'
}

These options will produce a plugin named 'foo' that indexes over messages of type 'bar', matching dest arguments in the provided functions against a field called 'baz' on the 'bar' messages.

For all exposed functions, the dest argument must be a FeedId/MessageId.

After calling the exported plugin with all options set to 'about', you get a plugin with the following API.

server.about.socialValue({ key, dest }, cb)

Where dest is a FeedId/ MessageId which is being described by some about messages, and key is the specific about property you want to know e.g.

server.about.socialValue({ key: 'name', dest: '@3r4+IyB5NVl2in6QOZHIu9oSrZud+NuVgl2GX3x2WG8=.ed25519' }, (err, value) => {
  console.log(value)
  // => 'Richard'
})

The default algorithm for the socialValue is based of the following priorities:

  1. the most recent value I have set for that dest/ key (if it exists)
  2. the most recent value that the 'owner' dest set for that key (if they've self assigned it)
  3. the most recent + 'popular' value for the dest / key (from all data in your network)

You can however provide your own custom algorithm using the option getSocialValue. (See code for details)

server.about.latestValue({ key, dest }, cb)

Same as socialValue, except only gets the most recent value that's been announced by anyone for this dest / key

server.about.socialValues({ key, dest }, cb)

Returns the most abouts for all people who have published things for this key / dest

server.about.socialValues({ key: 'name', dest: '@3r4+IyB5NVl2in6QOZHIu9oSrZud+NuVgl2GX3x2WG8=.ed25519' }, (err, values) => {
  console.log(values)
  // => {
     '@3r4+IyB5NVl2in6QOZHIu9oSrZud+NuVgl2GX3x2WG8=.ed25519': 'Richard',
     '@ye+QM09iPcDJD6YvQYjoQc7sLF/IFhmNbEqgdzQo3lQ=.ed25519': 'Dick'
  }
})

server.about.latestValues({ keys, dest }, cb)

NOTE - takes keys an Array of properties to return about a dest Uses the same algorithm as latestValue, except you can get more than one value at once.

e.g.

server.about.latestValues({ keys: ['title', 'image', 'location'], dest: '%Z1Kk8Aj8Bnw5+t4d73kRPHMA0Nj2bL1bx7n7obZhVZg=.sha256' }, (err, values) => {
  console.log(values)
  // => {
    title: 'Picnic Birthday Party',
    image: '&asrg0Mb/w3lLC+yZIJr/4aY0nkWT9Wn+32zrqhaIvy4=.sha256',
    location: 'Scorching Bay'
  }
})

server.about.socialValueStream({ key, dest }) => source

Similar to socialValue, except served over a stream. If the value changes a new value is sent down the stream

pull(
  server.about.socialValueStream({ key: 'avatar', dest: '@3r4+IyB5NVl2in6QOZHIu9oSrZud+NuVgl2GX3x2WG8=.ed25519' }),
  pull.drain(avatar => {
    console.log(avatar)
    // => '&asrg0Mb/w3lLC+yZIJr/4aY0nkWT9Wn+32zrqhaIvy4=.sha256'
    // (later) => '&gwEYOFxfKxHSviAqeGub34eOIGXuuwn3G6odVNW9UtQ=.sha256'
  })
)

server.about.socialValuesStream({ key, dest }) => source

Similar to socialValues, except served over a stream. If the values change only the new values are emitted.

pull(
  server.about.socialValueStream({ key: 'name', dest: '@3r4+IyB5NVl2in6QOZHIu9oSrZud+NuVgl2GX3x2WG8=.ed25519' }),
  pull.drain(title => {
    console.log(title)
    // => {
    //   '@3r4+IyB5NVl2in6QOZHIu9oSrZud+NuVgl2GX3x2WG8=.ed25519': 'Richard',
    //   '@ye+QM09iPcDJD6YvQYjoQc7sLF/IFhmNbEqgdzQo3lQ=.ed25519': 'Dick'
    // }
    // (later) => {
    //   '@ye+QM09iPcDJD6YvQYjoQc7sLF/IFhmNbEqgdzQo3lQ=.ed25519': 'Rich'
    // }
  })
)

server.about.latestValueStream({ key, dest, authorId = null }) => source

Same as latestValue expect a stream. First value emitted is the current value, subsequent are new values.

pull(
  server.about.socialValueStream({ key: 'title', dest: '%Z1Kk8Aj8Bnw5+t4d73kRPHMA0Nj2bL1bx7n7obZhVZg=.sha256' }),
  pull.drain(title => {
    console.log(title)
    // => 'Picnic Birthday Party'
    // (later) => 'Beach Party'
  })
)

If authorId is present, this provides a stream of values for a particular dest key, as asserted by that particular authorId

server.about.read({ reverse = false, limit, live, old, dest }) => source

A stream of all about messages that target dest

License

MIT