durable-objects

Create and review Cloudflare Durable Objects for stateful coordination, RPC, SQLite storage, alarms, and WebSockets.

Updated Nov 23, 2024
One-click install
npx skills add https://github.com/tokisakiyuu/dotfiles --skill durable-objects-tokisakiyuu
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: durable-objects
Source: https://github.com/tokisakiyuu/dotfiles/tree/main/home/dot_claude/skills/durable-objects
Command: npx skills add https://github.com/tokisakiyuu/dotfiles --skill durable-objects-tokisakiyuu

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Building stateful, coordinated applications on Cloudflare's edge requires deep knowledge of Durable Objects APIs, concurrency rules, storage patterns, and wrangler configuration, and outdated knowledge leads to subtle bugs like race conditions, lost state, and throughput bottlenecks. ## Core Features & Use Cases - Durable Object Implementation: Create DO classes with RPC methods, SQLite storage, schema migrations, alarms, and WebSocket hibernation following current best practices. - Code Review: Audit existing DO code for anti-patterns such as global singleton DOs, misused blockConcurrencyWhile, and unpersisted in-memory state. - Testing & Configuration: Set up Vitest tests with @cloudflare/vitest-pool-workers and configure wrangler bindings, migrations, and Workers handlers. - Use Case: When building a multiplayer game backend, use this Skill to design one DO per match with deterministic getByName routing, SQLite-backed state, and alarm-based turn timeouts. ## Quick Start Use the durable-objects skill to create a chat room Durable Object with SQLite message storage and WebSocket support, including the wrangler configuration.

Frequently Asked Questions about durable-objects

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a Cloudflare Durable Object with SQLite storage?▼

Extend the DurableObject class from cloudflare:workers and configure a wrangler migration with new_sqlite_classes. Initialize tables inside the constructor using ctx.blockConcurrencyWhile and access storage synchronously via ctx.storage.sql.exec.

How do I test Durable Objects with Vitest?▼

Use @cloudflare/vitest-pool-workers with defineWorkersConfig pointing at your wrangler config. Access stubs via env from cloudflare:test, inspect internals with runInDurableObject, and trigger alarms instantly with runDurableObjectAlarm.

Should I use RPC methods or fetch handlers in Durable Objects?▼

Use RPC methods with compatibility date 2024-04-03 or later. Public class methods become typed RPC endpoints callable directly on the stub, giving you type safety that a manual fetch handler lacks.

Why does my Durable Object have race conditions with external API calls?▼

Storage operations are protected by input and output gates, but fetch and other non-storage I/O allow request interleaving. Use optimistic locking with version numbers or transactions to guard state across external calls.

When should I not use Durable Objects?▼

Avoid Durable Objects for stateless request handling, which plain Workers handle better, and for workloads needing maximum global distribution or high fan-out of independent requests. DOs excel at per-entity coordination and strong consistency.

How do Durable Object alarms work?▼

Each DO supports one alarm at a time, and calling setAlarm replaces any existing alarm. The alarm handler runs with automatic retries on failure, so handlers should be idempotent and can reschedule by calling setAlarm again.