Skip to content

Support declarative Durable Object exports on Cloudflare Workers #996

Description

@AugusDogus

tl;dr - I’m building a Cloudflare-native application and want to use Cloudflare’s declarative Durable Object exports with Alchemy v2. This would let me adopt existing Durable Object namespaces without moving or losing their data.

I have draft PRs open in both Alchemy and Distilled, but I wanted to document the use case and make sure the direction makes sense. No hard feelings if this gets closed.

---- FROM HERE DOWN IS AI SLOP ----

Current limitation

Cloudflare’s declarative metadata.exports represents live Durable Object classes and lifecycle tombstones in one desired-state map. It can describe class creation, deletion, renaming, and transfers without maintaining an ordered migration history in application code.

Cloudflare.Worker currently derives legacy metadata.migrations automatically from Durable Object bindings. There is no public Worker prop for the declarative exports contract.

As a result, an application cannot opt into declarative lifecycle management or safely move an existing Alchemy-managed Worker from legacy migrations to declarative exports.

Feature request

Add an opt-in durableObjectExports prop:

yield* Cloudflare.Worker("Api", {
  main: "./worker.ts",
  durableObjectExports: {
    Counter: {
      type: "durable-object",
      storage: "sqlite",
    },
  },
  env: {
    Counter: Cloudflare.DurableObject("Counter"),
  },
});

When the prop is present:

  • Send the declaration as the Worker upload’s exports metadata
  • Treat the map as the complete Durable Object lifecycle declaration
  • Stop generating legacy migration arrays for that Worker
  • Allow one-way adoption from legacy migrations without moving existing data
  • Reject returning an adopted Worker to the legacy migration flow
  • Include the declaration in Worker diffing and pre-create behavior
  • Prevent lifecycle changes from riding a gradual rollout

Workers that omit the prop should retain the existing automatic migration behavior.

Implementation

Draft Alchemy implementation: alchemy-run/alchemy#989

Required generated SDK support: alchemy-run/distilled#394

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions