import { initTRPC } from '@trpc/server';
import type * as trpcExpress from '@trpc/server/adapters/express';
import superjson from 'superjson';
import type { OpenApiMeta } from 'trpc-openapi';
// Fake prisma
const prisma = 'prisma';
export interface CreateInnerTRPCContextOptions
extends Partial<trpcExpress.CreateExpressContextOptions> {}
export interface AppInnerContext
extends Partial<trpcExpress.CreateExpressContextOptions> {
prisma: string;
}
export async function createInnerTRPCContext(
_opts: CreateInnerTRPCContextOptions,
): Promise<AppInnerContext> {
return {
prisma,
};
}
type CreateTRPCContextOptions = CreateInnerTRPCContextOptions &
trpcExpress.CreateExpressContextOptions;
export type AppContext = AppInnerContext &
trpcExpress.CreateExpressContextOptions;
export async function createTRPCContext(
opts: CreateTRPCContextOptions,
): Promise<AppContext> {
const innerContext = await createInnerTRPCContext(opts);
return {
...innerContext,
req: opts.req,
res: opts.res,
};
}
const t = initTRPC.meta<OpenApiMeta>().context<AppInnerContext>().create({
transformer: superjson,
});
export const createTRPCRouter = t.router;
export const publicProcedure = t.procedure;