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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@agen/rpc

v0.1.6

Published

Async Generator utilities

Readme

@agen/rpc

Introduction

This package contains an implementation of Remote Procedure Calls on top of various transport layers such as socket.io, peerjs.com, websockets, WebRTC, HTTP2/REST etc.

Features:

  • Bi-directional asynchronious data streams
  • Simple service implementation based on async generators
  • Service definition using Protobuf schemas
  • Optional Protobuf-based binary serialization/deserialization
  • Automatic transparent creation of client and server stubs
  • Easy pluggable transport layer - 3 methods to implement: 'on', 'off', 'emit'

See https://observablehq.com/d/15e7a8cb4a361293

Remote procedure calls can be defines like the following sequence of operations:

-> [clientStub] --serializing--> [transport] -deserializing-> [serverStub] --+
                                                                             |
                                                                  [service execution]
                                                                             |
<- [clientStub] <-deserializing- [transport] <--serializing-- [serverStub] <-+

All client stubs, server stubs, all messages serialization/deserialization etc are performed by the library transparently for the user.

This library requires the following parameters:

  • Schema defining services and data structures
  • Service implementation - a simple JS object with async methods
  • Transport layer - like socket.io, peerjs.com, websockets, HTTP2/REST etc.

Schema

Schema for all service methods should have the following structure:

  • packageName - name of the package containing individual services
  • serviceName - name of the service regrouping multiple methods
  • methodName - name of the callable method
  • requestType - type name of request objects
  • requestStream - this flag defines if the method request is an AsyncIterator or a simple object
  • responseType - type name for response objects
  • responseStream - if this method is an AsyncGenerator or it returns a single object

Protobuf schemas are parsed and transformed to this internal format. It is possible to manually create schemas objects. In this case protobuf schema parser is not required.

Service Implementation

Service implementation object should reflect the structure defined by the schema:

 packageName -> serviceName -> methodName

Example:

{
  "test.package" : {                                // Name of the package

    "MyService" : {                                 // Name of the service

      async* sayHello(input) {                      // Service method.
        for await (let { name } of input) {
          yield { message : `Hello ${name}!` }
        }
      }

    }

  }
}

Each service method should correspond to the following simple constraints:

  • It should accepts just one parameter: a single serializable request object or an AsyncIterator over serializable objects
  • It should return just one serializable object or it is an AsyncIterator over serializable results

Method descriptors allow to transform JavaScript methods to universal format based on the following table:

This approach allows to wrap all service methods with functions of this type:

async function*(iterator:AsyncIterator):AsyncIterator{ ... }

All service methods have to accept serializable objects (for simple calls) or an async iterator (for input streams). As a result the service methods should return a serializable object or an async iterator returning serializable objects.

Possible signatures of service methods:

// 1) input: single object; output: single object  (like REST methods)
async function( input : Object ) : Object { ... }

// 2) input: single object; output: stream of response objects
async function*( input : Object ) : AsyncIterator { ... }

// 3) input: stream of objects; output: single response object
async function( input : AsyncIterator ) : Object { ... }

// 4) input: stream of objects; output: stream of response objects
async function( input : AsyncIterator ) : AsyncIterator { ... }