Openstatus
www.openstatus.dev
1import "server-only";
2
3import { type AppRouter, appRouter, t } from "@openstatus/api";
4import type { Context } from "@openstatus/api/src/trpc";
5import { db } from "@openstatus/db";
6import { createHydrationHelpers } from "@trpc/react-query/rsc";
7import { cache } from "react";
8import { makeQueryClient } from "./query-client";
9
10const createContextCached = cache(
11 async (..._args: unknown[]): Promise<Context> => {
12 return {
13 req: undefined,
14 db,
15 session: null,
16 };
17 },
18);
19
20// IMPORTANT: Create a stable getter for the query client that
21// will return the same client during the same request.
22export const getQueryClient = cache(makeQueryClient);
23const caller = t.createCallerFactory(appRouter)(createContextCached);
24export const { trpc: api, HydrateClient } = createHydrationHelpers<AppRouter>(
25 caller,
26 getQueryClient,
27);