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,1169 @@
1
+ import {
2
+ findConfigPathsUnderDirectory
3
+ } from "./index-9az6s7ad.js";
4
+ import {
5
+ buildPreviewScopeRowsFromLiveWorkers,
6
+ buildPreviewWorkerCandidatesByScope,
7
+ buildStableWorkerRowsFromLiveWorkers,
8
+ collectConfiguredWorkerFamilies,
9
+ formatOverviewStatus,
10
+ formatRecordDate,
11
+ loadTrackedPreviewScopeRows,
12
+ orderPreviewWorkerNamesForDeletion,
13
+ shouldUseColor
14
+ } from "./index-maxpsfk8.js";
15
+ import {
16
+ asOptionalString,
17
+ resolveCloudflareAccountId,
18
+ resolveNamedSelection
19
+ } from "./index-v5nmqthy.js";
20
+ import {
21
+ account
22
+ } from "./index-sqrksgb2.js";
23
+ import"./index-72mve6vh.js";
24
+ import {
25
+ retirePreviewRegistry
26
+ } from "./index-q4kaz181.js";
27
+ import {
28
+ cleanupPreviewScopedResources
29
+ } from "./index-k6vq6kkt.js";
30
+ import {
31
+ getDependencies
32
+ } from "./index-1xpj0m4r.js";
33
+ import {
34
+ bold,
35
+ cyanBold,
36
+ dim,
37
+ formatTableLine,
38
+ green,
39
+ logLine,
40
+ whiteDim,
41
+ yellowBold
42
+ } from "./index-stgn34cr.js";
43
+ import"./index-3t6rypgc.js";
44
+ import"./index-7g8zyws4.js";
45
+ import"./index-rbht7m9r.js";
46
+ import {
47
+ compileConfig
48
+ } from "./index-pnbs1b8k.js";
49
+ import {
50
+ ConfigNotFoundError,
51
+ loadConfig,
52
+ loadResolvedConfig,
53
+ resolveConfigPath
54
+ } from "./index-6psz1h4c.js";
55
+ import"./index-xk9djfjp.js";
56
+ import"./index-0w826dsr.js";
57
+ import {
58
+ resolvePreviewIdentifier
59
+ } from "./index-6jef5emv.js";
60
+ import"./index-t08te69w.js";
61
+ import"./index-37x76zdn.js";
62
+
63
+ // src/cli/preview-bindings.ts
64
+ var WRANGLER_TEXT_COLUMNS_REGEX = /\s{2,}/;
65
+ function normalizeCell(value) {
66
+ return (value ?? "").trim().replace(/\s+/g, " ");
67
+ }
68
+ function buildAssociationKey(type, resource) {
69
+ return `${normalizeCell(type).toLowerCase()}\x00${normalizeCell(resource).toLowerCase()}`;
70
+ }
71
+ function uniqueStrings(values) {
72
+ return Array.from(new Set(values.filter((value) => value.trim().length > 0)));
73
+ }
74
+ function formatSendEmailResource(entry) {
75
+ const destination = entry.destination_address?.trim();
76
+ if (destination) {
77
+ return destination;
78
+ }
79
+ const destinations = uniqueStrings(entry.allowed_destination_addresses ?? []);
80
+ const senders = uniqueStrings(entry.allowed_sender_addresses ?? []);
81
+ const destinationLabel = destinations.length > 0 ? destinations.join(", ") : "configured destinations";
82
+ if (senders.length === 0) {
83
+ return destinationLabel;
84
+ }
85
+ return `${destinationLabel} - senders: ${senders.join(", ")}`;
86
+ }
87
+ function addAssociationTarget(targets, input) {
88
+ const type = normalizeCell(input.type);
89
+ const resource = normalizeCell(input.resource);
90
+ const key = buildAssociationKey(type, resource);
91
+ const existing = targets.get(key);
92
+ if (existing) {
93
+ if (input.reference) {
94
+ existing.referenceLabels = uniqueStrings([...existing.referenceLabels, input.reference]);
95
+ }
96
+ if (input.note) {
97
+ existing.notes = uniqueStrings([...existing.notes, input.note]);
98
+ }
99
+ if (!existing.queueName && input.queueName) {
100
+ existing.queueName = input.queueName;
101
+ }
102
+ return;
103
+ }
104
+ targets.set(key, {
105
+ key,
106
+ referenceLabels: input.reference ? [input.reference] : [],
107
+ type,
108
+ resource,
109
+ notes: input.note ? [input.note] : [],
110
+ queueName: input.queueName
111
+ });
112
+ }
113
+ function collectBindingAssociationTargets(config) {
114
+ const compiled = compileConfig(config);
115
+ const targets = new Map;
116
+ for (const binding of compiled.kv_namespaces ?? []) {
117
+ addAssociationTarget(targets, {
118
+ reference: binding.binding,
119
+ type: "KV Namespace",
120
+ resource: binding.id
121
+ });
122
+ }
123
+ for (const binding of compiled.d1_databases ?? []) {
124
+ addAssociationTarget(targets, {
125
+ reference: binding.binding,
126
+ type: "D1 Database",
127
+ resource: binding.database_id
128
+ });
129
+ }
130
+ for (const binding of compiled.r2_buckets ?? []) {
131
+ addAssociationTarget(targets, {
132
+ reference: binding.binding,
133
+ type: "R2 Bucket",
134
+ resource: binding.bucket_name
135
+ });
136
+ }
137
+ for (const binding of compiled.durable_objects?.bindings ?? []) {
138
+ addAssociationTarget(targets, {
139
+ reference: binding.name,
140
+ type: "Durable Object Namespace",
141
+ resource: binding.class_name,
142
+ note: binding.script_name ? `script ${binding.script_name}` : undefined
143
+ });
144
+ }
145
+ for (const binding of compiled.queues?.producers ?? []) {
146
+ addAssociationTarget(targets, {
147
+ reference: binding.binding,
148
+ type: "Queue",
149
+ resource: binding.queue,
150
+ note: "producer binding",
151
+ queueName: binding.queue
152
+ });
153
+ }
154
+ for (const binding of compiled.queues?.consumers ?? []) {
155
+ addAssociationTarget(targets, {
156
+ type: "Queue",
157
+ resource: binding.queue,
158
+ note: "consumer attachment",
159
+ queueName: binding.queue
160
+ });
161
+ if (binding.dead_letter_queue) {
162
+ addAssociationTarget(targets, {
163
+ type: "Queue",
164
+ resource: binding.dead_letter_queue,
165
+ note: "dead letter queue",
166
+ queueName: binding.dead_letter_queue
167
+ });
168
+ }
169
+ }
170
+ for (const binding of compiled.services ?? []) {
171
+ addAssociationTarget(targets, {
172
+ reference: binding.binding,
173
+ type: "Worker",
174
+ resource: binding.entrypoint ? `${binding.service}#${binding.entrypoint}` : binding.service,
175
+ note: binding.environment ? `env ${binding.environment}` : undefined
176
+ });
177
+ }
178
+ if (compiled.ai?.binding) {
179
+ addAssociationTarget(targets, {
180
+ reference: compiled.ai.binding,
181
+ type: "AI",
182
+ resource: "Workers AI"
183
+ });
184
+ }
185
+ for (const binding of compiled.vectorize ?? []) {
186
+ addAssociationTarget(targets, {
187
+ reference: binding.binding,
188
+ type: "Vectorize",
189
+ resource: binding.index_name
190
+ });
191
+ }
192
+ for (const binding of compiled.hyperdrive ?? []) {
193
+ addAssociationTarget(targets, {
194
+ reference: binding.binding,
195
+ type: "Hyperdrive",
196
+ resource: binding.id
197
+ });
198
+ }
199
+ if (compiled.browser?.binding) {
200
+ addAssociationTarget(targets, {
201
+ reference: compiled.browser.binding,
202
+ type: "Browser",
203
+ resource: "Browser Rendering"
204
+ });
205
+ }
206
+ for (const binding of compiled.analytics_engine_datasets ?? []) {
207
+ addAssociationTarget(targets, {
208
+ reference: binding.binding,
209
+ type: "Analytics Engine",
210
+ resource: binding.dataset
211
+ });
212
+ }
213
+ for (const binding of compiled.send_email ?? []) {
214
+ addAssociationTarget(targets, {
215
+ reference: binding.name,
216
+ type: "Send Email",
217
+ resource: formatSendEmailResource(binding)
218
+ });
219
+ }
220
+ return Array.from(targets.values());
221
+ }
222
+ function getActiveVersionId(deployments) {
223
+ const sortedDeployments = [...deployments].sort((left, right) => right.createdOn.getTime() - left.createdOn.getTime());
224
+ for (const deployment of sortedDeployments) {
225
+ const version = [...deployment.versions].sort((left, right) => right.percentage - left.percentage)[0];
226
+ if (version?.versionId) {
227
+ return version.versionId;
228
+ }
229
+ }
230
+ return;
231
+ }
232
+ function extractWorkerNames(value) {
233
+ return Array.from(value.matchAll(/worker:([^,\s]+)/gi), (match) => match[1]);
234
+ }
235
+ function parseWranglerQueueInfo(output) {
236
+ const lines = output.split(/\r?\n/);
237
+ let queueName = "";
238
+ const producerWorkers = [];
239
+ const consumerWorkers = [];
240
+ let currentSection = null;
241
+ for (const rawLine of lines) {
242
+ const trimmed = rawLine.trim();
243
+ if (!trimmed) {
244
+ currentSection = null;
245
+ continue;
246
+ }
247
+ const queueMatch = trimmed.match(/^Queue Name:\s*(.+)$/i);
248
+ if (queueMatch) {
249
+ queueName = normalizeCell(queueMatch[1]);
250
+ currentSection = null;
251
+ continue;
252
+ }
253
+ const producerMatch = trimmed.match(/^Producers:\s*(.*)$/i);
254
+ if (producerMatch) {
255
+ producerWorkers.push(...extractWorkerNames(producerMatch[1]));
256
+ currentSection = producerMatch[1] ? null : "producers";
257
+ continue;
258
+ }
259
+ const consumerMatch = trimmed.match(/^Consumers:\s*(.*)$/i);
260
+ if (consumerMatch) {
261
+ consumerWorkers.push(...extractWorkerNames(consumerMatch[1]));
262
+ currentSection = consumerMatch[1] ? null : "consumers";
263
+ continue;
264
+ }
265
+ if (!currentSection) {
266
+ continue;
267
+ }
268
+ const extractedWorkers = extractWorkerNames(trimmed);
269
+ if (currentSection === "producers") {
270
+ producerWorkers.push(...extractedWorkers);
271
+ } else {
272
+ consumerWorkers.push(...extractedWorkers);
273
+ }
274
+ }
275
+ if (!queueName) {
276
+ return null;
277
+ }
278
+ return {
279
+ queueName,
280
+ producerWorkers: uniqueStrings(producerWorkers),
281
+ consumerWorkers: uniqueStrings(consumerWorkers)
282
+ };
283
+ }
284
+ function parseWranglerVersionBindings(output) {
285
+ const lines = output.split(/\r?\n/);
286
+ const bindings = [];
287
+ let inBindingTable = false;
288
+ for (const rawLine of lines) {
289
+ const trimmed = rawLine.trim();
290
+ if (!trimmed) {
291
+ continue;
292
+ }
293
+ if (/^(binding\s+type|type)\s{2,}/i.test(rawLine) || /^(binding\s+type|type)$/i.test(trimmed)) {
294
+ inBindingTable = true;
295
+ continue;
296
+ }
297
+ if (!inBindingTable) {
298
+ continue;
299
+ }
300
+ if (/^-+$/.test(trimmed)) {
301
+ continue;
302
+ }
303
+ const segments = trimmed.split(WRANGLER_TEXT_COLUMNS_REGEX).filter(Boolean);
304
+ if (segments.length < 2) {
305
+ continue;
306
+ }
307
+ if (segments[0].endsWith(":")) {
308
+ break;
309
+ }
310
+ const [type, bindingName, ...resourceParts] = segments;
311
+ if (!type || !bindingName) {
312
+ continue;
313
+ }
314
+ bindings.push({
315
+ type: normalizeCell(type),
316
+ bindingName: normalizeCell(bindingName),
317
+ resource: normalizeCell(resourceParts.join(" "))
318
+ });
319
+ }
320
+ return bindings;
321
+ }
322
+ async function inspectWorkerBindings(exec, options) {
323
+ const output = await runWranglerInspectionCommand(exec, ["wrangler", "versions", "view", options.versionId, "--name", options.workerName], options, "Wrangler versions view failed");
324
+ return parseWranglerVersionBindings(output);
325
+ }
326
+ async function runWranglerInspectionCommand(exec, args, options, failureMessage) {
327
+ const result = await exec.exec("bunx", args, {
328
+ cwd: options.cwd,
329
+ env: {
330
+ ...process.env,
331
+ CLOUDFLARE_ACCOUNT_ID: options.accountId,
332
+ FORCE_COLOR: process.env.FORCE_COLOR ?? "0"
333
+ }
334
+ });
335
+ if (result.exitCode !== 0) {
336
+ throw new Error(result.stderr || result.stdout || failureMessage);
337
+ }
338
+ return `${result.stdout}
339
+ ${result.stderr}`;
340
+ }
341
+ async function inspectQueueAssociation(exec, options) {
342
+ const output = await runWranglerInspectionCommand(exec, ["wrangler", "queues", "info", options.queueName], options, "Wrangler queues info failed");
343
+ return parseWranglerQueueInfo(output);
344
+ }
345
+ function formatReference(target) {
346
+ return target.referenceLabels.length > 0 ? target.referenceLabels.join(", ") : "—";
347
+ }
348
+ function formatResource(target) {
349
+ return target.resource || "—";
350
+ }
351
+ function buildRowNotes(target, queueAssociation) {
352
+ const notes = [...target.notes];
353
+ if (queueAssociation) {
354
+ notes.push(`producers ${queueAssociation.producerWorkers.length}`);
355
+ notes.push(`consumers ${queueAssociation.consumerWorkers.length}`);
356
+ }
357
+ return uniqueStrings(notes);
358
+ }
359
+ async function inspectBindingAssociations(options) {
360
+ const targets = collectBindingAssociationTargets(options.config);
361
+ const warnings = [];
362
+ const bindingUsage = new Map;
363
+ const scannedWorkers = [];
364
+ const queueTargets = uniqueStrings(targets.map((target) => target.queueName).filter((queueName) => typeof queueName === "string" && queueName.length > 0));
365
+ const queueAssociations = new Map;
366
+ const workers = await account.workers(options.accountId, options.apiOptions);
367
+ for (const worker of workers) {
368
+ let versionId;
369
+ try {
370
+ const deployments = await account.workerDeployments(options.accountId, worker.name, options.apiOptions);
371
+ versionId = getActiveVersionId(deployments);
372
+ } catch (error) {
373
+ const message = error instanceof Error ? error.message : String(error);
374
+ warnings.push(`Could not resolve active deployment for ${worker.name}: ${message}`);
375
+ continue;
376
+ }
377
+ if (!versionId) {
378
+ continue;
379
+ }
380
+ scannedWorkers.push(worker.name);
381
+ try {
382
+ const bindings = await inspectWorkerBindings(options.exec, {
383
+ accountId: options.accountId,
384
+ workerName: worker.name,
385
+ versionId,
386
+ cwd: options.cwd
387
+ });
388
+ for (const binding of bindings) {
389
+ const key = buildAssociationKey(binding.type, binding.resource);
390
+ const connectedWorkers = bindingUsage.get(key) ?? new Set;
391
+ connectedWorkers.add(worker.name);
392
+ bindingUsage.set(key, connectedWorkers);
393
+ }
394
+ } catch (error) {
395
+ const message = error instanceof Error ? error.message : String(error);
396
+ warnings.push(`Could not inspect bindings for ${worker.name}: ${message}`);
397
+ }
398
+ }
399
+ for (const queueName of queueTargets) {
400
+ try {
401
+ const queueAssociation = await inspectQueueAssociation(options.exec, {
402
+ accountId: options.accountId,
403
+ queueName,
404
+ cwd: options.cwd
405
+ });
406
+ if (queueAssociation) {
407
+ queueAssociations.set(queueName, queueAssociation);
408
+ }
409
+ } catch (error) {
410
+ const message = error instanceof Error ? error.message : String(error);
411
+ warnings.push(`Could not inspect queue ${queueName}: ${message}`);
412
+ }
413
+ }
414
+ const rows = targets.map((target) => {
415
+ const queueAssociation = target.queueName ? queueAssociations.get(target.queueName) : undefined;
416
+ const directlyConnectedWorkers = Array.from(bindingUsage.get(target.key) ?? []);
417
+ const connectedWorkers = uniqueStrings([
418
+ ...directlyConnectedWorkers,
419
+ ...queueAssociation?.producerWorkers ?? [],
420
+ ...queueAssociation?.consumerWorkers ?? []
421
+ ]).sort((left, right) => left.localeCompare(right));
422
+ return {
423
+ reference: formatReference(target),
424
+ type: target.type,
425
+ resource: formatResource(target),
426
+ workerCount: connectedWorkers.length,
427
+ connectedWorkers,
428
+ notes: buildRowNotes(target, queueAssociation),
429
+ producerWorkers: queueAssociation?.producerWorkers,
430
+ consumerWorkers: queueAssociation?.consumerWorkers
431
+ };
432
+ });
433
+ return {
434
+ workerName: options.workerName ?? options.config.name,
435
+ rows,
436
+ targets: targets.length,
437
+ scannedWorkers,
438
+ warnings
439
+ };
440
+ }
441
+
442
+ // src/cli/commands/previews-support/cleanup.ts
443
+ function comparePreviewCleanupScopeNames(left, right) {
444
+ if (left === "preview" && right !== "preview") {
445
+ return 1;
446
+ }
447
+ if (left !== "preview" && right === "preview") {
448
+ return -1;
449
+ }
450
+ return left.localeCompare(right);
451
+ }
452
+ function buildPreviewCleanupTarget(scope, scopeRows, workerCandidatesByScope, environment) {
453
+ const strategies = new Set;
454
+ const workerNames = [...workerCandidatesByScope.get(scope) ?? []];
455
+ for (const row of scopeRows) {
456
+ if (row.scope === scope) {
457
+ strategies.add(row.strategy);
458
+ }
459
+ }
460
+ if (workerNames.length > 0) {
461
+ strategies.add("dedicated workers");
462
+ }
463
+ if (scope === "preview" && environment === "preview") {
464
+ strategies.add("default preview scope");
465
+ }
466
+ return {
467
+ scope,
468
+ strategies: Array.from(strategies),
469
+ workerNames
470
+ };
471
+ }
472
+ function buildPreviewCleanupTargets(scopeRows, workerCandidatesByScope, environment) {
473
+ const scopeNames = new Set;
474
+ for (const row of scopeRows) {
475
+ scopeNames.add(row.scope);
476
+ }
477
+ for (const scope of workerCandidatesByScope.keys()) {
478
+ scopeNames.add(scope);
479
+ }
480
+ if (environment === "preview") {
481
+ scopeNames.add("preview");
482
+ }
483
+ return Array.from(scopeNames).sort(comparePreviewCleanupScopeNames).map((scope) => buildPreviewCleanupTarget(scope, scopeRows, workerCandidatesByScope, environment));
484
+ }
485
+ function getPreviewCleanupResourceCandidateCount(result) {
486
+ return result.candidates.kv.length + result.candidates.d1.length + result.candidates.r2.length + result.candidates.queues.length + result.candidates.vectorize.length + result.candidates.hyperdrive.length;
487
+ }
488
+ function buildPreviewCleanupResourceSummary(result) {
489
+ return [
490
+ result.candidates.kv.length > 0 ? `KV ${result.candidates.kv.length}` : null,
491
+ result.candidates.d1.length > 0 ? `D1 ${result.candidates.d1.length}` : null,
492
+ result.candidates.r2.length > 0 ? `R2 ${result.candidates.r2.length}` : null,
493
+ result.candidates.queues.length > 0 ? `Queues ${result.candidates.queues.length}` : null,
494
+ result.candidates.vectorize.length > 0 ? `Vectorize ${result.candidates.vectorize.length}` : null,
495
+ result.candidates.hyperdrive.length > 0 ? `Hyperdrive ${result.candidates.hyperdrive.length}` : null
496
+ ].filter((segment) => segment !== null);
497
+ }
498
+ function logResolvedPreviewScopes(logger, targets, theme) {
499
+ if (targets.length === 0) {
500
+ logLine(logger, `${dim("preview scopes", theme)} ${dim("none discovered (--all)", theme)}`);
501
+ logLine(logger);
502
+ return;
503
+ }
504
+ logLine(logger, `${dim("preview scopes", theme)} ${green(targets.map((target) => target.scope).join(", "), theme)} ${dim("(--all)", theme)}`);
505
+ logLine(logger);
506
+ }
507
+ function logPreviewCleanupScopeBreakdown(logger, executions, theme) {
508
+ const scopedExecutions = executions.filter((execution) => execution.target);
509
+ if (scopedExecutions.length === 0) {
510
+ return;
511
+ }
512
+ logLine(logger, `${dim("scope breakdown", theme)}`);
513
+ for (const execution of scopedExecutions) {
514
+ const target = execution.target;
515
+ const strategies = target.strategies.length > 0 ? dim(`(${target.strategies.join(" + ")})`, theme) : "";
516
+ const summary = [
517
+ target.workerNames.length > 0 ? `Workers ${target.workerNames.length}` : null,
518
+ ...buildPreviewCleanupResourceSummary(execution.result)
519
+ ].filter((segment) => segment !== null);
520
+ logLine(logger, ` ${green(target.scope, theme)} ${strategies} ${dim("—", theme)} ${summary.length > 0 ? summary.join(" · ") : dim("none", theme)}`);
521
+ }
522
+ logLine(logger);
523
+ }
524
+ async function retireDeletedPreviewWorkers(accountId, databaseName, scope, workerNames) {
525
+ const registry = await account.getPreviewRegistryContext({
526
+ accountId,
527
+ databaseName,
528
+ apiOptions: { timeout: 1e4 },
529
+ skipContextCache: true
530
+ });
531
+ if (!registry) {
532
+ return;
533
+ }
534
+ for (const workerName of workerNames) {
535
+ await retirePreviewRegistry({
536
+ accountId,
537
+ workerName,
538
+ databaseName,
539
+ apiOptions: { timeout: 1e4 },
540
+ branchName: scope,
541
+ previewAlias: scope,
542
+ apply: true
543
+ });
544
+ }
545
+ }
546
+ function showNoPreviewCleanupCandidatesHint(logger, selection, includeAll, theme) {
547
+ if (includeAll) {
548
+ logger.warn("No preview-only resources or dedicated preview Worker scripts were discovered across the resolved preview scopes. This usually means those previews were already cleaned up or the remaining previews only share stable Workers and shared account resources.");
549
+ return;
550
+ }
551
+ if (!selection?.identifier) {
552
+ return;
553
+ }
554
+ if (selection.source === "environment") {
555
+ logger.warn(`No preview-only resources or dedicated preview Worker scripts matched the default "${selection.identifier}" scope. If your previews use branch-style scopes such as "next" or "pr-1", rerun with --scope <name>, use --all, or set DEVFLARE_PREVIEW_BRANCH, DEVFLARE_PREVIEW_PR, or DEVFLARE_PREVIEW_IDENTIFIER.`);
556
+ return;
557
+ }
558
+ logger.warn(`No preview-only resources or dedicated preview Worker scripts matched the resolved "${selection.identifier}" scope. This usually means that scope was already cleaned up or the preview shares stable Workers without preview.scope() resources of its own.`);
559
+ }
560
+
561
+ // src/cli/commands/previews-support/render.ts
562
+ function logWorkerFamilyHeader(logger, families, theme) {
563
+ const primaryFamily = families.find((family) => family.role === "primary") ?? families[0];
564
+ const relatedFamilies = families.filter((family) => family.role !== "primary");
565
+ logLine(logger, `${dim("worker family", theme)} ${green(primaryFamily?.baseName ?? "unknown", theme)}`);
566
+ if (relatedFamilies.length > 0) {
567
+ logLine(logger, `${dim("related workers", theme)} ${whiteDim(String(relatedFamilies.length), theme)}`);
568
+ }
569
+ logLine(logger);
570
+ }
571
+ function logSection(logger, title, records, columns, theme) {
572
+ for (const line of buildSectionLines(title, records, columns, theme)) {
573
+ logLine(logger, line);
574
+ }
575
+ }
576
+ function logLiveWorkerFamilyOverview(logger, families, workers, workersSubdomain, theme) {
577
+ const stableRows = buildStableWorkerRowsFromLiveWorkers(families, workers, workersSubdomain);
578
+ const previewScopeRows = buildPreviewScopeRowsFromLiveWorkers(families, workers, workersSubdomain);
579
+ logWorkerFamilyHeader(logger, families, theme);
580
+ logSection(logger, "Stable workers", stableRows, buildStableWorkerColumns(theme), theme);
581
+ logLine(logger);
582
+ if (previewScopeRows.length === 0) {
583
+ logLine(logger, dim("No dedicated preview scopes found for this worker family.", theme));
584
+ } else {
585
+ logSection(logger, "Preview scopes", previewScopeRows, buildPreviewScopeColumns(theme), theme);
586
+ }
587
+ }
588
+ function buildStableWorkerColumns(theme) {
589
+ return [
590
+ {
591
+ label: "Worker",
592
+ width: 34,
593
+ value: (row) => row.workerName
594
+ },
595
+ {
596
+ label: "Role",
597
+ width: 20,
598
+ value: (row) => row.role
599
+ },
600
+ {
601
+ label: "Status",
602
+ width: 8,
603
+ value: (row) => formatOverviewStatus(row.status, theme)
604
+ },
605
+ {
606
+ label: "Updated",
607
+ width: 19,
608
+ value: (row) => whiteDim(formatRecordDate(row.updatedAt), theme)
609
+ },
610
+ {
611
+ label: "URL",
612
+ value: (row) => row.url ?? "N/A"
613
+ }
614
+ ];
615
+ }
616
+ function buildPreviewScopeColumns(theme) {
617
+ return [
618
+ {
619
+ label: "Scope",
620
+ width: 18,
621
+ value: (row) => row.scope
622
+ },
623
+ {
624
+ label: "Strategy",
625
+ width: 18,
626
+ value: (row) => row.strategy
627
+ },
628
+ {
629
+ label: "Workers",
630
+ width: 7,
631
+ value: (row) => row.workersLabel
632
+ },
633
+ {
634
+ label: "Status",
635
+ width: 10,
636
+ value: (row) => formatOverviewStatus(row.status, theme)
637
+ },
638
+ {
639
+ label: "Updated",
640
+ width: 19,
641
+ value: (row) => whiteDim(formatRecordDate(row.updatedAt), theme)
642
+ },
643
+ {
644
+ label: "Notes",
645
+ width: 30,
646
+ value: (row) => row.notes ?? dim("—", theme)
647
+ },
648
+ {
649
+ label: "Entry URL",
650
+ value: (row) => row.entryUrl ?? "N/A"
651
+ }
652
+ ];
653
+ }
654
+ function buildSectionLines(title, records, columns, theme) {
655
+ if (records.length === 0) {
656
+ return [];
657
+ }
658
+ const widths = columns.map((column) => column.width);
659
+ const coloredTitle = title === "Previews" || title === "Preview scopes" ? cyanBold(title, theme) : title === "Aliases" || title === "Stable workers" ? bold(title, theme) : yellowBold(title, theme);
660
+ return [
661
+ `${coloredTitle} ${dim(`(${records.length})`, theme)}`,
662
+ formatTableLine(columns.map((column) => dim(column.label, theme)), widths),
663
+ ...records.map((record) => formatTableLine(columns.map((column) => column.value(record)), widths))
664
+ ];
665
+ }
666
+ function showWorkerFamilyOverviewFromLiveWorkers(families, workers, workersSubdomain, logger, theme) {
667
+ logLine(logger);
668
+ logLiveWorkerFamilyOverview(logger, families, workers, workersSubdomain, theme);
669
+ logLine(logger);
670
+ logLine(logger, dim("Preview scopes are derived from live worker names and the current config family.", theme));
671
+ logLine(logger, dim("Use `devflare previews cleanup --scope <name>` to delete one scope or `--all` to clean every discovered scope.", theme));
672
+ logLine(logger);
673
+ }
674
+ function showWorkspaceWorkerFamilyOverviewFromLiveWorkers(familyGroups, workers, workersSubdomain, logger, theme) {
675
+ logLine(logger);
676
+ logLine(logger, `${dim("configured worker families", theme)} ${whiteDim(String(familyGroups.length), theme)}`);
677
+ logLine(logger);
678
+ for (const [index, families] of familyGroups.entries()) {
679
+ if (index > 0) {
680
+ logLine(logger);
681
+ }
682
+ logLiveWorkerFamilyOverview(logger, families, workers, workersSubdomain, theme);
683
+ }
684
+ logLine(logger);
685
+ logLine(logger, dim("Preview scopes are derived from live worker names and each discovered config family.", theme));
686
+ logLine(logger, dim("Run inside a configured package or pass `--config <path>` to narrow the summary or clean one family.", theme));
687
+ logLine(logger);
688
+ }
689
+ function buildBindingAssociationColumns(theme) {
690
+ return [
691
+ {
692
+ label: "Reference",
693
+ width: 24,
694
+ value: (row) => row.reference
695
+ },
696
+ {
697
+ label: "Type",
698
+ width: 24,
699
+ value: (row) => row.type
700
+ },
701
+ {
702
+ label: "Resource",
703
+ width: 36,
704
+ value: (row) => row.resource
705
+ },
706
+ {
707
+ label: "Workers",
708
+ width: 7,
709
+ value: (row) => String(row.workerCount)
710
+ },
711
+ {
712
+ label: "Notes",
713
+ width: 28,
714
+ value: (row) => row.notes.length > 0 ? row.notes.join(" · ") : dim("—", theme)
715
+ },
716
+ {
717
+ label: "Connected workers",
718
+ value: (row) => row.connectedWorkers.length > 0 ? row.connectedWorkers.join(", ") : dim("—", theme)
719
+ }
720
+ ];
721
+ }
722
+ function showBindingAssociations(logger, inspection, theme) {
723
+ logLine(logger);
724
+ logLine(logger, `${dim("worker family", theme)} ${green(inspection.workerName, theme)}`);
725
+ logLine(logger, `${dim("resolved targets", theme)} ${whiteDim(String(inspection.targets), theme)}`);
726
+ logLine(logger, `${dim("active deployments scanned", theme)} ${whiteDim(String(inspection.scannedWorkers.length), theme)}`);
727
+ if (inspection.rows.length === 0) {
728
+ logLine(logger);
729
+ logLine(logger, dim("No binding or resource targets were resolved from the current config.", theme));
730
+ logLine(logger);
731
+ return;
732
+ }
733
+ logLine(logger);
734
+ logSection(logger, "Bindings", inspection.rows, buildBindingAssociationColumns(theme), theme);
735
+ if (inspection.warnings.length > 0) {
736
+ logLine(logger);
737
+ for (const warning of inspection.warnings) {
738
+ logger.warn(warning);
739
+ }
740
+ }
741
+ logLine(logger);
742
+ }
743
+
744
+ // src/cli/commands/previews-support/types.ts
745
+ var PREVIEW_SUBCOMMANDS = ["list", "bindings", "cleanup"];
746
+
747
+ // src/cli/commands/previews.ts
748
+ var CLI_API_OPTIONS = {
749
+ timeout: 1e4
750
+ };
751
+ function compareConfiguredWorkerFamilies(left, right) {
752
+ if (left.role === "primary" && right.role !== "primary") {
753
+ return -1;
754
+ }
755
+ if (left.role !== "primary" && right.role === "primary") {
756
+ return 1;
757
+ }
758
+ return left.baseName.localeCompare(right.baseName);
759
+ }
760
+ function sortConfiguredWorkerFamilies(families) {
761
+ return [...families].sort(compareConfiguredWorkerFamilies);
762
+ }
763
+ function resolvePrimaryWorkerFamilyName(families) {
764
+ return families.find((family) => family.role === "primary")?.baseName ?? families[0]?.baseName;
765
+ }
766
+ function shouldReplaceConfiguredWorkerFamily(existing, candidate) {
767
+ return !existing || candidate.role === "primary" && existing.role !== "primary";
768
+ }
769
+ function mergeConfiguredWorkerFamilies(existing, candidates) {
770
+ const merged = new Map(existing.map((family) => [family.baseName, family]));
771
+ for (const candidate of candidates) {
772
+ if (shouldReplaceConfiguredWorkerFamily(merged.get(candidate.baseName), candidate)) {
773
+ merged.set(candidate.baseName, candidate);
774
+ }
775
+ }
776
+ return sortConfiguredWorkerFamilies(Array.from(merged.values()));
777
+ }
778
+ function comparePreviewConfiguredFamilyGroups(left, right) {
779
+ const leftName = resolvePrimaryWorkerFamilyName(left.families) ?? left.configPath ?? "";
780
+ const rightName = resolvePrimaryWorkerFamilyName(right.families) ?? right.configPath ?? "";
781
+ return leftName.localeCompare(rightName);
782
+ }
783
+ function upsertPreviewConfiguredFamilyGroup(groups, candidate) {
784
+ const primaryFamilyName = resolvePrimaryWorkerFamilyName(candidate.families);
785
+ const groupKey = primaryFamilyName ?? candidate.configPath ?? `group-${groups.size}`;
786
+ const existing = groups.get(groupKey);
787
+ if (!existing) {
788
+ groups.set(groupKey, {
789
+ ...candidate,
790
+ families: sortConfiguredWorkerFamilies(candidate.families)
791
+ });
792
+ return;
793
+ }
794
+ groups.set(groupKey, {
795
+ accountId: existing.accountId ?? candidate.accountId,
796
+ configPath: existing.configPath ?? candidate.configPath,
797
+ families: mergeConfiguredWorkerFamilies(existing.families, candidate.families)
798
+ });
799
+ }
800
+ async function discoverPreviewListConfigs(cwd, configFile, environment) {
801
+ const groups = new Map;
802
+ const accountIds = new Set;
803
+ const loadAndCollect = async (candidateConfigFile) => {
804
+ try {
805
+ const config = await loadConfig({ cwd, configFile: candidateConfigFile });
806
+ const families = collectConfiguredWorkerFamilies(config, environment);
807
+ const accountId = config.accountId?.trim() || undefined;
808
+ if (accountId) {
809
+ accountIds.add(accountId);
810
+ }
811
+ upsertPreviewConfiguredFamilyGroup(groups, {
812
+ accountId,
813
+ configPath: candidateConfigFile,
814
+ families
815
+ });
816
+ return true;
817
+ } catch (error) {
818
+ if (error instanceof ConfigNotFoundError) {
819
+ return false;
820
+ }
821
+ throw error;
822
+ }
823
+ };
824
+ if (configFile) {
825
+ await loadAndCollect(configFile);
826
+ } else {
827
+ const directConfigPath = await resolveConfigPath(cwd);
828
+ const loadedDirectly = directConfigPath ? await loadAndCollect() : false;
829
+ if (!loadedDirectly) {
830
+ const configPaths = await findConfigPathsUnderDirectory(cwd);
831
+ for (const configPath of configPaths) {
832
+ await loadAndCollect(configPath);
833
+ }
834
+ }
835
+ }
836
+ return {
837
+ accountIds: Array.from(accountIds).sort((left, right) => left.localeCompare(right)),
838
+ familyGroups: Array.from(groups.values()).sort(comparePreviewConfiguredFamilyGroups)
839
+ };
840
+ }
841
+ function isPreviewSubcommand(value) {
842
+ return PREVIEW_SUBCOMMANDS.includes(value);
843
+ }
844
+ function resolvePreviewScopeSelection(parsed, environment) {
845
+ const explicitScope = asOptionalString(parsed.options.scope) || asOptionalString(parsed.options.identifier);
846
+ if (explicitScope) {
847
+ return {
848
+ identifier: resolvePreviewIdentifier({ identifier: explicitScope }).identifier,
849
+ source: "scope-option"
850
+ };
851
+ }
852
+ const resolved = resolvePreviewIdentifier({
853
+ environment,
854
+ env: process.env
855
+ });
856
+ return {
857
+ identifier: resolved.identifier,
858
+ source: resolved.source
859
+ };
860
+ }
861
+ function formatPreviewScopeSource(source) {
862
+ switch (source) {
863
+ case "scope-option":
864
+ return "--scope";
865
+ case "identifier":
866
+ return "explicit identifier";
867
+ case "env-identifier":
868
+ return "DEVFLARE_PREVIEW_IDENTIFIER";
869
+ case "env-pr":
870
+ return "DEVFLARE_PREVIEW_PR";
871
+ case "env-branch":
872
+ return "DEVFLARE_PREVIEW_BRANCH";
873
+ case "environment":
874
+ return "default preview scope";
875
+ default:
876
+ return "no explicit preview scope";
877
+ }
878
+ }
879
+ function logResolvedPreviewScope(logger, selection, theme) {
880
+ if (!selection.identifier) {
881
+ return;
882
+ }
883
+ logLine(logger, `${dim("preview scope", theme)} ${green(selection.identifier, theme)} ${dim(`(${formatPreviewScopeSource(selection.source)})`, theme)}`);
884
+ logLine(logger);
885
+ }
886
+ async function loadLocalConfig(cwd, configFile, needsConfig) {
887
+ if (!needsConfig) {
888
+ return;
889
+ }
890
+ if (!configFile) {
891
+ const resolvedConfigPath = await resolveConfigPath(cwd);
892
+ if (!resolvedConfigPath) {
893
+ return;
894
+ }
895
+ try {
896
+ const config = await loadConfig({
897
+ cwd
898
+ });
899
+ return {
900
+ accountId: config.accountId,
901
+ name: config.name
902
+ };
903
+ } catch (error) {
904
+ if (error instanceof ConfigNotFoundError) {
905
+ return;
906
+ }
907
+ throw error;
908
+ }
909
+ }
910
+ try {
911
+ const config = await loadConfig({
912
+ cwd,
913
+ configFile
914
+ });
915
+ return {
916
+ accountId: config.accountId,
917
+ name: config.name
918
+ };
919
+ } catch (error) {
920
+ if (error instanceof ConfigNotFoundError) {
921
+ return;
922
+ }
923
+ throw error;
924
+ }
925
+ }
926
+ async function resolveAccountId(parsed, config) {
927
+ return resolveCloudflareAccountId({
928
+ explicitAccountId: asOptionalString(parsed.options.account),
929
+ configuredAccountId: config?.accountId,
930
+ apiOptions: CLI_API_OPTIONS
931
+ });
932
+ }
933
+ function resolveWorkerName(parsed, config) {
934
+ const selection = resolveNamedSelection({
935
+ explicitValue: asOptionalString(parsed.options.worker),
936
+ configuredValue: config?.name
937
+ });
938
+ return {
939
+ workerName: selection.value,
940
+ source: selection.source
941
+ };
942
+ }
943
+ async function resolveContext(parsed, options, subcommand) {
944
+ const cwd = options.cwd ?? process.cwd();
945
+ const configFile = asOptionalString(parsed.options.config);
946
+ const explicitAccountId = asOptionalString(parsed.options.account);
947
+ const environment = asOptionalString(parsed.options.env);
948
+ if (subcommand === "list") {
949
+ const listDiscovery = await discoverPreviewListConfigs(cwd, configFile, environment);
950
+ if (!explicitAccountId && listDiscovery.accountIds.length > 1) {
951
+ throw new Error("Multiple Cloudflare account ids were discovered across local Devflare configs. Pass --account to select one account explicitly for `devflare previews`.");
952
+ }
953
+ const accountId2 = await resolveCloudflareAccountId({
954
+ explicitAccountId,
955
+ configuredAccountId: listDiscovery.accountIds[0],
956
+ apiOptions: CLI_API_OPTIONS
957
+ });
958
+ if (!accountId2) {
959
+ throw new Error("No Cloudflare account could be resolved. Use --account or configure accountId in devflare.config.*.");
960
+ }
961
+ return {
962
+ accountId: accountId2,
963
+ workerName: undefined,
964
+ workerNameSource: "none",
965
+ config: undefined,
966
+ listDiscovery
967
+ };
968
+ }
969
+ const needsConfig = subcommand === "cleanup" || subcommand === "bindings" || !explicitAccountId;
970
+ const config = await loadLocalConfig(cwd, configFile, needsConfig);
971
+ if (needsConfig && !config) {
972
+ throw new Error("Preview commands now inspect and clean dedicated preview workers for the current package. Run inside a configured package or pass --config <path>.");
973
+ }
974
+ const accountId = await resolveAccountId(parsed, config);
975
+ const workerSelection = resolveWorkerName(parsed, config);
976
+ if (!accountId) {
977
+ throw new Error("No Cloudflare account could be resolved. Use --account or configure accountId in devflare.config.*.");
978
+ }
979
+ return {
980
+ accountId,
981
+ workerName: workerSelection.workerName,
982
+ workerNameSource: workerSelection.source,
983
+ config
984
+ };
985
+ }
986
+ async function runBindingsSubcommand(parsed, context, logger, options, environment, configFile, theme) {
987
+ const cwd = options.cwd ?? process.cwd();
988
+ const previewScope = resolvePreviewScopeSelection(parsed, environment);
989
+ logResolvedPreviewScope(logger, previewScope, theme);
990
+ const resolvedConfig = await loadResolvedConfig({
991
+ cwd,
992
+ configFile,
993
+ environment,
994
+ identifier: previewScope.identifier,
995
+ accountId: context.accountId
996
+ });
997
+ const deps = await getDependencies();
998
+ const inspection = await inspectBindingAssociations({
999
+ accountId: context.accountId,
1000
+ config: resolvedConfig,
1001
+ workerName: context.workerName ?? resolvedConfig.name,
1002
+ cwd,
1003
+ exec: deps.exec,
1004
+ apiOptions: CLI_API_OPTIONS
1005
+ });
1006
+ showBindingAssociations(logger, inspection, theme);
1007
+ return { exitCode: 0 };
1008
+ }
1009
+ async function runCleanupSubcommand(parsed, context, logger, options, databaseName, environment, configFile, includeAll, theme) {
1010
+ const cwd = options.cwd ?? process.cwd();
1011
+ const resolvedEnvironment = environment ?? "preview";
1012
+ const explicitScope = asOptionalString(parsed.options.scope) || asOptionalString(parsed.options.identifier);
1013
+ if (includeAll && explicitScope) {
1014
+ logger.error("Choose either --scope <name> or --all for preview cleanup, not both.");
1015
+ return { exitCode: 1 };
1016
+ }
1017
+ const previewScope = resolvePreviewScopeSelection(parsed, resolvedEnvironment);
1018
+ const config = await loadConfig({ cwd, configFile });
1019
+ const configuredFamilies = collectConfiguredWorkerFamilies(config, resolvedEnvironment);
1020
+ const liveWorkers = await account.workers(context.accountId, CLI_API_OPTIONS);
1021
+ const workerCandidatesByScope = buildPreviewWorkerCandidatesByScope(configuredFamilies, liveWorkers);
1022
+ const trackedScopeRows = includeAll || previewScope.identifier ? await loadTrackedPreviewScopeRows(context.accountId, databaseName, configuredFamilies, CLI_API_OPTIONS) : [];
1023
+ const cleanupTargets = includeAll ? buildPreviewCleanupTargets(trackedScopeRows, workerCandidatesByScope, resolvedEnvironment) : previewScope.identifier ? [buildPreviewCleanupTarget(previewScope.identifier, trackedScopeRows, workerCandidatesByScope, resolvedEnvironment)] : [];
1024
+ const cleanupRuns = cleanupTargets.length > 0 ? cleanupTargets.map((target) => ({
1025
+ scope: target.scope,
1026
+ target
1027
+ })) : [{
1028
+ scope: previewScope.identifier,
1029
+ target: undefined
1030
+ }];
1031
+ const applyCleanup = parsed.options.apply === true;
1032
+ const executions = [];
1033
+ if (includeAll) {
1034
+ logResolvedPreviewScopes(logger, cleanupTargets, theme);
1035
+ } else {
1036
+ logResolvedPreviewScope(logger, previewScope, theme);
1037
+ }
1038
+ for (const cleanupRun of cleanupRuns) {
1039
+ if (applyCleanup) {
1040
+ const orderedWorkerNames = cleanupRun.target ? orderPreviewWorkerNamesForDeletion(cleanupRun.target.workerNames, cleanupRun.target.scope, configuredFamilies) : [];
1041
+ for (const workerName of orderedWorkerNames) {
1042
+ await account.deleteWorker(context.accountId, workerName, CLI_API_OPTIONS);
1043
+ }
1044
+ if (cleanupRun.target && orderedWorkerNames.length > 0) {
1045
+ await retireDeletedPreviewWorkers(context.accountId, databaseName, cleanupRun.target.scope, orderedWorkerNames);
1046
+ }
1047
+ }
1048
+ const result = await cleanupPreviewScopedResources(config, {
1049
+ environment: resolvedEnvironment,
1050
+ identifier: cleanupRun.scope,
1051
+ accountId: context.accountId,
1052
+ apply: applyCleanup
1053
+ });
1054
+ executions.push({
1055
+ target: cleanupRun.target,
1056
+ result
1057
+ });
1058
+ }
1059
+ const totalWorkerCandidates = executions.reduce((sum, execution) => {
1060
+ return sum + (execution.target?.workerNames.length ?? 0);
1061
+ }, 0);
1062
+ const totalKvCandidates = executions.reduce((sum, execution) => sum + execution.result.candidates.kv.length, 0);
1063
+ const totalD1Candidates = executions.reduce((sum, execution) => sum + execution.result.candidates.d1.length, 0);
1064
+ const totalR2Candidates = executions.reduce((sum, execution) => sum + execution.result.candidates.r2.length, 0);
1065
+ const totalQueueCandidates = executions.reduce((sum, execution) => sum + execution.result.candidates.queues.length, 0);
1066
+ const totalVectorizeCandidates = executions.reduce((sum, execution) => sum + execution.result.candidates.vectorize.length, 0);
1067
+ const totalHyperdriveCandidates = executions.reduce((sum, execution) => sum + execution.result.candidates.hyperdrive.length, 0);
1068
+ const totalResourceCandidates = executions.reduce((sum, execution) => {
1069
+ return sum + getPreviewCleanupResourceCandidateCount(execution.result);
1070
+ }, 0);
1071
+ const totalCandidates = totalWorkerCandidates + totalResourceCandidates;
1072
+ const scopeCountSuffix = includeAll || previewScope.identifier ? ` across ${cleanupRuns.length} preview scope${cleanupRuns.length === 1 ? "" : "s"}` : "";
1073
+ logger.success(applyCleanup ? `Deleted ${totalCandidates} preview-only cleanup candidate${totalCandidates === 1 ? "" : "s"}${scopeCountSuffix}` : `Preview cleanup dry run complete with ${totalCandidates} candidate${totalCandidates === 1 ? "" : "s"}${scopeCountSuffix}`);
1074
+ const resourceSummary = [
1075
+ totalWorkerCandidates > 0 ? `Workers ${totalWorkerCandidates}` : null,
1076
+ totalKvCandidates > 0 ? `KV ${totalKvCandidates}` : null,
1077
+ totalD1Candidates > 0 ? `D1 ${totalD1Candidates}` : null,
1078
+ totalR2Candidates > 0 ? `R2 ${totalR2Candidates}` : null,
1079
+ totalQueueCandidates > 0 ? `Queues ${totalQueueCandidates}` : null,
1080
+ totalVectorizeCandidates > 0 ? `Vectorize ${totalVectorizeCandidates}` : null,
1081
+ totalHyperdriveCandidates > 0 ? `Hyperdrive ${totalHyperdriveCandidates}` : null
1082
+ ].filter((segment) => segment !== null);
1083
+ if (resourceSummary.length > 0) {
1084
+ logger.info(`Candidates: ${resourceSummary.join(" · ")}`);
1085
+ } else {
1086
+ logger.info("Candidates: none");
1087
+ showNoPreviewCleanupCandidatesHint(logger, previewScope, includeAll, theme);
1088
+ }
1089
+ if (includeAll || executions.some((execution) => Boolean(execution.target?.workerNames.length))) {
1090
+ logPreviewCleanupScopeBreakdown(logger, executions, theme);
1091
+ }
1092
+ const warnings = Array.from(new Set(executions.flatMap((execution) => execution.result.warnings)));
1093
+ for (const warning of warnings) {
1094
+ logger.warn(warning);
1095
+ }
1096
+ return { exitCode: 0 };
1097
+ }
1098
+ async function runListSubcommand(context, logger, theme) {
1099
+ const discoveredFamilyGroups = context.listDiscovery?.familyGroups ?? [];
1100
+ if (discoveredFamilyGroups.length === 0) {
1101
+ throw new Error("Preview listing needs a resolvable devflare config in the current package or workspace so Devflare can identify worker families.");
1102
+ }
1103
+ const matchingFamilyGroups = discoveredFamilyGroups.filter((group) => {
1104
+ return !group.accountId || group.accountId === context.accountId;
1105
+ });
1106
+ if (matchingFamilyGroups.length === 0) {
1107
+ throw new Error(`No configured preview worker families matched Cloudflare account ${context.accountId}. Pass --account or --config <path> to narrow the selection.`);
1108
+ }
1109
+ const liveWorkers = await account.workers(context.accountId, CLI_API_OPTIONS);
1110
+ const workersSubdomain = await account.workersSubdomain(context.accountId, CLI_API_OPTIONS);
1111
+ if (matchingFamilyGroups.length === 1) {
1112
+ showWorkerFamilyOverviewFromLiveWorkers(matchingFamilyGroups[0].families, liveWorkers, workersSubdomain, logger, theme);
1113
+ return { exitCode: 0 };
1114
+ }
1115
+ showWorkspaceWorkerFamilyOverviewFromLiveWorkers(matchingFamilyGroups.map((group) => group.families), liveWorkers, workersSubdomain, logger, theme);
1116
+ return { exitCode: 0 };
1117
+ }
1118
+ function resolvePreviewSubcommand(rawSubcommand) {
1119
+ if (!rawSubcommand) {
1120
+ return;
1121
+ }
1122
+ if (isPreviewSubcommand(rawSubcommand)) {
1123
+ return rawSubcommand;
1124
+ }
1125
+ return;
1126
+ }
1127
+ async function runPreviewsCommand(parsed, logger, options) {
1128
+ const isAuth = await account.isAuthenticated();
1129
+ if (!isAuth) {
1130
+ logger.error("Not authenticated with Cloudflare");
1131
+ logger.info("Run `devflare login` first.");
1132
+ return { exitCode: 1 };
1133
+ }
1134
+ const rawSubcommand = parsed.args[0];
1135
+ const subcommand = resolvePreviewSubcommand(rawSubcommand) ?? "list";
1136
+ const includeAll = parsed.options.all === true;
1137
+ const theme = {
1138
+ useColor: shouldUseColor(parsed.options)
1139
+ };
1140
+ if (rawSubcommand && !resolvePreviewSubcommand(rawSubcommand)) {
1141
+ logger.error(`Unknown previews subcommand: ${rawSubcommand}`);
1142
+ logger.info(`Available previews subcommands: ${PREVIEW_SUBCOMMANDS.join(", ")}`);
1143
+ return { exitCode: 1 };
1144
+ }
1145
+ try {
1146
+ const context = await resolveContext(parsed, options, subcommand);
1147
+ const databaseName = asOptionalString(parsed.options.database);
1148
+ const environment = asOptionalString(parsed.options.env);
1149
+ const configFile = asOptionalString(parsed.options.config);
1150
+ switch (subcommand) {
1151
+ case "bindings":
1152
+ return runBindingsSubcommand(parsed, context, logger, options, environment, configFile, theme);
1153
+ case "cleanup":
1154
+ return runCleanupSubcommand(parsed, context, logger, options, databaseName, environment, configFile, includeAll, theme);
1155
+ case "list":
1156
+ default:
1157
+ return runListSubcommand(context, logger, theme);
1158
+ }
1159
+ } catch (error) {
1160
+ if (error instanceof Error) {
1161
+ logger.error(error.message);
1162
+ return { exitCode: 1 };
1163
+ }
1164
+ throw error;
1165
+ }
1166
+ }
1167
+ export {
1168
+ runPreviewsCommand
1169
+ };