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

picorpc

v1.1.2

Published

A tiny RPC library and spec, inspired by JSON-RPC 2.0 and tRPC.

Downloads

30

Readme

PicoRPC

A tiny RPC library and spec, inspired by JSON-RPC 2.0 and tRPC.

Install

npm install --save picorpc

Usage

import {createAbstractClient, createAbstractServer} from 'picorpc';
import {createMemoryClient, createMemoryServer} from 'picorpc';
import {createHttpClient, createHttpServer} from 'picorpc';

// Custom map of procedures to expose to the client

const Procedures = {
  ctx () { // This procedure reads something from the context, which will be attached to "this"
    return this.value;
  },
  sum ( a, b ) { // This procedure is a simple pure function that doesn't use the context
    return a + b;
  },
  throw () { // This procedure throws, with a custom error code and data value
    const error = new Error ( 'Some custom error' );
    error.code = 1;
    error.data = 'Some data';
    throw error;
  }
};

// Create an in-memory client/server
// An in-memory server behind a proper HTTP server is the recommended way to expose procedures via an API
// An in-memory client is mostly useful for testing

const server = createMemoryServer ({
  procedures: Procedures
});

const client = createMemoryClient ({
  server, // The in-memory server to pass requests to
  context: () => ({ // Custom, optional, context object, which will be attached to every request automatically
    value: 123
  })
});

await client.sum ( 1, 2 ); // => 3
await client.ctx (); // => 123
await client.throw (); // => This will throw

// Create an HTTP client/server
// The HTTP server is intended for simple internal inter-process communication
// The HTTP client makes request with the fetch API, so it works everywhere

const client = createHttpClient ({
  context: () => ({ // Custom, optional, context object, which will be attached to every request automatically
    value: 123
  }),
  serializer: JSON.stringify, // Custom, optional, serializer
  deserializer: JSON.parse, // Custom, optional, deserializer
  url: 'http://localhost:6000' // Required endpoint URL
});

const server = createHttpServer ({
  serializer: JSON.stringify, // Custom, optional, serializer
  deserializer: JSON.parse, // Custom, optional, deserializer
  port: 6000, // The port to start listening at
  procedures: Procedures
});

await client.sum ( 1, 2 ); // => 3
await client.ctx (); // => 123
await client.throw (); // => This will throw

server.close (); // Close the server, stopping listening

// Create an abstract server, to use your own transport protocol

const client = createAbstractClient ({
  handler: request => {
    //TODO: Send the request somewhere and read the result back
  }
});

const client = createAbstractServer ({
  procedures: Procedures,
  handler: response => {
    //TODO: Do something with the response object, optionally
  }
});

License

MIT © Fabio Spampinato