devflare 1.0.0-next.7 → 1.0.0-next.71

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 (635) hide show
  1. package/LICENSE +21 -0
  2. package/LLM.md +17316 -2144
  3. package/README.md +398 -607
  4. package/bin/devflare.js +30 -14
  5. package/dist/_chunks/account-B9ULT9HA.js +462 -0
  6. package/dist/_chunks/account-resources-BdKj8q1h.js +159 -0
  7. package/dist/_chunks/ai-DKDn1iys.js +322 -0
  8. package/dist/_chunks/api-BKClUlUf.js +568 -0
  9. package/dist/_chunks/build-B9jQtUny.js +24 -0
  10. package/dist/_chunks/build-artifacts-C7AbI34o.js +484 -0
  11. package/dist/_chunks/cli-CBRR2-Xr.js +1214 -0
  12. package/dist/_chunks/cloudflare-D_5UWT84.js +157 -0
  13. package/dist/_chunks/colors-D0NVzAFN.js +13 -0
  14. package/dist/_chunks/command-utils-qlsHELwW.js +45 -0
  15. package/dist/_chunks/compiler-UxXQgEPq.js +521 -0
  16. package/dist/_chunks/config-CHdi5-5R.js +78 -0
  17. package/dist/_chunks/config-path-DzZbchb6.js +42 -0
  18. package/dist/_chunks/context-DGMev2AF.js +2515 -0
  19. package/dist/_chunks/decorators-eXNZ1S0N.js +19 -0
  20. package/dist/_chunks/dependencies-HLIhxbIe.js +57 -0
  21. package/dist/_chunks/deploy-dIZuouRW.js +1033 -0
  22. package/dist/_chunks/dev-CRW_hBA3.js +953 -0
  23. package/dist/_chunks/doctor-t8hKA53t.js +219 -0
  24. package/dist/_chunks/durable-object-DuMPM8re.js +234 -0
  25. package/dist/_chunks/env-D4uJqqgu.js +125 -0
  26. package/dist/_chunks/family-DHkROYgX.js +143 -0
  27. package/dist/_chunks/generated-artifacts-D_VIzDOi.js +31 -0
  28. package/dist/_chunks/generated-dir-DC2kM-mt.js +33 -0
  29. package/dist/_chunks/glob-DRw9sbfF.js +56 -0
  30. package/dist/_chunks/init-B9_QIZcO.js +165 -0
  31. package/dist/_chunks/loader-BC0skbnH.js +1330 -0
  32. package/dist/_chunks/local-dev-vars-BFLS-HoI.js +81 -0
  33. package/dist/_chunks/local-hyperdrive-CcORzo76.js +119 -0
  34. package/dist/_chunks/local-media-bindings-ZQe-epuw.js +335 -0
  35. package/dist/_chunks/local-secrets-C0n5oRgI.js +123 -0
  36. package/dist/_chunks/login-Ctw59McM.js +51 -0
  37. package/dist/_chunks/package-metadata-CLI488gB.js +39 -0
  38. package/dist/_chunks/preferences-CbYERA_m.js +241 -0
  39. package/dist/_chunks/preview-j9Kbx4-G.js +462 -0
  40. package/dist/_chunks/preview-registry-CTXU4mBc.js +1186 -0
  41. package/dist/_chunks/preview-resources-BNvfkfqP.js +359 -0
  42. package/dist/_chunks/previews-DXlf8SaQ.js +1133 -0
  43. package/dist/_chunks/productions-TkIy7b1Q.js +504 -0
  44. package/dist/_chunks/r2-presign-runtime-DlgH_FY8.js +291 -0
  45. package/dist/_chunks/ref-CYJNAAe_.js +178 -0
  46. package/dist/_chunks/remote-DB8SU7ea.js +79 -0
  47. package/dist/_chunks/remote-config-Bw6qIVM4.js +132 -0
  48. package/dist/_chunks/resolve-package-DeJUGxoE.js +152 -0
  49. package/dist/_chunks/rolldown-runtime-CvQ6eiug.js +14 -0
  50. package/dist/_chunks/routes-CRXB3-iw.js +851 -0
  51. package/dist/_chunks/runtime-BlKTWIgD.js +874 -0
  52. package/dist/_chunks/schema-normalization-CTdiY17P.js +667 -0
  53. package/dist/_chunks/secrets-CzSWX4-i.js +95 -0
  54. package/dist/_chunks/tail-DXKaqcPB.js +239 -0
  55. package/dist/_chunks/token-CEIRtse8.js +333 -0
  56. package/dist/_chunks/tokens-CE7-gV5E.js +221 -0
  57. package/dist/_chunks/types-BB15NBqw.js +484 -0
  58. package/dist/_chunks/ui-BhCdDC2N.js +103 -0
  59. package/dist/_chunks/usage-rRusKejc.js +272 -0
  60. package/dist/_chunks/vite-DTz2Pbtm.js +1267 -0
  61. package/dist/_chunks/vite-process-BhGXJ764.js +2928 -0
  62. package/dist/_chunks/vite-utils-D_VR07Ks.js +183 -0
  63. package/dist/_chunks/worker-CgIvLp-D.js +410 -0
  64. package/dist/_chunks/worker-bundler-CeMqQtBQ.js +457 -0
  65. package/dist/_chunks/worker-entrypoint-C8j23t6d.js +247 -0
  66. package/dist/_chunks/workerName-kEXwmV2m.js +23 -0
  67. package/dist/_chunks/workspace-CbollZBv.js +518 -0
  68. package/dist/_chunks/workspace-Ds3xMjOE.js +175 -0
  69. package/dist/bridge/client.d.ts +93 -8
  70. package/dist/bridge/client.d.ts.map +1 -1
  71. package/dist/bridge/do-rpc-dispatch.d.ts +23 -0
  72. package/dist/bridge/do-rpc-dispatch.d.ts.map +1 -0
  73. package/dist/bridge/do-websocket-connect.d.ts +33 -0
  74. package/dist/bridge/do-websocket-connect.d.ts.map +1 -0
  75. package/dist/bridge/gateway-runtime.d.ts +8 -0
  76. package/dist/bridge/gateway-runtime.d.ts.map +1 -0
  77. package/dist/bridge/index.d.ts +6 -6
  78. package/dist/bridge/index.d.ts.map +1 -1
  79. package/dist/bridge/log.d.ts +5 -0
  80. package/dist/bridge/log.d.ts.map +1 -0
  81. package/dist/bridge/miniflare-gateway.d.ts +45 -0
  82. package/dist/bridge/miniflare-gateway.d.ts.map +1 -0
  83. package/dist/bridge/miniflare.d.ts +92 -2
  84. package/dist/bridge/miniflare.d.ts.map +1 -1
  85. package/dist/bridge/proxy.d.ts +12 -11
  86. package/dist/bridge/proxy.d.ts.map +1 -1
  87. package/dist/bridge/r2-presign-runtime.d.ts +9 -0
  88. package/dist/bridge/r2-presign-runtime.d.ts.map +1 -0
  89. package/dist/bridge/server.d.ts +2 -1
  90. package/dist/bridge/server.d.ts.map +1 -1
  91. package/dist/bridge/v2/body-streams.d.ts +53 -0
  92. package/dist/bridge/v2/body-streams.d.ts.map +1 -0
  93. package/dist/bridge/v2/codec.d.ts +106 -0
  94. package/dist/bridge/v2/codec.d.ts.map +1 -0
  95. package/dist/bridge/v2/control-messages.d.ts +46 -0
  96. package/dist/bridge/v2/control-messages.d.ts.map +1 -0
  97. package/dist/bridge/v2/frames.d.ts +109 -0
  98. package/dist/bridge/v2/frames.d.ts.map +1 -0
  99. package/dist/bridge/v2/index.d.ts +11 -0
  100. package/dist/bridge/v2/index.d.ts.map +1 -0
  101. package/dist/bridge/v2/serialization.d.ts +48 -0
  102. package/dist/bridge/v2/serialization.d.ts.map +1 -0
  103. package/dist/bridge/v2/transport.d.ts +31 -0
  104. package/dist/bridge/v2/transport.d.ts.map +1 -0
  105. package/dist/bridge/v2/value-codec.d.ts +61 -0
  106. package/dist/bridge/v2/value-codec.d.ts.map +1 -0
  107. package/dist/bridge/v2/value-serialization.d.ts +139 -0
  108. package/dist/bridge/v2/value-serialization.d.ts.map +1 -0
  109. package/dist/bridge/{protocol.d.ts → v2/wire.d.ts} +32 -8
  110. package/dist/bridge/v2/wire.d.ts.map +1 -0
  111. package/dist/bridge/v2/ws-relay.d.ts +53 -0
  112. package/dist/bridge/v2/ws-relay.d.ts.map +1 -0
  113. package/dist/bridge/websocket-constructor.d.ts +38 -0
  114. package/dist/bridge/websocket-constructor.d.ts.map +1 -0
  115. package/dist/browser-shim/handler.d.ts +2 -2
  116. package/dist/browser-shim/handler.d.ts.map +1 -1
  117. package/dist/browser-shim/index.d.ts +2 -2
  118. package/dist/browser-shim/server.d.ts +63 -0
  119. package/dist/browser-shim/server.d.ts.map +1 -1
  120. package/dist/browser.d.ts +5778 -43
  121. package/dist/browser.d.ts.map +1 -1
  122. package/dist/browser.js +73 -142
  123. package/dist/bundler/defaults.d.ts +23 -0
  124. package/dist/bundler/defaults.d.ts.map +1 -0
  125. package/dist/bundler/do-bundler.d.ts +7 -0
  126. package/dist/bundler/do-bundler.d.ts.map +1 -1
  127. package/dist/bundler/index.d.ts +3 -1
  128. package/dist/bundler/index.d.ts.map +1 -1
  129. package/dist/bundler/rolldown-shared.d.ts +52 -0
  130. package/dist/bundler/rolldown-shared.d.ts.map +1 -0
  131. package/dist/bundler/worker-bundler.d.ts +13 -0
  132. package/dist/bundler/worker-bundler.d.ts.map +1 -0
  133. package/dist/bundler/worker-compat.d.ts +4 -0
  134. package/dist/bundler/worker-compat.d.ts.map +1 -0
  135. package/dist/cli/build-manifest.d.ts +66 -0
  136. package/dist/cli/build-manifest.d.ts.map +1 -0
  137. package/dist/cli/command-utils.d.ts +18 -0
  138. package/dist/cli/command-utils.d.ts.map +1 -0
  139. package/dist/cli/commands/account.d.ts +2 -2
  140. package/dist/cli/commands/account.d.ts.map +1 -1
  141. package/dist/cli/commands/ai.d.ts +1 -1
  142. package/dist/cli/commands/ai.d.ts.map +1 -1
  143. package/dist/cli/commands/build-artifacts.d.ts +40 -0
  144. package/dist/cli/commands/build-artifacts.d.ts.map +1 -0
  145. package/dist/cli/commands/build.d.ts +2 -2
  146. package/dist/cli/commands/build.d.ts.map +1 -1
  147. package/dist/cli/commands/config.d.ts +4 -0
  148. package/dist/cli/commands/config.d.ts.map +1 -0
  149. package/dist/cli/commands/deploy/metadata.d.ts +18 -0
  150. package/dist/cli/commands/deploy/metadata.d.ts.map +1 -0
  151. package/dist/cli/commands/deploy/prepare.d.ts +23 -0
  152. package/dist/cli/commands/deploy/prepare.d.ts.map +1 -0
  153. package/dist/cli/commands/deploy/runtime.d.ts +4 -0
  154. package/dist/cli/commands/deploy/runtime.d.ts.map +1 -0
  155. package/dist/cli/commands/deploy/verification.d.ts +36 -0
  156. package/dist/cli/commands/deploy/verification.d.ts.map +1 -0
  157. package/dist/cli/commands/deploy.d.ts +2 -2
  158. package/dist/cli/commands/deploy.d.ts.map +1 -1
  159. package/dist/cli/commands/dev.d.ts +9 -1
  160. package/dist/cli/commands/dev.d.ts.map +1 -1
  161. package/dist/cli/commands/doctor.d.ts +2 -2
  162. package/dist/cli/commands/doctor.d.ts.map +1 -1
  163. package/dist/cli/commands/init.d.ts +2 -2
  164. package/dist/cli/commands/init.d.ts.map +1 -1
  165. package/dist/cli/commands/login.d.ts +4 -0
  166. package/dist/cli/commands/login.d.ts.map +1 -0
  167. package/dist/cli/commands/previews-support/cleanup.d.ts +9 -0
  168. package/dist/cli/commands/previews-support/cleanup.d.ts.map +1 -0
  169. package/dist/cli/commands/previews-support/family.d.ts +10 -0
  170. package/dist/cli/commands/previews-support/family.d.ts.map +1 -0
  171. package/dist/cli/commands/previews-support/render.d.ts +8 -0
  172. package/dist/cli/commands/previews-support/render.d.ts.map +1 -0
  173. package/dist/cli/commands/previews-support/theme.d.ts +10 -0
  174. package/dist/cli/commands/previews-support/theme.d.ts.map +1 -0
  175. package/dist/cli/commands/previews-support/types.d.ts +70 -0
  176. package/dist/cli/commands/previews-support/types.d.ts.map +1 -0
  177. package/dist/cli/commands/previews.d.ts +4 -0
  178. package/dist/cli/commands/previews.d.ts.map +1 -0
  179. package/dist/cli/commands/productions.d.ts +4 -0
  180. package/dist/cli/commands/productions.d.ts.map +1 -0
  181. package/dist/cli/commands/remote.d.ts +1 -1
  182. package/dist/cli/commands/remote.d.ts.map +1 -1
  183. package/dist/cli/commands/secrets.d.ts +4 -0
  184. package/dist/cli/commands/secrets.d.ts.map +1 -0
  185. package/dist/cli/commands/tail.d.ts +44 -0
  186. package/dist/cli/commands/tail.d.ts.map +1 -0
  187. package/dist/cli/commands/token.d.ts +4 -0
  188. package/dist/cli/commands/token.d.ts.map +1 -0
  189. package/dist/cli/commands/type-generation/discovery.d.ts +7 -0
  190. package/dist/cli/commands/type-generation/discovery.d.ts.map +1 -0
  191. package/dist/cli/commands/type-generation/generator.d.ts +121 -0
  192. package/dist/cli/commands/type-generation/generator.d.ts.map +1 -0
  193. package/dist/cli/commands/type-generation/models.d.ts +27 -0
  194. package/dist/cli/commands/type-generation/models.d.ts.map +1 -0
  195. package/dist/cli/commands/types.d.ts +2 -2
  196. package/dist/cli/commands/types.d.ts.map +1 -1
  197. package/dist/cli/commands/worker.d.ts +4 -0
  198. package/dist/cli/commands/worker.d.ts.map +1 -0
  199. package/dist/cli/commands/workspace.d.ts +8 -0
  200. package/dist/cli/commands/workspace.d.ts.map +1 -0
  201. package/dist/cli/config-path.d.ts +6 -0
  202. package/dist/cli/config-path.d.ts.map +1 -0
  203. package/dist/cli/dependencies.d.ts +2 -1
  204. package/dist/cli/dependencies.d.ts.map +1 -1
  205. package/dist/cli/deploy-strategy.d.ts +17 -0
  206. package/dist/cli/deploy-strategy.d.ts.map +1 -0
  207. package/dist/cli/deploy-target.d.ts +17 -0
  208. package/dist/cli/deploy-target.d.ts.map +1 -0
  209. package/dist/cli/generated-artifacts.d.ts +12 -0
  210. package/dist/cli/generated-artifacts.d.ts.map +1 -0
  211. package/dist/cli/gradual-deploy.d.ts +49 -0
  212. package/dist/cli/gradual-deploy.d.ts.map +1 -0
  213. package/dist/cli/help-pages/pages/account.d.ts +3 -0
  214. package/dist/cli/help-pages/pages/account.d.ts.map +1 -0
  215. package/dist/cli/help-pages/pages/core.d.ts +4 -0
  216. package/dist/cli/help-pages/pages/core.d.ts.map +1 -0
  217. package/dist/cli/help-pages/pages/index.d.ts +3 -0
  218. package/dist/cli/help-pages/pages/index.d.ts.map +1 -0
  219. package/dist/cli/help-pages/pages/misc.d.ts +3 -0
  220. package/dist/cli/help-pages/pages/misc.d.ts.map +1 -0
  221. package/dist/cli/help-pages/pages/previews.d.ts +3 -0
  222. package/dist/cli/help-pages/pages/previews.d.ts.map +1 -0
  223. package/dist/cli/help-pages/pages/productions.d.ts +3 -0
  224. package/dist/cli/help-pages/pages/productions.d.ts.map +1 -0
  225. package/dist/cli/help-pages/render.d.ts +12 -0
  226. package/dist/cli/help-pages/render.d.ts.map +1 -0
  227. package/dist/cli/help-pages/shared.d.ts +15 -0
  228. package/dist/cli/help-pages/shared.d.ts.map +1 -0
  229. package/dist/cli/help-pages/types.d.ts +23 -0
  230. package/dist/cli/help-pages/types.d.ts.map +1 -0
  231. package/dist/cli/help.d.ts +6 -0
  232. package/dist/cli/help.d.ts.map +1 -0
  233. package/dist/cli/index.d.ts +1 -0
  234. package/dist/cli/index.d.ts.map +1 -1
  235. package/dist/cli/index.js +2 -0
  236. package/dist/cli/package-metadata.d.ts +16 -0
  237. package/dist/cli/package-metadata.d.ts.map +1 -0
  238. package/dist/cli/preview-bindings.d.ts +49 -0
  239. package/dist/cli/preview-bindings.d.ts.map +1 -0
  240. package/dist/cli/preview.d.ts +10 -0
  241. package/dist/cli/preview.d.ts.map +1 -0
  242. package/dist/cli/ui.d.ts +37 -0
  243. package/dist/cli/ui.d.ts.map +1 -0
  244. package/dist/cli/workspace-build-guard.d.ts +14 -0
  245. package/dist/cli/workspace-build-guard.d.ts.map +1 -0
  246. package/dist/cli/wrangler-auth.d.ts +1 -1
  247. package/dist/cloudflare/account-core.d.ts +6 -0
  248. package/dist/cloudflare/account-core.d.ts.map +1 -0
  249. package/dist/cloudflare/account-resources.d.ts +40 -0
  250. package/dist/cloudflare/account-resources.d.ts.map +1 -0
  251. package/dist/cloudflare/account-status.d.ts +11 -0
  252. package/dist/cloudflare/account-status.d.ts.map +1 -0
  253. package/dist/cloudflare/account-workers.d.ts +14 -0
  254. package/dist/cloudflare/account-workers.d.ts.map +1 -0
  255. package/dist/cloudflare/account.d.ts +7 -64
  256. package/dist/cloudflare/account.d.ts.map +1 -1
  257. package/dist/cloudflare/api.d.ts +71 -3
  258. package/dist/cloudflare/api.d.ts.map +1 -1
  259. package/dist/cloudflare/auth.d.ts +1 -1
  260. package/dist/cloudflare/auth.d.ts.map +1 -1
  261. package/dist/cloudflare/index.d.ts +61 -6
  262. package/dist/cloudflare/index.d.ts.map +1 -1
  263. package/dist/cloudflare/index.js +4 -13
  264. package/dist/cloudflare/known-permission-group-ids.generated.d.ts +10 -0
  265. package/dist/cloudflare/known-permission-group-ids.generated.d.ts.map +1 -0
  266. package/dist/cloudflare/kv-namespace.d.ts +4 -0
  267. package/dist/cloudflare/kv-namespace.d.ts.map +1 -0
  268. package/dist/cloudflare/preferences.d.ts +7 -0
  269. package/dist/cloudflare/preferences.d.ts.map +1 -1
  270. package/dist/cloudflare/preview-registry-cache.d.ts +6 -0
  271. package/dist/cloudflare/preview-registry-cache.d.ts.map +1 -0
  272. package/dist/cloudflare/preview-registry-inference.d.ts +14 -0
  273. package/dist/cloudflare/preview-registry-inference.d.ts.map +1 -0
  274. package/dist/cloudflare/preview-registry-records.d.ts +4 -0
  275. package/dist/cloudflare/preview-registry-records.d.ts.map +1 -0
  276. package/dist/cloudflare/preview-registry-shape.d.ts +47 -0
  277. package/dist/cloudflare/preview-registry-shape.d.ts.map +1 -0
  278. package/dist/cloudflare/preview-registry-store.d.ts +14 -0
  279. package/dist/cloudflare/preview-registry-store.d.ts.map +1 -0
  280. package/dist/cloudflare/preview-registry-transport.d.ts +4 -0
  281. package/dist/cloudflare/preview-registry-transport.d.ts.map +1 -0
  282. package/dist/cloudflare/preview-registry-types.d.ts +103 -0
  283. package/dist/cloudflare/preview-registry-types.d.ts.map +1 -0
  284. package/dist/cloudflare/preview-registry.d.ts +42 -0
  285. package/dist/cloudflare/preview-registry.d.ts.map +1 -0
  286. package/dist/cloudflare/preview-urls.d.ts +3 -0
  287. package/dist/cloudflare/preview-urls.d.ts.map +1 -0
  288. package/dist/cloudflare/registry-schema.d.ts +253 -0
  289. package/dist/cloudflare/registry-schema.d.ts.map +1 -0
  290. package/dist/cloudflare/remote-config.d.ts.map +1 -1
  291. package/dist/cloudflare/tokens.d.ts +44 -0
  292. package/dist/cloudflare/tokens.d.ts.map +1 -0
  293. package/dist/cloudflare/types.d.ts +124 -7
  294. package/dist/cloudflare/types.d.ts.map +1 -1
  295. package/dist/cloudflare/usage.d.ts +31 -3
  296. package/dist/cloudflare/usage.d.ts.map +1 -1
  297. package/dist/config/binding-resolution-helpers.d.ts +41 -0
  298. package/dist/config/binding-resolution-helpers.d.ts.map +1 -0
  299. package/dist/config/compatibility.d.ts +3 -0
  300. package/dist/config/compatibility.d.ts.map +1 -0
  301. package/dist/config/compiler/bindings.d.ts +14 -0
  302. package/dist/config/compiler/bindings.d.ts.map +1 -0
  303. package/dist/config/compiler/core-helpers.d.ts +6 -0
  304. package/dist/config/compiler/core-helpers.d.ts.map +1 -0
  305. package/dist/config/compiler/do-workers.d.ts +34 -0
  306. package/dist/config/compiler/do-workers.d.ts.map +1 -0
  307. package/dist/config/compiler/paths.d.ts +18 -0
  308. package/dist/config/compiler/paths.d.ts.map +1 -0
  309. package/dist/config/compiler/types.d.ts +308 -0
  310. package/dist/config/compiler/types.d.ts.map +1 -0
  311. package/dist/config/compiler.d.ts +22 -134
  312. package/dist/config/compiler.d.ts.map +1 -1
  313. package/dist/config/cron.d.ts +19 -0
  314. package/dist/config/cron.d.ts.map +1 -0
  315. package/dist/config/define.d.ts +8 -5
  316. package/dist/config/define.d.ts.map +1 -1
  317. package/dist/config/deploy-resources.d.ts +58 -0
  318. package/dist/config/deploy-resources.d.ts.map +1 -0
  319. package/dist/config/env-vars.d.ts +309 -0
  320. package/dist/config/env-vars.d.ts.map +1 -0
  321. package/dist/config/framework-providers.d.ts +9 -0
  322. package/dist/config/framework-providers.d.ts.map +1 -0
  323. package/dist/config/index.d.ts +13 -5
  324. package/dist/config/index.d.ts.map +1 -1
  325. package/dist/config/loader.d.ts +2 -1
  326. package/dist/config/loader.d.ts.map +1 -1
  327. package/dist/config/local-dev-vars.d.ts +15 -0
  328. package/dist/config/local-dev-vars.d.ts.map +1 -0
  329. package/dist/config/preview-resources.d.ts +83 -0
  330. package/dist/config/preview-resources.d.ts.map +1 -0
  331. package/dist/config/preview.d.ts +29 -0
  332. package/dist/config/preview.d.ts.map +1 -0
  333. package/dist/config/ref.d.ts +16 -25
  334. package/dist/config/ref.d.ts.map +1 -1
  335. package/dist/config/resolve-phased.d.ts +72 -0
  336. package/dist/config/resolve-phased.d.ts.map +1 -0
  337. package/dist/config/resolve.d.ts +11 -0
  338. package/dist/config/resolve.d.ts.map +1 -0
  339. package/dist/config/resource-resolution.d.ts +80 -0
  340. package/dist/config/resource-resolution.d.ts.map +1 -0
  341. package/dist/config/schema-bindings.d.ts +2124 -0
  342. package/dist/config/schema-bindings.d.ts.map +1 -0
  343. package/dist/config/schema-build.d.ts +67 -0
  344. package/dist/config/schema-build.d.ts.map +1 -0
  345. package/dist/config/schema-env.d.ts +3821 -0
  346. package/dist/config/schema-env.d.ts.map +1 -0
  347. package/dist/config/schema-normalization.d.ts +272 -0
  348. package/dist/config/schema-normalization.d.ts.map +1 -0
  349. package/dist/config/schema-runtime.d.ts +597 -0
  350. package/dist/config/schema-runtime.d.ts.map +1 -0
  351. package/dist/config/schema-types-bindings-platform.d.ts +520 -0
  352. package/dist/config/schema-types-bindings-platform.d.ts.map +1 -0
  353. package/dist/config/schema-types-bindings-resources.d.ts +802 -0
  354. package/dist/config/schema-types-bindings-resources.d.ts.map +1 -0
  355. package/dist/config/schema-types-bindings.d.ts +293 -0
  356. package/dist/config/schema-types-bindings.d.ts.map +1 -0
  357. package/dist/config/schema-types-build.d.ts +86 -0
  358. package/dist/config/schema-types-build.d.ts.map +1 -0
  359. package/dist/config/schema-types-runtime-server.d.ts +196 -0
  360. package/dist/config/schema-types-runtime-server.d.ts.map +1 -0
  361. package/dist/config/schema-types-runtime.d.ts +913 -0
  362. package/dist/config/schema-types-runtime.d.ts.map +1 -0
  363. package/dist/config/schema-types.d.ts +458 -0
  364. package/dist/config/schema-types.d.ts.map +1 -0
  365. package/dist/config/schema.d.ts +5796 -2023
  366. package/dist/config/schema.d.ts.map +1 -1
  367. package/dist/config/service-bindings-validation.d.ts +36 -0
  368. package/dist/config/service-bindings-validation.d.ts.map +1 -0
  369. package/dist/config/workspace.d.ts +282 -0
  370. package/dist/config/workspace.d.ts.map +1 -0
  371. package/dist/config-entry.d.ts +7 -0
  372. package/dist/config-entry.d.ts.map +1 -0
  373. package/dist/config-entry.js +3 -0
  374. package/dist/decorators/durable-object.d.ts.map +1 -1
  375. package/dist/decorators/index.d.ts +2 -2
  376. package/dist/decorators/index.js +2 -9
  377. package/dist/dev-server/d1-migrations.d.ts +36 -0
  378. package/dist/dev-server/d1-migrations.d.ts.map +1 -0
  379. package/dist/dev-server/dev-server-state.d.ts +59 -0
  380. package/dist/dev-server/dev-server-state.d.ts.map +1 -0
  381. package/dist/dev-server/gateway-script.d.ts +22 -0
  382. package/dist/dev-server/gateway-script.d.ts.map +1 -0
  383. package/dist/dev-server/index.d.ts +1 -1
  384. package/dist/dev-server/miniflare-bindings.d.ts +90 -0
  385. package/dist/dev-server/miniflare-bindings.d.ts.map +1 -0
  386. package/dist/dev-server/miniflare-dev-config.d.ts +57 -0
  387. package/dist/dev-server/miniflare-dev-config.d.ts.map +1 -0
  388. package/dist/dev-server/miniflare-log.d.ts +20 -0
  389. package/dist/dev-server/miniflare-log.d.ts.map +1 -0
  390. package/dist/dev-server/miniflare-worker-config.d.ts +100 -0
  391. package/dist/dev-server/miniflare-worker-config.d.ts.map +1 -0
  392. package/dist/dev-server/reload-queue.d.ts +13 -0
  393. package/dist/dev-server/reload-queue.d.ts.map +1 -0
  394. package/dist/dev-server/runtime-health.d.ts +79 -0
  395. package/dist/dev-server/runtime-health.d.ts.map +1 -0
  396. package/dist/dev-server/runtime-stdio.d.ts +8 -0
  397. package/dist/dev-server/runtime-stdio.d.ts.map +1 -0
  398. package/dist/dev-server/server-startup-helpers.d.ts +84 -0
  399. package/dist/dev-server/server-startup-helpers.d.ts.map +1 -0
  400. package/dist/dev-server/server.d.ts +2 -0
  401. package/dist/dev-server/server.d.ts.map +1 -1
  402. package/dist/dev-server/vite-process.d.ts +24 -0
  403. package/dist/dev-server/vite-process.d.ts.map +1 -0
  404. package/dist/dev-server/vite-utils.d.ts +19 -1
  405. package/dist/dev-server/vite-utils.d.ts.map +1 -1
  406. package/dist/dev-server/worker-source-watcher.d.ts +17 -0
  407. package/dist/dev-server/worker-source-watcher.d.ts.map +1 -0
  408. package/dist/dev-server/worker-surface-paths.d.ts +6 -0
  409. package/dist/dev-server/worker-surface-paths.d.ts.map +1 -0
  410. package/dist/dev-server/workspace/merge-config.d.ts +81 -0
  411. package/dist/dev-server/workspace/merge-config.d.ts.map +1 -0
  412. package/dist/dev-server/workspace/prepare-app.d.ts +84 -0
  413. package/dist/dev-server/workspace/prepare-app.d.ts.map +1 -0
  414. package/dist/dev-server/workspace/server.d.ts +47 -0
  415. package/dist/dev-server/workspace/server.d.ts.map +1 -0
  416. package/dist/env.d.ts +10 -0
  417. package/dist/env.d.ts.map +1 -1
  418. package/dist/index.d.ts +8 -12
  419. package/dist/index.d.ts.map +1 -1
  420. package/dist/index.js +10 -297
  421. package/dist/runtime/context-events.d.ts +13 -0
  422. package/dist/runtime/context-events.d.ts.map +1 -0
  423. package/dist/runtime/context-types.d.ts +82 -0
  424. package/dist/runtime/context-types.d.ts.map +1 -0
  425. package/dist/runtime/context.d.ts +20 -44
  426. package/dist/runtime/context.d.ts.map +1 -1
  427. package/dist/runtime/exports.d.ts +70 -55
  428. package/dist/runtime/exports.d.ts.map +1 -1
  429. package/dist/runtime/index.d.ts +11 -5
  430. package/dist/runtime/index.d.ts.map +1 -1
  431. package/dist/runtime/index.js +5 -184
  432. package/dist/runtime/middleware.d.ts +119 -67
  433. package/dist/runtime/middleware.d.ts.map +1 -1
  434. package/dist/runtime/r2-presign.d.ts +164 -0
  435. package/dist/runtime/r2-presign.d.ts.map +1 -0
  436. package/dist/runtime/router/index.d.ts +7 -0
  437. package/dist/runtime/router/index.d.ts.map +1 -0
  438. package/dist/runtime/router/types.d.ts +24 -0
  439. package/dist/runtime/router/types.d.ts.map +1 -0
  440. package/dist/runtime/validation.d.ts +18 -4
  441. package/dist/runtime/validation.d.ts.map +1 -1
  442. package/dist/secrets/local-secrets.d.ts +46 -0
  443. package/dist/secrets/local-secrets.d.ts.map +1 -0
  444. package/dist/shims/local-hyperdrive.d.ts +12 -0
  445. package/dist/shims/local-hyperdrive.d.ts.map +1 -0
  446. package/dist/shims/local-media-bindings.d.ts +19 -0
  447. package/dist/shims/local-media-bindings.d.ts.map +1 -0
  448. package/dist/shims/local-worker-loader.d.ts +3 -0
  449. package/dist/shims/local-worker-loader.d.ts.map +1 -0
  450. package/dist/sveltekit/index.d.ts +1 -1
  451. package/dist/sveltekit/index.d.ts.map +1 -1
  452. package/dist/sveltekit/index.js +377 -169
  453. package/dist/sveltekit/local-bindings.d.ts +4 -0
  454. package/dist/sveltekit/local-bindings.d.ts.map +1 -0
  455. package/dist/sveltekit/platform.d.ts +42 -2
  456. package/dist/sveltekit/platform.d.ts.map +1 -1
  457. package/dist/test/ai-search.d.ts +39 -0
  458. package/dist/test/ai-search.d.ts.map +1 -0
  459. package/dist/test/alarm.d.ts +55 -0
  460. package/dist/test/alarm.d.ts.map +1 -0
  461. package/dist/test/binding-hints.d.ts +10 -0
  462. package/dist/test/binding-hints.d.ts.map +1 -0
  463. package/dist/test/cf.d.ts +71 -35
  464. package/dist/test/cf.d.ts.map +1 -1
  465. package/dist/test/containers.d.ts +87 -0
  466. package/dist/test/containers.d.ts.map +1 -0
  467. package/dist/test/email.d.ts +16 -7
  468. package/dist/test/email.d.ts.map +1 -1
  469. package/dist/test/index.d.ts +20 -21
  470. package/dist/test/index.d.ts.map +1 -1
  471. package/dist/test/index.js +5115 -75
  472. package/dist/test/offline-bindings.d.ts +124 -0
  473. package/dist/test/offline-bindings.d.ts.map +1 -0
  474. package/dist/test/queue.d.ts.map +1 -1
  475. package/dist/test/remote-ai.d.ts.map +1 -1
  476. package/dist/test/remote-cloudflare.d.ts +13 -0
  477. package/dist/test/remote-cloudflare.d.ts.map +1 -0
  478. package/dist/test/remote-vectorize.d.ts.map +1 -1
  479. package/dist/test/resolve-service-bindings.d.ts +64 -4
  480. package/dist/test/resolve-service-bindings.d.ts.map +1 -1
  481. package/dist/test/scheduled.d.ts.map +1 -1
  482. package/dist/test/should-skip.d.ts +14 -18
  483. package/dist/test/should-skip.d.ts.map +1 -1
  484. package/dist/test/simple-context-bindings.d.ts +13 -0
  485. package/dist/test/simple-context-bindings.d.ts.map +1 -0
  486. package/dist/test/simple-context-durable-objects.d.ts +6 -0
  487. package/dist/test/simple-context-durable-objects.d.ts.map +1 -0
  488. package/dist/test/simple-context-env.d.ts +35 -0
  489. package/dist/test/simple-context-env.d.ts.map +1 -0
  490. package/dist/test/simple-context-gateway-script.d.ts +2 -0
  491. package/dist/test/simple-context-gateway-script.d.ts.map +1 -0
  492. package/dist/test/simple-context-handlers.d.ts +12 -0
  493. package/dist/test/simple-context-handlers.d.ts.map +1 -0
  494. package/dist/test/simple-context-lifecycle.d.ts +32 -0
  495. package/dist/test/simple-context-lifecycle.d.ts.map +1 -0
  496. package/dist/test/simple-context-mfconfig.d.ts +18 -0
  497. package/dist/test/simple-context-mfconfig.d.ts.map +1 -0
  498. package/dist/test/simple-context-multi-worker.d.ts +16 -0
  499. package/dist/test/simple-context-multi-worker.d.ts.map +1 -0
  500. package/dist/test/simple-context-paths.d.ts +40 -0
  501. package/dist/test/simple-context-paths.d.ts.map +1 -0
  502. package/dist/test/simple-context-runtime.d.ts +19 -0
  503. package/dist/test/simple-context-runtime.d.ts.map +1 -0
  504. package/dist/test/simple-context-startup.d.ts +11 -0
  505. package/dist/test/simple-context-startup.d.ts.map +1 -0
  506. package/dist/test/simple-context-transport.d.ts +14 -0
  507. package/dist/test/simple-context-transport.d.ts.map +1 -0
  508. package/dist/test/simple-context.d.ts +8 -27
  509. package/dist/test/simple-context.d.ts.map +1 -1
  510. package/dist/test/tail.d.ts +3 -2
  511. package/dist/test/tail.d.ts.map +1 -1
  512. package/dist/test/utilities/analytics-engine.d.ts +22 -0
  513. package/dist/test/utilities/analytics-engine.d.ts.map +1 -0
  514. package/dist/test/utilities/artifacts.d.ts +11 -0
  515. package/dist/test/utilities/artifacts.d.ts.map +1 -0
  516. package/dist/test/utilities/context.d.ts +39 -0
  517. package/dist/test/utilities/context.d.ts.map +1 -0
  518. package/dist/test/utilities/d1.d.ts +21 -0
  519. package/dist/test/utilities/d1.d.ts.map +1 -0
  520. package/dist/test/utilities/env.d.ts +45 -0
  521. package/dist/test/utilities/env.d.ts.map +1 -0
  522. package/dist/test/utilities/kv.d.ts +11 -0
  523. package/dist/test/utilities/kv.d.ts.map +1 -0
  524. package/dist/test/utilities/media.d.ts +16 -0
  525. package/dist/test/utilities/media.d.ts.map +1 -0
  526. package/dist/test/utilities/platform.d.ts +41 -0
  527. package/dist/test/utilities/platform.d.ts.map +1 -0
  528. package/dist/test/utilities/queue.d.ts +5 -0
  529. package/dist/test/utilities/queue.d.ts.map +1 -0
  530. package/dist/test/utilities/r2.d.ts +2 -0
  531. package/dist/test/utilities/r2.d.ts.map +1 -0
  532. package/dist/test/utilities/send-email.d.ts +27 -0
  533. package/dist/test/utilities/send-email.d.ts.map +1 -0
  534. package/dist/test/utilities/stream-flagship.d.ts +27 -0
  535. package/dist/test/utilities/stream-flagship.d.ts.map +1 -0
  536. package/dist/test/utilities/vectorize.d.ts +38 -0
  537. package/dist/test/utilities/vectorize.d.ts.map +1 -0
  538. package/dist/test/utilities/workflows.d.ts +26 -0
  539. package/dist/test/utilities/workflows.d.ts.map +1 -0
  540. package/dist/test/utilities.d.ts +14 -98
  541. package/dist/test/utilities.d.ts.map +1 -1
  542. package/dist/test/worker.d.ts +6 -0
  543. package/dist/test/worker.d.ts.map +1 -1
  544. package/dist/transform/durable-object.d.ts.map +1 -1
  545. package/dist/transform/index.d.ts +2 -2
  546. package/dist/transform/worker-entrypoint.d.ts +5 -0
  547. package/dist/transform/worker-entrypoint.d.ts.map +1 -1
  548. package/dist/utils/entrypoint-discovery.d.ts +6 -3
  549. package/dist/utils/entrypoint-discovery.d.ts.map +1 -1
  550. package/dist/utils/generated-dir.d.ts +25 -0
  551. package/dist/utils/generated-dir.d.ts.map +1 -0
  552. package/dist/utils/glob.d.ts.map +1 -1
  553. package/dist/utils/resolve-package.d.ts.map +1 -1
  554. package/dist/utils/send-email.d.ts +15 -0
  555. package/dist/utils/send-email.d.ts.map +1 -0
  556. package/dist/utils/send-email.js +163 -0
  557. package/dist/vite/config-file.d.ts +25 -0
  558. package/dist/vite/config-file.d.ts.map +1 -0
  559. package/dist/vite/index.d.ts +3 -2
  560. package/dist/vite/index.d.ts.map +1 -1
  561. package/dist/vite/index.js +2 -407
  562. package/dist/vite/plugin-config-hook.d.ts +28 -0
  563. package/dist/vite/plugin-config-hook.d.ts.map +1 -0
  564. package/dist/vite/plugin-context.d.ts +27 -0
  565. package/dist/vite/plugin-context.d.ts.map +1 -0
  566. package/dist/vite/plugin-durable-objects.d.ts +18 -0
  567. package/dist/vite/plugin-durable-objects.d.ts.map +1 -0
  568. package/dist/vite/plugin-programmatic.d.ts +44 -0
  569. package/dist/vite/plugin-programmatic.d.ts.map +1 -0
  570. package/dist/vite/plugin-service-bindings.d.ts +13 -0
  571. package/dist/vite/plugin-service-bindings.d.ts.map +1 -0
  572. package/dist/vite/plugin-transform.d.ts +41 -0
  573. package/dist/vite/plugin-transform.d.ts.map +1 -0
  574. package/dist/vite/plugin.d.ts +10 -41
  575. package/dist/vite/plugin.d.ts.map +1 -1
  576. package/dist/worker-entry/composed-worker.d.ts +5 -8
  577. package/dist/worker-entry/composed-worker.d.ts.map +1 -1
  578. package/dist/worker-entry/durable-object-discovery.d.ts +20 -0
  579. package/dist/worker-entry/durable-object-discovery.d.ts.map +1 -0
  580. package/dist/worker-entry/extensions.d.ts +5 -0
  581. package/dist/worker-entry/extensions.d.ts.map +1 -0
  582. package/dist/worker-entry/routes.d.ts +22 -0
  583. package/dist/worker-entry/routes.d.ts.map +1 -0
  584. package/dist/worker-entry/surface-paths.d.ts +26 -0
  585. package/dist/worker-entry/surface-paths.d.ts.map +1 -0
  586. package/dist/worker-entry/validate-fetch-style.d.ts +12 -0
  587. package/dist/worker-entry/validate-fetch-style.d.ts.map +1 -0
  588. package/dist/workflows/local-workflow-entrypoints.d.ts +7 -0
  589. package/dist/workflows/local-workflow-entrypoints.d.ts.map +1 -0
  590. package/package.json +160 -117
  591. package/R2.md +0 -170
  592. package/dist/account-rvrj687w.js +0 -397
  593. package/dist/ai-dx4fr9jh.js +0 -107
  594. package/dist/bridge/protocol.d.ts.map +0 -1
  595. package/dist/bridge/serialization.d.ts +0 -83
  596. package/dist/bridge/serialization.d.ts.map +0 -1
  597. package/dist/browser-shim/worker.d.ts +0 -14
  598. package/dist/browser-shim/worker.d.ts.map +0 -1
  599. package/dist/build-9myaxf07.js +0 -70
  600. package/dist/deploy-h1wz5p7m.js +0 -86
  601. package/dist/dev-rsdssknb.js +0 -2707
  602. package/dist/doctor-v7jy4s3r.js +0 -190
  603. package/dist/durable-object-t4kbb0yt.js +0 -13
  604. package/dist/index-18hvb6gb.js +0 -194
  605. package/dist/index-1xpj0m4r.js +0 -57
  606. package/dist/index-37x76zdn.js +0 -4
  607. package/dist/index-3t6rypgc.js +0 -13
  608. package/dist/index-62b3gt2g.js +0 -12
  609. package/dist/index-67qcae0f.js +0 -183
  610. package/dist/index-9ats0s83.js +0 -70
  611. package/dist/index-a0fjkq68.js +0 -198
  612. package/dist/index-a855bdsx.js +0 -18
  613. package/dist/index-ccrh4w3t.js +0 -1133
  614. package/dist/index-d8bdkx2h.js +0 -109
  615. package/dist/index-f8qh2tyh.js +0 -2152
  616. package/dist/index-gz1gndna.js +0 -307
  617. package/dist/index-hcex3rgh.js +0 -266
  618. package/dist/index-k7r18na8.js +0 -0
  619. package/dist/index-n3np2d6t.js +0 -462
  620. package/dist/index-n7rs26ft.js +0 -77
  621. package/dist/index-npc1c8jx.js +0 -44
  622. package/dist/index-p7g30wd2.js +0 -281
  623. package/dist/index-rbht7m9r.js +0 -36
  624. package/dist/index-tfyxa77h.js +0 -850
  625. package/dist/index-tk6ej9dj.js +0 -94
  626. package/dist/index-v8vvsn9x.js +0 -169
  627. package/dist/index-z14anrqp.js +0 -226
  628. package/dist/init-f9mgmew3.js +0 -186
  629. package/dist/remote-q59qk463.js +0 -97
  630. package/dist/test/bridge-context.d.ts +0 -76
  631. package/dist/test/bridge-context.d.ts.map +0 -1
  632. package/dist/test/multi-worker-context.d.ts +0 -114
  633. package/dist/test/multi-worker-context.d.ts.map +0 -1
  634. package/dist/types-wdcpnfvy.js +0 -487
  635. package/dist/worker-entrypoint-m9th0rg0.js +0 -13
