0.1.17 (#18)
All checks were successful
Publish / publish (push) Successful in 13s
Lint / lint (push) Successful in 11s

Co-authored-by: Julien Valverdé <julien.valverde@mailo.com>
Reviewed-on: #18
This commit was merged in pull request #18.
This commit is contained in:
Julien Valverdé
2024-09-07 20:56:30 +02:00
parent 07578a7ac7
commit 02d8e38f4d
25 changed files with 666 additions and 82 deletions

44
src/TRPC/middlewares.ts Normal file
View File

@@ -0,0 +1,44 @@
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 transport is supported by this procedure",
})
}),
)
)))
export const WebSocketOnly = importTRPCServer.pipe(Effect.map(({
experimental_standaloneMiddleware,
TRPCError,
}) => experimental_standaloneMiddleware<{
ctx: { readonly transaction: TRPCContextTransaction }
}>().create(opts =>
Match.value(opts.ctx.transaction).pipe(
Match.tag("WebSocket", transaction =>
opts.next({ ctx: { transaction } })
),
Match.orElse(() => {
throw new TRPCError({
code: "BAD_REQUEST",
message: "Only WebSocket transport is supported by this procedure",
})
}),
)
)))