devflare 1.0.0-next.3 → 1.0.0-next.30

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 (537) hide show
  1. package/LLM.md +15961 -1751
  2. package/README.md +389 -605
  3. package/bin/devflare.js +24 -14
  4. package/dist/account-fvf5gxc9.js +475 -0
  5. package/dist/api-2n6dd2ws.js +33 -0
  6. package/dist/bridge/client.d.ts +48 -6
  7. package/dist/bridge/client.d.ts.map +1 -1
  8. package/dist/bridge/gateway-runtime.d.ts +8 -0
  9. package/dist/bridge/gateway-runtime.d.ts.map +1 -0
  10. package/dist/bridge/index.d.ts +3 -3
  11. package/dist/bridge/index.d.ts.map +1 -1
  12. package/dist/bridge/log.d.ts +5 -0
  13. package/dist/bridge/log.d.ts.map +1 -0
  14. package/dist/bridge/miniflare.d.ts +74 -1
  15. package/dist/bridge/miniflare.d.ts.map +1 -1
  16. package/dist/bridge/proxy.d.ts +11 -10
  17. package/dist/bridge/proxy.d.ts.map +1 -1
  18. package/dist/bridge/server.d.ts +2 -1
  19. package/dist/bridge/server.d.ts.map +1 -1
  20. package/dist/bridge/v2/body-streams.d.ts +53 -0
  21. package/dist/bridge/v2/body-streams.d.ts.map +1 -0
  22. package/dist/bridge/v2/codec.d.ts +106 -0
  23. package/dist/bridge/v2/codec.d.ts.map +1 -0
  24. package/dist/bridge/v2/control-messages.d.ts +51 -0
  25. package/dist/bridge/v2/control-messages.d.ts.map +1 -0
  26. package/dist/bridge/v2/frames.d.ts +109 -0
  27. package/dist/bridge/v2/frames.d.ts.map +1 -0
  28. package/dist/bridge/v2/index.d.ts +11 -0
  29. package/dist/bridge/v2/index.d.ts.map +1 -0
  30. package/dist/bridge/v2/serialization.d.ts +48 -0
  31. package/dist/bridge/v2/serialization.d.ts.map +1 -0
  32. package/dist/bridge/v2/transport.d.ts +31 -0
  33. package/dist/bridge/v2/transport.d.ts.map +1 -0
  34. package/dist/bridge/v2/value-codec.d.ts +61 -0
  35. package/dist/bridge/v2/value-codec.d.ts.map +1 -0
  36. package/dist/bridge/{serialization.d.ts → v2/value-serialization.d.ts} +40 -18
  37. package/dist/bridge/v2/value-serialization.d.ts.map +1 -0
  38. package/dist/bridge/{protocol.d.ts → v2/wire.d.ts} +28 -4
  39. package/dist/bridge/v2/wire.d.ts.map +1 -0
  40. package/dist/bridge/v2/ws-relay.d.ts +53 -0
  41. package/dist/bridge/v2/ws-relay.d.ts.map +1 -0
  42. package/dist/browser-shim/handler.d.ts +1 -1
  43. package/dist/browser-shim/handler.d.ts.map +1 -1
  44. package/dist/browser-shim/server.d.ts +63 -0
  45. package/dist/browser-shim/server.d.ts.map +1 -1
  46. package/dist/browser.d.ts +4585 -0
  47. package/dist/browser.d.ts.map +1 -0
  48. package/dist/browser.js +147 -0
  49. package/dist/build-x1fhfsgs.js +54 -0
  50. package/dist/bundler/defaults.d.ts +23 -0
  51. package/dist/bundler/defaults.d.ts.map +1 -0
  52. package/dist/bundler/do-bundler.d.ts +7 -0
  53. package/dist/bundler/do-bundler.d.ts.map +1 -1
  54. package/dist/bundler/index.d.ts +2 -0
  55. package/dist/bundler/index.d.ts.map +1 -1
  56. package/dist/bundler/rolldown-shared.d.ts +53 -0
  57. package/dist/bundler/rolldown-shared.d.ts.map +1 -0
  58. package/dist/bundler/worker-bundler.d.ts +13 -0
  59. package/dist/bundler/worker-bundler.d.ts.map +1 -0
  60. package/dist/bundler/worker-compat.d.ts +4 -0
  61. package/dist/bundler/worker-compat.d.ts.map +1 -0
  62. package/dist/cli/build-manifest.d.ts +66 -0
  63. package/dist/cli/build-manifest.d.ts.map +1 -0
  64. package/dist/cli/command-utils.d.ts +18 -0
  65. package/dist/cli/command-utils.d.ts.map +1 -0
  66. package/dist/cli/commands/account.d.ts +1 -1
  67. package/dist/cli/commands/account.d.ts.map +1 -1
  68. package/dist/cli/commands/build-artifacts.d.ts +40 -0
  69. package/dist/cli/commands/build-artifacts.d.ts.map +1 -0
  70. package/dist/cli/commands/build.d.ts.map +1 -1
  71. package/dist/cli/commands/config.d.ts +4 -0
  72. package/dist/cli/commands/config.d.ts.map +1 -0
  73. package/dist/cli/commands/deploy/metadata.d.ts +18 -0
  74. package/dist/cli/commands/deploy/metadata.d.ts.map +1 -0
  75. package/dist/cli/commands/deploy/prepare.d.ts +23 -0
  76. package/dist/cli/commands/deploy/prepare.d.ts.map +1 -0
  77. package/dist/cli/commands/deploy/runtime.d.ts +4 -0
  78. package/dist/cli/commands/deploy/runtime.d.ts.map +1 -0
  79. package/dist/cli/commands/deploy/verification.d.ts +36 -0
  80. package/dist/cli/commands/deploy/verification.d.ts.map +1 -0
  81. package/dist/cli/commands/deploy.d.ts +2 -2
  82. package/dist/cli/commands/deploy.d.ts.map +1 -1
  83. package/dist/cli/commands/dev.d.ts +8 -0
  84. package/dist/cli/commands/dev.d.ts.map +1 -1
  85. package/dist/cli/commands/doctor.d.ts.map +1 -1
  86. package/dist/cli/commands/init.d.ts.map +1 -1
  87. package/dist/cli/commands/login.d.ts +4 -0
  88. package/dist/cli/commands/login.d.ts.map +1 -0
  89. package/dist/cli/commands/previews-support/cleanup.d.ts +9 -0
  90. package/dist/cli/commands/previews-support/cleanup.d.ts.map +1 -0
  91. package/dist/cli/commands/previews-support/family.d.ts +10 -0
  92. package/dist/cli/commands/previews-support/family.d.ts.map +1 -0
  93. package/dist/cli/commands/previews-support/render.d.ts +8 -0
  94. package/dist/cli/commands/previews-support/render.d.ts.map +1 -0
  95. package/dist/cli/commands/previews-support/theme.d.ts +10 -0
  96. package/dist/cli/commands/previews-support/theme.d.ts.map +1 -0
  97. package/dist/cli/commands/previews-support/types.d.ts +70 -0
  98. package/dist/cli/commands/previews-support/types.d.ts.map +1 -0
  99. package/dist/cli/commands/previews.d.ts +4 -0
  100. package/dist/cli/commands/previews.d.ts.map +1 -0
  101. package/dist/cli/commands/productions.d.ts +4 -0
  102. package/dist/cli/commands/productions.d.ts.map +1 -0
  103. package/dist/cli/commands/secrets.d.ts +4 -0
  104. package/dist/cli/commands/secrets.d.ts.map +1 -0
  105. package/dist/cli/commands/token.d.ts +4 -0
  106. package/dist/cli/commands/token.d.ts.map +1 -0
  107. package/dist/cli/commands/type-generation/discovery.d.ts +7 -0
  108. package/dist/cli/commands/type-generation/discovery.d.ts.map +1 -0
  109. package/dist/cli/commands/type-generation/generator.d.ts +112 -0
  110. package/dist/cli/commands/type-generation/generator.d.ts.map +1 -0
  111. package/dist/cli/commands/type-generation/models.d.ts +27 -0
  112. package/dist/cli/commands/type-generation/models.d.ts.map +1 -0
  113. package/dist/cli/commands/types.d.ts.map +1 -1
  114. package/dist/cli/commands/worker.d.ts +4 -0
  115. package/dist/cli/commands/worker.d.ts.map +1 -0
  116. package/dist/cli/config-path.d.ts +6 -0
  117. package/dist/cli/config-path.d.ts.map +1 -0
  118. package/dist/cli/dependencies.d.ts +1 -0
  119. package/dist/cli/dependencies.d.ts.map +1 -1
  120. package/dist/cli/deploy-strategy.d.ts +17 -0
  121. package/dist/cli/deploy-strategy.d.ts.map +1 -0
  122. package/dist/cli/deploy-target.d.ts +17 -0
  123. package/dist/cli/deploy-target.d.ts.map +1 -0
  124. package/dist/cli/generated-artifacts.d.ts +12 -0
  125. package/dist/cli/generated-artifacts.d.ts.map +1 -0
  126. package/dist/cli/help-pages/pages/account.d.ts +3 -0
  127. package/dist/cli/help-pages/pages/account.d.ts.map +1 -0
  128. package/dist/cli/help-pages/pages/core.d.ts +4 -0
  129. package/dist/cli/help-pages/pages/core.d.ts.map +1 -0
  130. package/dist/cli/help-pages/pages/index.d.ts +3 -0
  131. package/dist/cli/help-pages/pages/index.d.ts.map +1 -0
  132. package/dist/cli/help-pages/pages/misc.d.ts +3 -0
  133. package/dist/cli/help-pages/pages/misc.d.ts.map +1 -0
  134. package/dist/cli/help-pages/pages/previews.d.ts +3 -0
  135. package/dist/cli/help-pages/pages/previews.d.ts.map +1 -0
  136. package/dist/cli/help-pages/pages/productions.d.ts +3 -0
  137. package/dist/cli/help-pages/pages/productions.d.ts.map +1 -0
  138. package/dist/cli/help-pages/render.d.ts +12 -0
  139. package/dist/cli/help-pages/render.d.ts.map +1 -0
  140. package/dist/cli/help-pages/shared.d.ts +15 -0
  141. package/dist/cli/help-pages/shared.d.ts.map +1 -0
  142. package/dist/cli/help-pages/types.d.ts +23 -0
  143. package/dist/cli/help-pages/types.d.ts.map +1 -0
  144. package/dist/cli/help.d.ts +6 -0
  145. package/dist/cli/help.d.ts.map +1 -0
  146. package/dist/cli/index.d.ts +1 -0
  147. package/dist/cli/index.d.ts.map +1 -1
  148. package/dist/cli/index.js +12 -0
  149. package/dist/cli/package-metadata.d.ts +16 -0
  150. package/dist/cli/package-metadata.d.ts.map +1 -0
  151. package/dist/cli/preview-bindings.d.ts +49 -0
  152. package/dist/cli/preview-bindings.d.ts.map +1 -0
  153. package/dist/cli/preview.d.ts +10 -0
  154. package/dist/cli/preview.d.ts.map +1 -0
  155. package/dist/cli/ui.d.ts +37 -0
  156. package/dist/cli/ui.d.ts.map +1 -0
  157. package/dist/cli/workspace-build-guard.d.ts +14 -0
  158. package/dist/cli/workspace-build-guard.d.ts.map +1 -0
  159. package/dist/cloudflare/account-core.d.ts +6 -0
  160. package/dist/cloudflare/account-core.d.ts.map +1 -0
  161. package/dist/cloudflare/account-resources.d.ts +40 -0
  162. package/dist/cloudflare/account-resources.d.ts.map +1 -0
  163. package/dist/cloudflare/account-status.d.ts +11 -0
  164. package/dist/cloudflare/account-status.d.ts.map +1 -0
  165. package/dist/cloudflare/account-workers.d.ts +14 -0
  166. package/dist/cloudflare/account-workers.d.ts.map +1 -0
  167. package/dist/cloudflare/account.d.ts +7 -64
  168. package/dist/cloudflare/account.d.ts.map +1 -1
  169. package/dist/cloudflare/api.d.ts +71 -3
  170. package/dist/cloudflare/api.d.ts.map +1 -1
  171. package/dist/cloudflare/auth.d.ts.map +1 -1
  172. package/dist/cloudflare/index.d.ts +57 -2
  173. package/dist/cloudflare/index.d.ts.map +1 -1
  174. package/dist/cloudflare/index.js +49 -2
  175. package/dist/cloudflare/known-permission-group-ids.generated.d.ts +10 -0
  176. package/dist/cloudflare/known-permission-group-ids.generated.d.ts.map +1 -0
  177. package/dist/cloudflare/kv-namespace.d.ts +4 -0
  178. package/dist/cloudflare/kv-namespace.d.ts.map +1 -0
  179. package/dist/cloudflare/preferences.d.ts +7 -0
  180. package/dist/cloudflare/preferences.d.ts.map +1 -1
  181. package/dist/cloudflare/preview-registry-cache.d.ts +6 -0
  182. package/dist/cloudflare/preview-registry-cache.d.ts.map +1 -0
  183. package/dist/cloudflare/preview-registry-inference.d.ts +14 -0
  184. package/dist/cloudflare/preview-registry-inference.d.ts.map +1 -0
  185. package/dist/cloudflare/preview-registry-records.d.ts +4 -0
  186. package/dist/cloudflare/preview-registry-records.d.ts.map +1 -0
  187. package/dist/cloudflare/preview-registry-shape.d.ts +47 -0
  188. package/dist/cloudflare/preview-registry-shape.d.ts.map +1 -0
  189. package/dist/cloudflare/preview-registry-store.d.ts +14 -0
  190. package/dist/cloudflare/preview-registry-store.d.ts.map +1 -0
  191. package/dist/cloudflare/preview-registry-transport.d.ts +4 -0
  192. package/dist/cloudflare/preview-registry-transport.d.ts.map +1 -0
  193. package/dist/cloudflare/preview-registry-types.d.ts +103 -0
  194. package/dist/cloudflare/preview-registry-types.d.ts.map +1 -0
  195. package/dist/cloudflare/preview-registry.d.ts +42 -0
  196. package/dist/cloudflare/preview-registry.d.ts.map +1 -0
  197. package/dist/cloudflare/preview-urls.d.ts +3 -0
  198. package/dist/cloudflare/preview-urls.d.ts.map +1 -0
  199. package/dist/cloudflare/registry-schema.d.ts +253 -0
  200. package/dist/cloudflare/registry-schema.d.ts.map +1 -0
  201. package/dist/cloudflare/tokens.d.ts +44 -0
  202. package/dist/cloudflare/tokens.d.ts.map +1 -0
  203. package/dist/cloudflare/types.d.ts +124 -7
  204. package/dist/cloudflare/types.d.ts.map +1 -1
  205. package/dist/cloudflare/usage.d.ts +30 -2
  206. package/dist/cloudflare/usage.d.ts.map +1 -1
  207. package/dist/config/binding-resolution-helpers.d.ts +41 -0
  208. package/dist/config/binding-resolution-helpers.d.ts.map +1 -0
  209. package/dist/config/compatibility.d.ts +3 -0
  210. package/dist/config/compatibility.d.ts.map +1 -0
  211. package/dist/config/compiler/bindings.d.ts +14 -0
  212. package/dist/config/compiler/bindings.d.ts.map +1 -0
  213. package/dist/config/compiler/core-helpers.d.ts +6 -0
  214. package/dist/config/compiler/core-helpers.d.ts.map +1 -0
  215. package/dist/config/compiler/do-workers.d.ts +34 -0
  216. package/dist/config/compiler/do-workers.d.ts.map +1 -0
  217. package/dist/config/compiler/paths.d.ts +18 -0
  218. package/dist/config/compiler/paths.d.ts.map +1 -0
  219. package/dist/config/compiler/types.d.ts +267 -0
  220. package/dist/config/compiler/types.d.ts.map +1 -0
  221. package/dist/config/compiler.d.ts +22 -134
  222. package/dist/config/compiler.d.ts.map +1 -1
  223. package/dist/config/define.d.ts +7 -4
  224. package/dist/config/define.d.ts.map +1 -1
  225. package/dist/config/deploy-resources.d.ts +58 -0
  226. package/dist/config/deploy-resources.d.ts.map +1 -0
  227. package/dist/config/env-vars.d.ts +309 -0
  228. package/dist/config/env-vars.d.ts.map +1 -0
  229. package/dist/config/framework-providers.d.ts +9 -0
  230. package/dist/config/framework-providers.d.ts.map +1 -0
  231. package/dist/config/index.d.ts +12 -5
  232. package/dist/config/index.d.ts.map +1 -1
  233. package/dist/config/loader.d.ts +1 -0
  234. package/dist/config/loader.d.ts.map +1 -1
  235. package/dist/config/local-dev-vars.d.ts +15 -0
  236. package/dist/config/local-dev-vars.d.ts.map +1 -0
  237. package/dist/config/preview-resources.d.ts +83 -0
  238. package/dist/config/preview-resources.d.ts.map +1 -0
  239. package/dist/config/preview.d.ts +31 -0
  240. package/dist/config/preview.d.ts.map +1 -0
  241. package/dist/config/ref.d.ts +14 -23
  242. package/dist/config/ref.d.ts.map +1 -1
  243. package/dist/config/resolve-phased.d.ts +72 -0
  244. package/dist/config/resolve-phased.d.ts.map +1 -0
  245. package/dist/config/resolve.d.ts +11 -0
  246. package/dist/config/resolve.d.ts.map +1 -0
  247. package/dist/config/resource-resolution.d.ts +80 -0
  248. package/dist/config/resource-resolution.d.ts.map +1 -0
  249. package/dist/config/schema-bindings.d.ts +1495 -0
  250. package/dist/config/schema-bindings.d.ts.map +1 -0
  251. package/dist/config/schema-build.d.ts +67 -0
  252. package/dist/config/schema-build.d.ts.map +1 -0
  253. package/dist/config/schema-env.d.ts +3005 -0
  254. package/dist/config/schema-env.d.ts.map +1 -0
  255. package/dist/config/schema-normalization.d.ts +184 -0
  256. package/dist/config/schema-normalization.d.ts.map +1 -0
  257. package/dist/config/schema-runtime.d.ts +500 -0
  258. package/dist/config/schema-runtime.d.ts.map +1 -0
  259. package/dist/config/schema-types-bindings-platform.d.ts +378 -0
  260. package/dist/config/schema-types-bindings-platform.d.ts.map +1 -0
  261. package/dist/config/schema-types-bindings-resources.d.ts +551 -0
  262. package/dist/config/schema-types-bindings-resources.d.ts.map +1 -0
  263. package/dist/config/schema-types-bindings.d.ts +254 -0
  264. package/dist/config/schema-types-bindings.d.ts.map +1 -0
  265. package/dist/config/schema-types-build.d.ts +86 -0
  266. package/dist/config/schema-types-build.d.ts.map +1 -0
  267. package/dist/config/schema-types-runtime.d.ts +917 -0
  268. package/dist/config/schema-types-runtime.d.ts.map +1 -0
  269. package/dist/config/schema-types.d.ts +390 -0
  270. package/dist/config/schema-types.d.ts.map +1 -0
  271. package/dist/config/schema.d.ts +4495 -2214
  272. package/dist/config/schema.d.ts.map +1 -1
  273. package/dist/config/service-bindings-validation.d.ts +36 -0
  274. package/dist/config/service-bindings-validation.d.ts.map +1 -0
  275. package/dist/config-2d6x21jn.js +105 -0
  276. package/dist/config-entry.d.ts +7 -0
  277. package/dist/config-entry.d.ts.map +1 -0
  278. package/dist/config-entry.js +16 -0
  279. package/dist/decorators/durable-object.d.ts.map +1 -1
  280. package/dist/deploy-g85w9drn.js +1066 -0
  281. package/dist/dev-server/d1-migrations.d.ts +36 -0
  282. package/dist/dev-server/d1-migrations.d.ts.map +1 -0
  283. package/dist/dev-server/dev-server-state.d.ts +59 -0
  284. package/dist/dev-server/dev-server-state.d.ts.map +1 -0
  285. package/dist/dev-server/gateway-script.d.ts +21 -0
  286. package/dist/dev-server/gateway-script.d.ts.map +1 -0
  287. package/dist/dev-server/miniflare-bindings.d.ts +59 -0
  288. package/dist/dev-server/miniflare-bindings.d.ts.map +1 -0
  289. package/dist/dev-server/miniflare-dev-config.d.ts +36 -0
  290. package/dist/dev-server/miniflare-dev-config.d.ts.map +1 -0
  291. package/dist/dev-server/miniflare-log.d.ts +20 -0
  292. package/dist/dev-server/miniflare-log.d.ts.map +1 -0
  293. package/dist/dev-server/miniflare-worker-config.d.ts +74 -0
  294. package/dist/dev-server/miniflare-worker-config.d.ts.map +1 -0
  295. package/dist/dev-server/reload-queue.d.ts +13 -0
  296. package/dist/dev-server/reload-queue.d.ts.map +1 -0
  297. package/dist/dev-server/runtime-stdio.d.ts +8 -0
  298. package/dist/dev-server/runtime-stdio.d.ts.map +1 -0
  299. package/dist/dev-server/server-startup-helpers.d.ts +84 -0
  300. package/dist/dev-server/server-startup-helpers.d.ts.map +1 -0
  301. package/dist/dev-server/server.d.ts +2 -0
  302. package/dist/dev-server/server.d.ts.map +1 -1
  303. package/dist/dev-server/vite-process.d.ts +15 -0
  304. package/dist/dev-server/vite-process.d.ts.map +1 -0
  305. package/dist/dev-server/vite-utils.d.ts +19 -1
  306. package/dist/dev-server/vite-utils.d.ts.map +1 -1
  307. package/dist/dev-server/worker-source-watcher.d.ts +17 -0
  308. package/dist/dev-server/worker-source-watcher.d.ts.map +1 -0
  309. package/dist/dev-server/worker-surface-paths.d.ts +6 -0
  310. package/dist/dev-server/worker-surface-paths.d.ts.map +1 -0
  311. package/dist/dev-ymkq3thq.js +2609 -0
  312. package/dist/{doctor-fmgb3d28.js → doctor-sjrcz7x9.js} +104 -35
  313. package/dist/{durable-object-t4kbb0yt.js → durable-object-v3gsnybk.js} +1 -1
  314. package/dist/env.d.ts +10 -0
  315. package/dist/env.d.ts.map +1 -1
  316. package/dist/index-0gtmnw0m.js +895 -0
  317. package/dist/index-11p28kxx.js +256 -0
  318. package/dist/index-15fpa5tx.js +232 -0
  319. package/dist/index-1d4jg11n.js +542 -0
  320. package/dist/index-2sc756r1.js +1578 -0
  321. package/dist/index-3edvz3hs.js +124 -0
  322. package/dist/index-3jme4hgw.js +1234 -0
  323. package/dist/index-467tm7r4.js +1033 -0
  324. package/dist/index-5yvpk954.js +699 -0
  325. package/dist/index-627srx16.js +45 -0
  326. package/dist/index-62b3gt2g.js +12 -0
  327. package/dist/index-6sj0v0dk.js +2284 -0
  328. package/dist/index-706k4606.js +52 -0
  329. package/dist/index-7zfv1g9m.js +147 -0
  330. package/dist/index-85yjb686.js +413 -0
  331. package/dist/index-aabgympv.js +39 -0
  332. package/dist/{index-z14anrqp.js → index-aqrwyy57.js} +93 -31
  333. package/dist/index-c4jmfzz7.js +109 -0
  334. package/dist/index-c8p4njqy.js +479 -0
  335. package/dist/index-dm9q84c7.js +360 -0
  336. package/dist/index-fjmdb57t.js +581 -0
  337. package/dist/index-g4fcnwhc.js +1205 -0
  338. package/dist/{index-18hvb6gb.js → index-gn5wy09x.js} +13 -2
  339. package/dist/index-hpwa6vsw.js +239 -0
  340. package/dist/index-mg8vwqxf.js +514 -0
  341. package/dist/index-pmeashfz.js +476 -0
  342. package/dist/{index-07q6yxyc.js → index-q8f4kawk.js} +68 -32
  343. package/dist/index-qmmqww7h.js +133 -0
  344. package/dist/{index-rbht7m9r.js → index-qwgr4q7s.js} +2 -1
  345. package/dist/index-qz6nbwpw.js +111 -0
  346. package/dist/index-sqkbyw0c.js +1428 -0
  347. package/dist/index-stgn34cr.js +148 -0
  348. package/dist/index-t9y0sve5.js +155 -0
  349. package/dist/index-thwacc28.js +74 -0
  350. package/dist/index-vhqww6tt.js +307 -0
  351. package/dist/{index-1xpj0m4r.js → index-z9gy8w6b.js} +1 -1
  352. package/dist/index-za0r01bx.js +588 -0
  353. package/dist/index-zwmphmc5.js +185 -0
  354. package/dist/index.d.ts +3 -7
  355. package/dist/index.d.ts.map +1 -1
  356. package/dist/index.js +34 -269
  357. package/dist/{init-f9mgmew3.js → init-cwpergap.js} +63 -69
  358. package/dist/login-fthspvbx.js +77 -0
  359. package/dist/previews-aa16z2hj.js +1337 -0
  360. package/dist/productions-vemjgfz0.js +505 -0
  361. package/dist/runtime/context-events.d.ts +13 -0
  362. package/dist/runtime/context-events.d.ts.map +1 -0
  363. package/dist/runtime/context-types.d.ts +82 -0
  364. package/dist/runtime/context-types.d.ts.map +1 -0
  365. package/dist/runtime/context.d.ts +20 -44
  366. package/dist/runtime/context.d.ts.map +1 -1
  367. package/dist/runtime/exports.d.ts +70 -55
  368. package/dist/runtime/exports.d.ts.map +1 -1
  369. package/dist/runtime/index.d.ts +8 -1
  370. package/dist/runtime/index.d.ts.map +1 -1
  371. package/dist/runtime/index.js +108 -99
  372. package/dist/runtime/middleware.d.ts +102 -60
  373. package/dist/runtime/middleware.d.ts.map +1 -1
  374. package/dist/runtime/router/index.d.ts +7 -0
  375. package/dist/runtime/router/index.d.ts.map +1 -0
  376. package/dist/runtime/router/types.d.ts +24 -0
  377. package/dist/runtime/router/types.d.ts.map +1 -0
  378. package/dist/runtime/validation.d.ts +17 -3
  379. package/dist/runtime/validation.d.ts.map +1 -1
  380. package/dist/secrets/local-secrets.d.ts +46 -0
  381. package/dist/secrets/local-secrets.d.ts.map +1 -0
  382. package/dist/secrets-b0x50dd1.js +91 -0
  383. package/dist/shims/local-hyperdrive.d.ts +12 -0
  384. package/dist/shims/local-hyperdrive.d.ts.map +1 -0
  385. package/dist/shims/local-media-bindings.d.ts +19 -0
  386. package/dist/shims/local-media-bindings.d.ts.map +1 -0
  387. package/dist/shims/local-worker-loader.d.ts +3 -0
  388. package/dist/shims/local-worker-loader.d.ts.map +1 -0
  389. package/dist/sveltekit/index.js +169 -75
  390. package/dist/sveltekit/local-bindings.d.ts +4 -0
  391. package/dist/sveltekit/local-bindings.d.ts.map +1 -0
  392. package/dist/sveltekit/platform.d.ts +19 -1
  393. package/dist/sveltekit/platform.d.ts.map +1 -1
  394. package/dist/test/ai-search.d.ts +39 -0
  395. package/dist/test/ai-search.d.ts.map +1 -0
  396. package/dist/test/binding-hints.d.ts +11 -0
  397. package/dist/test/binding-hints.d.ts.map +1 -0
  398. package/dist/test/cf.d.ts +35 -21
  399. package/dist/test/cf.d.ts.map +1 -1
  400. package/dist/test/containers.d.ts +87 -0
  401. package/dist/test/containers.d.ts.map +1 -0
  402. package/dist/test/email.d.ts +16 -7
  403. package/dist/test/email.d.ts.map +1 -1
  404. package/dist/test/index.d.ts +5 -8
  405. package/dist/test/index.d.ts.map +1 -1
  406. package/dist/test/index.js +4641 -43
  407. package/dist/test/offline-bindings.d.ts +65 -0
  408. package/dist/test/offline-bindings.d.ts.map +1 -0
  409. package/dist/test/queue.d.ts.map +1 -1
  410. package/dist/test/remote-ai.d.ts.map +1 -1
  411. package/dist/test/remote-cloudflare.d.ts +13 -0
  412. package/dist/test/remote-cloudflare.d.ts.map +1 -0
  413. package/dist/test/remote-vectorize.d.ts.map +1 -1
  414. package/dist/test/resolve-service-bindings.d.ts +63 -3
  415. package/dist/test/resolve-service-bindings.d.ts.map +1 -1
  416. package/dist/test/scheduled.d.ts.map +1 -1
  417. package/dist/test/should-skip.d.ts +14 -18
  418. package/dist/test/should-skip.d.ts.map +1 -1
  419. package/dist/test/simple-context-bindings.d.ts +13 -0
  420. package/dist/test/simple-context-bindings.d.ts.map +1 -0
  421. package/dist/test/simple-context-durable-objects.d.ts +6 -0
  422. package/dist/test/simple-context-durable-objects.d.ts.map +1 -0
  423. package/dist/test/simple-context-env.d.ts +35 -0
  424. package/dist/test/simple-context-env.d.ts.map +1 -0
  425. package/dist/test/simple-context-gateway-script.d.ts +2 -0
  426. package/dist/test/simple-context-gateway-script.d.ts.map +1 -0
  427. package/dist/test/simple-context-handlers.d.ts +12 -0
  428. package/dist/test/simple-context-handlers.d.ts.map +1 -0
  429. package/dist/test/simple-context-lifecycle.d.ts +32 -0
  430. package/dist/test/simple-context-lifecycle.d.ts.map +1 -0
  431. package/dist/test/simple-context-mfconfig.d.ts +10 -0
  432. package/dist/test/simple-context-mfconfig.d.ts.map +1 -0
  433. package/dist/test/simple-context-multi-worker.d.ts +16 -0
  434. package/dist/test/simple-context-multi-worker.d.ts.map +1 -0
  435. package/dist/test/simple-context-paths.d.ts +40 -0
  436. package/dist/test/simple-context-paths.d.ts.map +1 -0
  437. package/dist/test/simple-context-runtime.d.ts +19 -0
  438. package/dist/test/simple-context-runtime.d.ts.map +1 -0
  439. package/dist/test/simple-context-startup.d.ts +11 -0
  440. package/dist/test/simple-context-startup.d.ts.map +1 -0
  441. package/dist/test/simple-context-transport.d.ts +14 -0
  442. package/dist/test/simple-context-transport.d.ts.map +1 -0
  443. package/dist/test/simple-context.d.ts +7 -26
  444. package/dist/test/simple-context.d.ts.map +1 -1
  445. package/dist/test/tail.d.ts +2 -1
  446. package/dist/test/tail.d.ts.map +1 -1
  447. package/dist/test/utilities/artifacts.d.ts +11 -0
  448. package/dist/test/utilities/artifacts.d.ts.map +1 -0
  449. package/dist/test/utilities/context.d.ts +39 -0
  450. package/dist/test/utilities/context.d.ts.map +1 -0
  451. package/dist/test/utilities/d1.d.ts +21 -0
  452. package/dist/test/utilities/d1.d.ts.map +1 -0
  453. package/dist/test/utilities/env.d.ts +40 -0
  454. package/dist/test/utilities/env.d.ts.map +1 -0
  455. package/dist/test/utilities/kv.d.ts +11 -0
  456. package/dist/test/utilities/kv.d.ts.map +1 -0
  457. package/dist/test/utilities/media.d.ts +16 -0
  458. package/dist/test/utilities/media.d.ts.map +1 -0
  459. package/dist/test/utilities/platform.d.ts +41 -0
  460. package/dist/test/utilities/platform.d.ts.map +1 -0
  461. package/dist/test/utilities/queue.d.ts +5 -0
  462. package/dist/test/utilities/queue.d.ts.map +1 -0
  463. package/dist/test/utilities/r2.d.ts +2 -0
  464. package/dist/test/utilities/r2.d.ts.map +1 -0
  465. package/dist/test/utilities/workflows.d.ts +26 -0
  466. package/dist/test/utilities/workflows.d.ts.map +1 -0
  467. package/dist/test/utilities.d.ts +10 -98
  468. package/dist/test/utilities.d.ts.map +1 -1
  469. package/dist/test/worker.d.ts +6 -0
  470. package/dist/test/worker.d.ts.map +1 -1
  471. package/dist/token-35jcdqq8.js +419 -0
  472. package/dist/transform/durable-object.d.ts.map +1 -1
  473. package/dist/transform/worker-entrypoint.d.ts +5 -0
  474. package/dist/transform/worker-entrypoint.d.ts.map +1 -1
  475. package/dist/types-03w8zkg6.js +705 -0
  476. package/dist/utils/entrypoint-discovery.d.ts +6 -3
  477. package/dist/utils/entrypoint-discovery.d.ts.map +1 -1
  478. package/dist/utils/resolve-package.d.ts.map +1 -1
  479. package/dist/utils/send-email.d.ts +15 -0
  480. package/dist/utils/send-email.d.ts.map +1 -0
  481. package/dist/utils/send-email.js +19 -0
  482. package/dist/vite/config-file.d.ts +25 -0
  483. package/dist/vite/config-file.d.ts.map +1 -0
  484. package/dist/vite/index.d.ts +1 -0
  485. package/dist/vite/index.d.ts.map +1 -1
  486. package/dist/vite/index.js +25 -331
  487. package/dist/vite/plugin-config-hook.d.ts +28 -0
  488. package/dist/vite/plugin-config-hook.d.ts.map +1 -0
  489. package/dist/vite/plugin-context.d.ts +27 -0
  490. package/dist/vite/plugin-context.d.ts.map +1 -0
  491. package/dist/vite/plugin-durable-objects.d.ts +18 -0
  492. package/dist/vite/plugin-durable-objects.d.ts.map +1 -0
  493. package/dist/vite/plugin-programmatic.d.ts +44 -0
  494. package/dist/vite/plugin-programmatic.d.ts.map +1 -0
  495. package/dist/vite/plugin-service-bindings.d.ts +13 -0
  496. package/dist/vite/plugin-service-bindings.d.ts.map +1 -0
  497. package/dist/vite/plugin-transform.d.ts +41 -0
  498. package/dist/vite/plugin-transform.d.ts.map +1 -0
  499. package/dist/vite/plugin.d.ts +10 -41
  500. package/dist/vite/plugin.d.ts.map +1 -1
  501. package/dist/worker-55q6b8nc.js +513 -0
  502. package/dist/worker-entry/composed-worker.d.ts +7 -0
  503. package/dist/worker-entry/composed-worker.d.ts.map +1 -0
  504. package/dist/worker-entry/durable-object-discovery.d.ts +20 -0
  505. package/dist/worker-entry/durable-object-discovery.d.ts.map +1 -0
  506. package/dist/worker-entry/extensions.d.ts +5 -0
  507. package/dist/worker-entry/extensions.d.ts.map +1 -0
  508. package/dist/worker-entry/routes.d.ts +22 -0
  509. package/dist/worker-entry/routes.d.ts.map +1 -0
  510. package/dist/worker-entry/surface-paths.d.ts +26 -0
  511. package/dist/worker-entry/surface-paths.d.ts.map +1 -0
  512. package/dist/{worker-entrypoint-m9th0rg0.js → worker-entrypoint-3rmzd4c1.js} +3 -1
  513. package/dist/workflows/local-workflow-entrypoints.d.ts +7 -0
  514. package/dist/workflows/local-workflow-entrypoints.d.ts.map +1 -0
  515. package/package.json +154 -115
  516. package/dist/account-rvrj687w.js +0 -397
  517. package/dist/bridge/protocol.d.ts.map +0 -1
  518. package/dist/bridge/serialization.d.ts.map +0 -1
  519. package/dist/browser-shim/worker.d.ts +0 -14
  520. package/dist/browser-shim/worker.d.ts.map +0 -1
  521. package/dist/build-mnf6v8gd.js +0 -53
  522. package/dist/deploy-nhceck39.js +0 -70
  523. package/dist/dev-pa8dhm20.js +0 -2162
  524. package/dist/index-67qcae0f.js +0 -183
  525. package/dist/index-ep3445yc.js +0 -2225
  526. package/dist/index-gz1gndna.js +0 -307
  527. package/dist/index-hcex3rgh.js +0 -266
  528. package/dist/index-m2q41jwa.js +0 -462
  529. package/dist/index-n7rs26ft.js +0 -77
  530. package/dist/index-pf5s73n9.js +0 -1413
  531. package/dist/index-tfyxa77h.js +0 -850
  532. package/dist/index-tk6ej9dj.js +0 -94
  533. package/dist/test/bridge-context.d.ts +0 -76
  534. package/dist/test/bridge-context.d.ts.map +0 -1
  535. package/dist/test/multi-worker-context.d.ts +0 -114
  536. package/dist/test/multi-worker-context.d.ts.map +0 -1
  537. package/dist/types-5nyrz1sz.js +0 -454
