devflare 1.0.0-next.5 → 1.0.0-next.50

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 (594) hide show
  1. package/LICENSE +21 -0
  2. package/LLM.md +17312 -2139
  3. package/README.md +394 -605
  4. package/bin/devflare.js +30 -14
  5. package/dist/_chunks/account-BI3WZMDy.js +462 -0
  6. package/dist/_chunks/account-resources-CsmVowJp.js +159 -0
  7. package/dist/_chunks/ai-CBEuLdoP.js +322 -0
  8. package/dist/_chunks/api-TzdliH-6.js +568 -0
  9. package/dist/_chunks/build-artifacts-DU5V0J0Z.js +483 -0
  10. package/dist/_chunks/build-e0KR38-4.js +24 -0
  11. package/dist/_chunks/cli-DuUz10Mn.js +1163 -0
  12. package/dist/_chunks/cloudflare-BaloqI3H.js +157 -0
  13. package/dist/_chunks/colors-DiK6wPJ5.js +13 -0
  14. package/dist/_chunks/command-utils-DA0Qx9_K.js +45 -0
  15. package/dist/_chunks/compiler-Zw16C9Pi.js +489 -0
  16. package/dist/_chunks/config-Brju62xy.js +78 -0
  17. package/dist/_chunks/config-path-DaL1ylZ_.js +42 -0
  18. package/dist/_chunks/context-CX50Y2Kb.js +2250 -0
  19. package/dist/_chunks/decorators-QmV57ixr.js +19 -0
  20. package/dist/_chunks/dependencies-C2oxFjU_.js +57 -0
  21. package/dist/_chunks/deploy-B-Kku1Vk.js +1032 -0
  22. package/dist/_chunks/dev-D4e_RRZn.js +3471 -0
  23. package/dist/_chunks/doctor-jm_K4dxL.js +219 -0
  24. package/dist/_chunks/durable-object-DMtH0XYX.js +234 -0
  25. package/dist/_chunks/env-S0_nMVz1.js +125 -0
  26. package/dist/_chunks/family-_9-mGSfO.js +143 -0
  27. package/dist/_chunks/generated-artifacts-dMJY4KAt.js +32 -0
  28. package/dist/_chunks/glob-CmQOvunB.js +56 -0
  29. package/dist/_chunks/init-DnkJOmpW.js +165 -0
  30. package/dist/_chunks/loader-Cr0_OWPy.js +1288 -0
  31. package/dist/_chunks/local-dev-vars-CTSa-wvF.js +81 -0
  32. package/dist/_chunks/local-hyperdrive-CJ90j46O.js +119 -0
  33. package/dist/_chunks/local-media-bindings-DsAW4AMF.js +335 -0
  34. package/dist/_chunks/local-secrets-DMPkmOn3.js +123 -0
  35. package/dist/_chunks/local-workflow-entrypoints-Cq_WJajd.js +90 -0
  36. package/dist/_chunks/login-FjTAAQbi.js +51 -0
  37. package/dist/_chunks/package-metadata-DjHBLB-z.js +39 -0
  38. package/dist/_chunks/preferences-BKp_7XJx.js +241 -0
  39. package/dist/_chunks/preview-C3Cdr8an.js +462 -0
  40. package/dist/_chunks/preview-registry-ClAbLTHH.js +1186 -0
  41. package/dist/_chunks/preview-resources-CGMBjsYB.js +359 -0
  42. package/dist/_chunks/previews-C7hs9-BT.js +1134 -0
  43. package/dist/_chunks/productions-T9Als4fE.js +411 -0
  44. package/dist/_chunks/ref-CYJNAAe_.js +178 -0
  45. package/dist/_chunks/remote-CZnP-HLJ.js +79 -0
  46. package/dist/_chunks/remote-config-D39BY9ji.js +132 -0
  47. package/dist/_chunks/resolve-package-qizBfCIm.js +152 -0
  48. package/dist/_chunks/rolldown-runtime-CvQ6eiug.js +14 -0
  49. package/dist/_chunks/routes-BFYCqHb-.js +833 -0
  50. package/dist/_chunks/runtime-DL-Nz3k8.js +550 -0
  51. package/dist/_chunks/schema-normalization-BCwTLTGp.js +660 -0
  52. package/dist/_chunks/secrets-DIpJGe6C.js +95 -0
  53. package/dist/_chunks/tail-IY-ijYmv.js +239 -0
  54. package/dist/_chunks/token-Dmi0KXyX.js +333 -0
  55. package/dist/_chunks/tokens-iVcgNXi-.js +221 -0
  56. package/dist/_chunks/types-DoKsMYfm.js +484 -0
  57. package/dist/_chunks/ui-BUoZApvE.js +103 -0
  58. package/dist/_chunks/usage-BBTGzjon.js +272 -0
  59. package/dist/_chunks/vite-CGtVNf5E.js +1267 -0
  60. package/dist/_chunks/vite-utils-OVLMV605.js +183 -0
  61. package/dist/_chunks/worker-BEZI4od1.js +410 -0
  62. package/dist/_chunks/worker-bundler-dTTnYU3n.js +458 -0
  63. package/dist/_chunks/worker-entrypoint-CQW77lG8.js +247 -0
  64. package/dist/_chunks/workerName-CFJsLZA-.js +23 -0
  65. package/dist/bridge/client.d.ts +49 -7
  66. package/dist/bridge/client.d.ts.map +1 -1
  67. package/dist/bridge/gateway-runtime.d.ts +8 -0
  68. package/dist/bridge/gateway-runtime.d.ts.map +1 -0
  69. package/dist/bridge/index.d.ts +6 -6
  70. package/dist/bridge/index.d.ts.map +1 -1
  71. package/dist/bridge/log.d.ts +5 -0
  72. package/dist/bridge/log.d.ts.map +1 -0
  73. package/dist/bridge/miniflare.d.ts +82 -2
  74. package/dist/bridge/miniflare.d.ts.map +1 -1
  75. package/dist/bridge/proxy.d.ts +12 -11
  76. package/dist/bridge/proxy.d.ts.map +1 -1
  77. package/dist/bridge/server.d.ts +2 -1
  78. package/dist/bridge/server.d.ts.map +1 -1
  79. package/dist/bridge/v2/body-streams.d.ts +53 -0
  80. package/dist/bridge/v2/body-streams.d.ts.map +1 -0
  81. package/dist/bridge/v2/codec.d.ts +106 -0
  82. package/dist/bridge/v2/codec.d.ts.map +1 -0
  83. package/dist/bridge/v2/control-messages.d.ts +46 -0
  84. package/dist/bridge/v2/control-messages.d.ts.map +1 -0
  85. package/dist/bridge/v2/frames.d.ts +109 -0
  86. package/dist/bridge/v2/frames.d.ts.map +1 -0
  87. package/dist/bridge/v2/index.d.ts +11 -0
  88. package/dist/bridge/v2/index.d.ts.map +1 -0
  89. package/dist/bridge/v2/serialization.d.ts +48 -0
  90. package/dist/bridge/v2/serialization.d.ts.map +1 -0
  91. package/dist/bridge/v2/transport.d.ts +31 -0
  92. package/dist/bridge/v2/transport.d.ts.map +1 -0
  93. package/dist/bridge/v2/value-codec.d.ts +61 -0
  94. package/dist/bridge/v2/value-codec.d.ts.map +1 -0
  95. package/dist/bridge/{serialization.d.ts → v2/value-serialization.d.ts} +40 -18
  96. package/dist/bridge/v2/value-serialization.d.ts.map +1 -0
  97. package/dist/bridge/{protocol.d.ts → v2/wire.d.ts} +32 -8
  98. package/dist/bridge/v2/wire.d.ts.map +1 -0
  99. package/dist/bridge/v2/ws-relay.d.ts +53 -0
  100. package/dist/bridge/v2/ws-relay.d.ts.map +1 -0
  101. package/dist/browser-shim/handler.d.ts +2 -2
  102. package/dist/browser-shim/handler.d.ts.map +1 -1
  103. package/dist/browser-shim/index.d.ts +2 -2
  104. package/dist/browser-shim/server.d.ts +63 -0
  105. package/dist/browser-shim/server.d.ts.map +1 -1
  106. package/dist/browser.d.ts +5411 -0
  107. package/dist/browser.d.ts.map +1 -0
  108. package/dist/browser.js +80 -0
  109. package/dist/bundler/defaults.d.ts +23 -0
  110. package/dist/bundler/defaults.d.ts.map +1 -0
  111. package/dist/bundler/do-bundler.d.ts +7 -0
  112. package/dist/bundler/do-bundler.d.ts.map +1 -1
  113. package/dist/bundler/index.d.ts +3 -1
  114. package/dist/bundler/index.d.ts.map +1 -1
  115. package/dist/bundler/rolldown-shared.d.ts +53 -0
  116. package/dist/bundler/rolldown-shared.d.ts.map +1 -0
  117. package/dist/bundler/worker-bundler.d.ts +13 -0
  118. package/dist/bundler/worker-bundler.d.ts.map +1 -0
  119. package/dist/bundler/worker-compat.d.ts +4 -0
  120. package/dist/bundler/worker-compat.d.ts.map +1 -0
  121. package/dist/cli/build-manifest.d.ts +66 -0
  122. package/dist/cli/build-manifest.d.ts.map +1 -0
  123. package/dist/cli/command-utils.d.ts +18 -0
  124. package/dist/cli/command-utils.d.ts.map +1 -0
  125. package/dist/cli/commands/account.d.ts +2 -2
  126. package/dist/cli/commands/account.d.ts.map +1 -1
  127. package/dist/cli/commands/ai.d.ts +1 -1
  128. package/dist/cli/commands/ai.d.ts.map +1 -1
  129. package/dist/cli/commands/build-artifacts.d.ts +40 -0
  130. package/dist/cli/commands/build-artifacts.d.ts.map +1 -0
  131. package/dist/cli/commands/build.d.ts +2 -2
  132. package/dist/cli/commands/build.d.ts.map +1 -1
  133. package/dist/cli/commands/config.d.ts +4 -0
  134. package/dist/cli/commands/config.d.ts.map +1 -0
  135. package/dist/cli/commands/deploy/metadata.d.ts +18 -0
  136. package/dist/cli/commands/deploy/metadata.d.ts.map +1 -0
  137. package/dist/cli/commands/deploy/prepare.d.ts +23 -0
  138. package/dist/cli/commands/deploy/prepare.d.ts.map +1 -0
  139. package/dist/cli/commands/deploy/runtime.d.ts +4 -0
  140. package/dist/cli/commands/deploy/runtime.d.ts.map +1 -0
  141. package/dist/cli/commands/deploy/verification.d.ts +36 -0
  142. package/dist/cli/commands/deploy/verification.d.ts.map +1 -0
  143. package/dist/cli/commands/deploy.d.ts +2 -2
  144. package/dist/cli/commands/deploy.d.ts.map +1 -1
  145. package/dist/cli/commands/dev.d.ts +9 -1
  146. package/dist/cli/commands/dev.d.ts.map +1 -1
  147. package/dist/cli/commands/doctor.d.ts +2 -2
  148. package/dist/cli/commands/doctor.d.ts.map +1 -1
  149. package/dist/cli/commands/init.d.ts +2 -2
  150. package/dist/cli/commands/init.d.ts.map +1 -1
  151. package/dist/cli/commands/login.d.ts +4 -0
  152. package/dist/cli/commands/login.d.ts.map +1 -0
  153. package/dist/cli/commands/previews-support/cleanup.d.ts +9 -0
  154. package/dist/cli/commands/previews-support/cleanup.d.ts.map +1 -0
  155. package/dist/cli/commands/previews-support/family.d.ts +10 -0
  156. package/dist/cli/commands/previews-support/family.d.ts.map +1 -0
  157. package/dist/cli/commands/previews-support/render.d.ts +8 -0
  158. package/dist/cli/commands/previews-support/render.d.ts.map +1 -0
  159. package/dist/cli/commands/previews-support/theme.d.ts +10 -0
  160. package/dist/cli/commands/previews-support/theme.d.ts.map +1 -0
  161. package/dist/cli/commands/previews-support/types.d.ts +70 -0
  162. package/dist/cli/commands/previews-support/types.d.ts.map +1 -0
  163. package/dist/cli/commands/previews.d.ts +4 -0
  164. package/dist/cli/commands/previews.d.ts.map +1 -0
  165. package/dist/cli/commands/productions.d.ts +4 -0
  166. package/dist/cli/commands/productions.d.ts.map +1 -0
  167. package/dist/cli/commands/remote.d.ts +1 -1
  168. package/dist/cli/commands/remote.d.ts.map +1 -1
  169. package/dist/cli/commands/secrets.d.ts +4 -0
  170. package/dist/cli/commands/secrets.d.ts.map +1 -0
  171. package/dist/cli/commands/tail.d.ts +44 -0
  172. package/dist/cli/commands/tail.d.ts.map +1 -0
  173. package/dist/cli/commands/token.d.ts +4 -0
  174. package/dist/cli/commands/token.d.ts.map +1 -0
  175. package/dist/cli/commands/type-generation/discovery.d.ts +7 -0
  176. package/dist/cli/commands/type-generation/discovery.d.ts.map +1 -0
  177. package/dist/cli/commands/type-generation/generator.d.ts +121 -0
  178. package/dist/cli/commands/type-generation/generator.d.ts.map +1 -0
  179. package/dist/cli/commands/type-generation/models.d.ts +27 -0
  180. package/dist/cli/commands/type-generation/models.d.ts.map +1 -0
  181. package/dist/cli/commands/types.d.ts +2 -2
  182. package/dist/cli/commands/types.d.ts.map +1 -1
  183. package/dist/cli/commands/worker.d.ts +4 -0
  184. package/dist/cli/commands/worker.d.ts.map +1 -0
  185. package/dist/cli/config-path.d.ts +6 -0
  186. package/dist/cli/config-path.d.ts.map +1 -0
  187. package/dist/cli/dependencies.d.ts +2 -1
  188. package/dist/cli/dependencies.d.ts.map +1 -1
  189. package/dist/cli/deploy-strategy.d.ts +17 -0
  190. package/dist/cli/deploy-strategy.d.ts.map +1 -0
  191. package/dist/cli/deploy-target.d.ts +17 -0
  192. package/dist/cli/deploy-target.d.ts.map +1 -0
  193. package/dist/cli/generated-artifacts.d.ts +12 -0
  194. package/dist/cli/generated-artifacts.d.ts.map +1 -0
  195. package/dist/cli/gradual-deploy.d.ts +49 -0
  196. package/dist/cli/gradual-deploy.d.ts.map +1 -0
  197. package/dist/cli/help-pages/pages/account.d.ts +3 -0
  198. package/dist/cli/help-pages/pages/account.d.ts.map +1 -0
  199. package/dist/cli/help-pages/pages/core.d.ts +4 -0
  200. package/dist/cli/help-pages/pages/core.d.ts.map +1 -0
  201. package/dist/cli/help-pages/pages/index.d.ts +3 -0
  202. package/dist/cli/help-pages/pages/index.d.ts.map +1 -0
  203. package/dist/cli/help-pages/pages/misc.d.ts +3 -0
  204. package/dist/cli/help-pages/pages/misc.d.ts.map +1 -0
  205. package/dist/cli/help-pages/pages/previews.d.ts +3 -0
  206. package/dist/cli/help-pages/pages/previews.d.ts.map +1 -0
  207. package/dist/cli/help-pages/pages/productions.d.ts +3 -0
  208. package/dist/cli/help-pages/pages/productions.d.ts.map +1 -0
  209. package/dist/cli/help-pages/render.d.ts +12 -0
  210. package/dist/cli/help-pages/render.d.ts.map +1 -0
  211. package/dist/cli/help-pages/shared.d.ts +15 -0
  212. package/dist/cli/help-pages/shared.d.ts.map +1 -0
  213. package/dist/cli/help-pages/types.d.ts +23 -0
  214. package/dist/cli/help-pages/types.d.ts.map +1 -0
  215. package/dist/cli/help.d.ts +6 -0
  216. package/dist/cli/help.d.ts.map +1 -0
  217. package/dist/cli/index.d.ts +1 -0
  218. package/dist/cli/index.d.ts.map +1 -1
  219. package/dist/cli/index.js +2 -0
  220. package/dist/cli/package-metadata.d.ts +16 -0
  221. package/dist/cli/package-metadata.d.ts.map +1 -0
  222. package/dist/cli/preview-bindings.d.ts +49 -0
  223. package/dist/cli/preview-bindings.d.ts.map +1 -0
  224. package/dist/cli/preview.d.ts +10 -0
  225. package/dist/cli/preview.d.ts.map +1 -0
  226. package/dist/cli/ui.d.ts +37 -0
  227. package/dist/cli/ui.d.ts.map +1 -0
  228. package/dist/cli/workspace-build-guard.d.ts +14 -0
  229. package/dist/cli/workspace-build-guard.d.ts.map +1 -0
  230. package/dist/cli/wrangler-auth.d.ts +1 -1
  231. package/dist/cloudflare/account-core.d.ts +6 -0
  232. package/dist/cloudflare/account-core.d.ts.map +1 -0
  233. package/dist/cloudflare/account-resources.d.ts +40 -0
  234. package/dist/cloudflare/account-resources.d.ts.map +1 -0
  235. package/dist/cloudflare/account-status.d.ts +11 -0
  236. package/dist/cloudflare/account-status.d.ts.map +1 -0
  237. package/dist/cloudflare/account-workers.d.ts +14 -0
  238. package/dist/cloudflare/account-workers.d.ts.map +1 -0
  239. package/dist/cloudflare/account.d.ts +7 -64
  240. package/dist/cloudflare/account.d.ts.map +1 -1
  241. package/dist/cloudflare/api.d.ts +71 -3
  242. package/dist/cloudflare/api.d.ts.map +1 -1
  243. package/dist/cloudflare/auth.d.ts +1 -1
  244. package/dist/cloudflare/auth.d.ts.map +1 -1
  245. package/dist/cloudflare/index.d.ts +61 -6
  246. package/dist/cloudflare/index.d.ts.map +1 -1
  247. package/dist/cloudflare/index.js +4 -13
  248. package/dist/cloudflare/known-permission-group-ids.generated.d.ts +10 -0
  249. package/dist/cloudflare/known-permission-group-ids.generated.d.ts.map +1 -0
  250. package/dist/cloudflare/kv-namespace.d.ts +4 -0
  251. package/dist/cloudflare/kv-namespace.d.ts.map +1 -0
  252. package/dist/cloudflare/preferences.d.ts +7 -0
  253. package/dist/cloudflare/preferences.d.ts.map +1 -1
  254. package/dist/cloudflare/preview-registry-cache.d.ts +6 -0
  255. package/dist/cloudflare/preview-registry-cache.d.ts.map +1 -0
  256. package/dist/cloudflare/preview-registry-inference.d.ts +14 -0
  257. package/dist/cloudflare/preview-registry-inference.d.ts.map +1 -0
  258. package/dist/cloudflare/preview-registry-records.d.ts +4 -0
  259. package/dist/cloudflare/preview-registry-records.d.ts.map +1 -0
  260. package/dist/cloudflare/preview-registry-shape.d.ts +47 -0
  261. package/dist/cloudflare/preview-registry-shape.d.ts.map +1 -0
  262. package/dist/cloudflare/preview-registry-store.d.ts +14 -0
  263. package/dist/cloudflare/preview-registry-store.d.ts.map +1 -0
  264. package/dist/cloudflare/preview-registry-transport.d.ts +4 -0
  265. package/dist/cloudflare/preview-registry-transport.d.ts.map +1 -0
  266. package/dist/cloudflare/preview-registry-types.d.ts +103 -0
  267. package/dist/cloudflare/preview-registry-types.d.ts.map +1 -0
  268. package/dist/cloudflare/preview-registry.d.ts +42 -0
  269. package/dist/cloudflare/preview-registry.d.ts.map +1 -0
  270. package/dist/cloudflare/preview-urls.d.ts +3 -0
  271. package/dist/cloudflare/preview-urls.d.ts.map +1 -0
  272. package/dist/cloudflare/registry-schema.d.ts +253 -0
  273. package/dist/cloudflare/registry-schema.d.ts.map +1 -0
  274. package/dist/cloudflare/remote-config.d.ts.map +1 -1
  275. package/dist/cloudflare/tokens.d.ts +44 -0
  276. package/dist/cloudflare/tokens.d.ts.map +1 -0
  277. package/dist/cloudflare/types.d.ts +124 -7
  278. package/dist/cloudflare/types.d.ts.map +1 -1
  279. package/dist/cloudflare/usage.d.ts +31 -3
  280. package/dist/cloudflare/usage.d.ts.map +1 -1
  281. package/dist/config/binding-resolution-helpers.d.ts +41 -0
  282. package/dist/config/binding-resolution-helpers.d.ts.map +1 -0
  283. package/dist/config/compatibility.d.ts +3 -0
  284. package/dist/config/compatibility.d.ts.map +1 -0
  285. package/dist/config/compiler/bindings.d.ts +14 -0
  286. package/dist/config/compiler/bindings.d.ts.map +1 -0
  287. package/dist/config/compiler/core-helpers.d.ts +6 -0
  288. package/dist/config/compiler/core-helpers.d.ts.map +1 -0
  289. package/dist/config/compiler/do-workers.d.ts +34 -0
  290. package/dist/config/compiler/do-workers.d.ts.map +1 -0
  291. package/dist/config/compiler/paths.d.ts +18 -0
  292. package/dist/config/compiler/paths.d.ts.map +1 -0
  293. package/dist/config/compiler/types.d.ts +298 -0
  294. package/dist/config/compiler/types.d.ts.map +1 -0
  295. package/dist/config/compiler.d.ts +22 -134
  296. package/dist/config/compiler.d.ts.map +1 -1
  297. package/dist/config/cron.d.ts +19 -0
  298. package/dist/config/cron.d.ts.map +1 -0
  299. package/dist/config/define.d.ts +8 -5
  300. package/dist/config/define.d.ts.map +1 -1
  301. package/dist/config/deploy-resources.d.ts +58 -0
  302. package/dist/config/deploy-resources.d.ts.map +1 -0
  303. package/dist/config/env-vars.d.ts +309 -0
  304. package/dist/config/env-vars.d.ts.map +1 -0
  305. package/dist/config/framework-providers.d.ts +9 -0
  306. package/dist/config/framework-providers.d.ts.map +1 -0
  307. package/dist/config/index.d.ts +12 -5
  308. package/dist/config/index.d.ts.map +1 -1
  309. package/dist/config/loader.d.ts +2 -1
  310. package/dist/config/loader.d.ts.map +1 -1
  311. package/dist/config/local-dev-vars.d.ts +15 -0
  312. package/dist/config/local-dev-vars.d.ts.map +1 -0
  313. package/dist/config/preview-resources.d.ts +83 -0
  314. package/dist/config/preview-resources.d.ts.map +1 -0
  315. package/dist/config/preview.d.ts +29 -0
  316. package/dist/config/preview.d.ts.map +1 -0
  317. package/dist/config/ref.d.ts +16 -25
  318. package/dist/config/ref.d.ts.map +1 -1
  319. package/dist/config/resolve-phased.d.ts +72 -0
  320. package/dist/config/resolve-phased.d.ts.map +1 -0
  321. package/dist/config/resolve.d.ts +11 -0
  322. package/dist/config/resolve.d.ts.map +1 -0
  323. package/dist/config/resource-resolution.d.ts +80 -0
  324. package/dist/config/resource-resolution.d.ts.map +1 -0
  325. package/dist/config/schema-bindings.d.ts +2025 -0
  326. package/dist/config/schema-bindings.d.ts.map +1 -0
  327. package/dist/config/schema-build.d.ts +67 -0
  328. package/dist/config/schema-build.d.ts.map +1 -0
  329. package/dist/config/schema-env.d.ts +3579 -0
  330. package/dist/config/schema-env.d.ts.map +1 -0
  331. package/dist/config/schema-normalization.d.ts +265 -0
  332. package/dist/config/schema-normalization.d.ts.map +1 -0
  333. package/dist/config/schema-runtime.d.ts +508 -0
  334. package/dist/config/schema-runtime.d.ts.map +1 -0
  335. package/dist/config/schema-types-bindings-platform.d.ts +508 -0
  336. package/dist/config/schema-types-bindings-platform.d.ts.map +1 -0
  337. package/dist/config/schema-types-bindings-resources.d.ts +767 -0
  338. package/dist/config/schema-types-bindings-resources.d.ts.map +1 -0
  339. package/dist/config/schema-types-bindings.d.ts +293 -0
  340. package/dist/config/schema-types-bindings.d.ts.map +1 -0
  341. package/dist/config/schema-types-build.d.ts +86 -0
  342. package/dist/config/schema-types-build.d.ts.map +1 -0
  343. package/dist/config/schema-types-runtime.d.ts +917 -0
  344. package/dist/config/schema-types-runtime.d.ts.map +1 -0
  345. package/dist/config/schema-types.d.ts +424 -0
  346. package/dist/config/schema-types.d.ts.map +1 -0
  347. package/dist/config/schema.d.ts +5324 -2011
  348. package/dist/config/schema.d.ts.map +1 -1
  349. package/dist/config/service-bindings-validation.d.ts +36 -0
  350. package/dist/config/service-bindings-validation.d.ts.map +1 -0
  351. package/dist/config-entry.d.ts +7 -0
  352. package/dist/config-entry.d.ts.map +1 -0
  353. package/dist/config-entry.js +3 -0
  354. package/dist/decorators/durable-object.d.ts.map +1 -1
  355. package/dist/decorators/index.d.ts +2 -2
  356. package/dist/decorators/index.js +2 -9
  357. package/dist/dev-server/d1-migrations.d.ts +36 -0
  358. package/dist/dev-server/d1-migrations.d.ts.map +1 -0
  359. package/dist/dev-server/dev-server-state.d.ts +59 -0
  360. package/dist/dev-server/dev-server-state.d.ts.map +1 -0
  361. package/dist/dev-server/gateway-script.d.ts +21 -0
  362. package/dist/dev-server/gateway-script.d.ts.map +1 -0
  363. package/dist/dev-server/index.d.ts +1 -1
  364. package/dist/dev-server/miniflare-bindings.d.ts +81 -0
  365. package/dist/dev-server/miniflare-bindings.d.ts.map +1 -0
  366. package/dist/dev-server/miniflare-dev-config.d.ts +36 -0
  367. package/dist/dev-server/miniflare-dev-config.d.ts.map +1 -0
  368. package/dist/dev-server/miniflare-log.d.ts +20 -0
  369. package/dist/dev-server/miniflare-log.d.ts.map +1 -0
  370. package/dist/dev-server/miniflare-worker-config.d.ts +82 -0
  371. package/dist/dev-server/miniflare-worker-config.d.ts.map +1 -0
  372. package/dist/dev-server/reload-queue.d.ts +13 -0
  373. package/dist/dev-server/reload-queue.d.ts.map +1 -0
  374. package/dist/dev-server/runtime-stdio.d.ts +8 -0
  375. package/dist/dev-server/runtime-stdio.d.ts.map +1 -0
  376. package/dist/dev-server/server-startup-helpers.d.ts +84 -0
  377. package/dist/dev-server/server-startup-helpers.d.ts.map +1 -0
  378. package/dist/dev-server/server.d.ts +2 -0
  379. package/dist/dev-server/server.d.ts.map +1 -1
  380. package/dist/dev-server/vite-process.d.ts +15 -0
  381. package/dist/dev-server/vite-process.d.ts.map +1 -0
  382. package/dist/dev-server/vite-utils.d.ts +19 -1
  383. package/dist/dev-server/vite-utils.d.ts.map +1 -1
  384. package/dist/dev-server/worker-source-watcher.d.ts +17 -0
  385. package/dist/dev-server/worker-source-watcher.d.ts.map +1 -0
  386. package/dist/dev-server/worker-surface-paths.d.ts +6 -0
  387. package/dist/dev-server/worker-surface-paths.d.ts.map +1 -0
  388. package/dist/env.d.ts +10 -0
  389. package/dist/env.d.ts.map +1 -1
  390. package/dist/index.d.ts +8 -12
  391. package/dist/index.d.ts.map +1 -1
  392. package/dist/index.js +9 -298
  393. package/dist/runtime/context-events.d.ts +13 -0
  394. package/dist/runtime/context-events.d.ts.map +1 -0
  395. package/dist/runtime/context-types.d.ts +82 -0
  396. package/dist/runtime/context-types.d.ts.map +1 -0
  397. package/dist/runtime/context.d.ts +20 -44
  398. package/dist/runtime/context.d.ts.map +1 -1
  399. package/dist/runtime/exports.d.ts +70 -55
  400. package/dist/runtime/exports.d.ts.map +1 -1
  401. package/dist/runtime/index.d.ts +10 -3
  402. package/dist/runtime/index.d.ts.map +1 -1
  403. package/dist/runtime/index.js +5 -111
  404. package/dist/runtime/middleware.d.ts +119 -67
  405. package/dist/runtime/middleware.d.ts.map +1 -1
  406. package/dist/runtime/router/index.d.ts +7 -0
  407. package/dist/runtime/router/index.d.ts.map +1 -0
  408. package/dist/runtime/router/types.d.ts +24 -0
  409. package/dist/runtime/router/types.d.ts.map +1 -0
  410. package/dist/runtime/validation.d.ts +18 -4
  411. package/dist/runtime/validation.d.ts.map +1 -1
  412. package/dist/secrets/local-secrets.d.ts +46 -0
  413. package/dist/secrets/local-secrets.d.ts.map +1 -0
  414. package/dist/shims/local-hyperdrive.d.ts +12 -0
  415. package/dist/shims/local-hyperdrive.d.ts.map +1 -0
  416. package/dist/shims/local-media-bindings.d.ts +19 -0
  417. package/dist/shims/local-media-bindings.d.ts.map +1 -0
  418. package/dist/shims/local-worker-loader.d.ts +3 -0
  419. package/dist/shims/local-worker-loader.d.ts.map +1 -0
  420. package/dist/sveltekit/index.d.ts +1 -1
  421. package/dist/sveltekit/index.d.ts.map +1 -1
  422. package/dist/sveltekit/index.js +313 -167
  423. package/dist/sveltekit/local-bindings.d.ts +4 -0
  424. package/dist/sveltekit/local-bindings.d.ts.map +1 -0
  425. package/dist/sveltekit/platform.d.ts +20 -2
  426. package/dist/sveltekit/platform.d.ts.map +1 -1
  427. package/dist/test/ai-search.d.ts +39 -0
  428. package/dist/test/ai-search.d.ts.map +1 -0
  429. package/dist/test/alarm.d.ts +55 -0
  430. package/dist/test/alarm.d.ts.map +1 -0
  431. package/dist/test/binding-hints.d.ts +10 -0
  432. package/dist/test/binding-hints.d.ts.map +1 -0
  433. package/dist/test/cf.d.ts +71 -35
  434. package/dist/test/cf.d.ts.map +1 -1
  435. package/dist/test/containers.d.ts +87 -0
  436. package/dist/test/containers.d.ts.map +1 -0
  437. package/dist/test/email.d.ts +16 -7
  438. package/dist/test/email.d.ts.map +1 -1
  439. package/dist/test/index.d.ts +20 -21
  440. package/dist/test/index.d.ts.map +1 -1
  441. package/dist/test/index.js +4971 -70
  442. package/dist/test/offline-bindings.d.ts +115 -0
  443. package/dist/test/offline-bindings.d.ts.map +1 -0
  444. package/dist/test/queue.d.ts.map +1 -1
  445. package/dist/test/remote-ai.d.ts.map +1 -1
  446. package/dist/test/remote-cloudflare.d.ts +13 -0
  447. package/dist/test/remote-cloudflare.d.ts.map +1 -0
  448. package/dist/test/remote-vectorize.d.ts.map +1 -1
  449. package/dist/test/resolve-service-bindings.d.ts +64 -4
  450. package/dist/test/resolve-service-bindings.d.ts.map +1 -1
  451. package/dist/test/scheduled.d.ts.map +1 -1
  452. package/dist/test/should-skip.d.ts +14 -18
  453. package/dist/test/should-skip.d.ts.map +1 -1
  454. package/dist/test/simple-context-bindings.d.ts +13 -0
  455. package/dist/test/simple-context-bindings.d.ts.map +1 -0
  456. package/dist/test/simple-context-durable-objects.d.ts +6 -0
  457. package/dist/test/simple-context-durable-objects.d.ts.map +1 -0
  458. package/dist/test/simple-context-env.d.ts +35 -0
  459. package/dist/test/simple-context-env.d.ts.map +1 -0
  460. package/dist/test/simple-context-gateway-script.d.ts +2 -0
  461. package/dist/test/simple-context-gateway-script.d.ts.map +1 -0
  462. package/dist/test/simple-context-handlers.d.ts +12 -0
  463. package/dist/test/simple-context-handlers.d.ts.map +1 -0
  464. package/dist/test/simple-context-lifecycle.d.ts +32 -0
  465. package/dist/test/simple-context-lifecycle.d.ts.map +1 -0
  466. package/dist/test/simple-context-mfconfig.d.ts +10 -0
  467. package/dist/test/simple-context-mfconfig.d.ts.map +1 -0
  468. package/dist/test/simple-context-multi-worker.d.ts +16 -0
  469. package/dist/test/simple-context-multi-worker.d.ts.map +1 -0
  470. package/dist/test/simple-context-paths.d.ts +40 -0
  471. package/dist/test/simple-context-paths.d.ts.map +1 -0
  472. package/dist/test/simple-context-runtime.d.ts +19 -0
  473. package/dist/test/simple-context-runtime.d.ts.map +1 -0
  474. package/dist/test/simple-context-startup.d.ts +11 -0
  475. package/dist/test/simple-context-startup.d.ts.map +1 -0
  476. package/dist/test/simple-context-transport.d.ts +14 -0
  477. package/dist/test/simple-context-transport.d.ts.map +1 -0
  478. package/dist/test/simple-context.d.ts +8 -27
  479. package/dist/test/simple-context.d.ts.map +1 -1
  480. package/dist/test/tail.d.ts +3 -2
  481. package/dist/test/tail.d.ts.map +1 -1
  482. package/dist/test/utilities/analytics-engine.d.ts +22 -0
  483. package/dist/test/utilities/analytics-engine.d.ts.map +1 -0
  484. package/dist/test/utilities/artifacts.d.ts +11 -0
  485. package/dist/test/utilities/artifacts.d.ts.map +1 -0
  486. package/dist/test/utilities/context.d.ts +39 -0
  487. package/dist/test/utilities/context.d.ts.map +1 -0
  488. package/dist/test/utilities/d1.d.ts +21 -0
  489. package/dist/test/utilities/d1.d.ts.map +1 -0
  490. package/dist/test/utilities/env.d.ts +43 -0
  491. package/dist/test/utilities/env.d.ts.map +1 -0
  492. package/dist/test/utilities/kv.d.ts +11 -0
  493. package/dist/test/utilities/kv.d.ts.map +1 -0
  494. package/dist/test/utilities/media.d.ts +16 -0
  495. package/dist/test/utilities/media.d.ts.map +1 -0
  496. package/dist/test/utilities/platform.d.ts +41 -0
  497. package/dist/test/utilities/platform.d.ts.map +1 -0
  498. package/dist/test/utilities/queue.d.ts +5 -0
  499. package/dist/test/utilities/queue.d.ts.map +1 -0
  500. package/dist/test/utilities/r2.d.ts +2 -0
  501. package/dist/test/utilities/r2.d.ts.map +1 -0
  502. package/dist/test/utilities/stream-flagship.d.ts +27 -0
  503. package/dist/test/utilities/stream-flagship.d.ts.map +1 -0
  504. package/dist/test/utilities/vectorize.d.ts +38 -0
  505. package/dist/test/utilities/vectorize.d.ts.map +1 -0
  506. package/dist/test/utilities/workflows.d.ts +26 -0
  507. package/dist/test/utilities/workflows.d.ts.map +1 -0
  508. package/dist/test/utilities.d.ts +13 -98
  509. package/dist/test/utilities.d.ts.map +1 -1
  510. package/dist/test/worker.d.ts +6 -0
  511. package/dist/test/worker.d.ts.map +1 -1
  512. package/dist/transform/durable-object.d.ts.map +1 -1
  513. package/dist/transform/index.d.ts +2 -2
  514. package/dist/transform/worker-entrypoint.d.ts +5 -0
  515. package/dist/transform/worker-entrypoint.d.ts.map +1 -1
  516. package/dist/utils/entrypoint-discovery.d.ts +6 -3
  517. package/dist/utils/entrypoint-discovery.d.ts.map +1 -1
  518. package/dist/utils/glob.d.ts.map +1 -1
  519. package/dist/utils/resolve-package.d.ts.map +1 -1
  520. package/dist/utils/send-email.d.ts +15 -0
  521. package/dist/utils/send-email.d.ts.map +1 -0
  522. package/dist/utils/send-email.js +163 -0
  523. package/dist/vite/config-file.d.ts +25 -0
  524. package/dist/vite/config-file.d.ts.map +1 -0
  525. package/dist/vite/index.d.ts +3 -2
  526. package/dist/vite/index.d.ts.map +1 -1
  527. package/dist/vite/index.js +2 -339
  528. package/dist/vite/plugin-config-hook.d.ts +28 -0
  529. package/dist/vite/plugin-config-hook.d.ts.map +1 -0
  530. package/dist/vite/plugin-context.d.ts +27 -0
  531. package/dist/vite/plugin-context.d.ts.map +1 -0
  532. package/dist/vite/plugin-durable-objects.d.ts +18 -0
  533. package/dist/vite/plugin-durable-objects.d.ts.map +1 -0
  534. package/dist/vite/plugin-programmatic.d.ts +44 -0
  535. package/dist/vite/plugin-programmatic.d.ts.map +1 -0
  536. package/dist/vite/plugin-service-bindings.d.ts +13 -0
  537. package/dist/vite/plugin-service-bindings.d.ts.map +1 -0
  538. package/dist/vite/plugin-transform.d.ts +41 -0
  539. package/dist/vite/plugin-transform.d.ts.map +1 -0
  540. package/dist/vite/plugin.d.ts +10 -41
  541. package/dist/vite/plugin.d.ts.map +1 -1
  542. package/dist/worker-entry/composed-worker.d.ts +7 -0
  543. package/dist/worker-entry/composed-worker.d.ts.map +1 -0
  544. package/dist/worker-entry/durable-object-discovery.d.ts +20 -0
  545. package/dist/worker-entry/durable-object-discovery.d.ts.map +1 -0
  546. package/dist/worker-entry/extensions.d.ts +5 -0
  547. package/dist/worker-entry/extensions.d.ts.map +1 -0
  548. package/dist/worker-entry/routes.d.ts +22 -0
  549. package/dist/worker-entry/routes.d.ts.map +1 -0
  550. package/dist/worker-entry/surface-paths.d.ts +26 -0
  551. package/dist/worker-entry/surface-paths.d.ts.map +1 -0
  552. package/dist/worker-entry/validate-fetch-style.d.ts +12 -0
  553. package/dist/worker-entry/validate-fetch-style.d.ts.map +1 -0
  554. package/dist/workflows/local-workflow-entrypoints.d.ts +7 -0
  555. package/dist/workflows/local-workflow-entrypoints.d.ts.map +1 -0
  556. package/package.json +159 -116
  557. package/R2.md +0 -170
  558. package/dist/account-rvrj687w.js +0 -397
  559. package/dist/ai-dx4fr9jh.js +0 -107
  560. package/dist/bridge/protocol.d.ts.map +0 -1
  561. package/dist/bridge/serialization.d.ts.map +0 -1
  562. package/dist/browser-shim/worker.d.ts +0 -14
  563. package/dist/browser-shim/worker.d.ts.map +0 -1
  564. package/dist/build-mnf6v8gd.js +0 -53
  565. package/dist/deploy-nhceck39.js +0 -70
  566. package/dist/dev-b9dmrj7b.js +0 -2417
  567. package/dist/doctor-fmgb3d28.js +0 -190
  568. package/dist/durable-object-t4kbb0yt.js +0 -13
  569. package/dist/index-07q6yxyc.js +0 -168
  570. package/dist/index-18hvb6gb.js +0 -194
  571. package/dist/index-1xpj0m4r.js +0 -57
  572. package/dist/index-37x76zdn.js +0 -4
  573. package/dist/index-3t6rypgc.js +0 -13
  574. package/dist/index-67qcae0f.js +0 -183
  575. package/dist/index-a855bdsx.js +0 -18
  576. package/dist/index-d8bdkx2h.js +0 -109
  577. package/dist/index-ep3445yc.js +0 -2225
  578. package/dist/index-gz1gndna.js +0 -307
  579. package/dist/index-hcex3rgh.js +0 -266
  580. package/dist/index-m2q41jwa.js +0 -462
  581. package/dist/index-n7rs26ft.js +0 -77
  582. package/dist/index-pf5s73n9.js +0 -1413
  583. package/dist/index-rbht7m9r.js +0 -36
  584. package/dist/index-tfyxa77h.js +0 -850
  585. package/dist/index-tk6ej9dj.js +0 -94
  586. package/dist/index-z14anrqp.js +0 -226
  587. package/dist/init-f9mgmew3.js +0 -186
  588. package/dist/remote-q59qk463.js +0 -97
  589. package/dist/test/bridge-context.d.ts +0 -76
  590. package/dist/test/bridge-context.d.ts.map +0 -1
  591. package/dist/test/multi-worker-context.d.ts +0 -114
  592. package/dist/test/multi-worker-context.d.ts.map +0 -1
  593. package/dist/types-5nyrz1sz.js +0 -454
  594. package/dist/worker-entrypoint-m9th0rg0.js +0 -13
