1import * as HttpRouter from "effect/http/HttpRouter";
2import { TestRoutes } from "./http.ts";
3/**
4 * The Git host with its pack hasher on AWS Lambda (DESIGN §22.11): the
5 * same building-block assembly as `stack.ts`, with `HasherLambda` in place
6 * of the in-process hasher. Needs BOTH provider sets — the Worker binds
7 * `InvokeFunction` cross-cloud (an IAM identity is minted for it).
8 */
9import * as AWS from "@/AWS";
10import * as Cloudflare from "@/Cloudflare";
11import * as Alchemy from "@/index.ts";
12import * as Effect from "effect/Effect";
13import * as Layer from "effect/Layer";
14import {
15 BlobStoreR2,
16 GIT_WORKER_OPTIONS,
17 ApiHandlersLive,
18 ReposDurableObject,
19 RegistryDurableObject,
20} from "@/Git/index.ts";
21import { HasherFunction, HasherLambda } from "@/Git/Hasher/index.ts";
22
23import { TEST_SECRET, TestApi, TestAuthLive } from "./stack.ts";
24export { TEST_SECRET };
25
26const GitObjects = Cloudflare.R2.Bucket("GitLambdaObjects", {
27 forceDestroy: true,
28});
29
30const GitLive = TestRoutes.pipe(
31 Layer.provide(ApiHandlersLive),
32 Layer.provide(ReposDurableObject),
33 Layer.provide(RegistryDurableObject),
34 Layer.provide(HasherLambda(HasherFunction)),
35 Layer.provide(AWS.Lambda.InvokeFunctionHttp),
36 Layer.provide(BlobStoreR2(GitObjects)),
37);
38
39export default class LambdaGitHost extends Cloudflare.Worker<LambdaGitHost>()(
40 "GitLambdaWorker",
41 {
42 main: import.meta.url,
43 ...GIT_WORKER_OPTIONS,
44 observability: { enabled: true },
45 },
46 Effect.gen(function* () {
47 const fetch = yield* HttpRouter.toHttpEffect(GitLive);
48 return { fetch };
49 }),
50) {}
51
52export const makeLambdaTestStack = (name: string) =>
53 Alchemy.Stack(
54 name,
55 {
56 providers: Layer.mergeAll(AWS.providers(), Cloudflare.providers()),
57 state: Cloudflare.state(),
58 },
59 Effect.gen(function* () {
60 const host = yield* LambdaGitHost;
61 return { url: host.url.as<string>() };
62 }),
63 );