@@ -0,0 +1,588 @@
1
+ // src/dev-server/miniflare-log.ts
2
+ var ANSI_ESCAPE_REGEX = /\u001B\[[0-9;]*m/g;
3
+ var COMPATIBILITY_DATE_FALLBACK_REGEX = /^The latest compatibility date supported by the installed Cloudflare Workers Runtime is "([^"]+)", but you've requested "([^"]+)"\. Falling back to "([^"]+)"\.\.\.$/;
4
+ var MINIFLARE_LOG_LEVEL_FALLBACKS = {
5
+ WARN: 2,
6
+ DEBUG: 4
7
+ };
8
+ function normalizeMiniflareMessage(message) {
9
+ return message.replace(ANSI_ESCAPE_REGEX, "").replace(/\s+/g, " ").trim();
10
+ }
11
+ function formatCompatibilityDateFallbackNotice(message) {
12
+ const normalizedMessage = normalizeMiniflareMessage(message);
13
+ const match = COMPATIBILITY_DATE_FALLBACK_REGEX.exec(normalizedMessage);
14
+ if (!match) {
15
+ return null;
16
+ }
17
+ const [, _supportedDate, requestedDate, fallbackDate] = match;
18
+ return `Using latest supported Cloudflare Workers Runtime compatibility date ${fallbackDate} (requested ${requestedDate})`;
19
+ }
20
+ function resolveMiniflareLogLevel(logLevel, levelName) {
21
+ return logLevel?.[levelName] ?? MINIFLARE_LOG_LEVEL_FALLBACKS[levelName];
22
+ }
23
+ function createMiniflareLog(BaseLog, logLevel, levelName, logger) {
24
+ if (!BaseLog) {
25
+ return;
26
+ }
27
+ return createCompatibilityAwareMiniflareLog(BaseLog, resolveMiniflareLogLevel(logLevel, levelName), logger);
28
+ }
29
+ function createCompatibilityAwareMiniflareLog(BaseLog, level, logger) {
30
+ const log = new BaseLog(level);
31
+ const originalWarn = log.warn.bind(log);
32
+ const originalInfo = log.info.bind(log);
33
+ log.warn = (message) => {
34
+ const notice = formatCompatibilityDateFallbackNotice(message);
35
+ if (!notice) {
36
+ originalWarn(message);
37
+ return;
38
+ }
39
+ if (logger) {
40
+ logger.info(notice);
41
+ return;
42
+ }
43
+ originalInfo(notice);
44
+ };
45
+ return log;
46
+ }
47
+
48
+ // src/bridge/gateway-runtime.ts
49
+ var GATEWAY_RUNTIME_JS = `
50
+ const RAW_EMAIL = 'EmailMessage::raw'
51
+
52
+ function arrayBufferToBase64(buffer) {
53
+ const bytes = new Uint8Array(buffer)
54
+ let binary = ''
55
+ for (let i = 0; i < bytes.byteLength; i++) binary += String.fromCharCode(bytes[i])
56
+ return btoa(binary)
57
+ }
58
+
59
+ function base64ToArrayBuffer(base64) {
60
+ const binary = atob(base64)
61
+ const bytes = new Uint8Array(binary.length)
62
+ for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i)
63
+ return bytes.buffer
64
+ }
65
+
66
+ function serializeR2Object(obj) {
67
+ if (!obj) return null
68
+ return {
69
+ __type: 'R2Object',
70
+ key: obj.key,
71
+ version: obj.version,
72
+ size: obj.size,
73
+ etag: obj.etag,
74
+ httpEtag: obj.httpEtag,
75
+ checksums: obj.checksums,
76
+ uploaded: obj.uploaded?.toISOString(),
77
+ httpMetadata: obj.httpMetadata,
78
+ customMetadata: obj.customMetadata,
79
+ range: obj.range,
80
+ storageClass: obj.storageClass
81
+ }
82
+ }
83
+
84
+ function serializeR2ObjectBody(obj, bodyData) {
85
+ if (!obj) return null
86
+ return {
87
+ __type: 'R2ObjectBody',
88
+ key: obj.key,
89
+ version: obj.version,
90
+ size: obj.size,
91
+ etag: obj.etag,
92
+ httpEtag: obj.httpEtag,
93
+ checksums: obj.checksums,
94
+ uploaded: obj.uploaded?.toISOString(),
95
+ httpMetadata: obj.httpMetadata,
96
+ customMetadata: obj.customMetadata,
97
+ range: obj.range,
98
+ storageClass: obj.storageClass,
99
+ bodyData
100
+ }
101
+ }
102
+
103
+ function serializeR2Objects(result) {
104
+ if (!result) return null
105
+ return {
106
+ objects: result.objects.map(serializeR2Object),
107
+ truncated: result.truncated,
108
+ cursor: result.cursor,
109
+ delimitedPrefixes: result.delimitedPrefixes
110
+ }
111
+ }
112
+
113
+ async function serializeResponse(response) {
114
+ let body = null
115
+ if (response.body) {
116
+ const bytes = await response.arrayBuffer()
117
+ if (bytes.byteLength > 0) {
118
+ body = { type: 'bytes', data: arrayBufferToBase64(bytes) }
119
+ }
120
+ }
121
+ return {
122
+ status: response.status,
123
+ statusText: response.statusText,
124
+ headers: [...response.headers.entries()],
125
+ body
126
+ }
127
+ }
128
+
129
+ function deserializeRequest(serializedReq) {
130
+ return new Request(serializedReq.url, {
131
+ method: serializedReq.method,
132
+ headers: serializedReq.headers,
133
+ body: serializedReq.body?.type === 'bytes'
134
+ ? base64ToArrayBuffer(serializedReq.body.data)
135
+ : undefined,
136
+ redirect: serializedReq.redirect
137
+ })
138
+ }
139
+
140
+ function createEmailMessageRaw(raw) {
141
+ if (typeof raw === 'string' || raw instanceof ReadableStream) {
142
+ return raw
143
+ }
144
+ if (raw instanceof ArrayBuffer || raw instanceof Uint8Array) {
145
+ return new Response(raw).body
146
+ }
147
+ throw new Error('Unsupported EmailMessage raw payload')
148
+ }
149
+
150
+ function isDurableObjectNamespace(binding) {
151
+ return !!binding
152
+ && typeof binding.idFromName === 'function'
153
+ && typeof binding.idFromString === 'function'
154
+ && typeof binding.newUniqueId === 'function'
155
+ }
156
+
157
+ /**
158
+ * Resolve a (possibly jurisdiction-scoped) DurableObjectNamespace.
159
+ * Forwards the jurisdiction faithfully when the binding supports it
160
+ * (real Cloudflare), and degrades to the plain binding otherwise
161
+ * (miniflare/workerd local emulation, which does not pin jurisdictions).
162
+ */
163
+ function resolveDoNamespace(binding, jurisdiction) {
164
+ if (jurisdiction && typeof binding.jurisdiction === 'function') {
165
+ return binding.jurisdiction(jurisdiction)
166
+ }
167
+ return binding
168
+ }
169
+
170
+ /**
171
+ * Execute an RPC method against the gateway's bindings.
172
+ *
173
+ * Method format: "binding.operation". Operations must be namespaced by
174
+ * binding kind (e.g. "kv.get", "r2.head", "d1.stmt.first", "do.fetch",
175
+ * "service.fetch", "queue.send", "email.send", "ai.run"). Bare verbs and the legacy
176
+ * "stmt.*" / "stub.*" sub-prefixes were removed in B3-final and now throw.
177
+ * Method vocabulary must stay in sync with the canonical server in
178
+ * src/bridge/server.ts.
179
+ */
180
+ async function executeRpcMethod(method, params, env, _ctx) {
181
+ const parts = method.split('.')
182
+ if (parts.length < 2) throw new Error('Invalid method format: ' + method)
183
+
184
+ const bindingName = parts[0]
185
+ const operation = parts.slice(1).join('.')
186
+ const binding = env[bindingName]
187
+
188
+ if (!binding) throw new Error('Binding not found: ' + bindingName)
189
+
190
+ const isNamespaced =
191
+ operation.indexOf('kv.') === 0 ||
192
+ operation.indexOf('r2.') === 0 ||
193
+ operation.indexOf('d1.') === 0 ||
194
+ operation.indexOf('do.') === 0 ||
195
+ operation.indexOf('service.') === 0 ||
196
+ operation.indexOf('queue.') === 0 ||
197
+ operation.indexOf('email.') === 0 ||
198
+ operation.indexOf('ai.') === 0 ||
199
+ operation.indexOf('workflow.') === 0 ||
200
+ operation.indexOf('var.') === 0
201
+ if (!isNamespaced) {
202
+ throw new Error(createUnsupportedBridgeOperationErrorMessage(bindingName, operation))
203
+ }
204
+
205
+ // KV
206
+ if (operation === 'kv.get') return binding.get(params[0], params[1])
207
+ if (operation === 'kv.put') return binding.put(params[0], params[1], params[2])
208
+ if (operation === 'kv.delete') return binding.delete(params[0])
209
+ if (operation === 'kv.list') return binding.list(params[0])
210
+ if (operation === 'kv.getWithMetadata') return binding.getWithMetadata(params[0], params[1])
211
+
212
+ // DO get (returns DOStub reference)
213
+ if (operation === 'do.get') {
214
+ return { __type: 'DOStub', binding: bindingName, id: params[0] }
215
+ }
216
+
217
+ // R2
218
+ if (operation === 'r2.head') return serializeR2Object(await binding.head(params[0]))
219
+ if (operation === 'r2.get') {
220
+ const obj = await binding.get(params[0], params[1])
221
+ if (!obj) return null
222
+ const body = await obj.arrayBuffer()
223
+ return serializeR2ObjectBody(obj, arrayBufferToBase64(body))
224
+ }
225
+ if (operation === 'r2.put') {
226
+ let value = params[1]
227
+ if (value && typeof value === 'object') {
228
+ if (value.__type === 'ArrayBuffer' || value.__type === 'Uint8Array') {
229
+ value = base64ToArrayBuffer(value.data)
230
+ }
231
+ }
232
+ return serializeR2Object(await binding.put(params[0], value, params[2]))
233
+ }
234
+ if (operation === 'r2.delete') return binding.delete(params[0])
235
+ if (operation === 'r2.list') return serializeR2Objects(await binding.list(params[0]))
236
+
237
+ // D1
238
+ if (operation === 'd1.exec') return binding.exec(params[0])
239
+ if (operation === 'd1.batch') {
240
+ const statements = params[0].map((s) => binding.prepare(s.sql).bind(...(s.bindings || [])))
241
+ return binding.batch(statements)
242
+ }
243
+ if (operation.indexOf('d1.stmt.') === 0) {
244
+ const mode = operation.split('.')[2]
245
+ const [sql, ...rest] = params
246
+ let bindings = rest
247
+ let extraParam
248
+ if (mode === 'first' || mode === 'raw') {
249
+ extraParam = rest[rest.length - 1]
250
+ bindings = rest.slice(0, -1)
251
+ }
252
+ let stmt = binding.prepare(sql)
253
+ if (bindings.length > 0) stmt = stmt.bind(...bindings)
254
+ if (mode === 'first') {
255
+ if (typeof extraParam === 'string' && extraParam.length > 0) return stmt.first(extraParam)
256
+ return stmt.first()
257
+ }
258
+ if (mode === 'all') return stmt.all()
259
+ if (mode === 'run') return stmt.run()
260
+ if (mode === 'raw') return stmt.raw(extraParam)
261
+ throw new Error('Unknown stmt mode: ' + mode)
262
+ }
263
+
264
+ // Durable Objects
265
+ if (operation === 'do.idFromName') {
266
+ const ns = resolveDoNamespace(binding, params[1])
267
+ const id = ns.idFromName(params[0])
268
+ return { __type: 'DOId', hex: id.toString() }
269
+ }
270
+ if (operation === 'do.idFromString') {
271
+ const id = binding.idFromString(params[0])
272
+ return { __type: 'DOId', hex: id.toString() }
273
+ }
274
+ if (operation === 'do.newUniqueId') {
275
+ const ns = resolveDoNamespace(binding, params[1])
276
+ const id = ns.newUniqueId(params[0])
277
+ return { __type: 'DOId', hex: id.toString() }
278
+ }
279
+ if (operation === 'do.fetch') {
280
+ const [, serializedId, serializedReq] = params
281
+ const id = binding.idFromString(serializedId.hex)
282
+ const stub = binding.get(id)
283
+ const response = await stub.fetch(new Request(serializedReq.url, {
284
+ method: serializedReq.method,
285
+ headers: serializedReq.headers,
286
+ body: serializedReq.body?.type === 'bytes'
287
+ ? base64ToArrayBuffer(serializedReq.body.data)
288
+ : undefined
289
+ }))
290
+ return serializeResponse(response)
291
+ }
292
+ if (operation === 'do.rpc') {
293
+ const [, serializedId, methodName, args] = params
294
+ const id = binding.idFromString(serializedId.hex)
295
+ const stub = binding.get(id)
296
+ const response = await stub.fetch(new Request('http://do/_rpc', {
297
+ method: 'POST',
298
+ headers: { 'Content-Type': 'application/json' },
299
+ body: JSON.stringify({ method: methodName, params: args })
300
+ }))
301
+ const result = await response.json()
302
+ if (!result.ok) throw new Error(result.error?.message || 'RPC failed')
303
+ return result.result
304
+ }
305
+
306
+ // Service Bindings
307
+ if (operation === 'service.fetch') {
308
+ if (!binding || typeof binding.fetch !== 'function') {
309
+ throw new Error('Service binding ' + bindingName + ' does not support fetch()')
310
+ }
311
+ const response = await binding.fetch(deserializeRequest(params[0]))
312
+ return serializeResponse(response)
313
+ }
314
+ if (operation === 'service.rpc') {
315
+ const methodName = params[0]
316
+ if (typeof methodName !== 'string') {
317
+ throw new Error('Service binding ' + bindingName + ' RPC method name must be a string')
318
+ }
319
+ const args = Array.isArray(params[1]) ? params[1] : []
320
+ const method = binding && binding[methodName]
321
+ if (typeof method !== 'function') {
322
+ throw new Error('Service binding ' + bindingName + ' does not support ' + methodName + '()')
323
+ }
324
+ return method.apply(binding, args)
325
+ }
326
+
327
+ // Queues
328
+ if (operation === 'queue.send') return binding.send(params[0], params[1])
329
+ if (operation === 'queue.sendBatch') return binding.sendBatch(params[0], params[1])
330
+
331
+ // Send Email
332
+ if (operation === 'email.send') {
333
+ if (binding && typeof binding.send === 'function') {
334
+ const message = params[0]
335
+ if (message && typeof message === 'object' && 'from' in message && 'to' in message && 'raw' in message) {
336
+ return binding.send({
337
+ from: message.from,
338
+ to: message.to,
339
+ [RAW_EMAIL]: createEmailMessageRaw(message.raw)
340
+ })
341
+ }
342
+ return binding.send(message)
343
+ }
344
+ return { ok: true, simulated: true }
345
+ }
346
+
347
+ // Workflows
348
+ if (operation === 'workflow.create') {
349
+ return serializeWorkflowInstance(await binding.create(params[0]))
350
+ }
351
+ if (operation === 'workflow.get') {
352
+ return serializeWorkflowInstance(await binding.get(params[0]))
353
+ }
354
+ if (operation === 'workflow.status') {
355
+ return (await binding.get(params[0])).status()
356
+ }
357
+ if (operation === 'workflow.pause') {
358
+ return (await binding.get(params[0])).pause()
359
+ }
360
+ if (operation === 'workflow.resume') {
361
+ return (await binding.get(params[0])).resume()
362
+ }
363
+ if (operation === 'workflow.terminate') {
364
+ return (await binding.get(params[0])).terminate()
365
+ }
366
+ if (operation === 'workflow.restart') {
367
+ return (await binding.get(params[0])).restart()
368
+ }
369
+ if (operation === 'workflow.sendEvent') {
370
+ return (await binding.get(params[0])).sendEvent(params[1])
371
+ }
372
+
373
+ // AI / generic run()
374
+ if (operation === 'ai.run') {
375
+ if (typeof binding.run !== 'function') {
376
+ throw new Error('Binding ' + bindingName + ' does not support run(): ' + method)
377
+ }
378
+ return binding.run(params[0], params[1])
379
+ }
380
+
381
+ throw new Error('Unknown operation: ' + method)
382
+ }
383
+
384
+ function createUnsupportedBridgeOperationErrorMessage(bindingName, operation) {
385
+ const base = "[devflare][bridge] Unsupported bridge operation '" + operation + "' for binding '" + bindingName + "'."
386
+ if (operation === 'fetch') {
387
+ return base + ' Devflare could not dispatch fetch() for this binding through the local bridge. '
388
+ + 'Expected Cloudflare API: env.' + bindingName + '.fetch(request). '
389
+ + 'If this came from SvelteKit platform.env, make sure the binding is declared as a service binding; '
390
+ + 'this is a Devflare local bridge issue when service bindings fall back to a bare fetch operation.'
391
+ }
392
+ if (operation === 'toString') {
393
+ return base + ' A platform.env value was coerced to a string through the bridge. '
394
+ + 'For SvelteKit local dev, declared vars should be plain string values and missing env names should read as undefined.'
395
+ }
396
+ return base + ' Bare verbs and the legacy stmt.*/stub.* sub-prefixes are not supported; '
397
+ + 'use the namespaced form (e.g. kv.get, r2.put, d1.stmt.first, do.fetch, service.fetch).'
398
+ }
399
+
400
+ function serializeWorkflowInstance(instance) {
401
+ return {
402
+ __type: 'WorkflowInstance',
403
+ id: instance.id
404
+ }
405
+ }
406
+
407
+ // ---------------------------------------------------------------------------
408
+ // WebSocket bridge (shared with src/bridge/server.ts in shape)
409
+ // ---------------------------------------------------------------------------
410
+ // NOTE: wsProxies is intentionally created per handleBridgeWebSocket call so
411
+ // state never leaks across connections or across gateway-script regenerations.
412
+
413
+ async function handleBridgeRpcCall(msg, ws, env, ctx) {
414
+ try {
415
+ const result = await executeRpcMethod(msg.method, msg.params, env, ctx)
416
+ ws.send(JSON.stringify({ t: 'rpc.ok', id: msg.id, result }))
417
+ } catch (error) {
418
+ ws.send(JSON.stringify({
419
+ t: 'rpc.err',
420
+ id: msg.id,
421
+ error: {
422
+ code: error?.code || 'INTERNAL_ERROR',
423
+ message: error?.message || String(error)
424
+ }
425
+ }))
426
+ }
427
+ }
428
+
429
+ async function handleBridgeWsOpen(msg, ws, env, wsProxies) {
430
+ try {
431
+ const binding = env[msg.target.binding]
432
+ const id = binding.idFromString(msg.target.id)
433
+ const stub = binding.get(id)
434
+
435
+ const headers = new Headers(msg.target.headers || [])
436
+ headers.set('Upgrade', 'websocket')
437
+
438
+ const response = await stub.fetch(new Request(msg.target.url, { method: 'GET', headers }))
439
+ const doWs = response.webSocket
440
+
441
+ if (!doWs) {
442
+ ws.send(JSON.stringify({
443
+ t: 'rpc.err',
444
+ id: 'ws_' + msg.wid,
445
+ error: { code: 'WS_FAILED', message: 'No WebSocket returned' }
446
+ }))
447
+ return
448
+ }
449
+
450
+ doWs.accept()
451
+ wsProxies.set(msg.wid, { doWs })
452
+
453
+ doWs.addEventListener('message', (event) => {
454
+ const isText = typeof event.data === 'string'
455
+ const data = isText ? event.data : arrayBufferToBase64(event.data)
456
+ ws.send(JSON.stringify({ t: 'ws.data', wid: msg.wid, data, isText }))
457
+ })
458
+
459
+ doWs.addEventListener('close', (event) => {
460
+ ws.send(JSON.stringify({ t: 'ws.close', wid: msg.wid, code: event.code, reason: event.reason }))
461
+ wsProxies.delete(msg.wid)
462
+ })
463
+
464
+ ws.send(JSON.stringify({ t: 'ws.opened', wid: msg.wid }))
465
+ } catch (error) {
466
+ ws.send(JSON.stringify({
467
+ t: 'rpc.err',
468
+ id: 'ws_' + msg.wid,
469
+ error: { code: 'WS_FAILED', message: error.message }
470
+ }))
471
+ }
472
+ }
473
+
474
+ function handleBridgeWsClose(msg, wsProxies) {
475
+ const proxy = wsProxies.get(msg.wid)
476
+ if (proxy) {
477
+ proxy.doWs.close(msg.code, msg.reason)
478
+ wsProxies.delete(msg.wid)
479
+ }
480
+ }
481
+
482
+ async function handleBridgeJsonMessage(data, ws, env, ctx, wsProxies) {
483
+ const msg = JSON.parse(data)
484
+ switch (msg.t) {
485
+ case 'hello':
486
+ // v2 handshake — acknowledge with welcome echoing the negotiated
487
+ // capability intersection. Capabilities advertised by the gateway
488
+ // are kept in sync with src/bridge/client.ts (BRIDGE_CLIENT_CAPABILITIES).
489
+ ws.send(JSON.stringify({
490
+ t: 'welcome',
491
+ protocolVersion: 2,
492
+ capabilities: ['streams', 'ws-relay', 'http-transfer']
493
+ .filter((c) => Array.isArray(msg.capabilities) && msg.capabilities.includes(c))
494
+ .sort()
495
+ }))
496
+ break
497
+ case 'rpc.call':
498
+ await handleBridgeRpcCall(msg, ws, env, ctx)
499
+ break
500
+ case 'ws.open':
501
+ await handleBridgeWsOpen(msg, ws, env, wsProxies)
502
+ break
503
+ case 'ws.close':
504
+ handleBridgeWsClose(msg, wsProxies)
505
+ break
506
+ }
507
+ }
508
+
509
+ function handleBridgeWebSocket(request, env, ctx) {
510
+ const { 0: client, 1: server } = new WebSocketPair()
511
+ server.accept()
512
+
513
+ // Per-connection state: recreated for every bridge client so reloads and
514
+ // concurrent clients never share WS proxy entries.
515
+ const wsProxies = new Map()
516
+
517
+ server.addEventListener('message', async (event) => {
518
+ try {
519
+ if (typeof event.data === 'string') {
520
+ await handleBridgeJsonMessage(event.data, server, env, ctx, wsProxies)
521
+ }
522
+ } catch (error) {
523
+ console.error('[Gateway] Error:', error)
524
+ }
525
+ })
526
+
527
+ server.addEventListener('close', () => {
528
+ for (const proxy of wsProxies.values()) {
529
+ // Best-effort cleanup: the DO-side WS may already be closed or in an
530
+ // invalid state; any throw here would abort sibling closes. Surface
531
+ // the swallowed error when DEVFLARE_DEBUG_BRIDGE is enabled.
532
+ try { proxy.doWs.close() } catch (error) {
533
+ if (globalThis.DEVFLARE_DEBUG_BRIDGE) {
534
+ console.warn('[devflare:bridge] proxy.doWs.close() failed', error)
535
+ }
536
+ }
537
+ }
538
+ wsProxies.clear()
539
+ })
540
+
541
+ return new Response(null, { status: 101, webSocket: client })
542
+ }
543
+
544
+ // ---------------------------------------------------------------------------
545
+ // HTTP transfer for R2 bodies (shared with src/bridge/server.ts in shape)
546
+ // ---------------------------------------------------------------------------
547
+
548
+ async function handleHttpTransfer(request, env, url) {
549
+ const transferIdEncoded = url.pathname.split('/').pop()
550
+ const transferId = decodeURIComponent(transferIdEncoded || '')
551
+ const [binding, ...keyParts] = transferId.split(':')
552
+ const key = keyParts.join(':')
553
+ const bucket = env[binding]
554
+
555
+ if (!bucket) return new Response('Bucket not found: ' + binding, { status: 404 })
556
+
557
+ if (request.method === 'PUT' || request.method === 'POST') {
558
+ const result = await bucket.put(key, request.body)
559
+ return new Response(JSON.stringify(serializeR2Object(result)), {
560
+ headers: { 'Content-Type': 'application/json' }
561
+ })
562
+ }
563
+
564
+ if (request.method === 'GET') {
565
+ const object = await bucket.get(key)
566
+ if (!object) return new Response('Not found', { status: 404 })
567
+ return new Response(object.body, {
568
+ headers: {
569
+ 'Content-Type': object.httpMetadata?.contentType || 'application/octet-stream',
570
+ 'Content-Length': String(object.size)
571
+ }
572
+ })
573
+ }
574
+
575
+ return new Response('Method not allowed', { status: 405 })
576
+ }
577
+ `;
578
+
579
+ // src/bridge/miniflare.ts
580
+ function isIgnorableMiniflareDisposeError(error) {
581
+ if (!(error instanceof Error)) {
582
+ return false;
583
+ }
584
+ const details = error;
585
+ return details.code === "EBADF" && details.syscall === "kill";
586
+ }
587
+
588
+ export { createMiniflareLog, GATEWAY_RUNTIME_JS, isIgnorableMiniflareDisposeError };