Documentation Index
Fetch the complete documentation index at: https://www.orionjs.com/llms.txt
Use this file to discover all available pages before exploring further.
Overview
@orion-js/trpc provides procedure helpers (queries, mutations, paginated queries), service decorators, and registerTRPCRoute to mount your router on Orion HTTP.
Install Dependencies
pnpm add @orion-js/trpc @trpc/server superjson
Server Setup
import {initTRPC} from '@trpc/server'
import {
defaultErrorFormatter,
registerTRPCRoute,
type TRPCContext,
} from '@orion-js/trpc'
import type {TRPCRouterRecord} from '@trpc/server'
import {deserialize as superjsonDeserialize, serialize as superjsonSerialize} from 'superjson'
const transformer = {
serialize: superjsonSerialize,
deserialize: superjsonDeserialize,
}
const t = initTRPC.context<TRPCContext>().create({
transformer,
errorFormatter: defaultErrorFormatter,
})
export function startTrpc<T extends TRPCRouterRecord>(procedures: T) {
const appRouter = t.router(procedures)
registerTRPCRoute({appRouter, path: '/trpc'})
return {router: appRouter}
}
Type Inference Requirement
To get native transformer inference on client types (so httpBatchLink({transformer}) is accepted), enable strictNullChecks:
{
"compilerOptions": {
"strictNullChecks": true
}
}
@orion-js/trpc exports defaultErrorFormatter which enriches tRPC error shapes with Orionjs-specific data (validation errors, user error codes, permission errors). Use it with your own initTRPC instance:
import {defaultErrorFormatter} from '@orion-js/trpc'
const t = initTRPC.create({
errorFormatter: defaultErrorFormatter,
})
You can also use mapErrorToTRPCError and getErrorData directly for custom error handling.
Server-Side Caller
Create a server-side caller for testing or internal use:
const {router} = startTrpc(procedures)
const caller = t.createCallerFactory(router)({viewer: null})
// Call procedures directly
const example = await caller.getExample({exampleId: '123'})