@statewalker/cellb 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +323 -2
- package/dist/adapters/files-backup.d.ts +16 -0
- package/dist/adapters/files-backup.js +32 -0
- package/dist/adapters/files-backup.js.map +1 -0
- package/dist/adapters/files-changelog.d.ts +33 -0
- package/dist/adapters/files-changelog.js +96 -0
- package/dist/adapters/files-changelog.js.map +1 -0
- package/dist/adapters/files-ltx.d.ts +35 -0
- package/dist/adapters/files-ltx.js +9 -0
- package/dist/adapters/files-ltx.js.map +1 -0
- package/dist/adapters/ltx-vfs.d.ts +21 -0
- package/dist/adapters/ltx-vfs.js +286 -0
- package/dist/adapters/ltx-vfs.js.map +1 -0
- package/dist/adapters/node-sqlite.d.ts +45 -0
- package/dist/adapters/node-sqlite.js +254 -0
- package/dist/adapters/node-sqlite.js.map +1 -0
- package/dist/adapters/wasm-page-hook.d.ts +26 -0
- package/dist/adapters/wasm-page-hook.js +55 -0
- package/dist/adapters/wasm-page-hook.js.map +1 -0
- package/dist/adapters/wasm-session.d.ts +11 -0
- package/dist/adapters/wasm-session.js +76 -0
- package/dist/adapters/wasm-session.js.map +1 -0
- package/dist/adapters/wasm-sqlite.d.ts +89 -0
- package/dist/adapters/wasm-sqlite.js +258 -0
- package/dist/adapters/wasm-sqlite.js.map +1 -0
- package/dist/bindings/assets.d.ts +26 -0
- package/dist/bindings/assets.js +260 -0
- package/dist/bindings/assets.js.map +1 -0
- package/dist/bindings/cache.d.ts +16 -0
- package/dist/bindings/cache.js +34 -0
- package/dist/bindings/cache.js.map +1 -0
- package/dist/bindings/celld-kv.d.ts +26 -0
- package/dist/bindings/celld-kv.js +81 -0
- package/dist/bindings/celld-kv.js.map +1 -0
- package/dist/bindings/celld-queues.d.ts +56 -0
- package/dist/bindings/celld-queues.js +223 -0
- package/dist/bindings/celld-queues.js.map +1 -0
- package/dist/bindings/celld-workflows.d.ts +22 -0
- package/dist/bindings/celld-workflows.js +54 -0
- package/dist/bindings/celld-workflows.js.map +1 -0
- package/dist/bindings/cron.d.ts +27 -0
- package/dist/bindings/cron.js +232 -0
- package/dist/bindings/cron.js.map +1 -0
- package/dist/bindings/d1-migrations.d.ts +22 -0
- package/dist/bindings/d1-migrations.js +32 -0
- package/dist/bindings/d1-migrations.js.map +1 -0
- package/dist/bindings/html-rewriter.d.ts +8 -0
- package/dist/bindings/html-rewriter.js +75 -0
- package/dist/bindings/html-rewriter.js.map +1 -0
- package/dist/bindings/r2-celld.d.ts +3 -0
- package/dist/bindings/r2-celld.js +113 -0
- package/dist/bindings/r2-celld.js.map +1 -0
- package/dist/bindings/r2.d.ts +236 -0
- package/dist/bindings/r2.js +419 -0
- package/dist/bindings/r2.js.map +1 -0
- package/dist/bindings/worker-loader.d.ts +83 -0
- package/dist/bindings/worker-loader.js +183 -0
- package/dist/bindings/worker-loader.js.map +1 -0
- package/dist/bindings/workers-ai.d.ts +39 -0
- package/dist/bindings/workers-ai.js +175 -0
- package/dist/bindings/workers-ai.js.map +1 -0
- package/dist/browser.d.ts +7 -0
- package/dist/browser.js +8 -0
- package/dist/browser.js.map +1 -0
- package/dist/bucket/celld-cells.d.ts +86 -0
- package/dist/bucket/celld-cells.js +273 -0
- package/dist/bucket/celld-cells.js.map +1 -0
- package/dist/bucket/celld-format.d.ts +10 -0
- package/dist/bucket/celld-format.js +27 -0
- package/dist/bucket/celld-format.js.map +1 -0
- package/dist/bucket/idb-object-store.d.ts +9 -0
- package/dist/bucket/idb-object-store.js +73 -0
- package/dist/bucket/idb-object-store.js.map +1 -0
- package/dist/bucket/ltx-log.d.ts +34 -0
- package/dist/bucket/ltx-log.js +289 -0
- package/dist/bucket/ltx-log.js.map +1 -0
- package/dist/bucket/object-store.d.ts +51 -0
- package/dist/bucket/object-store.js +114 -0
- package/dist/bucket/object-store.js.map +1 -0
- package/dist/bucket/s3-object-store.d.ts +25 -0
- package/dist/bucket/s3-object-store.js +151 -0
- package/dist/bucket/s3-object-store.js.map +1 -0
- package/dist/bucket/sqlite-object-store.d.ts +10 -0
- package/dist/bucket/sqlite-object-store.js +107 -0
- package/dist/bucket/sqlite-object-store.js.map +1 -0
- package/dist/core/alarms.d.ts +27 -0
- package/dist/core/alarms.js +88 -0
- package/dist/core/alarms.js.map +1 -0
- package/dist/core/async-context.d.ts +34 -0
- package/dist/core/async-context.js +50 -0
- package/dist/core/async-context.js.map +1 -0
- package/dist/core/celld-schema.d.ts +14 -0
- package/dist/core/celld-schema.js +34 -0
- package/dist/core/celld-schema.js.map +1 -0
- package/dist/core/durable-object.d.ts +28 -0
- package/dist/core/durable-object.js +31 -0
- package/dist/core/durable-object.js.map +1 -0
- package/dist/core/gates.d.ts +33 -0
- package/dist/core/gates.js +89 -0
- package/dist/core/gates.js.map +1 -0
- package/dist/core/handles.d.ts +90 -0
- package/dist/core/handles.js +224 -0
- package/dist/core/handles.js.map +1 -0
- package/dist/core/id.d.ts +19 -0
- package/dist/core/id.js +64 -0
- package/dist/core/id.js.map +1 -0
- package/dist/core/namespace.d.ts +38 -0
- package/dist/core/namespace.js +141 -0
- package/dist/core/namespace.js.map +1 -0
- package/dist/core/object-host.d.ts +91 -0
- package/dist/core/object-host.js +616 -0
- package/dist/core/object-host.js.map +1 -0
- package/dist/core/request-body.d.ts +9 -0
- package/dist/core/request-body.js +55 -0
- package/dist/core/request-body.js.map +1 -0
- package/dist/core/runtime.d.ts +121 -0
- package/dist/core/runtime.js +366 -0
- package/dist/core/runtime.js.map +1 -0
- package/dist/core/shard.d.ts +7 -0
- package/dist/core/shard.js +10 -0
- package/dist/core/shard.js.map +1 -0
- package/dist/core/sql-split.d.ts +15 -0
- package/dist/core/sql-split.js +101 -0
- package/dist/core/sql-split.js.map +1 -0
- package/dist/core/sql-storage.d.ts +53 -0
- package/dist/core/sql-storage.js +407 -0
- package/dist/core/sql-storage.js.map +1 -0
- package/dist/core/state.d.ts +44 -0
- package/dist/core/state.js +93 -0
- package/dist/core/state.js.map +1 -0
- package/dist/core/storage.d.ts +103 -0
- package/dist/core/storage.js +351 -0
- package/dist/core/storage.js.map +1 -0
- package/dist/core/worker-rejections.d.ts +21 -0
- package/dist/core/worker-rejections.js +55 -0
- package/dist/core/worker-rejections.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/isolate/browser.d.ts +16 -0
- package/dist/isolate/browser.js +37 -0
- package/dist/isolate/browser.js.map +1 -0
- package/dist/isolate/host.d.ts +24 -0
- package/dist/isolate/host.js +74 -0
- package/dist/isolate/host.js.map +1 -0
- package/dist/isolate/isolate-worker.d.ts +1 -0
- package/dist/isolate/isolate-worker.js +53 -0
- package/dist/isolate/isolate-worker.js.map +1 -0
- package/dist/isolate/isolate.d.ts +10 -0
- package/dist/isolate/isolate.js +169 -0
- package/dist/isolate/isolate.js.map +1 -0
- package/dist/isolate/node-entry.d.ts +1 -0
- package/dist/isolate/node-entry.js +12 -0
- package/dist/isolate/node-entry.js.map +1 -0
- package/dist/isolate/protocol.d.ts +66 -0
- package/dist/isolate/protocol.js +205 -0
- package/dist/isolate/protocol.js.map +1 -0
- package/dist/ltx/crc64.d.ts +6 -0
- package/dist/ltx/crc64.js +46 -0
- package/dist/ltx/crc64.js.map +1 -0
- package/dist/ltx/ltx-page-server.d.ts +65 -0
- package/dist/ltx/ltx-page-server.js +309 -0
- package/dist/ltx/ltx-page-server.js.map +1 -0
- package/dist/ltx/ltx-pages.d.ts +81 -0
- package/dist/ltx/ltx-pages.js +315 -0
- package/dist/ltx/ltx-pages.js.map +1 -0
- package/dist/ltx/ltx-store-worker.d.ts +1 -0
- package/dist/ltx/ltx-store-worker.js +38 -0
- package/dist/ltx/ltx-store-worker.js.map +1 -0
- package/dist/ltx/ltx.d.ts +45 -0
- package/dist/ltx/ltx.js +203 -0
- package/dist/ltx/ltx.js.map +1 -0
- package/dist/ltx/lz4.d.ts +9 -0
- package/dist/ltx/lz4.js +156 -0
- package/dist/ltx/lz4.js.map +1 -0
- package/dist/ltx/opfs-sync-files.d.ts +23 -0
- package/dist/ltx/opfs-sync-files.js +191 -0
- package/dist/ltx/opfs-sync-files.js.map +1 -0
- package/dist/ltx/xxh32.d.ts +1 -0
- package/dist/ltx/xxh32.js +43 -0
- package/dist/ltx/xxh32.js.map +1 -0
- package/dist/miniflare-compat/blob-service.d.ts +13 -0
- package/dist/miniflare-compat/blob-service.js +66 -0
- package/dist/miniflare-compat/blob-service.js.map +1 -0
- package/dist/miniflare-compat/kv-binding.d.ts +44 -0
- package/dist/miniflare-compat/kv-binding.js +99 -0
- package/dist/miniflare-compat/kv-binding.js.map +1 -0
- package/dist/miniflare-compat/shims/assert.d.ts +15 -0
- package/dist/miniflare-compat/shims/assert.js +24 -0
- package/dist/miniflare-compat/shims/assert.js.map +1 -0
- package/dist/miniflare-compat/shims/workerd-cloudflare.d.ts +7 -0
- package/dist/miniflare-compat/shims/workerd-cloudflare.js +6 -0
- package/dist/miniflare-compat/shims/workerd-cloudflare.js.map +1 -0
- package/dist/miniflare-compat/shims/workerd-globals.d.ts +1 -0
- package/dist/miniflare-compat/shims/workerd-globals.js +30 -0
- package/dist/miniflare-compat/shims/workerd-globals.js.map +1 -0
- package/dist/miniflare-compat/shims/workerd-internal.d.ts +20 -0
- package/dist/miniflare-compat/shims/workerd-internal.js +23 -0
- package/dist/miniflare-compat/shims/workerd-internal.js.map +1 -0
- package/dist/miniflare-compat/shims/workerd-performance.d.ts +4 -0
- package/dist/miniflare-compat/shims/workerd-performance.js +17 -0
- package/dist/miniflare-compat/shims/workerd-performance.js.map +1 -0
- package/dist/miniflare-compat/simulator-fetcher.d.ts +9 -0
- package/dist/miniflare-compat/simulator-fetcher.js +14 -0
- package/dist/miniflare-compat/simulator-fetcher.js.map +1 -0
- package/dist/miniflare-compat/vendored.d.ts +15 -0
- package/dist/miniflare-compat/vendored.js +27 -0
- package/dist/miniflare-compat/vendored.js.map +1 -0
- package/dist/node-compat/async_hooks.d.ts +22 -0
- package/dist/node-compat/async_hooks.js +176 -0
- package/dist/node-compat/async_hooks.js.map +1 -0
- package/dist/node-compat/browser-registry.d.ts +3 -0
- package/dist/node-compat/browser-registry.js +39 -0
- package/dist/node-compat/browser-registry.js.map +1 -0
- package/dist/node-compat/crypto.d.ts +60 -0
- package/dist/node-compat/crypto.js +143 -0
- package/dist/node-compat/crypto.js.map +1 -0
- package/dist/node-compat/diagnostics_channel.d.ts +27 -0
- package/dist/node-compat/diagnostics_channel.js +46 -0
- package/dist/node-compat/diagnostics_channel.js.map +1 -0
- package/dist/node-compat/fs.d.ts +35 -0
- package/dist/node-compat/fs.js +40 -0
- package/dist/node-compat/fs.js.map +1 -0
- package/dist/node-compat/globals.d.ts +3 -0
- package/dist/node-compat/globals.js +4 -0
- package/dist/node-compat/globals.js.map +1 -0
- package/dist/node-compat/install.d.ts +5 -0
- package/dist/node-compat/install.js +12 -0
- package/dist/node-compat/install.js.map +1 -0
- package/dist/node-compat/module.d.ts +12 -0
- package/dist/node-compat/module.js +36 -0
- package/dist/node-compat/module.js.map +1 -0
- package/dist/node-compat/modules.d.ts +8 -0
- package/dist/node-compat/modules.js +23 -0
- package/dist/node-compat/modules.js.map +1 -0
- package/dist/node-compat/os.d.ts +36 -0
- package/dist/node-compat/os.js +36 -0
- package/dist/node-compat/os.js.map +1 -0
- package/dist/node-compat/process.d.ts +14 -0
- package/dist/node-compat/process.js +16 -0
- package/dist/node-compat/process.js.map +1 -0
- package/dist/node-compat/shims.d.ts +4 -0
- package/dist/node.d.ts +5 -0
- package/dist/node.js +6 -0
- package/dist/node.js.map +1 -0
- package/dist/peer/celld-peer.d.ts +53 -0
- package/dist/peer/celld-peer.js +555 -0
- package/dist/peer/celld-peer.js.map +1 -0
- package/dist/ports.d.ts +183 -0
- package/dist/ports.js +10 -0
- package/dist/ports.js.map +1 -0
- package/dist/project/browser-bundle.d.ts +17 -0
- package/dist/project/browser-bundle.js +125 -0
- package/dist/project/browser-bundle.js.map +1 -0
- package/dist/project/browser-cookies.d.ts +12 -0
- package/dist/project/browser-cookies.js +90 -0
- package/dist/project/browser-cookies.js.map +1 -0
- package/dist/project/browser-host.d.ts +173 -0
- package/dist/project/browser-host.js +200 -0
- package/dist/project/browser-host.js.map +1 -0
- package/dist/project/browser-modules.d.ts +17 -0
- package/dist/project/browser-modules.js +89 -0
- package/dist/project/browser-modules.js.map +1 -0
- package/dist/project/browser-shards.d.ts +62 -0
- package/dist/project/browser-shards.js +210 -0
- package/dist/project/browser-shards.js.map +1 -0
- package/dist/project/browser-tabs.d.ts +103 -0
- package/dist/project/browser-tabs.js +418 -0
- package/dist/project/browser-tabs.js.map +1 -0
- package/dist/project/cloudflare-email.d.ts +8 -0
- package/dist/project/cloudflare-email.js +11 -0
- package/dist/project/cloudflare-email.js.map +1 -0
- package/dist/project/cloudflare-workers.d.ts +12 -0
- package/dist/project/cloudflare-workers.js +16 -0
- package/dist/project/cloudflare-workers.js.map +1 -0
- package/dist/project/host-modules.d.ts +4 -0
- package/dist/project/host-modules.js +40 -0
- package/dist/project/host-modules.js.map +1 -0
- package/dist/project/jsonc.d.ts +2 -0
- package/dist/project/jsonc.js +27 -0
- package/dist/project/jsonc.js.map +1 -0
- package/dist/project/lower-await.d.ts +2 -0
- package/dist/project/lower-await.js +151 -0
- package/dist/project/lower-await.js.map +1 -0
- package/dist/project/node-project.d.ts +38 -0
- package/dist/project/node-project.js +373 -0
- package/dist/project/node-project.js.map +1 -0
- package/dist/project/own-module.d.ts +6 -0
- package/dist/project/own-module.js +13 -0
- package/dist/project/own-module.js.map +1 -0
- package/dist/project/scheduler.d.ts +2 -0
- package/dist/project/scheduler.js +3 -0
- package/dist/project/scheduler.js.map +1 -0
- package/dist/project/site.d.ts +74 -0
- package/dist/project/site.js +206 -0
- package/dist/project/site.js.map +1 -0
- package/dist/project/virtual-modules.d.ts +3 -0
- package/dist/project/worker-scope.d.ts +27 -0
- package/dist/project/worker-scope.js +46 -0
- package/dist/project/worker-scope.js.map +1 -0
- package/dist/project/workerd-message-channel.d.ts +13 -0
- package/dist/project/workerd-message-channel.js +137 -0
- package/dist/project/workerd-message-channel.js.map +1 -0
- package/dist/project/workers-global-names.d.ts +6 -0
- package/dist/project/workers-global-names.js +15 -0
- package/dist/project/workers-global-names.js.map +1 -0
- package/dist/project/workers-globals-module.d.ts +8 -0
- package/dist/project/workers-globals-module.js +9 -0
- package/dist/project/workers-globals-module.js.map +1 -0
- package/dist/project/workers-globals.d.ts +9 -0
- package/dist/project/workers-globals.js +19 -0
- package/dist/project/workers-globals.js.map +1 -0
- package/dist/project/wrangler.d.ts +116 -0
- package/dist/project/wrangler.js +342 -0
- package/dist/project/wrangler.js.map +1 -0
- package/dist/router/cell-router.d.ts +72 -0
- package/dist/router/cell-router.js +247 -0
- package/dist/router/cell-router.js.map +1 -0
- package/dist/router/shard-worker.d.ts +44 -0
- package/dist/router/shard-worker.js +163 -0
- package/dist/router/shard-worker.js.map +1 -0
- package/dist/transport/cells-http.d.ts +25 -0
- package/dist/transport/cells-http.js +141 -0
- package/dist/transport/cells-http.js.map +1 -0
- package/dist/transport/cells-link.d.ts +27 -0
- package/dist/transport/cells-link.js +71 -0
- package/dist/transport/cells-link.js.map +1 -0
- package/dist/transport/port.d.ts +26 -0
- package/dist/transport/port.js +100 -0
- package/dist/transport/port.js.map +1 -0
- package/dist/v8/codec.d.ts +6 -0
- package/dist/v8/codec.js +9 -0
- package/dist/v8/codec.js.map +1 -0
- package/dist/v8/serialize.d.ts +10 -0
- package/dist/v8/serialize.js +601 -0
- package/dist/v8/serialize.js.map +1 -0
- package/dist/ws/client.d.ts +25 -0
- package/dist/ws/client.js +203 -0
- package/dist/ws/client.js.map +1 -0
- package/dist/ws/control.d.ts +48 -0
- package/dist/ws/control.js +44 -0
- package/dist/ws/control.js.map +1 -0
- package/dist/ws/frames.d.ts +38 -0
- package/dist/ws/frames.js +39 -0
- package/dist/ws/frames.js.map +1 -0
- package/dist/ws/server.d.ts +99 -0
- package/dist/ws/server.js +295 -0
- package/dist/ws/server.js.map +1 -0
- package/dist/ws/sw-connector.d.ts +10 -0
- package/dist/ws/sw-connector.js +25 -0
- package/dist/ws/sw-connector.js.map +1 -0
- package/dist/ws/upgrade.d.ts +28 -0
- package/dist/ws/upgrade.js +75 -0
- package/dist/ws/upgrade.js.map +1 -0
- package/package.json +111 -3
- package/vendor/celld/LICENSE +202 -0
- package/vendor/celld/kv.js +1131 -0
- package/vendor/celld/queues.js +1656 -0
- package/vendor/celld/workflows.js +1610 -0
- package/vendor/html-rewriter-wasm/html_rewriter.js +925 -0
- package/vendor/html-rewriter-wasm/html_rewriter_bg.wasm +0 -0
- package/vendor/miniflare/d1-api.js +738 -0
- package/vendor/miniflare/d1-database.js +6978 -0
- package/vendor/miniflare/kv-namespace.js +3061 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* workerd's `MessageChannel` on a Node host. In workerd an open port does not keep anything
|
|
3
|
+
* alive; on Node a port with a `message` handler is ref'd and holds the event loop open until it
|
|
4
|
+
* is closed. Libraries create such ports at module scope and never close them (React DOM's
|
|
5
|
+
* server renderer schedules its work over one), so a Worker bundle that imports them would keep
|
|
6
|
+
* the Node process alive after its runtime is closed.
|
|
7
|
+
*
|
|
8
|
+
* The ports of this channel are unref'd and hold the loop open only while a message posted to
|
|
9
|
+
* one of them waits for its handler, so a pending render still completes. Messages, transfers
|
|
10
|
+
* and `close()` are the real ports'. Where ports have no `unref` (browsers), it is the plain
|
|
11
|
+
* `MessageChannel`.
|
|
12
|
+
*/
|
|
13
|
+
/** Makes `port` unref'd except while messages posted to it wait for a handler. */
|
|
14
|
+
function weakPort(port, peer) {
|
|
15
|
+
const realRef = port.ref.bind(port);
|
|
16
|
+
const realUnref = port.unref.bind(port);
|
|
17
|
+
let pending = 0; // messages posted to this port, not yet dispatched
|
|
18
|
+
let handlers = 0; // `onmessage` and `message` listeners
|
|
19
|
+
let held = false;
|
|
20
|
+
const sync = () => {
|
|
21
|
+
const hold = pending > 0 && handlers > 0;
|
|
22
|
+
if (hold === held)
|
|
23
|
+
return;
|
|
24
|
+
held = hold;
|
|
25
|
+
if (hold)
|
|
26
|
+
realRef();
|
|
27
|
+
else
|
|
28
|
+
realUnref();
|
|
29
|
+
};
|
|
30
|
+
// Node refs a port when a handler is attached: keep that to `sync`.
|
|
31
|
+
port.ref = () => port;
|
|
32
|
+
port.unref = () => port;
|
|
33
|
+
const dispatched = new WeakSet();
|
|
34
|
+
const delivered = (event) => {
|
|
35
|
+
if (dispatched.has(event))
|
|
36
|
+
return;
|
|
37
|
+
dispatched.add(event);
|
|
38
|
+
pending = Math.max(0, pending - 1);
|
|
39
|
+
sync();
|
|
40
|
+
};
|
|
41
|
+
const wrappers = new WeakMap();
|
|
42
|
+
const wrap = (listener) => {
|
|
43
|
+
let wrapped = wrappers.get(listener);
|
|
44
|
+
if (!wrapped) {
|
|
45
|
+
wrapped = function (event) {
|
|
46
|
+
delivered(event);
|
|
47
|
+
return typeof listener === "function"
|
|
48
|
+
? listener.call(this, event)
|
|
49
|
+
: listener.handleEvent(event);
|
|
50
|
+
};
|
|
51
|
+
wrappers.set(listener, wrapped);
|
|
52
|
+
}
|
|
53
|
+
return wrapped;
|
|
54
|
+
};
|
|
55
|
+
const proto = Object.getPrototypeOf(port);
|
|
56
|
+
const onmessage = findAccessor(proto, "onmessage");
|
|
57
|
+
let current = null;
|
|
58
|
+
if (onmessage?.set && onmessage.get) {
|
|
59
|
+
Object.defineProperty(port, "onmessage", {
|
|
60
|
+
configurable: true,
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: () => current,
|
|
63
|
+
set: (fn) => {
|
|
64
|
+
if (typeof fn === "function" && !current)
|
|
65
|
+
handlers++;
|
|
66
|
+
if (typeof fn !== "function" && current)
|
|
67
|
+
handlers--;
|
|
68
|
+
current = typeof fn === "function" ? fn : null;
|
|
69
|
+
onmessage.set?.call(port, current && wrap(current));
|
|
70
|
+
realUnref();
|
|
71
|
+
held = false;
|
|
72
|
+
sync();
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
const add = port.addEventListener.bind(port);
|
|
77
|
+
const remove = port.removeEventListener.bind(port);
|
|
78
|
+
const registered = new Set();
|
|
79
|
+
port.addEventListener = ((type, listener, options) => {
|
|
80
|
+
if (type !== "message" || !listener)
|
|
81
|
+
return add(type, listener, options);
|
|
82
|
+
add(type, wrap(listener), options);
|
|
83
|
+
if (!registered.has(listener)) {
|
|
84
|
+
registered.add(listener);
|
|
85
|
+
handlers++;
|
|
86
|
+
}
|
|
87
|
+
realUnref();
|
|
88
|
+
held = false;
|
|
89
|
+
sync();
|
|
90
|
+
});
|
|
91
|
+
port.removeEventListener = ((type, listener, options) => {
|
|
92
|
+
if (type !== "message" || !listener)
|
|
93
|
+
return remove(type, listener, options);
|
|
94
|
+
remove(type, wrappers.get(listener) ?? listener, options);
|
|
95
|
+
if (registered.delete(listener))
|
|
96
|
+
handlers--;
|
|
97
|
+
sync();
|
|
98
|
+
});
|
|
99
|
+
// Posting from the peer: one more message waits on this port.
|
|
100
|
+
const post = peer.postMessage.bind(peer);
|
|
101
|
+
peer.postMessage = ((...args) => {
|
|
102
|
+
post(...args);
|
|
103
|
+
pending++;
|
|
104
|
+
sync();
|
|
105
|
+
});
|
|
106
|
+
const close = port.close.bind(port);
|
|
107
|
+
port.close = () => {
|
|
108
|
+
pending = 0;
|
|
109
|
+
handlers = 0;
|
|
110
|
+
sync();
|
|
111
|
+
close();
|
|
112
|
+
};
|
|
113
|
+
realUnref();
|
|
114
|
+
}
|
|
115
|
+
function findAccessor(proto, name) {
|
|
116
|
+
for (let p = proto; p; p = Object.getPrototypeOf(p)) {
|
|
117
|
+
const d = Object.getOwnPropertyDescriptor(p, name);
|
|
118
|
+
if (d)
|
|
119
|
+
return d;
|
|
120
|
+
}
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
const Base = globalThis.MessageChannel;
|
|
124
|
+
export const WorkerdMessageChannel = typeof Base === "function"
|
|
125
|
+
? class MessageChannel extends Base {
|
|
126
|
+
constructor() {
|
|
127
|
+
super();
|
|
128
|
+
const port1 = this.port1;
|
|
129
|
+
const port2 = this.port2;
|
|
130
|
+
if (typeof port1.unref !== "function" || typeof port1.ref !== "function")
|
|
131
|
+
return;
|
|
132
|
+
weakPort(port1, port2);
|
|
133
|
+
weakPort(port2, port1);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
: Base;
|
|
137
|
+
//# sourceMappingURL=workerd-message-channel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workerd-message-channel.js","sourceRoot":"","sources":["../../src/project/workerd-message-channel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH,kFAAkF;AAClF,SAAS,QAAQ,CAAC,IAAc,EAAE,IAAc;IAC9C,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpC,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxC,IAAI,OAAO,GAAG,CAAC,CAAC,CAAC,mDAAmD;IACpE,IAAI,QAAQ,GAAG,CAAC,CAAC,CAAC,sCAAsC;IACxD,IAAI,IAAI,GAAG,KAAK,CAAC;IACjB,MAAM,IAAI,GAAG,GAAG,EAAE;QAChB,MAAM,IAAI,GAAG,OAAO,GAAG,CAAC,IAAI,QAAQ,GAAG,CAAC,CAAC;QACzC,IAAI,IAAI,KAAK,IAAI;YAAE,OAAO;QAC1B,IAAI,GAAG,IAAI,CAAC;QACZ,IAAI,IAAI;YAAE,OAAO,EAAE,CAAC;;YACf,SAAS,EAAE,CAAC;IACnB,CAAC,CAAC;IACF,oEAAoE;IACpE,IAAI,CAAC,GAAG,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC;IACtB,IAAI,CAAC,KAAK,GAAG,GAAG,EAAE,C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Ac,CAAC,CAAC,CAAC,EAAE,CAAC;QACpD,MAAM,CAAC,GAAG,MAAM,CAAC,wBAAwB,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;QACnD,IAAI,CAAC;YAAE,OAAO,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,IAAI,GAAG,UAAU,CAAC,cAAc,CAAC;AAEvC,MAAM,CAAC,MAAM,qBAAqB,GAChC,OAAO,IAAI,KAAK,UAAU;IACxB,CAAC,CAAC,MAAM,cAAe,SAAQ,IAAI;QAC/B;YACE,KAAK,EAAE,CAAC;YACR,MAAM,KAAK,GAAG,IAAI,CAAC,KAAiB,CAAC;YACrC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAiB,CAAC;YACrC,IAAI,OAAO,KAAK,CAAC,KAAK,KAAK,UAAU,IAAI,OAAO,KAAK,CAAC,GAAG,KAAK,UAAU;gBAAE,OAAO;YACjF,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YACvB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QACzB,CAAC;KACF;IACH,CAAC,CAAC,IAAI,CAAC","sourcesContent":["/**\n * workerd's `MessageChannel` on a Node host. In workerd an open port does not keep anything\n * alive; on Node a port with a `message` handler is ref'd and holds the event loop open until it\n * is closed. Libraries create such ports at module scope and never close them (React DOM's\n * server renderer schedules its work over one), so a Worker bundle that imports them would keep\n * the Node process alive after its runtime is closed.\n *\n * The ports of this channel are unref'd and hold the loop open only while a message posted to\n * one of them waits for its handler, so a pending render still completes. Messages, transfers\n * and `close()` are the real ports'. Where ports have no `unref` (browsers), it is the plain\n * `MessageChannel`.\n */\n\ntype NodePort = MessagePort & { ref(): NodePort; unref(): NodePort };\ntype Listener = EventListenerOrEventListenerObject;\n\n/** Makes `port` unref'd except while messages posted to it wait for a handler. */\nfunction weakPort(port: NodePort, peer: NodePort): void {\n const realRef = port.ref.bind(port);\n const realUnref = port.unref.bind(port);\n let pending = 0; // messages posted to this port, not yet dispatched\n let handlers = 0; // `onmessage` and `message` listeners\n let held = false;\n const sync = () => {\n const hold = pending > 0 && handlers > 0;\n if (hold === held) return;\n held = hold;\n if (hold) realRef();\n else realUnref();\n };\n // Node refs a port when a handler is attached: keep that to `sync`.\n port.ref = () => port;\n port.unref = () => port;\n\n const dispatched = new WeakSet<Event>();\n const delivered = (event: Event) => {\n if (dispatched.has(event)) return;\n dispatched.add(event);\n pending = Math.max(0, pending - 1);\n sync();\n };\n const wrappers = new WeakMap<Listener, Listener>();\n const wrap = (listener: Listener): Listener => {\n let wrapped = wrappers.get(listener);\n if (!wrapped) {\n wrapped = function (this: unknown, event: Event) {\n delivered(event);\n return typeof listener === \"function\"\n ? listener.call(this, event)\n : listener.handleEvent(event);\n };\n wrappers.set(listener, wrapped);\n }\n return wrapped;\n };\n\n const proto = Object.getPrototypeOf(port) as object;\n const onmessage = findAccessor(proto, \"onmessage\");\n let current: ((event: MessageEvent) => unknown) | null = null;\n if (onmessage?.set && onmessage.get) {\n Object.defineProperty(port, \"onmessage\", {\n configurable: true,\n enumerable: true,\n get: () => current,\n set: (fn: ((event: MessageEvent) => unknown) | null) => {\n if (typeof fn === \"function\" && !current) handlers++;\n if (typeof fn !== \"function\" && current) handlers--;\n current = typeof fn === \"function\" ? fn : null;\n onmessage.set?.call(port, current && wrap(current as EventListener));\n realUnref();\n held = false;\n sync();\n },\n });\n }\n const add = port.addEventListener.bind(port);\n const remove = port.removeEventListener.bind(port);\n const registered = new Set<Listener>();\n port.addEventListener = ((type: string, listener: Listener | null, options?: unknown) => {\n if (type !== \"message\" || !listener) return add(type, listener as Listener, options as never);\n add(type, wrap(listener), options as never);\n if (!registered.has(listener)) {\n registered.add(listener);\n handlers++;\n }\n realUnref();\n held = false;\n sync();\n }) as typeof port.addEventListener;\n port.removeEventListener = ((type: string, listener: Listener | null, options?: unknown) => {\n if (type !== \"message\" || !listener)\n return remove(type, listener as Listener, options as never);\n remove(type, wrappers.get(listener) ?? listener, options as never);\n if (registered.delete(listener)) handlers--;\n sync();\n }) as typeof port.removeEventListener;\n\n // Posting from the peer: one more message waits on this port.\n const post = peer.postMessage.bind(peer) as (...args: unknown[]) => void;\n peer.postMessage = ((...args: unknown[]) => {\n post(...args);\n pending++;\n sync();\n }) as typeof peer.postMessage;\n const close = port.close.bind(port);\n port.close = () => {\n pending = 0;\n handlers = 0;\n sync();\n close();\n };\n realUnref();\n}\n\nfunction findAccessor(proto: object | null, name: string): PropertyDescriptor | undefined {\n for (let p = proto; p; p = Object.getPrototypeOf(p)) {\n const d = Object.getOwnPropertyDescriptor(p, name);\n if (d) return d;\n }\n return undefined;\n}\n\nconst Base = globalThis.MessageChannel;\n\nexport const WorkerdMessageChannel: typeof MessageChannel | undefined =\n typeof Base === \"function\"\n ? class MessageChannel extends Base {\n constructor() {\n super();\n const port1 = this.port1 as NodePort;\n const port2 = this.port2 as NodePort;\n if (typeof port1.unref !== \"function\" || typeof port1.ref !== \"function\") return;\n weakPort(port1, port2);\n weakPort(port2, port1);\n }\n }\n : Base;\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Workers globals substituted into browser bundles (`scheduler` aside, which is an
|
|
3
|
+
* expression): each is read from the realm that runs the code. workers-globals.ts spells the
|
|
4
|
+
* same list as static re-exports, because esbuild `inject` needs a literal module.
|
|
5
|
+
*/
|
|
6
|
+
export declare const WORKERS_GLOBAL_NAMES: readonly ["Request", "Response", "WebSocketPair", "caches", "HTMLRewriter", "WebSocketRequestResponsePair", "WebSocket"];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Workers globals substituted into browser bundles (`scheduler` aside, which is an
|
|
3
|
+
* expression): each is read from the realm that runs the code. workers-globals.ts spells the
|
|
4
|
+
* same list as static re-exports, because esbuild `inject` needs a literal module.
|
|
5
|
+
*/
|
|
6
|
+
export const WORKERS_GLOBAL_NAMES = [
|
|
7
|
+
"Request",
|
|
8
|
+
"Response",
|
|
9
|
+
"WebSocketPair",
|
|
10
|
+
"caches",
|
|
11
|
+
"HTMLRewriter",
|
|
12
|
+
"WebSocketRequestResponsePair",
|
|
13
|
+
"WebSocket",
|
|
14
|
+
];
|
|
15
|
+
//# sourceMappingURL=workers-global-names.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workers-global-names.js","sourceRoot":"","sources":["../../src/project/workers-global-names.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,SAAS;IACT,UAAU;IACV,eAAe;IACf,QAAQ;IACR,cAAc;IACd,8BAA8B;IAC9B,WAAW;CACH,CAAC","sourcesContent":["/**\n * The Workers globals substituted into browser bundles (`scheduler` aside, which is an\n * expression): each is read from the realm that runs the code. workers-globals.ts spells the\n * same list as static re-exports, because esbuild `inject` needs a literal module.\n */\nexport const WORKERS_GLOBAL_NAMES = [\n \"Request\",\n \"Response\",\n \"WebSocketPair\",\n \"caches\",\n \"HTMLRewriter\",\n \"WebSocketRequestResponsePair\",\n \"WebSocket\",\n] as const;\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The "cellb:ws" module that workers-globals.ts imports: the runtime's own
|
|
3
|
+
* Workers globals, loaded as an external module so user bundles share these instances.
|
|
4
|
+
*/
|
|
5
|
+
export { cellsCaches as caches } from "../bindings/cache.js";
|
|
6
|
+
export { HTMLRewriter } from "../bindings/html-rewriter.js";
|
|
7
|
+
export { CellsResponse, StandardWebSocketPair, WebSocketPair, WebSocketRequestResponsePair, WorkersWebSocket as WebSocket, } from "../ws/server.js";
|
|
8
|
+
export { CellsRequest } from "../ws/upgrade.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The "cellb:ws" module that workers-globals.ts imports: the runtime's own
|
|
3
|
+
* Workers globals, loaded as an external module so user bundles share these instances.
|
|
4
|
+
*/
|
|
5
|
+
export { cellsCaches as caches } from "../bindings/cache.js";
|
|
6
|
+
export { HTMLRewriter } from "../bindings/html-rewriter.js";
|
|
7
|
+
export { CellsResponse, StandardWebSocketPair, WebSocketPair, WebSocketRequestResponsePair, WorkersWebSocket as WebSocket, } from "../ws/server.js";
|
|
8
|
+
export { CellsRequest } from "../ws/upgrade.js";
|
|
9
|
+
//# sourceMappingURL=workers-globals-module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workers-globals-module.js","sourceRoot":"","sources":["../../src/project/workers-globals-module.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,WAAW,IAAI,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,aAAa,EACb,4BAA4B,EAC5B,gBAAgB,IAAI,SAAS,GAC9B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC","sourcesContent":["/**\n * The \"cellb:ws\" module that workers-globals.ts imports: the runtime's own\n * Workers globals, loaded as an external module so user bundles share these instances.\n */\nexport { cellsCaches as caches } from \"../bindings/cache.js\";\nexport { HTMLRewriter } from \"../bindings/html-rewriter.js\";\nexport {\n CellsResponse,\n StandardWebSocketPair,\n WebSocketPair,\n WebSocketRequestResponsePair,\n WorkersWebSocket as WebSocket,\n} from \"../ws/server.js\";\nexport { CellsRequest } from \"../ws/upgrade.js\";\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { CellsRequest as Request, CellsResponse as Response, caches, HTMLRewriter, WebSocket, WebSocketRequestResponsePair, } from "cellb:ws";
|
|
2
|
+
/** The project's `websocket_standard_binary_type` flag ("cellb:compat", one per bundle). */
|
|
3
|
+
export declare const WebSocketPair: any;
|
|
4
|
+
/** workerd's `MessageChannel`: an idle port does not keep the Node host alive. */
|
|
5
|
+
export { WorkerdMessageChannel as MessageChannel } from "./workerd-message-channel.js";
|
|
6
|
+
/** workerd's `scheduler`:`await scheduler.wait(ms)` is a promise-based setTimeout. */
|
|
7
|
+
export declare const scheduler: {
|
|
8
|
+
wait: (ms: number) => Promise<void>;
|
|
9
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Globals of the Workers runtime that browsers/Node lack or implement differently,
|
|
3
|
+
* substituted into user bundles (esbuild `inject` on the server, webrun-modules `~deps`
|
|
4
|
+
* in the browser) — the real globals are untouched. "cellb:ws" is resolved as an
|
|
5
|
+
* EXTERNAL module (workers-globals-module.ts): if it were bundled, the injected `Response` would
|
|
6
|
+
* also replace the `Response` that CellsResponse itself extends.
|
|
7
|
+
*/
|
|
8
|
+
import { standardBinaryType } from "cellb:compat";
|
|
9
|
+
import { WebSocketPair as LegacyWebSocketPair, StandardWebSocketPair } from "cellb:ws";
|
|
10
|
+
export { CellsRequest as Request, CellsResponse as Response, caches, HTMLRewriter, WebSocket, WebSocketRequestResponsePair, } from "cellb:ws";
|
|
11
|
+
/** The project's `websocket_standard_binary_type` flag ("cellb:compat", one per bundle). */
|
|
12
|
+
export const WebSocketPair = standardBinaryType ? StandardWebSocketPair : LegacyWebSocketPair;
|
|
13
|
+
/** workerd's `MessageChannel`: an idle port does not keep the Node host alive. */
|
|
14
|
+
export { WorkerdMessageChannel as MessageChannel } from "./workerd-message-channel.js";
|
|
15
|
+
/** workerd's `scheduler`:`await scheduler.wait(ms)` is a promise-based setTimeout. */
|
|
16
|
+
export const scheduler = {
|
|
17
|
+
wait: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=workers-globals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workers-globals.js","sourceRoot":"","sources":["../../src/project/workers-globals.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,aAAa,IAAI,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAEvF,OAAO,EACL,YAAY,IAAI,OAAO,EACvB,aAAa,IAAI,QAAQ,EACzB,MAAM,EACN,YAAY,EACZ,SAAS,EACT,4BAA4B,GAC7B,MAAM,UAAU,CAAC;AAElB,4FAA4F;AAC5F,MAAM,CAAC,MAAM,aAAa,GAAG,kBAAkB,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,mBAAmB,CAAC;AAE9F,kFAAkF;AAClF,OAAO,EAAE,qBAAqB,IAAI,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAEvF,sFAAsF;AACtF,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,IAAI,EAAE,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;CAC9E,CAAC","sourcesContent":["/**\n * Globals of the Workers runtime that browsers/Node lack or implement differently,\n * substituted into user bundles (esbuild `inject` on the server, webrun-modules `~deps`\n * in the browser) — the real globals are untouched. \"cellb:ws\" is resolved as an\n * EXTERNAL module (workers-globals-module.ts): if it were bundled, the injected `Response` would\n * also replace the `Response` that CellsResponse itself extends.\n */\nimport { standardBinaryType } from \"cellb:compat\";\nimport { WebSocketPair as LegacyWebSocketPair, StandardWebSocketPair } from \"cellb:ws\";\n\nexport {\n CellsRequest as Request,\n CellsResponse as Response,\n caches,\n HTMLRewriter,\n WebSocket,\n WebSocketRequestResponsePair,\n} from \"cellb:ws\";\n\n/** The project's `websocket_standard_binary_type` flag (\"cellb:compat\", one per bundle). */\nexport const WebSocketPair = standardBinaryType ? StandardWebSocketPair : LegacyWebSocketPair;\n\n/** workerd's `MessageChannel`: an idle port does not keep the Node host alive. */\nexport { WorkerdMessageChannel as MessageChannel } from \"./workerd-message-channel.js\";\n\n/** workerd's `scheduler`:`await scheduler.wait(ms)` is a promise-based setTimeout. */\nexport const scheduler = {\n wait: (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms)),\n};\n"]}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { FilesApi } from "@statewalker/webrun-files";
|
|
2
|
+
import { type AssetFiles, type AssetsConfig } from "../bindings/assets.js";
|
|
3
|
+
import { type QueueConsumerConfig } from "../bindings/celld-queues.js";
|
|
4
|
+
import { type ModuleLoader } from "../bindings/worker-loader.js";
|
|
5
|
+
import { type WorkersAiOptions } from "../bindings/workers-ai.js";
|
|
6
|
+
import { type CellRuntime, type CellRuntimeOptions, type WorkerModule } from "../core/runtime.js";
|
|
7
|
+
/** The subset of wrangler.json(c) that celld deploys (and cellb reads). */
|
|
8
|
+
export interface WranglerConfig {
|
|
9
|
+
name?: string;
|
|
10
|
+
main?: string;
|
|
11
|
+
compatibility_date?: string;
|
|
12
|
+
compatibility_flags?: string[];
|
|
13
|
+
vars?: Record<string, unknown>;
|
|
14
|
+
durable_objects?: {
|
|
15
|
+
bindings?: {
|
|
16
|
+
name: string;
|
|
17
|
+
class_name: string;
|
|
18
|
+
script_name?: string;
|
|
19
|
+
}[];
|
|
20
|
+
};
|
|
21
|
+
migrations?: {
|
|
22
|
+
tag: string;
|
|
23
|
+
new_sqlite_classes?: string[];
|
|
24
|
+
new_classes?: string[];
|
|
25
|
+
renamed_classes?: {
|
|
26
|
+
from: string;
|
|
27
|
+
to: string;
|
|
28
|
+
}[];
|
|
29
|
+
deleted_classes?: string[];
|
|
30
|
+
}[];
|
|
31
|
+
kv_namespaces?: {
|
|
32
|
+
binding: string;
|
|
33
|
+
id?: string;
|
|
34
|
+
}[];
|
|
35
|
+
d1_databases?: {
|
|
36
|
+
binding: string;
|
|
37
|
+
database_name?: string;
|
|
38
|
+
database_id?: string;
|
|
39
|
+
}[];
|
|
40
|
+
r2_buckets?: {
|
|
41
|
+
binding: string;
|
|
42
|
+
bucket_name: string;
|
|
43
|
+
}[];
|
|
44
|
+
queues?: {
|
|
45
|
+
producers?: {
|
|
46
|
+
binding: string;
|
|
47
|
+
queue: string;
|
|
48
|
+
delivery_delay?: number;
|
|
49
|
+
}[];
|
|
50
|
+
consumers?: QueueConsumerConfig[];
|
|
51
|
+
};
|
|
52
|
+
workflows?: WorkflowConfig[];
|
|
53
|
+
triggers?: {
|
|
54
|
+
crons?: string[];
|
|
55
|
+
};
|
|
56
|
+
assets?: AssetsConfig;
|
|
57
|
+
services?: {
|
|
58
|
+
binding: string;
|
|
59
|
+
service: string;
|
|
60
|
+
entrypoint?: string;
|
|
61
|
+
props?: unknown;
|
|
62
|
+
}[];
|
|
63
|
+
worker_loaders?: {
|
|
64
|
+
binding: string;
|
|
65
|
+
}[];
|
|
66
|
+
/** Workers AI: served by the host's OpenAI-compatible endpoint (`ProjectHost.ai`), if any. */
|
|
67
|
+
ai?: {
|
|
68
|
+
binding: string;
|
|
69
|
+
};
|
|
70
|
+
/** Containers (celld runs them with Docker or Podman): not supported, reported. */
|
|
71
|
+
containers?: {
|
|
72
|
+
class_name: string;
|
|
73
|
+
image?: string;
|
|
74
|
+
}[];
|
|
75
|
+
}
|
|
76
|
+
/** wrangler `workflows` entries. */
|
|
77
|
+
export interface WorkflowConfig {
|
|
78
|
+
binding: string;
|
|
79
|
+
name: string;
|
|
80
|
+
class_name: string;
|
|
81
|
+
}
|
|
82
|
+
export interface ProjectHost extends Pick<CellRuntimeOptions, "openSql" | "storage" | "clock" | "peers" | "route"> {
|
|
83
|
+
/** Files of `assets.directory` (path "/a/b.html" → bytes), loaded by the host. */
|
|
84
|
+
assetFiles?: AssetFiles;
|
|
85
|
+
/** Runs each loaded Worker in its own realm (celld isolates); classes still use `loadModules`. */
|
|
86
|
+
isolatedModules?: ModuleLoader;
|
|
87
|
+
/** Compiles code given to a Worker Loader binding (esbuild on Node, webrun-modules in browsers). */
|
|
88
|
+
loadModules?: ModuleLoader;
|
|
89
|
+
/** Blob store of the KV simulator (large values): OPFS in a browser, a directory or S3 on a server. */
|
|
90
|
+
files: FilesApi;
|
|
91
|
+
/** The OpenAI-compatible endpoint behind the `ai` binding; without it the binding is unsupported. */
|
|
92
|
+
ai?: WorkersAiOptions;
|
|
93
|
+
}
|
|
94
|
+
export interface ProjectRuntime {
|
|
95
|
+
runtime: CellRuntime;
|
|
96
|
+
/** Configuration entries cellb does not support yet (reported, not silently ignored). */
|
|
97
|
+
unsupported: string[];
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* What `env` of `cloudflare:workers` holds while the Worker's module is evaluated, before the
|
|
101
|
+
* runtime exists: the vars, and the bindings that need no runtime (`ai`; Flue's entry reads
|
|
102
|
+
* `env.AI` at load).
|
|
103
|
+
*/
|
|
104
|
+
export declare function loadTimeEnv(config: WranglerConfig, ai?: WorkersAiOptions): Record<string, unknown>;
|
|
105
|
+
/**
|
|
106
|
+
* Builds a runtime from a wrangler config and the Worker's module namespace — the same
|
|
107
|
+
* inputs celld deploys. Hosts differ only in `host` (storage) and in how they load `main`.
|
|
108
|
+
*/
|
|
109
|
+
export declare function createProjectRuntime(config: WranglerConfig, module: WorkerModule, host: ProjectHost): ProjectRuntime;
|
|
110
|
+
/**
|
|
111
|
+
* KV namespaces and D1 databases may omit their ids: wrangler provisions them on deploy, and
|
|
112
|
+
* framework builds (Astro's Cloudflare adapter, for one) emit such entries. A KV namespace
|
|
113
|
+
* then takes its binding name as id; a D1 database its `database_name`, else its binding name.
|
|
114
|
+
* Entries with ids are kept as they are, so storage shared with celld keeps its names.
|
|
115
|
+
*/
|
|
116
|
+
export declare function withResourceIds(config: WranglerConfig): WranglerConfig;
|