@@ -0,0 +1,1288 @@
1
+ import { l as isEnvVarDescriptor, n as materializePreviewScopedConfig, u as loadDevflareDotenvIntoProcess } from "./preview-C3Cdr8an.js";
2
+ import { S as bindingsSchema, a as normalizeD1Binding, d as normalizeKVBinding, g as normalizeR2Binding, h as normalizeQueueProducer, l as normalizeHyperdriveBinding, n as getLocalKVNamespaceIdentifier, t as getLocalD1DatabaseIdentifier } from "./schema-normalization-BCwTLTGp.js";
3
+ import { d as getPrimaryAccount, n as getEffectiveAccountId } from "./preferences-BKp_7XJx.js";
4
+ import { _ as listR2Buckets, g as listQueues, h as listKVNamespaces, i as createR2Bucket, m as listHyperdrives, n as createKVNamespace, p as listD1Databases, r as createQueue, t as createD1Database, v as listVectorizeIndexes } from "./account-resources-CsmVowJp.js";
5
+ import { createRequire } from "node:module";
6
+ import { existsSync } from "node:fs";
7
+ import { readFile } from "node:fs/promises";
8
+ import { dirname, join, resolve } from "pathe";
9
+ import { z } from "zod";
10
+ //#region src/config/compatibility.ts
11
+ const FORCED_COMPATIBILITY_FLAGS = ["nodejs_compat", "nodejs_als"];
12
+ function normalizeCompatibilityFlags(flags = []) {
13
+ return [...new Set([...FORCED_COMPATIBILITY_FLAGS, ...flags])];
14
+ }
15
+ //#endregion
16
+ //#region src/config/schema-build.ts
17
+ const rolldownOptionsSchema = z.custom((value) => {
18
+ return typeof value === "object" && value !== null && !Array.isArray(value);
19
+ }, { message: "Expected Rolldown options object" });
20
+ /**
21
+ * Rolldown configuration for Durable Object bundling.
22
+ * Controls Devflare's Rolldown-based DO bundler in local development.
23
+ */
24
+ const rolldownConfigSchema = z.object({
25
+ target: z.string().optional(),
26
+ minify: z.boolean().optional(),
27
+ sourcemap: z.boolean().optional(),
28
+ options: rolldownOptionsSchema.optional()
29
+ }).optional();
30
+ /**
31
+ * Vite-related configuration namespace.
32
+ * This keeps Vite-specific configuration distinct from Rolldown/DO bundling.
33
+ *
34
+ * Note: raw Vite build/server configuration still belongs in `vite.config.*`.
35
+ * Devflare currently models `plugins` here and leaves room for future Vite-side
36
+ * config without overloading the root config shape.
37
+ */
38
+ const viteConfigSchema = z.object({ plugins: z.array(z.unknown()).optional() }).catchall(z.unknown()).optional();
39
+ const envConfigSchemaInner = z.lazy(() => z.object(rootConfigShape).omit({
40
+ accountId: true,
41
+ wsRoutes: true
42
+ }).partial().strict());
43
+ //#endregion
44
+ //#region src/config/cron.ts
45
+ const CRON_FIELDS = [
46
+ {
47
+ name: "minute",
48
+ min: 0,
49
+ max: 59
50
+ },
51
+ {
52
+ name: "hour",
53
+ min: 0,
54
+ max: 23
55
+ },
56
+ {
57
+ name: "day-of-month",
58
+ min: 1,
59
+ max: 31
60
+ },
61
+ {
62
+ name: "month",
63
+ min: 1,
64
+ max: 12,
65
+ names: {
66
+ JAN: 1,
67
+ FEB: 2,
68
+ MAR: 3,
69
+ APR: 4,
70
+ MAY: 5,
71
+ JUN: 6,
72
+ JUL: 7,
73
+ AUG: 8,
74
+ SEP: 9,
75
+ OCT: 10,
76
+ NOV: 11,
77
+ DEC: 12
78
+ }
79
+ },
80
+ {
81
+ name: "day-of-week",
82
+ min: 0,
83
+ max: 7,
84
+ names: {
85
+ SUN: 0,
86
+ MON: 1,
87
+ TUE: 2,
88
+ WED: 3,
89
+ THU: 4,
90
+ FRI: 5,
91
+ SAT: 6
92
+ }
93
+ }
94
+ ];
95
+ /** Resolve a single value token (number or 3-letter name) for a field. */
96
+ function resolveFieldValue(token, field) {
97
+ if (/^\d+$/.test(token)) {
98
+ const value = Number.parseInt(token, 10);
99
+ if (value < field.min || value > field.max) return null;
100
+ return value;
101
+ }
102
+ if (field.names) {
103
+ const named = field.names[token.toUpperCase()];
104
+ if (named !== void 0) return named;
105
+ }
106
+ return null;
107
+ }
108
+ /** Validate a single non-`*` element (a number, range, or stepped form). */
109
+ function isValidFieldElement(element, field) {
110
+ let base = element;
111
+ let step = null;
112
+ const slashIndex = element.indexOf("/");
113
+ if (slashIndex !== -1) {
114
+ base = element.slice(0, slashIndex);
115
+ step = element.slice(slashIndex + 1);
116
+ if (!/^\d+$/.test(step) || Number.parseInt(step, 10) < 1) return false;
117
+ }
118
+ if (base === "*") return true;
119
+ const dashIndex = base.indexOf("-");
120
+ if (dashIndex !== -1) {
121
+ const startToken = base.slice(0, dashIndex);
122
+ const endToken = base.slice(dashIndex + 1);
123
+ const start = resolveFieldValue(startToken, field);
124
+ const end = resolveFieldValue(endToken, field);
125
+ if (start === null || end === null) return false;
126
+ return start <= end;
127
+ }
128
+ return resolveFieldValue(base, field) !== null;
129
+ }
130
+ /** Validate a single cron field (which may be a comma-separated list). */
131
+ function isValidCronField(value, field) {
132
+ if (value.length === 0) return false;
133
+ const elements = value.split(",");
134
+ for (const element of elements) if (element.length === 0 || !isValidFieldElement(element, field)) return false;
135
+ return true;
136
+ }
137
+ /**
138
+ * Returns true when `expression` is a valid Cloudflare 5-field cron expression.
139
+ *
140
+ * Accepts `*`, numbers, ranges (`1-5`), lists (`1,3,5`), steps (`*\/5`,
141
+ * `1-30/5`, `5/15`) and the 3-letter month (`JAN`-`DEC`) / weekday
142
+ * (`SUN`-`SAT`) names, with the correct per-field numeric ranges. Cloudflare
143
+ * cron has no seconds and no year field, so anything other than 5 fields is
144
+ * rejected.
145
+ */
146
+ function isValidCronExpression(expression) {
147
+ if (typeof expression !== "string") return false;
148
+ const fields = expression.trim().split(/\s+/);
149
+ if (fields.length !== CRON_FIELDS.length) return false;
150
+ for (let index = 0; index < CRON_FIELDS.length; index++) if (!isValidCronField(fields[index], CRON_FIELDS[index])) return false;
151
+ return true;
152
+ }
153
+ /**
154
+ * Human-readable message for an invalid cron expression, naming the bad value.
155
+ */
156
+ function formatInvalidCronMessage(expression) {
157
+ return `Invalid cron expression "${expression}". Cloudflare cron triggers use 5 fields: minute (0-59) hour (0-23) day-of-month (1-31) month (1-12 or JAN-DEC) day-of-week (0-7 or SUN-SAT). Each field accepts *, numbers, ranges (1-5), lists (1,3,5) and steps (*/5).`;
158
+ }
159
+ /**
160
+ * Throw a descriptive error when `expression` is not a valid cron expression.
161
+ */
162
+ function assertValidCronExpression(expression) {
163
+ if (!isValidCronExpression(expression)) throw new Error(formatInvalidCronMessage(expression));
164
+ }
165
+ /**
166
+ * Cloudflare Workers compatibility date schema.
167
+ * Must be in YYYY-MM-DD format (e.g., '2025-01-07').
168
+ */
169
+ const compatibilityDateSchema = z.string().regex(/^\d{4}-\d{2}-\d{2}$/, { message: "Compatibility date must be in YYYY-MM-DD format" });
170
+ /**
171
+ * Built-in file router configuration used for `src/routes/**` discovery.
172
+ */
173
+ const routesConfigSchema = z.object({
174
+ dir: z.string(),
175
+ prefix: z.string().optional()
176
+ });
177
+ /**
178
+ * File handler configuration.
179
+ * Maps handler types to their source file paths.
180
+ */
181
+ const filesSchema = z.object({
182
+ fetch: z.union([z.string(), z.literal(false)]).optional(),
183
+ queue: z.union([z.string(), z.literal(false)]).optional(),
184
+ scheduled: z.union([z.string(), z.literal(false)]).optional(),
185
+ email: z.union([z.string(), z.literal(false)]).optional(),
186
+ tail: z.union([z.string(), z.literal(false)]).optional(),
187
+ durableObjects: z.union([z.string(), z.literal(false)]).optional(),
188
+ entrypoints: z.union([z.string(), z.literal(false)]).optional(),
189
+ workflows: z.union([z.string(), z.literal(false)]).optional(),
190
+ routes: z.union([routesConfigSchema, z.literal(false)]).optional(),
191
+ transport: z.union([z.string(), z.null()]).optional()
192
+ }).optional();
193
+ /**
194
+ * Tail Consumer configuration.
195
+ */
196
+ const tailConsumerSchema = z.union([z.string().min(1), z.object({
197
+ service: z.string().min(1),
198
+ environment: z.string().min(1).optional()
199
+ }).strict()]);
200
+ /**
201
+ * Trigger configuration for scheduled (cron) events.
202
+ *
203
+ * Each cron expression is validated against the Cloudflare 5-field cron grammar
204
+ * at config-parse time, so a typo fails before deploy instead of silently never
205
+ * firing in production.
206
+ */
207
+ const triggersSchema = z.object({ crons: z.array(z.string()).optional() }).superRefine((triggers, ctx) => {
208
+ if (!triggers.crons) return;
209
+ triggers.crons.forEach((cron, index) => {
210
+ if (!isValidCronExpression(cron)) ctx.addIssue({
211
+ code: z.ZodIssueCode.custom,
212
+ path: ["crons", index],
213
+ message: formatInvalidCronMessage(cron)
214
+ });
215
+ });
216
+ }).optional();
217
+ /**
218
+ * Preview-specific Devflare behavior.
219
+ */
220
+ const previewsConfigSchema = z.object({ includeCrons: z.boolean().optional().default(false) }).optional();
221
+ /**
222
+ * Dev server configuration for `devflare dev`.
223
+ *
224
+ * Controls the host and port the local Miniflare runtime instance binds to.
225
+ * This is a development-only setting and is never emitted to compiled Wrangler
226
+ * output. CLI flags (`--runtime-port`, `--runtime-host`) and environment
227
+ * variables (`DEVFLARE_RUNTIME_PORT`, `DEVFLARE_RUNTIME_HOST`) take precedence
228
+ * over these values.
229
+ */
230
+ const serverConfigSchema = z.object({
231
+ host: z.string().min(1).optional(),
232
+ port: z.number().int().min(1).max(65535).optional()
233
+ }).strict().optional();
234
+ /**
235
+ * Secret declaration options.
236
+ */
237
+ const secretConfigSchema = z.object({ required: z.boolean().optional().default(true) });
238
+ /**
239
+ * Route configuration for worker deployment.
240
+ */
241
+ const routeConfigSchema = z.object({
242
+ pattern: z.string(),
243
+ zone_name: z.string().optional(),
244
+ zone_id: z.string().optional(),
245
+ custom_domain: z.boolean().optional()
246
+ }).superRefine((route, ctx) => {
247
+ if (!route.custom_domain) return;
248
+ if (route.pattern.includes("*")) ctx.addIssue({
249
+ code: z.ZodIssueCode.custom,
250
+ path: ["pattern"],
251
+ message: "Wildcard operators (*) are not allowed in Custom Domains"
252
+ });
253
+ if (route.pattern.includes("/")) ctx.addIssue({
254
+ code: z.ZodIssueCode.custom,
255
+ path: ["pattern"],
256
+ message: "Paths are not allowed in Custom Domains"
257
+ });
258
+ });
259
+ /**
260
+ * WebSocket route configuration for dev mode Durable Object proxying.
261
+ */
262
+ const wsRouteConfigSchema = z.object({
263
+ pattern: z.string(),
264
+ doNamespace: z.string(),
265
+ idParam: z.string().default("id"),
266
+ forwardPath: z.string().default("/websocket")
267
+ });
268
+ /**
269
+ * Static assets configuration.
270
+ */
271
+ const assetsConfigSchema = z.object({
272
+ directory: z.string(),
273
+ binding: z.string().optional(),
274
+ html_handling: z.enum([
275
+ "auto-trailing-slash",
276
+ "force-trailing-slash",
277
+ "drop-trailing-slash",
278
+ "none"
279
+ ]).optional(),
280
+ not_found_handling: z.enum([
281
+ "single-page-application",
282
+ "404-page",
283
+ "none"
284
+ ]).optional(),
285
+ run_worker_first: z.union([z.boolean(), z.array(z.string())]).optional()
286
+ }).strict().optional();
287
+ const smartPlacementSchema = z.object({
288
+ mode: z.enum(["off", "smart"]),
289
+ hint: z.string().optional()
290
+ }).strict().superRefine((placement, ctx) => {
291
+ if (placement.hint !== void 0 && placement.mode !== "smart") ctx.addIssue({
292
+ code: z.ZodIssueCode.custom,
293
+ path: ["hint"],
294
+ message: "placement.hint can only be set when placement.mode is smart"
295
+ });
296
+ });
297
+ const targetedRegionPlacementSchema = z.object({
298
+ mode: z.literal("targeted").optional(),
299
+ region: z.string().min(1)
300
+ }).strict();
301
+ const targetedHostPlacementSchema = z.object({
302
+ mode: z.literal("targeted").optional(),
303
+ host: z.string().min(1)
304
+ }).strict();
305
+ const targetedHostnamePlacementSchema = z.object({
306
+ mode: z.literal("targeted").optional(),
307
+ hostname: z.string().min(1)
308
+ }).strict();
309
+ /**
310
+ * Worker placement configuration.
311
+ */
312
+ const placementSchema = z.union([
313
+ smartPlacementSchema,
314
+ targetedRegionPlacementSchema,
315
+ targetedHostPlacementSchema,
316
+ targetedHostnamePlacementSchema
317
+ ]).optional();
318
+ const samplingRateSchema = z.number().min(0).max(1);
319
+ const observabilityLogsSchema = z.object({
320
+ enabled: z.boolean().optional(),
321
+ head_sampling_rate: samplingRateSchema.optional(),
322
+ invocation_logs: z.boolean().optional(),
323
+ persist: z.boolean().optional(),
324
+ destinations: z.array(z.string()).optional()
325
+ }).strict();
326
+ const observabilityTracesSchema = z.object({
327
+ enabled: z.boolean().optional(),
328
+ head_sampling_rate: samplingRateSchema.optional(),
329
+ persist: z.boolean().optional(),
330
+ destinations: z.array(z.string()).optional()
331
+ }).strict();
332
+ /**
333
+ * Observability configuration for logs and traces.
334
+ */
335
+ const observabilitySchema = z.object({
336
+ enabled: z.boolean().optional(),
337
+ head_sampling_rate: samplingRateSchema.optional(),
338
+ logs: observabilityLogsSchema.optional(),
339
+ traces: observabilityTracesSchema.optional()
340
+ }).strict().optional();
341
+ /**
342
+ * Resource limits configuration.
343
+ */
344
+ const limitsSchema = z.object({
345
+ cpu_ms: z.number().optional(),
346
+ subrequests: z.number().optional()
347
+ }).strict().optional();
348
+ const rolloutStepPercentageSchema = z.union([z.number().int().positive(), z.array(z.number().int().positive()).min(1)]);
349
+ /**
350
+ * Cloudflare Containers configuration.
351
+ *
352
+ * Devflare authors this in camelCase and compiles to Wrangler's top-level
353
+ * `containers` array. Runtime launch/testing is handled by the local
354
+ * container test shim, not by Miniflare itself.
355
+ */
356
+ const containerConfigSchema = z.object({
357
+ className: z.string().min(1),
358
+ image: z.string().min(1),
359
+ maxInstances: z.number().int().positive().optional(),
360
+ instanceType: z.string().min(1).optional(),
361
+ name: z.string().min(1).optional(),
362
+ imageBuildContext: z.string().min(1).optional(),
363
+ imageVars: z.record(z.string(), z.string()).optional(),
364
+ rolloutActiveGracePeriod: z.number().int().nonnegative().optional(),
365
+ rolloutStepPercentage: rolloutStepPercentageSchema.optional()
366
+ }).strict();
367
+ const containersConfigSchema = z.array(containerConfigSchema).optional();
368
+ /**
369
+ * Module rules for non-JavaScript Worker modules and imported assets.
370
+ *
371
+ * Wrangler also exposes Python-specific rule types while Python Workers are in
372
+ * beta. Devflare keeps those behind `wrangler.passthrough` until the local
373
+ * Python Worker toolchain has a stable Devflare integration point.
374
+ */
375
+ const moduleRuleSchema = z.object({
376
+ type: z.enum([
377
+ "ESModule",
378
+ "CommonJS",
379
+ "CompiledWasm",
380
+ "Text",
381
+ "Data"
382
+ ]),
383
+ globs: z.array(z.string()).min(1),
384
+ fallthrough: z.boolean().optional()
385
+ }).strict();
386
+ const moduleRulesSchema = z.array(moduleRuleSchema).optional();
387
+ /**
388
+ * Durable Object migration configuration.
389
+ */
390
+ const renamedClassMigrationSchema = z.object({
391
+ from: z.string(),
392
+ to: z.string()
393
+ }).strict();
394
+ const migrationSchema = z.object({
395
+ tag: z.string(),
396
+ new_classes: z.array(z.string()).optional(),
397
+ renamed_classes: z.array(renamedClassMigrationSchema).optional(),
398
+ deleted_classes: z.array(z.string()).optional(),
399
+ new_sqlite_classes: z.array(z.string()).optional()
400
+ }).strict();
401
+ /**
402
+ * Wrangler configuration passthrough.
403
+ */
404
+ const wranglerConfigSchema = z.object({ passthrough: z.record(z.string(), z.unknown()).optional() }).optional();
405
+ //#endregion
406
+ //#region src/config/schema.ts
407
+ /** Helper to get current date in YYYY-MM-DD format */
408
+ function getCurrentDate() {
409
+ return (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
410
+ }
411
+ function getSecretsStoreShorthandBindings(config) {
412
+ return Object.entries(config.bindings?.secretsStore ?? {}).filter(([, binding]) => typeof binding === "string").map(([bindingName]) => bindingName);
413
+ }
414
+ function addSecretsStoreShorthandIssues(ctx, config, pathPrefix = []) {
415
+ if (config.secretsStoreId) return;
416
+ for (const bindingName of getSecretsStoreShorthandBindings(config)) ctx.addIssue({
417
+ code: z.ZodIssueCode.custom,
418
+ path: [
419
+ ...pathPrefix,
420
+ "bindings",
421
+ "secretsStore",
422
+ bindingName
423
+ ],
424
+ message: `Secrets Store binding "${bindingName}" uses shorthand and requires top-level secretsStoreId.`
425
+ });
426
+ }
427
+ const varValueSchema = z.lazy(() => z.union([
428
+ z.string(),
429
+ z.number(),
430
+ z.boolean(),
431
+ z.null(),
432
+ z.custom(isEnvVarDescriptor),
433
+ z.array(varValueSchema),
434
+ z.record(z.string(), varValueSchema)
435
+ ]));
436
+ /**
437
+ * Raw Zod shape of the root devflare configuration (excluding the `env` field,
438
+ * which references back into this shape via the environment override schema).
439
+ *
440
+ * Exported so `schema-env.ts` can derive the environment override schema from
441
+ * the single source of truth without hand-listing every field.
442
+ */
443
+ const rootConfigShape = {
444
+ name: z.string({ required_error: "Worker name is required" }),
445
+ accountId: z.string().optional(),
446
+ secretsStoreId: z.string().min(1).optional(),
447
+ compatibilityDate: compatibilityDateSchema.optional().default(getCurrentDate),
448
+ compatibilityFlags: z.array(z.string()).optional().transform((flags = []) => normalizeCompatibilityFlags(flags)),
449
+ previews: previewsConfigSchema,
450
+ server: serverConfigSchema,
451
+ files: filesSchema,
452
+ bindings: bindingsSchema,
453
+ triggers: triggersSchema,
454
+ rules: moduleRulesSchema,
455
+ findAdditionalModules: z.boolean().optional(),
456
+ baseDir: z.string().optional(),
457
+ preserveFileNames: z.boolean().optional(),
458
+ logpush: z.boolean().optional(),
459
+ uploadSourceMaps: z.boolean().optional(),
460
+ keepVars: z.boolean().optional(),
461
+ tailConsumers: z.array(tailConsumerSchema).optional(),
462
+ vars: z.record(z.string(), varValueSchema).optional(),
463
+ secrets: z.record(z.string(), secretConfigSchema).optional(),
464
+ routes: z.array(routeConfigSchema).optional(),
465
+ wsRoutes: z.array(wsRouteConfigSchema).optional(),
466
+ assets: assetsConfigSchema,
467
+ containers: containersConfigSchema,
468
+ placement: placementSchema,
469
+ limits: limitsSchema,
470
+ observability: observabilitySchema,
471
+ migrations: z.array(migrationSchema).optional(),
472
+ rolldown: rolldownConfigSchema,
473
+ vite: viteConfigSchema,
474
+ wrangler: wranglerConfigSchema
475
+ };
476
+ const configSchema = z.object({
477
+ ...rootConfigShape,
478
+ env: z.record(z.string(), envConfigSchemaInner).optional()
479
+ }).strict().superRefine((config, ctx) => {
480
+ addSecretsStoreShorthandIssues(ctx, config);
481
+ for (const [envName, envConfig] of Object.entries(config.env ?? {})) addSecretsStoreShorthandIssues(ctx, {
482
+ ...envConfig,
483
+ secretsStoreId: envConfig.secretsStoreId ?? config.secretsStoreId
484
+ }, ["env", envName]);
485
+ });
486
+ //#endregion
487
+ //#region src/config/resolve.ts
488
+ function isPlainObject(value) {
489
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
490
+ const prototype = Object.getPrototypeOf(value);
491
+ return prototype === Object.prototype || prototype === null;
492
+ }
493
+ function mergeEnvironmentValue(base, override) {
494
+ if (override === void 0) return base;
495
+ if (Array.isArray(override)) return [...override];
496
+ if (isPlainObject(override)) {
497
+ const baseObject = isPlainObject(base) ? base : {};
498
+ const mergedObject = { ...baseObject };
499
+ for (const [key, value] of Object.entries(override)) mergedObject[key] = mergeEnvironmentValue(baseObject[key], value);
500
+ return mergedObject;
501
+ }
502
+ return override;
503
+ }
504
+ function withNormalizedCompatibilityFlags(config) {
505
+ return {
506
+ ...config,
507
+ compatibilityFlags: normalizeCompatibilityFlags(config.compatibilityFlags)
508
+ };
509
+ }
510
+ function mergeConfigForEnvironment(config, environment) {
511
+ if (!environment || !config.env?.[environment]) return withNormalizedCompatibilityFlags(config);
512
+ return withNormalizedCompatibilityFlags(mergeEnvironmentValue(config, config.env[environment]));
513
+ }
514
+ /**
515
+ * @internal Prefer the unified `resolveResources(config, { phase: 'build' })`
516
+ * facade for the env-merge + preview-materialize pipeline. This lower-level
517
+ * helper remains exported as the implementation that the seam and the
518
+ * build-time compiler delegate to; it is not part of the recommended public
519
+ * surface.
520
+ */
521
+ function resolveConfigForEnvironment(config, environment) {
522
+ return materializePreviewScopedConfig(mergeConfigForEnvironment(config, environment), { environment });
523
+ }
524
+ //#endregion
525
+ //#region src/config/framework-providers.ts
526
+ const SVELTE_CONFIG_FILES = [
527
+ "svelte.config.js",
528
+ "svelte.config.mjs",
529
+ "svelte.config.ts",
530
+ "svelte.config.cjs"
531
+ ];
532
+ async function readTextIfExists(path) {
533
+ try {
534
+ return await readFile(path, "utf-8");
535
+ } catch {
536
+ return null;
537
+ }
538
+ }
539
+ async function readPackageDependencies(cwd) {
540
+ const packageJsonText = await readTextIfExists(join(cwd, "package.json"));
541
+ if (!packageJsonText) return null;
542
+ try {
543
+ const packageJson = JSON.parse(packageJsonText);
544
+ return {
545
+ ...packageJson.dependencies ?? {},
546
+ ...packageJson.devDependencies ?? {},
547
+ ...packageJson.peerDependencies ?? {}
548
+ };
549
+ } catch {
550
+ return null;
551
+ }
552
+ }
553
+ async function findFirstExistingTextFile(cwd, candidates) {
554
+ for (const candidate of candidates) {
555
+ const fileText = await readTextIfExists(join(cwd, candidate));
556
+ if (fileText !== null) return fileText;
557
+ }
558
+ return null;
559
+ }
560
+ const frameworkProviders = [{
561
+ id: "sveltekit-cloudflare",
562
+ async resolve(context) {
563
+ const dependencies = await readPackageDependencies(context.cwd);
564
+ if (!dependencies?.["@sveltejs/kit"] || !dependencies["@sveltejs/adapter-cloudflare"]) return null;
565
+ const svelteConfigText = await findFirstExistingTextFile(context.cwd, SVELTE_CONFIG_FILES);
566
+ if (!svelteConfigText) return null;
567
+ if (!/@sveltejs\/adapter-cloudflare|adapter-cloudflare/.test(svelteConfigText)) return null;
568
+ return {
569
+ id: this.id,
570
+ config: {
571
+ files: { fetch: ".adapter-cloudflare/_worker.js" },
572
+ assets: {
573
+ binding: "ASSETS",
574
+ directory: ".adapter-cloudflare"
575
+ }
576
+ }
577
+ };
578
+ }
579
+ }];
580
+ function hasFrameworkInferenceGap(config) {
581
+ return config.files?.fetch === void 0 || config.assets?.directory === void 0 || config.assets?.binding === void 0;
582
+ }
583
+ function mergeInferredConfig(config, inferredConfig) {
584
+ const mergedFiles = inferredConfig.files ? {
585
+ ...inferredConfig.files,
586
+ ...config.files ?? {}
587
+ } : config.files;
588
+ const mergedAssets = inferredConfig.assets ? {
589
+ ...inferredConfig.assets,
590
+ ...config.assets ?? {}
591
+ } : config.assets;
592
+ return {
593
+ ...config,
594
+ ...mergedFiles && { files: mergedFiles },
595
+ ...mergedAssets && { assets: mergedAssets }
596
+ };
597
+ }
598
+ async function applyFrameworkConfigProviders(config, context) {
599
+ if (!hasFrameworkInferenceGap(config)) return config;
600
+ for (const provider of frameworkProviders) {
601
+ const resolution = await provider.resolve({
602
+ ...context,
603
+ config
604
+ });
605
+ if (!resolution) continue;
606
+ return mergeInferredConfig(config, resolution.config);
607
+ }
608
+ return config;
609
+ }
610
+ //#endregion
611
+ //#region src/config/binding-resolution-helpers.ts
612
+ function normalizeKVNameBinding(bindingConfig) {
613
+ const normalized = normalizeKVBinding(bindingConfig);
614
+ return {
615
+ id: normalized.namespaceId,
616
+ name: normalized.name
617
+ };
618
+ }
619
+ function normalizeD1NameBinding(bindingConfig) {
620
+ const normalized = normalizeD1Binding(bindingConfig);
621
+ return {
622
+ id: normalized.databaseId,
623
+ name: normalized.name
624
+ };
625
+ }
626
+ function normalizeHyperdriveNameBinding(bindingConfig) {
627
+ const normalized = normalizeHyperdriveBinding(bindingConfig);
628
+ return {
629
+ id: normalized.configurationId,
630
+ name: normalized.name
631
+ };
632
+ }
633
+ function materializeIdBindings(bindings, resolveId) {
634
+ return Object.fromEntries(Object.entries(bindings).map(([bindingName, bindingConfig]) => {
635
+ return [bindingName, { id: resolveId(bindingConfig) }];
636
+ }));
637
+ }
638
+ function materializeHyperdriveIdBindings(bindings, idsByName) {
639
+ if (!bindings) return;
640
+ return Object.fromEntries(Object.entries(bindings).map(([bindingName, bindingConfig]) => {
641
+ const normalized = normalizeHyperdriveBinding(bindingConfig);
642
+ return [bindingName, {
643
+ id: normalized.configurationId ?? idsByName?.get(normalized.name ?? "") ?? normalized.name ?? "",
644
+ ...normalized.localConnectionString && { localConnectionString: normalized.localConnectionString }
645
+ }];
646
+ }));
647
+ }
648
+ function collectPendingNameBindings(bindings, normalizeBinding) {
649
+ if (!bindings) return [];
650
+ return Object.entries(bindings).map(([bindingName, bindingConfig]) => {
651
+ const normalized = normalizeBinding(bindingConfig);
652
+ return normalized.id ? null : {
653
+ bindingName,
654
+ resourceName: normalized.name ?? ""
655
+ };
656
+ }).filter((binding) => binding !== null);
657
+ }
658
+ function materializeResolvedNameBindings(bindings, normalizeBinding, idsByName) {
659
+ if (!bindings) return;
660
+ return materializeIdBindings(bindings, (bindingConfig) => {
661
+ const normalized = normalizeBinding(bindingConfig);
662
+ return normalized.id ?? idsByName.get(normalized.name ?? "") ?? "";
663
+ });
664
+ }
665
+ function withResolvedIdBindings(resolvedConfig, bindings) {
666
+ return {
667
+ ...resolvedConfig,
668
+ bindings: {
669
+ ...resolvedConfig.bindings,
670
+ ...bindings.kv ? { kv: bindings.kv } : {},
671
+ ...bindings.d1 ? { d1: bindings.d1 } : {},
672
+ ...bindings.hyperdrive ? { hyperdrive: bindings.hyperdrive } : {}
673
+ }
674
+ };
675
+ }
676
+ function formatMissingBindings(missing) {
677
+ return missing.map(({ bindingName, resourceName }) => `${bindingName} → ${resourceName}`).join(", ");
678
+ }
679
+ //#endregion
680
+ //#region src/config/deploy-resources.ts
681
+ const defaultDeployResourcePreparationApi = {
682
+ getPrimaryAccount,
683
+ getEffectiveAccountId,
684
+ listKVNamespaces,
685
+ createKVNamespace,
686
+ listD1Databases,
687
+ createD1Database,
688
+ listR2Buckets,
689
+ createR2Bucket,
690
+ listQueues,
691
+ createQueue,
692
+ listHyperdrives,
693
+ listVectorizeIndexes
694
+ };
695
+ function createEmptyDeployResourceNames() {
696
+ return {
697
+ kv: [],
698
+ d1: [],
699
+ r2: [],
700
+ queues: [],
701
+ vectorize: [],
702
+ hyperdrive: []
703
+ };
704
+ }
705
+ /**
706
+ * C13 — surface partial-progress orphans on a failed deploy preparation.
707
+ *
708
+ * If any resource was already created before the throw, attach a clear
709
+ * footer to the error message listing what was created so the user can
710
+ * decide whether to keep, delete, or rerun. Auto-deletion is intentionally
711
+ * not performed: deletion is irreversible, has cross-binding side effects
712
+ * (DBs may have data, queues may be inflight), and the deploy may simply
713
+ * be retried after fixing the underlying error.
714
+ */
715
+ function decorateOrphanError(err, created) {
716
+ const summaryParts = [];
717
+ if (created.kv.length > 0) summaryParts.push(`KV: ${created.kv.join(", ")}`);
718
+ if (created.d1.length > 0) summaryParts.push(`D1: ${created.d1.join(", ")}`);
719
+ if (created.hyperdrive.length > 0) summaryParts.push(`Hyperdrive: ${created.hyperdrive.join(", ")}`);
720
+ if (created.r2.length > 0) summaryParts.push(`R2: ${created.r2.join(", ")}`);
721
+ if (created.queues.length > 0) summaryParts.push(`Queues: ${created.queues.join(", ")}`);
722
+ if (created.vectorize.length > 0) summaryParts.push(`Vectorize: ${created.vectorize.join(", ")}`);
723
+ const base = err instanceof Error ? err : new Error(String(err));
724
+ if (summaryParts.length === 0) return base;
725
+ const orphanFooter = `\n\nDeploy preparation failed AFTER provisioning the following Cloudflare resources, which were left in your account:\n - ${summaryParts.join("\n - ")}\nRe-run \`devflare deploy\` after fixing the error to reuse them, or delete them manually if abandoning the deploy.`;
726
+ const decorated = /* @__PURE__ */ new Error(`${base.message}${orphanFooter}`);
727
+ if ("cause" in base && base.cause !== void 0) decorated.cause = base.cause;
728
+ else decorated.cause = base;
729
+ return decorated;
730
+ }
731
+ function resolveDeployResourcePreparationApi(overrides) {
732
+ return {
733
+ ...defaultDeployResourcePreparationApi,
734
+ ...overrides ?? {}
735
+ };
736
+ }
737
+ function resolveUniqueNames(values) {
738
+ const names = /* @__PURE__ */ new Set();
739
+ for (const value of values) {
740
+ const trimmed = value?.trim();
741
+ if (!trimmed) continue;
742
+ names.add(trimmed);
743
+ }
744
+ return [...names];
745
+ }
746
+ function collectQueueNames(config) {
747
+ const queues = config.bindings?.queues;
748
+ if (!queues) return [];
749
+ return resolveUniqueNames([...Object.values(queues.producers ?? {}).map((producer) => normalizeQueueProducer(producer).queue), ...(queues.consumers ?? []).flatMap((consumer) => [consumer.queue, consumer.deadLetterQueue])]);
750
+ }
751
+ function collectVectorizeIndexNames(config) {
752
+ return resolveUniqueNames(Object.values(config.bindings?.vectorize ?? {}).map((binding) => binding.indexName));
753
+ }
754
+ function resolveUniquePendingBindings(pendingBindings) {
755
+ return [...new Map(pendingBindings.map((binding) => [binding.resourceName, binding])).values()];
756
+ }
757
+ async function resolveLookupAccountId$1(config, options, cloudflareApi) {
758
+ const envAccountId = typeof process !== "undefined" ? process.env?.CLOUDFLARE_ACCOUNT_ID?.trim() : void 0;
759
+ const explicitAccountId = options.accountId ?? config.accountId ?? (envAccountId || void 0);
760
+ if (explicitAccountId) return explicitAccountId;
761
+ let primaryAccount;
762
+ try {
763
+ primaryAccount = await cloudflareApi.getPrimaryAccount();
764
+ } catch (error) {
765
+ throw new ConfigResourceResolutionError("Could not prepare Cloudflare-backed deploy resources because Devflare could not read your Cloudflare accounts. Set accountId in devflare.config.ts, configure a workspace/global default account, or log in with Wrangler.", error);
766
+ }
767
+ if (!primaryAccount) throw new ConfigResourceResolutionError("Could not prepare Cloudflare-backed deploy resources because no Cloudflare account is available. Set accountId in devflare.config.ts, configure a workspace/global default account, or log in with Wrangler.");
768
+ try {
769
+ const { accountId } = await cloudflareApi.getEffectiveAccountId(primaryAccount.id);
770
+ return accountId;
771
+ } catch (error) {
772
+ throw new ConfigResourceResolutionError(`Could not determine the effective Cloudflare account for deploy-time resource preparation after selecting primary account ${primaryAccount.id}.`, error);
773
+ }
774
+ }
775
+ async function resolveOrCreateResourceIdsByName(pendingBindings, options) {
776
+ if (pendingBindings.length === 0) return {
777
+ idsByName: /* @__PURE__ */ new Map(),
778
+ created: [],
779
+ existing: []
780
+ };
781
+ let resources;
782
+ try {
783
+ resources = await options.listResources();
784
+ } catch (error) {
785
+ throw new ConfigResourceResolutionError(options.listFailureMessage, error);
786
+ }
787
+ const idsByName = new Map(resources.map((resource) => [resource.name, resource.id]));
788
+ const created = [];
789
+ const existing = resolveUniquePendingBindings(pendingBindings).filter(({ resourceName }) => idsByName.has(resourceName)).map(({ resourceName }) => resourceName);
790
+ const missingBindings = resolveUniquePendingBindings(pendingBindings).filter(({ resourceName }) => !idsByName.has(resourceName));
791
+ if (missingBindings.length === 0) return {
792
+ idsByName,
793
+ created,
794
+ existing
795
+ };
796
+ if (!options.createResource) throw new ConfigResourceResolutionError(options.missingFailureMessage(missingBindings));
797
+ for (const missingBinding of missingBindings) try {
798
+ const createdResource = await options.createResource(missingBinding.resourceName);
799
+ idsByName.set(createdResource.name, createdResource.id);
800
+ created.push(createdResource.name);
801
+ } catch (error) {
802
+ throw new ConfigResourceResolutionError(options.createFailureMessage?.(missingBinding.resourceName) ?? `Could not create Cloudflare resource "${missingBinding.resourceName}" during deploy preparation.`, error);
803
+ }
804
+ return {
805
+ idsByName,
806
+ created,
807
+ existing
808
+ };
809
+ }
810
+ async function ensureNamedResourcesExist(resourceNames, options) {
811
+ if (resourceNames.length === 0) return {
812
+ created: [],
813
+ existing: []
814
+ };
815
+ let resources;
816
+ try {
817
+ resources = await options.listResources();
818
+ } catch (error) {
819
+ throw new ConfigResourceResolutionError(options.listFailureMessage, error);
820
+ }
821
+ const existingNames = new Set(resources.map((resource) => resource.name));
822
+ const existing = resourceNames.filter((resourceName) => existingNames.has(resourceName));
823
+ const missingNames = resourceNames.filter((resourceName) => !existingNames.has(resourceName));
824
+ const created = [];
825
+ if (missingNames.length === 0) return {
826
+ created,
827
+ existing
828
+ };
829
+ if (!options.createResource) throw new ConfigResourceResolutionError(options.missingFailureMessage(missingNames));
830
+ for (const resourceName of missingNames) try {
831
+ const createdResource = await options.createResource(resourceName);
832
+ created.push(createdResource.name);
833
+ } catch (error) {
834
+ throw new ConfigResourceResolutionError(options.createFailureMessage?.(resourceName) ?? `Could not create Cloudflare resource "${resourceName}" during deploy preparation.`, error);
835
+ }
836
+ return {
837
+ created,
838
+ existing
839
+ };
840
+ }
841
+ async function prepareMaterializedConfigResourcesForDeploy(resolvedConfig, options = {}) {
842
+ const created = createEmptyDeployResourceNames();
843
+ const existing = createEmptyDeployResourceNames();
844
+ const warnings = [];
845
+ const kvBindings = resolvedConfig.bindings?.kv;
846
+ const d1Bindings = resolvedConfig.bindings?.d1;
847
+ const hyperdriveBindings = resolvedConfig.bindings?.hyperdrive;
848
+ const r2Names = resolveUniqueNames(Object.values(resolvedConfig.bindings?.r2 ?? {}).map((bucket) => normalizeR2Binding(bucket).bucketName));
849
+ const queueNames = collectQueueNames(resolvedConfig);
850
+ const vectorizeNames = collectVectorizeIndexNames(resolvedConfig);
851
+ if (!kvBindings && !d1Bindings && !hyperdriveBindings && r2Names.length === 0 && queueNames.length === 0 && vectorizeNames.length === 0) return {
852
+ config: brandAsDeployConfig(resolvedConfig),
853
+ created,
854
+ existing,
855
+ warnings
856
+ };
857
+ const pendingKVNameBindings = collectPendingNameBindings(kvBindings, normalizeKVNameBinding);
858
+ const pendingD1NameBindings = collectPendingNameBindings(d1Bindings, normalizeD1NameBinding);
859
+ const pendingHyperdriveNameBindings = collectPendingNameBindings(hyperdriveBindings, normalizeHyperdriveNameBinding);
860
+ if (pendingKVNameBindings.length === 0 && pendingD1NameBindings.length === 0 && pendingHyperdriveNameBindings.length === 0 && r2Names.length === 0 && queueNames.length === 0 && vectorizeNames.length === 0) return {
861
+ config: brandAsDeployConfig(withResolvedIdBindings(resolvedConfig, {
862
+ kv: kvBindings ? materializeIdBindings(kvBindings, getLocalKVNamespaceIdentifier) : void 0,
863
+ d1: d1Bindings ? materializeIdBindings(d1Bindings, getLocalD1DatabaseIdentifier) : void 0,
864
+ hyperdrive: materializeHyperdriveIdBindings(hyperdriveBindings)
865
+ })),
866
+ created,
867
+ existing,
868
+ warnings
869
+ };
870
+ const cloudflareApi = resolveDeployResourcePreparationApi(options.cloudflare);
871
+ const accountId = await resolveLookupAccountId$1(resolvedConfig, options, cloudflareApi);
872
+ if (options.describeOnly) {
873
+ cloudflareApi.createKVNamespace = (async (_acc, name) => ({
874
+ id: `<would-create:${name}>`,
875
+ name
876
+ }));
877
+ cloudflareApi.createD1Database = (async (_acc, name) => ({
878
+ id: `<would-create:${name}>`,
879
+ name,
880
+ version: "",
881
+ tableCount: 0,
882
+ sizeBytes: 0
883
+ }));
884
+ cloudflareApi.createR2Bucket = (async (_acc, name) => ({ name }));
885
+ cloudflareApi.createQueue = (async (_acc, name) => ({
886
+ id: `<would-create:${name}>`,
887
+ name
888
+ }));
889
+ }
890
+ try {
891
+ const hyperdriveIdsByName = await resolveOrCreateResourceIdsByName(pendingHyperdriveNameBindings, {
892
+ listResources: async () => cloudflareApi.listHyperdrives(accountId),
893
+ listFailureMessage: `Could not list Hyperdrive configurations for Cloudflare account ${accountId} while preparing deploy resources.`,
894
+ missingFailureMessage: (missingBindings) => {
895
+ return `Could not find Hyperdrive configuration(s) for ${formatMissingBindings(missingBindings)} in Cloudflare account ${accountId}. Cloudflare does not expose a create API that Devflare can use from only a binding name, so create the Hyperdrive config first or configure the binding with an explicit id.`;
896
+ }
897
+ });
898
+ created.hyperdrive.push(...hyperdriveIdsByName.created);
899
+ existing.hyperdrive.push(...hyperdriveIdsByName.existing);
900
+ const vectorizeState = await ensureNamedResourcesExist(vectorizeNames, {
901
+ listResources: async () => cloudflareApi.listVectorizeIndexes(accountId),
902
+ listFailureMessage: `Could not list Vectorize indexes for Cloudflare account ${accountId} while preparing deploy resources.`,
903
+ missingFailureMessage: (missingNames) => {
904
+ return `Could not find Vectorize index(es) ${missingNames.join(", ")} in Cloudflare account ${accountId}. Devflare can only auto-provision preview-scoped Vectorize indexes by cloning an existing base index; for normal deploys create the index first.`;
905
+ }
906
+ });
907
+ created.vectorize.push(...vectorizeState.created);
908
+ existing.vectorize.push(...vectorizeState.existing);
909
+ const namespaceIdsByName = await resolveOrCreateResourceIdsByName(pendingKVNameBindings, {
910
+ listResources: async () => cloudflareApi.listKVNamespaces(accountId),
911
+ createResource: async (resourceName) => cloudflareApi.createKVNamespace(accountId, resourceName),
912
+ listFailureMessage: `Could not list KV namespaces for Cloudflare account ${accountId} while preparing deploy resources.`,
913
+ missingFailureMessage: (missingBindings) => {
914
+ return `Could not find KV namespace(s) for ${formatMissingBindings(missingBindings)} in Cloudflare account ${accountId}.`;
915
+ },
916
+ createFailureMessage: (resourceName) => {
917
+ return `Could not create KV namespace "${resourceName}" in Cloudflare account ${accountId} during deploy preparation.`;
918
+ }
919
+ });
920
+ created.kv.push(...namespaceIdsByName.created);
921
+ existing.kv.push(...namespaceIdsByName.existing);
922
+ const databaseIdsByName = await resolveOrCreateResourceIdsByName(pendingD1NameBindings, {
923
+ listResources: async () => cloudflareApi.listD1Databases(accountId),
924
+ createResource: async (resourceName) => cloudflareApi.createD1Database(accountId, resourceName),
925
+ listFailureMessage: `Could not list D1 databases for Cloudflare account ${accountId} while preparing deploy resources.`,
926
+ missingFailureMessage: (missingBindings) => {
927
+ return `Could not find D1 database(s) for ${formatMissingBindings(missingBindings)} in Cloudflare account ${accountId}.`;
928
+ },
929
+ createFailureMessage: (resourceName) => {
930
+ return `Could not create D1 database "${resourceName}" in Cloudflare account ${accountId} during deploy preparation.`;
931
+ }
932
+ });
933
+ created.d1.push(...databaseIdsByName.created);
934
+ existing.d1.push(...databaseIdsByName.existing);
935
+ const r2State = await ensureNamedResourcesExist(r2Names, {
936
+ listResources: async () => cloudflareApi.listR2Buckets(accountId),
937
+ createResource: async (resourceName) => cloudflareApi.createR2Bucket(accountId, resourceName),
938
+ listFailureMessage: `Could not list R2 buckets for Cloudflare account ${accountId} while preparing deploy resources.`,
939
+ missingFailureMessage: (missingNames) => {
940
+ return `Could not find R2 bucket(s) ${missingNames.join(", ")} in Cloudflare account ${accountId}.`;
941
+ },
942
+ createFailureMessage: (resourceName) => {
943
+ return `Could not create R2 bucket "${resourceName}" in Cloudflare account ${accountId} during deploy preparation.`;
944
+ }
945
+ });
946
+ created.r2.push(...r2State.created);
947
+ existing.r2.push(...r2State.existing);
948
+ const queueState = await ensureNamedResourcesExist(queueNames, {
949
+ listResources: async () => cloudflareApi.listQueues(accountId),
950
+ createResource: async (resourceName) => cloudflareApi.createQueue(accountId, resourceName),
951
+ listFailureMessage: `Could not list Queues for Cloudflare account ${accountId} while preparing deploy resources.`,
952
+ missingFailureMessage: (missingNames) => {
953
+ return `Could not find Queue(s) ${missingNames.join(", ")} in Cloudflare account ${accountId}.`;
954
+ },
955
+ createFailureMessage: (resourceName) => {
956
+ return `Could not create Queue "${resourceName}" in Cloudflare account ${accountId} during deploy preparation.`;
957
+ }
958
+ });
959
+ created.queues.push(...queueState.created);
960
+ existing.queues.push(...queueState.existing);
961
+ return {
962
+ config: brandAsDeployConfig(withResolvedIdBindings(resolvedConfig, {
963
+ kv: kvBindings ? pendingKVNameBindings.length > 0 ? materializeResolvedNameBindings(kvBindings, normalizeKVNameBinding, namespaceIdsByName.idsByName) : materializeIdBindings(kvBindings, getLocalKVNamespaceIdentifier) : void 0,
964
+ d1: d1Bindings ? pendingD1NameBindings.length > 0 ? materializeResolvedNameBindings(d1Bindings, normalizeD1NameBinding, databaseIdsByName.idsByName) : materializeIdBindings(d1Bindings, getLocalD1DatabaseIdentifier) : void 0,
965
+ hyperdrive: hyperdriveBindings ? pendingHyperdriveNameBindings.length > 0 ? materializeHyperdriveIdBindings(hyperdriveBindings, hyperdriveIdsByName.idsByName) : materializeHyperdriveIdBindings(hyperdriveBindings) : void 0
966
+ })),
967
+ created,
968
+ existing,
969
+ warnings
970
+ };
971
+ } catch (err) {
972
+ throw decorateOrphanError(err, created);
973
+ }
974
+ }
975
+ async function prepareConfigResourcesForDeploy(config, options = {}) {
976
+ return prepareMaterializedConfigResourcesForDeploy(await resolveResources(config, {
977
+ phase: "build",
978
+ environment: options.environment,
979
+ preview: {
980
+ environment: options.environment,
981
+ env: options.env,
982
+ identifier: options.identifier
983
+ }
984
+ }), {
985
+ accountId: options.accountId,
986
+ cloudflare: options.cloudflare,
987
+ describeOnly: options.describeOnly
988
+ });
989
+ }
990
+ //#endregion
991
+ //#region src/config/resolve-phased.ts
992
+ /**
993
+ * Cast helper used at the resolve-phase boundaries. The brand is a phantom
994
+ * intersection so this is a zero-cost reinterpretation.
995
+ */
996
+ function brandAsLocalConfig(config) {
997
+ return config;
998
+ }
999
+ /**
1000
+ * Cast helper used at the resolve-phase boundaries. The brand is a phantom
1001
+ * intersection so this is a zero-cost reinterpretation.
1002
+ */
1003
+ function brandAsDeployConfig(config) {
1004
+ return config;
1005
+ }
1006
+ /**
1007
+ * Unified phase-discriminated resource resolver. Facade over the legacy
1008
+ * per-phase helpers; stamps the appropriate phase brand on the returned
1009
+ * config so callers can narrow at the type layer.
1010
+ */
1011
+ async function resolveResources(config, options) {
1012
+ const previewMerged = materializePreviewScopedConfig(mergeConfigForEnvironment(config, options.environment), {
1013
+ environment: options.environment,
1014
+ ...options.preview
1015
+ });
1016
+ switch (options.phase) {
1017
+ case "build": return previewMerged;
1018
+ case "local": return resolveConfigForLocalRuntime(previewMerged, void 0);
1019
+ case "deploy":
1020
+ if (options.provision) return (await prepareMaterializedConfigResourcesForDeploy(previewMerged, options.preparation ?? {
1021
+ accountId: options.accountId,
1022
+ cloudflare: options.cloudflare
1023
+ })).config;
1024
+ return await resolveMaterializedConfigResources(previewMerged, {
1025
+ accountId: options.accountId,
1026
+ cloudflare: options.cloudflare
1027
+ });
1028
+ }
1029
+ }
1030
+ //#endregion
1031
+ //#region src/config/resource-resolution.ts
1032
+ const defaultCloudflareApi = {
1033
+ getPrimaryAccount,
1034
+ getEffectiveAccountId,
1035
+ listKVNamespaces,
1036
+ listD1Databases,
1037
+ listHyperdrives
1038
+ };
1039
+ var ConfigResourceResolutionError = class extends Error {
1040
+ code = "CONFIG_RESOURCE_RESOLUTION_ERROR";
1041
+ constructor(message, cause) {
1042
+ super(message);
1043
+ this.name = "ConfigResourceResolutionError";
1044
+ if (cause !== void 0) this.cause = cause;
1045
+ }
1046
+ };
1047
+ function resolveCloudflareApi(overrides) {
1048
+ return {
1049
+ ...defaultCloudflareApi,
1050
+ ...overrides ?? {}
1051
+ };
1052
+ }
1053
+ async function resolveLookupAccountId(config, options, cloudflareApi) {
1054
+ const explicitAccountId = options.accountId ?? config.accountId;
1055
+ if (explicitAccountId) return explicitAccountId;
1056
+ let primaryAccount;
1057
+ try {
1058
+ primaryAccount = await cloudflareApi.getPrimaryAccount();
1059
+ } catch (error) {
1060
+ throw new ConfigResourceResolutionError("Could not resolve Cloudflare-backed resource names because Devflare could not read your Cloudflare accounts. Set accountId in devflare.config.ts, configure a workspace/global default account, or log in with Wrangler.", error);
1061
+ }
1062
+ if (!primaryAccount) throw new ConfigResourceResolutionError("Could not resolve Cloudflare-backed resource names because no Cloudflare account is available. Set accountId in devflare.config.ts, configure a workspace/global default account, or log in with Wrangler.");
1063
+ try {
1064
+ const { accountId } = await cloudflareApi.getEffectiveAccountId(primaryAccount.id);
1065
+ return accountId;
1066
+ } catch (error) {
1067
+ throw new ConfigResourceResolutionError(`Could not determine the effective Cloudflare account for name-based resource resolution after selecting primary account ${primaryAccount.id}.`, error);
1068
+ }
1069
+ }
1070
+ async function resolveResourceIdsByName(pendingBindings, options) {
1071
+ if (pendingBindings.length === 0) return /* @__PURE__ */ new Map();
1072
+ let resources;
1073
+ try {
1074
+ resources = await options.listResources();
1075
+ } catch (error) {
1076
+ throw new ConfigResourceResolutionError(options.listFailureMessage, error);
1077
+ }
1078
+ const idsByName = new Map(resources.map((resource) => [resource.name, resource.id]));
1079
+ const missingBindings = pendingBindings.filter(({ resourceName }) => {
1080
+ return !idsByName.has(resourceName);
1081
+ });
1082
+ if (missingBindings.length > 0) throw new ConfigResourceResolutionError(options.missingFailureMessage(missingBindings));
1083
+ return idsByName;
1084
+ }
1085
+ /**
1086
+ * Resolve environment overrides and normalize KV/D1/Hyperdrive bindings for purely local runtimes.
1087
+ *
1088
+ * Local Miniflare/workerd flows can use either an explicit resource ID or the
1089
+ * stable resource name as the backing identifier, so this path avoids requiring
1090
+ * Cloudflare auth for local development and tests.
1091
+ *
1092
+ * @internal Prefer the unified `resolveResources(config, { phase: 'local' })`
1093
+ * facade. This lower-level helper remains exported for backwards compatibility
1094
+ * and as the implementation that the seam delegates to; it is not part of the
1095
+ * recommended public surface and may be removed in a future major release.
1096
+ */
1097
+ function resolveConfigForLocalRuntime(config, environment) {
1098
+ const resolvedConfig = resolveConfigForEnvironment(config, environment);
1099
+ const kvBindings = resolvedConfig.bindings?.kv;
1100
+ const d1Bindings = resolvedConfig.bindings?.d1;
1101
+ const hyperdriveBindings = resolvedConfig.bindings?.hyperdrive;
1102
+ if (!kvBindings && !d1Bindings && !hyperdriveBindings) return brandAsLocalConfig(resolvedConfig);
1103
+ collectPendingNameBindings(kvBindings, normalizeKVNameBinding);
1104
+ return brandAsLocalConfig(withResolvedIdBindings(resolvedConfig, {
1105
+ kv: kvBindings ? materializeIdBindings(kvBindings, getLocalKVNamespaceIdentifier) : void 0,
1106
+ d1: d1Bindings ? materializeIdBindings(d1Bindings, getLocalD1DatabaseIdentifier) : void 0,
1107
+ hyperdrive: materializeHyperdriveIdBindings(hyperdriveBindings)
1108
+ }));
1109
+ }
1110
+ /**
1111
+ * Resolve Cloudflare-backed resource references such as KV/D1/Hyperdrive
1112
+ * name bindings into concrete IDs.
1113
+ *
1114
+ * Used by the deploy path and by automation/programmatic consumers that need
1115
+ * fully-resolved bindings against a live Cloudflare account. The build path
1116
+ * intentionally does NOT call this — `compileBuildConfig({ preserveNamedBindings: true })`
1117
+ * keeps name-only bindings symbolic in the build artifact so builds remain
1118
+ * reproducible offline. Pick this helper only when ID resolution is desired.
1119
+ *
1120
+ * @internal Prefer the unified `resolveResources(config, { phase: 'deploy' })`
1121
+ * facade. This lower-level helper remains exported as the implementation the
1122
+ * seam delegates to; it is not part of the recommended public surface.
1123
+ */
1124
+ async function resolveMaterializedConfigResources(resolvedConfig, options = {}) {
1125
+ const kvBindings = resolvedConfig.bindings?.kv;
1126
+ const d1Bindings = resolvedConfig.bindings?.d1;
1127
+ const hyperdriveBindings = resolvedConfig.bindings?.hyperdrive;
1128
+ if (!kvBindings && !d1Bindings && !hyperdriveBindings) return brandAsDeployConfig(resolvedConfig);
1129
+ const pendingKVNameBindings = collectPendingNameBindings(kvBindings, normalizeKVNameBinding);
1130
+ const pendingD1NameBindings = collectPendingNameBindings(d1Bindings, normalizeD1NameBinding);
1131
+ const pendingHyperdriveNameBindings = collectPendingNameBindings(hyperdriveBindings, normalizeHyperdriveNameBinding);
1132
+ if (pendingKVNameBindings.length === 0 && pendingD1NameBindings.length === 0 && pendingHyperdriveNameBindings.length === 0) return brandAsDeployConfig(withResolvedIdBindings(resolvedConfig, {
1133
+ kv: kvBindings ? materializeIdBindings(kvBindings, getLocalKVNamespaceIdentifier) : void 0,
1134
+ d1: d1Bindings ? materializeIdBindings(d1Bindings, getLocalD1DatabaseIdentifier) : void 0,
1135
+ hyperdrive: materializeHyperdriveIdBindings(hyperdriveBindings)
1136
+ }));
1137
+ const cloudflareApi = resolveCloudflareApi(options.cloudflare);
1138
+ const accountId = await resolveLookupAccountId(resolvedConfig, options, cloudflareApi);
1139
+ const namespaceIdsByName = await resolveResourceIdsByName(pendingKVNameBindings, {
1140
+ listResources: async () => cloudflareApi.listKVNamespaces(accountId),
1141
+ listFailureMessage: `Could not list KV namespaces for Cloudflare account ${accountId} while resolving name-based KV bindings.`,
1142
+ missingFailureMessage: (missingBindings) => {
1143
+ return `Could not find KV namespace(s) for ${formatMissingBindings(missingBindings)} in Cloudflare account ${accountId}.`;
1144
+ }
1145
+ });
1146
+ const databaseIdsByName = await resolveResourceIdsByName(pendingD1NameBindings, {
1147
+ listResources: async () => cloudflareApi.listD1Databases(accountId),
1148
+ listFailureMessage: `Could not list D1 databases for Cloudflare account ${accountId} while resolving name-based D1 bindings.`,
1149
+ missingFailureMessage: (missingBindings) => {
1150
+ return `Could not find D1 database(s) for ${formatMissingBindings(missingBindings)} in Cloudflare account ${accountId}.`;
1151
+ }
1152
+ });
1153
+ const hyperdriveIdsByName = await resolveResourceIdsByName(pendingHyperdriveNameBindings, {
1154
+ listResources: async () => cloudflareApi.listHyperdrives(accountId),
1155
+ listFailureMessage: `Could not list Hyperdrive configurations for Cloudflare account ${accountId} while resolving name-based Hyperdrive bindings.`,
1156
+ missingFailureMessage: (missingBindings) => {
1157
+ return `Could not find Hyperdrive configuration(s) for ${formatMissingBindings(missingBindings)} in Cloudflare account ${accountId}.`;
1158
+ }
1159
+ });
1160
+ return brandAsDeployConfig(withResolvedIdBindings(resolvedConfig, {
1161
+ kv: materializeResolvedNameBindings(kvBindings, normalizeKVNameBinding, namespaceIdsByName),
1162
+ d1: materializeResolvedNameBindings(d1Bindings, normalizeD1NameBinding, databaseIdsByName),
1163
+ hyperdrive: materializeHyperdriveIdBindings(hyperdriveBindings, hyperdriveIdsByName)
1164
+ }));
1165
+ }
1166
+ /**
1167
+ * Resolve Cloudflare-backed resource references such as KV/D1/Hyperdrive name bindings into
1168
+ * concrete IDs for build, deploy, and automation workflows.
1169
+ *
1170
+ * @internal Prefer the unified `resolveResources(config, { phase: 'deploy' })`
1171
+ * facade. This wrapper is now a thin shim over the seam, retained for
1172
+ * backwards compatibility with existing callers (`loadResolvedConfig`, etc.).
1173
+ */
1174
+ async function resolveConfigResources(config, options = {}) {
1175
+ return resolveResources(config, {
1176
+ phase: "deploy",
1177
+ environment: options.environment,
1178
+ preview: {
1179
+ environment: options.environment,
1180
+ env: options.env,
1181
+ identifier: options.identifier
1182
+ },
1183
+ accountId: options.accountId,
1184
+ cloudflare: options.cloudflare
1185
+ });
1186
+ }
1187
+ /**
1188
+ * Load devflare.config.* and resolve any Cloudflare-backed resource references.
1189
+ *
1190
+ * This is the public Node-side API for external automation that needs the same
1191
+ * resolved values Devflare build/deploy flows use.
1192
+ */
1193
+ async function loadResolvedConfig(options = {}) {
1194
+ return resolveConfigResources(await loadConfig(options), options);
1195
+ }
1196
+ //#endregion
1197
+ //#region src/config/loader.ts
1198
+ /**
1199
+ * Config file names to search for, in order of priority
1200
+ */
1201
+ const CONFIG_FILES = [
1202
+ "devflare.config.ts",
1203
+ "devflare.config.mts",
1204
+ "devflare.config.js",
1205
+ "devflare.config.mjs"
1206
+ ];
1207
+ function resolveC12Module(cwd) {
1208
+ const requireFromCwd = createRequire(join(cwd, "__devflare__.cjs"));
1209
+ try {
1210
+ return requireFromCwd("c12");
1211
+ } catch {
1212
+ return createRequire(import.meta.url)("c12");
1213
+ }
1214
+ }
1215
+ async function resolveConfigDotenvDirectory(cwd, configFile) {
1216
+ const explicitConfigPath = resolve(cwd, configFile);
1217
+ if (existsSync(explicitConfigPath)) return dirname(explicitConfigPath);
1218
+ const discoveredConfigPath = await resolveConfigPath(cwd);
1219
+ return discoveredConfigPath ? dirname(discoveredConfigPath) : cwd;
1220
+ }
1221
+ /**
1222
+ * Resolve the config file path in a directory
1223
+ *
1224
+ * @param cwd - Directory to search in
1225
+ * @returns Path to config file or undefined
1226
+ */
1227
+ async function resolveConfigPath(cwd) {
1228
+ for (const file of CONFIG_FILES) {
1229
+ const path = join(cwd, file);
1230
+ if (existsSync(path)) return path;
1231
+ }
1232
+ }
1233
+ /**
1234
+ * Load and validate devflare configuration
1235
+ *
1236
+ * @param options - Loading options
1237
+ * @returns Validated DevflareConfig
1238
+ * @throws When config file not found or validation fails
1239
+ */
1240
+ async function loadConfig(options = {}) {
1241
+ const cwd = resolve(options.cwd ?? process.cwd());
1242
+ const configFile = options.configFile ?? "devflare.config";
1243
+ const { loadConfig: c12LoadConfig } = resolveC12Module(cwd);
1244
+ await loadDevflareDotenvIntoProcess(await resolveConfigDotenvDirectory(cwd, configFile));
1245
+ const { config, configFile: loadedFile } = await c12LoadConfig({
1246
+ name: "devflare",
1247
+ cwd,
1248
+ configFile,
1249
+ defaultConfig: void 0,
1250
+ rcFile: false,
1251
+ globalRc: false,
1252
+ dotenv: false
1253
+ });
1254
+ if (!config || !loadedFile) throw new ConfigNotFoundError(cwd, configFile);
1255
+ const result = configSchema.safeParse(config);
1256
+ if (!result.success) throw new ConfigValidationError(result.error.issues, loadedFile);
1257
+ return applyFrameworkConfigProviders(result.data, {
1258
+ cwd,
1259
+ configPath: loadedFile
1260
+ });
1261
+ }
1262
+ /**
1263
+ * Error thrown when config file is not found
1264
+ */
1265
+ var ConfigNotFoundError = class extends Error {
1266
+ code = "CONFIG_NOT_FOUND";
1267
+ constructor(cwd, configFile) {
1268
+ super(`Config file not found in ${cwd}.\nExpected one of: ${CONFIG_FILES.join(", ")}\nRun 'devflare init' to create a new config.`);
1269
+ this.cwd = cwd;
1270
+ this.configFile = configFile;
1271
+ this.name = "ConfigNotFoundError";
1272
+ }
1273
+ };
1274
+ /**
1275
+ * Error thrown when config validation fails
1276
+ */
1277
+ var ConfigValidationError = class extends Error {
1278
+ code = "CONFIG_VALIDATION_ERROR";
1279
+ constructor(issues, configFile) {
1280
+ const issueMessages = issues.map((i) => ` - ${i.path.join(".")}: ${i.message}`).join("\n");
1281
+ super(`Invalid config in ${configFile}:\n${issueMessages}`);
1282
+ this.issues = issues;
1283
+ this.configFile = configFile;
1284
+ this.name = "ConfigValidationError";
1285
+ }
1286
+ };
1287
+ //#endregion
1288
+ export { ConfigResourceResolutionError as a, prepareConfigResourcesForDeploy as c, configSchema as d, assertValidCronExpression as f, resolveConfigPath as i, mergeConfigForEnvironment as l, ConfigValidationError as n, loadResolvedConfig as o, normalizeCompatibilityFlags as p, loadConfig as r, resolveResources as s, ConfigNotFoundError as t, resolveConfigForEnvironment as u };