43 lines
1.1 KiB
TypeScript
43 lines
1.1 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> extends TRPCContextRuntime<R>, TRPCContextTransaction {}
|
|
|
|
export interface TRPCContextRuntime<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>
|
|
}
|
|
|
|
export interface TRPCContextTransaction {
|
|
readonly transaction: TRPCTransaction
|
|
}
|
|
|
|
|
|
export type TRPCTransaction = Data.TaggedEnum<{
|
|
readonly Express: {
|
|
readonly req: express.Request
|
|
readonly res: express.Response
|
|
}
|
|
|
|
readonly WebSocket: {
|
|
readonly req: IncomingMessage
|
|
readonly res: WebSocket
|
|
}
|
|
}>
|
|
|
|
export const TRPCTransactionEnum = Data.taggedEnum<TRPCTransaction>()
|