1import * as Cloudflare from "@/Cloudflare";
2import * as Alchemy from "@/index.ts";
3import * as Effect from "effect/Effect";
4import * as path from "pathe";
5import type { Probe } from "./worker.ts";
6
7/**
8 * The "Bind on an async Worker" shape from the Containers guide, exactly as
9 * issue #1321 reported it: one name for the env key, the Container's logical
10 * id AND the Durable Object class — `className` omitted, so it defaults to
11 * the env key.
12 *
13 * Distinct from `fixtures/async` (which names a class that differs from the
14 * env key): with all three names equal there is nothing left to tell the
15 * Worker's `durable_object_namespace` binding and its `containers` metadata
16 * apart, so this is the shape that collapsed under one `sid` and lost the
17 * namespace binding (see "async container bound on env" in
18 * `Container.test.ts`).
19 */
20export const InferredClassWorker = Cloudflare.Worker("InferredClassWorker", {
21 main: path.resolve(import.meta.dirname, "worker.ts"),
22 env: {
23 Probe: Cloudflare.Container<Probe>("Probe", {
24 image: "mendhak/http-https-echo:latest",
25 }),
26 },
27});
28
29export default (state = Cloudflare.state()) =>
30 Alchemy.Stack(
31 "InferredClassContainerStack",
32 { providers: Cloudflare.providers(), state },
33 Effect.gen(function* () {
34 const worker = yield* InferredClassWorker;
35 return { url: worker.url.as<string>() };
36 }),
37 );