@fantasticfour/world-cloudflare

中文文档
2.4.3发布于 2026/08/26Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 4709

Cloudflare Durable Objects World implementation with edge-native SQLite storage and global <10ms latency

原始使用文档
文档目录12 节
  1. Why Use This Package
  2. Installation
  3. Prerequisites
  4. Usage
  5. Architecture
  6. Configuration
  7. Test Coverage
  8. Cost Estimate
  9. Local Development
  10. When to Choose This Package
  11. Performance Characteristics
  12. License

@fantasticfour/world-cloudflare

Edge-native workflow backend using Cloudflare Durable Objects with SQLite storage and global sub-10ms latency. Deploy workflows to Cloudflare's global network for maximum performance.

Why Use This Package

  • Edge-First: Runs globally on Cloudflare's network
  • Low Latency: Sub-10ms response times worldwide
  • SQLite Storage: SQL queries within each Durable Object
  • Auto-Scaling: Automatic geographic distribution
  • Real-Time: WebSocket-based streaming
  • Vendor Integration: Native Cloudflare Workers ecosystem

Best for applications requiring global low-latency workflow execution, especially those already on Cloudflare infrastructure.

Installation

pnpm add @fantasticfour/world-cloudflare

Prerequisites

  • Cloudflare Account: Workers paid plan required for Durable Objects
  • Wrangler CLI: For deployment (pnpm add -D wrangler)

Usage

The world talks to its Durable Objects over RPC through the WORKFLOW_DB and WORKFLOW_STREAMS bindings, so it cannot register those classes for you: only your Worker's entrypoint can. Re-export them from your entrypoint or wrangler deploy fails with Your Worker depends on the following Durable Objects, which are not exported in your entrypoint file.

import { createCloudflareWorld } from '@fantasticfour/world-cloudflare';

// Required: wrangler binds these to the classes named in wrangler.toml.
export { StreamDO, WorkflowRunDO } from '@fantasticfour/world-cloudflare/worker';

// In your Cloudflare Worker
export default {
  async fetch(request, env) {
    const world = createCloudflareWorld({ env });

    // Create a workflow run
    const run = await world.runs.create({
      runId: ulid(),
      workflowName: 'my-workflow',
      status: 'pending',
      input: ['arg1', 'arg2'],
      deploymentId: 'production',
      executionContext: {},
      createdAt: new Date(),
      updatedAt: new Date(),
    });

    return new Response(JSON.stringify(run));
  },
};

Architecture

  • Storage: Durable Objects with SQLite (per-workflow-run isolation)
  • Queue: Cloudflare Queues with automatic retries
  • Streaming: WebSocket-based real-time events via Durable Objects
  • Indexing: Workers KV for global workflow lookups
  • IDs: ULID-based for sortable identifiers

Configuration

Configure in wrangler.toml:

All four bindings are required, and the binding names are fixed: createCloudflareWorld reads them off env by name.

name = "my-workflow-app"
main = "src/index.ts" # the entrypoint that re-exports StreamDO and WorkflowRunDO
compatibility_date = "2024-11-27"
compatibility_flags = ["nodejs_compat"]

[[durable_objects.bindings]]
name = "WORKFLOW_DB"
class_name = "WorkflowRunDO"

[[durable_objects.bindings]]
name = "WORKFLOW_STREAMS"
class_name = "StreamDO"

# Both classes use DO SQLite storage, so they must be introduced as
# new_sqlite_classes. Without this migration the bindings resolve but every
# storage call fails at runtime.
[[migrations]]
tag = "v1"
new_sqlite_classes = ["WorkflowRunDO", "StreamDO"]

[[queues.producers]]
queue = "workflow-queue"
binding = "WORKFLOW_QUEUE"

[[kv_namespaces]]
binding = "WORKFLOW_INDEX"
id = "your-kv-namespace-id"

Test Coverage

This package includes comprehensive tests:

  • storage.test.ts: CRUD operations, Durable Object integration, status transitions
  • spec.test.ts: @workflow/world interface compliance
  • durable-objects.test.ts: DO isolation, state persistence, KV indexing, concurrent updates

Total: ~1,350 lines of test coverage ensuring production reliability.

Cost Estimate

Cloudflare Pricing:

  • Durable Objects: $0.15/million requests
  • Queues: $0.40/million operations
  • Workers KV: $0.50/million reads
  • Workers: Included with paid plan ($5/month)

Estimated Monthly Cost:

  • Low usage (100K workflows/month): $5-10
  • Medium usage (1M workflows/month): $10-20
  • High usage (10M workflows/month): $50-100

Note: Requires Workers paid plan ($5/month minimum).

Local Development

Use Wrangler for local development:

# Install wrangler
pnpm add -D wrangler

# Run locally with Miniflare
pnpm wrangler dev

# Deploy to Cloudflare
pnpm wrangler deploy

When to Choose This Package

Use world-cloudflare when:

  • Global sub-10ms latency required
  • Already using Cloudflare Workers
  • Edge computing benefits needed
  • WebSocket streaming important
  • Vendor lock-in acceptable

Consider alternatives when:

  • Multi-cloud strategy required -> use @fantasticfour/world-upstash
  • Traditional infrastructure preferred -> use @fantasticfour/world-postgres-redis
  • Cost optimization priority -> use @fantasticfour/world-redis
  • AWS ecosystem -> use @fantasticfour/world-dynamodb-sqs

Performance Characteristics

  • Latency: <10ms globally (edge deployment)
  • Cold Starts: Minimal (~1-5ms for Durable Objects)
  • Throughput: Scales automatically with traffic
  • Geographic Distribution: Automatic via Cloudflare network

License

Apache License

版本与发布记录

@fantasticfour/world-cloudflare 共发布 17 个版本,首次发布于 2025/11/28;过去 12 个月发布了 17 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.4.3latest2026/08/262 个月前
2.4.22026/08/262 个月前
2.4.12026/08/202 个月前
2.4.02026/08/202 个月前
2.3.12026/07/114 个月前
2.3.02026/07/114 个月前

关于 @fantasticfour/world-cloudflare 的常见问题

@fantasticfour/world-cloudflare 是什么?

Cloudflare Durable Objects World implementation with edge-native SQLite storage and global <10ms latency

如何安装 @fantasticfour/world-cloudflare?

在项目目录运行 npm install @fantasticfour/world-cloudflare,或使用 pnpm add / yarn add / bun add。

@fantasticfour/world-cloudflare 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@fantasticfour/world-cloudflare 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@fantasticfour/world-cloudflare 可以商用吗?

@fantasticfour/world-cloudflare 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@fantasticfour/world-cloudflare 的下载量有多少?

根据 npm 官方下载统计,@fantasticfour/world-cloudflare 在 2026/10/15 – 2026/11/13 这 30 天内被下载 4,709 次,日均约 157 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@fantasticfour/world-cloudflare 还在维护吗?

最新版本 2.4.3 发布于 2026/08/26(2 个月前);至今共发布 17 个版本,其中过去 12 个月发布了 17 个;首次发布于 2025/11/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。