Middleware fix
All checks were successful
Lint / lint (push) Successful in 13s

This commit is contained in:
Julien Valverdé
2024-09-08 07:40:03 +02:00
parent 704aa945f7
commit da4de9db11
3 changed files with 38 additions and 23 deletions

View File

@@ -16,11 +16,22 @@ const { TRPCContextCreator, TRPCContextCreatorLive } = TRPC.TRPCContextCreator.m
const { TRPCBuilder, TRPCBuilderLive } = TRPC.TRPCBuilder.make<Services>() const { TRPCBuilder, TRPCBuilderLive } = TRPC.TRPCBuilder.make<Services>()
const router = TRPCBuilder.pipe(Effect.map(t => t.router({ const router = Effect.gen(function*() {
ping: t.procedure.query(({ ctx }) => ctx.run( const t = yield* TRPCBuilder
Effect.succeed("pong")
)), return t.router({
}))) ping: t.procedure.query(({ ctx }) => ctx.run(
Effect.succeed("pong")
)),
expressOnlyProcedure: t.procedure
.use(yield* TRPC.ExpressOnly)
.query(({ ctx }) => ctx.run(Effect.gen(function*() {
ctx.transaction
}))),
})
})
const { TRPCRouter, TRPCRouterLive } = TRPC.TRPCRouter.make(router) const { TRPCRouter, TRPCRouterLive } = TRPC.TRPCRouter.make(router)

View File

@@ -9,14 +9,16 @@ export const ExpressOnly = importTRPCServer.pipe(Effect.map(({
}) => experimental_standaloneMiddleware<{ }) => experimental_standaloneMiddleware<{
ctx: TRPCContextTransaction ctx: TRPCContextTransaction
}>().create(({ ctx, next }) => next({ }>().create(({ ctx, next }) => next({
ctx: Match.value(ctx.transaction).pipe( ctx: {
Match.tag("Express", identity), transaction: Match.value(ctx.transaction).pipe(
Match.tag("Express", identity),
Match.orElse(() => { Match.orElse(() => {
throw new TRPCError({ throw new TRPCError({
code: "BAD_REQUEST", code: "BAD_REQUEST",
message: "Only Express transport is supported by this procedure", message: "Only Express transport is supported by this procedure",
}) })
}), }),
) )
}
})))) }))))

View File

@@ -9,14 +9,16 @@ export const WebSocketOnly = importTRPCServer.pipe(Effect.map(({
}) => experimental_standaloneMiddleware<{ }) => experimental_standaloneMiddleware<{
ctx: TRPCContextTransaction ctx: TRPCContextTransaction
}>().create(({ ctx, next }) => next({ }>().create(({ ctx, next }) => next({
ctx: Match.value(ctx.transaction).pipe( ctx: {
Match.tag("WebSocket", identity), transaction: Match.value(ctx.transaction).pipe(
Match.tag("WebSocket", identity),
Match.orElse(() => { Match.orElse(() => {
throw new TRPCError({ throw new TRPCError({
code: "BAD_REQUEST", code: "BAD_REQUEST",
message: "Only WebSocket transport is supported by this procedure", message: "Only WebSocket transport is supported by this procedure",
}) })
}), }),
) )
}
})))) }))))