Diffinery

homeflare/celldpublic

celld/docs/cloudflare-compat.md
176 lines · 12.0 KBRaw History
1# Cloudflare compatibility
2
3celld runs the Workers runtime, with Durable Objects as the stateful
4core: module Workers, fetch, JS RPC, service bindings, and static assets.
5This page shows that Worker surface, API by API. celld does not run the
6rest of the Cloudflare platform, and the scope rule is simple: if
7Cloudflare builds a function on Durable Objects, celld can get that
8function, and a function on a different primitive is out of scope.
9Cloudflare builds D1 on Durable Objects, so a D1 binding is a thin layer
10over what celld already has. KV is a global cache with eventual
11consistency, and R2 is blob storage: different systems, not on the
12roadmap.
13
14A configuration or binding that is not available must fail loudly, at
15deploy or at first use. A silent compatibility gap is a bug; the known
16gaps have marks below.
17
18## Services
19
20| service | notes |
21| --- | --- |
22| **Workers** | Module Workers: `fetch`, JS RPC, service bindings, Durable Object bindings, `vars`. |
23| **Durable Objects** | The stateful core. SQLite storage, alarms, inbound hibernatable WebSockets, outbound `ws:`/`wss:` WebSocket clients (constructor and `fetch()` upgrade), one writer for each cell, names as addresses, RPC methods on stubs. |
24| **Static assets** | Immutable files, served from the fleet bucket: `assets.directory`, `binding`, `html_handling`, `not_found_handling`, `run_worker_first`, plus `_headers` and `_redirects`. An asset-only project deploys without a Worker. |
25| **Worker Loader (Code Mode)** | Experimental. Bind a loader with `CELLD_WORKER_LOADER`. A Worker can then start sandboxed isolates at runtime. See [Dynamic Worker loading](#dynamic-worker-loading-code-mode). |
26
27Planned: **D1** (a D1 database is a Durable Object with a SQL API; celld
28already has the hard part), **Workflows** (durable execution over cells
29and alarms), **Queues** (a Durable Object shape; if demand appears).
30
31A note on durable execution, because the two terms are close. A
32durable-execution engine (Temporal, Restate, Azure Durable Functions)
33models a process: a sequence of steps that ends. A cell models an
34entity: a named unit with state that persists indefinitely. You can
35build either primitive on the other — Cloudflare builds Workflows on
36Durable Objects — so choose the one that matches the shape of the
37problem. A concert, a user, and a document are entities; an order
38pipeline is a process.
39
40Not planned: **KV** (a different consistency model), **R2** (celld runs
41*on* blob storage; celld does not provide blob storage; declared
42`r2_buckets` bindings load, but each method throws), **Cache API**,
43**Workers AI, Vectorize, Hyperdrive, Browser Rendering, Email** (managed
44platform services; an experimental HTTP adapter for an AI binding exists
45behind `CELLD_AI_URL`), **cron triggers, custom domains, TLS
46termination** (platform surface; celld has its own durable alarms; put
47TLS in your ingress proxy), **Python Workers** (workerd supplies the
48Pyodide runtime and the Python module shim; that layer is platform
49surface, not a function on Durable Objects; celld can add support if
50demand appears).
51
52## Runtime APIs
53
54Cloudflare's [Runtime APIs
55index](https://developers.cloudflare.com/workers/runtime-apis/), category
56by category:
57
58| API | status |
59| --- | --- |
60| Fetch, Request, Response, Headers | **Yes.** Gaps: `Response.redirect()`, `Response.error()`, and the `cache` request option are missing. |
61| Bindings (`env`) | **Yes** for Durable Objects, service bindings, `vars`, assets. Other binding types are out of scope (see Services). |
62| Context (`ctx`) | **Yes**: `waitUntil`, `props`, `exports`. `passThroughOnException()` is accepted but has no effect. There is no CDN behind it. `ctx.facets` is absent (see Facets). |
63| Handlers | `fetch`, `alarm`, `webSocketMessage`/`Close`/`Error`, RPC methods. **No** `scheduled` (cron), `queue`, `tail`, or `email` handlers. |
64| RPC | **Yes**, for most of the surface. See [RPC](#rpc). |
65| Streams | **Yes.** This includes byte streams, BYOB readers, `tee`/`pipeTo`/`pipeThrough`, `IdentityTransformStream`, `FixedLengthStream`, and `CompressionStream`/`DecompressionStream`. Gap: `ReadableStream.from()`. |
66| Encoding | **Yes**: `TextEncoder`/`TextDecoder` (legacy encodings included), encoder and decoder streams, `atob`/`btoa`. |
67| WebSockets | **Yes**, inbound (hibernatable, with attachments) and outbound. An attachment holds anything that structured clone accepts. Auto-response works: `setWebSocketAutoResponse` answers a matched message without a wake of the cell. Gap: `getTags()`. |
68| Web Crypto | **Partial**: `digest` (including MD5), HMAC sign and verify, AES-GCM, RSA-OAEP decrypt, Ed25519 and ECDSA-P256 sign, and `verify` for RSASSA-PKCS1-v1_5 and ECDSA-P256 (RS256 and ES256 JWTs). `importKey` and `exportKey` handle `spki`, `pkcs8`, `jwk` and `raw` for RSA, EC (P-256, P-384, P-521), Ed25519 and X25519, validating at import; keys cross to `node:crypto` through `KeyObject.from()`. `generateKey` covers AES, HMAC, RSA (OAEP, PKCS#1 v1.5, PSS), EC P-256 and Ed25519. Cloudflare's extensions `timingSafeEqual` and `DigestStream` (with CRC32, CRC32C and CRC64-NVME) are available. AES-CBC, AES-CTR and AES-GCM (12- or 16-byte IVs). ECDH `deriveBits` and `deriveKey` on P-256, P-384 and P-521. Missing: `wrapKey`/`unwrapKey`, RSA-PSS *signing*, HKDF and PBKDF2 through `deriveBits` (they are available through `node:crypto`). An algorithm that is not available throws. |
69| Web standards | **Yes**: `URL`, `URLSearchParams`, `URLPattern`, `AbortController`/`AbortSignal` (with `timeout()`, `any()`; a signal does **not** abort across an RPC call, and `signal.onabort` is accepted but never invoked — use `addEventListener('abort')`), `Blob`/`File`/`FormData`, `Event`/`EventTarget`, `DOMException`, `queueMicrotask`, `structuredClone` (not conformant on exotic types), `navigator.userAgent`. |
70| WebAssembly | **Yes** (V8's own, without restrictions). A bundle can import a `.wasm` file as a compiled module, as on Cloudflare; see [WebAssembly](wasm.md). |
71| Performance and timers | `setTimeout`/`clearTimeout`, `setImmediate`, `scheduler.wait()`. `setInterval` throws. `performance.now()` has millisecond resolution. The other parts of `performance` are stubs. |
72| Console | `log`/`info`/`warn`/`error` are real. `debug`/`trace`/`group`/`table` do nothing. `assert`/`time`/`count` are absent. |
73| Node.js compatibility | **Partial.** See [node: imports](#node-imports). |
74| Facets (`ctx.facets`) | **No.** A Durable Object cannot create a facet, and `ctx.facets` is not defined. celld also has no first-class `DurableObjectClass` value, so `ctx.exports` gives no stub for a Durable Object class that the configuration does not declare. |
75| Cache (`caches`) | **No.** |
76| HTMLRewriter | **No.** |
77| TCP sockets (`cloudflare:sockets`) | **No.** Known silent gap: `connect()` currently gives an inert stub. It does not throw. |
78| EventSource, MessageChannel, BroadcastChannel | **No.** The classes exist so that bundles load, but they do nothing. |
79
80## RPC
81
82celld implements the Workers [JS RPC
83system](https://developers.cloudflare.com/workers/runtime-apis/rpc/):
84`WorkerEntrypoint` and `RpcTarget` from `cloudflare:workers`, named
85entrypoints on service bindings, and method calls on Durable Object stubs
86(this needs `extends DurableObject`, or the `js_rpc` compat flag).
87Arguments and returns use structured clone. Functions, streams, and
88`RpcTarget`s become stubs. Promise pipelining, `ctx.exports` loopback
89stubs, and stubs in DO storage are available. `ctx.exports` covers the
90entrypoints that the configuration declares, so it gives no stub for an
91undeclared Durable Object class.
92
93The current limits: a cross-isolate service binding with a named
94entrypoint can do single method calls, but not `fetch()`, awaitable
95properties, or pipelined paths; a same-isolate binding has the full
96surface.
97
98A stub cannot cross an isolate boundary yet, and a Durable Object is its
99own isolate. A Durable Object method therefore takes and returns
100structured-cloneable values. If you pass a function to one, or return an
101`RpcTarget` from one, the call throws `RPC stubs cannot cross isolate
102boundaries yet`. Callbacks, `RpcTarget` instances and promise pipelining
103all work through `ctx.exports`, which shares the isolate. The
104[`rpc` example](https://github.com/denoland/celld/tree/main/examples/rpc)
105shows each of these.
106
107## Dynamic Worker loading (Code Mode)
108
109Set `CELLD_WORKER_LOADER=LOADER`. Workers then get `env.LOADER`. This is
110an experimental port of Cloudflare's [Worker
111Loader](https://developers.cloudflare.com/workers/runtime-apis/bindings/worker-loader/).
112`loader.get(name, getCode)` (memoized) and `loader.load(code)` start a
113new isolate for each loaded worker. These inputs are honored:
114`mainModule`, sibling `modules`, `compatibilityDate`/`Flags`, plain-JSON
115`env`, and `globalOutbound: null` (no egress). The limits of workerd
116apply: 64 MiB of code and 1 MiB of env, plus the
117`CELLD_MAX_LOADED_WORKERS` limit. A loaded worker serves `fetch()` and
118single RPC method calls. Not yet available: `globalOutbound` as a
119Fetcher, capability stubs in `env`, awaitable or pipelined properties.
120
121## node: imports
122
123`node:` specifiers are always available; the `nodejs_compat` flag is not
124necessary, and celld does not read it. `celld deploy` externalizes
125`node:*` at bundle time. The runtime supplies its own subset (it does not
126use the Wrangler-style unenv polyfills):
127
128- **Implemented**: `node:assert`, `node:async_hooks` (a real
129 `AsyncLocalStorage`), `node:buffer`, `node:events`, `node:path`,
130 `node:stream` (+ `stream/web`, `stream/promises`, `stream/consumers`),
131 `node:timers/promises`, `node:util`.
132- **Partial**: `node:crypto` (hashes, HMAC, HKDF, PBKDF2, `webcrypto`, secret
133 key objects, asymmetric keys, and one-shot signatures. `createPublicKey` and
134 `createPrivateKey` read PEM, DER and JWK for RSA, EC (P-256, P-384, P-521),
135 Ed25519, X25519 and DSA, including password-protected PKCS#8, and give a key
136 with `asymmetricKeyType`, `asymmetricKeyDetails`, `toCryptoKey()` and
137 `export()` to DER, PEM or JWK. `generateKeyPairSync` covers RSA, EC P-256,
138 Ed25519 and X25519. `sign()` and `verify()` cover Ed25519, RSA PKCS#1 v1.5
139 and ECDSA P-256, with DER signatures as Node's `dsaEncoding` default
140 requires. What still throws: Diffie-Hellman throughout, the streaming
141 `createSign`/`createVerify`, ciphers, RSA-PSS, DSA signing, and key
142 generation for DSA and DH), `node:zlib` (only the sync `gzip`/`deflate`
143 family), `node:fs` (reads fail with `ENOENT`, `existsSync` is `false`).
144- **Not implemented**: the rest — `node:http(s)`, `node:net`,
145 `node:tls`, `node:dns`, `node:os`, `node:process` (the `process`
146 global exists, the module does not), `node:worker_threads`, `node:vm`,
147 `node:child_process`, and the others. Known silent gap: these
148 currently give inert stubs. They do not fail the import.
149
150## Compatibility flags
151
152`compatibility_date` and `compatibility_flags` are honored for the
153switches that celld models: `delete_all_deletes_alarm`, `js_rpc`,
154`fetcher_no_get_put_delete`, `sqlite_vec`, `websocket_standard_binary_type`,
155and the assets navigation behavior. The `sqlite_vec` flag enables the pre-v1
156sqlite-vec extension, and a compatibility date never enables it.
157`Cloudflare.compatibilityFlags` reports only
158the flags that celld honors. A flag that celld does not model is absent
159rather than reported as enabled, and celld accepts it without effect.
160
161## Wrangler configuration
162
163`celld deploy` builds a standard Wrangler project (esbuild on `PATH`)
164and accepts `wrangler.jsonc` or `wrangler.json`, not `wrangler.toml`.
165The available config keys are `name`, `main`,
166`compatibility_date`, `compatibility_flags`, `durable_objects`,
167`migrations`, `assets`, `services`, and `vars`. An asset-only project can
168omit `main`. celld refuses symlinks and special files in the asset
169directory, and `.assetsignore` still needs Wrangler. Each other key —
170`routes`, `kv_namespaces`, `triggers`, and the rest — stops the deploy
171with an error that names the key: remove the key, or deploy that project
172with Wrangler.
173
174This page is the reference for the implemented Worker surface. For the
175operational boundaries of the current release — TLS, platforms, pressure
176shedding, updates — see the [limitations](limitations.md).