0.1.17 #18
@@ -1,12 +1,7 @@
|
|||||||
import { Effect, type Cause } from "effect"
|
import { Effect, type Cause } from "effect"
|
||||||
import { ImportError } from "../../ImportError"
|
import { importTRPCServer } from "./importTRPCServer"
|
||||||
|
|
||||||
|
|
||||||
const importTRPCServer = Effect.tryPromise({
|
|
||||||
try: () => import("@trpc/server"),
|
|
||||||
catch: cause => new ImportError({ path: "@trpc/server", cause }),
|
|
||||||
})
|
|
||||||
|
|
||||||
export const createTRCPErrorMapper = importTRPCServer.pipe(Effect.map(({ TRPCError }) =>
|
export const createTRCPErrorMapper = importTRPCServer.pipe(Effect.map(({ TRPCError }) =>
|
||||||
<A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.sandbox(effect).pipe(
|
<A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.sandbox(effect).pipe(
|
||||||
Effect.catchTags({
|
Effect.catchTags({
|
||||||
|
|||||||
8
src/Layers/trpc/importTRPCServer.ts
Normal file
8
src/Layers/trpc/importTRPCServer.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { Effect } from "effect"
|
||||||
|
import { ImportError } from "../../ImportError"
|
||||||
|
|
||||||
|
|
||||||
|
export const importTRPCServer = Effect.tryPromise({
|
||||||
|
try: () => import("@trpc/server"),
|
||||||
|
catch: cause => new ImportError({ path: "@trpc/server", cause }),
|
||||||
|
})
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
export * from "./middlewares"
|
||||||
export * as TRPCBuilder from "./TRPCBuilder"
|
export * as TRPCBuilder from "./TRPCBuilder"
|
||||||
export * as TRPCContext from "./TRPCContext"
|
export * as TRPCContext from "./TRPCContext"
|
||||||
export * as TRPCContextCreator from "./TRPCContextCreator"
|
export * as TRPCContextCreator from "./TRPCContextCreator"
|
||||||
|
|||||||
24
src/Layers/trpc/middlewares.ts
Normal file
24
src/Layers/trpc/middlewares.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
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",
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
)))
|
||||||
Reference in New Issue
Block a user