| 1 | import { DurableObject } from "cloudflare:workers"; |
| 2 | |
| 3 | // Minimal async (non-Effect) Worker that hosts Durable Object classes. |
| 4 | // Used by the `durableObjectNamespaces` stability tests: deploying with a DO |
| 5 | // binding populates `worker.durableObjectNamespaces.<ClassName>` with the |
| 6 | // namespace id Cloudflare assigns, which a downstream resource then references. |
| 7 | export class Counter extends DurableObject { |
| 8 | async increment() { |
| 9 | const count = ((await this.ctx.storage.get<number>("count")) ?? 0) + 1; |
| 10 | await this.ctx.storage.put("count", count); |
| 11 | return count; |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | export class Meter extends DurableObject { |
| 16 | async read() { |
| 17 | return (await this.ctx.storage.get<number>("value")) ?? 0; |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | export default { |
| 22 | // The DOs only need to be *hosted* (declared + class exported) to populate |
| 23 | // `worker.durableObjectNamespaces`; the fetch handler intentionally doesn't |
| 24 | // invoke them so the webhook's live URL probe always gets a clean 200. |
| 25 | fetch: async () => new Response("ok"), |
| 26 | }; |