0.1.20 #21
@@ -16,11 +16,22 @@ const { TRPCContextCreator, TRPCContextCreatorLive } = TRPC.TRPCContextCreator.m
|
||||
const { TRPCBuilder, TRPCBuilderLive } = TRPC.TRPCBuilder.make<Services>()
|
||||
|
||||
|
||||
const router = TRPCBuilder.pipe(Effect.map(t => t.router({
|
||||
ping: t.procedure.query(({ ctx }) => ctx.run(
|
||||
Effect.succeed("pong")
|
||||
)),
|
||||
})))
|
||||
const router = Effect.gen(function*() {
|
||||
const t = yield* TRPCBuilder
|
||||
|
||||
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)
|
||||
|
||||
|
||||
|
||||
@@ -9,14 +9,16 @@ export const ExpressOnly = importTRPCServer.pipe(Effect.map(({
|
||||
}) => experimental_standaloneMiddleware<{
|
||||
ctx: TRPCContextTransaction
|
||||
}>().create(({ ctx, next }) => next({
|
||||
ctx: Match.value(ctx.transaction).pipe(
|
||||
Match.tag("Express", identity),
|
||||
ctx: {
|
||||
transaction: Match.value(ctx.transaction).pipe(
|
||||
Match.tag("Express", identity),
|
||||
|
||||
Match.orElse(() => {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Only Express transport is supported by this procedure",
|
||||
})
|
||||
}),
|
||||
)
|
||||
Match.orElse(() => {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Only Express transport is supported by this procedure",
|
||||
})
|
||||
}),
|
||||
)
|
||||
}
|
||||
}))))
|
||||
|
||||
@@ -9,14 +9,16 @@ export const WebSocketOnly = importTRPCServer.pipe(Effect.map(({
|
||||
}) => experimental_standaloneMiddleware<{
|
||||
ctx: TRPCContextTransaction
|
||||
}>().create(({ ctx, next }) => next({
|
||||
ctx: Match.value(ctx.transaction).pipe(
|
||||
Match.tag("WebSocket", identity),
|
||||
ctx: {
|
||||
transaction: Match.value(ctx.transaction).pipe(
|
||||
Match.tag("WebSocket", identity),
|
||||
|
||||
Match.orElse(() => {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Only WebSocket transport is supported by this procedure",
|
||||
})
|
||||
}),
|
||||
)
|
||||
Match.orElse(() => {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Only WebSocket transport is supported by this procedure",
|
||||
})
|
||||
}),
|
||||
)
|
||||
}
|
||||
}))))
|
||||
|
||||
Reference in New Issue
Block a user