TRPC context creator

This commit is contained in:
Julien Valverdé
2024-07-09 02:36:37 +02:00
parent c25c525d6f
commit 139d52a9a1
2 changed files with 7 additions and 3 deletions

View File

@@ -10,5 +10,5 @@ export interface TRPCContext {
options?: { readonly signal?: AbortSignal } options?: { readonly signal?: AbortSignal }
) => Promise<A> ) => Promise<A>
req: Request // req: Request
} }

View File

@@ -1,5 +1,6 @@
import { TRPCError } from "@trpc/server" import { TRPCError } from "@trpc/server"
import type { CreateExpressContextOptions } from "@trpc/server/adapters/express" import type { CreateExpressContextOptions } from "@trpc/server/adapters/express"
import type { CreateWSSContextFnOptions } from "@trpc/server/adapters/ws"
import { Context, Effect, Layer, Runtime } from "effect" import { Context, Effect, Layer, Runtime } from "effect"
import type { Services } from "../Services" import type { Services } from "../Services"
import type { TRPCContext } from "./TRPCContext" import type { TRPCContext } from "./TRPCContext"
@@ -9,7 +10,10 @@ import type { TRPCContext } from "./TRPCContext"
* Provides a function that instantiates a fresh context for each tRPC procedure call * Provides a function that instantiates a fresh context for each tRPC procedure call
*/ */
export class TRPCContextCreator extends Context.Tag("TRPCContextCreator")<TRPCContextCreator, export class TRPCContextCreator extends Context.Tag("TRPCContextCreator")<TRPCContextCreator,
(opts: CreateExpressContextOptions) => TRPCContext (opts:
| CreateExpressContextOptions
| CreateWSSContextFnOptions
) => TRPCContext
>() {} >() {}
export module TRPCContextCreator { export module TRPCContextCreator {
@@ -20,7 +24,7 @@ export module TRPCContextCreator {
return ({ req }) => ({ return ({ req }) => ({
runtime, runtime,
run, run,
req, // req,
}) })
})) }))
} }