Files
thilalib/src/TRPC/TRPCContext.ts
Julien Valverdé 02d8e38f4d
All checks were successful
Publish / publish (push) Successful in 13s
Lint / lint (push) Successful in 11s
0.1.17 (#18)
Co-authored-by: Julien Valverdé <julien.valverde@mailo.com>
Reviewed-on: #18
2024-09-07 20:56:30 +02:00

39 lines
1.0 KiB
TypeScript

import type { TRPCError } from "@trpc/server"
import { Data, type Effect, type Runtime } from "effect"
import type { RuntimeFiber } from "effect/Fiber"
import type express from "express"
import type { IncomingMessage } from "node:http"
import type { WebSocket } from "ws"
export interface TRPCContext<R> {
readonly runtime: Runtime.Runtime<R>
readonly run: <A, E>(
effect: Effect.Effect<A, E, R>,
options?: { readonly signal?: AbortSignal },
) => Promise<A>
readonly fork: <A, E>(
effect: Effect.Effect<A, E, R>,
options?: Runtime.RunForkOptions,
) => RuntimeFiber<A, TRPCError>
readonly transaction: TRPCContextTransaction
}
export type TRPCContextTransaction = Data.TaggedEnum<{
readonly Express: {
readonly req: express.Request
readonly res: express.Response
}
readonly WebSocket: {
readonly req: IncomingMessage
readonly res: WebSocket
}
}>
export const TRPCContextTransactionEnum = Data.taggedEnum<TRPCContextTransaction>()