devflare 1.0.0-next.14 → 1.0.0-next.16

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 (380) hide show
  1. package/LLM.md +9360 -1784
  2. package/README.md +391 -32
  3. package/bin/devflare.js +17 -7
  4. package/dist/account-0w8wdzjv.js +475 -0
  5. package/dist/account-eygq6qx7.js +475 -0
  6. package/dist/account-fw8nafav.js +475 -0
  7. package/dist/account-pzq69nys.js +475 -0
  8. package/dist/account-s66jb15j.js +475 -0
  9. package/dist/api-d6ekexs5.js +25 -0
  10. package/dist/bridge/index.d.ts +1 -1
  11. package/dist/bridge/index.d.ts.map +1 -1
  12. package/dist/bridge/miniflare.d.ts.map +1 -1
  13. package/dist/bridge/protocol.d.ts +1 -1
  14. package/dist/bridge/protocol.d.ts.map +1 -1
  15. package/dist/bridge/proxy.d.ts +0 -4
  16. package/dist/bridge/proxy.d.ts.map +1 -1
  17. package/dist/bridge/serialization.d.ts.map +1 -1
  18. package/dist/bridge/server.d.ts +1 -1
  19. package/dist/bridge/server.d.ts.map +1 -1
  20. package/dist/browser-shim/handler.d.ts +1 -1
  21. package/dist/browser-shim/handler.d.ts.map +1 -1
  22. package/dist/browser.d.ts +1651 -34
  23. package/dist/browser.d.ts.map +1 -1
  24. package/dist/build-1kmkwqgh.js +53 -0
  25. package/dist/build-506kjhcm.js +53 -0
  26. package/dist/build-66866ahs.js +53 -0
  27. package/dist/build-g1adm3ww.js +53 -0
  28. package/dist/build-p3r3117t.js +53 -0
  29. package/dist/bundler/do-bundler.d.ts.map +1 -1
  30. package/dist/bundler/rolldown-shared.d.ts +24 -0
  31. package/dist/bundler/rolldown-shared.d.ts.map +1 -0
  32. package/dist/bundler/worker-bundler.d.ts +0 -1
  33. package/dist/bundler/worker-bundler.d.ts.map +1 -1
  34. package/dist/cli/command-utils.d.ts +18 -0
  35. package/dist/cli/command-utils.d.ts.map +1 -0
  36. package/dist/cli/commands/account.d.ts +1 -1
  37. package/dist/cli/commands/account.d.ts.map +1 -1
  38. package/dist/cli/commands/build-artifacts.d.ts +27 -0
  39. package/dist/cli/commands/build-artifacts.d.ts.map +1 -0
  40. package/dist/cli/commands/build.d.ts.map +1 -1
  41. package/dist/cli/commands/config.d.ts +4 -0
  42. package/dist/cli/commands/config.d.ts.map +1 -0
  43. package/dist/cli/commands/deploy.d.ts.map +1 -1
  44. package/dist/cli/commands/dev.d.ts.map +1 -1
  45. package/dist/cli/commands/doctor.d.ts.map +1 -1
  46. package/dist/cli/commands/init.d.ts.map +1 -1
  47. package/dist/cli/commands/login.d.ts +4 -0
  48. package/dist/cli/commands/login.d.ts.map +1 -0
  49. package/dist/cli/commands/previews-support/cleanup.d.ts +9 -0
  50. package/dist/cli/commands/previews-support/cleanup.d.ts.map +1 -0
  51. package/dist/cli/commands/previews-support/family.d.ts +10 -0
  52. package/dist/cli/commands/previews-support/family.d.ts.map +1 -0
  53. package/dist/cli/commands/previews-support/render.d.ts +8 -0
  54. package/dist/cli/commands/previews-support/render.d.ts.map +1 -0
  55. package/dist/cli/commands/previews-support/theme.d.ts +10 -0
  56. package/dist/cli/commands/previews-support/theme.d.ts.map +1 -0
  57. package/dist/cli/commands/previews-support/types.d.ts +70 -0
  58. package/dist/cli/commands/previews-support/types.d.ts.map +1 -0
  59. package/dist/cli/commands/previews.d.ts +4 -0
  60. package/dist/cli/commands/previews.d.ts.map +1 -0
  61. package/dist/cli/commands/productions.d.ts +4 -0
  62. package/dist/cli/commands/productions.d.ts.map +1 -0
  63. package/dist/cli/commands/token.d.ts +4 -0
  64. package/dist/cli/commands/token.d.ts.map +1 -0
  65. package/dist/cli/commands/type-generation/discovery.d.ts +7 -0
  66. package/dist/cli/commands/type-generation/discovery.d.ts.map +1 -0
  67. package/dist/cli/commands/type-generation/generator.d.ts +44 -0
  68. package/dist/cli/commands/type-generation/generator.d.ts.map +1 -0
  69. package/dist/cli/commands/type-generation/models.d.ts +27 -0
  70. package/dist/cli/commands/type-generation/models.d.ts.map +1 -0
  71. package/dist/cli/commands/types.d.ts.map +1 -1
  72. package/dist/cli/commands/worker.d.ts +4 -0
  73. package/dist/cli/commands/worker.d.ts.map +1 -0
  74. package/dist/cli/config-path.d.ts +2 -1
  75. package/dist/cli/config-path.d.ts.map +1 -1
  76. package/dist/cli/deploy-strategy.d.ts +17 -0
  77. package/dist/cli/deploy-strategy.d.ts.map +1 -0
  78. package/dist/cli/deploy-target.d.ts +17 -0
  79. package/dist/cli/deploy-target.d.ts.map +1 -0
  80. package/dist/cli/generated-artifacts.d.ts +12 -0
  81. package/dist/cli/generated-artifacts.d.ts.map +1 -0
  82. package/dist/cli/help-pages/pages/account.d.ts +3 -0
  83. package/dist/cli/help-pages/pages/account.d.ts.map +1 -0
  84. package/dist/cli/help-pages/pages/core.d.ts +4 -0
  85. package/dist/cli/help-pages/pages/core.d.ts.map +1 -0
  86. package/dist/cli/help-pages/pages/index.d.ts +3 -0
  87. package/dist/cli/help-pages/pages/index.d.ts.map +1 -0
  88. package/dist/cli/help-pages/pages/misc.d.ts +3 -0
  89. package/dist/cli/help-pages/pages/misc.d.ts.map +1 -0
  90. package/dist/cli/help-pages/pages/previews.d.ts +3 -0
  91. package/dist/cli/help-pages/pages/previews.d.ts.map +1 -0
  92. package/dist/cli/help-pages/pages/productions.d.ts +3 -0
  93. package/dist/cli/help-pages/pages/productions.d.ts.map +1 -0
  94. package/dist/cli/help-pages/render.d.ts +12 -0
  95. package/dist/cli/help-pages/render.d.ts.map +1 -0
  96. package/dist/cli/help-pages/shared.d.ts +15 -0
  97. package/dist/cli/help-pages/shared.d.ts.map +1 -0
  98. package/dist/cli/help-pages/types.d.ts +23 -0
  99. package/dist/cli/help-pages/types.d.ts.map +1 -0
  100. package/dist/cli/help.d.ts +6 -0
  101. package/dist/cli/help.d.ts.map +1 -0
  102. package/dist/cli/index.d.ts +1 -0
  103. package/dist/cli/index.d.ts.map +1 -1
  104. package/dist/cli/preview-bindings.d.ts +42 -0
  105. package/dist/cli/preview-bindings.d.ts.map +1 -0
  106. package/dist/cli/preview.d.ts +11 -0
  107. package/dist/cli/preview.d.ts.map +1 -0
  108. package/dist/cli/ui.d.ts +37 -0
  109. package/dist/cli/ui.d.ts.map +1 -0
  110. package/dist/cli/workspace-build-guard.d.ts +14 -0
  111. package/dist/cli/workspace-build-guard.d.ts.map +1 -0
  112. package/dist/cloudflare/account-core.d.ts +6 -0
  113. package/dist/cloudflare/account-core.d.ts.map +1 -0
  114. package/dist/cloudflare/account-resources.d.ts +40 -0
  115. package/dist/cloudflare/account-resources.d.ts.map +1 -0
  116. package/dist/cloudflare/account-status.d.ts +11 -0
  117. package/dist/cloudflare/account-status.d.ts.map +1 -0
  118. package/dist/cloudflare/account-workers.d.ts +14 -0
  119. package/dist/cloudflare/account-workers.d.ts.map +1 -0
  120. package/dist/cloudflare/account.d.ts +7 -64
  121. package/dist/cloudflare/account.d.ts.map +1 -1
  122. package/dist/cloudflare/api.d.ts +4 -0
  123. package/dist/cloudflare/api.d.ts.map +1 -1
  124. package/dist/cloudflare/index.d.ts +57 -2
  125. package/dist/cloudflare/index.d.ts.map +1 -1
  126. package/dist/cloudflare/kv-namespace.d.ts +3 -0
  127. package/dist/cloudflare/kv-namespace.d.ts.map +1 -0
  128. package/dist/cloudflare/preferences.d.ts.map +1 -1
  129. package/dist/cloudflare/preview-registry-cache.d.ts +6 -0
  130. package/dist/cloudflare/preview-registry-cache.d.ts.map +1 -0
  131. package/dist/cloudflare/preview-registry-records.d.ts +61 -0
  132. package/dist/cloudflare/preview-registry-records.d.ts.map +1 -0
  133. package/dist/cloudflare/preview-registry-store.d.ts +14 -0
  134. package/dist/cloudflare/preview-registry-store.d.ts.map +1 -0
  135. package/dist/cloudflare/preview-registry-types.d.ts +103 -0
  136. package/dist/cloudflare/preview-registry-types.d.ts.map +1 -0
  137. package/dist/cloudflare/preview-registry.d.ts +42 -0
  138. package/dist/cloudflare/preview-registry.d.ts.map +1 -0
  139. package/dist/cloudflare/registry-schema.d.ts +253 -0
  140. package/dist/cloudflare/registry-schema.d.ts.map +1 -0
  141. package/dist/cloudflare/tokens.d.ts +18 -0
  142. package/dist/cloudflare/tokens.d.ts.map +1 -0
  143. package/dist/cloudflare/types.d.ts +122 -5
  144. package/dist/cloudflare/types.d.ts.map +1 -1
  145. package/dist/cloudflare/usage.d.ts.map +1 -1
  146. package/dist/config/compiler.d.ts +4 -0
  147. package/dist/config/compiler.d.ts.map +1 -1
  148. package/dist/config/framework-providers.d.ts +9 -0
  149. package/dist/config/framework-providers.d.ts.map +1 -0
  150. package/dist/config/index.d.ts +5 -3
  151. package/dist/config/index.d.ts.map +1 -1
  152. package/dist/config/loader.d.ts +1 -0
  153. package/dist/config/loader.d.ts.map +1 -1
  154. package/dist/config/preview-resources.d.ts +77 -0
  155. package/dist/config/preview-resources.d.ts.map +1 -0
  156. package/dist/config/preview.d.ts +31 -0
  157. package/dist/config/preview.d.ts.map +1 -0
  158. package/dist/config/ref.d.ts +0 -22
  159. package/dist/config/ref.d.ts.map +1 -1
  160. package/dist/config/resolve.d.ts +1 -0
  161. package/dist/config/resolve.d.ts.map +1 -1
  162. package/dist/config/resource-resolution.d.ts +60 -0
  163. package/dist/config/resource-resolution.d.ts.map +1 -0
  164. package/dist/config/schema-bindings.d.ts +693 -0
  165. package/dist/config/schema-bindings.d.ts.map +1 -0
  166. package/dist/config/schema-build.d.ts +67 -0
  167. package/dist/config/schema-build.d.ts.map +1 -0
  168. package/dist/config/schema-env.d.ts +1341 -0
  169. package/dist/config/schema-env.d.ts.map +1 -0
  170. package/dist/config/schema-normalization.d.ts +64 -0
  171. package/dist/config/schema-normalization.d.ts.map +1 -0
  172. package/dist/config/schema-runtime.d.ts +230 -0
  173. package/dist/config/schema-runtime.d.ts.map +1 -0
  174. package/dist/config/schema.d.ts +640 -3669
  175. package/dist/config/schema.d.ts.map +1 -1
  176. package/dist/config-entry.d.ts +5 -0
  177. package/dist/config-entry.d.ts.map +1 -0
  178. package/dist/config-fjwke42y.js +59 -0
  179. package/dist/config-hwdqjse7.js +59 -0
  180. package/dist/config-pxvewrhv.js +59 -0
  181. package/dist/config-q0g5qdga.js +59 -0
  182. package/dist/decorators/durable-object.d.ts.map +1 -1
  183. package/dist/deploy-7nmzc9r8.js +609 -0
  184. package/dist/deploy-csfhdr64.js +691 -0
  185. package/dist/deploy-ex4g5avz.js +621 -0
  186. package/dist/deploy-jnb0bhka.js +609 -0
  187. package/dist/deploy-tp0g6qdp.js +609 -0
  188. package/dist/deploy-ykpcjkc2.js +690 -0
  189. package/dist/{dev-c1xc1gq9.js → dev-2pd33m28.js} +392 -348
  190. package/dist/dev-7ef5e2j1.js +2409 -0
  191. package/dist/dev-8nssqatr.js +2409 -0
  192. package/dist/dev-grznx8fn.js +2409 -0
  193. package/dist/dev-server/d1-migrations.d.ts +14 -0
  194. package/dist/dev-server/d1-migrations.d.ts.map +1 -0
  195. package/dist/dev-server/gateway-script.d.ts +8 -0
  196. package/dist/dev-server/gateway-script.d.ts.map +1 -0
  197. package/dist/dev-server/runtime-stdio.d.ts.map +1 -1
  198. package/dist/dev-server/server.d.ts.map +1 -1
  199. package/dist/dev-server/vite-process.d.ts +14 -0
  200. package/dist/dev-server/vite-process.d.ts.map +1 -0
  201. package/dist/dev-server/vite-utils.d.ts +1 -1
  202. package/dist/dev-server/vite-utils.d.ts.map +1 -1
  203. package/dist/dev-server/worker-source-watcher.d.ts +11 -0
  204. package/dist/dev-server/worker-source-watcher.d.ts.map +1 -0
  205. package/dist/dev-server/worker-surface-paths.d.ts +6 -0
  206. package/dist/dev-server/worker-surface-paths.d.ts.map +1 -0
  207. package/dist/{doctor-z4ffybce.js → doctor-04ammrrh.js} +67 -31
  208. package/dist/doctor-fmjj65mc.js +245 -0
  209. package/dist/doctor-fzkznce1.js +245 -0
  210. package/dist/doctor-sa5xv1bz.js +245 -0
  211. package/dist/index-091sh1ma.js +1229 -0
  212. package/dist/index-0apbm26n.js +788 -0
  213. package/dist/index-0eqksag4.js +418 -0
  214. package/dist/{index-dr6sbp8d.js → index-0kfzdywd.js} +15 -2
  215. package/dist/index-0w826dsr.js +379 -0
  216. package/dist/{index-rfhx0yd5.js → index-11m5a8wd.js} +110 -32
  217. package/dist/{index-xxwbb2nt.js → index-1sp39f2f.js} +114 -58
  218. package/dist/index-2jnrqbny.js +1301 -0
  219. package/dist/index-2pb7b9mw.js +378 -0
  220. package/dist/{index-0kzg8wed.js → index-2x53aqjm.js} +1071 -890
  221. package/dist/index-3ke5d2vn.js +1229 -0
  222. package/dist/index-43dq8yx8.js +788 -0
  223. package/dist/index-4rrttqj5.js +378 -0
  224. package/dist/index-4v9bc2pc.js +1367 -0
  225. package/dist/index-61jsjnsv.js +280 -0
  226. package/dist/index-6jef5emv.js +176 -0
  227. package/dist/index-6psz1h4c.js +788 -0
  228. package/dist/index-72mve6vh.js +168 -0
  229. package/dist/{index-zbvmtcn2.js → index-74198nxd.js} +179 -77
  230. package/dist/index-7g8zyws4.js +192 -0
  231. package/dist/index-7kcxjhta.js +456 -0
  232. package/dist/index-7v583xan.js +418 -0
  233. package/dist/index-7x0ybbtx.js +133 -0
  234. package/dist/index-816krz9p.js +52 -0
  235. package/dist/index-82f1z98k.js +41 -0
  236. package/dist/index-8t5nb4qx.js +133 -0
  237. package/dist/index-9az6s7ad.js +52 -0
  238. package/dist/{index-59df49vn.js → index-9ba1etyz.js} +29 -51
  239. package/dist/{index-001mw014.js → index-9fbtk7gv.js} +134 -248
  240. package/dist/index-9n6djthj.js +490 -0
  241. package/dist/index-aabgympv.js +39 -0
  242. package/dist/index-b8m6883k.js +74 -0
  243. package/dist/{index-5yxg30va.js → index-cgbvmse6.js} +15 -6
  244. package/dist/index-d8etnfef.js +1229 -0
  245. package/dist/index-e9yw4d6y.js +133 -0
  246. package/dist/index-epw1jxz5.js +1204 -0
  247. package/dist/index-f85s8gj3.js +2649 -0
  248. package/dist/index-fe2ngvh7.js +1229 -0
  249. package/dist/index-fvsadj32.js +192 -0
  250. package/dist/index-gs4y9gdf.js +456 -0
  251. package/dist/{index-fef08w43.js → index-h18pxvzs.js} +7 -6
  252. package/dist/index-hfj1a2c4.js +2649 -0
  253. package/dist/{index-8gtqgb3q.js → index-hjy8ctpc.js} +14 -92
  254. package/dist/index-htzf0py1.js +1204 -0
  255. package/dist/index-j185x270.js +897 -0
  256. package/dist/index-jb75kwa4.js +519 -0
  257. package/dist/index-jwd8pcb2.js +897 -0
  258. package/dist/index-k29yjhv0.js +52 -0
  259. package/dist/index-k6vq6kkt.js +456 -0
  260. package/dist/{index-vky23txa.js → index-m3fmw6mx.js} +2 -2
  261. package/dist/index-maxpsfk8.js +402 -0
  262. package/dist/index-mbdmrner.js +402 -0
  263. package/dist/index-mea5bc45.js +418 -0
  264. package/dist/index-mqekt778.js +185 -0
  265. package/dist/index-na3mnm1k.js +74 -0
  266. package/dist/index-p03n4qet.js +1367 -0
  267. package/dist/index-p296ban8.js +191 -0
  268. package/dist/index-pnbs1b8k.js +280 -0
  269. package/dist/index-q4kaz181.js +1207 -0
  270. package/dist/index-ry131z23.js +378 -0
  271. package/dist/index-sgb7c8nm.js +402 -0
  272. package/dist/index-sqrksgb2.js +133 -0
  273. package/dist/index-stgn34cr.js +148 -0
  274. package/dist/{index-v8vvsn9x.js → index-t08te69w.js} +1 -18
  275. package/dist/index-thna1tkd.js +280 -0
  276. package/dist/index-v5nmqthy.js +74 -0
  277. package/dist/{index-n932ytmq.js → index-vt4yxkmf.js} +2 -2
  278. package/dist/index-wyq6c6yj.js +402 -0
  279. package/dist/index-wztc9stx.js +418 -0
  280. package/dist/index-x9cwdxw5.js +456 -0
  281. package/dist/index-xk9djfjp.js +519 -0
  282. package/dist/index-yc0gcchc.js +418 -0
  283. package/dist/index-yqbxjysa.js +897 -0
  284. package/dist/index-yzddwp02.js +788 -0
  285. package/dist/index-zfhq6s96.js +74 -0
  286. package/dist/index-zt22fe2j.js +54 -0
  287. package/dist/index-zyt5byt6.js +2649 -0
  288. package/dist/index.d.ts +2 -2
  289. package/dist/index.d.ts.map +1 -1
  290. package/dist/{init-na2atvz2.js → init-r4hnxan3.js} +24 -17
  291. package/dist/login-2hnz4m4n.js +77 -0
  292. package/dist/login-5bsxxpvc.js +77 -0
  293. package/dist/login-6tzvczw2.js +77 -0
  294. package/dist/login-bhaw72zc.js +77 -0
  295. package/dist/login-x8tgckqm.js +77 -0
  296. package/dist/previews-3rn8mz2c.js +1168 -0
  297. package/dist/previews-d487qde5.js +1200 -0
  298. package/dist/previews-gm3z0syj.js +1168 -0
  299. package/dist/previews-j9ymq4ys.js +1169 -0
  300. package/dist/previews-q031mx34.js +1168 -0
  301. package/dist/productions-120xg0aq.js +505 -0
  302. package/dist/productions-5ev5qweg.js +505 -0
  303. package/dist/productions-me3tdvr9.js +505 -0
  304. package/dist/productions-p5rbgp2f.js +505 -0
  305. package/dist/productions-x9p0pym1.js +505 -0
  306. package/dist/runtime/context-events.d.ts +13 -0
  307. package/dist/runtime/context-events.d.ts.map +1 -0
  308. package/dist/runtime/context-types.d.ts +82 -0
  309. package/dist/runtime/context-types.d.ts.map +1 -0
  310. package/dist/runtime/context.d.ts +6 -267
  311. package/dist/runtime/context.d.ts.map +1 -1
  312. package/dist/runtime/exports.d.ts +3 -3
  313. package/dist/runtime/index.d.ts +1 -1
  314. package/dist/runtime/index.d.ts.map +1 -1
  315. package/dist/runtime/middleware.d.ts +8 -38
  316. package/dist/runtime/middleware.d.ts.map +1 -1
  317. package/dist/src/browser.js +23 -14
  318. package/dist/src/cli/index.js +3 -1
  319. package/dist/src/cloudflare/index.js +49 -2
  320. package/dist/src/config-entry.js +14 -0
  321. package/dist/src/index.js +33 -20
  322. package/dist/src/runtime/index.js +3 -9
  323. package/dist/src/sveltekit/index.js +10 -7
  324. package/dist/src/test/index.js +16 -18
  325. package/dist/src/vite/index.js +7 -4
  326. package/dist/sveltekit/platform.d.ts +1 -1
  327. package/dist/sveltekit/platform.d.ts.map +1 -1
  328. package/dist/test/cf.d.ts +10 -10
  329. package/dist/test/email.d.ts.map +1 -1
  330. package/dist/test/index.d.ts +1 -6
  331. package/dist/test/index.d.ts.map +1 -1
  332. package/dist/test/queue.d.ts.map +1 -1
  333. package/dist/test/remote-ai.d.ts.map +1 -1
  334. package/dist/test/remote-cloudflare.d.ts +13 -0
  335. package/dist/test/remote-cloudflare.d.ts.map +1 -0
  336. package/dist/test/remote-vectorize.d.ts.map +1 -1
  337. package/dist/test/resolve-service-bindings.d.ts.map +1 -1
  338. package/dist/test/scheduled.d.ts.map +1 -1
  339. package/dist/test/should-skip.d.ts +0 -18
  340. package/dist/test/should-skip.d.ts.map +1 -1
  341. package/dist/test/simple-context-durable-objects.d.ts +6 -0
  342. package/dist/test/simple-context-durable-objects.d.ts.map +1 -0
  343. package/dist/test/simple-context-gateway-script.d.ts +2 -0
  344. package/dist/test/simple-context-gateway-script.d.ts.map +1 -0
  345. package/dist/test/simple-context-paths.d.ts +40 -0
  346. package/dist/test/simple-context-paths.d.ts.map +1 -0
  347. package/dist/test/simple-context.d.ts +1 -23
  348. package/dist/test/simple-context.d.ts.map +1 -1
  349. package/dist/test/tail.d.ts.map +1 -1
  350. package/dist/test/worker.d.ts.map +1 -1
  351. package/dist/token-kedhcret.js +419 -0
  352. package/dist/token-m8jmnjwk.js +419 -0
  353. package/dist/{types-sffr9681.js → types-0sqwkp7x.js} +244 -139
  354. package/dist/types-1gwr2ex6.js +572 -0
  355. package/dist/types-6e5yx6km.js +572 -0
  356. package/dist/types-p0gckpn6.js +572 -0
  357. package/dist/utils/send-email.d.ts.map +1 -1
  358. package/dist/vite/config-file.d.ts.map +1 -1
  359. package/dist/vite/plugin.d.ts.map +1 -1
  360. package/dist/worker-0srh2jfr.js +513 -0
  361. package/dist/worker-4xrfd10a.js +513 -0
  362. package/dist/worker-entry/composed-worker.d.ts +0 -7
  363. package/dist/worker-entry/composed-worker.d.ts.map +1 -1
  364. package/dist/worker-entry/surface-paths.d.ts +15 -0
  365. package/dist/worker-entry/surface-paths.d.ts.map +1 -0
  366. package/dist/worker-qtam8grz.js +513 -0
  367. package/dist/worker-qzm0b7br.js +513 -0
  368. package/dist/worker-y9ha6g44.js +513 -0
  369. package/package.json +17 -10
  370. package/R2.md +0 -200
  371. package/dist/account-8psavtg6.js +0 -420
  372. package/dist/build-n639efmn.js +0 -101
  373. package/dist/deploy-zvnq6xh7.js +0 -117
  374. package/dist/index-2q3pmzrx.js +0 -90
  375. package/dist/index-f4q0jbnj.js +0 -195
  376. package/dist/index-n7rs26ft.js +0 -77
  377. package/dist/index-tfyxa77h.js +0 -850
  378. package/dist/index-wyf3s77s.js +0 -343
  379. package/dist/test/multi-worker-context.d.ts +0 -114
  380. package/dist/test/multi-worker-context.d.ts.map +0 -1
