refactor(core-trpc): break the core-api package cycle
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>
This commit is contained in:
@@ -32,3 +32,13 @@ export const marketingPagesRouter = router({
|
||||
});
|
||||
|
||||
export type MarketingPagesRouter = typeof marketingPagesRouter;
|
||||
|
||||
/**
|
||||
* This feature's slice as it is mounted in the app router (the `marketingPages` key
|
||||
* in @repo/core-api). UI hooks pass it to `useTRPC<MarketingPagesAppSlice>()` so
|
||||
* they stay fully typed without core-trpc (or this feature's client code)
|
||||
* depending on the composition layer. Type-only: erased at compile time.
|
||||
*/
|
||||
export type MarketingPagesAppSlice = ReturnType<
|
||||
typeof router<{ marketingPages: typeof marketingPagesRouter }>
|
||||
>;
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
import { useSuspenseQuery } from "@tanstack/react-query";
|
||||
import { useTRPC } from "@repo/core-trpc";
|
||||
import type { MarketingPagesAppSlice } from "../../integrations/api/router";
|
||||
import type { Page } from "../../entities/models/page";
|
||||
|
||||
export function usePageBySlug(slug: string) {
|
||||
const trpc = useTRPC();
|
||||
const trpc = useTRPC<MarketingPagesAppSlice>();
|
||||
// A missing slug now rejects with NOT_FOUND (PageNotFoundError), so a
|
||||
// resolved query always carries a Page.
|
||||
return useSuspenseQuery(
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
import { useSuspenseQuery } from "@tanstack/react-query";
|
||||
import { useTRPC } from "@repo/core-trpc";
|
||||
import type { MarketingPagesAppSlice } from "../../integrations/api/router";
|
||||
import type { SiteSettings } from "../../entities/models/site-settings";
|
||||
|
||||
export function useSiteSettings() {
|
||||
const trpc = useTRPC();
|
||||
const trpc = useTRPC<MarketingPagesAppSlice>();
|
||||
return useSuspenseQuery(
|
||||
trpc.marketingPages.siteSettings.queryOptions({}),
|
||||
) as { data: SiteSettings };
|
||||
|
||||
Reference in New Issue
Block a user