0.1.17 #18
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user