| 1 | import * as HttpRouter from "effect/http/HttpRouter"; |
| 2 | import { TestRoutes } from "./http.ts"; |
| 3 | /** |
| 4 | * The Git host with its pack hasher on dynamically loaded Workers (DESIGN |
| 5 | * §22.12): the same building-block assembly as `stack.ts`, with |
| 6 | * `HasherWorkerLoader` in place of the in-process hasher. |
| 7 | */ |
| 8 | import * as Cloudflare from "@/Cloudflare"; |
| 9 | import * as Alchemy from "@/index.ts"; |
| 10 | import * as Effect from "effect/Effect"; |
| 11 | import * as Layer from "effect/Layer"; |
| 12 | import { |
| 13 | BlobStoreR2, |
| 14 | GIT_WORKER_OPTIONS, |
| 15 | ApiHandlersLive, |
| 16 | ReposDurableObject, |
| 17 | RegistryDurableObject, |
| 18 | } from "@/Git/index.ts"; |
| 19 | import { HasherWorkerLoader } from "@/Git/Hasher/index.ts"; |
| 20 | |
| 21 | import { TEST_SECRET, TestApi, TestAuthLive } from "./stack.ts"; |
| 22 | export { TEST_SECRET }; |
| 23 | |
| 24 | const GitObjects = Cloudflare.R2.Bucket("GitLoaderObjects", { |
| 25 | forceDestroy: true, |
| 26 | }); |
| 27 | |
| 28 | const GitLive = TestRoutes.pipe( |
| 29 | Layer.provide(ApiHandlersLive), |
| 30 | Layer.provide(ReposDurableObject), |
| 31 | Layer.provide(RegistryDurableObject), |
| 32 | Layer.provide(HasherWorkerLoader()), |
| 33 | Layer.provide(BlobStoreR2(GitObjects)), |
| 34 | ); |
| 35 | |
| 36 | export default class LoaderGitHost extends Cloudflare.Worker<LoaderGitHost>()( |
| 37 | "GitLoaderWorker", |
| 38 | { |
| 39 | main: import.meta.url, |
| 40 | ...GIT_WORKER_OPTIONS, |
| 41 | observability: { enabled: true }, |
| 42 | }, |
| 43 | Effect.gen(function* () { |
| 44 | const fetch = yield* HttpRouter.toHttpEffect(GitLive); |
| 45 | return { fetch }; |
| 46 | }), |
| 47 | ) {} |
| 48 | |
| 49 | export const makeLoaderTestStack = (name: string) => |
| 50 | Alchemy.Stack( |
| 51 | name, |
| 52 | { providers: Cloudflare.providers(), state: Cloudflare.state() }, |
| 53 | Effect.gen(function* () { |
| 54 | const host = yield* LoaderGitHost; |
| 55 | return { url: host.url.as<string>() }; |
| 56 | }), |
| 57 | ); |