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

@casfa/port-rpc

v0.1.0

Published

Type-safe request/response RPC over MessagePort with timeout, Transferable auto-extraction, and namespace proxying

Readme

@casfa/port-rpc

Type-safe request/response RPC over MessagePort with timeout, automatic Transferable extraction, and namespace proxying.

Designed for Main Thread ↔ Service Worker communication but works with any MessagePort-based channel (Worker, iframe, etc.).

Features

  • Request/response matching — auto-incrementing id with pending-map resolution
  • Timeout — configurable per-client, defaults to 30 s
  • Transferable auto-extractionArrayBuffer / Uint8Array args are automatically transferred (zero-copy)
  • Namespace proxyProxy-based method routing for typed remote APIs
  • Handler utilitiesrespond(), respondError(), dispatchNamespaceRPC() for the receiver side
  • Zero dependencies — pure TypeScript, no runtime deps

Usage

Caller side (main thread)

import { createRPC, createNamespaceProxy } from "@casfa/port-rpc";

const { port1, port2 } = new MessageChannel();
port1.start();

// Send port2 to the service worker
sw.postMessage({ type: "connect" }, [port2]);

const rpc = createRPC(port1, { timeoutMs: 10_000 });

// Type-safe namespace proxy
type MathService = {
  add(a: number, b: number): Promise<number>;
  multiply(a: number, b: number): Promise<number>;
};

const math = createNamespaceProxy<MathService>(rpc, "math");
const sum = await math.add(1, 2); // → 3

Handler side (service worker)

import { respond, respondError, dispatchNamespaceRPC } from "@casfa/port-rpc";

const mathService = {
  add: (a: number, b: number) => a + b,
  multiply: (a: number, b: number) => a * b,
};

port.onmessage = async (e) => {
  const msg = e.data;
  switch (msg.type) {
    case "rpc":
      await dispatchNamespaceRPC({
        target: mathService,
        method: msg.method,
        args: msg.args,
        port,
        id: msg.id,
      });
      break;
    case "ping":
      respond(port, msg.id, "pong");
      break;
  }
};

API

createRPC<TMsg>(port, options?)

Create an RPC client. Returns RPCFn<TMsg> — a function that sends a message and returns a Promise<unknown>.

createNamespaceProxy<T>(rpc, namespace)

Create a Proxy that routes method calls through RPC as { type: "rpc", target, method, args } messages.

respond(port, id, result, transfers?)

Send a successful RPC response.

respondError(port, id, code, err)

Send an error RPC response.

dispatchNamespaceRPC(opts)

Invoke target[method](...args), await the result, and send the response. Auto-extracts Transferable buffers from { ok: true, data: Uint8Array } result patterns.

extractTransferables(args)

Extract ArrayBuffer / Uint8Array.buffer from an args array.

Testing

bun test src/