Tip
oRPC v2 is close to stable. If you’ve tried the beta, tell us what was hard to migrate, which changes surprised you, and what you still need before upgrading. Join the v2 discussion.
Highlights
-
Breaking: Effectful handlers can only fail with errors declared in
.errors, andmiddlewareGenonly withORPCError. UseEffect.die/Effect.orDiefor anything else. #2591handlerGen(function* ({ input, errors }) { const user = yield* findUser(input.id).pipe( Effect.catchTag('UserNotFound', () => Effect.fail(errors.NOT_FOUND())), ) const posts = yield* Effect.tryPromise(() => db.posts.list(user.id)).pipe(Effect.orDie) return { user, posts } })
-
Breaking: The OpenTelemetry integration requires
@opentelemetry/api>=1.10.0,@opentelemetry/instrumentation>=0.302.0 and Node.js 22.15+. #2594 -
New
@orpc/experimental-cache: tag-based caching and revalidation for procedure output, with stale-while-revalidate, TanStack Query refetch by tag, and stores for memory, Redis, Upstash, Bun Redis, Vercel Runtime Cache and more. #1964import { cache, revalidate } from '@orpc/experimental-cache' const findPlanet = os .$context<CacheContext>() .input(z.object({ id: z.number() })) .use(cache({ tags: (_, input) => ['planets', `planet:${input.id}`], ttl: 60_000, swr: 300_000, })) .handler(({ input }) => db.planets.find(input.id)) const updatePlanet = os .$context<CacheContext>() .input(z.object({ id: z.number(), name: z.string() })) .use(revalidate({ tags: (_, input) => [`planet:${input.id}`] })) .handler(({ input }) => db.planets.update(input))
-
createRouterFromClient(contract, client)turns a client into a router, so it can be served by any handler or exposed as MCP tools. #2579import { createRouterFromClient } from '@orpc/server' const router = createRouterFromClient(contract, client) const handler = new RPCHandler(router)
-
experimental_ORPCExceptionFilterfor NestJS sends errors thrown before@Implement, like from guards or body parsing, as oRPC errors. #2581import { experimental_ORPCExceptionFilter as ORPCExceptionFilter } from '@orpc/nest' @Module({ providers: [{ provide: APP_FILTER, useClass: ORPCExceptionFilter }], }) export class AppModule {}
-
catchDefinedORPCErrorCodeandcatchDefinedORPCErrorCodescatch only declared errors, soerror.datakeeps its type. #2590import { catchDefinedORPCErrorCode } from '@orpc/effect' client.getUser({ id }).pipe( catchDefinedORPCErrorCode('NOT_FOUND', error => Effect.succeed(error.data.id)), // string )
-
Base64 strings with a
contentMediaTypestay in JSON bodies instead of being treated as files in OpenAPI. #2580
🚀 Features
- cache: Add tag-based caching and revalidation helpers - by @dinwwwh in #1964 (ce753)
- effect: Add catchDefinedORPCErrorCode and catchDefinedORPCErrorCodes - by @dinwwwh in #2590 (b596a)
- nest: Add experimental_ORPCExceptionFilter - by @dinwwwh in #2581 (56bf8)
- server: Add createRouterFromClient - by @dinwwwh in #2579 (21c80)
🐞 Bug Fixes
- effect: Restrict failures in effectful handlers and middleware - by @dinwwwh in #2591 (86967)
- json-schema, openapi: Don't treat base64 strings with a contentMediaType as files - by @dinwwwh in #2580 (29469)
- opentelemetry: Require @opentelemetry/api >=1.10.0 and instrumentation >=0.302.0 - by @dinwwwh in #2594 (8cbbb)