refactor(core-trpc): make the tRPC context router-agnostic
Ports the type-safety/ergonomics half of the upstream cycle-break: core-trpc no longer imports AppRouter from @repo/core-api (an illegal core -> core-composition boundary edge). The runtime context and both providers are now AnyTRPCRouter-generic; consumers inject their router type via useTRPC<TRouter>(). The clean-slate tree is already cycle-free (no kept feature consumes core-trpc), so this is purely the architecture/boundary improvement. The per-feature app-slice types the upstream commit added for the demo features are intentionally skipped: no kept feature consumes useTRPC yet. Also covers the router-agnostic useTRPC delegation: the refactor turned useTRPC into a wrapper function whose body was unexercised, dropping client.ts below the coverage floor — client.test.ts stubs the context factory and asserts the delegation, restoring client.ts to 100%. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016j8z4VHjedXDTjEDNg7qHK
This commit is contained in:
@@ -1,4 +1,15 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { describe, it, expect, vi } from "vitest";
|
||||
|
||||
// Stub the tRPC context factory so useTRPC() can run outside a React render:
|
||||
// the real context.useTRPC() requires a mounted TRPCProvider. The stubbed
|
||||
// proxy lets us exercise the router-agnostic delegation (client.ts:useTRPC).
|
||||
vi.mock("@trpc/tanstack-react-query", () => ({
|
||||
createTRPCContext: () => ({
|
||||
TRPCProvider: () => null,
|
||||
useTRPC: () => ({ __proxy: "trpc-options-proxy" }),
|
||||
}),
|
||||
}));
|
||||
|
||||
import { useTRPC, TRPCProvider } from "./client";
|
||||
|
||||
describe("core-trpc client exports", () => {
|
||||
@@ -9,4 +20,10 @@ describe("core-trpc client exports", () => {
|
||||
it("exports TRPCProvider component", () => {
|
||||
expect(TRPCProvider).toBeTypeOf("function");
|
||||
});
|
||||
|
||||
it("useTRPC delegates to the underlying router-agnostic tRPC proxy", () => {
|
||||
// The generic is a compile-time-only cast; at runtime it returns whatever
|
||||
// the shared context proxy yields.
|
||||
expect(useTRPC()).toEqual({ __proxy: "trpc-options-proxy" });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user