Diffinery

homeflare/celldpublic

celld/docs/cloudflare-compat.md
142 lines · 8.7 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
31Not planned: **KV** (a different consistency model), **R2** (celld runs
32*on* blob storage; celld does not provide blob storage; declared
33`r2_buckets` bindings load, but each method throws), **Cache API**,
34**Workers AI, Vectorize, Hyperdrive, Browser Rendering, Email** (managed
35platform services; an experimental HTTP adapter for an AI binding exists
36behind `CELLD_AI_URL`), **cron triggers, custom domains, TLS
37termination** (platform surface; celld has its own durable alarms; put
38TLS in your ingress proxy).
39
40## Runtime APIs
41
42Cloudflare's [Runtime APIs
43index](https://developers.cloudflare.com/workers/runtime-apis/), category
44by category:
45
46| API | status |
47| --- | --- |
48| Fetch, Request, Response, Headers | **Yes.** Gaps: `Response.redirect()`, `Response.error()`, and the `cache` request option are missing. |
49| Bindings (`env`) | **Yes** for Durable Objects, service bindings, `vars`, assets. Other binding types are out of scope (see Services). |
50| Context (`ctx`) | **Yes**: `waitUntil`, `props`, `exports`. `passThroughOnException()` is accepted but has no effect. There is no CDN behind it. |
51| Handlers | `fetch`, `alarm`, `webSocketMessage`/`Close`/`Error`, RPC methods. **No** `scheduled` (cron), `queue`, `tail`, or `email` handlers. |
52| RPC | **Yes**, for most of the surface. See [RPC](#rpc). |
53| Streams | **Yes.** This includes byte streams, BYOB readers, `tee`/`pipeTo`/`pipeThrough`, `IdentityTransformStream`, `FixedLengthStream`, and `CompressionStream`/`DecompressionStream`. Gap: `ReadableStream.from()`. |
54| Encoding | **Yes**: `TextEncoder`/`TextDecoder` (legacy encodings included), encoder and decoder streams, `atob`/`btoa`. |
55| WebSockets | **Yes**, inbound (hibernatable, with attachments) and outbound. Gap: auto-response (`WebSocketRequestResponsePair`) and `getTags()`. |
56| Web Crypto | **Partial**: `digest`, HMAC sign and verify, AES-GCM, RSA-OAEP decrypt, Ed25519 and ECDSA-P256 sign, `getRandomValues`, `randomUUID`. Missing: `deriveKey`/`deriveBits`/`wrapKey`/`unwrapKey`, verify other than HMAC, `DigestStream`. An algorithm that is not available throws. |
57| Web standards | **Yes**: `URL`, `URLSearchParams`, `URLPattern`, `AbortController`/`AbortSignal` (with `timeout()`, `any()`), `Blob`/`File`/`FormData`, `Event`/`EventTarget`, `DOMException`, `queueMicrotask`, `structuredClone` (not conformant on exotic types), `navigator.userAgent`. |
58| WebAssembly | **Yes** (V8's own, without restrictions). |
59| Performance and timers | `setTimeout`/`clearTimeout`, `setImmediate`, `scheduler.wait()`. `setInterval` throws. `performance.now()` has millisecond resolution. The other parts of `performance` are stubs. |
60| Console | `log`/`info`/`warn`/`error` are real. `debug`/`trace`/`group`/`table` do nothing. `assert`/`time`/`count` are absent. |
61| Node.js compatibility | **Partial.** See [node: imports](#node-imports). |
62| Cache (`caches`) | **No.** |
63| HTMLRewriter | **No.** |
64| TCP sockets (`cloudflare:sockets`) | **No.** Known silent gap: `connect()` currently gives an inert stub. It does not throw. |
65| EventSource, MessageChannel, BroadcastChannel | **No.** The classes exist so that bundles load, but they do nothing. |
66
67## RPC
68
69celld implements the Workers [JS RPC
70system](https://developers.cloudflare.com/workers/runtime-apis/rpc/):
71`WorkerEntrypoint` and `RpcTarget` from `cloudflare:workers`, named
72entrypoints on service bindings, and method calls on Durable Object stubs
73(this needs `extends DurableObject`, or the `js_rpc` compat flag).
74Arguments and returns use structured clone. Functions, streams, and
75`RpcTarget`s become stubs. Promise pipelining, `ctx.exports` loopback
76stubs, and stubs in DO storage are available.
77
78The current limits: a cross-isolate service binding with a named
79entrypoint can do single method calls, but not `fetch()`, awaitable
80properties, or pipelined paths; a same-isolate binding has the full
81surface.
82
83## Dynamic Worker loading (Code Mode)
84
85Set `CELLD_WORKER_LOADER=LOADER`. Workers then get `env.LOADER`. This is
86an experimental port of Cloudflare's [Worker
87Loader](https://developers.cloudflare.com/workers/runtime-apis/bindings/worker-loader/).
88`loader.get(name, getCode)` (memoized) and `loader.load(code)` start a
89new isolate for each loaded worker. These inputs are honored:
90`mainModule`, sibling `modules`, `compatibilityDate`/`Flags`, plain-JSON
91`env`, and `globalOutbound: null` (no egress). The limits of workerd
92apply: 64 MiB of code and 1 MiB of env, plus the
93`CELLD_MAX_LOADED_WORKERS` limit. A loaded worker serves `fetch()` and
94single RPC method calls. Not yet available: `globalOutbound` as a
95Fetcher, capability stubs in `env`, awaitable or pipelined properties.
96
97## node: imports
98
99`node:` specifiers are always available; the `nodejs_compat` flag is not
100necessary, and celld does not read it. `celld deploy` externalizes
101`node:*` at bundle time. The runtime supplies its own subset (it does not
102use the Wrangler-style unenv polyfills):
103
104- **Implemented**: `node:assert`, `node:async_hooks` (a real
105 `AsyncLocalStorage`), `node:buffer`, `node:events`, `node:path`,
106 `node:stream` (+ `stream/web`, `stream/promises`, `stream/consumers`),
107 `node:timers/promises`, `node:util`.
108- **Partial**: `node:crypto` (hashes, HMAC, HKDF, PBKDF2, key objects,
109 `webcrypto`; signatures, ciphers, and DH throw), `node:zlib` (only the
110 sync `gzip`/`deflate` family), `node:fs` (reads fail with `ENOENT`,
111 `existsSync` is `false`).
112- **Not implemented**: the rest — `node:http(s)`, `node:net`,
113 `node:tls`, `node:dns`, `node:os`, `node:process` (the `process`
114 global exists, the module does not), `node:worker_threads`, `node:vm`,
115 `node:child_process`, and the others. Known silent gap: these
116 currently give inert stubs. They do not fail the import.
117
118## Compatibility flags
119
120`compatibility_date` and `compatibility_flags` are honored for the
121switches that celld models: `delete_all_deletes_alarm`, `js_rpc`,
122`fetcher_no_get_put_delete`, `websocket_standard_binary_type`, and the
123assets navigation behavior. `Cloudflare.compatibilityFlags` reports only
124the flags that celld honors. A flag that celld does not model is absent
125rather than reported as enabled, and celld accepts it without effect.
126
127## Wrangler configuration
128
129`celld deploy` builds a standard Wrangler project (esbuild on `PATH`)
130and accepts `wrangler.jsonc` or `wrangler.json`, not `wrangler.toml`.
131The available config keys are `name`, `main`,
132`compatibility_date`, `compatibility_flags`, `durable_objects`,
133`migrations`, `assets`, `services`, and `vars`. An asset-only project can
134omit `main`. celld refuses symlinks and special files in the asset
135directory, and `.assetsignore` still needs Wrangler. Each other key —
136`routes`, `kv_namespaces`, `triggers`, and the rest — stops the deploy
137with an error that names the key: remove the key, or deploy that project
138with Wrangler.
139
140This page is the reference for the implemented Worker surface. For the
141operational boundaries of the current release — TLS, platforms, pressure
142shedding, updates — see the [limitations](limitations.md).