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 🙏

© 2026 – Pkg Stats / Ryan Hefner

caf_pubsub

v0.4.2

Published

Cloud Assistants lib for a publish/subscribe bus

Readme

Caf.js

Co-design cloud assistants with your web app and IoT devices.

See https://www.cafjs.com

Library to Access a Publish/Subscribe Bus

Build Status

This repository contains a Caf.js library that implements a publish/subscribe bus using, for example, a Redis backend.

There are two types of channels:

  • A private channel name is prefixed by the CA name, i.e., <ca_name>-<whatever>, and only that CA can publish messages.

  • A forum channel has a name of the form forum-<whatever>, and anybody can publish to it. However, subscribers can filter publishers using method ACLs, since pubsub messages are always processed by invoking a CA method. This method is chosen by the subscriber.

Anybody can subscribe to a channel if they know its name, and we recommend to use hard to guess channel names to limit visibility.

The delivery guarantees depend on the pubsub backend service. Redis, for example, is best effort. However, when the plugin has committed to publish a message, it will retry after a CA or node.js process crash.

A pubsub service complements well a SharedMap (see {@link external:caf_sharing}). SharedMaps are silently updated, and this makes them very efficient when shared by many CAs. Messages generated by a pubsub service are processed by subscribed CAs and, for example, can trigger external actions. By combining them, we can get the right mix of silent updates vs external actions.

Caf.js discourages point-to-point communication between CAs. At the network infrastructure level, point-to-point becomes all-to-all very quickly, limiting the scalability of the system.

However, if you really need point-to-point, you can always use a private pubsub channel, or write a new plugin...

Instead, applications should expose higher-level communication patterns to improve scalability. These patterns can then be implemented efficiently with specialized services, such as SharedMap or pubsub. This approach is common for HPC applications that, for example, use MPI collective communication calls.

Hello World (see examples/helloworld)

The following example has a privileged CA, i.e., admin, that regularly publishes messages in a private channel. CAs with the same owner subscribe to this channel, and the handler function notifies clients using sessions (see {@link external:caf_session}).

exports.methods = {
    async __ca_init__() {
        this.state.counter = 0;
        this.$.pubsub.subscribe(mainChannel(this), '__ca_handle__');
        this.$.security.addRule(this.$.security.newSimpleRule(
            '__ca_handle__', this.$.security.SELF, ADMIN_CA
        ));
        return [];
    },
    async __ca_pulse__() {
        if (isAdmin(this)) {
            this.state.counter = this.state.counter + 1;
            this.$.pubsub.publish(mainChannel(this),
                                  'Counter: ' + this.state.counter);
        }
        return [];
    },
    async __ca_handle__(topic, msg, from) {
        this.$.log && this.$.log.debug('Got ' + msg);
        this.$.session.notify([msg]);
        return [];
    }
}

A couple of helper functions for naming:

const ADMIN_CA = 'admin';
const ADMIN_CHANNEL = 'myNews';
const isAdmin = function(self) {
    const name = self.__ca_getName__();
    return (caf.splitName(name)[1] === ADMIN_CA);
};
const mainChannel = function(self) {
    const name = self.__ca_getName__();
    return caf.joinName(caf.splitName(name)[0], ADMIN_CA, ADMIN_CHANNEL);
};

See the client code in examples/helloworld/client1.js

API

See {@link module:caf_pubsub/proxy_pubsub}

Configuration

framework.json

See {@link module:caf_pubsub/plug_pubsub}

ca.json

See {@link module:caf_pubsub/plug_ca_pubsub}