Skip to content

feat(cloudflare/workers-for-platforms): dispatch namespace binding + deploy workers into namespaces - #715

Merged
sam-goodwin merged 5 commits into
mainfrom
claude/serene-gould-9fca87
Jun 30, 2026
Merged

feat(cloudflare/workers-for-platforms): dispatch namespace binding + deploy workers into namespaces#715
sam-goodwin merged 5 commits into
mainfrom
claude/serene-gould-9fca87

Conversation

@sam-goodwin

@sam-goodwin sam-goodwin commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Add the Workers for Platforms dynamic-dispatch binding and let a Worker deploy into a dispatch namespace as a "user worker" — no duplicate Worker resource.

Bind a dispatch namespace to a platform Worker

Two interchangeable styles, both emitting the native dispatch_namespace binding:

// Effect-native — yield the binding, get a typed client
const dispatch = yield* Cloudflare.WorkersForPlatforms.Get(namespace);
const userWorker = yield* dispatch.get("customer-a"); // Effect<Fetcher, DispatchNamespaceError, RuntimeContext>
// Async / InferEnv — pass the namespace on env, call it directly
const platform = Cloudflare.Worker("Platform", {
  main: "./handler.ts",
  env: { DISPATCH: namespace },          // DispatchNamespace is now a valid env binding
});
type Env = Cloudflare.InferEnv<typeof platform>; // env.DISPATCH : cf.DispatchNamespace

// handler.ts
export default {
  async fetch(request: Request, env: Env) {
    return env.DISPATCH.get("customer-a").fetch(request);
  },
};

Provide Cloudflare.WorkersForPlatforms.GetBinding on the Worker's runtime layer for the Effect-native path.

Worker namespace prop — deploy into a namespace

const ns = yield* Cloudflare.WorkersForPlatforms.DispatchNamespace("Customers", {});
const userWorker = yield* Cloudflare.Worker("CustomerA", {
  namespace: ns.name, // string | DispatchNamespace
  script: `export default { fetch() { return new Response("hi") } }`,
});

The provider switches its put/read/delete/settings calls to the dispatch/namespaces/:ns/scripts endpoints when namespace is set, skips the (inapplicable) subdomain / custom-domain / workers.dev / cron reconciliation and the precreate placeholder, and replaces the Worker if it moves into/out of/between namespaces. Reference the namespace via ns.name (an Output) so it resolves and orders correctly.

Tests

DispatchBinding.test.ts deploys a namespace + a user worker in it + two platform workers (Effect-native Get and async env/InferEnv), then drives each over HttpClient (forwards by script name, asserts the dispatched response + header pass-through), plus an unknown-script negative case. Verified live: fresh deploy → dispatch round-trip for both styles → destroy.

Depends on

distilled patch alchemy-run/distilled#361 (typed errors + a placement-union fix for getDispatchNamespaceScriptSetting (append the omitted response variant)); the submodule pointer is bumped to it here.

🤖 Generated with Claude Code

…deploy workers into namespaces

Add the `Get` dynamic-dispatch binding and teach the Worker resource to
deploy into a dispatch namespace as a user worker.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@alchemy-version-bot

alchemy-version-bot Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Install the packages built from this commit:

alchemy

bun add alchemy@https://pkg.ing/alchemy/5343c81

@alchemy.run/better-auth

bun add @alchemy.run/better-auth@https://pkg.ing/@alchemy.run/better-auth/5343c81

@alchemy.run/pr-package

bun add @alchemy.run/pr-package@https://pkg.ing/@alchemy.run/pr-package/5343c81

sam-goodwin and others added 4 commits June 30, 2026 01:37
…v + InferEnv

Passing a DispatchNamespace on a Worker's `env` now emits a native
`dispatch_namespace` binding, and `InferEnv` types `env.X` as the runtime
`DispatchNamespace`. Adds an async-worker fixture + InferEnv e2e test alongside
the Effect-native `Get` one, and documents both binding styles on the resource.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…acement model

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…mespaceScriptSetting

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@sam-goodwin
sam-goodwin merged commit c9f8961 into main Jun 30, 2026
9 checks passed
@sam-goodwin
sam-goodwin deleted the claude/serene-gould-9fca87 branch June 30, 2026 23:36
DavidJFelix pushed a commit to DavidJFelix/alchemy-effect that referenced this pull request Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant