RPC
toTrpc(router) turns your routes into tRPC-style procedures. Same QueryPlan
source, typed end to end.
Generate procedures
Section titled “Generate procedures”import { toTrpc } from "@mountsqli/api";
const procedures = toTrpc(router);// → [{ path, resolver }] ready to mount on a tRPC routerHow it fits
Section titled “How it fits”graph TD R[Router + QueryPlans] --> REST[createRestHandler] R --> OAS[toOpenApi] R --> RPC[toTrpc]
One router, three transports. The plan is the contract; REST, OpenAPI, and RPC are different surfaces over it.
Real-world example
Section titled “Real-world example”const router = createRouter();router.get("/users", { plan: db.from(users)._plan });
export const appRouter = trpc.router({ users: trpc.procedure.query(() => { const [proc] = toTrpc(router).filter((p) => p.path === "users"); return proc.resolver(/* ctx */); }),});Best practices
Section titled “Best practices”- Keep one
Routeras the API source of truth. - Reuse the same plans across REST and RPC for consistency.
- Validate inputs with
ValidationShapebefore resolving.
Common mistakes
Section titled “Common mistakes”- Maintaining separate REST and RPC route definitions (drift) — derive both from one router.
Related
Section titled “Related”- Overview — the Router model.
- OpenAPI & Codegen — the REST spec sibling.
