t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/GCP/Run/fixtures/invoke-caller.ts
Julius Marminge 6f9cea00ae
chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:22:30 -07:00

39 lines
1.4 KiB
TypeScript

import * as GCP from "@/GCP";
import * as Effect from "effect/Effect";
import { HttpServerRequest } from "effect/http/HttpServerRequest";
import * as HttpServerResponse from "effect/http/HttpServerResponse";
import InvokeCallee from "./invoke-callee.ts";
/**
* Public Effect-native Cloud Run Service that calls the private
* {@link InvokeCallee} through `GCP.Run.InvokeService`.
*/
export default class InvokeCaller extends GCP.Function<InvokeCaller>()(
"InvokeCaller",
{
main: import.meta.url,
location: "us-central1",
invokerIamDisabled: true,
},
Effect.gen(function* () {
const callee = yield* GCP.Run.InvokeService(InvokeCallee);
return {
fetch: Effect.gen(function* () {
const request = yield* HttpServerRequest;
const path = new URL(request.originalUrl, "http://localhost").pathname;
const response =
path === "/post"
? yield* callee.fetch("/echo", {
method: "POST",
headers: { "content-type": "text/plain" },
body: "ping",
})
: yield* callee.fetch("/hello");
return yield* HttpServerResponse.json({
status: response.status,
body: response.status === 200 ? yield* response.json : undefined,
});
}).pipe(Effect.orDie),
};
}).pipe(Effect.provide(GCP.Run.InvokeServiceHttp)),
) {}