TRPCContextRequest

This commit is contained in:
Julien Valverdé
2024-07-13 05:46:30 +02:00
parent 2a909a34bc
commit d053c61eab
2 changed files with 15 additions and 4 deletions

View File

@@ -1,10 +1,14 @@
import type { TRPCError } from "@trpc/server" 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 { RuntimeFiber } from "effect/Fiber"
import type { Request } from "express"
import type { IncomingMessage } from "node:http"
import type { Services } from "../Services" import type { Services } from "../Services"
export interface TRPCContext { export interface TRPCContext {
req: TRPCContextRequest
runtime: Runtime.Runtime<Services> runtime: Runtime.Runtime<Services>
run: <A, E>( run: <A, E>(
@@ -16,6 +20,12 @@ export interface TRPCContext {
effect: Effect.Effect<A, E, Services>, effect: Effect.Effect<A, E, Services>,
options?: Runtime.RunForkOptions, options?: Runtime.RunForkOptions,
) => RuntimeFiber<A, TRPCError> ) => RuntimeFiber<A, TRPCError>
// req: Request
} }
export type TRPCContextRequest = Data.TaggedEnum<{
Express: { readonly req: Request }
WebSocket: { readonly req: IncomingMessage }
}>
export const TRPCContextRequestEnum = Data.taggedEnum<TRPCContextRequest>()

View File

@@ -37,10 +37,11 @@ export module TRPCContextCreator {
) )
return ({ req }) => ({ return ({ req }) => ({
runtime, runtime,
run, run,
fork, fork,
// req,
}) })
})) }))
} }