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

pubway

v2.0.0

Published

A library that manages side-effects from publish/subscription connections

Downloads

376

Readme

pubway

Lets say you have four nodes in a system:

  • Client A
  • Client B
  • Server C
  • Database D

These four nodes go through these two scenarios:

  1. Client A sends a change request to Server C which applies the change to Database D and responds with the new data.
  2. Client B sends a change request to Server C which applies the change to Database D and responds with the new data.

Both scenarios end with each client missing the changed data the other made. There are two ways to combat this obstacle:

  • The Client periodically asks for the subset or set of data. (Polling)
  • The Client is told of the subset that changed. (Publish/Subscribe)

Assuming you've decided the latter option is the correct choice you now have the task of figuring out how you're going to publish/subscribe and the application layer protocol for handling these messages. For example, one problem you'll encounter is that messages can have a content limitation. Pusher for example has 10kB message limit. Since data can be variable in size I don't think it's a good idea to assume we can send the entire resource "up the wire".

I will leave the former problem up to the market (Pusher, Firebase, etc). The latter problem is something I can solve! Now that we've got the situation laid out here is what pubway.js does:

pubway.js is a SDK for publish/subscribe sockets or an application layer protocol for the messages. pubway.js is told the data stores your client has and how to initiate state changes. An example would be a server telling clients of an account changing it's name:

PATCH /resources/accounts/f26c1cb0-c7a1-44a7-8b72-2843568406bd/name

Seem similar? It matches the first line in an HTTP request! Here's the pattern broken down:

intent path
  • intent: One of PATCH or DELETE, where PATCH means "this resource has changed" and DELETE means "This resource no longer exists".
  • path: This is intended to be the path of a tree, but can be decoded as anything you want.

Here's what a redux-based pubway usage would look like:

import pusher from "pusher-js"
import pubway from "pubway"

import store from "./store"

pusher.listen("updates-channel", pubway(({intent, path}) => store.dispatch(changeResources(intent, path))))

You can also define multiple side-effects:

import pusher from "pusher-js"
import pubway from "pubway"

import store from "./store"

pusher.listen("updates-channel", pubway([
  ({intent, path}) => store.dispatch(changeResources(intent, path)),
  ({intent, path}) => window.update(intent, path)
]))

Okay, so what if path contains confidential information? Well we can still operate much the same way:

GET /jwt/e257e5f087ff1490b417412f7f3d49f74fbaad1b188f0e3588e70e0c9a49cc7a

And now here's what our adapter looks like:

import pusher from "pusher-js"
import pubway from "pubway"

import store from "./store"
import decode from "./decode"

pusher.listen("updates-channel", pubway(({intent, path}) => store.dispatch(changeEncryptedResources(intent, path))))