Context work
This commit is contained in:
@@ -8,6 +8,6 @@ export const router = Effect.gen(function*() {
|
|||||||
const proc = yield* procedure
|
const proc = yield* procedure
|
||||||
|
|
||||||
return t.router({
|
return t.router({
|
||||||
ping: proc.query(() => "pong")
|
ping: proc.query(({ ctx }) => ctx.run(Effect.succeed("pong")))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { CreateExpressContextOptions } from "@trpc/server/adapters/express"
|
import type { CreateExpressContextOptions } from "@trpc/server/adapters/express"
|
||||||
import { Context, Layer } from "effect"
|
import { Context, Effect, Layer, Runtime } from "effect"
|
||||||
|
import type { Services } from "../Services"
|
||||||
import type { TRPCContext } from "./TRPCContext"
|
import type { TRPCContext } from "./TRPCContext"
|
||||||
|
|
||||||
|
|
||||||
@@ -11,5 +12,14 @@ export class CreateTRPCContext extends Context.Tag("CreateTRPCContext")<CreateTR
|
|||||||
>() {}
|
>() {}
|
||||||
|
|
||||||
export module CreateTRPCContext {
|
export module CreateTRPCContext {
|
||||||
export const Live = Layer.sync(CreateTRPCContext, () => ({ req }) => ({ req }))
|
export const Live = Layer.effect(CreateTRPCContext, Effect.gen(function*() {
|
||||||
|
const run = yield* Effect.runtime<Services>().pipe(
|
||||||
|
Effect.map(Runtime.runFork)
|
||||||
|
)
|
||||||
|
|
||||||
|
return ({ req }) => ({
|
||||||
|
req,
|
||||||
|
run,
|
||||||
|
})
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
|
import type { Effect, Runtime } from "effect"
|
||||||
|
import type { RuntimeFiber } from "effect/Fiber"
|
||||||
import type { Request } from "express"
|
import type { Request } from "express"
|
||||||
|
import type { Services } from "../Services"
|
||||||
|
|
||||||
|
|
||||||
export interface TRPCContext {
|
export interface TRPCContext {
|
||||||
req: Request
|
req: Request
|
||||||
|
run: <A, E>(
|
||||||
|
self: Effect.Effect<A, E, Services>,
|
||||||
|
options?: Runtime.RunForkOptions,
|
||||||
|
) => RuntimeFiber<A, E>
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user