@@ -0,0 +1,1207 @@
1
+ import {
2
+ createD1Database,
3
+ getWorkerVersionDetail,
4
+ getWorkersSubdomain,
5
+ listD1Databases,
6
+ listWorkerDeployments,
7
+ listWorkerVersions,
8
+ queryD1Database
9
+ } from "./index-xk9djfjp.js";
10
+ import {
11
+ CloudflareAPIError
12
+ } from "./index-0w826dsr.js";
13
+
14
+ // src/cli/preview.ts
15
+ function normalizeWorkersSubdomain(accountSubdomain) {
16
+ return accountSubdomain.trim().replace(/^https?:\/\//i, "").replace(/\.workers\.dev\/?$/i, "");
17
+ }
18
+ function formatPreviewAliasUrl(alias, workerName, accountSubdomain) {
19
+ const normalizedSubdomain = normalizeWorkersSubdomain(accountSubdomain);
20
+ return `https://${alias}-${workerName}.${normalizedSubdomain}.workers.dev`;
21
+ }
22
+ function formatWorkersDevUrl(workerName, accountSubdomain) {
23
+ const normalizedSubdomain = normalizeWorkersSubdomain(accountSubdomain);
24
+ return `https://${workerName}.${normalizedSubdomain}.workers.dev`;
25
+ }
26
+ function formatVersionPreviewUrl(versionId, workerName, accountSubdomain) {
27
+ const normalizedSubdomain = normalizeWorkersSubdomain(accountSubdomain);
28
+ const versionPrefix = versionId.split("-")[0] || versionId;
29
+ return `https://${versionPrefix}-${workerName}.${normalizedSubdomain}.workers.dev`;
30
+ }
31
+ function matchNamedValue(output, patterns) {
32
+ for (const pattern of patterns) {
33
+ const match = output.match(pattern);
34
+ if (match?.[1]) {
35
+ return match[1];
36
+ }
37
+ }
38
+ return;
39
+ }
40
+ function appendUniqueUrls(target, value) {
41
+ if (typeof value === "string") {
42
+ if (value.startsWith("http://") || value.startsWith("https://")) {
43
+ target.push(value);
44
+ }
45
+ return;
46
+ }
47
+ if (!Array.isArray(value)) {
48
+ return;
49
+ }
50
+ for (const item of value) {
51
+ appendUniqueUrls(target, item);
52
+ }
53
+ }
54
+ function parseWranglerStructuredOutput(output) {
55
+ const records = output.replace(/\r/g, "").split(`
56
+ `).map((line) => line.trim()).filter(Boolean).map((line) => {
57
+ try {
58
+ return JSON.parse(line);
59
+ } catch {
60
+ return null;
61
+ }
62
+ }).filter((record) => record !== null);
63
+ const urls = [];
64
+ let versionId;
65
+ let previewUrl;
66
+ for (const record of records) {
67
+ if (!versionId && typeof record.version_id === "string" && record.version_id.trim()) {
68
+ versionId = record.version_id.trim();
69
+ }
70
+ appendUniqueUrls(urls, record.targets);
71
+ appendUniqueUrls(urls, record.preview_urls);
72
+ appendUniqueUrls(urls, record.urls);
73
+ appendUniqueUrls(urls, record.url);
74
+ if (!previewUrl && typeof record.preview_url === "string" && record.preview_url.trim()) {
75
+ previewUrl = record.preview_url.trim();
76
+ }
77
+ }
78
+ const uniqueUrls = [...new Set(urls)];
79
+ if (!previewUrl) {
80
+ previewUrl = uniqueUrls.find((url) => url.includes("workers.dev"));
81
+ }
82
+ return {
83
+ versionId,
84
+ previewUrl,
85
+ urls: uniqueUrls
86
+ };
87
+ }
88
+ function mergeParsedWranglerDeployOutputs(...outputs) {
89
+ const urls = [...new Set(outputs.flatMap((output) => output.urls))];
90
+ return {
91
+ versionId: outputs.map((output) => output.versionId).find((value) => Boolean(value)),
92
+ previewUrl: outputs.map((output) => output.previewUrl).find((value) => Boolean(value)) ?? urls.find((url) => url.includes("workers.dev")),
93
+ urls
94
+ };
95
+ }
96
+ function parseWranglerDeployOutput(output) {
97
+ const normalizedOutput = output.replace(/\r/g, "");
98
+ const urls = [...new Set(normalizedOutput.match(/https?:\/\/[^\s'"`]+/g) ?? [])];
99
+ const previewUrl = matchNamedValue(normalizedOutput, [
100
+ /Preview URL:\s*(https?:\/\/\S+)/i,
101
+ /Version Preview URL:\s*(https?:\/\/\S+)/i
102
+ ]) ?? urls.find((url) => url.includes("workers.dev"));
103
+ const versionId = matchNamedValue(normalizedOutput, [
104
+ /Worker Version ID:\s*([A-Za-z0-9_-]+)/i,
105
+ /Version ID:\s*([A-Za-z0-9_-]+)/i,
106
+ /version(?:_id| id)?\s*[:=]\s*([A-Za-z0-9_-]+)/i,
107
+ /"id"\s*:\s*"([A-Za-z0-9_-]+)"/i
108
+ ]);
109
+ return {
110
+ versionId,
111
+ previewUrl,
112
+ urls
113
+ };
114
+ }
115
+
116
+ // src/cloudflare/preview-registry-types.ts
117
+ var DEVFLARE_PREVIEW_REGISTRY_DATABASE = "devflare-registry";
118
+
119
+ // src/cloudflare/registry-schema.ts
120
+ import { z } from "zod/v4";
121
+ var recordIdSchema = z.string().min(1);
122
+ var cloudflareAccountIdSchema = z.string().min(1);
123
+ var cloudflareVersionIdSchema = z.string().uuid();
124
+ var workerNameSchema = z.string().min(1);
125
+ var timestampSchema = z.coerce.date();
126
+ var urlSchema = z.string().url();
127
+ var branchNameSchema = z.string().min(1);
128
+ var commitShaSchema = z.string().regex(/^[a-f0-9]{7,40}$/i, {
129
+ message: "Commit SHA must be 7 to 40 hexadecimal characters"
130
+ });
131
+ var previewAliasSchema = z.string().regex(/^[a-z][a-z0-9-]*$/, {
132
+ message: "Preview names must start with a lowercase letter and contain only lowercase letters, numbers, and dashes"
133
+ });
134
+ var cloudflareUserIdSchema = z.union([
135
+ z.string().min(1),
136
+ z.number().int().nonnegative().transform((value) => String(value))
137
+ ]);
138
+ var devflareAccountRecordSchema = z.object({
139
+ id: recordIdSchema,
140
+ ver: z.number().int().min(1),
141
+ createdAt: timestampSchema,
142
+ updatedAt: timestampSchema.optional(),
143
+ deletedAt: timestampSchema.optional(),
144
+ createdBy: cloudflareUserIdSchema
145
+ }).strict();
146
+ function createDevflareAccountRecordSchema(shape) {
147
+ return devflareAccountRecordSchema.extend(shape);
148
+ }
149
+ var devflareRecordSourceSchema = z.enum([
150
+ "cli",
151
+ "github-action",
152
+ "workers-builds",
153
+ "dashboard",
154
+ "unknown"
155
+ ]);
156
+ var devflarePreviewStatusSchema = z.enum([
157
+ "active",
158
+ "superseded",
159
+ "orphaned",
160
+ "deleted"
161
+ ]);
162
+ var devflarePreviewAliasStatusSchema = z.enum([
163
+ "active",
164
+ "reassigned",
165
+ "deleted"
166
+ ]);
167
+ var devflareDeploymentChannelSchema = z.enum([
168
+ "production",
169
+ "preview"
170
+ ]);
171
+ var devflareDeploymentStatusSchema = z.enum([
172
+ "active",
173
+ "superseded",
174
+ "rolled_back",
175
+ "deleted"
176
+ ]);
177
+ var devflarePreviewRecordSchema = createDevflareAccountRecordSchema({
178
+ kind: z.literal("preview"),
179
+ accountId: cloudflareAccountIdSchema,
180
+ workerName: workerNameSchema,
181
+ versionId: cloudflareVersionIdSchema,
182
+ previewUrl: urlSchema,
183
+ alias: previewAliasSchema.optional(),
184
+ aliasPreviewUrl: urlSchema.optional(),
185
+ branchName: branchNameSchema.optional(),
186
+ commitSha: commitShaSchema.optional(),
187
+ deploymentId: recordIdSchema.optional(),
188
+ source: devflareRecordSourceSchema.default("unknown"),
189
+ status: devflarePreviewStatusSchema.default("active")
190
+ }).superRefine((record, ctx) => {
191
+ if (record.aliasPreviewUrl && !record.alias) {
192
+ ctx.addIssue({
193
+ code: "custom",
194
+ path: ["aliasPreviewUrl"],
195
+ message: "aliasPreviewUrl requires alias to be set"
196
+ });
197
+ }
198
+ });
199
+ var devflarePreviewAliasRecordSchema = createDevflareAccountRecordSchema({
200
+ kind: z.literal("previewAlias"),
201
+ accountId: cloudflareAccountIdSchema,
202
+ workerName: workerNameSchema,
203
+ alias: previewAliasSchema,
204
+ aliasPreviewUrl: urlSchema,
205
+ versionId: cloudflareVersionIdSchema,
206
+ previewId: recordIdSchema.optional(),
207
+ branchName: branchNameSchema.optional(),
208
+ commitSha: commitShaSchema.optional(),
209
+ source: devflareRecordSourceSchema.default("unknown"),
210
+ status: devflarePreviewAliasStatusSchema.default("active")
211
+ });
212
+ var devflareDeploymentRecordSchema = createDevflareAccountRecordSchema({
213
+ kind: z.literal("deployment"),
214
+ accountId: cloudflareAccountIdSchema,
215
+ workerName: workerNameSchema,
216
+ deploymentId: recordIdSchema,
217
+ channel: devflareDeploymentChannelSchema,
218
+ status: devflareDeploymentStatusSchema.default("active"),
219
+ versionId: cloudflareVersionIdSchema,
220
+ previewId: recordIdSchema.optional(),
221
+ environment: z.string().min(1).optional(),
222
+ url: urlSchema.optional(),
223
+ message: z.string().min(1).optional(),
224
+ commitSha: commitShaSchema.optional(),
225
+ source: devflareRecordSourceSchema.default("unknown")
226
+ }).superRefine((record, ctx) => {
227
+ if (record.channel === "preview" && !record.previewId) {
228
+ ctx.addIssue({
229
+ code: "custom",
230
+ path: ["previewId"],
231
+ message: "Preview deployments must reference the preview record they materialize"
232
+ });
233
+ }
234
+ if (record.channel === "production" && record.previewId) {
235
+ ctx.addIssue({
236
+ code: "custom",
237
+ path: ["previewId"],
238
+ message: "Production deployments should not reference previewId"
239
+ });
240
+ }
241
+ });
242
+ var devflareAccountLayerRecordSchema = z.discriminatedUnion("kind", [
243
+ devflarePreviewRecordSchema,
244
+ devflarePreviewAliasRecordSchema,
245
+ devflareDeploymentRecordSchema
246
+ ]);
247
+
248
+ // src/cloudflare/preview-registry-cache.ts
249
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
250
+ import { homedir } from "node:os";
251
+ import { join } from "node:path";
252
+ var DEVFLARE_CACHE_DIR = ".devflare";
253
+ var PREVIEW_REGISTRY_CACHE_FILE = "preview-registry.json";
254
+ function getDevflareCacheDir() {
255
+ const override = process.env.DEVFLARE_CACHE_DIR?.trim();
256
+ if (override) {
257
+ return override;
258
+ }
259
+ return join(homedir(), DEVFLARE_CACHE_DIR);
260
+ }
261
+ function getPreviewRegistryCachePath() {
262
+ return join(getDevflareCacheDir(), PREVIEW_REGISTRY_CACHE_FILE);
263
+ }
264
+ function getPreviewRegistryCacheKey(accountId, databaseName) {
265
+ return `${accountId}:${databaseName}`;
266
+ }
267
+ function readPreviewRegistryCache() {
268
+ const cachePath = getPreviewRegistryCachePath();
269
+ if (!existsSync(cachePath)) {
270
+ return {};
271
+ }
272
+ try {
273
+ const content = readFileSync(cachePath, "utf-8");
274
+ return JSON.parse(content);
275
+ } catch {
276
+ return {};
277
+ }
278
+ }
279
+ function writePreviewRegistryCache(cache) {
280
+ try {
281
+ const cacheDir = getDevflareCacheDir();
282
+ if (!existsSync(cacheDir)) {
283
+ mkdirSync(cacheDir, { recursive: true });
284
+ }
285
+ writeFileSync(getPreviewRegistryCachePath(), JSON.stringify(cache, null, "\t"), "utf-8");
286
+ } catch {}
287
+ }
288
+ function getRegistryDatabaseName(databaseName) {
289
+ return databaseName?.trim() || DEVFLARE_PREVIEW_REGISTRY_DATABASE;
290
+ }
291
+ function getCachedPreviewRegistryContext(accountId, databaseName) {
292
+ const entry = readPreviewRegistryCache().registries?.[getPreviewRegistryCacheKey(accountId, databaseName)];
293
+ if (!entry?.databaseId) {
294
+ return null;
295
+ }
296
+ return {
297
+ accountId: entry.accountId,
298
+ databaseId: entry.databaseId,
299
+ databaseName: entry.databaseName,
300
+ created: false
301
+ };
302
+ }
303
+ function cachePreviewRegistryContext(registry) {
304
+ const cache = readPreviewRegistryCache();
305
+ const registries = cache.registries ?? {};
306
+ registries[getPreviewRegistryCacheKey(registry.accountId, registry.databaseName)] = {
307
+ accountId: registry.accountId,
308
+ databaseId: registry.databaseId,
309
+ databaseName: registry.databaseName,
310
+ updatedAt: new Date().toISOString()
311
+ };
312
+ writePreviewRegistryCache({
313
+ ...cache,
314
+ registries
315
+ });
316
+ }
317
+ function clearCachedPreviewRegistryContext(accountId, databaseName) {
318
+ const cache = readPreviewRegistryCache();
319
+ if (!cache.registries) {
320
+ return;
321
+ }
322
+ delete cache.registries[getPreviewRegistryCacheKey(accountId, databaseName)];
323
+ writePreviewRegistryCache(cache);
324
+ }
325
+
326
+ // src/cloudflare/preview-registry-records.ts
327
+ function toIsoString(date) {
328
+ return date ? date.toISOString() : null;
329
+ }
330
+ function inferRecordSource(explicitSource, fallbackSource) {
331
+ if (explicitSource) {
332
+ return explicitSource;
333
+ }
334
+ if (fallbackSource === "dashboard") {
335
+ return "dashboard";
336
+ }
337
+ if (fallbackSource === "workers-builds") {
338
+ return "workers-builds";
339
+ }
340
+ if (fallbackSource === "wrangler") {
341
+ return process.env.GITHUB_ACTIONS === "true" ? "github-action" : "cli";
342
+ }
343
+ return "unknown";
344
+ }
345
+ function getPreviewRecordId(workerName, versionId) {
346
+ return `preview:${workerName}:${versionId}`;
347
+ }
348
+ function getPreviewAliasRecordId(workerName, alias) {
349
+ return `previewAlias:${workerName}:${alias}`;
350
+ }
351
+ function getPreviewDeploymentId(workerName, versionId) {
352
+ return `preview:${workerName}:${versionId}`;
353
+ }
354
+ function getDeploymentRecordId(workerName, deploymentId) {
355
+ return `deployment:${workerName}:${deploymentId}`;
356
+ }
357
+ function hasRetireSelector(options) {
358
+ return Boolean(options.branchName || options.previewAlias || options.versionId || options.commitSha);
359
+ }
360
+ function matchesRetireSelector(options, candidate) {
361
+ return options.branchName !== undefined && candidate.branchName === options.branchName || options.previewAlias !== undefined && candidate.previewAlias === options.previewAlias || options.versionId !== undefined && candidate.versionId === options.versionId || options.commitSha !== undefined && candidate.commitSha === options.commitSha;
362
+ }
363
+ function getPreviewRetireCandidate(record) {
364
+ return {
365
+ branchName: record.branchName,
366
+ previewAlias: record.alias,
367
+ versionId: record.versionId,
368
+ commitSha: record.commitSha
369
+ };
370
+ }
371
+ function matchesPreviewRetireTarget(record, options) {
372
+ return matchesRetireSelector(options, getPreviewRetireCandidate(record));
373
+ }
374
+ function matchesPreviewAliasRetireTarget(record, options) {
375
+ return matchesRetireSelector(options, getPreviewRetireCandidate(record));
376
+ }
377
+ function matchesPreviewDeploymentRetireTarget(record, options) {
378
+ return record.channel === "preview" && matchesRetireSelector(options, {
379
+ versionId: record.versionId,
380
+ commitSha: record.commitSha
381
+ });
382
+ }
383
+ function markRecordDeleted(record, now, parser) {
384
+ return parser.parse({
385
+ ...record,
386
+ updatedAt: now,
387
+ deletedAt: now,
388
+ status: "deleted"
389
+ });
390
+ }
391
+ function getVersionAuthorId(version, existingCreatedBy) {
392
+ return version?.metadata.authorId || existingCreatedBy || "unknown";
393
+ }
394
+ function createPreviewLinkedRecordBase(options) {
395
+ return {
396
+ createdAt: options.existingCreatedAt ?? options.previewRecord.createdAt,
397
+ updatedAt: options.now,
398
+ deletedAt: undefined,
399
+ createdBy: options.previewRecord.createdBy,
400
+ accountId: options.accountId,
401
+ workerName: options.workerName,
402
+ versionId: options.previewRecord.versionId,
403
+ previewId: options.previewRecord.id,
404
+ commitSha: options.previewRecord.commitSha,
405
+ source: options.previewRecord.source,
406
+ status: "active"
407
+ };
408
+ }
409
+ function buildPreviewRecord(options) {
410
+ const alias = options.previewAlias ?? options.existing?.alias;
411
+ const previewUrl = options.previewUrl ?? options.existing?.previewUrl ?? (options.workersSubdomain ? formatVersionPreviewUrl(options.version.id, options.workerName, options.workersSubdomain) : undefined);
412
+ const aliasPreviewUrl = options.previewAliasUrl ?? options.existing?.aliasPreviewUrl ?? (alias && options.workersSubdomain ? formatPreviewAliasUrl(alias, options.workerName, options.workersSubdomain) : undefined);
413
+ if (!previewUrl) {
414
+ return null;
415
+ }
416
+ return devflarePreviewRecordSchema.parse({
417
+ id: getPreviewRecordId(options.workerName, options.version.id),
418
+ kind: "preview",
419
+ ver: 1,
420
+ createdAt: options.existing?.createdAt ?? options.version.metadata.createdOn ?? options.now,
421
+ updatedAt: options.now,
422
+ deletedAt: undefined,
423
+ createdBy: getVersionAuthorId(options.version, options.existing?.createdBy),
424
+ accountId: options.accountId,
425
+ workerName: options.workerName,
426
+ versionId: options.version.id,
427
+ previewUrl,
428
+ alias,
429
+ aliasPreviewUrl,
430
+ branchName: options.branchName ?? options.existing?.branchName,
431
+ commitSha: options.commitSha ?? options.existing?.commitSha,
432
+ deploymentId: options.existing?.deploymentId,
433
+ source: inferRecordSource(options.source, options.version.metadata.source),
434
+ status: "active"
435
+ });
436
+ }
437
+ function buildPreviewAliasRecord(options) {
438
+ if (!options.previewRecord.alias || !options.previewRecord.aliasPreviewUrl) {
439
+ return null;
440
+ }
441
+ return devflarePreviewAliasRecordSchema.parse({
442
+ id: getPreviewAliasRecordId(options.workerName, options.previewRecord.alias),
443
+ kind: "previewAlias",
444
+ ver: 1,
445
+ ...createPreviewLinkedRecordBase({
446
+ accountId: options.accountId,
447
+ workerName: options.workerName,
448
+ previewRecord: options.previewRecord,
449
+ existingCreatedAt: options.existing?.createdAt,
450
+ now: options.now
451
+ }),
452
+ alias: options.previewRecord.alias,
453
+ aliasPreviewUrl: options.previewRecord.aliasPreviewUrl,
454
+ branchName: options.previewRecord.branchName
455
+ });
456
+ }
457
+ function buildPreviewDeploymentRecord(options) {
458
+ const deploymentId = getPreviewDeploymentId(options.workerName, options.previewRecord.versionId);
459
+ return devflareDeploymentRecordSchema.parse({
460
+ id: getDeploymentRecordId(options.workerName, deploymentId),
461
+ kind: "deployment",
462
+ ver: 1,
463
+ ...createPreviewLinkedRecordBase({
464
+ accountId: options.accountId,
465
+ workerName: options.workerName,
466
+ previewRecord: options.previewRecord,
467
+ existingCreatedAt: options.existing?.createdAt,
468
+ now: options.now
469
+ }),
470
+ deploymentId,
471
+ channel: "preview",
472
+ environment: "preview",
473
+ url: options.previewRecord.aliasPreviewUrl ?? options.previewRecord.previewUrl,
474
+ message: options.existing?.message
475
+ });
476
+ }
477
+ function buildProductionDeploymentRecord(options) {
478
+ const versionId = options.deployment.versions[0]?.versionId;
479
+ if (!versionId) {
480
+ return null;
481
+ }
482
+ const productionUrl = options.workersSubdomain ? `https://${options.workerName}.${options.workersSubdomain}.workers.dev` : options.existing?.url;
483
+ return devflareDeploymentRecordSchema.parse({
484
+ id: getDeploymentRecordId(options.workerName, options.deployment.id),
485
+ kind: "deployment",
486
+ ver: 1,
487
+ createdAt: options.existing?.createdAt ?? options.deployment.createdOn,
488
+ updatedAt: options.now,
489
+ deletedAt: undefined,
490
+ createdBy: getVersionAuthorId(options.version, options.existing?.createdBy),
491
+ accountId: options.accountId,
492
+ workerName: options.workerName,
493
+ deploymentId: options.deployment.id,
494
+ channel: "production",
495
+ status: options.status,
496
+ versionId,
497
+ environment: "production",
498
+ url: productionUrl,
499
+ message: options.deploymentMessage ?? options.deployment.message ?? options.existing?.message,
500
+ commitSha: options.commitSha ?? options.existing?.commitSha,
501
+ source: inferRecordSource(options.source, options.version?.metadata.source ?? options.deployment.source)
502
+ });
503
+ }
504
+ async function getVersionInfoById(accountId, workerName, versionId, versionMap, apiOptions) {
505
+ const existing = versionMap.get(versionId);
506
+ if (existing) {
507
+ return existing;
508
+ }
509
+ try {
510
+ const version = await getWorkerVersionDetail(accountId, workerName, versionId, apiOptions);
511
+ versionMap.set(versionId, version);
512
+ return version;
513
+ } catch {
514
+ return;
515
+ }
516
+ }
517
+ function markPreviewRecordDeleted(record, now) {
518
+ return markRecordDeleted(record, now, devflarePreviewRecordSchema);
519
+ }
520
+ function markPreviewAliasRecordDeleted(record, now) {
521
+ return markRecordDeleted(record, now, devflarePreviewAliasRecordSchema);
522
+ }
523
+ function markDeploymentRecordDeleted(record, now) {
524
+ return markRecordDeleted(record, now, devflareDeploymentRecordSchema);
525
+ }
526
+ function getExplicitPreviewSyncOverrides(options, versionId) {
527
+ if (versionId !== options.versionId) {
528
+ return {};
529
+ }
530
+ return {
531
+ previewAlias: options.previewAlias,
532
+ previewUrl: options.previewUrl,
533
+ previewAliasUrl: options.previewAliasUrl,
534
+ branchName: options.branchName,
535
+ commitSha: options.commitSha
536
+ };
537
+ }
538
+
539
+ // src/cloudflare/preview-registry-store.ts
540
+ var REGISTRY_SCHEMA_STATEMENTS = [
541
+ `CREATE TABLE IF NOT EXISTS devflare_preview_records (
542
+ id TEXT PRIMARY KEY,
543
+ ver INTEGER NOT NULL,
544
+ account_id TEXT NOT NULL,
545
+ worker_name TEXT NOT NULL,
546
+ version_id TEXT NOT NULL UNIQUE,
547
+ preview_url TEXT NOT NULL,
548
+ alias TEXT,
549
+ alias_preview_url TEXT,
550
+ branch_name TEXT,
551
+ commit_sha TEXT,
552
+ deployment_id TEXT,
553
+ source TEXT NOT NULL,
554
+ status TEXT NOT NULL,
555
+ created_by TEXT NOT NULL,
556
+ created_at TEXT NOT NULL,
557
+ updated_at TEXT,
558
+ deleted_at TEXT,
559
+ payload_json TEXT NOT NULL
560
+ )`,
561
+ "CREATE INDEX IF NOT EXISTS idx_devflare_preview_records_account_worker ON devflare_preview_records(account_id, worker_name)",
562
+ "CREATE INDEX IF NOT EXISTS idx_devflare_preview_records_status ON devflare_preview_records(status)",
563
+ `CREATE TABLE IF NOT EXISTS devflare_preview_alias_records (
564
+ id TEXT PRIMARY KEY,
565
+ ver INTEGER NOT NULL,
566
+ account_id TEXT NOT NULL,
567
+ worker_name TEXT NOT NULL,
568
+ alias TEXT NOT NULL,
569
+ alias_preview_url TEXT NOT NULL,
570
+ version_id TEXT NOT NULL,
571
+ preview_id TEXT,
572
+ branch_name TEXT,
573
+ commit_sha TEXT,
574
+ source TEXT NOT NULL,
575
+ status TEXT NOT NULL,
576
+ created_by TEXT NOT NULL,
577
+ created_at TEXT NOT NULL,
578
+ updated_at TEXT,
579
+ deleted_at TEXT,
580
+ payload_json TEXT NOT NULL
581
+ )`,
582
+ "CREATE INDEX IF NOT EXISTS idx_devflare_preview_alias_records_account_worker ON devflare_preview_alias_records(account_id, worker_name)",
583
+ "CREATE INDEX IF NOT EXISTS idx_devflare_preview_alias_records_alias ON devflare_preview_alias_records(alias)",
584
+ `CREATE TABLE IF NOT EXISTS devflare_deployment_records (
585
+ id TEXT PRIMARY KEY,
586
+ ver INTEGER NOT NULL,
587
+ account_id TEXT NOT NULL,
588
+ worker_name TEXT NOT NULL,
589
+ deployment_id TEXT NOT NULL UNIQUE,
590
+ channel TEXT NOT NULL,
591
+ status TEXT NOT NULL,
592
+ version_id TEXT NOT NULL,
593
+ preview_id TEXT,
594
+ environment TEXT,
595
+ url TEXT,
596
+ message TEXT,
597
+ commit_sha TEXT,
598
+ source TEXT NOT NULL,
599
+ created_by TEXT NOT NULL,
600
+ created_at TEXT NOT NULL,
601
+ updated_at TEXT,
602
+ deleted_at TEXT,
603
+ payload_json TEXT NOT NULL
604
+ )`,
605
+ "CREATE INDEX IF NOT EXISTS idx_devflare_deployment_records_account_worker ON devflare_deployment_records(account_id, worker_name)",
606
+ "CREATE INDEX IF NOT EXISTS idx_devflare_deployment_records_channel_status ON devflare_deployment_records(channel, status)"
607
+ ];
608
+ var schemaEnsuredRegistryIds = new Set;
609
+ async function runQuery(registry, sql, params = [], apiOptions) {
610
+ const results = await queryD1Database(registry.accountId, registry.databaseId, {
611
+ sql,
612
+ params
613
+ }, apiOptions);
614
+ return results[0]?.results ?? [];
615
+ }
616
+ async function runStatement(registry, sql, params = [], apiOptions) {
617
+ await queryD1Database(registry.accountId, registry.databaseId, {
618
+ sql,
619
+ params
620
+ }, apiOptions);
621
+ }
622
+ async function ensurePreviewRegistrySchema(registry, apiOptions) {
623
+ if (schemaEnsuredRegistryIds.has(registry.databaseId)) {
624
+ return;
625
+ }
626
+ for (const statement of REGISTRY_SCHEMA_STATEMENTS) {
627
+ await runStatement(registry, statement, [], apiOptions);
628
+ }
629
+ schemaEnsuredRegistryIds.add(registry.databaseId);
630
+ }
631
+ function clearPreviewRegistrySchemaCache(databaseId) {
632
+ schemaEnsuredRegistryIds.delete(databaseId);
633
+ }
634
+ function isMissingRegistrySchemaError(error) {
635
+ if (error instanceof CloudflareAPIError) {
636
+ const message = error.message.toLowerCase();
637
+ return message.includes("no such table") || message.includes("no such column");
638
+ }
639
+ if (error instanceof Error) {
640
+ const message = error.message.toLowerCase();
641
+ return message.includes("no such table") || message.includes("no such column");
642
+ }
643
+ return false;
644
+ }
645
+ function isUnavailableRegistryContextError(error) {
646
+ if (error instanceof CloudflareAPIError) {
647
+ const message = error.message.toLowerCase();
648
+ return error.code === 404 || (message.includes("database") || message.includes("d1")) && (message.includes("not found") || message.includes("does not exist") || message.includes("unknown"));
649
+ }
650
+ if (error instanceof Error) {
651
+ const message = error.message.toLowerCase();
652
+ return (message.includes("database") || message.includes("d1")) && (message.includes("not found") || message.includes("does not exist"));
653
+ }
654
+ return false;
655
+ }
656
+ function parseStoredPreviewRecord(row) {
657
+ return devflarePreviewRecordSchema.parse(JSON.parse(row.payload_json));
658
+ }
659
+ function parseStoredPreviewAliasRecord(row) {
660
+ return devflarePreviewAliasRecordSchema.parse(JSON.parse(row.payload_json));
661
+ }
662
+ function parseStoredDeploymentRecord(row) {
663
+ return devflareDeploymentRecordSchema.parse(JSON.parse(row.payload_json));
664
+ }
665
+ async function readPreviewRows(registry, workerName, apiOptions) {
666
+ const sql = workerName ? "SELECT payload_json FROM devflare_preview_records WHERE account_id = ? AND worker_name = ? ORDER BY created_at DESC" : "SELECT payload_json FROM devflare_preview_records WHERE account_id = ? ORDER BY created_at DESC";
667
+ const params = workerName ? [registry.accountId, workerName] : [registry.accountId];
668
+ const rows = await runQuery(registry, sql, params, apiOptions);
669
+ return rows.map((row) => parseStoredPreviewRecord(row));
670
+ }
671
+ async function readPreviewAliasRows(registry, workerName, apiOptions) {
672
+ const sql = workerName ? "SELECT payload_json FROM devflare_preview_alias_records WHERE account_id = ? AND worker_name = ? ORDER BY created_at DESC" : "SELECT payload_json FROM devflare_preview_alias_records WHERE account_id = ? ORDER BY created_at DESC";
673
+ const params = workerName ? [registry.accountId, workerName] : [registry.accountId];
674
+ const rows = await runQuery(registry, sql, params, apiOptions);
675
+ return rows.map((row) => parseStoredPreviewAliasRecord(row));
676
+ }
677
+ async function readDeploymentRows(registry, workerName, apiOptions) {
678
+ const sql = workerName ? "SELECT payload_json FROM devflare_deployment_records WHERE account_id = ? AND worker_name = ? ORDER BY created_at DESC" : "SELECT payload_json FROM devflare_deployment_records WHERE account_id = ? ORDER BY created_at DESC";
679
+ const params = workerName ? [registry.accountId, workerName] : [registry.accountId];
680
+ const rows = await runQuery(registry, sql, params, apiOptions);
681
+ return rows.map((row) => parseStoredDeploymentRecord(row));
682
+ }
683
+ async function upsertPreviewRecord(registry, record, apiOptions) {
684
+ const normalizedRecord = devflarePreviewRecordSchema.parse(record);
685
+ await runStatement(registry, `INSERT INTO devflare_preview_records (
686
+ id,
687
+ ver,
688
+ account_id,
689
+ worker_name,
690
+ version_id,
691
+ preview_url,
692
+ alias,
693
+ alias_preview_url,
694
+ branch_name,
695
+ commit_sha,
696
+ deployment_id,
697
+ source,
698
+ status,
699
+ created_by,
700
+ created_at,
701
+ updated_at,
702
+ deleted_at,
703
+ payload_json
704
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
705
+ ON CONFLICT(id) DO UPDATE SET
706
+ ver = excluded.ver,
707
+ account_id = excluded.account_id,
708
+ worker_name = excluded.worker_name,
709
+ version_id = excluded.version_id,
710
+ preview_url = excluded.preview_url,
711
+ alias = excluded.alias,
712
+ alias_preview_url = excluded.alias_preview_url,
713
+ branch_name = excluded.branch_name,
714
+ commit_sha = excluded.commit_sha,
715
+ deployment_id = excluded.deployment_id,
716
+ source = excluded.source,
717
+ status = excluded.status,
718
+ created_by = excluded.created_by,
719
+ created_at = excluded.created_at,
720
+ updated_at = excluded.updated_at,
721
+ deleted_at = excluded.deleted_at,
722
+ payload_json = excluded.payload_json`, [
723
+ normalizedRecord.id,
724
+ normalizedRecord.ver,
725
+ normalizedRecord.accountId,
726
+ normalizedRecord.workerName,
727
+ normalizedRecord.versionId,
728
+ normalizedRecord.previewUrl,
729
+ normalizedRecord.alias ?? null,
730
+ normalizedRecord.aliasPreviewUrl ?? null,
731
+ normalizedRecord.branchName ?? null,
732
+ normalizedRecord.commitSha ?? null,
733
+ normalizedRecord.deploymentId ?? null,
734
+ normalizedRecord.source,
735
+ normalizedRecord.status,
736
+ normalizedRecord.createdBy,
737
+ normalizedRecord.createdAt.toISOString(),
738
+ toIsoString(normalizedRecord.updatedAt),
739
+ toIsoString(normalizedRecord.deletedAt),
740
+ JSON.stringify(normalizedRecord)
741
+ ], apiOptions);
742
+ }
743
+ async function upsertPreviewAliasRecord(registry, record, apiOptions) {
744
+ const normalizedRecord = devflarePreviewAliasRecordSchema.parse(record);
745
+ await runStatement(registry, `INSERT INTO devflare_preview_alias_records (
746
+ id,
747
+ ver,
748
+ account_id,
749
+ worker_name,
750
+ alias,
751
+ alias_preview_url,
752
+ version_id,
753
+ preview_id,
754
+ branch_name,
755
+ commit_sha,
756
+ source,
757
+ status,
758
+ created_by,
759
+ created_at,
760
+ updated_at,
761
+ deleted_at,
762
+ payload_json
763
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
764
+ ON CONFLICT(id) DO UPDATE SET
765
+ ver = excluded.ver,
766
+ account_id = excluded.account_id,
767
+ worker_name = excluded.worker_name,
768
+ alias = excluded.alias,
769
+ alias_preview_url = excluded.alias_preview_url,
770
+ version_id = excluded.version_id,
771
+ preview_id = excluded.preview_id,
772
+ branch_name = excluded.branch_name,
773
+ commit_sha = excluded.commit_sha,
774
+ source = excluded.source,
775
+ status = excluded.status,
776
+ created_by = excluded.created_by,
777
+ created_at = excluded.created_at,
778
+ updated_at = excluded.updated_at,
779
+ deleted_at = excluded.deleted_at,
780
+ payload_json = excluded.payload_json`, [
781
+ normalizedRecord.id,
782
+ normalizedRecord.ver,
783
+ normalizedRecord.accountId,
784
+ normalizedRecord.workerName,
785
+ normalizedRecord.alias,
786
+ normalizedRecord.aliasPreviewUrl,
787
+ normalizedRecord.versionId,
788
+ normalizedRecord.previewId ?? null,
789
+ normalizedRecord.branchName ?? null,
790
+ normalizedRecord.commitSha ?? null,
791
+ normalizedRecord.source,
792
+ normalizedRecord.status,
793
+ normalizedRecord.createdBy,
794
+ normalizedRecord.createdAt.toISOString(),
795
+ toIsoString(normalizedRecord.updatedAt),
796
+ toIsoString(normalizedRecord.deletedAt),
797
+ JSON.stringify(normalizedRecord)
798
+ ], apiOptions);
799
+ }
800
+ async function upsertDeploymentRecord(registry, record, apiOptions) {
801
+ const normalizedRecord = devflareDeploymentRecordSchema.parse(record);
802
+ await runStatement(registry, `INSERT INTO devflare_deployment_records (
803
+ id,
804
+ ver,
805
+ account_id,
806
+ worker_name,
807
+ deployment_id,
808
+ channel,
809
+ status,
810
+ version_id,
811
+ preview_id,
812
+ environment,
813
+ url,
814
+ message,
815
+ commit_sha,
816
+ source,
817
+ created_by,
818
+ created_at,
819
+ updated_at,
820
+ deleted_at,
821
+ payload_json
822
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
823
+ ON CONFLICT(id) DO UPDATE SET
824
+ ver = excluded.ver,
825
+ account_id = excluded.account_id,
826
+ worker_name = excluded.worker_name,
827
+ deployment_id = excluded.deployment_id,
828
+ channel = excluded.channel,
829
+ status = excluded.status,
830
+ version_id = excluded.version_id,
831
+ preview_id = excluded.preview_id,
832
+ environment = excluded.environment,
833
+ url = excluded.url,
834
+ message = excluded.message,
835
+ commit_sha = excluded.commit_sha,
836
+ source = excluded.source,
837
+ created_by = excluded.created_by,
838
+ created_at = excluded.created_at,
839
+ updated_at = excluded.updated_at,
840
+ deleted_at = excluded.deleted_at,
841
+ payload_json = excluded.payload_json`, [
842
+ normalizedRecord.id,
843
+ normalizedRecord.ver,
844
+ normalizedRecord.accountId,
845
+ normalizedRecord.workerName,
846
+ normalizedRecord.deploymentId,
847
+ normalizedRecord.channel,
848
+ normalizedRecord.status,
849
+ normalizedRecord.versionId,
850
+ normalizedRecord.previewId ?? null,
851
+ normalizedRecord.environment ?? null,
852
+ normalizedRecord.url ?? null,
853
+ normalizedRecord.message ?? null,
854
+ normalizedRecord.commitSha ?? null,
855
+ normalizedRecord.source,
856
+ normalizedRecord.createdBy,
857
+ normalizedRecord.createdAt.toISOString(),
858
+ toIsoString(normalizedRecord.updatedAt),
859
+ toIsoString(normalizedRecord.deletedAt),
860
+ JSON.stringify(normalizedRecord)
861
+ ], apiOptions);
862
+ }
863
+
864
+ // src/cloudflare/preview-registry.ts
865
+ async function withRegistryReadRecovery(registry, apiOptions, operation) {
866
+ try {
867
+ return {
868
+ registry,
869
+ result: await operation(registry)
870
+ };
871
+ } catch (error) {
872
+ if (isMissingRegistrySchemaError(error)) {
873
+ clearPreviewRegistrySchemaCache(registry.databaseId);
874
+ await ensurePreviewRegistrySchema(registry, apiOptions);
875
+ return {
876
+ registry,
877
+ result: await operation(registry)
878
+ };
879
+ }
880
+ if (!isUnavailableRegistryContextError(error)) {
881
+ throw error;
882
+ }
883
+ clearCachedPreviewRegistryContext(registry.accountId, registry.databaseName);
884
+ const refreshedRegistry = await ensurePreviewRegistry({
885
+ accountId: registry.accountId,
886
+ databaseName: registry.databaseName,
887
+ apiOptions,
888
+ skipContextCache: true
889
+ });
890
+ return {
891
+ registry: refreshedRegistry,
892
+ result: await operation(refreshedRegistry)
893
+ };
894
+ }
895
+ }
896
+ async function loadTrackedRegistryRows(registry, workerName, apiOptions) {
897
+ const [previews, aliases, deployments] = await Promise.all([
898
+ readPreviewRows(registry, workerName, apiOptions),
899
+ readPreviewAliasRows(registry, workerName, apiOptions),
900
+ readDeploymentRows(registry, workerName, apiOptions)
901
+ ]);
902
+ return {
903
+ previews,
904
+ aliases,
905
+ deployments
906
+ };
907
+ }
908
+ async function applyDeletedRecords(registry, options) {
909
+ for (const preview of options.previews) {
910
+ await upsertPreviewRecord(registry, markPreviewRecordDeleted(preview, options.now), options.apiOptions);
911
+ }
912
+ for (const alias of options.aliases) {
913
+ await upsertPreviewAliasRecord(registry, markPreviewAliasRecordDeleted(alias, options.now), options.apiOptions);
914
+ }
915
+ for (const deployment of options.deployments) {
916
+ await upsertDeploymentRecord(registry, markDeploymentRecordDeleted(deployment, options.now), options.apiOptions);
917
+ }
918
+ }
919
+ async function getPreviewRegistryContext(options) {
920
+ const databaseName = getRegistryDatabaseName(options.databaseName);
921
+ if (options.skipContextCache !== true) {
922
+ const cached = getCachedPreviewRegistryContext(options.accountId, databaseName);
923
+ if (cached) {
924
+ return cached;
925
+ }
926
+ }
927
+ const databases = await listD1Databases(options.accountId, options.apiOptions);
928
+ const existing = databases.find((database) => database.name === databaseName);
929
+ if (!existing) {
930
+ return null;
931
+ }
932
+ const registry = {
933
+ accountId: options.accountId,
934
+ databaseId: existing.id,
935
+ databaseName,
936
+ created: false
937
+ };
938
+ cachePreviewRegistryContext(registry);
939
+ return registry;
940
+ }
941
+ async function ensurePreviewRegistry(options) {
942
+ const existingContext = await getPreviewRegistryContext(options);
943
+ let registry = existingContext;
944
+ if (!registry) {
945
+ const created = await createD1Database(options.accountId, getRegistryDatabaseName(options.databaseName), options.apiOptions);
946
+ registry = {
947
+ accountId: options.accountId,
948
+ databaseId: created.id,
949
+ databaseName: created.name,
950
+ created: true
951
+ };
952
+ cachePreviewRegistryContext(registry);
953
+ options.logger?.info?.(`Created Devflare preview registry D1 database: ${registry.databaseName}`);
954
+ }
955
+ if (registry.created || options.skipSchemaIfExisting !== true) {
956
+ await ensurePreviewRegistrySchema(registry, options.apiOptions);
957
+ }
958
+ return registry;
959
+ }
960
+ async function listTrackedRegistryState(options) {
961
+ const { result } = await withRegistryReadRecovery(options.registry, options.apiOptions, async (registry) => {
962
+ return loadTrackedRegistryRows(registry, options.workerName, options.apiOptions);
963
+ });
964
+ return result;
965
+ }
966
+ async function listTrackedPreviewRecords(options) {
967
+ const registry = await ensurePreviewRegistry({
968
+ accountId: options.accountId,
969
+ databaseName: options.databaseName,
970
+ apiOptions: options.apiOptions,
971
+ skipSchemaIfExisting: true
972
+ });
973
+ const { registry: resolvedRegistry, result } = await withRegistryReadRecovery(registry, options.apiOptions, (activeRegistry) => readPreviewRows(activeRegistry, options.workerName, options.apiOptions));
974
+ return {
975
+ registry: resolvedRegistry,
976
+ records: result
977
+ };
978
+ }
979
+ async function listTrackedPreviewAliasRecords(options) {
980
+ const registry = await ensurePreviewRegistry({
981
+ accountId: options.accountId,
982
+ databaseName: options.databaseName,
983
+ apiOptions: options.apiOptions,
984
+ skipSchemaIfExisting: true
985
+ });
986
+ const { registry: resolvedRegistry, result } = await withRegistryReadRecovery(registry, options.apiOptions, (activeRegistry) => readPreviewAliasRows(activeRegistry, options.workerName, options.apiOptions));
987
+ return {
988
+ registry: resolvedRegistry,
989
+ records: result
990
+ };
991
+ }
992
+ async function listTrackedDeploymentRecords(options) {
993
+ const registry = await ensurePreviewRegistry({
994
+ accountId: options.accountId,
995
+ databaseName: options.databaseName,
996
+ apiOptions: options.apiOptions,
997
+ skipSchemaIfExisting: true
998
+ });
999
+ const { registry: resolvedRegistry, result } = await withRegistryReadRecovery(registry, options.apiOptions, (activeRegistry) => readDeploymentRows(activeRegistry, options.workerName, options.apiOptions));
1000
+ return {
1001
+ registry: resolvedRegistry,
1002
+ records: result
1003
+ };
1004
+ }
1005
+ async function reconcilePreviewRegistry(options) {
1006
+ const now = options.now ?? new Date;
1007
+ const registry = await ensurePreviewRegistry({
1008
+ accountId: options.accountId,
1009
+ databaseName: options.databaseName,
1010
+ apiOptions: options.apiOptions,
1011
+ logger: options.logger
1012
+ });
1013
+ const workersSubdomain = await getWorkersSubdomain(options.accountId, options.apiOptions);
1014
+ const liveVersions = await listWorkerVersions(options.accountId, options.workerName, options.apiOptions);
1015
+ const liveDeployments = await listWorkerDeployments(options.accountId, options.workerName, options.apiOptions);
1016
+ const { previews: previewRecords, aliases: aliasRecords, deployments: deploymentRecords } = await loadTrackedRegistryRows(registry, options.workerName, options.apiOptions);
1017
+ const previewRecordByVersionId = new Map(previewRecords.map((record) => [record.versionId, record]));
1018
+ const previewAliasRecordByAlias = new Map(aliasRecords.map((record) => [record.alias, record]));
1019
+ const deploymentRecordById = new Map(deploymentRecords.map((record) => [record.deploymentId, record]));
1020
+ const syncedPreviews = [];
1021
+ const syncedAliases = [];
1022
+ const syncedDeployments = [];
1023
+ const versionMetadataMap = new Map(liveVersions.map((version) => [version.id, version]));
1024
+ const previewVersions = [...liveVersions.filter((candidate) => candidate.metadata.hasPreview)];
1025
+ if (options.versionId && (options.previewUrl || options.previewAliasUrl || options.previewAlias) && !previewVersions.some((version) => version.id === options.versionId)) {
1026
+ const explicitPreviewVersion = await getVersionInfoById(options.accountId, options.workerName, options.versionId, versionMetadataMap, options.apiOptions);
1027
+ if (explicitPreviewVersion) {
1028
+ previewVersions.unshift({
1029
+ ...explicitPreviewVersion,
1030
+ metadata: {
1031
+ ...explicitPreviewVersion.metadata,
1032
+ hasPreview: true
1033
+ }
1034
+ });
1035
+ }
1036
+ }
1037
+ for (const version of previewVersions) {
1038
+ const previewRecord = buildPreviewRecord({
1039
+ accountId: options.accountId,
1040
+ workerName: options.workerName,
1041
+ version,
1042
+ existing: previewRecordByVersionId.get(version.id),
1043
+ workersSubdomain,
1044
+ ...getExplicitPreviewSyncOverrides(options, version.id),
1045
+ source: options.source,
1046
+ now
1047
+ });
1048
+ if (!previewRecord) {
1049
+ options.logger?.warn?.(`Skipping preview registry sync for ${version.id} because no preview URL could be determined.`);
1050
+ continue;
1051
+ }
1052
+ await upsertPreviewRecord(registry, previewRecord, options.apiOptions);
1053
+ syncedPreviews.push(previewRecord);
1054
+ const aliasRecord = buildPreviewAliasRecord({
1055
+ accountId: options.accountId,
1056
+ workerName: options.workerName,
1057
+ previewRecord,
1058
+ existing: previewRecord.alias ? previewAliasRecordByAlias.get(previewRecord.alias) : undefined,
1059
+ now
1060
+ });
1061
+ if (aliasRecord) {
1062
+ await upsertPreviewAliasRecord(registry, aliasRecord, options.apiOptions);
1063
+ syncedAliases.push(aliasRecord);
1064
+ }
1065
+ const previewDeploymentRecord = buildPreviewDeploymentRecord({
1066
+ accountId: options.accountId,
1067
+ workerName: options.workerName,
1068
+ previewRecord,
1069
+ existing: deploymentRecordById.get(getPreviewDeploymentId(options.workerName, previewRecord.versionId)),
1070
+ now
1071
+ });
1072
+ await upsertDeploymentRecord(registry, previewDeploymentRecord, options.apiOptions);
1073
+ syncedDeployments.push(previewDeploymentRecord);
1074
+ }
1075
+ for (const [index, deployment] of liveDeployments.entries()) {
1076
+ const versionId = deployment.versions[0]?.versionId;
1077
+ const version = versionId ? await getVersionInfoById(options.accountId, options.workerName, versionId, versionMetadataMap, options.apiOptions) : undefined;
1078
+ const deploymentRecord = buildProductionDeploymentRecord({
1079
+ accountId: options.accountId,
1080
+ workerName: options.workerName,
1081
+ deployment,
1082
+ version,
1083
+ existing: deploymentRecordById.get(deployment.id),
1084
+ workersSubdomain,
1085
+ source: options.source,
1086
+ commitSha: versionId === options.versionId ? options.commitSha : undefined,
1087
+ deploymentMessage: index === 0 ? options.deploymentMessage : undefined,
1088
+ status: index === 0 ? "active" : "superseded",
1089
+ now
1090
+ });
1091
+ if (!deploymentRecord) {
1092
+ continue;
1093
+ }
1094
+ await upsertDeploymentRecord(registry, deploymentRecord, options.apiOptions);
1095
+ syncedDeployments.push(deploymentRecord);
1096
+ }
1097
+ return {
1098
+ registry,
1099
+ previews: syncedPreviews,
1100
+ previewAliases: syncedAliases,
1101
+ deployments: syncedDeployments
1102
+ };
1103
+ }
1104
+ async function cleanupPreviewRegistry(options) {
1105
+ const now = options.now ?? new Date;
1106
+ const registry = await ensurePreviewRegistry({
1107
+ accountId: options.accountId,
1108
+ databaseName: options.databaseName,
1109
+ apiOptions: options.apiOptions,
1110
+ logger: options.logger
1111
+ });
1112
+ const { previews, aliases, deployments } = await loadTrackedRegistryRows(registry, options.workerName, options.apiOptions);
1113
+ const cutoff = new Date(now.getTime() - Math.max(options.days ?? 7, 0) * 24 * 60 * 60 * 1000);
1114
+ const previewCandidates = previews.filter((record) => !record.deletedAt && record.createdAt <= cutoff && record.status !== "active");
1115
+ const aliasCandidates = aliases.filter((record) => !record.deletedAt && record.createdAt <= cutoff && record.status !== "active");
1116
+ const deploymentCandidates = deployments.filter((record) => !record.deletedAt && record.createdAt <= cutoff && record.status !== "active");
1117
+ if (options.apply) {
1118
+ await applyDeletedRecords(registry, {
1119
+ previews: previewCandidates,
1120
+ aliases: aliasCandidates,
1121
+ deployments: deploymentCandidates,
1122
+ now,
1123
+ apiOptions: options.apiOptions
1124
+ });
1125
+ }
1126
+ return {
1127
+ registry,
1128
+ previews,
1129
+ aliases,
1130
+ deployments,
1131
+ candidates: {
1132
+ previews: previewCandidates,
1133
+ aliases: aliasCandidates,
1134
+ deployments: deploymentCandidates
1135
+ },
1136
+ applied: options.apply === true
1137
+ };
1138
+ }
1139
+ async function retirePreviewRegistry(options) {
1140
+ if (!hasRetireSelector(options)) {
1141
+ throw new Error("Retiring preview registry records requires at least one selector: branchName, previewAlias, versionId, or commitSha.");
1142
+ }
1143
+ const now = options.now ?? new Date;
1144
+ const registry = await ensurePreviewRegistry({
1145
+ accountId: options.accountId,
1146
+ databaseName: options.databaseName,
1147
+ apiOptions: options.apiOptions,
1148
+ logger: options.logger
1149
+ });
1150
+ const { previews, aliases, deployments } = await loadTrackedRegistryRows(registry, options.workerName, options.apiOptions);
1151
+ const directlyMatchedPreviews = previews.filter((record) => !record.deletedAt && matchesPreviewRetireTarget(record, options));
1152
+ const directlyMatchedAliases = aliases.filter((record) => !record.deletedAt && matchesPreviewAliasRetireTarget(record, options));
1153
+ const directlyMatchedDeployments = deployments.filter((record) => !record.deletedAt && matchesPreviewDeploymentRetireTarget(record, options));
1154
+ const candidatePreviewIds = new Set([
1155
+ ...directlyMatchedPreviews.map((record) => record.id),
1156
+ ...directlyMatchedAliases.flatMap((record) => record.previewId ? [record.previewId] : [])
1157
+ ]);
1158
+ const candidateVersionIds = new Set([
1159
+ ...directlyMatchedPreviews.map((record) => record.versionId),
1160
+ ...directlyMatchedAliases.map((record) => record.versionId),
1161
+ ...directlyMatchedDeployments.map((record) => record.versionId),
1162
+ ...options.versionId ? [options.versionId] : []
1163
+ ]);
1164
+ const previewCandidates = previews.filter((record) => {
1165
+ return !record.deletedAt && (matchesPreviewRetireTarget(record, options) || candidatePreviewIds.has(record.id) || candidateVersionIds.has(record.versionId));
1166
+ });
1167
+ const resolvedPreviewIds = new Set(previewCandidates.map((record) => record.id));
1168
+ const resolvedVersionIds = new Set([
1169
+ ...candidateVersionIds,
1170
+ ...previewCandidates.map((record) => record.versionId)
1171
+ ]);
1172
+ const aliasCandidates = aliases.filter((record) => {
1173
+ return !record.deletedAt && (matchesPreviewAliasRetireTarget(record, options) || resolvedVersionIds.has(record.versionId) || record.previewId !== undefined && resolvedPreviewIds.has(record.previewId));
1174
+ });
1175
+ for (const record of aliasCandidates) {
1176
+ resolvedVersionIds.add(record.versionId);
1177
+ if (record.previewId) {
1178
+ resolvedPreviewIds.add(record.previewId);
1179
+ }
1180
+ }
1181
+ const deploymentCandidates = deployments.filter((record) => {
1182
+ return !record.deletedAt && record.channel === "preview" && (matchesPreviewDeploymentRetireTarget(record, options) || resolvedVersionIds.has(record.versionId) || record.previewId !== undefined && resolvedPreviewIds.has(record.previewId));
1183
+ });
1184
+ if (options.apply) {
1185
+ await applyDeletedRecords(registry, {
1186
+ previews: previewCandidates,
1187
+ aliases: aliasCandidates,
1188
+ deployments: deploymentCandidates,
1189
+ now,
1190
+ apiOptions: options.apiOptions
1191
+ });
1192
+ }
1193
+ return {
1194
+ registry,
1195
+ previews,
1196
+ aliases,
1197
+ deployments,
1198
+ candidates: {
1199
+ previews: previewCandidates,
1200
+ aliases: aliasCandidates,
1201
+ deployments: deploymentCandidates
1202
+ },
1203
+ applied: options.apply === true
1204
+ };
1205
+ }
1206
+
1207
+ export { formatWorkersDevUrl, parseWranglerStructuredOutput, mergeParsedWranglerDeployOutputs, parseWranglerDeployOutput, DEVFLARE_PREVIEW_REGISTRY_DATABASE, devflareAccountRecordSchema, createDevflareAccountRecordSchema, devflareRecordSourceSchema, devflarePreviewStatusSchema, devflarePreviewAliasStatusSchema, devflareDeploymentChannelSchema, devflareDeploymentStatusSchema, devflarePreviewRecordSchema, devflarePreviewAliasRecordSchema, devflareDeploymentRecordSchema, devflareAccountLayerRecordSchema, getPreviewRegistryContext, ensurePreviewRegistry, listTrackedRegistryState, listTrackedPreviewRecords, listTrackedPreviewAliasRecords, listTrackedDeploymentRecords, reconcilePreviewRegistry, cleanupPreviewRegistry, retirePreviewRegistry };