From d053c61eabf201fcfd195ff86305d7497f2cef8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Sat, 13 Jul 2024 05:46:30 +0200 Subject: [PATCH] TRPCContextRequest --- packages/server/src/trpc/TRPCContext.ts | 16 +++++++++++++--- packages/server/src/trpc/TRPCContextCreator.ts | 3 ++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/server/src/trpc/TRPCContext.ts b/packages/server/src/trpc/TRPCContext.ts index 3f40cf5..e7b6571 100644 --- a/packages/server/src/trpc/TRPCContext.ts +++ b/packages/server/src/trpc/TRPCContext.ts @@ -1,10 +1,14 @@ import type { TRPCError } from "@trpc/server" -import type { Effect, Runtime } from "effect" +import { Data, type Effect, type Runtime } from "effect" import type { RuntimeFiber } from "effect/Fiber" +import type { Request } from "express" +import type { IncomingMessage } from "node:http" import type { Services } from "../Services" export interface TRPCContext { + req: TRPCContextRequest + runtime: Runtime.Runtime run: ( @@ -16,6 +20,12 @@ export interface TRPCContext { effect: Effect.Effect, options?: Runtime.RunForkOptions, ) => RuntimeFiber - - // req: Request } + + +export type TRPCContextRequest = Data.TaggedEnum<{ + Express: { readonly req: Request } + WebSocket: { readonly req: IncomingMessage } +}> + +export const TRPCContextRequestEnum = Data.taggedEnum() diff --git a/packages/server/src/trpc/TRPCContextCreator.ts b/packages/server/src/trpc/TRPCContextCreator.ts index 9b2e0ee..c856923 100644 --- a/packages/server/src/trpc/TRPCContextCreator.ts +++ b/packages/server/src/trpc/TRPCContextCreator.ts @@ -37,10 +37,11 @@ export module TRPCContextCreator { ) return ({ req }) => ({ + + runtime, run, fork, - // req, }) })) }