@@ -0,0 +1,874 @@
1
+ import { D as createFetchEvent, b as createContextProxy, n as getContextOrNull, v as runWithEventContext } from "./context-DGMev2AF.js";
2
+ import { AwsV4Signer } from "aws4fetch";
3
+ //#region src/runtime/exports.ts
4
+ /**
5
+ * Creates a readonly proxy that throws on mutation attempts. Thin wrapper
6
+ * over {@link createContextProxy} with `mutable: false`.
7
+ */
8
+ function createReadonlyProxy(getter, name) {
9
+ return createContextProxy(getter, name, { mutable: false });
10
+ }
11
+ /**
12
+ * Access environment bindings (KV, D1, R2, etc.) and variables
13
+ *
14
+ * @remarks
15
+ * This is readonly - bindings cannot be reassigned at runtime.
16
+ * Available only within an active Devflare-managed handler or middleware call trail.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { env, type FetchEvent } from 'devflare/runtime'
21
+ *
22
+ * export async function fetch(event: FetchEvent) {
23
+ * const value = await env.MY_KV.get('key')
24
+ * const dbResult = await env.DB.prepare('SELECT * FROM users').all()
25
+ * return new Response(JSON.stringify({
26
+ * path: event.url.pathname,
27
+ * value,
28
+ * dbResult
29
+ * }))
30
+ * }
31
+ * ```
32
+ *
33
+ * @throws {ContextAccessError} When accessed outside an active Devflare-managed handler trail
34
+ */
35
+ const env = createReadonlyProxy(() => getContextOrNull()?.env, "env");
36
+ /**
37
+ * Access typed runtime variables declared with `defineConfig({ vars })`.
38
+ *
39
+ * @remarks
40
+ * This proxy reads from the active Worker environment object, just like
41
+ * {@link env}, but its type is generated from the `vars` config lane. Nested
42
+ * values are preserved, so `vars.mongo.database` works when config declares a
43
+ * nested object.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * import { vars } from 'devflare/runtime'
48
+ *
49
+ * export async function fetch() {
50
+ * return Response.json({
51
+ * database: vars.mongo.database
52
+ * })
53
+ * }
54
+ * ```
55
+ *
56
+ * @throws {ContextAccessError} When accessed outside an active Devflare-managed handler trail
57
+ */
58
+ const vars = createReadonlyProxy(() => getContextOrNull()?.env, "vars");
59
+ /**
60
+ * Access the ExecutionContext for background tasks
61
+ *
62
+ * @remarks
63
+ * Provides `waitUntil()` for background processing and
64
+ * `passThroughOnException()` for error handling on worker surfaces.
65
+ * When running inside a Durable Object, this proxy exposes the current
66
+ * `DurableObjectState` instead.
67
+ * This is readonly.
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * import { ctx, type FetchEvent } from 'devflare/runtime'
72
+ *
73
+ * export async function fetch(event: FetchEvent) {
74
+ * const response = new Response('OK')
75
+ * ctx.waitUntil(analytics.track(event.url.pathname))
76
+ * return response
77
+ * }
78
+ * ```
79
+ *
80
+ * @throws {ContextAccessError} When accessed outside an active Devflare-managed handler trail
81
+ */
82
+ const ctx = createReadonlyProxy(() => getContextOrNull()?.ctx, "ctx");
83
+ /**
84
+ * Access the current event object.
85
+ *
86
+ * @remarks
87
+ * This is the generic event proxy for the active AsyncLocalStorage context.
88
+ *
89
+ * For strong per-surface typing, prefer `getFetchEvent()`, `getQueueEvent()`,
90
+ * `getScheduledEvent()`, `getEmailEvent()`, and the Durable Object getters
91
+ * from `devflare/runtime`.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * import { event as runtimeEvent, type FetchEvent, type ScheduledEvent } from 'devflare/runtime'
96
+ *
97
+ * export async function fetch(event: FetchEvent) {
98
+ * console.log(runtimeEvent.type)
99
+ * console.log(event.url.pathname)
100
+ * }
101
+ *
102
+ * export async function scheduled(event: ScheduledEvent) {
103
+ * console.log(runtimeEvent.type)
104
+ * console.log(event.cron)
105
+ * }
106
+ * ```
107
+ *
108
+ * @throws {ContextAccessError} When accessed outside an active Devflare-managed handler trail
109
+ */
110
+ const event = createReadonlyProxy(() => getContextOrNull()?.event, "event");
111
+ /**
112
+ * Mutable request-scoped storage for sharing data between middleware
113
+ *
114
+ * @remarks
115
+ * Unlike `env` and `ctx`, locals can be mutated. Each request gets
116
+ * a fresh locals object. Use this for:
117
+ * - Authentication state
118
+ * - Parsed request data
119
+ * - Computed values shared across middleware
120
+ *
121
+ * @example
122
+ * ```ts
123
+ * import { locals, type FetchEvent } from 'devflare/runtime'
124
+ *
125
+ * // In auth middleware
126
+ * const authMiddleware = async (event: FetchEvent, next: () => Promise<Response>) => {
127
+ * locals.user = await validateToken(event.request?.headers.get('Authorization'))
128
+ * return next()
129
+ * }
130
+ *
131
+ * // In handler
132
+ * export async function fetch(event: FetchEvent) {
133
+ * void event
134
+ * console.log(locals.user)
135
+ * }
136
+ * ```
137
+ *
138
+ * @throws {ContextAccessError} When accessed outside an active Devflare-managed handler trail
139
+ */
140
+ const locals = createContextProxy(() => getContextOrNull()?.locals, "locals");
141
+ //#endregion
142
+ //#region src/runtime/middleware.ts
143
+ const FETCH_SEQUENCE_SYMBOL = Symbol.for("devflare.fetch-sequence");
144
+ const FETCH_RESOLVE_STYLE_SYMBOL = Symbol.for("devflare.fetch-resolve-style");
145
+ const FETCH_WORKER_STYLE_SYMBOL = Symbol.for("devflare.fetch-worker-style");
146
+ const QUEUE_WORKER_STYLE_SYMBOL = Symbol.for("devflare.queue-worker-style");
147
+ const SCHEDULED_WORKER_STYLE_SYMBOL = Symbol.for("devflare.scheduled-worker-style");
148
+ function createNotFoundResponse() {
149
+ return new Response("Not Found", { status: 404 });
150
+ }
151
+ function isFunction(value) {
152
+ return typeof value === "function";
153
+ }
154
+ /**
155
+ * Tag a handler as resolve-style: `(event, resolve) => Response`.
156
+ *
157
+ * Attaches `FETCH_RESOLVE_STYLE_SYMBOL` so detection survives minification
158
+ * (which rewrites parameter names and function source output).
159
+ */
160
+ function markResolveStyle(handler) {
161
+ Object.defineProperty(handler, FETCH_RESOLVE_STYLE_SYMBOL, {
162
+ value: true,
163
+ enumerable: false,
164
+ configurable: true,
165
+ writable: false
166
+ });
167
+ return handler;
168
+ }
169
+ /**
170
+ * Tag a handler as worker-style: `(request, env)` or `(request, env, ctx)`.
171
+ *
172
+ * Required for 2-argument worker-style handlers because devflare can no
173
+ * longer disambiguate `(event, resolve)` vs `(request, env)` from arity
174
+ * alone — the parameter-name fallback was removed in R1-strict.
175
+ */
176
+ function markWorkerStyle(handler) {
177
+ Object.defineProperty(handler, FETCH_WORKER_STYLE_SYMBOL, {
178
+ value: true,
179
+ enumerable: false,
180
+ configurable: true,
181
+ writable: false
182
+ });
183
+ return handler;
184
+ }
185
+ /**
186
+ * Explicit escape hatch for declaring a handler's calling convention.
187
+ *
188
+ * - `options.style === 'resolve'` marks the handler so it is dispatched as
189
+ * `(event, resolve) => Response`.
190
+ * - `options.style === 'worker'` marks the handler so it is dispatched as
191
+ * `(request, env[, ctx]) => Response`.
192
+ *
193
+ * The marker is required for 2-argument handlers; 1-arg `(event)` and
194
+ * 3-arg `(request, env, ctx)` handlers do not need to be wrapped.
195
+ */
196
+ function defineFetchHandler(handler, options) {
197
+ if (options?.style === "resolve") return markResolveStyle(handler);
198
+ if (options?.style === "worker") return markWorkerStyle(handler);
199
+ return handler;
200
+ }
201
+ function hasResolveStyleMarker(handler) {
202
+ const record = handler;
203
+ return Boolean(record[FETCH_RESOLVE_STYLE_SYMBOL] || record[FETCH_SEQUENCE_SYMBOL]);
204
+ }
205
+ function hasWorkerStyleMarker(handler) {
206
+ return Boolean(handler[FETCH_WORKER_STYLE_SYMBOL]);
207
+ }
208
+ /**
209
+ * Detect resolve-style `(event, resolve) => Response` handlers.
210
+ *
211
+ * Symbol-based only — the previous parameter-name fallback was removed in
212
+ * R1-strict. Callers that rely on a 2-argument resolve-style handler must
213
+ * wrap it with `markResolveStyle`, `defineFetchHandler({ style: 'resolve' })`,
214
+ * or compose it via `sequence(...)`.
215
+ */
216
+ function isResolveStyleFunction(handler) {
217
+ return hasResolveStyleMarker(handler);
218
+ }
219
+ /**
220
+ * Throw a clear error for ambiguous unmarked 2-argument fetch handlers.
221
+ *
222
+ * In R1-strict, devflare no longer guesses the calling convention from
223
+ * parameter names. 2-arg handlers must be marked with
224
+ * `defineFetchHandler(fn, { style: 'resolve' | 'worker' })` (or wrapped via
225
+ * `markResolveStyle` / `markWorkerStyle` / `sequence(...)`) so dispatch is
226
+ * unambiguous and minification-safe.
227
+ */
228
+ function assertExplicit2ArgStyle(handler) {
229
+ if (handler.length !== 2) return;
230
+ if (hasResolveStyleMarker(handler) || hasWorkerStyleMarker(handler)) return;
231
+ throw new Error("[devflare] Ambiguous 2-argument fetch handler. The calling convention must be declared explicitly via `defineFetchHandler(fn, { style: 'resolve' })` (for `(event, resolve) => Response`) or `defineFetchHandler(fn, { style: 'worker' })` (for `(request, env) => Response`). Single-arg `(event) => Response` and 3-arg worker-style `(request, env, ctx) => Response` handlers do not require wrapping.");
232
+ }
233
+ /**
234
+ * Tag a queue handler as worker-style: `(batch, env)` or `(batch, env, ctx)`.
235
+ *
236
+ * Required for 2-argument worker-style queue handlers because devflare can
237
+ * no longer disambiguate `(event)` vs `(batch, env)` from arity alone in
238
+ * R1-strict.
239
+ */
240
+ function defineQueueHandler(handler) {
241
+ Object.defineProperty(handler, QUEUE_WORKER_STYLE_SYMBOL, {
242
+ value: true,
243
+ enumerable: false,
244
+ configurable: true,
245
+ writable: false
246
+ });
247
+ return handler;
248
+ }
249
+ /**
250
+ * Tag a scheduled handler as worker-style: `(controller, env)` or
251
+ * `(controller, env, ctx)`.
252
+ */
253
+ function defineScheduledHandler(handler) {
254
+ Object.defineProperty(handler, SCHEDULED_WORKER_STYLE_SYMBOL, {
255
+ value: true,
256
+ enumerable: false,
257
+ configurable: true,
258
+ writable: false
259
+ });
260
+ return handler;
261
+ }
262
+ function hasQueueWorkerStyleMarker(handler) {
263
+ return Boolean(handler[QUEUE_WORKER_STYLE_SYMBOL]);
264
+ }
265
+ function hasScheduledWorkerStyleMarker(handler) {
266
+ return Boolean(handler[SCHEDULED_WORKER_STYLE_SYMBOL]);
267
+ }
268
+ /**
269
+ * Throw a clear error for ambiguous unmarked 2-argument queue handlers.
270
+ *
271
+ * Mirrors `assertExplicit2ArgStyle` for the queue surface. 2-arg handlers
272
+ * must be wrapped with `defineQueueHandler(fn)` so dispatch is unambiguous
273
+ * and minification-safe; 1-arg `(event)` and 3-arg `(batch, env, ctx)` do
274
+ * not require wrapping.
275
+ */
276
+ function assertExplicitQueueHandlerStyle(handler) {
277
+ if (handler.length !== 2) return;
278
+ if (hasQueueWorkerStyleMarker(handler)) return;
279
+ throw new Error("[devflare] Ambiguous 2-argument queue handler. The calling convention must be declared explicitly via `defineQueueHandler(fn)` for `(batch, env) => void` worker-style handlers. Single-arg `(event) => void` and 3-arg `(batch, env, ctx) => void` handlers do not require wrapping.");
280
+ }
281
+ /**
282
+ * Throw a clear error for ambiguous unmarked 2-argument scheduled handlers.
283
+ */
284
+ function assertExplicitScheduledHandlerStyle(handler) {
285
+ if (handler.length !== 2) return;
286
+ if (hasScheduledWorkerStyleMarker(handler)) return;
287
+ throw new Error("[devflare] Ambiguous 2-argument scheduled handler. The calling convention must be declared explicitly via `defineScheduledHandler(fn)` for `(controller, env) => void` worker-style handlers. Single-arg `(event) => void` and 3-arg `(controller, env, ctx) => void` handlers do not require wrapping.");
288
+ }
289
+ /**
290
+ * Detect Cloudflare Worker-style `fetch(request, env[, ctx])` handlers.
291
+ *
292
+ * Returns true when:
293
+ * - arity is `>= 3` (unambiguous worker signature), or
294
+ * - the handler is explicitly marked worker-style via `markWorkerStyle` or
295
+ * `defineFetchHandler({ style: 'worker' })`.
296
+ *
297
+ * In R1-strict, 2-argument worker-style handlers must be marked — there is
298
+ * no parameter-name fallback. Unmarked 2-arg handlers throw via
299
+ * `assertExplicit2ArgStyle` when invoked.
300
+ */
301
+ function isWorkerStyleFetchFunction(handler) {
302
+ if (isResolveStyleFunction(handler)) return false;
303
+ if (handler.length >= 3) return true;
304
+ return hasWorkerStyleMarker(handler);
305
+ }
306
+ function invokeWorkerStyleFetchFunction(handler, event) {
307
+ return handler(event.request, event.env, event.ctx);
308
+ }
309
+ function bindMethod(target, key) {
310
+ if (!target || typeof target !== "object") return null;
311
+ const value = target[key];
312
+ if (!isFunction(value)) return null;
313
+ const boundHandler = value.bind(target);
314
+ if (isResolveStyleFunction(value)) markResolveStyle(boundHandler);
315
+ if (hasWorkerStyleMarker(value)) markWorkerStyle(boundHandler);
316
+ return boundHandler;
317
+ }
318
+ function createFetchSequence(middlewares) {
319
+ return async (event, resolve = async () => createNotFoundResponse()) => {
320
+ const executeMiddleware = async (index, activeEvent) => {
321
+ if (index >= middlewares.length) return resolve(activeEvent);
322
+ const middleware = middlewares[index];
323
+ return middleware(activeEvent, async (nextEvent = activeEvent) => {
324
+ return executeMiddleware(index + 1, nextEvent);
325
+ });
326
+ };
327
+ return executeMiddleware(0, event);
328
+ };
329
+ }
330
+ /**
331
+ * Compose request-wide middleware into a single fetch surface.
332
+ */
333
+ function sequence(...middlewares) {
334
+ const composed = createFetchSequence(middlewares);
335
+ Object.defineProperty(composed, FETCH_SEQUENCE_SYMBOL, {
336
+ value: true,
337
+ enumerable: false,
338
+ configurable: false,
339
+ writable: false
340
+ });
341
+ return markResolveStyle(composed);
342
+ }
343
+ function getDefaultHandleHandler(module) {
344
+ return bindMethod(module.default, "handle");
345
+ }
346
+ function getDefaultFetchHandler(module) {
347
+ const defaultExport = module.default;
348
+ if (isFunction(defaultExport)) return defaultExport;
349
+ return bindMethod(defaultExport, "fetch");
350
+ }
351
+ function getPrimaryFetchEntryCandidates(module) {
352
+ const candidates = [];
353
+ const namedHandle = isFunction(module.handle) ? module.handle : null;
354
+ if (namedHandle) candidates.push({
355
+ name: "handle",
356
+ handler: namedHandle
357
+ });
358
+ const namedFetch = isFunction(module.fetch) ? module.fetch : null;
359
+ if (namedFetch) candidates.push({
360
+ name: "fetch",
361
+ handler: namedFetch
362
+ });
363
+ const defaultHandle = getDefaultHandleHandler(module);
364
+ if (defaultHandle) candidates.push({
365
+ name: "default.handle",
366
+ handler: defaultHandle
367
+ });
368
+ const defaultFetch = getDefaultFetchHandler(module);
369
+ if (defaultFetch) candidates.push({
370
+ name: isFunction(module.default) ? "default" : "default.fetch",
371
+ handler: defaultFetch
372
+ });
373
+ return candidates;
374
+ }
375
+ function assertSinglePrimaryFetchEntry(candidates) {
376
+ if (candidates.length <= 1) return;
377
+ const foundEntries = candidates.map(({ name }) => `"${name}"`).join(", ");
378
+ throw new Error(`Ambiguous fetch entry module. Export exactly one primary fetch entry per module. Use either "fetch" or "handle" (or one default equivalent), not both. Found: ${foundEntries}`);
379
+ }
380
+ function resolveMethodHandler(module, method) {
381
+ const normalizedMethod = method.toUpperCase();
382
+ const directHandler = isFunction(module[normalizedMethod]) ? module[normalizedMethod] : bindMethod(module.default, normalizedMethod);
383
+ if (directHandler) return {
384
+ handler: directHandler,
385
+ stripBody: false
386
+ };
387
+ if (normalizedMethod === "HEAD") {
388
+ const getHandler = isFunction(module.GET) ? module.GET : bindMethod(module.default, "GET");
389
+ if (getHandler) return {
390
+ handler: getHandler,
391
+ stripBody: true
392
+ };
393
+ }
394
+ const allHandler = isFunction(module.ALL) ? module.ALL : bindMethod(module.default, "ALL");
395
+ if (allHandler) return {
396
+ handler: allHandler,
397
+ stripBody: false
398
+ };
399
+ return null;
400
+ }
401
+ async function invokeResolvedFetchHandler(handler, event) {
402
+ if (isResolveStyleFunction(handler)) return handler(event, async () => createNotFoundResponse());
403
+ if (isWorkerStyleFetchFunction(handler)) return invokeWorkerStyleFetchFunction(handler, event);
404
+ assertExplicit2ArgStyle(handler);
405
+ return handler(event);
406
+ }
407
+ /**
408
+ * Resolve the primary fetch surface for a module.
409
+ *
410
+ * `fetch` and `handle` are treated as aliases for the same primary fetch
411
+ * entry. Exporting more than one primary entry from the same module is
412
+ * rejected as ambiguous.
413
+ */
414
+ function resolveFetchHandler(module) {
415
+ const candidates = getPrimaryFetchEntryCandidates(module);
416
+ assertSinglePrimaryFetchEntry(candidates);
417
+ return candidates[0]?.handler ?? null;
418
+ }
419
+ /**
420
+ * Invoke a fetch entry handler with the supported calling conventions.
421
+ *
422
+ * This supports:
423
+ * - `fetch(request)`
424
+ * - `fetch(request, env)`
425
+ * - `fetch(request, env, ctx)`
426
+ * - `fetch(event)`
427
+ * - `fetch(event, resolve)` / `handle(event, resolve)`
428
+ */
429
+ async function invokeFetchHandler(handler, event, resolve = async () => createNotFoundResponse()) {
430
+ if (!isFunction(handler)) return resolve(event);
431
+ if (isResolveStyleFunction(handler)) return await handler(event, resolve) ?? createNotFoundResponse();
432
+ if (isWorkerStyleFetchFunction(handler)) return await invokeWorkerStyleFetchFunction(handler, event) ?? createNotFoundResponse();
433
+ assertExplicit2ArgStyle(handler);
434
+ return await handler(event) ?? createNotFoundResponse();
435
+ }
436
+ /**
437
+ * Create a SvelteKit-style `resolve(event)` callback for a fetch module.
438
+ *
439
+ * Resolution order is:
440
+ * - matching HTTP method export such as `GET()` / `POST()` / `ALL()`
441
+ * - 404 response
442
+ */
443
+ function createResolveFetch(module, _currentEntry, initialEvent, options = {}) {
444
+ return async (nextEvent = initialEvent) => {
445
+ return runWithEventContext(nextEvent, async () => {
446
+ const methodResolution = resolveMethodHandler(module, nextEvent.request.method);
447
+ if (methodResolution) {
448
+ const finalResponse = await invokeResolvedFetchHandler(methodResolution.handler, nextEvent) ?? createNotFoundResponse();
449
+ if (methodResolution.stripBody) return new Response(null, finalResponse);
450
+ return finalResponse;
451
+ }
452
+ if (options.fallbackResolve) return options.fallbackResolve(nextEvent);
453
+ return createNotFoundResponse();
454
+ });
455
+ };
456
+ }
457
+ /**
458
+ * Invoke the resolved fetch surface for a module.
459
+ *
460
+ * This lets runtime wrappers support a single request-wide `handle` or
461
+ * `fetch` export, default exports, and same-module method handlers such as
462
+ * `GET()`.
463
+ */
464
+ async function invokeFetchModule(module, event, fallbackResolve) {
465
+ const handler = resolveFetchHandler(module);
466
+ if (!handler) return createResolveFetch(module, null, event, { fallbackResolve })(event);
467
+ return invokeFetchHandler(handler, event, createResolveFetch(module, handler, event, { fallbackResolve }));
468
+ }
469
+ //#endregion
470
+ //#region src/runtime/router/index.ts
471
+ function normalizePathname(pathname) {
472
+ if (!pathname || pathname === "/") return "/";
473
+ const trimmed = (pathname.startsWith("/") ? pathname : `/${pathname}`).replace(/\/+$|\/+$/g, "");
474
+ return trimmed === "" ? "/" : trimmed;
475
+ }
476
+ function decodePathSegment(segment) {
477
+ try {
478
+ return decodeURIComponent(segment);
479
+ } catch {
480
+ return segment;
481
+ }
482
+ }
483
+ function getPathSegments(pathname) {
484
+ const normalizedPathname = normalizePathname(pathname);
485
+ if (normalizedPathname === "/") return [];
486
+ return normalizedPathname.slice(1).split("/").filter(Boolean).map(decodePathSegment);
487
+ }
488
+ function getMatchPathname(input) {
489
+ if (input instanceof Request) return new URL(input.url).pathname;
490
+ if (input instanceof URL) return input.pathname;
491
+ if (input.includes("://")) return new URL(input).pathname;
492
+ return input;
493
+ }
494
+ function matchRouteSegments(routeSegments, pathnameSegments) {
495
+ if (routeSegments.length === 0) return pathnameSegments.length === 0 ? {} : null;
496
+ const params = {};
497
+ let routeIndex = 0;
498
+ let pathIndex = 0;
499
+ while (routeIndex < routeSegments.length) {
500
+ const routeSegment = routeSegments[routeIndex];
501
+ if (routeSegment.type === "optional-rest") {
502
+ params[routeSegment.name] = pathnameSegments.slice(pathIndex).join("/");
503
+ pathIndex = pathnameSegments.length;
504
+ routeIndex += 1;
505
+ continue;
506
+ }
507
+ if (routeSegment.type === "rest") {
508
+ if (pathIndex >= pathnameSegments.length) return null;
509
+ params[routeSegment.name] = pathnameSegments.slice(pathIndex).join("/");
510
+ pathIndex = pathnameSegments.length;
511
+ routeIndex += 1;
512
+ continue;
513
+ }
514
+ const pathnameSegment = pathnameSegments[pathIndex];
515
+ if (pathnameSegment === void 0) return null;
516
+ if (routeSegment.type === "static") {
517
+ if (pathnameSegment !== routeSegment.value) return null;
518
+ } else params[routeSegment.name] = pathnameSegment;
519
+ pathIndex += 1;
520
+ routeIndex += 1;
521
+ }
522
+ if (pathIndex !== pathnameSegments.length) return null;
523
+ return params;
524
+ }
525
+ function matchFetchRoute(routes, input) {
526
+ const pathnameSegments = getPathSegments(getMatchPathname(input));
527
+ for (const route of routes) {
528
+ const params = matchRouteSegments(route.segments, pathnameSegments);
529
+ if (params) return {
530
+ route,
531
+ params
532
+ };
533
+ }
534
+ return null;
535
+ }
536
+ async function invokeRouteModules(routes, event) {
537
+ const match = matchFetchRoute(routes, event.request);
538
+ if (!match) return new Response("Not Found", { status: 404 });
539
+ const routeEvent = createFetchEvent(event.request, event.env, event.ctx, {
540
+ params: match.params,
541
+ locals: event.locals
542
+ });
543
+ return runWithEventContext(routeEvent, () => invokeFetchModule(match.route.module, routeEvent));
544
+ }
545
+ function createRouteResolve(routes, initialEvent) {
546
+ return async (nextEvent = initialEvent) => {
547
+ return invokeRouteModules(routes, nextEvent);
548
+ };
549
+ }
550
+ //#endregion
551
+ //#region src/runtime/r2-presign.ts
552
+ /** URL path prefix of the local presign endpoint served by devflare gateways. */
553
+ const R2_PRESIGN_LOCAL_PATH_PREFIX = "/_devflare/r2/presigned/";
554
+ /** Version tag prepended to the local canonical string (breaks old URLs on format changes). */
555
+ const LOCAL_CANONICAL_VERSION = "devflare:r2-presign:v1";
556
+ /** Env/var names devflare injects in local dev + tests to enable local presigning. */
557
+ const R2_PRESIGN_SECRET_VAR = "DEVFLARE_R2_PRESIGN_SECRET";
558
+ const R2_PRESIGN_ORIGIN_VAR = "DEVFLARE_R2_PRESIGN_ORIGIN";
559
+ /** Var (injected at deploy compile time) mapping R2 binding names to bucket metadata. */
560
+ const R2_BUCKETS_VAR = "DEVFLARE_R2_BUCKETS";
561
+ /** Default env/secret names for R2 S3 API credentials in production. */
562
+ const R2_ACCOUNT_ID_VAR = "R2_ACCOUNT_ID";
563
+ const R2_ACCESS_KEY_ID_VAR = "R2_ACCESS_KEY_ID";
564
+ const R2_SECRET_ACCESS_KEY_VAR = "R2_SECRET_ACCESS_KEY";
565
+ /** Maximum expiry accepted by S3-style presigned URLs (7 days, in seconds). */
566
+ const MAX_EXPIRES_IN_SECONDS = 10080 * 60;
567
+ /** Default presigned URL lifetime (15 minutes, in seconds). */
568
+ const DEFAULT_EXPIRES_IN_SECONDS = 900;
569
+ /**
570
+ * Read a string value by name from the platform `env`, falling back to
571
+ * `process.env`. Handles dev-mode env proxies gracefully: any non-string
572
+ * (e.g. a bridge binding proxy) is treated as absent.
573
+ */
574
+ function readEnvString(env, name) {
575
+ let own;
576
+ try {
577
+ own = env?.[name];
578
+ } catch {
579
+ own = void 0;
580
+ }
581
+ if (typeof own === "string" && own.length > 0) return own;
582
+ const fromProcess = (globalThis.process?.env)?.[name];
583
+ return typeof fromProcess === "string" && fromProcess.length > 0 ? fromProcess : void 0;
584
+ }
585
+ /**
586
+ * Resolve the local presign context (origin + secret) injected by devflare in
587
+ * dev/test. Returns `null` outside devflare-managed local environments.
588
+ */
589
+ function resolveLocalContext(env) {
590
+ const secret = readEnvString(env, R2_PRESIGN_SECRET_VAR);
591
+ const origin = readEnvString(env, R2_PRESIGN_ORIGIN_VAR);
592
+ if (!secret || !origin) return null;
593
+ return {
594
+ origin: origin.replace(/\/$/, ""),
595
+ secret
596
+ };
597
+ }
598
+ /**
599
+ * Parse the injected `DEVFLARE_R2_BUCKETS` mapping from `env`. Accepts either
600
+ * a JSON string var or an already-parsed object (wrangler JSON vars).
601
+ */
602
+ function readBucketsVar(env) {
603
+ let raw;
604
+ try {
605
+ raw = env?.[R2_BUCKETS_VAR];
606
+ } catch {
607
+ return null;
608
+ }
609
+ if (raw === void 0 || raw === null) raw = (globalThis.process?.env)?.[R2_BUCKETS_VAR];
610
+ if (typeof raw === "string") try {
611
+ raw = JSON.parse(raw);
612
+ } catch {
613
+ return null;
614
+ }
615
+ if (!raw || typeof raw !== "object") return null;
616
+ const entries = {};
617
+ for (const [binding, value] of Object.entries(raw)) {
618
+ if (!value || typeof value !== "object") continue;
619
+ const bucketName = value.bucketName;
620
+ if (typeof bucketName !== "string" || bucketName.length === 0) continue;
621
+ const jurisdiction = value.jurisdiction;
622
+ entries[binding] = {
623
+ bucketName,
624
+ ...typeof jurisdiction === "string" && jurisdiction.length > 0 && { jurisdiction }
625
+ };
626
+ }
627
+ return entries;
628
+ }
629
+ /**
630
+ * Validate the binding/key/options tuple shared by PUT and GET presigning.
631
+ * Returns the effective expiry in seconds.
632
+ *
633
+ * @throws {RangeError} on out-of-range `expiresIn`, `contentLength` or `maxSizeBytes`.
634
+ * @throws {TypeError} on an empty binding or key.
635
+ */
636
+ function validateCommonInputs(binding, key, options) {
637
+ if (typeof binding !== "string" || binding.length === 0) throw new TypeError("[devflare] presignR2*: `binding` must be a non-empty R2 binding name.");
638
+ if (typeof key !== "string" || key.length === 0) throw new TypeError("[devflare] presignR2*: `key` must be a non-empty object key.");
639
+ if (key.startsWith("/")) throw new TypeError("[devflare] presignR2*: `key` must not start with \"/\".");
640
+ const controlChars = /[\u0000-\u001f\u007f]/;
641
+ if (controlChars.test(key) || controlChars.test(binding)) throw new TypeError("[devflare] presignR2*: `binding`/`key` must not contain control characters.");
642
+ const expiresIn = options.expiresIn ?? DEFAULT_EXPIRES_IN_SECONDS;
643
+ if (!Number.isInteger(expiresIn) || expiresIn < 1 || expiresIn > MAX_EXPIRES_IN_SECONDS) throw new RangeError(`[devflare] presignR2*: \`expiresIn\` must be an integer between 1 and ${MAX_EXPIRES_IN_SECONDS} seconds (got ${expiresIn}).`);
644
+ if (options.contentLength !== void 0) {
645
+ if (!Number.isInteger(options.contentLength) || options.contentLength < 0) throw new RangeError("[devflare] presignR2Put: `contentLength` must be a non-negative integer byte count.");
646
+ }
647
+ if (options.maxSizeBytes !== void 0) {
648
+ if (!Number.isInteger(options.maxSizeBytes) || options.maxSizeBytes < 1) throw new RangeError("[devflare] presignR2Put: `maxSizeBytes` must be a positive integer byte count.");
649
+ }
650
+ if (options.contentLength !== void 0 && options.maxSizeBytes !== void 0 && options.contentLength > options.maxSizeBytes) throw new RangeError(`[devflare] presignR2Put: \`contentLength\` (${options.contentLength}) exceeds \`maxSizeBytes\` (${options.maxSizeBytes}).`);
651
+ return expiresIn;
652
+ }
653
+ /**
654
+ * Percent-encode an object key for use in a URL path, RFC 3986-strict
655
+ * (S3 canonical-URI compatible), preserving `/` as the segment separator.
656
+ */
657
+ function encodeKeyPath(key) {
658
+ return key.split("/").map((segment) => encodeURIComponent(segment).replace(/[!'()*]/g, (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`)).join("/");
659
+ }
660
+ /** Compute a lowercase hex HMAC-SHA256 of `message` with `secret` via WebCrypto. */
661
+ async function hmacSha256Hex(secret, message) {
662
+ const encoder = new TextEncoder();
663
+ const cryptoKey = await crypto.subtle.importKey("raw", encoder.encode(secret), {
664
+ name: "HMAC",
665
+ hash: "SHA-256"
666
+ }, false, ["sign"]);
667
+ const signature = await crypto.subtle.sign("HMAC", cryptoKey, encoder.encode(message));
668
+ return [...new Uint8Array(signature)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
669
+ }
670
+ /**
671
+ * Build the canonical string covered by the local signature. MUST match
672
+ * `buildCanonicalString` in `src/bridge/r2-presign-runtime.ts` byte-for-byte.
673
+ */
674
+ function buildLocalCanonicalString(input) {
675
+ return [
676
+ LOCAL_CANONICAL_VERSION,
677
+ input.method,
678
+ input.binding,
679
+ input.key,
680
+ String(input.expires),
681
+ input.contentType ?? "",
682
+ input.contentLength !== void 0 ? String(input.contentLength) : "",
683
+ input.maxSizeBytes !== void 0 ? String(input.maxSizeBytes) : ""
684
+ ].join("\n");
685
+ }
686
+ /** Mint a signed URL against the devflare gateway's local presign endpoint. */
687
+ async function presignLocal(input) {
688
+ const expires = Math.floor(Date.now() / 1e3) + input.expiresIn;
689
+ const signature = await hmacSha256Hex(input.secret, buildLocalCanonicalString({
690
+ method: input.method,
691
+ binding: input.binding,
692
+ key: input.key,
693
+ expires,
694
+ contentType: input.contentType,
695
+ contentLength: input.contentLength,
696
+ maxSizeBytes: input.maxSizeBytes
697
+ }));
698
+ const url = new URL(`${input.origin}${R2_PRESIGN_LOCAL_PATH_PREFIX}${encodeURIComponent(input.binding)}/${encodeKeyPath(input.key)}`);
699
+ url.searchParams.set("X-Devflare-Method", input.method);
700
+ url.searchParams.set("X-Devflare-Expires", String(expires));
701
+ if (input.contentType !== void 0) url.searchParams.set("X-Devflare-Content-Type", input.contentType);
702
+ if (input.contentLength !== void 0) url.searchParams.set("X-Devflare-Content-Length", String(input.contentLength));
703
+ if (input.maxSizeBytes !== void 0) url.searchParams.set("X-Devflare-Max-Size", String(input.maxSizeBytes));
704
+ url.searchParams.set("X-Devflare-Signature", signature);
705
+ return {
706
+ url: url.toString(),
707
+ method: input.method,
708
+ headers: input.contentType !== void 0 ? { "content-type": input.contentType } : {},
709
+ expiresAt: /* @__PURE__ */ new Date(expires * 1e3),
710
+ key: input.key,
711
+ mode: "local"
712
+ };
713
+ }
714
+ /**
715
+ * Resolve production credentials from options or env.
716
+ *
717
+ * @throws {Error} naming exactly which credential values are missing.
718
+ */
719
+ function resolveCredentials(env, options) {
720
+ if (options.credentials) return options.credentials;
721
+ const accountId = readEnvString(env, R2_ACCOUNT_ID_VAR);
722
+ const accessKeyId = readEnvString(env, R2_ACCESS_KEY_ID_VAR);
723
+ const secretAccessKey = readEnvString(env, R2_SECRET_ACCESS_KEY_VAR);
724
+ if (accountId && accessKeyId && secretAccessKey) return {
725
+ accountId,
726
+ accessKeyId,
727
+ secretAccessKey
728
+ };
729
+ const missing = [
730
+ !accountId && "R2_ACCOUNT_ID",
731
+ !accessKeyId && "R2_ACCESS_KEY_ID",
732
+ !secretAccessKey && "R2_SECRET_ACCESS_KEY"
733
+ ].filter(Boolean);
734
+ throw new Error(`[devflare] presignR2*: missing R2 S3 credentials (${missing.join(", ")}). Provide them as Worker secrets (\`wrangler secret put <NAME>\`) or pass \`options.credentials\`. Create R2 S3 credentials under Cloudflare Dashboard → R2 → Manage R2 API Tokens. In devflare local dev no credentials are needed — this error usually means the code runs in production without the secrets set.`);
735
+ }
736
+ /**
737
+ * Resolve the production bucket for a binding from options or the injected
738
+ * `DEVFLARE_R2_BUCKETS` mapping.
739
+ *
740
+ * @throws {Error} when the bucket cannot be resolved.
741
+ */
742
+ function resolveBucket(env, binding, options) {
743
+ if (options.bucketName) return {
744
+ bucketName: options.bucketName,
745
+ ...options.jurisdiction && { jurisdiction: options.jurisdiction }
746
+ };
747
+ const entry = readBucketsVar(env)?.[binding];
748
+ if (entry) return {
749
+ bucketName: entry.bucketName,
750
+ ...(options.jurisdiction ?? entry.jurisdiction) && { jurisdiction: options.jurisdiction ?? entry.jurisdiction }
751
+ };
752
+ throw new Error(`[devflare] presignR2*: cannot resolve the bucket name for binding '${binding}'. Deploy through devflare (which injects the ${R2_BUCKETS_VAR} var from \`bindings.r2\`) or pass \`options.bucketName\` explicitly.`);
753
+ }
754
+ /** Mint a real S3 SigV4 presigned URL against the R2 S3 endpoint. */
755
+ async function presignRemote(input) {
756
+ const jurisdictionHost = input.bucket.jurisdiction ? `.${input.bucket.jurisdiction}` : "";
757
+ const endpoint = new URL(`https://${input.credentials.accountId}${jurisdictionHost}.r2.cloudflarestorage.com/${input.bucket.bucketName}/${encodeKeyPath(input.key)}`);
758
+ endpoint.searchParams.set("X-Amz-Expires", String(input.expiresIn));
759
+ const signedHeaders = {};
760
+ if (input.contentType !== void 0) signedHeaders["content-type"] = input.contentType;
761
+ if (input.contentLength !== void 0) signedHeaders["content-length"] = String(input.contentLength);
762
+ return {
763
+ url: (await new AwsV4Signer({
764
+ url: endpoint.toString(),
765
+ method: input.method,
766
+ accessKeyId: input.credentials.accessKeyId,
767
+ secretAccessKey: input.credentials.secretAccessKey,
768
+ region: "auto",
769
+ service: "s3",
770
+ signQuery: true,
771
+ allHeaders: true,
772
+ headers: signedHeaders
773
+ }).sign()).url.toString(),
774
+ method: input.method,
775
+ headers: input.contentType !== void 0 ? { "content-type": input.contentType } : {},
776
+ expiresAt: new Date(Date.now() + input.expiresIn * 1e3),
777
+ key: input.key,
778
+ mode: "remote"
779
+ };
780
+ }
781
+ /**
782
+ * Presign a direct-to-R2 `PUT` URL for a browser (or any HTTP client) upload.
783
+ *
784
+ * Resolves to a real R2 S3 presigned URL in production and to a signed
785
+ * devflare-gateway URL in local dev and the test harness — same call, same
786
+ * guarantees (signature, expiry, method, content type, size), so upload and
787
+ * quota logic can be exercised identically in every environment.
788
+ *
789
+ * @param env - The platform env (`platform.env` in SvelteKit, `env` in a
790
+ * Worker handler). Used to detect the local dev context and to read
791
+ * production credentials/bucket mapping.
792
+ * @param binding - The R2 binding name from `bindings.r2` (e.g. `'BUCKET'`).
793
+ * @param key - Object key to upload to. Percent-encoding is handled internally.
794
+ * @param options - Expiry, enforcement (content type / length / max size) and
795
+ * production credential overrides.
796
+ * @returns The presigned request: `url` to PUT to, `headers` the client must
797
+ * send, and `expiresAt`.
798
+ * @throws {Error} in production when credentials or the bucket mapping are missing.
799
+ * @throws {TypeError | RangeError} on invalid inputs.
800
+ *
801
+ * @example
802
+ * ```ts
803
+ * // Server (SvelteKit endpoint) — reserve quota first, then presign:
804
+ * const { url, headers } = await presignR2Put(platform.env, 'BUCKET', `media/${id}.png`, {
805
+ * expiresIn: 600,
806
+ * contentType: file.type,
807
+ * contentLength: file.size
808
+ * })
809
+ *
810
+ * // Browser — upload directly to storage:
811
+ * await fetch(url, { method: 'PUT', body: file, headers })
812
+ *
813
+ * // Server — finalize: confirm the object before committing quota:
814
+ * const head = await platform.env.BUCKET.head(`media/${id}.png`)
815
+ * ```
816
+ */
817
+ async function presignR2Put(env, binding, key, options = {}) {
818
+ const expiresIn = validateCommonInputs(binding, key, options);
819
+ const local = resolveLocalContext(env);
820
+ if (local) return presignLocal({
821
+ ...local,
822
+ method: "PUT",
823
+ binding,
824
+ key,
825
+ expiresIn,
826
+ contentType: options.contentType,
827
+ contentLength: options.contentLength,
828
+ maxSizeBytes: options.maxSizeBytes
829
+ });
830
+ return presignRemote({
831
+ credentials: resolveCredentials(env, options),
832
+ bucket: resolveBucket(env, binding, options),
833
+ method: "PUT",
834
+ key,
835
+ expiresIn,
836
+ contentType: options.contentType,
837
+ contentLength: options.contentLength
838
+ });
839
+ }
840
+ /**
841
+ * Presign a direct-from-R2 `GET` URL (also valid for `HEAD`) so a browser can
842
+ * download an object without routing the bytes through the Worker.
843
+ *
844
+ * Same dev/prod symmetry as {@link presignR2Put}. Note that browser reads
845
+ * from real R2 additionally require CORS rules on the bucket itself.
846
+ *
847
+ * @param env - The platform env (see {@link presignR2Put}).
848
+ * @param binding - The R2 binding name from `bindings.r2`.
849
+ * @param key - Object key to read.
850
+ * @param options - Expiry and production credential overrides.
851
+ * @returns The presigned request; `headers` is always empty for GET.
852
+ * @throws {Error} in production when credentials or the bucket mapping are missing.
853
+ * @throws {TypeError | RangeError} on invalid inputs.
854
+ */
855
+ async function presignR2Get(env, binding, key, options = {}) {
856
+ const expiresIn = validateCommonInputs(binding, key, options);
857
+ const local = resolveLocalContext(env);
858
+ if (local) return presignLocal({
859
+ ...local,
860
+ method: "GET",
861
+ binding,
862
+ key,
863
+ expiresIn
864
+ });
865
+ return presignRemote({
866
+ credentials: resolveCredentials(env, options),
867
+ bucket: resolveBucket(env, binding, options),
868
+ method: "GET",
869
+ key,
870
+ expiresIn
871
+ });
872
+ }
873
+ //#endregion
874
+ export { vars as C, locals as S, resolveFetchHandler as _, matchFetchRoute as a, env as b, assertExplicitScheduledHandlerStyle as c, defineQueueHandler as d, defineScheduledHandler as f, markWorkerStyle as g, markResolveStyle as h, invokeRouteModules as i, createResolveFetch as l, invokeFetchModule as m, presignR2Put as n, assertExplicit2ArgStyle as o, invokeFetchHandler as p, createRouteResolve as r, assertExplicitQueueHandlerStyle as s, presignR2Get as t, defineFetchHandler as u, sequence as v, event as x, ctx as y };