| 1 | import { bindFunction } from "@/Railway/Bind.ts"; |
| 2 | import { Function } from "@/Railway/Function.ts"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as HttpServerResponse from "effect/http/HttpServerResponse"; |
| 5 | import Greeter from "./rpc-greeter.ts"; |
| 6 | import { Partition, Site } from "./rpc-shared.ts"; |
| 7 | |
| 8 | /** |
| 9 | * Tagged Function that binds {@link Greeter} and calls `.greet` over the |
| 10 | * private mesh. Public fetch is the only way a laptop can observe the |
| 11 | * trusted call. |
| 12 | */ |
| 13 | export default class Caller extends Function<Caller>()( |
| 14 | "Caller", |
| 15 | { |
| 16 | project: Site, |
| 17 | environment: Partition, |
| 18 | main: import.meta.url, |
| 19 | }, |
| 20 | Effect.gen(function* () { |
| 21 | const greeter = yield* bindFunction(Greeter); |
| 22 | return { |
| 23 | fetch: greeter |
| 24 | .greet("sam") |
| 25 | .pipe(Effect.map((greeting) => HttpServerResponse.text(greeting))), |
| 26 | }; |
| 27 | }), |
| 28 | ) {} |