emdash 0.37.0 → 0.39.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 (1445) hide show
  1. package/dist/action-token-On1sot_c.mjs +26 -0
  2. package/dist/action-token-On1sot_c.mjs.map +1 -0
  3. package/dist/activation-CaMfdBt1.mjs +382 -0
  4. package/dist/activation-CaMfdBt1.mjs.map +1 -0
  5. package/dist/adapters-Cq10K4_c.d.mts +171 -0
  6. package/dist/adapters-Cq10K4_c.d.mts.map +1 -0
  7. package/dist/after-PcEvMY_6.mjs +96 -0
  8. package/dist/after-PcEvMY_6.mjs.map +1 -0
  9. package/dist/allowed-origins-1Sa-2wZK.mjs +116 -0
  10. package/dist/allowed-origins-1Sa-2wZK.mjs.map +1 -0
  11. package/dist/api/route-utils.d.mts +4 -3
  12. package/dist/api/route-utils.d.mts.map +1 -1
  13. package/dist/api/route-utils.mjs +45 -29
  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 -6
  17. package/dist/api-DmjKxPCY.mjs +4831 -0
  18. package/dist/api-DmjKxPCY.mjs.map +1 -0
  19. package/dist/api-tokens-BIXItFKV.mjs +163 -0
  20. package/dist/api-tokens-BIXItFKV.mjs.map +1 -0
  21. package/dist/apply-drpfmqrR.mjs +1005 -0
  22. package/dist/apply-drpfmqrR.mjs.map +1 -0
  23. package/dist/artifact-fetch-COiMhVgk.mjs +813 -0
  24. package/dist/artifact-fetch-COiMhVgk.mjs.map +1 -0
  25. package/dist/astro/index.d.mts +14 -12
  26. package/dist/astro/index.d.mts.map +1 -1
  27. package/dist/astro/index.mjs +123 -13
  28. package/dist/astro/index.mjs.map +1 -1
  29. package/dist/astro/middleware/auth.d.mts +12 -10
  30. package/dist/astro/middleware/auth.d.mts.map +1 -1
  31. package/dist/astro/middleware/auth.mjs +20 -11
  32. package/dist/astro/middleware/auth.mjs.map +1 -1
  33. package/dist/astro/middleware/media-usage-write-fence.mjs +5 -5
  34. package/dist/astro/middleware/redirect.mjs +11 -9
  35. package/dist/astro/middleware/redirect.mjs.map +1 -1
  36. package/dist/astro/middleware/request-context.d.mts +1 -1
  37. package/dist/astro/middleware/request-context.d.mts.map +1 -1
  38. package/dist/astro/middleware/request-context.mjs +154 -28
  39. package/dist/astro/middleware/request-context.mjs.map +1 -1
  40. package/dist/astro/middleware/setup.mjs +1 -1
  41. package/dist/astro/middleware.d.mts +13 -10
  42. package/dist/astro/middleware.d.mts.map +1 -1
  43. package/dist/astro/middleware.mjs +122 -3041
  44. package/dist/astro/middleware.mjs.map +1 -1
  45. package/dist/astro/routes/api/admin/allowed-domains/_domain_.mjs +10 -9
  46. package/dist/astro/routes/api/admin/allowed-domains/_domain_.mjs.map +1 -1
  47. package/dist/astro/routes/api/admin/allowed-domains/index.mjs +10 -9
  48. package/dist/astro/routes/api/admin/allowed-domains/index.mjs.map +1 -1
  49. package/dist/astro/routes/api/admin/api-tokens/_id_.mjs +5 -5
  50. package/dist/astro/routes/api/admin/api-tokens/index.mjs +6 -6
  51. package/dist/astro/routes/api/admin/byline-fields/_slug_/usage.mjs +6 -6
  52. package/dist/astro/routes/api/admin/byline-fields/_slug_.mjs +13 -12
  53. package/dist/astro/routes/api/admin/byline-fields/_slug_.mjs.map +1 -1
  54. package/dist/astro/routes/api/admin/byline-fields/index.mjs +13 -12
  55. package/dist/astro/routes/api/admin/byline-fields/index.mjs.map +1 -1
  56. package/dist/astro/routes/api/admin/byline-fields/reorder.mjs +13 -12
  57. package/dist/astro/routes/api/admin/byline-fields/reorder.mjs.map +1 -1
  58. package/dist/astro/routes/api/admin/bylines/_id_/index.mjs +22 -21
  59. package/dist/astro/routes/api/admin/bylines/_id_/index.mjs.map +1 -1
  60. package/dist/astro/routes/api/admin/bylines/_id_/translations.mjs +22 -21
  61. package/dist/astro/routes/api/admin/bylines/_id_/translations.mjs.map +1 -1
  62. package/dist/astro/routes/api/admin/bylines/index.mjs +22 -21
  63. package/dist/astro/routes/api/admin/bylines/index.mjs.map +1 -1
  64. package/dist/astro/routes/api/admin/comments/_id_/status.d.mts.map +1 -1
  65. package/dist/astro/routes/api/admin/comments/_id_/status.mjs +21 -54
  66. package/dist/astro/routes/api/admin/comments/_id_/status.mjs.map +1 -1
  67. package/dist/astro/routes/api/admin/comments/_id_.mjs +8 -8
  68. package/dist/astro/routes/api/admin/comments/bulk.mjs +15 -14
  69. package/dist/astro/routes/api/admin/comments/bulk.mjs.map +1 -1
  70. package/dist/astro/routes/api/admin/comments/counts.mjs +8 -8
  71. package/dist/astro/routes/api/admin/comments/index.mjs +15 -14
  72. package/dist/astro/routes/api/admin/comments/index.mjs.map +1 -1
  73. package/dist/astro/routes/api/admin/hooks/exclusive/_hookName_.mjs +6 -6
  74. package/dist/astro/routes/api/admin/hooks/exclusive/index.mjs +5 -5
  75. package/dist/astro/routes/api/admin/media-usage/activation.mjs +17 -16
  76. package/dist/astro/routes/api/admin/media-usage/activation.mjs.map +1 -1
  77. package/dist/astro/routes/api/admin/media-usage/collection-deletions/index.mjs +19 -18
  78. package/dist/astro/routes/api/admin/media-usage/collection-deletions/index.mjs.map +1 -1
  79. package/dist/astro/routes/api/admin/media-usage/collection-deletions/retry.mjs +19 -18
  80. package/dist/astro/routes/api/admin/media-usage/collection-deletions/retry.mjs.map +1 -1
  81. package/dist/astro/routes/api/admin/media-usage/progress.mjs +17 -17
  82. package/dist/astro/routes/api/admin/media-usage/repair.mjs +21 -20
  83. package/dist/astro/routes/api/admin/media-usage/repair.mjs.map +1 -1
  84. package/dist/astro/routes/api/admin/media-usage/work/index.mjs +19 -18
  85. package/dist/astro/routes/api/admin/media-usage/work/index.mjs.map +1 -1
  86. package/dist/astro/routes/api/admin/media-usage/work/retry.mjs +19 -18
  87. package/dist/astro/routes/api/admin/media-usage/work/retry.mjs.map +1 -1
  88. package/dist/astro/routes/api/admin/oauth-clients/_id_.mjs +5 -5
  89. package/dist/astro/routes/api/admin/oauth-clients/index.mjs +5 -5
  90. package/dist/astro/routes/api/admin/plugins/_id_/disable.d.mts.map +1 -1
  91. package/dist/astro/routes/api/admin/plugins/_id_/disable.mjs +9 -66
  92. package/dist/astro/routes/api/admin/plugins/_id_/disable.mjs.map +1 -1
  93. package/dist/astro/routes/api/admin/plugins/_id_/enable.d.mts.map +1 -1
  94. package/dist/astro/routes/api/admin/plugins/_id_/enable.mjs +9 -69
  95. package/dist/astro/routes/api/admin/plugins/_id_/enable.mjs.map +1 -1
  96. package/dist/astro/routes/api/admin/plugins/_id_/index.mjs +66 -59
  97. package/dist/astro/routes/api/admin/plugins/_id_/index.mjs.map +1 -1
  98. package/dist/astro/routes/api/admin/plugins/_id_/mcp.mjs +6 -6
  99. package/dist/astro/routes/api/admin/plugins/_id_/settings.mjs +65 -59
  100. package/dist/astro/routes/api/admin/plugins/_id_/settings.mjs.map +1 -1
  101. package/dist/astro/routes/api/admin/plugins/_id_/uninstall.mjs +70 -61
  102. package/dist/astro/routes/api/admin/plugins/_id_/uninstall.mjs.map +1 -1
  103. package/dist/astro/routes/api/admin/plugins/_id_/update.d.mts.map +1 -1
  104. package/dist/astro/routes/api/admin/plugins/_id_/update.mjs +87 -63
  105. package/dist/astro/routes/api/admin/plugins/_id_/update.mjs.map +1 -1
  106. package/dist/astro/routes/api/admin/plugins/index.mjs +66 -59
  107. package/dist/astro/routes/api/admin/plugins/index.mjs.map +1 -1
  108. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/icon.mjs +4 -4
  109. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/index.mjs +65 -59
  110. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/index.mjs.map +1 -1
  111. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.d.mts.map +1 -1
  112. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.mjs +85 -63
  113. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.mjs.map +1 -1
  114. package/dist/astro/routes/api/admin/plugins/marketplace/index.mjs +65 -59
  115. package/dist/astro/routes/api/admin/plugins/marketplace/index.mjs.map +1 -1
  116. package/dist/astro/routes/api/admin/plugins/registry/_id_/uninstall.mjs +70 -61
  117. package/dist/astro/routes/api/admin/plugins/registry/_id_/uninstall.mjs.map +1 -1
  118. package/dist/astro/routes/api/admin/plugins/registry/_id_/update.d.mts.map +1 -1
  119. package/dist/astro/routes/api/admin/plugins/registry/_id_/update.mjs +90 -66
  120. package/dist/astro/routes/api/admin/plugins/registry/_id_/update.mjs.map +1 -1
  121. package/dist/astro/routes/api/admin/plugins/registry/artifact.d.mts.map +1 -1
  122. package/dist/astro/routes/api/admin/plugins/registry/artifact.mjs +9 -7
  123. package/dist/astro/routes/api/admin/plugins/registry/artifact.mjs.map +1 -1
  124. package/dist/astro/routes/api/admin/plugins/registry/install.d.mts.map +1 -1
  125. package/dist/astro/routes/api/admin/plugins/registry/install.mjs +77 -63
  126. package/dist/astro/routes/api/admin/plugins/registry/install.mjs.map +1 -1
  127. package/dist/astro/routes/api/admin/plugins/registry/verify.d.mts.map +1 -1
  128. package/dist/astro/routes/api/admin/plugins/registry/verify.mjs +67 -61
  129. package/dist/astro/routes/api/admin/plugins/registry/verify.mjs.map +1 -1
  130. package/dist/astro/routes/api/admin/plugins/updates.d.mts.map +1 -1
  131. package/dist/astro/routes/api/admin/plugins/updates.mjs +66 -60
  132. package/dist/astro/routes/api/admin/plugins/updates.mjs.map +1 -1
  133. package/dist/astro/routes/api/admin/scheduled-policy-rejections/_collection_/_id_.d.mts +8 -0
  134. package/dist/astro/routes/api/admin/scheduled-policy-rejections/_collection_/_id_.d.mts.map +1 -0
  135. package/dist/astro/routes/api/admin/scheduled-policy-rejections/_collection_/_id_.mjs +27 -0
  136. package/dist/astro/routes/api/admin/scheduled-policy-rejections/_collection_/_id_.mjs.map +1 -0
  137. package/dist/astro/routes/api/admin/themes/marketplace/_id_/index.mjs +65 -59
  138. package/dist/astro/routes/api/admin/themes/marketplace/_id_/index.mjs.map +1 -1
  139. package/dist/astro/routes/api/admin/themes/marketplace/_id_/thumbnail.mjs +4 -4
  140. package/dist/astro/routes/api/admin/themes/marketplace/index.mjs +65 -59
  141. package/dist/astro/routes/api/admin/themes/marketplace/index.mjs.map +1 -1
  142. package/dist/astro/routes/api/admin/users/_id_/disable.mjs +4 -4
  143. package/dist/astro/routes/api/admin/users/_id_/enable.mjs +3 -3
  144. package/dist/astro/routes/api/admin/users/_id_/index.mjs +11 -10
  145. package/dist/astro/routes/api/admin/users/_id_/index.mjs.map +1 -1
  146. package/dist/astro/routes/api/admin/users/_id_/send-recovery.mjs +5 -5
  147. package/dist/astro/routes/api/admin/users/index.mjs +10 -9
  148. package/dist/astro/routes/api/admin/users/index.mjs.map +1 -1
  149. package/dist/astro/routes/api/auth/dev-bypass.mjs +5 -5
  150. package/dist/astro/routes/api/auth/invite/accept.mjs +3 -3
  151. package/dist/astro/routes/api/auth/invite/complete.mjs +15 -14
  152. package/dist/astro/routes/api/auth/invite/complete.mjs.map +1 -1
  153. package/dist/astro/routes/api/auth/invite/index.mjs +12 -11
  154. package/dist/astro/routes/api/auth/invite/index.mjs.map +1 -1
  155. package/dist/astro/routes/api/auth/invite/register-options.mjs +14 -13
  156. package/dist/astro/routes/api/auth/invite/register-options.mjs.map +1 -1
  157. package/dist/astro/routes/api/auth/logout.mjs +4 -4
  158. package/dist/astro/routes/api/auth/magic-link/send.mjs +14 -13
  159. package/dist/astro/routes/api/auth/magic-link/send.mjs.map +1 -1
  160. package/dist/astro/routes/api/auth/magic-link/verify.mjs +4 -4
  161. package/dist/astro/routes/api/auth/me.mjs +11 -10
  162. package/dist/astro/routes/api/auth/me.mjs.map +1 -1
  163. package/dist/astro/routes/api/auth/mode.mjs +4 -4
  164. package/dist/astro/routes/api/auth/oauth/_provider_/callback.mjs +4 -4
  165. package/dist/astro/routes/api/auth/oauth/_provider_.mjs +2 -2
  166. package/dist/astro/routes/api/auth/passkey/_id_.mjs +10 -9
  167. package/dist/astro/routes/api/auth/passkey/_id_.mjs.map +1 -1
  168. package/dist/astro/routes/api/auth/passkey/index.mjs +3 -3
  169. package/dist/astro/routes/api/auth/passkey/options.mjs +16 -15
  170. package/dist/astro/routes/api/auth/passkey/options.mjs.map +1 -1
  171. package/dist/astro/routes/api/auth/passkey/register/options.mjs +14 -13
  172. package/dist/astro/routes/api/auth/passkey/register/options.mjs.map +1 -1
  173. package/dist/astro/routes/api/auth/passkey/register/verify.mjs +15 -14
  174. package/dist/astro/routes/api/auth/passkey/register/verify.mjs.map +1 -1
  175. package/dist/astro/routes/api/auth/passkey/verify.mjs +15 -14
  176. package/dist/astro/routes/api/auth/passkey/verify.mjs.map +1 -1
  177. package/dist/astro/routes/api/auth/signup/complete.mjs +15 -14
  178. package/dist/astro/routes/api/auth/signup/complete.mjs.map +1 -1
  179. package/dist/astro/routes/api/auth/signup/request.mjs +14 -13
  180. package/dist/astro/routes/api/auth/signup/request.mjs.map +1 -1
  181. package/dist/astro/routes/api/auth/signup/verify.mjs +3 -3
  182. package/dist/astro/routes/api/comments/_collection_/_contentId_/index.d.mts.map +1 -1
  183. package/dist/astro/routes/api/comments/_collection_/_contentId_/index.mjs +15 -211
  184. package/dist/astro/routes/api/comments/_collection_/_contentId_/index.mjs.map +1 -1
  185. package/dist/astro/routes/api/comments/_collection_/_contentId_/reactions.mjs +18 -17
  186. package/dist/astro/routes/api/comments/_collection_/_contentId_/reactions.mjs.map +1 -1
  187. package/dist/astro/routes/api/content/_collection_/_id_/compare.mjs +4 -4
  188. package/dist/astro/routes/api/content/_collection_/_id_/discard-draft.d.mts.map +1 -1
  189. package/dist/astro/routes/api/content/_collection_/_id_/discard-draft.mjs +17 -11
  190. package/dist/astro/routes/api/content/_collection_/_id_/discard-draft.mjs.map +1 -1
  191. package/dist/astro/routes/api/content/_collection_/_id_/duplicate.mjs +5 -5
  192. package/dist/astro/routes/api/content/_collection_/_id_/lock.d.mts +10 -0
  193. package/dist/astro/routes/api/content/_collection_/_id_/lock.d.mts.map +1 -0
  194. package/dist/astro/routes/api/content/_collection_/_id_/lock.mjs +67 -0
  195. package/dist/astro/routes/api/content/_collection_/_id_/lock.mjs.map +1 -0
  196. package/dist/astro/routes/api/content/_collection_/_id_/permanent.mjs +4 -4
  197. package/dist/astro/routes/api/content/_collection_/_id_/plugin-extensions/_pluginId_/_kind_/_extensionId_.d.mts +8 -0
  198. package/dist/astro/routes/api/content/_collection_/_id_/plugin-extensions/_pluginId_/_kind_/_extensionId_.d.mts.map +1 -0
  199. package/dist/astro/routes/api/content/_collection_/_id_/plugin-extensions/_pluginId_/_kind_/_extensionId_.mjs +35 -0
  200. package/dist/astro/routes/api/content/_collection_/_id_/plugin-extensions/_pluginId_/_kind_/_extensionId_.mjs.map +1 -0
  201. package/dist/astro/routes/api/content/_collection_/_id_/preview-url.mjs +16 -15
  202. package/dist/astro/routes/api/content/_collection_/_id_/preview-url.mjs.map +1 -1
  203. package/dist/astro/routes/api/content/_collection_/_id_/publish.d.mts +9 -2
  204. package/dist/astro/routes/api/content/_collection_/_id_/publish.d.mts.map +1 -1
  205. package/dist/astro/routes/api/content/_collection_/_id_/publish.mjs +28 -16
  206. package/dist/astro/routes/api/content/_collection_/_id_/publish.mjs.map +1 -1
  207. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/children.mjs +27 -23
  208. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/children.mjs.map +1 -1
  209. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/parents.mjs +27 -23
  210. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/parents.mjs.map +1 -1
  211. package/dist/astro/routes/api/content/_collection_/_id_/restore.mjs +5 -5
  212. package/dist/astro/routes/api/content/_collection_/_id_/revisions.mjs +4 -4
  213. package/dist/astro/routes/api/content/_collection_/_id_/schedule.d.mts.map +1 -1
  214. package/dist/astro/routes/api/content/_collection_/_id_/schedule.mjs +27 -12
  215. package/dist/astro/routes/api/content/_collection_/_id_/schedule.mjs.map +1 -1
  216. package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.mjs +23 -20
  217. package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.mjs.map +1 -1
  218. package/dist/astro/routes/api/content/_collection_/_id_/translations.mjs +4 -4
  219. package/dist/astro/routes/api/content/_collection_/_id_/unpublish.d.mts.map +1 -1
  220. package/dist/astro/routes/api/content/_collection_/_id_/unpublish.mjs +25 -12
  221. package/dist/astro/routes/api/content/_collection_/_id_/unpublish.mjs.map +1 -1
  222. package/dist/astro/routes/api/content/_collection_/_id_.d.mts.map +1 -1
  223. package/dist/astro/routes/api/content/_collection_/_id_.mjs +27 -14
  224. package/dist/astro/routes/api/content/_collection_/_id_.mjs.map +1 -1
  225. package/dist/astro/routes/api/content/_collection_/authors.mjs +4 -4
  226. package/dist/astro/routes/api/content/_collection_/index.mjs +18 -12
  227. package/dist/astro/routes/api/content/_collection_/index.mjs.map +1 -1
  228. package/dist/astro/routes/api/content/_collection_/trash.mjs +11 -10
  229. package/dist/astro/routes/api/content/_collection_/trash.mjs.map +1 -1
  230. package/dist/astro/routes/api/dashboard.mjs +14 -12
  231. package/dist/astro/routes/api/dashboard.mjs.map +1 -1
  232. package/dist/astro/routes/api/dev/emails.mjs +4 -4
  233. package/dist/astro/routes/api/health.d.mts +8 -0
  234. package/dist/astro/routes/api/health.d.mts.map +1 -0
  235. package/dist/astro/routes/api/health.mjs +21 -0
  236. package/dist/astro/routes/api/health.mjs.map +1 -0
  237. package/dist/astro/routes/api/import/probe.d.mts +3 -3
  238. package/dist/astro/routes/api/import/probe.mjs +25 -23
  239. package/dist/astro/routes/api/import/probe.mjs.map +1 -1
  240. package/dist/astro/routes/api/import/wordpress/analyze.mjs +5 -5
  241. package/dist/astro/routes/api/import/wordpress/execute.d.mts +13 -11
  242. package/dist/astro/routes/api/import/wordpress/execute.d.mts.map +1 -1
  243. package/dist/astro/routes/api/import/wordpress/execute.mjs +20 -19
  244. package/dist/astro/routes/api/import/wordpress/execute.mjs.map +1 -1
  245. package/dist/astro/routes/api/import/wordpress/media.d.mts +12 -10
  246. package/dist/astro/routes/api/import/wordpress/media.d.mts.map +1 -1
  247. package/dist/astro/routes/api/import/wordpress/media.mjs +15 -14
  248. package/dist/astro/routes/api/import/wordpress/media.mjs.map +1 -1
  249. package/dist/astro/routes/api/import/wordpress/prepare.mjs +14 -13
  250. package/dist/astro/routes/api/import/wordpress/prepare.mjs.map +1 -1
  251. package/dist/astro/routes/api/import/wordpress/rewrite-urls.d.mts +13 -11
  252. package/dist/astro/routes/api/import/wordpress/rewrite-urls.d.mts.map +1 -1
  253. package/dist/astro/routes/api/import/wordpress/rewrite-urls.mjs +18 -17
  254. package/dist/astro/routes/api/import/wordpress/rewrite-urls.mjs.map +1 -1
  255. package/dist/astro/routes/api/import/wordpress-plugin/analyze.d.mts +1 -1
  256. package/dist/astro/routes/api/import/wordpress-plugin/analyze.mjs +25 -23
  257. package/dist/astro/routes/api/import/wordpress-plugin/analyze.mjs.map +1 -1
  258. package/dist/astro/routes/api/import/wordpress-plugin/callback.mjs +1 -1
  259. package/dist/astro/routes/api/import/wordpress-plugin/execute.d.mts +13 -11
  260. package/dist/astro/routes/api/import/wordpress-plugin/execute.d.mts.map +1 -1
  261. package/dist/astro/routes/api/import/wordpress-plugin/execute.mjs +36 -33
  262. package/dist/astro/routes/api/import/wordpress-plugin/execute.mjs.map +1 -1
  263. package/dist/astro/routes/api/manifest.mjs +17 -9
  264. package/dist/astro/routes/api/manifest.mjs.map +1 -1
  265. package/dist/astro/routes/api/mcp.d.mts.map +1 -1
  266. package/dist/astro/routes/api/mcp.mjs +192 -110
  267. package/dist/astro/routes/api/mcp.mjs.map +1 -1
  268. package/dist/astro/routes/api/media/_id_/confirm.mjs +15 -14
  269. package/dist/astro/routes/api/media/_id_/confirm.mjs.map +1 -1
  270. package/dist/astro/routes/api/media/_id_/replace.mjs +12 -11
  271. package/dist/astro/routes/api/media/_id_/replace.mjs.map +1 -1
  272. package/dist/astro/routes/api/media/_id_/upload.mjs +8 -8
  273. package/dist/astro/routes/api/media/_id_/usage.mjs +23 -22
  274. package/dist/astro/routes/api/media/_id_/usage.mjs.map +1 -1
  275. package/dist/astro/routes/api/media/_id_.mjs +22 -21
  276. package/dist/astro/routes/api/media/_id_.mjs.map +1 -1
  277. package/dist/astro/routes/api/media/asset/_id_/_filename_.d.mts +8 -0
  278. package/dist/astro/routes/api/media/asset/_id_/_filename_.d.mts.map +1 -0
  279. package/dist/astro/routes/api/media/asset/_id_/_filename_.mjs +52 -0
  280. package/dist/astro/routes/api/media/asset/_id_/_filename_.mjs.map +1 -0
  281. package/dist/astro/routes/api/media/file/_...key_.mjs +3 -3
  282. package/dist/astro/routes/api/media/folders/_id_.mjs +12 -11
  283. package/dist/astro/routes/api/media/folders/_id_.mjs.map +1 -1
  284. package/dist/astro/routes/api/media/folders/index.mjs +12 -11
  285. package/dist/astro/routes/api/media/folders/index.mjs.map +1 -1
  286. package/dist/astro/routes/api/media/providers/_providerId_/_itemId_.mjs +4 -4
  287. package/dist/astro/routes/api/media/providers/_providerId_/index.mjs +4 -4
  288. package/dist/astro/routes/api/media/providers/index.mjs +4 -4
  289. package/dist/astro/routes/api/media/upload-url.mjs +14 -13
  290. package/dist/astro/routes/api/media/upload-url.mjs.map +1 -1
  291. package/dist/astro/routes/api/media.mjs +26 -25
  292. package/dist/astro/routes/api/media.mjs.map +1 -1
  293. package/dist/astro/routes/api/menus/_name_/items/_id_.mjs +15 -14
  294. package/dist/astro/routes/api/menus/_name_/items/_id_.mjs.map +1 -1
  295. package/dist/astro/routes/api/menus/_name_/items.mjs +15 -14
  296. package/dist/astro/routes/api/menus/_name_/items.mjs.map +1 -1
  297. package/dist/astro/routes/api/menus/_name_/reorder.mjs +15 -14
  298. package/dist/astro/routes/api/menus/_name_/reorder.mjs.map +1 -1
  299. package/dist/astro/routes/api/menus/_name_/translations.mjs +15 -14
  300. package/dist/astro/routes/api/menus/_name_/translations.mjs.map +1 -1
  301. package/dist/astro/routes/api/menus/_name_.mjs +15 -14
  302. package/dist/astro/routes/api/menus/_name_.mjs.map +1 -1
  303. package/dist/astro/routes/api/menus/index.mjs +15 -14
  304. package/dist/astro/routes/api/menus/index.mjs.map +1 -1
  305. package/dist/astro/routes/api/oauth/authorize.mjs +6 -6
  306. package/dist/astro/routes/api/oauth/device/authorize.mjs +7 -7
  307. package/dist/astro/routes/api/oauth/device/code.mjs +10 -10
  308. package/dist/astro/routes/api/oauth/device/token.mjs +9 -9
  309. package/dist/astro/routes/api/oauth/register.mjs +4 -4
  310. package/dist/astro/routes/api/oauth/token/refresh.mjs +7 -7
  311. package/dist/astro/routes/api/oauth/token/revoke.mjs +7 -7
  312. package/dist/astro/routes/api/oauth/token.mjs +7 -7
  313. package/dist/astro/routes/api/openapi.json.mjs +95 -24
  314. package/dist/astro/routes/api/openapi.json.mjs.map +1 -1
  315. package/dist/astro/routes/api/plugins/_pluginId_/_...path_.d.mts +2 -1
  316. package/dist/astro/routes/api/plugins/_pluginId_/_...path_.d.mts.map +1 -1
  317. package/dist/astro/routes/api/plugins/_pluginId_/_...path_.mjs +22 -40
  318. package/dist/astro/routes/api/plugins/_pluginId_/_...path_.mjs.map +1 -1
  319. package/dist/astro/routes/api/redirects/404s/index.mjs +18 -14
  320. package/dist/astro/routes/api/redirects/404s/index.mjs.map +1 -1
  321. package/dist/astro/routes/api/redirects/404s/summary.mjs +18 -14
  322. package/dist/astro/routes/api/redirects/404s/summary.mjs.map +1 -1
  323. package/dist/astro/routes/api/redirects/_id_.d.mts.map +1 -1
  324. package/dist/astro/routes/api/redirects/_id_.mjs +20 -22
  325. package/dist/astro/routes/api/redirects/_id_.mjs.map +1 -1
  326. package/dist/astro/routes/api/redirects/index.d.mts.map +1 -1
  327. package/dist/astro/routes/api/redirects/index.mjs +19 -19
  328. package/dist/astro/routes/api/redirects/index.mjs.map +1 -1
  329. package/dist/astro/routes/api/relations/_id_/index.mjs +27 -23
  330. package/dist/astro/routes/api/relations/_id_/index.mjs.map +1 -1
  331. package/dist/astro/routes/api/relations/_id_/translations.mjs +21 -18
  332. package/dist/astro/routes/api/relations/_id_/translations.mjs.map +1 -1
  333. package/dist/astro/routes/api/relations/index.mjs +27 -23
  334. package/dist/astro/routes/api/relations/index.mjs.map +1 -1
  335. package/dist/astro/routes/api/revisions/_revisionId_/index.mjs +4 -4
  336. package/dist/astro/routes/api/revisions/_revisionId_/restore.mjs +5 -5
  337. package/dist/astro/routes/api/schema/collections/_slug_/fields/_fieldSlug_.mjs +65 -59
  338. package/dist/astro/routes/api/schema/collections/_slug_/fields/_fieldSlug_.mjs.map +1 -1
  339. package/dist/astro/routes/api/schema/collections/_slug_/fields/index.mjs +65 -59
  340. package/dist/astro/routes/api/schema/collections/_slug_/fields/index.mjs.map +1 -1
  341. package/dist/astro/routes/api/schema/collections/_slug_/fields/reorder.mjs +65 -59
  342. package/dist/astro/routes/api/schema/collections/_slug_/fields/reorder.mjs.map +1 -1
  343. package/dist/astro/routes/api/schema/collections/_slug_/index.mjs +65 -59
  344. package/dist/astro/routes/api/schema/collections/_slug_/index.mjs.map +1 -1
  345. package/dist/astro/routes/api/schema/collections/index.mjs +65 -59
  346. package/dist/astro/routes/api/schema/collections/index.mjs.map +1 -1
  347. package/dist/astro/routes/api/schema/collections/reorder.mjs +65 -59
  348. package/dist/astro/routes/api/schema/collections/reorder.mjs.map +1 -1
  349. package/dist/astro/routes/api/schema/index.mjs +16 -14
  350. package/dist/astro/routes/api/schema/index.mjs.map +1 -1
  351. package/dist/astro/routes/api/schema/orphans/_slug_.mjs +65 -59
  352. package/dist/astro/routes/api/schema/orphans/_slug_.mjs.map +1 -1
  353. package/dist/astro/routes/api/schema/orphans/index.mjs +65 -59
  354. package/dist/astro/routes/api/schema/orphans/index.mjs.map +1 -1
  355. package/dist/astro/routes/api/search/enable.mjs +16 -14
  356. package/dist/astro/routes/api/search/enable.mjs.map +1 -1
  357. package/dist/astro/routes/api/search/index.mjs +17 -14
  358. package/dist/astro/routes/api/search/index.mjs.map +1 -1
  359. package/dist/astro/routes/api/search/rebuild.mjs +16 -14
  360. package/dist/astro/routes/api/search/rebuild.mjs.map +1 -1
  361. package/dist/astro/routes/api/search/stats.mjs +10 -9
  362. package/dist/astro/routes/api/search/stats.mjs.map +1 -1
  363. package/dist/astro/routes/api/search/suggest.mjs +15 -13
  364. package/dist/astro/routes/api/search/suggest.mjs.map +1 -1
  365. package/dist/astro/routes/api/sections/_slug_.mjs +15 -13
  366. package/dist/astro/routes/api/sections/_slug_.mjs.map +1 -1
  367. package/dist/astro/routes/api/sections/index.mjs +15 -13
  368. package/dist/astro/routes/api/sections/index.mjs.map +1 -1
  369. package/dist/astro/routes/api/settings/backups/archives/_name_.mjs +9 -8
  370. package/dist/astro/routes/api/settings/backups/archives/_name_.mjs.map +1 -1
  371. package/dist/astro/routes/api/settings/backups/archives/index.mjs +8 -7
  372. package/dist/astro/routes/api/settings/backups/archives/index.mjs.map +1 -1
  373. package/dist/astro/routes/api/settings/backups/export.mjs +9 -8
  374. package/dist/astro/routes/api/settings/backups/export.mjs.map +1 -1
  375. package/dist/astro/routes/api/settings/backups/index.mjs +10 -9
  376. package/dist/astro/routes/api/settings/backups/index.mjs.map +1 -1
  377. package/dist/astro/routes/api/settings/email.mjs +6 -6
  378. package/dist/astro/routes/api/settings.mjs +22 -20
  379. package/dist/astro/routes/api/settings.mjs.map +1 -1
  380. package/dist/astro/routes/api/setup/admin-verify.mjs +16 -15
  381. package/dist/astro/routes/api/setup/admin-verify.mjs.map +1 -1
  382. package/dist/astro/routes/api/setup/admin.mjs +15 -14
  383. package/dist/astro/routes/api/setup/admin.mjs.map +1 -1
  384. package/dist/astro/routes/api/setup/dev-bypass.mjs +42 -38
  385. package/dist/astro/routes/api/setup/dev-bypass.mjs.map +1 -1
  386. package/dist/astro/routes/api/setup/dev-reset.mjs +4 -4
  387. package/dist/astro/routes/api/setup/index.mjs +43 -38
  388. package/dist/astro/routes/api/setup/index.mjs.map +1 -1
  389. package/dist/astro/routes/api/setup/status.mjs +5 -5
  390. package/dist/astro/routes/api/snapshot.mjs +11 -10
  391. package/dist/astro/routes/api/snapshot.mjs.map +1 -1
  392. package/dist/astro/routes/api/taxonomies/_name_/reorder.mjs +23 -21
  393. package/dist/astro/routes/api/taxonomies/_name_/reorder.mjs.map +1 -1
  394. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_/translations.mjs +23 -21
  395. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_/translations.mjs.map +1 -1
  396. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_.mjs +23 -21
  397. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_.mjs.map +1 -1
  398. package/dist/astro/routes/api/taxonomies/_name_/terms/index.mjs +23 -21
  399. package/dist/astro/routes/api/taxonomies/_name_/terms/index.mjs.map +1 -1
  400. package/dist/astro/routes/api/taxonomies/_name_/translations.mjs +22 -20
  401. package/dist/astro/routes/api/taxonomies/_name_/translations.mjs.map +1 -1
  402. package/dist/astro/routes/api/taxonomies/_name_.mjs +23 -21
  403. package/dist/astro/routes/api/taxonomies/_name_.mjs.map +1 -1
  404. package/dist/astro/routes/api/taxonomies/index.mjs +23 -21
  405. package/dist/astro/routes/api/taxonomies/index.mjs.map +1 -1
  406. package/dist/astro/routes/api/themes/preview.mjs +8 -8
  407. package/dist/astro/routes/api/typegen.mjs +6 -6
  408. package/dist/astro/routes/api/visual-editing/action-token.d.mts +8 -0
  409. package/dist/astro/routes/api/visual-editing/action-token.d.mts.map +1 -0
  410. package/dist/astro/routes/api/visual-editing/action-token.mjs +25 -0
  411. package/dist/astro/routes/api/visual-editing/action-token.mjs.map +1 -0
  412. package/dist/astro/routes/api/visual-editing/content/_collection_/_id_/publish.d.mts +8 -0
  413. package/dist/astro/routes/api/visual-editing/content/_collection_/_id_/publish.d.mts.map +1 -0
  414. package/dist/astro/routes/api/visual-editing/content/_collection_/_id_/publish.mjs +37 -0
  415. package/dist/astro/routes/api/visual-editing/content/_collection_/_id_/publish.mjs.map +1 -0
  416. package/dist/astro/routes/api/visual-editing/toolbar-labels.d.mts +8 -0
  417. package/dist/astro/routes/api/visual-editing/toolbar-labels.d.mts.map +1 -0
  418. package/dist/astro/routes/api/visual-editing/toolbar-labels.mjs +20 -0
  419. package/dist/astro/routes/api/visual-editing/toolbar-labels.mjs.map +1 -0
  420. package/dist/astro/routes/api/well-known/auth.mjs +2 -2
  421. package/dist/astro/routes/api/well-known/oauth-authorization-server.mjs +2 -2
  422. package/dist/astro/routes/api/well-known/oauth-protected-resource.mjs +2 -2
  423. package/dist/astro/routes/api/widget-areas/_name_/reorder.mjs +12 -11
  424. package/dist/astro/routes/api/widget-areas/_name_/reorder.mjs.map +1 -1
  425. package/dist/astro/routes/api/widget-areas/_name_/widgets/_id_.mjs +16 -15
  426. package/dist/astro/routes/api/widget-areas/_name_/widgets/_id_.mjs.map +1 -1
  427. package/dist/astro/routes/api/widget-areas/_name_/widgets.mjs +16 -15
  428. package/dist/astro/routes/api/widget-areas/_name_/widgets.mjs.map +1 -1
  429. package/dist/astro/routes/api/widget-areas/_name_.mjs +10 -10
  430. package/dist/astro/routes/api/widget-areas/index.mjs +16 -15
  431. package/dist/astro/routes/api/widget-areas/index.mjs.map +1 -1
  432. package/dist/astro/routes/api/widget-components.mjs +4 -4
  433. package/dist/astro/routes/robots.txt.mjs +13 -12
  434. package/dist/astro/routes/robots.txt.mjs.map +1 -1
  435. package/dist/astro/routes/sitemap-_collection_.xml.d.mts.map +1 -1
  436. package/dist/astro/routes/sitemap-_collection_.xml.mjs +24 -19
  437. package/dist/astro/routes/sitemap-_collection_.xml.mjs.map +1 -1
  438. package/dist/astro/routes/sitemap.xml.mjs +14 -13
  439. package/dist/astro/routes/sitemap.xml.mjs.map +1 -1
  440. package/dist/astro/types.d.mts +79 -26
  441. package/dist/astro/types.d.mts.map +1 -1
  442. package/dist/auth/providers/github.d.mts +1 -1
  443. package/dist/auth/providers/google.d.mts +1 -1
  444. package/dist/authoritative-records-DbqshfKD.mjs +5172 -0
  445. package/dist/authoritative-records-DbqshfKD.mjs.map +1 -0
  446. package/dist/authorize-BXpfMpp0.mjs +40 -0
  447. package/dist/authorize-BXpfMpp0.mjs.map +1 -0
  448. package/dist/backup-BsPQdwnS.mjs +246 -0
  449. package/dist/backup-BsPQdwnS.mjs.map +1 -0
  450. package/dist/base64-DvnNgP7e.mjs +63 -0
  451. package/dist/base64-DvnNgP7e.mjs.map +1 -0
  452. package/dist/byline-Doh-wt99.mjs +906 -0
  453. package/dist/byline-Doh-wt99.mjs.map +1 -0
  454. package/dist/byline-fields-CsrdvaLV.mjs +123 -0
  455. package/dist/byline-fields-CsrdvaLV.mjs.map +1 -0
  456. package/dist/byline-registry-D6lWzXk6.mjs +406 -0
  457. package/dist/byline-registry-D6lWzXk6.mjs.map +1 -0
  458. package/dist/bylines-Cop0hkoy.mjs +214 -0
  459. package/dist/bylines-Cop0hkoy.mjs.map +1 -0
  460. package/dist/bylines-kpBzHPr8.mjs +232 -0
  461. package/dist/bylines-kpBzHPr8.mjs.map +1 -0
  462. package/dist/cache-B0pOlXdM.mjs +108 -0
  463. package/dist/cache-B0pOlXdM.mjs.map +1 -0
  464. package/dist/capture-triggers-gxQxnxrJ.mjs +362 -0
  465. package/dist/capture-triggers-gxQxnxrJ.mjs.map +1 -0
  466. package/dist/challenge-store-CkRdSdd8.mjs +51 -0
  467. package/dist/challenge-store-CkRdSdd8.mjs.map +1 -0
  468. package/dist/checksum-Bsi2D9M1.mjs +162 -0
  469. package/dist/checksum-Bsi2D9M1.mjs.map +1 -0
  470. package/dist/chrome-tags-D7LGB91U.mjs +24 -0
  471. package/dist/chrome-tags-D7LGB91U.mjs.map +1 -0
  472. package/dist/chunks-BmWyou79.mjs +25 -0
  473. package/dist/chunks-BmWyou79.mjs.map +1 -0
  474. package/dist/cli/index.mjs +921 -106
  475. package/dist/cli/index.mjs.map +1 -1
  476. package/dist/client/cf-access.d.mts +1 -1
  477. package/dist/client/index.d.mts +17 -7
  478. package/dist/client/index.d.mts.map +1 -1
  479. package/dist/client/index.mjs +17 -12
  480. package/dist/client/index.mjs.map +1 -1
  481. package/dist/collection-deletion-C3Xixmkx.mjs +436 -0
  482. package/dist/collection-deletion-C3Xixmkx.mjs.map +1 -0
  483. package/dist/collection-slugs-cache-D9auiKmI.mjs +85 -0
  484. package/dist/collection-slugs-cache-D9auiKmI.mjs.map +1 -0
  485. package/dist/comment-DcT8qdPK.mjs +313 -0
  486. package/dist/comment-DcT8qdPK.mjs.map +1 -0
  487. package/dist/comment-reaction-DY5-y8Y5.mjs +85 -0
  488. package/dist/comment-reaction-DY5-y8Y5.mjs.map +1 -0
  489. package/dist/comments-B67VRNGw.mjs +204 -0
  490. package/dist/comments-B67VRNGw.mjs.map +1 -0
  491. package/dist/comments-BVzzt6x5.mjs +99 -0
  492. package/dist/comments-BVzzt6x5.mjs.map +1 -0
  493. package/dist/components-DIl9Qzh6.mjs +108 -0
  494. package/dist/components-DIl9Qzh6.mjs.map +1 -0
  495. package/dist/config-B2acLeC5.mjs +242 -0
  496. package/dist/config-B2acLeC5.mjs.map +1 -0
  497. package/dist/config-CGVeT8Hc.mjs +73 -0
  498. package/dist/config-CGVeT8Hc.mjs.map +1 -0
  499. package/dist/config-D3HhLON3.d.mts +39 -0
  500. package/dist/config-D3HhLON3.d.mts.map +1 -0
  501. package/dist/config-DS7e4EZ9.d.mts +6387 -0
  502. package/dist/config-DS7e4EZ9.d.mts.map +1 -0
  503. package/dist/content-DZ3B5qtA.mjs +2216 -0
  504. package/dist/content-DZ3B5qtA.mjs.map +1 -0
  505. package/dist/content-list-query-CbPdzsna.d.mts +26 -0
  506. package/dist/content-list-query-CbPdzsna.d.mts.map +1 -0
  507. package/dist/content-policy-CM4skrNi.mjs +46 -0
  508. package/dist/content-policy-CM4skrNi.mjs.map +1 -0
  509. package/dist/content-refresh-BHLHJgyt.mjs +3599 -0
  510. package/dist/content-refresh-BHLHJgyt.mjs.map +1 -0
  511. package/dist/content-repair-BVll5WNl.mjs +440 -0
  512. package/dist/content-repair-BVll5WNl.mjs.map +1 -0
  513. package/dist/context-B195kjqZ.mjs +1835 -0
  514. package/dist/context-B195kjqZ.mjs.map +1 -0
  515. package/dist/cron-BcR3RN4K.mjs +282 -0
  516. package/dist/cron-BcR3RN4K.mjs.map +1 -0
  517. package/dist/dashboard-CZD4G7k_.mjs +151 -0
  518. package/dist/dashboard-CZD4G7k_.mjs.map +1 -0
  519. package/dist/database/migration-lock.d.mts +37 -0
  520. package/dist/database/migration-lock.d.mts.map +1 -0
  521. package/dist/database/migration-lock.mjs +76 -0
  522. package/dist/database/migration-lock.mjs.map +1 -0
  523. package/dist/database/pg-migration-lock.d.mts +1 -1
  524. package/dist/database/pg-migration-lock.mjs +1 -1
  525. package/dist/database/pg-migration-lock.mjs.map +1 -1
  526. package/dist/datetime-normalization-PeiEdcRY.mjs +187 -0
  527. package/dist/datetime-normalization-PeiEdcRY.mjs.map +1 -0
  528. package/dist/db/index.d.mts +3 -3
  529. package/dist/db/index.mjs +4 -3
  530. package/dist/db/index.mjs.map +1 -1
  531. package/dist/db/libsql-migrations.d.mts +1 -1
  532. package/dist/db/libsql-migrations.mjs +7 -6
  533. package/dist/db/libsql-migrations.mjs.map +1 -1
  534. package/dist/db/libsql.d.mts +1 -1
  535. package/dist/db/postgres-migrations.d.mts +1 -1
  536. package/dist/db/postgres-migrations.mjs +7 -6
  537. package/dist/db/postgres-migrations.mjs.map +1 -1
  538. package/dist/db/postgres.d.mts +1 -1
  539. package/dist/db/sqlite-migrations.d.mts +1 -1
  540. package/dist/db/sqlite-migrations.mjs +7 -6
  541. package/dist/db/sqlite-migrations.mjs.map +1 -1
  542. package/dist/db/sqlite.d.mts +1 -1
  543. package/dist/db/sqlite.mjs +1 -1
  544. package/dist/db-errors-CBD5yMro.mjs +55 -0
  545. package/dist/db-errors-CBD5yMro.mjs.map +1 -0
  546. package/dist/default-BtlxWgh9.mjs +81 -0
  547. package/dist/default-BtlxWgh9.mjs.map +1 -0
  548. package/dist/deferred-tasks-Ba9fphlE.d.mts +9 -0
  549. package/dist/deferred-tasks-Ba9fphlE.d.mts.map +1 -0
  550. package/dist/dev-typegen-CZaPLl3V.mjs +29 -0
  551. package/dist/dev-typegen-CZaPLl3V.mjs.map +1 -0
  552. package/dist/device-flow-3E5l0fpH.mjs +466 -0
  553. package/dist/device-flow-3E5l0fpH.mjs.map +1 -0
  554. package/dist/dialect-helpers-CtYdsX4W.mjs +307 -0
  555. package/dist/dialect-helpers-CtYdsX4W.mjs.map +1 -0
  556. package/dist/direct-executor-ZI8E01Yt.mjs +104 -0
  557. package/dist/direct-executor-ZI8E01Yt.mjs.map +1 -0
  558. package/dist/dist-2hDLsLeq.mjs +810 -0
  559. package/dist/dist-2hDLsLeq.mjs.map +1 -0
  560. package/dist/email-console-gc-E3Eqj.mjs +50 -0
  561. package/dist/email-console-gc-E3Eqj.mjs.map +1 -0
  562. package/dist/emdash-runtime-DZGinqTL.mjs +4041 -0
  563. package/dist/emdash-runtime-DZGinqTL.mjs.map +1 -0
  564. package/dist/enrich-C2Mk0lwE.mjs +194 -0
  565. package/dist/enrich-C2Mk0lwE.mjs.map +1 -0
  566. package/dist/entry-lock-D3C99MXS.mjs +1520 -0
  567. package/dist/entry-lock-D3C99MXS.mjs.map +1 -0
  568. package/dist/entry-lock-D9rnj2Lu.mjs +163 -0
  569. package/dist/entry-lock-D9rnj2Lu.mjs.map +1 -0
  570. package/dist/entry-lock-DX7QkqEg.d.mts +3503 -0
  571. package/dist/entry-lock-DX7QkqEg.d.mts.map +1 -0
  572. package/dist/entry-locks-CO_KaoU5.mjs +167 -0
  573. package/dist/entry-locks-CO_KaoU5.mjs.map +1 -0
  574. package/dist/error-CCTCskie.mjs +90 -0
  575. package/dist/error-CCTCskie.mjs.map +1 -0
  576. package/dist/errors-W3PA8HqB.mjs +447 -0
  577. package/dist/errors-W3PA8HqB.mjs.map +1 -0
  578. package/dist/escape-DN4Qmjsl.mjs +9 -0
  579. package/dist/escape-DN4Qmjsl.mjs.map +1 -0
  580. package/dist/field-defs-cache-B337z8UJ.mjs +77 -0
  581. package/dist/field-defs-cache-B337z8UJ.mjs.map +1 -0
  582. package/dist/focal-point-Gr34o-4o.mjs +23 -0
  583. package/dist/focal-point-Gr34o-4o.mjs.map +1 -0
  584. package/dist/fts-manager-DMb0sbIQ.mjs +413 -0
  585. package/dist/fts-manager-DMb0sbIQ.mjs.map +1 -0
  586. package/dist/hash-CLVFzWvx.mjs +37 -0
  587. package/dist/hash-CLVFzWvx.mjs.map +1 -0
  588. package/dist/hook-result-KY1jq21o.d.mts +31 -0
  589. package/dist/hook-result-KY1jq21o.d.mts.map +1 -0
  590. package/dist/hreflang-BgS2FqhH.d.mts +50 -0
  591. package/dist/hreflang-BgS2FqhH.d.mts.map +1 -0
  592. package/dist/hreflang-CrJwqoeb.mjs +105 -0
  593. package/dist/hreflang-CrJwqoeb.mjs.map +1 -0
  594. package/dist/http-route-dispatch-DAKlanXb.mjs +339 -0
  595. package/dist/http-route-dispatch-DAKlanXb.mjs.map +1 -0
  596. package/dist/identity-DRGSHEEr.mjs +35 -0
  597. package/dist/identity-DRGSHEEr.mjs.map +1 -0
  598. package/dist/import-DFr5B_hC.mjs +2020 -0
  599. package/dist/import-DFr5B_hC.mjs.map +1 -0
  600. package/dist/index-CDwKDkTq.d.mts +623 -0
  601. package/dist/index-CDwKDkTq.d.mts.map +1 -0
  602. package/dist/index.d.mts +27 -22
  603. package/dist/index.mjs +101 -86
  604. package/dist/init-lock-4eRRB4Le.mjs +56 -0
  605. package/dist/init-lock-4eRRB4Le.mjs.map +1 -0
  606. package/dist/install-finalization-5Os-QZ-2.mjs +58 -0
  607. package/dist/install-finalization-5Os-QZ-2.mjs.map +1 -0
  608. package/dist/lifecycle-7e-Lt_kX.mjs +25 -0
  609. package/dist/lifecycle-7e-Lt_kX.mjs.map +1 -0
  610. package/dist/load-Cu5bvCZh.mjs +28 -0
  611. package/dist/load-Cu5bvCZh.mjs.map +1 -0
  612. package/dist/loader-t4TxaFiQ.mjs +1004 -0
  613. package/dist/loader-t4TxaFiQ.mjs.map +1 -0
  614. package/dist/manifest-builder-D31UoJCu.mjs +189 -0
  615. package/dist/manifest-builder-D31UoJCu.mjs.map +1 -0
  616. package/dist/manifest-schema-Bkh8SeHd.mjs +491 -0
  617. package/dist/manifest-schema-Bkh8SeHd.mjs.map +1 -0
  618. package/dist/media/image-endpoint.mjs +1 -1
  619. package/dist/media/index.d.mts +1 -1
  620. package/dist/media/index.mjs +4 -4
  621. package/dist/media/local-runtime.d.mts +14 -12
  622. package/dist/media/local-runtime.d.mts.map +1 -1
  623. package/dist/media/local-runtime.mjs +12 -11
  624. package/dist/media/local-runtime.mjs.map +1 -1
  625. package/dist/media-TBlKCwo7.mjs +334 -0
  626. package/dist/media-TBlKCwo7.mjs.map +1 -0
  627. package/dist/media-allowlist-s60eAIf6.mjs +44 -0
  628. package/dist/media-allowlist-s60eAIf6.mjs.map +1 -0
  629. package/dist/media-folders-ClIRLUQv.mjs +210 -0
  630. package/dist/media-folders-ClIRLUQv.mjs.map +1 -0
  631. package/dist/media-url-DY_ijO3B.mjs +43 -0
  632. package/dist/media-url-DY_ijO3B.mjs.map +1 -0
  633. package/dist/media-usage-C4NolTpQ.mjs +1833 -0
  634. package/dist/media-usage-C4NolTpQ.mjs.map +1 -0
  635. package/dist/media-usage-activation-CAhmb14O.mjs +78 -0
  636. package/dist/media-usage-activation-CAhmb14O.mjs.map +1 -0
  637. package/dist/media-usage-work-Cu5DqewW.mjs +586 -0
  638. package/dist/media-usage-work-Cu5DqewW.mjs.map +1 -0
  639. package/dist/media-usage-work-DJr3rOEN.mjs +152 -0
  640. package/dist/media-usage-work-DJr3rOEN.mjs.map +1 -0
  641. package/dist/media-usage-write-fence-DW5oHT7q.mjs +42 -0
  642. package/dist/media-usage-write-fence-DW5oHT7q.mjs.map +1 -0
  643. package/dist/menus-DbgU9z5Q.mjs +3732 -0
  644. package/dist/menus-DbgU9z5Q.mjs.map +1 -0
  645. package/dist/menus-Wy8m5NcH.mjs +753 -0
  646. package/dist/menus-Wy8m5NcH.mjs.map +1 -0
  647. package/dist/migrations/index.d.mts +2 -2
  648. package/dist/migrations/index.d.mts.map +1 -1
  649. package/dist/migrations/index.mjs +6 -5
  650. package/dist/mime-CCYRC4r1.mjs +36 -0
  651. package/dist/mime-CCYRC4r1.mjs.map +1 -0
  652. package/dist/mode-CkmOhFqj.mjs +23 -0
  653. package/dist/mode-CkmOhFqj.mjs.map +1 -0
  654. package/dist/node-sqlite-compat-vpVaILnb.mjs +46 -0
  655. package/dist/node-sqlite-compat-vpVaILnb.mjs.map +1 -0
  656. package/dist/normalize-dChXQjwS.mjs +191 -0
  657. package/dist/normalize-dChXQjwS.mjs.map +1 -0
  658. package/dist/oauth-authorization-DZ-R-hmx.mjs +274 -0
  659. package/dist/oauth-authorization-DZ-R-hmx.mjs.map +1 -0
  660. package/dist/oauth-clients-BMPA8vjl.mjs +266 -0
  661. package/dist/oauth-clients-BMPA8vjl.mjs.map +1 -0
  662. package/dist/oauth-state-store-0gIdb48-.mjs +50 -0
  663. package/dist/oauth-state-store-0gIdb48-.mjs.map +1 -0
  664. package/dist/oauth-user-lookup-ChVW4UWu.mjs +26 -0
  665. package/dist/oauth-user-lookup-ChVW4UWu.mjs.map +1 -0
  666. package/dist/object-cache/memory.d.mts +1 -1
  667. package/dist/object-cache-DlSVbn5Y.mjs +534 -0
  668. package/dist/object-cache-DlSVbn5Y.mjs.map +1 -0
  669. package/dist/options-D5WcorD5.mjs +200 -0
  670. package/dist/options-D5WcorD5.mjs.map +1 -0
  671. package/dist/options-DAknChnw.d.mts +77 -0
  672. package/dist/options-DAknChnw.d.mts.map +1 -0
  673. package/dist/page/index.d.mts +2 -2
  674. package/dist/page/index.d.mts.map +1 -1
  675. package/dist/page/index.mjs +13 -0
  676. package/dist/page/index.mjs.map +1 -1
  677. package/dist/parse-Cr379Av9.mjs +81 -0
  678. package/dist/parse-Cr379Av9.mjs.map +1 -0
  679. package/dist/parse-tj9XLNO_.d.mts +165 -0
  680. package/dist/parse-tj9XLNO_.d.mts.map +1 -0
  681. package/dist/passkey-config-BD-wMaCf.mjs +46 -0
  682. package/dist/passkey-config-BD-wMaCf.mjs.map +1 -0
  683. package/dist/patterns-Do3iqi7N.mjs +145 -0
  684. package/dist/patterns-Do3iqi7N.mjs.map +1 -0
  685. package/dist/placeholder-CubPFn_L.d.mts +306 -0
  686. package/dist/placeholder-CubPFn_L.d.mts.map +1 -0
  687. package/dist/plugin-test-runtime.d.mts +97 -0
  688. package/dist/plugin-test-runtime.d.mts.map +1 -0
  689. package/dist/plugin-test-runtime.mjs +105 -0
  690. package/dist/plugin-types.d.mts +53 -15
  691. package/dist/plugin-types.d.mts.map +1 -1
  692. package/dist/plugin-types.mjs +18 -1
  693. package/dist/plugin-types.mjs.map +1 -0
  694. package/dist/plugin-utils.d.mts +12 -10
  695. package/dist/plugin-utils.d.mts.map +1 -1
  696. package/dist/plugins/adapt-sandbox-entry.d.mts +12 -10
  697. package/dist/plugins/adapt-sandbox-entry.d.mts.map +1 -1
  698. package/dist/plugins/adapt-sandbox-entry.mjs +18 -13
  699. package/dist/plugins/adapt-sandbox-entry.mjs.map +1 -1
  700. package/dist/plugins/host.d.mts +7 -0
  701. package/dist/plugins/host.mjs +45 -0
  702. package/dist/plugins/http-wire.d.mts +25 -0
  703. package/dist/plugins/http-wire.d.mts.map +1 -0
  704. package/dist/plugins/http-wire.mjs +148 -0
  705. package/dist/plugins/http-wire.mjs.map +1 -0
  706. package/dist/plugins/secret-redactor.d.mts +9 -0
  707. package/dist/plugins/secret-redactor.d.mts.map +1 -0
  708. package/dist/plugins/secret-redactor.mjs +51 -0
  709. package/dist/plugins/secret-redactor.mjs.map +1 -0
  710. package/dist/plugins-DHurtdXQ.mjs +277 -0
  711. package/dist/plugins-DHurtdXQ.mjs.map +1 -0
  712. package/dist/policy-lyZnjpwz.mjs +45 -0
  713. package/dist/policy-lyZnjpwz.mjs.map +1 -0
  714. package/dist/portable-text-oAwodbPS.mjs +286 -0
  715. package/dist/portable-text-oAwodbPS.mjs.map +1 -0
  716. package/dist/preview-Cup2bj8c.mjs +107 -0
  717. package/dist/preview-Cup2bj8c.mjs.map +1 -0
  718. package/dist/protocol-C1CNiKX4.d.mts +61 -0
  719. package/dist/protocol-C1CNiKX4.d.mts.map +1 -0
  720. package/dist/public-submission-Cs-pFMQK.mjs +245 -0
  721. package/dist/public-submission-Cs-pFMQK.mjs.map +1 -0
  722. package/dist/public-url-BWVHsfQv.mjs +101 -0
  723. package/dist/public-url-BWVHsfQv.mjs.map +1 -0
  724. package/dist/query-D-lxiOgn.mjs +890 -0
  725. package/dist/query-D-lxiOgn.mjs.map +1 -0
  726. package/dist/query-D7kHKOws.mjs +41 -0
  727. package/dist/query-D7kHKOws.mjs.map +1 -0
  728. package/dist/rate-limit-CqJn-w4h.mjs +120 -0
  729. package/dist/rate-limit-CqJn-w4h.mjs.map +1 -0
  730. package/dist/redirect-BrChFPIu.mjs +17 -0
  731. package/dist/redirect-BrChFPIu.mjs.map +1 -0
  732. package/dist/redirect-D2Yo-b6S.mjs +415 -0
  733. package/dist/redirect-D2Yo-b6S.mjs.map +1 -0
  734. package/dist/redirects-BCiTaIQ-.mjs +146 -0
  735. package/dist/redirects-BCiTaIQ-.mjs.map +1 -0
  736. package/dist/redirects-ByItliuu.mjs +644 -0
  737. package/dist/redirects-ByItliuu.mjs.map +1 -0
  738. package/dist/registry/testing.d.mts +14 -0
  739. package/dist/registry/testing.d.mts.map +1 -0
  740. package/dist/registry/testing.mjs +255 -0
  741. package/dist/registry/testing.mjs.map +1 -0
  742. package/dist/registry-CkuPoZs7.mjs +1222 -0
  743. package/dist/registry-CkuPoZs7.mjs.map +1 -0
  744. package/dist/relation-XTAtOpJO.mjs +334 -0
  745. package/dist/relation-XTAtOpJO.mjs.map +1 -0
  746. package/dist/relations-B4w-G5U9.mjs +309 -0
  747. package/dist/relations-B4w-G5U9.mjs.map +1 -0
  748. package/dist/relations-O63JWBRj.mjs +403 -0
  749. package/dist/relations-O63JWBRj.mjs.map +1 -0
  750. package/dist/request-cache-DaMhSQdx.mjs +104 -0
  751. package/dist/request-cache-DaMhSQdx.mjs.map +1 -0
  752. package/dist/request-context.d.mts +1 -1
  753. package/dist/request-meta-C8yl_sIs.mjs +141 -0
  754. package/dist/request-meta-C8yl_sIs.mjs.map +1 -0
  755. package/dist/resolve-BJIS8wKr.mjs +199 -0
  756. package/dist/resolve-BJIS8wKr.mjs.map +1 -0
  757. package/dist/route-wire-D66L2oaZ.mjs +197 -0
  758. package/dist/route-wire-D66L2oaZ.mjs.map +1 -0
  759. package/dist/routes-DYsTe-oR.mjs +321 -0
  760. package/dist/routes-DYsTe-oR.mjs.map +1 -0
  761. package/dist/runner-3gfxRsJG.d.mts +68 -0
  762. package/dist/runner-3gfxRsJG.d.mts.map +1 -0
  763. package/dist/runner-ClrleR8A.mjs +5502 -0
  764. package/dist/runner-ClrleR8A.mjs.map +1 -0
  765. package/dist/runtime.d.mts +13 -11
  766. package/dist/runtime.d.mts.map +1 -1
  767. package/dist/runtime.mjs +6 -5
  768. package/dist/runtime.mjs.map +1 -1
  769. package/dist/schema-CPhPM9Do.mjs +420 -0
  770. package/dist/schema-CPhPM9Do.mjs.map +1 -0
  771. package/dist/schema-DEERRrKS.mjs +9 -0
  772. package/dist/schema-DEERRrKS.mjs.map +1 -0
  773. package/dist/scopes-Bn8_rCSt.mjs +27 -0
  774. package/dist/scopes-Bn8_rCSt.mjs.map +1 -0
  775. package/dist/search-lami_Ota.mjs +448 -0
  776. package/dist/search-lami_Ota.mjs.map +1 -0
  777. package/dist/secrets-DNgVgz_e.mjs +341 -0
  778. package/dist/secrets-DNgVgz_e.mjs.map +1 -0
  779. package/dist/sections-BIpd4Cxf.mjs +346 -0
  780. package/dist/sections-BIpd4Cxf.mjs.map +1 -0
  781. package/dist/seed/index.d.mts +2 -2
  782. package/dist/seed/index.mjs +35 -31
  783. package/dist/seo/index.d.mts +3 -3
  784. package/dist/seo/index.d.mts.map +1 -1
  785. package/dist/seo/index.mjs +27 -26
  786. package/dist/seo/index.mjs.map +1 -1
  787. package/dist/seo-BtU70b7l.mjs +114 -0
  788. package/dist/seo-BtU70b7l.mjs.map +1 -0
  789. package/dist/seo-_4qmazxz.mjs +133 -0
  790. package/dist/seo-_4qmazxz.mjs.map +1 -0
  791. package/dist/service-Bpy5iTX0.mjs +150 -0
  792. package/dist/service-Bpy5iTX0.mjs.map +1 -0
  793. package/dist/session-user-BQeS2Mrb.mjs +51 -0
  794. package/dist/session-user-BQeS2Mrb.mjs.map +1 -0
  795. package/dist/settings-DmroR53o.mjs +420 -0
  796. package/dist/settings-DmroR53o.mjs.map +1 -0
  797. package/dist/settings-g2F2a3Ub.mjs +51 -0
  798. package/dist/settings-g2F2a3Ub.mjs.map +1 -0
  799. package/dist/setup-complete-BrZaXpVV.mjs +26 -0
  800. package/dist/setup-complete-BrZaXpVV.mjs.map +1 -0
  801. package/dist/setup-nonce-Cb9-884O.mjs +25 -0
  802. package/dist/setup-nonce-Cb9-884O.mjs.map +1 -0
  803. package/dist/single-flight-cache-B5O2qhO1.mjs +104 -0
  804. package/dist/single-flight-cache-B5O2qhO1.mjs.map +1 -0
  805. package/dist/site-url-DjhYCaep.mjs +16 -0
  806. package/dist/site-url-DjhYCaep.mjs.map +1 -0
  807. package/dist/slugify-T5GHH42D.mjs +17 -0
  808. package/dist/slugify-T5GHH42D.mjs.map +1 -0
  809. package/dist/snapshot-C32Xuv3o.mjs +233 -0
  810. package/dist/snapshot-C32Xuv3o.mjs.map +1 -0
  811. package/dist/ssrf-Co1GGFZz.mjs +406 -0
  812. package/dist/ssrf-Co1GGFZz.mjs.map +1 -0
  813. package/dist/state-C7gCoiHr.mjs +153 -0
  814. package/dist/state-C7gCoiHr.mjs.map +1 -0
  815. package/dist/status-DLoBmcDz.mjs +30 -0
  816. package/dist/status-DLoBmcDz.mjs.map +1 -0
  817. package/dist/storage/local.d.mts +1 -1
  818. package/dist/storage/local.mjs +1 -1
  819. package/dist/storage/s3.d.mts +1 -1
  820. package/dist/storage/s3.mjs +1 -1
  821. package/dist/storage-query-CPctdMKX.d.mts +1519 -0
  822. package/dist/storage-query-CPctdMKX.d.mts.map +1 -0
  823. package/dist/target-CUKlGrXb.mjs +27 -0
  824. package/dist/target-CUKlGrXb.mjs.map +1 -0
  825. package/dist/taxonomies-BpqpXJUE.mjs +707 -0
  826. package/dist/taxonomies-BpqpXJUE.mjs.map +1 -0
  827. package/dist/taxonomies-ClCo4IGO.mjs +899 -0
  828. package/dist/taxonomies-ClCo4IGO.mjs.map +1 -0
  829. package/dist/taxonomy-Dj1vpw5E.mjs +508 -0
  830. package/dist/taxonomy-Dj1vpw5E.mjs.map +1 -0
  831. package/dist/tokens-Ns02GAma.mjs +171 -0
  832. package/dist/tokens-Ns02GAma.mjs.map +1 -0
  833. package/dist/transaction-BcJO4Tmc.mjs +29 -0
  834. package/dist/transaction-BcJO4Tmc.mjs.map +1 -0
  835. package/dist/transport-B8P1xsqk.mjs +136 -0
  836. package/dist/transport-B8P1xsqk.mjs.map +1 -0
  837. package/dist/transport-BLHZZcD_.d.mts +42 -0
  838. package/dist/transport-BLHZZcD_.d.mts.map +1 -0
  839. package/dist/trusted-proxy-Cg7SuD15.mjs +51 -0
  840. package/dist/trusted-proxy-Cg7SuD15.mjs.map +1 -0
  841. package/dist/turnstile-DWCSh_Qc.mjs +53 -0
  842. package/dist/turnstile-DWCSh_Qc.mjs.map +1 -0
  843. package/dist/types-B3RkqvDW.mjs +156 -0
  844. package/dist/types-B3RkqvDW.mjs.map +1 -0
  845. package/dist/types-BkUg2yHx.mjs +92 -0
  846. package/dist/types-BkUg2yHx.mjs.map +1 -0
  847. package/dist/types-BtuppOTV.mjs +16 -0
  848. package/dist/types-BtuppOTV.mjs.map +1 -0
  849. package/dist/types-CCR3ivXE.d.mts +363 -0
  850. package/dist/types-CCR3ivXE.d.mts.map +1 -0
  851. package/dist/types-CSHgU_-_.mjs +18 -0
  852. package/dist/types-CSHgU_-_.mjs.map +1 -0
  853. package/dist/types-CbwqGOXm.d.mts +766 -0
  854. package/dist/types-CbwqGOXm.d.mts.map +1 -0
  855. package/dist/types-D4RGIc2I.d.mts +198 -0
  856. package/dist/types-D4RGIc2I.d.mts.map +1 -0
  857. package/dist/types-DEHidMEk.d.mts +1637 -0
  858. package/dist/types-DEHidMEk.d.mts.map +1 -0
  859. package/dist/types-DQeU2SR7.d.mts +279 -0
  860. package/dist/types-DQeU2SR7.d.mts.map +1 -0
  861. package/dist/types-DxQWoQLA.d.mts +264 -0
  862. package/dist/types-DxQWoQLA.d.mts.map +1 -0
  863. package/dist/types-FBBnGZ2Y.d.mts +198 -0
  864. package/dist/types-FBBnGZ2Y.d.mts.map +1 -0
  865. package/dist/types-ZCnlropY.mjs +69 -0
  866. package/dist/types-ZCnlropY.mjs.map +1 -0
  867. package/dist/types-_Qtyawiy.d.mts +124 -0
  868. package/dist/types-_Qtyawiy.d.mts.map +1 -0
  869. package/dist/types-gC6FAoa_.d.mts +75 -0
  870. package/dist/types-gC6FAoa_.d.mts.map +1 -0
  871. package/dist/types-k--LneIF.mjs +22 -0
  872. package/dist/types-k--LneIF.mjs.map +1 -0
  873. package/dist/upload-attempts-2xdnoKGe.mjs +27 -0
  874. package/dist/upload-attempts-2xdnoKGe.mjs.map +1 -0
  875. package/dist/url-pattern-3m3reMzr.mjs +33 -0
  876. package/dist/url-pattern-3m3reMzr.mjs.map +1 -0
  877. package/dist/user-DroRntkx.mjs +171 -0
  878. package/dist/user-DroRntkx.mjs.map +1 -0
  879. package/dist/utils-CC2oNGV8.mjs +435 -0
  880. package/dist/utils-CC2oNGV8.mjs.map +1 -0
  881. package/dist/validate-BCP9HNDn.mjs +384 -0
  882. package/dist/validate-BCP9HNDn.mjs.map +1 -0
  883. package/dist/validate-CyQ7I3xF.d.mts +410 -0
  884. package/dist/validate-CyQ7I3xF.d.mts.map +1 -0
  885. package/dist/validate-DANX1-Qi.mjs +120 -0
  886. package/dist/validate-DANX1-Qi.mjs.map +1 -0
  887. package/dist/validation-DBy6WF94.mjs +216 -0
  888. package/dist/validation-DBy6WF94.mjs.map +1 -0
  889. package/dist/version-B57E4Uo7.mjs +7 -0
  890. package/dist/version-B57E4Uo7.mjs.map +1 -0
  891. package/dist/widgets-wQ7Xcgq8.mjs +126 -0
  892. package/dist/widgets-wQ7Xcgq8.mjs.map +1 -0
  893. package/dist/wxr-taxonomies-DIHfvEDt.mjs +406 -0
  894. package/dist/wxr-taxonomies-DIHfvEDt.mjs.map +1 -0
  895. package/dist/wxr-taxonomies-DU2ZSiGc.d.mts +34 -0
  896. package/dist/wxr-taxonomies-DU2ZSiGc.d.mts.map +1 -0
  897. package/dist/zod-generator-D_yHIWfs.mjs +329 -0
  898. package/dist/zod-generator-D_yHIWfs.mjs.map +1 -0
  899. package/package.json +39 -12
  900. package/src/api/errors.ts +23 -0
  901. package/src/api/handlers/backup.ts +11 -5
  902. package/src/api/handlers/content.ts +226 -85
  903. package/src/api/handlers/dashboard.ts +31 -1
  904. package/src/api/handlers/entry-lock.ts +206 -0
  905. package/src/api/handlers/index.ts +3 -0
  906. package/src/api/handlers/manifest.ts +5 -6
  907. package/src/api/handlers/marketplace.ts +126 -34
  908. package/src/api/handlers/media-upload.ts +31 -4
  909. package/src/api/handlers/menus.ts +9 -0
  910. package/src/api/handlers/plugin-settings.ts +35 -3
  911. package/src/api/handlers/redirects.ts +221 -138
  912. package/src/api/handlers/registry.ts +75 -29
  913. package/src/api/handlers/revision.ts +16 -27
  914. package/src/api/handlers/seo.ts +10 -1
  915. package/src/api/handlers/snapshot.ts +87 -72
  916. package/src/api/handlers/taxonomies.ts +79 -5
  917. package/src/api/handlers/validation.ts +120 -19
  918. package/src/api/openapi/document.ts +133 -11
  919. package/src/api/schemas/content.ts +32 -12
  920. package/src/api/schemas/entry-lock.ts +57 -0
  921. package/src/api/schemas/index.ts +1 -0
  922. package/src/api/schemas/schema.ts +10 -1
  923. package/src/api/schemas/search.ts +4 -0
  924. package/src/api/types.ts +4 -0
  925. package/src/astro/integration/index.ts +22 -6
  926. package/src/astro/integration/routes.ts +89 -0
  927. package/src/astro/integration/runtime.ts +40 -24
  928. package/src/astro/integration/virtual-modules.ts +4 -0
  929. package/src/astro/integration/vite-config.ts +31 -0
  930. package/src/astro/middleware/auth.ts +25 -4
  931. package/src/astro/middleware/request-context.ts +28 -10
  932. package/src/astro/middleware.ts +33 -1
  933. package/src/astro/prefetch.ts +2 -2
  934. package/src/astro/routes/api/admin/comments/[id]/status.ts +22 -58
  935. package/src/astro/routes/api/admin/plugins/[id]/disable.ts +2 -15
  936. package/src/astro/routes/api/admin/plugins/[id]/enable.ts +2 -25
  937. package/src/astro/routes/api/admin/plugins/[id]/uninstall.ts +1 -0
  938. package/src/astro/routes/api/admin/plugins/[id]/update.ts +23 -4
  939. package/src/astro/routes/api/admin/plugins/marketplace/[id]/install.ts +12 -2
  940. package/src/astro/routes/api/admin/plugins/registry/[id]/uninstall.ts +1 -0
  941. package/src/astro/routes/api/admin/plugins/registry/[id]/update.ts +29 -10
  942. package/src/astro/routes/api/admin/plugins/registry/artifact.ts +8 -2
  943. package/src/astro/routes/api/admin/plugins/registry/install.ts +15 -4
  944. package/src/astro/routes/api/admin/plugins/registry/verify.ts +2 -1
  945. package/src/astro/routes/api/admin/plugins/updates.ts +6 -1
  946. package/src/astro/routes/api/admin/scheduled-policy-rejections/[collection]/[id].ts +34 -0
  947. package/src/astro/routes/api/comments/[collection]/[contentId]/index.ts +4 -259
  948. package/src/astro/routes/api/content/[collection]/[id]/discard-draft.ts +10 -0
  949. package/src/astro/routes/api/content/[collection]/[id]/lock.ts +133 -0
  950. package/src/astro/routes/api/content/[collection]/[id]/plugin-extensions/[pluginId]/[kind]/[extensionId].ts +29 -0
  951. package/src/astro/routes/api/content/[collection]/[id]/publish.ts +21 -4
  952. package/src/astro/routes/api/content/[collection]/[id]/schedule.ts +30 -1
  953. package/src/astro/routes/api/content/[collection]/[id]/unpublish.ts +15 -1
  954. package/src/astro/routes/api/content/[collection]/[id].ts +27 -2
  955. package/src/astro/routes/api/content/[collection]/index.ts +3 -0
  956. package/src/astro/routes/api/health.ts +23 -0
  957. package/src/astro/routes/api/manifest.ts +14 -4
  958. package/src/astro/routes/api/mcp.ts +2 -1
  959. package/src/astro/routes/api/media/asset/[id]/[filename].ts +50 -0
  960. package/src/astro/routes/api/plugins/[pluginId]/[...path].ts +13 -81
  961. package/src/astro/routes/api/redirects/[id].ts +0 -3
  962. package/src/astro/routes/api/redirects/index.ts +0 -2
  963. package/src/astro/routes/api/search/index.ts +1 -0
  964. package/src/astro/routes/api/visual-editing/action-token.ts +36 -0
  965. package/src/astro/routes/api/visual-editing/content/[collection]/[id]/publish.ts +32 -0
  966. package/src/astro/routes/api/visual-editing/toolbar-labels.ts +16 -0
  967. package/src/astro/routes/sitemap-[collection].xml.ts +11 -4
  968. package/src/astro/types.ts +83 -12
  969. package/src/cli/commands/bundle-utils.ts +19 -19
  970. package/src/cli/commands/bundle.ts +9 -6
  971. package/src/cli/commands/content.ts +32 -6
  972. package/src/cli/commands/doctor.ts +25 -0
  973. package/src/cli/commands/export-seed.ts +195 -56
  974. package/src/cli/commands/migrate.ts +71 -23
  975. package/src/cli/commands/publish.ts +2 -2
  976. package/src/client/index.ts +34 -7
  977. package/src/comments/public-submission.ts +246 -0
  978. package/src/comments/service.ts +59 -12
  979. package/src/components/EmDashBodyEnd.astro +4 -1
  980. package/src/components/EmDashBodyStart.astro +4 -1
  981. package/src/components/EmDashHead.astro +36 -16
  982. package/src/components/Gallery.astro +18 -4
  983. package/src/components/InlineEditor.astro +3 -1
  984. package/src/components/InlinePortableTextEditor.tsx +106 -11
  985. package/src/components/PortableText.astro +4 -0
  986. package/src/components/Table.astro +147 -62
  987. package/src/components/widgets/Archives.astro +6 -5
  988. package/src/config/errors.ts +13 -0
  989. package/src/config/secrets.ts +25 -11
  990. package/src/content/converters/portable-text-to-prosemirror.ts +26 -2
  991. package/src/content/converters/prosemirror-to-portable-text.ts +35 -6
  992. package/src/content/converters/types.ts +10 -0
  993. package/src/content/known-fields.ts +44 -0
  994. package/src/database/connection.ts +5 -1
  995. package/src/database/content-datetime.ts +123 -0
  996. package/src/database/datetime-storage.ts +452 -0
  997. package/src/database/dialect-helpers.ts +161 -1
  998. package/src/database/migration-lock.ts +140 -0
  999. package/src/database/migrations/075_entry_edit_locks.ts +44 -0
  1000. package/src/database/migrations/076_collection_nav_group.ts +22 -0
  1001. package/src/database/migrations/077_plugin_storage_revisions.ts +89 -0
  1002. package/src/database/migrations/078_menu_item_translation_groups.ts +15 -0
  1003. package/src/database/migrations/079_datetime_normalization.ts +13 -0
  1004. package/src/database/migrations/080_content_translation_locale_unique.ts +88 -0
  1005. package/src/database/migrations/081_redirect_write_guards.ts +257 -0
  1006. package/src/database/migrations/082_taxonomy_translation_locale_unique.ts +49 -0
  1007. package/src/database/migrations/runner.ts +63 -15
  1008. package/src/database/pg-migration-lock.ts +2 -2
  1009. package/src/database/repositories/byline.ts +9 -0
  1010. package/src/database/repositories/comment.ts +86 -0
  1011. package/src/database/repositories/content.ts +560 -69
  1012. package/src/database/repositories/entry-locks.ts +257 -0
  1013. package/src/database/repositories/media.ts +35 -4
  1014. package/src/database/repositories/menu.ts +1 -0
  1015. package/src/database/repositories/options.ts +113 -7
  1016. package/src/database/repositories/plugin-storage.ts +159 -0
  1017. package/src/database/repositories/redirect.ts +262 -56
  1018. package/src/database/repositories/revision.ts +116 -17
  1019. package/src/database/repositories/taxonomy.ts +42 -0
  1020. package/src/database/repositories/types.ts +5 -0
  1021. package/src/database/types.ts +26 -1
  1022. package/src/datetime-normalization.ts +311 -0
  1023. package/src/db/node-sqlite-compat.ts +3 -2
  1024. package/src/emdash-runtime.ts +1994 -424
  1025. package/src/fields/image.ts +2 -0
  1026. package/src/i18n/config.ts +6 -6
  1027. package/src/i18n/resolve.ts +98 -15
  1028. package/src/index.ts +101 -0
  1029. package/src/loader.ts +49 -4
  1030. package/src/mcp/server.ts +216 -68
  1031. package/src/media/responsive.ts +23 -0
  1032. package/src/media/usage/content-refresh.ts +2 -1
  1033. package/src/media/usage/extractor.ts +50 -15
  1034. package/src/media/usage/types.ts +1 -1
  1035. package/src/menus/index.ts +64 -35
  1036. package/src/migrations/direct-executor.ts +40 -2
  1037. package/src/migrations/index.ts +1 -0
  1038. package/src/migrations/protocol.ts +11 -1
  1039. package/src/page/seo-contributions.ts +78 -1
  1040. package/src/page/seo-panel.ts +47 -0
  1041. package/src/plugin-test-runtime.ts +17 -0
  1042. package/src/plugin-types.ts +128 -21
  1043. package/src/plugins/adapt-sandbox-entry.ts +34 -27
  1044. package/src/plugins/conditional-storage.ts +30 -0
  1045. package/src/plugins/content-access.ts +170 -0
  1046. package/src/plugins/content-policy.ts +74 -0
  1047. package/src/plugins/context.ts +790 -166
  1048. package/src/plugins/cron.ts +18 -10
  1049. package/src/plugins/define-plugin.ts +55 -54
  1050. package/src/plugins/editor-draft.ts +257 -0
  1051. package/src/plugins/hooks.ts +136 -3
  1052. package/src/plugins/host.ts +29 -0
  1053. package/src/plugins/http-route-dispatch.ts +389 -0
  1054. package/src/plugins/http-wire.ts +180 -0
  1055. package/src/plugins/index.ts +97 -3
  1056. package/src/plugins/install-finalization.ts +77 -0
  1057. package/src/plugins/lifecycle.ts +47 -0
  1058. package/src/plugins/manager.ts +5 -2
  1059. package/src/plugins/manifest-schema.ts +314 -58
  1060. package/src/plugins/media.ts +166 -0
  1061. package/src/plugins/request-meta.ts +12 -2
  1062. package/src/plugins/route-wire.ts +304 -0
  1063. package/src/plugins/routes.ts +38 -5
  1064. package/src/plugins/sandbox/index.ts +4 -0
  1065. package/src/plugins/sandbox/proxy.ts +129 -0
  1066. package/src/plugins/sandbox/types.ts +83 -7
  1067. package/src/plugins/secret-redactor.ts +65 -0
  1068. package/src/plugins/settings.ts +303 -0
  1069. package/src/plugins/state.ts +26 -0
  1070. package/src/plugins/storage-query.ts +45 -0
  1071. package/src/plugins/storage-update.ts +96 -0
  1072. package/src/plugins/types.ts +602 -15
  1073. package/src/query.ts +84 -4
  1074. package/src/registry/authoritative-records.ts +26 -0
  1075. package/src/registry/config.ts +182 -31
  1076. package/src/registry/testing.ts +100 -0
  1077. package/src/registry/types.ts +12 -70
  1078. package/src/scheduled-publish.ts +70 -3
  1079. package/src/schema/collection-slugs-cache.ts +157 -0
  1080. package/src/schema/index.ts +1 -0
  1081. package/src/schema/registry.ts +64 -1
  1082. package/src/schema/types.ts +32 -6
  1083. package/src/schema/zod-generator.ts +5 -13
  1084. package/src/search/fts-manager.ts +3 -3
  1085. package/src/search/query.ts +32 -5
  1086. package/src/search/types.ts +8 -0
  1087. package/src/security/ssrf.ts +167 -141
  1088. package/src/seed/apply.ts +41 -3
  1089. package/src/seed/types.ts +13 -3
  1090. package/src/seed/validate.ts +18 -1
  1091. package/src/seo/hreflang.ts +10 -6
  1092. package/src/seo/index.ts +5 -10
  1093. package/src/seo/media-url.ts +26 -0
  1094. package/src/settings/index.ts +53 -11
  1095. package/src/taxonomies/term-counts.ts +22 -5
  1096. package/src/visual-editing/action-token.ts +31 -0
  1097. package/src/visual-editing/toolbar-bootstrap.ts +31 -6
  1098. package/src/visual-editing/toolbar.ts +103 -12
  1099. package/src/widgets/archives.ts +10 -9
  1100. package/src/widgets/index.ts +11 -1
  1101. package/dist/activation-K0kGBWuJ.mjs +0 -382
  1102. package/dist/activation-K0kGBWuJ.mjs.map +0 -1
  1103. package/dist/adapters-BDQwg236.d.mts +0 -171
  1104. package/dist/adapters-BDQwg236.d.mts.map +0 -1
  1105. package/dist/after-CBU2vkoO.mjs +0 -96
  1106. package/dist/after-CBU2vkoO.mjs.map +0 -1
  1107. package/dist/allowed-origins-BGglilcs.mjs +0 -116
  1108. package/dist/allowed-origins-BGglilcs.mjs.map +0 -1
  1109. package/dist/api-Dz6rgoa3.mjs +0 -10040
  1110. package/dist/api-Dz6rgoa3.mjs.map +0 -1
  1111. package/dist/api-tokens-BSsQACNe.mjs +0 -163
  1112. package/dist/api-tokens-BSsQACNe.mjs.map +0 -1
  1113. package/dist/apply-B4SIOxR1.mjs +0 -980
  1114. package/dist/apply-B4SIOxR1.mjs.map +0 -1
  1115. package/dist/authorize-Bkf_UHhD.mjs +0 -40
  1116. package/dist/authorize-Bkf_UHhD.mjs.map +0 -1
  1117. package/dist/backup-rwVAl9NI.mjs +0 -241
  1118. package/dist/backup-rwVAl9NI.mjs.map +0 -1
  1119. package/dist/base64-CvLhUKQv.mjs +0 -63
  1120. package/dist/base64-CvLhUKQv.mjs.map +0 -1
  1121. package/dist/bundle-C8S2Zl6U.mjs +0 -663
  1122. package/dist/bundle-C8S2Zl6U.mjs.map +0 -1
  1123. package/dist/byline-DuhF7NWl.mjs +0 -902
  1124. package/dist/byline-DuhF7NWl.mjs.map +0 -1
  1125. package/dist/byline-fields-BovY4KYM.mjs +0 -123
  1126. package/dist/byline-fields-BovY4KYM.mjs.map +0 -1
  1127. package/dist/byline-registry-Bpu9-MVs.mjs +0 -406
  1128. package/dist/byline-registry-Bpu9-MVs.mjs.map +0 -1
  1129. package/dist/bylines-CJ5nd6Lw.mjs +0 -232
  1130. package/dist/bylines-CJ5nd6Lw.mjs.map +0 -1
  1131. package/dist/bylines-RwBAeOF1.mjs +0 -214
  1132. package/dist/bylines-RwBAeOF1.mjs.map +0 -1
  1133. package/dist/cache-BF5Kvn59.mjs +0 -108
  1134. package/dist/cache-BF5Kvn59.mjs.map +0 -1
  1135. package/dist/capture-triggers-CNW1q3HK.mjs +0 -362
  1136. package/dist/capture-triggers-CNW1q3HK.mjs.map +0 -1
  1137. package/dist/challenge-store-DQN_Yrck.mjs +0 -51
  1138. package/dist/challenge-store-DQN_Yrck.mjs.map +0 -1
  1139. package/dist/chrome-tags-D8fiZG94.mjs +0 -24
  1140. package/dist/chrome-tags-D8fiZG94.mjs.map +0 -1
  1141. package/dist/chunks-C4szrD8o.mjs +0 -25
  1142. package/dist/chunks-C4szrD8o.mjs.map +0 -1
  1143. package/dist/collection-deletion-Bj07NHbj.mjs +0 -436
  1144. package/dist/collection-deletion-Bj07NHbj.mjs.map +0 -1
  1145. package/dist/comment-reaction-BhrvSHml.mjs +0 -85
  1146. package/dist/comment-reaction-BhrvSHml.mjs.map +0 -1
  1147. package/dist/comment-vxOzWbZN.mjs +0 -255
  1148. package/dist/comment-vxOzWbZN.mjs.map +0 -1
  1149. package/dist/comments-Ct4ensnf.mjs +0 -204
  1150. package/dist/comments-Ct4ensnf.mjs.map +0 -1
  1151. package/dist/components-DJbo1z0S.mjs +0 -108
  1152. package/dist/components-DJbo1z0S.mjs.map +0 -1
  1153. package/dist/config-B9eZ340f.d.mts +0 -34
  1154. package/dist/config-B9eZ340f.d.mts.map +0 -1
  1155. package/dist/config-C3EBstHi.mjs +0 -72
  1156. package/dist/config-C3EBstHi.mjs.map +0 -1
  1157. package/dist/config-it29yDLA.mjs +0 -1163
  1158. package/dist/config-it29yDLA.mjs.map +0 -1
  1159. package/dist/content-DjvM0T92.mjs +0 -1725
  1160. package/dist/content-DjvM0T92.mjs.map +0 -1
  1161. package/dist/content-list-query-Btqd4uV2.d.mts +0 -26
  1162. package/dist/content-list-query-Btqd4uV2.d.mts.map +0 -1
  1163. package/dist/content-refresh-Bwp-8yGy.mjs +0 -3588
  1164. package/dist/content-refresh-Bwp-8yGy.mjs.map +0 -1
  1165. package/dist/content-repair-Czdp7jz5.mjs +0 -440
  1166. package/dist/content-repair-Czdp7jz5.mjs.map +0 -1
  1167. package/dist/context-CX6gxOLW.mjs +0 -1068
  1168. package/dist/context-CX6gxOLW.mjs.map +0 -1
  1169. package/dist/cron-C6o7VppJ.mjs +0 -277
  1170. package/dist/cron-C6o7VppJ.mjs.map +0 -1
  1171. package/dist/dashboard-C2kTeeRI.mjs +0 -140
  1172. package/dist/dashboard-C2kTeeRI.mjs.map +0 -1
  1173. package/dist/db-errors-Cl-sKYTm.mjs +0 -55
  1174. package/dist/db-errors-Cl-sKYTm.mjs.map +0 -1
  1175. package/dist/default-Clra32mw.mjs +0 -81
  1176. package/dist/default-Clra32mw.mjs.map +0 -1
  1177. package/dist/deferred-tasks-CvDETTJO.d.mts +0 -9
  1178. package/dist/deferred-tasks-CvDETTJO.d.mts.map +0 -1
  1179. package/dist/dev-typegen-DzOPfsNj.mjs +0 -29
  1180. package/dist/dev-typegen-DzOPfsNj.mjs.map +0 -1
  1181. package/dist/device-flow-D2oCWvLJ.mjs +0 -466
  1182. package/dist/device-flow-D2oCWvLJ.mjs.map +0 -1
  1183. package/dist/dialect-helpers-BSbfaO3F.mjs +0 -202
  1184. package/dist/dialect-helpers-BSbfaO3F.mjs.map +0 -1
  1185. package/dist/direct-executor-Bfa5_ToE.mjs +0 -85
  1186. package/dist/direct-executor-Bfa5_ToE.mjs.map +0 -1
  1187. package/dist/dist-89xCrGqi.mjs +0 -810
  1188. package/dist/dist-89xCrGqi.mjs.map +0 -1
  1189. package/dist/email-console-Dzb6uGYa.mjs +0 -50
  1190. package/dist/email-console-Dzb6uGYa.mjs.map +0 -1
  1191. package/dist/enrich-BX0IDp4z.mjs +0 -194
  1192. package/dist/enrich-BX0IDp4z.mjs.map +0 -1
  1193. package/dist/error-DFrQjppn.mjs +0 -90
  1194. package/dist/error-DFrQjppn.mjs.map +0 -1
  1195. package/dist/errors-DsVoDUjJ.mjs +0 -427
  1196. package/dist/errors-DsVoDUjJ.mjs.map +0 -1
  1197. package/dist/escape-HmHTC1Is.mjs +0 -9
  1198. package/dist/escape-HmHTC1Is.mjs.map +0 -1
  1199. package/dist/field-defs-cache-BM4SIRqH.mjs +0 -77
  1200. package/dist/field-defs-cache-BM4SIRqH.mjs.map +0 -1
  1201. package/dist/focal-point-BeWFo6Xx.mjs +0 -23
  1202. package/dist/focal-point-BeWFo6Xx.mjs.map +0 -1
  1203. package/dist/fts-manager-Do1BlW2r.mjs +0 -413
  1204. package/dist/fts-manager-Do1BlW2r.mjs.map +0 -1
  1205. package/dist/hash-3JJPlHF2.mjs +0 -37
  1206. package/dist/hash-3JJPlHF2.mjs.map +0 -1
  1207. package/dist/hook-result-DCh2WUpe.d.mts +0 -31
  1208. package/dist/hook-result-DCh2WUpe.d.mts.map +0 -1
  1209. package/dist/hreflang-B6hbAuuO.d.mts +0 -48
  1210. package/dist/hreflang-B6hbAuuO.d.mts.map +0 -1
  1211. package/dist/hreflang-DQbPZliA.mjs +0 -102
  1212. package/dist/hreflang-DQbPZliA.mjs.map +0 -1
  1213. package/dist/identity-DksvEazf.mjs +0 -35
  1214. package/dist/identity-DksvEazf.mjs.map +0 -1
  1215. package/dist/import-CJpaBBBT.mjs +0 -2020
  1216. package/dist/import-CJpaBBBT.mjs.map +0 -1
  1217. package/dist/index-BJNMCWmu.d.mts +0 -6562
  1218. package/dist/index-BJNMCWmu.d.mts.map +0 -1
  1219. package/dist/index-Du8K7bWa.d.mts +0 -278
  1220. package/dist/index-Du8K7bWa.d.mts.map +0 -1
  1221. package/dist/init-lock-DJkX6Hto.mjs +0 -56
  1222. package/dist/init-lock-DJkX6Hto.mjs.map +0 -1
  1223. package/dist/load-CawHjTOH.mjs +0 -28
  1224. package/dist/load-CawHjTOH.mjs.map +0 -1
  1225. package/dist/loader-Z8vl7zTq.mjs +0 -966
  1226. package/dist/loader-Z8vl7zTq.mjs.map +0 -1
  1227. package/dist/manifest-builder-COtzuca2.mjs +0 -189
  1228. package/dist/manifest-builder-COtzuca2.mjs.map +0 -1
  1229. package/dist/manifest-schema-BNWwR8Vd.mjs +0 -301
  1230. package/dist/manifest-schema-BNWwR8Vd.mjs.map +0 -1
  1231. package/dist/media-BBm8Wg3f.mjs +0 -318
  1232. package/dist/media-BBm8Wg3f.mjs.map +0 -1
  1233. package/dist/media-BHjus86Y.mjs +0 -464
  1234. package/dist/media-BHjus86Y.mjs.map +0 -1
  1235. package/dist/media-allowlist-CoTBWoDp.mjs +0 -44
  1236. package/dist/media-allowlist-CoTBWoDp.mjs.map +0 -1
  1237. package/dist/media-folders-BGkATs8n.mjs +0 -210
  1238. package/dist/media-folders-BGkATs8n.mjs.map +0 -1
  1239. package/dist/media-upload-BCidR-EY.mjs +0 -147
  1240. package/dist/media-upload-BCidR-EY.mjs.map +0 -1
  1241. package/dist/media-url-DHoPr0hq.mjs +0 -26
  1242. package/dist/media-url-DHoPr0hq.mjs.map +0 -1
  1243. package/dist/media-usage-CdY5jhSR.mjs +0 -1833
  1244. package/dist/media-usage-CdY5jhSR.mjs.map +0 -1
  1245. package/dist/media-usage-activation-BgeMtK5C.mjs +0 -78
  1246. package/dist/media-usage-activation-BgeMtK5C.mjs.map +0 -1
  1247. package/dist/media-usage-work-CnGCdHxx.mjs +0 -152
  1248. package/dist/media-usage-work-CnGCdHxx.mjs.map +0 -1
  1249. package/dist/media-usage-work-D6D9sMCA.mjs +0 -586
  1250. package/dist/media-usage-work-D6D9sMCA.mjs.map +0 -1
  1251. package/dist/media-usage-write-fence-hjeD4u7s.mjs +0 -42
  1252. package/dist/media-usage-write-fence-hjeD4u7s.mjs.map +0 -1
  1253. package/dist/menus-6qSwTNxG.mjs +0 -4010
  1254. package/dist/menus-6qSwTNxG.mjs.map +0 -1
  1255. package/dist/menus-uvPLXMZf.mjs +0 -744
  1256. package/dist/menus-uvPLXMZf.mjs.map +0 -1
  1257. package/dist/mime-CUIG6x84.mjs +0 -36
  1258. package/dist/mime-CUIG6x84.mjs.map +0 -1
  1259. package/dist/mode-DN_WneRx.mjs +0 -23
  1260. package/dist/mode-DN_WneRx.mjs.map +0 -1
  1261. package/dist/node-sqlite-compat-BuJXIeMz.mjs +0 -46
  1262. package/dist/node-sqlite-compat-BuJXIeMz.mjs.map +0 -1
  1263. package/dist/normalize-C2xNjTSG.mjs +0 -191
  1264. package/dist/normalize-C2xNjTSG.mjs.map +0 -1
  1265. package/dist/oauth-authorization-Dj6Kwc21.mjs +0 -274
  1266. package/dist/oauth-authorization-Dj6Kwc21.mjs.map +0 -1
  1267. package/dist/oauth-clients-FD7I0J8m.mjs +0 -266
  1268. package/dist/oauth-clients-FD7I0J8m.mjs.map +0 -1
  1269. package/dist/oauth-state-store-DkmDOmHs.mjs +0 -50
  1270. package/dist/oauth-state-store-DkmDOmHs.mjs.map +0 -1
  1271. package/dist/oauth-user-lookup-CvIwGpYd.mjs +0 -26
  1272. package/dist/oauth-user-lookup-CvIwGpYd.mjs.map +0 -1
  1273. package/dist/object-cache-DVKnyOfy.mjs +0 -534
  1274. package/dist/object-cache-DVKnyOfy.mjs.map +0 -1
  1275. package/dist/options-BHPeIbBd.mjs +0 -117
  1276. package/dist/options-BHPeIbBd.mjs.map +0 -1
  1277. package/dist/options-CYb4y7hM.d.mts +0 -221
  1278. package/dist/options-CYb4y7hM.d.mts.map +0 -1
  1279. package/dist/parse-Ckpg-Qfp.mjs +0 -81
  1280. package/dist/parse-Ckpg-Qfp.mjs.map +0 -1
  1281. package/dist/passkey-config-O_lj3y0k.mjs +0 -46
  1282. package/dist/passkey-config-O_lj3y0k.mjs.map +0 -1
  1283. package/dist/patterns-D9iDO3j8.mjs +0 -145
  1284. package/dist/patterns-D9iDO3j8.mjs.map +0 -1
  1285. package/dist/placeholder-4X9BrRrp.d.mts +0 -306
  1286. package/dist/placeholder-4X9BrRrp.d.mts.map +0 -1
  1287. package/dist/policy-Dhtwntrt.mjs +0 -45
  1288. package/dist/policy-Dhtwntrt.mjs.map +0 -1
  1289. package/dist/portable-text-U85hOafW.mjs +0 -286
  1290. package/dist/portable-text-U85hOafW.mjs.map +0 -1
  1291. package/dist/preview-B_vJLvf8.mjs +0 -107
  1292. package/dist/preview-B_vJLvf8.mjs.map +0 -1
  1293. package/dist/protocol-JdD2YhY9.d.mts +0 -52
  1294. package/dist/protocol-JdD2YhY9.d.mts.map +0 -1
  1295. package/dist/public-url-CarhZJgf.mjs +0 -101
  1296. package/dist/public-url-CarhZJgf.mjs.map +0 -1
  1297. package/dist/query-BZKZcG5b.mjs +0 -881
  1298. package/dist/query-BZKZcG5b.mjs.map +0 -1
  1299. package/dist/query-BndaFxxp.mjs +0 -41
  1300. package/dist/query-BndaFxxp.mjs.map +0 -1
  1301. package/dist/rate-limit-BZmATC6W.mjs +0 -120
  1302. package/dist/rate-limit-BZmATC6W.mjs.map +0 -1
  1303. package/dist/redirect-CZkbozu9.mjs +0 -313
  1304. package/dist/redirect-CZkbozu9.mjs.map +0 -1
  1305. package/dist/redirect-CzqnLxK-.mjs +0 -17
  1306. package/dist/redirect-CzqnLxK-.mjs.map +0 -1
  1307. package/dist/redirects-BLNOWQTn.mjs +0 -1238
  1308. package/dist/redirects-BLNOWQTn.mjs.map +0 -1
  1309. package/dist/redirects-CqzNM0KM.mjs +0 -579
  1310. package/dist/redirects-CqzNM0KM.mjs.map +0 -1
  1311. package/dist/registry-AZAsRsor.mjs +0 -1179
  1312. package/dist/registry-AZAsRsor.mjs.map +0 -1
  1313. package/dist/relation-04DfKRTO.mjs +0 -334
  1314. package/dist/relation-04DfKRTO.mjs.map +0 -1
  1315. package/dist/relations-C4htk5sb.mjs +0 -309
  1316. package/dist/relations-C4htk5sb.mjs.map +0 -1
  1317. package/dist/relations-CcFwDJdJ.mjs +0 -403
  1318. package/dist/relations-CcFwDJdJ.mjs.map +0 -1
  1319. package/dist/relations-DnRK4YIT.d.mts +0 -3354
  1320. package/dist/relations-DnRK4YIT.d.mts.map +0 -1
  1321. package/dist/request-cache-DH9zdCOD.mjs +0 -104
  1322. package/dist/request-cache-DH9zdCOD.mjs.map +0 -1
  1323. package/dist/request-meta-DYxLlnmz.mjs +0 -140
  1324. package/dist/request-meta-DYxLlnmz.mjs.map +0 -1
  1325. package/dist/resolve-prZ3mP7l.mjs +0 -143
  1326. package/dist/resolve-prZ3mP7l.mjs.map +0 -1
  1327. package/dist/runner-BLIDKpmA.mjs +0 -4676
  1328. package/dist/runner-BLIDKpmA.mjs.map +0 -1
  1329. package/dist/runner-YKfIMnaF.d.mts +0 -67
  1330. package/dist/runner-YKfIMnaF.d.mts.map +0 -1
  1331. package/dist/schema-CGnBeLiW.mjs +0 -9
  1332. package/dist/schema-CGnBeLiW.mjs.map +0 -1
  1333. package/dist/schema-DYr-Vd-L.mjs +0 -420
  1334. package/dist/schema-DYr-Vd-L.mjs.map +0 -1
  1335. package/dist/scopes-BhWvBavj.mjs +0 -27
  1336. package/dist/scopes-BhWvBavj.mjs.map +0 -1
  1337. package/dist/search-C-qDk4kx.mjs +0 -439
  1338. package/dist/search-C-qDk4kx.mjs.map +0 -1
  1339. package/dist/secrets-rEtHt-6z.mjs +0 -330
  1340. package/dist/secrets-rEtHt-6z.mjs.map +0 -1
  1341. package/dist/sections-B_nYvlwn.mjs +0 -346
  1342. package/dist/sections-B_nYvlwn.mjs.map +0 -1
  1343. package/dist/seo-926NRIgt.mjs +0 -133
  1344. package/dist/seo-926NRIgt.mjs.map +0 -1
  1345. package/dist/seo-CVWkdv6x.mjs +0 -113
  1346. package/dist/seo-CVWkdv6x.mjs.map +0 -1
  1347. package/dist/service-CJl3ZAYs.mjs +0 -195
  1348. package/dist/service-CJl3ZAYs.mjs.map +0 -1
  1349. package/dist/session-user-BlMgqCHS.mjs +0 -51
  1350. package/dist/session-user-BlMgqCHS.mjs.map +0 -1
  1351. package/dist/settings--wobrkkC.mjs +0 -258
  1352. package/dist/settings--wobrkkC.mjs.map +0 -1
  1353. package/dist/settings-Cwm6o2jY.mjs +0 -51
  1354. package/dist/settings-Cwm6o2jY.mjs.map +0 -1
  1355. package/dist/setup-complete-DQbClIN2.mjs +0 -26
  1356. package/dist/setup-complete-DQbClIN2.mjs.map +0 -1
  1357. package/dist/setup-nonce-DZCFS2sn.mjs +0 -25
  1358. package/dist/setup-nonce-DZCFS2sn.mjs.map +0 -1
  1359. package/dist/single-flight-cache-BPuGPdcN.mjs +0 -104
  1360. package/dist/single-flight-cache-BPuGPdcN.mjs.map +0 -1
  1361. package/dist/site-url-BrxA_E9H.mjs +0 -16
  1362. package/dist/site-url-BrxA_E9H.mjs.map +0 -1
  1363. package/dist/slugify-B994zkXC.mjs +0 -17
  1364. package/dist/slugify-B994zkXC.mjs.map +0 -1
  1365. package/dist/snapshot--OCDTqdb.mjs +0 -216
  1366. package/dist/snapshot--OCDTqdb.mjs.map +0 -1
  1367. package/dist/ssrf-5sIM5jzl.mjs +0 -349
  1368. package/dist/ssrf-5sIM5jzl.mjs.map +0 -1
  1369. package/dist/state-BpFVsJZB.mjs +0 -136
  1370. package/dist/state-BpFVsJZB.mjs.map +0 -1
  1371. package/dist/status-B777-dXz.mjs +0 -30
  1372. package/dist/status-B777-dXz.mjs.map +0 -1
  1373. package/dist/target-BmR0iTwz.mjs +0 -27
  1374. package/dist/target-BmR0iTwz.mjs.map +0 -1
  1375. package/dist/taxonomies-DkAkMupr.mjs +0 -837
  1376. package/dist/taxonomies-DkAkMupr.mjs.map +0 -1
  1377. package/dist/taxonomies-Wfy_Lg12.mjs +0 -698
  1378. package/dist/taxonomies-Wfy_Lg12.mjs.map +0 -1
  1379. package/dist/taxonomy-tJepplLL.mjs +0 -484
  1380. package/dist/taxonomy-tJepplLL.mjs.map +0 -1
  1381. package/dist/tokens-BCO1oruF.mjs +0 -171
  1382. package/dist/tokens-BCO1oruF.mjs.map +0 -1
  1383. package/dist/transaction-0KOpOyMu.mjs +0 -29
  1384. package/dist/transaction-0KOpOyMu.mjs.map +0 -1
  1385. package/dist/transport-Dr3qtwXC.mjs +0 -136
  1386. package/dist/transport-Dr3qtwXC.mjs.map +0 -1
  1387. package/dist/transport-xh6YKW2G.d.mts +0 -42
  1388. package/dist/transport-xh6YKW2G.d.mts.map +0 -1
  1389. package/dist/trusted-proxy-BR5F1Otp.mjs +0 -51
  1390. package/dist/trusted-proxy-BR5F1Otp.mjs.map +0 -1
  1391. package/dist/types-3qNFPlci.mjs +0 -16
  1392. package/dist/types-3qNFPlci.mjs.map +0 -1
  1393. package/dist/types-75KIqzL9.mjs +0 -142
  1394. package/dist/types-75KIqzL9.mjs.map +0 -1
  1395. package/dist/types-B6GrPic4.d.mts +0 -1335
  1396. package/dist/types-B6GrPic4.d.mts.map +0 -1
  1397. package/dist/types-BuHW4xDE.d.mts +0 -259
  1398. package/dist/types-BuHW4xDE.d.mts.map +0 -1
  1399. package/dist/types-C00oyCZp.d.mts +0 -198
  1400. package/dist/types-C00oyCZp.d.mts.map +0 -1
  1401. package/dist/types-CDtkNSFQ.d.mts +0 -75
  1402. package/dist/types-CDtkNSFQ.d.mts.map +0 -1
  1403. package/dist/types-CPeXo1wF.d.mts +0 -124
  1404. package/dist/types-CPeXo1wF.d.mts.map +0 -1
  1405. package/dist/types-CQPWhPxE.mjs +0 -92
  1406. package/dist/types-CQPWhPxE.mjs.map +0 -1
  1407. package/dist/types-CXFkwEGC.d.mts +0 -198
  1408. package/dist/types-CXFkwEGC.d.mts.map +0 -1
  1409. package/dist/types-DM3vioBY.mjs +0 -18
  1410. package/dist/types-DM3vioBY.mjs.map +0 -1
  1411. package/dist/types-DczELMop.d.mts +0 -363
  1412. package/dist/types-DczELMop.d.mts.map +0 -1
  1413. package/dist/types-DfuTR6dL.mjs +0 -3
  1414. package/dist/types-FV23hEoW.d.mts +0 -743
  1415. package/dist/types-FV23hEoW.d.mts.map +0 -1
  1416. package/dist/types-xDMtUFnO.d.mts +0 -257
  1417. package/dist/types-xDMtUFnO.d.mts.map +0 -1
  1418. package/dist/upload-attempts-BsqoQ1fn.mjs +0 -27
  1419. package/dist/upload-attempts-BsqoQ1fn.mjs.map +0 -1
  1420. package/dist/url-pattern-D4c2czpJ.mjs +0 -33
  1421. package/dist/url-pattern-D4c2czpJ.mjs.map +0 -1
  1422. package/dist/user-BTZ40aq6.mjs +0 -171
  1423. package/dist/user-BTZ40aq6.mjs.map +0 -1
  1424. package/dist/utils-BKvNjjhY.mjs +0 -435
  1425. package/dist/utils-BKvNjjhY.mjs.map +0 -1
  1426. package/dist/validate-BpwoDOgt.mjs +0 -120
  1427. package/dist/validate-BpwoDOgt.mjs.map +0 -1
  1428. package/dist/validate-DE_LRwo9.mjs +0 -379
  1429. package/dist/validate-DE_LRwo9.mjs.map +0 -1
  1430. package/dist/validate-DUP27OYD.d.mts +0 -400
  1431. package/dist/validate-DUP27OYD.d.mts.map +0 -1
  1432. package/dist/validation-BMImFJ11.mjs +0 -153
  1433. package/dist/validation-BMImFJ11.mjs.map +0 -1
  1434. package/dist/version-Bii3suaO.mjs +0 -7
  1435. package/dist/version-Bii3suaO.mjs.map +0 -1
  1436. package/dist/widgets-D3gJ10xU.mjs +0 -122
  1437. package/dist/widgets-D3gJ10xU.mjs.map +0 -1
  1438. package/dist/wxr-taxonomies-B2Og_6rU.d.mts +0 -34
  1439. package/dist/wxr-taxonomies-B2Og_6rU.d.mts.map +0 -1
  1440. package/dist/wxr-taxonomies-Cxngsjwo.mjs +0 -406
  1441. package/dist/wxr-taxonomies-Cxngsjwo.mjs.map +0 -1
  1442. package/dist/zod-generator-BuYSQJB7.mjs +0 -331
  1443. package/dist/zod-generator-BuYSQJB7.mjs.map +0 -1
  1444. /package/dist/{api-tokens-BfYts-sq.mjs → api-tokens-DS1VzN7_.mjs} +0 -0
  1445. /package/dist/{ssrf-Dg3cIT-b.mjs → ssrf-BRpTDMV6.mjs} +0 -0
