1import { bindFunction } from "@/Railway/Bind.ts";
2import { Function } from "@/Railway/Function.ts";
3import * as Effect from "effect/Effect";
4import * as HttpServerResponse from "effect/http/HttpServerResponse";
5import Greeter from "./rpc-greeter.ts";
6import { 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 */
13export 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) {}