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

@phnq/message

v1.14.7

Published

Asynchronous, incremental messaging client and server

Downloads

847

Readme

@phnq/message

CircleCI

npm version

Message-based communication between agents:

  • request/response semantics
  • multiple async responses
  • symmetric full-duplex communication
  • transport abstraction

Usage

See tests for usage examples.

Protocol

Messages are passed as JSON. For example:

{
  "t": "send",
  "c": 1,
  "s": "2dbb50ed-2cd6-4fe3-af79-baf5cd643ce3",
  "p": { "greeting": "Hello" }
}
  • t - type, one of send, error, anomaly, response, multi, end
  • c - conversation, for grouping multiple messages together
  • s - source, unique id that identifies the agent sending the message
  • p - payload, the data being sent to another agent

Conversation

A conversation between agents consists of a single request by one agent, followed by zero or more responses from another agent. The request is always of type send, and the responses can be of various types depending on the situation:

Single Response

A single, non-error response will be of type response. For example:

Request:

{
  "t": "send",
  "c": 1,
  "s": "2dbb50ed-2cd6-4fe3-af79-baf5cd643ce3",
  "p": { "question": "How are you?" }
}

Response:

{
  "t": "response",
  "c": 1,
  "s": "13c5a54d-4e25-478b-a6be-295be08e8f01",
  "p": { "answer": "I'm fine." }
}

Multiple responses

Multiple responses will consist of payload-carrying messages with the type multi, followed by a single message of type end.

Request:

{
  "t": "send",
  "c": 2,
  "s": "2dbb50ed-2cd6-4fe3-af79-baf5cd643ce3",
  "p": {
    "question": "What are the names of your pets?"
  }
}

Responses:

{
  "t": "multi",
  "c": 2,
  "s": "13c5a54d-4e25-478b-a6be-295be08e8f01",
  "p": { "dog": "Fido" }
}
{
  "t": "multi",
  "c": 2,
  "s": "13c5a54d-4e25-478b-a6be-295be08e8f01",
  "p": { "cat": "Fritz" }
}
{
  "t": "multi",
  "c": 2,
  "s": "13c5a54d-4e25-478b-a6be-295be08e8f01",
  "p": { "fish": "Fred" }
}
{
  "t": "end",
  "c": 2,
  "s": "13c5a54d-4e25-478b-a6be-295be08e8f01",
  "p": {}
}

Error responses

Error responses are similar to the single response, but have the type error or anomaly. The difference between error and anomaly is only semantic; error is meant to depict something unexpected whereas anomaly is meant to depict something unusal.

Transport

The transport for transmitting the messages in the protocol is abstract. The abstraction is very simple. The TypeScript interface is the following:

export interface MessageTransport {
  send(message: Message): Promise<void>;
  onReceive(receive: (message: Message) => void): void;
}

With this simple abstraction, creating transport implementation is fairly trivial. There are two included:

  • WebSocketTransport - for transmitting the protocol over WebSockets
  • NATSTransport - for transmitting the protocol between services attached to a NATS pub/sub messaging system