@rpc-dart/trpc-adapter
v0.3.0
Published
tRPC v11 extraction adapter: route probe, inference harness, and Contract IR normalizer.
Maintainers
Readme
@rpc-dart/trpc-adapter
tRPC v11 router extraction adapter for rpc-dart. Inspects router definitions with the TypeScript compiler API and produces a normalized Contract IR.
Part of the rpc-dart monorepo.
Capabilities
- Compiler-level inspection: Uses
ts.TypeCheckerto inspect procedure inputs, outputs, and return types directly from TypeScript AST nodes without requiring a running server. - Input vs. output fidelity: Differentiates
z.input(wire format accepted from the client) fromz.output(wire format returned by the procedure), accurately handling Zod.transform(),.default(), and.coerce(). - Three-state PATCH detection: Identifies fields that are both optional and nullable, tagging them in the IR for three-state
RpcOpt<T>handling. - Enums and unions: Extracts string/numeric enums and maps discriminated unions with explicit discriminator keys into sealed type hierarchies.
Installation
npm install @rpc-dart/trpc-adapter
# or
pnpm add @rpc-dart/trpc-adapterUsage
import { extractContract } from '@rpc-dart/trpc-adapter';
const { ir, diagnostics } = await extractContract({
tsconfigPath: './tsconfig.json',
entryFile: './src/trpc/router.ts',
exportName: 'appRouter',
protocol: { kind: 'trpc', version: '11', transformer: 'superjson' },
policies: { unserializablePolicy: 'error' }, // 'warn-dynamic' | 'skip-procedure'
});Links
License
MIT © Aditya Jandu
