tRPC work
All checks were successful
Lint / lint (push) Successful in 12s

This commit is contained in:
Julien Valverdé
2024-09-06 03:54:18 +02:00
parent f232da4630
commit 9b80664c95
5 changed files with 52 additions and 11 deletions

View File

@@ -5,17 +5,21 @@ import { createTRCPErrorMapper } from "./createTRCPErrorMapper"
import { TRPCContextTransactionEnum, type TRPCContext, type TRPCContextTransaction } from "./TRPCContext"
export { TRPCErrorCause } from "./createTRCPErrorMapper"
export { TRPCContextTransactionEnum } from "./TRPCContext"
export type { TRPCContext, TRPCContextTransaction } from "./TRPCContext"
export interface TRPCContextCreatorService<R> {
readonly createContext: (transaction: TRPCContextTransaction) => TRPCContext<R>
readonly createExpressContext: (context: CreateExpressContextOptions) => TRPCContext<R>
readonly createWebSocketContext: (context: CreateWSSContextFnOptions) => TRPCContext<R>
}
export class TRPCUnknownContextCreator extends Context.Tag("@thilalib/TRPC/TRPCContextCreator")<TRPCUnknownContextCreator,
TRPCContextCreatorService<unknown>
>() {}
export const make = <R>() => {
class TRPCContextCreator extends Context.Tag("TRPCContextCreator")<TRPCContextCreator, {
readonly createContext: (transaction: TRPCContextTransaction) => TRPCContext<R>
readonly createExpressContext: (context: CreateExpressContextOptions) => TRPCContext<R>
readonly createWebSocketContext: (context: CreateWSSContextFnOptions) => TRPCContext<R>
}>() {}
class TRPCContextCreator extends Context.Tag("@thilalib/TRPC/TRPCContextCreator")<TRPCContextCreator,
TRPCContextCreatorService<R>
>() {}
const TRPCContextCreatorLive = Layer.effect(TRPCContextCreator, Effect.gen(function*() {
const runtime = yield* Effect.runtime<R>()
@@ -37,14 +41,12 @@ export const make = <R>() => {
options,
)
const createContext = (transaction: TRPCContextTransaction) => ({
runtime,
run,
fork,
transaction,
})
const createExpressContext = (context: CreateExpressContextOptions) => createContext(TRPCContextTransactionEnum.Express(context))
const createWebSocketContext = (context: CreateWSSContextFnOptions) => createContext(TRPCContextTransactionEnum.WebSocket(context))