0.1.17 #18
@@ -5,21 +5,21 @@ import { createTRCPErrorMapper } from "./createTRCPErrorMapper"
|
|||||||
import { TRPCContextTransactionEnum, type TRPCContext, type TRPCContextTransaction } from "./TRPCContext"
|
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> {
|
export interface TRPCContextCreatorService<R> {
|
||||||
readonly createContext: (transaction: TRPCContextTransaction) => TRPCContext<R>
|
readonly createContext: (transaction: TRPCContextTransaction) => TRPCContext<R>
|
||||||
readonly createExpressContext: (context: CreateExpressContextOptions) => TRPCContext<R>
|
readonly createExpressContext: (context: CreateExpressContextOptions) => TRPCContext<R>
|
||||||
readonly createWebSocketContext: (context: CreateWSSContextFnOptions) => TRPCContext<R>
|
readonly createWebSocketContext: (context: CreateWSSContextFnOptions) => TRPCContext<R>
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TRPCUnknownContextCreator extends Context.Tag("@thilalib/TRPC/TRPCContextCreator")<TRPCUnknownContextCreator,
|
export const TRPCUnknownContextCreator = Context.GenericTag<typeof Identifier, TRPCContextCreatorService<unknown>>(Identifier)
|
||||||
TRPCContextCreatorService<unknown>
|
|
||||||
>() {}
|
|
||||||
|
|
||||||
|
|
||||||
export const make = <R>() => {
|
export const make = <R>() => {
|
||||||
class TRPCContextCreator extends Context.Tag("@thilalib/TRPC/TRPCContextCreator")<TRPCContextCreator,
|
const TRPCContextCreator = Context.GenericTag<typeof Identifier, TRPCContextCreatorService<R>>(Identifier)
|
||||||
TRPCContextCreatorService<R>
|
|
||||||
>() {}
|
|
||||||
|
|
||||||
const TRPCContextCreatorLive = Layer.effect(TRPCContextCreator, Effect.gen(function*() {
|
const TRPCContextCreatorLive = Layer.effect(TRPCContextCreator, Effect.gen(function*() {
|
||||||
const runtime = yield* Effect.runtime<R>()
|
const runtime = yield* Effect.runtime<R>()
|
||||||
@@ -53,5 +53,5 @@ export const make = <R>() => {
|
|||||||
return { createContext, createExpressContext, createWebSocketContext }
|
return { createContext, createExpressContext, createWebSocketContext }
|
||||||
}))
|
}))
|
||||||
|
|
||||||
return { TRPCContextCreator, TRPCContextCreatorLive }
|
return { TRPCContextCreator, TRPCContextCreatorLive } as const
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user