core-trpc imported AppRouter (type-only) from core-api, which depends on the features, which depend on core-trpc — a cycle that killed every turbo graph walk (lint/build/CI) and an illegal core -> core-composition boundary edge. The tRPC context is now router-agnostic (AnyTRPCRouter); useTRPC takes the router type as a generic and each feature exports a type-only app-slice (e.g. BlogAppSlice) mirroring its mount key, so UI hooks keep full procedure typing without touching the composition layer. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
21 lines
826 B
TypeScript
21 lines
826 B
TypeScript
"use client";
|
|
|
|
import { createTRPCContext } from "@trpc/tanstack-react-query";
|
|
import type { TRPCOptionsProxy } from "@trpc/tanstack-react-query";
|
|
import type { AnyTRPCRouter } from "@trpc/server";
|
|
|
|
// core-trpc must not depend on @repo/core-api (core → core-composition is an
|
|
// illegal boundary edge and creates a package cycle through the features).
|
|
// The runtime context is router-agnostic; consumers inject their router type
|
|
// as a generic: features pass their app-slice type (e.g. `BlogAppSlice`),
|
|
// apps may pass the full AppRouter.
|
|
const context = createTRPCContext<AnyTRPCRouter>();
|
|
|
|
export const TRPCProvider = context.TRPCProvider;
|
|
|
|
export function useTRPC<
|
|
TRouter extends AnyTRPCRouter = AnyTRPCRouter,
|
|
>(): TRPCOptionsProxy<TRouter> {
|
|
return context.useTRPC() as unknown as TRPCOptionsProxy<TRouter>;
|
|
}
|