Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
TSX
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108import "server-only";import type { AppRouter } from "@openstatus/api";import { HydrationBoundary } from "@tanstack/react-query";import { dehydrate } from "@tanstack/react-query";import { TRPCClientError, createTRPCClient } from "@trpc/client";import { type ResolverDef, type TRPCQueryOptions, createTRPCOptionsProxy,} from "@trpc/tanstack-react-query";import { cookies } from "next/headers";import { notFound } from "next/navigation";import { cache } from "react";
import { makeQueryClient } from "./query-client";import { endingLink, sentryLoggerLink } from "./shared";
// IMPORTANT: Create a stable getter for the query client that// will return the same client during the same request.export const getQueryClient = cache(makeQueryClient);
export const trpc = createTRPCOptionsProxy<AppRouter>({ queryClient: getQueryClient, client: createTRPCClient({ links: [ sentryLoggerLink(), endingLink({ headers: { "x-trpc-source": "server", }, // `typeof fetch` carries a `preconnect` static (React 19 typings) that // tRPC's link will never invoke โ cast the call-signature wrapper. fetch: (async (url, options) => { const cookieStore = await cookies(); return fetch(url, { ...options, credentials: "include", headers: { ...options?.headers, cookie: cookieStore.toString(), }, }); }) as typeof fetch, }), ], }),});
export function HydrateClient(props: { children: React.ReactNode }) { const queryClient = getQueryClient();
return ( <HydrationBoundary state={dehydrate(queryClient)}> {props.children} </HydrationBoundary> );}
// oxlint-disable-next-line typescript/no-explicit-any -- FIXME: remove anyexport function prefetch<T extends ReturnType<TRPCQueryOptions<any>>>( queryOptions: T,) { const queryClient = getQueryClient();
if (queryOptions.queryKey[1]?.type === "infinite") { // oxlint-disable-next-line typescript/no-explicit-any -- FIXME: remove any void queryClient.prefetchInfiniteQuery(queryOptions as any); } else { void queryClient.prefetchQuery(queryOptions); }}
// oxlint-disable-next-line typescript/no-explicit-any -- FIXME: remove anyexport function batchPrefetch<T extends ReturnType<TRPCQueryOptions<any>>>( queryOptionsArray: T[],) { const queryClient = getQueryClient();
for (const queryOptions of queryOptionsArray) { if (queryOptions.queryKey[1]?.type === "infinite") { // oxlint-disable-next-line typescript/no-explicit-any -- FIXME: remove any void queryClient.prefetchInfiniteQuery(queryOptions as any); } else { void queryClient.prefetchQuery(queryOptions); } }}
/** * Fetches a query and calls `notFound()` if the server returns NOT_FOUND. * Use this for gating queries in layouts where the resource must exist. */export async function fetchQueryOrNotFound< T extends ReturnType<TRPCQueryOptions<ResolverDef>>,>(queryOptions: T) { const queryClient = getQueryClient(); try { return (await queryClient.fetchQuery(queryOptions)) as Awaited< ReturnType<Extract<T["queryFn"], (...args: never[]) => unknown>> >; } catch (error) { if (error instanceof TRPCClientError && error.data?.code === "NOT_FOUND") { notFound(); } throw error; }}