@@ -0,0 +1,2216 @@
1
+ import { u as __exportAll } from "./runner-ClrleR8A.mjs";
2
+ import { n as isMissingTableError } from "./db-errors-CBD5yMro.mjs";
3
+ import { t as validateIdentifier } from "./validate-DANX1-Qi.mjs";
4
+ import { s as executeAtomicBatchIfSupported } from "./dialect-helpers-CtYdsX4W.mjs";
5
+ import { i as normalizeExplicitDatetime, n as normalizeContentDatetimes, r as normalizeDatetime, t as DatetimeNormalizationError } from "./datetime-normalization-PeiEdcRY.mjs";
6
+ import { c as invalidateCollectionCache } from "./object-cache-DlSVbn5Y.mjs";
7
+ import { u as isIndexableFieldType } from "./types-B3RkqvDW.mjs";
8
+ import { n as chunks, t as SQL_BATCH_SIZE } from "./chunks-BmWyou79.mjs";
9
+ import { n as slugify } from "./slugify-T5GHH42D.mjs";
10
+ import { a as ScheduledNotDueError, i as InvalidCursorError, n as ContentMutationConflictError, o as decodeCursor, r as EmDashValidationError, s as encodeCursor, t as ContentCollectionNotFoundError } from "./types-BkUg2yHx.mjs";
11
+ import { t as withTransaction } from "./transaction-BcJO4Tmc.mjs";
12
+ import { sql } from "kysely";
13
+ import { monotonicFactory, ulid } from "ulidx";
14
+
15
+ //#region src/content/known-fields.ts
16
+ /**
17
+ * Reconcile an entry's keys with the fields its collection currently declares.
18
+ *
19
+ * A draft revision stores the whole `data` as JSON, so deleting a field leaves the old
20
+ * value inside the revision. Every content-write surface needs the same two rules to keep
21
+ * that from stranding the entry, so they live here rather than in one caller.
22
+ */
23
+ /** Keys EmDash reserves (`_slug` and the like). No field declares them. */
24
+ function isReservedKey(key) {
25
+ return key.startsWith("_");
26
+ }
27
+ /**
28
+ * The entry data without the keys the collection has no field for.
29
+ *
30
+ * Reserved keys are kept.
31
+ */
32
+ function keepKnownFields(data, knownFieldSlugs) {
33
+ const result = {};
34
+ for (const [key, value] of Object.entries(data)) if (isReservedKey(key) || knownFieldSlugs.has(key)) result[key] = value;
35
+ return result;
36
+ }
37
+ /**
38
+ * Incoming keys with no matching field that the entry already stores.
39
+ *
40
+ * Dropping these lets a read-then-write save succeed after the field was deleted. A key the
41
+ * entry has never stored is not returned, so a genuinely unknown field is still reported.
42
+ */
43
+ function staleStoredKeys(data, stored, knownFieldSlugs) {
44
+ return Object.keys(data).filter((key) => !isReservedKey(key) && !knownFieldSlugs.has(key) && Object.hasOwn(stored, key));
45
+ }
46
+
47
+ //#endregion
48
+ //#region src/search/match.ts
49
+ /**
50
+ * FTS5 match-expression builder for structured (non-user-syntax) queries.
51
+ *
52
+ * Unlike `escapeQuery` in `query.ts` (which powers the public search API and
53
+ * deliberately passes through FTS5 operators like AND/OR/NOT), this builder
54
+ * treats the input as plain words: every term is double-quoted with interior
55
+ * quotes escaped, so the result can never produce an FTS5 syntax error. Used
56
+ * by the admin content-list filter, where the input is a filter box, not a
57
+ * search-syntax field.
58
+ */
59
+ const WHITESPACE_RE = /\s+/;
60
+ const DOUBLE_QUOTE_RE = /"/g;
61
+ const GLOB_SPECIAL_RE = /[[\]*?]/g;
62
+ /**
63
+ * Build a prefix-matching FTS5 MATCH expression from free-form input.
64
+ *
65
+ * `hello wor` becomes `"hello"* "wor"*` — implicit AND with per-term prefix
66
+ * matching. Returns `""` when the input contains no usable terms; callers
67
+ * must fall back to their non-FTS path in that case.
68
+ */
69
+ function buildFtsPrefixMatch(input) {
70
+ const terms = input.trim().split(WHITESPACE_RE).map((term) => term.replace(DOUBLE_QUOTE_RE, "\"\"")).filter((term) => term.length > 0);
71
+ if (terms.length === 0) return "";
72
+ return terms.map((term) => `"${term}"*`).join(" ");
73
+ }
74
+ /**
75
+ * Build a GLOB prefix pattern from free-form input, treating GLOB
76
+ * metacharacters (`* ? [ ]`) literally by wrapping each in a character
77
+ * class (GLOB has no ESCAPE clause).
78
+ *
79
+ * GLOB (unlike default LIKE) is case-sensitive, so with a lowercased
80
+ * pattern it matches slugs (lowercase by construction) while staying
81
+ * servable by the ordinary BINARY-collated slug index — SQLite's GLOB
82
+ * optimization turns a `prefix*` pattern into an index range scan.
83
+ */
84
+ function buildSlugGlobPrefix(input) {
85
+ return `${input.trim().toLowerCase().replace(GLOB_SPECIAL_RE, (c) => `[${c}]`)}*`;
86
+ }
87
+
88
+ //#endregion
89
+ //#region src/database/content-datetime.ts
90
+ function repeaterDatetimeFields(validation) {
91
+ if (!validation) return [];
92
+ let parsed;
93
+ try {
94
+ parsed = JSON.parse(validation);
95
+ } catch {
96
+ return [];
97
+ }
98
+ if (typeof parsed !== "object" || parsed === null || !("subFields" in parsed)) return [];
99
+ const subFields = parsed.subFields;
100
+ if (!Array.isArray(subFields)) return [];
101
+ return subFields.filter((field) => typeof field === "object" && field !== null && "type" in field && field.type === "datetime" && "slug" in field && typeof field.slug === "string").map((field) => field.slug);
102
+ }
103
+ var ContentDatetimeNormalizer = class {
104
+ constructor(db) {
105
+ this.db = db;
106
+ }
107
+ context(collection) {
108
+ return this.loadContext(collection);
109
+ }
110
+ async loadContext(collection) {
111
+ const [rows, timezoneRow] = await Promise.all([this.db.selectFrom("_emdash_fields as field").innerJoin("_emdash_collections as collection", "collection.id", "field.collection_id").select([
112
+ "field.slug",
113
+ "field.type",
114
+ "field.validation"
115
+ ]).where("collection.slug", "=", collection).where("field.type", "in", ["datetime", "repeater"]).execute(), this.db.selectFrom("options").select("value").where("name", "=", "site:timezone").executeTakeFirst()]);
116
+ let timezone = "UTC";
117
+ if (timezoneRow) try {
118
+ const configured = JSON.parse(timezoneRow.value);
119
+ if (typeof configured === "string" && configured) timezone = configured;
120
+ } catch {}
121
+ return {
122
+ timezone,
123
+ fields: rows.map((row) => row.type === "datetime" ? {
124
+ slug: row.slug,
125
+ type: "datetime"
126
+ } : {
127
+ slug: row.slug,
128
+ type: "repeater",
129
+ datetimeSubFields: repeaterDatetimeFields(row.validation)
130
+ })
131
+ };
132
+ }
133
+ async normalizeData(collection, data) {
134
+ const [normalized] = await this.normalizeDataMany(collection, [data]);
135
+ return normalized ?? data;
136
+ }
137
+ async normalizeDataMany(collection, items) {
138
+ const context = await this.context(collection);
139
+ try {
140
+ return items.map((data) => normalizeContentDatetimes(data, context.fields, context.timezone).value);
141
+ } catch (error) {
142
+ if (error instanceof DatetimeNormalizationError) throw new EmDashValidationError(error.message);
143
+ throw error;
144
+ }
145
+ }
146
+ async normalizeValue(collection, value) {
147
+ const context = await this.context(collection);
148
+ try {
149
+ return normalizeDatetime(value, context.timezone).value;
150
+ } catch (error) {
151
+ if (error instanceof DatetimeNormalizationError) throw new EmDashValidationError(error.message);
152
+ throw error;
153
+ }
154
+ }
155
+ };
156
+
157
+ //#endregion
158
+ //#region src/database/repositories/revision.ts
159
+ const monotonic = monotonicFactory();
160
+ function createRevisionId() {
161
+ return monotonic();
162
+ }
163
+ function normalizeRevisionLimit(value) {
164
+ const numeric = Number(value);
165
+ if (!Number.isFinite(numeric)) return 50;
166
+ return Math.max(1, Math.min(Math.trunc(numeric), 100));
167
+ }
168
+ /**
169
+ * Revision repository for version history
170
+ *
171
+ * Each revision stores a JSON snapshot of the content at a point in time.
172
+ * Used when collection has `supports: ["revisions"]` enabled.
173
+ */
174
+ var RevisionRepository = class {
175
+ datetimes;
176
+ constructor(db) {
177
+ this.db = db;
178
+ this.datetimes = new ContentDatetimeNormalizer(db);
179
+ }
180
+ /**
181
+ * Create a new revision
182
+ */
183
+ async create(input) {
184
+ const id = createRevisionId();
185
+ const data = await this.datetimes.normalizeData(input.collection, input.data);
186
+ const row = {
187
+ id,
188
+ collection: input.collection,
189
+ entry_id: input.entryId,
190
+ data: JSON.stringify(data),
191
+ author_id: input.authorId ?? null
192
+ };
193
+ await this.db.insertInto("revisions").values(row).execute();
194
+ const revision = await this.findById(id);
195
+ if (!revision) throw new Error("Failed to create revision");
196
+ await this.queuePruning(input.collection, input.entryId, id);
197
+ return revision;
198
+ }
199
+ async queuePruning(collection, entryId, revisionId) {
200
+ try {
201
+ await this.db.insertInto("_emdash_revision_prune_queue").values({
202
+ collection,
203
+ entry_id: entryId,
204
+ revision_id: revisionId
205
+ }).onConflict((conflict) => conflict.columns(["collection", "entry_id"]).doUpdateSet({ revision_id: revisionId })).execute();
206
+ } catch (error) {
207
+ console.error(`[revisions] Failed to queue revision pruning for ${collection}/${entryId}:`, error);
208
+ }
209
+ }
210
+ /**
211
+ * Find revision by ID
212
+ */
213
+ async findById(id) {
214
+ const row = await this.db.selectFrom("revisions").selectAll().where("id", "=", id).executeTakeFirst();
215
+ return row ? this.normalizeRow(row) : null;
216
+ }
217
+ /**
218
+ * Get all revisions for an entry (newest first)
219
+ *
220
+ * Orders by monotonic ULID (descending). The monotonic factory
221
+ * guarantees strictly increasing IDs even within the same millisecond.
222
+ */
223
+ async findByEntry(collection, entryId, options = {}) {
224
+ let query = this.db.selectFrom("revisions").selectAll().where("collection", "=", collection).where("entry_id", "=", entryId).orderBy("id", "desc");
225
+ if (options.limit) query = query.limit(options.limit);
226
+ const rows = await query.execute();
227
+ const data = await this.datetimes.normalizeDataMany(collection, rows.map((row) => JSON.parse(row.data)));
228
+ return rows.map((row, index) => {
229
+ const normalized = data[index];
230
+ if (!normalized) throw new Error("Failed to normalize revision data");
231
+ return this.rowToRevision(row, normalized);
232
+ });
233
+ }
234
+ /** Read revisions only when the owning content row is visible in the same statement snapshot. */
235
+ async findVisibleByEntry(collection, entryId, options = {}) {
236
+ validateIdentifier(collection, "collection");
237
+ const tableName = `ec_${collection}`;
238
+ const limit = normalizeRevisionLimit(options.limit);
239
+ const result = await sql`
240
+ SELECT revisions.* FROM revisions
241
+ WHERE revisions.collection = ${collection}
242
+ AND revisions.entry_id = ${entryId}
243
+ AND EXISTS (
244
+ SELECT 1 FROM ${sql.ref(tableName)} AS content
245
+ WHERE content.id = ${entryId}
246
+ AND content.deleted_at IS NULL
247
+ )
248
+ ORDER BY revisions.id DESC
249
+ LIMIT ${limit}
250
+ `.execute(this.db);
251
+ const data = await this.datetimes.normalizeDataMany(collection, result.rows.map((row) => JSON.parse(row.data)));
252
+ return result.rows.map((row, index) => {
253
+ const normalized = data[index];
254
+ if (!normalized) throw new Error("Failed to normalize revision data");
255
+ return this.rowToRevision(row, normalized);
256
+ });
257
+ }
258
+ /** Read one revision only when its owning content row is visible in the same statement snapshot. */
259
+ async findVisibleById(collection, entryId, revisionId) {
260
+ validateIdentifier(collection, "collection");
261
+ const tableName = `ec_${collection}`;
262
+ const row = (await sql`
263
+ SELECT revisions.* FROM revisions
264
+ WHERE revisions.id = ${revisionId}
265
+ AND revisions.collection = ${collection}
266
+ AND revisions.entry_id = ${entryId}
267
+ AND EXISTS (
268
+ SELECT 1 FROM ${sql.ref(tableName)} AS content
269
+ WHERE content.id = ${entryId}
270
+ AND content.deleted_at IS NULL
271
+ )
272
+ LIMIT 1
273
+ `.execute(this.db)).rows[0];
274
+ return row ? this.normalizeRow(row) : null;
275
+ }
276
+ /**
277
+ * Get the most recent revision for an entry
278
+ */
279
+ async findLatest(collection, entryId) {
280
+ const row = await this.db.selectFrom("revisions").selectAll().where("collection", "=", collection).where("entry_id", "=", entryId).orderBy("id", "desc").limit(1).executeTakeFirst();
281
+ return row ? this.normalizeRow(row) : null;
282
+ }
283
+ /**
284
+ * Count revisions for an entry
285
+ */
286
+ async countByEntry(collection, entryId) {
287
+ const result = await this.db.selectFrom("revisions").select((eb) => eb.fn.count("id").as("count")).where("collection", "=", collection).where("entry_id", "=", entryId).executeTakeFirst();
288
+ return Number(result?.count || 0);
289
+ }
290
+ /**
291
+ * Delete all revisions for an entry (use when entry is deleted)
292
+ */
293
+ async deleteByEntry(collection, entryId) {
294
+ const result = await this.db.deleteFrom("revisions").where("collection", "=", collection).where("entry_id", "=", entryId).executeTakeFirst();
295
+ try {
296
+ await this.db.deleteFrom("_emdash_revision_prune_queue").where("collection", "=", collection).where("entry_id", "=", entryId).execute();
297
+ } catch (error) {
298
+ console.error(`[revisions] Failed to clear queued revision pruning for ${collection}/${entryId}:`, error);
299
+ }
300
+ return Number(result.numDeletedRows ?? 0);
301
+ }
302
+ /**
303
+ * Delete old revisions, keeping the most recent N
304
+ */
305
+ async pruneOldRevisions(collection, entryId, keepCount, throughRevisionId) {
306
+ validateIdentifier(collection, "collection");
307
+ const tableName = `ec_${collection}`;
308
+ let keepQuery = this.db.selectFrom("revisions").select("id").where("collection", "=", collection).where("entry_id", "=", entryId).orderBy("created_at", "desc").orderBy("id", "desc").limit(keepCount);
309
+ if (throughRevisionId) keepQuery = keepQuery.where("id", "<=", throughRevisionId);
310
+ const keepIds = (await keepQuery.execute()).map((r) => r.id);
311
+ if (keepIds.length === 0) return 0;
312
+ const result = await sql`
313
+ DELETE FROM revisions
314
+ WHERE collection = ${collection}
315
+ AND entry_id = ${entryId}
316
+ ${throughRevisionId ? sql`AND id <= ${throughRevisionId}` : sql``}
317
+ AND id NOT IN (${sql.join(keepIds.map((id) => sql`${id}`))})
318
+ AND NOT EXISTS (
319
+ SELECT 1 FROM ${sql.ref(tableName)} AS content
320
+ WHERE content.live_revision_id = revisions.id
321
+ OR content.draft_revision_id = revisions.id
322
+ )
323
+ `.execute(this.db);
324
+ return Number(result.numAffectedRows ?? 0);
325
+ }
326
+ async pruneQueuedEntry(collection, entryId, queuedRevisionId, keepCount) {
327
+ const pruned = await this.pruneOldRevisions(collection, entryId, keepCount, queuedRevisionId);
328
+ await this.db.deleteFrom("_emdash_revision_prune_queue").where("collection", "=", collection).where("entry_id", "=", entryId).where("revision_id", "=", queuedRevisionId).execute();
329
+ return pruned;
330
+ }
331
+ async deleteIfUnreferenced(collection, entryId, revisionId) {
332
+ validateIdentifier(collection, "collection");
333
+ const tableName = `ec_${collection}`;
334
+ return ((await sql`
335
+ DELETE FROM revisions
336
+ WHERE id = ${revisionId}
337
+ AND collection = ${collection}
338
+ AND entry_id = ${entryId}
339
+ AND NOT EXISTS (
340
+ SELECT 1 FROM ${sql.ref(tableName)} AS content
341
+ WHERE content.live_revision_id = revisions.id
342
+ OR content.draft_revision_id = revisions.id
343
+ )
344
+ `.execute(this.db)).numAffectedRows ?? 0n) > 0n;
345
+ }
346
+ /**
347
+ * Convert database row to Revision object
348
+ */
349
+ async normalizeRow(row) {
350
+ const data = await this.datetimes.normalizeData(row.collection, JSON.parse(row.data));
351
+ return this.rowToRevision(row, data);
352
+ }
353
+ rowToRevision(row, data) {
354
+ return {
355
+ id: row.id,
356
+ collection: row.collection,
357
+ entryId: row.entry_id,
358
+ data,
359
+ authorId: row.author_id,
360
+ createdAt: row.created_at
361
+ };
362
+ }
363
+ };
364
+
365
+ //#endregion
366
+ //#region src/database/repositories/content.ts
367
+ var content_exports = /* @__PURE__ */ __exportAll({
368
+ ContentRepository: () => ContentRepository,
369
+ isConfirmedStatementFailure: () => isConfirmedStatementFailure,
370
+ isSystemOrderField: () => isSystemOrderField
371
+ });
372
+ const ULID_PATTERN = /^[0-9A-Z]{26}$/;
373
+ const SQLSTATE_PATTERN = /^[0-9A-Z]{5}$/;
374
+ const MAX_DRAFT_STAGE_ATTEMPTS = 32;
375
+ const LIKE_WILDCARD_RE = /[\\%_]/g;
376
+ const MAX_INDEXED_FIELD_FILTERS = 20;
377
+ const MAX_IN_FILTER_VALUES = SQL_BATCH_SIZE;
378
+ const MAX_FILTER_STRING_LENGTH = 2048;
379
+ function assertRevisionPrecondition(item, expected) {
380
+ if (expected && (item.version !== expected.version || item.updatedAt !== expected.updatedAt)) throw new ContentMutationConflictError();
381
+ }
382
+ function nullableColumnMatch(column, value) {
383
+ validateIdentifier(column, "content column");
384
+ return value === null ? sql`${sql.ref(column)} IS NULL` : sql`${sql.ref(column)} = ${value}`;
385
+ }
386
+ function sameStoredValue(left, right) {
387
+ return Object.is(serializeValue(left), serializeValue(right));
388
+ }
389
+ function matchesPublication(observed, existing, revision, revisionId, slug, publishedAt, updatedAt) {
390
+ if (observed.version !== existing.version + 1 || observed.status !== "published" || observed.slug !== slug || observed.liveRevisionId !== revisionId || observed.draftRevisionId !== null || observed.scheduledAt !== null || observed.publishedAt !== publishedAt || observed.updatedAt !== updatedAt) return false;
391
+ return Object.entries(revision.data).every(([key, value]) => SYSTEM_COLUMNS.has(key) || key.startsWith("_") || sameStoredValue(observed.data[key], value));
392
+ }
393
+ function matchesLifecyclePublication(observed, existing, liveRevisionId, publishedAt, updatedAt) {
394
+ if (observed.version !== existing.version + 1 || observed.status !== "published" || observed.slug !== existing.slug || observed.liveRevisionId !== liveRevisionId || observed.draftRevisionId !== null || observed.scheduledAt !== null || observed.publishedAt !== publishedAt || observed.updatedAt !== updatedAt) return false;
395
+ return Object.entries(existing.data).every(([key, value]) => sameStoredValue(observed.data[key], value));
396
+ }
397
+ function matchesPublicationFence(observed, existing) {
398
+ return observed.version === existing.version && observed.status === existing.status && observed.liveRevisionId === existing.liveRevisionId && observed.draftRevisionId === existing.draftRevisionId && observed.scheduledAt === existing.scheduledAt;
399
+ }
400
+ function isConfirmedStatementFailure(error) {
401
+ if (typeof error !== "object" || error === null || !("code" in error)) return false;
402
+ const code = error.code;
403
+ return typeof code === "string" && (code === "ERR_SQLITE_ERROR" || code.startsWith("SQLITE_") || SQLSTATE_PATTERN.test(code));
404
+ }
405
+ function encodeIndexedFieldCursor(field, value, id) {
406
+ const payload = {
407
+ version: 1,
408
+ field,
409
+ value
410
+ };
411
+ return encodeCursor(JSON.stringify(payload), id);
412
+ }
413
+ function decodeIndexedFieldCursor(cursor, field) {
414
+ const { orderValue, id } = decodeCursor(cursor);
415
+ let payload;
416
+ try {
417
+ payload = JSON.parse(orderValue);
418
+ } catch {
419
+ throw new InvalidCursorError(cursor);
420
+ }
421
+ if (payload === null || typeof payload !== "object") throw new InvalidCursorError(cursor);
422
+ const candidate = payload;
423
+ const validValue = candidate.value === null || typeof candidate.value === "string" || typeof candidate.value === "number";
424
+ if (candidate.version !== 1 || candidate.field !== field || !validValue) throw new InvalidCursorError(cursor);
425
+ return {
426
+ value: candidate.value,
427
+ id
428
+ };
429
+ }
430
+ /**
431
+ * Whitelist mapping a public date-filter field to its physical column. Keeping
432
+ * this separate from `mapOrderField` makes the filterable set explicit and
433
+ * prevents filtering on arbitrary columns.
434
+ */
435
+ const DATE_FILTER_COLUMNS = {
436
+ createdAt: "created_at",
437
+ updatedAt: "updated_at",
438
+ publishedAt: "published_at"
439
+ };
440
+ /**
441
+ * Built-in sort fields → their physical columns. A closed set that blocks
442
+ * sorting by arbitrary columns; per-collection fields are allowed
443
+ * separately via `mapOrderField`'s `sortableExtras`.
444
+ */
445
+ const ORDER_FIELD_COLUMNS = {
446
+ createdAt: "created_at",
447
+ updatedAt: "updated_at",
448
+ publishedAt: "published_at",
449
+ scheduledAt: "scheduled_at",
450
+ deletedAt: "deleted_at",
451
+ title: "title",
452
+ name: "name",
453
+ slug: "slug",
454
+ status: "status",
455
+ locale: "locale"
456
+ };
457
+ /** True when `field` maps to a system column and needs no per-collection resolution. */
458
+ function isSystemOrderField(field) {
459
+ return field in ORDER_FIELD_COLUMNS;
460
+ }
461
+ /**
462
+ * System columns that exist in every ec_* table
463
+ */
464
+ const SYSTEM_COLUMNS = new Set([
465
+ "id",
466
+ "slug",
467
+ "status",
468
+ "author_id",
469
+ "primary_byline_id",
470
+ "created_at",
471
+ "updated_at",
472
+ "published_at",
473
+ "scheduled_at",
474
+ "deleted_at",
475
+ "version",
476
+ "live_revision_id",
477
+ "draft_revision_id",
478
+ "locale",
479
+ "translation_group"
480
+ ]);
481
+ /**
482
+ * Get the table name for a collection type
483
+ */
484
+ function getTableName(type) {
485
+ validateIdentifier(type, "collection type");
486
+ return `ec_${type}`;
487
+ }
488
+ /**
489
+ * Serialize a value for database storage
490
+ * Objects/arrays are JSON-stringified
491
+ * Booleans are converted to 0/1 for SQLite
492
+ */
493
+ function serializeValue(value) {
494
+ if (value === null || value === void 0) return null;
495
+ if (typeof value === "boolean") return value ? 1 : 0;
496
+ if (typeof value === "object") return JSON.stringify(value);
497
+ return value;
498
+ }
499
+ function writableContentData(data) {
500
+ const writable = {};
501
+ for (const [key, value] of Object.entries(data)) {
502
+ if (SYSTEM_COLUMNS.has(key)) continue;
503
+ validateIdentifier(key, "content field name");
504
+ writable[key] = value;
505
+ }
506
+ return writable;
507
+ }
508
+ /**
509
+ * Deserialize a value from database storage
510
+ * Attempts to parse JSON strings that look like objects/arrays
511
+ */
512
+ function deserializeValue(value) {
513
+ if (typeof value === "string") {
514
+ if (value.startsWith("{") || value.startsWith("[")) try {
515
+ return JSON.parse(value);
516
+ } catch {
517
+ return value;
518
+ }
519
+ }
520
+ return value;
521
+ }
522
+ /** Pattern for escaping special regex characters */
523
+ const REGEX_ESCAPE_PATTERN = /[.*+?^${}()|[\]\\]/g;
524
+ /**
525
+ * Escape special regex characters in a string for use in `new RegExp()`
526
+ */
527
+ function escapeRegExp(s) {
528
+ return s.replace(REGEX_ESCAPE_PATTERN, "\\$&");
529
+ }
530
+ /**
531
+ * Repository for content CRUD operations
532
+ *
533
+ * Content is stored in per-collection tables (ec_posts, ec_pages, etc.)
534
+ * Each field becomes a real column in the table.
535
+ */
536
+ var ContentRepository = class {
537
+ datetimes;
538
+ constructor(db) {
539
+ this.db = db;
540
+ this.datetimes = new ContentDatetimeNormalizer(db);
541
+ }
542
+ /**
543
+ * Create a new content item
544
+ */
545
+ async create(input) {
546
+ const id = input.id ?? ulid();
547
+ const now = (/* @__PURE__ */ new Date()).toISOString();
548
+ const { type, slug, data: inputData, status = "draft", authorId, primaryBylineId, locale, translationOf, inheritFields = [], publishedAt, createdAt } = input;
549
+ const data = await this.datetimes.normalizeData(type, inputData);
550
+ const normalizedCreatedAt = createdAt ? await this.datetimes.normalizeValue(type, createdAt) : now;
551
+ const normalizedPublishedAt = publishedAt ? await this.datetimes.normalizeValue(type, publishedAt) : null;
552
+ if (!type) throw new EmDashValidationError("Content type is required");
553
+ const tableName = getTableName(type);
554
+ const columns = [
555
+ "id",
556
+ "slug",
557
+ "status",
558
+ "author_id",
559
+ "primary_byline_id",
560
+ "created_at",
561
+ "updated_at",
562
+ "published_at",
563
+ "version",
564
+ "locale",
565
+ "translation_group"
566
+ ];
567
+ const values = [
568
+ id,
569
+ slug || null,
570
+ status,
571
+ authorId || null,
572
+ primaryBylineId ?? null,
573
+ normalizedCreatedAt,
574
+ now,
575
+ normalizedPublishedAt,
576
+ 1,
577
+ locale || "en",
578
+ id
579
+ ];
580
+ const inherited = new Set(inheritFields);
581
+ for (const field of inherited) {
582
+ validateIdentifier(field, "inherited content field name");
583
+ if (!SYSTEM_COLUMNS.has(field) && !Object.hasOwn(data, field)) {
584
+ columns.push(field);
585
+ values.push(null);
586
+ }
587
+ }
588
+ if (data && typeof data === "object") {
589
+ for (const [key, value] of Object.entries(data)) if (!SYSTEM_COLUMNS.has(key)) {
590
+ validateIdentifier(key, "content field name");
591
+ columns.push(key);
592
+ values.push(serializeValue(value));
593
+ }
594
+ }
595
+ const columnRefs = columns.map((c) => sql.ref(c));
596
+ const valuePlaceholders = values.map((value, index) => {
597
+ const column = columns[index];
598
+ if (translationOf && column === "translation_group") return sql`COALESCE(${sql.ref("translation_source.translation_group")}, ${sql.ref("translation_source.id")})`;
599
+ if (translationOf && inherited.has(column)) return sql.ref(`translation_source.${column}`);
600
+ return value === null ? sql`NULL` : sql`${value}`;
601
+ });
602
+ if (translationOf) await sql`
603
+ INSERT INTO ${sql.ref(tableName)} (${sql.join(columnRefs, sql`, `)})
604
+ SELECT ${sql.join(valuePlaceholders, sql`, `)}
605
+ FROM ${sql.ref(tableName)} AS translation_source
606
+ WHERE translation_source.id = ${translationOf}
607
+ AND translation_source.deleted_at IS NULL
608
+ `.execute(this.db);
609
+ else await sql`
610
+ INSERT INTO ${sql.ref(tableName)} (${sql.join(columnRefs, sql`, `)})
611
+ VALUES (${sql.join(valuePlaceholders, sql`, `)})
612
+ `.execute(this.db);
613
+ invalidateCollectionCache(type);
614
+ const item = await this.findById(type, id);
615
+ if (!item) {
616
+ if (translationOf) throw new EmDashValidationError("Translation source content not found");
617
+ throw new Error("Failed to create content");
618
+ }
619
+ return item;
620
+ }
621
+ /**
622
+ * Generate a unique slug for a content item within a collection.
623
+ *
624
+ * Checks the collection table for existing slugs that match `baseSlug`
625
+ * (optionally scoped to a locale) and appends a numeric suffix (`-1`,
626
+ * `-2`, etc.) on collision to guarantee uniqueness.
627
+ *
628
+ * Returns null when slug normalization cannot produce a value.
629
+ */
630
+ async generateUniqueSlug(type, text, locale) {
631
+ const baseSlug = slugify(text);
632
+ if (!baseSlug) return null;
633
+ const tableName = getTableName(type);
634
+ if ((locale ? await sql`
635
+ SELECT slug FROM ${sql.ref(tableName)}
636
+ WHERE slug = ${baseSlug}
637
+ AND locale = ${locale}
638
+ LIMIT 1
639
+ `.execute(this.db) : await sql`
640
+ SELECT slug FROM ${sql.ref(tableName)}
641
+ WHERE slug = ${baseSlug}
642
+ LIMIT 1
643
+ `.execute(this.db)).rows.length === 0) return baseSlug;
644
+ const pattern = `${baseSlug}-%`;
645
+ const candidates = locale ? await sql`
646
+ SELECT slug FROM ${sql.ref(tableName)}
647
+ WHERE (slug = ${baseSlug} OR slug LIKE ${pattern})
648
+ AND locale = ${locale}
649
+ `.execute(this.db) : await sql`
650
+ SELECT slug FROM ${sql.ref(tableName)}
651
+ WHERE slug = ${baseSlug} OR slug LIKE ${pattern}
652
+ `.execute(this.db);
653
+ let maxSuffix = 0;
654
+ const suffixPattern = new RegExp(`^${escapeRegExp(baseSlug)}-(\\d+)$`);
655
+ for (const row of candidates.rows) {
656
+ const match = suffixPattern.exec(row.slug);
657
+ if (match) {
658
+ const n = parseInt(match[1], 10);
659
+ if (n > maxSuffix) maxSuffix = n;
660
+ }
661
+ }
662
+ return `${baseSlug}-${maxSuffix + 1}`;
663
+ }
664
+ /**
665
+ * Duplicate a content item
666
+ * Creates a new draft copy with "(Copy)" appended to the title.
667
+ * A slug is auto-generated from the new title by the handler layer.
668
+ */
669
+ async duplicate(type, id, authorId) {
670
+ const original = await this.findById(type, id);
671
+ if (!original) throw new EmDashValidationError("Content item not found");
672
+ const newData = { ...original.data };
673
+ if (typeof newData.title === "string") newData.title = `${newData.title} (Copy)`;
674
+ else if (typeof newData.name === "string") newData.name = `${newData.name} (Copy)`;
675
+ const slugSource = typeof newData.title === "string" ? newData.title : typeof newData.name === "string" ? newData.name : null;
676
+ const slug = slugSource ? await this.generateUniqueSlug(type, slugSource, original.locale ?? void 0) : null;
677
+ return this.create({
678
+ type,
679
+ slug,
680
+ data: newData,
681
+ status: "draft",
682
+ authorId: authorId || original.authorId || void 0,
683
+ locale: original.locale ?? void 0
684
+ });
685
+ }
686
+ /**
687
+ * Find content by ID
688
+ */
689
+ async findById(type, id) {
690
+ const tableName = getTableName(type);
691
+ const row = (await sql`
692
+ SELECT * FROM ${sql.ref(tableName)}
693
+ WHERE id = ${id}
694
+ AND deleted_at IS NULL
695
+ `.execute(this.db)).rows[0];
696
+ if (!row) return null;
697
+ return this.mapRow(type, row);
698
+ }
699
+ /**
700
+ * Find content by id, including trashed (soft-deleted) items.
701
+ * Used by restore endpoint for ownership checks.
702
+ */
703
+ async findByIdIncludingTrashed(type, id) {
704
+ const tableName = getTableName(type);
705
+ const row = (await sql`
706
+ SELECT * FROM ${sql.ref(tableName)}
707
+ WHERE id = ${id}
708
+ `.execute(this.db)).rows[0];
709
+ if (!row) return null;
710
+ return this.mapRow(type, row);
711
+ }
712
+ /**
713
+ * Find content by ID or slug. Tries ID first if it looks like a ULID,
714
+ * otherwise tries slug. Falls back to the other if the first lookup misses.
715
+ */
716
+ async findByIdOrSlug(type, identifier, locale) {
717
+ return this._findByIdOrSlug(type, identifier, false, locale);
718
+ }
719
+ /**
720
+ * Find content by ID or slug, including trashed (soft-deleted) items.
721
+ * Used by restore/permanent-delete endpoints.
722
+ */
723
+ async findByIdOrSlugIncludingTrashed(type, identifier, locale) {
724
+ return this._findByIdOrSlug(type, identifier, true, locale);
725
+ }
726
+ async isTrashed(type, id) {
727
+ const tableName = getTableName(type);
728
+ return await this.db.selectFrom(tableName).select("id").where("id", "=", id).where("deleted_at", "is not", null).executeTakeFirst() !== void 0;
729
+ }
730
+ async _findByIdOrSlug(type, identifier, includeTrashed, locale) {
731
+ const looksLikeUlid = ULID_PATTERN.test(identifier);
732
+ const findById = includeTrashed ? (t, id) => this.findByIdIncludingTrashed(t, id) : (t, id) => this.findById(t, id);
733
+ const findBySlug = includeTrashed ? (t, s) => this.findBySlugIncludingTrashed(t, s, locale) : (t, s) => this.findBySlug(t, s, locale);
734
+ try {
735
+ if (looksLikeUlid) {
736
+ const byId = await findById(type, identifier);
737
+ if (byId) return byId;
738
+ return await findBySlug(type, identifier);
739
+ }
740
+ const bySlug = await findBySlug(type, identifier);
741
+ if (bySlug) return bySlug;
742
+ return await findById(type, identifier);
743
+ } catch (error) {
744
+ if (isMissingTableError(error)) return null;
745
+ throw error;
746
+ }
747
+ }
748
+ /**
749
+ * Find content by slug
750
+ */
751
+ async findBySlug(type, slug, locale) {
752
+ const tableName = getTableName(type);
753
+ const row = (locale ? await sql`
754
+ SELECT * FROM ${sql.ref(tableName)}
755
+ WHERE slug = ${slug}
756
+ AND locale = ${locale}
757
+ AND deleted_at IS NULL
758
+ `.execute(this.db) : await sql`
759
+ SELECT * FROM ${sql.ref(tableName)}
760
+ WHERE slug = ${slug}
761
+ AND deleted_at IS NULL
762
+ ORDER BY locale ASC
763
+ LIMIT 1
764
+ `.execute(this.db)).rows[0];
765
+ if (!row) return null;
766
+ return this.mapRow(type, row);
767
+ }
768
+ /**
769
+ * Find content by slug, including trashed (soft-deleted) items.
770
+ * Used by restore/permanent-delete endpoints.
771
+ */
772
+ async findBySlugIncludingTrashed(type, slug, locale) {
773
+ const tableName = getTableName(type);
774
+ const row = (locale ? await sql`
775
+ SELECT * FROM ${sql.ref(tableName)}
776
+ WHERE slug = ${slug}
777
+ AND locale = ${locale}
778
+ `.execute(this.db) : await sql`
779
+ SELECT * FROM ${sql.ref(tableName)}
780
+ WHERE slug = ${slug}
781
+ ORDER BY locale ASC
782
+ LIMIT 1
783
+ `.execute(this.db)).rows[0];
784
+ if (!row) return null;
785
+ return this.mapRow(type, row);
786
+ }
787
+ /**
788
+ * Find many content items with filtering and pagination
789
+ */
790
+ async findMany(type, options = {}) {
791
+ const tableName = getTableName(type);
792
+ const limit = Math.min(options.limit || 50, 100);
793
+ const orderField = options.orderBy?.field || "createdAt";
794
+ const orderDirection = options.orderBy?.direction || "desc";
795
+ const resolvedOrderField = await this.resolveOrderField(type, orderField, options.sortableExtras);
796
+ const dbField = resolvedOrderField.column;
797
+ const resolvedFieldFilters = await this.resolveFieldFilters(type, options.where?.fieldFilters);
798
+ const safeOrderDirection = orderDirection.toLowerCase() === "asc" ? "ASC" : "DESC";
799
+ let query = this.db.selectFrom(tableName).selectAll().where("deleted_at", "is", null);
800
+ if (options.where?.status) query = query.where("status", "=", options.where.status);
801
+ if (options.where?.authorId) query = query.where("author_id", "=", options.where.authorId);
802
+ if (options.where?.locale) query = query.where("locale", "=", options.where.locale);
803
+ query = this.applySearchFilter(query, options.where, type);
804
+ query = this.applyDateFilter(query, options.where);
805
+ query = this.applyBylineFilter(query, options.where, type);
806
+ query = this.applyFieldFilters(query, resolvedFieldFilters);
807
+ if (options.cursor) if (resolvedOrderField.indexedCustomField) {
808
+ const { value, id: cursorId } = decodeIndexedFieldCursor(options.cursor, orderField);
809
+ const isPresent = sql`${sql.ref(dbField)} IS NOT NULL`;
810
+ const falseLiteral = sql`FALSE`;
811
+ const trueLiteral = sql`TRUE`;
812
+ if (safeOrderDirection === "ASC" && value === null) query = query.where(sql`
813
+ (${isPresent}) > ${falseLiteral}
814
+ OR ((${isPresent}) = ${falseLiteral} AND ${sql.ref("id")} > ${cursorId})
815
+ `);
816
+ else if (safeOrderDirection === "DESC" && value === null) query = query.where(sql`
817
+ (${isPresent}) = ${falseLiteral} AND ${sql.ref("id")} < ${cursorId}
818
+ `);
819
+ else if (safeOrderDirection === "ASC") query = query.where(sql`
820
+ (${isPresent}, ${sql.ref(dbField)}, ${sql.ref("id")})
821
+ > (${trueLiteral}, ${value}, ${cursorId})
822
+ `);
823
+ else query = query.where(sql`
824
+ (${isPresent}, ${sql.ref(dbField)}, ${sql.ref("id")})
825
+ < (${trueLiteral}, ${value}, ${cursorId})
826
+ `);
827
+ } else {
828
+ const { orderValue, id: cursorId } = decodeCursor(options.cursor);
829
+ if (safeOrderDirection === "DESC") query = query.where((eb) => eb.or([eb(dbField, "<", orderValue), eb.and([eb(dbField, "=", orderValue), eb("id", "<", cursorId)])]));
830
+ else query = query.where((eb) => eb.or([eb(dbField, ">", orderValue), eb.and([eb(dbField, "=", orderValue), eb("id", ">", cursorId)])]));
831
+ }
832
+ const indexedOrderFilter = resolvedOrderField.indexedCustomField ? resolvedFieldFilters.find((filter) => filter.column === dbField) : void 0;
833
+ if (resolvedOrderField.indexedCustomField && !indexedOrderFilter) query = query.orderBy(sql`${sql.ref(dbField)} IS NOT NULL`, safeOrderDirection === "ASC" ? "asc" : "desc");
834
+ if (indexedOrderFilter?.kind !== "null") query = query.orderBy(dbField, safeOrderDirection === "ASC" ? "asc" : "desc");
835
+ query = query.orderBy("id", safeOrderDirection === "ASC" ? "asc" : "desc").limit(limit + 1);
836
+ const [rowsResult, countResult] = await Promise.allSettled([query.execute(), this.countWithResolvedFilters(type, options.where, resolvedFieldFilters)]);
837
+ if (rowsResult.status === "rejected") throw rowsResult.reason;
838
+ if (countResult.status === "rejected") throw countResult.reason;
839
+ const rows = rowsResult.value;
840
+ const total = countResult.value;
841
+ const hasMore = rows.length > limit;
842
+ const items = rows.slice(0, limit);
843
+ const mappedResult = {
844
+ items: items.map((row) => this.mapRow(type, row)),
845
+ total
846
+ };
847
+ if (hasMore && items.length > 0) {
848
+ const lastRow = items.at(-1);
849
+ const lastOrderValue = lastRow[dbField];
850
+ if (resolvedOrderField.indexedCustomField) {
851
+ if (lastOrderValue !== null && typeof lastOrderValue !== "string" && typeof lastOrderValue !== "number") throw new EmDashValidationError(`Invalid indexed value for order field: ${orderField}`);
852
+ mappedResult.nextCursor = encodeIndexedFieldCursor(orderField, lastOrderValue, String(lastRow.id));
853
+ } else mappedResult.nextCursor = encodeCursor(typeof lastOrderValue === "string" || typeof lastOrderValue === "number" ? String(lastOrderValue) : "", String(lastRow.id));
854
+ }
855
+ return mappedResult;
856
+ }
857
+ /**
858
+ * Update content
859
+ */
860
+ async update(type, id, input) {
861
+ const tableName = getTableName(type);
862
+ const now = (/* @__PURE__ */ new Date()).toISOString();
863
+ const updates = {};
864
+ if (input.status !== void 0) updates.status = input.status;
865
+ if (input.slug !== void 0) updates.slug = input.slug;
866
+ if (input.publishedAt !== void 0) updates.published_at = input.publishedAt === null ? null : await this.datetimes.normalizeValue(type, input.publishedAt);
867
+ if (input.scheduledAt !== void 0) updates.scheduled_at = input.scheduledAt === null ? null : await this.datetimes.normalizeValue(type, input.scheduledAt);
868
+ if (input.authorId !== void 0) updates.author_id = input.authorId;
869
+ if (input.primaryBylineId !== void 0) updates.primary_byline_id = input.primaryBylineId;
870
+ if (input.data !== void 0 && typeof input.data === "object") {
871
+ const data = await this.datetimes.normalizeData(type, writableContentData(input.data));
872
+ for (const [key, value] of Object.entries(data)) updates[key] = serializeValue(value);
873
+ }
874
+ const hasColumnWrites = Object.keys(updates).length > 0;
875
+ if (hasColumnWrites) updates.updated_at = now;
876
+ updates.version = sql`version + 1`;
877
+ await this.db.updateTable(tableName).set(updates).where("id", "=", id).where("deleted_at", "is", null).execute();
878
+ if (hasColumnWrites) invalidateCollectionCache(type);
879
+ const updated = await this.findById(type, id);
880
+ if (!updated) throw new Error("Content not found");
881
+ return updated;
882
+ }
883
+ async restoreRevision(type, id, revisionData, authorId) {
884
+ const tableName = getTableName(type);
885
+ const existing = await this.findById(type, id);
886
+ if (!existing) throw new EmDashValidationError("Content item not found");
887
+ const normalizedSnapshot = await this.datetimes.normalizeData(type, revisionData);
888
+ const { _slug, ...snapshotFields } = normalizedSnapshot;
889
+ const fieldData = writableContentData(snapshotFields);
890
+ const revisionId = createRevisionId();
891
+ const now = (/* @__PURE__ */ new Date()).toISOString();
892
+ const assignments = [];
893
+ if (typeof _slug === "string") assignments.push(sql`slug = ${_slug}`);
894
+ for (const [field, value] of Object.entries(fieldData)) {
895
+ validateIdentifier(field, "content field name");
896
+ assignments.push(sql`${sql.ref(field)} = ${serializeValue(value)}`);
897
+ }
898
+ assignments.push(sql`draft_revision_id = ${revisionId}`, sql`updated_at = ${now}`, sql`version = version + 1`);
899
+ const buildQueries = () => {
900
+ return [
901
+ sql`
902
+ INSERT INTO revisions (id, collection, entry_id, data, author_id)
903
+ VALUES (${revisionId}, ${type}, ${id}, ${JSON.stringify(normalizedSnapshot)}, ${authorId})
904
+ RETURNING id
905
+ `,
906
+ sql`
907
+ UPDATE ${sql.ref(tableName)}
908
+ SET ${sql.join(assignments, sql`, `)}
909
+ WHERE id = ${id}
910
+ AND deleted_at IS NULL
911
+ AND version = ${existing.version}
912
+ AND updated_at = ${existing.updatedAt}
913
+ AND status = ${existing.status}
914
+ AND ${nullableColumnMatch("live_revision_id", existing.liveRevisionId)}
915
+ AND ${nullableColumnMatch("draft_revision_id", existing.draftRevisionId)}
916
+ AND ${nullableColumnMatch("scheduled_at", existing.scheduledAt)}
917
+ RETURNING id
918
+ `,
919
+ sql`
920
+ DELETE FROM revisions
921
+ WHERE id = ${revisionId}
922
+ AND NOT EXISTS (
923
+ SELECT 1 FROM ${sql.ref(tableName)}
924
+ WHERE id = ${id}
925
+ AND draft_revision_id = ${revisionId}
926
+ AND version = ${existing.version + 1}
927
+ )
928
+ `,
929
+ sql`
930
+ UPDATE ${sql.ref(tableName)}
931
+ SET draft_revision_id = ${existing.draftRevisionId}
932
+ WHERE id = ${id}
933
+ AND draft_revision_id = ${revisionId}
934
+ AND version = ${existing.version + 1}
935
+ RETURNING id
936
+ `
937
+ ];
938
+ };
939
+ const batched = await executeAtomicBatchIfSupported(this.db, buildQueries());
940
+ if (batched) {
941
+ if (batched[0]?.rows.length !== 1 || batched[1]?.rows.length !== 1 || batched[3]?.rows.length !== 1) throw new ContentMutationConflictError();
942
+ } else await withTransaction(this.db, async (trx) => {
943
+ const [audit, update, removeUnappliedAudit, releaseMarker] = buildQueries();
944
+ if ((await audit.execute(trx)).rows.length !== 1) throw new ContentMutationConflictError();
945
+ const updateResult = await update.execute(trx);
946
+ await removeUnappliedAudit.execute(trx);
947
+ const releaseResult = await releaseMarker.execute(trx);
948
+ if (updateResult.rows.length !== 1 || releaseResult.rows.length !== 1) throw new ContentMutationConflictError();
949
+ });
950
+ invalidateCollectionCache(type);
951
+ const item = await this.findById(type, id);
952
+ if (!item) throw new Error("Content not found");
953
+ await new RevisionRepository(this.db).queuePruning(type, id, revisionId);
954
+ return {
955
+ item,
956
+ revisionId
957
+ };
958
+ }
959
+ async restoreDraftRevision(type, id, revisionData, authorId) {
960
+ const tableName = getTableName(type);
961
+ const existing = await this.findById(type, id);
962
+ if (!existing) return null;
963
+ const normalizedSnapshot = await this.datetimes.normalizeData(type, revisionData);
964
+ const revisionId = createRevisionId();
965
+ const buildQueries = () => {
966
+ return [
967
+ sql`
968
+ INSERT INTO revisions (id, collection, entry_id, data, author_id)
969
+ VALUES (${revisionId}, ${type}, ${id}, ${JSON.stringify(normalizedSnapshot)}, ${authorId})
970
+ RETURNING id
971
+ `,
972
+ sql`
973
+ UPDATE ${sql.ref(tableName)}
974
+ SET draft_revision_id = ${revisionId},
975
+ version = version + 1
976
+ WHERE id = ${id}
977
+ AND deleted_at IS NULL
978
+ AND version = ${existing.version}
979
+ AND updated_at = ${existing.updatedAt}
980
+ AND status = ${existing.status}
981
+ AND ${nullableColumnMatch("live_revision_id", existing.liveRevisionId)}
982
+ AND ${nullableColumnMatch("draft_revision_id", existing.draftRevisionId)}
983
+ AND ${nullableColumnMatch("scheduled_at", existing.scheduledAt)}
984
+ RETURNING id
985
+ `,
986
+ sql`
987
+ DELETE FROM revisions
988
+ WHERE id = ${revisionId}
989
+ AND NOT EXISTS (
990
+ SELECT 1 FROM ${sql.ref(tableName)}
991
+ WHERE id = ${id}
992
+ AND draft_revision_id = ${revisionId}
993
+ AND version = ${existing.version + 1}
994
+ )
995
+ `
996
+ ];
997
+ };
998
+ const batched = await executeAtomicBatchIfSupported(this.db, buildQueries());
999
+ if (batched) {
1000
+ if (batched[0]?.rows.length !== 1 || batched[1]?.rows.length !== 1) throw new ContentMutationConflictError();
1001
+ } else await withTransaction(this.db, async (trx) => {
1002
+ const [audit, stage, removeUnstagedAudit] = buildQueries();
1003
+ if ((await audit.execute(trx)).rows.length !== 1) throw new ContentMutationConflictError();
1004
+ const stageResult = await stage.execute(trx);
1005
+ await removeUnstagedAudit.execute(trx);
1006
+ if (stageResult.rows.length !== 1) throw new ContentMutationConflictError();
1007
+ });
1008
+ invalidateCollectionCache(type);
1009
+ await new RevisionRepository(this.db).queuePruning(type, id, revisionId);
1010
+ return revisionId;
1011
+ }
1012
+ /**
1013
+ * Update plugin-authored fields without letting content columns diverge
1014
+ * from the revision pointers that publication promotes.
1015
+ */
1016
+ async updateDraftAware(type, id, input) {
1017
+ const data = input.data ? await this.datetimes.normalizeData(type, writableContentData(input.data)) : {};
1018
+ const stagedSlug = typeof input.slug === "string" ? input.slug : void 0;
1019
+ if (!(Object.keys(data).length > 0 || stagedSlug !== void 0)) return this.update(type, id, {
1020
+ ...input,
1021
+ data
1022
+ });
1023
+ const collectionRows = await this.db.selectFrom("_emdash_collections as collection").leftJoin("_emdash_fields as field", "field.collection_id", "collection.id").select(["collection.supports", "field.slug as fieldSlug"]).where("collection.slug", "=", type).execute();
1024
+ const supportsRaw = collectionRows[0]?.supports;
1025
+ const supports = supportsRaw ? JSON.parse(supportsRaw) : [];
1026
+ if (!Array.isArray(supports) || !supports.includes("revisions")) return this.update(type, id, {
1027
+ ...input,
1028
+ data
1029
+ });
1030
+ const fieldSlugs = new Set(collectionRows.map((row) => row.fieldSlug).filter((slug) => Boolean(slug)));
1031
+ const revisionRepo = new RevisionRepository(this.db);
1032
+ let existing = await this.findById(type, id);
1033
+ let incoming = data;
1034
+ if (existing) {
1035
+ let stored = existing.data ?? {};
1036
+ if (existing.draftRevisionId) {
1037
+ const draft = await revisionRepo.findById(existing.draftRevisionId);
1038
+ if (draft?.data) stored = draft.data;
1039
+ }
1040
+ const stale = staleStoredKeys(data, stored, fieldSlugs);
1041
+ if (stale.length > 0) {
1042
+ incoming = { ...data };
1043
+ for (const key of stale) delete incoming[key];
1044
+ }
1045
+ }
1046
+ for (const field of Object.keys(incoming)) if (!fieldSlugs.has(field)) throw new EmDashValidationError(`Unknown field '${field}' in collection '${type}'`);
1047
+ for (let attempt = 0; existing && attempt < MAX_DRAFT_STAGE_ATTEMPTS; attempt++) {
1048
+ let baseData = existing.data;
1049
+ if (existing.draftRevisionId) {
1050
+ const draft = await revisionRepo.findById(existing.draftRevisionId);
1051
+ if (draft) baseData = draft.data;
1052
+ }
1053
+ const mergedData = keepKnownFields({
1054
+ ...baseData,
1055
+ ...incoming
1056
+ }, fieldSlugs);
1057
+ if (stagedSlug !== void 0) mergedData._slug = stagedSlug;
1058
+ const revision = await revisionRepo.create({
1059
+ collection: type,
1060
+ entryId: id,
1061
+ data: mergedData,
1062
+ ...input.revisionAuthorId ? { authorId: input.revisionAuthorId } : {}
1063
+ });
1064
+ let staged;
1065
+ try {
1066
+ staged = await this.replaceDraftRevisionForUpdate(type, id, revision.id, existing, input);
1067
+ } catch (error) {
1068
+ await this.deleteUnstagedRevision(revisionRepo, type, id, revision.id);
1069
+ throw error;
1070
+ }
1071
+ if (staged) {
1072
+ const updated = await this.findById(type, id);
1073
+ if (!updated) throw new Error("Content not found");
1074
+ const draftData = {};
1075
+ for (const [key, value] of Object.entries(mergedData)) if (!key.startsWith("_")) draftData[key] = value;
1076
+ return {
1077
+ ...updated,
1078
+ data: {
1079
+ ...updated.data,
1080
+ ...draftData
1081
+ }
1082
+ };
1083
+ }
1084
+ await this.deleteUnstagedRevision(revisionRepo, type, id, revision.id);
1085
+ existing = await this.findById(type, id);
1086
+ }
1087
+ if (!existing) throw new Error("Content not found");
1088
+ throw new ContentMutationConflictError();
1089
+ }
1090
+ async deleteUnstagedRevision(revisionRepo, type, id, revisionId) {
1091
+ try {
1092
+ await revisionRepo.deleteIfUnreferenced(type, id, revisionId);
1093
+ } catch (error) {
1094
+ console.error(`[content] Failed to clean up unstaged revision ${revisionId}:`, error);
1095
+ }
1096
+ }
1097
+ async replaceDraftRevisionForUpdate(type, id, revisionId, expected, input) {
1098
+ const tableName = getTableName(type);
1099
+ const assignments = [sql`draft_revision_id = ${revisionId}`];
1100
+ let liveMetadataChanged = false;
1101
+ if (input.status !== void 0) {
1102
+ assignments.push(sql`status = ${input.status}`);
1103
+ liveMetadataChanged = true;
1104
+ }
1105
+ if (input.slug === null) {
1106
+ assignments.push(sql`slug = NULL`);
1107
+ liveMetadataChanged = true;
1108
+ }
1109
+ if (input.publishedAt !== void 0) {
1110
+ const publishedAt = input.publishedAt === null ? null : await this.datetimes.normalizeValue(type, input.publishedAt);
1111
+ assignments.push(sql`published_at = ${publishedAt}`);
1112
+ liveMetadataChanged = true;
1113
+ }
1114
+ if (input.scheduledAt !== void 0) {
1115
+ const scheduledAt = input.scheduledAt === null ? null : await this.datetimes.normalizeValue(type, input.scheduledAt);
1116
+ assignments.push(sql`scheduled_at = ${scheduledAt}`);
1117
+ liveMetadataChanged = true;
1118
+ }
1119
+ if (input.authorId !== void 0) {
1120
+ assignments.push(sql`author_id = ${input.authorId}`);
1121
+ liveMetadataChanged = true;
1122
+ }
1123
+ if (input.primaryBylineId !== void 0) {
1124
+ assignments.push(sql`primary_byline_id = ${input.primaryBylineId}`);
1125
+ liveMetadataChanged = true;
1126
+ }
1127
+ if (liveMetadataChanged) assignments.push(sql`updated_at = ${(/* @__PURE__ */ new Date()).toISOString()}`);
1128
+ assignments.push(sql`version = version + 1`);
1129
+ const changed = ((await sql`
1130
+ UPDATE ${sql.ref(tableName)}
1131
+ SET ${sql.join(assignments, sql`, `)}
1132
+ WHERE id = ${id}
1133
+ AND deleted_at IS NULL
1134
+ AND version = ${expected.version}
1135
+ AND ${nullableColumnMatch("live_revision_id", expected.liveRevisionId)}
1136
+ AND ${nullableColumnMatch("draft_revision_id", expected.draftRevisionId)}
1137
+ AND EXISTS (
1138
+ SELECT 1 FROM revisions
1139
+ WHERE revisions.id = ${revisionId}
1140
+ AND revisions.collection = ${type}
1141
+ AND revisions.entry_id = ${id}
1142
+ )
1143
+ `.execute(this.db)).numAffectedRows ?? 0n) > 0n;
1144
+ if (changed && liveMetadataChanged) invalidateCollectionCache(type);
1145
+ return changed;
1146
+ }
1147
+ /**
1148
+ * Copy non-translatable field values to every other entry in the
1149
+ * translation group, trashed entries included.
1150
+ *
1151
+ * Only the fields present in `data` are copied. With `previous`, `data` is
1152
+ * the entry's complete new state and only the fields whose value differs
1153
+ * from `previous` are copied, an absent field as null. An entry that already
1154
+ * holds every copied value is left untouched, so its `updated_at` does not
1155
+ * move.
1156
+ *
1157
+ * On collections with revisions a changed entry also gets a new live
1158
+ * revision, because republishing and unpublishing read that revision rather
1159
+ * than the columns. A pending draft takes a value only where it still holds
1160
+ * the entry's previous value, so an unpublished edit to the field survives.
1161
+ */
1162
+ async syncNonTranslatableFields(type, sourceId, translationGroup, data, options = {}) {
1163
+ const tableName = getTableName(type);
1164
+ const collectionRows = await this.db.selectFrom("_emdash_collections as collection").leftJoin("_emdash_fields as field", (join) => join.onRef("field.collection_id", "=", "collection.id").on("field.translatable", "=", 0)).select(["collection.supports", "field.slug as fieldSlug"]).where("collection.slug", "=", type).execute();
1165
+ const { previous } = options;
1166
+ const values = {};
1167
+ for (const { fieldSlug } of collectionRows) {
1168
+ if (!fieldSlug) continue;
1169
+ if (previous) {
1170
+ if (!sameStoredValue(previous[fieldSlug], data[fieldSlug])) values[fieldSlug] = data[fieldSlug] ?? null;
1171
+ } else if (fieldSlug in data) values[fieldSlug] = data[fieldSlug];
1172
+ }
1173
+ if (Object.keys(values).length === 0) return;
1174
+ const normalizedValues = await this.datetimes.normalizeData(type, values);
1175
+ const supportsRaw = collectionRows[0]?.supports;
1176
+ const supports = supportsRaw ? JSON.parse(supportsRaw) : [];
1177
+ const usesRevisions = Array.isArray(supports) && supports.includes("revisions");
1178
+ const siblings = await sql`
1179
+ SELECT * FROM ${sql.ref(tableName)}
1180
+ WHERE translation_group = ${translationGroup}
1181
+ AND id != ${sourceId}
1182
+ `.execute(this.db);
1183
+ let changed = false;
1184
+ for (const row of siblings.rows) if (await this.syncSiblingValues(type, this.mapRow(type, row), normalizedValues, usesRevisions)) changed = true;
1185
+ if (changed) invalidateCollectionCache(type);
1186
+ }
1187
+ async syncSiblingValues(type, initial, values, usesRevisions) {
1188
+ const tableName = getTableName(type);
1189
+ const revisionRepo = new RevisionRepository(this.db);
1190
+ let sibling = initial;
1191
+ for (let attempt = 0; sibling && attempt < MAX_DRAFT_STAGE_ATTEMPTS; attempt++) {
1192
+ const current = sibling;
1193
+ const changed = {};
1194
+ for (const [field, value] of Object.entries(values)) if (!sameStoredValue(current.data[field], value)) changed[field] = value;
1195
+ if (Object.keys(changed).length === 0) return false;
1196
+ const assignments = [];
1197
+ for (const [field, value] of Object.entries(changed)) {
1198
+ validateIdentifier(field, "content field name");
1199
+ assignments.push(sql`${sql.ref(field)} = ${serializeValue(value)}`);
1200
+ }
1201
+ const createdRevisionIds = [];
1202
+ const cleanUp = async () => {
1203
+ for (const revisionId of createdRevisionIds) await this.deleteUnstagedRevision(revisionRepo, type, current.id, revisionId);
1204
+ };
1205
+ let synced;
1206
+ try {
1207
+ const live = usesRevisions && current.liveRevisionId ? await revisionRepo.findById(current.liveRevisionId) : null;
1208
+ if (live) {
1209
+ const revision = await revisionRepo.create({
1210
+ collection: type,
1211
+ entryId: current.id,
1212
+ data: {
1213
+ ...live.data,
1214
+ ...changed
1215
+ }
1216
+ });
1217
+ createdRevisionIds.push(revision.id);
1218
+ assignments.push(sql`live_revision_id = ${revision.id}`);
1219
+ }
1220
+ const draft = usesRevisions && current.draftRevisionId ? await revisionRepo.findById(current.draftRevisionId) : null;
1221
+ const carried = {};
1222
+ for (const [field, value] of Object.entries(changed)) if (draft && sameStoredValue(draft.data[field], current.data[field])) carried[field] = value;
1223
+ if (draft && Object.keys(carried).length > 0) {
1224
+ const revision = await revisionRepo.create({
1225
+ collection: type,
1226
+ entryId: current.id,
1227
+ data: {
1228
+ ...draft.data,
1229
+ ...carried
1230
+ }
1231
+ });
1232
+ createdRevisionIds.push(revision.id);
1233
+ assignments.push(sql`draft_revision_id = ${revision.id}`);
1234
+ }
1235
+ assignments.push(sql`updated_at = ${(/* @__PURE__ */ new Date()).toISOString()}`, sql`version = version + 1`);
1236
+ synced = ((await sql`
1237
+ UPDATE ${sql.ref(tableName)}
1238
+ SET ${sql.join(assignments, sql`, `)}
1239
+ WHERE id = ${current.id}
1240
+ AND version = ${current.version}
1241
+ AND ${nullableColumnMatch("live_revision_id", current.liveRevisionId)}
1242
+ AND ${nullableColumnMatch("draft_revision_id", current.draftRevisionId)}
1243
+ `.execute(this.db)).numAffectedRows ?? 0n) > 0n;
1244
+ } catch (error) {
1245
+ await cleanUp();
1246
+ throw error;
1247
+ }
1248
+ if (synced) return true;
1249
+ await cleanUp();
1250
+ sibling = await this.findByIdIncludingTrashed(type, current.id);
1251
+ }
1252
+ if (!sibling) return false;
1253
+ throw new ContentMutationConflictError();
1254
+ }
1255
+ /**
1256
+ * Delete content (soft delete - moves to trash)
1257
+ */
1258
+ async delete(type, id) {
1259
+ const tableName = getTableName(type);
1260
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1261
+ const changed = ((await sql`
1262
+ UPDATE ${sql.ref(tableName)}
1263
+ SET deleted_at = ${now}
1264
+ WHERE id = ${id}
1265
+ AND deleted_at IS NULL
1266
+ `.execute(this.db)).numAffectedRows ?? 0n) > 0n;
1267
+ if (changed) invalidateCollectionCache(type);
1268
+ return changed;
1269
+ }
1270
+ /**
1271
+ * Restore content from trash
1272
+ *
1273
+ * The entry comes back as a draft with no schedule. The live version is not
1274
+ * copied into a draft revision: collections without revisions save to the
1275
+ * columns, and a draft revision would hide those saves.
1276
+ */
1277
+ async restore(type, id, expectedRevision) {
1278
+ const tableName = getTableName(type);
1279
+ const existing = await this.findByIdOrSlugIncludingTrashed(type, id);
1280
+ if (!existing) return null;
1281
+ assertRevisionPrecondition(existing, expectedRevision);
1282
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1283
+ const restored = (await sql`
1284
+ UPDATE ${sql.ref(tableName)}
1285
+ SET deleted_at = NULL,
1286
+ live_revision_id = NULL,
1287
+ status = 'draft',
1288
+ scheduled_at = NULL,
1289
+ updated_at = ${now},
1290
+ version = ${existing.version + 1}
1291
+ WHERE id = ${existing.id}
1292
+ AND deleted_at IS NOT NULL
1293
+ AND version = ${existing.version}
1294
+ AND updated_at = ${existing.updatedAt}
1295
+ RETURNING *
1296
+ `.execute(this.db)).rows[0];
1297
+ if (!restored) throw new ContentMutationConflictError("Content changed while restoring");
1298
+ invalidateCollectionCache(type);
1299
+ return this.mapRow(type, restored);
1300
+ }
1301
+ /**
1302
+ * Permanently delete content (cannot be undone)
1303
+ */
1304
+ /**
1305
+ * Permanently delete a soft-deleted content row.
1306
+ *
1307
+ * Returns `true` only when a soft-deleted (trashed) row was removed.
1308
+ * Returns `false` when no row exists OR when the row exists but is live —
1309
+ * the caller is responsible for distinguishing these cases (typically via
1310
+ * a follow-up `findByIdOrSlugIncludingTrashed` to surface NOT_FOUND vs
1311
+ * NOT_TRASHED). The `AND deleted_at IS NOT NULL` clause is the safety net
1312
+ * that prevents permanent delete from bypassing the trash workflow.
1313
+ */
1314
+ async permanentDelete(type, id) {
1315
+ const tableName = getTableName(type);
1316
+ const changed = ((await sql`
1317
+ DELETE FROM ${sql.ref(tableName)}
1318
+ WHERE id = ${id}
1319
+ AND deleted_at IS NOT NULL
1320
+ `.execute(this.db)).numAffectedRows ?? 0n) > 0n;
1321
+ if (changed) invalidateCollectionCache(type);
1322
+ return changed;
1323
+ }
1324
+ /**
1325
+ * Find trashed content items
1326
+ */
1327
+ async findTrashed(type, options = {}) {
1328
+ const tableName = getTableName(type);
1329
+ const limit = Math.min(options.limit || 50, 100);
1330
+ const orderField = options.orderBy?.field || "deletedAt";
1331
+ const orderDirection = options.orderBy?.direction || "desc";
1332
+ const dbField = this.mapOrderField(orderField);
1333
+ const safeOrderDirection = orderDirection.toLowerCase() === "asc" ? "ASC" : "DESC";
1334
+ let query = this.db.selectFrom(tableName).selectAll().where("deleted_at", "is not", null);
1335
+ if (options.where?.locale) query = query.where("locale", "=", options.where.locale);
1336
+ if (options.cursor) {
1337
+ const { orderValue, id: cursorId } = decodeCursor(options.cursor);
1338
+ if (safeOrderDirection === "DESC") query = query.where((eb) => eb.or([eb(dbField, "<", orderValue), eb.and([eb(dbField, "=", orderValue), eb("id", "<", cursorId)])]));
1339
+ else query = query.where((eb) => eb.or([eb(dbField, ">", orderValue), eb.and([eb(dbField, "=", orderValue), eb("id", ">", cursorId)])]));
1340
+ }
1341
+ query = query.orderBy(dbField, safeOrderDirection === "ASC" ? "asc" : "desc").orderBy("id", safeOrderDirection === "ASC" ? "asc" : "desc").limit(limit + 1);
1342
+ const rows = await query.execute();
1343
+ const hasMore = rows.length > limit;
1344
+ const items = rows.slice(0, limit);
1345
+ const mappedResult = { items: items.map((row) => {
1346
+ const record = row;
1347
+ return {
1348
+ ...this.mapRow(type, record),
1349
+ deletedAt: typeof record.deleted_at === "string" ? record.deleted_at : ""
1350
+ };
1351
+ }) };
1352
+ if (hasMore && items.length > 0) {
1353
+ const lastRow = items.at(-1);
1354
+ const lastOrderValue = lastRow[dbField];
1355
+ mappedResult.nextCursor = encodeCursor(typeof lastOrderValue === "string" || typeof lastOrderValue === "number" ? String(lastOrderValue) : "", String(lastRow.id));
1356
+ }
1357
+ return mappedResult;
1358
+ }
1359
+ /**
1360
+ * Count trashed content items
1361
+ */
1362
+ async countTrashed(type, options = {}) {
1363
+ const tableName = getTableName(type);
1364
+ let query = this.db.selectFrom(tableName).select((eb) => eb.fn.count("id").as("count")).where("deleted_at", "is not", null);
1365
+ if (options.locale) query = query.where("locale", "=", options.locale);
1366
+ const result = await query.executeTakeFirst();
1367
+ return Number(result?.count || 0);
1368
+ }
1369
+ /**
1370
+ * Apply the optional `q` filter.
1371
+ *
1372
+ * When the handler sets `useFts` (collection has a healthy FTS5 index
1373
+ * covering the display columns; SQLite only), the filter is served from
1374
+ * the index: a token-prefix MATCH against `_emdash_fts_<slug>` OR'd with
1375
+ * an index-served `slug GLOB 'term*'` prefix (the slug is not in the FTS
1376
+ * index). Both sides are index-backed, so SQLite's OR optimization avoids
1377
+ * the full-table scan the LIKE fallback needs (#1517). The trade-off is
1378
+ * search semantics: token-prefix matching instead of arbitrary substring.
1379
+ *
1380
+ * Fallback (Postgres, search disabled, or no usable terms): case-
1381
+ * insensitive substring LIKE across the handler-resolved `searchColumns`
1382
+ * (OR'd). User input is treated literally (LIKE wildcards escaped) and
1383
+ * `lower()` is applied on both sides for SQLite/Postgres parity.
1384
+ */
1385
+ applySearchFilter(query, where, type) {
1386
+ const term = where?.q?.trim();
1387
+ const columns = where?.searchColumns;
1388
+ if (!term || !columns || columns.length === 0) return query;
1389
+ if (where.useFts) {
1390
+ const match = buildFtsPrefixMatch(term);
1391
+ if (match) {
1392
+ validateIdentifier(type, "collection slug");
1393
+ const ftsTable = `_emdash_fts_${type}`;
1394
+ const slugPrefix = buildSlugGlobPrefix(term);
1395
+ return query.where((eb) => eb.or([sql`id IN (SELECT id FROM ${sql.ref(ftsTable)} WHERE ${sql.ref(ftsTable)} MATCH ${match})`, sql`slug GLOB ${slugPrefix}`]));
1396
+ }
1397
+ }
1398
+ const pattern = `%${term.replace(LIKE_WILDCARD_RE, (c) => `\\${c}`)}%`;
1399
+ return query.where((eb) => eb.or(columns.map((col) => {
1400
+ validateIdentifier(col, "search column");
1401
+ return sql`lower(CAST(${sql.ref(col)} AS TEXT)) LIKE lower(${pattern}) ESCAPE '\\'`;
1402
+ })));
1403
+ }
1404
+ /**
1405
+ * Apply the optional inclusive date-range filter. The field is mapped
1406
+ * through `DATE_FILTER_COLUMNS` (a closed whitelist), and bounds compare
1407
+ * lexicographically against the stored ISO 8601 timestamps. A `publishedAt`
1408
+ * range naturally excludes never-published rows (their column is NULL).
1409
+ */
1410
+ applyDateFilter(query, where) {
1411
+ const filter = where?.dateFilter;
1412
+ if (!filter) return query;
1413
+ const column = DATE_FILTER_COLUMNS[filter.field];
1414
+ if (!column) throw new EmDashValidationError(`Invalid date filter field: ${filter.field}`);
1415
+ const { from, to } = filter;
1416
+ if (!from && !to) return query;
1417
+ let next = query;
1418
+ if (from) next = next.where((eb) => eb(column, ">=", from));
1419
+ if (to) next = next.where((eb) => eb(column, "<=", to));
1420
+ return next;
1421
+ }
1422
+ /**
1423
+ * Apply the optional byline filter as a correlated (NOT) EXISTS against
1424
+ * `_emdash_content_bylines`.
1425
+ *
1426
+ * Correlating from the content table preserves the outer sort index so
1427
+ * `LIMIT` can short-circuit. `mode: "none"` tests the junction rather than
1428
+ * `primary_byline_id` because the two are written in the same call but
1429
+ * are not atomically consistent, so the junction is authoritative.
1430
+ *
1431
+ * Whether a credit *renders* is locale-scoped; whether one *exists* is
1432
+ * not. Both are needed: the first decides what the filter matches, the
1433
+ * second decides whether the author fallback applies at all.
1434
+ */
1435
+ applyBylineFilter(query, where, type) {
1436
+ const filter = where?.bylineFilter;
1437
+ if (!filter) return query;
1438
+ const tableName = getTableName(type);
1439
+ const idColumn = `${tableName}.id`;
1440
+ const authorColumn = `${tableName}.author_id`;
1441
+ const localeColumn = `${tableName}.locale`;
1442
+ const creditRenders = (eb, bylineIds) => {
1443
+ let sub = eb.selectFrom("_emdash_content_bylines as cb").innerJoin("_emdash_bylines as b", "b.translation_group", "cb.byline_id").select("cb.id").where("cb.collection_slug", "=", type).whereRef("cb.content_id", "=", idColumn);
1444
+ sub = filter.locale ? sub.where("b.locale", "=", filter.locale) : sub.whereRef("b.locale", "=", localeColumn);
1445
+ if (bylineIds) sub = sub.where("cb.byline_id", "in", bylineIds);
1446
+ return eb.exists(sub);
1447
+ };
1448
+ const hasExplicitCredit = (eb) => eb.exists(eb.selectFrom("_emdash_content_bylines as cb").select("cb.id").where("cb.collection_slug", "=", type).whereRef("cb.content_id", "=", idColumn));
1449
+ const authorHasByline = (eb, bylineIds) => {
1450
+ let sub = eb.selectFrom("_emdash_bylines as b").select("b.id").whereRef("b.user_id", "=", authorColumn);
1451
+ sub = filter.locale ? sub.where("b.locale", "=", filter.locale) : sub.whereRef("b.locale", "=", localeColumn);
1452
+ if (bylineIds) sub = sub.where("b.translation_group", "in", bylineIds);
1453
+ return eb.exists(sub);
1454
+ };
1455
+ if (filter.mode === "none") return query.where((eb) => {
1456
+ const uncredited = eb.not(creditRenders(eb));
1457
+ return filter.includeInferred ? eb.and([uncredited, eb.or([hasExplicitCredit(eb), eb.not(authorHasByline(eb))])]) : uncredited;
1458
+ });
1459
+ const bylineIds = filter.bylineIds ?? [];
1460
+ if (bylineIds.length === 0) return query.where(() => sql`1 = 0`);
1461
+ return query.where((eb) => {
1462
+ if (!filter.includeInferred) return creditRenders(eb, bylineIds);
1463
+ return eb.or([creditRenders(eb, bylineIds), eb.and([eb.not(hasExplicitCredit(eb)), authorHasByline(eb, bylineIds)])]);
1464
+ });
1465
+ }
1466
+ /**
1467
+ * Count content items
1468
+ */
1469
+ async count(type, where) {
1470
+ const resolvedFieldFilters = await this.resolveFieldFilters(type, where?.fieldFilters);
1471
+ return this.countWithResolvedFilters(type, where, resolvedFieldFilters);
1472
+ }
1473
+ async countWithResolvedFilters(type, where, resolvedFieldFilters) {
1474
+ const tableName = getTableName(type);
1475
+ let query = this.db.selectFrom(tableName).select((eb) => eb.fn.count("id").as("count")).where("deleted_at", "is", null);
1476
+ if (where?.status) query = query.where("status", "=", where.status);
1477
+ if (where?.authorId) query = query.where("author_id", "=", where.authorId);
1478
+ if (where?.locale) query = query.where("locale", "=", where.locale);
1479
+ query = this.applySearchFilter(query, where, type);
1480
+ query = this.applyDateFilter(query, where);
1481
+ query = this.applyBylineFilter(query, where, type);
1482
+ query = this.applyFieldFilters(query, resolvedFieldFilters);
1483
+ const result = await query.executeTakeFirst();
1484
+ return Number(result?.count || 0);
1485
+ }
1486
+ /**
1487
+ * Distinct, non-null `author_id` values across the collection's live
1488
+ * (non-trashed) content. Used to populate the admin author filter with
1489
+ * only the users who have actually authored entries, rather than the
1490
+ * full user directory (which requires admin privileges to read).
1491
+ */
1492
+ async findDistinctAuthorIds(type) {
1493
+ const tableName = getTableName(type);
1494
+ return (await this.db.selectFrom(tableName).select("author_id").distinct().where("deleted_at", "is", null).where("author_id", "is not", null).execute()).map((row) => row.author_id).filter((id) => id !== null);
1495
+ }
1496
+ async getStats(type, now = /* @__PURE__ */ new Date()) {
1497
+ const tableName = getTableName(type);
1498
+ const nowIso = now.toISOString();
1499
+ const result = await this.db.selectFrom(tableName).select((eb) => [
1500
+ eb.fn.count("id").as("total"),
1501
+ eb.fn.sum(eb.case().when("status", "=", "published").then(1).else(0).end()).as("published"),
1502
+ eb.fn.sum(eb.case().when("status", "=", "draft").then(1).else(0).end()).as("draft"),
1503
+ sql`SUM(CASE WHEN scheduled_at IS NOT NULL THEN 1 ELSE 0 END)`.as("scheduled"),
1504
+ sql`SUM(CASE WHEN scheduled_at IS NOT NULL AND scheduled_at <= ${nowIso} THEN 1 ELSE 0 END)`.as("overdue_scheduled")
1505
+ ]).where("deleted_at", "is", null).executeTakeFirst();
1506
+ return {
1507
+ total: Number(result?.total || 0),
1508
+ published: Number(result?.published || 0),
1509
+ draft: Number(result?.draft || 0),
1510
+ scheduled: Number(result?.scheduled || 0),
1511
+ overdueScheduled: Number(result?.overdue_scheduled || 0)
1512
+ };
1513
+ }
1514
+ /**
1515
+ * Schedule content for future publishing
1516
+ *
1517
+ * Sets status to 'scheduled' and stores the scheduled publish time.
1518
+ * The content will be auto-published when the scheduled time is reached.
1519
+ */
1520
+ async schedule(type, id, scheduledAt, currentTime = /* @__PURE__ */ new Date(), expectedRevision) {
1521
+ const tableName = getTableName(type);
1522
+ const now = currentTime.toISOString();
1523
+ const normalizedScheduledAt = await this.datetimes.normalizeValue(type, scheduledAt);
1524
+ if (new Date(normalizedScheduledAt) <= currentTime) throw new EmDashValidationError("Scheduled date must be in the future");
1525
+ const existing = await this.findById(type, id);
1526
+ if (!existing) throw new EmDashValidationError("Content item not found");
1527
+ assertRevisionPrecondition(existing, expectedRevision);
1528
+ const newStatus = existing.status === "published" ? "published" : "scheduled";
1529
+ if (((await sql`
1530
+ UPDATE ${sql.ref(tableName)}
1531
+ SET status = ${newStatus},
1532
+ scheduled_at = ${normalizedScheduledAt},
1533
+ updated_at = ${now}
1534
+ WHERE id = ${id}
1535
+ AND deleted_at IS NULL
1536
+ AND version = ${existing.version}
1537
+ AND updated_at = ${existing.updatedAt}
1538
+ AND status = ${existing.status}
1539
+ AND ${nullableColumnMatch("scheduled_at", existing.scheduledAt)}
1540
+ `.execute(this.db)).numAffectedRows ?? 0n) === 0n) throw new ContentMutationConflictError("Content changed while scheduling");
1541
+ invalidateCollectionCache(type);
1542
+ const updated = await this.findById(type, id);
1543
+ if (!updated) throw new Error("Content not found");
1544
+ return updated;
1545
+ }
1546
+ /**
1547
+ * Unschedule content
1548
+ *
1549
+ * Clears the scheduled time. Published posts stay published;
1550
+ * draft/scheduled posts revert to 'draft'.
1551
+ */
1552
+ async unschedule(type, id, expectedRevision) {
1553
+ const tableName = getTableName(type);
1554
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1555
+ const existing = await this.findById(type, id);
1556
+ if (!existing) throw new EmDashValidationError("Content item not found");
1557
+ assertRevisionPrecondition(existing, expectedRevision);
1558
+ const newStatus = existing.status === "published" ? "published" : "draft";
1559
+ const result = await sql`
1560
+ UPDATE ${sql.ref(tableName)}
1561
+ SET status = ${newStatus},
1562
+ scheduled_at = NULL,
1563
+ updated_at = ${now}
1564
+ WHERE id = ${id}
1565
+ AND scheduled_at IS NOT NULL
1566
+ AND deleted_at IS NULL
1567
+ AND version = ${existing.version}
1568
+ AND updated_at = ${existing.updatedAt}
1569
+ AND status = ${existing.status}
1570
+ AND ${nullableColumnMatch("scheduled_at", existing.scheduledAt)}
1571
+ `.execute(this.db);
1572
+ if (existing.scheduledAt !== null && (result.numAffectedRows ?? 0n) === 0n) throw new ContentMutationConflictError("Content changed while unscheduling");
1573
+ invalidateCollectionCache(type);
1574
+ const updated = await this.findById(type, id);
1575
+ if (!updated) throw new Error("Content not found");
1576
+ return updated;
1577
+ }
1578
+ /**
1579
+ * Find content that is ready to be published
1580
+ *
1581
+ * Returns all content where scheduled_at <= now, regardless of status.
1582
+ * This covers both draft-scheduled posts (status='scheduled') and
1583
+ * published posts with scheduled draft changes (status='published').
1584
+ *
1585
+ * `limit` (optional) caps how many due rows are returned, oldest-due first.
1586
+ * The scheduled-publishing sweep passes a limit so a large backlog can't
1587
+ * fan out unbounded publish/webhook work in a single tick (and blow a Worker
1588
+ * invocation's CPU/subrequest budget); the remainder drains on later ticks.
1589
+ */
1590
+ async findReadyToPublish(type, limit, currentTime = /* @__PURE__ */ new Date(), after) {
1591
+ const tableName = getTableName(type);
1592
+ const now = currentTime.toISOString();
1593
+ const limitClause = typeof limit === "number" && Number.isInteger(limit) && limit > 0 ? sql`LIMIT ${limit}` : sql``;
1594
+ const afterClause = after ? sql`AND (scheduled_at > ${after.scheduledAt} OR (scheduled_at = ${after.scheduledAt} AND id > ${after.id}))` : sql``;
1595
+ return (await sql`
1596
+ SELECT * FROM ${sql.ref(tableName)}
1597
+ WHERE scheduled_at IS NOT NULL
1598
+ AND scheduled_at <= ${now}
1599
+ AND deleted_at IS NULL
1600
+ ${afterClause}
1601
+ ORDER BY scheduled_at ASC, id ASC
1602
+ ${limitClause}
1603
+ `.execute(this.db)).rows.map((row) => this.mapRow(type, row));
1604
+ }
1605
+ /**
1606
+ * Find all translations in a translation group
1607
+ */
1608
+ async findTranslations(type, translationGroup) {
1609
+ const tableName = getTableName(type);
1610
+ return (await sql`
1611
+ SELECT * FROM ${sql.ref(tableName)}
1612
+ WHERE translation_group = ${translationGroup}
1613
+ AND deleted_at IS NULL
1614
+ ORDER BY locale ASC
1615
+ `.execute(this.db)).rows.map((row) => this.mapRow(type, row));
1616
+ }
1617
+ /** Whether any row of `translationGroup` exists, trashed rows included. */
1618
+ async hasTranslationsIncludingTrashed(type, translationGroup) {
1619
+ const tableName = getTableName(type);
1620
+ return (await sql`
1621
+ SELECT id FROM ${sql.ref(tableName)}
1622
+ WHERE translation_group = ${translationGroup}
1623
+ LIMIT 1
1624
+ `.execute(this.db)).rows.length > 0;
1625
+ }
1626
+ /**
1627
+ * Batch variant of {@link findTranslations}: every (non-deleted) locale
1628
+ * variant for any of `translationGroups`, in one `WHERE translation_group IN
1629
+ * (...)` query chunked at `SQL_BATCH_SIZE` for D1's bind-parameter limit.
1630
+ * Lets callers resolve many edge groups without an N+1 per group. The caller
1631
+ * groups the flat result by `translationGroup` itself.
1632
+ *
1633
+ * `translation_group` leads the sort so the ordering follows
1634
+ * `idx_{table}_del_tg_locale` past its `deleted_at` equality; callers group by
1635
+ * `translationGroup`, so the per-group locale order they rely on is preserved.
1636
+ *
1637
+ * `publishedOnly` restricts the result to `status = 'published'` — reference
1638
+ * reads pass this for callers without `content:read_drafts` so draft/scheduled
1639
+ * entries never leak through an edge traversal.
1640
+ *
1641
+ * A reference edge stores only a collection slug (no SQL FK), so the table may
1642
+ * have been dropped since the edge was written. That is a tolerated dangling
1643
+ * state, not an error: a missing table resolves to no rows, mirroring how the
1644
+ * content read handlers treat `isMissingTableError`.
1645
+ */
1646
+ async findTranslationsForGroups(type, translationGroups, options = {}) {
1647
+ if (translationGroups.length === 0) return [];
1648
+ const tableName = getTableName(type);
1649
+ const publishedFilter = options.publishedOnly ? sql`AND status = 'published'` : sql``;
1650
+ const items = [];
1651
+ try {
1652
+ for (const chunk of chunks(translationGroups, SQL_BATCH_SIZE)) {
1653
+ const result = await sql`
1654
+ SELECT * FROM ${sql.ref(tableName)}
1655
+ WHERE translation_group IN (${sql.join(chunk)})
1656
+ AND deleted_at IS NULL
1657
+ ${publishedFilter}
1658
+ ORDER BY translation_group ASC, locale ASC
1659
+ `.execute(this.db);
1660
+ for (const row of result.rows) items.push(this.mapRow(type, row));
1661
+ }
1662
+ } catch (error) {
1663
+ if (isMissingTableError(error)) return [];
1664
+ throw error;
1665
+ }
1666
+ return items;
1667
+ }
1668
+ /**
1669
+ * Batch variant of {@link findByIdOrSlug}: resolve many identifiers (each an
1670
+ * id OR a slug) within `type` in a constant number of queries — one `WHERE id
1671
+ * IN (...)` and one `WHERE slug IN (...)`, each chunked at `SQL_BATCH_SIZE`.
1672
+ * Returns a map from the input identifier to its resolved item; identifiers
1673
+ * that match nothing are absent. Used on write paths that accept a list of
1674
+ * references, so a single request doesn't fan out to an N+1 of point lookups.
1675
+ *
1676
+ * Resolution mirrors {@link findByIdOrSlug}: a ULID-shaped identifier prefers
1677
+ * the id match and falls back to slug; anything else prefers the slug match
1678
+ * and falls back to id. Slug matches collapse to the lowest-locale variant
1679
+ * (`ORDER BY locale ASC`), matching the slug-without-locale lookup.
1680
+ */
1681
+ async findManyByIdOrSlug(type, identifiers) {
1682
+ const resolved = /* @__PURE__ */ new Map();
1683
+ const unique = [...new Set(identifiers)];
1684
+ if (unique.length === 0) return resolved;
1685
+ const tableName = getTableName(type);
1686
+ const byId = /* @__PURE__ */ new Map();
1687
+ const bySlug = /* @__PURE__ */ new Map();
1688
+ try {
1689
+ for (const chunk of chunks(unique, SQL_BATCH_SIZE)) {
1690
+ const idRows = await sql`
1691
+ SELECT * FROM ${sql.ref(tableName)}
1692
+ WHERE id IN (${sql.join(chunk)})
1693
+ AND deleted_at IS NULL
1694
+ `.execute(this.db);
1695
+ for (const row of idRows.rows) {
1696
+ const item = this.mapRow(type, row);
1697
+ byId.set(item.id, item);
1698
+ }
1699
+ const slugRows = await sql`
1700
+ SELECT * FROM ${sql.ref(tableName)}
1701
+ WHERE slug IN (${sql.join(chunk)})
1702
+ AND deleted_at IS NULL
1703
+ ORDER BY locale ASC
1704
+ `.execute(this.db);
1705
+ for (const row of slugRows.rows) {
1706
+ const item = this.mapRow(type, row);
1707
+ if (item.slug != null && !bySlug.has(item.slug)) bySlug.set(item.slug, item);
1708
+ }
1709
+ }
1710
+ } catch (error) {
1711
+ if (isMissingTableError(error)) return resolved;
1712
+ throw error;
1713
+ }
1714
+ for (const identifier of unique) {
1715
+ const item = ULID_PATTERN.test(identifier) ? byId.get(identifier) ?? bySlug.get(identifier) : bySlug.get(identifier) ?? byId.get(identifier);
1716
+ if (item) resolved.set(identifier, item);
1717
+ }
1718
+ return resolved;
1719
+ }
1720
+ /**
1721
+ * Publish the current draft
1722
+ *
1723
+ * Promotes draft_revision_id to live_revision_id and clears draft pointer.
1724
+ * Syncs the draft revision's data into the content table columns so the
1725
+ * content table always reflects the published version.
1726
+ * If no draft revision exists, creates one from current data and publishes it.
1727
+ * When `promoteRevision` is false, publishes the current content-table data
1728
+ * by changing lifecycle metadata only.
1729
+ *
1730
+ * `publishedAt` (optional) overrides the publication timestamp. If omitted,
1731
+ * the existing `published_at` is preserved (idempotent re-publish keeps the
1732
+ * original date) and falls back to the current time on first publish. Pass
1733
+ * an explicit value to backdate a publish (e.g. when migrating content from
1734
+ * another CMS).
1735
+ *
1736
+ * `requireDue` gates the final update on the row still being due.
1737
+ * `expectedScheduledAt` additionally fences changes made after a sweep
1738
+ * selected the row but before publication preparation began.
1739
+ */
1740
+ async publish(type, id, publishedAt, requireDue = false, expectedScheduledAt, promoteRevision = true, requireSlug = true, expectedRevision, currentTime = /* @__PURE__ */ new Date()) {
1741
+ const tableName = getTableName(type);
1742
+ const now = currentTime.toISOString();
1743
+ const existing = await this.findById(type, id);
1744
+ if (!existing) throw new EmDashValidationError("Content item not found");
1745
+ assertRevisionPrecondition(existing, expectedRevision);
1746
+ const requestedPublishedAt = publishedAt ? await this.datetimes.normalizeValue(type, publishedAt) : void 0;
1747
+ const currentPublishedAt = existing.publishedAt ? await this.datetimes.normalizeValue(type, existing.publishedAt) : null;
1748
+ if (requireDue && expectedScheduledAt !== void 0 && existing.scheduledAt !== expectedScheduledAt) throw new ScheduledNotDueError();
1749
+ if (!promoteRevision && requireSlug && !existing.slug?.trim()) throw new EmDashValidationError("Cannot publish routable content without a slug");
1750
+ if (!promoteRevision) {
1751
+ const revisionRepo = new RevisionRepository(this.db);
1752
+ let provisionalRevisionId = null;
1753
+ try {
1754
+ let liveRevisionId = existing.liveRevisionId;
1755
+ if (!liveRevisionId) {
1756
+ const revision = await revisionRepo.create({
1757
+ collection: type,
1758
+ entryId: id,
1759
+ data: existing.data
1760
+ });
1761
+ liveRevisionId = revision.id;
1762
+ provisionalRevisionId = revision.id;
1763
+ }
1764
+ const intendedPublishedAt = requestedPublishedAt ?? currentPublishedAt ?? now;
1765
+ const duePredicate = requireDue ? sql`AND scheduled_at IS NOT NULL AND scheduled_at <= ${now}` : sql``;
1766
+ let published = false;
1767
+ try {
1768
+ published = ((await sql`
1769
+ UPDATE ${sql.ref(tableName)}
1770
+ SET live_revision_id = ${liveRevisionId},
1771
+ draft_revision_id = NULL,
1772
+ status = 'published',
1773
+ scheduled_at = NULL,
1774
+ published_at = ${intendedPublishedAt},
1775
+ updated_at = ${now},
1776
+ version = version + 1
1777
+ WHERE id = ${id}
1778
+ AND deleted_at IS NULL
1779
+ AND version = ${existing.version}
1780
+ AND updated_at = ${existing.updatedAt}
1781
+ AND status = ${existing.status}
1782
+ AND ${nullableColumnMatch("live_revision_id", existing.liveRevisionId)}
1783
+ AND ${nullableColumnMatch("draft_revision_id", existing.draftRevisionId)}
1784
+ AND ${nullableColumnMatch("scheduled_at", existing.scheduledAt)}
1785
+ ${duePredicate}
1786
+ `.execute(this.db)).numAffectedRows ?? 0n) > 0n;
1787
+ } catch (error) {
1788
+ if (isConfirmedStatementFailure(error)) throw error;
1789
+ let observed;
1790
+ try {
1791
+ observed = await this.findById(type, id);
1792
+ } catch (reconciliationError) {
1793
+ throw new Error("Unable to confirm whether content publication completed", { cause: reconciliationError });
1794
+ }
1795
+ if (!observed) throw new Error("Unable to confirm whether content publication completed", { cause: error });
1796
+ published = matchesLifecyclePublication(observed, existing, liveRevisionId, intendedPublishedAt, now);
1797
+ if (!published && matchesPublicationFence(observed, existing)) throw error;
1798
+ if (!published) throw new Error("Unable to confirm whether content publication completed", { cause: error });
1799
+ }
1800
+ if (!published) throw requireDue ? new ScheduledNotDueError() : new ContentMutationConflictError();
1801
+ invalidateCollectionCache(type);
1802
+ const updated = await this.findById(type, id);
1803
+ if (!updated) throw new Error("Content not found");
1804
+ return updated;
1805
+ } catch (error) {
1806
+ if (provisionalRevisionId) try {
1807
+ await revisionRepo.deleteIfUnreferenced(type, id, provisionalRevisionId);
1808
+ } catch (cleanupError) {
1809
+ console.error(`[content] Failed to clean up provisional revision ${provisionalRevisionId}:`, cleanupError);
1810
+ }
1811
+ throw error;
1812
+ }
1813
+ }
1814
+ const revisionRepo = new RevisionRepository(this.db);
1815
+ let provisionalRevisionId = null;
1816
+ try {
1817
+ let revisionToPublish = existing.draftRevisionId || existing.liveRevisionId;
1818
+ if (!revisionToPublish) {
1819
+ const revision = await revisionRepo.create({
1820
+ collection: type,
1821
+ entryId: id,
1822
+ data: existing.data
1823
+ });
1824
+ revisionToPublish = revision.id;
1825
+ provisionalRevisionId = revision.id;
1826
+ }
1827
+ const revision = await revisionRepo.findById(revisionToPublish);
1828
+ if (!revision || revision.collection !== type || revision.entryId !== id) throw new EmDashValidationError("Revision does not belong to the specified content item");
1829
+ const stagedSlug = typeof revision.data._slug === "string" ? revision.data._slug : null;
1830
+ const intendedSlug = stagedSlug ?? existing.slug;
1831
+ if (requireSlug && !intendedSlug?.trim()) throw new EmDashValidationError("Cannot publish routable content without a slug");
1832
+ const intendedPublishedAt = requestedPublishedAt ?? currentPublishedAt ?? now;
1833
+ if (stagedSlug !== null && stagedSlug !== existing.slug && existing.locale !== null) {
1834
+ const conflict = await this.findBySlugIncludingTrashed(type, stagedSlug, existing.locale);
1835
+ if (conflict && conflict.id !== id) throw new EmDashValidationError(`Cannot publish: slug '${stagedSlug}' is already used by another entry in this collection (id: ${conflict.id}). Choose a different slug.`, { code: "SLUG_CONFLICT" });
1836
+ }
1837
+ const assignments = [];
1838
+ if (stagedSlug !== null) assignments.push(sql`slug = ${stagedSlug}`);
1839
+ for (const [key, value] of Object.entries(revision.data)) {
1840
+ if (SYSTEM_COLUMNS.has(key) || key.startsWith("_")) continue;
1841
+ validateIdentifier(key, "content field name");
1842
+ assignments.push(sql`${sql.ref(key)} = ${serializeValue(value)}`);
1843
+ }
1844
+ assignments.push(sql`live_revision_id = ${revisionToPublish}`, sql`draft_revision_id = NULL`, sql`status = 'published'`, sql`scheduled_at = NULL`, sql`published_at = ${intendedPublishedAt}`, sql`updated_at = ${now}`, sql`version = version + 1`);
1845
+ const duePredicate = requireDue ? sql`AND scheduled_at IS NOT NULL AND scheduled_at <= ${now}` : sql``;
1846
+ let promoted = false;
1847
+ try {
1848
+ promoted = ((await sql`
1849
+ UPDATE ${sql.ref(tableName)}
1850
+ SET ${sql.join(assignments, sql`, `)}
1851
+ WHERE id = ${id}
1852
+ AND deleted_at IS NULL
1853
+ AND version = ${existing.version}
1854
+ AND updated_at = ${existing.updatedAt}
1855
+ AND status = ${existing.status}
1856
+ AND ${nullableColumnMatch("live_revision_id", existing.liveRevisionId)}
1857
+ AND ${nullableColumnMatch("draft_revision_id", existing.draftRevisionId)}
1858
+ AND ${nullableColumnMatch("scheduled_at", existing.scheduledAt)}
1859
+ ${duePredicate}
1860
+ AND EXISTS (
1861
+ SELECT 1 FROM revisions
1862
+ WHERE revisions.id = ${revisionToPublish}
1863
+ AND revisions.collection = ${type}
1864
+ AND revisions.entry_id = ${id}
1865
+ )
1866
+ `.execute(this.db)).numAffectedRows ?? 0n) > 0n;
1867
+ } catch (error) {
1868
+ if (isConfirmedStatementFailure(error)) throw error;
1869
+ let observed;
1870
+ try {
1871
+ observed = await this.findById(type, id);
1872
+ } catch (reconciliationError) {
1873
+ throw new Error("Unable to confirm whether content publication completed", { cause: reconciliationError });
1874
+ }
1875
+ if (!observed) throw new Error("Unable to confirm whether content publication completed", { cause: error });
1876
+ promoted = matchesPublication(observed, existing, revision, revisionToPublish, intendedSlug, intendedPublishedAt, now);
1877
+ if (!promoted && matchesPublicationFence(observed, existing)) throw error;
1878
+ if (!promoted) throw new Error("Unable to confirm whether content publication completed", { cause: error });
1879
+ }
1880
+ if (!promoted) throw requireDue ? new ScheduledNotDueError() : new ContentMutationConflictError();
1881
+ invalidateCollectionCache(type);
1882
+ const updated = await this.findById(type, id);
1883
+ if (!updated) throw new Error("Content not found");
1884
+ return updated;
1885
+ } catch (error) {
1886
+ if (provisionalRevisionId) try {
1887
+ await revisionRepo.deleteIfUnreferenced(type, id, provisionalRevisionId);
1888
+ } catch (cleanupError) {
1889
+ console.error(`[content] Failed to clean up provisional revision ${provisionalRevisionId}:`, cleanupError);
1890
+ }
1891
+ throw error;
1892
+ }
1893
+ }
1894
+ /**
1895
+ * Unpublish content
1896
+ *
1897
+ * Removes live pointer and cancels any pending schedule, but preserves the
1898
+ * draft and publication date. If no draft exists, creates one from the live
1899
+ * version so the content isn't lost.
1900
+ */
1901
+ async unpublish(type, id, expectedRevision) {
1902
+ const tableName = getTableName(type);
1903
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1904
+ const existing = await this.findById(type, id);
1905
+ if (!existing) throw new EmDashValidationError("Content item not found");
1906
+ assertRevisionPrecondition(existing, expectedRevision);
1907
+ if (existing.status === "draft" && !existing.liveRevisionId && !existing.scheduledAt) return existing;
1908
+ const revisionRepo = new RevisionRepository(this.db);
1909
+ let provisionalRevisionId = null;
1910
+ try {
1911
+ let draftRevisionId = existing.draftRevisionId;
1912
+ if (!draftRevisionId && existing.liveRevisionId) {
1913
+ const liveRevision = await revisionRepo.findById(existing.liveRevisionId);
1914
+ if (liveRevision) {
1915
+ const draft = await revisionRepo.create({
1916
+ collection: type,
1917
+ entryId: id,
1918
+ data: liveRevision.data
1919
+ });
1920
+ draftRevisionId = draft.id;
1921
+ provisionalRevisionId = draft.id;
1922
+ }
1923
+ }
1924
+ if (((await sql`
1925
+ UPDATE ${sql.ref(tableName)}
1926
+ SET live_revision_id = NULL,
1927
+ draft_revision_id = ${draftRevisionId},
1928
+ status = 'draft',
1929
+ scheduled_at = NULL,
1930
+ updated_at = ${now},
1931
+ version = version + 1
1932
+ WHERE id = ${id}
1933
+ AND deleted_at IS NULL
1934
+ AND version = ${existing.version}
1935
+ AND updated_at = ${existing.updatedAt}
1936
+ AND status = ${existing.status}
1937
+ AND ${nullableColumnMatch("live_revision_id", existing.liveRevisionId)}
1938
+ AND ${nullableColumnMatch("draft_revision_id", existing.draftRevisionId)}
1939
+ AND ${nullableColumnMatch("scheduled_at", existing.scheduledAt)}
1940
+ `.execute(this.db)).numAffectedRows ?? 0n) === 0n) throw new ContentMutationConflictError();
1941
+ invalidateCollectionCache(type);
1942
+ const updated = await this.findById(type, id);
1943
+ if (!updated) throw new Error("Content not found");
1944
+ return updated;
1945
+ } catch (error) {
1946
+ if (provisionalRevisionId) try {
1947
+ await revisionRepo.deleteIfUnreferenced(type, id, provisionalRevisionId);
1948
+ } catch (cleanupError) {
1949
+ console.error(`[content] Failed to clean up provisional revision ${provisionalRevisionId}:`, cleanupError);
1950
+ }
1951
+ throw error;
1952
+ }
1953
+ }
1954
+ /**
1955
+ * Set the draft revision pointer for a content item.
1956
+ *
1957
+ * Used by seed/import paths that stage a new revision's data before
1958
+ * promoting it to live via `publish()`.
1959
+ *
1960
+ * Validates that the content item exists and is not soft-deleted, that
1961
+ * the revision exists, and that the revision belongs to the same
1962
+ * collection and entry. Without these checks, a caller could leave the
1963
+ * content row pointing at a missing or unrelated revision.
1964
+ */
1965
+ async setDraftRevision(type, id, revisionId) {
1966
+ const existing = await this.findById(type, id);
1967
+ if (!existing) throw new EmDashValidationError("Content item not found");
1968
+ const revision = await new RevisionRepository(this.db).findById(revisionId);
1969
+ if (!revision) throw new EmDashValidationError("Revision not found");
1970
+ if (revision.collection !== type || revision.entryId !== id) throw new EmDashValidationError("Revision does not belong to the specified content item");
1971
+ if (!await this.replaceDraftRevision(type, id, revisionId, existing)) throw new ContentMutationConflictError();
1972
+ }
1973
+ async replaceDraftRevision(type, id, revisionId, expected) {
1974
+ const tableName = getTableName(type);
1975
+ return ((await sql`
1976
+ UPDATE ${sql.ref(tableName)}
1977
+ SET draft_revision_id = ${revisionId},
1978
+ version = version + 1
1979
+ WHERE id = ${id}
1980
+ AND deleted_at IS NULL
1981
+ AND version = ${expected.version}
1982
+ AND ${nullableColumnMatch("live_revision_id", expected.liveRevisionId)}
1983
+ AND ${nullableColumnMatch("draft_revision_id", expected.draftRevisionId)}
1984
+ AND EXISTS (
1985
+ SELECT 1 FROM revisions
1986
+ WHERE revisions.id = ${revisionId}
1987
+ AND revisions.collection = ${type}
1988
+ AND revisions.entry_id = ${id}
1989
+ )
1990
+ `.execute(this.db)).numAffectedRows ?? 0n) > 0n;
1991
+ }
1992
+ /**
1993
+ * Discard pending draft changes
1994
+ *
1995
+ * Clears draft_revision_id. The content table columns already hold the
1996
+ * published version, so no data sync is needed.
1997
+ */
1998
+ async discardDraft(type, id, expectedRevision) {
1999
+ const tableName = getTableName(type);
2000
+ const existing = await this.findById(type, id);
2001
+ if (!existing) throw new EmDashValidationError("Content item not found");
2002
+ assertRevisionPrecondition(existing, expectedRevision);
2003
+ if (!existing.draftRevisionId) return existing;
2004
+ if (((await sql`
2005
+ UPDATE ${sql.ref(tableName)}
2006
+ SET draft_revision_id = NULL,
2007
+ version = version + 1
2008
+ WHERE id = ${id}
2009
+ AND deleted_at IS NULL
2010
+ AND version = ${existing.version}
2011
+ AND updated_at = ${existing.updatedAt}
2012
+ AND status = ${existing.status}
2013
+ AND ${nullableColumnMatch("live_revision_id", existing.liveRevisionId)}
2014
+ AND ${nullableColumnMatch("draft_revision_id", existing.draftRevisionId)}
2015
+ AND ${nullableColumnMatch("scheduled_at", existing.scheduledAt)}
2016
+ `.execute(this.db)).numAffectedRows ?? 0n) === 0n) throw new ContentMutationConflictError();
2017
+ const updated = await this.findById(type, id);
2018
+ if (!updated) throw new Error("Content not found");
2019
+ return updated;
2020
+ }
2021
+ /**
2022
+ * Count content items with a pending schedule.
2023
+ * Includes both draft-scheduled (status='scheduled') and published
2024
+ * posts with scheduled draft changes (status='published', scheduled_at set).
2025
+ */
2026
+ async countScheduled(type) {
2027
+ const tableName = getTableName(type);
2028
+ const result = await sql`
2029
+ SELECT COUNT(id) as count FROM ${sql.ref(tableName)}
2030
+ WHERE scheduled_at IS NOT NULL
2031
+ AND deleted_at IS NULL
2032
+ `.execute(this.db);
2033
+ return Number(result.rows[0]?.count || 0);
2034
+ }
2035
+ /**
2036
+ * Map database row to ContentItem
2037
+ * Extracts system columns and puts content fields in data
2038
+ * Excludes null values from data to match input semantics
2039
+ */
2040
+ mapRow(type, row) {
2041
+ const data = {};
2042
+ for (const [key, value] of Object.entries(row)) if (!SYSTEM_COLUMNS.has(key) && value !== null) data[key] = deserializeValue(value);
2043
+ return {
2044
+ id: row.id,
2045
+ type,
2046
+ slug: row.slug,
2047
+ status: row.status,
2048
+ data,
2049
+ authorId: row.author_id,
2050
+ primaryBylineId: row.primary_byline_id ?? null,
2051
+ createdAt: row.created_at,
2052
+ updatedAt: row.updated_at,
2053
+ publishedAt: row.published_at,
2054
+ scheduledAt: row.scheduled_at,
2055
+ liveRevisionId: row.live_revision_id ?? null,
2056
+ draftRevisionId: row.draft_revision_id ?? null,
2057
+ version: typeof row.version === "number" ? row.version : 1,
2058
+ locale: row.locale ?? null,
2059
+ translationGroup: row.translation_group ?? null
2060
+ };
2061
+ }
2062
+ normalizeFilterScalar(field, type, value) {
2063
+ if (type === "number" || type === "integer") {
2064
+ if (typeof value !== "number" || !Number.isFinite(value)) throw new EmDashValidationError(`Filter for field "${field}" must use a finite number`);
2065
+ if (type === "integer" && !Number.isInteger(value)) throw new EmDashValidationError(`Filter for field "${field}" must use an integer`);
2066
+ return value;
2067
+ }
2068
+ if (type === "boolean") {
2069
+ if (typeof value !== "boolean") throw new EmDashValidationError(`Filter for field "${field}" must use a boolean`);
2070
+ return value ? 1 : 0;
2071
+ }
2072
+ if (typeof value !== "string") throw new EmDashValidationError(`Filter for field "${field}" must use a string`);
2073
+ if (value.length > MAX_FILTER_STRING_LENGTH) throw new EmDashValidationError(`Filter value for field "${field}" exceeds ${MAX_FILTER_STRING_LENGTH} characters`);
2074
+ if (type === "datetime") try {
2075
+ return normalizeExplicitDatetime(value);
2076
+ } catch {
2077
+ throw new EmDashValidationError(`Filter for datetime field "${field}" must use an ISO 8601 datetime with Z or an explicit offset`);
2078
+ }
2079
+ return value;
2080
+ }
2081
+ normalizeFieldFilter(field, type, value) {
2082
+ if (value === null) return {
2083
+ column: field,
2084
+ kind: "null"
2085
+ };
2086
+ if (typeof value !== "object") return {
2087
+ column: field,
2088
+ kind: "exact",
2089
+ value: this.normalizeFilterScalar(field, type, value)
2090
+ };
2091
+ if (Array.isArray(value)) throw new EmDashValidationError(`Invalid filter for field "${field}"`);
2092
+ const record = value;
2093
+ const keys = Object.keys(record);
2094
+ if (keys.length === 1 && keys[0] === "in") {
2095
+ if (!Array.isArray(record.in) || record.in.length === 0) throw new EmDashValidationError(`IN filter for field "${field}" must not be empty`);
2096
+ if (record.in.length > MAX_IN_FILTER_VALUES) throw new EmDashValidationError(`IN filter for field "${field}" exceeds ${MAX_IN_FILTER_VALUES} values`);
2097
+ return {
2098
+ column: field,
2099
+ kind: "in",
2100
+ values: record.in.map((entry) => this.normalizeFilterScalar(field, type, entry))
2101
+ };
2102
+ }
2103
+ const rangeKeys = new Set([
2104
+ "gt",
2105
+ "gte",
2106
+ "lt",
2107
+ "lte"
2108
+ ]);
2109
+ if (keys.length === 0 || keys.some((key) => !rangeKeys.has(key))) throw new EmDashValidationError(`Invalid filter operator for field "${field}"`);
2110
+ if (type === "boolean") throw new EmDashValidationError(`Boolean field "${field}" does not support range filters`);
2111
+ const bounds = {};
2112
+ for (const key of keys) {
2113
+ if (record[key] === void 0) continue;
2114
+ bounds[key] = this.normalizeFilterScalar(field, type, record[key]);
2115
+ }
2116
+ if (Object.keys(bounds).length === 0) throw new EmDashValidationError(`Range filter for field "${field}" has no bounds`);
2117
+ return {
2118
+ column: field,
2119
+ kind: "range",
2120
+ bounds
2121
+ };
2122
+ }
2123
+ async collectionExists(type) {
2124
+ return await this.db.selectFrom("_emdash_collections").where("slug", "=", type).select("id").executeTakeFirst() !== void 0;
2125
+ }
2126
+ async resolveFieldFilters(type, filters) {
2127
+ const resolvedFilters = filters ?? {};
2128
+ const fields = Object.keys(resolvedFilters);
2129
+ if (fields.length === 0) return [];
2130
+ if (fields.length > MAX_INDEXED_FIELD_FILTERS) {
2131
+ if (!await this.collectionExists(type)) return [];
2132
+ throw new EmDashValidationError(`Content list queries support at most ${MAX_INDEXED_FIELD_FILTERS} indexed field filters`);
2133
+ }
2134
+ const rows = await this.db.selectFrom("_emdash_fields as field").innerJoin("_emdash_collections as collection", "collection.id", "field.collection_id").where("collection.slug", "=", type).where("field.slug", "in", fields).where("field.indexed", "=", 1).select(["field.slug", "field.type"]).execute();
2135
+ const metadata = new Map(rows.map((row) => [row.slug, row.type]));
2136
+ if (metadata.size === 0 && !await this.collectionExists(type)) return [];
2137
+ for (const field of fields) try {
2138
+ validateIdentifier(field, "content filter field");
2139
+ } catch {
2140
+ throw new EmDashValidationError(`Invalid content filter field: ${field}`);
2141
+ }
2142
+ const normalized = fields.map((field) => {
2143
+ const fieldType = metadata.get(field);
2144
+ if (!fieldType || !isIndexableFieldType(fieldType)) throw new EmDashValidationError(`Cannot filter by field "${field}". Custom fields must be indexed before filtering.`);
2145
+ return this.normalizeFieldFilter(field, fieldType, resolvedFilters[field]);
2146
+ });
2147
+ if (normalized.reduce((total, filter) => {
2148
+ if (filter.kind === "null") return total;
2149
+ if (filter.kind === "exact") return total + 1;
2150
+ if (filter.kind === "in") return total + filter.values.length;
2151
+ return total + Object.keys(filter.bounds).length;
2152
+ }, 0) > SQL_BATCH_SIZE) throw new EmDashValidationError(`Indexed field filters have a total operand budget of ${SQL_BATCH_SIZE}`);
2153
+ return normalized;
2154
+ }
2155
+ applyFieldFilters(query, filters) {
2156
+ let next = query;
2157
+ for (const filter of filters) {
2158
+ const column = sql.ref(filter.column);
2159
+ const isPresent = sql`${column} IS NOT NULL`;
2160
+ if (filter.kind === "null") {
2161
+ next = next.where(() => sql`(${isPresent}) = FALSE AND ${column} IS NULL`);
2162
+ continue;
2163
+ }
2164
+ if (filter.kind === "exact") {
2165
+ next = next.where(() => sql`(${isPresent}) = TRUE AND ${column} = ${filter.value}`);
2166
+ continue;
2167
+ }
2168
+ if (filter.kind === "in") {
2169
+ const values = sql.join(filter.values.map((value) => sql`${value}`), sql`, `);
2170
+ next = next.where(() => sql`(${isPresent}) = TRUE AND ${column} IN (${values})`);
2171
+ continue;
2172
+ }
2173
+ next = next.where(() => sql`(${isPresent}) = TRUE`);
2174
+ if (filter.bounds.gt !== void 0) next = next.where(() => sql`${column} > ${filter.bounds.gt}`);
2175
+ if (filter.bounds.gte !== void 0) next = next.where(() => sql`${column} >= ${filter.bounds.gte}`);
2176
+ if (filter.bounds.lt !== void 0) next = next.where(() => sql`${column} < ${filter.bounds.lt}`);
2177
+ if (filter.bounds.lte !== void 0) next = next.where(() => sql`${column} <= ${filter.bounds.lte}`);
2178
+ }
2179
+ return next;
2180
+ }
2181
+ /**
2182
+ * Map order field names to database columns.
2183
+ * Only allows known fields to prevent column enumeration via crafted orderBy values.
2184
+ */
2185
+ mapOrderField(field, sortableExtras = []) {
2186
+ const mapped = ORDER_FIELD_COLUMNS[field];
2187
+ if (mapped) return mapped;
2188
+ if (sortableExtras.includes(field)) {
2189
+ validateIdentifier(field, "order field");
2190
+ return field;
2191
+ }
2192
+ throw new EmDashValidationError(`Invalid order field: ${field}`);
2193
+ }
2194
+ async resolveOrderField(type, field, sortableExtras = []) {
2195
+ try {
2196
+ return {
2197
+ column: this.mapOrderField(field, sortableExtras),
2198
+ indexedCustomField: false
2199
+ };
2200
+ } catch (error) {
2201
+ if (!(error instanceof EmDashValidationError)) throw error;
2202
+ }
2203
+ const customField = await this.db.selectFrom("_emdash_collections as collection").leftJoin("_emdash_fields as field", (join) => join.onRef("field.collection_id", "=", "collection.id").on("field.slug", "=", field).on("field.indexed", "=", 1)).where("collection.slug", "=", type).select(["collection.id as collectionId", "field.slug as fieldSlug"]).executeTakeFirst();
2204
+ if (!customField) throw new ContentCollectionNotFoundError(type);
2205
+ if (!customField.fieldSlug) throw new EmDashValidationError(`Invalid order field: ${field}. Custom fields must be indexed before sorting.`);
2206
+ validateIdentifier(customField.fieldSlug, "content order field");
2207
+ return {
2208
+ column: customField.fieldSlug,
2209
+ indexedCustomField: true
2210
+ };
2211
+ }
2212
+ };
2213
+
2214
+ //#endregion
2215
+ export { normalizeRevisionLimit as a, RevisionRepository as i, content_exports as n, keepKnownFields as o, isSystemOrderField as r, staleStoredKeys as s, ContentRepository as t };
2216
+ //# sourceMappingURL=content-DZ3B5qtA.mjs.map