diff --git a/bun.lockb b/bun.lockb index 9ff58ea..d873213 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index cbcb17e..be73307 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@thilawyn/thilalib", - "version": "0.1.19", + "version": "0.1.20", "type": "module", "files": [ "./dist" @@ -53,7 +53,7 @@ }, "dependencies": { "remeda": "^2.12.0", - "type-fest": "^4.26.0" + "type-fest": "^4.26.1" }, "devDependencies": { "@effect/schema": "^0.72.3", diff --git a/src/TRPC/example.ts b/src/TRPC/example.ts index 1a3bd14..22ca552 100644 --- a/src/TRPC/example.ts +++ b/src/TRPC/example.ts @@ -16,11 +16,22 @@ const { TRPCContextCreator, TRPCContextCreatorLive } = TRPC.TRPCContextCreator.m const { TRPCBuilder, TRPCBuilderLive } = TRPC.TRPCBuilder.make() -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) diff --git a/src/TRPC/middlewares/DecodeInput.ts b/src/TRPC/middlewares/DecodeInput.ts index 449d870..f6eb513 100644 --- a/src/TRPC/middlewares/DecodeInput.ts +++ b/src/TRPC/middlewares/DecodeInput.ts @@ -23,7 +23,7 @@ export const DecodeInput = ( ) return experimental_standaloneMiddleware<{ - ctx: TRPCContextRuntime + ctx: TRPCContextRuntime input: I }>().create( async ({ ctx, input, next }) => next({ diff --git a/src/TRPC/middlewares/ExpressOnly.ts b/src/TRPC/middlewares/ExpressOnly.ts index c6bed4c..2e06fad 100644 --- a/src/TRPC/middlewares/ExpressOnly.ts +++ b/src/TRPC/middlewares/ExpressOnly.ts @@ -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", + }) + }), + ) + } })))) diff --git a/src/TRPC/middlewares/WebSocketOnly.ts b/src/TRPC/middlewares/WebSocketOnly.ts index b5da83d..78c8155 100644 --- a/src/TRPC/middlewares/WebSocketOnly.ts +++ b/src/TRPC/middlewares/WebSocketOnly.ts @@ -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", + }) + }), + ) + } }))))