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

@stagas/rpc

v1.0.0

Published

Typed RPC for MessagePort-like transports.

Readme

@stagas/rpc

Typed RPC for MessagePort-like transports.

@stagas/rpc turns a bidirectional message channel into a promise-based remote API. Pass it a port and a local API object, then call methods on the returned proxy as if they were local async functions.

Features

  • Typed remote method calls through a proxy API.
  • Works with Worker, MessagePort, and other postMessage-compatible ports.
  • Supports bidirectional RPC by giving each side its own local API.
  • Automatically transfers common transferable values such as MessagePort and OffscreenCanvas.
  • Allows custom transferable constructors for application-specific values.

Install

npm install @stagas/rpc
bun add @stagas/rpc

Usage

Define the API exposed by the worker:

// worker.ts
import { rpc } from '@stagas/rpc'

const api = {
  async add(a: number, b: number) {
    return a + b
  },
}

rpc(self, api)

Create a typed client from the main thread:

// main.ts
import { rpc } from '@stagas/rpc'

type WorkerApi = {
  add(a: number, b: number): Promise<number>
}

const worker = new Worker(new URL('./worker.ts', import.meta.url), {
  type: 'module',
})

const remote = rpc<WorkerApi>(worker)

const total = await remote.add(2, 3)

You can also call methods by name:

const total = await remote('add', 2, 3)

Bidirectional RPC

Both sides can expose methods. The same rpc call accepts a local API object and returns a proxy for the remote API.

type ClientApi = {
  notify(message: string): Promise<void>
}

type WorkerApi = {
  start(): Promise<void>
}

const clientApi: ClientApi = {
  async notify(message) {
    console.log(message)
  },
}

const worker = new Worker(new URL('./worker.ts', import.meta.url), {
  type: 'module',
})

const remote = rpc<WorkerApi>(worker, clientApi)

await remote.start()

Transferables

@stagas/rpc detects transferable values in call arguments and return values. By default it transfers MessagePort and OffscreenCanvas when they are available in the current runtime.

Pass custom constructors as the third argument when your transport should transfer additional value types:

const remote = rpc<WorkerApi>(worker, {}, [
  MessagePort,
  OffscreenCanvas,
])

Transferable values may be passed directly or as properties of a plain object.

API

rpc<TRemote>(port, api?, transferables?)

Creates an RPC peer on top of a MessagePort-like object.

port

An object with onmessage, onmessageerror, and postMessage. Browser workers, message ports, and compatible transports are supported.

api

An object whose function properties are exposed to the remote peer. Incoming calls reject when the requested method does not exist or is not a function.

transferables

An array of constructors used to detect values that should be sent through the structured clone transfer list.

Returns

A callable proxy that supports both property access and direct method-name calls:

await remote.someMethod(arg)
await remote('someMethod', arg)

TypeScript

Declare the remote API as a method map where every method returns a promise.

type RemoteApi = {
  resize(width: number, height: number): Promise<void>
  snapshot(): Promise<ImageBitmap>
}

const remote = rpc<RemoteApi>(port)

License

MIT