Diffinery

homeflare/celldpublic

celld/docs/cloudflare-compat.md
139 lines · 8.7 KBRaw History
1# Cloudflare compatibility
2
3celld runs the Workers runtime — module Workers, fetch, JS RPC, service
4bindings, static assets — with Durable Objects as its stateful core. That
5Worker surface is the bulk of this page, documented API by API below. What
6celld does not run is the rest of the Cloudflare platform, and there the
7scope rule is simple: **anything built on Durable Objects is in reach; a
8fundamentally different primitive is out.** Cloudflare builds D1 on Durable
9Objects, so a D1 binding is a thin layer over what celld already has. KV is
10a globally-replicated eventually-consistent edge cache and R2 is blob
11storage — different systems, not on the roadmap.
12
13Unsupported configuration and bindings should fail loudly at deploy or at
14first use. Silent compatibility gaps are bugs; the known ones are marked
15below.
16
17## Services
18
19| service | notes |
20| --- | --- |
21| **Workers** | Module Workers: `fetch`, JS RPC, service bindings, Durable Object bindings, `vars`. |
22| **Durable Objects** | The stateful core. SQLite storage, alarms, inbound hibernatable WebSockets, outbound `ws:`/`wss:` WebSocket clients (constructor and `fetch()` upgrade), single-writer semantics, addressed by name, RPC methods on stubs. |
23| **Static assets** | Co-deployed immutable files, served from the fleet bucket: `assets.directory`, `binding`, `html_handling`, `not_found_handling`, `run_worker_first`, plus `_headers` and `_redirects`. Asset-only projects deploy without a Worker. |
24| **Worker Loader (Code Mode)** | Experimental: bind a loader with `CELLD_WORKER_LOADER` and a Worker can spawn sandboxed isolates at runtime. See [Dynamic Worker loading](#dynamic-worker-loading-code-mode). |
25
26Planned: **D1** (a D1 database is a Durable Object with a SQL API; celld
27already has the hard part), **Workflows** (durable execution over cells and
28alarms), **Queues** (DO-shaped; if demand appears).
29
30Not planned: **KV** (a different consistency model), **R2** (blob storage is
31what celld runs *on*, not what it provides — declared `r2_buckets` bindings
32load, but every method throws), **Cache API**, **Workers AI, Vectorize,
33Hyperdrive, Browser Rendering, Email** (managed platform services; an
34experimental HTTP adapter for an AI binding exists behind `CELLD_AI_URL`),
35**cron triggers, custom domains, TLS termination** (platform surface — celld
36has its own durable alarms; put TLS in your ingress proxy).
37
38## Runtime APIs
39
40Cloudflare's [Runtime APIs
41index](https://developers.cloudflare.com/workers/runtime-apis/), category by
42category:
43
44| API | status |
45| --- | --- |
46| Fetch, Request, Response, Headers | **Yes.** Gaps: `Response.redirect()`/`Response.error()` and the `cache` request option are missing. |
47| Bindings (`env`) | **Yes** for Durable Objects, service bindings, `vars`, assets. Other binding types are out of scope (see Services). |
48| Context (`ctx`) | **Yes**: `waitUntil`, `props`, `exports`. `passThroughOnException()` is accepted but has no effect — there is no CDN behind it. |
49| Handlers | `fetch`, `alarm`, `webSocketMessage`/`Close`/`Error`, RPC methods. **No** `scheduled` (cron), `queue`, `tail`, or `email` handlers. |
50| RPC | **Yes**, substantially — see [RPC](#rpc). |
51| Streams | **Yes**, including byte streams, BYOB readers, `tee`/`pipeTo`/`pipeThrough`, `IdentityTransformStream`, `FixedLengthStream`, `CompressionStream`/`DecompressionStream`. Gap: `ReadableStream.from()`. |
52| Encoding | **Yes**: `TextEncoder`/`TextDecoder` (legacy encodings included), encoder/decoder streams, `atob`/`btoa`. |
53| WebSockets | **Yes**, inbound (hibernatable, with attachments) and outbound. Gap: auto-response (`WebSocketRequestResponsePair`) and `getTags()`. |
54| Web Crypto | **Partial**: `digest`, HMAC sign/verify, AES-GCM, RSA-OAEP decrypt, Ed25519/ECDSA-P256 sign, `getRandomValues`, `randomUUID`. Missing: `deriveKey`/`deriveBits`/`wrapKey`/`unwrapKey`, non-HMAC `verify`, `DigestStream`. Unsupported algorithms throw. |
55| Web standards | **Yes**: `URL`, `URLSearchParams`, `URLPattern`, `AbortController`/`AbortSignal` (incl. `timeout()`, `any()`), `Blob`/`File`/`FormData`, `Event`/`EventTarget`, `DOMException`, `queueMicrotask`, `structuredClone` (non-conformant on exotic types), `navigator.userAgent`. |
56| WebAssembly | **Yes** (V8's own, unrestricted). |
57| Performance and timers | `setTimeout`/`clearTimeout`, `setImmediate`, `scheduler.wait()`. `setInterval` throws. `performance.now()` has millisecond resolution and `performance` is otherwise a stub. |
58| Console | `log`/`info`/`warn`/`error` are real; `debug`/`trace`/`group`/`table` are no-ops; `assert`/`time`/`count` are absent. |
59| Node.js compatibility | **Partial** — see [node: imports](#node-imports). |
60| Cache (`caches`) | **No.** |
61| HTMLRewriter | **No.** |
62| TCP sockets (`cloudflare:sockets`) | **No.** Known silent gap: `connect()` currently resolves to an inert stub instead of throwing. |
63| EventSource, MessageChannel, BroadcastChannel | **No.** The classes exist so bundles load, but they are inert. |
64
65## RPC
66
67The Workers [JS RPC
68system](https://developers.cloudflare.com/workers/runtime-apis/rpc/) is
69implemented: `WorkerEntrypoint` and `RpcTarget` from `cloudflare:workers`,
70named entrypoints on service bindings, arbitrary method calls on Durable
71Object stubs (requires `extends DurableObject`, or the `js_rpc` compat
72flag), structured-clone arguments and returns with stub lifting for
73functions, streams, and `RpcTarget`s, promise pipelining, `ctx.exports`
74loopback stubs, and stubs persisted in DO storage.
75
76Current limits: a cross-isolate service binding with a named entrypoint
77supports single method calls but not `fetch()`, awaitable properties, or
78pipelined paths; same-isolate bindings support the full surface.
79
80## Dynamic Worker loading (Code Mode)
81
82Set `CELLD_WORKER_LOADER=LOADER` and Workers get `env.LOADER`, an
83experimental port of Cloudflare's [Worker
84Loader](https://developers.cloudflare.com/workers/runtime-apis/bindings/worker-loader/):
85`loader.get(name, getCode)` (memoized) and `loader.load(code)` spawn a fresh
86isolate per loaded worker; `mainModule`, sibling `modules`,
87`compatibilityDate`/`Flags`, plain-JSON `env`, and `globalOutbound: null`
88(deny egress) are honored, with workerd's 64 MiB code and 1 MiB env limits
89and a `CELLD_MAX_LOADED_WORKERS` cap. Loaded workers serve `fetch()` and
90single RPC method calls. Not yet: `globalOutbound` as a Fetcher, capability
91stubs in `env`, awaitable or pipelined properties.
92
93## node: imports
94
95`node:` specifiers are always available — the `nodejs_compat` flag is not
96required and not read. `celld deploy` externalizes `node:*` at bundle time
97and the runtime provides its own subset (Wrangler-style unenv polyfills are
98not used):
99
100- **Implemented**: `node:assert`, `node:async_hooks` (a real
101 `AsyncLocalStorage`), `node:buffer`, `node:events`, `node:path`,
102 `node:stream` (+ `stream/web`, `stream/promises`, `stream/consumers`),
103 `node:timers/promises`, `node:util`.
104- **Partial**: `node:crypto` (hashes, HMAC, HKDF, PBKDF2, key objects,
105 `webcrypto`; signatures, ciphers, and DH throw), `node:zlib` (sync
106 `gzip`/`deflate` family only), `node:fs` (reads fail with `ENOENT`,
107 `existsSync` is `false`).
108- **Not implemented**: everything else — `node:http(s)`, `node:net`,
109 `node:tls`, `node:dns`, `node:os`, `node:process` (the `process` global
110 exists, the module does not), `node:worker_threads`, `node:vm`,
111 `node:child_process`, and the rest. Known silent gap: these currently
112 resolve to inert stubs instead of failing the import.
113
114## Compatibility flags
115
116`compatibility_date` and `compatibility_flags` are honored for the switches
117celld models: `delete_all_deletes_alarm`, `js_rpc`,
118`fetcher_no_get_put_delete`, `websocket_standard_binary_type`, and the
119assets navigation behavior. `Cloudflare.compatibilityFlags` reports only
120flags celld actually honors; a flag celld does not model is absent rather
121than reported as enabled — and is otherwise accepted without effect.
122
123## Wrangler configuration
124
125`celld deploy` builds a standard Wrangler project (esbuild on `PATH`) and
126accepts `wrangler.jsonc` or `wrangler.json` — not `wrangler.toml`. The
127supported config keys are `name`, `main`, `compatibility_date`,
128`compatibility_flags`, `durable_objects`, `migrations`, `assets`,
129`services`, and `vars`; `main` may be omitted for an asset-only project.
130Symlinks and special files in the asset directory are refused, and
131`.assetsignore` still requires Wrangler. Any other key — `routes`,
132`kv_namespaces`, `triggers`, and the rest — fails the deploy with an error
133naming it rather than being silently dropped. Remove it or deploy that
134project with Wrangler.
135
136This page is the definitive reference for the implemented Worker surface.
137For the operational boundaries of the current release — TLS, platform
138support, pressure shedding, updates — see the
139[limitations](limitations.md).