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

effect-trpc

v1.2.3

Published

End-to-end typesafe APIs with Effect

Readme

effect-trpc

End-to-end typesafe APIs with Effect.

Built on Effect RPC patterns + Effect Atom for reactive state.

Features

  • Type-safe procedures — Query, Mutation, Stream
  • Router composition — Nested routes with path-based types
  • Middleware — Authentication, authorization, logging
  • Transports — HTTP, Loopback (testing)
  • Reactivity — Path-based cache invalidation
  • React hooks — Built on @effect-atom/atom-react
  • SSR support — Dehydration/hydration utilities

Installation

npm install effect-trpc effect @effect/schema

Quick Start

1. Define your router

import { Procedure, Router } from "effect-trpc"
import { Schema } from "effect"

// Define schemas
class User extends Schema.Class<User>("User")({
  id: Schema.String,
  name: Schema.String,
  email: Schema.String,
}) {}

class CreateUserInput extends Schema.Class<CreateUserInput>("CreateUserInput")({
  name: Schema.String,
  email: Schema.String,
}) {}

// Define router
const appRouter = Router.make("@api", {
  users: {
    list: Procedure.query({ success: Schema.Array(User) }),
    get: Procedure.query({
      payload: Schema.Struct({ id: Schema.String }),
      success: User,
    }),
    create: Procedure.mutation({
      payload: CreateUserInput,
      success: User,
      invalidates: ["users"], // Auto-invalidate queries
    }),
  },
  health: Procedure.query({ success: Schema.String }),
})

export type AppRouter = typeof appRouter

2. Create server handlers

import { Server } from "effect-trpc"
import { Effect } from "effect"

const handlers = {
  users: {
    list: () => Effect.succeed(users),
    get: ({ id }) => Effect.succeed(users.find(u => u.id === id)),
    create: (input) => Effect.succeed(createUser(input)),
  },
  health: () => Effect.succeed("OK"),
}

const server = Server.make(appRouter, handlers)

// For Next.js App Router
export const POST = Server.toFetchHandler(server, AppLive)

3. Use in React

import { Client, Transport } from "effect-trpc"

const api = Client.make(appRouter)

function App() {
  return (
    <api.Provider layer={Transport.http("/api")}>
      <UserList />
    </api.Provider>
  )
}

function UserList() {
  const { data, isLoading, refetch } = api.users.list.useQuery()
  
  if (isLoading) return <div>Loading...</div>
  
  return (
    <ul>
      {data?.map(user => (
        <li key={user.id}>{user.name}</li>
      ))}
    </ul>
  )
}

4. Vanilla JS (no React)

import { Client, Transport, Effect } from "effect-trpc"

// Create bound client with transport
const api = Client.make(appRouter).provide(Transport.http("/api"))

// Run queries
const users = await api.users.list.runPromise()
const user = await api.users.get.runPromise({ id: "1" })

// Run mutations (auto-invalidates "users" queries)
const newUser = await api.users.create.runPromise({
  name: "Alice",
  email: "[email protected]",
})

Middleware

import { Middleware, Server } from "effect-trpc"
import { Context, Effect } from "effect"

// Define what middleware provides
class CurrentUser extends Context.Tag("CurrentUser")<CurrentUser, User>() {}

// Define middleware tag
class AuthMiddleware extends Middleware.Tag<AuthMiddleware>()("AuthMiddleware", {
  provides: CurrentUser,
  failure: UnauthorizedError,
}) {}

// Implement middleware
const AuthMiddlewareLive = Middleware.implement(AuthMiddleware, (request) =>
  Effect.gen(function* () {
    const token = request.headers.get("authorization")
    if (!token) return yield* Effect.fail(new UnauthorizedError({}))
    return yield* verifyToken(token)
  })
)

// Apply to server
const secureServer = server.pipe(Server.middleware(AuthMiddleware))

Path-Based Invalidation

// Mutation with invalidation
const createUser = Procedure.mutation({
  payload: CreateUserInput,
  success: User,
  invalidates: ["users"], // Invalidates users.list, users.get, etc.
})

// Hierarchical: invalidating "users" invalidates all descendants
// - users/list
// - users/get
// - users/permissions/edit

API Reference

Modules

| Module | Description | |--------|-------------| | Procedure | Define queries, mutations, streams | | Router | Compose procedures into a router | | Server | Handle requests, apply middleware | | Client | Type-safe client with React hooks | | Transport | HTTP, Loopback, Mock transports | | Middleware | Cross-cutting concerns | | Reactivity | Cache invalidation | | SSR | Server-side rendering utilities |

Type Helpers

import type { 
  InferProcedurePayload,
  InferProcedureSuccess,
  InferProcedureError,
  InferRouterPaths,
  InferRouterProcedure,
} from "effect-trpc"

type Paths = InferRouterPaths<AppRouter>
// "users.list" | "users.get" | "users.create" | "health"

type UserPayload = InferProcedurePayload<typeof appRouter.users.get>
// { id: string }

Status

  • ✅ Core RPC (Procedure, Router, Server)
  • ✅ HTTP Transport
  • ✅ Request Batching
  • ✅ Middleware
  • ✅ Path-based Reactivity
  • ✅ React Integration
  • ✅ SSR utilities
  • 🚧 WebSocket Transport (planned)

License

MIT