RPC server work

This commit is contained in:
Julien Valverdé
2024-07-04 23:12:32 +02:00
parent 5f15dedfbf
commit eb464edefd
6 changed files with 34 additions and 19 deletions

View File

@@ -0,0 +1,12 @@
import type { CreateExpressContextOptions } from "@trpc/server/adapters/express"
import { Context, Layer } from "effect"
import type { TRPCContext } from "./TRPCContext"
export class CreateTRPCContext extends Context.Tag("CreateTRPCContext")<CreateTRPCContext,
(opts: CreateExpressContextOptions) => TRPCContext
>() {}
export module CreateTRPCContext {
export const Live = Layer.sync(CreateTRPCContext, () => ({ req }) => ({ req }))
}

View File

@@ -1,6 +1,6 @@
import { initTRPC } from "@trpc/server"
import { Context, Layer } from "effect"
import type { TRPCContext } from "./context"
import type { TRPCContext } from "./TRPCContext"
const createTRPC = () => initTRPC.context<TRPCContext>().create()

View File

@@ -0,0 +1,6 @@
import type { Request } from "express"
export interface TRPCContext {
req: Request
}

View File

@@ -1,5 +0,0 @@
import type { CreateExpressContextOptions } from "@trpc/server/adapters/express"
export const createTRPCContext = ({ req }: CreateExpressContextOptions) => ({ req })
export type TRPCContext = Awaited<ReturnType<typeof createTRPCContext>>