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 🙏

© 2025 – Pkg Stats / Ryan Hefner

tinytrpc

v0.1.37

Published

Typesafe discord interactions

Downloads

32

Readme

TinyTrpc

Typed discord UIs. Command-click to a component's handler.

It's this but cooler

// creation
new ButtonBuilder({
   customId: buttonName + "-" + pageNumber,
});

// handling
const [buttonName, pageNumber] = interaction.customId.split("-")

Full demo

init.

import { flare } from "tinytrpc";

// Simple "middleware"
const adminOnly = (interaction: Interaction) => interaction.memberPermissions?.has("Administrator") ?? false;

// Optional context for handler
type Context = ButtonInteraction<"raw" | "cached">;
// optional but convenient shortcut for combining routers
const lens = flare<Context>();

Basic router with context + middleware checkpoint

const adminPageScope = lens
   // Never miss a permissions check. Useful in nested routers.
   .lock(adminOnly)
   // Your methods
   .scope({
      // TS requires first param to be context
      async delete(interaction: Context, page: number) {
         // "page" comes from component's customId payload
         await deletePage(interaction.guildId, page);
      },
   });

Nesting routers

const { router, handler } = lens.scope({
   page: {
      admin: adminPageScope, // (uses "_internal" prop for nesting)

      // More methods, any shape
      async open(interaction: Context, page: number) {
         const pageData = await getPageData(interaction.guildId, page);

         // Example use
         const buttonRow = new ActionRowBuilder<ButtonBuilder>();
         buttonRow.addComponents(
            new ButtonBuilder({
               label: "next",
               // generate customId with next page as payload
               // context is provided later by handler
               customId: router.page.open(page + 1),
            }),
            new ButtonBuilder({
               label: "delete",
               // You can go to handler's definition via command-click!
               customId: router.page.admin.delete(page),
            }),
         );

         await interaction.update({ components: [buttonRow] });
      },
   },
});

Generic interaction handler

async function resolveAnyInteraction(interaction: Interaction) {
   if (!interaction.isButton()) return;
   if (!interaction.inGuild()) return;
   // handler second param is conditionally required if you use context
   await handler(interaction.customId, interaction);
}

Disclaimer

Keep component payloads tiny, don't stuff it.

  • Discord caps customId length at 100 characters
    • 10 characters are used for matching the method ID
  • You payload is JSON.stringified
    • If your payload doesn't fit, string compression is attempted
  • No runtime type validation. Not zod.
    • fn.length (num of JSON.parsed params) must match method

Why does this exist?

  • Why not store interaction data in a database?
  • Why not just do
// creating component
db.set(customId, payload)
// handling component interaction
db.get(customId)

Because you might

  1. Want structure + intelisense for handling complex interactions
  2. Want to persist data within discord
  3. Have a value too tiny for a db. Why waste a roundtrip?