25 lines
757 B
TypeScript
25 lines
757 B
TypeScript
import { Effect, Match } from "effect"
|
|
import type { TRPCContextTransaction } from "./TRPCContext"
|
|
import { importTRPCServer } from "./importTRPCServer"
|
|
|
|
|
|
export const ExpressOnly = importTRPCServer.pipe(Effect.map(({
|
|
experimental_standaloneMiddleware,
|
|
TRPCError,
|
|
}) => experimental_standaloneMiddleware<{
|
|
ctx: { readonly transaction: TRPCContextTransaction }
|
|
}>().create(opts =>
|
|
Match.value(opts.ctx.transaction).pipe(
|
|
Match.tag("Express", transaction =>
|
|
opts.next({ ctx: { transaction } })
|
|
),
|
|
|
|
Match.orElse(() => {
|
|
throw new TRPCError({
|
|
code: "BAD_REQUEST",
|
|
message: "Only Express backend is supported by this procedure",
|
|
})
|
|
}),
|
|
)
|
|
)))
|