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

rpc-with-types

v4.0.3

Published

TypeScript Remote-procedure-call Framework

Downloads

11

Readme

rpc-with-types

An experimental library that implements a bidirectional Method+Event protocol for your homogenous Typescript code.

Here is a short example how it works:

// { server, client }

// Define a Method and an Event
const FindUser = Method.new("GetUser", t.string, t.type({ name: t.string, age: t.number }));
const NewUser = Event.new("NewUser", t.string);

// Implement a Method on the Server
server.onMethod(FindUser, name => { name: "Alice", age: 80000 });
server.onEvent(NewUser, name => console.log(`New user: ${name}`));

// Call it from the Client
const { name, age } = await (new FindUser("Alice").with(client));
new NewUser("Hashelq").with(client)

What is interesting, that everything you have just seen can also be used backwards!

client.onMethod(FindUser, name => { name: "???", age: -1 });
client.onEvent(NewUser, name => console.log(`New user: ${name}`));

const { name, age } = await (new FindUser("Alice").withs(server, server.clients[0]));
new NewUser("HashElq").withs(client, server.clients[0]);

Too complicated

src/tests.ts - is a great source of finding ways to create a websocket RPC environment.

How it works

A human readable JSON text is sent between the server and client sides.

Default protocol to use is WS. In fact you can implement any protocol you want to use with the lib.

Compatibility

rpc-with-types is tested against:

  • nodejs 20.11.0
  • bun 1.0.26

Sessions

interface Session {
  lastMessage: string
};

const server = new Server<Session>({ sessionInit: () => { lastMessage: "" } /* other params */});

server.onEvent(..., (message: string, { _socket, session } => {
  session.lastMessage = message;
}))

Links to understand how to deal with it