github middleapi/orpc untagged-8ff61c36561887e20161
v2.0.0-beta.55

pre-releaseone hour ago

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, and middlewareGen only with ORPCError. Use Effect.die / Effect.orDie for anything else. #2591

    handlerGen(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. #1964

    import { 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. #2579

    import { createRouterFromClient } from '@orpc/server'
    
    const router = createRouterFromClient(contract, client)
    const handler = new RPCHandler(router)
  • experimental_ORPCExceptionFilter for NestJS sends errors thrown before @Implement, like from guards or body parsing, as oRPC errors. #2581

    import { experimental_ORPCExceptionFilter as ORPCExceptionFilter } from '@orpc/nest'
    
    @Module({
      providers: [{ provide: APP_FILTER, useClass: ORPCExceptionFilter }],
    })
    export class AppModule {}
  • catchDefinedORPCErrorCode and catchDefinedORPCErrorCodes catch only declared errors, so error.data keeps its type. #2590

    import { catchDefinedORPCErrorCode } from '@orpc/effect'
    
    client.getUser({ id }).pipe(
      catchDefinedORPCErrorCode('NOT_FOUND', error => Effect.succeed(error.data.id)), // string
    )
  • Base64 strings with a contentMediaType stay in JSON bodies instead of being treated as files in OpenAPI. #2580


   🚀 Features

   🐞 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)
    View changes on GitHub

Don't miss a new orpc release

NewReleases is sending notifications on new releases.