UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

82 lines • 3.34 kB
import { ClientRuntimeConfig } from "../types.cjs"; import { QueryClient } from "@tanstack/react-query"; import { AnyRoute, AnyRouteMatch, AnyRouter, RouterHistory } from "@tanstack/react-router"; import { NavManifest } from "every-plugin/ui/manifest"; //#region src/ui/types.d.ts interface RouterContext<TSession = unknown> { queryClient: QueryClient; runtimeConfig?: Partial<ClientRuntimeConfig>; session?: TSession; cspNonce?: string; locale?: string; /** nav manifest derived from composed routes' staticData.nav */ pluginNav?: NavManifest; } interface RouterContextWithApi<TApiClient = unknown, TSession = unknown> extends RouterContext<TSession> { apiClient?: TApiClient; /** auth client — concrete apps narrow this to their bound AuthClient type. */ authClient?: unknown; } interface CreateRouterOptions<TApiClient = unknown, TSession = unknown> { history?: RouterHistory; context?: Partial<RouterContextWithApi<TApiClient, TSession>>; basepath?: string; /** composed route tree — manifest construction passes it here; the bundled tree stays the core-only fallback. */ routeTree?: unknown; } /** * The app's authored router factory — the single router-policy seam, minting * the hydrated client router AND each SSR request's router (parity). Apps * type it against their concrete clients; the framework sees them opaquely * (`any` at the boundary — the same contract shape the manifest option * bundles use). */ type AppRouterFactory = (opts: CreateRouterOptions<any, any> & { context: RouterContextWithApi<any, any> & { apiClient: any; authClient: any; }; }) => { router: AnyRouter; queryClient?: QueryClient; }; type HeadMeta = NonNullable<AnyRouteMatch["meta"]>[number]; type HeadLink = NonNullable<AnyRouteMatch["links"]>[number]; type HeadScript = NonNullable<AnyRouteMatch["headScripts"]>[number]; interface HeadData { meta: HeadMeta[]; links: HeadLink[]; scripts: HeadScript[]; } interface RenderOptions<TSession = unknown> { runtimeConfig: Partial<ClientRuntimeConfig>; basepath?: string; session?: TSession; cspNonce?: string; /** composed route tree — server composition only. */ routeTree?: AnyRoute; /** nav manifest derived from composed routes — server composition only. */ pluginNav?: NavManifest; /** correlation id from the host request — appears in SSR error logs. */ requestId?: string; } interface RenderOptionsWithApi<TApiClient = unknown, TSession = unknown> extends RenderOptions<TSession> { apiClient: TApiClient; authClient?: unknown; } interface RenderResult { stream: ReadableStream; statusCode: number; headers: Headers; } interface RouterModule<TApiClient = unknown, TSession = unknown> { createRouter: (opts?: CreateRouterOptions<TApiClient, TSession>) => { router: AnyRouter; queryClient: QueryClient; }; getRouteHead: (pathname: string, context?: Partial<RouterContextWithApi<TApiClient, TSession>>) => Promise<HeadData>; renderToStream: (request: Request, options: RenderOptionsWithApi<TApiClient, TSession>) => Promise<RenderResult>; } //#endregion export { AppRouterFactory, CreateRouterOptions, HeadData, HeadLink, HeadMeta, HeadScript, RenderOptions, RenderOptionsWithApi, RenderResult, RouterContext, RouterContextWithApi, RouterModule }; //# sourceMappingURL=types.d.cts.map