@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.
Files changed (365) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +323 -2
  3. package/dist/adapters/files-backup.d.ts +16 -0
  4. package/dist/adapters/files-backup.js +32 -0
  5. package/dist/adapters/files-backup.js.map +1 -0
  6. package/dist/adapters/files-changelog.d.ts +33 -0
  7. package/dist/adapters/files-changelog.js +96 -0
  8. package/dist/adapters/files-changelog.js.map +1 -0
  9. package/dist/adapters/files-ltx.d.ts +35 -0
  10. package/dist/adapters/files-ltx.js +9 -0
  11. package/dist/adapters/files-ltx.js.map +1 -0
  12. package/dist/adapters/ltx-vfs.d.ts +21 -0
  13. package/dist/adapters/ltx-vfs.js +286 -0
  14. package/dist/adapters/ltx-vfs.js.map +1 -0
  15. package/dist/adapters/node-sqlite.d.ts +45 -0
  16. package/dist/adapters/node-sqlite.js +254 -0
  17. package/dist/adapters/node-sqlite.js.map +1 -0
  18. package/dist/adapters/wasm-page-hook.d.ts +26 -0
  19. package/dist/adapters/wasm-page-hook.js +55 -0
  20. package/dist/adapters/wasm-page-hook.js.map +1 -0
  21. package/dist/adapters/wasm-session.d.ts +11 -0
  22. package/dist/adapters/wasm-session.js +76 -0
  23. package/dist/adapters/wasm-session.js.map +1 -0
  24. package/dist/adapters/wasm-sqlite.d.ts +89 -0
  25. package/dist/adapters/wasm-sqlite.js +258 -0
  26. package/dist/adapters/wasm-sqlite.js.map +1 -0
  27. package/dist/bindings/assets.d.ts +26 -0
  28. package/dist/bindings/assets.js +260 -0
  29. package/dist/bindings/assets.js.map +1 -0
  30. package/dist/bindings/cache.d.ts +16 -0
  31. package/dist/bindings/cache.js +34 -0
  32. package/dist/bindings/cache.js.map +1 -0
  33. package/dist/bindings/celld-kv.d.ts +26 -0
  34. package/dist/bindings/celld-kv.js +81 -0
  35. package/dist/bindings/celld-kv.js.map +1 -0
  36. package/dist/bindings/celld-queues.d.ts +56 -0
  37. package/dist/bindings/celld-queues.js +223 -0
  38. package/dist/bindings/celld-queues.js.map +1 -0
  39. package/dist/bindings/celld-workflows.d.ts +22 -0
  40. package/dist/bindings/celld-workflows.js +54 -0
  41. package/dist/bindings/celld-workflows.js.map +1 -0
  42. package/dist/bindings/cron.d.ts +27 -0
  43. package/dist/bindings/cron.js +232 -0
  44. package/dist/bindings/cron.js.map +1 -0
  45. package/dist/bindings/d1-migrations.d.ts +22 -0
  46. package/dist/bindings/d1-migrations.js +32 -0
  47. package/dist/bindings/d1-migrations.js.map +1 -0
  48. package/dist/bindings/html-rewriter.d.ts +8 -0
  49. package/dist/bindings/html-rewriter.js +75 -0
  50. package/dist/bindings/html-rewriter.js.map +1 -0
  51. package/dist/bindings/r2-celld.d.ts +3 -0
  52. package/dist/bindings/r2-celld.js +113 -0
  53. package/dist/bindings/r2-celld.js.map +1 -0
  54. package/dist/bindings/r2.d.ts +236 -0
  55. package/dist/bindings/r2.js +419 -0
  56. package/dist/bindings/r2.js.map +1 -0
  57. package/dist/bindings/worker-loader.d.ts +83 -0
  58. package/dist/bindings/worker-loader.js +183 -0
  59. package/dist/bindings/worker-loader.js.map +1 -0
  60. package/dist/bindings/workers-ai.d.ts +39 -0
  61. package/dist/bindings/workers-ai.js +175 -0
  62. package/dist/bindings/workers-ai.js.map +1 -0
  63. package/dist/browser.d.ts +7 -0
  64. package/dist/browser.js +8 -0
  65. package/dist/browser.js.map +1 -0
  66. package/dist/bucket/celld-cells.d.ts +86 -0
  67. package/dist/bucket/celld-cells.js +273 -0
  68. package/dist/bucket/celld-cells.js.map +1 -0
  69. package/dist/bucket/celld-format.d.ts +10 -0
  70. package/dist/bucket/celld-format.js +27 -0
  71. package/dist/bucket/celld-format.js.map +1 -0
  72. package/dist/bucket/idb-object-store.d.ts +9 -0
  73. package/dist/bucket/idb-object-store.js +73 -0
  74. package/dist/bucket/idb-object-store.js.map +1 -0
  75. package/dist/bucket/ltx-log.d.ts +34 -0
  76. package/dist/bucket/ltx-log.js +289 -0
  77. package/dist/bucket/ltx-log.js.map +1 -0
  78. package/dist/bucket/object-store.d.ts +51 -0
  79. package/dist/bucket/object-store.js +114 -0
  80. package/dist/bucket/object-store.js.map +1 -0
  81. package/dist/bucket/s3-object-store.d.ts +25 -0
  82. package/dist/bucket/s3-object-store.js +151 -0
  83. package/dist/bucket/s3-object-store.js.map +1 -0
  84. package/dist/bucket/sqlite-object-store.d.ts +10 -0
  85. package/dist/bucket/sqlite-object-store.js +107 -0
  86. package/dist/bucket/sqlite-object-store.js.map +1 -0
  87. package/dist/core/alarms.d.ts +27 -0
  88. package/dist/core/alarms.js +88 -0
  89. package/dist/core/alarms.js.map +1 -0
  90. package/dist/core/async-context.d.ts +34 -0
  91. package/dist/core/async-context.js +50 -0
  92. package/dist/core/async-context.js.map +1 -0
  93. package/dist/core/celld-schema.d.ts +14 -0
  94. package/dist/core/celld-schema.js +34 -0
  95. package/dist/core/celld-schema.js.map +1 -0
  96. package/dist/core/durable-object.d.ts +28 -0
  97. package/dist/core/durable-object.js +31 -0
  98. package/dist/core/durable-object.js.map +1 -0
  99. package/dist/core/gates.d.ts +33 -0
  100. package/dist/core/gates.js +89 -0
  101. package/dist/core/gates.js.map +1 -0
  102. package/dist/core/handles.d.ts +90 -0
  103. package/dist/core/handles.js +224 -0
  104. package/dist/core/handles.js.map +1 -0
  105. package/dist/core/id.d.ts +19 -0
  106. package/dist/core/id.js +64 -0
  107. package/dist/core/id.js.map +1 -0
  108. package/dist/core/namespace.d.ts +38 -0
  109. package/dist/core/namespace.js +141 -0
  110. package/dist/core/namespace.js.map +1 -0
  111. package/dist/core/object-host.d.ts +91 -0
  112. package/dist/core/object-host.js +616 -0
  113. package/dist/core/object-host.js.map +1 -0
  114. package/dist/core/request-body.d.ts +9 -0
  115. package/dist/core/request-body.js +55 -0
  116. package/dist/core/request-body.js.map +1 -0
  117. package/dist/core/runtime.d.ts +121 -0
  118. package/dist/core/runtime.js +366 -0
  119. package/dist/core/runtime.js.map +1 -0
  120. package/dist/core/shard.d.ts +7 -0
  121. package/dist/core/shard.js +10 -0
  122. package/dist/core/shard.js.map +1 -0
  123. package/dist/core/sql-split.d.ts +15 -0
  124. package/dist/core/sql-split.js +101 -0
  125. package/dist/core/sql-split.js.map +1 -0
  126. package/dist/core/sql-storage.d.ts +53 -0
  127. package/dist/core/sql-storage.js +407 -0
  128. package/dist/core/sql-storage.js.map +1 -0
  129. package/dist/core/state.d.ts +44 -0
  130. package/dist/core/state.js +93 -0
  131. package/dist/core/state.js.map +1 -0
  132. package/dist/core/storage.d.ts +103 -0
  133. package/dist/core/storage.js +351 -0
  134. package/dist/core/storage.js.map +1 -0
  135. package/dist/core/worker-rejections.d.ts +21 -0
  136. package/dist/core/worker-rejections.js +55 -0
  137. package/dist/core/worker-rejections.js.map +1 -0
  138. package/dist/index.d.ts +22 -0
  139. package/dist/index.js +23 -0
  140. package/dist/index.js.map +1 -0
  141. package/dist/isolate/browser.d.ts +16 -0
  142. package/dist/isolate/browser.js +37 -0
  143. package/dist/isolate/browser.js.map +1 -0
  144. package/dist/isolate/host.d.ts +24 -0
  145. package/dist/isolate/host.js +74 -0
  146. package/dist/isolate/host.js.map +1 -0
  147. package/dist/isolate/isolate-worker.d.ts +1 -0
  148. package/dist/isolate/isolate-worker.js +53 -0
  149. package/dist/isolate/isolate-worker.js.map +1 -0
  150. package/dist/isolate/isolate.d.ts +10 -0
  151. package/dist/isolate/isolate.js +169 -0
  152. package/dist/isolate/isolate.js.map +1 -0
  153. package/dist/isolate/node-entry.d.ts +1 -0
  154. package/dist/isolate/node-entry.js +12 -0
  155. package/dist/isolate/node-entry.js.map +1 -0
  156. package/dist/isolate/protocol.d.ts +66 -0
  157. package/dist/isolate/protocol.js +205 -0
  158. package/dist/isolate/protocol.js.map +1 -0
  159. package/dist/ltx/crc64.d.ts +6 -0
  160. package/dist/ltx/crc64.js +46 -0
  161. package/dist/ltx/crc64.js.map +1 -0
  162. package/dist/ltx/ltx-page-server.d.ts +65 -0
  163. package/dist/ltx/ltx-page-server.js +309 -0
  164. package/dist/ltx/ltx-page-server.js.map +1 -0
  165. package/dist/ltx/ltx-pages.d.ts +81 -0
  166. package/dist/ltx/ltx-pages.js +315 -0
  167. package/dist/ltx/ltx-pages.js.map +1 -0
  168. package/dist/ltx/ltx-store-worker.d.ts +1 -0
  169. package/dist/ltx/ltx-store-worker.js +38 -0
  170. package/dist/ltx/ltx-store-worker.js.map +1 -0
  171. package/dist/ltx/ltx.d.ts +45 -0
  172. package/dist/ltx/ltx.js +203 -0
  173. package/dist/ltx/ltx.js.map +1 -0
  174. package/dist/ltx/lz4.d.ts +9 -0
  175. package/dist/ltx/lz4.js +156 -0
  176. package/dist/ltx/lz4.js.map +1 -0
  177. package/dist/ltx/opfs-sync-files.d.ts +23 -0
  178. package/dist/ltx/opfs-sync-files.js +191 -0
  179. package/dist/ltx/opfs-sync-files.js.map +1 -0
  180. package/dist/ltx/xxh32.d.ts +1 -0
  181. package/dist/ltx/xxh32.js +43 -0
  182. package/dist/ltx/xxh32.js.map +1 -0
  183. package/dist/miniflare-compat/blob-service.d.ts +13 -0
  184. package/dist/miniflare-compat/blob-service.js +66 -0
  185. package/dist/miniflare-compat/blob-service.js.map +1 -0
  186. package/dist/miniflare-compat/kv-binding.d.ts +44 -0
  187. package/dist/miniflare-compat/kv-binding.js +99 -0
  188. package/dist/miniflare-compat/kv-binding.js.map +1 -0
  189. package/dist/miniflare-compat/shims/assert.d.ts +15 -0
  190. package/dist/miniflare-compat/shims/assert.js +24 -0
  191. package/dist/miniflare-compat/shims/assert.js.map +1 -0
  192. package/dist/miniflare-compat/shims/workerd-cloudflare.d.ts +7 -0
  193. package/dist/miniflare-compat/shims/workerd-cloudflare.js +6 -0
  194. package/dist/miniflare-compat/shims/workerd-cloudflare.js.map +1 -0
  195. package/dist/miniflare-compat/shims/workerd-globals.d.ts +1 -0
  196. package/dist/miniflare-compat/shims/workerd-globals.js +30 -0
  197. package/dist/miniflare-compat/shims/workerd-globals.js.map +1 -0
  198. package/dist/miniflare-compat/shims/workerd-internal.d.ts +20 -0
  199. package/dist/miniflare-compat/shims/workerd-internal.js +23 -0
  200. package/dist/miniflare-compat/shims/workerd-internal.js.map +1 -0
  201. package/dist/miniflare-compat/shims/workerd-performance.d.ts +4 -0
  202. package/dist/miniflare-compat/shims/workerd-performance.js +17 -0
  203. package/dist/miniflare-compat/shims/workerd-performance.js.map +1 -0
  204. package/dist/miniflare-compat/simulator-fetcher.d.ts +9 -0
  205. package/dist/miniflare-compat/simulator-fetcher.js +14 -0
  206. package/dist/miniflare-compat/simulator-fetcher.js.map +1 -0
  207. package/dist/miniflare-compat/vendored.d.ts +15 -0
  208. package/dist/miniflare-compat/vendored.js +27 -0
  209. package/dist/miniflare-compat/vendored.js.map +1 -0
  210. package/dist/node-compat/async_hooks.d.ts +22 -0
  211. package/dist/node-compat/async_hooks.js +176 -0
  212. package/dist/node-compat/async_hooks.js.map +1 -0
  213. package/dist/node-compat/browser-registry.d.ts +3 -0
  214. package/dist/node-compat/browser-registry.js +39 -0
  215. package/dist/node-compat/browser-registry.js.map +1 -0
  216. package/dist/node-compat/crypto.d.ts +60 -0
  217. package/dist/node-compat/crypto.js +143 -0
  218. package/dist/node-compat/crypto.js.map +1 -0
  219. package/dist/node-compat/diagnostics_channel.d.ts +27 -0
  220. package/dist/node-compat/diagnostics_channel.js +46 -0
  221. package/dist/node-compat/diagnostics_channel.js.map +1 -0
  222. package/dist/node-compat/fs.d.ts +35 -0
  223. package/dist/node-compat/fs.js +40 -0
  224. package/dist/node-compat/fs.js.map +1 -0
  225. package/dist/node-compat/globals.d.ts +3 -0
  226. package/dist/node-compat/globals.js +4 -0
  227. package/dist/node-compat/globals.js.map +1 -0
  228. package/dist/node-compat/install.d.ts +5 -0
  229. package/dist/node-compat/install.js +12 -0
  230. package/dist/node-compat/install.js.map +1 -0
  231. package/dist/node-compat/module.d.ts +12 -0
  232. package/dist/node-compat/module.js +36 -0
  233. package/dist/node-compat/module.js.map +1 -0
  234. package/dist/node-compat/modules.d.ts +8 -0
  235. package/dist/node-compat/modules.js +23 -0
  236. package/dist/node-compat/modules.js.map +1 -0
  237. package/dist/node-compat/os.d.ts +36 -0
  238. package/dist/node-compat/os.js +36 -0
  239. package/dist/node-compat/os.js.map +1 -0
  240. package/dist/node-compat/process.d.ts +14 -0
  241. package/dist/node-compat/process.js +16 -0
  242. package/dist/node-compat/process.js.map +1 -0
  243. package/dist/node-compat/shims.d.ts +4 -0
  244. package/dist/node.d.ts +5 -0
  245. package/dist/node.js +6 -0
  246. package/dist/node.js.map +1 -0
  247. package/dist/peer/celld-peer.d.ts +53 -0
  248. package/dist/peer/celld-peer.js +555 -0
  249. package/dist/peer/celld-peer.js.map +1 -0
  250. package/dist/ports.d.ts +183 -0
  251. package/dist/ports.js +10 -0
  252. package/dist/ports.js.map +1 -0
  253. package/dist/project/browser-bundle.d.ts +17 -0
  254. package/dist/project/browser-bundle.js +125 -0
  255. package/dist/project/browser-bundle.js.map +1 -0
  256. package/dist/project/browser-cookies.d.ts +12 -0
  257. package/dist/project/browser-cookies.js +90 -0
  258. package/dist/project/browser-cookies.js.map +1 -0
  259. package/dist/project/browser-host.d.ts +173 -0
  260. package/dist/project/browser-host.js +200 -0
  261. package/dist/project/browser-host.js.map +1 -0
  262. package/dist/project/browser-modules.d.ts +17 -0
  263. package/dist/project/browser-modules.js +89 -0
  264. package/dist/project/browser-modules.js.map +1 -0
  265. package/dist/project/browser-shards.d.ts +62 -0
  266. package/dist/project/browser-shards.js +210 -0
  267. package/dist/project/browser-shards.js.map +1 -0
  268. package/dist/project/browser-tabs.d.ts +103 -0
  269. package/dist/project/browser-tabs.js +418 -0
  270. package/dist/project/browser-tabs.js.map +1 -0
  271. package/dist/project/cloudflare-email.d.ts +8 -0
  272. package/dist/project/cloudflare-email.js +11 -0
  273. package/dist/project/cloudflare-email.js.map +1 -0
  274. package/dist/project/cloudflare-workers.d.ts +12 -0
  275. package/dist/project/cloudflare-workers.js +16 -0
  276. package/dist/project/cloudflare-workers.js.map +1 -0
  277. package/dist/project/host-modules.d.ts +4 -0
  278. package/dist/project/host-modules.js +40 -0
  279. package/dist/project/host-modules.js.map +1 -0
  280. package/dist/project/jsonc.d.ts +2 -0
  281. package/dist/project/jsonc.js +27 -0
  282. package/dist/project/jsonc.js.map +1 -0
  283. package/dist/project/lower-await.d.ts +2 -0
  284. package/dist/project/lower-await.js +151 -0
  285. package/dist/project/lower-await.js.map +1 -0
  286. package/dist/project/node-project.d.ts +38 -0
  287. package/dist/project/node-project.js +373 -0
  288. package/dist/project/node-project.js.map +1 -0
  289. package/dist/project/own-module.d.ts +6 -0
  290. package/dist/project/own-module.js +13 -0
  291. package/dist/project/own-module.js.map +1 -0
  292. package/dist/project/scheduler.d.ts +2 -0
  293. package/dist/project/scheduler.js +3 -0
  294. package/dist/project/scheduler.js.map +1 -0
  295. package/dist/project/site.d.ts +74 -0
  296. package/dist/project/site.js +206 -0
  297. package/dist/project/site.js.map +1 -0
  298. package/dist/project/virtual-modules.d.ts +3 -0
  299. package/dist/project/worker-scope.d.ts +27 -0
  300. package/dist/project/worker-scope.js +46 -0
  301. package/dist/project/worker-scope.js.map +1 -0
  302. package/dist/project/workerd-message-channel.d.ts +13 -0
  303. package/dist/project/workerd-message-channel.js +137 -0
  304. package/dist/project/workerd-message-channel.js.map +1 -0
  305. package/dist/project/workers-global-names.d.ts +6 -0
  306. package/dist/project/workers-global-names.js +15 -0
  307. package/dist/project/workers-global-names.js.map +1 -0
  308. package/dist/project/workers-globals-module.d.ts +8 -0
  309. package/dist/project/workers-globals-module.js +9 -0
  310. package/dist/project/workers-globals-module.js.map +1 -0
  311. package/dist/project/workers-globals.d.ts +9 -0
  312. package/dist/project/workers-globals.js +19 -0
  313. package/dist/project/workers-globals.js.map +1 -0
  314. package/dist/project/wrangler.d.ts +116 -0
  315. package/dist/project/wrangler.js +342 -0
  316. package/dist/project/wrangler.js.map +1 -0
  317. package/dist/router/cell-router.d.ts +72 -0
  318. package/dist/router/cell-router.js +247 -0
  319. package/dist/router/cell-router.js.map +1 -0
  320. package/dist/router/shard-worker.d.ts +44 -0
  321. package/dist/router/shard-worker.js +163 -0
  322. package/dist/router/shard-worker.js.map +1 -0
  323. package/dist/transport/cells-http.d.ts +25 -0
  324. package/dist/transport/cells-http.js +141 -0
  325. package/dist/transport/cells-http.js.map +1 -0
  326. package/dist/transport/cells-link.d.ts +27 -0
  327. package/dist/transport/cells-link.js +71 -0
  328. package/dist/transport/cells-link.js.map +1 -0
  329. package/dist/transport/port.d.ts +26 -0
  330. package/dist/transport/port.js +100 -0
  331. package/dist/transport/port.js.map +1 -0
  332. package/dist/v8/codec.d.ts +6 -0
  333. package/dist/v8/codec.js +9 -0
  334. package/dist/v8/codec.js.map +1 -0
  335. package/dist/v8/serialize.d.ts +10 -0
  336. package/dist/v8/serialize.js +601 -0
  337. package/dist/v8/serialize.js.map +1 -0
  338. package/dist/ws/client.d.ts +25 -0
  339. package/dist/ws/client.js +203 -0
  340. package/dist/ws/client.js.map +1 -0
  341. package/dist/ws/control.d.ts +48 -0
  342. package/dist/ws/control.js +44 -0
  343. package/dist/ws/control.js.map +1 -0
  344. package/dist/ws/frames.d.ts +38 -0
  345. package/dist/ws/frames.js +39 -0
  346. package/dist/ws/frames.js.map +1 -0
  347. package/dist/ws/server.d.ts +99 -0
  348. package/dist/ws/server.js +295 -0
  349. package/dist/ws/server.js.map +1 -0
  350. package/dist/ws/sw-connector.d.ts +10 -0
  351. package/dist/ws/sw-connector.js +25 -0
  352. package/dist/ws/sw-connector.js.map +1 -0
  353. package/dist/ws/upgrade.d.ts +28 -0
  354. package/dist/ws/upgrade.js +75 -0
  355. package/dist/ws/upgrade.js.map +1 -0
  356. package/package.json +111 -3
  357. package/vendor/celld/LICENSE +202 -0
  358. package/vendor/celld/kv.js +1131 -0
  359. package/vendor/celld/queues.js +1656 -0
  360. package/vendor/celld/workflows.js +1610 -0
  361. package/vendor/html-rewriter-wasm/html_rewriter.js +925 -0
  362. package/vendor/html-rewriter-wasm/html_rewriter_bg.wasm +0 -0
  363. package/vendor/miniflare/d1-api.js +738 -0
  364. package/vendor/miniflare/d1-database.js +6978 -0
  365. package/vendor/miniflare/kv-namespace.js +3061 -0
