@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
+ // Typed entry points to the generated bundles in vendor/miniflare (scripts/vendor-miniflare.mjs).
2
+ // @ts-expect-error — generated JS, no declarations
3
+ import makeD1BindingJs from "../../vendor/miniflare/d1-api.js";
4
+ // @ts-expect-error — generated JS, no declarations
5
+ import { D1DatabaseObject as D1Js } from "../../vendor/miniflare/d1-database.js";
6
+ // @ts-expect-error — generated JS, no declarations
7
+ import { KVNamespaceObject as KVJs } from "../../vendor/miniflare/kv-namespace.js";
8
+ /** Miniflare's KV simulator object (workers-sdk, unchanged). */
9
+ export const KVNamespaceObject = KVJs;
10
+ /**
11
+ * Miniflare's D1 simulator object (workers-sdk, unchanged). It asks its storage for
12
+ * bookmarks (commit tokens of D1 sessions); celld's Durable Object storage has no bookmark
13
+ * API (calling it is a TypeError), so only the simulator's instances get these methods.
14
+ */
15
+ export const D1DatabaseObject = class CellsD1Database extends D1Js {
16
+ constructor(ctx, env) {
17
+ let n = 0;
18
+ Object.assign(ctx.storage, {
19
+ getCurrentBookmark: async () => `${Date.now().toString(16).padStart(12, "0")}-${(++n).toString(16).padStart(8, "0")}`,
20
+ getBookmarkForTime: async (time) => `${new Date(time).getTime().toString(16).padStart(12, "0")}-00000000`,
21
+ });
22
+ super(ctx, env);
23
+ }
24
+ };
25
+ /** workerd's D1 binding client (src/cloudflare/internal/d1-api.ts, unchanged). */
26
+ export const makeD1Binding = makeD1BindingJs;
27
+ //# sourceMappingURL=vendored.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vendored.js","sourceRoot":"","sources":["../../src/miniflare-compat/vendored.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAElG,mDAAmD;AACnD,OAAO,eAAe,MAAM,kCAAkC,CAAC;AAC/D,mDAAmD;AACnD,OAAO,EAAE,gBAAgB,IAAI,IAAI,EAAE,MAAM,uCAAuC,CAAC;AACjF,mDAAmD;AACnD,OAAO,EAAE,iBAAiB,IAAI,IAAI,EAAE,MAAM,wCAAwC,CAAC;AAGnF,gEAAgE;AAChE,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAA0B,CAAC;AAC5D;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,eAAgB,SAAS,IAGnD;IACV,YAAY,GAAQ,EAAE,GAAQ;QAC5B,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE;YACzB,kBAAkB,EAAE,KAAK,IAAI,EAAE,CAC7B,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE;YACvF,kBAAkB,EAAE,KAAK,EAAE,IAAmB,EAAE,EAAE,CAChD,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,WAAW;SACxE,CAAC,CAAC;QACH,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAClB,CAAC;CAC+B,CAAC;AACnC,kFAAkF;AAClF,MAAM,CAAC,MAAM,aAAa,GAAG,eAEhB,CAAC","sourcesContent":["// Typed entry points to the generated bundles in vendor/miniflare (scripts/vendor-miniflare.mjs).\n\n// @ts-expect-error — generated JS, no declarations\nimport makeD1BindingJs from \"../../vendor/miniflare/d1-api.js\";\n// @ts-expect-error — generated JS, no declarations\nimport { D1DatabaseObject as D1Js } from \"../../vendor/miniflare/d1-database.js\";\n// @ts-expect-error — generated JS, no declarations\nimport { KVNamespaceObject as KVJs } from \"../../vendor/miniflare/kv-namespace.js\";\nimport type { DurableObjectClass } from \"../core/handles.js\";\n\n/** Miniflare's KV simulator object (workers-sdk, unchanged). */\nexport const KVNamespaceObject = KVJs as DurableObjectClass;\n/**\n * Miniflare's D1 simulator object (workers-sdk, unchanged). It asks its storage for\n * bookmarks (commit tokens of D1 sessions); celld's Durable Object storage has no bookmark\n * API (calling it is a TypeError), so only the simulator's instances get these methods.\n */\nexport const D1DatabaseObject = class CellsD1Database extends (D1Js as new (\n ctx: any,\n env: any,\n) => object) {\n constructor(ctx: any, env: any) {\n let n = 0;\n Object.assign(ctx.storage, {\n getCurrentBookmark: async () =>\n `${Date.now().toString(16).padStart(12, \"0\")}-${(++n).toString(16).padStart(8, \"0\")}`,\n getBookmarkForTime: async (time: number | Date) =>\n `${new Date(time).getTime().toString(16).padStart(12, \"0\")}-00000000`,\n });\n super(ctx, env);\n }\n} as unknown as DurableObjectClass;\n/** workerd's D1 binding client (src/cloudflare/internal/d1-api.ts, unchanged). */\nexport const makeD1Binding = makeD1BindingJs as (env: {\n fetcher: { fetch: typeof fetch };\n}) => unknown;\n"]}
@@ -0,0 +1,22 @@
1
+ export declare class AsyncLocalStorage<T> {
2
+ getStore(): T | undefined;
3
+ run<R>(store: T, fn: (...args: unknown[]) => R, ...args: unknown[]): R;
4
+ /** The store for the rest of the current synchronous part and what it schedules. */
5
+ enterWith(store: T): void;
6
+ exit<R>(fn: (...args: unknown[]) => R, ...args: unknown[]): R;
7
+ disable(): void;
8
+ /** `fn` bound to the current stores. */
9
+ static bind<F extends (...args: any[]) => unknown>(fn: F): F;
10
+ /** Runs a function later in the stores current now. */
11
+ static snapshot(): <R>(fn: (...args: unknown[]) => R, ...args: unknown[]) => R;
12
+ }
13
+ /**
14
+ * Makes continuations carry the current stores, in the realm of `g` (a browser worker that runs
15
+ * Worker code). Idempotent. With AsyncContext the engine carries them: nothing to install.
16
+ */
17
+ export declare function installAsyncContext(g?: typeof globalThis): void;
18
+ declare const _default: {
19
+ AsyncLocalStorage: typeof AsyncLocalStorage;
20
+ installAsyncContext: typeof installAsyncContext;
21
+ };
22
+ export default _default;
@@ -0,0 +1,176 @@
1
+ /**
2
+ * `node:async_hooks` AsyncLocalStorage for browsers (nodejs_compat).
3
+ *
4
+ * In a realm with TC39 AsyncContext (Stage 2; no browser ships it yet), each AsyncLocalStorage
5
+ * is an `AsyncContext.Variable`: the engine carries it through every `await`, as workerd, celld
6
+ * and Node do, and `installAsyncContext()` patches nothing. Code needs no lowering there (lowered
7
+ * code works too). `enterWith()` has no AsyncContext counterpart and throws.
8
+ *
9
+ * Elsewhere this module simulates it:
10
+ *
11
+ * - a context is an immutable frame (store per AsyncLocalStorage); `run()` makes its frame
12
+ * current for the synchronous part of the call only;
13
+ * - `installAsyncContext()` makes continuations carry the frame that was current when they
14
+ * were scheduled: `Promise.prototype.then` (so `catch`, `finally` and `await` on a thenable),
15
+ * `setTimeout`, `setInterval` and `queueMicrotask`;
16
+ * - a native `await` does not call `then`, so code that relies on propagation is compiled with
17
+ * `async`/`await` lowered to generators (with nodejs_compat, `bundleWorkerForBrowser` does it
18
+ * with esbuild, an in-browser site with `lowerAwait`): each `await` then goes through
19
+ * `Promise.prototype.then`.
20
+ *
21
+ * Code that is not lowered (cellb itself) resumes after a native `await` in the root frame: it
22
+ * neither sees nor leaks another event's stores.
23
+ *
24
+ * Without `installAsyncContext()` (code compiled without lowering), `run()` keeps its store set
25
+ * until its promise settles instead: one run at a time sees its store after `await`, concurrent
26
+ * runs share whichever was set last.
27
+ */
28
+ import { nativeAsyncContext } from "../core/async-context.js";
29
+ const native = nativeAsyncContext();
30
+ const variables = new WeakMap();
31
+ /** Stores whose `disable()` holds until their next `run()` (native backend). */
32
+ const disabled = new WeakSet();
33
+ const variableOf = (als, ac) => {
34
+ let v = variables.get(als);
35
+ if (!v) {
36
+ v = new ac.Variable();
37
+ variables.set(als, v);
38
+ }
39
+ return v;
40
+ };
41
+ // One state per realm: a browser bundle carries its own copy of this module (node:async_hooks
42
+ // bundled in), and its stores must be the frames that cellb's patched `then` restores.
43
+ const STATE = Symbol.for("cellb.asyncContext.state");
44
+ const realm = globalThis;
45
+ if (!realm[STATE]) {
46
+ const root = new Map();
47
+ realm[STATE] = { root, current: root, propagate: false };
48
+ }
49
+ const state = realm[STATE];
50
+ const ROOT = state.root;
51
+ function runIn(frame, fn, thisArg, args) {
52
+ const prev = state.current;
53
+ state.current = frame;
54
+ try {
55
+ return fn.apply(thisArg, args);
56
+ }
57
+ finally {
58
+ state.current = prev;
59
+ }
60
+ }
61
+ /** `fn` bound to the frame current now. */
62
+ // biome-ignore lint/suspicious/noExplicitAny: any function, called with its own arguments
63
+ function bindToCurrent(fn) {
64
+ const frame = state.current;
65
+ if (frame === ROOT)
66
+ return fn; // nothing to carry; the callback runs in the root frame anyway
67
+ return function (...args) {
68
+ return runIn(frame, fn, this, args);
69
+ };
70
+ }
71
+ export class AsyncLocalStorage {
72
+ getStore() {
73
+ const self = this;
74
+ if (native)
75
+ return disabled.has(self) ? undefined : variableOf(self, native).get();
76
+ return state.current.get(self);
77
+ }
78
+ run(store, fn, ...args) {
79
+ if (native) {
80
+ disabled.delete(this);
81
+ return variableOf(this, native).run(store, fn, ...args);
82
+ }
83
+ const frame = new Map(state.current).set(this, store);
84
+ if (state.propagate)
85
+ return runIn(frame, fn, undefined, args);
86
+ // Without installAsyncContext() (code whose `await` is not lowered): the store stays set
87
+ // until the run's promise settles — right for one run at a time, shared between concurrent
88
+ // ones.
89
+ const prev = state.current;
90
+ state.current = frame;
91
+ let r;
92
+ try {
93
+ r = fn(...args);
94
+ }
95
+ catch (e) {
96
+ state.current = prev;
97
+ throw e;
98
+ }
99
+ if (r instanceof Promise)
100
+ return r.finally(() => {
101
+ state.current = prev;
102
+ });
103
+ state.current = prev;
104
+ return r;
105
+ }
106
+ /** The store for the rest of the current synchronous part and what it schedules. */
107
+ enterWith(store) {
108
+ if (native)
109
+ throw new Error("AsyncLocalStorage.enterWith() is not available with AsyncContext: use run() instead");
110
+ state.current = new Map(state.current).set(this, store);
111
+ }
112
+ exit(fn, ...args) {
113
+ if (native)
114
+ return variableOf(this, native).run(undefined, fn, ...args);
115
+ const frame = new Map(state.current);
116
+ frame.delete(this);
117
+ return runIn(frame, fn, undefined, args);
118
+ }
119
+ disable() {
120
+ if (native) {
121
+ disabled.add(this);
122
+ return;
123
+ }
124
+ if (!state.current.has(this))
125
+ return;
126
+ const frame = new Map(state.current);
127
+ frame.delete(this);
128
+ state.current = frame;
129
+ }
130
+ /** `fn` bound to the current stores. */
131
+ // biome-ignore lint/suspicious/noExplicitAny: any function, called with its own arguments
132
+ static bind(fn) {
133
+ if (native)
134
+ return native.Snapshot.wrap(fn);
135
+ return bindToCurrent(fn);
136
+ }
137
+ /** Runs a function later in the stores current now. */
138
+ static snapshot() {
139
+ if (native) {
140
+ const snapshot = new native.Snapshot();
141
+ return (fn, ...args) => snapshot.run(fn, ...args);
142
+ }
143
+ const frame = state.current;
144
+ return (fn, ...args) => runIn(frame, fn, undefined, args);
145
+ }
146
+ }
147
+ const INSTALLED = Symbol.for("cellb.asyncContext");
148
+ /**
149
+ * Makes continuations carry the current stores, in the realm of `g` (a browser worker that runs
150
+ * Worker code). Idempotent. With AsyncContext the engine carries them: nothing to install.
151
+ */
152
+ export function installAsyncContext(g = globalThis) {
153
+ if (native)
154
+ return;
155
+ const proto = g.Promise.prototype;
156
+ if (proto[INSTALLED])
157
+ return;
158
+ Object.defineProperty(proto, INSTALLED, { value: true });
159
+ state.propagate = true;
160
+ function then(onFulfilled, onRejected) {
161
+ return original.call(this, typeof onFulfilled === "function" ? bindToCurrent(onFulfilled) : onFulfilled, typeof onRejected === "function" ? bindToCurrent(onRejected) : onRejected);
162
+ }
163
+ const original = proto.then;
164
+ // biome-ignore lint/suspicious/noThenProperty: replacing Promise.prototype.then is the point
165
+ Object.defineProperty(proto, "then", { value: then, writable: true, configurable: true });
166
+ const timer = (schedule) => function (handler, ...rest) {
167
+ const h = typeof handler === "function" ? bindToCurrent(handler) : handler;
168
+ return schedule.call(this ?? g, h, ...rest);
169
+ };
170
+ g.setTimeout = timer(g.setTimeout);
171
+ g.setInterval = timer(g.setInterval);
172
+ const queue = g.queueMicrotask;
173
+ g.queueMicrotask = (cb) => queue.call(g, bindToCurrent(cb));
174
+ }
175
+ export default { AsyncLocalStorage, installAsyncContext };
176
+ //# sourceMappingURL=async_hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async_hooks.js","sourceRoot":"","sources":["../../src/node-compat/async_hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,EAA2B,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAIvF,MAAM,MAAM,GAAG,kBAAkB,EAAE,CAAC;AAEpC,MAAM,SAAS,GAAG,IAAI,OAAO,EAA8C,CAAC;AAC5E,gFAAgF;AAChF,MAAM,QAAQ,GAAG,IAAI,OAAO,EAA8B,CAAC;AAC3D,MAAM,UAAU,GAAG,CAAC,GAA+B,EAAE,EAAsB,EAAE,EAAE;IAC7E,IAAI,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC3B,IAAI,CAAC,CAAC,EAAE,CAAC;QACP,CAAC,GAAG,IAAI,EAAE,CAAC,QAAQ,EAAE,CAAC;QACtB,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC,CAAC;AAEF,8FAA8F;AAC9F,uFAAuF;AACvF,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;AACrD,MAAM,KAAK,GAAG,UAAqC,CAAC;AACpD,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;IAClB,MAAM,IAAI,GAAU,IAAI,G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gB,EAAE,GAAG,IAAe;QAC3D,MAAM,CAAC,GAAG,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,aAAa,CAAC,OAAwB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;QAC5F,OAAQ,QAAyC,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;IAChF,CAAiB,CAAC;IACpB,CAAC,CAAC,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;IACnC,CAAC,CAAC,WAAW,GAAG,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;IACrC,MAAM,KAAK,GAAG,CAAC,CAAC,cAAc,CAAC;IAC/B,CAAC,CAAC,cAAc,GAAG,CAAC,EAAgB,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,aAAa,CAAC,EAAE,CAAC,CAAC,CAAC;AAC5E,CAAC;AAED,eAAe,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,CAAC","sourcesContent":["/**\n * `node:async_hooks` AsyncLocalStorage for browsers (nodejs_compat).\n *\n * In a realm with TC39 AsyncContext (Stage 2; no browser ships it yet), each AsyncLocalStorage\n * is an `AsyncContext.Variable`: the engine carries it through every `await`, as workerd, celld\n * and Node do, and `installAsyncContext()` patches nothing. Code needs no lowering there (lowered\n * code works too). `enterWith()` has no AsyncContext counterpart and throws.\n *\n * Elsewhere this module simulates it:\n *\n * - a context is an immutable frame (store per AsyncLocalStorage); `run()` makes its frame\n * current for the synchronous part of the call only;\n * - `installAsyncContext()` makes continuations carry the frame that was current when they\n * were scheduled: `Promise.prototype.then` (so `catch`, `finally` and `await` on a thenable),\n * `setTimeout`, `setInterval` and `queueMicrotask`;\n * - a native `await` does not call `then`, so code that relies on propagation is compiled with\n * `async`/`await` lowered to generators (with nodejs_compat, `bundleWorkerForBrowser` does it\n * with esbuild, an in-browser site with `lowerAwait`): each `await` then goes through\n * `Promise.prototype.then`.\n *\n * Code that is not lowered (cellb itself) resumes after a native `await` in the root frame: it\n * neither sees nor leaks another event's stores.\n *\n * Without `installAsyncContext()` (code compiled without lowering), `run()` keeps its store set\n * until its promise settles instead: one run at a time sees its store after `await`, concurrent\n * runs share whichever was set last.\n */\nimport { type NativeAsyncContext, nativeAsyncContext } from \"../core/async-context.js\";\n\ntype Frame = ReadonlyMap<AsyncLocalStorage<unknown>, unknown>;\n\nconst native = nativeAsyncContext();\ntype NativeVariable = InstanceType<NativeAsyncContext[\"Variable\"]>;\nconst variables = new WeakMap<AsyncLocalStorage<unknown>, NativeVariable>();\n/** Stores whose `disable()` holds until their next `run()` (native backend). */\nconst disabled = new WeakSet<AsyncLocalStorage<unknown>>();\nconst variableOf = (als: AsyncLocalStorage<unknown>, ac: NativeAsyncContext) => {\n let v = variables.get(als);\n if (!v) {\n v = new ac.Variable();\n variables.set(als, v);\n }\n return v;\n};\n\n// One state per realm: a browser bundle carries its own copy of this module (node:async_hooks\n// bundled in), and its stores must be the frames that cellb's patched `then` restores.\nconst STATE = Symbol.for(\"cellb.asyncContext.state\");\nconst realm = globalThis as Record<symbol, unknown>;\nif (!realm[STATE]) {\n const root: Frame = new Map();\n realm[STATE] = { root, current: root, propagate: false };\n}\nconst state = realm[STATE] as { root: Frame; current: Frame; propagate: boolean };\nconst ROOT = state.root;\n\nfunction runIn<R>(\n frame: Frame,\n fn: (...args: unknown[]) => R,\n thisArg: unknown,\n args: unknown[],\n): R {\n const prev = state.current;\n state.current = frame;\n try {\n return fn.apply(thisArg, args);\n } finally {\n state.current = prev;\n }\n}\n\n/** `fn` bound to the frame current now. */\n// biome-ignore lint/suspicious/noExplicitAny: any function, called with its own arguments\nfunction bindToCurrent<F extends (...args: any[]) => unknown>(fn: F): F {\n const frame = state.current;\n if (frame === ROOT) return fn; // nothing to carry; the callback runs in the root frame anyway\n return function (this: unknown, ...args: unknown[]) {\n return runIn(frame, fn, this, args);\n } as F;\n}\n\nexport class AsyncLocalStorage<T> {\n getStore(): T | undefined {\n const self = this as AsyncLocalStorage<unknown>;\n if (native) return disabled.has(self) ? undefined : (variableOf(self, native).get() as T);\n return state.current.get(self) as T | undefined;\n }\n run<R>(store: T, fn: (...args: unknown[]) => R, ...args: unknown[]): R {\n if (native) {\n disabled.delete(this as AsyncLocalStorage<unknown>);\n return variableOf(this as AsyncLocalStorage<unknown>, native).run(store, fn, ...args);\n }\n const frame = new Map(state.current).set(this as AsyncLocalStorage<unknown>, store);\n if (state.propagate) return runIn(frame, fn, undefined, args);\n // Without installAsyncContext() (code whose `await` is not lowered): the store stays set\n // until the run's promise settles — right for one run at a time, shared between concurrent\n // ones.\n const prev = state.current;\n state.current = frame;\n let r: R;\n try {\n r = fn(...args);\n } catch (e) {\n state.current = prev;\n throw e;\n }\n if (r instanceof Promise)\n return r.finally(() => {\n state.current = prev;\n }) as R;\n state.current = prev;\n return r;\n }\n /** The store for the rest of the current synchronous part and what it schedules. */\n enterWith(store: T): void {\n if (native)\n throw new Error(\n \"AsyncLocalStorage.enterWith() is not available with AsyncContext: use run() instead\",\n );\n state.current = new Map(state.current).set(this as AsyncLocalStorage<unknown>, store);\n }\n exit<R>(fn: (...args: unknown[]) => R, ...args: unknown[]): R {\n if (native)\n return variableOf(this as AsyncLocalStorage<unknown>, native).run(undefined, fn, ...args);\n const frame = new Map(state.current);\n frame.delete(this as AsyncLocalStorage<unknown>);\n return runIn(frame, fn, undefined, args);\n }\n disable(): void {\n if (native) {\n disabled.add(this as AsyncLocalStorage<unknown>);\n return;\n }\n if (!state.current.has(this as AsyncLocalStorage<unknown>)) return;\n const frame = new Map(state.current);\n frame.delete(this as AsyncLocalStorage<unknown>);\n state.current = frame;\n }\n /** `fn` bound to the current stores. */\n // biome-ignore lint/suspicious/noExplicitAny: any function, called with its own arguments\n static bind<F extends (...args: any[]) => unknown>(fn: F): F {\n if (native) return native.Snapshot.wrap(fn);\n return bindToCurrent(fn);\n }\n /** Runs a function later in the stores current now. */\n static snapshot(): <R>(fn: (...args: unknown[]) => R, ...args: unknown[]) => R {\n if (native) {\n const snapshot = new native.Snapshot();\n return (fn, ...args) => snapshot.run(fn, ...args);\n }\n const frame = state.current;\n return (fn, ...args) => runIn(frame, fn, undefined, args);\n }\n}\n\nconst INSTALLED = Symbol.for(\"cellb.asyncContext\");\n\n/**\n * Makes continuations carry the current stores, in the realm of `g` (a browser worker that runs\n * Worker code). Idempotent. With AsyncContext the engine carries them: nothing to install.\n */\nexport function installAsyncContext(g: typeof globalThis = globalThis): void {\n if (native) return;\n const proto = g.Promise.prototype as Promise<unknown> & { [INSTALLED]?: true };\n if (proto[INSTALLED]) return;\n Object.defineProperty(proto, INSTALLED, { value: true });\n state.propagate = true;\n type Callback = ((value: unknown) => unknown) | null | undefined;\n function then(this: Promise<unknown>, onFulfilled?: Callback, onRejected?: Callback) {\n return original.call(\n this,\n typeof onFulfilled === \"function\" ? bindToCurrent(onFulfilled) : onFulfilled,\n typeof onRejected === \"function\" ? bindToCurrent(onRejected) : onRejected,\n );\n }\n const original = proto.then;\n // biome-ignore lint/suspicious/noThenProperty: replacing Promise.prototype.then is the point\n Object.defineProperty(proto, \"then\", { value: then, writable: true, configurable: true });\n const timer = <F extends typeof g.setTimeout | typeof g.setInterval>(schedule: F) =>\n function (this: unknown, handler: unknown, ...rest: unknown[]) {\n const h = typeof handler === \"function\" ? bindToCurrent(handler as () => unknown) : handler;\n return (schedule as (...a: unknown[]) => unknown).call(this ?? g, h, ...rest);\n } as unknown as F;\n g.setTimeout = timer(g.setTimeout);\n g.setInterval = timer(g.setInterval);\n const queue = g.queueMicrotask;\n g.queueMicrotask = (cb: VoidFunction) => queue.call(g, bindToCurrent(cb));\n}\n\nexport default { AsyncLocalStorage, installAsyncContext };\n"]}
@@ -0,0 +1,3 @@
1
+ /** Registry entries: each module under its `node:*` name (a provided name wins over
2
+ * webrun-modules' own polyfill), plus the Buffer/process globals. */
3
+ export declare const nodeRegistryEntries: Record<string, unknown>;
@@ -0,0 +1,39 @@
1
+ // nodejs_compat for the in-browser module server: the polyfill modules as registry entries
2
+ // (imported here so the browser bundler includes them in the worker that runs Worker code).
3
+ // An entry is the module's default export, carrying its named exports as properties: the
4
+ // module server's proxy serves the entry itself as `default` (so `import assert from
5
+ // "node:assert"` must be callable) and its keys as the named exports.
6
+ import assert from "assert";
7
+ import { Buffer } from "buffer";
8
+ import EventEmitter from "events";
9
+ import path from "path-browserify";
10
+ import util from "util";
11
+ import * as async_hooks from "./async_hooks.js";
12
+ import * as crypto from "./crypto.js";
13
+ import * as diagnostics_channel from "./diagnostics_channel.js";
14
+ import * as fs from "./fs.js";
15
+ import nodeModule from "./module.js";
16
+ import * as os from "./os.js";
17
+ import { process } from "./process.js";
18
+ const modules = {
19
+ "node:assert": assert,
20
+ "node:buffer": { Buffer, default: { Buffer } },
21
+ "node:events": EventEmitter, // npm `events`: EventEmitter.EventEmitter, EventEmitter.once
22
+ "node:path": { ...path, default: path },
23
+ "node:util": { ...util, default: util },
24
+ "node:crypto": { ...crypto },
25
+ "node:async_hooks": { ...async_hooks },
26
+ "node:process": process,
27
+ "node:diagnostics_channel": { ...diagnostics_channel },
28
+ "node:os": { ...os },
29
+ "node:fs": { ...fs },
30
+ "node:module": nodeModule,
31
+ };
32
+ /** Registry entries: each module under its `node:*` name (a provided name wins over
33
+ * webrun-modules' own polyfill), plus the Buffer/process globals. */
34
+ export const nodeRegistryEntries = {
35
+ ...modules,
36
+ Buffer,
37
+ process,
38
+ };
39
+ //# sourceMappingURL=browser-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-registry.js","sourceRoot":"","sources":["../../src/node-compat/browser-registry.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,4FAA4F;AAC5F,yFAAyF;AACzF,qFAAqF;AACrF,sEAAsE;AACtE,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,YAAY,MAAM,QAAQ,CAAC;AAClC,OAAO,IAAI,MAAM,iBAAiB,CAAC;AACnC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,mBAAmB,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,OAAO,GAA4B;IACvC,aAAa,EAAE,MAAM;IACrB,aAAa,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,EAAE;IAC9C,aAAa,EAAE,YAAY,EAAE,6DAA6D;IAC1F,WAAW,EAAE,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE;IACvC,WAAW,EAAE,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE;IACvC,aAAa,EAAE,EAAE,GAAG,MAAM,EAAE;IAC5B,kBAAkB,EAAE,EAAE,GAAG,WAAW,EAAE;IACtC,cAAc,EAAE,OAAO;IACvB,0BAA0B,EAAE,EAAE,GAAG,mBAAmB,EAAE;IACtD,SAAS,EAAE,EAAE,GAAG,EAAE,EAAE;IACpB,SAAS,EAAE,EAAE,GAAG,EAAE,EAAE;IACpB,aAAa,EAAE,UAAU;CAC1B,CAAC;AAEF;sEACsE;AACtE,MAAM,CAAC,MAAM,mBAAmB,GAA4B;IAC1D,GAAG,OAAO;IACV,MAAM;IACN,OAAO;CACR,CAAC","sourcesContent":["// nodejs_compat for the in-browser module server: the polyfill modules as registry entries\n// (imported here so the browser bundler includes them in the worker that runs Worker code).\n// An entry is the module's default export, carrying its named exports as properties: the\n// module server's proxy serves the entry itself as `default` (so `import assert from\n// \"node:assert\"` must be callable) and its keys as the named exports.\nimport assert from \"assert\";\nimport { Buffer } from \"buffer\";\nimport EventEmitter from \"events\";\nimport path from \"path-browserify\";\nimport util from \"util\";\nimport * as async_hooks from \"./async_hooks.js\";\nimport * as crypto from \"./crypto.js\";\nimport * as diagnostics_channel from \"./diagnostics_channel.js\";\nimport * as fs from \"./fs.js\";\nimport nodeModule from \"./module.js\";\nimport * as os from \"./os.js\";\nimport { process } from \"./process.js\";\n\nconst modules: Record<string, unknown> = {\n \"node:assert\": assert,\n \"node:buffer\": { Buffer, default: { Buffer } },\n \"node:events\": EventEmitter, // npm `events`: EventEmitter.EventEmitter, EventEmitter.once\n \"node:path\": { ...path, default: path },\n \"node:util\": { ...util, default: util },\n \"node:crypto\": { ...crypto },\n \"node:async_hooks\": { ...async_hooks },\n \"node:process\": process,\n \"node:diagnostics_channel\": { ...diagnostics_channel },\n \"node:os\": { ...os },\n \"node:fs\": { ...fs },\n \"node:module\": nodeModule,\n};\n\n/** Registry entries: each module under its `node:*` name (a provided name wins over\n * webrun-modules' own polyfill), plus the Buffer/process globals. */\nexport const nodeRegistryEntries: Record<string, unknown> = {\n ...modules,\n Buffer,\n process,\n};\n"]}
@@ -0,0 +1,60 @@
1
+ import { Buffer } from "buffer";
2
+ declare class Hash {
3
+ #private;
4
+ private readonly fn;
5
+ constructor(fn: (m: Uint8Array) => Uint8Array);
6
+ update(data: string | Uint8Array, enc?: BufferEncoding): this;
7
+ digest(enc?: BufferEncoding): Buffer | string;
8
+ }
9
+ export declare function createHash(name: string): Hash;
10
+ export declare function createHmac(name: string, key: string | Uint8Array): Hash;
11
+ export declare function randomUUID(): string;
12
+ export declare function randomBytes(n: number): Buffer;
13
+ export declare function timingSafeEqual(a: Uint8Array, b: Uint8Array): boolean;
14
+ /**
15
+ * A public key as `createPublicKey` returns it: its type and its bytes, exportable as DER or
16
+ * PEM. Libraries build these when they load (sigstore's trust roots, in EmDash's plugin
17
+ * registry); signatures are checked through `verify`, which is not available here.
18
+ */
19
+ export declare class KeyObject {
20
+ #private;
21
+ readonly type = "public";
22
+ readonly asymmetricKeyType: string | undefined;
23
+ constructor(der: Uint8Array, format: "spki" | "pkcs1");
24
+ export(opts?: {
25
+ format?: "der" | "pem";
26
+ type?: string;
27
+ }): Buffer | string;
28
+ equals(other: KeyObject): boolean;
29
+ }
30
+ type KeyInput = string | Uint8Array | KeyObject | {
31
+ key: string | Uint8Array;
32
+ format?: "pem" | "der";
33
+ type?: "spki" | "pkcs1";
34
+ };
35
+ export declare function createPublicKey(input: KeyInput): KeyObject;
36
+ declare const noVerify: () => never;
37
+ export declare function verify(..._args: unknown[]): boolean;
38
+ export declare function createVerify(_algorithm: string): {
39
+ update(): {
40
+ update(): /*elided*/ any;
41
+ verify: typeof noVerify;
42
+ };
43
+ verify: typeof noVerify;
44
+ };
45
+ export declare const webcrypto: Crypto;
46
+ export declare const subtle: SubtleCrypto;
47
+ declare const _default: {
48
+ createHash: typeof createHash;
49
+ createHmac: typeof createHmac;
50
+ randomUUID: typeof randomUUID;
51
+ randomBytes: typeof randomBytes;
52
+ timingSafeEqual: typeof timingSafeEqual;
53
+ KeyObject: typeof KeyObject;
54
+ createPublicKey: typeof createPublicKey;
55
+ verify: typeof verify;
56
+ createVerify: typeof createVerify;
57
+ webcrypto: Crypto;
58
+ subtle: SubtleCrypto;
59
+ };
60
+ export default _default;
@@ -0,0 +1,143 @@
1
+ /**
2
+ * `node:crypto` subset for browsers (nodejs_compat): hashes, HMAC, random, timingSafeEqual, and
3
+ * public `KeyObject`s (`createPublicKey`) without signature checks.
4
+ */
5
+ import { hmac } from "@noble/hashes/hmac";
6
+ import { md5, sha1 } from "@noble/hashes/legacy";
7
+ import { sha256, sha384, sha512 } from "@noble/hashes/sha2";
8
+ import { Buffer } from "buffer";
9
+ const HASHES = { md5, sha1, sha256, sha384, sha512 };
10
+ const algo = (name) => {
11
+ const h = HASHES[name.toLowerCase().replace("-", "")];
12
+ if (!h)
13
+ throw new Error(`Digest method not supported: ${name}`);
14
+ return h;
15
+ };
16
+ const bytes = (data, enc) => typeof data === "string" ? new Uint8Array(Buffer.from(data, enc ?? "utf8")) : data;
17
+ class Hash {
18
+ fn;
19
+ #parts = [];
20
+ constructor(fn) {
21
+ this.fn = fn;
22
+ }
23
+ update(data, enc) {
24
+ this.#parts.push(bytes(data, enc));
25
+ return this;
26
+ }
27
+ digest(enc) {
28
+ const all = Buffer.concat(this.#parts);
29
+ const out = Buffer.from(this.fn(new Uint8Array(all)));
30
+ return enc ? out.toString(enc) : out;
31
+ }
32
+ }
33
+ export function createHash(name) {
34
+ return new Hash(algo(name));
35
+ }
36
+ export function createHmac(name, key) {
37
+ const h = algo(name);
38
+ return new Hash((m) => hmac(h, bytes(key), m));
39
+ }
40
+ export function randomUUID() {
41
+ return crypto.randomUUID();
42
+ }
43
+ export function randomBytes(n) {
44
+ return Buffer.from(crypto.getRandomValues(new Uint8Array(n)));
45
+ }
46
+ export function timingSafeEqual(a, b) {
47
+ if (a.byteLength !== b.byteLength)
48
+ throw new RangeError("Input buffers must have the same byte length");
49
+ let d = 0;
50
+ for (let i = 0; i < a.byteLength; i++)
51
+ d |= a[i] ^ b[i];
52
+ return d === 0;
53
+ }
54
+ const OIDS = [
55
+ [[0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01], "rsa"],
56
+ [[0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01], "ec"],
57
+ [[0x2b, 0x65, 0x70], "ed25519"],
58
+ [[0x2b, 0x65, 0x71], "ed448"],
59
+ ];
60
+ const contains = (hay, needle) => {
61
+ outer: for (let i = 0; i + needle.length <= hay.length; i++) {
62
+ for (let j = 0; j < needle.length; j++)
63
+ if (hay[i + j] !== needle[j])
64
+ continue outer;
65
+ return true;
66
+ }
67
+ return false;
68
+ };
69
+ /**
70
+ * A public key as `createPublicKey` returns it: its type and its bytes, exportable as DER or
71
+ * PEM. Libraries build these when they load (sigstore's trust roots, in EmDash's plugin
72
+ * registry); signatures are checked through `verify`, which is not available here.
73
+ */
74
+ export class KeyObject {
75
+ type = "public";
76
+ asymmetricKeyType;
77
+ #der;
78
+ #format;
79
+ constructor(der, format) {
80
+ this.#der = der;
81
+ this.#format = format;
82
+ this.asymmetricKeyType =
83
+ format === "pkcs1" ? "rsa" : OIDS.find(([oid]) => contains(der.subarray(0, 32), oid))?.[1];
84
+ }
85
+ export(opts = {}) {
86
+ if (opts.format === "pem") {
87
+ const label = this.#format === "pkcs1" ? "RSA PUBLIC KEY" : "PUBLIC KEY";
88
+ const b64 = Buffer.from(this.#der).toString("base64").replace(/.{64}/g, "$&\n");
89
+ return `-----BEGIN ${label}-----\n${b64.replace(/\n$/, "")}\n-----END ${label}-----\n`;
90
+ }
91
+ return Buffer.from(this.#der);
92
+ }
93
+ equals(other) {
94
+ const a = this.export();
95
+ const b = other.export();
96
+ return a.length === b.length && timingSafeEqual(a, b);
97
+ }
98
+ }
99
+ export function createPublicKey(input) {
100
+ if (input instanceof KeyObject)
101
+ return input;
102
+ const spec = typeof input === "string" || input instanceof Uint8Array ? { key: input } : input;
103
+ if (typeof spec.key === "string" || spec.format === "pem") {
104
+ const pem = typeof spec.key === "string" ? spec.key : Buffer.from(spec.key).toString("utf8");
105
+ const m = /-----BEGIN ([A-Z ]+)-----([\s\S]*?)-----END \1-----/.exec(pem);
106
+ if (!m)
107
+ throw new TypeError("createPublicKey: not a PEM public key");
108
+ if (!/PUBLIC KEY/.test(m[1]))
109
+ throw new Error(`createPublicKey: ${m[1]} is not supported in browsers (nodejs_compat)`);
110
+ return new KeyObject(new Uint8Array(Buffer.from(m[2].replace(/\s+/g, ""), "base64")), m[1] === "RSA PUBLIC KEY" ? "pkcs1" : "spki");
111
+ }
112
+ return new KeyObject(new Uint8Array(spec.key), spec.type === "pkcs1" ? "pkcs1" : "spki");
113
+ }
114
+ const noVerify = () => {
115
+ throw new Error("node:crypto signature verification is not available in browsers (nodejs_compat)");
116
+ };
117
+ export function verify(..._args) {
118
+ return noVerify();
119
+ }
120
+ export function createVerify(_algorithm) {
121
+ return {
122
+ update() {
123
+ return this;
124
+ },
125
+ verify: noVerify,
126
+ };
127
+ }
128
+ export const webcrypto = globalThis.crypto;
129
+ export const subtle = globalThis.crypto.subtle;
130
+ export default {
131
+ createHash,
132
+ createHmac,
133
+ randomUUID,
134
+ randomBytes,
135
+ timingSafeEqual,
136
+ KeyObject,
137
+ createPublicKey,
138
+ verify,
139
+ createVerify,
140
+ webcrypto,
141
+ subtle,
142
+ };
143
+ //# sourceMappingURL=crypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../src/node-compat/crypto.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,MAAM,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAW,CAAC;AAE9D,MAAM,IAAI,GAAG,CAAC,IAAY,EAAyB,EAAE;IACnD,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAS,CAAC,CAAC;IAC9D,IAAI,CAAC,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,IAAI,EAAE,CAAC,CAAC;IAChE,OAAO,CAAC,CAAC;AACX,CAAC,CAAC;AACF,MAAM,KAAK,GAAG,CAAC,IAAyB,EAAE,GAAoB,EAAE,EAAE,CAChE,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,GAA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AQ,CAAC,CAAC,EAC/D,CAAC,CAAC,CAAC,CAAC,KAAK,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAC7C,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,SAAS,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAC3F,CAAC;AAED,MAAM,QAAQ,GAAG,GAAU,EAAE;IAC3B,MAAM,IAAI,KAAK,CACb,iFAAiF,CAClF,CAAC;AACJ,CAAC,CAAC;AACF,MAAM,UAAU,MAAM,CAAC,GAAG,KAAgB;IACxC,OAAO,QAAQ,EAAE,CAAC;AACpB,CAAC;AACD,MAAM,UAAU,YAAY,CAAC,UAAkB;IAC7C,OAAO;QACL,MAAM;YACJ,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,EAAE,QAAQ;KACjB,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CAAC,MAAM,CAAC;AAC3C,MAAM,CAAC,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC;AAC/C,eAAe;IACb,UAAU;IACV,UAAU;IACV,UAAU;IACV,WAAW;IACX,eAAe;IACf,SAAS;IACT,eAAe;IACf,MAAM;IACN,YAAY;IACZ,SAAS;IACT,MAAM;CACP,CAAC","sourcesContent":["/**\n * `node:crypto` subset for browsers (nodejs_compat): hashes, HMAC, random, timingSafeEqual, and\n * public `KeyObject`s (`createPublicKey`) without signature checks.\n */\nimport { hmac } from \"@noble/hashes/hmac\";\nimport { md5, sha1 } from \"@noble/hashes/legacy\";\nimport { sha256, sha384, sha512 } from \"@noble/hashes/sha2\";\nimport { Buffer } from \"buffer\";\n\nconst HASHES = { md5, sha1, sha256, sha384, sha512 } as const;\ntype Algo = keyof typeof HASHES;\nconst algo = (name: string): (typeof HASHES)[Algo] => {\n const h = HASHES[name.toLowerCase().replace(\"-\", \"\") as Algo];\n if (!h) throw new Error(`Digest method not supported: ${name}`);\n return h;\n};\nconst bytes = (data: string | Uint8Array, enc?: BufferEncoding) =>\n typeof data === \"string\" ? new Uint8Array(Buffer.from(data, enc ?? \"utf8\")) : data;\n\nclass Hash {\n #parts: Uint8Array[] = [];\n constructor(private readonly fn: (m: Uint8Array) => Uint8Array) {}\n update(data: string | Uint8Array, enc?: BufferEncoding): this {\n this.#parts.push(bytes(data, enc));\n return this;\n }\n digest(enc?: BufferEncoding): Buffer | string {\n const all = Buffer.concat(this.#parts);\n const out = Buffer.from(this.fn(new Uint8Array(all)));\n return enc ? out.toString(enc) : out;\n }\n}\n\nexport function createHash(name: string) {\n return new Hash(algo(name));\n}\nexport function createHmac(name: string, key: string | Uint8Array) {\n const h = algo(name);\n return new Hash((m) => hmac(h as never, bytes(key), m));\n}\nexport function randomUUID(): string {\n return crypto.randomUUID();\n}\nexport function randomBytes(n: number): Buffer {\n return Buffer.from(crypto.getRandomValues(new Uint8Array(n)));\n}\nexport function timingSafeEqual(a: Uint8Array, b: Uint8Array): boolean {\n if (a.byteLength !== b.byteLength)\n throw new RangeError(\"Input buffers must have the same byte length\");\n let d = 0;\n for (let i = 0; i < a.byteLength; i++) d |= a[i] ^ b[i];\n return d === 0;\n}\n\nconst OIDS: [number[], string][] = [\n [[0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01], \"rsa\"],\n [[0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01], \"ec\"],\n [[0x2b, 0x65, 0x70], \"ed25519\"],\n [[0x2b, 0x65, 0x71], \"ed448\"],\n];\nconst contains = (hay: Uint8Array, needle: number[]) => {\n outer: for (let i = 0; i + needle.length <= hay.length; i++) {\n for (let j = 0; j < needle.length; j++) if (hay[i + j] !== needle[j]) continue outer;\n return true;\n }\n return false;\n};\n\n/**\n * A public key as `createPublicKey` returns it: its type and its bytes, exportable as DER or\n * PEM. Libraries build these when they load (sigstore's trust roots, in EmDash's plugin\n * registry); signatures are checked through `verify`, which is not available here.\n */\nexport class KeyObject {\n readonly type = \"public\";\n readonly asymmetricKeyType: string | undefined;\n readonly #der: Uint8Array;\n readonly #format: \"spki\" | \"pkcs1\";\n constructor(der: Uint8Array, format: \"spki\" | \"pkcs1\") {\n this.#der = der;\n this.#format = format;\n this.asymmetricKeyType =\n format === \"pkcs1\" ? \"rsa\" : OIDS.find(([oid]) => contains(der.subarray(0, 32), oid))?.[1];\n }\n export(opts: { format?: \"der\" | \"pem\"; type?: string } = {}): Buffer | string {\n if (opts.format === \"pem\") {\n const label = this.#format === \"pkcs1\" ? \"RSA PUBLIC KEY\" : \"PUBLIC KEY\";\n const b64 = Buffer.from(this.#der).toString(\"base64\").replace(/.{64}/g, \"$&\\n\");\n return `-----BEGIN ${label}-----\\n${b64.replace(/\\n$/, \"\")}\\n-----END ${label}-----\\n`;\n }\n return Buffer.from(this.#der);\n }\n equals(other: KeyObject): boolean {\n const a = this.export() as Buffer;\n const b = other.export() as Buffer;\n return a.length === b.length && timingSafeEqual(a, b);\n }\n}\n\ntype KeyInput =\n | string\n | Uint8Array\n | KeyObject\n | { key: string | Uint8Array; format?: \"pem\" | \"der\"; type?: \"spki\" | \"pkcs1\" };\n\nexport function createPublicKey(input: KeyInput): KeyObject {\n if (input instanceof KeyObject) return input;\n const spec = typeof input === \"string\" || input instanceof Uint8Array ? { key: input } : input;\n if (typeof spec.key === \"string\" || spec.format === \"pem\") {\n const pem = typeof spec.key === \"string\" ? spec.key : Buffer.from(spec.key).toString(\"utf8\");\n const m = /-----BEGIN ([A-Z ]+)-----([\\s\\S]*?)-----END \\1-----/.exec(pem);\n if (!m) throw new TypeError(\"createPublicKey: not a PEM public key\");\n if (!/PUBLIC KEY/.test(m[1]))\n throw new Error(`createPublicKey: ${m[1]} is not supported in browsers (nodejs_compat)`);\n return new KeyObject(\n new Uint8Array(Buffer.from(m[2].replace(/\\s+/g, \"\"), \"base64\")),\n m[1] === \"RSA PUBLIC KEY\" ? \"pkcs1\" : \"spki\",\n );\n }\n return new KeyObject(new Uint8Array(spec.key), spec.type === \"pkcs1\" ? \"pkcs1\" : \"spki\");\n}\n\nconst noVerify = (): never => {\n throw new Error(\n \"node:crypto signature verification is not available in browsers (nodejs_compat)\",\n );\n};\nexport function verify(..._args: unknown[]): boolean {\n return noVerify();\n}\nexport function createVerify(_algorithm: string) {\n return {\n update() {\n return this;\n },\n verify: noVerify,\n };\n}\n\nexport const webcrypto = globalThis.crypto;\nexport const subtle = globalThis.crypto.subtle;\nexport default {\n createHash,\n createHmac,\n randomUUID,\n randomBytes,\n timingSafeEqual,\n KeyObject,\n createPublicKey,\n verify,\n createVerify,\n webcrypto,\n subtle,\n};\n"]}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * `node:diagnostics_channel` for browsers (nodejs_compat): named channels with subscribers,
3
+ * enough for libraries that publish to them (the Agents SDK publishes its events this way).
4
+ */
5
+ type Listener = (message: unknown, name: string | symbol) => void;
6
+ export declare class Channel {
7
+ #private;
8
+ readonly name: string | symbol;
9
+ constructor(name: string | symbol);
10
+ get hasSubscribers(): boolean;
11
+ subscribe(listener: Listener): void;
12
+ unsubscribe(listener: Listener): boolean;
13
+ publish(message: unknown): void;
14
+ runStores<T>(_data: unknown, fn: (...args: unknown[]) => T, thisArg?: unknown, ...args: unknown[]): T;
15
+ }
16
+ export declare function channel(name: string | symbol): Channel;
17
+ export declare const hasSubscribers: (name: string | symbol) => boolean;
18
+ export declare const subscribe: (name: string | symbol, l: Listener) => void;
19
+ export declare const unsubscribe: (name: string | symbol, l: Listener) => boolean;
20
+ declare const _default: {
21
+ Channel: typeof Channel;
22
+ channel: typeof channel;
23
+ hasSubscribers: typeof hasSubscribers;
24
+ subscribe: typeof subscribe;
25
+ unsubscribe: typeof unsubscribe;
26
+ };
27
+ export default _default;
@@ -0,0 +1,46 @@
1
+ export class Channel {
2
+ name;
3
+ #listeners = new Set();
4
+ constructor(name) {
5
+ this.name = name;
6
+ }
7
+ get hasSubscribers() {
8
+ return this.#listeners.size > 0;
9
+ }
10
+ subscribe(listener) {
11
+ this.#listeners.add(listener);
12
+ }
13
+ unsubscribe(listener) {
14
+ return this.#listeners.delete(listener);
15
+ }
16
+ publish(message) {
17
+ for (const l of this.#listeners) {
18
+ try {
19
+ l(message, this.name);
20
+ }
21
+ catch (e) {
22
+ // As Node: a failing subscriber does not fail the publisher.
23
+ queueMicrotask(() => {
24
+ throw e;
25
+ });
26
+ }
27
+ }
28
+ }
29
+ runStores(_data, fn, thisArg, ...args) {
30
+ return fn.apply(thisArg, args);
31
+ }
32
+ }
33
+ const channels = new Map();
34
+ export function channel(name) {
35
+ let c = channels.get(name);
36
+ if (!c) {
37
+ c = new Channel(name);
38
+ channels.set(name, c);
39
+ }
40
+ return c;
41
+ }
42
+ export const hasSubscribers = (name) => channel(name).hasSubscribers;
43
+ export const subscribe = (name, l) => channel(name).subscribe(l);
44
+ export const unsubscribe = (name, l) => channel(name).unsubscribe(l);
45
+ export default { Channel, channel, hasSubscribers, subscribe, unsubscribe };
46
+ //# sourceMappingURL=diagnostics_channel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics_channel.js","sourceRoot":"","sources":["../../src/node-compat/diagnostics_channel.ts"],"names":[],"mappings":"AAMA,MAAM,OAAO,OAAO;IAEG,IAAI;IADhB,UAAU,GAAG,IAAI,GAAG,EAAY,CAAC;IAC1C,YAAqB,IAAqB;oBAArB,IAAI;IAAoB,CAAC;IAC9C,IAAI,cAAc;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC,CAAC;IAClC,CAAC;IACD,SAAS,CAAC,QAAkB;QAC1B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC;IACD,WAAW,CAAC,QAAkB;QAC5B,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC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,CAAC,CAAC,CAAC,CAAC;AAEhG,eAAe,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC","sourcesContent":["/**\n * `node:diagnostics_channel` for browsers (nodejs_compat): named channels with subscribers,\n * enough for libraries that publish to them (the Agents SDK publishes its events this way).\n */\ntype Listener = (message: unknown, name: string | symbol) => void;\n\nexport class Channel {\n readonly #listeners = new Set<Listener>();\n constructor(readonly name: string | symbol) {}\n get hasSubscribers(): boolean {\n return this.#listeners.size > 0;\n }\n subscribe(listener: Listener): void {\n this.#listeners.add(listener);\n }\n unsubscribe(listener: Listener): boolean {\n return this.#listeners.delete(listener);\n }\n publish(message: unknown): void {\n for (const l of this.#listeners) {\n try {\n l(message, this.name);\n } catch (e) {\n // As Node: a failing subscriber does not fail the publisher.\n queueMicrotask(() => {\n throw e;\n });\n }\n }\n }\n runStores<T>(\n _data: unknown,\n fn: (...args: unknown[]) => T,\n thisArg?: unknown,\n ...args: unknown[]\n ): T {\n return fn.apply(thisArg, args);\n }\n}\n\nconst channels = new Map<string | symbol, Channel>();\n\nexport function channel(name: string | symbol): Channel {\n let c = channels.get(name);\n if (!c) {\n c = new Channel(name);\n channels.set(name, c);\n }\n return c;\n}\nexport const hasSubscribers = (name: string | symbol) => channel(name).hasSubscribers;\nexport const subscribe = (name: string | symbol, l: Listener) => channel(name).subscribe(l);\nexport const unsubscribe = (name: string | symbol, l: Listener) => channel(name).unsubscribe(l);\n\nexport default { Channel, channel, hasSubscribers, subscribe, unsubscribe };\n"]}