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

@openknot-ts/trpc-router

v0.0.6-preview

Published

Typed tRPC routers composed from OpenKnot Wire units.

Readme

@openknot-ts/trpc-router

Declares tRPC routers as Wire units, with exact router and client types, and supplies the default native tRPC instance. It has no HTTP host or adapter dependency: @openknot-ts/trpc-knot-server-handler and @openknot-ts/trpc-fastify serve the routers.

Usage

import { http } from "@openknot-ts/knot-http-node";
import { trpcHttp } from "@openknot-ts/trpc-knot-server-handler";
import { trpcRouter } from "@openknot-ts/trpc-router";
import type { Resolved } from "@openknot-ts/wire";
import { defineApplication, providePlugs } from "@openknot-ts/wire";

export const router = trpcRouter({
  requirements: { createRoleExposure },
  routes: ({ trpc, createRoleExposure }) => ({
    createRole: trpc.procedure.input(createRoleSchema).mutation(createRoleExposure),
  }),
});

export type AppRouter = Resolved<typeof router>;
export const transport = providePlugs([router]);

export const application = defineApplication({
  modules: [behavior, flow, io, channels, transport, http, trpcHttp],
});

The handler merges the routers the selected modules list. A router reached only as a dependency is not exposed. No routers, duplicate procedure paths or incompatible formatters fail at startup.

API

| Export | Description | | --- | --- | | trpcRouter({ requirements?, trpc?, routes }) | Declares a router. routes receives the native trpc object and the declared dependencies. | | trpcRouter.compose({ routers }) | Composes routers under named prefixes (client.roles.*). | | trpc | The default native instance: { isDev: false, errorFormatter: authenticationErrorFormatter } over TrpcAuthenticationContext, created per application. Rebind it with unit({ provides: trpc, ... }). | | trpcRootRouter | The merged root router that handlers serve. |

Flow inputs in routes

Inside routes, each required exposure is a native resolver, and a topic or broadcast's subscribe is one:

routes: ({ trpc, createRole, updateRole, logs }) => ({
  createRole: trpc.procedure.input(createRoleSchema).mutation(createRole),

  // The procedure says where a named guard input comes from.
  updateRole: trpc.procedure
    .input(updateRoleSchema)
    .mutation(({ input, ctx }) => updateRole({ input, ctx, access: ctx.token })),

  logs: trpc.procedure.subscription(logs.subscribe),
}),
  • A resolver forwards the input, named guard inputs and traceAttributes, takes the actor and propagation from the context, and returns the value or throws the error.
  • Cancelled and unavailable inputs reject with their tRPC codes; mapping authored errors stays with the application.
  • Queries and mutations follow the context's signal; subscriptions follow the resolver's own signal.
  • To transform a result, call the resolver: .query(async (options) => toDto(await getState(options))).
  • A guard named ctx, path or batchIndex fails at startup.

Outside routes the references are ordinary Flow invokers. Routers declared without trpcRouter() use invokeFlow.

Feature routers

export const api = trpcRouter.compose({ routers: { roles, logs } });
export type AppRouter = Resolved<typeof api>;
export const transport = providePlugs([api]);

Several flat routers can be typed with tRPC's TRPCMergeRouters<[Resolved<typeof roles>, Resolved<typeof logs>]>.

Custom instances

Different context, meta, formatter or transformer types use a typed reference:

const customTrpc = unit({ factory: () => initTRPC.context<CustomContext>().meta<CustomMeta>().create(nativeOptions) });

const router = trpcRouter({
  trpc: customTrpc,
  routes: ({ trpc }) => ({
    /* native procedures with CustomContext / CustomMeta inference */
  }),
});

Protect procedures with trpcAuthentication from @openknot-ts/trpc-context/wire, or @openknot-ts/auth0-authentication, through .use() on a common procedure.

Tests

pnpm --filter @openknot-ts/trpc-router test covers router types, composition and imports without a host.