TRPCContextCreator refactoring
All checks were successful
Lint / lint (push) Successful in 12s

This commit is contained in:
Julien Valverdé
2024-09-07 05:15:19 +02:00
parent aa12c67a4e
commit 253c3ec00d

View File

@@ -5,21 +5,21 @@ import { createTRCPErrorMapper } from "./createTRCPErrorMapper"
import { TRPCContextTransactionEnum, type TRPCContext, type TRPCContextTransaction } from "./TRPCContext"
export const Identifier = "@thilalib/TRPC/TRPCContextCreator"
export interface TRPCContextCreator<R> extends Context.Tag<typeof Identifier, TRPCContextCreatorService<R>> {}
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 TRPCUnknownContextCreator = Context.GenericTag<typeof Identifier, TRPCContextCreatorService<unknown>>(Identifier)
export const make = <R>() => {
class TRPCContextCreator extends Context.Tag("@thilalib/TRPC/TRPCContextCreator")<TRPCContextCreator,
TRPCContextCreatorService<R>
>() {}
const TRPCContextCreator = Context.GenericTag<typeof Identifier, TRPCContextCreatorService<R>>(Identifier)
const TRPCContextCreatorLive = Layer.effect(TRPCContextCreator, Effect.gen(function*() {
const runtime = yield* Effect.runtime<R>()
@@ -53,5 +53,5 @@ export const make = <R>() => {
return { createContext, createExpressContext, createWebSocketContext }
}))
return { TRPCContextCreator, TRPCContextCreatorLive }
return { TRPCContextCreator, TRPCContextCreatorLive } as const
}