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

secret-stack-decorators

v1.1.0

Published

OOP decorators to write secret-stack plugins

Downloads

244

Readme

secret-stack-decorators

TypeScript or Babel decorators that make it possible to write secret-stack plugins in OOP style

Usage

npm install --save secret-stack-decorators

Only supports secret-stack >=6.2.0

In your TypeScript or Babel codebase, import plugin and muxrpc:

import {plugin, muxrpc} from 'secret-stack-decorators';

@plugin('1.0.0' /* version */)
class myplugin /* name */ {
  constructor(ssb, config) {
    /* init */
  }

  // This method will not show in the resulting plugin object
  privateMethod(x, y) {
    // ...
  }

  @muxrpc('sync') /* manifest: `shout: 'sync'` */
  shout = messsage => {
    // ...
  }

  @muxrpc('duplex', {anonymous: 'allow'}) /* manifest and permissions */
  communicate() {
    // ...
  }
}

module.exports = myplugin;

Example

Before:

var plugin = {
  name: 'ebt',
  version: '1.0.0',
  manifest: {
    replicate: 'duplex',
    request: 'sync',
    block: 'sync',
    peerStatus: 'sync'
  },
  permissions: {
    anonymous: {allow: ['replicate']}
  },
  init: function (sbot, config) {
    // INITIALIZATION CODE

    return {
      replicate: function (opts) { /* ... */ },
      request: function (id, other) { /* ... */ },
      block: function (id) { /* ... */ },
      peerStatus: function (id) { /* ... */ },
    }
  }
}

After:

@plugin('1.0.0')
class ebt {
  constructor(sbot, config) {
    // INITIALIZATION CODE
  }

  @muxrpc('duplex', {anonymous: 'allow'})
  replicate(opts) { /* ... */ }

  @muxrpc('sync')
  request(id, other) { /* ... */ }

  @muxrpc('sync')
  block(id) { /* ... */ }

  @muxrpc('sync')
  peerStatus(id) { /* ... */ }
}

API

@plugin(version: string)

This decorator should be placed on a class that is meant to be a secret-stack plugin. The version argument should be a string expressing a SemVer version.

Important: the name of the class is used as a string to register the plugin. class foo will be transformed to api.foo. This is why the class's name is usually lowercase.

@muxrpc(manifestType: string, permission?: object)

The manifestType argument is a string, should have the value 'sync' or 'async' or 'source' or 'sink' or 'duplex'. The optional permission object should have the shape {role: 'allow' | 'deny'}, i.e., the object's keys are names of roles (such as anonymous or master, etc), and the value can be either the string 'allow' or the string 'deny'.

License

MIT