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

swim-proto-js

v0.4.2

Published

Swim Protocol JavaScript Implementation

Downloads

9

Readme

Swim Protocol JavaScript Implementation

JavaScript Library

The Swim protocol library can be used in any standard JavaScript environment. Use npm to incorporate the library into Node.js projects.

npm install --save swim-proto-js
var proto = require('swim-proto-js');

var envelope = proto.parse('@event(node: "house#kitchen", lane: "light/on")');
proto.stringify(envelope);

Protocol Envelopes

The Swim protocol defines a set of RECON datatypes used for URI-linked multiplexed structural messaging.

@event

Send an event message to a node on some lane, or receive an event message that propagated through a linked node on a subscribed lane. node_uri and lane_uri always refer to origin node and lane to which the event was published. link_uris enumerates all links the event passed through prior to reaching the receiver.

<< @event([node:] <node_uri>, [lane:] <lane_uri>[, via: <link_uris>]) <body>

Examples

<< @event(node: "swim://iot.example.com/L01FE", lane: "light/off", via: "house#kitchen/light) {
  time: @date("2015-02-03T07:53:31-0800")
}

<< @event(node: "swim://iot.example.com/SD02FD", lane: "alarm/smoke", via: "house#garage/smoke_detector") {
  time: @data("2015-02-03T11:17:12-0800")
  concentration: 330 @ppm
  duration: 10 @seconds
}

@command

Send a command message to a node on some lane, or receive a command message that propagated through a linked node on a subscribed lane. node_uri and lane_uri always refer to origin node and lane to which the command was published. link_uris enumerates all links the command passed through prior to reaching the receiver.

<< @command([node:] <node_uri>, [lane:] <lane_uri>[, via: <link_uris>]) <body>

Examples

<< @command(node: "house#kitchen", lane: "light/on")

<< @command(node: "swim://town.example.com/fire_dept", lane: "alarm/silence", via: "house") {
  reason: "homeowner reported false alarm"
}

@sync

Request a replay of events that have propagated through a node on some lane. The receiver should respond with the minimum set of events necessary to reconstruct the receiver's current state, as it pertains to the requested message lane.

A @sync request establishes a corresponding link, if one doesn't already exist.

>> @sync([node:] <node_uri>, [lane:] <lane_uri>[, prio: <priority>])
<< @synced([node:] <node_uri>, [lane:] <lane_uri>)

Examples

>> @sync(node: "house", lane: "light/level", prio: 0.5)
<< @event(node: "house#kitchen", lane: "light/level") { level: 100 }
<< @event(node: "house#hallway", lane: "light/level") { level: 0 }
<< @synced(node: "house", lane: "light/level")

@link

Subscribe to messages that flow through some node on some lane.

>> @link([node:] <node_uri>, [lane:] <lane_uri>[, prio: <priority>])
<< @linked([node:] <node_uri>, [lane:] <lane_uri>[, prio: <priority>])

Examples

>> @link("house#kitchen", "light")
<< @linked(node: "house#kitchen", lane: "light")

>> @link(node: "house", lane: "alarm", prio: 0.5)
<< @linked(node: "house", lane: "alarm", prio: 0.5)

@unlink

Remove an existing message subscription identified by a (node_uri, lane_uri) pair.

>> @unlink([node:] <node_uri>, [lane:] <lane_uri>)
<< @unlinked([node:] <node_uri>, [lane:] <lane_uri>)

@auth

Authorizes the connection with credentials contained in <body>.

Examples

>> @auth <body>
<< @authed <body>

@deauth

De-authorizes the connection.

Examples

>> @deauth <body>
<< @deauthed <body>