0.1.20 (#21)
All checks were successful
Publish / publish (push) Successful in 12s
Lint / lint (push) Successful in 12s

Co-authored-by: Julien Valverdé <julien.valverde@mailo.com>
Reviewed-on: #21
This commit was merged in pull request #21.
This commit is contained in:
Julien Valverdé
2024-09-09 04:05:14 +02:00
parent 704aa945f7
commit 6713bba164
6 changed files with 41 additions and 26 deletions

BIN
bun.lockb

Binary file not shown.

View File

@@ -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",

View File

@@ -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)

View File

@@ -23,7 +23,7 @@ export const DecodeInput = <A, I>(
)
return experimental_standaloneMiddleware<{
ctx: TRPCContextRuntime<any>
ctx: TRPCContextRuntime<never>
input: I
}>().create(
async ({ ctx, input, next }) => next({

View File

@@ -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",
})
}),
)
}
}))))

View File

@@ -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",
})
}),
)
}
}))))