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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@supercat1337/rpc

v1.0.5

Published

A simple RPC library for JavaScript

Readme

This library is a JavaScript implementation of a Remote Procedure Call (RPC) system.

The purpose of this library is to enable communication between different parts of an application, or between different applications, using a standardized RPC protocol. This allows developers to write code that can be executed remotely, and receive responses from the remote execution.

Installation

To install the library, run the following command:

npm install @supercat1337/rpc

Usage

import { 
  RPCRequestBody, 
  RPCErrorResponse, 
  rpcFetchData 
} from '@supercat1337/rpc';

async function rpcCall() {
  let requestMessage = new RPCRequestBody(
    "method", // The name of the method to be invoked
    { foo: "bar" }, // The parameters for the method
    "request_id" // The optional identifier for the request
  );

  let rpcResponse = await rpcFetchData("http://localhost:8545", { // The URL of the RPC server
    method: "POST", // The HTTP method
    body: requestMessage.toFormData(), // The body of the request
  });

  if (rpcResponse instanceof RPCErrorResponse) { // Check if the response is an error
    console.error(rpcResponse.error.message);
  } else {
    console.log(rpcResponse.result);
  }
}

rpcCall();

The library consists of the following classes and functions:

  • extractRPCResponse(object, response_id = null, notify = true) - This function takes a JSON response object and extracts a response message from it. It checks the response type (error, data, or paged data) and creates a corresponding response message object (RPCErrorResponse, RPCDataResponse, or RPCPagedResponse). If notification is enabled, it notifies the response event handler with the extracted response message. The function returns the extracted response message.

  • rpcFetchData(input, options, id = null, notify = true) - This function fetches data using the RPC protocol and returns a response message. This function acts as a wrapper around the rpcFetch function.

  • rpcFetchPageData(input, options, id = null, notify = true) - This function fetches paged data using the RPC protocol and returns a response message. This function acts as a wrapper around the rpcFetch function.

  • RPCRequestBody class: This class is used to create RPC requests.

  • RPCDataResponse class: This class is used to create RPC responses.

  • RPCErrorResponse class: This class is used to create RPC error responses.

  • RPCPagedResponse class: This class is used to create RPC paged responses.

  • responseEventHandler: This service is used to handle RPC responses and events.

ResponseEventHandler Service

The ResponseEventHandler Service acts as a central hub for response events, allowing different components to listen for and react to specific responses without having to know about each other's implementation details.

Components can subscribe to specific response events using the on method, providing a callback function that will be executed when the response is received. When a response is received, the responseEventHandler instance can notify all subscribed components by emitting the response event, and the subscribed components can react accordingly.

The responseEventHandler service is designed to decouple the components that send and receive responses, making it easier to manage complex workflows and interactions between different parts of the application.

The responseEventHandler service is used to handle responses from remote procedure calls (RPCs), given the presence of RPC-related constants and classes in the surrounding code.

Usage

import {
  RPCDataResponse,
  RPCErrorResponse,
  RPCRequestBody,
  responseEventHandler,
  rpcFetchData,
} from '@supercat1337/rpc';

async function rpcCall() {
  let requestMessage = new RPCRequestBody(
    "method", // The name of the method to be invoked
    { foo: "bar" }, // The parameters for the method
    "request_id" // The optional identifier for the request
  );

  let rpcResponse = await rpcFetchData("http://localhost:8545", { // The URL of the RPC server
    method: "POST", // The HTTP method to use
    body: requestMessage.toFormData(), // The FormData object representing the RPCRequestBody
  });

  return rpcResponse;
}

responseEventHandler.on( // Subscribe to the response event
  "request_id", // The ID of the response
  (
  /** @type {RPCDataResponse<{foo: string, bar: number}>|RPCErrorResponse} */ rpcResponse // The response message
  ) => {
    if (rpcResponse instanceof RPCErrorResponse) { // Check if the response is an error
      console.error(rpcResponse.error.message);
    } else {
      console.log(rpcResponse.result);
    }
  }
);

rpcCall();