emdash 1.3.1 → 1.5.0

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 (1941) hide show
  1. package/dist/action-token-CKphU6ur.mjs +26 -0
  2. package/dist/action-token-CKphU6ur.mjs.map +1 -0
  3. package/dist/activation-X5iMalte.mjs +387 -0
  4. package/dist/activation-X5iMalte.mjs.map +1 -0
  5. package/dist/adapters-DFsc9XjW.d.mts +173 -0
  6. package/dist/adapters-DFsc9XjW.d.mts.map +1 -0
  7. package/dist/after-B3AvMfBQ.mjs +50 -0
  8. package/dist/after-B3AvMfBQ.mjs.map +1 -0
  9. package/dist/allowed-origins-BFDNF-05.mjs +116 -0
  10. package/dist/allowed-origins-BFDNF-05.mjs.map +1 -0
  11. package/dist/api/route-utils.d.mts +4 -4
  12. package/dist/api/route-utils.d.mts.map +1 -1
  13. package/dist/api/route-utils.mjs +7 -65
  14. package/dist/api/route-utils.mjs.map +1 -1
  15. package/dist/api/schemas/index.d.mts +2 -2
  16. package/dist/api/schemas/index.mjs +7 -12
  17. package/dist/api-tokens-B-p5eI6J.mjs +9 -0
  18. package/dist/api-tokens-B-p5eI6J.mjs.map +1 -0
  19. package/dist/api-tokens-D27OQ0oQ.mjs +173 -0
  20. package/dist/api-tokens-D27OQ0oQ.mjs.map +1 -0
  21. package/dist/apply-Culv7QJl.mjs +1774 -0
  22. package/dist/apply-Culv7QJl.mjs.map +1 -0
  23. package/dist/approvals-oLE5G5jw.mjs +460 -0
  24. package/dist/approvals-oLE5G5jw.mjs.map +1 -0
  25. package/dist/artifact-fetch-ByK_1pck.mjs +659 -0
  26. package/dist/artifact-fetch-ByK_1pck.mjs.map +1 -0
  27. package/dist/artifacts-BXKMIV2F.mjs +323 -0
  28. package/dist/artifacts-BXKMIV2F.mjs.map +1 -0
  29. package/dist/astro/index.d.mts +17 -14
  30. package/dist/astro/index.d.mts.map +1 -1
  31. package/dist/astro/index.mjs +257 -24
  32. package/dist/astro/index.mjs.map +1 -1
  33. package/dist/astro/middleware/auth.d.mts +15 -12
  34. package/dist/astro/middleware/auth.d.mts.map +1 -1
  35. package/dist/astro/middleware/auth.mjs +62 -25
  36. package/dist/astro/middleware/auth.mjs.map +1 -1
  37. package/dist/astro/middleware/media-usage-write-fence.d.mts.map +1 -1
  38. package/dist/astro/middleware/media-usage-write-fence.mjs +5 -7
  39. package/dist/astro/middleware/media-usage-write-fence.mjs.map +1 -1
  40. package/dist/astro/middleware/redirect.d.mts.map +1 -1
  41. package/dist/astro/middleware/redirect.mjs +18 -26
  42. package/dist/astro/middleware/redirect.mjs.map +1 -1
  43. package/dist/astro/middleware/request-context.d.mts.map +1 -1
  44. package/dist/astro/middleware/request-context.mjs +128 -80
  45. package/dist/astro/middleware/request-context.mjs.map +1 -1
  46. package/dist/astro/middleware/setup.mjs +1 -1
  47. package/dist/astro/middleware.d.mts +15 -12
  48. package/dist/astro/middleware.d.mts.map +1 -1
  49. package/dist/astro/middleware.mjs +62 -158
  50. package/dist/astro/middleware.mjs.map +1 -1
  51. package/dist/astro/routes/PluginRegistry.d.mts +1 -5
  52. package/dist/astro/routes/PluginRegistry.d.mts.map +1 -1
  53. package/dist/astro/routes/PluginRegistry.mjs +11 -10
  54. package/dist/astro/routes/PluginRegistry.mjs.map +1 -1
  55. package/dist/astro/routes/api/admin/allowed-domains/_domain_.mjs +3 -18
  56. package/dist/astro/routes/api/admin/allowed-domains/_domain_.mjs.map +1 -1
  57. package/dist/astro/routes/api/admin/allowed-domains/index.mjs +3 -18
  58. package/dist/astro/routes/api/admin/allowed-domains/index.mjs.map +1 -1
  59. package/dist/astro/routes/api/admin/api-tokens/_id_.mjs +2 -8
  60. package/dist/astro/routes/api/admin/api-tokens/_id_.mjs.map +1 -1
  61. package/dist/astro/routes/api/admin/api-tokens/index.mjs +4 -9
  62. package/dist/astro/routes/api/admin/api-tokens/index.mjs.map +1 -1
  63. package/dist/astro/routes/api/admin/byline-fields/_slug_/usage.mjs +3 -8
  64. package/dist/astro/routes/api/admin/byline-fields/_slug_/usage.mjs.map +1 -1
  65. package/dist/astro/routes/api/admin/byline-fields/_slug_.mjs +5 -21
  66. package/dist/astro/routes/api/admin/byline-fields/_slug_.mjs.map +1 -1
  67. package/dist/astro/routes/api/admin/byline-fields/index.mjs +5 -21
  68. package/dist/astro/routes/api/admin/byline-fields/index.mjs.map +1 -1
  69. package/dist/astro/routes/api/admin/byline-fields/reorder.mjs +5 -21
  70. package/dist/astro/routes/api/admin/byline-fields/reorder.mjs.map +1 -1
  71. package/dist/astro/routes/api/admin/bylines/_id_/index.mjs +8 -33
  72. package/dist/astro/routes/api/admin/bylines/_id_/index.mjs.map +1 -1
  73. package/dist/astro/routes/api/admin/bylines/_id_/translations.mjs +8 -33
  74. package/dist/astro/routes/api/admin/bylines/_id_/translations.mjs.map +1 -1
  75. package/dist/astro/routes/api/admin/bylines/index.mjs +8 -32
  76. package/dist/astro/routes/api/admin/bylines/index.mjs.map +1 -1
  77. package/dist/astro/routes/api/admin/comments/_id_/status.d.mts.map +1 -1
  78. package/dist/astro/routes/api/admin/comments/_id_/status.mjs +9 -25
  79. package/dist/astro/routes/api/admin/comments/_id_/status.mjs.map +1 -1
  80. package/dist/astro/routes/api/admin/comments/_id_.d.mts.map +1 -1
  81. package/dist/astro/routes/api/admin/comments/_id_.mjs +12 -12
  82. package/dist/astro/routes/api/admin/comments/_id_.mjs.map +1 -1
  83. package/dist/astro/routes/api/admin/comments/bulk.d.mts.map +1 -1
  84. package/dist/astro/routes/api/admin/comments/bulk.mjs +16 -25
  85. package/dist/astro/routes/api/admin/comments/bulk.mjs.map +1 -1
  86. package/dist/astro/routes/api/admin/comments/counts.mjs +3 -10
  87. package/dist/astro/routes/api/admin/comments/counts.mjs.map +1 -1
  88. package/dist/astro/routes/api/admin/comments/index.mjs +5 -23
  89. package/dist/astro/routes/api/admin/comments/index.mjs.map +1 -1
  90. package/dist/astro/routes/api/admin/core-update.mjs +160 -10
  91. package/dist/astro/routes/api/admin/core-update.mjs.map +1 -1
  92. package/dist/astro/routes/api/admin/hooks/exclusive/_hookName_.mjs +4 -8
  93. package/dist/astro/routes/api/admin/hooks/exclusive/_hookName_.mjs.map +1 -1
  94. package/dist/astro/routes/api/admin/hooks/exclusive/index.mjs +2 -6
  95. package/dist/astro/routes/api/admin/hooks/exclusive/index.mjs.map +1 -1
  96. package/dist/astro/routes/api/admin/media-usage/activation.mjs +6 -25
  97. package/dist/astro/routes/api/admin/media-usage/activation.mjs.map +1 -1
  98. package/dist/astro/routes/api/admin/media-usage/collection-deletions/index.mjs +6 -26
  99. package/dist/astro/routes/api/admin/media-usage/collection-deletions/index.mjs.map +1 -1
  100. package/dist/astro/routes/api/admin/media-usage/collection-deletions/retry.mjs +6 -26
  101. package/dist/astro/routes/api/admin/media-usage/collection-deletions/retry.mjs.map +1 -1
  102. package/dist/astro/routes/api/admin/media-usage/progress.mjs +4 -29
  103. package/dist/astro/routes/api/admin/media-usage/progress.mjs.map +1 -1
  104. package/dist/astro/routes/api/admin/media-usage/repair.mjs +5 -36
  105. package/dist/astro/routes/api/admin/media-usage/repair.mjs.map +1 -1
  106. package/dist/astro/routes/api/admin/media-usage/work/index.mjs +6 -26
  107. package/dist/astro/routes/api/admin/media-usage/work/index.mjs.map +1 -1
  108. package/dist/astro/routes/api/admin/media-usage/work/retry.mjs +6 -26
  109. package/dist/astro/routes/api/admin/media-usage/work/retry.mjs.map +1 -1
  110. package/dist/astro/routes/api/admin/oauth-clients/_id_.mjs +3 -7
  111. package/dist/astro/routes/api/admin/oauth-clients/_id_.mjs.map +1 -1
  112. package/dist/astro/routes/api/admin/oauth-clients/index.mjs +3 -7
  113. package/dist/astro/routes/api/admin/oauth-clients/index.mjs.map +1 -1
  114. package/dist/astro/routes/api/admin/plugins/_id_/disable.mjs +4 -10
  115. package/dist/astro/routes/api/admin/plugins/_id_/disable.mjs.map +1 -1
  116. package/dist/astro/routes/api/admin/plugins/_id_/enable.mjs +4 -10
  117. package/dist/astro/routes/api/admin/plugins/_id_/enable.mjs.map +1 -1
  118. package/dist/astro/routes/api/admin/plugins/_id_/index.mjs +3 -87
  119. package/dist/astro/routes/api/admin/plugins/_id_/index.mjs.map +1 -1
  120. package/dist/astro/routes/api/admin/plugins/_id_/mcp.mjs +4 -8
  121. package/dist/astro/routes/api/admin/plugins/_id_/mcp.mjs.map +1 -1
  122. package/dist/astro/routes/api/admin/plugins/_id_/settings.mjs +4 -86
  123. package/dist/astro/routes/api/admin/plugins/_id_/settings.mjs.map +1 -1
  124. package/dist/astro/routes/api/admin/plugins/_id_/uninstall.mjs +5 -86
  125. package/dist/astro/routes/api/admin/plugins/_id_/uninstall.mjs.map +1 -1
  126. package/dist/astro/routes/api/admin/plugins/_id_/update.mjs +9 -97
  127. package/dist/astro/routes/api/admin/plugins/_id_/update.mjs.map +1 -1
  128. package/dist/astro/routes/api/admin/plugins/index.mjs +3 -87
  129. package/dist/astro/routes/api/admin/plugins/index.mjs.map +1 -1
  130. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/icon.mjs +3 -8
  131. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/icon.mjs.map +1 -1
  132. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/index.mjs +3 -86
  133. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/index.mjs.map +1 -1
  134. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.mjs +9 -97
  135. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.mjs.map +1 -1
  136. package/dist/astro/routes/api/admin/plugins/marketplace/index.mjs +3 -86
  137. package/dist/astro/routes/api/admin/plugins/marketplace/index.mjs.map +1 -1
  138. package/dist/astro/routes/api/admin/plugins/registry/_id_/uninstall.mjs +7 -86
  139. package/dist/astro/routes/api/admin/plugins/registry/_id_/uninstall.mjs.map +1 -1
  140. package/dist/astro/routes/api/admin/plugins/registry/_id_/update.mjs +14 -98
  141. package/dist/astro/routes/api/admin/plugins/registry/_id_/update.mjs.map +1 -1
  142. package/dist/astro/routes/api/admin/plugins/registry/artifact.mjs +6 -10
  143. package/dist/astro/routes/api/admin/plugins/registry/artifact.mjs.map +1 -1
  144. package/dist/astro/routes/api/admin/plugins/registry/install.mjs +11 -89
  145. package/dist/astro/routes/api/admin/plugins/registry/install.mjs.map +1 -1
  146. package/dist/astro/routes/api/admin/plugins/registry/publisher-handle.mjs +4 -8
  147. package/dist/astro/routes/api/admin/plugins/registry/publisher-handle.mjs.map +1 -1
  148. package/dist/astro/routes/api/admin/plugins/registry/verify.mjs +8 -87
  149. package/dist/astro/routes/api/admin/plugins/registry/verify.mjs.map +1 -1
  150. package/dist/astro/routes/api/admin/plugins/updates.mjs +7 -86
  151. package/dist/astro/routes/api/admin/plugins/updates.mjs.map +1 -1
  152. package/dist/astro/routes/api/admin/scheduled-policy-rejections/_collection_/_id_.mjs +4 -8
  153. package/dist/astro/routes/api/admin/scheduled-policy-rejections/_collection_/_id_.mjs.map +1 -1
  154. package/dist/astro/routes/api/admin/themes/marketplace/_id_/index.mjs +3 -86
  155. package/dist/astro/routes/api/admin/themes/marketplace/_id_/index.mjs.map +1 -1
  156. package/dist/astro/routes/api/admin/themes/marketplace/_id_/thumbnail.mjs +3 -8
  157. package/dist/astro/routes/api/admin/themes/marketplace/_id_/thumbnail.mjs.map +1 -1
  158. package/dist/astro/routes/api/admin/themes/marketplace/index.mjs +3 -86
  159. package/dist/astro/routes/api/admin/themes/marketplace/index.mjs.map +1 -1
  160. package/dist/astro/routes/api/admin/transfer/_...path_.mjs +1 -5
  161. package/dist/astro/routes/api/admin/transfer/_...path_.mjs.map +1 -1
  162. package/dist/astro/routes/api/admin/transfer/approvals/_id_/approve.mjs +6 -50
  163. package/dist/astro/routes/api/admin/transfer/approvals/_id_/approve.mjs.map +1 -1
  164. package/dist/astro/routes/api/admin/transfer/approvals/_id_/deny.mjs +6 -50
  165. package/dist/astro/routes/api/admin/transfer/approvals/_id_/deny.mjs.map +1 -1
  166. package/dist/astro/routes/api/admin/transfer/approvals/index.mjs +8 -52
  167. package/dist/astro/routes/api/admin/transfer/approvals/index.mjs.map +1 -1
  168. package/dist/astro/routes/api/admin/transfer/capabilities.mjs +8 -51
  169. package/dist/astro/routes/api/admin/transfer/capabilities.mjs.map +1 -1
  170. package/dist/astro/routes/api/admin/transfer/exports/_id_/advance.mjs +7 -52
  171. package/dist/astro/routes/api/admin/transfer/exports/_id_/advance.mjs.map +1 -1
  172. package/dist/astro/routes/api/admin/transfer/exports/_id_/archive.mjs +8 -53
  173. package/dist/astro/routes/api/admin/transfer/exports/_id_/archive.mjs.map +1 -1
  174. package/dist/astro/routes/api/admin/transfer/exports/_id_/files/_...path_.mjs +8 -53
  175. package/dist/astro/routes/api/admin/transfer/exports/_id_/files/_...path_.mjs.map +1 -1
  176. package/dist/astro/routes/api/admin/transfer/exports/_id_/index.mjs +7 -52
  177. package/dist/astro/routes/api/admin/transfer/exports/_id_/index.mjs.map +1 -1
  178. package/dist/astro/routes/api/admin/transfer/exports/_id_/manifest.mjs +8 -53
  179. package/dist/astro/routes/api/admin/transfer/exports/_id_/manifest.mjs.map +1 -1
  180. package/dist/astro/routes/api/admin/transfer/exports/index.mjs +9 -54
  181. package/dist/astro/routes/api/admin/transfer/exports/index.mjs.map +1 -1
  182. package/dist/astro/routes/api/admin/transfer/imports/_id_/abandon.mjs +7 -52
  183. package/dist/astro/routes/api/admin/transfer/imports/_id_/abandon.mjs.map +1 -1
  184. package/dist/astro/routes/api/admin/transfer/imports/_id_/advance.mjs +7 -52
  185. package/dist/astro/routes/api/admin/transfer/imports/_id_/advance.mjs.map +1 -1
  186. package/dist/astro/routes/api/admin/transfer/imports/_id_/analyze.mjs +9 -53
  187. package/dist/astro/routes/api/admin/transfer/imports/_id_/analyze.mjs.map +1 -1
  188. package/dist/astro/routes/api/admin/transfer/imports/_id_/cancel.mjs +7 -52
  189. package/dist/astro/routes/api/admin/transfer/imports/_id_/cancel.mjs.map +1 -1
  190. package/dist/astro/routes/api/admin/transfer/imports/_id_/execute.mjs +10 -54
  191. package/dist/astro/routes/api/admin/transfer/imports/_id_/execute.mjs.map +1 -1
  192. package/dist/astro/routes/api/admin/transfer/imports/_id_/files/_...path_.mjs +8 -52
  193. package/dist/astro/routes/api/admin/transfer/imports/_id_/files/_...path_.mjs.map +1 -1
  194. package/dist/astro/routes/api/admin/transfer/imports/_id_/index.mjs +7 -52
  195. package/dist/astro/routes/api/admin/transfer/imports/_id_/index.mjs.map +1 -1
  196. package/dist/astro/routes/api/admin/transfer/imports/_id_/missing.mjs +9 -54
  197. package/dist/astro/routes/api/admin/transfer/imports/_id_/missing.mjs.map +1 -1
  198. package/dist/astro/routes/api/admin/transfer/imports/_id_/plan.mjs +7 -52
  199. package/dist/astro/routes/api/admin/transfer/imports/_id_/plan.mjs.map +1 -1
  200. package/dist/astro/routes/api/admin/transfer/imports/_id_/receipt.mjs +7 -52
  201. package/dist/astro/routes/api/admin/transfer/imports/_id_/receipt.mjs.map +1 -1
  202. package/dist/astro/routes/api/admin/transfer/imports/index.mjs +11 -54
  203. package/dist/astro/routes/api/admin/transfer/imports/index.mjs.map +1 -1
  204. package/dist/astro/routes/api/admin/users/_id_/disable.mjs +2 -6
  205. package/dist/astro/routes/api/admin/users/_id_/disable.mjs.map +1 -1
  206. package/dist/astro/routes/api/admin/users/_id_/enable.mjs +1 -5
  207. package/dist/astro/routes/api/admin/users/_id_/enable.mjs.map +1 -1
  208. package/dist/astro/routes/api/admin/users/_id_/index.mjs +4 -19
  209. package/dist/astro/routes/api/admin/users/_id_/index.mjs.map +1 -1
  210. package/dist/astro/routes/api/admin/users/_id_/send-recovery.d.mts.map +1 -1
  211. package/dist/astro/routes/api/admin/users/_id_/send-recovery.mjs +11 -10
  212. package/dist/astro/routes/api/admin/users/_id_/send-recovery.mjs.map +1 -1
  213. package/dist/astro/routes/api/admin/users/index.mjs +3 -18
  214. package/dist/astro/routes/api/admin/users/index.mjs.map +1 -1
  215. package/dist/astro/routes/api/auth/dev-bypass.d.mts.map +1 -1
  216. package/dist/astro/routes/api/auth/dev-bypass.mjs +10 -7
  217. package/dist/astro/routes/api/auth/dev-bypass.mjs.map +1 -1
  218. package/dist/astro/routes/api/auth/handover.mjs +3 -9
  219. package/dist/astro/routes/api/auth/handover.mjs.map +1 -1
  220. package/dist/astro/routes/api/auth/invite/accept.mjs +1 -5
  221. package/dist/astro/routes/api/auth/invite/accept.mjs.map +1 -1
  222. package/dist/astro/routes/api/auth/invite/complete.d.mts.map +1 -1
  223. package/dist/astro/routes/api/auth/invite/complete.mjs +11 -26
  224. package/dist/astro/routes/api/auth/invite/complete.mjs.map +1 -1
  225. package/dist/astro/routes/api/auth/invite/index.d.mts.map +1 -1
  226. package/dist/astro/routes/api/auth/invite/index.mjs +13 -23
  227. package/dist/astro/routes/api/auth/invite/index.mjs.map +1 -1
  228. package/dist/astro/routes/api/auth/invite/register-options.d.mts.map +1 -1
  229. package/dist/astro/routes/api/auth/invite/register-options.mjs +9 -23
  230. package/dist/astro/routes/api/auth/invite/register-options.mjs.map +1 -1
  231. package/dist/astro/routes/api/auth/logout.mjs +2 -6
  232. package/dist/astro/routes/api/auth/logout.mjs.map +1 -1
  233. package/dist/astro/routes/api/auth/magic-link/send.d.mts.map +1 -1
  234. package/dist/astro/routes/api/auth/magic-link/send.mjs +15 -26
  235. package/dist/astro/routes/api/auth/magic-link/send.mjs.map +1 -1
  236. package/dist/astro/routes/api/auth/magic-link/verify.mjs +5 -20
  237. package/dist/astro/routes/api/auth/magic-link/verify.mjs.map +1 -1
  238. package/dist/astro/routes/api/auth/me.d.mts +3 -1
  239. package/dist/astro/routes/api/auth/me.d.mts.map +1 -1
  240. package/dist/astro/routes/api/auth/me.mjs +30 -30
  241. package/dist/astro/routes/api/auth/me.mjs.map +1 -1
  242. package/dist/astro/routes/api/auth/mode.mjs +2 -6
  243. package/dist/astro/routes/api/auth/mode.mjs.map +1 -1
  244. package/dist/astro/routes/api/auth/oauth/_provider_/callback.d.mts.map +1 -1
  245. package/dist/astro/routes/api/auth/oauth/_provider_/callback.mjs +6 -14
  246. package/dist/astro/routes/api/auth/oauth/_provider_/callback.mjs.map +1 -1
  247. package/dist/astro/routes/api/auth/oauth/_provider_.d.mts.map +1 -1
  248. package/dist/astro/routes/api/auth/oauth/_provider_.mjs +3 -4
  249. package/dist/astro/routes/api/auth/oauth/_provider_.mjs.map +1 -1
  250. package/dist/astro/routes/api/auth/passkey/_id_.mjs +3 -18
  251. package/dist/astro/routes/api/auth/passkey/_id_.mjs.map +1 -1
  252. package/dist/astro/routes/api/auth/passkey/index.mjs +1 -5
  253. package/dist/astro/routes/api/auth/passkey/index.mjs.map +1 -1
  254. package/dist/astro/routes/api/auth/passkey/options.d.mts.map +1 -1
  255. package/dist/astro/routes/api/auth/passkey/options.mjs +12 -26
  256. package/dist/astro/routes/api/auth/passkey/options.mjs.map +1 -1
  257. package/dist/astro/routes/api/auth/passkey/register/options.d.mts.map +1 -1
  258. package/dist/astro/routes/api/auth/passkey/register/options.mjs +9 -23
  259. package/dist/astro/routes/api/auth/passkey/register/options.mjs.map +1 -1
  260. package/dist/astro/routes/api/auth/passkey/register/verify.d.mts.map +1 -1
  261. package/dist/astro/routes/api/auth/passkey/register/verify.mjs +10 -24
  262. package/dist/astro/routes/api/auth/passkey/register/verify.mjs.map +1 -1
  263. package/dist/astro/routes/api/auth/passkey/verify.d.mts.map +1 -1
  264. package/dist/astro/routes/api/auth/passkey/verify.mjs +11 -26
  265. package/dist/astro/routes/api/auth/passkey/verify.mjs.map +1 -1
  266. package/dist/astro/routes/api/auth/signup/complete.d.mts.map +1 -1
  267. package/dist/astro/routes/api/auth/signup/complete.mjs +11 -26
  268. package/dist/astro/routes/api/auth/signup/complete.mjs.map +1 -1
  269. package/dist/astro/routes/api/auth/signup/request.d.mts.map +1 -1
  270. package/dist/astro/routes/api/auth/signup/request.mjs +9 -24
  271. package/dist/astro/routes/api/auth/signup/request.mjs.map +1 -1
  272. package/dist/astro/routes/api/auth/signup/verify.mjs +1 -5
  273. package/dist/astro/routes/api/auth/signup/verify.mjs.map +1 -1
  274. package/dist/astro/routes/api/calendar.mjs +5 -19
  275. package/dist/astro/routes/api/calendar.mjs.map +1 -1
  276. package/dist/astro/routes/api/comments/_collection_/_contentId_/index.mjs +5 -19
  277. package/dist/astro/routes/api/comments/_collection_/_contentId_/index.mjs.map +1 -1
  278. package/dist/astro/routes/api/comments/_collection_/_contentId_/reactions.mjs +8 -26
  279. package/dist/astro/routes/api/comments/_collection_/_contentId_/reactions.mjs.map +1 -1
  280. package/dist/astro/routes/api/content/_collection_/_id_/compare.mjs +2 -6
  281. package/dist/astro/routes/api/content/_collection_/_id_/compare.mjs.map +1 -1
  282. package/dist/astro/routes/api/content/_collection_/_id_/discard-draft.mjs +14 -24
  283. package/dist/astro/routes/api/content/_collection_/_id_/discard-draft.mjs.map +1 -1
  284. package/dist/astro/routes/api/content/_collection_/_id_/duplicate.mjs +3 -6
  285. package/dist/astro/routes/api/content/_collection_/_id_/duplicate.mjs.map +1 -1
  286. package/dist/astro/routes/api/content/_collection_/_id_/lock.d.mts.map +1 -1
  287. package/dist/astro/routes/api/content/_collection_/_id_/lock.mjs +9 -24
  288. package/dist/astro/routes/api/content/_collection_/_id_/lock.mjs.map +1 -1
  289. package/dist/astro/routes/api/content/_collection_/_id_/permanent.mjs +3 -7
  290. package/dist/astro/routes/api/content/_collection_/_id_/permanent.mjs.map +1 -1
  291. package/dist/astro/routes/api/content/_collection_/_id_/plugin-extensions/_pluginId_/_kind_/_extensionId_.mjs +2 -13
  292. package/dist/astro/routes/api/content/_collection_/_id_/plugin-extensions/_pluginId_/_kind_/_extensionId_.mjs.map +1 -1
  293. package/dist/astro/routes/api/content/_collection_/_id_/preview-url.mjs +13 -43
  294. package/dist/astro/routes/api/content/_collection_/_id_/preview-url.mjs.map +1 -1
  295. package/dist/astro/routes/api/content/_collection_/_id_/publish.mjs +7 -23
  296. package/dist/astro/routes/api/content/_collection_/_id_/publish.mjs.map +1 -1
  297. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/children.mjs +5 -45
  298. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/children.mjs.map +1 -1
  299. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/parents.mjs +5 -45
  300. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/parents.mjs.map +1 -1
  301. package/dist/astro/routes/api/content/_collection_/_id_/restore.mjs +4 -7
  302. package/dist/astro/routes/api/content/_collection_/_id_/restore.mjs.map +1 -1
  303. package/dist/astro/routes/api/content/_collection_/_id_/revisions/editors.d.mts +8 -0
  304. package/dist/astro/routes/api/content/_collection_/_id_/revisions/editors.d.mts.map +1 -0
  305. package/dist/astro/routes/api/content/_collection_/_id_/revisions/editors.mjs +16 -0
  306. package/dist/astro/routes/api/content/_collection_/_id_/revisions/editors.mjs.map +1 -0
  307. package/dist/astro/routes/api/content/_collection_/_id_/revisions.d.mts +2 -1
  308. package/dist/astro/routes/api/content/_collection_/_id_/revisions.d.mts.map +1 -1
  309. package/dist/astro/routes/api/content/_collection_/_id_/revisions.mjs +28 -7
  310. package/dist/astro/routes/api/content/_collection_/_id_/revisions.mjs.map +1 -1
  311. package/dist/astro/routes/api/content/_collection_/_id_/room.d.mts +8 -0
  312. package/dist/astro/routes/api/content/_collection_/_id_/room.d.mts.map +1 -0
  313. package/dist/astro/routes/api/content/_collection_/_id_/room.mjs +29 -0
  314. package/dist/astro/routes/api/content/_collection_/_id_/room.mjs.map +1 -0
  315. package/dist/astro/routes/api/content/_collection_/_id_/schedule.mjs +11 -24
  316. package/dist/astro/routes/api/content/_collection_/_id_/schedule.mjs.map +1 -1
  317. package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.d.mts.map +1 -1
  318. package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.mjs +32 -38
  319. package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.mjs.map +1 -1
  320. package/dist/astro/routes/api/content/_collection_/_id_/translations.mjs +2 -6
  321. package/dist/astro/routes/api/content/_collection_/_id_/translations.mjs.map +1 -1
  322. package/dist/astro/routes/api/content/_collection_/_id_/unpublish.mjs +7 -23
  323. package/dist/astro/routes/api/content/_collection_/_id_/unpublish.mjs.map +1 -1
  324. package/dist/astro/routes/api/content/_collection_/_id_.d.mts.map +1 -1
  325. package/dist/astro/routes/api/content/_collection_/_id_.mjs +28 -52
  326. package/dist/astro/routes/api/content/_collection_/_id_.mjs.map +1 -1
  327. package/dist/astro/routes/api/content/_collection_/authors.mjs +2 -6
  328. package/dist/astro/routes/api/content/_collection_/authors.mjs.map +1 -1
  329. package/dist/astro/routes/api/content/_collection_/index.mjs +5 -19
  330. package/dist/astro/routes/api/content/_collection_/index.mjs.map +1 -1
  331. package/dist/astro/routes/api/content/_collection_/trash.mjs +4 -19
  332. package/dist/astro/routes/api/content/_collection_/trash.mjs.map +1 -1
  333. package/dist/astro/routes/api/dashboard.mjs +141 -21
  334. package/dist/astro/routes/api/dashboard.mjs.map +1 -1
  335. package/dist/astro/routes/api/dev/emails.mjs +2 -6
  336. package/dist/astro/routes/api/dev/emails.mjs.map +1 -1
  337. package/dist/astro/routes/api/dev/scheduled-tasks.mjs +4 -125
  338. package/dist/astro/routes/api/dev/scheduled-tasks.mjs.map +1 -1
  339. package/dist/astro/routes/api/health.mjs +3 -7
  340. package/dist/astro/routes/api/health.mjs.map +1 -1
  341. package/dist/astro/routes/api/import/probe.d.mts +4 -3
  342. package/dist/astro/routes/api/import/probe.d.mts.map +1 -1
  343. package/dist/astro/routes/api/import/probe.mjs +6 -37
  344. package/dist/astro/routes/api/import/probe.mjs.map +1 -1
  345. package/dist/astro/routes/api/import/wordpress/analyze.d.mts +6 -3
  346. package/dist/astro/routes/api/import/wordpress/analyze.d.mts.map +1 -1
  347. package/dist/astro/routes/api/import/wordpress/analyze.mjs +10 -32
  348. package/dist/astro/routes/api/import/wordpress/analyze.mjs.map +1 -1
  349. package/dist/astro/routes/api/import/wordpress/execute.d.mts +32 -14
  350. package/dist/astro/routes/api/import/wordpress/execute.d.mts.map +1 -1
  351. package/dist/astro/routes/api/import/wordpress/execute.mjs +147 -47
  352. package/dist/astro/routes/api/import/wordpress/execute.mjs.map +1 -1
  353. package/dist/astro/routes/api/import/wordpress/media.d.mts +16 -13
  354. package/dist/astro/routes/api/import/wordpress/media.d.mts.map +1 -1
  355. package/dist/astro/routes/api/import/wordpress/media.mjs +11 -27
  356. package/dist/astro/routes/api/import/wordpress/media.mjs.map +1 -1
  357. package/dist/astro/routes/api/import/wordpress/prepare.mjs +10 -26
  358. package/dist/astro/routes/api/import/wordpress/prepare.mjs.map +1 -1
  359. package/dist/astro/routes/api/import/wordpress/rewrite-urls.d.mts +16 -13
  360. package/dist/astro/routes/api/import/wordpress/rewrite-urls.d.mts.map +1 -1
  361. package/dist/astro/routes/api/import/wordpress/rewrite-urls.mjs +12 -39
  362. package/dist/astro/routes/api/import/wordpress/rewrite-urls.mjs.map +1 -1
  363. package/dist/astro/routes/api/import/wordpress-plugin/analyze.d.mts +1 -1
  364. package/dist/astro/routes/api/import/wordpress-plugin/analyze.mjs +6 -37
  365. package/dist/astro/routes/api/import/wordpress-plugin/analyze.mjs.map +1 -1
  366. package/dist/astro/routes/api/import/wordpress-plugin/callback.mjs +1 -1
  367. package/dist/astro/routes/api/import/wordpress-plugin/execute.d.mts +16 -13
  368. package/dist/astro/routes/api/import/wordpress-plugin/execute.d.mts.map +1 -1
  369. package/dist/astro/routes/api/import/wordpress-plugin/execute.mjs +189 -61
  370. package/dist/astro/routes/api/import/wordpress-plugin/execute.mjs.map +1 -1
  371. package/dist/astro/routes/api/manifest.d.mts.map +1 -1
  372. package/dist/astro/routes/api/manifest.mjs +32 -13
  373. package/dist/astro/routes/api/manifest.mjs.map +1 -1
  374. package/dist/astro/routes/api/mcp.mjs +130 -126
  375. package/dist/astro/routes/api/mcp.mjs.map +1 -1
  376. package/dist/astro/routes/api/media/_id_/confirm.d.mts.map +1 -1
  377. package/dist/astro/routes/api/media/_id_/confirm.mjs +50 -30
  378. package/dist/astro/routes/api/media/_id_/confirm.mjs.map +1 -1
  379. package/dist/astro/routes/api/media/_id_/replace.mjs +5 -20
  380. package/dist/astro/routes/api/media/_id_/replace.mjs.map +1 -1
  381. package/dist/astro/routes/api/media/_id_/upload.mjs +6 -10
  382. package/dist/astro/routes/api/media/_id_/upload.mjs.map +1 -1
  383. package/dist/astro/routes/api/media/_id_/usage.mjs +6 -38
  384. package/dist/astro/routes/api/media/_id_/usage.mjs.map +1 -1
  385. package/dist/astro/routes/api/media/_id_.mjs +5 -36
  386. package/dist/astro/routes/api/media/_id_.mjs.map +1 -1
  387. package/dist/astro/routes/api/media/asset/_id_/_filename_.d.mts.map +1 -1
  388. package/dist/astro/routes/api/media/asset/_id_/_filename_.mjs +4 -7
  389. package/dist/astro/routes/api/media/asset/_id_/_filename_.mjs.map +1 -1
  390. package/dist/astro/routes/api/media/file/_...key_.d.mts.map +1 -1
  391. package/dist/astro/routes/api/media/file/_...key_.mjs +52 -13
  392. package/dist/astro/routes/api/media/file/_...key_.mjs.map +1 -1
  393. package/dist/astro/routes/api/media/folders/_id_.mjs +5 -20
  394. package/dist/astro/routes/api/media/folders/_id_.mjs.map +1 -1
  395. package/dist/astro/routes/api/media/folders/index.mjs +5 -20
  396. package/dist/astro/routes/api/media/folders/index.mjs.map +1 -1
  397. package/dist/astro/routes/api/media/providers/_providerId_/_itemId_.mjs +2 -6
  398. package/dist/astro/routes/api/media/providers/_providerId_/_itemId_.mjs.map +1 -1
  399. package/dist/astro/routes/api/media/providers/_providerId_/index.mjs +2 -6
  400. package/dist/astro/routes/api/media/providers/_providerId_/index.mjs.map +1 -1
  401. package/dist/astro/routes/api/media/providers/index.mjs +2 -6
  402. package/dist/astro/routes/api/media/providers/index.mjs.map +1 -1
  403. package/dist/astro/routes/api/media/upload-url.mjs +8 -23
  404. package/dist/astro/routes/api/media/upload-url.mjs.map +1 -1
  405. package/dist/astro/routes/api/media.mjs +20 -43
  406. package/dist/astro/routes/api/media.mjs.map +1 -1
  407. package/dist/astro/routes/api/menus/_name_/items/_id_.mjs +8 -25
  408. package/dist/astro/routes/api/menus/_name_/items/_id_.mjs.map +1 -1
  409. package/dist/astro/routes/api/menus/_name_/items.mjs +8 -25
  410. package/dist/astro/routes/api/menus/_name_/items.mjs.map +1 -1
  411. package/dist/astro/routes/api/menus/_name_/reorder.mjs +8 -25
  412. package/dist/astro/routes/api/menus/_name_/reorder.mjs.map +1 -1
  413. package/dist/astro/routes/api/menus/_name_/translations.mjs +7 -25
  414. package/dist/astro/routes/api/menus/_name_/translations.mjs.map +1 -1
  415. package/dist/astro/routes/api/menus/_name_.mjs +8 -25
  416. package/dist/astro/routes/api/menus/_name_.mjs.map +1 -1
  417. package/dist/astro/routes/api/menus/index.mjs +8 -25
  418. package/dist/astro/routes/api/menus/index.mjs.map +1 -1
  419. package/dist/astro/routes/api/oauth/authorize.mjs +5 -6
  420. package/dist/astro/routes/api/oauth/authorize.mjs.map +1 -1
  421. package/dist/astro/routes/api/oauth/device/authorize.d.mts.map +1 -1
  422. package/dist/astro/routes/api/oauth/device/authorize.mjs +3 -9
  423. package/dist/astro/routes/api/oauth/device/authorize.mjs.map +1 -1
  424. package/dist/astro/routes/api/oauth/device/code.mjs +6 -13
  425. package/dist/astro/routes/api/oauth/device/code.mjs.map +1 -1
  426. package/dist/astro/routes/api/oauth/device/token.mjs +5 -12
  427. package/dist/astro/routes/api/oauth/device/token.mjs.map +1 -1
  428. package/dist/astro/routes/api/oauth/register.mjs +4 -9
  429. package/dist/astro/routes/api/oauth/register.mjs.map +1 -1
  430. package/dist/astro/routes/api/oauth/token/refresh.mjs +3 -9
  431. package/dist/astro/routes/api/oauth/token/refresh.mjs.map +1 -1
  432. package/dist/astro/routes/api/oauth/token/revoke.mjs +3 -9
  433. package/dist/astro/routes/api/oauth/token/revoke.mjs.map +1 -1
  434. package/dist/astro/routes/api/oauth/token.d.mts.map +1 -1
  435. package/dist/astro/routes/api/oauth/token.mjs +5 -10
  436. package/dist/astro/routes/api/oauth/token.mjs.map +1 -1
  437. package/dist/astro/routes/api/openapi.json.mjs +15 -31
  438. package/dist/astro/routes/api/openapi.json.mjs.map +1 -1
  439. package/dist/astro/routes/api/plugins/_pluginId_/_...path_.mjs +2 -13
  440. package/dist/astro/routes/api/plugins/_pluginId_/_...path_.mjs.map +1 -1
  441. package/dist/astro/routes/api/redirects/404s/index.mjs +5 -28
  442. package/dist/astro/routes/api/redirects/404s/index.mjs.map +1 -1
  443. package/dist/astro/routes/api/redirects/404s/summary.mjs +5 -28
  444. package/dist/astro/routes/api/redirects/404s/summary.mjs.map +1 -1
  445. package/dist/astro/routes/api/redirects/_id_.mjs +6 -29
  446. package/dist/astro/routes/api/redirects/_id_.mjs.map +1 -1
  447. package/dist/astro/routes/api/redirects/index.mjs +6 -29
  448. package/dist/astro/routes/api/redirects/index.mjs.map +1 -1
  449. package/dist/astro/routes/api/relations/_id_/index.mjs +5 -45
  450. package/dist/astro/routes/api/relations/_id_/index.mjs.map +1 -1
  451. package/dist/astro/routes/api/relations/index.mjs +5 -45
  452. package/dist/astro/routes/api/relations/index.mjs.map +1 -1
  453. package/dist/astro/routes/api/revisions/_revisionId_/index.mjs +2 -6
  454. package/dist/astro/routes/api/revisions/_revisionId_/index.mjs.map +1 -1
  455. package/dist/astro/routes/api/revisions/_revisionId_/restore.mjs +7 -23
  456. package/dist/astro/routes/api/revisions/_revisionId_/restore.mjs.map +1 -1
  457. package/dist/astro/routes/api/schema/block-types/_slug_/index.mjs +5 -87
  458. package/dist/astro/routes/api/schema/block-types/_slug_/index.mjs.map +1 -1
  459. package/dist/astro/routes/api/schema/block-types/_slug_/versions/_version_/activate.mjs +5 -87
  460. package/dist/astro/routes/api/schema/block-types/_slug_/versions/_version_/activate.mjs.map +1 -1
  461. package/dist/astro/routes/api/schema/block-types/index.mjs +5 -87
  462. package/dist/astro/routes/api/schema/block-types/index.mjs.map +1 -1
  463. package/dist/astro/routes/api/schema/collections/_slug_/fields/_fieldSlug_.mjs +5 -87
  464. package/dist/astro/routes/api/schema/collections/_slug_/fields/_fieldSlug_.mjs.map +1 -1
  465. package/dist/astro/routes/api/schema/collections/_slug_/fields/index.mjs +5 -87
  466. package/dist/astro/routes/api/schema/collections/_slug_/fields/index.mjs.map +1 -1
  467. package/dist/astro/routes/api/schema/collections/_slug_/fields/reorder.mjs +5 -87
  468. package/dist/astro/routes/api/schema/collections/_slug_/fields/reorder.mjs.map +1 -1
  469. package/dist/astro/routes/api/schema/collections/_slug_/index.mjs +5 -87
  470. package/dist/astro/routes/api/schema/collections/_slug_/index.mjs.map +1 -1
  471. package/dist/astro/routes/api/schema/collections/index.mjs +5 -87
  472. package/dist/astro/routes/api/schema/collections/index.mjs.map +1 -1
  473. package/dist/astro/routes/api/schema/collections/reorder.mjs +5 -87
  474. package/dist/astro/routes/api/schema/collections/reorder.mjs.map +1 -1
  475. package/dist/astro/routes/api/schema/index.mjs +4 -22
  476. package/dist/astro/routes/api/schema/index.mjs.map +1 -1
  477. package/dist/astro/routes/api/schema/orphans/_slug_.mjs +5 -87
  478. package/dist/astro/routes/api/schema/orphans/_slug_.mjs.map +1 -1
  479. package/dist/astro/routes/api/schema/orphans/index.mjs +3 -86
  480. package/dist/astro/routes/api/schema/orphans/index.mjs.map +1 -1
  481. package/dist/astro/routes/api/search/enable.mjs +5 -26
  482. package/dist/astro/routes/api/search/enable.mjs.map +1 -1
  483. package/dist/astro/routes/api/search/index.mjs +4 -25
  484. package/dist/astro/routes/api/search/index.mjs.map +1 -1
  485. package/dist/astro/routes/api/search/rebuild.mjs +5 -26
  486. package/dist/astro/routes/api/search/rebuild.mjs.map +1 -1
  487. package/dist/astro/routes/api/search/stats.mjs +3 -14
  488. package/dist/astro/routes/api/search/stats.mjs.map +1 -1
  489. package/dist/astro/routes/api/search/suggest.mjs +4 -25
  490. package/dist/astro/routes/api/search/suggest.mjs.map +1 -1
  491. package/dist/astro/routes/api/sections/_slug_.mjs +5 -25
  492. package/dist/astro/routes/api/sections/_slug_.mjs.map +1 -1
  493. package/dist/astro/routes/api/sections/index.mjs +5 -25
  494. package/dist/astro/routes/api/sections/index.mjs.map +1 -1
  495. package/dist/astro/routes/api/settings/backups/archives/_name_.mjs +4 -10
  496. package/dist/astro/routes/api/settings/backups/archives/_name_.mjs.map +1 -1
  497. package/dist/astro/routes/api/settings/backups/archives/index.mjs +3 -10
  498. package/dist/astro/routes/api/settings/backups/archives/index.mjs.map +1 -1
  499. package/dist/astro/routes/api/settings/backups/export.mjs +4 -10
  500. package/dist/astro/routes/api/settings/backups/export.mjs.map +1 -1
  501. package/dist/astro/routes/api/settings/backups/index.mjs +5 -11
  502. package/dist/astro/routes/api/settings/backups/index.mjs.map +1 -1
  503. package/dist/astro/routes/api/settings/domain-notify.d.mts.map +1 -1
  504. package/dist/astro/routes/api/settings/domain-notify.mjs +14 -14
  505. package/dist/astro/routes/api/settings/domain-notify.mjs.map +1 -1
  506. package/dist/astro/routes/api/settings/domain.mjs +8 -27
  507. package/dist/astro/routes/api/settings/domain.mjs.map +1 -1
  508. package/dist/astro/routes/api/settings/email.d.mts +2 -1
  509. package/dist/astro/routes/api/settings/email.d.mts.map +1 -1
  510. package/dist/astro/routes/api/settings/email.mjs +124 -16
  511. package/dist/astro/routes/api/settings/email.mjs.map +1 -1
  512. package/dist/astro/routes/api/settings.mjs +7 -35
  513. package/dist/astro/routes/api/settings.mjs.map +1 -1
  514. package/dist/astro/routes/api/setup/admin-verify.d.mts.map +1 -1
  515. package/dist/astro/routes/api/setup/admin-verify.mjs +13 -29
  516. package/dist/astro/routes/api/setup/admin-verify.mjs.map +1 -1
  517. package/dist/astro/routes/api/setup/admin.d.mts.map +1 -1
  518. package/dist/astro/routes/api/setup/admin.mjs +10 -24
  519. package/dist/astro/routes/api/setup/admin.mjs.map +1 -1
  520. package/dist/astro/routes/api/setup/dev-bypass.d.mts.map +1 -1
  521. package/dist/astro/routes/api/setup/dev-bypass.mjs +13 -58
  522. package/dist/astro/routes/api/setup/dev-bypass.mjs.map +1 -1
  523. package/dist/astro/routes/api/setup/dev-reset.mjs +2 -6
  524. package/dist/astro/routes/api/setup/dev-reset.mjs.map +1 -1
  525. package/dist/astro/routes/api/setup/index.mjs +14 -65
  526. package/dist/astro/routes/api/setup/index.mjs.map +1 -1
  527. package/dist/astro/routes/api/setup/status.mjs +3 -7
  528. package/dist/astro/routes/api/setup/status.mjs.map +1 -1
  529. package/dist/astro/routes/api/site/domain-proof.mjs +2 -21
  530. package/dist/astro/routes/api/site/domain-proof.mjs.map +1 -1
  531. package/dist/astro/routes/api/snapshot.mjs +6 -13
  532. package/dist/astro/routes/api/snapshot.mjs.map +1 -1
  533. package/dist/astro/routes/api/taxonomies/_name_/reorder.mjs +7 -34
  534. package/dist/astro/routes/api/taxonomies/_name_/reorder.mjs.map +1 -1
  535. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_/translations.mjs +7 -34
  536. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_/translations.mjs.map +1 -1
  537. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_.mjs +8 -34
  538. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_.mjs.map +1 -1
  539. package/dist/astro/routes/api/taxonomies/_name_/terms/index.mjs +7 -34
  540. package/dist/astro/routes/api/taxonomies/_name_/terms/index.mjs.map +1 -1
  541. package/dist/astro/routes/api/taxonomies/_name_/translations.mjs +5 -32
  542. package/dist/astro/routes/api/taxonomies/_name_/translations.mjs.map +1 -1
  543. package/dist/astro/routes/api/taxonomies/_name_.mjs +8 -34
  544. package/dist/astro/routes/api/taxonomies/_name_.mjs.map +1 -1
  545. package/dist/astro/routes/api/taxonomies/bulk-tag.mjs +13 -46
  546. package/dist/astro/routes/api/taxonomies/bulk-tag.mjs.map +1 -1
  547. package/dist/astro/routes/api/taxonomies/index.mjs +8 -34
  548. package/dist/astro/routes/api/taxonomies/index.mjs.map +1 -1
  549. package/dist/astro/routes/api/themes/preview.mjs +4 -10
  550. package/dist/astro/routes/api/themes/preview.mjs.map +1 -1
  551. package/dist/astro/routes/api/typegen.mjs +3 -7
  552. package/dist/astro/routes/api/typegen.mjs.map +1 -1
  553. package/dist/astro/routes/api/visual-editing/action-token.mjs +3 -10
  554. package/dist/astro/routes/api/visual-editing/action-token.mjs.map +1 -1
  555. package/dist/astro/routes/api/visual-editing/content/_collection_/_id_/publish.mjs +3 -26
  556. package/dist/astro/routes/api/visual-editing/content/_collection_/_id_/publish.mjs.map +1 -1
  557. package/dist/astro/routes/api/visual-editing/toolbar-labels.mjs +1 -5
  558. package/dist/astro/routes/api/visual-editing/toolbar-labels.mjs.map +1 -1
  559. package/dist/astro/routes/api/well-known/auth.d.mts.map +1 -1
  560. package/dist/astro/routes/api/well-known/auth.mjs +4 -3
  561. package/dist/astro/routes/api/well-known/auth.mjs.map +1 -1
  562. package/dist/astro/routes/api/well-known/oauth-authorization-server.mjs +2 -2
  563. package/dist/astro/routes/api/well-known/oauth-protected-resource.mjs +2 -2
  564. package/dist/astro/routes/api/widget-areas/_name_/reorder.d.mts.map +1 -1
  565. package/dist/astro/routes/api/widget-areas/_name_/reorder.mjs +11 -22
  566. package/dist/astro/routes/api/widget-areas/_name_/reorder.mjs.map +1 -1
  567. package/dist/astro/routes/api/widget-areas/_name_/widgets/_id_.d.mts.map +1 -1
  568. package/dist/astro/routes/api/widget-areas/_name_/widgets/_id_.mjs +10 -27
  569. package/dist/astro/routes/api/widget-areas/_name_/widgets/_id_.mjs.map +1 -1
  570. package/dist/astro/routes/api/widget-areas/_name_/widgets.mjs +9 -27
  571. package/dist/astro/routes/api/widget-areas/_name_/widgets.mjs.map +1 -1
  572. package/dist/astro/routes/api/widget-areas/_name_.mjs +7 -15
  573. package/dist/astro/routes/api/widget-areas/_name_.mjs.map +1 -1
  574. package/dist/astro/routes/api/widget-areas/index.mjs +9 -27
  575. package/dist/astro/routes/api/widget-areas/index.mjs.map +1 -1
  576. package/dist/astro/routes/api/widget-components.mjs +2 -6
  577. package/dist/astro/routes/api/widget-components.mjs.map +1 -1
  578. package/dist/astro/routes/robots.txt.d.mts.map +1 -1
  579. package/dist/astro/routes/robots.txt.mjs +6 -24
  580. package/dist/astro/routes/robots.txt.mjs.map +1 -1
  581. package/dist/astro/routes/sitemap-_collection_.xml.mjs +11 -25
  582. package/dist/astro/routes/sitemap-_collection_.xml.mjs.map +1 -1
  583. package/dist/astro/routes/sitemap.xml.d.mts.map +1 -1
  584. package/dist/astro/routes/sitemap.xml.mjs +5 -23
  585. package/dist/astro/routes/sitemap.xml.mjs.map +1 -1
  586. package/dist/astro/types.d.mts +49 -23
  587. package/dist/astro/types.d.mts.map +1 -1
  588. package/dist/audit-T3NRtoQ5.mjs +127 -0
  589. package/dist/audit-T3NRtoQ5.mjs.map +1 -0
  590. package/dist/auth/providers/github.d.mts +1 -1
  591. package/dist/auth/providers/google.d.mts +1 -1
  592. package/dist/auth/providers/microsoft.d.mts +1 -1
  593. package/dist/authoritative-records-Cd5BVXRs.mjs +5183 -0
  594. package/dist/authoritative-records-Cd5BVXRs.mjs.map +1 -0
  595. package/dist/authorize-B-4ogCQG.mjs +74 -0
  596. package/dist/authorize-B-4ogCQG.mjs.map +1 -0
  597. package/dist/backup-BQhg3MEK.mjs +246 -0
  598. package/dist/backup-BQhg3MEK.mjs.map +1 -0
  599. package/dist/base64-GXviT28w.mjs +63 -0
  600. package/dist/base64-GXviT28w.mjs.map +1 -0
  601. package/dist/block-types-BTzqdEZV.mjs +132 -0
  602. package/dist/block-types-BTzqdEZV.mjs.map +1 -0
  603. package/dist/block-values-DzZIh7WN.mjs +215 -0
  604. package/dist/block-values-DzZIh7WN.mjs.map +1 -0
  605. package/dist/byline--sweE_MZ.mjs +930 -0
  606. package/dist/byline--sweE_MZ.mjs.map +1 -0
  607. package/dist/byline-fields-Czdq4Yad.mjs +123 -0
  608. package/dist/byline-fields-Czdq4Yad.mjs.map +1 -0
  609. package/dist/byline-registry-Cr7kjrxM.mjs +406 -0
  610. package/dist/byline-registry-Cr7kjrxM.mjs.map +1 -0
  611. package/dist/bylines-DnuH3H8z.mjs +234 -0
  612. package/dist/bylines-DnuH3H8z.mjs.map +1 -0
  613. package/dist/bylines-txlwgzIK.mjs +150 -0
  614. package/dist/bylines-txlwgzIK.mjs.map +1 -0
  615. package/dist/cache-BjnpmIpb.mjs +151 -0
  616. package/dist/cache-BjnpmIpb.mjs.map +1 -0
  617. package/dist/canonical-Cb-rJGRU.mjs +174 -0
  618. package/dist/canonical-Cb-rJGRU.mjs.map +1 -0
  619. package/dist/capture-triggers-BZmIEdX2.mjs +362 -0
  620. package/dist/capture-triggers-BZmIEdX2.mjs.map +1 -0
  621. package/dist/challenge-store-B0PoBBqW.mjs +51 -0
  622. package/dist/challenge-store-B0PoBBqW.mjs.map +1 -0
  623. package/dist/checksum-CH9TyM-N.mjs +162 -0
  624. package/dist/checksum-CH9TyM-N.mjs.map +1 -0
  625. package/dist/chrome-tags-BocDVqqx.mjs +24 -0
  626. package/dist/chrome-tags-BocDVqqx.mjs.map +1 -0
  627. package/dist/chunks-DRnEstVb.mjs +25 -0
  628. package/dist/chunks-DRnEstVb.mjs.map +1 -0
  629. package/dist/cli/index.mjs +892 -94
  630. package/dist/cli/index.mjs.map +1 -1
  631. package/dist/client/cf-access.d.mts +1 -1
  632. package/dist/client/index.d.mts +97 -97
  633. package/dist/client/index.d.mts.map +1 -1
  634. package/dist/client/index.mjs +15 -6
  635. package/dist/client/index.mjs.map +1 -1
  636. package/dist/collection-slugs-cache-CYMrqHZ6.mjs +91 -0
  637. package/dist/collection-slugs-cache-CYMrqHZ6.mjs.map +1 -0
  638. package/dist/comment-BGeXmJ8F.mjs +335 -0
  639. package/dist/comment-BGeXmJ8F.mjs.map +1 -0
  640. package/dist/comment-reaction-ty-JEDYR.mjs +85 -0
  641. package/dist/comment-reaction-ty-JEDYR.mjs.map +1 -0
  642. package/dist/comments-ByrrLvZL.mjs +99 -0
  643. package/dist/comments-ByrrLvZL.mjs.map +1 -0
  644. package/dist/comments-DqhARoef.mjs +195 -0
  645. package/dist/comments-DqhARoef.mjs.map +1 -0
  646. package/dist/components-u2HE5Mu9.mjs +112 -0
  647. package/dist/components-u2HE5Mu9.mjs.map +1 -0
  648. package/dist/config-B4F2ttAZ.d.mts +7230 -0
  649. package/dist/config-B4F2ttAZ.d.mts.map +1 -0
  650. package/dist/config-BnrtMvHW.mjs +228 -0
  651. package/dist/config-BnrtMvHW.mjs.map +1 -0
  652. package/dist/config-DEse9gaE.d.mts +41 -0
  653. package/dist/config-DEse9gaE.d.mts.map +1 -0
  654. package/dist/connection-BaIVuaDX.mjs +36 -0
  655. package/dist/connection-BaIVuaDX.mjs.map +1 -0
  656. package/dist/content-Dxztag5t.mjs +2270 -0
  657. package/dist/content-Dxztag5t.mjs.map +1 -0
  658. package/dist/content-list-query-yYbBU-dB.d.mts +26 -0
  659. package/dist/content-list-query-yYbBU-dB.d.mts.map +1 -0
  660. package/dist/content-policy-Drm9sqdA.mjs +68 -0
  661. package/dist/content-policy-Drm9sqdA.mjs.map +1 -0
  662. package/dist/content-repair-2PdahlgZ.mjs +443 -0
  663. package/dist/content-repair-2PdahlgZ.mjs.map +1 -0
  664. package/dist/content-save-KMll0S7E.mjs +202 -0
  665. package/dist/content-save-KMll0S7E.mjs.map +1 -0
  666. package/dist/context-C3OZjexd.mjs +2225 -0
  667. package/dist/context-C3OZjexd.mjs.map +1 -0
  668. package/dist/credits-C8uXoWfN.mjs +110 -0
  669. package/dist/credits-C8uXoWfN.mjs.map +1 -0
  670. package/dist/cron-CrjBjDuy.mjs +310 -0
  671. package/dist/cron-CrjBjDuy.mjs.map +1 -0
  672. package/dist/db/index.d.mts +3 -3
  673. package/dist/db/index.mjs +1 -4
  674. package/dist/db/index.mjs.map +1 -1
  675. package/dist/db/libsql-migrations.d.mts +1 -1
  676. package/dist/db/libsql-migrations.mjs +2 -7
  677. package/dist/db/libsql-migrations.mjs.map +1 -1
  678. package/dist/db/libsql.d.mts +1 -1
  679. package/dist/db/postgres-migrations.d.mts +1 -1
  680. package/dist/db/postgres-migrations.mjs +2 -7
  681. package/dist/db/postgres-migrations.mjs.map +1 -1
  682. package/dist/db/postgres.d.mts +1 -1
  683. package/dist/db/sqlite-migrations.d.mts +1 -1
  684. package/dist/db/sqlite-migrations.mjs +2 -7
  685. package/dist/db/sqlite-migrations.mjs.map +1 -1
  686. package/dist/db/sqlite.d.mts +1 -1
  687. package/dist/db/sqlite.mjs +1 -1
  688. package/dist/default-DPoN3H5H.mjs +81 -0
  689. package/dist/default-DPoN3H5H.mjs.map +1 -0
  690. package/dist/deferred-tasks-uSx5qCFn.d.mts +10 -0
  691. package/dist/deferred-tasks-uSx5qCFn.d.mts.map +1 -0
  692. package/dist/deferred-tasks-yv85msJv.mjs +52 -0
  693. package/dist/deferred-tasks-yv85msJv.mjs.map +1 -0
  694. package/dist/destination-BNL1K7Mz.mjs +18 -0
  695. package/dist/destination-BNL1K7Mz.mjs.map +1 -0
  696. package/dist/dev-typegen-BVQAguf4.mjs +29 -0
  697. package/dist/dev-typegen-BVQAguf4.mjs.map +1 -0
  698. package/dist/device-flow-hT8lKWXq.mjs +519 -0
  699. package/dist/device-flow-hT8lKWXq.mjs.map +1 -0
  700. package/dist/dialect-helpers-DqUMP9fJ.mjs +350 -0
  701. package/dist/dialect-helpers-DqUMP9fJ.mjs.map +1 -0
  702. package/dist/digest-xYRiuW_E.mjs +194 -0
  703. package/dist/digest-xYRiuW_E.mjs.map +1 -0
  704. package/dist/direct-executor-CZ2SH1bq.mjs +117 -0
  705. package/dist/direct-executor-CZ2SH1bq.mjs.map +1 -0
  706. package/dist/dist-kxThYgdL.mjs +810 -0
  707. package/dist/dist-kxThYgdL.mjs.map +1 -0
  708. package/dist/email-console-CochjAlh.mjs +50 -0
  709. package/dist/email-console-CochjAlh.mjs.map +1 -0
  710. package/dist/email-locale-BoxaIPG8.mjs +25 -0
  711. package/dist/email-locale-BoxaIPG8.mjs.map +1 -0
  712. package/dist/email-smtp-BnHR_Ccx.mjs +643 -0
  713. package/dist/email-smtp-BnHR_Ccx.mjs.map +1 -0
  714. package/dist/emdash-runtime-CXsdCQnM.mjs +5262 -0
  715. package/dist/emdash-runtime-CXsdCQnM.mjs.map +1 -0
  716. package/dist/enrich-BReo_COC.mjs +203 -0
  717. package/dist/enrich-BReo_COC.mjs.map +1 -0
  718. package/dist/entry-lock-BfnhlRhC.mjs +207 -0
  719. package/dist/entry-lock-BfnhlRhC.mjs.map +1 -0
  720. package/dist/entry-lock-DsVhZcJN.mjs +1228 -0
  721. package/dist/entry-lock-DsVhZcJN.mjs.map +1 -0
  722. package/dist/entry-locks-D_kjygT1.mjs +173 -0
  723. package/dist/entry-locks-D_kjygT1.mjs.map +1 -0
  724. package/dist/env-types-CXI9uaMU.mjs +38 -0
  725. package/dist/env-types-CXI9uaMU.mjs.map +1 -0
  726. package/dist/error-DcDNU7hZ.mjs +92 -0
  727. package/dist/error-DcDNU7hZ.mjs.map +1 -0
  728. package/dist/errors-BYdjOimY.mjs +18 -0
  729. package/dist/errors-BYdjOimY.mjs.map +1 -0
  730. package/dist/errors-CJ6711al.mjs +120 -0
  731. package/dist/errors-CJ6711al.mjs.map +1 -0
  732. package/dist/errors-CwYHYcWF.mjs +502 -0
  733. package/dist/errors-CwYHYcWF.mjs.map +1 -0
  734. package/dist/escape-YSAGQRHa.mjs +9 -0
  735. package/dist/escape-YSAGQRHa.mjs.map +1 -0
  736. package/dist/fence-C3MLClBo.mjs +162 -0
  737. package/dist/fence-C3MLClBo.mjs.map +1 -0
  738. package/dist/field-defs-cache-Cpk0eFsQ.mjs +79 -0
  739. package/dist/field-defs-cache-Cpk0eFsQ.mjs.map +1 -0
  740. package/dist/field-map-6o9hPcRl.mjs +84 -0
  741. package/dist/field-map-6o9hPcRl.mjs.map +1 -0
  742. package/dist/focal-point-Cup37tLI.mjs +23 -0
  743. package/dist/focal-point-Cup37tLI.mjs.map +1 -0
  744. package/dist/fts-manager-B3iLXCGz.mjs +500 -0
  745. package/dist/fts-manager-B3iLXCGz.mjs.map +1 -0
  746. package/dist/gc-D24C-KP7.mjs +62 -0
  747. package/dist/gc-D24C-KP7.mjs.map +1 -0
  748. package/dist/hash-SY9Nq5FH.mjs +37 -0
  749. package/dist/hash-SY9Nq5FH.mjs.map +1 -0
  750. package/dist/hook-result-BU5rI-6M.d.mts +31 -0
  751. package/dist/hook-result-BU5rI-6M.d.mts.map +1 -0
  752. package/dist/hook-result-CO4E3zDv.mjs +3854 -0
  753. package/dist/hook-result-CO4E3zDv.mjs.map +1 -0
  754. package/dist/hreflang-Bzvlo9Ci.mjs +105 -0
  755. package/dist/hreflang-Bzvlo9Ci.mjs.map +1 -0
  756. package/dist/hreflang-Ds0WbBOu.d.mts +51 -0
  757. package/dist/hreflang-Ds0WbBOu.d.mts.map +1 -0
  758. package/dist/http-route-dispatch-BsjkWBZF.mjs +348 -0
  759. package/dist/http-route-dispatch-BsjkWBZF.mjs.map +1 -0
  760. package/dist/identity-CahxkBZC.mjs +35 -0
  761. package/dist/identity-CahxkBZC.mjs.map +1 -0
  762. package/dist/index-BauU0yTw.d.mts +261 -0
  763. package/dist/index-BauU0yTw.d.mts.map +1 -0
  764. package/dist/index.d.mts +26 -24
  765. package/dist/index.mjs +2111 -121
  766. package/dist/index.mjs.map +1 -0
  767. package/dist/init-lock-Dn7efXfy.mjs +56 -0
  768. package/dist/init-lock-Dn7efXfy.mjs.map +1 -0
  769. package/dist/install-finalization-CIl610wT.mjs +58 -0
  770. package/dist/install-finalization-CIl610wT.mjs.map +1 -0
  771. package/dist/json-recordset-CrS6ZqMk.mjs +12 -0
  772. package/dist/json-recordset-CrS6ZqMk.mjs.map +1 -0
  773. package/dist/json-schema-CBcJlGcY.mjs +15 -0
  774. package/dist/json-schema-CBcJlGcY.mjs.map +1 -0
  775. package/dist/keys-DJ62Wt5b.mjs +61 -0
  776. package/dist/keys-DJ62Wt5b.mjs.map +1 -0
  777. package/dist/kinds-D7_f3Qu3.mjs +974 -0
  778. package/dist/kinds-D7_f3Qu3.mjs.map +1 -0
  779. package/dist/lifecycle-DPCkpFHV.mjs +49 -0
  780. package/dist/lifecycle-DPCkpFHV.mjs.map +1 -0
  781. package/dist/limits-Bv6mXNM-.mjs +44 -0
  782. package/dist/limits-Bv6mXNM-.mjs.map +1 -0
  783. package/dist/load-r9P0fsRH.mjs +36 -0
  784. package/dist/load-r9P0fsRH.mjs.map +1 -0
  785. package/dist/loader-CSEfTKzr.mjs +1537 -0
  786. package/dist/loader-CSEfTKzr.mjs.map +1 -0
  787. package/dist/loops-BxzrcxPO.mjs +217 -0
  788. package/dist/loops-BxzrcxPO.mjs.map +1 -0
  789. package/dist/manifest-builder-BLWqITXR.mjs +196 -0
  790. package/dist/manifest-builder-BLWqITXR.mjs.map +1 -0
  791. package/dist/manifest-schema-BRpk5V7x.mjs +497 -0
  792. package/dist/manifest-schema-BRpk5V7x.mjs.map +1 -0
  793. package/dist/marketplace-5YFgYPVr.mjs +257 -0
  794. package/dist/marketplace-5YFgYPVr.mjs.map +1 -0
  795. package/dist/marketplace-zPVE4UY5.mjs +965 -0
  796. package/dist/marketplace-zPVE4UY5.mjs.map +1 -0
  797. package/dist/media/image-endpoint.d.mts.map +1 -1
  798. package/dist/media/image-endpoint.mjs +2 -1
  799. package/dist/media/image-endpoint.mjs.map +1 -1
  800. package/dist/media/index.d.mts +10 -5
  801. package/dist/media/index.d.mts.map +1 -1
  802. package/dist/media/index.mjs +4 -4
  803. package/dist/media/index.mjs.map +1 -1
  804. package/dist/media/local-runtime.d.mts +17 -14
  805. package/dist/media/local-runtime.d.mts.map +1 -1
  806. package/dist/media/local-runtime.mjs +3 -20
  807. package/dist/media/local-runtime.mjs.map +1 -1
  808. package/dist/media-C5fg1Xte.d.mts +203 -0
  809. package/dist/media-C5fg1Xte.d.mts.map +1 -0
  810. package/dist/media-CPETKjop.mjs +424 -0
  811. package/dist/media-CPETKjop.mjs.map +1 -0
  812. package/dist/media-Cid3xIHk.mjs +294 -0
  813. package/dist/media-Cid3xIHk.mjs.map +1 -0
  814. package/dist/media-DJaAAYI2.mjs +2805 -0
  815. package/dist/media-DJaAAYI2.mjs.map +1 -0
  816. package/dist/media-allowlist-B7JwNf-U.mjs +75 -0
  817. package/dist/media-allowlist-B7JwNf-U.mjs.map +1 -0
  818. package/dist/media-folders-BI7B7XUM.mjs +210 -0
  819. package/dist/media-folders-BI7B7XUM.mjs.map +1 -0
  820. package/dist/media-url-xWuPVfqO.mjs +43 -0
  821. package/dist/media-url-xWuPVfqO.mjs.map +1 -0
  822. package/dist/media-usage-SwtWPxy4.mjs +282 -0
  823. package/dist/media-usage-SwtWPxy4.mjs.map +1 -0
  824. package/dist/media-usage-activation-BTa1H4wE.mjs +78 -0
  825. package/dist/media-usage-activation-BTa1H4wE.mjs.map +1 -0
  826. package/dist/media-usage-work-BxHWfbKq.mjs +1036 -0
  827. package/dist/media-usage-work-BxHWfbKq.mjs.map +1 -0
  828. package/dist/media-usage-work-DYenZS8y.mjs +151 -0
  829. package/dist/media-usage-work-DYenZS8y.mjs.map +1 -0
  830. package/dist/menu-FtSf33fF.mjs +420 -0
  831. package/dist/menu-FtSf33fF.mjs.map +1 -0
  832. package/dist/menus--MSfZ5Eu.mjs +433 -0
  833. package/dist/menus--MSfZ5Eu.mjs.map +1 -0
  834. package/dist/menus-C8h6Jtpu.mjs +92 -0
  835. package/dist/menus-C8h6Jtpu.mjs.map +1 -0
  836. package/dist/menus-CpFAi_LK.mjs +434 -0
  837. package/dist/menus-CpFAi_LK.mjs.map +1 -0
  838. package/dist/migrations/index.d.mts +1 -1
  839. package/dist/migrations/index.mjs +2 -6
  840. package/dist/mime-Dx6aHTsR.mjs +82 -0
  841. package/dist/mime-Dx6aHTsR.mjs.map +1 -0
  842. package/dist/mode-D6Qg_-2J.mjs +23 -0
  843. package/dist/mode-D6Qg_-2J.mjs.map +1 -0
  844. package/dist/node-sqlite-compat-DvYkqx7Q.mjs +63 -0
  845. package/dist/node-sqlite-compat-DvYkqx7Q.mjs.map +1 -0
  846. package/dist/normalize-qcU0SKGf.mjs +220 -0
  847. package/dist/normalize-qcU0SKGf.mjs.map +1 -0
  848. package/dist/oauth-authorization-CBxtOboy.mjs +287 -0
  849. package/dist/oauth-authorization-CBxtOboy.mjs.map +1 -0
  850. package/dist/oauth-clients-HLGHmHqI.mjs +266 -0
  851. package/dist/oauth-clients-HLGHmHqI.mjs.map +1 -0
  852. package/dist/oauth-state-store-B4YAveSb.mjs +80 -0
  853. package/dist/oauth-state-store-B4YAveSb.mjs.map +1 -0
  854. package/dist/oauth-user-lookup-CTYMaKlq.mjs +26 -0
  855. package/dist/oauth-user-lookup-CTYMaKlq.mjs.map +1 -0
  856. package/dist/object-cache/memory.d.mts +1 -1
  857. package/dist/object-cache-DeATK4vw.mjs +805 -0
  858. package/dist/object-cache-DeATK4vw.mjs.map +1 -0
  859. package/dist/options-BJZMHnpx.d.mts +81 -0
  860. package/dist/options-BJZMHnpx.d.mts.map +1 -0
  861. package/dist/options-CMocxAku.mjs +208 -0
  862. package/dist/options-CMocxAku.mjs.map +1 -0
  863. package/dist/ownership-46c5NS0I.mjs +12 -0
  864. package/dist/ownership-46c5NS0I.mjs.map +1 -0
  865. package/dist/page/index.d.mts +2 -2
  866. package/dist/page/index.d.mts.map +1 -1
  867. package/dist/page/index.mjs +23 -27
  868. package/dist/page/index.mjs.map +1 -1
  869. package/dist/parse-B1E5cdyD.mjs +82 -0
  870. package/dist/parse-B1E5cdyD.mjs.map +1 -0
  871. package/dist/parse-Clt6wmpy.d.mts +178 -0
  872. package/dist/parse-Clt6wmpy.d.mts.map +1 -0
  873. package/dist/parts-CMwESQ6e.mjs +68 -0
  874. package/dist/parts-CMwESQ6e.mjs.map +1 -0
  875. package/dist/passkey-config-DiVZI-cx.mjs +46 -0
  876. package/dist/passkey-config-DiVZI-cx.mjs.map +1 -0
  877. package/dist/paths-NrYImb_h.mjs +77 -0
  878. package/dist/paths-NrYImb_h.mjs.map +1 -0
  879. package/dist/patterns-BxMSQThP.mjs +174 -0
  880. package/dist/patterns-BxMSQThP.mjs.map +1 -0
  881. package/dist/placeholder-B0vI-EQ9.d.mts +316 -0
  882. package/dist/placeholder-B0vI-EQ9.d.mts.map +1 -0
  883. package/dist/plan-CSb3BdFS.mjs +135 -0
  884. package/dist/plan-CSb3BdFS.mjs.map +1 -0
  885. package/dist/plugin-settings-HdYYRFi3.mjs +162 -0
  886. package/dist/plugin-settings-HdYYRFi3.mjs.map +1 -0
  887. package/dist/plugin-test-runtime.d.mts +24 -15
  888. package/dist/plugin-test-runtime.d.mts.map +1 -1
  889. package/dist/plugin-test-runtime.mjs +11 -127
  890. package/dist/plugin-tool-name-CCXxYq3K.mjs +27 -0
  891. package/dist/plugin-tool-name-CCXxYq3K.mjs.map +1 -0
  892. package/dist/plugin-types.d.mts +2 -2
  893. package/dist/plugin-utils.d.mts +15 -12
  894. package/dist/plugin-utils.d.mts.map +1 -1
  895. package/dist/plugins/adapt-sandbox-entry.d.mts +15 -12
  896. package/dist/plugins/adapt-sandbox-entry.d.mts.map +1 -1
  897. package/dist/plugins/adapt-sandbox-entry.mjs +6 -4
  898. package/dist/plugins/adapt-sandbox-entry.mjs.map +1 -1
  899. package/dist/plugins/host.d.mts +13 -6
  900. package/dist/plugins/host.d.mts.map +1 -0
  901. package/dist/plugins/host.mjs +10 -63
  902. package/dist/plugins-Bc70Xs37.mjs +261 -0
  903. package/dist/plugins-Bc70Xs37.mjs.map +1 -0
  904. package/dist/policy-C-ngDrxa.mjs +56 -0
  905. package/dist/policy-C-ngDrxa.mjs.map +1 -0
  906. package/dist/portable-text-T17rOqF7.mjs +454 -0
  907. package/dist/portable-text-T17rOqF7.mjs.map +1 -0
  908. package/dist/protocol-CmSX4cXv.d.mts +65 -0
  909. package/dist/protocol-CmSX4cXv.d.mts.map +1 -0
  910. package/dist/public-plugin-api-routes-_xsWTlwE.mjs +316 -0
  911. package/dist/public-plugin-api-routes-_xsWTlwE.mjs.map +1 -0
  912. package/dist/public-submission-ui3pFYtq.mjs +253 -0
  913. package/dist/public-submission-ui3pFYtq.mjs.map +1 -0
  914. package/dist/public-url-DMRZPAiW.mjs +123 -0
  915. package/dist/public-url-DMRZPAiW.mjs.map +1 -0
  916. package/dist/query-C1K9PzUc.mjs +41 -0
  917. package/dist/query-C1K9PzUc.mjs.map +1 -0
  918. package/dist/query-DdmHrvie.mjs +1201 -0
  919. package/dist/query-DdmHrvie.mjs.map +1 -0
  920. package/dist/query-EVjg8-Bq.mjs +37 -0
  921. package/dist/query-EVjg8-Bq.mjs.map +1 -0
  922. package/dist/range-BaF0521t.mjs +51 -0
  923. package/dist/range-BaF0521t.mjs.map +1 -0
  924. package/dist/rate-limit-6MngP0_m.mjs +127 -0
  925. package/dist/rate-limit-6MngP0_m.mjs.map +1 -0
  926. package/dist/receipt-BFm5eaN7.mjs +43 -0
  927. package/dist/receipt-BFm5eaN7.mjs.map +1 -0
  928. package/dist/redirect-ChcHI1KC.mjs +466 -0
  929. package/dist/redirect-ChcHI1KC.mjs.map +1 -0
  930. package/dist/redirect-EpidEf_5.mjs +19 -0
  931. package/dist/redirect-EpidEf_5.mjs.map +1 -0
  932. package/dist/redirect-paths-B9cXh9Wv.mjs +36 -0
  933. package/dist/redirect-paths-B9cXh9Wv.mjs.map +1 -0
  934. package/dist/redirects-D3zHoxhn.mjs +446 -0
  935. package/dist/redirects-D3zHoxhn.mjs.map +1 -0
  936. package/dist/redirects-dFPJ0HrD.mjs +148 -0
  937. package/dist/redirects-dFPJ0HrD.mjs.map +1 -0
  938. package/dist/registry/testing.mjs +2 -3
  939. package/dist/registry/testing.mjs.map +1 -1
  940. package/dist/registry-CDzYrAFY.mjs +6074 -0
  941. package/dist/registry-CDzYrAFY.mjs.map +1 -0
  942. package/dist/registry-Cf9vkVxW.mjs +1449 -0
  943. package/dist/registry-Cf9vkVxW.mjs.map +1 -0
  944. package/dist/registry-mZi_lxtT.mjs +755 -0
  945. package/dist/registry-mZi_lxtT.mjs.map +1 -0
  946. package/dist/relations-Eyop_U4o.mjs +798 -0
  947. package/dist/relations-Eyop_U4o.mjs.map +1 -0
  948. package/dist/request-cache-BYMs-BGX.mjs +104 -0
  949. package/dist/request-cache-BYMs-BGX.mjs.map +1 -0
  950. package/dist/request-context.d.mts +16 -3
  951. package/dist/request-context.d.mts.map +1 -1
  952. package/dist/request-context.mjs +22 -1
  953. package/dist/request-context.mjs.map +1 -1
  954. package/dist/request-meta-DsSkOdO0.mjs +141 -0
  955. package/dist/request-meta-DsSkOdO0.mjs.map +1 -0
  956. package/dist/resolve-Z5YK_6ew.mjs +199 -0
  957. package/dist/resolve-Z5YK_6ew.mjs.map +1 -0
  958. package/dist/resolve-s7ANHtFx.mjs +92 -0
  959. package/dist/resolve-s7ANHtFx.mjs.map +1 -0
  960. package/dist/rev-B6HS7337.mjs +50 -0
  961. package/dist/rev-B6HS7337.mjs.map +1 -0
  962. package/dist/revision-D7EedSdU.mjs +503 -0
  963. package/dist/revision-D7EedSdU.mjs.map +1 -0
  964. package/dist/rooms/index.d.mts +48 -0
  965. package/dist/rooms/index.d.mts.map +1 -0
  966. package/dist/rooms/index.mjs +6 -0
  967. package/dist/rooms/node/index.d.mts +25 -0
  968. package/dist/rooms/node/index.d.mts.map +1 -0
  969. package/dist/rooms/node/index.mjs +583 -0
  970. package/dist/rooms/node/index.mjs.map +1 -0
  971. package/dist/rooms/notifications.d.mts +47 -0
  972. package/dist/rooms/notifications.d.mts.map +1 -0
  973. package/dist/rooms/notifications.mjs +125 -0
  974. package/dist/rooms/notifications.mjs.map +1 -0
  975. package/dist/rooms/room.d.mts +76 -0
  976. package/dist/rooms/room.d.mts.map +1 -0
  977. package/dist/rooms/room.mjs +1257 -0
  978. package/dist/rooms/room.mjs.map +1 -0
  979. package/dist/rooms/site.d.mts +23 -0
  980. package/dist/rooms/site.d.mts.map +1 -0
  981. package/dist/rooms/site.mjs +146 -0
  982. package/dist/rooms/site.mjs.map +1 -0
  983. package/dist/rooms-CSNLTJsG.mjs +331 -0
  984. package/dist/rooms-CSNLTJsG.mjs.map +1 -0
  985. package/dist/rooms-CVsLla78.mjs +169 -0
  986. package/dist/rooms-CVsLla78.mjs.map +1 -0
  987. package/dist/rooms-CyXG83RZ.d.mts +4653 -0
  988. package/dist/rooms-CyXG83RZ.d.mts.map +1 -0
  989. package/dist/route-cache-CBpXPq-N.mjs +30 -0
  990. package/dist/route-cache-CBpXPq-N.mjs.map +1 -0
  991. package/dist/route-cache-DkhMwAIC.mjs +20 -0
  992. package/dist/route-cache-DkhMwAIC.mjs.map +1 -0
  993. package/dist/route-wire-DKSTaEz_.mjs +197 -0
  994. package/dist/route-wire-DKSTaEz_.mjs.map +1 -0
  995. package/dist/routes-QcHRiebw.mjs +272 -0
  996. package/dist/routes-QcHRiebw.mjs.map +1 -0
  997. package/dist/runner-4BfB04Rg.mjs +6950 -0
  998. package/dist/runner-4BfB04Rg.mjs.map +1 -0
  999. package/dist/runner-CAHS_KER.d.mts +79 -0
  1000. package/dist/runner-CAHS_KER.d.mts.map +1 -0
  1001. package/dist/runtime-holder-0g6pqbzx.mjs +36 -0
  1002. package/dist/runtime-holder-0g6pqbzx.mjs.map +1 -0
  1003. package/dist/runtime.d.mts +16 -13
  1004. package/dist/runtime.d.mts.map +1 -1
  1005. package/dist/runtime.mjs +1 -8
  1006. package/dist/runtime.mjs.map +1 -1
  1007. package/dist/scheduler-health-C5HEg2Yl.mjs +31 -0
  1008. package/dist/scheduler-health-C5HEg2Yl.mjs.map +1 -0
  1009. package/dist/schema/project-env-types.mjs +7 -55
  1010. package/dist/schema/project-env-types.mjs.map +1 -1
  1011. package/dist/schema-DS7ooMmp.mjs +13 -0
  1012. package/dist/schema-DS7ooMmp.mjs.map +1 -0
  1013. package/dist/schema-Mjtj7n1t.mjs +815 -0
  1014. package/dist/schema-Mjtj7n1t.mjs.map +1 -0
  1015. package/dist/scopes-BaR6WUyq.mjs +34 -0
  1016. package/dist/scopes-BaR6WUyq.mjs.map +1 -0
  1017. package/dist/search-B9RFgr0N.mjs +450 -0
  1018. package/dist/search-B9RFgr0N.mjs.map +1 -0
  1019. package/dist/secrets-C4UrjPiG.mjs +369 -0
  1020. package/dist/secrets-C4UrjPiG.mjs.map +1 -0
  1021. package/dist/sections-Bfa0oF8Q.mjs +129 -0
  1022. package/dist/sections-Bfa0oF8Q.mjs.map +1 -0
  1023. package/dist/sections-Bn2C6we7.mjs +222 -0
  1024. package/dist/sections-Bn2C6we7.mjs.map +1 -0
  1025. package/dist/seed/index.d.mts +3 -3
  1026. package/dist/seed/index.mjs +6 -54
  1027. package/dist/seo/index.d.mts +8 -6
  1028. package/dist/seo/index.d.mts.map +1 -1
  1029. package/dist/seo/index.mjs +10 -41
  1030. package/dist/seo/index.mjs.map +1 -1
  1031. package/dist/seo-DPW6k5_-.mjs +188 -0
  1032. package/dist/seo-DPW6k5_-.mjs.map +1 -0
  1033. package/dist/service-B4mHMku9.mjs +150 -0
  1034. package/dist/service-B4mHMku9.mjs.map +1 -0
  1035. package/dist/session-user-CF2jNfj7.mjs +61 -0
  1036. package/dist/session-user-CF2jNfj7.mjs.map +1 -0
  1037. package/dist/settings-4r88LLIM.mjs +66 -0
  1038. package/dist/settings-4r88LLIM.mjs.map +1 -0
  1039. package/dist/settings-BB2xxz3Y.mjs +74 -0
  1040. package/dist/settings-BB2xxz3Y.mjs.map +1 -0
  1041. package/dist/settings-BTkGl-bX.mjs +413 -0
  1042. package/dist/settings-BTkGl-bX.mjs.map +1 -0
  1043. package/dist/settings-y8Jx8b7g.mjs +157 -0
  1044. package/dist/settings-y8Jx8b7g.mjs.map +1 -0
  1045. package/dist/setup-complete-BGRiC59t.mjs +65 -0
  1046. package/dist/setup-complete-BGRiC59t.mjs.map +1 -0
  1047. package/dist/setup-nonce-D43FsOgZ.mjs +25 -0
  1048. package/dist/setup-nonce-D43FsOgZ.mjs.map +1 -0
  1049. package/dist/single-flight-cache-BCP1Tvcm.mjs +104 -0
  1050. package/dist/single-flight-cache-BCP1Tvcm.mjs.map +1 -0
  1051. package/dist/site-domain-CFX7g6ik.mjs +131 -0
  1052. package/dist/site-domain-CFX7g6ik.mjs.map +1 -0
  1053. package/dist/site-settings-C0D9fv7e.mjs +50 -0
  1054. package/dist/site-settings-C0D9fv7e.mjs.map +1 -0
  1055. package/dist/site-title-C0JVN6en.mjs +14 -0
  1056. package/dist/site-title-C0JVN6en.mjs.map +1 -0
  1057. package/dist/site-url-DzVnHJ8j.mjs +45 -0
  1058. package/dist/site-url-DzVnHJ8j.mjs.map +1 -0
  1059. package/dist/sitemap-name-Ja_Cvwx9.mjs +26 -0
  1060. package/dist/sitemap-name-Ja_Cvwx9.mjs.map +1 -0
  1061. package/dist/slug-CO2jtUda.mjs +16 -0
  1062. package/dist/slug-CO2jtUda.mjs.map +1 -0
  1063. package/dist/slugify-sxuydlHd.mjs +22 -0
  1064. package/dist/slugify-sxuydlHd.mjs.map +1 -0
  1065. package/dist/snapshot-C9OWUtFr.mjs +466 -0
  1066. package/dist/snapshot-C9OWUtFr.mjs.map +1 -0
  1067. package/dist/snapshot-CR5tan8p.mjs +184 -0
  1068. package/dist/snapshot-CR5tan8p.mjs.map +1 -0
  1069. package/dist/ssrf-Lj1KZxYt.mjs +406 -0
  1070. package/dist/ssrf-Lj1KZxYt.mjs.map +1 -0
  1071. package/dist/stage-ChbGIslu.mjs +662 -0
  1072. package/dist/stage-ChbGIslu.mjs.map +1 -0
  1073. package/dist/staged-BN8pRZwX.mjs +686 -0
  1074. package/dist/staged-BN8pRZwX.mjs.map +1 -0
  1075. package/dist/state-DtcE0eN3.mjs +178 -0
  1076. package/dist/state-DtcE0eN3.mjs.map +1 -0
  1077. package/dist/status-vvme29qV.mjs +30 -0
  1078. package/dist/status-vvme29qV.mjs.map +1 -0
  1079. package/dist/storage/local.d.mts +1 -1
  1080. package/dist/storage/local.mjs +2 -2
  1081. package/dist/storage/s3.d.mts +1 -1
  1082. package/dist/storage/s3.mjs +1 -1
  1083. package/dist/storage-query-BDUX3Cef.d.mts +1608 -0
  1084. package/dist/storage-query-BDUX3Cef.d.mts.map +1 -0
  1085. package/dist/tar-CAvEHFbE.mjs +449 -0
  1086. package/dist/tar-CAvEHFbE.mjs.map +1 -0
  1087. package/dist/target-BM_6fT9m.mjs +27 -0
  1088. package/dist/target-BM_6fT9m.mjs.map +1 -0
  1089. package/dist/taxonomies-BMuFLd53.mjs +722 -0
  1090. package/dist/taxonomies-BMuFLd53.mjs.map +1 -0
  1091. package/dist/taxonomies-ClkYcmcH.mjs +937 -0
  1092. package/dist/taxonomies-ClkYcmcH.mjs.map +1 -0
  1093. package/dist/taxonomy-s1GcBCRo.mjs +593 -0
  1094. package/dist/taxonomy-s1GcBCRo.mjs.map +1 -0
  1095. package/dist/tokens-Cpm6FIKJ.mjs +171 -0
  1096. package/dist/tokens-Cpm6FIKJ.mjs.map +1 -0
  1097. package/dist/transaction-SKrr6u84.mjs +44 -0
  1098. package/dist/transaction-SKrr6u84.mjs.map +1 -0
  1099. package/dist/transfer-B3CsI5MG.mjs +8963 -0
  1100. package/dist/transfer-B3CsI5MG.mjs.map +1 -0
  1101. package/dist/transfer-DqUiK3ca.mjs +166 -0
  1102. package/dist/transfer-DqUiK3ca.mjs.map +1 -0
  1103. package/dist/transfer-download-CWPfhL91.mjs +33 -0
  1104. package/dist/transfer-download-CWPfhL91.mjs.map +1 -0
  1105. package/dist/transformations-ClH4dJeM.mjs +196 -0
  1106. package/dist/transformations-ClH4dJeM.mjs.map +1 -0
  1107. package/dist/transport-C6Ps8ejN.mjs +144 -0
  1108. package/dist/transport-C6Ps8ejN.mjs.map +1 -0
  1109. package/dist/transport-D4hWYmO_.d.mts +42 -0
  1110. package/dist/transport-D4hWYmO_.d.mts.map +1 -0
  1111. package/dist/trusted-proxy-CWX1sqgb.mjs +51 -0
  1112. package/dist/trusted-proxy-CWX1sqgb.mjs.map +1 -0
  1113. package/dist/turnstile-B6zM50Mh.mjs +58 -0
  1114. package/dist/turnstile-B6zM50Mh.mjs.map +1 -0
  1115. package/dist/types-BBH-w_KS.mjs +133 -0
  1116. package/dist/types-BBH-w_KS.mjs.map +1 -0
  1117. package/dist/types-Ba3bWb9D.mjs +37 -0
  1118. package/dist/types-Ba3bWb9D.mjs.map +1 -0
  1119. package/dist/types-BmBK2cqf.mjs +201 -0
  1120. package/dist/types-BmBK2cqf.mjs.map +1 -0
  1121. package/dist/types-C0M6z2A4.mjs +16 -0
  1122. package/dist/types-C0M6z2A4.mjs.map +1 -0
  1123. package/dist/types-CG1dR_Cm.d.mts +934 -0
  1124. package/dist/types-CG1dR_Cm.d.mts.map +1 -0
  1125. package/dist/types-CImd8MBY.d.mts +1756 -0
  1126. package/dist/types-CImd8MBY.d.mts.map +1 -0
  1127. package/dist/types-CML-oGr6.d.mts +293 -0
  1128. package/dist/types-CML-oGr6.d.mts.map +1 -0
  1129. package/dist/types-CZO9f_vJ.d.mts +381 -0
  1130. package/dist/types-CZO9f_vJ.d.mts.map +1 -0
  1131. package/dist/types-CpFfDrGH.mjs +18 -0
  1132. package/dist/types-CpFfDrGH.mjs.map +1 -0
  1133. package/dist/types-D2zSjG0c.mjs +63 -0
  1134. package/dist/types-D2zSjG0c.mjs.map +1 -0
  1135. package/dist/types-DLKviL1s.d.mts +93 -0
  1136. package/dist/types-DLKviL1s.d.mts.map +1 -0
  1137. package/dist/types-Df0R58Wu.mjs +77 -0
  1138. package/dist/types-Df0R58Wu.mjs.map +1 -0
  1139. package/dist/types-DwNwhyWP.d.mts +227 -0
  1140. package/dist/types-DwNwhyWP.d.mts.map +1 -0
  1141. package/dist/types-DwZgl0Zn.d.mts +366 -0
  1142. package/dist/types-DwZgl0Zn.d.mts.map +1 -0
  1143. package/dist/types-Dyb_OuSw.d.mts +125 -0
  1144. package/dist/types-Dyb_OuSw.d.mts.map +1 -0
  1145. package/dist/types-iOnPkHRk.d.mts +209 -0
  1146. package/dist/types-iOnPkHRk.d.mts.map +1 -0
  1147. package/dist/ui-comments.d.mts +66 -0
  1148. package/dist/ui-search.d.mts +75 -0
  1149. package/dist/ui-webmcp-search.d.mts +29 -0
  1150. package/dist/ui.d.mts +576 -0
  1151. package/dist/upload-attempts-5Ot7-vsw.mjs +32 -0
  1152. package/dist/upload-attempts-5Ot7-vsw.mjs.map +1 -0
  1153. package/dist/url-BVdd-tah.mjs +104 -0
  1154. package/dist/url-BVdd-tah.mjs.map +1 -0
  1155. package/dist/url-ZCjpMO-q.mjs +74 -0
  1156. package/dist/url-ZCjpMO-q.mjs.map +1 -0
  1157. package/dist/url-pattern-BQT-sGmD.mjs +41 -0
  1158. package/dist/url-pattern-BQT-sGmD.mjs.map +1 -0
  1159. package/dist/urls-Cq_hUk4P.mjs +79 -0
  1160. package/dist/urls-Cq_hUk4P.mjs.map +1 -0
  1161. package/dist/user-C4km6fox.mjs +184 -0
  1162. package/dist/user-C4km6fox.mjs.map +1 -0
  1163. package/dist/utils-Cpo0_V09.d.mts +374 -0
  1164. package/dist/utils-Cpo0_V09.d.mts.map +1 -0
  1165. package/dist/utils-DMDmdhU3.mjs +450 -0
  1166. package/dist/utils-DMDmdhU3.mjs.map +1 -0
  1167. package/dist/validate-BNupiQtz.mjs +524 -0
  1168. package/dist/validate-BNupiQtz.mjs.map +1 -0
  1169. package/dist/validate-DBfkJa3O.d.mts +472 -0
  1170. package/dist/validate-DBfkJa3O.d.mts.map +1 -0
  1171. package/dist/validation-W_efZFgP.mjs +204 -0
  1172. package/dist/validation-W_efZFgP.mjs.map +1 -0
  1173. package/dist/version-C61rw8-y.mjs +9 -0
  1174. package/dist/version-C61rw8-y.mjs.map +1 -0
  1175. package/dist/version-DhGLeLRo.mjs +7 -0
  1176. package/dist/version-DhGLeLRo.mjs.map +1 -0
  1177. package/dist/version-eqLBDtcz.mjs +49 -0
  1178. package/dist/version-eqLBDtcz.mjs.map +1 -0
  1179. package/dist/video-My3h7vwE.mjs +18 -0
  1180. package/dist/video-My3h7vwE.mjs.map +1 -0
  1181. package/dist/virtual-modules-BZKqvjRC.mjs +568 -0
  1182. package/dist/virtual-modules-BZKqvjRC.mjs.map +1 -0
  1183. package/dist/widgets-DAdni19y.mjs +134 -0
  1184. package/dist/widgets-DAdni19y.mjs.map +1 -0
  1185. package/dist/wxr-DDPJOgkM.mjs +1054 -0
  1186. package/dist/wxr-DDPJOgkM.mjs.map +1 -0
  1187. package/dist/wxr-taxonomies-B0U2fJgs.mjs +735 -0
  1188. package/dist/wxr-taxonomies-B0U2fJgs.mjs.map +1 -0
  1189. package/dist/wxr-taxonomies-CyP2k4-Q.d.mts +34 -0
  1190. package/dist/wxr-taxonomies-CyP2k4-Q.d.mts.map +1 -0
  1191. package/dist/zod-generator-ChRSYUix.mjs +425 -0
  1192. package/dist/zod-generator-ChRSYUix.mjs.map +1 -0
  1193. package/package.json +81 -33
  1194. package/src/api/content-save.ts +281 -0
  1195. package/src/api/error.ts +6 -2
  1196. package/src/api/errors.ts +11 -0
  1197. package/src/api/handlers/content.ts +92 -26
  1198. package/src/api/handlers/device-flow.ts +1 -3
  1199. package/src/api/handlers/entry-lock.ts +69 -14
  1200. package/src/api/handlers/marketplace.ts +8 -2
  1201. package/src/api/handlers/media-allowlist.ts +56 -0
  1202. package/src/api/handlers/media-upload.ts +9 -1
  1203. package/src/api/handlers/menus.ts +3 -3
  1204. package/src/api/handlers/oauth-authorization.ts +1 -3
  1205. package/src/api/handlers/plugins.ts +4 -4
  1206. package/src/api/handlers/registry.ts +33 -21
  1207. package/src/api/handlers/relations.ts +20 -4
  1208. package/src/api/handlers/revision.ts +29 -0
  1209. package/src/api/handlers/rooms.ts +233 -0
  1210. package/src/api/handlers/site-domain.ts +1 -1
  1211. package/src/api/handlers/snapshot.ts +90 -30
  1212. package/src/api/handlers/staged-references.ts +14 -0
  1213. package/src/api/list-preconditions.ts +101 -0
  1214. package/src/api/openapi/document.ts +5 -5
  1215. package/src/api/parse.ts +3 -2
  1216. package/src/api/public-url.ts +21 -0
  1217. package/src/api/schemas/auth.ts +57 -1
  1218. package/src/api/schemas/content.ts +14 -0
  1219. package/src/api/schemas/entry-lock.ts +6 -1
  1220. package/src/api/schemas/import.ts +6 -0
  1221. package/src/api/schemas/index.ts +1 -0
  1222. package/src/api/schemas/media.ts +20 -0
  1223. package/src/api/schemas/rooms.ts +27 -0
  1224. package/src/api/schemas/schema.ts +9 -1
  1225. package/src/api/schemas/settings.ts +2 -0
  1226. package/src/api/site-title.ts +13 -0
  1227. package/src/api/types.ts +3 -0
  1228. package/src/astro/integration/admin-nav.ts +52 -0
  1229. package/src/astro/integration/index.ts +26 -5
  1230. package/src/astro/integration/routes.ts +15 -5
  1231. package/src/astro/integration/runtime.ts +46 -0
  1232. package/src/astro/integration/shims/use-sync-external-store-with-selector.js +2 -0
  1233. package/src/astro/integration/shims/use-sync-external-store.js +4 -1
  1234. package/src/astro/integration/virtual-modules.ts +80 -17
  1235. package/src/astro/integration/vite-config.ts +136 -0
  1236. package/src/astro/middleware/auth.ts +53 -18
  1237. package/src/astro/middleware/media-usage-write-fence.ts +4 -0
  1238. package/src/astro/middleware/redirect.ts +11 -1
  1239. package/src/astro/middleware/request-context.ts +57 -27
  1240. package/src/astro/middleware.ts +44 -29
  1241. package/src/astro/routes/PluginRegistry.tsx +21 -17
  1242. package/src/astro/routes/api/admin/comments/[id]/status.ts +9 -1
  1243. package/src/astro/routes/api/admin/comments/[id].ts +10 -3
  1244. package/src/astro/routes/api/admin/comments/bulk.ts +18 -4
  1245. package/src/astro/routes/api/admin/plugins/marketplace/[id]/install.ts +1 -1
  1246. package/src/astro/routes/api/admin/plugins/registry/install.ts +1 -1
  1247. package/src/astro/routes/api/admin/users/[id]/send-recovery.ts +9 -2
  1248. package/src/astro/routes/api/auth/dev-bypass.ts +20 -1
  1249. package/src/astro/routes/api/auth/invite/complete.ts +2 -1
  1250. package/src/astro/routes/api/auth/invite/index.ts +9 -2
  1251. package/src/astro/routes/api/auth/invite/register-options.ts +2 -1
  1252. package/src/astro/routes/api/auth/magic-link/send.ts +9 -2
  1253. package/src/astro/routes/api/auth/me.ts +38 -17
  1254. package/src/astro/routes/api/auth/oauth/[provider]/callback.ts +6 -11
  1255. package/src/astro/routes/api/auth/oauth/[provider].ts +6 -11
  1256. package/src/astro/routes/api/auth/passkey/options.ts +2 -1
  1257. package/src/astro/routes/api/auth/passkey/register/options.ts +2 -1
  1258. package/src/astro/routes/api/auth/passkey/register/verify.ts +2 -1
  1259. package/src/astro/routes/api/auth/passkey/verify.ts +2 -1
  1260. package/src/astro/routes/api/auth/signup/complete.ts +2 -1
  1261. package/src/astro/routes/api/auth/signup/request.ts +2 -1
  1262. package/src/astro/routes/api/comments/[collection]/[contentId]/index.ts +2 -2
  1263. package/src/astro/routes/api/content/[collection]/[id]/discard-draft.ts +1 -0
  1264. package/src/astro/routes/api/content/[collection]/[id]/lock.ts +6 -3
  1265. package/src/astro/routes/api/content/[collection]/[id]/preview-url.ts +6 -2
  1266. package/src/astro/routes/api/content/[collection]/[id]/revisions/editors.ts +30 -0
  1267. package/src/astro/routes/api/content/[collection]/[id]/revisions.ts +37 -1
  1268. package/src/astro/routes/api/content/[collection]/[id]/room.ts +43 -0
  1269. package/src/astro/routes/api/content/[collection]/[id]/schedule.ts +3 -1
  1270. package/src/astro/routes/api/content/[collection]/[id]/terms/[taxonomy].ts +54 -2
  1271. package/src/astro/routes/api/content/[collection]/[id].ts +22 -73
  1272. package/src/astro/routes/api/import/wordpress/analyze.ts +16 -29
  1273. package/src/astro/routes/api/import/wordpress/execute.ts +193 -15
  1274. package/src/astro/routes/api/import/wordpress/media.ts +6 -1
  1275. package/src/astro/routes/api/import/wordpress/rewrite-urls.ts +9 -5
  1276. package/src/astro/routes/api/import/wordpress-plugin/execute.ts +25 -19
  1277. package/src/astro/routes/api/manifest.ts +40 -5
  1278. package/src/astro/routes/api/media/[id]/confirm.ts +42 -14
  1279. package/src/astro/routes/api/media/asset/[id]/[filename].ts +1 -0
  1280. package/src/astro/routes/api/media/file/[...key].ts +19 -4
  1281. package/src/astro/routes/api/media/upload-url.ts +1 -1
  1282. package/src/astro/routes/api/media.ts +14 -4
  1283. package/src/astro/routes/api/oauth/device/authorize.ts +0 -2
  1284. package/src/astro/routes/api/oauth/token.ts +5 -1
  1285. package/src/astro/routes/api/revisions/[revisionId]/restore.ts +1 -1
  1286. package/src/astro/routes/api/settings/domain-notify.ts +9 -2
  1287. package/src/astro/routes/api/settings/email.ts +197 -8
  1288. package/src/astro/routes/api/setup/admin-verify.ts +2 -1
  1289. package/src/astro/routes/api/setup/admin.ts +2 -1
  1290. package/src/astro/routes/api/setup/dev-bypass.ts +3 -1
  1291. package/src/astro/routes/api/setup/index.ts +5 -2
  1292. package/src/astro/routes/api/well-known/auth.ts +2 -1
  1293. package/src/astro/routes/api/widget-areas/[name]/reorder.ts +7 -1
  1294. package/src/astro/routes/api/widget-areas/[name]/widgets/[id].ts +3 -1
  1295. package/src/astro/routes/api/widget-areas/[name]/widgets.ts +2 -1
  1296. package/src/astro/routes/api/widget-areas/[name].ts +2 -1
  1297. package/src/astro/routes/api/widget-areas/index.ts +2 -1
  1298. package/src/astro/routes/robots.txt.ts +9 -10
  1299. package/src/astro/routes/sitemap-[collection].xml.ts +5 -6
  1300. package/src/astro/routes/sitemap.xml.ts +2 -6
  1301. package/src/astro/runtime-holder.ts +41 -0
  1302. package/src/astro/types.ts +46 -8
  1303. package/src/auth/api-tokens.ts +3 -0
  1304. package/src/auth/oauth-env.ts +35 -0
  1305. package/src/bylines/field-defs-cache.ts +9 -4
  1306. package/src/cleanup.ts +44 -0
  1307. package/src/cli/commands/export-seed.ts +4 -3
  1308. package/src/cli/commands/import/wordpress.ts +158 -56
  1309. package/src/cli/commands/import.ts +139 -0
  1310. package/src/cli/commands/login.ts +26 -1
  1311. package/src/cli/commands/schema.ts +2 -2
  1312. package/src/cli/commands/seed.ts +3 -3
  1313. package/src/cli/credentials.ts +58 -17
  1314. package/src/cli/index.ts +4 -1
  1315. package/src/cli/wxr/parser.ts +15 -13
  1316. package/src/client/index.ts +38 -24
  1317. package/src/client/portable-text.ts +390 -192
  1318. package/src/client/transport.ts +14 -4
  1319. package/src/comments/public-submission.ts +7 -0
  1320. package/src/comments/route-cache.ts +39 -0
  1321. package/src/components/Columns.astro +2 -4
  1322. package/src/components/CommentForm.astro +6 -0
  1323. package/src/components/Comments.astro +5 -1
  1324. package/src/components/Cover.astro +2 -4
  1325. package/src/components/EmDashHead.astro +9 -7
  1326. package/src/components/EmDashImage.astro +161 -34
  1327. package/src/components/EmDashMedia.astro +36 -31
  1328. package/src/components/Embed.astro +49 -17
  1329. package/src/components/Gallery.astro +6 -2
  1330. package/src/components/Image.astro +15 -3
  1331. package/src/components/InlinePortableTextEditor.tsx +1 -0
  1332. package/src/components/LiveSearch.astro +23 -1
  1333. package/src/components/PortableText.astro +5 -8
  1334. package/src/components/inline-bubble-menu.tsx +109 -95
  1335. package/src/components/inline-image.tsx +54 -48
  1336. package/src/components/marks/Link.astro +7 -0
  1337. package/src/components/widgets/Archives.astro +6 -2
  1338. package/src/components/widgets/Categories.astro +7 -2
  1339. package/src/components/widgets/RecentPosts.astro +23 -13
  1340. package/src/components/widgets/Search.astro +3 -1
  1341. package/src/components/widgets/Tags.astro +7 -2
  1342. package/src/config/options-schema.ts +124 -0
  1343. package/src/content/converters/video.ts +6 -65
  1344. package/src/database/dialect-helpers.ts +67 -3
  1345. package/src/database/migrations/092_plugin_kv_options.ts +93 -0
  1346. package/src/database/migrations/093_menu_item_orphans.ts +21 -0
  1347. package/src/database/migrations/094_media_usage_file_url_reindex.ts +57 -0
  1348. package/src/database/migrations/095_plugin_storage_unique_scope.ts +134 -0
  1349. package/src/database/migrations/096_revision_kind_and_editors.ts +29 -0
  1350. package/src/database/migrations/097_room_storage.ts +43 -0
  1351. package/src/database/migrations/content-sized.ts +16 -0
  1352. package/src/database/migrations/policy.ts +6 -1
  1353. package/src/database/migrations/runner.ts +37 -8
  1354. package/src/database/plugin-storage-index-name.ts +29 -0
  1355. package/src/database/repositories/byline.ts +99 -86
  1356. package/src/database/repositories/content.ts +179 -17
  1357. package/src/database/repositories/entry-locks.ts +35 -29
  1358. package/src/database/repositories/media-usage.ts +1 -1
  1359. package/src/database/repositories/media.ts +40 -0
  1360. package/src/database/repositories/menu.ts +193 -135
  1361. package/src/database/repositories/redirect.ts +116 -46
  1362. package/src/database/repositories/revision.ts +216 -20
  1363. package/src/database/repositories/seo.ts +2 -0
  1364. package/src/database/repositories/taxonomy.ts +91 -27
  1365. package/src/database/repositories/types.ts +3 -3
  1366. package/src/database/repositories/user.ts +34 -0
  1367. package/src/database/transaction.ts +23 -2
  1368. package/src/database/types.ts +24 -2
  1369. package/src/emdash-runtime.ts +1071 -247
  1370. package/src/i18n/resolve.ts +10 -0
  1371. package/src/import/index.ts +0 -12
  1372. package/src/import/menus.ts +202 -151
  1373. package/src/import/registry.ts +30 -1
  1374. package/src/import/utils.ts +15 -2
  1375. package/src/index.ts +11 -0
  1376. package/src/loader.ts +209 -115
  1377. package/src/mcp/server.ts +103 -29
  1378. package/src/media/content-disposition.ts +56 -0
  1379. package/src/media/enrich.ts +20 -4
  1380. package/src/media/image-endpoint.ts +1 -0
  1381. package/src/media/mime.ts +1 -0
  1382. package/src/media/normalize.ts +2 -0
  1383. package/src/media/placeholder.ts +4 -0
  1384. package/src/media/portable-text-file-refs.ts +98 -0
  1385. package/src/media/responsive.ts +29 -1
  1386. package/src/media/types.ts +2 -0
  1387. package/src/media/url.ts +15 -0
  1388. package/src/media/usage/content-fields.ts +2 -1
  1389. package/src/media/usage/content-snapshots.ts +111 -34
  1390. package/src/media/usage/extractor.ts +42 -8
  1391. package/src/media/usage/types.ts +5 -0
  1392. package/src/menus/index.ts +137 -25
  1393. package/src/object-cache/index.ts +402 -17
  1394. package/src/page/jsonld.ts +26 -11
  1395. package/src/plugin-test-runtime.ts +1 -0
  1396. package/src/plugins/adapt-sandbox-entry.ts +2 -0
  1397. package/src/plugins/content-policy.ts +36 -2
  1398. package/src/plugins/context.ts +17 -7
  1399. package/src/plugins/cron.ts +6 -3
  1400. package/src/plugins/define-plugin.ts +5 -1
  1401. package/src/plugins/editor-draft.ts +9 -3
  1402. package/src/plugins/email-smtp.ts +936 -0
  1403. package/src/plugins/hooks.ts +34 -8
  1404. package/src/plugins/host.ts +2 -0
  1405. package/src/plugins/http-route-dispatch.ts +3 -1
  1406. package/src/plugins/lifecycle.ts +25 -1
  1407. package/src/plugins/manager.ts +3 -0
  1408. package/src/plugins/sandbox/types.ts +10 -1
  1409. package/src/plugins/storage-indexes.ts +64 -55
  1410. package/src/plugins/types.ts +16 -1
  1411. package/src/query.ts +116 -47
  1412. package/src/redirects/cache.ts +3 -2
  1413. package/src/redirects/loops.ts +20 -4
  1414. package/src/redirects/patterns.ts +16 -0
  1415. package/src/request-context.ts +29 -1
  1416. package/src/rooms/document.ts +99 -0
  1417. package/src/rooms/hash.ts +19 -0
  1418. package/src/rooms/index.ts +28 -0
  1419. package/src/rooms/kysely-store.ts +279 -0
  1420. package/src/rooms/limits.ts +41 -0
  1421. package/src/rooms/merge.ts +115 -0
  1422. package/src/rooms/node/index.ts +30 -0
  1423. package/src/rooms/node/registry.ts +232 -0
  1424. package/src/rooms/node/signals.ts +89 -0
  1425. package/src/rooms/node/upgrades.ts +210 -0
  1426. package/src/rooms/notifications.ts +157 -0
  1427. package/src/rooms/parts.ts +74 -0
  1428. package/src/rooms/room.ts +1559 -0
  1429. package/src/rooms/site.ts +185 -0
  1430. package/src/rooms/snapshot.ts +11 -0
  1431. package/src/rooms/types.ts +298 -0
  1432. package/src/scheduled-publish.ts +18 -5
  1433. package/src/schema/registry.ts +14 -3
  1434. package/src/schema/types.ts +17 -8
  1435. package/src/search/errors.ts +22 -0
  1436. package/src/search/fts-manager.ts +26 -9
  1437. package/src/search/index.ts +2 -0
  1438. package/src/seed/apply.ts +161 -92
  1439. package/src/seed/index.ts +1 -1
  1440. package/src/seed/load.ts +9 -0
  1441. package/src/seed/types.ts +23 -14
  1442. package/src/seo/hreflang.ts +5 -4
  1443. package/src/seo/index.ts +10 -4
  1444. package/src/seo/title-field.ts +19 -0
  1445. package/src/settings/index.ts +36 -3
  1446. package/src/settings/types.ts +7 -0
  1447. package/src/taxonomies/index.ts +77 -76
  1448. package/src/transfer/analyze/target.ts +5 -0
  1449. package/src/transfer/domain.ts +23 -0
  1450. package/src/transfer/export/readers.ts +6 -2
  1451. package/src/transfer/format/columns.ts +4 -0
  1452. package/src/transfer/format/settings.ts +1 -0
  1453. package/src/transfer/import/advance.ts +12 -1
  1454. package/src/transfer/import/scaffold.ts +73 -9
  1455. package/src/transfer/import/stages.ts +53 -2
  1456. package/src/ui.ts +18 -19
  1457. package/src/utils/revalidating-cache.ts +85 -0
  1458. package/src/virtual-modules.d.ts +20 -3
  1459. package/src/visual-editing/toolbar.ts +79 -52
  1460. package/src/widgets/index.ts +27 -13
  1461. package/src/widgets/recent-posts.ts +13 -0
  1462. package/dist/action-token-B1ds4laA.mjs +0 -26
  1463. package/dist/action-token-B1ds4laA.mjs.map +0 -1
  1464. package/dist/activation-sGF9br3X.mjs +0 -387
  1465. package/dist/activation-sGF9br3X.mjs.map +0 -1
  1466. package/dist/adapters-BOMSX9PU.d.mts +0 -173
  1467. package/dist/adapters-BOMSX9PU.d.mts.map +0 -1
  1468. package/dist/after-PcEvMY_6.mjs +0 -96
  1469. package/dist/after-PcEvMY_6.mjs.map +0 -1
  1470. package/dist/allowed-origins-CovsTkm3.mjs +0 -116
  1471. package/dist/allowed-origins-CovsTkm3.mjs.map +0 -1
  1472. package/dist/api-C_LxFnOm.mjs +0 -5077
  1473. package/dist/api-C_LxFnOm.mjs.map +0 -1
  1474. package/dist/api-tokens-C7l0GUAF.mjs +0 -3
  1475. package/dist/api-tokens-DQ9Ee-vP.mjs +0 -173
  1476. package/dist/api-tokens-DQ9Ee-vP.mjs.map +0 -1
  1477. package/dist/apply-CLjfxvyH.mjs +0 -1758
  1478. package/dist/apply-CLjfxvyH.mjs.map +0 -1
  1479. package/dist/approvals-ocK89i4H.mjs +0 -460
  1480. package/dist/approvals-ocK89i4H.mjs.map +0 -1
  1481. package/dist/artifact-fetch-CgvvpoWQ.mjs +0 -659
  1482. package/dist/artifact-fetch-CgvvpoWQ.mjs.map +0 -1
  1483. package/dist/artifacts-DwOYYBQm.mjs +0 -323
  1484. package/dist/artifacts-DwOYYBQm.mjs.map +0 -1
  1485. package/dist/audit-B8XE-0UV.mjs +0 -127
  1486. package/dist/audit-B8XE-0UV.mjs.map +0 -1
  1487. package/dist/authoritative-records-LPtrIGOY.mjs +0 -5183
  1488. package/dist/authoritative-records-LPtrIGOY.mjs.map +0 -1
  1489. package/dist/authorize-CoDsRRp5.mjs +0 -74
  1490. package/dist/authorize-CoDsRRp5.mjs.map +0 -1
  1491. package/dist/backup-2Wj-hTCN.mjs +0 -246
  1492. package/dist/backup-2Wj-hTCN.mjs.map +0 -1
  1493. package/dist/base64-BQBZwXCx.mjs +0 -63
  1494. package/dist/base64-BQBZwXCx.mjs.map +0 -1
  1495. package/dist/block-types-C3gJEe7l.mjs +0 -132
  1496. package/dist/block-types-C3gJEe7l.mjs.map +0 -1
  1497. package/dist/block-values-CgbMtSGU.mjs +0 -215
  1498. package/dist/block-values-CgbMtSGU.mjs.map +0 -1
  1499. package/dist/byline-CzGZC2Zs.mjs +0 -922
  1500. package/dist/byline-CzGZC2Zs.mjs.map +0 -1
  1501. package/dist/byline-fields-B1qHvRps.mjs +0 -280
  1502. package/dist/byline-fields-B1qHvRps.mjs.map +0 -1
  1503. package/dist/byline-fields-vYd_4Q1e.mjs +0 -123
  1504. package/dist/byline-fields-vYd_4Q1e.mjs.map +0 -1
  1505. package/dist/byline-registry-BhzpO41z.mjs +0 -406
  1506. package/dist/byline-registry-BhzpO41z.mjs.map +0 -1
  1507. package/dist/bylines-BF555iIz.mjs +0 -150
  1508. package/dist/bylines-BF555iIz.mjs.map +0 -1
  1509. package/dist/bylines-DJx6IWWi.mjs +0 -234
  1510. package/dist/bylines-DJx6IWWi.mjs.map +0 -1
  1511. package/dist/cache-BWzswWB-.mjs +0 -151
  1512. package/dist/cache-BWzswWB-.mjs.map +0 -1
  1513. package/dist/canonical-DjF_z6GI.mjs +0 -174
  1514. package/dist/canonical-DjF_z6GI.mjs.map +0 -1
  1515. package/dist/capture-triggers-D7g3fOZj.mjs +0 -362
  1516. package/dist/capture-triggers-D7g3fOZj.mjs.map +0 -1
  1517. package/dist/challenge-store-Cfjdvw86.mjs +0 -51
  1518. package/dist/challenge-store-Cfjdvw86.mjs.map +0 -1
  1519. package/dist/checksum-BF4acJwn.mjs +0 -162
  1520. package/dist/checksum-BF4acJwn.mjs.map +0 -1
  1521. package/dist/chrome-tags-BDs29G3g.mjs +0 -24
  1522. package/dist/chrome-tags-BDs29G3g.mjs.map +0 -1
  1523. package/dist/chunks-CYBOL-zn.mjs +0 -25
  1524. package/dist/chunks-CYBOL-zn.mjs.map +0 -1
  1525. package/dist/collection-slugs-cache-B2J5aESO.mjs +0 -91
  1526. package/dist/collection-slugs-cache-B2J5aESO.mjs.map +0 -1
  1527. package/dist/comment-DV7dybcs.mjs +0 -335
  1528. package/dist/comment-DV7dybcs.mjs.map +0 -1
  1529. package/dist/comment-reaction-CWwqiT6x.mjs +0 -85
  1530. package/dist/comment-reaction-CWwqiT6x.mjs.map +0 -1
  1531. package/dist/comments-DVjWJm8X.mjs +0 -99
  1532. package/dist/comments-DVjWJm8X.mjs.map +0 -1
  1533. package/dist/comments-Q-ILHCEI.mjs +0 -195
  1534. package/dist/comments-Q-ILHCEI.mjs.map +0 -1
  1535. package/dist/components-DnOmvvgg.mjs +0 -112
  1536. package/dist/components-DnOmvvgg.mjs.map +0 -1
  1537. package/dist/config-9IzA83_U.d.mts +0 -6811
  1538. package/dist/config-9IzA83_U.d.mts.map +0 -1
  1539. package/dist/config-BdQzFtmR.mjs +0 -228
  1540. package/dist/config-BdQzFtmR.mjs.map +0 -1
  1541. package/dist/config-Cs2RBkJ6.d.mts +0 -41
  1542. package/dist/config-Cs2RBkJ6.d.mts.map +0 -1
  1543. package/dist/connection-CiXgZyCY.mjs +0 -36
  1544. package/dist/connection-CiXgZyCY.mjs.map +0 -1
  1545. package/dist/content-Dt0Os_WQ.mjs +0 -2109
  1546. package/dist/content-Dt0Os_WQ.mjs.map +0 -1
  1547. package/dist/content-list-query-BK26u9Ly.d.mts +0 -26
  1548. package/dist/content-list-query-BK26u9Ly.d.mts.map +0 -1
  1549. package/dist/content-policy-BLDbNJOb.mjs +0 -46
  1550. package/dist/content-policy-BLDbNJOb.mjs.map +0 -1
  1551. package/dist/content-repair-CjwbLy4m.mjs +0 -442
  1552. package/dist/content-repair-CjwbLy4m.mjs.map +0 -1
  1553. package/dist/context-ErV7UdQY.mjs +0 -2089
  1554. package/dist/context-ErV7UdQY.mjs.map +0 -1
  1555. package/dist/credits-BRyjafiF.mjs +0 -110
  1556. package/dist/credits-BRyjafiF.mjs.map +0 -1
  1557. package/dist/cron-Bm5xa7tv.mjs +0 -306
  1558. package/dist/cron-Bm5xa7tv.mjs.map +0 -1
  1559. package/dist/dashboard-DVxQ5XiI.mjs +0 -168
  1560. package/dist/dashboard-DVxQ5XiI.mjs.map +0 -1
  1561. package/dist/default-B9Tf2n94.mjs +0 -81
  1562. package/dist/default-B9Tf2n94.mjs.map +0 -1
  1563. package/dist/deferred-tasks-CpPEqsga.d.mts +0 -9
  1564. package/dist/deferred-tasks-CpPEqsga.d.mts.map +0 -1
  1565. package/dist/destination-DR3IHjmy.mjs +0 -18
  1566. package/dist/destination-DR3IHjmy.mjs.map +0 -1
  1567. package/dist/dev-typegen-ZeWYV8Jp.mjs +0 -29
  1568. package/dist/dev-typegen-ZeWYV8Jp.mjs.map +0 -1
  1569. package/dist/device-flow-BbYNZ9Xi.mjs +0 -521
  1570. package/dist/device-flow-BbYNZ9Xi.mjs.map +0 -1
  1571. package/dist/dialect-helpers-7_IqPdh9.mjs +0 -307
  1572. package/dist/dialect-helpers-7_IqPdh9.mjs.map +0 -1
  1573. package/dist/digest-DlBa7kJl.mjs +0 -194
  1574. package/dist/digest-DlBa7kJl.mjs.map +0 -1
  1575. package/dist/direct-executor-5T8gkhvA.mjs +0 -117
  1576. package/dist/direct-executor-5T8gkhvA.mjs.map +0 -1
  1577. package/dist/dist-DY0aOmAP.mjs +0 -810
  1578. package/dist/dist-DY0aOmAP.mjs.map +0 -1
  1579. package/dist/email-console-v3OM8It-.mjs +0 -50
  1580. package/dist/email-console-v3OM8It-.mjs.map +0 -1
  1581. package/dist/email-locale-CoZo-oZx.mjs +0 -25
  1582. package/dist/email-locale-CoZo-oZx.mjs.map +0 -1
  1583. package/dist/emdash-runtime-DwezbIqQ.mjs +0 -4392
  1584. package/dist/emdash-runtime-DwezbIqQ.mjs.map +0 -1
  1585. package/dist/enrich-C3XIJi0O.mjs +0 -194
  1586. package/dist/enrich-C3XIJi0O.mjs.map +0 -1
  1587. package/dist/entry-lock-CY7XpdSw.d.mts +0 -4568
  1588. package/dist/entry-lock-CY7XpdSw.d.mts.map +0 -1
  1589. package/dist/entry-lock-DDuWaAiP.mjs +0 -1211
  1590. package/dist/entry-lock-DDuWaAiP.mjs.map +0 -1
  1591. package/dist/entry-lock-D_Og9Gy3.mjs +0 -163
  1592. package/dist/entry-lock-D_Og9Gy3.mjs.map +0 -1
  1593. package/dist/entry-locks-Cp8_BcQQ.mjs +0 -167
  1594. package/dist/entry-locks-Cp8_BcQQ.mjs.map +0 -1
  1595. package/dist/env-types-Br8uywYA.mjs +0 -38
  1596. package/dist/env-types-Br8uywYA.mjs.map +0 -1
  1597. package/dist/error-CT2SsX5S.mjs +0 -90
  1598. package/dist/error-CT2SsX5S.mjs.map +0 -1
  1599. package/dist/errors-BMaCpLeS.mjs +0 -479
  1600. package/dist/errors-BMaCpLeS.mjs.map +0 -1
  1601. package/dist/errors-DlJwot7q.mjs +0 -120
  1602. package/dist/errors-DlJwot7q.mjs.map +0 -1
  1603. package/dist/escape-BfbDyuQ-.mjs +0 -9
  1604. package/dist/escape-BfbDyuQ-.mjs.map +0 -1
  1605. package/dist/fence-BOD3SxZG.mjs +0 -162
  1606. package/dist/fence-BOD3SxZG.mjs.map +0 -1
  1607. package/dist/field-defs-cache-C7sR7ZeU.mjs +0 -77
  1608. package/dist/field-defs-cache-C7sR7ZeU.mjs.map +0 -1
  1609. package/dist/field-map-C_rDXfdJ.mjs +0 -84
  1610. package/dist/field-map-C_rDXfdJ.mjs.map +0 -1
  1611. package/dist/focal-point-CgCcr1Ca.mjs +0 -23
  1612. package/dist/focal-point-CgCcr1Ca.mjs.map +0 -1
  1613. package/dist/fts-manager-BzFo0xx6.mjs +0 -483
  1614. package/dist/fts-manager-BzFo0xx6.mjs.map +0 -1
  1615. package/dist/gc-B_c3DPpi.mjs +0 -75
  1616. package/dist/gc-B_c3DPpi.mjs.map +0 -1
  1617. package/dist/hash-A-o2ZX8O.mjs +0 -37
  1618. package/dist/hash-A-o2ZX8O.mjs.map +0 -1
  1619. package/dist/hook-result-f8t7hIuu.d.mts +0 -31
  1620. package/dist/hook-result-f8t7hIuu.d.mts.map +0 -1
  1621. package/dist/hreflang-BpUK9Lcu.mjs +0 -105
  1622. package/dist/hreflang-BpUK9Lcu.mjs.map +0 -1
  1623. package/dist/hreflang-D07R-RbI.d.mts +0 -50
  1624. package/dist/hreflang-D07R-RbI.d.mts.map +0 -1
  1625. package/dist/http-route-dispatch-C2Ep2Uf6.mjs +0 -342
  1626. package/dist/http-route-dispatch-C2Ep2Uf6.mjs.map +0 -1
  1627. package/dist/identity-BivQ8wkV.mjs +0 -35
  1628. package/dist/identity-BivQ8wkV.mjs.map +0 -1
  1629. package/dist/import-B4UvHNJz.mjs +0 -2126
  1630. package/dist/import-B4UvHNJz.mjs.map +0 -1
  1631. package/dist/index-C37Ty40w.d.mts +0 -623
  1632. package/dist/index-C37Ty40w.d.mts.map +0 -1
  1633. package/dist/init-lock-BGmew3r1.mjs +0 -56
  1634. package/dist/init-lock-BGmew3r1.mjs.map +0 -1
  1635. package/dist/install-finalization-BbYaB4wj.mjs +0 -58
  1636. package/dist/install-finalization-BbYaB4wj.mjs.map +0 -1
  1637. package/dist/json-recordset-BjYIWFkV.mjs +0 -12
  1638. package/dist/json-recordset-BjYIWFkV.mjs.map +0 -1
  1639. package/dist/json-schema-Cde7le0s.mjs +0 -15
  1640. package/dist/json-schema-Cde7le0s.mjs.map +0 -1
  1641. package/dist/keys-CusTXpw-.mjs +0 -61
  1642. package/dist/keys-CusTXpw-.mjs.map +0 -1
  1643. package/dist/kinds-DogmNB6n.mjs +0 -974
  1644. package/dist/kinds-DogmNB6n.mjs.map +0 -1
  1645. package/dist/lifecycle-BLCoCz4T.mjs +0 -25
  1646. package/dist/lifecycle-BLCoCz4T.mjs.map +0 -1
  1647. package/dist/load-Dds3KhXr.mjs +0 -28
  1648. package/dist/load-Dds3KhXr.mjs.map +0 -1
  1649. package/dist/loader-D4w4XE7q.mjs +0 -1420
  1650. package/dist/loader-D4w4XE7q.mjs.map +0 -1
  1651. package/dist/loops-IYgzQdQu.mjs +0 -205
  1652. package/dist/loops-IYgzQdQu.mjs.map +0 -1
  1653. package/dist/manifest-builder-CGF5kujD.mjs +0 -196
  1654. package/dist/manifest-builder-CGF5kujD.mjs.map +0 -1
  1655. package/dist/manifest-schema-B0BxPSjB.mjs +0 -497
  1656. package/dist/manifest-schema-B0BxPSjB.mjs.map +0 -1
  1657. package/dist/marketplace-DNvEGLqU.mjs +0 -257
  1658. package/dist/marketplace-DNvEGLqU.mjs.map +0 -1
  1659. package/dist/media-BL9MRrSG.mjs +0 -294
  1660. package/dist/media-BL9MRrSG.mjs.map +0 -1
  1661. package/dist/media-B_x5B9EA.mjs +0 -373
  1662. package/dist/media-B_x5B9EA.mjs.map +0 -1
  1663. package/dist/media-allowlist-CpmqBbIQ.mjs +0 -45
  1664. package/dist/media-allowlist-CpmqBbIQ.mjs.map +0 -1
  1665. package/dist/media-folders-CNs_A_B-.mjs +0 -210
  1666. package/dist/media-folders-CNs_A_B-.mjs.map +0 -1
  1667. package/dist/media-qTTHVkls.mjs +0 -416
  1668. package/dist/media-qTTHVkls.mjs.map +0 -1
  1669. package/dist/media-url-GJboA1fl.mjs +0 -43
  1670. package/dist/media-url-GJboA1fl.mjs.map +0 -1
  1671. package/dist/media-usage-ClWgrX0d.mjs +0 -282
  1672. package/dist/media-usage-ClWgrX0d.mjs.map +0 -1
  1673. package/dist/media-usage-activation-B8Fjtq0h.mjs +0 -78
  1674. package/dist/media-usage-activation-B8Fjtq0h.mjs.map +0 -1
  1675. package/dist/media-usage-work-L8-Au4j-.mjs +0 -1036
  1676. package/dist/media-usage-work-L8-Au4j-.mjs.map +0 -1
  1677. package/dist/media-usage-work-LXgze5j9.mjs +0 -151
  1678. package/dist/media-usage-work-LXgze5j9.mjs.map +0 -1
  1679. package/dist/menus-BAxcbsbv.mjs +0 -818
  1680. package/dist/menus-BAxcbsbv.mjs.map +0 -1
  1681. package/dist/menus-BI6oBXco.mjs +0 -92
  1682. package/dist/menus-BI6oBXco.mjs.map +0 -1
  1683. package/dist/menus-fvGFd4m6.mjs +0 -3725
  1684. package/dist/menus-fvGFd4m6.mjs.map +0 -1
  1685. package/dist/mime-DwhtRyUt.mjs +0 -81
  1686. package/dist/mime-DwhtRyUt.mjs.map +0 -1
  1687. package/dist/mode-DIDSUwuN.mjs +0 -23
  1688. package/dist/mode-DIDSUwuN.mjs.map +0 -1
  1689. package/dist/node-sqlite-compat-Ddr_mlR9.mjs +0 -63
  1690. package/dist/node-sqlite-compat-Ddr_mlR9.mjs.map +0 -1
  1691. package/dist/normalize-Ip_hFAm8.mjs +0 -216
  1692. package/dist/normalize-Ip_hFAm8.mjs.map +0 -1
  1693. package/dist/oauth-authorization-CcMgeT8R.mjs +0 -274
  1694. package/dist/oauth-authorization-CcMgeT8R.mjs.map +0 -1
  1695. package/dist/oauth-clients-C_osi0PU.mjs +0 -266
  1696. package/dist/oauth-clients-C_osi0PU.mjs.map +0 -1
  1697. package/dist/oauth-state-store-DGLP-6CK.mjs +0 -50
  1698. package/dist/oauth-state-store-DGLP-6CK.mjs.map +0 -1
  1699. package/dist/oauth-user-lookup-z77Ee0Hm.mjs +0 -26
  1700. package/dist/oauth-user-lookup-z77Ee0Hm.mjs.map +0 -1
  1701. package/dist/object-cache-EjasjtoQ.mjs +0 -586
  1702. package/dist/object-cache-EjasjtoQ.mjs.map +0 -1
  1703. package/dist/options-CmUpkyKW.d.mts +0 -81
  1704. package/dist/options-CmUpkyKW.d.mts.map +0 -1
  1705. package/dist/options-DhrI7eMv.mjs +0 -208
  1706. package/dist/options-DhrI7eMv.mjs.map +0 -1
  1707. package/dist/ownership-DCk5NutQ.mjs +0 -12
  1708. package/dist/ownership-DCk5NutQ.mjs.map +0 -1
  1709. package/dist/parse-2W-E2f7w.mjs +0 -81
  1710. package/dist/parse-2W-E2f7w.mjs.map +0 -1
  1711. package/dist/parse-6pN8Xqg5.d.mts +0 -176
  1712. package/dist/parse-6pN8Xqg5.d.mts.map +0 -1
  1713. package/dist/passkey-config-DTTZB6EI.mjs +0 -46
  1714. package/dist/passkey-config-DTTZB6EI.mjs.map +0 -1
  1715. package/dist/paths-CQA62503.mjs +0 -77
  1716. package/dist/paths-CQA62503.mjs.map +0 -1
  1717. package/dist/patterns-CryGz_EV.mjs +0 -159
  1718. package/dist/patterns-CryGz_EV.mjs.map +0 -1
  1719. package/dist/placeholder-BlfXkucE.d.mts +0 -313
  1720. package/dist/placeholder-BlfXkucE.d.mts.map +0 -1
  1721. package/dist/plan-B95eiwnF.mjs +0 -135
  1722. package/dist/plan-B95eiwnF.mjs.map +0 -1
  1723. package/dist/plugin-tool-name-BDA7m4Xa.mjs +0 -27
  1724. package/dist/plugin-tool-name-BDA7m4Xa.mjs.map +0 -1
  1725. package/dist/plugins-BhxLJ008.mjs +0 -261
  1726. package/dist/plugins-BhxLJ008.mjs.map +0 -1
  1727. package/dist/policy-DOJ2sPqB.mjs +0 -53
  1728. package/dist/policy-DOJ2sPqB.mjs.map +0 -1
  1729. package/dist/portable-text-RCMpCj47.mjs +0 -311
  1730. package/dist/portable-text-RCMpCj47.mjs.map +0 -1
  1731. package/dist/preview-DFwL5APO.mjs +0 -107
  1732. package/dist/preview-DFwL5APO.mjs.map +0 -1
  1733. package/dist/protocol-B-ztxp_y.d.mts +0 -65
  1734. package/dist/protocol-B-ztxp_y.d.mts.map +0 -1
  1735. package/dist/public-plugin-api-routes-ik4fPZMv.mjs +0 -316
  1736. package/dist/public-plugin-api-routes-ik4fPZMv.mjs.map +0 -1
  1737. package/dist/public-submission-C5JZIykp.mjs +0 -251
  1738. package/dist/public-submission-C5JZIykp.mjs.map +0 -1
  1739. package/dist/public-url-CQwzRljH.mjs +0 -101
  1740. package/dist/public-url-CQwzRljH.mjs.map +0 -1
  1741. package/dist/query-BFHjCzSh.mjs +0 -37
  1742. package/dist/query-BFHjCzSh.mjs.map +0 -1
  1743. package/dist/query-DuwyFr5Z.mjs +0 -41
  1744. package/dist/query-DuwyFr5Z.mjs.map +0 -1
  1745. package/dist/query-eR_Nz70M.mjs +0 -1157
  1746. package/dist/query-eR_Nz70M.mjs.map +0 -1
  1747. package/dist/range-BQWPjWgQ.mjs +0 -51
  1748. package/dist/range-BQWPjWgQ.mjs.map +0 -1
  1749. package/dist/rate-limit-mPKeQ3sm.mjs +0 -127
  1750. package/dist/rate-limit-mPKeQ3sm.mjs.map +0 -1
  1751. package/dist/receipt-CmUpyuW5.mjs +0 -43
  1752. package/dist/receipt-CmUpyuW5.mjs.map +0 -1
  1753. package/dist/redirect-BtiMkehU.mjs +0 -19
  1754. package/dist/redirect-BtiMkehU.mjs.map +0 -1
  1755. package/dist/redirect-DcmNMvOs.mjs +0 -423
  1756. package/dist/redirect-DcmNMvOs.mjs.map +0 -1
  1757. package/dist/redirect-paths-K5i3xYfR.mjs +0 -36
  1758. package/dist/redirect-paths-K5i3xYfR.mjs.map +0 -1
  1759. package/dist/redirects-BA_TvtuH.mjs +0 -148
  1760. package/dist/redirects-BA_TvtuH.mjs.map +0 -1
  1761. package/dist/redirects-BIrRvgn4.mjs +0 -446
  1762. package/dist/redirects-BIrRvgn4.mjs.map +0 -1
  1763. package/dist/registry-DymfZkAN.mjs +0 -8374
  1764. package/dist/registry-DymfZkAN.mjs.map +0 -1
  1765. package/dist/relations-DrEs3Sc1.mjs +0 -789
  1766. package/dist/relations-DrEs3Sc1.mjs.map +0 -1
  1767. package/dist/request-cache-5z2WzWmh.mjs +0 -104
  1768. package/dist/request-cache-5z2WzWmh.mjs.map +0 -1
  1769. package/dist/request-meta-o8RIf9pa.mjs +0 -141
  1770. package/dist/request-meta-o8RIf9pa.mjs.map +0 -1
  1771. package/dist/resolve-CVy9xgy_.mjs +0 -102
  1772. package/dist/resolve-CVy9xgy_.mjs.map +0 -1
  1773. package/dist/resolve-DdNXBJSr.mjs +0 -199
  1774. package/dist/resolve-DdNXBJSr.mjs.map +0 -1
  1775. package/dist/revision-Dx7Uth1X.mjs +0 -374
  1776. package/dist/revision-Dx7Uth1X.mjs.map +0 -1
  1777. package/dist/route-cache-DAG5dPhh.mjs +0 -20
  1778. package/dist/route-cache-DAG5dPhh.mjs.map +0 -1
  1779. package/dist/route-wire-Xbsu8Vih.mjs +0 -197
  1780. package/dist/route-wire-Xbsu8Vih.mjs.map +0 -1
  1781. package/dist/routes-YQkSOsws.mjs +0 -272
  1782. package/dist/routes-YQkSOsws.mjs.map +0 -1
  1783. package/dist/runner-CLorw5vo.mjs +0 -6669
  1784. package/dist/runner-CLorw5vo.mjs.map +0 -1
  1785. package/dist/runner-g1A9P-wD.d.mts +0 -73
  1786. package/dist/runner-g1A9P-wD.d.mts.map +0 -1
  1787. package/dist/schema-Bss8qImF.mjs +0 -13
  1788. package/dist/schema-Bss8qImF.mjs.map +0 -1
  1789. package/dist/schema-C036pqEw.mjs +0 -815
  1790. package/dist/schema-C036pqEw.mjs.map +0 -1
  1791. package/dist/scopes-C_SoYl9x.mjs +0 -34
  1792. package/dist/scopes-C_SoYl9x.mjs.map +0 -1
  1793. package/dist/search-uNqCgePJ.mjs +0 -450
  1794. package/dist/search-uNqCgePJ.mjs.map +0 -1
  1795. package/dist/secrets-Cc_O3Kp-.mjs +0 -369
  1796. package/dist/secrets-Cc_O3Kp-.mjs.map +0 -1
  1797. package/dist/sections-BLusMa96.mjs +0 -346
  1798. package/dist/sections-BLusMa96.mjs.map +0 -1
  1799. package/dist/seo-BodxIpws.mjs +0 -188
  1800. package/dist/seo-BodxIpws.mjs.map +0 -1
  1801. package/dist/seo-DaMYIQY8.mjs +0 -133
  1802. package/dist/seo-DaMYIQY8.mjs.map +0 -1
  1803. package/dist/service-BuM1BRsA.mjs +0 -150
  1804. package/dist/service-BuM1BRsA.mjs.map +0 -1
  1805. package/dist/session-user-2DpQDMKw.mjs +0 -61
  1806. package/dist/session-user-2DpQDMKw.mjs.map +0 -1
  1807. package/dist/settings-B3ZmPF_8.mjs +0 -73
  1808. package/dist/settings-B3ZmPF_8.mjs.map +0 -1
  1809. package/dist/settings-P5hwPX6_.mjs +0 -66
  1810. package/dist/settings-P5hwPX6_.mjs.map +0 -1
  1811. package/dist/settings-yIqoN-Ok.mjs +0 -519
  1812. package/dist/settings-yIqoN-Ok.mjs.map +0 -1
  1813. package/dist/setup-complete-eu6MUQnt.mjs +0 -65
  1814. package/dist/setup-complete-eu6MUQnt.mjs.map +0 -1
  1815. package/dist/setup-nonce-CyPOapqY.mjs +0 -25
  1816. package/dist/setup-nonce-CyPOapqY.mjs.map +0 -1
  1817. package/dist/single-flight-cache-D0EaGbN1.mjs +0 -104
  1818. package/dist/single-flight-cache-D0EaGbN1.mjs.map +0 -1
  1819. package/dist/site-domain-8lEJl_0U.mjs +0 -131
  1820. package/dist/site-domain-8lEJl_0U.mjs.map +0 -1
  1821. package/dist/site-settings-uPkW0e6o.mjs +0 -50
  1822. package/dist/site-settings-uPkW0e6o.mjs.map +0 -1
  1823. package/dist/site-url-25SGVXwL.mjs +0 -45
  1824. package/dist/site-url-25SGVXwL.mjs.map +0 -1
  1825. package/dist/sitemap-name-DTK7CYnY.mjs +0 -26
  1826. package/dist/sitemap-name-DTK7CYnY.mjs.map +0 -1
  1827. package/dist/slug-BEDl2IJY.mjs +0 -16
  1828. package/dist/slug-BEDl2IJY.mjs.map +0 -1
  1829. package/dist/slugify-BDEG9pLk.mjs +0 -22
  1830. package/dist/slugify-BDEG9pLk.mjs.map +0 -1
  1831. package/dist/snapshot-CvkIBRLY.mjs +0 -414
  1832. package/dist/snapshot-CvkIBRLY.mjs.map +0 -1
  1833. package/dist/ssrf-BBXcxG-f.mjs +0 -1
  1834. package/dist/ssrf-mcCKMH6B.mjs +0 -406
  1835. package/dist/ssrf-mcCKMH6B.mjs.map +0 -1
  1836. package/dist/stage-BQfGzGOy.mjs +0 -662
  1837. package/dist/stage-BQfGzGOy.mjs.map +0 -1
  1838. package/dist/staged-B5vQGeSf.mjs +0 -686
  1839. package/dist/staged-B5vQGeSf.mjs.map +0 -1
  1840. package/dist/state-dO6t6OxV.mjs +0 -178
  1841. package/dist/state-dO6t6OxV.mjs.map +0 -1
  1842. package/dist/status-DSURZwKS.mjs +0 -30
  1843. package/dist/status-DSURZwKS.mjs.map +0 -1
  1844. package/dist/storage-query-Cy0SZ8iG.d.mts +0 -1619
  1845. package/dist/storage-query-Cy0SZ8iG.d.mts.map +0 -1
  1846. package/dist/tar-DWzcUZ_Q.mjs +0 -449
  1847. package/dist/tar-DWzcUZ_Q.mjs.map +0 -1
  1848. package/dist/target-C9htUbrT.mjs +0 -27
  1849. package/dist/target-C9htUbrT.mjs.map +0 -1
  1850. package/dist/taxonomies-By2aGvq2.mjs +0 -729
  1851. package/dist/taxonomies-By2aGvq2.mjs.map +0 -1
  1852. package/dist/taxonomies-CVRd_jz0.mjs +0 -937
  1853. package/dist/taxonomies-CVRd_jz0.mjs.map +0 -1
  1854. package/dist/taxonomy-BG_xu2Qf.mjs +0 -563
  1855. package/dist/taxonomy-BG_xu2Qf.mjs.map +0 -1
  1856. package/dist/tokens-U5vzgSrM.mjs +0 -171
  1857. package/dist/tokens-U5vzgSrM.mjs.map +0 -1
  1858. package/dist/transaction-CkoQ5wqQ.mjs +0 -29
  1859. package/dist/transaction-CkoQ5wqQ.mjs.map +0 -1
  1860. package/dist/transfer-DA0OSfaT.mjs +0 -8873
  1861. package/dist/transfer-DA0OSfaT.mjs.map +0 -1
  1862. package/dist/transfer-Pyf3d7ka.mjs +0 -166
  1863. package/dist/transfer-Pyf3d7ka.mjs.map +0 -1
  1864. package/dist/transfer-download-cX7SuWEy.mjs +0 -33
  1865. package/dist/transfer-download-cX7SuWEy.mjs.map +0 -1
  1866. package/dist/transformations-DczubD4j.mjs +0 -196
  1867. package/dist/transformations-DczubD4j.mjs.map +0 -1
  1868. package/dist/transport-Dm5QzpT_.d.mts +0 -42
  1869. package/dist/transport-Dm5QzpT_.d.mts.map +0 -1
  1870. package/dist/transport-DtIrjEFO.mjs +0 -137
  1871. package/dist/transport-DtIrjEFO.mjs.map +0 -1
  1872. package/dist/trusted-proxy-CDRd5Kmw.mjs +0 -51
  1873. package/dist/trusted-proxy-CDRd5Kmw.mjs.map +0 -1
  1874. package/dist/turnstile-Ct5YuFNY.mjs +0 -58
  1875. package/dist/turnstile-Ct5YuFNY.mjs.map +0 -1
  1876. package/dist/types-Bgujop4S.d.mts +0 -374
  1877. package/dist/types-Bgujop4S.d.mts.map +0 -1
  1878. package/dist/types-BirHUEXt.mjs +0 -18
  1879. package/dist/types-BirHUEXt.mjs.map +0 -1
  1880. package/dist/types-BqJgTL_y.d.mts +0 -293
  1881. package/dist/types-BqJgTL_y.d.mts.map +0 -1
  1882. package/dist/types-C-lrOt9T.d.mts +0 -87
  1883. package/dist/types-C-lrOt9T.d.mts.map +0 -1
  1884. package/dist/types-CCEHAhOv.d.mts +0 -916
  1885. package/dist/types-CCEHAhOv.d.mts.map +0 -1
  1886. package/dist/types-CLVwYRBr.d.mts +0 -227
  1887. package/dist/types-CLVwYRBr.d.mts.map +0 -1
  1888. package/dist/types-C_asjp1J.mjs +0 -201
  1889. package/dist/types-C_asjp1J.mjs.map +0 -1
  1890. package/dist/types-CadaL_k8.d.mts +0 -366
  1891. package/dist/types-CadaL_k8.d.mts.map +0 -1
  1892. package/dist/types-DVbTb4Hk.mjs +0 -77
  1893. package/dist/types-DVbTb4Hk.mjs.map +0 -1
  1894. package/dist/types-Ddku19Zw.d.mts +0 -209
  1895. package/dist/types-Ddku19Zw.d.mts.map +0 -1
  1896. package/dist/types-DwhEvIVb.mjs +0 -133
  1897. package/dist/types-DwhEvIVb.mjs.map +0 -1
  1898. package/dist/types-FIiGQ3PE.mjs +0 -16
  1899. package/dist/types-FIiGQ3PE.mjs.map +0 -1
  1900. package/dist/types-OauzCOY0.mjs +0 -37
  1901. package/dist/types-OauzCOY0.mjs.map +0 -1
  1902. package/dist/types-mQGTpP-4.d.mts +0 -1741
  1903. package/dist/types-mQGTpP-4.d.mts.map +0 -1
  1904. package/dist/types-nbjz3Mgm.d.mts +0 -125
  1905. package/dist/types-nbjz3Mgm.d.mts.map +0 -1
  1906. package/dist/update-check-hW32-0pf.mjs +0 -161
  1907. package/dist/update-check-hW32-0pf.mjs.map +0 -1
  1908. package/dist/upload-attempts-Bpik1TLF.mjs +0 -32
  1909. package/dist/upload-attempts-Bpik1TLF.mjs.map +0 -1
  1910. package/dist/url-DTfGDJhI.mjs +0 -104
  1911. package/dist/url-DTfGDJhI.mjs.map +0 -1
  1912. package/dist/url-pattern-CJeCyNij.mjs +0 -41
  1913. package/dist/url-pattern-CJeCyNij.mjs.map +0 -1
  1914. package/dist/user-nQInBZbE.mjs +0 -171
  1915. package/dist/user-nQInBZbE.mjs.map +0 -1
  1916. package/dist/utils-govudc_U.mjs +0 -442
  1917. package/dist/utils-govudc_U.mjs.map +0 -1
  1918. package/dist/validate-BxLvcDYh.mjs +0 -524
  1919. package/dist/validate-BxLvcDYh.mjs.map +0 -1
  1920. package/dist/validate-mnoVfASU.d.mts +0 -468
  1921. package/dist/validate-mnoVfASU.d.mts.map +0 -1
  1922. package/dist/validation-DQDEvh87.mjs +0 -221
  1923. package/dist/validation-DQDEvh87.mjs.map +0 -1
  1924. package/dist/version-BOFfLiVT.mjs +0 -49
  1925. package/dist/version-BOFfLiVT.mjs.map +0 -1
  1926. package/dist/version-Dcvx_C9g.mjs +0 -7
  1927. package/dist/version-Dcvx_C9g.mjs.map +0 -1
  1928. package/dist/version-DzTJ3gD7.mjs +0 -9
  1929. package/dist/version-DzTJ3gD7.mjs.map +0 -1
  1930. package/dist/video-BX7AI5nJ.mjs +0 -54
  1931. package/dist/video-BX7AI5nJ.mjs.map +0 -1
  1932. package/dist/virtual-modules-CU29aip9.mjs +0 -515
  1933. package/dist/virtual-modules-CU29aip9.mjs.map +0 -1
  1934. package/dist/widgets-HIeFmZxt.mjs +0 -121
  1935. package/dist/widgets-HIeFmZxt.mjs.map +0 -1
  1936. package/dist/wxr-taxonomies-Dy2i2ON3.d.mts +0 -34
  1937. package/dist/wxr-taxonomies-Dy2i2ON3.d.mts.map +0 -1
  1938. package/dist/wxr-taxonomies-DyOGhl8W.mjs +0 -454
  1939. package/dist/wxr-taxonomies-DyOGhl8W.mjs.map +0 -1
  1940. package/dist/zod-generator-VxCPVDpo.mjs +0 -425
  1941. package/dist/zod-generator-VxCPVDpo.mjs.map +0 -1
@@ -0,0 +1,2805 @@
1
+ import { t as validateIdentifier } from "./validate-DANX1-Qi.mjs";
2
+ import { u as isPostgres } from "./dialect-helpers-DqUMP9fJ.mjs";
3
+ import { getRequestContext } from "./request-context.mjs";
4
+ import { n as chunks, t as SQL_BATCH_SIZE } from "./chunks-DRnEstVb.mjs";
5
+ import { a as InvalidCursorError, l as decodeCursor, u as encodeCursor } from "./types-BBH-w_KS.mjs";
6
+ import { t as withTransaction } from "./transaction-SKrr6u84.mjs";
7
+ import { n as normalizeFocalPoint } from "./focal-point-Cup37tLI.mjs";
8
+ import { t as jsonTextValues } from "./json-recordset-CrS6ZqMk.mjs";
9
+ import { n as MediaUsageActivationVersionMismatchError, t as MEDIA_USAGE_ACTIVATION_RUNTIME_GENERATION } from "./activation-X5iMalte.mjs";
10
+ import { sql } from "kysely";
11
+ import { ulid } from "ulidx";
12
+
13
+ //#region src/media/usage/projection-fingerprint.ts
14
+ const MEDIA_USAGE_PROJECTION_FINGERPRINT_VERSION = 1;
15
+ const FINGERPRINT_PREFIX = `media-usage-projection:v${MEDIA_USAGE_PROJECTION_FINGERPRINT_VERSION}:sha256:`;
16
+ const FINGERPRINT_PATTERN = new RegExp(`^${FINGERPRINT_PREFIX}[a-f0-9]{64}$`);
17
+ async function buildMediaUsageProjectionFingerprint(input) {
18
+ if (!input.collectionId) throw new Error("Media usage projection fingerprints require a collection identity");
19
+ const canonicalOccurrences = input.occurrences.map((occurrence) => ({
20
+ fieldSlug: occurrence.fieldSlug,
21
+ fieldPath: occurrence.fieldPath,
22
+ occurrenceIndex: occurrence.occurrenceIndex ?? 0,
23
+ referenceType: occurrence.referenceType,
24
+ mediaId: occurrence.mediaId,
25
+ provider: occurrence.provider,
26
+ providerAssetId: occurrence.providerAssetId,
27
+ mediaKind: occurrence.mediaKind ?? null,
28
+ mimeType: occurrence.mimeType ?? null
29
+ })).map((occurrence) => ({
30
+ occurrence,
31
+ key: canonicalJson(occurrence)
32
+ })).toSorted((a, b) => compareCanonicalStrings(a.key, b.key)).map(({ occurrence }) => occurrence);
33
+ return buildCanonicalSha256Fingerprint(FINGERPRINT_PREFIX, {
34
+ fingerprintVersion: MEDIA_USAGE_PROJECTION_FINGERPRINT_VERSION,
35
+ collectionId: input.collectionId,
36
+ extractionSchema: normalizeExtractionFields(input.extractionFields),
37
+ source: {
38
+ sourceKey: input.source.sourceKey,
39
+ sourceType: input.source.sourceType,
40
+ collectionSlug: input.source.collectionSlug ?? null,
41
+ contentId: input.source.contentId ?? null,
42
+ sourceVariant: input.source.sourceVariant,
43
+ locale: input.source.locale ?? null,
44
+ translationGroup: input.source.translationGroup ?? null,
45
+ contentSlug: input.source.contentSlug ?? null,
46
+ contentTitle: input.source.contentTitle ?? null,
47
+ contentStatus: input.source.contentStatus ?? null,
48
+ contentScheduledAt: input.source.contentScheduledAt ?? null,
49
+ contentDeletedAt: input.source.contentDeletedAt ?? null,
50
+ revisionId: input.source.revisionId ?? null,
51
+ schemaVersion: input.source.schemaVersion ?? 1,
52
+ sourceCompleteness: input.source.sourceCompleteness ?? "complete"
53
+ },
54
+ occurrences: canonicalOccurrences
55
+ });
56
+ }
57
+ async function buildCanonicalSha256Fingerprint(prefix, payload) {
58
+ const encodedPayload = new TextEncoder().encode(canonicalJson(payload));
59
+ const digest = await crypto.subtle.digest("SHA-256", encodedPayload);
60
+ return {
61
+ fingerprint: `${prefix}${Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("")}`,
62
+ byteLength: encodedPayload.byteLength
63
+ };
64
+ }
65
+ function normalizeExtractionFields(fields) {
66
+ return fields.map((field) => {
67
+ if (field.type === "blocks") return {
68
+ slug: field.slug,
69
+ type: field.type,
70
+ blockTypes: (field.blockTypes ?? []).map((type) => ({
71
+ slug: type.slug,
72
+ currentVersion: type.currentVersion,
73
+ versions: type.versions.map((version) => ({
74
+ version: version.version,
75
+ fingerprint: version.fingerprint
76
+ }))
77
+ }))
78
+ };
79
+ if (field.type !== "repeater") return {
80
+ slug: field.slug,
81
+ type: field.type
82
+ };
83
+ return {
84
+ slug: field.slug,
85
+ type: field.type,
86
+ subFields: (field.validation?.subFields ?? []).map((subField) => ({
87
+ slug: subField.slug,
88
+ type: subField.type
89
+ })).toSorted((a, b) => compareCanonicalStrings(a.slug, b.slug))
90
+ };
91
+ }).toSorted((a, b) => compareCanonicalStrings(String(a.slug), String(b.slug)));
92
+ }
93
+ function compareCanonicalStrings(a, b) {
94
+ return a < b ? -1 : a > b ? 1 : 0;
95
+ }
96
+ function isMediaUsageProjectionFingerprint(value) {
97
+ return typeof value === "string" && FINGERPRINT_PATTERN.test(value);
98
+ }
99
+ function canonicalJson(value) {
100
+ return JSON.stringify(canonicalize(value));
101
+ }
102
+ function canonicalize(value) {
103
+ if (value === void 0) return null;
104
+ if (typeof value === "bigint") return value.toString();
105
+ if (typeof value === "number") return Number.isFinite(value) ? value : null;
106
+ if (Array.isArray(value)) return value.map((item) => canonicalize(item));
107
+ if (!isRecord(value)) return value;
108
+ const canonical = {};
109
+ for (const key of Object.keys(value).toSorted()) canonical[key] = canonicalize(value[key]);
110
+ return canonical;
111
+ }
112
+ function isRecord(value) {
113
+ return typeof value === "object" && value !== null && !Array.isArray(value);
114
+ }
115
+
116
+ //#endregion
117
+ //#region src/media/usage/types.ts
118
+ const CONTENT_SOURCE_SCHEMA_VERSION = 2;
119
+
120
+ //#endregion
121
+ //#region src/database/repositories/media-usage.ts
122
+ const OCCURRENCE_BIND_COLUMNS = 13;
123
+ const D1_MAX_BOUND_PARAMETERS = 100;
124
+ const MEDIA_USAGE_GENERATION_WRITE_LEASE_MS = 3600 * 1e3;
125
+ const OCCURRENCE_INSERT_BATCH_SIZE = Math.max(1, Math.floor(D1_MAX_BOUND_PARAMETERS / OCCURRENCE_BIND_COLUMNS));
126
+ function cleanupDeleteBatchSize(cleanupLease) {
127
+ return cleanupLease ? SQL_BATCH_SIZE - 3 : SQL_BATCH_SIZE;
128
+ }
129
+ function canIssueCleanupStatement(canIssueStatement) {
130
+ return canIssueStatement?.() ?? true;
131
+ }
132
+ function nullableRefMatch(left, right) {
133
+ const leftRef = sql.ref(left);
134
+ const rightRef = sql.ref(right);
135
+ return sql`(
136
+ (${leftRef} IS NULL AND ${rightRef} IS NULL)
137
+ OR ${leftRef} = ${rightRef}
138
+ )`;
139
+ }
140
+ const MAX_JSON_BIND_BYTES = 19e5;
141
+ const MEDIA_USAGE_EVENT_QUERY_CEILING = 900;
142
+ const MEDIA_USAGE_QUERY_RESERVE = 150;
143
+ function chunkJsonRows(rows) {
144
+ const batches = [];
145
+ let batch = [];
146
+ let batchBytes = 2;
147
+ for (const row of rows) {
148
+ const rowBytes = new TextEncoder().encode(JSON.stringify(row)).byteLength + (batch.length > 0 ? 1 : 0);
149
+ if (batch.length > 0 && batchBytes + rowBytes > MAX_JSON_BIND_BYTES) {
150
+ batches.push(batch);
151
+ batch = [];
152
+ batchBytes = 2;
153
+ }
154
+ batch.push(row);
155
+ batchBytes += rowBytes;
156
+ }
157
+ if (batch.length > 0) batches.push(batch);
158
+ return batches;
159
+ }
160
+ function mediaUsageQueryBudgetAllows(queries) {
161
+ const metrics = getRequestContext()?.metrics;
162
+ return !metrics || metrics.dbCount + queries + MEDIA_USAGE_QUERY_RESERVE <= MEDIA_USAGE_EVENT_QUERY_CEILING;
163
+ }
164
+ function mergeInto(target, source) {
165
+ for (const value of source) target.add(value);
166
+ }
167
+ function batchOccurrenceRows(prepared, now) {
168
+ return prepared.flatMap((item) => item.projection.occurrences.map((occurrence) => ({
169
+ id: ulid(),
170
+ source_key: item.row.source_key,
171
+ generation: item.generation,
172
+ field_slug: occurrence.fieldSlug,
173
+ field_path: occurrence.fieldPath,
174
+ occurrence_index: occurrence.occurrenceIndex ?? 0,
175
+ reference_type: occurrence.referenceType,
176
+ media_id: occurrence.mediaId,
177
+ provider: occurrence.provider,
178
+ provider_asset_id: occurrence.providerAssetId,
179
+ media_kind: occurrence.mediaKind ?? null,
180
+ mime_type: occurrence.mimeType ?? null,
181
+ created_at: now,
182
+ lease_token: item.leaseToken
183
+ })));
184
+ }
185
+ function cleanupDurationSeconds(value) {
186
+ if (!Number.isSafeInteger(value) || value < 0) throw new Error("Media usage cleanup duration must be a non-negative whole number of seconds");
187
+ return value;
188
+ }
189
+ const CONTENT_SOURCE_ELIGIBILITY = sql`(
190
+ s.source_variant = 'draft_overlay'
191
+ OR (
192
+ s.source_variant = 'columns'
193
+ AND (
194
+ s.content_status = 'published'
195
+ OR NOT EXISTS (
196
+ SELECT 1
197
+ FROM _emdash_media_usage_sources AS overlay
198
+ WHERE overlay.source_type = 'content'
199
+ AND overlay.collection_slug = s.collection_slug
200
+ AND overlay.content_id = s.content_id
201
+ AND overlay.source_variant = 'draft_overlay'
202
+ AND ${contentSourceMatchesActiveCollection("overlay", "s.collection_id")}
203
+ )
204
+ )
205
+ )
206
+ )`;
207
+ function contentSourceMatchesActiveCollection(source, currentCollectionId) {
208
+ return sql`(
209
+ NOT EXISTS (
210
+ SELECT 1
211
+ FROM _emdash_media_usage_activation AS activation
212
+ WHERE activation.task_key = 'incremental_capture'
213
+ AND activation.state = 'active'
214
+ )
215
+ OR (
216
+ ${sql.ref(`${source}.collection_id`)} = ${sql.ref(currentCollectionId)}
217
+ AND ${sql.ref(`${source}.identity_version`)} = 1
218
+ )
219
+ )`;
220
+ }
221
+ /** Persistence-only repository for the internal media usage projection tables. */
222
+ var MediaUsageRepository = class {
223
+ constructor(db) {
224
+ this.db = db;
225
+ }
226
+ async replaceSource(source, occurrences) {
227
+ const generation = ulid();
228
+ if (!await this.withGenerationWriteLease(source, generation, async (leaseToken, now) => {
229
+ await withTransaction(this.db, async (trx) => {
230
+ if (!await this.lockCanonicalSourceCollection(trx, source)) throw new Error(`Media usage collection is no longer current for ${source.sourceKey}`);
231
+ await this.insertOccurrences(trx, source.sourceKey, generation, occurrences, now);
232
+ if (!await this.upsertSource(trx, source, generation, now, leaseToken)) throw new Error(`Media usage generation lease expired for ${source.sourceKey}`);
233
+ });
234
+ })) throw new Error(`Media usage collection is no longer current for ${source.sourceKey}`);
235
+ const replaced = await this.findSource(source.sourceKey);
236
+ if (!replaced) throw new Error(`Media usage source ${source.sourceKey} was not persisted`);
237
+ return replaced;
238
+ }
239
+ async replaceSourceIfCurrent(source, occurrences, expectedCurrentGeneration) {
240
+ if (expectedCurrentGeneration !== null && await this.projectionMatchesCurrentGeneration(source, expectedCurrentGeneration)) return {
241
+ replaced: false,
242
+ unchanged: true,
243
+ source: null
244
+ };
245
+ const generation = ulid();
246
+ let replaced = false;
247
+ await this.withGenerationWriteLease(source, generation, async (leaseToken, now) => {
248
+ const row = this.buildSourceRow(source, generation, now);
249
+ await withTransaction(this.db, async (trx) => {
250
+ if (!await this.lockCanonicalSourceCollection(trx, source)) return;
251
+ await this.insertOccurrences(trx, source.sourceKey, generation, occurrences, now);
252
+ if (expectedCurrentGeneration === null) {
253
+ replaced = await this.insertSourceIfAbsent(trx, row, leaseToken);
254
+ return;
255
+ }
256
+ replaced = await this.updateSourceIfGeneration(trx, row, expectedCurrentGeneration, leaseToken);
257
+ });
258
+ });
259
+ return {
260
+ replaced,
261
+ unchanged: false,
262
+ source: replaced ? null : await this.findSource(source.sourceKey)
263
+ };
264
+ }
265
+ async findSource(sourceKey) {
266
+ const row = await this.db.selectFrom("_emdash_media_usage_sources").selectAll().where("source_key", "=", sourceKey).executeTakeFirst();
267
+ return row ? rowToSource(row) : null;
268
+ }
269
+ async findSources(sourceKeys) {
270
+ const uniqueSourceKeys = [...new Set(sourceKeys)];
271
+ const sources = /* @__PURE__ */ new Map();
272
+ if (uniqueSourceKeys.length === 0) return sources;
273
+ for (const sourceKeyBatch of chunkJsonRows(uniqueSourceKeys)) {
274
+ const result = await sql`
275
+ WITH requested AS (${jsonTextValues(this.db, sourceKeyBatch)})
276
+ SELECT source.*
277
+ FROM _emdash_media_usage_sources AS source
278
+ INNER JOIN requested ON requested.value = source.source_key
279
+ `.execute(this.db);
280
+ for (const row of result.rows) {
281
+ const source = rowToSource(row);
282
+ sources.set(source.sourceKey, source);
283
+ }
284
+ }
285
+ return sources;
286
+ }
287
+ async measureSourceGenerationDeletion(sourceKey, generation, maxOccurrences) {
288
+ if (!Number.isSafeInteger(maxOccurrences) || maxOccurrences < 0) throw new Error("Media usage deletion measurement requires a non-negative row limit");
289
+ const payload = sql`
290
+ COALESCE(field_slug, '') || COALESCE(field_path, '') ||
291
+ COALESCE(reference_type, '') || COALESCE(media_id, '') ||
292
+ COALESCE(provider, '') || COALESCE(provider_asset_id, '') ||
293
+ COALESCE(media_kind, '') || COALESCE(mime_type, '')
294
+ `;
295
+ const occurrenceBytes = isPostgres(this.db) ? sql`octet_length(${payload})` : sql`length(CAST(${payload} AS BLOB))`;
296
+ const rows = await this.db.selectFrom("_emdash_media_usage").select(occurrenceBytes.as("occurrence_bytes")).where("source_key", "=", sourceKey).where("generation", "=", generation).limit(maxOccurrences + 1).execute();
297
+ return {
298
+ occurrenceCount: rows.length,
299
+ occurrenceBytes: rows.reduce((total, row) => total + Number(row.occurrence_bytes), 0),
300
+ exceedsOccurrenceLimit: rows.length > maxOccurrences
301
+ };
302
+ }
303
+ async replaceSourceIfMatching(source, occurrences, expectedSource) {
304
+ if (expectedSource !== null && await this.projectionMatchesExpectedSource(source, expectedSource)) return {
305
+ replaced: false,
306
+ unchanged: true,
307
+ source: null
308
+ };
309
+ const generation = ulid();
310
+ let replaced = false;
311
+ await this.withGenerationWriteLease(source, generation, async (leaseToken, now) => {
312
+ const row = this.buildSourceRow(source, generation, now);
313
+ await withTransaction(this.db, async (trx) => {
314
+ if (!await this.lockCanonicalSourceCollection(trx, source)) return;
315
+ await this.insertOccurrences(trx, source.sourceKey, generation, occurrences, now);
316
+ if (expectedSource === null) {
317
+ replaced = await this.insertSourceIfAbsent(trx, row, leaseToken);
318
+ return;
319
+ }
320
+ replaced = await this.updateSourceIfMatching(trx, row, expectedSource, leaseToken);
321
+ });
322
+ });
323
+ return {
324
+ replaced,
325
+ unchanged: false,
326
+ source: replaced ? null : await this.findSource(source.sourceKey)
327
+ };
328
+ }
329
+ async replaceNewSourcesBatch(projections) {
330
+ const unique = [...new Map(projections.map((projection) => [projection.source.sourceKey, projection])).values()];
331
+ if (unique.length === 0) return /* @__PURE__ */ new Set();
332
+ const collectionSlug = unique[0]?.source.collectionSlug;
333
+ const collectionId = unique[0]?.source.collectionId;
334
+ if (!collectionSlug || !collectionId) throw new Error("Canonical media usage batch requires collection identity");
335
+ validateIdentifier(collectionSlug, "collection slug");
336
+ if (unique.some((projection) => projection.source.collectionSlug !== collectionSlug || projection.source.collectionId !== collectionId)) throw new Error("Canonical media usage batch must contain one collection");
337
+ const now = (/* @__PURE__ */ new Date()).toISOString();
338
+ const expiresAt = new Date(Date.now() + MEDIA_USAGE_GENERATION_WRITE_LEASE_MS).toISOString();
339
+ const prepared = unique.map((projection) => {
340
+ const generation = ulid();
341
+ return {
342
+ projection,
343
+ generation,
344
+ leaseToken: ulid(),
345
+ row: this.buildSourceRow(projection.source, generation, now)
346
+ };
347
+ });
348
+ const sourceRows = prepared.map((item) => ({
349
+ ...item.row,
350
+ lease_token: item.leaseToken
351
+ }));
352
+ const occurrenceRows = batchOccurrenceRows(prepared, now);
353
+ if (!mediaUsageQueryBudgetAllows(2 + chunkJsonRows(occurrenceRows).length + chunkJsonRows(sourceRows).length)) {
354
+ if (unique.length === 1) return /* @__PURE__ */ new Set();
355
+ const midpoint = Math.ceil(unique.length / 2);
356
+ const inserted = /* @__PURE__ */ new Set();
357
+ mergeInto(inserted, await this.replaceNewSourcesBatch(unique.slice(0, midpoint)));
358
+ mergeInto(inserted, await this.replaceNewSourcesBatch(unique.slice(midpoint)));
359
+ return inserted;
360
+ }
361
+ const leasesPayload = JSON.stringify(prepared.map((item) => ({
362
+ source_key: item.row.source_key,
363
+ collection_id: item.row.collection_id,
364
+ collection_slug: item.row.collection_slug,
365
+ generation: item.generation,
366
+ lease_token: item.leaseToken,
367
+ expires_at: expiresAt,
368
+ created_at: now
369
+ })));
370
+ const leases = this.generationWriteBatchInput(leasesPayload);
371
+ await sql`
372
+ WITH input AS (${leases})
373
+ INSERT INTO _emdash_media_usage_generation_writes (
374
+ source_key, generation, lease_token, expires_at, created_at
375
+ )
376
+ SELECT source_key, generation, lease_token, expires_at, created_at
377
+ FROM input
378
+ WHERE EXISTS (
379
+ SELECT 1
380
+ FROM _emdash_collections AS collection
381
+ INNER JOIN _emdash_media_usage_index_status AS status
382
+ ON status.collection_id = collection.id
383
+ AND status.scope_key = collection.slug
384
+ WHERE collection.id = input.collection_id
385
+ AND collection.slug = input.collection_slug
386
+ AND status.adapter_id = 'content-media'
387
+ AND status.scope_type = 'collection'
388
+ AND status.capture_state = 'active'
389
+ AND NOT EXISTS (
390
+ SELECT 1 FROM _emdash_media_usage_collection_deletions AS deletion
391
+ WHERE deletion.collection_id = input.collection_id
392
+ )
393
+ )
394
+ `.execute(this.db);
395
+ try {
396
+ await this.insertBatchOccurrences(occurrenceRows);
397
+ const tableName = `ec_${collectionSlug}`;
398
+ validateIdentifier(tableName, "content table");
399
+ const inserted = /* @__PURE__ */ new Set();
400
+ for (const sourceRowBatch of chunkJsonRows(sourceRows)) {
401
+ const result = await sql`
402
+ WITH input AS (${this.sourceBatchInput(JSON.stringify(sourceRowBatch))})
403
+ INSERT INTO _emdash_media_usage_sources (
404
+ source_key, source_type, collection_id, collection_slug, content_id,
405
+ source_variant, locale, translation_group, content_slug, content_title,
406
+ content_status, content_scheduled_at, content_deleted_at, revision_id,
407
+ current_generation, schema_version, source_updated_at, source_version,
408
+ source_fingerprint, identity_version, source_completeness,
409
+ last_attempted_at, last_error_code, indexed_at, updated_at
410
+ )
411
+ SELECT
412
+ input.source_key, input.source_type, input.collection_id, input.collection_slug,
413
+ input.content_id, input.source_variant, input.locale, input.translation_group,
414
+ input.content_slug, input.content_title, input.content_status,
415
+ input.content_scheduled_at, input.content_deleted_at, input.revision_id,
416
+ input.current_generation, input.schema_version, input.source_updated_at,
417
+ input.source_version, input.source_fingerprint, input.identity_version,
418
+ input.source_completeness, input.last_attempted_at, input.last_error_code,
419
+ input.indexed_at, input.updated_at
420
+ FROM input
421
+ WHERE EXISTS (
422
+ SELECT 1
423
+ FROM _emdash_media_usage_generation_writes AS writer
424
+ WHERE writer.source_key = input.source_key
425
+ AND writer.generation = input.current_generation
426
+ AND writer.lease_token = input.lease_token
427
+ AND ${this.generationWriteLeaseExpiryIsInFuture("writer.expires_at")}
428
+ )
429
+ AND EXISTS (
430
+ SELECT 1
431
+ FROM _emdash_collections AS collection
432
+ INNER JOIN _emdash_media_usage_index_status AS status
433
+ ON status.collection_id = collection.id
434
+ AND status.scope_key = collection.slug
435
+ WHERE collection.id = input.collection_id
436
+ AND collection.slug = input.collection_slug
437
+ AND status.adapter_id = 'content-media'
438
+ AND status.scope_type = 'collection'
439
+ AND status.capture_state = 'active'
440
+ AND NOT EXISTS (
441
+ SELECT 1
442
+ FROM _emdash_media_usage_collection_deletions AS deletion
443
+ WHERE deletion.collection_id = input.collection_id
444
+ )
445
+ )
446
+ AND EXISTS (
447
+ SELECT 1
448
+ FROM ${sql.ref(tableName)} AS content
449
+ WHERE content.id = input.content_id
450
+ AND content.version = input.source_version
451
+ AND content.updated_at = input.source_updated_at
452
+ AND (
453
+ (input.source_variant = 'columns' AND ${nullableRefMatch("content.live_revision_id", "input.revision_id")})
454
+ OR
455
+ (input.source_variant = 'draft_overlay' AND ${nullableRefMatch("content.draft_revision_id", "input.revision_id")})
456
+ )
457
+ )
458
+ ON CONFLICT (source_key) DO NOTHING
459
+ RETURNING source_key
460
+ `.execute(this.db);
461
+ for (const row of result.rows) inserted.add(row.source_key);
462
+ }
463
+ return inserted;
464
+ } finally {
465
+ await sql`
466
+ WITH input AS (${leases})
467
+ DELETE FROM _emdash_media_usage_generation_writes AS writer
468
+ WHERE EXISTS (
469
+ SELECT 1
470
+ FROM input
471
+ WHERE input.source_key = writer.source_key
472
+ AND input.generation = writer.generation
473
+ AND input.lease_token = writer.lease_token
474
+ )
475
+ `.execute(this.db);
476
+ }
477
+ }
478
+ async replaceExistingSourcesBatch(projections) {
479
+ const unique = [...new Map(projections.map((projection) => [projection.source.sourceKey, projection])).values()];
480
+ if (unique.length === 0) return /* @__PURE__ */ new Set();
481
+ const collectionSlug = unique[0]?.source.collectionSlug;
482
+ const collectionId = unique[0]?.source.collectionId;
483
+ if (!collectionSlug || !collectionId) throw new Error("Canonical media usage batch requires collection identity");
484
+ validateIdentifier(collectionSlug, "collection slug");
485
+ if (unique.some((projection) => projection.source.collectionSlug !== collectionSlug || projection.source.collectionId !== collectionId)) throw new Error("Canonical media usage batch must contain one collection");
486
+ const now = (/* @__PURE__ */ new Date()).toISOString();
487
+ const expiresAt = new Date(Date.now() + MEDIA_USAGE_GENERATION_WRITE_LEASE_MS).toISOString();
488
+ const prepared = unique.map((projection) => {
489
+ const generation = ulid();
490
+ return {
491
+ projection,
492
+ generation,
493
+ leaseToken: ulid(),
494
+ row: this.buildSourceRow(projection.source, generation, now)
495
+ };
496
+ });
497
+ const sourceRows = prepared.map((item) => ({
498
+ ...item.row,
499
+ lease_token: item.leaseToken,
500
+ expected_generation: item.projection.expectedSource.currentGeneration,
501
+ expected_collection_id: item.projection.expectedSource.collectionId,
502
+ expected_updated_at: item.projection.expectedSource.updatedAt,
503
+ expected_source_fingerprint: item.projection.expectedSource.sourceFingerprint,
504
+ expected_source_updated_at: item.projection.expectedSource.sourceUpdatedAt,
505
+ expected_source_version: item.projection.expectedSource.sourceVersion,
506
+ expected_identity_version: item.projection.expectedSource.identityVersion,
507
+ expected_revision_id: item.projection.expectedSource.revisionId,
508
+ expected_source_completeness: item.projection.expectedSource.sourceCompleteness,
509
+ expected_last_attempted_at: item.projection.expectedSource.lastAttemptedAt,
510
+ expected_last_error_code: item.projection.expectedSource.lastErrorCode
511
+ }));
512
+ const occurrenceRows = batchOccurrenceRows(prepared, now);
513
+ if (!mediaUsageQueryBudgetAllows(2 + chunkJsonRows(occurrenceRows).length + chunkJsonRows(sourceRows).length)) {
514
+ if (unique.length === 1) return /* @__PURE__ */ new Set();
515
+ const midpoint = Math.ceil(unique.length / 2);
516
+ const replaced = /* @__PURE__ */ new Set();
517
+ mergeInto(replaced, await this.replaceExistingSourcesBatch(unique.slice(0, midpoint)));
518
+ mergeInto(replaced, await this.replaceExistingSourcesBatch(unique.slice(midpoint)));
519
+ return replaced;
520
+ }
521
+ const leasesPayload = JSON.stringify(prepared.map((item) => ({
522
+ source_key: item.row.source_key,
523
+ collection_id: item.row.collection_id,
524
+ collection_slug: item.row.collection_slug,
525
+ generation: item.generation,
526
+ lease_token: item.leaseToken,
527
+ expires_at: expiresAt,
528
+ created_at: now
529
+ })));
530
+ const leases = this.generationWriteBatchInput(leasesPayload);
531
+ await sql`
532
+ WITH input AS (${leases})
533
+ INSERT INTO _emdash_media_usage_generation_writes (
534
+ source_key, generation, lease_token, expires_at, created_at
535
+ )
536
+ SELECT source_key, generation, lease_token, expires_at, created_at
537
+ FROM input
538
+ WHERE EXISTS (
539
+ SELECT 1
540
+ FROM _emdash_collections AS collection
541
+ INNER JOIN _emdash_media_usage_index_status AS status
542
+ ON status.collection_id = collection.id
543
+ AND status.scope_key = collection.slug
544
+ WHERE collection.id = input.collection_id
545
+ AND collection.slug = input.collection_slug
546
+ AND status.adapter_id = 'content-media'
547
+ AND status.scope_type = 'collection'
548
+ AND status.capture_state = 'active'
549
+ AND NOT EXISTS (
550
+ SELECT 1 FROM _emdash_media_usage_collection_deletions AS deletion
551
+ WHERE deletion.collection_id = input.collection_id
552
+ )
553
+ )
554
+ `.execute(this.db);
555
+ try {
556
+ await this.insertBatchOccurrences(occurrenceRows);
557
+ const tableName = `ec_${collectionSlug}`;
558
+ validateIdentifier(tableName, "content table");
559
+ const replaced = /* @__PURE__ */ new Set();
560
+ for (const sourceRowBatch of chunkJsonRows(sourceRows)) {
561
+ const result = await sql`
562
+ WITH input AS (${this.sourceBatchInput(JSON.stringify(sourceRowBatch))})
563
+ UPDATE _emdash_media_usage_sources AS source
564
+ SET source_type = input.source_type,
565
+ collection_id = input.collection_id,
566
+ collection_slug = input.collection_slug,
567
+ content_id = input.content_id,
568
+ source_variant = input.source_variant,
569
+ locale = input.locale,
570
+ translation_group = input.translation_group,
571
+ content_slug = input.content_slug,
572
+ content_title = input.content_title,
573
+ content_status = input.content_status,
574
+ content_scheduled_at = input.content_scheduled_at,
575
+ content_deleted_at = input.content_deleted_at,
576
+ revision_id = input.revision_id,
577
+ current_generation = input.current_generation,
578
+ schema_version = input.schema_version,
579
+ source_updated_at = input.source_updated_at,
580
+ source_version = input.source_version,
581
+ source_fingerprint = input.source_fingerprint,
582
+ identity_version = input.identity_version,
583
+ source_completeness = input.source_completeness,
584
+ last_attempted_at = input.last_attempted_at,
585
+ last_error_code = input.last_error_code,
586
+ indexed_at = input.indexed_at,
587
+ updated_at = input.updated_at
588
+ FROM input
589
+ WHERE source.source_key = input.source_key
590
+ AND source.current_generation = input.expected_generation
591
+ AND ${this.batchRefsMatch("source.collection_id", "input.expected_collection_id")}
592
+ AND source.updated_at = input.expected_updated_at
593
+ AND ${this.batchRefsMatch("source.source_fingerprint", "input.expected_source_fingerprint")}
594
+ AND ${this.batchRefsMatch("source.source_updated_at", "input.expected_source_updated_at")}
595
+ AND ${this.batchRefsMatch("source.source_version", "input.expected_source_version")}
596
+ AND ${this.batchRefsMatch("source.identity_version", "input.expected_identity_version")}
597
+ AND ${this.batchRefsMatch("source.revision_id", "input.expected_revision_id")}
598
+ AND source.source_completeness = input.expected_source_completeness
599
+ AND ${this.batchRefsMatch("source.last_attempted_at", "input.expected_last_attempted_at")}
600
+ AND ${this.batchRefsMatch("source.last_error_code", "input.expected_last_error_code")}
601
+ AND EXISTS (
602
+ SELECT 1
603
+ FROM _emdash_media_usage_generation_writes AS writer
604
+ WHERE writer.source_key = input.source_key
605
+ AND writer.generation = input.current_generation
606
+ AND writer.lease_token = input.lease_token
607
+ AND ${this.generationWriteLeaseExpiryIsInFuture("writer.expires_at")}
608
+ )
609
+ AND EXISTS (
610
+ SELECT 1
611
+ FROM _emdash_collections AS collection
612
+ INNER JOIN _emdash_media_usage_index_status AS status
613
+ ON status.collection_id = collection.id
614
+ AND status.scope_key = collection.slug
615
+ WHERE collection.id = input.collection_id
616
+ AND collection.slug = input.collection_slug
617
+ AND status.adapter_id = 'content-media'
618
+ AND status.scope_type = 'collection'
619
+ AND status.capture_state = 'active'
620
+ AND NOT EXISTS (
621
+ SELECT 1
622
+ FROM _emdash_media_usage_collection_deletions AS deletion
623
+ WHERE deletion.collection_id = input.collection_id
624
+ )
625
+ )
626
+ AND EXISTS (
627
+ SELECT 1
628
+ FROM ${sql.ref(tableName)} AS content
629
+ WHERE content.id = input.content_id
630
+ AND content.version = input.source_version
631
+ AND content.updated_at = input.source_updated_at
632
+ AND (
633
+ (input.source_variant = 'columns' AND ${nullableRefMatch("content.live_revision_id", "input.revision_id")})
634
+ OR
635
+ (input.source_variant = 'draft_overlay' AND ${nullableRefMatch("content.draft_revision_id", "input.revision_id")})
636
+ )
637
+ )
638
+ RETURNING ${isPostgres(this.db) ? sql`source.source_key` : sql`source_key`} AS source_key
639
+ `.execute(this.db);
640
+ for (const row of result.rows) replaced.add(row.source_key);
641
+ }
642
+ return replaced;
643
+ } finally {
644
+ await sql`
645
+ WITH input AS (${leases})
646
+ DELETE FROM _emdash_media_usage_generation_writes AS writer
647
+ WHERE EXISTS (
648
+ SELECT 1
649
+ FROM input
650
+ WHERE input.source_key = writer.source_key
651
+ AND input.generation = writer.generation
652
+ AND input.lease_token = writer.lease_token
653
+ )
654
+ `.execute(this.db);
655
+ }
656
+ }
657
+ async matchingExistingSourcesBatch(projections) {
658
+ if (projections.length === 0) return /* @__PURE__ */ new Set();
659
+ const now = (/* @__PURE__ */ new Date()).toISOString();
660
+ const rows = projections.map((projection) => ({
661
+ ...this.buildSourceRow(projection.source, projection.expectedSource.currentGeneration, now),
662
+ expected_generation: projection.expectedSource.currentGeneration,
663
+ expected_collection_id: projection.expectedSource.collectionId,
664
+ expected_updated_at: projection.expectedSource.updatedAt,
665
+ expected_source_fingerprint: projection.expectedSource.sourceFingerprint,
666
+ expected_source_updated_at: projection.expectedSource.sourceUpdatedAt,
667
+ expected_source_version: projection.expectedSource.sourceVersion,
668
+ expected_identity_version: projection.expectedSource.identityVersion,
669
+ expected_revision_id: projection.expectedSource.revisionId,
670
+ expected_source_completeness: projection.expectedSource.sourceCompleteness,
671
+ expected_last_attempted_at: projection.expectedSource.lastAttemptedAt,
672
+ expected_last_error_code: projection.expectedSource.lastErrorCode
673
+ }));
674
+ if (!mediaUsageQueryBudgetAllows(chunkJsonRows(rows).length)) {
675
+ if (projections.length === 1) return /* @__PURE__ */ new Set();
676
+ const midpoint = Math.ceil(projections.length / 2);
677
+ const matched = /* @__PURE__ */ new Set();
678
+ mergeInto(matched, await this.matchingExistingSourcesBatch(projections.slice(0, midpoint)));
679
+ mergeInto(matched, await this.matchingExistingSourcesBatch(projections.slice(midpoint)));
680
+ return matched;
681
+ }
682
+ const matched = /* @__PURE__ */ new Set();
683
+ for (const batch of chunkJsonRows(rows)) {
684
+ const result = await sql`
685
+ WITH input AS (${this.sourceBatchInput(JSON.stringify(batch))})
686
+ SELECT source.source_key
687
+ FROM _emdash_media_usage_sources AS source
688
+ INNER JOIN input ON input.source_key = source.source_key
689
+ WHERE source.current_generation = input.expected_generation
690
+ AND ${this.batchRefsMatch("source.collection_id", "input.expected_collection_id")}
691
+ AND source.updated_at = input.expected_updated_at
692
+ AND ${this.batchRefsMatch("source.source_fingerprint", "input.expected_source_fingerprint")}
693
+ AND ${this.batchRefsMatch("source.source_updated_at", "input.expected_source_updated_at")}
694
+ AND ${this.batchRefsMatch("source.source_version", "input.expected_source_version")}
695
+ AND ${this.batchRefsMatch("source.identity_version", "input.expected_identity_version")}
696
+ AND ${this.batchRefsMatch("source.revision_id", "input.expected_revision_id")}
697
+ AND source.source_completeness = input.expected_source_completeness
698
+ AND ${this.batchRefsMatch("source.last_attempted_at", "input.expected_last_attempted_at")}
699
+ AND ${this.batchRefsMatch("source.last_error_code", "input.expected_last_error_code")}
700
+ AND EXISTS (
701
+ SELECT 1
702
+ FROM _emdash_collections AS collection
703
+ WHERE collection.id = source.collection_id
704
+ AND collection.slug = source.collection_slug
705
+ )
706
+ `.execute(this.db);
707
+ for (const row of result.rows) matched.add(row.source_key);
708
+ }
709
+ return matched;
710
+ }
711
+ async markSourceAttempted(source) {
712
+ if (source.collectionId !== void 0 && source.collectionId !== null) {
713
+ const expectedSource = await this.findSource(source.sourceKey);
714
+ if (!(await this.markSourceAttemptedIfMatching(source, expectedSource)).attempted) throw new Error(`Canonical media usage source ${source.sourceKey} is no longer current`);
715
+ const attempted = await this.findSource(source.sourceKey);
716
+ if (!attempted) throw new Error(`Media usage source ${source.sourceKey} was not persisted`);
717
+ return attempted;
718
+ }
719
+ const generation = ulid();
720
+ await this.withGenerationWriteLease(source, generation, async (leaseToken, now) => {
721
+ const row = this.buildAttemptedSourceRow(source, generation, now);
722
+ const updates = this.attemptedSourceUpdateSet(source, row);
723
+ if (((await this.db.insertInto("_emdash_media_usage_sources").values(row).onConflict((oc) => oc.column("source_key").doUpdateSet(updates)).executeTakeFirst()).numInsertedOrUpdatedRows ?? 0n) <= 0n) throw new Error(`Media usage generation lease expired for ${source.sourceKey}`);
724
+ });
725
+ const attempted = await this.findSource(source.sourceKey);
726
+ if (!attempted) throw new Error(`Media usage source ${source.sourceKey} was not persisted`);
727
+ return attempted;
728
+ }
729
+ async markSourceAttemptedIfMatching(source, expectedSource) {
730
+ const generation = ulid();
731
+ let attempted = false;
732
+ if (expectedSource === null) await this.withGenerationWriteLease(source, generation, async (leaseToken, now) => {
733
+ const row = this.buildAttemptedSourceRow(source, generation, now);
734
+ await withTransaction(this.db, async (trx) => {
735
+ if (!await this.lockCanonicalSourceCollection(trx, source)) return;
736
+ attempted = await this.persistSourceIfWriteLease(trx, row, leaseToken, sql`ON CONFLICT (source_key) DO NOTHING`);
737
+ });
738
+ });
739
+ else {
740
+ const row = this.buildAttemptedSourceRow(source, generation, (/* @__PURE__ */ new Date()).toISOString());
741
+ await withTransaction(this.db, async (trx) => {
742
+ if (!await this.lockCanonicalSourceCollection(trx, source)) return;
743
+ attempted = await this.updateAttemptedSourceIfMatching(trx, source, row, expectedSource);
744
+ });
745
+ }
746
+ return {
747
+ attempted,
748
+ source: attempted ? null : await this.findSource(source.sourceKey)
749
+ };
750
+ }
751
+ async findActiveEntryCountsByMediaIds(mediaIds) {
752
+ const uniqueMediaIds = [...new Set(mediaIds)];
753
+ const counts = new Map(uniqueMediaIds.map((mediaId) => [mediaId, 0]));
754
+ for (const mediaIdBatch of chunks(uniqueMediaIds, SQL_BATCH_SIZE)) {
755
+ const visibleEntries = this.currentContentMediaUsageBaseQuery().select([
756
+ "u.media_id as media_id",
757
+ "s.collection_slug as collection_slug",
758
+ "s.content_id as content_id"
759
+ ]).where("u.media_id", "in", mediaIdBatch).where((eb) => eb.not(eb.exists(eb.selectFrom("_emdash_media_usage_sources as deleted_source").select("deleted_source.source_key").where("deleted_source.source_type", "=", "content").whereRef("deleted_source.collection_slug", "=", "s.collection_slug").whereRef("deleted_source.content_id", "=", "s.content_id").where("deleted_source.source_variant", "in", ["columns", "draft_overlay"]).where(contentSourceMatchesActiveCollection("deleted_source", "collection.id")).where("deleted_source.content_deleted_at", "is not", null)))).distinct().as("visible_entries");
760
+ const rows = await this.db.selectFrom(visibleEntries).select("media_id").select((eb) => eb.fn.countAll().as("usage_count")).groupBy("media_id").execute();
761
+ for (const row of rows) if (row.media_id !== null) counts.set(row.media_id, Number(row.usage_count));
762
+ }
763
+ return counts;
764
+ }
765
+ /**
766
+ * Read collection index status and the named options in one statement.
767
+ * The one-row anchor keeps the option values readable on a site with no
768
+ * collections.
769
+ */
770
+ async findCoverageWithOptions(identity, optionNames) {
771
+ let query = this.db.selectFrom(this.db.selectNoFrom(sql`1`.as("anchor")).as("anchor")).leftJoin("_emdash_collections as collection", (join) => join.on(sql`1 = 1`)).leftJoin("_emdash_media_usage_index_status as status", (join) => join.on("status.adapter_id", "=", identity.adapterId).on("status.scope_type", "=", identity.scopeType).onRef("status.scope_key", "=", "collection.slug")).select([
772
+ "collection.slug as collection_slug",
773
+ "status.status as status",
774
+ "status.schema_version as schema_version",
775
+ "status.reconciliation_required as reconciliation_required"
776
+ ]).orderBy("collection.slug", "asc");
777
+ const optionAliases = optionNames.map((name, index) => [name, `option_${index}`]);
778
+ for (const [name, alias] of optionAliases) query = query.select((eb) => eb.selectFrom("options").select("value").where("name", "=", name).as(alias));
779
+ const rows = await query.execute();
780
+ const scopes = [];
781
+ for (const row of rows) {
782
+ if (typeof row.collection_slug !== "string") continue;
783
+ scopes.push({
784
+ collectionSlug: row.collection_slug,
785
+ status: typeof row.status === "string" ? row.status : null,
786
+ schemaVersion: row.schema_version == null ? null : Number(row.schema_version),
787
+ reconciliationRequired: row.reconciliation_required != null && Number(row.reconciliation_required) !== 0
788
+ });
789
+ }
790
+ const firstRow = rows[0];
791
+ const options = /* @__PURE__ */ new Map();
792
+ for (const [name, alias] of optionAliases) {
793
+ const value = firstRow?.[alias];
794
+ options.set(name, typeof value === "string" ? value : null);
795
+ }
796
+ return {
797
+ scopes,
798
+ options
799
+ };
800
+ }
801
+ async findCollectionProgress() {
802
+ const row = (await sql`
803
+ WITH collection_progress AS (
804
+ SELECT
805
+ CASE WHEN status.status = 'complete'
806
+ AND status.schema_version = ${CONTENT_SOURCE_SCHEMA_VERSION}
807
+ AND status.reconciliation_required = 0
808
+ AND status.capture_state = 'active'
809
+ AND NOT EXISTS (
810
+ SELECT 1 FROM _emdash_media_usage_work AS work
811
+ WHERE work.collection_id = collection.id
812
+ AND work.collection_slug = collection.slug
813
+ )
814
+ THEN 1 ELSE 0 END AS is_ready,
815
+ CASE WHEN status.collection_id IS NULL
816
+ OR COALESCE(status.capture_state, '') <> 'active'
817
+ OR status.status NOT IN ('complete', 'never', 'running', 'partial', 'failed', 'stale')
818
+ OR status.status = 'failed'
819
+ OR (
820
+ status.reconciliation_required = 0
821
+ AND (
822
+ status.status <> 'complete'
823
+ OR COALESCE(status.schema_version, -1) <> ${CONTENT_SOURCE_SCHEMA_VERSION}
824
+ )
825
+ AND NOT EXISTS (
826
+ SELECT 1 FROM _emdash_media_usage_work AS work
827
+ WHERE work.collection_id = collection.id
828
+ AND work.collection_slug = collection.slug
829
+ )
830
+ )
831
+ OR EXISTS (
832
+ SELECT 1 FROM _emdash_media_usage_work AS work
833
+ WHERE work.collection_id = collection.id
834
+ AND work.collection_slug = collection.slug
835
+ AND work.state = 'failed'
836
+ )
837
+ OR EXISTS (
838
+ SELECT 1 FROM _emdash_media_usage_reconciliations AS reconciliation
839
+ WHERE reconciliation.collection_id = collection.id
840
+ AND reconciliation.collection_slug = collection.slug
841
+ AND reconciliation.state = 'failed'
842
+ AND status.reconciliation_required = 1
843
+ AND (
844
+ reconciliation.target_epoch IS NULL
845
+ OR reconciliation.target_epoch >= status.change_epoch
846
+ )
847
+ )
848
+ THEN 1 ELSE 0 END AS needs_attention
849
+ FROM _emdash_collections AS collection
850
+ LEFT JOIN _emdash_media_usage_index_status AS status
851
+ ON status.adapter_id = 'content-media'
852
+ AND status.scope_type = 'collection'
853
+ AND status.collection_id = collection.id
854
+ AND status.scope_key = collection.slug
855
+ WHERE NOT EXISTS (
856
+ SELECT 1 FROM _emdash_media_usage_collection_deletions AS deletion
857
+ WHERE deletion.collection_id = collection.id
858
+ AND deletion.collection_slug = collection.slug
859
+ )
860
+ )
861
+ SELECT
862
+ (
863
+ SELECT activation.runtime_generation
864
+ FROM _emdash_media_usage_activation AS activation
865
+ WHERE activation.task_key = 'incremental_capture'
866
+ ) AS activation_generation,
867
+ EXISTS (
868
+ SELECT 1 FROM _emdash_media_usage_activation AS activation
869
+ WHERE activation.task_key = 'incremental_capture'
870
+ AND activation.state = 'active'
871
+ ) AS activation_active,
872
+ COUNT(*) AS total_collections,
873
+ COALESCE(SUM(is_ready), 0) AS ready_collections,
874
+ EXISTS (
875
+ SELECT 1 FROM _emdash_media_usage_collection_deletions AS deletion
876
+ WHERE deletion.state IN ('pending', 'retry', 'leased')
877
+ ) AS cleanup_pending,
878
+ CASE WHEN COALESCE(MAX(needs_attention), 0) = 1 OR EXISTS (
879
+ SELECT 1 FROM _emdash_media_usage_collection_deletions AS deletion
880
+ WHERE deletion.state = 'failed'
881
+ ) THEN 1 ELSE 0 END AS needs_attention
882
+ FROM collection_progress
883
+ `.execute(this.db)).rows[0];
884
+ if (!row) throw new Error("Media usage progress query returned no result");
885
+ if (!row.activation_active) return null;
886
+ if (Number(row.activation_generation) !== MEDIA_USAGE_ACTIVATION_RUNTIME_GENERATION) throw new MediaUsageActivationVersionMismatchError("Media usage activation runtime generation is incompatible");
887
+ const readyCollections = Number(row.ready_collections);
888
+ const totalCollections = Number(row.total_collections);
889
+ const cleanupPending = Number(row.cleanup_pending);
890
+ const needsAttention = Number(row.needs_attention);
891
+ if (!Number.isSafeInteger(readyCollections) || !Number.isSafeInteger(totalCollections) || readyCollections < 0 || totalCollections < readyCollections || cleanupPending !== 0 && cleanupPending !== 1 || needsAttention !== 0 && needsAttention !== 1) throw new Error("Media usage progress query returned invalid counts");
892
+ return {
893
+ status: needsAttention ? "needs_attention" : readyCollections === totalCollections && cleanupPending === 0 ? "ready" : "indexing",
894
+ readyCollections,
895
+ totalCollections
896
+ };
897
+ }
898
+ async findCurrentEntryUsagePageByMediaId(mediaId, options = {}) {
899
+ const requestedLimit = Math.floor(options.limit ?? 50);
900
+ const limit = Number.isFinite(requestedLimit) ? Math.min(Math.max(1, requestedLimit), 100) : 50;
901
+ const cursor = options.cursor ? decodeCursor(options.cursor) : null;
902
+ if (cursor && (cursor.orderValue.length === 0 || cursor.id.length === 0)) throw new InvalidCursorError(options.cursor ?? "");
903
+ let matchedGroups = this.currentContentMediaUsageBaseQuery().select([
904
+ "collection.id as collection_id",
905
+ "s.collection_slug as collection_slug",
906
+ "s.content_id as content_id"
907
+ ]).where("u.media_id", "=", mediaId).distinct();
908
+ if (cursor) matchedGroups = matchedGroups.where((eb) => eb.or([eb("s.collection_slug", ">", cursor.orderValue), eb.and([eb("s.collection_slug", "=", cursor.orderValue), eb("s.content_id", ">", cursor.id)])]));
909
+ matchedGroups = matchedGroups.orderBy("s.collection_slug", "asc").orderBy("s.content_id", "asc").limit(limit + 1);
910
+ const rows = await this.db.with("matched_groups", () => matchedGroups).with("page_groups", (db) => db.selectFrom("matched_groups").selectAll().orderBy("collection_slug", "asc").orderBy("content_id", "asc").limit(limit)).with("entry_state", (db) => db.selectFrom("page_groups as page").crossJoin("_emdash_media_usage_sources as state").select([
911
+ "page.collection_id",
912
+ "page.collection_slug",
913
+ "page.content_id"
914
+ ]).select((eb) => eb.fn.max("state.content_deleted_at").as("entry_deleted_at")).whereRef("page.collection_slug", "=", "state.collection_slug").whereRef("page.content_id", "=", "state.content_id").where("state.source_type", "=", "content").where("state.source_variant", "in", ["columns", "draft_overlay"]).where(contentSourceMatchesActiveCollection("state", "page.collection_id")).groupBy([
915
+ "page.collection_id",
916
+ "page.collection_slug",
917
+ "page.content_id"
918
+ ])).selectFrom("entry_state as page").crossJoin("_emdash_media_usage_sources as s").crossJoin("_emdash_media_usage as u").whereRef("page.collection_slug", "=", "s.collection_slug").whereRef("page.content_id", "=", "s.content_id").where(contentSourceMatchesActiveCollection("s", "page.collection_id")).whereRef("s.source_key", "=", "u.source_key").whereRef("s.current_generation", "=", "u.generation").select(currentUsageSelect).select("page.entry_deleted_at").select(sql`CASE
919
+ WHEN (SELECT COUNT(*) FROM matched_groups) > ${limit} THEN 1
920
+ ELSE 0
921
+ END`.as("has_more")).where("u.media_id", "=", mediaId).where("s.source_type", "=", "content").where("s.collection_slug", "is not", null).where("s.content_id", "is not", null).where("s.source_variant", "in", ["columns", "draft_overlay"]).where(CONTENT_SOURCE_ELIGIBILITY).orderBy("s.collection_slug", "asc").orderBy("s.content_id", "asc").orderBy("s.source_variant", "asc").orderBy("s.source_key", "asc").orderBy("u.field_path", "asc").orderBy("u.occurrence_index", "asc").orderBy("u.id", "asc").execute();
922
+ const items = groupUsageRows(rows);
923
+ const result = { items };
924
+ if (Number(rows[0]?.has_more ?? 0) === 1 && items.length > 0) {
925
+ const last = items.at(-1);
926
+ result.nextCursor = encodeCursor(last.collectionSlug, last.contentId);
927
+ }
928
+ return result;
929
+ }
930
+ async findCurrentUsageByMediaId(mediaId) {
931
+ return (await this.db.selectFrom("_emdash_media_usage_sources as s").innerJoin("_emdash_media_usage as u", (join) => join.onRef("u.source_key", "=", "s.source_key").onRef("u.generation", "=", "s.current_generation")).select(currentUsageSelect).where("u.media_id", "=", mediaId).orderBy("s.source_key", "asc").orderBy("u.field_path", "asc").orderBy("u.occurrence_index", "asc").execute()).map(rowToUsageRecord);
932
+ }
933
+ async findCurrentUsageByProviderAsset(provider, providerAssetId) {
934
+ return (await this.db.selectFrom("_emdash_media_usage_sources as s").innerJoin("_emdash_media_usage as u", (join) => join.onRef("u.source_key", "=", "s.source_key").onRef("u.generation", "=", "s.current_generation")).select(currentUsageSelect).where("u.provider", "=", provider).where("u.provider_asset_id", "=", providerAssetId).orderBy("s.source_key", "asc").orderBy("u.field_path", "asc").orderBy("u.occurrence_index", "asc").execute()).map(rowToUsageRecord);
935
+ }
936
+ async findCurrentUsagePageByMediaId(mediaId, options = {}) {
937
+ return this.findCurrentUsagePage((query) => query.where("u.media_id", "=", mediaId), options);
938
+ }
939
+ async findCurrentUsagePageByProviderAsset(provider, providerAssetId, options = {}) {
940
+ return this.findCurrentUsagePage((query) => query.where("u.provider", "=", provider).where("u.provider_asset_id", "=", providerAssetId), options);
941
+ }
942
+ async deleteSource(sourceKey) {
943
+ return this.deleteSources([sourceKey]);
944
+ }
945
+ async deleteSourceIfCurrent(sourceKey, expectedCurrentGeneration) {
946
+ let deleted = false;
947
+ await withTransaction(this.db, async (trx) => {
948
+ await this.lockCleanupBeforeSourceDelete(trx);
949
+ const result = await trx.deleteFrom("_emdash_media_usage_sources").where("source_key", "=", sourceKey).where("current_generation", "=", expectedCurrentGeneration).executeTakeFirst();
950
+ deleted = Number(result.numDeletedRows ?? 0) > 0;
951
+ if (!deleted) return;
952
+ await this.deleteSourceGenerationOccurrences(trx, sourceKey, expectedCurrentGeneration);
953
+ });
954
+ return {
955
+ deleted,
956
+ source: await this.findSource(sourceKey)
957
+ };
958
+ }
959
+ async deleteSourceIfMatching(sourceKey, expectedSource) {
960
+ let deleted = false;
961
+ await withTransaction(this.db, async (trx) => {
962
+ await this.lockCleanupBeforeSourceDelete(trx);
963
+ const result = await trx.deleteFrom("_emdash_media_usage_sources").where("source_key", "=", sourceKey).where(this.sourceMatchExpression(expectedSource)).where(this.currentCollectionExists(expectedSource.collectionId, expectedSource.collectionSlug)).executeTakeFirst();
964
+ deleted = Number(result.numDeletedRows ?? 0) > 0;
965
+ if (!deleted) return;
966
+ await this.deleteSourceGenerationOccurrences(trx, sourceKey, expectedSource.currentGeneration);
967
+ });
968
+ return {
969
+ deleted,
970
+ source: await this.findSource(sourceKey)
971
+ };
972
+ }
973
+ async deleteSourceIfMatchingContentAbsent(sourceKey, expectedSource, collectionSlug, contentId) {
974
+ validateIdentifier(collectionSlug, "collection slug");
975
+ const tableName = `ec_${collectionSlug}`;
976
+ let deleted = false;
977
+ await withTransaction(this.db, async (trx) => {
978
+ await this.lockCleanupBeforeSourceDelete(trx);
979
+ const result = await trx.deleteFrom("_emdash_media_usage_sources").where("source_key", "=", sourceKey).where(this.sourceMatchExpression(expectedSource)).where(this.currentCollectionExists(expectedSource.collectionId, expectedSource.collectionSlug)).where(sql`NOT EXISTS (SELECT 1 FROM ${sql.ref(tableName)} WHERE id = ${contentId})`).executeTakeFirst();
980
+ deleted = Number(result.numDeletedRows ?? 0) > 0;
981
+ if (!deleted) return;
982
+ await this.deleteSourceGenerationOccurrences(trx, sourceKey, expectedSource.currentGeneration);
983
+ });
984
+ const contentPresent = deleted ? false : await this.contentRowExists(tableName, contentId);
985
+ return {
986
+ deleted,
987
+ contentPresent,
988
+ source: deleted || contentPresent ? null : await this.findSource(sourceKey)
989
+ };
990
+ }
991
+ async deleteSources(sourceKeys) {
992
+ return this.deleteSourceKeys(sourceKeys);
993
+ }
994
+ async deleteContentSources(collectionSlug, contentId) {
995
+ const sourceKeys = (await this.db.selectFrom("_emdash_media_usage_sources").select("source_key").where("source_type", "=", "content").where("collection_slug", "=", collectionSlug).where("content_id", "=", contentId).execute()).map((row) => row.source_key);
996
+ return this.deleteSourceKeys(sourceKeys);
997
+ }
998
+ async deleteCollectionSources(collectionSlug) {
999
+ let deleted = 0;
1000
+ while (true) {
1001
+ const sourceRows = await this.db.selectFrom("_emdash_media_usage_sources").select("source_key").where("source_type", "=", "content").where("collection_slug", "=", collectionSlug).orderBy("source_key", "asc").limit(SQL_BATCH_SIZE).execute();
1002
+ if (sourceRows.length === 0) break;
1003
+ deleted += await this.deleteSourceKeys(sourceRows.map((row) => row.source_key));
1004
+ }
1005
+ return deleted;
1006
+ }
1007
+ async findCollectionContentSources(collectionSlug, collectionId) {
1008
+ let query = this.db.selectFrom("_emdash_media_usage_sources").selectAll().where("source_type", "=", "content").where("collection_slug", "=", collectionSlug).orderBy("source_key", "asc");
1009
+ if (collectionId !== void 0) query = query.where("collection_id", "=", collectionId);
1010
+ return (await query.execute()).map((row) => rowToSource(row));
1011
+ }
1012
+ async claimMediaUsageCleanup(input) {
1013
+ const leaseDurationSeconds = cleanupDurationSeconds(input.leaseDurationSeconds);
1014
+ const nextEligibleDelaySeconds = cleanupDurationSeconds(input.nextEligibleDelaySeconds);
1015
+ const sweepSafetyWindowSeconds = cleanupDurationSeconds(input.sweepSafetyWindowSeconds);
1016
+ const claimedAt = this.cleanupTimestampOffset(0);
1017
+ const leaseExpiresAt = this.cleanupTimestampOffset(leaseDurationSeconds);
1018
+ const nextEligibleAt = this.cleanupTimestampOffset(nextEligibleDelaySeconds);
1019
+ const sweepBeforeAt = this.cleanupTimestampOffset(-sweepSafetyWindowSeconds);
1020
+ const row = await this.db.updateTable("_emdash_media_usage_cleanup").set({
1021
+ lease_token: input.leaseToken,
1022
+ lease_expires_at: leaseExpiresAt,
1023
+ next_eligible_at: nextEligibleAt,
1024
+ last_started_at: claimedAt,
1025
+ updated_at: claimedAt,
1026
+ scan_before_at: sql`CASE
1027
+ WHEN scan_before_at IS NULL THEN ${sweepBeforeAt}
1028
+ ELSE scan_before_at
1029
+ END`
1030
+ }).where("task_key", "=", "projection_gc").where(this.cleanupTimestampIsDue("next_eligible_at")).where((eb) => eb.or([eb("lease_token", "is", null), this.cleanupTimestampIsDue("lease_expires_at")])).returning([
1031
+ "cursor_created_at",
1032
+ "cursor_id",
1033
+ "last_started_at",
1034
+ "scan_before_at",
1035
+ "consecutive_failures"
1036
+ ]).executeTakeFirst();
1037
+ if (!row) return null;
1038
+ if (!row.last_started_at || !row.scan_before_at) throw new Error("Media usage cleanup claim did not persist its database timestamps");
1039
+ return {
1040
+ leaseToken: input.leaseToken,
1041
+ cursor: row.cursor_created_at && row.cursor_id ? {
1042
+ createdAt: row.cursor_created_at,
1043
+ id: row.cursor_id
1044
+ } : null,
1045
+ claimedAt: row.last_started_at,
1046
+ scanBeforeAt: row.scan_before_at,
1047
+ consecutiveFailures: row.consecutive_failures
1048
+ };
1049
+ }
1050
+ /**
1051
+ * Scans for reclaimable occurrences, or resolves to `null` when the sweep was
1052
+ * never issued because the lease is gone or the tick is out of budget. An
1053
+ * empty array means the scan ran and found nothing, which lets the caller
1054
+ * retire the sweep window; `null` must leave the cursor where it was.
1055
+ */
1056
+ async findMediaUsageCleanupCandidates(input) {
1057
+ if (!await this.admitCleanupScan(input.cleanupLease, input.canIssueStatement)) return null;
1058
+ let query = this.db.selectFrom("_emdash_media_usage as u").leftJoin("_emdash_media_usage_sources as s", "s.source_key", "u.source_key").leftJoin("_emdash_media_usage_generation_writes as writer", (join) => join.onRef("writer.source_key", "=", "u.source_key").onRef("writer.generation", "=", "u.generation")).select([
1059
+ "u.id as id",
1060
+ "u.source_key as source_key",
1061
+ "u.generation as generation",
1062
+ "u.created_at as created_at",
1063
+ "s.current_generation as current_generation",
1064
+ "s.indexed_at as indexed_at",
1065
+ "writer.expires_at as write_lease_expires_at"
1066
+ ]).where("u.created_at", "<", input.cutoff).orderBy("u.created_at", "asc").orderBy("u.id", "asc").limit(Math.max(0, Math.floor(input.limit)));
1067
+ if (input.cursor) {
1068
+ const cursor = input.cursor;
1069
+ query = query.where((eb) => eb(eb.refTuple("u.created_at", "u.id"), ">", eb.tuple(cursor.createdAt, cursor.id)));
1070
+ }
1071
+ return (await query.execute()).map((row) => ({
1072
+ id: row.id,
1073
+ sourceKey: row.source_key,
1074
+ generation: row.generation,
1075
+ createdAt: row.created_at,
1076
+ currentGeneration: row.current_generation,
1077
+ indexedAt: row.indexed_at,
1078
+ writeLeaseExpiresAt: row.write_lease_expires_at
1079
+ }));
1080
+ }
1081
+ async completeMediaUsageCleanup(input) {
1082
+ const updates = {
1083
+ lease_token: null,
1084
+ lease_expires_at: null,
1085
+ cursor_created_at: input.sweepComplete ? null : input.nextCursor?.createdAt ?? null,
1086
+ cursor_id: input.sweepComplete ? null : input.nextCursor?.id ?? null,
1087
+ ...input.sweepComplete ? { scan_before_at: null } : {},
1088
+ consecutive_failures: 0,
1089
+ last_completed_at: this.cleanupTimestampOffset(0),
1090
+ last_candidate_count: input.candidateCount,
1091
+ last_deleted_orphans: input.deletedOrphans,
1092
+ last_deleted_stale: input.deletedStale,
1093
+ last_deleted_abandoned: input.deletedAbandoned,
1094
+ last_deleted_write_leases: input.deletedWriteLeases,
1095
+ last_backlog_lower_bound: input.backlogLowerBound,
1096
+ last_scan_has_more: input.scanHasMore ? 1 : 0,
1097
+ last_duration_ms: input.durationMs,
1098
+ last_error_code: null,
1099
+ updated_at: this.cleanupTimestampOffset(0)
1100
+ };
1101
+ const result = await this.db.updateTable("_emdash_media_usage_cleanup").set(updates).where("task_key", "=", "projection_gc").where("lease_token", "=", input.leaseToken).where(this.cleanupLeaseExpiryIsInFuture("_emdash_media_usage_cleanup.lease_expires_at")).executeTakeFirst();
1102
+ return Number(result.numUpdatedRows ?? 0) > 0;
1103
+ }
1104
+ async failMediaUsageCleanup(input) {
1105
+ const retryDelaySeconds = cleanupDurationSeconds(input.retryDelaySeconds);
1106
+ const result = await this.db.updateTable("_emdash_media_usage_cleanup").set({
1107
+ lease_token: null,
1108
+ lease_expires_at: null,
1109
+ next_eligible_at: this.cleanupTimestampOffset(retryDelaySeconds),
1110
+ consecutive_failures: input.consecutiveFailures,
1111
+ last_completed_at: this.cleanupTimestampOffset(0),
1112
+ last_duration_ms: input.durationMs,
1113
+ last_error_code: input.errorCode,
1114
+ updated_at: this.cleanupTimestampOffset(0)
1115
+ }).where("task_key", "=", "projection_gc").where("lease_token", "=", input.leaseToken).where(this.cleanupLeaseExpiryIsInFuture("_emdash_media_usage_cleanup.lease_expires_at")).executeTakeFirst();
1116
+ return Number(result.numUpdatedRows ?? 0) > 0;
1117
+ }
1118
+ async deleteOrphanOccurrencesOlderThan(cutoff, limit, options = {}) {
1119
+ const batchLimit = Math.floor(limit);
1120
+ if (batchLimit <= 0) return 0;
1121
+ if (options.candidateIds) return this.deleteOrphanCandidateIds(options.candidateIds.slice(0, batchLimit), cutoff, options.cleanupLease, options.canIssueStatement);
1122
+ if (!await this.admitCleanupScan(options.cleanupLease, options.canIssueStatement)) return 0;
1123
+ const rows = await this.db.selectFrom("_emdash_media_usage as u").leftJoin("_emdash_media_usage_sources as s", (join) => join.onRef("s.source_key", "=", "u.source_key")).leftJoin("_emdash_media_usage_generation_writes as writer", (join) => join.onRef("writer.source_key", "=", "u.source_key").onRef("writer.generation", "=", "u.generation")).select("u.id").where("s.source_key", "is", null).where("u.created_at", "<", cutoff).where(this.noActiveGenerationWriteExpression("u")).orderBy("u.created_at", "asc").orderBy("u.id", "asc").limit(batchLimit).execute();
1124
+ return this.deleteOrphanCandidateIds(rows.map((row) => row.id), cutoff, options.cleanupLease, options.canIssueStatement);
1125
+ }
1126
+ async deleteStaleGenerationsOlderThan(cutoff, limit, options = {}) {
1127
+ const batchLimit = Math.floor(limit);
1128
+ if (batchLimit <= 0) return 0;
1129
+ if (options.candidateIds) return this.deleteStaleCandidateIds(options.candidateIds.slice(0, batchLimit), cutoff, options.cleanupLease, options.canIssueStatement);
1130
+ if (!await this.admitCleanupScan(options.cleanupLease, options.canIssueStatement)) return 0;
1131
+ const rows = await this.db.selectFrom("_emdash_media_usage as u").innerJoin("_emdash_media_usage_sources as s", (join) => join.onRef("s.source_key", "=", "u.source_key")).leftJoin("_emdash_media_usage_generation_writes as writer", (join) => join.onRef("writer.source_key", "=", "u.source_key").onRef("writer.generation", "=", "u.generation")).select("u.id").where("u.created_at", "<", cutoff).whereRef("u.generation", "!=", "s.current_generation").whereRef("u.created_at", "<", "s.indexed_at").where(this.noActiveGenerationWriteExpression("u")).orderBy("u.created_at", "asc").orderBy("u.id", "asc").limit(batchLimit).execute();
1132
+ return this.deleteStaleCandidateIds(rows.map((row) => row.id), cutoff, options.cleanupLease, options.canIssueStatement);
1133
+ }
1134
+ async deleteAbandonedGenerationsOlderThan(cutoff, limit, options = {}) {
1135
+ const batchLimit = Math.floor(limit);
1136
+ if (batchLimit <= 0) return 0;
1137
+ if (options.candidateIds) return this.deleteAbandonedCandidateIds(options.candidateIds.slice(0, batchLimit), cutoff, options.cleanupLease, options.canIssueStatement);
1138
+ if (!await this.admitCleanupScan(options.cleanupLease, options.canIssueStatement)) return 0;
1139
+ const rows = await this.db.selectFrom("_emdash_media_usage as u").innerJoin("_emdash_media_usage_sources as s", (join) => join.onRef("s.source_key", "=", "u.source_key")).leftJoin("_emdash_media_usage_generation_writes as writer", (join) => join.onRef("writer.source_key", "=", "u.source_key").onRef("writer.generation", "=", "u.generation")).select("u.id").where("u.created_at", "<", cutoff).whereRef("u.generation", "!=", "s.current_generation").whereRef("u.created_at", ">=", "s.indexed_at").where(this.noActiveGenerationWriteExpression("u")).orderBy("u.created_at", "asc").orderBy("u.id", "asc").limit(batchLimit).execute();
1140
+ return this.deleteAbandonedCandidateIds(rows.map((row) => row.id), cutoff, options.cleanupLease, options.canIssueStatement);
1141
+ }
1142
+ async deleteExpiredGenerationWriteLeases(limit, cleanupLease, canIssueStatement) {
1143
+ const batchLimit = Math.floor(limit);
1144
+ if (batchLimit <= 0) return 0;
1145
+ if (!await this.admitCleanupScan(cleanupLease, canIssueStatement)) return 0;
1146
+ const rows = await this.db.selectFrom("_emdash_media_usage_generation_writes").select("lease_token").where(this.generationWriteLeaseHasExpired("expires_at")).orderBy("expires_at", "asc").orderBy("lease_token", "asc").limit(batchLimit).execute();
1147
+ if (rows.length === 0 || !canIssueCleanupStatement(canIssueStatement)) return 0;
1148
+ let deleteQuery = this.db.deleteFrom("_emdash_media_usage_generation_writes").where("lease_token", "in", rows.map((row) => row.lease_token)).where(this.generationWriteLeaseHasExpired("expires_at"));
1149
+ if (cleanupLease) deleteQuery = deleteQuery.where(this.activeCleanupLeaseExpression(cleanupLease));
1150
+ const result = await deleteQuery.executeTakeFirst();
1151
+ return Number(result.numDeletedRows ?? 0);
1152
+ }
1153
+ async upsertIndexStatus(input) {
1154
+ const now = input.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString();
1155
+ const row = {
1156
+ adapter_id: input.adapterId,
1157
+ scope_type: input.scopeType,
1158
+ scope_key: input.scopeKey,
1159
+ status: input.status,
1160
+ schema_version: input.schemaVersion ?? 1,
1161
+ started_at: input.startedAt ?? null,
1162
+ completed_at: input.completedAt ?? null,
1163
+ cursor: input.cursor ?? null,
1164
+ indexed_source_count: input.indexedSourceCount ?? 0,
1165
+ failed_source_count: input.failedSourceCount ?? 0,
1166
+ last_error_code: input.lastErrorCode ?? null,
1167
+ updated_at: now
1168
+ };
1169
+ await this.db.insertInto("_emdash_media_usage_index_status").values(row).onConflict((oc) => oc.columns([
1170
+ "adapter_id",
1171
+ "scope_type",
1172
+ "scope_key"
1173
+ ]).doUpdateSet({
1174
+ status: row.status,
1175
+ schema_version: row.schema_version,
1176
+ started_at: row.started_at,
1177
+ completed_at: row.completed_at,
1178
+ cursor: row.cursor,
1179
+ indexed_source_count: row.indexed_source_count,
1180
+ failed_source_count: row.failed_source_count,
1181
+ last_error_code: row.last_error_code,
1182
+ updated_at: row.updated_at
1183
+ })).execute();
1184
+ const status = await this.findIndexStatus(input);
1185
+ if (!status) throw new Error(`Media usage index status ${input.adapterId}:${input.scopeType}:${input.scopeKey} was not persisted`);
1186
+ return status;
1187
+ }
1188
+ async invalidateIndexStatusForSchemaChange(collectionSlug) {
1189
+ const result = await this.db.updateTable("_emdash_media_usage_index_status as status").set({
1190
+ change_epoch: sql`change_epoch + 1`,
1191
+ status: "stale",
1192
+ completed_at: null,
1193
+ cursor: null,
1194
+ last_error_code: "CONTENT_USAGE_STALE",
1195
+ reconciliation_required: 1,
1196
+ updated_at: this.sortableUtcTimestamp()
1197
+ }).where("status.adapter_id", "=", "content-media").where("status.scope_type", "=", "collection").where("status.scope_key", "=", collectionSlug).where("status.capture_state", "=", "active").where((eb) => eb.exists(eb.selectFrom("_emdash_collections as collection").select("collection.id").whereRef("collection.id", "=", "status.collection_id").whereRef("collection.slug", "=", "status.scope_key"))).where(sql`EXISTS (
1198
+ SELECT 1
1199
+ FROM _emdash_media_usage_activation AS activation
1200
+ WHERE activation.task_key = 'incremental_capture'
1201
+ AND activation.state = 'active'
1202
+ )`).executeTakeFirst();
1203
+ return Number(result.numUpdatedRows ?? 0) === 1;
1204
+ }
1205
+ async beginIndexStatusRepair(input) {
1206
+ return this.upsertIndexStatus({
1207
+ adapterId: input.adapterId,
1208
+ scopeType: input.scopeType,
1209
+ scopeKey: input.scopeKey,
1210
+ status: "running",
1211
+ schemaVersion: input.schemaVersion,
1212
+ startedAt: input.startedAt,
1213
+ completedAt: null,
1214
+ cursor: input.runToken,
1215
+ indexedSourceCount: 0,
1216
+ failedSourceCount: 0,
1217
+ lastErrorCode: null,
1218
+ updatedAt: input.updatedAt
1219
+ });
1220
+ }
1221
+ async finalizeIndexStatusRepairIfRunning(input) {
1222
+ const updates = {
1223
+ status: input.status,
1224
+ completed_at: input.completedAt,
1225
+ cursor: null,
1226
+ indexed_source_count: input.indexedSourceCount ?? 0,
1227
+ failed_source_count: input.failedSourceCount ?? 0,
1228
+ last_error_code: input.lastErrorCode ?? null,
1229
+ updated_at: input.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString()
1230
+ };
1231
+ if (input.schemaVersion !== void 0) updates.schema_version = input.schemaVersion;
1232
+ const result = await this.db.updateTable("_emdash_media_usage_index_status").set(updates).where("adapter_id", "=", input.adapterId).where("scope_type", "=", input.scopeType).where("scope_key", "=", input.scopeKey).where("status", "=", "running").where("cursor", "=", input.runToken).executeTakeFirst();
1233
+ return {
1234
+ finalized: Number(result.numUpdatedRows ?? 0) > 0,
1235
+ status: await this.findIndexStatus(input)
1236
+ };
1237
+ }
1238
+ async beginIndexStatusRepairAtCurrentEpoch(input) {
1239
+ const now = this.sortableUtcTimestamp();
1240
+ const row = await this.db.updateTable("_emdash_media_usage_index_status").set({
1241
+ status: "running",
1242
+ schema_version: input.schemaVersion,
1243
+ started_at: now,
1244
+ completed_at: null,
1245
+ cursor: input.runToken,
1246
+ indexed_source_count: 0,
1247
+ failed_source_count: 0,
1248
+ last_error_code: null,
1249
+ reconciliation_required: 1,
1250
+ updated_at: now
1251
+ }).where("adapter_id", "=", input.adapterId).where("scope_type", "=", input.scopeType).where("scope_key", "=", input.scopeKey).where("collection_id", "=", input.collectionId).where("capture_state", "=", "active").where(sql`EXISTS (
1252
+ SELECT 1
1253
+ FROM _emdash_collections AS collection
1254
+ WHERE collection.id = ${input.collectionId}
1255
+ AND collection.slug = ${input.scopeKey}
1256
+ )`).where(sql`EXISTS (
1257
+ SELECT 1
1258
+ FROM _emdash_media_usage_activation AS activation
1259
+ WHERE activation.task_key = 'incremental_capture'
1260
+ AND activation.state = 'active'
1261
+ )`).returning(["change_epoch", "started_at"]).executeTakeFirst();
1262
+ if (!row?.started_at) return null;
1263
+ return {
1264
+ changeEpoch: row.change_epoch,
1265
+ startedAt: row.started_at
1266
+ };
1267
+ }
1268
+ async finalizeIndexStatusRepairAtEpoch(input) {
1269
+ const now = this.sortableUtcTimestamp();
1270
+ const updates = {
1271
+ status: input.status,
1272
+ schema_version: input.schemaVersion,
1273
+ completed_at: now,
1274
+ cursor: null,
1275
+ indexed_source_count: input.indexedSourceCount,
1276
+ failed_source_count: input.failedSourceCount,
1277
+ last_error_code: input.lastErrorCode,
1278
+ reconciliation_required: input.status === "complete" ? 0 : 1,
1279
+ updated_at: now
1280
+ };
1281
+ let query = this.db.updateTable("_emdash_media_usage_index_status").set(updates).where("adapter_id", "=", input.adapterId).where("scope_type", "=", input.scopeType).where("scope_key", "=", input.scopeKey).where("collection_id", "=", input.collectionId).where("status", "=", "running").where("cursor", "=", input.runToken).where("change_epoch", "=", input.startingEpoch).where(sql`EXISTS (
1282
+ SELECT 1
1283
+ FROM _emdash_collections AS collection
1284
+ WHERE collection.id = ${input.collectionId}
1285
+ AND collection.slug = ${input.scopeKey}
1286
+ )`);
1287
+ if (input.status === "complete") query = query.where(sql`NOT EXISTS (
1288
+ SELECT 1
1289
+ FROM _emdash_media_usage_work AS work
1290
+ WHERE work.collection_id = ${input.collectionId}
1291
+ )`);
1292
+ const result = await query.executeTakeFirst();
1293
+ const finalized = Number(result.numUpdatedRows ?? 0) > 0;
1294
+ if (!finalized) await this.db.updateTable("_emdash_media_usage_index_status").set({
1295
+ status: "stale",
1296
+ completed_at: null,
1297
+ cursor: null,
1298
+ last_error_code: "CONTENT_USAGE_REPAIR_CONFLICT",
1299
+ reconciliation_required: 1,
1300
+ updated_at: this.sortableUtcTimestamp()
1301
+ }).where("adapter_id", "=", input.adapterId).where("scope_type", "=", input.scopeType).where("scope_key", "=", input.scopeKey).where("collection_id", "=", input.collectionId).where("status", "=", "running").where("cursor", "=", input.runToken).execute();
1302
+ return {
1303
+ finalized,
1304
+ status: await this.findIndexStatusForCollection(input, input.collectionId)
1305
+ };
1306
+ }
1307
+ async recordIncrementalSuccess(input) {
1308
+ const observed = await this.db.selectFrom("_emdash_media_usage_index_status").select("change_epoch").where("adapter_id", "=", "content-media").where("scope_type", "=", "collection").where("scope_key", "=", input.collectionSlug).where("collection_id", "=", input.collectionId).where("capture_state", "=", "active").where(sql`EXISTS (
1309
+ SELECT 1
1310
+ FROM _emdash_collections AS collection
1311
+ WHERE collection.id = ${input.collectionId}
1312
+ AND collection.slug = ${input.collectionSlug}
1313
+ )`).executeTakeFirst();
1314
+ if (!observed) return false;
1315
+ const canComplete = sql`(
1316
+ reconciliation_required = 0
1317
+ AND status IN ('complete', 'stale', 'partial')
1318
+ AND NOT EXISTS (
1319
+ SELECT 1
1320
+ FROM _emdash_media_usage_work AS work
1321
+ WHERE work.collection_id = ${input.collectionId}
1322
+ )
1323
+ )`;
1324
+ const now = this.sortableUtcTimestamp();
1325
+ const result = await this.db.updateTable("_emdash_media_usage_index_status").set({
1326
+ status: sql`CASE WHEN ${canComplete} THEN 'complete' ELSE status END`,
1327
+ completed_at: sql`CASE WHEN ${canComplete} THEN ${now} ELSE completed_at END`,
1328
+ last_error_code: sql`CASE WHEN ${canComplete} THEN NULL ELSE last_error_code END`,
1329
+ cursor: sql`CASE WHEN ${canComplete} THEN NULL ELSE cursor END`,
1330
+ last_incremental_success_at: now,
1331
+ updated_at: now
1332
+ }).where("adapter_id", "=", "content-media").where("scope_type", "=", "collection").where("scope_key", "=", input.collectionSlug).where("collection_id", "=", input.collectionId).where("change_epoch", "=", observed.change_epoch).where("capture_state", "=", "active").where(sql`EXISTS (
1333
+ SELECT 1
1334
+ FROM _emdash_collections AS collection
1335
+ WHERE collection.id = ${input.collectionId}
1336
+ AND collection.slug = ${input.collectionSlug}
1337
+ )`).executeTakeFirst();
1338
+ return Number(result.numUpdatedRows ?? 0) > 0;
1339
+ }
1340
+ async prepareIncrementalFinalization(input) {
1341
+ const observed = await this.db.selectFrom("_emdash_media_usage_index_status").select(["change_epoch", "reconciliation_required"]).where("adapter_id", "=", "content-media").where("scope_type", "=", "collection").where("scope_key", "=", input.collectionSlug).where("collection_id", "=", input.collectionId).where("capture_state", "=", "active").executeTakeFirst();
1342
+ if (!observed) return { outcome: "lost" };
1343
+ if (observed.reconciliation_required !== 0) return { outcome: "not_required" };
1344
+ const marker = `incremental-finalize:${String(observed.change_epoch)}:${ulid()}`;
1345
+ const result = await this.db.updateTable("_emdash_media_usage_index_status").set({
1346
+ cursor: marker,
1347
+ updated_at: this.sortableUtcTimestamp()
1348
+ }).where("adapter_id", "=", "content-media").where("scope_type", "=", "collection").where("scope_key", "=", input.collectionSlug).where("collection_id", "=", input.collectionId).where("capture_state", "=", "active").where("reconciliation_required", "=", 0).where("change_epoch", "=", observed.change_epoch).where(sql`EXISTS (
1349
+ SELECT 1
1350
+ FROM _emdash_collections AS collection
1351
+ WHERE collection.id = ${input.collectionId}
1352
+ AND collection.slug = ${input.collectionSlug}
1353
+ )`).where(sql`NOT EXISTS (
1354
+ SELECT 1
1355
+ FROM _emdash_media_usage_collection_deletions AS deletion
1356
+ WHERE deletion.collection_id = ${input.collectionId}
1357
+ )`).executeTakeFirst();
1358
+ return Number(result.numUpdatedRows ?? 0) > 0 ? {
1359
+ outcome: "marked",
1360
+ marker
1361
+ } : { outcome: "lost" };
1362
+ }
1363
+ async recoverIncrementalFinalizations() {
1364
+ const markerMatchesEpoch = isPostgres(this.db) ? sql`status.cursor LIKE ('incremental-finalize:' || status.change_epoch::text || ':%')` : sql`status.cursor LIKE ('incremental-finalize:' || CAST(status.change_epoch AS text) || ':%')`;
1365
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1366
+ return (await sql`
1367
+ UPDATE _emdash_media_usage_index_status AS status
1368
+ SET status = 'complete',
1369
+ completed_at = ${now},
1370
+ cursor = NULL,
1371
+ last_error_code = NULL,
1372
+ last_incremental_success_at = ${now},
1373
+ updated_at = ${now}
1374
+ WHERE status.adapter_id = 'content-media'
1375
+ AND status.scope_type = 'collection'
1376
+ AND status.capture_state = 'active'
1377
+ AND status.reconciliation_required = 0
1378
+ AND status.cursor IS NOT NULL
1379
+ AND ${markerMatchesEpoch}
1380
+ AND EXISTS (
1381
+ SELECT 1
1382
+ FROM _emdash_collections AS collection
1383
+ WHERE collection.id = status.collection_id
1384
+ AND collection.slug = status.scope_key
1385
+ )
1386
+ AND NOT EXISTS (
1387
+ SELECT 1
1388
+ FROM _emdash_media_usage_collection_deletions AS deletion
1389
+ WHERE deletion.collection_id = status.collection_id
1390
+ )
1391
+ AND NOT EXISTS (
1392
+ SELECT 1
1393
+ FROM _emdash_media_usage_work AS work
1394
+ WHERE work.collection_id = status.collection_id
1395
+ )
1396
+ RETURNING collection_id
1397
+ `.execute(this.db)).rows.length;
1398
+ }
1399
+ async recordIncrementalFailure(input) {
1400
+ const now = this.sortableUtcTimestamp();
1401
+ const automaticRunOwnsCoverage = sql`EXISTS (
1402
+ SELECT 1
1403
+ FROM _emdash_media_usage_reconciliations AS reconciliation
1404
+ WHERE reconciliation.collection_id = ${input.collectionId}
1405
+ AND reconciliation.run_token = cursor
1406
+ )`;
1407
+ const result = await this.db.updateTable("_emdash_media_usage_index_status").set({
1408
+ status: sql`CASE
1409
+ WHEN ${automaticRunOwnsCoverage} THEN status
1410
+ WHEN reconciliation_required = 0 THEN 'partial'
1411
+ WHEN status = 'running' THEN 'stale'
1412
+ ELSE status
1413
+ END`,
1414
+ completed_at: sql`CASE
1415
+ WHEN ${automaticRunOwnsCoverage} THEN completed_at
1416
+ WHEN reconciliation_required = 0 OR status = 'running' THEN NULL
1417
+ ELSE completed_at
1418
+ END`,
1419
+ cursor: sql`CASE
1420
+ WHEN ${automaticRunOwnsCoverage} THEN cursor
1421
+ WHEN status = 'running' THEN NULL
1422
+ ELSE cursor
1423
+ END`,
1424
+ last_error_code: input.errorCode,
1425
+ updated_at: now
1426
+ }).where("adapter_id", "=", "content-media").where("scope_type", "=", "collection").where("scope_key", "=", input.collectionSlug).where("collection_id", "=", input.collectionId).where(sql`EXISTS (
1427
+ SELECT 1
1428
+ FROM _emdash_media_usage_work AS work
1429
+ WHERE work.collection_id = ${input.collectionId}
1430
+ AND work.content_id = ${input.contentId}
1431
+ AND work.work_version = ${input.workVersion}
1432
+ AND work.state = 'failed'
1433
+ AND work.last_error_code = ${input.errorCode}
1434
+ )`).where(sql`EXISTS (
1435
+ SELECT 1
1436
+ FROM _emdash_collections AS collection
1437
+ WHERE collection.id = ${input.collectionId}
1438
+ AND collection.slug = ${input.collectionSlug}
1439
+ )`).executeTakeFirst();
1440
+ return Number(result.numUpdatedRows ?? 0) > 0;
1441
+ }
1442
+ async recordIncrementalFailuresByCollection(input) {
1443
+ const collectionIds = [...new Set(input.collectionIds)];
1444
+ if (collectionIds.length === 0) return /* @__PURE__ */ new Set();
1445
+ const collections = jsonTextValues(this.db, collectionIds);
1446
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1447
+ const result = await sql`
1448
+ WITH failed_collections AS (${collections})
1449
+ UPDATE _emdash_media_usage_index_status AS status
1450
+ SET status = CASE
1451
+ WHEN EXISTS (
1452
+ SELECT 1
1453
+ FROM _emdash_media_usage_reconciliations AS reconciliation
1454
+ WHERE reconciliation.collection_id = status.collection_id
1455
+ AND reconciliation.run_token = status.cursor
1456
+ ) THEN status.status
1457
+ WHEN status.reconciliation_required = 0 THEN 'partial'
1458
+ WHEN status.status = 'running' THEN 'stale'
1459
+ ELSE status.status
1460
+ END,
1461
+ completed_at = CASE
1462
+ WHEN EXISTS (
1463
+ SELECT 1
1464
+ FROM _emdash_media_usage_reconciliations AS reconciliation
1465
+ WHERE reconciliation.collection_id = status.collection_id
1466
+ AND reconciliation.run_token = status.cursor
1467
+ ) THEN status.completed_at
1468
+ WHEN status.reconciliation_required = 0 OR status.status = 'running' THEN NULL
1469
+ ELSE status.completed_at
1470
+ END,
1471
+ cursor = CASE
1472
+ WHEN EXISTS (
1473
+ SELECT 1
1474
+ FROM _emdash_media_usage_reconciliations AS reconciliation
1475
+ WHERE reconciliation.collection_id = status.collection_id
1476
+ AND reconciliation.run_token = status.cursor
1477
+ ) THEN status.cursor
1478
+ WHEN status.status = 'running' THEN NULL
1479
+ ELSE status.cursor
1480
+ END,
1481
+ last_error_code = ${input.errorCode},
1482
+ updated_at = ${now}
1483
+ WHERE status.adapter_id = 'content-media'
1484
+ AND status.scope_type = 'collection'
1485
+ AND status.collection_id IN (SELECT value FROM failed_collections)
1486
+ AND EXISTS (
1487
+ SELECT 1
1488
+ FROM _emdash_media_usage_work AS work
1489
+ WHERE work.collection_id = status.collection_id
1490
+ AND work.state = 'failed'
1491
+ AND work.last_error_code = ${input.errorCode}
1492
+ )
1493
+ AND EXISTS (
1494
+ SELECT 1
1495
+ FROM _emdash_collections AS collection
1496
+ WHERE collection.id = status.collection_id
1497
+ AND collection.slug = status.scope_key
1498
+ )
1499
+ RETURNING collection_id
1500
+ `.execute(this.db);
1501
+ return new Set(result.rows.map((row) => row.collection_id));
1502
+ }
1503
+ async findIndexStatus(identity) {
1504
+ const row = await this.db.selectFrom("_emdash_media_usage_index_status").selectAll().where("adapter_id", "=", identity.adapterId).where("scope_type", "=", identity.scopeType).where("scope_key", "=", identity.scopeKey).executeTakeFirst();
1505
+ return row ? rowToIndexStatus(row) : null;
1506
+ }
1507
+ async findIndexStatusForCollection(identity, collectionId) {
1508
+ const row = await this.db.selectFrom("_emdash_media_usage_index_status").selectAll().where("adapter_id", "=", identity.adapterId).where("scope_type", "=", identity.scopeType).where("scope_key", "=", identity.scopeKey).where("collection_id", "=", collectionId).executeTakeFirst();
1509
+ return row ? rowToIndexStatus(row) : null;
1510
+ }
1511
+ async deleteIndexStatus(identity, collectionId) {
1512
+ let query = this.db.deleteFrom("_emdash_media_usage_index_status").where("adapter_id", "=", identity.adapterId).where("scope_type", "=", identity.scopeType).where("scope_key", "=", identity.scopeKey);
1513
+ if (collectionId !== void 0) query = query.where("collection_id", "=", collectionId);
1514
+ const result = await query.executeTakeFirst();
1515
+ return Number(result.numDeletedRows ?? 0);
1516
+ }
1517
+ sortableUtcTimestamp() {
1518
+ return isPostgres(this.db) ? sql`to_char(clock_timestamp() AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"')` : sql`strftime('%Y-%m-%dT%H:%M:%fZ', 'now')`;
1519
+ }
1520
+ async findCurrentUsagePage(applyFilter, options) {
1521
+ const limit = Math.min(Math.max(1, options.limit ?? 50), 100);
1522
+ let query = applyFilter(this.currentUsageBaseQuery()).orderBy("u.id", "asc").limit(limit + 1);
1523
+ if (options.cursor) {
1524
+ const { id } = decodeCursor(options.cursor);
1525
+ query = query.where("u.id", ">", id);
1526
+ }
1527
+ const rows = await query.execute();
1528
+ const items = rows.slice(0, limit).map(rowToUsageRecord);
1529
+ const result = { items };
1530
+ if (rows.length > limit && items.length > 0) {
1531
+ const last = items.at(-1);
1532
+ result.nextCursor = encodeCursor(last.occurrence.id, last.occurrence.id);
1533
+ }
1534
+ return result;
1535
+ }
1536
+ currentUsageBaseQuery() {
1537
+ return this.db.selectFrom("_emdash_media_usage_sources as s").innerJoin("_emdash_media_usage as u", (join) => join.onRef("u.source_key", "=", "s.source_key").onRef("u.generation", "=", "s.current_generation")).select(currentUsageSelect);
1538
+ }
1539
+ currentContentMediaUsageBaseQuery() {
1540
+ return this.db.selectFrom("_emdash_media_usage as u").crossJoin("_emdash_media_usage_sources as s").innerJoin("_emdash_collections as collection", "collection.slug", "s.collection_slug").whereRef("s.source_key", "=", "u.source_key").whereRef("s.current_generation", "=", "u.generation").where("s.source_type", "=", "content").where("s.collection_slug", "is not", null).where("s.content_id", "is not", null).where("s.source_variant", "in", ["columns", "draft_overlay"]).where(contentSourceMatchesActiveCollection("s", "collection.id")).where(CONTENT_SOURCE_ELIGIBILITY);
1541
+ }
1542
+ async deleteOrphanCandidateIds(ids, cutoff, cleanupLease, canIssueStatement) {
1543
+ let deleted = 0;
1544
+ for (const idBatch of chunks([...ids], cleanupDeleteBatchSize(cleanupLease))) {
1545
+ if (!canIssueCleanupStatement(canIssueStatement)) break;
1546
+ if (cleanupLease) {
1547
+ await this.markOrphanCandidatesForCleanup(idBatch, cutoff, cleanupLease);
1548
+ if (!canIssueCleanupStatement(canIssueStatement)) break;
1549
+ }
1550
+ let query = this.db.deleteFrom("_emdash_media_usage").where("id", "in", idBatch).where("created_at", "<", cutoff).where(sql`NOT EXISTS (SELECT 1 FROM _emdash_media_usage_sources source WHERE source.source_key = _emdash_media_usage.source_key)`).where(this.noActiveGenerationWriteExpression());
1551
+ if (cleanupLease) query = query.where("cleanup_lease_token", "=", cleanupLease.leaseToken).where(this.activeCleanupLeaseExpression(cleanupLease));
1552
+ const result = await query.executeTakeFirst();
1553
+ deleted += Number(result.numDeletedRows ?? 0);
1554
+ }
1555
+ return deleted;
1556
+ }
1557
+ async deleteStaleCandidateIds(ids, cutoff, cleanupLease, canIssueStatement) {
1558
+ let deleted = 0;
1559
+ for (const idBatch of chunks([...ids], cleanupDeleteBatchSize(cleanupLease))) {
1560
+ if (!canIssueCleanupStatement(canIssueStatement)) break;
1561
+ if (cleanupLease) {
1562
+ await this.markStaleCandidatesForCleanup(idBatch, cutoff, cleanupLease);
1563
+ if (!canIssueCleanupStatement(canIssueStatement)) break;
1564
+ }
1565
+ let query = this.db.deleteFrom("_emdash_media_usage").where("id", "in", idBatch).where("created_at", "<", cutoff).where((eb) => eb.exists(eb.selectFrom("_emdash_media_usage_sources as source").select("source.source_key").whereRef("source.source_key", "=", "_emdash_media_usage.source_key").whereRef("source.current_generation", "!=", "_emdash_media_usage.generation").whereRef("_emdash_media_usage.created_at", "<", "source.indexed_at"))).where(this.noActiveGenerationWriteExpression());
1566
+ if (cleanupLease) query = query.where("cleanup_lease_token", "=", cleanupLease.leaseToken).where(this.activeCleanupLeaseExpression(cleanupLease));
1567
+ const result = await query.executeTakeFirst();
1568
+ deleted += Number(result.numDeletedRows ?? 0);
1569
+ }
1570
+ return deleted;
1571
+ }
1572
+ async deleteAbandonedCandidateIds(ids, cutoff, cleanupLease, canIssueStatement) {
1573
+ let deleted = 0;
1574
+ for (const idBatch of chunks([...ids], cleanupDeleteBatchSize(cleanupLease))) {
1575
+ if (!canIssueCleanupStatement(canIssueStatement)) break;
1576
+ if (cleanupLease) {
1577
+ await this.markAbandonedCandidatesForCleanup(idBatch, cutoff, cleanupLease);
1578
+ if (!canIssueCleanupStatement(canIssueStatement)) break;
1579
+ }
1580
+ let query = this.db.deleteFrom("_emdash_media_usage").where("id", "in", idBatch).where("created_at", "<", cutoff).where((eb) => eb.exists(eb.selectFrom("_emdash_media_usage_sources as source").select("source.source_key").whereRef("source.source_key", "=", "_emdash_media_usage.source_key").whereRef("source.current_generation", "!=", "_emdash_media_usage.generation").whereRef("_emdash_media_usage.created_at", ">=", "source.indexed_at"))).where(this.noActiveGenerationWriteExpression());
1581
+ if (cleanupLease) query = query.where("cleanup_lease_token", "=", cleanupLease.leaseToken).where(this.activeCleanupLeaseExpression(cleanupLease));
1582
+ const result = await query.executeTakeFirst();
1583
+ deleted += Number(result.numDeletedRows ?? 0);
1584
+ }
1585
+ return deleted;
1586
+ }
1587
+ async markOrphanCandidatesForCleanup(ids, cutoff, cleanupLease) {
1588
+ await this.db.updateTable("_emdash_media_usage").set({ cleanup_lease_token: cleanupLease.leaseToken }).where("id", "in", ids).where("created_at", "<", cutoff).where(sql`NOT EXISTS (SELECT 1 FROM _emdash_media_usage_sources source WHERE source.source_key = _emdash_media_usage.source_key)`).where(this.noActiveGenerationWriteExpression()).where(this.activeCleanupLeaseExpression(cleanupLease)).execute();
1589
+ }
1590
+ async markStaleCandidatesForCleanup(ids, cutoff, cleanupLease) {
1591
+ await this.db.updateTable("_emdash_media_usage").set({ cleanup_lease_token: cleanupLease.leaseToken }).where("id", "in", ids).where("created_at", "<", cutoff).where((eb) => eb.exists(eb.selectFrom("_emdash_media_usage_sources as source").select("source.source_key").whereRef("source.source_key", "=", "_emdash_media_usage.source_key").whereRef("source.current_generation", "!=", "_emdash_media_usage.generation").whereRef("_emdash_media_usage.created_at", "<", "source.indexed_at"))).where(this.noActiveGenerationWriteExpression()).where(this.activeCleanupLeaseExpression(cleanupLease)).execute();
1592
+ }
1593
+ async markAbandonedCandidatesForCleanup(ids, cutoff, cleanupLease) {
1594
+ await this.db.updateTable("_emdash_media_usage").set({ cleanup_lease_token: cleanupLease.leaseToken }).where("id", "in", ids).where("created_at", "<", cutoff).where((eb) => eb.exists(eb.selectFrom("_emdash_media_usage_sources as source").select("source.source_key").whereRef("source.source_key", "=", "_emdash_media_usage.source_key").whereRef("source.current_generation", "!=", "_emdash_media_usage.generation").whereRef("_emdash_media_usage.created_at", ">=", "source.indexed_at"))).where(this.noActiveGenerationWriteExpression()).where(this.activeCleanupLeaseExpression(cleanupLease)).execute();
1595
+ }
1596
+ noActiveGenerationWriteExpression(usageTable = "_emdash_media_usage") {
1597
+ return sql`NOT EXISTS (
1598
+ SELECT 1
1599
+ FROM _emdash_media_usage_generation_writes AS writer
1600
+ WHERE writer.source_key = ${sql.ref(`${usageTable}.source_key`)}
1601
+ AND writer.generation = ${sql.ref(`${usageTable}.generation`)}
1602
+ AND ${this.generationWriteLeaseExpiryIsInFuture("writer.expires_at")}
1603
+ )`;
1604
+ }
1605
+ /**
1606
+ * Gates a bounded cleanup scan on the lease and the tick's statement budget.
1607
+ *
1608
+ * The budget is re-read after the lease row because that read is itself a
1609
+ * statement: an isolate suspended across it can resume with the budget spent.
1610
+ */
1611
+ async admitCleanupScan(cleanupLease, canIssueStatement) {
1612
+ if (!canIssueCleanupStatement(canIssueStatement)) return false;
1613
+ if (!cleanupLease) return true;
1614
+ return await this.holdsCleanupLease(cleanupLease) && canIssueCleanupStatement(canIssueStatement);
1615
+ }
1616
+ /**
1617
+ * Reads the lease row on its own so a lost lease can short-circuit a sweep.
1618
+ *
1619
+ * As a row-level `EXISTS` inside a `LIMIT`ed scan this predicate is constant
1620
+ * across every candidate row: when it is false the limit is unreachable and
1621
+ * the scan reads the whole `created_at` range before returning nothing.
1622
+ * Mutating statements still carry {@link activeCleanupLeaseExpression},
1623
+ * which is what actually fences a displaced owner.
1624
+ */
1625
+ async holdsCleanupLease(cleanupLease) {
1626
+ let query = this.db.selectFrom("_emdash_media_usage_cleanup").select("task_key").where("task_key", "=", "projection_gc").where("lease_token", "=", cleanupLease.leaseToken).where(this.cleanupLeaseExpiryIsInFuture("_emdash_media_usage_cleanup.lease_expires_at"));
1627
+ if (isPostgres(this.db)) query = query.forUpdate();
1628
+ return await query.executeTakeFirst() !== void 0;
1629
+ }
1630
+ activeCleanupLeaseExpression(cleanupLease) {
1631
+ const rowLock = isPostgres(this.db) ? sql` FOR UPDATE` : sql``;
1632
+ return sql`EXISTS (
1633
+ SELECT 1
1634
+ FROM _emdash_media_usage_cleanup AS cleanup
1635
+ WHERE cleanup.task_key = 'projection_gc'
1636
+ AND cleanup.lease_token = ${cleanupLease.leaseToken}
1637
+ AND ${this.cleanupLeaseExpiryIsInFuture("cleanup.lease_expires_at")}
1638
+ ${rowLock}
1639
+ )`;
1640
+ }
1641
+ cleanupLeaseExpiryIsInFuture(column) {
1642
+ const leaseExpiresAt = sql.ref(column);
1643
+ return isPostgres(this.db) ? sql`${leaseExpiresAt}::timestamptz > clock_timestamp()` : sql`${leaseExpiresAt} > strftime('%Y-%m-%dT%H:%M:%fZ', 'now')`;
1644
+ }
1645
+ cleanupTimestampIsDue(column) {
1646
+ const timestamp = sql.ref(column);
1647
+ return isPostgres(this.db) ? sql`${timestamp}::timestamptz <= clock_timestamp()` : sql`${timestamp} <= strftime('%Y-%m-%dT%H:%M:%fZ', 'now')`;
1648
+ }
1649
+ cleanupTimestampOffset(offsetSeconds) {
1650
+ if (isPostgres(this.db)) return sql`to_char(
1651
+ (clock_timestamp() AT TIME ZONE 'UTC') + (${offsetSeconds} * INTERVAL '1 second'),
1652
+ 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'
1653
+ )`;
1654
+ return sql`strftime(
1655
+ '%Y-%m-%dT%H:%M:%fZ',
1656
+ 'now',
1657
+ ${`${offsetSeconds >= 0 ? "+" : ""}${offsetSeconds} seconds`}
1658
+ )`;
1659
+ }
1660
+ generationWriteLeaseHasExpired(column) {
1661
+ const leaseExpiresAt = sql.ref(column);
1662
+ return isPostgres(this.db) ? sql`${leaseExpiresAt}::timestamptz <= clock_timestamp()` : sql`${leaseExpiresAt} <= strftime('%Y-%m-%dT%H:%M:%fZ', 'now')`;
1663
+ }
1664
+ async deleteSourceKeys(sourceKeys) {
1665
+ const uniqueSourceKeys = [...new Set(sourceKeys)];
1666
+ if (uniqueSourceKeys.length === 0) return 0;
1667
+ return withTransaction(this.db, async (trx) => {
1668
+ await this.lockCleanupBeforeSourceDelete(trx);
1669
+ let deleted = 0;
1670
+ for (const sourceKeyBatch of chunks(uniqueSourceKeys, SQL_BATCH_SIZE)) {
1671
+ const result = await trx.deleteFrom("_emdash_media_usage_sources").where("source_key", "in", sourceKeyBatch).executeTakeFirst();
1672
+ deleted += Number(result.numDeletedRows ?? 0);
1673
+ await trx.updateTable("_emdash_media_usage").set({ cleanup_lease_token: null }).where("source_key", "in", sourceKeyBatch).execute();
1674
+ await trx.deleteFrom("_emdash_media_usage").where("source_key", "in", sourceKeyBatch).execute();
1675
+ }
1676
+ return deleted;
1677
+ });
1678
+ }
1679
+ async deleteSourceGenerationOccurrences(db, sourceKey, generation) {
1680
+ await db.updateTable("_emdash_media_usage").set({ cleanup_lease_token: null }).where("source_key", "=", sourceKey).where("generation", "=", generation).execute();
1681
+ await db.deleteFrom("_emdash_media_usage").where("source_key", "=", sourceKey).where("generation", "=", generation).execute();
1682
+ }
1683
+ async lockCleanupBeforeSourceDelete(db) {
1684
+ if (!isPostgres(this.db)) return;
1685
+ await sql`
1686
+ SELECT 1
1687
+ FROM _emdash_media_usage_cleanup
1688
+ WHERE task_key = 'projection_gc'
1689
+ FOR SHARE
1690
+ `.execute(db);
1691
+ }
1692
+ async insertOccurrences(db, sourceKey, generation, occurrences, now) {
1693
+ if (occurrences.length === 0) return;
1694
+ const rows = occurrences.map((occurrence) => ({
1695
+ id: ulid(),
1696
+ source_key: sourceKey,
1697
+ generation,
1698
+ field_slug: occurrence.fieldSlug,
1699
+ field_path: occurrence.fieldPath,
1700
+ occurrence_index: occurrence.occurrenceIndex ?? 0,
1701
+ reference_type: occurrence.referenceType,
1702
+ media_id: occurrence.mediaId,
1703
+ provider: occurrence.provider,
1704
+ provider_asset_id: occurrence.providerAssetId,
1705
+ media_kind: occurrence.mediaKind ?? null,
1706
+ mime_type: occurrence.mimeType ?? null,
1707
+ created_at: now
1708
+ }));
1709
+ for (const rowBatch of chunks(rows, OCCURRENCE_INSERT_BATCH_SIZE)) await db.insertInto("_emdash_media_usage").values(rowBatch).execute();
1710
+ }
1711
+ async insertBatchOccurrences(rows) {
1712
+ for (const rowBatch of chunkJsonRows(rows)) await sql`
1713
+ WITH input AS (${this.occurrenceBatchInput(JSON.stringify(rowBatch))})
1714
+ INSERT INTO _emdash_media_usage (
1715
+ id, source_key, generation, field_slug, field_path, occurrence_index,
1716
+ reference_type, media_id, provider, provider_asset_id, media_kind,
1717
+ mime_type, created_at
1718
+ )
1719
+ SELECT
1720
+ id, source_key, generation, field_slug, field_path, occurrence_index,
1721
+ reference_type, media_id, provider, provider_asset_id, media_kind,
1722
+ mime_type, created_at
1723
+ FROM input
1724
+ WHERE EXISTS (
1725
+ SELECT 1
1726
+ FROM _emdash_media_usage_generation_writes AS writer
1727
+ WHERE writer.source_key = input.source_key
1728
+ AND writer.generation = input.generation
1729
+ AND writer.lease_token = input.lease_token
1730
+ AND ${this.generationWriteLeaseExpiryIsInFuture("writer.expires_at")}
1731
+ )
1732
+ `.execute(this.db);
1733
+ }
1734
+ occurrenceBatchInput(payload) {
1735
+ if (isPostgres(this.db)) return sql`
1736
+ SELECT
1737
+ entry.value ->> 'id' AS id,
1738
+ entry.value ->> 'source_key' AS source_key,
1739
+ entry.value ->> 'generation' AS generation,
1740
+ entry.value ->> 'field_slug' AS field_slug,
1741
+ entry.value ->> 'field_path' AS field_path,
1742
+ CAST(entry.value ->> 'occurrence_index' AS integer) AS occurrence_index,
1743
+ entry.value ->> 'reference_type' AS reference_type,
1744
+ entry.value ->> 'media_id' AS media_id,
1745
+ entry.value ->> 'provider' AS provider,
1746
+ entry.value ->> 'provider_asset_id' AS provider_asset_id,
1747
+ entry.value ->> 'media_kind' AS media_kind,
1748
+ entry.value ->> 'mime_type' AS mime_type,
1749
+ entry.value ->> 'created_at' AS created_at,
1750
+ entry.value ->> 'lease_token' AS lease_token
1751
+ FROM jsonb_array_elements(${payload}::jsonb) AS entry(value)
1752
+ `;
1753
+ return sql`
1754
+ SELECT
1755
+ json_extract(entry.value, '$.id') AS id,
1756
+ json_extract(entry.value, '$.source_key') AS source_key,
1757
+ json_extract(entry.value, '$.generation') AS generation,
1758
+ json_extract(entry.value, '$.field_slug') AS field_slug,
1759
+ json_extract(entry.value, '$.field_path') AS field_path,
1760
+ CAST(json_extract(entry.value, '$.occurrence_index') AS integer) AS occurrence_index,
1761
+ json_extract(entry.value, '$.reference_type') AS reference_type,
1762
+ json_extract(entry.value, '$.media_id') AS media_id,
1763
+ json_extract(entry.value, '$.provider') AS provider,
1764
+ json_extract(entry.value, '$.provider_asset_id') AS provider_asset_id,
1765
+ json_extract(entry.value, '$.media_kind') AS media_kind,
1766
+ json_extract(entry.value, '$.mime_type') AS mime_type,
1767
+ json_extract(entry.value, '$.created_at') AS created_at,
1768
+ json_extract(entry.value, '$.lease_token') AS lease_token
1769
+ FROM json_each(${payload}) AS entry
1770
+ `;
1771
+ }
1772
+ sourceBatchInput(payload) {
1773
+ if (isPostgres(this.db)) return sql`
1774
+ SELECT
1775
+ entry.value ->> 'source_key' AS source_key,
1776
+ entry.value ->> 'source_type' AS source_type,
1777
+ entry.value ->> 'collection_id' AS collection_id,
1778
+ entry.value ->> 'collection_slug' AS collection_slug,
1779
+ entry.value ->> 'content_id' AS content_id,
1780
+ entry.value ->> 'source_variant' AS source_variant,
1781
+ entry.value ->> 'locale' AS locale,
1782
+ entry.value ->> 'translation_group' AS translation_group,
1783
+ entry.value ->> 'content_slug' AS content_slug,
1784
+ entry.value ->> 'content_title' AS content_title,
1785
+ entry.value ->> 'content_status' AS content_status,
1786
+ entry.value ->> 'content_scheduled_at' AS content_scheduled_at,
1787
+ entry.value ->> 'content_deleted_at' AS content_deleted_at,
1788
+ entry.value ->> 'revision_id' AS revision_id,
1789
+ entry.value ->> 'current_generation' AS current_generation,
1790
+ CAST(entry.value ->> 'schema_version' AS integer) AS schema_version,
1791
+ entry.value ->> 'source_updated_at' AS source_updated_at,
1792
+ CAST(entry.value ->> 'source_version' AS bigint) AS source_version,
1793
+ entry.value ->> 'source_fingerprint' AS source_fingerprint,
1794
+ CAST(entry.value ->> 'identity_version' AS integer) AS identity_version,
1795
+ entry.value ->> 'source_completeness' AS source_completeness,
1796
+ entry.value ->> 'last_attempted_at' AS last_attempted_at,
1797
+ entry.value ->> 'last_error_code' AS last_error_code,
1798
+ entry.value ->> 'indexed_at' AS indexed_at,
1799
+ entry.value ->> 'updated_at' AS updated_at,
1800
+ entry.value ->> 'lease_token' AS lease_token,
1801
+ entry.value ->> 'expected_generation' AS expected_generation,
1802
+ entry.value ->> 'expected_collection_id' AS expected_collection_id,
1803
+ entry.value ->> 'expected_updated_at' AS expected_updated_at,
1804
+ entry.value ->> 'expected_source_fingerprint' AS expected_source_fingerprint,
1805
+ entry.value ->> 'expected_source_updated_at' AS expected_source_updated_at,
1806
+ CAST(entry.value ->> 'expected_source_version' AS bigint) AS expected_source_version,
1807
+ CAST(entry.value ->> 'expected_identity_version' AS integer) AS expected_identity_version,
1808
+ entry.value ->> 'expected_revision_id' AS expected_revision_id,
1809
+ entry.value ->> 'expected_source_completeness' AS expected_source_completeness,
1810
+ entry.value ->> 'expected_last_attempted_at' AS expected_last_attempted_at,
1811
+ entry.value ->> 'expected_last_error_code' AS expected_last_error_code
1812
+ FROM jsonb_array_elements(${payload}::jsonb) AS entry(value)
1813
+ `;
1814
+ return sql`
1815
+ SELECT
1816
+ json_extract(entry.value, '$.source_key') AS source_key,
1817
+ json_extract(entry.value, '$.source_type') AS source_type,
1818
+ json_extract(entry.value, '$.collection_id') AS collection_id,
1819
+ json_extract(entry.value, '$.collection_slug') AS collection_slug,
1820
+ json_extract(entry.value, '$.content_id') AS content_id,
1821
+ json_extract(entry.value, '$.source_variant') AS source_variant,
1822
+ json_extract(entry.value, '$.locale') AS locale,
1823
+ json_extract(entry.value, '$.translation_group') AS translation_group,
1824
+ json_extract(entry.value, '$.content_slug') AS content_slug,
1825
+ json_extract(entry.value, '$.content_title') AS content_title,
1826
+ json_extract(entry.value, '$.content_status') AS content_status,
1827
+ json_extract(entry.value, '$.content_scheduled_at') AS content_scheduled_at,
1828
+ json_extract(entry.value, '$.content_deleted_at') AS content_deleted_at,
1829
+ json_extract(entry.value, '$.revision_id') AS revision_id,
1830
+ json_extract(entry.value, '$.current_generation') AS current_generation,
1831
+ CAST(json_extract(entry.value, '$.schema_version') AS integer) AS schema_version,
1832
+ json_extract(entry.value, '$.source_updated_at') AS source_updated_at,
1833
+ CAST(json_extract(entry.value, '$.source_version') AS integer) AS source_version,
1834
+ json_extract(entry.value, '$.source_fingerprint') AS source_fingerprint,
1835
+ CAST(json_extract(entry.value, '$.identity_version') AS integer) AS identity_version,
1836
+ json_extract(entry.value, '$.source_completeness') AS source_completeness,
1837
+ json_extract(entry.value, '$.last_attempted_at') AS last_attempted_at,
1838
+ json_extract(entry.value, '$.last_error_code') AS last_error_code,
1839
+ json_extract(entry.value, '$.indexed_at') AS indexed_at,
1840
+ json_extract(entry.value, '$.updated_at') AS updated_at,
1841
+ json_extract(entry.value, '$.lease_token') AS lease_token,
1842
+ json_extract(entry.value, '$.expected_generation') AS expected_generation,
1843
+ json_extract(entry.value, '$.expected_collection_id') AS expected_collection_id,
1844
+ json_extract(entry.value, '$.expected_updated_at') AS expected_updated_at,
1845
+ json_extract(entry.value, '$.expected_source_fingerprint') AS expected_source_fingerprint,
1846
+ json_extract(entry.value, '$.expected_source_updated_at') AS expected_source_updated_at,
1847
+ CAST(json_extract(entry.value, '$.expected_source_version') AS integer) AS expected_source_version,
1848
+ CAST(json_extract(entry.value, '$.expected_identity_version') AS integer) AS expected_identity_version,
1849
+ json_extract(entry.value, '$.expected_revision_id') AS expected_revision_id,
1850
+ json_extract(entry.value, '$.expected_source_completeness') AS expected_source_completeness,
1851
+ json_extract(entry.value, '$.expected_last_attempted_at') AS expected_last_attempted_at,
1852
+ json_extract(entry.value, '$.expected_last_error_code') AS expected_last_error_code
1853
+ FROM json_each(${payload}) AS entry
1854
+ `;
1855
+ }
1856
+ generationWriteBatchInput(payload) {
1857
+ if (isPostgres(this.db)) return sql`
1858
+ SELECT
1859
+ entry.value ->> 'source_key' AS source_key,
1860
+ entry.value ->> 'collection_id' AS collection_id,
1861
+ entry.value ->> 'collection_slug' AS collection_slug,
1862
+ entry.value ->> 'generation' AS generation,
1863
+ entry.value ->> 'lease_token' AS lease_token,
1864
+ entry.value ->> 'expires_at' AS expires_at,
1865
+ entry.value ->> 'created_at' AS created_at
1866
+ FROM jsonb_array_elements(${payload}::jsonb) AS entry(value)
1867
+ `;
1868
+ return sql`
1869
+ SELECT
1870
+ json_extract(entry.value, '$.source_key') AS source_key,
1871
+ json_extract(entry.value, '$.collection_id') AS collection_id,
1872
+ json_extract(entry.value, '$.collection_slug') AS collection_slug,
1873
+ json_extract(entry.value, '$.generation') AS generation,
1874
+ json_extract(entry.value, '$.lease_token') AS lease_token,
1875
+ json_extract(entry.value, '$.expires_at') AS expires_at,
1876
+ json_extract(entry.value, '$.created_at') AS created_at
1877
+ FROM json_each(${payload}) AS entry
1878
+ `;
1879
+ }
1880
+ batchRefsMatch(left, right) {
1881
+ const leftRef = sql.ref(left);
1882
+ const rightRef = sql.ref(right);
1883
+ return isPostgres(this.db) ? sql`${leftRef} IS NOT DISTINCT FROM ${rightRef}` : sql`${leftRef} IS ${rightRef}`;
1884
+ }
1885
+ async lockCanonicalSourceCollection(db, source) {
1886
+ if (source.collectionId === void 0 || source.collectionId === null) return true;
1887
+ if (!source.collectionSlug) return false;
1888
+ if (!isPostgres(this.db)) return true;
1889
+ return await db.selectFrom("_emdash_collections").select("id").where("id", "=", source.collectionId).where("slug", "=", source.collectionSlug).forKeyShare().executeTakeFirst() !== void 0;
1890
+ }
1891
+ async upsertSource(db, source, generation, now, leaseToken) {
1892
+ const row = this.buildSourceRow(source, generation, now);
1893
+ return this.persistSourceIfWriteLease(db, row, leaseToken, sql`
1894
+ ON CONFLICT (source_key) DO UPDATE SET
1895
+ source_type = excluded.source_type,
1896
+ collection_id = excluded.collection_id,
1897
+ collection_slug = excluded.collection_slug,
1898
+ content_id = excluded.content_id,
1899
+ source_variant = excluded.source_variant,
1900
+ locale = excluded.locale,
1901
+ translation_group = excluded.translation_group,
1902
+ content_slug = excluded.content_slug,
1903
+ content_title = excluded.content_title,
1904
+ content_status = excluded.content_status,
1905
+ content_scheduled_at = excluded.content_scheduled_at,
1906
+ content_deleted_at = excluded.content_deleted_at,
1907
+ revision_id = excluded.revision_id,
1908
+ current_generation = excluded.current_generation,
1909
+ schema_version = excluded.schema_version,
1910
+ source_updated_at = excluded.source_updated_at,
1911
+ source_version = excluded.source_version,
1912
+ source_fingerprint = excluded.source_fingerprint,
1913
+ identity_version = excluded.identity_version,
1914
+ source_completeness = excluded.source_completeness,
1915
+ last_attempted_at = excluded.last_attempted_at,
1916
+ last_error_code = excluded.last_error_code,
1917
+ indexed_at = excluded.indexed_at,
1918
+ updated_at = excluded.updated_at
1919
+ `);
1920
+ }
1921
+ async insertSourceIfAbsent(db, row, leaseToken) {
1922
+ return this.persistSourceIfWriteLease(db, row, leaseToken, sql`ON CONFLICT (source_key) DO NOTHING`);
1923
+ }
1924
+ async persistSourceIfWriteLease(db, row, leaseToken, conflict) {
1925
+ const result = await sql`
1926
+ INSERT INTO _emdash_media_usage_sources (
1927
+ source_key,
1928
+ source_type,
1929
+ collection_id,
1930
+ collection_slug,
1931
+ content_id,
1932
+ source_variant,
1933
+ locale,
1934
+ translation_group,
1935
+ content_slug,
1936
+ content_title,
1937
+ content_status,
1938
+ content_scheduled_at,
1939
+ content_deleted_at,
1940
+ revision_id,
1941
+ current_generation,
1942
+ schema_version,
1943
+ source_updated_at,
1944
+ source_version,
1945
+ source_fingerprint,
1946
+ identity_version,
1947
+ source_completeness,
1948
+ last_attempted_at,
1949
+ last_error_code,
1950
+ indexed_at,
1951
+ updated_at
1952
+ )
1953
+ SELECT
1954
+ ${row.source_key},
1955
+ ${row.source_type},
1956
+ ${row.collection_id},
1957
+ ${row.collection_slug},
1958
+ ${row.content_id},
1959
+ ${row.source_variant},
1960
+ ${row.locale},
1961
+ ${row.translation_group},
1962
+ ${row.content_slug},
1963
+ ${row.content_title},
1964
+ ${row.content_status},
1965
+ ${row.content_scheduled_at},
1966
+ ${row.content_deleted_at},
1967
+ ${row.revision_id},
1968
+ ${row.current_generation},
1969
+ ${row.schema_version},
1970
+ ${row.source_updated_at},
1971
+ ${row.source_version},
1972
+ ${row.source_fingerprint},
1973
+ ${row.identity_version},
1974
+ ${row.source_completeness},
1975
+ ${row.last_attempted_at},
1976
+ ${row.last_error_code},
1977
+ ${row.indexed_at},
1978
+ ${row.updated_at}
1979
+ WHERE EXISTS (
1980
+ SELECT 1
1981
+ FROM _emdash_media_usage_generation_writes
1982
+ WHERE source_key = ${row.source_key}
1983
+ AND generation = ${row.current_generation}
1984
+ AND lease_token = ${leaseToken}
1985
+ AND ${this.generationWriteLeaseExpiryIsInFuture("expires_at")}
1986
+ )
1987
+ AND ${this.currentCollectionExists(row.collection_id, row.collection_slug)}
1988
+ AND ${this.currentCanonicalContentExists(row)}
1989
+ ${conflict}
1990
+ `.execute(db);
1991
+ return Number(result.numAffectedRows ?? 0) > 0;
1992
+ }
1993
+ generationWriteLeaseExpression(row, leaseToken) {
1994
+ return (eb) => eb.exists(eb.selectFrom("_emdash_media_usage_generation_writes").select("source_key").where("source_key", "=", row.source_key).where("generation", "=", row.current_generation).where("lease_token", "=", leaseToken).where(this.generationWriteLeaseExpiryIsInFuture("_emdash_media_usage_generation_writes.expires_at")));
1995
+ }
1996
+ generationWriteLeaseExpiryIsInFuture(column) {
1997
+ const leaseExpiresAt = sql.ref(column);
1998
+ return isPostgres(this.db) ? sql`${leaseExpiresAt}::timestamptz > clock_timestamp()` : sql`${leaseExpiresAt} > strftime('%Y-%m-%dT%H:%M:%fZ', 'now')`;
1999
+ }
2000
+ async withGenerationWriteLease(source, generation, write) {
2001
+ const leaseToken = ulid();
2002
+ const owner = (await sql`
2003
+ INSERT INTO _emdash_media_usage_generation_writes (
2004
+ source_key, generation, lease_token, expires_at, created_at
2005
+ )
2006
+ SELECT
2007
+ ${source.sourceKey},
2008
+ ${generation},
2009
+ ${leaseToken},
2010
+ ${this.generationWriteLeaseTimestampOffset(MEDIA_USAGE_GENERATION_WRITE_LEASE_MS / 1e3)},
2011
+ ${this.generationWriteLeaseTimestampOffset(0)}
2012
+ WHERE ${this.currentCollectionExists(source.collectionId ?? null, source.collectionSlug ?? null)}
2013
+ RETURNING created_at
2014
+ `.execute(this.db)).rows[0];
2015
+ if (!owner) return false;
2016
+ try {
2017
+ await write(leaseToken, owner.created_at);
2018
+ return true;
2019
+ } finally {
2020
+ try {
2021
+ await this.db.deleteFrom("_emdash_media_usage_generation_writes").where("source_key", "=", source.sourceKey).where("generation", "=", generation).where("lease_token", "=", leaseToken).execute();
2022
+ } catch (error) {
2023
+ console.error("[media-usage] Failed to release generation write lease:", error);
2024
+ }
2025
+ }
2026
+ }
2027
+ generationWriteLeaseTimestampOffset(offsetSeconds) {
2028
+ if (isPostgres(this.db)) return sql`to_char(
2029
+ (clock_timestamp() AT TIME ZONE 'UTC') + (${offsetSeconds} * INTERVAL '1 second'),
2030
+ 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'
2031
+ )`;
2032
+ return sql`strftime(
2033
+ '%Y-%m-%dT%H:%M:%fZ',
2034
+ 'now',
2035
+ ${`${offsetSeconds >= 0 ? "+" : ""}${offsetSeconds} seconds`}
2036
+ )`;
2037
+ }
2038
+ async updateSourceIfGeneration(db, row, expectedCurrentGeneration, leaseToken) {
2039
+ const result = await db.updateTable("_emdash_media_usage_sources").set(this.sourceUpdateSet(row)).where("source_key", "=", row.source_key).where("current_generation", "=", expectedCurrentGeneration).where(this.generationWriteLeaseExpression(row, leaseToken)).where(this.currentCollectionExists(row.collection_id, row.collection_slug)).where(this.currentCanonicalContentExists(row)).executeTakeFirst();
2040
+ return Number(result.numUpdatedRows ?? 0) > 0;
2041
+ }
2042
+ async updateSourceIfMatching(db, row, expectedSource, leaseToken) {
2043
+ const result = await db.updateTable("_emdash_media_usage_sources").set(this.sourceUpdateSet(row)).where("source_key", "=", row.source_key).where(this.sourceMatchExpression(expectedSource)).where(this.generationWriteLeaseExpression(row, leaseToken)).where(this.currentCollectionExists(row.collection_id, row.collection_slug)).where(this.currentCanonicalContentExists(row)).executeTakeFirst();
2044
+ return Number(result.numUpdatedRows ?? 0) > 0;
2045
+ }
2046
+ async updateAttemptedSourceIfMatching(db, source, row, expectedSource) {
2047
+ const result = await db.updateTable("_emdash_media_usage_sources").set(this.attemptedSourceUpdateSet(source, row)).where("source_key", "=", row.source_key).where(this.sourceMatchExpression(expectedSource)).where(this.currentCollectionExists(row.collection_id, row.collection_slug)).where(this.currentCanonicalContentExists(row)).executeTakeFirst();
2048
+ return Number(result.numUpdatedRows ?? 0) > 0;
2049
+ }
2050
+ sourceMatchExpression(expectedSource) {
2051
+ return (eb) => eb.and([
2052
+ eb("current_generation", "=", expectedSource.currentGeneration),
2053
+ eb("source_completeness", "=", expectedSource.sourceCompleteness),
2054
+ this.nullableStringExpression(eb, "collection_id", expectedSource.collectionId),
2055
+ this.nullableStringExpression(eb, "updated_at", expectedSource.updatedAt),
2056
+ this.nullableStringExpression(eb, "source_fingerprint", expectedSource.sourceFingerprint),
2057
+ this.nullableStringExpression(eb, "source_updated_at", expectedSource.sourceUpdatedAt),
2058
+ this.nullableNumberExpression(eb, "source_version", expectedSource.sourceVersion),
2059
+ this.nullableNumberExpression(eb, "identity_version", expectedSource.identityVersion),
2060
+ this.nullableStringExpression(eb, "revision_id", expectedSource.revisionId),
2061
+ this.nullableStringExpression(eb, "last_attempted_at", expectedSource.lastAttemptedAt),
2062
+ this.nullableStringExpression(eb, "last_error_code", expectedSource.lastErrorCode)
2063
+ ]);
2064
+ }
2065
+ async projectionMatchesCurrentGeneration(source, expectedCurrentGeneration) {
2066
+ const fingerprint = source.sourceFingerprint;
2067
+ if (!isMediaUsageProjectionFingerprint(fingerprint)) return false;
2068
+ return await this.db.selectFrom("_emdash_media_usage_sources").select("source_key").where("source_key", "=", source.sourceKey).where("current_generation", "=", expectedCurrentGeneration).where("source_fingerprint", "=", fingerprint).where("source_completeness", "=", source.sourceCompleteness ?? "complete").where("last_error_code", "is", null).where(this.currentCollectionExists(source.collectionId ?? null, source.collectionSlug ?? null)).executeTakeFirst() !== void 0;
2069
+ }
2070
+ async projectionMatchesExpectedSource(source, expectedSource) {
2071
+ const fingerprint = source.sourceFingerprint;
2072
+ if (!isMediaUsageProjectionFingerprint(fingerprint) || expectedSource.sourceFingerprint !== fingerprint || expectedSource.sourceCompleteness !== (source.sourceCompleteness ?? "complete") || expectedSource.lastErrorCode !== null) return false;
2073
+ return await this.db.selectFrom("_emdash_media_usage_sources").select("source_key").where("source_key", "=", source.sourceKey).where(this.sourceMatchExpression(expectedSource)).where(this.currentCollectionExists(source.collectionId ?? null, source.collectionSlug ?? null)).executeTakeFirst() !== void 0;
2074
+ }
2075
+ nullableStringExpression(eb, column, value) {
2076
+ return value === null ? eb(column, "is", null) : eb(column, "=", value);
2077
+ }
2078
+ currentCollectionExists(collectionId, collectionSlug) {
2079
+ if (collectionId === null) return sql`1 = 1`;
2080
+ return sql`EXISTS (
2081
+ SELECT 1
2082
+ FROM _emdash_collections
2083
+ WHERE id = ${collectionId}
2084
+ AND slug = ${collectionSlug}
2085
+ )`;
2086
+ }
2087
+ currentCanonicalContentExists(row) {
2088
+ if (row.collection_id === null || row.identity_version !== 1 || row.source_type !== "content") return sql`1 = 1`;
2089
+ if (!row.collection_slug || !row.content_id || row.source_version === null || row.source_updated_at === null) return sql`1 = 0`;
2090
+ validateIdentifier(row.collection_slug, "collection slug");
2091
+ const tableName = `ec_${row.collection_slug}`;
2092
+ validateIdentifier(tableName, "content table");
2093
+ const revisionColumn = row.source_variant === "columns" ? "live_revision_id" : row.source_variant === "draft_overlay" ? "draft_revision_id" : null;
2094
+ if (!revisionColumn) return sql`1 = 0`;
2095
+ const revision = sql.ref(`content.${revisionColumn}`);
2096
+ const revisionMatches = row.revision_id === null ? sql`${revision} IS NULL` : sql`${revision} = ${row.revision_id}`;
2097
+ return sql`EXISTS (
2098
+ SELECT 1
2099
+ FROM ${sql.ref(tableName)} AS content
2100
+ WHERE content.id = ${row.content_id}
2101
+ AND content.version = ${row.source_version}
2102
+ AND content.updated_at = ${row.source_updated_at}
2103
+ AND ${revisionMatches}
2104
+ )`;
2105
+ }
2106
+ nullableNumberExpression(eb, column, value) {
2107
+ return value === null ? eb(column, "is", null) : eb(column, "=", value);
2108
+ }
2109
+ async contentRowExists(tableName, contentId) {
2110
+ return (await sql`
2111
+ SELECT id
2112
+ FROM ${sql.ref(tableName)}
2113
+ WHERE id = ${contentId}
2114
+ LIMIT 1
2115
+ `.execute(this.db)).rows.length > 0;
2116
+ }
2117
+ buildSourceRow(source, generation, now) {
2118
+ return {
2119
+ source_key: source.sourceKey,
2120
+ source_type: source.sourceType,
2121
+ collection_id: source.collectionId ?? null,
2122
+ collection_slug: source.collectionSlug ?? null,
2123
+ content_id: source.contentId ?? null,
2124
+ source_variant: source.sourceVariant,
2125
+ locale: source.locale ?? null,
2126
+ translation_group: source.translationGroup ?? null,
2127
+ content_slug: source.contentSlug ?? null,
2128
+ content_title: source.contentTitle ?? null,
2129
+ content_status: source.contentStatus ?? null,
2130
+ content_scheduled_at: source.contentScheduledAt ?? null,
2131
+ content_deleted_at: source.contentDeletedAt ?? null,
2132
+ revision_id: source.revisionId ?? null,
2133
+ current_generation: generation,
2134
+ schema_version: source.schemaVersion ?? 1,
2135
+ source_updated_at: source.sourceUpdatedAt ?? null,
2136
+ source_version: source.sourceVersion ?? null,
2137
+ source_fingerprint: source.sourceFingerprint ?? null,
2138
+ identity_version: source.identityVersion ?? null,
2139
+ source_completeness: source.sourceCompleteness ?? "complete",
2140
+ last_attempted_at: source.lastAttemptedAt ?? now,
2141
+ last_error_code: null,
2142
+ indexed_at: now,
2143
+ updated_at: now
2144
+ };
2145
+ }
2146
+ buildAttemptedSourceRow(source, generation, now) {
2147
+ return {
2148
+ source_key: source.sourceKey,
2149
+ source_type: source.sourceType,
2150
+ collection_id: source.collectionId ?? null,
2151
+ collection_slug: source.collectionSlug ?? null,
2152
+ content_id: source.contentId ?? null,
2153
+ source_variant: source.sourceVariant,
2154
+ locale: source.locale ?? null,
2155
+ translation_group: source.translationGroup ?? null,
2156
+ content_slug: source.contentSlug ?? null,
2157
+ content_title: source.contentTitle ?? null,
2158
+ content_status: source.contentStatus ?? null,
2159
+ content_scheduled_at: source.contentScheduledAt ?? null,
2160
+ content_deleted_at: source.contentDeletedAt ?? null,
2161
+ revision_id: source.revisionId ?? null,
2162
+ current_generation: generation,
2163
+ schema_version: source.schemaVersion ?? 1,
2164
+ source_updated_at: source.sourceUpdatedAt ?? null,
2165
+ source_version: source.sourceVersion ?? null,
2166
+ source_fingerprint: source.sourceFingerprint ?? null,
2167
+ identity_version: source.identityVersion ?? null,
2168
+ source_completeness: source.sourceCompleteness ?? (source.lastErrorCode ? "failed" : "unknown"),
2169
+ last_attempted_at: source.lastAttemptedAt ?? now,
2170
+ last_error_code: source.lastErrorCode ?? null,
2171
+ indexed_at: now,
2172
+ updated_at: now
2173
+ };
2174
+ }
2175
+ attemptedSourceUpdateSet(source, row) {
2176
+ const updates = {
2177
+ source_type: row.source_type,
2178
+ source_variant: row.source_variant,
2179
+ source_completeness: row.source_completeness,
2180
+ last_attempted_at: row.last_attempted_at,
2181
+ last_error_code: row.last_error_code,
2182
+ updated_at: row.updated_at
2183
+ };
2184
+ if (source.collectionSlug !== void 0) updates.collection_slug = row.collection_slug;
2185
+ if (source.collectionId !== void 0) updates.collection_id = row.collection_id;
2186
+ if (source.contentId !== void 0) updates.content_id = row.content_id;
2187
+ if (source.locale !== void 0) updates.locale = row.locale;
2188
+ if (source.translationGroup !== void 0) updates.translation_group = row.translation_group;
2189
+ if (source.contentSlug !== void 0) updates.content_slug = row.content_slug;
2190
+ if (source.contentTitle !== void 0) updates.content_title = row.content_title;
2191
+ if (source.contentStatus !== void 0) updates.content_status = row.content_status;
2192
+ if (source.contentScheduledAt !== void 0) updates.content_scheduled_at = row.content_scheduled_at;
2193
+ if (source.contentDeletedAt !== void 0) updates.content_deleted_at = row.content_deleted_at;
2194
+ if (source.revisionId !== void 0) updates.revision_id = row.revision_id;
2195
+ if (source.schemaVersion !== void 0) updates.schema_version = row.schema_version;
2196
+ if (source.sourceUpdatedAt !== void 0) updates.source_updated_at = row.source_updated_at;
2197
+ if (source.sourceVersion !== void 0) updates.source_version = row.source_version;
2198
+ if (source.sourceFingerprint !== void 0) updates.source_fingerprint = row.source_fingerprint;
2199
+ if (source.identityVersion !== void 0) updates.identity_version = row.identity_version;
2200
+ return updates;
2201
+ }
2202
+ sourceUpdateSet(row) {
2203
+ return {
2204
+ source_type: row.source_type,
2205
+ collection_id: row.collection_id,
2206
+ collection_slug: row.collection_slug,
2207
+ content_id: row.content_id,
2208
+ source_variant: row.source_variant,
2209
+ locale: row.locale,
2210
+ translation_group: row.translation_group,
2211
+ content_slug: row.content_slug,
2212
+ content_title: row.content_title,
2213
+ content_status: row.content_status,
2214
+ content_scheduled_at: row.content_scheduled_at,
2215
+ content_deleted_at: row.content_deleted_at,
2216
+ revision_id: row.revision_id,
2217
+ current_generation: row.current_generation,
2218
+ schema_version: row.schema_version,
2219
+ source_updated_at: row.source_updated_at,
2220
+ source_version: row.source_version,
2221
+ source_fingerprint: row.source_fingerprint,
2222
+ identity_version: row.identity_version,
2223
+ source_completeness: row.source_completeness,
2224
+ last_attempted_at: row.last_attempted_at,
2225
+ last_error_code: row.last_error_code,
2226
+ indexed_at: row.indexed_at,
2227
+ updated_at: row.updated_at
2228
+ };
2229
+ }
2230
+ };
2231
+ const currentUsageSelect = [
2232
+ "s.source_key as source_key",
2233
+ "s.source_type as source_type",
2234
+ "s.collection_id as collection_id",
2235
+ "s.collection_slug as collection_slug",
2236
+ "s.content_id as content_id",
2237
+ "s.source_variant as source_variant",
2238
+ "s.locale as locale",
2239
+ "s.translation_group as translation_group",
2240
+ "s.content_slug as content_slug",
2241
+ "s.content_title as content_title",
2242
+ "s.content_status as content_status",
2243
+ "s.content_scheduled_at as content_scheduled_at",
2244
+ "s.content_deleted_at as content_deleted_at",
2245
+ "s.revision_id as revision_id",
2246
+ "s.current_generation as current_generation",
2247
+ "s.schema_version as schema_version",
2248
+ "s.source_updated_at as source_updated_at",
2249
+ "s.source_version as source_version",
2250
+ "s.source_fingerprint as source_fingerprint",
2251
+ "s.identity_version as identity_version",
2252
+ "s.source_completeness as source_completeness",
2253
+ "s.last_attempted_at as last_attempted_at",
2254
+ "s.last_error_code as last_error_code",
2255
+ "s.indexed_at as indexed_at",
2256
+ "s.created_at as source_created_at",
2257
+ "s.updated_at as source_row_updated_at",
2258
+ "u.id as occurrence_id",
2259
+ "u.generation as generation",
2260
+ "u.field_slug as field_slug",
2261
+ "u.field_path as field_path",
2262
+ "u.occurrence_index as occurrence_index",
2263
+ "u.reference_type as reference_type",
2264
+ "u.media_id as media_id",
2265
+ "u.provider as provider",
2266
+ "u.provider_asset_id as provider_asset_id",
2267
+ "u.media_kind as media_kind",
2268
+ "u.mime_type as mime_type",
2269
+ "u.created_at as occurrence_created_at"
2270
+ ];
2271
+ function groupUsageRows(rows) {
2272
+ const groups = [];
2273
+ for (const row of rows) {
2274
+ if (row.collection_slug === null || row.content_id === null) continue;
2275
+ const record = rowToUsageRecord(row);
2276
+ let group = groups.at(-1);
2277
+ if (!group || group.collectionSlug !== row.collection_slug || group.contentId !== row.content_id) {
2278
+ group = {
2279
+ collectionSlug: row.collection_slug,
2280
+ contentId: row.content_id,
2281
+ contentDeletedAt: row.entry_deleted_at,
2282
+ sources: []
2283
+ };
2284
+ groups.push(group);
2285
+ }
2286
+ let source = group.sources.at(-1);
2287
+ if (!source || source.source.sourceKey !== record.source.sourceKey) {
2288
+ source = {
2289
+ source: record.source,
2290
+ occurrences: []
2291
+ };
2292
+ group.sources.push(source);
2293
+ }
2294
+ source.occurrences.push(record.occurrence);
2295
+ }
2296
+ return groups;
2297
+ }
2298
+ function rowToSource(row) {
2299
+ return {
2300
+ sourceKey: row.source_key,
2301
+ sourceType: row.source_type,
2302
+ collectionId: row.collection_id,
2303
+ collectionSlug: row.collection_slug,
2304
+ contentId: row.content_id,
2305
+ sourceVariant: row.source_variant,
2306
+ locale: row.locale,
2307
+ translationGroup: row.translation_group,
2308
+ contentSlug: row.content_slug,
2309
+ contentTitle: row.content_title,
2310
+ contentStatus: row.content_status,
2311
+ contentScheduledAt: row.content_scheduled_at,
2312
+ contentDeletedAt: row.content_deleted_at,
2313
+ revisionId: row.revision_id,
2314
+ currentGeneration: row.current_generation,
2315
+ schemaVersion: Number(row.schema_version),
2316
+ sourceUpdatedAt: row.source_updated_at,
2317
+ sourceVersion: row.source_version === null ? null : Number(row.source_version),
2318
+ sourceFingerprint: row.source_fingerprint,
2319
+ identityVersion: row.identity_version === null ? null : Number(row.identity_version),
2320
+ sourceCompleteness: row.source_completeness,
2321
+ lastAttemptedAt: row.last_attempted_at,
2322
+ lastErrorCode: row.last_error_code,
2323
+ indexedAt: row.indexed_at,
2324
+ createdAt: row.created_at,
2325
+ updatedAt: row.updated_at
2326
+ };
2327
+ }
2328
+ function rowToOccurrence(row) {
2329
+ return {
2330
+ id: row.id,
2331
+ sourceKey: row.source_key,
2332
+ generation: row.generation,
2333
+ fieldSlug: row.field_slug,
2334
+ fieldPath: row.field_path,
2335
+ occurrenceIndex: Number(row.occurrence_index),
2336
+ referenceType: row.reference_type,
2337
+ mediaId: row.media_id,
2338
+ provider: row.provider,
2339
+ providerAssetId: row.provider_asset_id,
2340
+ mediaKind: row.media_kind,
2341
+ mimeType: row.mime_type,
2342
+ createdAt: row.created_at
2343
+ };
2344
+ }
2345
+ function rowToUsageRecord(row) {
2346
+ return {
2347
+ source: rowToSource({
2348
+ source_key: row.source_key,
2349
+ source_type: row.source_type,
2350
+ collection_id: row.collection_id,
2351
+ collection_slug: row.collection_slug,
2352
+ content_id: row.content_id,
2353
+ source_variant: row.source_variant,
2354
+ locale: row.locale,
2355
+ translation_group: row.translation_group,
2356
+ content_slug: row.content_slug,
2357
+ content_title: row.content_title,
2358
+ content_status: row.content_status,
2359
+ content_scheduled_at: row.content_scheduled_at,
2360
+ content_deleted_at: row.content_deleted_at,
2361
+ revision_id: row.revision_id,
2362
+ current_generation: row.current_generation,
2363
+ schema_version: row.schema_version,
2364
+ source_updated_at: row.source_updated_at,
2365
+ source_version: row.source_version,
2366
+ source_fingerprint: row.source_fingerprint,
2367
+ identity_version: row.identity_version,
2368
+ source_completeness: row.source_completeness,
2369
+ last_attempted_at: row.last_attempted_at,
2370
+ last_error_code: row.last_error_code,
2371
+ indexed_at: row.indexed_at,
2372
+ created_at: row.source_created_at,
2373
+ updated_at: row.source_row_updated_at
2374
+ }),
2375
+ occurrence: rowToOccurrence({
2376
+ id: row.occurrence_id,
2377
+ source_key: row.source_key,
2378
+ generation: row.generation,
2379
+ field_slug: row.field_slug,
2380
+ field_path: row.field_path,
2381
+ occurrence_index: row.occurrence_index,
2382
+ reference_type: row.reference_type,
2383
+ media_id: row.media_id,
2384
+ provider: row.provider,
2385
+ provider_asset_id: row.provider_asset_id,
2386
+ media_kind: row.media_kind,
2387
+ mime_type: row.mime_type,
2388
+ created_at: row.occurrence_created_at,
2389
+ cleanup_lease_token: null
2390
+ })
2391
+ };
2392
+ }
2393
+ function rowToIndexStatus(row) {
2394
+ return {
2395
+ adapterId: row.adapter_id,
2396
+ scopeType: row.scope_type,
2397
+ scopeKey: row.scope_key,
2398
+ status: row.status,
2399
+ schemaVersion: Number(row.schema_version),
2400
+ startedAt: row.started_at,
2401
+ completedAt: row.completed_at,
2402
+ cursor: row.cursor,
2403
+ indexedSourceCount: Number(row.indexed_source_count),
2404
+ failedSourceCount: Number(row.failed_source_count),
2405
+ lastErrorCode: row.last_error_code,
2406
+ updatedAt: row.updated_at
2407
+ };
2408
+ }
2409
+
2410
+ //#endregion
2411
+ //#region src/database/repositories/media.ts
2412
+ /** Escape LIKE wildcard characters and the escape char itself in user-supplied values */
2413
+ function escapeLike(value) {
2414
+ return value.replaceAll("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_");
2415
+ }
2416
+ /**
2417
+ * Normalize a mimeType filter (string or array) into a clean string[].
2418
+ * Entries that are empty strings are dropped.
2419
+ */
2420
+ function normalizeMimeFilter(input) {
2421
+ if (!input) return [];
2422
+ return (Array.isArray(input) ? input : [input]).filter((entry) => typeof entry === "string" && entry.length > 0).map((entry) => entry.endsWith("/") ? entry.toLowerCase() : entry.split(";")[0].trim().toLowerCase());
2423
+ }
2424
+ function normalizeListLimit(limit) {
2425
+ const integer = typeof limit === "number" && !Number.isNaN(limit) ? Math.trunc(limit) : 50;
2426
+ return Math.min(Math.max(integer, 1), 100);
2427
+ }
2428
+ /**
2429
+ * Build a WHERE clause that matches `mime_type` against any of the given
2430
+ * filter entries — exact equality for full MIMEs, LIKE prefix for entries
2431
+ * ending in "/".
2432
+ */
2433
+ function mimeMatchExpr(eb, filters) {
2434
+ return eb.or(filters.map((entry) => entry.endsWith("/") ? sql`mime_type LIKE ${`${escapeLike(entry)}%`} ESCAPE '\\'` : eb("mime_type", "=", entry)));
2435
+ }
2436
+ const UPLOAD_ATTEMPT_CLEANUP_AGE_MS = 3600 * 1e3;
2437
+ const UPLOAD_ATTEMPT_CLEANUP_BATCH_SIZE = 100;
2438
+ /**
2439
+ * Media repository for database operations
2440
+ */
2441
+ var MediaRepository = class {
2442
+ constructor(db) {
2443
+ this.db = db;
2444
+ }
2445
+ /**
2446
+ * Create a new media item
2447
+ */
2448
+ async create(input) {
2449
+ const id = ulid();
2450
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2451
+ const row = {
2452
+ id,
2453
+ filename: input.filename,
2454
+ mime_type: input.mimeType,
2455
+ size: input.size ?? null,
2456
+ width: input.width ?? null,
2457
+ height: input.height ?? null,
2458
+ focal_x: null,
2459
+ focal_y: null,
2460
+ alt: input.alt ?? null,
2461
+ caption: input.caption ?? null,
2462
+ storage_key: input.storageKey,
2463
+ content_hash: input.contentHash ?? null,
2464
+ blurhash: input.blurhash ?? null,
2465
+ dominant_color: input.dominantColor ?? null,
2466
+ status: input.status ?? "ready",
2467
+ created_at: now,
2468
+ author_id: input.authorId ?? null,
2469
+ folder_id: input.folderId ?? null
2470
+ };
2471
+ await this.db.insertInto("media").values(row).execute();
2472
+ return this.rowToItem(row);
2473
+ }
2474
+ /**
2475
+ * Create a pending media item (for signed URL upload flow)
2476
+ */
2477
+ async createPending(input) {
2478
+ return this.create({
2479
+ ...input,
2480
+ status: "pending"
2481
+ });
2482
+ }
2483
+ async createUploadAttempt(mediaId, storageKey) {
2484
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2485
+ await this.db.insertInto("_emdash_media_upload_attempts").values({
2486
+ media_id: mediaId,
2487
+ storage_key: storageKey,
2488
+ status: "active",
2489
+ created_at: now,
2490
+ updated_at: now
2491
+ }).execute();
2492
+ }
2493
+ /**
2494
+ * Register a stored object for cleanup before its media row is removed,
2495
+ * so a failed storage delete is retried by the cleanup sweep instead of
2496
+ * leaving the object unreferenced and unreachable.
2497
+ */
2498
+ async trackStorageKeyForCleanup(mediaId, storageKey) {
2499
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2500
+ await this.db.insertInto("_emdash_media_upload_attempts").values({
2501
+ media_id: mediaId,
2502
+ storage_key: storageKey,
2503
+ status: "cleanup",
2504
+ created_at: now,
2505
+ updated_at: now
2506
+ }).onConflict((oc) => oc.column("storage_key").doUpdateSet({
2507
+ status: "cleanup",
2508
+ updated_at: now
2509
+ })).execute();
2510
+ }
2511
+ async hasUploadAttempt(storageKey) {
2512
+ return await this.db.selectFrom("_emdash_media_upload_attempts").select("storage_key").where("storage_key", "=", storageKey).executeTakeFirst() !== void 0;
2513
+ }
2514
+ async claimUploadAttemptForCleanup(storageKey) {
2515
+ const result = await this.db.updateTable("_emdash_media_upload_attempts").set({
2516
+ status: "cleanup",
2517
+ updated_at: (/* @__PURE__ */ new Date()).toISOString()
2518
+ }).where("storage_key", "=", storageKey).where((eb) => eb.not(eb.exists(eb.selectFrom("media").select("media.id").whereRef("media.storage_key", "=", "_emdash_media_upload_attempts.storage_key")))).executeTakeFirst();
2519
+ return Number(result.numUpdatedRows ?? 0) > 0;
2520
+ }
2521
+ async deleteUploadAttempt(storageKey) {
2522
+ await this.db.deleteFrom("_emdash_media_upload_attempts").where("storage_key", "=", storageKey).execute();
2523
+ }
2524
+ async deferUploadAttemptCleanup(storageKey) {
2525
+ await this.db.updateTable("_emdash_media_upload_attempts").set({ updated_at: (/* @__PURE__ */ new Date()).toISOString() }).where("storage_key", "=", storageKey).execute();
2526
+ }
2527
+ async deleteCompletedUploadAttempts() {
2528
+ const result = await this.db.deleteFrom("_emdash_media_upload_attempts").where("status", "=", "active").where((eb) => eb.exists(eb.selectFrom("media").select("media.id").whereRef("media.id", "=", "_emdash_media_upload_attempts.media_id").whereRef("media.storage_key", "=", "_emdash_media_upload_attempts.storage_key").where("media.status", "=", "ready"))).executeTakeFirst();
2529
+ return Number(result.numDeletedRows ?? 0);
2530
+ }
2531
+ async findUploadAttemptsForCleanup(maxAgeMs = UPLOAD_ATTEMPT_CLEANUP_AGE_MS, limit = UPLOAD_ATTEMPT_CLEANUP_BATCH_SIZE) {
2532
+ const cutoff = new Date(Date.now() - maxAgeMs).toISOString();
2533
+ return (await this.db.selectFrom("_emdash_media_upload_attempts").select("storage_key").where((eb) => eb.or([eb("status", "=", "cleanup"), eb("created_at", "<", cutoff)])).where((eb) => eb.not(eb.exists(eb.selectFrom("media").select("media.id").whereRef("media.storage_key", "=", "_emdash_media_upload_attempts.storage_key")))).orderBy("updated_at", "asc").limit(limit).execute()).map((row) => row.storage_key);
2534
+ }
2535
+ async publishPendingStorageKey(id, expectedStorageKey, storageKey, contentHash) {
2536
+ const result = await this.db.updateTable("media").set({
2537
+ storage_key: storageKey,
2538
+ ...contentHash !== void 0 ? { content_hash: contentHash } : {}
2539
+ }).where("id", "=", id).where("status", "=", "pending").where("storage_key", "=", expectedStorageKey).where((eb) => eb.exists(eb.selectFrom("_emdash_media_upload_attempts").select("storage_key").where("media_id", "=", id).where("storage_key", "=", storageKey).where("status", "=", "active"))).executeTakeFirst();
2540
+ return Number(result.numUpdatedRows ?? 0) > 0;
2541
+ }
2542
+ /**
2543
+ * Confirm upload (mark as ready)
2544
+ */
2545
+ async confirmUpload(id, metadata, expectedStorageKey) {
2546
+ const updates = { status: "ready" };
2547
+ if (metadata?.width !== void 0) updates.width = metadata.width;
2548
+ if (metadata?.height !== void 0) updates.height = metadata.height;
2549
+ if (metadata?.size !== void 0) updates.size = metadata.size;
2550
+ if (metadata?.blurhash !== void 0) updates.blurhash = metadata.blurhash;
2551
+ if (metadata?.dominantColor !== void 0) updates.dominant_color = metadata.dominantColor;
2552
+ if (metadata?.contentHash !== void 0) updates.content_hash = metadata.contentHash;
2553
+ let query = this.db.updateTable("media").set(updates).where("id", "=", id).where("status", "=", "pending");
2554
+ if (expectedStorageKey !== void 0) query = query.where("storage_key", "=", expectedStorageKey);
2555
+ const row = await query.returningAll().executeTakeFirst();
2556
+ return row ? this.rowToItem(row) : null;
2557
+ }
2558
+ /**
2559
+ * Mark upload as failed
2560
+ */
2561
+ async markFailed(id, expectedStorageKey) {
2562
+ let query = this.db.updateTable("media").set({ status: "failed" }).where("id", "=", id);
2563
+ if (expectedStorageKey !== void 0) query = query.where("status", "=", "pending").where("storage_key", "=", expectedStorageKey);
2564
+ const row = await query.returningAll().executeTakeFirst();
2565
+ return row ? this.rowToItem(row) : null;
2566
+ }
2567
+ /**
2568
+ * Find the pending media row minted for a signed upload URL.
2569
+ */
2570
+ async findPendingByStorageKey(storageKey) {
2571
+ const row = await this.db.selectFrom("media").selectAll().where("storage_key", "=", storageKey).where("status", "=", "pending").executeTakeFirst();
2572
+ return row ? this.rowToItem(row) : null;
2573
+ }
2574
+ /**
2575
+ * Find media by ID
2576
+ */
2577
+ async findById(id) {
2578
+ const row = await this.db.selectFrom("media").selectAll().where("id", "=", id).executeTakeFirst();
2579
+ return row ? this.rowToItem(row) : null;
2580
+ }
2581
+ /**
2582
+ * Map each storage key to the id of its media item, in one query per JSON
2583
+ * bind's worth of keys. Unknown keys are left out.
2584
+ */
2585
+ async findIdsByStorageKeys(storageKeys) {
2586
+ const ids = /* @__PURE__ */ new Map();
2587
+ for (const batch of chunkJsonRows(storageKeys)) {
2588
+ const result = await sql`
2589
+ WITH requested AS (${jsonTextValues(this.db, batch)})
2590
+ SELECT media.id, media.storage_key
2591
+ FROM media
2592
+ INNER JOIN requested ON requested.value = media.storage_key
2593
+ ORDER BY media.id
2594
+ `.execute(this.db);
2595
+ for (const row of result.rows) if (!ids.has(row.storage_key)) ids.set(row.storage_key, row.id);
2596
+ }
2597
+ return ids;
2598
+ }
2599
+ /**
2600
+ * Find the original upload filename for a storage key.
2601
+ *
2602
+ * Used by the public media file route to name the download after the file
2603
+ * the editor uploaded rather than after its storage key. Selects the single
2604
+ * column it needs: this runs on every unauthenticated download.
2605
+ */
2606
+ async findFilenameByStorageKey(storageKey) {
2607
+ return (await this.db.selectFrom("media").select("filename").where("storage_key", "=", storageKey).executeTakeFirst())?.filename ?? null;
2608
+ }
2609
+ /**
2610
+ * Find media by filename
2611
+ * Useful for idempotent imports
2612
+ */
2613
+ async findByFilename(filename) {
2614
+ const row = await this.db.selectFrom("media").selectAll().where("filename", "=", filename).executeTakeFirst();
2615
+ return row ? this.rowToItem(row) : null;
2616
+ }
2617
+ async findAvailableFilename(filename) {
2618
+ const exists = async (candidate) => Boolean(await this.db.selectFrom("media").select("id").where(sql`lower(filename)`, "=", candidate.toLowerCase()).executeTakeFirst());
2619
+ if (!await exists(filename)) return filename;
2620
+ const extensionIndex = filename.lastIndexOf(".");
2621
+ const hasExtension = extensionIndex > 0;
2622
+ const extension = hasExtension ? filename.slice(extensionIndex) : "";
2623
+ const stem = hasExtension ? filename.slice(0, extensionIndex) : filename;
2624
+ let copyNumber = 2;
2625
+ let candidate = `${stem}-${copyNumber}${extension}`;
2626
+ while (await exists(candidate)) {
2627
+ copyNumber += 1;
2628
+ candidate = `${stem}-${copyNumber}${extension}`;
2629
+ }
2630
+ return candidate;
2631
+ }
2632
+ /**
2633
+ * Find media by content hash
2634
+ * Used for deduplication - same content = same hash
2635
+ */
2636
+ async findByContentHash(contentHash) {
2637
+ const row = await this.db.selectFrom("media").selectAll().where("content_hash", "=", contentHash).where("status", "=", "ready").executeTakeFirst();
2638
+ return row ? this.rowToItem(row) : null;
2639
+ }
2640
+ /**
2641
+ * Find many media items with cursor pagination
2642
+ *
2643
+ * Uses keyset pagination (cursor-based) for consistent results.
2644
+ * The cursor encodes the created_at and id of the last item.
2645
+ */
2646
+ async findMany(options = {}) {
2647
+ const limit = normalizeListLimit(options.limit);
2648
+ let query = this.applyListFilters(this.db.selectFrom("media"), options).selectAll().orderBy("created_at", "desc").orderBy("id", "desc").limit(limit + 1);
2649
+ if (options.cursor) {
2650
+ const { orderValue: createdAt, id: cursorId } = decodeCursor(options.cursor);
2651
+ query = query.where((eb) => eb.or([eb("created_at", "<", createdAt), eb.and([eb("created_at", "=", createdAt), eb("id", "<", cursorId)])]));
2652
+ }
2653
+ const rows = await query.execute();
2654
+ const hasMore = rows.length > limit;
2655
+ const items = rows.slice(0, limit).map((row) => this.rowToItem(row));
2656
+ let nextCursor;
2657
+ if (hasMore && items.length > 0) {
2658
+ const lastItem = items.at(-1);
2659
+ nextCursor = encodeCursor(lastItem.createdAt, lastItem.id);
2660
+ }
2661
+ return {
2662
+ items,
2663
+ nextCursor
2664
+ };
2665
+ }
2666
+ async findPage(options) {
2667
+ const limit = normalizeListLimit(options.limit);
2668
+ const offset = (options.page - 1) * limit;
2669
+ const filtered = this.applyListFilters(this.db.selectFrom("media"), options);
2670
+ const rows = await filtered.selectAll().orderBy("created_at", "desc").orderBy("id", "desc").limit(limit).offset(offset).execute();
2671
+ const count = await filtered.select((eb) => eb.fn.count("id").as("count")).executeTakeFirst();
2672
+ return {
2673
+ items: rows.map((row) => this.rowToItem(row)),
2674
+ totalCount: Number(count?.count ?? 0)
2675
+ };
2676
+ }
2677
+ /**
2678
+ * Update media metadata
2679
+ */
2680
+ async update(id, input) {
2681
+ if (!await this.findById(id)) return null;
2682
+ const updates = {};
2683
+ if (input.alt !== void 0) updates.alt = input.alt;
2684
+ if (input.caption !== void 0) updates.caption = input.caption;
2685
+ if (input.width !== void 0) updates.width = input.width;
2686
+ if (input.height !== void 0) updates.height = input.height;
2687
+ if (input.folderId !== void 0) updates.folder_id = input.folderId;
2688
+ if (input.focalX !== void 0 && input.focalY !== void 0) {
2689
+ updates.focal_x = input.focalX;
2690
+ updates.focal_y = input.focalY;
2691
+ }
2692
+ if (Object.keys(updates).length > 0) await this.db.updateTable("media").set(updates).where("id", "=", id).execute();
2693
+ return this.findById(id);
2694
+ }
2695
+ async updateReadyMetadata(id, input) {
2696
+ const updates = {};
2697
+ if (input.alt !== void 0) updates.alt = input.alt;
2698
+ if (input.caption !== void 0) updates.caption = input.caption;
2699
+ if (input.focalX !== void 0 && input.focalY !== void 0) {
2700
+ updates.focal_x = input.focalX;
2701
+ updates.focal_y = input.focalY;
2702
+ }
2703
+ if (Object.keys(updates).length === 0) throw new TypeError("Media metadata update requires at least one field");
2704
+ const row = await this.db.updateTable("media").set(updates).where("id", "=", id).where("status", "=", "ready").returningAll().executeTakeFirst();
2705
+ return row ? this.rowToItem(row) : null;
2706
+ }
2707
+ async replaceReadyFile(id, expectedStorageKey, input) {
2708
+ const row = await this.db.updateTable("media").set({
2709
+ size: input.size,
2710
+ width: input.width,
2711
+ height: input.height,
2712
+ content_hash: input.contentHash,
2713
+ blurhash: null,
2714
+ dominant_color: null,
2715
+ focal_x: null,
2716
+ focal_y: null
2717
+ }).where("id", "=", id).where("status", "=", "ready").where("storage_key", "=", expectedStorageKey).returningAll().executeTakeFirst();
2718
+ return row ? this.rowToItem(row) : null;
2719
+ }
2720
+ /**
2721
+ * Delete media item
2722
+ */
2723
+ async deleteWithStorageKey(id) {
2724
+ const deleted = await this.db.deleteFrom("media").where("id", "=", id).returning("storage_key").executeTakeFirst();
2725
+ if (deleted) return deleted.storage_key;
2726
+ return null;
2727
+ }
2728
+ async isStorageKeyReferenced(storageKey) {
2729
+ return await this.db.selectFrom("media").select("id").where("storage_key", "=", storageKey).executeTakeFirst() !== void 0;
2730
+ }
2731
+ async delete(id) {
2732
+ return await this.deleteWithStorageKey(id) !== null;
2733
+ }
2734
+ /**
2735
+ * Count media items
2736
+ */
2737
+ async count(mimeType) {
2738
+ const filters = normalizeMimeFilter(mimeType);
2739
+ let query = this.db.selectFrom("media").select((eb) => eb.fn.count("id").as("count"));
2740
+ if (filters.length > 0) query = query.where((eb) => mimeMatchExpr(eb, filters));
2741
+ const result = await query.executeTakeFirst();
2742
+ return Number(result?.count || 0);
2743
+ }
2744
+ applyListFilters(query, options) {
2745
+ const mimeFilters = normalizeMimeFilter(options.mimeType);
2746
+ if (mimeFilters.length > 0) query = query.where((eb) => mimeMatchExpr(eb, mimeFilters));
2747
+ const term = options.q?.trim();
2748
+ if (term) {
2749
+ const pattern = `%${escapeLike(term)}%`;
2750
+ query = query.where(sql`lower(filename)`, "like", sql`lower(${pattern}) escape '\\'`);
2751
+ }
2752
+ if (options.status !== "all") query = query.where("status", "=", options.status ?? "ready");
2753
+ if (options.folderId === null) query = query.where("folder_id", "is", null);
2754
+ else if (options.folderId !== void 0) query = query.where("folder_id", "=", options.folderId);
2755
+ return query;
2756
+ }
2757
+ /**
2758
+ * Delete pending uploads older than the given age.
2759
+ * Pending uploads that were never confirmed indicate abandoned upload flows.
2760
+ *
2761
+ * Returns the storage keys of deleted rows so callers can remove the
2762
+ * corresponding files from object storage.
2763
+ */
2764
+ async cleanupPendingUploads(maxAgeMs = 3600 * 1e3) {
2765
+ const cutoff = new Date(Date.now() - maxAgeMs).toISOString();
2766
+ const keys = (await this.db.deleteFrom("media").where("status", "=", "pending").where("created_at", "<", cutoff).returning("storage_key").execute()).map((r) => r.storage_key);
2767
+ if (keys.length === 0) return keys;
2768
+ const stillReferenced = /* @__PURE__ */ new Set();
2769
+ for (const batch of chunks(keys, SQL_BATCH_SIZE)) {
2770
+ const refs = await this.db.selectFrom("media").select("storage_key").where("storage_key", "in", batch).execute();
2771
+ for (const ref of refs) stillReferenced.add(ref.storage_key);
2772
+ }
2773
+ return keys.filter((key) => !stillReferenced.has(key));
2774
+ }
2775
+ /**
2776
+ * Convert database row to MediaItem
2777
+ */
2778
+ rowToItem(row) {
2779
+ const focalPoint = normalizeFocalPoint(row.focal_x, row.focal_y);
2780
+ return {
2781
+ id: row.id,
2782
+ filename: row.filename,
2783
+ mimeType: row.mime_type,
2784
+ size: row.size,
2785
+ width: row.width,
2786
+ height: row.height,
2787
+ focalX: focalPoint?.focalX ?? null,
2788
+ focalY: focalPoint?.focalY ?? null,
2789
+ alt: row.alt,
2790
+ caption: row.caption,
2791
+ storageKey: row.storage_key,
2792
+ contentHash: row.content_hash,
2793
+ blurhash: row.blurhash,
2794
+ dominantColor: row.dominant_color,
2795
+ status: row.status,
2796
+ createdAt: row.created_at,
2797
+ authorId: row.author_id,
2798
+ folderId: row.folder_id
2799
+ };
2800
+ }
2801
+ };
2802
+
2803
+ //#endregion
2804
+ export { buildMediaUsageProjectionFingerprint as a, buildCanonicalSha256Fingerprint as i, MediaUsageRepository as n, CONTENT_SOURCE_SCHEMA_VERSION as r, MediaRepository as t };
2805
+ //# sourceMappingURL=media-DJaAAYI2.mjs.map