@@ -0,0 +1,27 @@
1
+ /** Parses JSONC (wrangler.jsonc): `//` and block comments, trailing commas. */
2
+ export function parseJsonc(text) {
3
+ let out = "";
4
+ for (let i = 0; i < text.length; i++) {
5
+ const c = text[i];
6
+ if (c === '"') {
7
+ let j = i + 1;
8
+ while (j < text.length && text[j] !== '"')
9
+ j += text[j] === "\\" ? 2 : 1;
10
+ out += text.slice(i, j + 1);
11
+ i = j;
12
+ }
13
+ else if (c === "/" && text[i + 1] === "/") {
14
+ while (i < text.length && text[i] !== "\n")
15
+ i++;
16
+ out += "\n";
17
+ }
18
+ else if (c === "/" && text[i + 1] === "*") {
19
+ const end = text.indexOf("*/", i + 2);
20
+ i = end < 0 ? text.length : end + 1;
21
+ }
22
+ else
23
+ out += c;
24
+ }
25
+ return JSON.parse(out.replace(/,(\s*[}\]])/g, "$1"));
26
+ }
27
+ //# sourceMappingURL=jsonc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonc.js","sourceRoot":"","sources":["../../src/project/jsonc.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;YACd,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACd,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG;gBAAE,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACzE,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;YAC5B,CAAC,GAAG,CAAC,CAAC;QACR,CAAC;aAAM,IAAI,CAAC,KAAK,GAAG,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;YAC5C,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI;gBAAE,CAAC,EAAE,CAAC;YAChD,GAAG,IAAI,IAAI,CAAC;QACd,CAAC;aAAM,IAAI,CAAC,KAAK,GAAG,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;YAC5C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;YACtC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;QACtC,CAAC;;YAAM,GAAG,IAAI,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC,CAAC;AACvD,CAAC","sourcesContent":["/** Parses JSONC (wrangler.jsonc): `//` and block comments, trailing commas. */\nexport function parseJsonc(text: string): unknown {\n let out = \"\";\n for (let i = 0; i < text.length; i++) {\n const c = text[i];\n if (c === '\"') {\n let j = i + 1;\n while (j < text.length && text[j] !== '\"') j += text[j] === \"\\\\\" ? 2 : 1;\n out += text.slice(i, j + 1);\n i = j;\n } else if (c === \"/\" && text[i + 1] === \"/\") {\n while (i < text.length && text[i] !== \"\\n\") i++;\n out += \"\\n\";\n } else if (c === \"/\" && text[i + 1] === \"*\") {\n const end = text.indexOf(\"*/\", i + 2);\n i = end < 0 ? text.length : end + 1;\n } else out += c;\n }\n return JSON.parse(out.replace(/,(\\s*[}\\]])/g, \"$1\"));\n}\n"]}
@@ -0,0 +1,2 @@
1
+ /** `code` with its async functions lowered; `code` itself when it has none or does not parse. */
2
+ export declare function lowerAwait(code: string): string;
@@ -0,0 +1,151 @@
1
+ /**
2
+ * `async`/`await` lowered to generators, for the modules an in-browser site serves (what
3
+ * esbuild's `supported: { "async-await": false }` does for `bundleWorkerForBrowser`): each `await`
4
+ * then resumes through `Promise.prototype.then`, which cellb's `node:async_hooks` polyfill makes
5
+ * carry the AsyncLocalStorage stores (see `installAsyncContext`).
6
+ *
7
+ * async function f(a) { BODY } → function f(a) { return __cellbAsync(function* () { BODY }.apply(this, arguments)); }
8
+ * async (a) => EXPR → (a) => __cellbAsync(function* () { return EXPR; }.call(this))
9
+ * await X → (yield X)
10
+ * for await (L of R) BODY → a loop over `yield it.next()`, closing the iterator on exit
11
+ *
12
+ * Left as they are: async generators (their awaits stay native, as their bodies), functions that
13
+ * use `super` or `new.target` (a generator nested in them cannot), and top-level await. Their
14
+ * awaits resume in the polyfill's root frame: they see no store rather than another event's.
15
+ */
16
+ import { parse } from "acorn";
17
+ const ASYNC_RUNNER = 'function __cellbAsync(g){return new Promise(function(res,rej){function step(m,v){var r;try{r=g[m](v)}catch(e){rej(e);return}if(r.done)res(r.value);else Promise.resolve(r.value).then(function(x){step("next",x)},function(e){step("throw",e)})}step("next")})}';
18
+ const ASYNC_ITERATOR = "function __cellbIter(o){var m=o[Symbol.asyncIterator];if(m)return m.call(o);var it=o[Symbol.iterator](),w=function(r){return Promise.resolve(r.value).then(function(x){return{value:x,done:r.done}})};return{next:function(v){return w(it.next(v))},return:it.return&&function(v){return w(it.return(v))}}}";
19
+ const isFunction = (n) => n.type === "FunctionDeclaration" ||
20
+ n.type === "FunctionExpression" ||
21
+ n.type === "ArrowFunctionExpression";
22
+ function childrenOf(node) {
23
+ const out = [];
24
+ for (const key in node) {
25
+ if (key === "type" || key === "start" || key === "end" || key === "loc" || key === "range")
26
+ continue;
27
+ const v = node[key];
28
+ if (Array.isArray(v)) {
29
+ for (const c of v)
30
+ if (c && typeof c.type === "string")
31
+ out.push(c);
32
+ }
33
+ else if (v && typeof v.type === "string")
34
+ out.push(v);
35
+ }
36
+ return out.sort((a, b) => a.start - b.start);
37
+ }
38
+ /** `super` or `new.target` in `fn`'s own body (not in the functions it declares). */
39
+ function usesSuperOrNewTarget(fn) {
40
+ let found = false;
41
+ const visit = (n) => {
42
+ if (found)
43
+ return;
44
+ if (n.type === "Super" || n.type === "MetaProperty") {
45
+ found = true;
46
+ return;
47
+ }
48
+ for (const c of childrenOf(n))
49
+ if (!(isFunction(c) && c.type !== "ArrowFunctionExpression") && c.type !== "ClassBody")
50
+ visit(c);
51
+ };
52
+ visit(fn.body);
53
+ return found;
54
+ }
55
+ const lowered = (n) => isFunction(n) && n.async && !n.generator && !usesSuperOrNewTarget(n);
56
+ /** `code` with its async functions lowered; `code` itself when it has none or does not parse. */
57
+ export function lowerAwait(code) {
58
+ if (!/\basync\b/.test(code))
59
+ return code;
60
+ let program;
61
+ try {
62
+ program = parse(code, {
63
+ ecmaVersion: "latest",
64
+ sourceType: "module",
65
+ allowHashBang: true,
66
+ });
67
+ }
68
+ catch {
69
+ return code;
70
+ }
71
+ let changed = false;
72
+ let iterUsed = false;
73
+ let temp = 0;
74
+ // `inLowered`: whether `await` here belongs to a function being lowered.
75
+ const render = (node, inLowered) => {
76
+ if (isFunction(node))
77
+ return renderFunction(node);
78
+ if (inLowered && node.type === "AwaitExpression")
79
+ return `(yield ${render(node.argument, inLowered)})`;
80
+ if (inLowered && node.type === "ForOfStatement" && node.await)
81
+ return renderForAwait(node, "", inLowered);
82
+ if (inLowered && node.type === "LabeledStatement") {
83
+ let labels = "";
84
+ let body = node;
85
+ while (body.type === "LabeledStatement") {
86
+ labels += `${body.label.name}: `;
87
+ body = body.body;
88
+ }
89
+ if (body.type === "ForOfStatement" && body.await)
90
+ return renderForAwait(body, labels, inLowered);
91
+ }
92
+ let text = generic(node, inLowered);
93
+ // `async` of a lowered method sits before its key (`static async [k]() {}`).
94
+ if ((node.type === "MethodDefinition" || (node.type === "Property" && node.method)) &&
95
+ lowered(node.value)) {
96
+ const head = node.key.start - node.start - (node.computed ? 1 : 0);
97
+ const prefix = text.slice(0, head).replace(/\basync\b\s*/, "");
98
+ text = prefix + text.slice(head);
99
+ }
100
+ return text;
101
+ };
102
+ const generic = (node, inLowered, wrap) => {
103
+ let out = "";
104
+ let at = node.start;
105
+ for (const c of childrenOf(node)) {
106
+ if (c.start < at)
107
+ continue; // the same node twice (a shorthand property's key and value)
108
+ out += code.slice(at, c.start);
109
+ const text = render(c, inLowered);
110
+ out += wrap ? wrap(c, text) : text;
111
+ at = c.end;
112
+ }
113
+ return out + code.slice(at, node.end);
114
+ };
115
+ const renderFunction = (fn) => {
116
+ if (!lowered(fn))
117
+ return generic(fn, false);
118
+ changed = true;
119
+ const arrow = fn.type === "ArrowFunctionExpression";
120
+ const text = generic(fn, true, (child, body) => {
121
+ if (child !== fn.body)
122
+ return body;
123
+ // An arrow's `arguments` is its enclosing function's: pass them on only when it reads them
124
+ // (a module has none).
125
+ const call = !arrow || /\barguments\b/.test(body) ? ".apply(this, arguments)" : ".call(this)";
126
+ if (fn.expression)
127
+ return `__cellbAsync(function* () { return ${body}; }${call})`;
128
+ return `{ return __cellbAsync(function* () ${body}${call}); }`;
129
+ });
130
+ return text.replace(/^async\b\s*/, "");
131
+ };
132
+ const renderForAwait = (loop, labels, inLowered) => {
133
+ iterUsed = true;
134
+ const n = temp++;
135
+ const it = `__cellbIt${n}`;
136
+ const step = `__cellbStep${n}`;
137
+ const left = render(loop.left, inLowered);
138
+ const assign = loop.left.type === "VariableDeclaration"
139
+ ? `${left} = ${step}.value;`
140
+ : `(${left} = ${step}.value);`;
141
+ return (`{ const ${it} = __cellbIter(${render(loop.right, inLowered)}); let ${step}; ` +
142
+ `try { ${labels}for (;;) { ${step} = undefined; ${step} = yield ${it}.next(); ` +
143
+ `if (${step}.done) break; { ${assign} ${render(loop.body, inLowered)} } } } ` +
144
+ `finally { if (${step} && !${step}.done && ${it}.return) yield ${it}.return(); } }`);
145
+ };
146
+ const out = render(program, false);
147
+ if (!changed)
148
+ return code;
149
+ return `${out}\n${ASYNC_RUNNER}\n${iterUsed ? `${ASYNC_ITERATOR}\n` : ""}`;
150
+ }
151
+ //# sourceMappingURL=lower-await.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lower-await.js","sourceRoot":"","sources":["../../src/project/lower-await.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAa,KAAK,EAAE,MAAM,OAAO,CAAC;AAKzC,MAAM,YAAY,GAChB,iQAAiQ,CAAC;AACpQ,MAAM,cAAc,GAClB,6SAA6S,CAAC;AAEhT,MAAM,UAAU,GAAG,CAAC,CAAU,EAAE,EAAE,CAChC,CAAC,CAAC,IAAI,KAAK,qBAAqB;IAChC,CAAC,CAAC,IAAI,KAAK,oBAAoB;IAC/B,CAAC,CAAC,IAAI,KAAK,yBAAyB,CAAC;AAEvC,SAAS,UAAU,CAAC,IAAa;IAC/B,MAAM,GAAG,GAAc,EAAE,CAAC;IAC1B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,OAAO,IAAI,GAAG,KAAK,KAAK,IAAI,GAAG,KAAK,KAAK,IAAI,GAAG,KAAK,OAAO;YACxF,SAAS;QACX,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;QACpB,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;YACrB,KAAK,MAAM,CAAC,IAAI,CAAC;gBAAE,IAAI,CAAC,IAAI,OAAO,C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,CAAC;QAC3B,MAAM,IAAI,GAAG,cAAc,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAC1C,MAAM,MAAM,GACV,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,qBAAqB;YACtC,CAAC,CAAC,GAAG,IAAI,MAAM,IAAI,SAAS;YAC5B,CAAC,CAAC,IAAI,IAAI,MAAM,IAAI,UAAU,CAAC;QACnC,OAAO,CACL,WAAW,EAAE,kBAAkB,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,CAAC,UAAU,IAAI,IAAI;YAC9E,SAAS,MAAM,cAAc,IAAI,iBAAiB,IAAI,YAAY,EAAE,WAAW;YAC/E,OAAO,IAAI,mBAAmB,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS;YAC7E,iBAAiB,IAAI,QAAQ,IAAI,YAAY,EAAE,kBAAkB,EAAE,gBAAgB,CACpF,CAAC;IACJ,CAAC,CAAC;IAEF,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACnC,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;IAC1B,OAAO,GAAG,GAAG,KAAK,YAAY,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,cAAc,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AAC7E,CAAC","sourcesContent":["/**\n * `async`/`await` lowered to generators, for the modules an in-browser site serves (what\n * esbuild's `supported: { \"async-await\": false }` does for `bundleWorkerForBrowser`): each `await`\n * then resumes through `Promise.prototype.then`, which cellb's `node:async_hooks` polyfill makes\n * carry the AsyncLocalStorage stores (see `installAsyncContext`).\n *\n * async function f(a) { BODY } → function f(a) { return __cellbAsync(function* () { BODY }.apply(this, arguments)); }\n * async (a) => EXPR → (a) => __cellbAsync(function* () { return EXPR; }.call(this))\n * await X → (yield X)\n * for await (L of R) BODY → a loop over `yield it.next()`, closing the iterator on exit\n *\n * Left as they are: async generators (their awaits stay native, as their bodies), functions that\n * use `super` or `new.target` (a generator nested in them cannot), and top-level await. Their\n * awaits resume in the polyfill's root frame: they see no store rather than another event's.\n */\nimport { type Node, parse } from \"acorn\";\n\n// biome-ignore lint/suspicious/noExplicitAny: walking acorn's ESTree nodes by their properties\ntype AnyNode = Node & Record<string, any>;\n\nconst ASYNC_RUNNER =\n 'function __cellbAsync(g){return new Promise(function(res,rej){function step(m,v){var r;try{r=g[m](v)}catch(e){rej(e);return}if(r.done)res(r.value);else Promise.resolve(r.value).then(function(x){step(\"next\",x)},function(e){step(\"throw\",e)})}step(\"next\")})}';\nconst ASYNC_ITERATOR =\n \"function __cellbIter(o){var m=o[Symbol.asyncIterator];if(m)return m.call(o);var it=o[Symbol.iterator](),w=function(r){return Promise.resolve(r.value).then(function(x){return{value:x,done:r.done}})};return{next:function(v){return w(it.next(v))},return:it.return&&function(v){return w(it.return(v))}}}\";\n\nconst isFunction = (n: AnyNode) =>\n n.type === \"FunctionDeclaration\" ||\n n.type === \"FunctionExpression\" ||\n n.type === \"ArrowFunctionExpression\";\n\nfunction childrenOf(node: AnyNode): AnyNode[] {\n const out: AnyNode[] = [];\n for (const key in node) {\n if (key === \"type\" || key === \"start\" || key === \"end\" || key === \"loc\" || key === \"range\")\n continue;\n const v = node[key];\n if (Array.isArray(v)) {\n for (const c of v) if (c && typeof c.type === \"string\") out.push(c);\n } else if (v && typeof v.type === \"string\") out.push(v);\n }\n return out.sort((a, b) => a.start - b.start);\n}\n\n/** `super` or `new.target` in `fn`'s own body (not in the functions it declares). */\nfunction usesSuperOrNewTarget(fn: AnyNode): boolean {\n let found = false;\n const visit = (n: AnyNode) => {\n if (found) return;\n if (n.type === \"Super\" || n.type === \"MetaProperty\") {\n found = true;\n return;\n }\n for (const c of childrenOf(n))\n if (!(isFunction(c) && c.type !== \"ArrowFunctionExpression\") && c.type !== \"ClassBody\")\n visit(c);\n };\n visit(fn.body);\n return found;\n}\n\nconst lowered = (n: AnyNode) =>\n isFunction(n) && n.async && !n.generator && !usesSuperOrNewTarget(n);\n\n/** `code` with its async functions lowered; `code` itself when it has none or does not parse. */\nexport function lowerAwait(code: string): string {\n if (!/\\basync\\b/.test(code)) return code;\n let program: AnyNode;\n try {\n program = parse(code, {\n ecmaVersion: \"latest\",\n sourceType: \"module\",\n allowHashBang: true,\n }) as AnyNode;\n } catch {\n return code;\n }\n let changed = false;\n let iterUsed = false;\n let temp = 0;\n\n // `inLowered`: whether `await` here belongs to a function being lowered.\n const render = (node: AnyNode, inLowered: boolean): string => {\n if (isFunction(node)) return renderFunction(node);\n if (inLowered && node.type === \"AwaitExpression\")\n return `(yield ${render(node.argument, inLowered)})`;\n if (inLowered && node.type === \"ForOfStatement\" && node.await)\n return renderForAwait(node, \"\", inLowered);\n if (inLowered && node.type === \"LabeledStatement\") {\n let labels = \"\";\n let body = node;\n while (body.type === \"LabeledStatement\") {\n labels += `${body.label.name}: `;\n body = body.body;\n }\n if (body.type === \"ForOfStatement\" && body.await)\n return renderForAwait(body, labels, inLowered);\n }\n let text = generic(node, inLowered);\n // `async` of a lowered method sits before its key (`static async [k]() {}`).\n if (\n (node.type === \"MethodDefinition\" || (node.type === \"Property\" && node.method)) &&\n lowered(node.value)\n ) {\n const head = node.key.start - node.start - (node.computed ? 1 : 0);\n const prefix = text.slice(0, head).replace(/\\basync\\b\\s*/, \"\");\n text = prefix + text.slice(head);\n }\n return text;\n };\n\n const generic = (\n node: AnyNode,\n inLowered: boolean,\n wrap?: (child: AnyNode, text: string) => string,\n ): string => {\n let out = \"\";\n let at = node.start;\n for (const c of childrenOf(node)) {\n if (c.start < at) continue; // the same node twice (a shorthand property's key and value)\n out += code.slice(at, c.start);\n const text = render(c, inLowered);\n out += wrap ? wrap(c, text) : text;\n at = c.end;\n }\n return out + code.slice(at, node.end);\n };\n\n const renderFunction = (fn: AnyNode): string => {\n if (!lowered(fn)) return generic(fn, false);\n changed = true;\n const arrow = fn.type === \"ArrowFunctionExpression\";\n const text = generic(fn, true, (child, body) => {\n if (child !== fn.body) return body;\n // An arrow's `arguments` is its enclosing function's: pass them on only when it reads them\n // (a module has none).\n const call = !arrow || /\\barguments\\b/.test(body) ? \".apply(this, arguments)\" : \".call(this)\";\n if (fn.expression) return `__cellbAsync(function* () { return ${body}; }${call})`;\n return `{ return __cellbAsync(function* () ${body}${call}); }`;\n });\n return text.replace(/^async\\b\\s*/, \"\");\n };\n\n const renderForAwait = (loop: AnyNode, labels: string, inLowered: boolean): string => {\n iterUsed = true;\n const n = temp++;\n const it = `__cellbIt${n}`;\n const step = `__cellbStep${n}`;\n const left = render(loop.left, inLowered);\n const assign =\n loop.left.type === \"VariableDeclaration\"\n ? `${left} = ${step}.value;`\n : `(${left} = ${step}.value);`;\n return (\n `{ const ${it} = __cellbIter(${render(loop.right, inLowered)}); let ${step}; ` +\n `try { ${labels}for (;;) { ${step} = undefined; ${step} = yield ${it}.next(); ` +\n `if (${step}.done) break; { ${assign} ${render(loop.body, inLowered)} } } } ` +\n `finally { if (${step} && !${step}.done && ${it}.return) yield ${it}.return(); } }`\n );\n };\n\n const out = render(program, false);\n if (!changed) return code;\n return `${out}\\n${ASYNC_RUNNER}\\n${iterUsed ? `${ASYNC_ITERATOR}\\n` : \"\"}`;\n}\n"]}
@@ -0,0 +1,38 @@
1
+ import { type LogSink, type ModuleLoader } from "../bindings/worker-loader.js";
2
+ import type { WorkerModule } from "../core/runtime.js";
3
+ import type { CellStorage } from "../ports.js";
4
+ import { type WorkerScope } from "./worker-scope.js";
5
+ import { type ProjectHost, type ProjectRuntime, type WranglerConfig } from "./wrangler.js";
6
+ /** Reads `wrangler.jsonc` / `wrangler.json` of a project directory (celld reads the same files). */
7
+ export declare function readWranglerConfig(dir: string): WranglerConfig;
8
+ /**
9
+ * Node host: bundles `main` with esbuild (as `celld deploy` does) and builds the runtime.
10
+ * `cloudflare:workers` resolves to cellb's module so user classes extend the
11
+ * runtime's own DurableObject / WorkerEntrypoint.
12
+ */
13
+ /** Bundles Worker code (a file, or in-memory modules) with the runtime's module mappings, then imports it. */
14
+ export declare function bundleWorker(entry: {
15
+ path: string;
16
+ } | {
17
+ modules: Record<string, string>;
18
+ main: string;
19
+ }, logs?: LogSink, outbound?: typeof fetch, opts?: {
20
+ nodeCompat?: boolean;
21
+ standardBinaryType?: boolean;
22
+ scope?: WorkerScope;
23
+ }): Promise<WorkerModule>;
24
+ /** Worker Loader on Node: compiles `WorkerCode.modules` with esbuild (as celld compiles loaded code). */
25
+ export declare const nodeModuleLoader: ModuleLoader;
26
+ export declare function loadNodeProject(dir: string, host: Omit<ProjectHost, "loadModules"> & Partial<Pick<ProjectHost, "loadModules">>): Promise<ProjectRuntime & {
27
+ config: WranglerConfig;
28
+ }>;
29
+ /** Reads an assets directory into "/path" → bytes (what `celld deploy` uploads). */
30
+ export declare function readAssetDirectory(root: string): Map<string, Uint8Array>;
31
+ /**
32
+ * `celld d1 migrations apply DATABASE` for a Node-hosted project: reads
33
+ * `migrations_dir` (default "migrations") of the `d1_databases` entry and applies what is new.
34
+ */
35
+ export declare function applyNodeD1Migrations(dir: string, runtime: {
36
+ env: Record<string, unknown>;
37
+ }, database: string): Promise<string[]>;
38
+ export declare function nodeIsolatedLoader(storage?: () => CellStorage | undefined): ModuleLoader;
@@ -0,0 +1,373 @@
1
+ import { existsSync, mkdtempSync, readdirSync, readFileSync, statSync, writeFileSync, } from "node:fs";
2
+ import { builtinModules, createRequire } from "node:module";
3
+ import { tmpdir } from "node:os";
4
+ import { join, resolve } from "node:path";
5
+ import { Worker as NodeWorker } from "node:worker_threads";
6
+ import { build } from "esbuild";
7
+ import { applyD1Migrations } from "../bindings/d1-migrations.js";
8
+ import { moduleText, outboundFetch, } from "../bindings/worker-loader.js";
9
+ import { ctxExports } from "../core/handles.js";
10
+ import { isolatedModuleLoader } from "../isolate/host.js";
11
+ import * as workersClasses from "./cloudflare-workers.js";
12
+ import { parseJsonc } from "./jsonc.js";
13
+ import { ownModule } from "./own-module.js";
14
+ import { workerScope } from "./worker-scope.js";
15
+ import { createProjectRuntime, loadTimeEnv, } from "./wrangler.js";
16
+ /** Reads `wrangler.jsonc` / `wrangler.json` of a project directory (celld reads the same files). */
17
+ export function readWranglerConfig(dir) {
18
+ for (const name of ["wrangler.jsonc", "wrangler.json"]) {
19
+ const p = join(dir, name);
20
+ if (existsSync(p))
21
+ return parseJsonc(readFileSync(p, "utf8"));
22
+ }
23
+ throw new Error(`no wrangler.jsonc or wrangler.json in ${dir}`);
24
+ }
25
+ /** A bare Node.js built-in specifier ("path", "fs/promises"), not one of a package. */
26
+ const nodeBuiltinName = new RegExp(`^(${builtinModules
27
+ .filter((m) => !m.startsWith("_") && !m.includes(":"))
28
+ .map((m) => m.replace(/[/]/g, "\\/"))
29
+ .join("|")})$`);
30
+ /**
31
+ * Node host: bundles `main` with esbuild (as `celld deploy` does) and builds the runtime.
32
+ * `cloudflare:workers` resolves to cellb's module so user classes extend the
33
+ * runtime's own DurableObject / WorkerEntrypoint.
34
+ */
35
+ /** Bundles Worker code (a file, or in-memory modules) with the runtime's module mappings, then imports it. */
36
+ export async function bundleWorker(entry, logs, outbound, opts = {}) {
37
+ // `env` and `exports` of `cloudflare:workers` belong to one Worker: the bundle reads them
38
+ // from its own scope (empty objects for code that has none).
39
+ const scopeKey = opts.scope ? `s${Math.random().toString(36).slice(2)}` : "";
40
+ if (opts.scope) {
41
+ const g = globalThis;
42
+ g.__cellsWorkerScopes ??= {};
43
+ g.__cellsWorkerScopes[scopeKey] = opts.scope;
44
+ }
45
+ // Loaded code gets a bundle-local `fetch` (globalOutbound policy)…
46
+ const outboundKey = outbound ? `o${Math.random().toString(36).slice(2)}` : "";
47
+ if (outbound) {
48
+ const g = globalThis;
49
+ g.__cellsOutbound ??= {};
50
+ g.__cellsOutbound[outboundKey] = outbound;
51
+ }
52
+ // …and a bundle-local `console` that also feeds its Tail Workers.
53
+ const consoleKey = logs ? `c${Math.random().toString(36).slice(2)}` : "";
54
+ if (logs) {
55
+ const g = globalThis;
56
+ g.__cellsConsoles ??= {};
57
+ const registry = g.__cellsConsoles;
58
+ const real = globalThis.console;
59
+ const wrap = (level) => (...args) => {
60
+ logs(level, args);
61
+ real[level](...args);
62
+ };
63
+ registry[consoleKey] = Object.assign(Object.create(real), {
64
+ log: wrap("log"),
65
+ info: wrap("info"),
66
+ warn: wrap("warn"),
67
+ error: wrap("error"),
68
+ debug: wrap("debug"),
69
+ });
70
+ }
71
+ const outDir = mkdtempSync(join(tmpdir(), "cells-worker-"));
72
+ const out = join(outDir, "worker.mjs");
73
+ const cfWorkers = ownModule(import.meta.dirname, "cloudflare-workers");
74
+ // This bundle's `cloudflare:workers`: the runtime's classes plus its own `env` and `exports`.
75
+ // A file of its own, kept out of the bundle so it adds no names to the Worker's scope.
76
+ const workersModule = join(outDir, "cloudflare-workers.mjs");
77
+ writeFileSync(workersModule, [
78
+ `export * from ${JSON.stringify(cfWorkers)};`,
79
+ `const scope = globalThis.__cellsWorkerScopes?.[${JSON.stringify(scopeKey)}];`,
80
+ "export const env = scope ? scope.env : {};",
81
+ "export const exports = scope ? scope.exports : {};",
82
+ "export const waitUntil = (p) => scope?.waitUntil(p);",
83
+ ].join("\n"));
84
+ const memory = "modules" in entry ? entry.modules : undefined;
85
+ await build({
86
+ entryPoints: [
87
+ memory ? `memory:${entry.main}` : entry.path,
88
+ ],
89
+ outfile: out,
90
+ bundle: true,
91
+ format: "esm",
92
+ platform: "neutral",
93
+ // As `celld deploy` resolves packages: workerd's conditions, then `module` and `main` (the
94
+ // neutral platform has no main fields, so a package with only `main` would not resolve).
95
+ conditions: ["workerd", "worker", "browser"],
96
+ mainFields: ["module", "main"],
97
+ target: "es2022",
98
+ logLevel: "silent",
99
+ // nodejs_compat: CommonJS dependencies `require()` Node's built-ins (mime-types requires
100
+ // node:path), as they may under workerd's nodejs_compat. In an ES module bundle esbuild's
101
+ // require shim needs a `require` in scope: vitest's module runner provides one, plain Node
102
+ // does not.
103
+ ...(opts.nodeCompat
104
+ ? {
105
+ banner: {
106
+ js: 'import { createRequire as __cellbCreateRequire } from "node:module";\nconst require = __cellbCreateRequire(import.meta.url);',
107
+ },
108
+ }
109
+ : {}),
110
+ inject: [
111
+ ownModule(import.meta.dirname, "workers-globals"),
112
+ ...(logs ? ["cellb:console"] : []),
113
+ ...(outbound ? ["cellb:fetch"] : []),
114
+ ],
115
+ plugins: [
116
+ {
117
+ name: "cells-modules",
118
+ setup(b) {
119
+ b.onResolve({ filter: /^cellb:console$/ }, () => ({
120
+ path: "console",
121
+ namespace: "cells-console",
122
+ }));
123
+ // nodejs_compat on a Node host: `node:*` are the real Node.js modules.
124
+ if (opts.nodeCompat) {
125
+ b.onResolve({ filter: /^node:/ }, (a) => ({ path: a.path, external: true }));
126
+ // workerd's nodejs_compat also takes the bare names ("path", "fs/promises").
127
+ b.onResolve({ filter: nodeBuiltinName }, (a) => ({
128
+ path: `node:${a.path}`,
129
+ external: true,
130
+ }));
131
+ }
132
+ b.onResolve({ filter: /^cellb:compat$/ }, () => ({
133
+ path: "compat",
134
+ namespace: "cells-compat",
135
+ }));
136
+ b.onLoad({ filter: /.*/, namespace: "cells-compat" }, () => ({
137
+ contents: `export const standardBinaryType = ${!!opts.standardBinaryType};`,
138
+ loader: "js",
139
+ }));
140
+ b.onResolve({ filter: /^cellb:fetch$/ }, () => ({
141
+ path: "fetch",
142
+ namespace: "cells-fetch",
143
+ }));
144
+ b.onLoad({ filter: /.*/, namespace: "cells-fetch" }, () => ({
145
+ contents: `export const fetch = globalThis.__cellsOutbound[${JSON.stringify(outboundKey)}];`,
146
+ loader: "js",
147
+ }));
148
+ b.onLoad({ filter: /.*/, namespace: "cells-console" }, () => ({
149
+ contents: `export const console = globalThis.__cellsConsoles[${JSON.stringify(consoleKey)}];`,
150
+ loader: "js",
151
+ }));
152
+ b.onResolve({ filter: /^cloudflare:workers$/ }, () => ({
153
+ path: workersModule,
154
+ external: true,
155
+ }));
156
+ b.onResolve({ filter: /^cloudflare:email$/ }, () => ({
157
+ path: ownModule(import.meta.dirname, "cloudflare-email"),
158
+ external: true,
159
+ }));
160
+ b.onResolve({ filter: /^cellb:ws$/ }, () => ({
161
+ path: ownModule(import.meta.dirname, "workers-globals-module"),
162
+ external: true,
163
+ }));
164
+ if (!memory)
165
+ return;
166
+ b.onResolve({ filter: /^memory:/ }, (a) => ({
167
+ path: a.path.slice(7),
168
+ namespace: "memory",
169
+ }));
170
+ b.onResolve({ filter: /^\.{1,2}\// }, (a) => a.namespace === "memory"
171
+ ? {
172
+ path: new URL(a.path, `file:///${a.importer}`).pathname.slice(1),
173
+ namespace: "memory",
174
+ }
175
+ : undefined);
176
+ b.onLoad({ filter: /.*/, namespace: "memory" }, (a) => ({
177
+ contents: memory[a.path],
178
+ loader: "js",
179
+ }));
180
+ },
181
+ },
182
+ ],
183
+ });
184
+ return (await import(/* @vite-ignore */ out));
185
+ }
186
+ /** Worker Loader on Node: compiles `WorkerCode.modules` with esbuild (as celld compiles loaded code). */
187
+ export const nodeModuleLoader = async (_id, code, logs) => {
188
+ const outbound = outboundFetch(code);
189
+ const modules = {};
190
+ for (const [name, m] of Object.entries(code.modules))
191
+ modules[name] = moduleText(m);
192
+ // `env` and `exports` of the loaded code's `cloudflare:workers` are its own (WorkerCode.env).
193
+ const env = code.env ?? {};
194
+ const scope = workerScope(env);
195
+ const module = (await bundleWorker({ modules, main: code.mainModule }, logs, outbound, {
196
+ scope,
197
+ }));
198
+ scope.bind({ env, exports: ctxExports(module, env) });
199
+ return module;
200
+ };
201
+ export async function loadNodeProject(dir, host) {
202
+ const config = readWranglerConfig(dir);
203
+ if (!config.main && !config.assets)
204
+ throw new Error("wrangler config has neither `main` nor `assets`");
205
+ const flags = config.compatibility_flags ?? [];
206
+ const nodeCompat = flags.some((f) => f.startsWith("nodejs_compat"));
207
+ const standardBinaryType = flags.includes("websocket_standard_binary_type");
208
+ // The module reads `env` from `cloudflare:workers` while it is evaluated, before the
209
+ // runtime exists: until then the scope holds the configuration's vars (and `ai`).
210
+ const scope = workerScope(loadTimeEnv(config, host.ai));
211
+ // A bundle built elsewhere for cellb (cellbHostModule: webrun-bundler in a browser, say) reads
212
+ // the runtime from globals, as in the browser realm: set them here too, so the same bundle
213
+ // runs on Node. (One such project per process: the globals are the process's.)
214
+ installHostModuleGlobals(scope);
215
+ // As the browser host: nodejs_compat fills process.env with the text vars (from compatibility
216
+ // date 2025-04-01). Node shares its real process with the Worker, so they land there.
217
+ if (nodeCompat &&
218
+ !flags.includes("nodejs_compat_do_not_populate_process_env") &&
219
+ (flags.includes("nodejs_compat_populate_process_env") ||
220
+ (config.compatibility_date ?? "") >= "2025-04-01"))
221
+ for (const [k, v] of Object.entries(config.vars ?? {}))
222
+ if (typeof v === "string")
223
+ process.env[k] ??= v;
224
+ const module = config.main
225
+ ? await bundleWorker({ path: resolve(dir, config.main) }, undefined, undefined, {
226
+ nodeCompat,
227
+ standardBinaryType,
228
+ scope,
229
+ })
230
+ : { default: {} };
231
+ const assetFiles = config.assets?.directory
232
+ ? readAssetDirectory(resolve(dir, config.assets.directory))
233
+ : undefined;
234
+ const project = createProjectRuntime(config, module, {
235
+ loadModules: nodeModuleLoader,
236
+ // own realm, as celld; facets logged like the root's
237
+ isolatedModules: nodeIsolatedLoader(() => host.storage),
238
+ assetFiles,
239
+ ...host,
240
+ });
241
+ scope.bind(project.runtime);
242
+ return { ...project, config };
243
+ }
244
+ /** Reads an assets directory into "/path" → bytes (what `celld deploy` uploads). */
245
+ export function readAssetDirectory(root) {
246
+ const files = new Map();
247
+ const walk = (dir, prefix) => {
248
+ for (const name of readdirSync(dir)) {
249
+ const full = join(dir, name);
250
+ if (statSync(full).isDirectory())
251
+ walk(full, `${prefix}${name}/`);
252
+ else
253
+ files.set(`${prefix}${name}`, new Uint8Array(readFileSync(full)));
254
+ }
255
+ };
256
+ walk(root, "/");
257
+ return files;
258
+ }
259
+ /**
260
+ * `celld d1 migrations apply DATABASE` for a Node-hosted project: reads
261
+ * `migrations_dir` (default "migrations") of the `d1_databases` entry and applies what is new.
262
+ */
263
+ export async function applyNodeD1Migrations(dir, runtime, database) {
264
+ const config = readWranglerConfig(dir);
265
+ const d1 = config.d1_databases?.find((d) => d.database_name === database || d.binding === database);
266
+ if (!d1)
267
+ throw new Error(`no d1_databases entry named ${database}`);
268
+ const mdir = resolve(dir, d1.migrations_dir ?? "migrations");
269
+ const files = existsSync(mdir)
270
+ ? readdirSync(mdir).map((f) => [f, readFileSync(join(mdir, f), "utf8")])
271
+ : [];
272
+ return applyD1Migrations(runtime.env[d1.binding], files, d1.migrations_table ?? "d1_migrations");
273
+ }
274
+ /**
275
+ * Loaded Workers in worker threads (one realm each), like celld's isolates. The code is
276
+ * bundled with esbuild (cloudflare:workers bundled in) and imported in the thread from a
277
+ * data: URL; Durable Object classes for facets still load in this realm.
278
+ */
279
+ let isolateEntry;
280
+ export function nodeIsolatedLoader(storage) {
281
+ return isolatedModuleLoader({
282
+ storage,
283
+ spawn: () => {
284
+ const port = new NodeWorker(new URL(`file://${isolateEntryPathSync()}`));
285
+ port.unref(); // an idle isolate never keeps the process alive
286
+ return { port: port, terminate: () => void port.terminate() };
287
+ },
288
+ prepare: async (_id, code) => {
289
+ isolateEntry ??= buildIsolateEntry();
290
+ await isolateEntry;
291
+ const modules = {};
292
+ for (const [name, m] of Object.entries(code.modules))
293
+ modules[name] = moduleText(m);
294
+ const out = await build({
295
+ entryPoints: [`memory:${code.mainModule}`],
296
+ write: false,
297
+ bundle: true,
298
+ format: "esm",
299
+ platform: "neutral",
300
+ target: "es2022",
301
+ logLevel: "silent",
302
+ plugins: [
303
+ {
304
+ name: "isolate-modules",
305
+ setup(b) {
306
+ // The loaded Worker is its thread's own: `env` and `exports` are the scope
307
+ // serveIsolate keeps for it.
308
+ b.onResolve({ filter: /^cloudflare:workers$/ }, () => ({
309
+ path: "cloudflare:workers",
310
+ namespace: "isolate-workers",
311
+ }));
312
+ b.onLoad({ filter: /.*/, namespace: "isolate-workers" }, () => ({
313
+ contents: [
314
+ 'export * from "./cloudflare-workers.ts";',
315
+ "export const env = globalThis.__cellsProjectScope.env, exports = globalThis.__cellsProjectScope.exports, waitUntil = (p) => globalThis.__cellsProjectScope.waitUntil(p);",
316
+ ].join("\n"),
317
+ loader: "js",
318
+ resolveDir: import.meta.dirname,
319
+ }));
320
+ b.onResolve({ filter: /^cloudflare:email$/ }, () => ({
321
+ path: ownModule(import.meta.dirname, "cloudflare-email"),
322
+ }));
323
+ b.onResolve({ filter: /^memory:/ }, (a) => ({
324
+ path: a.path.slice(7),
325
+ namespace: "memory",
326
+ }));
327
+ b.onResolve({ filter: /^\.{1,2}\// }, (a) => a.namespace === "memory"
328
+ ? {
329
+ path: new URL(a.path, `file:///${a.importer}`).pathname.slice(1),
330
+ namespace: "memory",
331
+ }
332
+ : undefined);
333
+ b.onLoad({ filter: /.*/, namespace: "memory" }, (a) => ({
334
+ contents: modules[a.path],
335
+ loader: "js",
336
+ }));
337
+ },
338
+ },
339
+ ],
340
+ });
341
+ return { source: out.outputFiles[0].text };
342
+ },
343
+ });
344
+ }
345
+ let isolateEntryFile = "";
346
+ function isolateEntryPathSync() {
347
+ if (!isolateEntryFile)
348
+ throw new Error("isolate entry not built yet");
349
+ return isolateEntryFile;
350
+ }
351
+ async function buildIsolateEntry() {
352
+ isolateEntryFile = join(mkdtempSync(join(tmpdir(), "cells-isolate-")), "isolate.mjs");
353
+ await build({
354
+ entryPoints: [ownModule(import.meta.dirname, "../isolate/node-entry")],
355
+ outfile: isolateEntryFile,
356
+ bundle: true,
357
+ format: "esm",
358
+ platform: "node",
359
+ target: "node22",
360
+ logLevel: "silent",
361
+ });
362
+ return isolateEntryFile;
363
+ }
364
+ /** The globals `@statewalker/cellb/host-modules` bundles read (see host-modules.ts). */
365
+ function installHostModuleGlobals(scope) {
366
+ const g = globalThis;
367
+ g.__cellsProjectScope = scope;
368
+ g.__cellsWorkersModule ??= workersClasses;
369
+ // node:* from Node itself (the browser realm gives cellb's polyfills).
370
+ g.__cellsNodeModules ??= new Proxy({}, { get: (_t, k) => (typeof k === "string" ? requireBuiltin(k) : undefined) });
371
+ }
372
+ const requireBuiltin = createRequire(import.meta.url);
373
+ //# sourceMappingURL=node-project.js.map