@statewalker/cellb 0.8.0 → 0.8.3
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/README.md +4 -2
- package/dist/adapters/wasm-sqlite.d.ts +2 -0
- package/dist/adapters/wasm-sqlite.js +89 -31
- package/dist/adapters/wasm-sqlite.js.map +1 -1
- package/dist/project/browser-modules.js +14 -4
- package/dist/project/browser-modules.js.map +1 -1
- package/dist/project/lower-await.js +22 -2
- package/dist/project/lower-await.js.map +1 -1
- package/dist/project/module-specifiers.d.ts +14 -0
- package/dist/project/module-specifiers.js +302 -0
- package/dist/project/module-specifiers.js.map +1 -0
- package/dist/project/node-project.js +4 -8
- package/dist/project/node-project.js.map +1 -1
- package/dist/project/site-compiler.js +23 -2
- package/dist/project/site-compiler.js.map +1 -1
- package/dist/project/wrangler.d.ts +4 -4
- package/dist/project/wrangler.js +9 -6
- package/dist/project/wrangler.js.map +1 -1
- package/package.json +20 -20
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"site-compiler.js","sourceRoot":"","sources":["../../src/project/site-compiler.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAyB9C,oEAAoE;AACpE,SAAS,iBAAiB,CAAC,gBAAyB;IAClD,OAAO,KAAK,EAAE,OAAO,EAAE,EAAE;QACvB,IAAI,CAAE,UAA0D,CAAC,SAAS,EAAE,aAAa;YACvF,MAAM,IAAI,KAAK,CACb,wFAAwF;gBACtF,qFAAqF,CACxF,CAAC;QACJ,MAAM,OAAO,GAAG,IAAI,iBAAiB,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAC5D,IAAI,gBAAgB;YAAE,OAAO,CAAC,mBAAmB,CAAC,gBAAgB,C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n * `siteCompiler`: a project's sources served by an in-browser HTTP server (`createProjectSite`,\n * hosted in a ServiceWorker by webrun-site-host), for `loadProject(files, { compile })`. Modules\n * are compiled one by one as the browser imports them; nothing is bundled.\n *\n * `loadProject` runs in a Dedicated Worker, which cannot register a ServiceWorker: the site is\n * hosted by a page. `siteHostOverPort` (worker) and `hostSitesForWorker` (page) do that over a\n * MessagePort: the worker serves the site's handler, the page mounts it in its ServiceWorker.\n */\nimport type { SiteHandler } from \"@statewalker/webrun-site-builder\";\nimport { HostedSiteBuilder } from \"@statewalker/webrun-site-host\";\nimport { linkOverPort, serveHandlerOverPort } from \"../transport/port.js\";\nimport { createProjectSite } from \"./site.js\";\nimport type { ProjectCompiler } from \"./source-project.js\";\n\n/** A site, hosted: its base URL (ending in \"/\") and how to take it down. */\nexport interface HostedProjectSite {\n baseUrl: string;\n stop(): Promise<void>;\n}\n\n/** Hosts a site handler where this realm's code can `import()` from it. */\nexport type SiteHost = (handler: SiteHandler) => Promise<HostedProjectSite>;\n\nexport interface SiteCompilerOptions {\n /**\n * Where the site is hosted. Default: a ServiceWorker this realm registers (`HostedSiteBuilder`),\n * which a page can do and a Dedicated Worker cannot; in a worker, pass `siteHostOverPort(port)`\n * and call `hostSitesForWorker(port)` in the page.\n */\n host?: SiteHost;\n /** The ServiceWorker script for the default host (default: `/sw-worker.js`). */\n serviceWorkerUrl?: string;\n /** `createProjectSite`'s `lowerAwait` (default: with nodejs_compat, unless AsyncContext). */\n lowerAwait?: boolean;\n}\n\n/** The default host: a ServiceWorker registered from this realm. */\nfunction serviceWorkerHost(serviceWorkerUrl?: string): SiteHost {\n return async (handler) => {\n if (!(globalThis as { navigator?: { serviceWorker?: unknown } }).navigator?.serviceWorker)\n throw new Error(\n \"siteCompiler: this realm cannot register a ServiceWorker (a Dedicated Worker cannot): \" +\n \"pass `host: siteHostOverPort(port)` and call `hostSitesForWorker(port)` in the page\",\n );\n const builder = new HostedSiteBuilder().setHandler(handler);\n if (serviceWorkerUrl) builder.setServiceWorkerUrl(serviceWorkerUrl);\n const site = await builder.build();\n return { baseUrl: site.baseUrl, stop: () => site.stop() };\n };\n}\n\n/**\n * A compiler for `loadProject(files, { compile })` that serves the project's modules from an\n * in-browser HTTP server (`createProjectSite`): `main` and Worker Loader code are imported from\n * it, so a change can rebuild one module. The site stops when the project closes.\n */\nexport function siteCompiler(options: SiteCompilerOptions = {}): ProjectCompiler {\n const host = options.host ?? serviceWorkerHost(options.serviceWorkerUrl);\n return {\n kind: \"site\",\n async compile({ files, nodeCompat }) {\n let nodeModules: Record<string, unknown> | undefined;\n if (nodeCompat) {\n // The served `node:*` proxies take their export names from the registry entries, which\n // the browser host binds in this realm; the npm `util` polyfill reads `process` when it\n // is imported.\n (await import(\"../node-compat/install.js\")).installNodeGlobals();\n nodeModules = (await import(\"../node-compat/browser-registry.js\")).nodeRegistryEntries;\n }\n const handler = createProjectSite({\n projectFiles: files,\n nodeCompat,\n nodeModules,\n lowerAwait: options.lowerAwait,\n });\n const site = await host(handler);\n const baseUrl = site.baseUrl.endsWith(\"/\") ? site.baseUrl : `${site.baseUrl}/`;\n return { code: { site: baseUrl }, close: () => site.stop() };\n },\n };\n}\n\nconst HOST_SITE = \"cellb:host-site\";\nconst STOP_SITE = \"cellb:stop-site\";\n\n/**\n * Where a worker and its page talk about sites: a MessagePort, the `Worker` (page side) or the\n * worker's own scope (`self`). Other messages on it are left alone.\n */\nexport interface SiteControl {\n postMessage(message: unknown, transfer: Transferable[]): void;\n addEventListener(type: \"message\", listener: (e: MessageEvent) => void): void;\n removeEventListener(type: \"message\", listener: (e: MessageEvent) => void): void;\n}\n\n/** What a worker asks its page for, on the control port. */\ninterface HostSiteRequest {\n type: typeof HOST_SITE;\n /** The worker serves the site's handler on this port's other end. */\n link: MessagePort;\n /** The page answers here, and the worker asks to stop here. */\n reply: MessagePort;\n}\n\n/** The next message on `port`, or `{ error }` after `timeoutMs` (a page that never answers). */\nconst once = (port: MessagePort, timeoutMs: number) =>\n new Promise<{ baseUrl?: string; error?: string }>((resolve) => {\n const timer = setTimeout(\n () =>\n resolve({ error: `no answer in ${timeoutMs} ms (does the page run hostSitesForWorker?)` }),\n timeoutMs,\n );\n port.onmessage = (e) => {\n clearTimeout(timer);\n resolve(e.data);\n };\n });\n\n/**\n * Worker side: hosts each site through the page at the other end of `control`, which runs\n * `hostSitesForWorker`. The handler stays in this worker; the page's ServiceWorker forwards each\n * request to it.\n */\nexport function siteHostOverPort(\n control: SiteControl,\n /**\n * How long the page may take to host the site (default 30 s; a ServiceWorker's first install\n * can be slow), and to confirm it stopped one (default 2 s; the worker stops serving anyway).\n */\n {\n timeoutMs = 30_000,\n stopTimeoutMs = 2_000,\n }: { timeoutMs?: number; stopTimeoutMs?: number } = {},\n): SiteHost {\n return async (handler) => {\n const link = new MessageChannel();\n const reply = new MessageChannel();\n const stopServing = await serveHandlerOverPort(link.port1, handler);\n const answered = once(reply.port1, timeoutMs);\n const request: HostSiteRequest = { type: HOST_SITE, link: link.port2, reply: reply.port2 };\n control.postMessage(request, [link.port2, reply.port2]);\n const { baseUrl, error } = await answered;\n if (!baseUrl) {\n // A page that hosts the site after all finds this stop waiting for it, and takes the site\n // down (its port stays open for that).\n reply.port1.onmessage = null;\n reply.port1.postMessage({ type: STOP_SITE });\n await stopServing();\n throw new Error(`the page did not host the site: ${error}`);\n }\n return {\n baseUrl,\n stop: async () => {\n // A page that does not answer stops nothing: the worker stops serving all the same.\n const stopped = once(reply.port1, stopTimeoutMs);\n reply.port1.postMessage({ type: STOP_SITE });\n await stopped;\n reply.port1.close();\n await stopServing();\n },\n };\n };\n}\n\n/**\n * Page side: hosts in this page's ServiceWorker the sites a worker asks for over `control`\n * (`siteHostOverPort`). Returns a function that stops listening; the sites stop when the worker\n * stops them.\n */\nexport function hostSitesForWorker(\n control: SiteControl,\n options: { serviceWorkerUrl?: string } = {},\n): () => void {\n const listener = async (e: MessageEvent) => {\n const req = e.data as HostSiteRequest | undefined;\n if (req?.type !== HOST_SITE) return;\n try {\n // The worker may give up waiting (`timeoutMs`) and ask to stop before the site is up: the\n // stop then waits on `reply` until the handler below reads it.\n const link = await linkOverPort(req.link);\n const builder = new HostedSiteBuilder().setHandler(link.send);\n if (options.serviceWorkerUrl) builder.setServiceWorkerUrl(options.serviceWorkerUrl);\n const site = await builder.build();\n req.reply.onmessage = async (m) => {\n if ((m.data as { type?: string })?.type !== STOP_SITE) return;\n await site.stop().catch(() => {});\n await link.close().catch(() => {});\n req.reply.postMessage({ stopped: true });\n req.reply.close();\n };\n req.reply.postMessage({ baseUrl: site.baseUrl });\n } catch (err) {\n req.reply.postMessage({ error: String((err as Error)?.message ?? err) });\n req.reply.close();\n }\n };\n control.addEventListener(\"message\", listener);\n (control as { start?: () => void }).start?.();\n return () => control.removeEventListener(\"message\", listener);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"site-compiler.js","sourceRoot":"","sources":["../../src/project/site-compiler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AAEjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAG9C;;;;;GAKG;AACH,SAAS,oBAAoB;IAC3B,OAAO,IAAI,iBAAiB,CAAC;QAC3B,cAAc,EAAE,CAAC,EAAE,GAAG,EAAE,gBAAgB,EAAE,EAAE,EAAE,CAAC,IAAI,aAAa,CAAC,EAAE,GAAG,EAAE,gBAAgB,EAAE,CAAC;KAC5F,CAAC,CAAC;AACL,CAAC;AAwBD,oEAAoE;AACpE,SAAS,iBAAiB,CAAC,gBAAyB;IAClD,OAAO,KAAK,EAAE,OAAO,EAAE,EAAE;QACvB,IAAI,CAAE,UAA0D,CAAC,SAAS,EAAE,aAAa;YACvF,MAAM,IAAI,KAAK,CACb,w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C,CAAC;IAC7C,OAAkC,CAAC,KAAK,EAAE,EAAE,CAAC;IAC9C,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC,mBAAmB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;AAChE,CAAC","sourcesContent":["/**\n * `siteCompiler`: a project's sources served by an in-browser HTTP server (`createProjectSite`,\n * hosted in a ServiceWorker by webrun-site-host), for `loadProject(files, { compile })`. Modules\n * are compiled one by one as the browser imports them; nothing is bundled.\n *\n * `loadProject` runs in a Dedicated Worker, which cannot register a ServiceWorker: the site is\n * hosted by a page. `siteHostOverPort` (worker) and `hostSitesForWorker` (page) do that over a\n * MessagePort: the worker serves the site's handler, the page mounts it in its ServiceWorker.\n */\n\nimport { SwHttpAdapter } from \"@statewalker/webrun-http-browser\";\nimport type { SiteHandler } from \"@statewalker/webrun-site-builder\";\nimport { HostedSiteBuilder } from \"@statewalker/webrun-site-host\";\nimport { linkOverPort, serveHandlerOverPort } from \"../transport/port.js\";\nimport { createProjectSite } from \"./site.js\";\nimport type { ProjectCompiler } from \"./source-project.js\";\n\n/**\n * A `HostedSiteBuilder` whose page side is this package's webrun-http-browser (`SwHttpAdapter`),\n * not the older one webrun-site-host depends on (^0.7). From 0.12.5 it rebuilds a request's url at\n * the page's scheme, so a site hosted on an https page answers; and its version is the one whose\n * ServiceWorker (`sw-worker.js`) hosts serve.\n */\nfunction newHostedSiteBuilder(): HostedSiteBuilder {\n return new HostedSiteBuilder({\n adapterFactory: ({ key, serviceWorkerUrl }) => new SwHttpAdapter({ key, serviceWorkerUrl }),\n });\n}\n\n/** A site, hosted: its base URL (ending in \"/\") and how to take it down. */\nexport interface HostedProjectSite {\n baseUrl: string;\n stop(): Promise<void>;\n}\n\n/** Hosts a site handler where this realm's code can `import()` from it. */\nexport type SiteHost = (handler: SiteHandler) => Promise<HostedProjectSite>;\n\nexport interface SiteCompilerOptions {\n /**\n * Where the site is hosted. Default: a ServiceWorker this realm registers (`HostedSiteBuilder`),\n * which a page can do and a Dedicated Worker cannot; in a worker, pass `siteHostOverPort(port)`\n * and call `hostSitesForWorker(port)` in the page.\n */\n host?: SiteHost;\n /** The ServiceWorker script for the default host (default: `/sw-worker.js`). */\n serviceWorkerUrl?: string;\n /** `createProjectSite`'s `lowerAwait` (default: with nodejs_compat, unless AsyncContext). */\n lowerAwait?: boolean;\n}\n\n/** The default host: a ServiceWorker registered from this realm. */\nfunction serviceWorkerHost(serviceWorkerUrl?: string): SiteHost {\n return async (handler) => {\n if (!(globalThis as { navigator?: { serviceWorker?: unknown } }).navigator?.serviceWorker)\n throw new Error(\n \"siteCompiler: this realm cannot register a ServiceWorker (a Dedicated Worker cannot): \" +\n \"pass `host: siteHostOverPort(port)` and call `hostSitesForWorker(port)` in the page\",\n );\n const builder = newHostedSiteBuilder().setHandler(handler);\n if (serviceWorkerUrl) builder.setServiceWorkerUrl(serviceWorkerUrl);\n const site = await builder.build();\n return { baseUrl: site.baseUrl, stop: () => site.stop() };\n };\n}\n\n/**\n * A compiler for `loadProject(files, { compile })` that serves the project's modules from an\n * in-browser HTTP server (`createProjectSite`): `main` and Worker Loader code are imported from\n * it, so a change can rebuild one module. The site stops when the project closes.\n */\nexport function siteCompiler(options: SiteCompilerOptions = {}): ProjectCompiler {\n const host = options.host ?? serviceWorkerHost(options.serviceWorkerUrl);\n return {\n kind: \"site\",\n async compile({ files, nodeCompat }) {\n let nodeModules: Record<string, unknown> | undefined;\n if (nodeCompat) {\n // The served `node:*` proxies take their export names from the registry entries, which\n // the browser host binds in this realm; the npm `util` polyfill reads `process` when it\n // is imported.\n (await import(\"../node-compat/install.js\")).installNodeGlobals();\n nodeModules = (await import(\"../node-compat/browser-registry.js\")).nodeRegistryEntries;\n }\n const handler = createProjectSite({\n projectFiles: files,\n nodeCompat,\n nodeModules,\n lowerAwait: options.lowerAwait,\n });\n const site = await host(handler);\n const baseUrl = site.baseUrl.endsWith(\"/\") ? site.baseUrl : `${site.baseUrl}/`;\n return { code: { site: baseUrl }, close: () => site.stop() };\n },\n };\n}\n\nconst HOST_SITE = \"cellb:host-site\";\nconst STOP_SITE = \"cellb:stop-site\";\n\n/**\n * Where a worker and its page talk about sites: a MessagePort, the `Worker` (page side) or the\n * worker's own scope (`self`). Other messages on it are left alone.\n */\nexport interface SiteControl {\n postMessage(message: unknown, transfer: Transferable[]): void;\n addEventListener(type: \"message\", listener: (e: MessageEvent) => void): void;\n removeEventListener(type: \"message\", listener: (e: MessageEvent) => void): void;\n}\n\n/** What a worker asks its page for, on the control port. */\ninterface HostSiteRequest {\n type: typeof HOST_SITE;\n /** The worker serves the site's handler on this port's other end. */\n link: MessagePort;\n /** The page answers here, and the worker asks to stop here. */\n reply: MessagePort;\n}\n\n/** The next message on `port`, or `{ error }` after `timeoutMs` (a page that never answers). */\nconst once = (port: MessagePort, timeoutMs: number) =>\n new Promise<{ baseUrl?: string; error?: string }>((resolve) => {\n const timer = setTimeout(\n () =>\n resolve({ error: `no answer in ${timeoutMs} ms (does the page run hostSitesForWorker?)` }),\n timeoutMs,\n );\n port.onmessage = (e) => {\n clearTimeout(timer);\n resolve(e.data);\n };\n });\n\n/**\n * Worker side: hosts each site through the page at the other end of `control`, which runs\n * `hostSitesForWorker`. The handler stays in this worker; the page's ServiceWorker forwards each\n * request to it.\n */\nexport function siteHostOverPort(\n control: SiteControl,\n /**\n * How long the page may take to host the site (default 30 s; a ServiceWorker's first install\n * can be slow), and to confirm it stopped one (default 2 s; the worker stops serving anyway).\n */\n {\n timeoutMs = 30_000,\n stopTimeoutMs = 2_000,\n }: { timeoutMs?: number; stopTimeoutMs?: number } = {},\n): SiteHost {\n return async (handler) => {\n const link = new MessageChannel();\n const reply = new MessageChannel();\n const stopServing = await serveHandlerOverPort(link.port1, handler);\n const answered = once(reply.port1, timeoutMs);\n const request: HostSiteRequest = { type: HOST_SITE, link: link.port2, reply: reply.port2 };\n control.postMessage(request, [link.port2, reply.port2]);\n const { baseUrl, error } = await answered;\n if (!baseUrl) {\n // A page that hosts the site after all finds this stop waiting for it, and takes the site\n // down (its port stays open for that).\n reply.port1.onmessage = null;\n reply.port1.postMessage({ type: STOP_SITE });\n await stopServing();\n throw new Error(`the page did not host the site: ${error}`);\n }\n return {\n baseUrl,\n stop: async () => {\n // A page that does not answer stops nothing: the worker stops serving all the same.\n const stopped = once(reply.port1, stopTimeoutMs);\n reply.port1.postMessage({ type: STOP_SITE });\n await stopped;\n reply.port1.close();\n await stopServing();\n },\n };\n };\n}\n\n/**\n * Page side: hosts in this page's ServiceWorker the sites a worker asks for over `control`\n * (`siteHostOverPort`). Returns a function that stops listening; the sites stop when the worker\n * stops them.\n */\nexport function hostSitesForWorker(\n control: SiteControl,\n options: { serviceWorkerUrl?: string } = {},\n): () => void {\n const listener = async (e: MessageEvent) => {\n const req = e.data as HostSiteRequest | undefined;\n if (req?.type !== HOST_SITE) return;\n try {\n // The worker may give up waiting (`timeoutMs`) and ask to stop before the site is up: the\n // stop then waits on `reply` until the handler below reads it.\n const link = await linkOverPort(req.link);\n const builder = newHostedSiteBuilder().setHandler(link.send);\n if (options.serviceWorkerUrl) builder.setServiceWorkerUrl(options.serviceWorkerUrl);\n const site = await builder.build();\n req.reply.onmessage = async (m) => {\n if ((m.data as { type?: string })?.type !== STOP_SITE) return;\n await site.stop().catch(() => {});\n await link.close().catch(() => {});\n req.reply.postMessage({ stopped: true });\n req.reply.close();\n };\n req.reply.postMessage({ baseUrl: site.baseUrl });\n } catch (err) {\n req.reply.postMessage({ error: String((err as Error)?.message ?? err) });\n req.reply.close();\n }\n };\n control.addEventListener(\"message\", listener);\n (control as { start?: () => void }).start?.();\n return () => control.removeEventListener(\"message\", listener);\n}\n"]}
|
|
@@ -138,16 +138,16 @@ export declare function createProjectRuntime(config: WranglerConfig, module: Wor
|
|
|
138
138
|
* Entries with ids are kept as they are, so storage shared with celld keeps its names.
|
|
139
139
|
*/
|
|
140
140
|
export declare function withResourceIds(config: WranglerConfig): WranglerConfig;
|
|
141
|
+
/** Whether `config` asks for nodejs_compat (the flag, or a `nodejs_compat_*` one). */
|
|
142
|
+
export declare function hasNodeCompat(config: WranglerConfig): boolean;
|
|
143
|
+
/** The configuration files of a project folder, in the order celld reads them. */
|
|
144
|
+
export declare const WRANGLER_FILES: string[];
|
|
141
145
|
/**
|
|
142
146
|
* workerd fills `process.env` with the project's text `vars` under nodejs_compat from
|
|
143
147
|
* compatibility date 2025-04-01 (`nodejs_compat_populate_process_env`), unless
|
|
144
148
|
* `nodejs_compat_do_not_populate_process_env` is set. Frameworks read their settings there
|
|
145
149
|
* (EmDash's `EMDASH_SITE_URL`, for one).
|
|
146
150
|
*/
|
|
147
|
-
/** Whether `config` asks for nodejs_compat (the flag, or a `nodejs_compat_*` one). */
|
|
148
|
-
export declare function hasNodeCompat(config: WranglerConfig): boolean;
|
|
149
|
-
/** The configuration files of a project folder, in the order celld reads them. */
|
|
150
|
-
export declare const WRANGLER_FILES: string[];
|
|
151
151
|
export declare function populatesProcessEnv(config: WranglerConfig): boolean;
|
|
152
152
|
/** The text `vars` of a project, as `process.env` holds them. */
|
|
153
153
|
export declare function processEnvOf(config: WranglerConfig): Record<string, string>;
|
package/dist/project/wrangler.js
CHANGED
|
@@ -131,6 +131,9 @@ export function createProjectRuntime(config, module, host) {
|
|
|
131
131
|
continue; // the host's bundler maps node:*
|
|
132
132
|
else if (f === "websocket_standard_binary_type")
|
|
133
133
|
continue; // the host picks the project's WebSocketPair
|
|
134
|
+
else if (f === "nodejs_compat_populate_process_env" ||
|
|
135
|
+
f === "nodejs_compat_do_not_populate_process_env")
|
|
136
|
+
continue; // the host fills process.env or not (populatesProcessEnv)
|
|
134
137
|
else
|
|
135
138
|
unsupported.push(`compatibility_flags: ${f}`);
|
|
136
139
|
}
|
|
@@ -372,18 +375,18 @@ export function withResourceIds(config) {
|
|
|
372
375
|
d1_databases: d1?.map((d) => d.database_id ? d : { ...d, database_id: d.database_name ?? d.binding }),
|
|
373
376
|
};
|
|
374
377
|
}
|
|
375
|
-
/**
|
|
376
|
-
* workerd fills `process.env` with the project's text `vars` under nodejs_compat from
|
|
377
|
-
* compatibility date 2025-04-01 (`nodejs_compat_populate_process_env`), unless
|
|
378
|
-
* `nodejs_compat_do_not_populate_process_env` is set. Frameworks read their settings there
|
|
379
|
-
* (EmDash's `EMDASH_SITE_URL`, for one).
|
|
380
|
-
*/
|
|
381
378
|
/** Whether `config` asks for nodejs_compat (the flag, or a `nodejs_compat_*` one). */
|
|
382
379
|
export function hasNodeCompat(config) {
|
|
383
380
|
return (config.compatibility_flags ?? []).some((f) => f.startsWith("nodejs_compat"));
|
|
384
381
|
}
|
|
385
382
|
/** The configuration files of a project folder, in the order celld reads them. */
|
|
386
383
|
export const WRANGLER_FILES = ["wrangler.jsonc", "wrangler.json"];
|
|
384
|
+
/**
|
|
385
|
+
* workerd fills `process.env` with the project's text `vars` under nodejs_compat from
|
|
386
|
+
* compatibility date 2025-04-01 (`nodejs_compat_populate_process_env`), unless
|
|
387
|
+
* `nodejs_compat_do_not_populate_process_env` is set. Frameworks read their settings there
|
|
388
|
+
* (EmDash's `EMDASH_SITE_URL`, for one).
|
|
389
|
+
*/
|
|
387
390
|
export function populatesProcessEnv(config) {
|
|
388
391
|
const flags = config.compatibility_flags ?? [];
|
|
389
392
|
if (!hasNodeCompat(config))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrangler.js","sourceRoot":"","sources":["../../src/project/wrangler.ts"],"names":[],"mappings":"AAIA,OAAO,EAAyB,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAGL,iBAAiB,GAElB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAC5E,OAAO,EAAE,WAAW,EA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AAC","sourcesContent":["import type { FilesApi } from \"@statewalker/webrun-files\";\nimport type { AssetFiles, AssetsConfig } from \"../bindings/assets.js\";\nimport type { QueueConsumerConfig } from \"../bindings/celld-queues.js\";\nimport type { ModuleLoader } from \"../bindings/worker-loader.js\";\nimport { type WorkersAiOptions, workersAi } from \"../bindings/workers-ai.js\";\nimport { entrypointStub } from \"../core/handles.js\";\nimport type { DurableObjectNamespace } from \"../core/namespace.js\";\nimport {\n type CellRuntime,\n type CellRuntimeOptions,\n createCellRuntime,\n type WorkerModule,\n} from \"../core/runtime.js\";\nimport { splitSqlStatements } from \"../core/sql-split.js\";\nimport { filesApiBlobService } from \"../miniflare-compat/blob-service.js\";\nimport { simulatorFetcher } from \"../miniflare-compat/simulator-fetcher.js\";\nimport { systemClock } from \"../ports.js\";\nimport type { ModuleRule } from \"./module-rules.js\";\n\n/** The subset of wrangler.json(c) that celld deploys (and cellb reads). */\nexport interface WranglerConfig {\n name?: string;\n main?: string;\n compatibility_date?: string;\n compatibility_flags?: string[];\n vars?: Record<string, unknown>;\n durable_objects?: { bindings?: { name: string; class_name: string; script_name?: string }[] };\n migrations?: {\n tag: string;\n new_sqlite_classes?: string[];\n new_classes?: string[];\n renamed_classes?: { from: string; to: string }[];\n deleted_classes?: string[];\n }[];\n kv_namespaces?: { binding: string; id?: string }[];\n d1_databases?: { binding: string; database_name?: string; database_id?: string }[];\n r2_buckets?: { binding: string; bucket_name: string }[];\n queues?: {\n producers?: { binding: string; queue: string; delivery_delay?: number }[];\n consumers?: QueueConsumerConfig[];\n };\n workflows?: WorkflowConfig[];\n triggers?: { crons?: string[] };\n assets?: AssetsConfig;\n services?: { binding: string; service: string; entrypoint?: string; props?: unknown }[];\n worker_loaders?: { binding: string }[];\n /** Workers AI: served by the host's OpenAI-compatible endpoint (`ProjectHost.ai`), if any. */\n ai?: { binding: string };\n /** Module rules: how imports of non-JS files load (`CompiledWasm`, `Data`, `Text`). */\n rules?: ModuleRule[];\n /** Containers (celld runs them with Docker or Podman): not supported, reported. */\n containers?: { class_name: string; image?: string }[];\n}\n\n/** wrangler `workflows` entries. */\nexport interface WorkflowConfig {\n binding: string;\n name: string;\n class_name: string;\n}\n\n/** Runs the Worker's `queue(batch, env, ctx)` handler for a batch celld's queue cell leased. */\ninterface QueueDispatcher {\n deliver(batch: unknown): Promise<void>;\n}\n\nexport interface ProjectHost\n extends Pick<CellRuntimeOptions, \"openSql\" | \"storage\" | \"clock\" | \"peers\" | \"route\"> {\n /** Files of `assets.directory` (path \"/a/b.html\" → bytes), loaded by the host. */\n assetFiles?: AssetFiles;\n /** Runs each loaded Worker in its own realm (celld isolates); classes still use `loadModules`. */\n isolatedModules?: ModuleLoader;\n /** Compiles code given to a Worker Loader binding (esbuild on Node, webrun-modules in browsers). */\n loadModules?: ModuleLoader;\n /** Blob store of the KV simulator (large values): OPFS in a browser, a directory or S3 on a server. */\n files: FilesApi;\n /** The OpenAI-compatible endpoint behind the `ai` binding; without it the binding is unsupported. */\n ai?: WorkersAiOptions;\n /** The binding implementations the config needs: `await loadProjectBindings(config)`. */\n bindings?: ProjectBindings;\n}\n\n/**\n * The implementations of the bindings a project declares, loaded on demand: a project with\n * Durable Objects only loads none of them (Miniflare's D1 simulator, celld's KV, queue and\n * workflow code, R2, assets, cron and Worker Loaders), and a browser bundle keeps them in chunks\n * of their own.\n */\nexport interface ProjectBindings {\n kv?: typeof import(\"../bindings/celld-kv.js\");\n d1?: typeof import(\"../miniflare-compat/vendored.js\");\n queues?: typeof import(\"../bindings/celld-queues.js\");\n workflows?: typeof import(\"../bindings/celld-workflows.js\");\n r2?: typeof import(\"../bindings/r2.js\");\n r2Celld?: typeof import(\"../bindings/r2-celld.js\");\n cron?: typeof import(\"../bindings/cron.js\");\n assets?: typeof import(\"../bindings/assets.js\");\n workerLoader?: typeof import(\"../bindings/worker-loader.js\");\n}\n\n/** Loads the binding implementations `config` declares, for `createProjectRuntime`'s host. */\nexport async function loadProjectBindings(config: WranglerConfig): Promise<ProjectBindings> {\n const when = <T>(cond: unknown, load: () => Promise<T>) =>\n cond ? load() : Promise.resolve(undefined);\n const [kv, d1, queues, workflows, r2, r2Celld, cron, assets, workerLoader] = await Promise.all([\n when(config.kv_namespaces?.length, () => import(\"../bindings/celld-kv.js\")),\n when(config.d1_databases?.length, () => import(\"../miniflare-compat/vendored.js\")),\n when(\n config.queues?.producers?.length || config.queues?.consumers?.length,\n () => import(\"../bindings/celld-queues.js\"),\n ),\n when(config.workflows?.length, () => import(\"../bindings/celld-workflows.js\")),\n when(config.r2_buckets?.length, () => import(\"../bindings/r2.js\")),\n when(config.r2_buckets?.length, () => import(\"../bindings/r2-celld.js\")),\n when(config.triggers?.crons?.length, () => import(\"../bindings/cron.js\")),\n when(config.assets, () => import(\"../bindings/assets.js\")),\n when(config.worker_loaders?.length, () => import(\"../bindings/worker-loader.js\")),\n ]);\n return { kv, d1, queues, workflows, r2, r2Celld, cron, assets, workerLoader };\n}\n\n/** The loaded implementation of a binding the config declares, or an error saying how to load it. */\nfunction binding<K extends keyof ProjectBindings>(\n host: ProjectHost,\n key: K,\n what: string,\n): NonNullable<ProjectBindings[K]> {\n const m = host.bindings?.[key];\n if (!m)\n throw new Error(\n `${what}: the host has no implementation loaded; pass \\`bindings: await loadProjectBindings(config)\\``,\n );\n return m as NonNullable<ProjectBindings[K]>;\n}\n\nexport interface ProjectRuntime {\n runtime: CellRuntime;\n /** Configuration entries cellb does not support yet (reported, not silently ignored). */\n unsupported: string[];\n}\n\n/**\n * What `env` of `cloudflare:workers` holds while the Worker's module is evaluated, before the\n * runtime exists: the vars, and the bindings that need no runtime (`ai`; Flue's entry reads\n * `env.AI` at load).\n */\nexport function loadTimeEnv(\n config: WranglerConfig,\n ai?: WorkersAiOptions,\n): Record<string, unknown> {\n const env: Record<string, unknown> = { ...config.vars };\n if (config.ai && ai) env[config.ai.binding] = workersAi(ai);\n return env;\n}\n\n// Internal bindings carrying the runtime-supplied objects behind KV and D1.\nconst KV_OBJECTS = \"__CELLS_KV_OBJECTS\";\nconst D1_OBJECTS = \"__CELLS_D1_OBJECTS\";\nconst QUEUE_OBJECTS = \"__CELLS_QUEUE_OBJECTS\";\nconst WORKFLOW_OBJECTS = \"__CELLS_WORKFLOW_OBJECTS\";\n\n/**\n * Builds a runtime from a wrangler config and the Worker's module namespace — the same\n * inputs celld deploys. Hosts differ only in `host` (storage) and in how they load `main`.\n */\nexport function createProjectRuntime(\n config: WranglerConfig,\n module: WorkerModule,\n host: ProjectHost,\n): ProjectRuntime {\n config = withResourceIds(config);\n const unsupported: string[] = [];\n const durableObjects: NonNullable<CellRuntimeOptions[\"durableObjects\"]> = {};\n const sqliteClasses = new Set<string>();\n for (const m of config.migrations ?? []) {\n for (const c of m.new_sqlite_classes ?? []) sqliteClasses.add(c);\n for (const c of m.new_classes ?? []) sqliteClasses.add(c); // KV-backed on Cloudflare; SQLite here (superset)\n for (const r of m.renamed_classes ?? [])\n unsupported.push(`migrations.renamed_classes (${r.from} → ${r.to})`);\n }\n // wrangler's module rule types: the bundles apply CompiledWasm, Data and Text (module-rules.ts)\n for (const [i, r] of (config.rules ?? []).entries())\n if (![\"ESModule\", \"CommonJS\", \"CompiledWasm\", \"Data\", \"Text\"].includes(r.type))\n unsupported.push(`rules[${i}].type \"${r.type}\"`);\n for (const c of config.containers ?? [])\n unsupported.push(`containers[${c.class_name}] (cellb runs no containers)`);\n for (const b of config.durable_objects?.bindings ?? []) {\n if (b.script_name) unsupported.push(`durable_objects.bindings[${b.name}].script_name`);\n durableObjects[b.name] = { className: b.class_name };\n }\n const worker: WorkerModule = { ...module };\n let kv: ReturnType<NonNullable<ProjectBindings[\"kv\"]>[\"celldKv\"]> | undefined;\n if (config.kv_namespaces?.length) {\n kv = binding(host, \"kv\", \"kv_namespaces\").celldKv(host.files);\n worker.__KvNamespace = kv.KvNamespaceCell as never;\n durableObjects[KV_OBJECTS] = { className: \"__KvNamespace\" };\n }\n if (config.d1_databases?.length) {\n worker.__D1Database = binding(host, \"d1\", \"d1_databases\").D1DatabaseObject;\n durableObjects[D1_OBJECTS] = { className: \"__D1Database\" };\n }\n // Queues: every queue is a cell of a runtime-supplied class (as on celld).\n const consumers = new Map((config.queues?.consumers ?? []).map((c) => [c.queue, c]));\n // celld's own queue code (vendor/celld/queues.js): its queue cell, producer and consumer\n // batch, so a queue's cell (and pending messages) is celld's format.\n let queueDispatcher: QueueDispatcher | undefined;\n let queues: ReturnType<NonNullable<ProjectBindings[\"queues\"]>[\"celldQueues\"]> | undefined;\n if (config.queues?.producers?.length || consumers.size) {\n queues = binding(host, \"queues\", \"queues\").celldQueues({\n namespace: () => runtime.env[QUEUE_OBJECTS] as never,\n consumers: [...consumers.values()],\n compatibilityDate: config.compatibility_date,\n runConsumer: (batch) => queueDispatcher!.deliver(batch as never),\n });\n worker.__Queue = queues.QueueCell as never;\n durableObjects[QUEUE_OBJECTS] = { className: \"__Queue\" };\n }\n // Workflows: every instance is a cell of a runtime-supplied class (as on celld).\n // celld's own workflow code (vendor/celld/workflows.js): its instance cell and binding.\n let workflows:\n | ReturnType<NonNullable<ProjectBindings[\"workflows\"]>[\"celldWorkflows\"]>\n | undefined;\n if (config.workflows?.length) {\n workflows = binding(host, \"workflows\", \"workflows\").celldWorkflows({\n script: config.name ?? \"worker\",\n workflows: Object.fromEntries(config.workflows.map((w) => [w.name, w.class_name])),\n exports: () => module as Record<string, unknown>,\n env: () => runtime.env,\n namespace: () => runtime.env[WORKFLOW_OBJECTS],\n });\n worker[workflows.className] = workflows.WorkflowCell as never;\n durableObjects[WORKFLOW_OBJECTS] = { className: workflows.className };\n }\n if (config.ai && !host.ai)\n unsupported.push(\n `ai[${config.ai.binding}] (Workers AI: give the host an OpenAI-compatible \\`ai\\`)`,\n );\n for (const s of config.services ?? [])\n if (s.service !== config.name)\n unsupported.push(\n `services[${s.binding}] → \"${s.service}\" (only this script's own entrypoints)`,\n );\n const sqlExtensions: string[] = [];\n let deleteAllPreservesAlarm = false;\n for (const f of config.compatibility_flags ?? []) {\n if (f === \"delete_all_preserves_alarm\") deleteAllPreservesAlarm = true;\n else if (f === \"delete_all_deletes_alarm\")\n continue; // the default\n else if (f === \"sqlite_vec\")\n sqlExtensions.push(\"sqlite_vec\"); // vec0 virtual tables, as on celld\n else if (f === \"nodejs_compat\" || f === \"nodejs_compat_v2\")\n continue; // the host's bundler maps node:*\n else if (f === \"websocket_standard_binary_type\")\n continue; // the host picks the project's WebSocketPair\n else unsupported.push(`compatibility_flags: ${f}`);\n }\n\n const runtime = createCellRuntime({\n worker,\n durableObjects,\n vars: { ...config.vars, MINIFLARE_BLOBS: filesApiBlobService(host.files) },\n openSql: host.openSql,\n sqlExtensions,\n deleteAllPreservesAlarm,\n scriptName: config.name ?? \"worker\",\n // celld's fleet-wide namespaces for the resources several scripts can share.\n namespaceKeys: {\n __KvNamespace: \"cells:v1:kv:__KvNamespace\",\n __D1Database: \"cells:v1:d1:__D1Database\",\n __Queue: \"cells:v1:queue:__Queue\",\n },\n storage: host.storage,\n clock: host.clock,\n peers: host.peers,\n route: host.route,\n });\n const env = runtime.env as Record<string, unknown>;\n if (config.ai && host.ai) env[config.ai.binding] = workersAi(host.ai);\n // KV: celld's own client against celld's own namespace cell (cell name \"<id>/<shard>\").\n for (const ns of config.kv_namespaces ?? [])\n env[ns.binding] = new kv!.KvNamespace(() => env[KV_OBJECTS], `${ns.id}/0`);\n for (const p of config.queues?.producers ?? [])\n env[p.binding] = queues!.producer(p.queue, p.delivery_delay ?? 0);\n if (consumers.size) {\n const handler = (module.default as { queue?: (b: unknown, e: unknown, c: unknown) => unknown })\n .queue;\n if (typeof handler !== \"function\")\n unsupported.push(\"queues.consumers without a queue() handler\");\n queueDispatcher = {\n deliver: async (batch) => {\n const pending: Promise<unknown>[] = [];\n await handler?.call(module.default, batch, env, {\n waitUntil: (p: Promise<unknown>) => pending.push(p),\n passThroughOnException() {},\n });\n await Promise.allSettled(pending);\n },\n };\n }\n // The isolates of loaded Workers end with the runtime (on Node, a worker thread's port would\n // keep the process alive; in a browser, a Dedicated Worker would outlive the runtime).\n const isolated = host.isolatedModules as\n | (ModuleLoader & { close?(): void | Promise<void> })\n | undefined;\n if (config.worker_loaders?.length && isolated?.close) {\n const close = runtime.close.bind(runtime);\n runtime.close = async () => {\n await close();\n await isolated.close?.();\n };\n }\n for (const l of config.worker_loaders ?? []) {\n if (!host.loadModules) {\n unsupported.push(`worker_loaders[${l.binding}] (the host provides no module loader)`);\n continue;\n }\n const { workerLoader } = binding(host, \"workerLoader\", \"worker_loaders\");\n env[l.binding] = host.isolatedModules\n ? workerLoader(host.isolatedModules) // facets of loaded code run in the isolate as well\n : workerLoader(host.loadModules);\n }\n // Cron Triggers (validated at load time like `celld deploy` does).\n const crons = config.triggers?.crons ?? [];\n if (crons.length) {\n const scheduled = (\n module.default as { scheduled?: (c: unknown, e: unknown, x: unknown) => unknown }\n ).scheduled;\n if (typeof scheduled !== \"function\")\n unsupported.push(\"triggers.crons without a scheduled() handler\");\n else {\n const db = host.openSql(\"__cellb/cron\");\n const stop = binding(host, \"cron\", \"triggers.crons\").startCronTriggers(\n crons,\n (c, x) => runtime.runEvent(() => scheduled.call(module.default, c, env, x)),\n host.clock ?? systemClock,\n cronState(db),\n );\n const close = runtime.close.bind(runtime);\n runtime.close = async () => {\n stop();\n db.close();\n await close();\n };\n }\n }\n // Static assets: routed before the Worker; `assets.binding` exposes env.ASSETS.\n if (config.assets) {\n const hasWorker = typeof (module.default as { fetch?: unknown })?.fetch === \"function\";\n if (host.assetFiles?.has(\"/.assetsignore\"))\n throw new Error(\n `${config.assets.directory ?? \"assets\"}/.assetsignore is not supported by celld; remove it`,\n );\n const assets = binding(host, \"assets\", \"assets\").createAssets(\n host.assetFiles ?? new Map(),\n config.assets,\n hasWorker,\n );\n if (config.assets.binding) env[config.assets.binding] = assets.binding;\n const workerFetch = runtime.fetch.bind(runtime);\n runtime.fetch = async (req) =>\n assets.route(req) ??\n (hasWorker ? workerFetch(req) : new Response(\"Not found\", { status: 404 }));\n }\n for (const w of config.workflows ?? []) env[w.binding] = workflows!.binding(w.name);\n // Service bindings to this script's own entrypoints (a celld fleet runs one application):\n // default export or a named WorkerEntrypoint, with fetch() and JS RPC.\n for (const s of config.services ?? []) {\n if (s.service !== config.name) continue;\n const target = s.entrypoint ? module[s.entrypoint] : module.default;\n if (!target)\n unsupported.push(`services[${s.binding}].entrypoint \"${s.entrypoint}\" is not exported`);\n else env[s.binding] = entrypointStub(target, env, s.props);\n }\n // R2 objects live directly in the host's store, as celld keeps them in the fleet bucket.\n // With a celld fleet bucket, R2 objects live in it as celld keeps them; else in the FilesApi.\n for (const r2 of config.r2_buckets ?? []) {\n const { r2Bucket, r2BucketOn } = binding(host, \"r2\", \"r2_buckets\");\n const { celldR2Backend } = binding(host, \"r2Celld\", \"r2_buckets\");\n env[r2.binding] = host.storage?.objects\n ? r2BucketOn(celldR2Backend(host.storage.objects, r2.bucket_name), r2.binding)\n : r2Bucket(host.files, `/r2/${r2.bucket_name}`, r2.binding);\n }\n for (const d1 of config.d1_databases ?? [])\n env[d1.binding] = celldExec(\n binding(host, \"d1\", \"d1_databases\").makeD1Binding({\n fetcher: simulatorFetcher(\n env[D1_OBJECTS] as DurableObjectNamespace,\n d1.database_id as string, // set by withResourceIds\n ) as never,\n }) as D1Like,\n );\n for (const name of [...sqliteClasses])\n if (!Object.values(durableObjects).some((d) => d.className === name)) {\n // A migrated class without a binding is fine (reachable through other code paths only).\n }\n return { runtime, unsupported };\n}\n\ninterface D1Like {\n exec(sql: string): Promise<{ count: number; duration: number }>;\n prepare(sql: string): { run(): Promise<unknown> };\n}\n\n/**\n * `D1Database#exec` as celld implements it: statements are split by SQL syntax.\n * workerd's d1-api.ts splits on NEWLINES (Cloudflare's documented behaviour), so a\n * multi-line `CREATE TABLE` fails there but works on celld — and celld is the\n * reference here (verified on celld 0.6.2 by the d1 example in conformance/).\n */\nfunction celldExec<T extends D1Like>(db: T): T {\n const exec = async (sql: string) => {\n const t0 = Date.now();\n const statements = splitSqlStatements(sql).filter((s) => s.trim());\n for (const statement of statements) {\n if (/^\\s*BEGIN\\b/i.test(statement))\n throw new Error(\n \"D1_EXEC_ERROR: the SQL ends in an incomplete statement, which did not run: terminate the last statement with a semicolon\",\n );\n guard(statement);\n await db.prepare(statement).run();\n }\n return { count: statements.length, duration: Date.now() - t0 };\n };\n return celldD1(db, exec) as T;\n}\n\n/**\n * celld's D1 rules on top of workerd's client (celld docs/services/d1.md, checked by the\n * d1-details project): ATTACH/DETACH and TEMP objects are \"not authorized\", VACUUM is\n * \"authorization denied\"; there is one primary and no replica, so sessions return the\n * bookmark \"celld:primary\" and every result reports served_by_primary/served_by_region\n * \"local\"; a read-only statement reports last_row_id and changes as 0.\n */\nfunction guard(sql: string): void {\n if (/^\\s*(ATTACH|DETACH)\\b/i.test(sql) || /^\\s*CREATE\\s+(TEMP|TEMPORARY)\\b/i.test(sql))\n throw new Error(\"D1_ERROR: not authorized\");\n if (/^\\s*VACUUM\\b/i.test(sql)) throw new Error(\"D1_ERROR: authorization denied\");\n}\n\nfunction celldMeta(r: any): any {\n if (!r?.meta) return r;\n r.meta.served_by_primary = true;\n r.meta.served_by_region = \"local\";\n if (r.meta.changed_db === false) {\n r.meta.last_row_id = 0;\n r.meta.changes = 0;\n }\n return r;\n}\n\nfunction celldStatement(stmt: any): any {\n return new Proxy(stmt, {\n get(t, p, r) {\n const v = Reflect.get(t, p, r);\n if (p === \"bind\") return (...a: unknown[]) => celldStatement(v.apply(t, a));\n if (p === \"run\" || p === \"all\")\n return async (...a: unknown[]) => celldMeta(await v.apply(t, a));\n return typeof v === \"function\" ? v.bind(t) : v;\n },\n });\n}\n\nfunction celldD1(db: any, exec?: (sql: string) => Promise<unknown>): any {\n return new Proxy(db, {\n get(t, p, r) {\n if (p === \"exec\" && exec) return exec;\n const v = Reflect.get(t, p, r);\n if (p === \"prepare\")\n return (sql: string) => {\n guard(sql);\n return celldStatement(v.call(t, sql));\n };\n if (p === \"batch\")\n return async (stmts: unknown[], ...a: unknown[]) =>\n ((await v.call(t, stmts, ...a)) as unknown[]).map(celldMeta);\n if (p === \"withSession\")\n return () => {\n const session = celldD1(t);\n return new Proxy(session, {\n get: (s, q, rr) =>\n q === \"getBookmark\" ? () => \"celld:primary\" : Reflect.get(s, q, rr),\n });\n };\n if (p === \"getBookmark\") return () => \"celld:primary\";\n return typeof v === \"function\" ? v.bind(t) : v;\n },\n });\n}\n\n/** Last fired occurrence per cron expression, in a small SQLite database of the host. */\nfunction cronState(db: ReturnType<ProjectHost[\"openSql\"]>) {\n db.exec(\n \"CREATE TABLE IF NOT EXISTS cron_state (expression TEXT PRIMARY KEY, scheduled_time INTEGER)\",\n [],\n );\n return {\n get: (e: string) => {\n const row = db.exec(\"SELECT scheduled_time FROM cron_state WHERE expression = ?\", [e])\n .rows[0];\n return row ? Number(row[0]) : undefined;\n },\n set: (e: string, t: number) =>\n void db.exec(\"INSERT OR REPLACE INTO cron_state (expression, scheduled_time) VALUES (?, ?)\", [\n e,\n t,\n ]),\n };\n}\n\n/**\n * KV namespaces and D1 databases may omit their ids: wrangler provisions them on deploy, and\n * framework builds (Astro's Cloudflare adapter, for one) emit such entries. A KV namespace\n * then takes its binding name as id; a D1 database its `database_name`, else its binding name.\n * Entries with ids are kept as they are, so storage shared with celld keeps its names.\n */\nexport function withResourceIds(config: WranglerConfig): WranglerConfig {\n const kv = config.kv_namespaces;\n const d1 = config.d1_databases;\n if (!kv?.some((n) => !n.id) && !d1?.some((d) => !d.database_id)) return config;\n return {\n ...config,\n kv_namespaces: kv?.map((n) => (n.id ? n : { ...n, id: n.binding })),\n d1_databases: d1?.map((d) =>\n d.database_id ? d : { ...d, database_id: d.database_name ?? d.binding },\n ),\n };\n}\n\n/**\n * workerd fills `process.env` with the project's text `vars` under nodejs_compat from\n * compatibility date 2025-04-01 (`nodejs_compat_populate_process_env`), unless\n * `nodejs_compat_do_not_populate_process_env` is set. Frameworks read their settings there\n * (EmDash's `EMDASH_SITE_URL`, for one).\n */\n/** Whether `config` asks for nodejs_compat (the flag, or a `nodejs_compat_*` one). */\nexport function hasNodeCompat(config: WranglerConfig): boolean {\n return (config.compatibility_flags ?? []).some((f) => f.startsWith(\"nodejs_compat\"));\n}\n\n/** The configuration files of a project folder, in the order celld reads them. */\nexport const WRANGLER_FILES = [\"wrangler.jsonc\", \"wrangler.json\"];\n\nexport function populatesProcessEnv(config: WranglerConfig): boolean {\n const flags = config.compatibility_flags ?? [];\n if (!hasNodeCompat(config)) return false;\n if (flags.includes(\"nodejs_compat_do_not_populate_process_env\")) return false;\n if (flags.includes(\"nodejs_compat_populate_process_env\")) return true;\n return (config.compatibility_date ?? \"\") >= \"2025-04-01\";\n}\n\n/** The text `vars` of a project, as `process.env` holds them. */\nexport function processEnvOf(config: WranglerConfig): Record<string, string> {\n const env: Record<string, string> = {};\n for (const [k, v] of Object.entries(config.vars ?? {})) if (typeof v === \"string\") env[k] = v;\n return env;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"wrangler.js","sourceRoot":"","sources":["../../src/project/wrangler.ts"],"names":[],"mappings":"AAIA,OAAO,EAAyB,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAGL,iBAAiB,GAElB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAoF1C,8FAA8F;AAC9F,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,MAAsB;IAC9D,MAAM,IAAI,GAAG,CAAI,IAAa,EAAE,IAAsB,EAAE,EAAE,CACxD,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,C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O,EAAE,CACxE;KACF,CAAC;AACJ,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,aAAa,CAAC,MAAsB;IAClD,OAAO,CAAC,MAAM,CAAC,mBAAmB,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC;AACvF,CAAC;AAED,kFAAkF;AAClF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAC;AAElE;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAsB;IACxD,MAAM,KAAK,GAAG,MAAM,CAAC,mBAAmB,IAAI,EAAE,CAAC;IAC/C,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC;QAAE,OAAO,KAAK,CAAC;IACzC,IAAI,KAAK,CAAC,QAAQ,CAAC,2CAA2C,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9E,IAAI,KAAK,CAAC,QAAQ,CAAC,oCAAoC,CAAC;QAAE,OAAO,IAAI,CAAC;IACtE,OAAO,CAAC,MAAM,CAAC,kBAAkB,IAAI,EAAE,CAAC,IAAI,YAAY,CAAC;AAC3D,CAAC;AAED,iEAAiE;AACjE,MAAM,UAAU,YAAY,CAAC,MAAsB;IACjD,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;QAAE,IAAI,OAAO,CAAC,KAAK,QAAQ;YAAE,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAC9F,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import type { FilesApi } from \"@statewalker/webrun-files\";\nimport type { AssetFiles, AssetsConfig } from \"../bindings/assets.js\";\nimport type { QueueConsumerConfig } from \"../bindings/celld-queues.js\";\nimport type { ModuleLoader } from \"../bindings/worker-loader.js\";\nimport { type WorkersAiOptions, workersAi } from \"../bindings/workers-ai.js\";\nimport { entrypointStub } from \"../core/handles.js\";\nimport type { DurableObjectNamespace } from \"../core/namespace.js\";\nimport {\n type CellRuntime,\n type CellRuntimeOptions,\n createCellRuntime,\n type WorkerModule,\n} from \"../core/runtime.js\";\nimport { splitSqlStatements } from \"../core/sql-split.js\";\nimport { filesApiBlobService } from \"../miniflare-compat/blob-service.js\";\nimport { simulatorFetcher } from \"../miniflare-compat/simulator-fetcher.js\";\nimport { systemClock } from \"../ports.js\";\nimport type { ModuleRule } from \"./module-rules.js\";\n\n/** The subset of wrangler.json(c) that celld deploys (and cellb reads). */\nexport interface WranglerConfig {\n name?: string;\n main?: string;\n compatibility_date?: string;\n compatibility_flags?: string[];\n vars?: Record<string, unknown>;\n durable_objects?: { bindings?: { name: string; class_name: string; script_name?: string }[] };\n migrations?: {\n tag: string;\n new_sqlite_classes?: string[];\n new_classes?: string[];\n renamed_classes?: { from: string; to: string }[];\n deleted_classes?: string[];\n }[];\n kv_namespaces?: { binding: string; id?: string }[];\n d1_databases?: { binding: string; database_name?: string; database_id?: string }[];\n r2_buckets?: { binding: string; bucket_name: string }[];\n queues?: {\n producers?: { binding: string; queue: string; delivery_delay?: number }[];\n consumers?: QueueConsumerConfig[];\n };\n workflows?: WorkflowConfig[];\n triggers?: { crons?: string[] };\n assets?: AssetsConfig;\n services?: { binding: string; service: string; entrypoint?: string; props?: unknown }[];\n worker_loaders?: { binding: string }[];\n /** Workers AI: served by the host's OpenAI-compatible endpoint (`ProjectHost.ai`), if any. */\n ai?: { binding: string };\n /** Module rules: how imports of non-JS files load (`CompiledWasm`, `Data`, `Text`). */\n rules?: ModuleRule[];\n /** Containers (celld runs them with Docker or Podman): not supported, reported. */\n containers?: { class_name: string; image?: string }[];\n}\n\n/** wrangler `workflows` entries. */\nexport interface WorkflowConfig {\n binding: string;\n name: string;\n class_name: string;\n}\n\n/** Runs the Worker's `queue(batch, env, ctx)` handler for a batch celld's queue cell leased. */\ninterface QueueDispatcher {\n deliver(batch: unknown): Promise<void>;\n}\n\nexport interface ProjectHost\n extends Pick<CellRuntimeOptions, \"openSql\" | \"storage\" | \"clock\" | \"peers\" | \"route\"> {\n /** Files of `assets.directory` (path \"/a/b.html\" → bytes), loaded by the host. */\n assetFiles?: AssetFiles;\n /** Runs each loaded Worker in its own realm (celld isolates); classes still use `loadModules`. */\n isolatedModules?: ModuleLoader;\n /** Compiles code given to a Worker Loader binding (esbuild on Node, webrun-modules in browsers). */\n loadModules?: ModuleLoader;\n /** Blob store of the KV simulator (large values): OPFS in a browser, a directory or S3 on a server. */\n files: FilesApi;\n /** The OpenAI-compatible endpoint behind the `ai` binding; without it the binding is unsupported. */\n ai?: WorkersAiOptions;\n /** The binding implementations the config needs: `await loadProjectBindings(config)`. */\n bindings?: ProjectBindings;\n}\n\n/**\n * The implementations of the bindings a project declares, loaded on demand: a project with\n * Durable Objects only loads none of them (Miniflare's D1 simulator, celld's KV, queue and\n * workflow code, R2, assets, cron and Worker Loaders), and a browser bundle keeps them in chunks\n * of their own.\n */\nexport interface ProjectBindings {\n kv?: typeof import(\"../bindings/celld-kv.js\");\n d1?: typeof import(\"../miniflare-compat/vendored.js\");\n queues?: typeof import(\"../bindings/celld-queues.js\");\n workflows?: typeof import(\"../bindings/celld-workflows.js\");\n r2?: typeof import(\"../bindings/r2.js\");\n r2Celld?: typeof import(\"../bindings/r2-celld.js\");\n cron?: typeof import(\"../bindings/cron.js\");\n assets?: typeof import(\"../bindings/assets.js\");\n workerLoader?: typeof import(\"../bindings/worker-loader.js\");\n}\n\n/** Loads the binding implementations `config` declares, for `createProjectRuntime`'s host. */\nexport async function loadProjectBindings(config: WranglerConfig): Promise<ProjectBindings> {\n const when = <T>(cond: unknown, load: () => Promise<T>) =>\n cond ? load() : Promise.resolve(undefined);\n const [kv, d1, queues, workflows, r2, r2Celld, cron, assets, workerLoader] = await Promise.all([\n when(config.kv_namespaces?.length, () => import(\"../bindings/celld-kv.js\")),\n when(config.d1_databases?.length, () => import(\"../miniflare-compat/vendored.js\")),\n when(\n config.queues?.producers?.length || config.queues?.consumers?.length,\n () => import(\"../bindings/celld-queues.js\"),\n ),\n when(config.workflows?.length, () => import(\"../bindings/celld-workflows.js\")),\n when(config.r2_buckets?.length, () => import(\"../bindings/r2.js\")),\n when(config.r2_buckets?.length, () => import(\"../bindings/r2-celld.js\")),\n when(config.triggers?.crons?.length, () => import(\"../bindings/cron.js\")),\n when(config.assets, () => import(\"../bindings/assets.js\")),\n when(config.worker_loaders?.length, () => import(\"../bindings/worker-loader.js\")),\n ]);\n return { kv, d1, queues, workflows, r2, r2Celld, cron, assets, workerLoader };\n}\n\n/** The loaded implementation of a binding the config declares, or an error saying how to load it. */\nfunction binding<K extends keyof ProjectBindings>(\n host: ProjectHost,\n key: K,\n what: string,\n): NonNullable<ProjectBindings[K]> {\n const m = host.bindings?.[key];\n if (!m)\n throw new Error(\n `${what}: the host has no implementation loaded; pass \\`bindings: await loadProjectBindings(config)\\``,\n );\n return m as NonNullable<ProjectBindings[K]>;\n}\n\nexport interface ProjectRuntime {\n runtime: CellRuntime;\n /** Configuration entries cellb does not support yet (reported, not silently ignored). */\n unsupported: string[];\n}\n\n/**\n * What `env` of `cloudflare:workers` holds while the Worker's module is evaluated, before the\n * runtime exists: the vars, and the bindings that need no runtime (`ai`; Flue's entry reads\n * `env.AI` at load).\n */\nexport function loadTimeEnv(\n config: WranglerConfig,\n ai?: WorkersAiOptions,\n): Record<string, unknown> {\n const env: Record<string, unknown> = { ...config.vars };\n if (config.ai && ai) env[config.ai.binding] = workersAi(ai);\n return env;\n}\n\n// Internal bindings carrying the runtime-supplied objects behind KV and D1.\nconst KV_OBJECTS = \"__CELLS_KV_OBJECTS\";\nconst D1_OBJECTS = \"__CELLS_D1_OBJECTS\";\nconst QUEUE_OBJECTS = \"__CELLS_QUEUE_OBJECTS\";\nconst WORKFLOW_OBJECTS = \"__CELLS_WORKFLOW_OBJECTS\";\n\n/**\n * Builds a runtime from a wrangler config and the Worker's module namespace — the same\n * inputs celld deploys. Hosts differ only in `host` (storage) and in how they load `main`.\n */\nexport function createProjectRuntime(\n config: WranglerConfig,\n module: WorkerModule,\n host: ProjectHost,\n): ProjectRuntime {\n config = withResourceIds(config);\n const unsupported: string[] = [];\n const durableObjects: NonNullable<CellRuntimeOptions[\"durableObjects\"]> = {};\n const sqliteClasses = new Set<string>();\n for (const m of config.migrations ?? []) {\n for (const c of m.new_sqlite_classes ?? []) sqliteClasses.add(c);\n for (const c of m.new_classes ?? []) sqliteClasses.add(c); // KV-backed on Cloudflare; SQLite here (superset)\n for (const r of m.renamed_classes ?? [])\n unsupported.push(`migrations.renamed_classes (${r.from} → ${r.to})`);\n }\n // wrangler's module rule types: the bundles apply CompiledWasm, Data and Text (module-rules.ts)\n for (const [i, r] of (config.rules ?? []).entries())\n if (![\"ESModule\", \"CommonJS\", \"CompiledWasm\", \"Data\", \"Text\"].includes(r.type))\n unsupported.push(`rules[${i}].type \"${r.type}\"`);\n for (const c of config.containers ?? [])\n unsupported.push(`containers[${c.class_name}] (cellb runs no containers)`);\n for (const b of config.durable_objects?.bindings ?? []) {\n if (b.script_name) unsupported.push(`durable_objects.bindings[${b.name}].script_name`);\n durableObjects[b.name] = { className: b.class_name };\n }\n const worker: WorkerModule = { ...module };\n let kv: ReturnType<NonNullable<ProjectBindings[\"kv\"]>[\"celldKv\"]> | undefined;\n if (config.kv_namespaces?.length) {\n kv = binding(host, \"kv\", \"kv_namespaces\").celldKv(host.files);\n worker.__KvNamespace = kv.KvNamespaceCell as never;\n durableObjects[KV_OBJECTS] = { className: \"__KvNamespace\" };\n }\n if (config.d1_databases?.length) {\n worker.__D1Database = binding(host, \"d1\", \"d1_databases\").D1DatabaseObject;\n durableObjects[D1_OBJECTS] = { className: \"__D1Database\" };\n }\n // Queues: every queue is a cell of a runtime-supplied class (as on celld).\n const consumers = new Map((config.queues?.consumers ?? []).map((c) => [c.queue, c]));\n // celld's own queue code (vendor/celld/queues.js): its queue cell, producer and consumer\n // batch, so a queue's cell (and pending messages) is celld's format.\n let queueDispatcher: QueueDispatcher | undefined;\n let queues: ReturnType<NonNullable<ProjectBindings[\"queues\"]>[\"celldQueues\"]> | undefined;\n if (config.queues?.producers?.length || consumers.size) {\n queues = binding(host, \"queues\", \"queues\").celldQueues({\n namespace: () => runtime.env[QUEUE_OBJECTS] as never,\n consumers: [...consumers.values()],\n compatibilityDate: config.compatibility_date,\n runConsumer: (batch) => queueDispatcher!.deliver(batch as never),\n });\n worker.__Queue = queues.QueueCell as never;\n durableObjects[QUEUE_OBJECTS] = { className: \"__Queue\" };\n }\n // Workflows: every instance is a cell of a runtime-supplied class (as on celld).\n // celld's own workflow code (vendor/celld/workflows.js): its instance cell and binding.\n let workflows:\n | ReturnType<NonNullable<ProjectBindings[\"workflows\"]>[\"celldWorkflows\"]>\n | undefined;\n if (config.workflows?.length) {\n workflows = binding(host, \"workflows\", \"workflows\").celldWorkflows({\n script: config.name ?? \"worker\",\n workflows: Object.fromEntries(config.workflows.map((w) => [w.name, w.class_name])),\n exports: () => module as Record<string, unknown>,\n env: () => runtime.env,\n namespace: () => runtime.env[WORKFLOW_OBJECTS],\n });\n worker[workflows.className] = workflows.WorkflowCell as never;\n durableObjects[WORKFLOW_OBJECTS] = { className: workflows.className };\n }\n if (config.ai && !host.ai)\n unsupported.push(\n `ai[${config.ai.binding}] (Workers AI: give the host an OpenAI-compatible \\`ai\\`)`,\n );\n for (const s of config.services ?? [])\n if (s.service !== config.name)\n unsupported.push(\n `services[${s.binding}] → \"${s.service}\" (only this script's own entrypoints)`,\n );\n const sqlExtensions: string[] = [];\n let deleteAllPreservesAlarm = false;\n for (const f of config.compatibility_flags ?? []) {\n if (f === \"delete_all_preserves_alarm\") deleteAllPreservesAlarm = true;\n else if (f === \"delete_all_deletes_alarm\")\n continue; // the default\n else if (f === \"sqlite_vec\")\n sqlExtensions.push(\"sqlite_vec\"); // vec0 virtual tables, as on celld\n else if (f === \"nodejs_compat\" || f === \"nodejs_compat_v2\")\n continue; // the host's bundler maps node:*\n else if (f === \"websocket_standard_binary_type\")\n continue; // the host picks the project's WebSocketPair\n else if (\n f === \"nodejs_compat_populate_process_env\" ||\n f === \"nodejs_compat_do_not_populate_process_env\"\n )\n continue; // the host fills process.env or not (populatesProcessEnv)\n else unsupported.push(`compatibility_flags: ${f}`);\n }\n\n const runtime = createCellRuntime({\n worker,\n durableObjects,\n vars: { ...config.vars, MINIFLARE_BLOBS: filesApiBlobService(host.files) },\n openSql: host.openSql,\n sqlExtensions,\n deleteAllPreservesAlarm,\n scriptName: config.name ?? \"worker\",\n // celld's fleet-wide namespaces for the resources several scripts can share.\n namespaceKeys: {\n __KvNamespace: \"cells:v1:kv:__KvNamespace\",\n __D1Database: \"cells:v1:d1:__D1Database\",\n __Queue: \"cells:v1:queue:__Queue\",\n },\n storage: host.storage,\n clock: host.clock,\n peers: host.peers,\n route: host.route,\n });\n const env = runtime.env as Record<string, unknown>;\n if (config.ai && host.ai) env[config.ai.binding] = workersAi(host.ai);\n // KV: celld's own client against celld's own namespace cell (cell name \"<id>/<shard>\").\n for (const ns of config.kv_namespaces ?? [])\n env[ns.binding] = new kv!.KvNamespace(() => env[KV_OBJECTS], `${ns.id}/0`);\n for (const p of config.queues?.producers ?? [])\n env[p.binding] = queues!.producer(p.queue, p.delivery_delay ?? 0);\n if (consumers.size) {\n const handler = (module.default as { queue?: (b: unknown, e: unknown, c: unknown) => unknown })\n .queue;\n if (typeof handler !== \"function\")\n unsupported.push(\"queues.consumers without a queue() handler\");\n queueDispatcher = {\n deliver: async (batch) => {\n const pending: Promise<unknown>[] = [];\n await handler?.call(module.default, batch, env, {\n waitUntil: (p: Promise<unknown>) => pending.push(p),\n passThroughOnException() {},\n });\n await Promise.allSettled(pending);\n },\n };\n }\n // The isolates of loaded Workers end with the runtime (on Node, a worker thread's port would\n // keep the process alive; in a browser, a Dedicated Worker would outlive the runtime).\n const isolated = host.isolatedModules as\n | (ModuleLoader & { close?(): void | Promise<void> })\n | undefined;\n if (config.worker_loaders?.length && isolated?.close) {\n const close = runtime.close.bind(runtime);\n runtime.close = async () => {\n await close();\n await isolated.close?.();\n };\n }\n for (const l of config.worker_loaders ?? []) {\n if (!host.loadModules) {\n unsupported.push(`worker_loaders[${l.binding}] (the host provides no module loader)`);\n continue;\n }\n const { workerLoader } = binding(host, \"workerLoader\", \"worker_loaders\");\n env[l.binding] = host.isolatedModules\n ? workerLoader(host.isolatedModules) // facets of loaded code run in the isolate as well\n : workerLoader(host.loadModules);\n }\n // Cron Triggers (validated at load time like `celld deploy` does).\n const crons = config.triggers?.crons ?? [];\n if (crons.length) {\n const scheduled = (\n module.default as { scheduled?: (c: unknown, e: unknown, x: unknown) => unknown }\n ).scheduled;\n if (typeof scheduled !== \"function\")\n unsupported.push(\"triggers.crons without a scheduled() handler\");\n else {\n const db = host.openSql(\"__cellb/cron\");\n const stop = binding(host, \"cron\", \"triggers.crons\").startCronTriggers(\n crons,\n (c, x) => runtime.runEvent(() => scheduled.call(module.default, c, env, x)),\n host.clock ?? systemClock,\n cronState(db),\n );\n const close = runtime.close.bind(runtime);\n runtime.close = async () => {\n stop();\n db.close();\n await close();\n };\n }\n }\n // Static assets: routed before the Worker; `assets.binding` exposes env.ASSETS.\n if (config.assets) {\n const hasWorker = typeof (module.default as { fetch?: unknown })?.fetch === \"function\";\n if (host.assetFiles?.has(\"/.assetsignore\"))\n throw new Error(\n `${config.assets.directory ?? \"assets\"}/.assetsignore is not supported by celld; remove it`,\n );\n const assets = binding(host, \"assets\", \"assets\").createAssets(\n host.assetFiles ?? new Map(),\n config.assets,\n hasWorker,\n );\n if (config.assets.binding) env[config.assets.binding] = assets.binding;\n const workerFetch = runtime.fetch.bind(runtime);\n runtime.fetch = async (req) =>\n assets.route(req) ??\n (hasWorker ? workerFetch(req) : new Response(\"Not found\", { status: 404 }));\n }\n for (const w of config.workflows ?? []) env[w.binding] = workflows!.binding(w.name);\n // Service bindings to this script's own entrypoints (a celld fleet runs one application):\n // default export or a named WorkerEntrypoint, with fetch() and JS RPC.\n for (const s of config.services ?? []) {\n if (s.service !== config.name) continue;\n const target = s.entrypoint ? module[s.entrypoint] : module.default;\n if (!target)\n unsupported.push(`services[${s.binding}].entrypoint \"${s.entrypoint}\" is not exported`);\n else env[s.binding] = entrypointStub(target, env, s.props);\n }\n // R2 objects live directly in the host's store, as celld keeps them in the fleet bucket.\n // With a celld fleet bucket, R2 objects live in it as celld keeps them; else in the FilesApi.\n for (const r2 of config.r2_buckets ?? []) {\n const { r2Bucket, r2BucketOn } = binding(host, \"r2\", \"r2_buckets\");\n const { celldR2Backend } = binding(host, \"r2Celld\", \"r2_buckets\");\n env[r2.binding] = host.storage?.objects\n ? r2BucketOn(celldR2Backend(host.storage.objects, r2.bucket_name), r2.binding)\n : r2Bucket(host.files, `/r2/${r2.bucket_name}`, r2.binding);\n }\n for (const d1 of config.d1_databases ?? [])\n env[d1.binding] = celldExec(\n binding(host, \"d1\", \"d1_databases\").makeD1Binding({\n fetcher: simulatorFetcher(\n env[D1_OBJECTS] as DurableObjectNamespace,\n d1.database_id as string, // set by withResourceIds\n ) as never,\n }) as D1Like,\n );\n for (const name of [...sqliteClasses])\n if (!Object.values(durableObjects).some((d) => d.className === name)) {\n // A migrated class without a binding is fine (reachable through other code paths only).\n }\n return { runtime, unsupported };\n}\n\ninterface D1Like {\n exec(sql: string): Promise<{ count: number; duration: number }>;\n prepare(sql: string): { run(): Promise<unknown> };\n}\n\n/**\n * `D1Database#exec` as celld implements it: statements are split by SQL syntax.\n * workerd's d1-api.ts splits on NEWLINES (Cloudflare's documented behaviour), so a\n * multi-line `CREATE TABLE` fails there but works on celld — and celld is the\n * reference here (verified on celld 0.6.2 by the d1 example in conformance/).\n */\nfunction celldExec<T extends D1Like>(db: T): T {\n const exec = async (sql: string) => {\n const t0 = Date.now();\n const statements = splitSqlStatements(sql).filter((s) => s.trim());\n for (const statement of statements) {\n if (/^\\s*BEGIN\\b/i.test(statement))\n throw new Error(\n \"D1_EXEC_ERROR: the SQL ends in an incomplete statement, which did not run: terminate the last statement with a semicolon\",\n );\n guard(statement);\n await db.prepare(statement).run();\n }\n return { count: statements.length, duration: Date.now() - t0 };\n };\n return celldD1(db, exec) as T;\n}\n\n/**\n * celld's D1 rules on top of workerd's client (celld docs/services/d1.md, checked by the\n * d1-details project): ATTACH/DETACH and TEMP objects are \"not authorized\", VACUUM is\n * \"authorization denied\"; there is one primary and no replica, so sessions return the\n * bookmark \"celld:primary\" and every result reports served_by_primary/served_by_region\n * \"local\"; a read-only statement reports last_row_id and changes as 0.\n */\nfunction guard(sql: string): void {\n if (/^\\s*(ATTACH|DETACH)\\b/i.test(sql) || /^\\s*CREATE\\s+(TEMP|TEMPORARY)\\b/i.test(sql))\n throw new Error(\"D1_ERROR: not authorized\");\n if (/^\\s*VACUUM\\b/i.test(sql)) throw new Error(\"D1_ERROR: authorization denied\");\n}\n\nfunction celldMeta(r: any): any {\n if (!r?.meta) return r;\n r.meta.served_by_primary = true;\n r.meta.served_by_region = \"local\";\n if (r.meta.changed_db === false) {\n r.meta.last_row_id = 0;\n r.meta.changes = 0;\n }\n return r;\n}\n\nfunction celldStatement(stmt: any): any {\n return new Proxy(stmt, {\n get(t, p, r) {\n const v = Reflect.get(t, p, r);\n if (p === \"bind\") return (...a: unknown[]) => celldStatement(v.apply(t, a));\n if (p === \"run\" || p === \"all\")\n return async (...a: unknown[]) => celldMeta(await v.apply(t, a));\n return typeof v === \"function\" ? v.bind(t) : v;\n },\n });\n}\n\nfunction celldD1(db: any, exec?: (sql: string) => Promise<unknown>): any {\n return new Proxy(db, {\n get(t, p, r) {\n if (p === \"exec\" && exec) return exec;\n const v = Reflect.get(t, p, r);\n if (p === \"prepare\")\n return (sql: string) => {\n guard(sql);\n return celldStatement(v.call(t, sql));\n };\n if (p === \"batch\")\n return async (stmts: unknown[], ...a: unknown[]) =>\n ((await v.call(t, stmts, ...a)) as unknown[]).map(celldMeta);\n if (p === \"withSession\")\n return () => {\n const session = celldD1(t);\n return new Proxy(session, {\n get: (s, q, rr) =>\n q === \"getBookmark\" ? () => \"celld:primary\" : Reflect.get(s, q, rr),\n });\n };\n if (p === \"getBookmark\") return () => \"celld:primary\";\n return typeof v === \"function\" ? v.bind(t) : v;\n },\n });\n}\n\n/** Last fired occurrence per cron expression, in a small SQLite database of the host. */\nfunction cronState(db: ReturnType<ProjectHost[\"openSql\"]>) {\n db.exec(\n \"CREATE TABLE IF NOT EXISTS cron_state (expression TEXT PRIMARY KEY, scheduled_time INTEGER)\",\n [],\n );\n return {\n get: (e: string) => {\n const row = db.exec(\"SELECT scheduled_time FROM cron_state WHERE expression = ?\", [e])\n .rows[0];\n return row ? Number(row[0]) : undefined;\n },\n set: (e: string, t: number) =>\n void db.exec(\"INSERT OR REPLACE INTO cron_state (expression, scheduled_time) VALUES (?, ?)\", [\n e,\n t,\n ]),\n };\n}\n\n/**\n * KV namespaces and D1 databases may omit their ids: wrangler provisions them on deploy, and\n * framework builds (Astro's Cloudflare adapter, for one) emit such entries. A KV namespace\n * then takes its binding name as id; a D1 database its `database_name`, else its binding name.\n * Entries with ids are kept as they are, so storage shared with celld keeps its names.\n */\nexport function withResourceIds(config: WranglerConfig): WranglerConfig {\n const kv = config.kv_namespaces;\n const d1 = config.d1_databases;\n if (!kv?.some((n) => !n.id) && !d1?.some((d) => !d.database_id)) return config;\n return {\n ...config,\n kv_namespaces: kv?.map((n) => (n.id ? n : { ...n, id: n.binding })),\n d1_databases: d1?.map((d) =>\n d.database_id ? d : { ...d, database_id: d.database_name ?? d.binding },\n ),\n };\n}\n\n/** Whether `config` asks for nodejs_compat (the flag, or a `nodejs_compat_*` one). */\nexport function hasNodeCompat(config: WranglerConfig): boolean {\n return (config.compatibility_flags ?? []).some((f) => f.startsWith(\"nodejs_compat\"));\n}\n\n/** The configuration files of a project folder, in the order celld reads them. */\nexport const WRANGLER_FILES = [\"wrangler.jsonc\", \"wrangler.json\"];\n\n/**\n * workerd fills `process.env` with the project's text `vars` under nodejs_compat from\n * compatibility date 2025-04-01 (`nodejs_compat_populate_process_env`), unless\n * `nodejs_compat_do_not_populate_process_env` is set. Frameworks read their settings there\n * (EmDash's `EMDASH_SITE_URL`, for one).\n */\nexport function populatesProcessEnv(config: WranglerConfig): boolean {\n const flags = config.compatibility_flags ?? [];\n if (!hasNodeCompat(config)) return false;\n if (flags.includes(\"nodejs_compat_do_not_populate_process_env\")) return false;\n if (flags.includes(\"nodejs_compat_populate_process_env\")) return true;\n return (config.compatibility_date ?? \"\") >= \"2025-04-01\";\n}\n\n/** The text `vars` of a project, as `process.env` holds them. */\nexport function processEnvOf(config: WranglerConfig): Record<string, string> {\n const env: Record<string, string> = {};\n for (const [k, v] of Object.entries(config.vars ?? {})) if (typeof v === \"string\") env[k] = v;\n return env;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statewalker/cellb",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3",
|
|
4
4
|
"description": "cellb: isomorphic Durable Objects runtime (celld/Cloudflare-compatible surface) for browsers and servers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -62,29 +62,29 @@
|
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"@noble/hashes": "^2.4.0",
|
|
65
|
-
"@sqlite.org/sqlite-wasm": "^3.
|
|
66
|
-
"@statewalker/webrun-files": "^0.10.
|
|
67
|
-
"@statewalker/webrun-files-browser": "^0.10.
|
|
68
|
-
"@statewalker/webrun-files-mem": "^0.10.
|
|
65
|
+
"@sqlite.org/sqlite-wasm": "^3.54.1-build1",
|
|
66
|
+
"@statewalker/webrun-files": "^0.10.3",
|
|
67
|
+
"@statewalker/webrun-files-browser": "^0.10.2",
|
|
68
|
+
"@statewalker/webrun-files-mem": "^0.10.3",
|
|
69
69
|
"@statewalker/webrun-files-node": "^0.10.3",
|
|
70
|
-
"@statewalker/webrun-http-browser": "^0.12.
|
|
71
|
-
"@statewalker/webrun-http-streams": "^0.4.
|
|
72
|
-
"@statewalker/webrun-rpc": "^0.10.
|
|
70
|
+
"@statewalker/webrun-http-browser": "^0.12.5",
|
|
71
|
+
"@statewalker/webrun-http-streams": "^0.4.2",
|
|
72
|
+
"@statewalker/webrun-rpc": "^0.10.2",
|
|
73
73
|
"@statewalker/webrun-streams": "^0.2.3",
|
|
74
74
|
"acorn": "^8.19.0",
|
|
75
75
|
"assert": "^2.1.0",
|
|
76
76
|
"buffer": "^6.0.3",
|
|
77
77
|
"events": "^3.3.0",
|
|
78
78
|
"path-browserify": "^1.0.1",
|
|
79
|
-
"sqlite-vec": "^0.1.
|
|
79
|
+
"sqlite-vec": "^0.1.9",
|
|
80
80
|
"util": "^0.12.5",
|
|
81
|
-
"worker-timers": "^8.0.
|
|
82
|
-
"ws": "^8.22.
|
|
81
|
+
"worker-timers": "^8.0.34",
|
|
82
|
+
"ws": "^8.22.2"
|
|
83
83
|
},
|
|
84
84
|
"peerDependencies": {
|
|
85
85
|
"@statewalker/webrun-bundler": "^0.1.1",
|
|
86
|
-
"@statewalker/webrun-modules": "^0.3.
|
|
87
|
-
"@statewalker/webrun-site-builder": "^0.2.
|
|
86
|
+
"@statewalker/webrun-modules": "^0.3.6",
|
|
87
|
+
"@statewalker/webrun-site-builder": "^0.2.2",
|
|
88
88
|
"@statewalker/webrun-site-host": "^0.3.0",
|
|
89
89
|
"esbuild": ">=0.25"
|
|
90
90
|
},
|
|
@@ -106,15 +106,15 @@
|
|
|
106
106
|
}
|
|
107
107
|
},
|
|
108
108
|
"devDependencies": {
|
|
109
|
-
"@playwright/test": "^1.
|
|
109
|
+
"@playwright/test": "^1.65.0",
|
|
110
110
|
"@sparticuz/chromium": "^153.0.0",
|
|
111
111
|
"@statewalker/webrun-bundler": "^0.1.1",
|
|
112
|
-
"@statewalker/webrun-modules": "^0.3.
|
|
113
|
-
"@statewalker/webrun-site-builder": "^0.2.
|
|
112
|
+
"@statewalker/webrun-modules": "^0.3.6",
|
|
113
|
+
"@statewalker/webrun-site-builder": "^0.2.2",
|
|
114
114
|
"@statewalker/webrun-site-host": "^0.3.0",
|
|
115
|
-
"@types/node": "^26.6.
|
|
115
|
+
"@types/node": "^26.6.6",
|
|
116
116
|
"@types/ws": "^8.18.2",
|
|
117
|
-
"esbuild": "^0.28.
|
|
117
|
+
"esbuild": "^0.28.2",
|
|
118
118
|
"esbuild-wasm": "0.28.2",
|
|
119
119
|
"html-rewriter-wasm": "^0.4.1",
|
|
120
120
|
"miniflare": "4.20260730.0",
|
|
@@ -122,8 +122,8 @@
|
|
|
122
122
|
"partywhen": "0.1.5",
|
|
123
123
|
"sqlite-vec-wasm-demo": "0.1.6",
|
|
124
124
|
"typescript": "^7.0.2",
|
|
125
|
-
"vite": "^8.3.
|
|
126
|
-
"vitest": "^5.0
|
|
125
|
+
"vite": "^8.3.8",
|
|
126
|
+
"vitest": "^5.1.0",
|
|
127
127
|
"zod": "^3.25.0"
|
|
128
128
|
},
|
|
129
129
|
"scripts": {
|