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

@nodescript/protocomm

v1.1.0

Published

Bi-directional transport-agnostic JSON-based messaging

Downloads

272

Readme

Protocomm

Bi-directional transport-agnostic JSON-based messaging.

Status: experimental, subject to change.

Introduction

In software engineering communication protocols are defined as formal rules for transmitting the information. Modern systems tend to deal with application-level protocols such as HTTP which are already considered high level in the OSI stack. However, in practice the need often arises for implementing even more application- or domain-specific protocols on top of the existing ones.

One widely known example would be a typical RESTful API which is in fact a protocol between the application server providing the functionality and the frontend application using such functionality.

Protocols aren't cheap. Good protocols try to address a lot of concerns and have to deal with a fair amounts of trade-offs. This drives a lot of initiatives to further standardize the application protocols written on top of other application protocols (e.g. Swagger/OpenAPI, JSON-RPC, gRPC-over-HTTP, etc). Such initiatives oftentimes have different goals, limitations and implications.

This library is one such initiative with following key considerations:

  • It is designed for modern web applications written in TypeScript.
  • Such applications may consist of many different components "talking" to each other.
  • Such components may or may not exist in the same runtime/process/node. They may or may not have networking layer to communicate over.
  • Some example of communications:
    • frontend application talking to a backend via HTTP (i.e. your typical webapp)
    • frontend application sending requests to a backend via WebSocket and receiving the responses and events asynchronously
    • a web page sending and receiving messages to/from the isolated iframe
    • multiple processes communicating with each other using IPC
    • two different systems talking to each other via TCP
  • Protocols need to be transport-agnostic. The transport is abstracted as a readable/writeable streams. Protocomm will take care of serializing and deserializing the payloads.
  • Protocols should be fully typesafe on both sides of the communication. We rely on TypeScript to provide both Client and Handler with compile-time type safety guarantees.
  • Protocol messages and payload need to be validated in runtime. Runtime validation should fully correspond to compile-time validation.
  • Protocol messages should have a reasonable strategy for dealing with protocol evolution.
  • It should be possible to generate the documentation from the protocol definitions.

Protocomm is loosely based on JSON-RPC and is inspired by Chrome DevTools Protocol and Protobuf.

Concepts

  • Communication always happen between a Client and a Handler.

    Their roles in a particular communication are not equal: client is always an initiator, and the handler is typically expected to handle multiple clients (although this is not enforced in any way).

  • Protocol is an interface that both Client and Handler need to adhere to. It consists of one or more domains.

  • Domain is an interface that defines methods and events.

  • Each domain needs a corresponding Domain Definition — a static JSON object with metadata available in runtime. It describes the schema of methods and events and is used to automatically generate the client, validate the payloads, as well as for other meta purposes (such as documentation).

  • Protocol Index is a collection of Domain Definition objects, corresponding to a particular protocol.

A protocol is typically implemented as a standalone isomorphic package shared between both parties and contains type definitions, schema and domain definitions of all entities and DTOs used in communication. Such package is then used on the "backend" side to implement the necessary functionality and on the "consumer" side to generate the client.

Usage

Please refer to the tests setup for an example of fictional service. More examples are under construction.