emdash 0.36.0 → 0.38.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 (991) hide show
  1. package/dist/{activation-K0kGBWuJ.mjs → activation-DyNTe_Tl.mjs} +3 -3
  2. package/dist/{activation-K0kGBWuJ.mjs.map → activation-DyNTe_Tl.mjs.map} +1 -1
  3. package/dist/{adapters-CzL3H752.d.mts → adapters-DCEgOBXi.d.mts} +4 -2
  4. package/dist/{adapters-CzL3H752.d.mts.map → adapters-DCEgOBXi.d.mts.map} +1 -1
  5. package/dist/{allowed-origins-maylGaHv.mjs → allowed-origins-GFUVavRj.mjs} +2 -2
  6. package/dist/{allowed-origins-maylGaHv.mjs.map → allowed-origins-GFUVavRj.mjs.map} +1 -1
  7. package/dist/api/route-utils.d.mts +3 -3
  8. package/dist/api/route-utils.mjs +25 -24
  9. package/dist/api/route-utils.mjs.map +1 -1
  10. package/dist/api/schemas/index.d.mts +2 -2
  11. package/dist/api/schemas/index.mjs +5 -5
  12. package/dist/api-BvxJmnFY.mjs +10094 -0
  13. package/dist/api-BvxJmnFY.mjs.map +1 -0
  14. package/dist/{api-tokens-9YrrCoE6.mjs → api-tokens-xpGqMHrC.mjs} +2 -2
  15. package/dist/{api-tokens-9YrrCoE6.mjs.map → api-tokens-xpGqMHrC.mjs.map} +1 -1
  16. package/dist/{apply-B_VMpJ2P.mjs → apply-DLmM3R7f.mjs} +26 -22
  17. package/dist/apply-DLmM3R7f.mjs.map +1 -0
  18. package/dist/artifact-fetch-P2JXVwOq.mjs +972 -0
  19. package/dist/artifact-fetch-P2JXVwOq.mjs.map +1 -0
  20. package/dist/astro/image-endpoint.mjs +2 -2
  21. package/dist/astro/image-endpoint.mjs.map +1 -1
  22. package/dist/astro/index.d.mts +12 -12
  23. package/dist/astro/index.d.mts.map +1 -1
  24. package/dist/astro/index.mjs +138 -39
  25. package/dist/astro/index.mjs.map +1 -1
  26. package/dist/astro/middleware/auth.d.mts +10 -10
  27. package/dist/astro/middleware/auth.mjs +6 -6
  28. package/dist/astro/middleware/media-usage-write-fence.mjs +3 -3
  29. package/dist/astro/middleware/redirect.mjs +7 -5
  30. package/dist/astro/middleware/redirect.mjs.map +1 -1
  31. package/dist/astro/middleware/request-context.mjs +3 -3
  32. package/dist/astro/middleware/setup.mjs +1 -1
  33. package/dist/astro/middleware.d.mts +10 -10
  34. package/dist/astro/middleware.d.mts.map +1 -1
  35. package/dist/astro/middleware.mjs +223 -232
  36. package/dist/astro/middleware.mjs.map +1 -1
  37. package/dist/astro/routes/api/admin/allowed-domains/_domain_.mjs +6 -6
  38. package/dist/astro/routes/api/admin/allowed-domains/index.mjs +6 -6
  39. package/dist/astro/routes/api/admin/api-tokens/_id_.mjs +3 -3
  40. package/dist/astro/routes/api/admin/api-tokens/index.d.mts.map +1 -1
  41. package/dist/astro/routes/api/admin/api-tokens/index.mjs +5 -5
  42. package/dist/astro/routes/api/admin/api-tokens/index.mjs.map +1 -1
  43. package/dist/astro/routes/api/admin/byline-fields/_slug_/usage.mjs +4 -4
  44. package/dist/astro/routes/api/admin/byline-fields/_slug_.mjs +9 -9
  45. package/dist/astro/routes/api/admin/byline-fields/index.mjs +9 -9
  46. package/dist/astro/routes/api/admin/byline-fields/reorder.mjs +9 -9
  47. package/dist/astro/routes/api/admin/bylines/_id_/index.mjs +17 -17
  48. package/dist/astro/routes/api/admin/bylines/_id_/translations.mjs +17 -17
  49. package/dist/astro/routes/api/admin/bylines/index.mjs +17 -17
  50. package/dist/astro/routes/api/admin/comments/_id_/status.mjs +13 -13
  51. package/dist/astro/routes/api/admin/comments/_id_.mjs +5 -5
  52. package/dist/astro/routes/api/admin/comments/bulk.mjs +10 -10
  53. package/dist/astro/routes/api/admin/comments/counts.mjs +5 -5
  54. package/dist/astro/routes/api/admin/comments/index.mjs +10 -10
  55. package/dist/astro/routes/api/admin/hooks/exclusive/_hookName_.mjs +4 -4
  56. package/dist/astro/routes/api/admin/hooks/exclusive/index.mjs +3 -3
  57. package/dist/astro/routes/api/admin/media-usage/activation.mjs +13 -13
  58. package/dist/astro/routes/api/admin/media-usage/collection-deletions/index.mjs +15 -15
  59. package/dist/astro/routes/api/admin/media-usage/collection-deletions/retry.mjs +15 -15
  60. package/dist/astro/routes/api/admin/media-usage/progress.mjs +14 -14
  61. package/dist/astro/routes/api/admin/media-usage/repair.mjs +17 -17
  62. package/dist/astro/routes/api/admin/media-usage/work/index.mjs +15 -15
  63. package/dist/astro/routes/api/admin/media-usage/work/retry.mjs +15 -15
  64. package/dist/astro/routes/api/admin/oauth-clients/_id_.mjs +4 -4
  65. package/dist/astro/routes/api/admin/oauth-clients/_id_.mjs.map +1 -1
  66. package/dist/astro/routes/api/admin/oauth-clients/index.mjs +4 -4
  67. package/dist/astro/routes/api/admin/oauth-clients/index.mjs.map +1 -1
  68. package/dist/astro/routes/api/admin/plugins/_id_/disable.mjs +59 -56
  69. package/dist/astro/routes/api/admin/plugins/_id_/disable.mjs.map +1 -1
  70. package/dist/astro/routes/api/admin/plugins/_id_/enable.mjs +59 -56
  71. package/dist/astro/routes/api/admin/plugins/_id_/enable.mjs.map +1 -1
  72. package/dist/astro/routes/api/admin/plugins/_id_/index.mjs +57 -54
  73. package/dist/astro/routes/api/admin/plugins/_id_/index.mjs.map +1 -1
  74. package/dist/astro/routes/api/admin/plugins/_id_/mcp.mjs +4 -4
  75. package/dist/astro/routes/api/admin/plugins/_id_/settings.mjs +57 -54
  76. package/dist/astro/routes/api/admin/plugins/_id_/settings.mjs.map +1 -1
  77. package/dist/astro/routes/api/admin/plugins/_id_/uninstall.mjs +58 -55
  78. package/dist/astro/routes/api/admin/plugins/_id_/uninstall.mjs.map +1 -1
  79. package/dist/astro/routes/api/admin/plugins/_id_/update.mjs +58 -55
  80. package/dist/astro/routes/api/admin/plugins/_id_/update.mjs.map +1 -1
  81. package/dist/astro/routes/api/admin/plugins/index.mjs +57 -54
  82. package/dist/astro/routes/api/admin/plugins/index.mjs.map +1 -1
  83. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/icon.mjs +2 -2
  84. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/index.mjs +57 -54
  85. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/index.mjs.map +1 -1
  86. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.mjs +58 -55
  87. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.mjs.map +1 -1
  88. package/dist/astro/routes/api/admin/plugins/marketplace/index.mjs +57 -54
  89. package/dist/astro/routes/api/admin/plugins/marketplace/index.mjs.map +1 -1
  90. package/dist/astro/routes/api/admin/plugins/registry/_id_/uninstall.mjs +58 -55
  91. package/dist/astro/routes/api/admin/plugins/registry/_id_/uninstall.mjs.map +1 -1
  92. package/dist/astro/routes/api/admin/plugins/registry/_id_/update.d.mts.map +1 -1
  93. package/dist/astro/routes/api/admin/plugins/registry/_id_/update.mjs +64 -57
  94. package/dist/astro/routes/api/admin/plugins/registry/_id_/update.mjs.map +1 -1
  95. package/dist/astro/routes/api/admin/plugins/registry/artifact.mjs +18 -16
  96. package/dist/astro/routes/api/admin/plugins/registry/artifact.mjs.map +1 -1
  97. package/dist/astro/routes/api/admin/plugins/registry/install.d.mts.map +1 -1
  98. package/dist/astro/routes/api/admin/plugins/registry/install.mjs +65 -58
  99. package/dist/astro/routes/api/admin/plugins/registry/install.mjs.map +1 -1
  100. package/dist/astro/routes/api/admin/plugins/registry/verify.d.mts +8 -0
  101. package/dist/astro/routes/api/admin/plugins/registry/verify.d.mts.map +1 -0
  102. package/dist/astro/routes/api/admin/plugins/registry/verify.mjs +96 -0
  103. package/dist/astro/routes/api/admin/plugins/registry/verify.mjs.map +1 -0
  104. package/dist/astro/routes/api/admin/plugins/updates.mjs +57 -54
  105. package/dist/astro/routes/api/admin/plugins/updates.mjs.map +1 -1
  106. package/dist/astro/routes/api/admin/themes/marketplace/_id_/index.mjs +57 -54
  107. package/dist/astro/routes/api/admin/themes/marketplace/_id_/index.mjs.map +1 -1
  108. package/dist/astro/routes/api/admin/themes/marketplace/_id_/thumbnail.mjs +2 -2
  109. package/dist/astro/routes/api/admin/themes/marketplace/index.mjs +57 -54
  110. package/dist/astro/routes/api/admin/themes/marketplace/index.mjs.map +1 -1
  111. package/dist/astro/routes/api/admin/users/_id_/disable.mjs +1 -1
  112. package/dist/astro/routes/api/admin/users/_id_/enable.mjs +1 -1
  113. package/dist/astro/routes/api/admin/users/_id_/index.mjs +6 -6
  114. package/dist/astro/routes/api/admin/users/_id_/send-recovery.mjs +3 -3
  115. package/dist/astro/routes/api/admin/users/index.mjs +6 -6
  116. package/dist/astro/routes/api/auth/dev-bypass.mjs +3 -3
  117. package/dist/astro/routes/api/auth/invite/accept.mjs +1 -1
  118. package/dist/astro/routes/api/auth/invite/complete.mjs +11 -11
  119. package/dist/astro/routes/api/auth/invite/index.mjs +8 -8
  120. package/dist/astro/routes/api/auth/invite/register-options.mjs +10 -10
  121. package/dist/astro/routes/api/auth/logout.mjs +2 -2
  122. package/dist/astro/routes/api/auth/magic-link/send.mjs +10 -10
  123. package/dist/astro/routes/api/auth/magic-link/verify.mjs +2 -2
  124. package/dist/astro/routes/api/auth/me.mjs +7 -7
  125. package/dist/astro/routes/api/auth/mode.mjs +2 -2
  126. package/dist/astro/routes/api/auth/oauth/_provider_/callback.mjs +4 -4
  127. package/dist/astro/routes/api/auth/oauth/_provider_.mjs +2 -2
  128. package/dist/astro/routes/api/auth/passkey/_id_.mjs +6 -6
  129. package/dist/astro/routes/api/auth/passkey/index.mjs +1 -1
  130. package/dist/astro/routes/api/auth/passkey/options.mjs +12 -12
  131. package/dist/astro/routes/api/auth/passkey/register/options.mjs +10 -10
  132. package/dist/astro/routes/api/auth/passkey/register/verify.mjs +11 -11
  133. package/dist/astro/routes/api/auth/passkey/verify.mjs +11 -11
  134. package/dist/astro/routes/api/auth/signup/complete.mjs +11 -11
  135. package/dist/astro/routes/api/auth/signup/request.mjs +10 -10
  136. package/dist/astro/routes/api/auth/signup/verify.mjs +1 -1
  137. package/dist/astro/routes/api/comments/_collection_/_contentId_/index.mjs +14 -14
  138. package/dist/astro/routes/api/comments/_collection_/_contentId_/reactions.mjs +13 -13
  139. package/dist/astro/routes/api/content/_collection_/_id_/compare.mjs +2 -2
  140. package/dist/astro/routes/api/content/_collection_/_id_/discard-draft.d.mts.map +1 -1
  141. package/dist/astro/routes/api/content/_collection_/_id_/discard-draft.mjs +19 -5
  142. package/dist/astro/routes/api/content/_collection_/_id_/discard-draft.mjs.map +1 -1
  143. package/dist/astro/routes/api/content/_collection_/_id_/duplicate.mjs +3 -3
  144. package/dist/astro/routes/api/content/_collection_/_id_/lock.d.mts +10 -0
  145. package/dist/astro/routes/api/content/_collection_/_id_/lock.d.mts.map +1 -0
  146. package/dist/astro/routes/api/content/_collection_/_id_/lock.mjs +66 -0
  147. package/dist/astro/routes/api/content/_collection_/_id_/lock.mjs.map +1 -0
  148. package/dist/astro/routes/api/content/_collection_/_id_/permanent.mjs +2 -2
  149. package/dist/astro/routes/api/content/_collection_/_id_/preview-url.mjs +11 -11
  150. package/dist/astro/routes/api/content/_collection_/_id_/publish.d.mts.map +1 -1
  151. package/dist/astro/routes/api/content/_collection_/_id_/publish.mjs +18 -10
  152. package/dist/astro/routes/api/content/_collection_/_id_/publish.mjs.map +1 -1
  153. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/children.mjs +20 -18
  154. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/children.mjs.map +1 -1
  155. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/parents.mjs +20 -18
  156. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/parents.mjs.map +1 -1
  157. package/dist/astro/routes/api/content/_collection_/_id_/restore.mjs +3 -3
  158. package/dist/astro/routes/api/content/_collection_/_id_/revisions.mjs +2 -2
  159. package/dist/astro/routes/api/content/_collection_/_id_/schedule.d.mts.map +1 -1
  160. package/dist/astro/routes/api/content/_collection_/_id_/schedule.mjs +15 -8
  161. package/dist/astro/routes/api/content/_collection_/_id_/schedule.mjs.map +1 -1
  162. package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.mjs +16 -15
  163. package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.mjs.map +1 -1
  164. package/dist/astro/routes/api/content/_collection_/_id_/translations.mjs +2 -2
  165. package/dist/astro/routes/api/content/_collection_/_id_/unpublish.d.mts.map +1 -1
  166. package/dist/astro/routes/api/content/_collection_/_id_/unpublish.mjs +19 -5
  167. package/dist/astro/routes/api/content/_collection_/_id_/unpublish.mjs.map +1 -1
  168. package/dist/astro/routes/api/content/_collection_/_id_.d.mts.map +1 -1
  169. package/dist/astro/routes/api/content/_collection_/_id_.mjs +23 -11
  170. package/dist/astro/routes/api/content/_collection_/_id_.mjs.map +1 -1
  171. package/dist/astro/routes/api/content/_collection_/authors.mjs +2 -2
  172. package/dist/astro/routes/api/content/_collection_/index.mjs +14 -9
  173. package/dist/astro/routes/api/content/_collection_/index.mjs.map +1 -1
  174. package/dist/astro/routes/api/content/_collection_/trash.mjs +7 -7
  175. package/dist/astro/routes/api/dashboard.mjs +8 -8
  176. package/dist/astro/routes/api/dev/emails.mjs +2 -2
  177. package/dist/astro/routes/api/import/probe.d.mts +3 -3
  178. package/dist/astro/routes/api/import/probe.mjs +18 -18
  179. package/dist/astro/routes/api/import/wordpress/analyze.mjs +3 -3
  180. package/dist/astro/routes/api/import/wordpress/execute.d.mts +11 -11
  181. package/dist/astro/routes/api/import/wordpress/execute.mjs +15 -14
  182. package/dist/astro/routes/api/import/wordpress/execute.mjs.map +1 -1
  183. package/dist/astro/routes/api/import/wordpress/media.d.mts +10 -10
  184. package/dist/astro/routes/api/import/wordpress/media.mjs +11 -11
  185. package/dist/astro/routes/api/import/wordpress/prepare.mjs +10 -10
  186. package/dist/astro/routes/api/import/wordpress/rewrite-urls.d.mts +11 -11
  187. package/dist/astro/routes/api/import/wordpress/rewrite-urls.mjs +13 -13
  188. package/dist/astro/routes/api/import/wordpress-plugin/analyze.d.mts +1 -1
  189. package/dist/astro/routes/api/import/wordpress-plugin/analyze.mjs +18 -18
  190. package/dist/astro/routes/api/import/wordpress-plugin/execute.d.mts +11 -11
  191. package/dist/astro/routes/api/import/wordpress-plugin/execute.mjs +29 -28
  192. package/dist/astro/routes/api/import/wordpress-plugin/execute.mjs.map +1 -1
  193. package/dist/astro/routes/api/manifest.mjs +4 -4
  194. package/dist/astro/routes/api/manifest.mjs.map +1 -1
  195. package/dist/astro/routes/api/mcp.mjs +213 -74
  196. package/dist/astro/routes/api/mcp.mjs.map +1 -1
  197. package/dist/astro/routes/api/media/_id_/confirm.mjs +11 -11
  198. package/dist/astro/routes/api/media/_id_/replace.d.mts +8 -0
  199. package/dist/astro/routes/api/media/_id_/replace.d.mts.map +1 -0
  200. package/dist/astro/routes/api/media/_id_/replace.mjs +91 -0
  201. package/dist/astro/routes/api/media/_id_/replace.mjs.map +1 -0
  202. package/dist/astro/routes/api/media/_id_/upload.mjs +6 -6
  203. package/dist/astro/routes/api/media/_id_/usage.mjs +19 -19
  204. package/dist/astro/routes/api/media/_id_.mjs +18 -18
  205. package/dist/astro/routes/api/media/file/_...key_.d.mts.map +1 -1
  206. package/dist/astro/routes/api/media/file/_...key_.mjs +3 -2
  207. package/dist/astro/routes/api/media/file/_...key_.mjs.map +1 -1
  208. package/dist/astro/routes/api/media/folders/_id_.mjs +8 -8
  209. package/dist/astro/routes/api/media/folders/index.mjs +8 -8
  210. package/dist/astro/routes/api/media/providers/_providerId_/_itemId_.mjs +2 -2
  211. package/dist/astro/routes/api/media/providers/_providerId_/index.mjs +2 -2
  212. package/dist/astro/routes/api/media/providers/index.mjs +2 -2
  213. package/dist/astro/routes/api/media/upload-url.mjs +16 -14
  214. package/dist/astro/routes/api/media/upload-url.mjs.map +1 -1
  215. package/dist/astro/routes/api/media.d.mts.map +1 -1
  216. package/dist/astro/routes/api/media.mjs +53 -30
  217. package/dist/astro/routes/api/media.mjs.map +1 -1
  218. package/dist/astro/routes/api/menus/_name_/items/_id_.d.mts.map +1 -1
  219. package/dist/astro/routes/api/menus/_name_/items/_id_.mjs +20 -13
  220. package/dist/astro/routes/api/menus/_name_/items/_id_.mjs.map +1 -1
  221. package/dist/astro/routes/api/menus/_name_/items.d.mts.map +1 -1
  222. package/dist/astro/routes/api/menus/_name_/items.mjs +15 -11
  223. package/dist/astro/routes/api/menus/_name_/items.mjs.map +1 -1
  224. package/dist/astro/routes/api/menus/_name_/reorder.d.mts.map +1 -1
  225. package/dist/astro/routes/api/menus/_name_/reorder.mjs +15 -11
  226. package/dist/astro/routes/api/menus/_name_/reorder.mjs.map +1 -1
  227. package/dist/astro/routes/api/menus/_name_/translations.d.mts.map +1 -1
  228. package/dist/astro/routes/api/menus/_name_/translations.mjs +16 -12
  229. package/dist/astro/routes/api/menus/_name_/translations.mjs.map +1 -1
  230. package/dist/astro/routes/api/menus/_name_.d.mts.map +1 -1
  231. package/dist/astro/routes/api/menus/_name_.mjs +21 -14
  232. package/dist/astro/routes/api/menus/_name_.mjs.map +1 -1
  233. package/dist/astro/routes/api/menus/index.d.mts.map +1 -1
  234. package/dist/astro/routes/api/menus/index.mjs +15 -11
  235. package/dist/astro/routes/api/menus/index.mjs.map +1 -1
  236. package/dist/astro/routes/api/oauth/authorize.mjs +6 -6
  237. package/dist/astro/routes/api/oauth/device/authorize.mjs +5 -5
  238. package/dist/astro/routes/api/oauth/device/code.mjs +8 -8
  239. package/dist/astro/routes/api/oauth/device/token.mjs +7 -7
  240. package/dist/astro/routes/api/oauth/register.mjs +2 -2
  241. package/dist/astro/routes/api/oauth/token/refresh.mjs +5 -5
  242. package/dist/astro/routes/api/oauth/token/revoke.mjs +5 -5
  243. package/dist/astro/routes/api/oauth/token.mjs +5 -5
  244. package/dist/astro/routes/api/openapi.json.mjs +184 -52
  245. package/dist/astro/routes/api/openapi.json.mjs.map +1 -1
  246. package/dist/astro/routes/api/plugins/_pluginId_/_...path_.mjs +4 -4
  247. package/dist/astro/routes/api/redirects/404s/index.mjs +12 -11
  248. package/dist/astro/routes/api/redirects/404s/index.mjs.map +1 -1
  249. package/dist/astro/routes/api/redirects/404s/summary.mjs +12 -11
  250. package/dist/astro/routes/api/redirects/404s/summary.mjs.map +1 -1
  251. package/dist/astro/routes/api/redirects/_id_.mjs +13 -12
  252. package/dist/astro/routes/api/redirects/_id_.mjs.map +1 -1
  253. package/dist/astro/routes/api/redirects/index.mjs +13 -12
  254. package/dist/astro/routes/api/redirects/index.mjs.map +1 -1
  255. package/dist/astro/routes/api/relations/_id_/index.mjs +20 -18
  256. package/dist/astro/routes/api/relations/_id_/index.mjs.map +1 -1
  257. package/dist/astro/routes/api/relations/_id_/translations.mjs +15 -13
  258. package/dist/astro/routes/api/relations/_id_/translations.mjs.map +1 -1
  259. package/dist/astro/routes/api/relations/index.mjs +20 -18
  260. package/dist/astro/routes/api/relations/index.mjs.map +1 -1
  261. package/dist/astro/routes/api/revisions/_revisionId_/index.mjs +2 -2
  262. package/dist/astro/routes/api/revisions/_revisionId_/restore.mjs +3 -3
  263. package/dist/astro/routes/api/schema/collections/_slug_/fields/_fieldSlug_.mjs +57 -54
  264. package/dist/astro/routes/api/schema/collections/_slug_/fields/_fieldSlug_.mjs.map +1 -1
  265. package/dist/astro/routes/api/schema/collections/_slug_/fields/index.mjs +57 -54
  266. package/dist/astro/routes/api/schema/collections/_slug_/fields/index.mjs.map +1 -1
  267. package/dist/astro/routes/api/schema/collections/_slug_/fields/reorder.mjs +57 -54
  268. package/dist/astro/routes/api/schema/collections/_slug_/fields/reorder.mjs.map +1 -1
  269. package/dist/astro/routes/api/schema/collections/_slug_/index.mjs +57 -54
  270. package/dist/astro/routes/api/schema/collections/_slug_/index.mjs.map +1 -1
  271. package/dist/astro/routes/api/schema/collections/index.mjs +57 -54
  272. package/dist/astro/routes/api/schema/collections/index.mjs.map +1 -1
  273. package/dist/astro/routes/api/schema/collections/reorder.mjs +57 -54
  274. package/dist/astro/routes/api/schema/collections/reorder.mjs.map +1 -1
  275. package/dist/astro/routes/api/schema/index.mjs +13 -11
  276. package/dist/astro/routes/api/schema/index.mjs.map +1 -1
  277. package/dist/astro/routes/api/schema/orphans/_slug_.mjs +57 -54
  278. package/dist/astro/routes/api/schema/orphans/_slug_.mjs.map +1 -1
  279. package/dist/astro/routes/api/schema/orphans/index.mjs +57 -54
  280. package/dist/astro/routes/api/schema/orphans/index.mjs.map +1 -1
  281. package/dist/astro/routes/api/search/enable.mjs +12 -11
  282. package/dist/astro/routes/api/search/enable.mjs.map +1 -1
  283. package/dist/astro/routes/api/search/index.mjs +11 -10
  284. package/dist/astro/routes/api/search/index.mjs.map +1 -1
  285. package/dist/astro/routes/api/search/rebuild.mjs +12 -11
  286. package/dist/astro/routes/api/search/rebuild.mjs.map +1 -1
  287. package/dist/astro/routes/api/search/stats.mjs +7 -6
  288. package/dist/astro/routes/api/search/stats.mjs.map +1 -1
  289. package/dist/astro/routes/api/search/suggest.mjs +11 -10
  290. package/dist/astro/routes/api/search/suggest.mjs.map +1 -1
  291. package/dist/astro/routes/api/sections/_slug_.mjs +11 -10
  292. package/dist/astro/routes/api/sections/_slug_.mjs.map +1 -1
  293. package/dist/astro/routes/api/sections/index.mjs +11 -10
  294. package/dist/astro/routes/api/sections/index.mjs.map +1 -1
  295. package/dist/astro/routes/api/settings/backups/archives/_name_.mjs +7 -6
  296. package/dist/astro/routes/api/settings/backups/archives/_name_.mjs.map +1 -1
  297. package/dist/astro/routes/api/settings/backups/archives/index.mjs +6 -5
  298. package/dist/astro/routes/api/settings/backups/archives/index.mjs.map +1 -1
  299. package/dist/astro/routes/api/settings/backups/export.mjs +7 -6
  300. package/dist/astro/routes/api/settings/backups/export.mjs.map +1 -1
  301. package/dist/astro/routes/api/settings/backups/index.mjs +8 -7
  302. package/dist/astro/routes/api/settings/backups/index.mjs.map +1 -1
  303. package/dist/astro/routes/api/settings/email.mjs +5 -5
  304. package/dist/astro/routes/api/settings/email.mjs.map +1 -1
  305. package/dist/astro/routes/api/settings.d.mts.map +1 -1
  306. package/dist/astro/routes/api/settings.mjs +21 -17
  307. package/dist/astro/routes/api/settings.mjs.map +1 -1
  308. package/dist/astro/routes/api/setup/admin-verify.mjs +12 -12
  309. package/dist/astro/routes/api/setup/admin.mjs +11 -11
  310. package/dist/astro/routes/api/setup/dev-bypass.mjs +35 -33
  311. package/dist/astro/routes/api/setup/dev-bypass.mjs.map +1 -1
  312. package/dist/astro/routes/api/setup/dev-reset.mjs +2 -2
  313. package/dist/astro/routes/api/setup/index.mjs +35 -33
  314. package/dist/astro/routes/api/setup/index.mjs.map +1 -1
  315. package/dist/astro/routes/api/setup/status.mjs +3 -3
  316. package/dist/astro/routes/api/snapshot.mjs +8 -7
  317. package/dist/astro/routes/api/snapshot.mjs.map +1 -1
  318. package/dist/astro/routes/api/taxonomies/_name_/reorder.d.mts.map +1 -1
  319. package/dist/astro/routes/api/taxonomies/_name_/reorder.mjs +22 -17
  320. package/dist/astro/routes/api/taxonomies/_name_/reorder.mjs.map +1 -1
  321. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_/translations.d.mts.map +1 -1
  322. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_/translations.mjs +23 -18
  323. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_/translations.mjs.map +1 -1
  324. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_.d.mts.map +1 -1
  325. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_.mjs +27 -19
  326. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_.mjs.map +1 -1
  327. package/dist/astro/routes/api/taxonomies/_name_/terms/index.d.mts.map +1 -1
  328. package/dist/astro/routes/api/taxonomies/_name_/terms/index.mjs +22 -17
  329. package/dist/astro/routes/api/taxonomies/_name_/terms/index.mjs.map +1 -1
  330. package/dist/astro/routes/api/taxonomies/_name_/translations.mjs +16 -15
  331. package/dist/astro/routes/api/taxonomies/_name_/translations.mjs.map +1 -1
  332. package/dist/astro/routes/api/taxonomies/_name_.d.mts.map +1 -1
  333. package/dist/astro/routes/api/taxonomies/_name_.mjs +28 -20
  334. package/dist/astro/routes/api/taxonomies/_name_.mjs.map +1 -1
  335. package/dist/astro/routes/api/taxonomies/index.d.mts.map +1 -1
  336. package/dist/astro/routes/api/taxonomies/index.mjs +22 -17
  337. package/dist/astro/routes/api/taxonomies/index.mjs.map +1 -1
  338. package/dist/astro/routes/api/themes/preview.mjs +5 -5
  339. package/dist/astro/routes/api/typegen.mjs +4 -4
  340. package/dist/astro/routes/api/well-known/auth.mjs +2 -2
  341. package/dist/astro/routes/api/well-known/oauth-authorization-server.mjs +2 -2
  342. package/dist/astro/routes/api/well-known/oauth-protected-resource.mjs +2 -2
  343. package/dist/astro/routes/api/widget-areas/_name_/reorder.d.mts.map +1 -1
  344. package/dist/astro/routes/api/widget-areas/_name_/reorder.mjs +10 -8
  345. package/dist/astro/routes/api/widget-areas/_name_/reorder.mjs.map +1 -1
  346. package/dist/astro/routes/api/widget-areas/_name_/widgets/_id_.d.mts.map +1 -1
  347. package/dist/astro/routes/api/widget-areas/_name_/widgets/_id_.mjs +18 -14
  348. package/dist/astro/routes/api/widget-areas/_name_/widgets/_id_.mjs.map +1 -1
  349. package/dist/astro/routes/api/widget-areas/_name_/widgets.d.mts.map +1 -1
  350. package/dist/astro/routes/api/widget-areas/_name_/widgets.mjs +16 -13
  351. package/dist/astro/routes/api/widget-areas/_name_/widgets.mjs.map +1 -1
  352. package/dist/astro/routes/api/widget-areas/_name_.d.mts.map +1 -1
  353. package/dist/astro/routes/api/widget-areas/_name_.mjs +9 -7
  354. package/dist/astro/routes/api/widget-areas/_name_.mjs.map +1 -1
  355. package/dist/astro/routes/api/widget-areas/index.d.mts.map +1 -1
  356. package/dist/astro/routes/api/widget-areas/index.mjs +16 -13
  357. package/dist/astro/routes/api/widget-areas/index.mjs.map +1 -1
  358. package/dist/astro/routes/api/widget-components.mjs +2 -2
  359. package/dist/astro/routes/robots.txt.mjs +8 -8
  360. package/dist/astro/routes/sitemap-_collection_.xml.mjs +13 -12
  361. package/dist/astro/routes/sitemap-_collection_.xml.mjs.map +1 -1
  362. package/dist/astro/routes/sitemap.xml.mjs +9 -9
  363. package/dist/astro/types.d.mts +50 -20
  364. package/dist/astro/types.d.mts.map +1 -1
  365. package/dist/auth/providers/github.d.mts +1 -1
  366. package/dist/auth/providers/google.d.mts +1 -1
  367. package/dist/{authorize-ByYs-Uxs.mjs → authorize-C2QHlWSS.mjs} +2 -2
  368. package/dist/{authorize-ByYs-Uxs.mjs.map → authorize-C2QHlWSS.mjs.map} +1 -1
  369. package/dist/{backup-ChyHfIoX.mjs → backup-oS8ft5Cm.mjs} +5 -5
  370. package/dist/{backup-ChyHfIoX.mjs.map → backup-oS8ft5Cm.mjs.map} +1 -1
  371. package/dist/{bundle-DZFhFurR.mjs → bundle-CL0JjIPx.mjs} +4 -4
  372. package/dist/{bundle-DZFhFurR.mjs.map → bundle-CL0JjIPx.mjs.map} +1 -1
  373. package/dist/{byline-Cpnwrje1.mjs → byline-Vdi85CsZ.mjs} +27 -14
  374. package/dist/byline-Vdi85CsZ.mjs.map +1 -0
  375. package/dist/{byline-fields-CAyA_Umd.mjs → byline-fields-DPVRFMz2.mjs} +2 -2
  376. package/dist/{byline-fields-CAyA_Umd.mjs.map → byline-fields-DPVRFMz2.mjs.map} +1 -1
  377. package/dist/{byline-registry-Bpu9-MVs.mjs → byline-registry-BxDGIO0I.mjs} +2 -2
  378. package/dist/{byline-registry-Bpu9-MVs.mjs.map → byline-registry-BxDGIO0I.mjs.map} +1 -1
  379. package/dist/{bylines-BSo9B9RX.mjs → bylines-BX8QhcTk.mjs} +7 -7
  380. package/dist/{bylines-BSo9B9RX.mjs.map → bylines-BX8QhcTk.mjs.map} +1 -1
  381. package/dist/{bylines-CHjvehVX.mjs → bylines-w-E1IEQd.mjs} +3 -3
  382. package/dist/{bylines-CHjvehVX.mjs.map → bylines-w-E1IEQd.mjs.map} +1 -1
  383. package/dist/{cache-5VirJ2Cn.mjs → cache--7HKu5Xm.mjs} +4 -4
  384. package/dist/{cache-5VirJ2Cn.mjs.map → cache--7HKu5Xm.mjs.map} +1 -1
  385. package/dist/{capture-triggers-CNW1q3HK.mjs → capture-triggers-CeAsC76Z.mjs} +2 -2
  386. package/dist/{capture-triggers-CNW1q3HK.mjs.map → capture-triggers-CeAsC76Z.mjs.map} +1 -1
  387. package/dist/{challenge-store-D5pSY2S1.mjs → challenge-store-BIOak-tp.mjs} +5 -3
  388. package/dist/challenge-store-BIOak-tp.mjs.map +1 -0
  389. package/dist/chrome-tags-DzDQBCjX.mjs +24 -0
  390. package/dist/chrome-tags-DzDQBCjX.mjs.map +1 -0
  391. package/dist/{chunks-bNiX6_DR.mjs → chunks-VG_tyqnP.mjs} +2 -2
  392. package/dist/{chunks-bNiX6_DR.mjs.map → chunks-VG_tyqnP.mjs.map} +1 -1
  393. package/dist/cli/index.mjs +68 -40
  394. package/dist/cli/index.mjs.map +1 -1
  395. package/dist/client/cf-access.d.mts +1 -1
  396. package/dist/client/index.d.mts +17 -7
  397. package/dist/client/index.d.mts.map +1 -1
  398. package/dist/client/index.mjs +17 -12
  399. package/dist/client/index.mjs.map +1 -1
  400. package/dist/{collection-deletion-m_oi2c0N.mjs → collection-deletion-BCwaWTDw.mjs} +4 -4
  401. package/dist/{collection-deletion-m_oi2c0N.mjs.map → collection-deletion-BCwaWTDw.mjs.map} +1 -1
  402. package/dist/collection-slugs-cache-7lTmNzeA.mjs +85 -0
  403. package/dist/collection-slugs-cache-7lTmNzeA.mjs.map +1 -0
  404. package/dist/{comment-reaction-CRuItEjt.mjs → comment-reaction-CDyvPQRj.mjs} +2 -2
  405. package/dist/{comment-reaction-CRuItEjt.mjs.map → comment-reaction-CDyvPQRj.mjs.map} +1 -1
  406. package/dist/{comment-DhvLEdhQ.mjs → comment-vxOzWbZN.mjs} +2 -2
  407. package/dist/{comment-DhvLEdhQ.mjs.map → comment-vxOzWbZN.mjs.map} +1 -1
  408. package/dist/{comments-CLj4bi8I.mjs → comments-VzmVLyaC.mjs} +2 -2
  409. package/dist/{comments-CLj4bi8I.mjs.map → comments-VzmVLyaC.mjs.map} +1 -1
  410. package/dist/{components-v4U4DT2y.mjs → components-CL6Wkdk-.mjs} +1 -1
  411. package/dist/{components-v4U4DT2y.mjs.map → components-CL6Wkdk-.mjs.map} +1 -1
  412. package/dist/config--eWjQJE5.mjs +217 -0
  413. package/dist/config--eWjQJE5.mjs.map +1 -0
  414. package/dist/{index-DWbJrsAg.d.mts → config-CGAhyOjP.d.mts} +276 -76
  415. package/dist/config-CGAhyOjP.d.mts.map +1 -0
  416. package/dist/{config-DrfghTPe.d.mts → config-ChFzshGd.d.mts} +1 -1
  417. package/dist/{config-DrfghTPe.d.mts.map → config-ChFzshGd.d.mts.map} +1 -1
  418. package/dist/{content-CP-SeXNa.mjs → content-CNfMWuhY.mjs} +202 -46
  419. package/dist/content-CNfMWuhY.mjs.map +1 -0
  420. package/dist/{content-list-query-BhejKVqb.d.mts → content-list-query-B8d4UQp9.d.mts} +1 -1
  421. package/dist/{content-list-query-BhejKVqb.d.mts.map → content-list-query-B8d4UQp9.d.mts.map} +1 -1
  422. package/dist/{content-refresh-DLOfIhYc.mjs → content-refresh-GTMyi2Xy.mjs} +53 -26
  423. package/dist/content-refresh-GTMyi2Xy.mjs.map +1 -0
  424. package/dist/{content-repair-BCxzy0r4.mjs → content-repair-CIMt5C0U.mjs} +4 -4
  425. package/dist/{content-repair-BCxzy0r4.mjs.map → content-repair-CIMt5C0U.mjs.map} +1 -1
  426. package/dist/{context-BR5hRWiK.mjs → context-C9PB8vGd.mjs} +308 -33
  427. package/dist/context-C9PB8vGd.mjs.map +1 -0
  428. package/dist/{cron-CWfWrWKG.mjs → cron-DHAy9oyq.mjs} +1 -1
  429. package/dist/{cron-CWfWrWKG.mjs.map → cron-DHAy9oyq.mjs.map} +1 -1
  430. package/dist/{dashboard-CkIV2rnQ.mjs → dashboard-BNSvAN8A.mjs} +5 -5
  431. package/dist/{dashboard-CkIV2rnQ.mjs.map → dashboard-BNSvAN8A.mjs.map} +1 -1
  432. package/dist/db/index.d.mts +3 -3
  433. package/dist/db/index.mjs +2 -2
  434. package/dist/db/index.mjs.map +1 -1
  435. package/dist/db/libsql-migrations.d.mts +1 -1
  436. package/dist/db/libsql-migrations.mjs +5 -5
  437. package/dist/db/libsql.d.mts +1 -1
  438. package/dist/db/postgres-migrations.d.mts +1 -1
  439. package/dist/db/postgres-migrations.mjs +5 -5
  440. package/dist/db/postgres.d.mts +1 -1
  441. package/dist/db/postgres.d.mts.map +1 -1
  442. package/dist/db/postgres.mjs +19 -3
  443. package/dist/db/postgres.mjs.map +1 -1
  444. package/dist/db/sqlite-migrations.d.mts +1 -1
  445. package/dist/db/sqlite-migrations.mjs +5 -5
  446. package/dist/db/sqlite.d.mts +1 -1
  447. package/dist/db/sqlite.mjs +1 -1
  448. package/dist/{default-YMEfcQUx.mjs → default-ByZ0JqZo.mjs} +1 -1
  449. package/dist/{default-YMEfcQUx.mjs.map → default-ByZ0JqZo.mjs.map} +1 -1
  450. package/dist/{deferred-tasks-DfqxH5Xf.d.mts → deferred-tasks-Cu4NSJpa.d.mts} +1 -1
  451. package/dist/{deferred-tasks-DfqxH5Xf.d.mts.map → deferred-tasks-Cu4NSJpa.d.mts.map} +1 -1
  452. package/dist/dev-typegen-DHT7lcMU.mjs +29 -0
  453. package/dist/dev-typegen-DHT7lcMU.mjs.map +1 -0
  454. package/dist/{device-flow-CojjSBwb.mjs → device-flow-Cf6bhCCT.mjs} +4 -4
  455. package/dist/{device-flow-CojjSBwb.mjs.map → device-flow-Cf6bhCCT.mjs.map} +1 -1
  456. package/dist/{dialect-helpers-BSbfaO3F.mjs → dialect-helpers-BcQvkHgn.mjs} +83 -2
  457. package/dist/dialect-helpers-BcQvkHgn.mjs.map +1 -0
  458. package/dist/{direct-executor-BWeWiRYB.mjs → direct-executor-yAyUGSqB.mjs} +3 -3
  459. package/dist/{direct-executor-BWeWiRYB.mjs.map → direct-executor-yAyUGSqB.mjs.map} +1 -1
  460. package/dist/{dist-89xCrGqi.mjs → dist-BAsh8dbf.mjs} +1 -1
  461. package/dist/{dist-89xCrGqi.mjs.map → dist-BAsh8dbf.mjs.map} +1 -1
  462. package/dist/{email-console-CEJgR_LB.mjs → email-console-DNup1Fku.mjs} +1 -1
  463. package/dist/{email-console-CEJgR_LB.mjs.map → email-console-DNup1Fku.mjs.map} +1 -1
  464. package/dist/{enrich-BX0IDp4z.mjs → enrich-t2Xvjdqa.mjs} +3 -3
  465. package/dist/{enrich-BX0IDp4z.mjs.map → enrich-t2Xvjdqa.mjs.map} +1 -1
  466. package/dist/entry-lock-BEr8gDkG.mjs +163 -0
  467. package/dist/entry-lock-BEr8gDkG.mjs.map +1 -0
  468. package/dist/{relations-C7B46bcU.d.mts → entry-lock-CGAtrwAR.d.mts} +265 -76
  469. package/dist/entry-lock-CGAtrwAR.d.mts.map +1 -0
  470. package/dist/{redirects-CRIM55KH.mjs → entry-lock-DIYHAaSw.mjs} +112 -34
  471. package/dist/entry-lock-DIYHAaSw.mjs.map +1 -0
  472. package/dist/entry-locks-BEcX7ET0.mjs +167 -0
  473. package/dist/entry-locks-BEcX7ET0.mjs.map +1 -0
  474. package/dist/{error-D9w94fjV.mjs → error-BDcFyoRt.mjs} +2 -2
  475. package/dist/{error-D9w94fjV.mjs.map → error-BDcFyoRt.mjs.map} +1 -1
  476. package/dist/{errors-n2j49uNf.mjs → errors-DvMdNrgf.mjs} +10 -1
  477. package/dist/errors-DvMdNrgf.mjs.map +1 -0
  478. package/dist/{escape-DN4Qmjsl.mjs → escape-B3asJC6W.mjs} +1 -1
  479. package/dist/{escape-DN4Qmjsl.mjs.map → escape-B3asJC6W.mjs.map} +1 -1
  480. package/dist/{field-defs-cache-Bh4q6oar.mjs → field-defs-cache-Cf5FHK0M.mjs} +5 -5
  481. package/dist/{field-defs-cache-Bh4q6oar.mjs.map → field-defs-cache-Cf5FHK0M.mjs.map} +1 -1
  482. package/dist/{fts-manager-BhOdW0bi.mjs → fts-manager-iddym8cd.mjs} +4 -4
  483. package/dist/{fts-manager-BhOdW0bi.mjs.map → fts-manager-iddym8cd.mjs.map} +1 -1
  484. package/dist/{hash-CTcngWvj.mjs → hash-BRweX6jz.mjs} +1 -1
  485. package/dist/{hash-CTcngWvj.mjs.map → hash-BRweX6jz.mjs.map} +1 -1
  486. package/dist/hook-result-BrshYHLx.d.mts +31 -0
  487. package/dist/hook-result-BrshYHLx.d.mts.map +1 -0
  488. package/dist/{hreflang-7pTHsLZJ.d.mts → hreflang-CQpu5bMy.d.mts} +2 -2
  489. package/dist/{hreflang-7pTHsLZJ.d.mts.map → hreflang-CQpu5bMy.d.mts.map} +1 -1
  490. package/dist/{hreflang-Huc6O5wa.mjs → hreflang-DshnweTC.mjs} +9 -8
  491. package/dist/{hreflang-Huc6O5wa.mjs.map → hreflang-DshnweTC.mjs.map} +1 -1
  492. package/dist/{identity-DXmb4aVp.mjs → identity-CjGKDq8J.mjs} +3 -3
  493. package/dist/{identity-DXmb4aVp.mjs.map → identity-CjGKDq8J.mjs.map} +1 -1
  494. package/dist/{import-C4_O3KXU.mjs → import-D96g2otw.mjs} +6 -6
  495. package/dist/{import-C4_O3KXU.mjs.map → import-D96g2otw.mjs.map} +1 -1
  496. package/dist/{index-6bRee8zb.d.mts → index-1ECYpfiF.d.mts} +3 -3
  497. package/dist/{index-6bRee8zb.d.mts.map → index-1ECYpfiF.d.mts.map} +1 -1
  498. package/dist/index.d.mts +22 -21
  499. package/dist/index.mjs +84 -81
  500. package/dist/{init-lock-DJkX6Hto.mjs → init-lock-CFNBe_iH.mjs} +1 -1
  501. package/dist/{init-lock-DJkX6Hto.mjs.map → init-lock-CFNBe_iH.mjs.map} +1 -1
  502. package/dist/{load-Bo7fZAbg.mjs → load-DPtY9cZo.mjs} +2 -2
  503. package/dist/{load-Bo7fZAbg.mjs.map → load-DPtY9cZo.mjs.map} +1 -1
  504. package/dist/{loader-ZsjE4paL.mjs → loader-WJi6GFRn.mjs} +90 -17
  505. package/dist/loader-WJi6GFRn.mjs.map +1 -0
  506. package/dist/{manifest-builder-QXuqvVMP.mjs → manifest-builder-BfNlGQIA.mjs} +2 -2
  507. package/dist/{manifest-builder-QXuqvVMP.mjs.map → manifest-builder-BfNlGQIA.mjs.map} +1 -1
  508. package/dist/{manifest-schema-CUYPfCEH.mjs → manifest-schema-CILooI5J.mjs} +5 -5
  509. package/dist/manifest-schema-CILooI5J.mjs.map +1 -0
  510. package/dist/media/image-endpoint.d.mts +4 -2
  511. package/dist/media/image-endpoint.d.mts.map +1 -1
  512. package/dist/media/image-endpoint.mjs +6 -4
  513. package/dist/media/image-endpoint.mjs.map +1 -1
  514. package/dist/media/index.d.mts +1 -1
  515. package/dist/media/index.mjs +3 -3
  516. package/dist/media/local-runtime.d.mts +12 -12
  517. package/dist/media/local-runtime.mjs +7 -7
  518. package/dist/{media-D6SeAfBl.mjs → media-BBm8Wg3f.mjs} +30 -2
  519. package/dist/media-BBm8Wg3f.mjs.map +1 -0
  520. package/dist/{media-BjwNuLEu.mjs → media-C1EIZKh1.mjs} +35 -5
  521. package/dist/media-C1EIZKh1.mjs.map +1 -0
  522. package/dist/{media-allowlist-D35v7bmL.mjs → media-allowlist-elXJgb_K.mjs} +2 -2
  523. package/dist/{media-allowlist-D35v7bmL.mjs.map → media-allowlist-elXJgb_K.mjs.map} +1 -1
  524. package/dist/{media-folders-D-0CmRZj.mjs → media-folders-DASfX_DH.mjs} +1 -1
  525. package/dist/{media-folders-D-0CmRZj.mjs.map → media-folders-DASfX_DH.mjs.map} +1 -1
  526. package/dist/{media-upload-C7bLXGcI.mjs → media-upload-C7_AQJ5v.mjs} +9 -9
  527. package/dist/{media-upload-C7bLXGcI.mjs.map → media-upload-C7_AQJ5v.mjs.map} +1 -1
  528. package/dist/{media-url-DH7giMx_.mjs → media-url-8dVl1loq.mjs} +19 -2
  529. package/dist/media-url-8dVl1loq.mjs.map +1 -0
  530. package/dist/{media-usage-BTRJvS6V.mjs → media-usage-C1EswMTq.mjs} +10 -10
  531. package/dist/{media-usage-BTRJvS6V.mjs.map → media-usage-C1EswMTq.mjs.map} +1 -1
  532. package/dist/{media-usage-activation-Dx0kPV6b.mjs → media-usage-activation-CrHNltlL.mjs} +3 -3
  533. package/dist/{media-usage-activation-Dx0kPV6b.mjs.map → media-usage-activation-CrHNltlL.mjs.map} +1 -1
  534. package/dist/{media-usage-work-C-fhM30c.mjs → media-usage-work-C5B1zT1c.mjs} +2 -2
  535. package/dist/{media-usage-work-C-fhM30c.mjs.map → media-usage-work-C5B1zT1c.mjs.map} +1 -1
  536. package/dist/{media-usage-work-DWb2XPMI.mjs → media-usage-work-IkQx_Yz6.mjs} +4 -4
  537. package/dist/{media-usage-work-DWb2XPMI.mjs.map → media-usage-work-IkQx_Yz6.mjs.map} +1 -1
  538. package/dist/{media-usage-write-fence-BwoJVRDC.mjs → media-usage-write-fence-B9anjOSg.mjs} +3 -3
  539. package/dist/{media-usage-write-fence-BwoJVRDC.mjs.map → media-usage-write-fence-B9anjOSg.mjs.map} +1 -1
  540. package/dist/{menus-CNg0QlDt.mjs → menus-D8mC4eaN.mjs} +406 -175
  541. package/dist/menus-D8mC4eaN.mjs.map +1 -0
  542. package/dist/{menus-CD7EFLwz.mjs → menus-UdwjHZJC.mjs} +12 -4
  543. package/dist/{menus-CD7EFLwz.mjs.map → menus-UdwjHZJC.mjs.map} +1 -1
  544. package/dist/migrations/index.d.mts +1 -1
  545. package/dist/migrations/index.mjs +4 -4
  546. package/dist/{mime-CUIG6x84.mjs → mime-DYpsOAny.mjs} +1 -1
  547. package/dist/{mime-CUIG6x84.mjs.map → mime-DYpsOAny.mjs.map} +1 -1
  548. package/dist/{mode-DaUM_MB2.mjs → mode-Dm4BHhRH.mjs} +1 -1
  549. package/dist/{mode-DaUM_MB2.mjs.map → mode-Dm4BHhRH.mjs.map} +1 -1
  550. package/dist/{node-sqlite-compat-Udb4Y-rs.mjs → node-sqlite-compat-2sezm-Zd.mjs} +1 -1
  551. package/dist/{node-sqlite-compat-Udb4Y-rs.mjs.map → node-sqlite-compat-2sezm-Zd.mjs.map} +1 -1
  552. package/dist/{normalize-CSxdKBVa.mjs → normalize-4nkKGsuW.mjs} +15 -5
  553. package/dist/normalize-4nkKGsuW.mjs.map +1 -0
  554. package/dist/{oauth-authorization-Dpsb-fMJ.mjs → oauth-authorization-BxE_lURD.mjs} +4 -4
  555. package/dist/{oauth-authorization-Dpsb-fMJ.mjs.map → oauth-authorization-BxE_lURD.mjs.map} +1 -1
  556. package/dist/{oauth-clients-Bxnoe_67.mjs → oauth-clients-DJIdOdq0.mjs} +1 -1
  557. package/dist/{oauth-clients-Bxnoe_67.mjs.map → oauth-clients-DJIdOdq0.mjs.map} +1 -1
  558. package/dist/{oauth-state-store-0C4s0K6w.mjs → oauth-state-store-CsdxP57n.mjs} +1 -1
  559. package/dist/{oauth-state-store-0C4s0K6w.mjs.map → oauth-state-store-CsdxP57n.mjs.map} +1 -1
  560. package/dist/{oauth-user-lookup-wlGYSeqX.mjs → oauth-user-lookup-HzzW-dkF.mjs} +1 -1
  561. package/dist/{oauth-user-lookup-wlGYSeqX.mjs.map → oauth-user-lookup-HzzW-dkF.mjs.map} +1 -1
  562. package/dist/object-cache/memory.d.mts +1 -1
  563. package/dist/{object-cache-71tPfV4A.mjs → object-cache-DVKnyOfy.mjs} +19 -3
  564. package/dist/object-cache-DVKnyOfy.mjs.map +1 -0
  565. package/dist/{options-BHPeIbBd.mjs → options-D1FBiAv1.mjs} +60 -5
  566. package/dist/options-D1FBiAv1.mjs.map +1 -0
  567. package/dist/{options-BhZIeFY1.d.mts → options-D8Y0VHc7.d.mts} +30 -11
  568. package/dist/options-D8Y0VHc7.d.mts.map +1 -0
  569. package/dist/page/index.d.mts +2 -2
  570. package/dist/page/index.d.mts.map +1 -1
  571. package/dist/page/index.mjs +12 -0
  572. package/dist/page/index.mjs.map +1 -1
  573. package/dist/{parse-BRJg1kz8.mjs → parse-WRg5C3NX.mjs} +2 -2
  574. package/dist/{parse-BRJg1kz8.mjs.map → parse-WRg5C3NX.mjs.map} +1 -1
  575. package/dist/{passkey-config-B3P0nHRR.mjs → passkey-config-qIdO-wF6.mjs} +1 -1
  576. package/dist/{passkey-config-B3P0nHRR.mjs.map → passkey-config-qIdO-wF6.mjs.map} +1 -1
  577. package/dist/{patterns-D9iDO3j8.mjs → patterns-DC8CLptu.mjs} +1 -1
  578. package/dist/{patterns-D9iDO3j8.mjs.map → patterns-DC8CLptu.mjs.map} +1 -1
  579. package/dist/{placeholder-BR4ZhVJl.d.mts → placeholder-COrvARyD.d.mts} +1 -1
  580. package/dist/{placeholder-BR4ZhVJl.d.mts.map → placeholder-COrvARyD.d.mts.map} +1 -1
  581. package/dist/plugin-types.d.mts +8 -3
  582. package/dist/plugin-types.d.mts.map +1 -1
  583. package/dist/plugin-utils.d.mts +10 -10
  584. package/dist/plugins/adapt-sandbox-entry.d.mts +10 -10
  585. package/dist/plugins/adapt-sandbox-entry.mjs +2 -2
  586. package/dist/{policy-BVRganJQ.mjs → policy-XCfb-IE9.mjs} +2 -2
  587. package/dist/{policy-BVRganJQ.mjs.map → policy-XCfb-IE9.mjs.map} +1 -1
  588. package/dist/{portable-text-C8Tvp4_g.mjs → portable-text-BS3d5n-0.mjs} +1 -1
  589. package/dist/{portable-text-C8Tvp4_g.mjs.map → portable-text-BS3d5n-0.mjs.map} +1 -1
  590. package/dist/{preview-dn2dUyM0.mjs → preview-BxwsGgGp.mjs} +2 -2
  591. package/dist/{preview-dn2dUyM0.mjs.map → preview-BxwsGgGp.mjs.map} +1 -1
  592. package/dist/{protocol-CuBEsqgE.d.mts → protocol-CLn58-nw.d.mts} +2 -2
  593. package/dist/{protocol-CuBEsqgE.d.mts.map → protocol-CLn58-nw.d.mts.map} +1 -1
  594. package/dist/{public-url-DRz_AinV.mjs → public-url-FWWAvnre.mjs} +1 -1
  595. package/dist/{public-url-DRz_AinV.mjs.map → public-url-FWWAvnre.mjs.map} +1 -1
  596. package/dist/{query-D18vTdha.mjs → query-DygOte9M.mjs} +26 -17
  597. package/dist/query-DygOte9M.mjs.map +1 -0
  598. package/dist/{query-tZDEdtCN.mjs → query-gtXT03Wc.mjs} +5 -5
  599. package/dist/{query-tZDEdtCN.mjs.map → query-gtXT03Wc.mjs.map} +1 -1
  600. package/dist/{rate-limit-on7KPo-v.mjs → rate-limit-CQUPm0dh.mjs} +2 -2
  601. package/dist/{rate-limit-on7KPo-v.mjs.map → rate-limit-CQUPm0dh.mjs.map} +1 -1
  602. package/dist/{redirect-DrbEmU9a.mjs → redirect-D1cWafi6.mjs} +1 -1
  603. package/dist/{redirect-DrbEmU9a.mjs.map → redirect-D1cWafi6.mjs.map} +1 -1
  604. package/dist/{redirect-CZkbozu9.mjs → redirect-DId44BS1.mjs} +19 -6
  605. package/dist/redirect-DId44BS1.mjs.map +1 -0
  606. package/dist/{redirects-BahWiu8Z.mjs → redirects-DN-ZE33W.mjs} +5 -5
  607. package/dist/{redirects-BahWiu8Z.mjs.map → redirects-DN-ZE33W.mjs.map} +1 -1
  608. package/dist/{registry-Cx-jEJOS.mjs → registry-DTqaqxed.mjs} +46 -12
  609. package/dist/registry-DTqaqxed.mjs.map +1 -0
  610. package/dist/{relation-A6wLF_DS.mjs → relation-DxgCHOBw.mjs} +2 -2
  611. package/dist/{relation-A6wLF_DS.mjs.map → relation-DxgCHOBw.mjs.map} +1 -1
  612. package/dist/{relations-Cj5hZ6Zg.mjs → relations-KKDSLUwS.mjs} +4 -4
  613. package/dist/{relations-Cj5hZ6Zg.mjs.map → relations-KKDSLUwS.mjs.map} +1 -1
  614. package/dist/{relations-BTPM2saV.mjs → relations-rOmbndUJ.mjs} +8 -8
  615. package/dist/relations-rOmbndUJ.mjs.map +1 -0
  616. package/dist/{request-cache-DH9zdCOD.mjs → request-cache-DAZZmesc.mjs} +1 -1
  617. package/dist/{request-cache-DH9zdCOD.mjs.map → request-cache-DAZZmesc.mjs.map} +1 -1
  618. package/dist/request-context.d.mts +1 -1
  619. package/dist/{request-meta-DRp5ENd_.mjs → request-meta-BgjUQLQ-.mjs} +2 -2
  620. package/dist/{request-meta-DRp5ENd_.mjs.map → request-meta-BgjUQLQ-.mjs.map} +1 -1
  621. package/dist/{resolve-DxUpTMmE.mjs → resolve-Cy0aWSRj.mjs} +37 -4
  622. package/dist/resolve-Cy0aWSRj.mjs.map +1 -0
  623. package/dist/{runner-zgqA_CqP.d.mts → runner-CfwysRM0.d.mts} +3 -2
  624. package/dist/runner-CfwysRM0.d.mts.map +1 -0
  625. package/dist/{runner-77GOZCnH.mjs → runner-nEzvnogG.mjs} +476 -295
  626. package/dist/runner-nEzvnogG.mjs.map +1 -0
  627. package/dist/runtime.d.mts +11 -11
  628. package/dist/runtime.mjs +3 -2
  629. package/dist/runtime.mjs.map +1 -1
  630. package/dist/{schema-BY-oVntF.mjs → schema-CRu38Pr5.mjs} +3 -3
  631. package/dist/{schema-BY-oVntF.mjs.map → schema-CRu38Pr5.mjs.map} +1 -1
  632. package/dist/{schema-Cw9kVK0I.mjs → schema-DifxndJx.mjs} +5 -5
  633. package/dist/{schema-Cw9kVK0I.mjs.map → schema-DifxndJx.mjs.map} +1 -1
  634. package/dist/{scopes-vMR1uIbt.mjs → scopes-D5A1OZbq.mjs} +3 -3
  635. package/dist/{scopes-vMR1uIbt.mjs.map → scopes-D5A1OZbq.mjs.map} +1 -1
  636. package/dist/{search-CfT3KxO5.mjs → search-DEPFSBFq.mjs} +4 -4
  637. package/dist/{search-CfT3KxO5.mjs.map → search-DEPFSBFq.mjs.map} +1 -1
  638. package/dist/{secrets-BH2Qow1-.mjs → secrets-CdfzLdoO.mjs} +3 -3
  639. package/dist/{secrets-BH2Qow1-.mjs.map → secrets-CdfzLdoO.mjs.map} +1 -1
  640. package/dist/{sections-DTfjyf1z.mjs → sections-3X52kmIR.mjs} +2 -2
  641. package/dist/{sections-DTfjyf1z.mjs.map → sections-3X52kmIR.mjs.map} +1 -1
  642. package/dist/seed/index.d.mts +2 -2
  643. package/dist/seed/index.mjs +28 -26
  644. package/dist/seo/index.d.mts +3 -3
  645. package/dist/seo/index.d.mts.map +1 -1
  646. package/dist/seo/index.mjs +20 -21
  647. package/dist/seo/index.mjs.map +1 -1
  648. package/dist/{seo-Cm-dtvgk.mjs → seo-Bw68KxRc.mjs} +3 -3
  649. package/dist/{seo-Cm-dtvgk.mjs.map → seo-Bw68KxRc.mjs.map} +1 -1
  650. package/dist/{seo-BSiTIXzd.mjs → seo-C4AmbsMU.mjs} +3 -2
  651. package/dist/seo-C4AmbsMU.mjs.map +1 -0
  652. package/dist/{service-DYsDHEKe.mjs → service-J_-Vgo7R.mjs} +3 -3
  653. package/dist/{service-DYsDHEKe.mjs.map → service-J_-Vgo7R.mjs.map} +1 -1
  654. package/dist/{session-user-CNAfvsdw.mjs → session-user-CbnMMwk6.mjs} +1 -1
  655. package/dist/{session-user-CNAfvsdw.mjs.map → session-user-CbnMMwk6.mjs.map} +1 -1
  656. package/dist/{settings-DjtkUo__.mjs → settings-AnEFYICn.mjs} +3 -3
  657. package/dist/{settings-DjtkUo__.mjs.map → settings-AnEFYICn.mjs.map} +1 -1
  658. package/dist/{settings-BgN-0DT-.mjs → settings-DcMjREe5.mjs} +21 -8
  659. package/dist/settings-DcMjREe5.mjs.map +1 -0
  660. package/dist/{setup-complete-CcpXaPU7.mjs → setup-complete-BClXXTvr.mjs} +2 -2
  661. package/dist/{setup-complete-CcpXaPU7.mjs.map → setup-complete-BClXXTvr.mjs.map} +1 -1
  662. package/dist/{setup-nonce-Reyw30jg.mjs → setup-nonce-BheRa4RG.mjs} +1 -1
  663. package/dist/{setup-nonce-Reyw30jg.mjs.map → setup-nonce-BheRa4RG.mjs.map} +1 -1
  664. package/dist/{single-flight-cache-BPuGPdcN.mjs → single-flight-cache-jaswDzmQ.mjs} +2 -2
  665. package/dist/{single-flight-cache-BPuGPdcN.mjs.map → single-flight-cache-jaswDzmQ.mjs.map} +1 -1
  666. package/dist/{site-url-Cs_V9n3V.mjs → site-url-Bqf-ea3N.mjs} +3 -3
  667. package/dist/{site-url-Cs_V9n3V.mjs.map → site-url-Bqf-ea3N.mjs.map} +1 -1
  668. package/dist/{snapshot-DSB8P7Lm.mjs → snapshot-C4CtXntb.mjs} +51 -35
  669. package/dist/snapshot-C4CtXntb.mjs.map +1 -0
  670. package/dist/{ssrf-DqebVE34.mjs → ssrf-gl4gFNhw.mjs} +151 -93
  671. package/dist/ssrf-gl4gFNhw.mjs.map +1 -0
  672. package/dist/{state-BJfU9Uzw.mjs → state-1F6IOhdQ.mjs} +1 -1
  673. package/dist/{state-BJfU9Uzw.mjs.map → state-1F6IOhdQ.mjs.map} +1 -1
  674. package/dist/{status-DDu8HIQl.mjs → status-Cenfk_r5.mjs} +1 -1
  675. package/dist/{status-DDu8HIQl.mjs.map → status-Cenfk_r5.mjs.map} +1 -1
  676. package/dist/storage/local.d.mts +2 -1
  677. package/dist/storage/local.d.mts.map +1 -1
  678. package/dist/storage/local.mjs +1 -1
  679. package/dist/storage/local.mjs.map +1 -1
  680. package/dist/storage/s3.d.mts +2 -1
  681. package/dist/storage/s3.d.mts.map +1 -1
  682. package/dist/storage/s3.mjs +3 -2
  683. package/dist/storage/s3.mjs.map +1 -1
  684. package/dist/{target-D0o26Azo.mjs → target-CRzeTs8G.mjs} +1 -1
  685. package/dist/{target-D0o26Azo.mjs.map → target-CRzeTs8G.mjs.map} +1 -1
  686. package/dist/{taxonomies-CPGxo-bn.mjs → taxonomies-BOdxuZpV.mjs} +23 -13
  687. package/dist/taxonomies-BOdxuZpV.mjs.map +1 -0
  688. package/dist/{taxonomies-kmyudNGP.mjs → taxonomies-NcFDq5Gg.mjs} +58 -23
  689. package/dist/taxonomies-NcFDq5Gg.mjs.map +1 -0
  690. package/dist/{taxonomy-8X09dLN5.mjs → taxonomy-DP1vny4K.mjs} +12 -4
  691. package/dist/{taxonomy-8X09dLN5.mjs.map → taxonomy-DP1vny4K.mjs.map} +1 -1
  692. package/dist/{tokens-gTS-IVUp.mjs → tokens-CDk8ox9p.mjs} +1 -1
  693. package/dist/{tokens-gTS-IVUp.mjs.map → tokens-CDk8ox9p.mjs.map} +1 -1
  694. package/dist/{transport-_6R1ub7t.d.mts → transport-BVn4tVb9.d.mts} +1 -1
  695. package/dist/{transport-_6R1ub7t.d.mts.map → transport-BVn4tVb9.d.mts.map} +1 -1
  696. package/dist/{transport-fX59xaJz.mjs → transport-DP0JI-8i.mjs} +1 -1
  697. package/dist/{transport-fX59xaJz.mjs.map → transport-DP0JI-8i.mjs.map} +1 -1
  698. package/dist/{trusted-proxy-fe6nEgR4.mjs → trusted-proxy-BTM6UxqD.mjs} +1 -1
  699. package/dist/{trusted-proxy-fe6nEgR4.mjs.map → trusted-proxy-BTM6UxqD.mjs.map} +1 -1
  700. package/dist/{types-D_DWe7k9.d.mts → types-2n848aVW.d.mts} +3 -2
  701. package/dist/types-2n848aVW.d.mts.map +1 -0
  702. package/dist/types-A2cN6a4a.mjs +3 -0
  703. package/dist/{types-75KIqzL9.mjs → types-BMXnRIrX.mjs} +4 -2
  704. package/dist/types-BMXnRIrX.mjs.map +1 -0
  705. package/dist/{types-Vg6f5i3s.d.mts → types-BouXpOsa.d.mts} +121 -4
  706. package/dist/types-BouXpOsa.d.mts.map +1 -0
  707. package/dist/{types-BXUmsINL.mjs → types-ByG2coLw.mjs} +1 -1
  708. package/dist/{types-BXUmsINL.mjs.map → types-ByG2coLw.mjs.map} +1 -1
  709. package/dist/types-CQPWhPxE.mjs.map +1 -1
  710. package/dist/{types-Blb-MRC3.d.mts → types-DEfNJ__A.d.mts} +1 -1
  711. package/dist/{types-Blb-MRC3.d.mts.map → types-DEfNJ__A.d.mts.map} +1 -1
  712. package/dist/{types-Br-ERaxh.d.mts → types-DKcKSbtB.d.mts} +23 -7
  713. package/dist/types-DKcKSbtB.d.mts.map +1 -0
  714. package/dist/{types-BzBd3PeX.d.mts → types-DRYs7uTL.d.mts} +1 -1
  715. package/dist/{types-BzBd3PeX.d.mts.map → types-DRYs7uTL.d.mts.map} +1 -1
  716. package/dist/{types-CLqvnd05.d.mts → types-DaEg7KX2.d.mts} +1 -1
  717. package/dist/{types-CLqvnd05.d.mts.map → types-DaEg7KX2.d.mts.map} +1 -1
  718. package/dist/{types-DJQxln7q.d.mts → types-LU8utpP_.d.mts} +14 -10
  719. package/dist/types-LU8utpP_.d.mts.map +1 -0
  720. package/dist/{types-D5VVLr7J.d.mts → types-VpYfPUxN.d.mts} +1 -1
  721. package/dist/{types-D5VVLr7J.d.mts.map → types-VpYfPUxN.d.mts.map} +1 -1
  722. package/dist/{types-DM3vioBY.mjs → types-c9GP7Dj5.mjs} +1 -1
  723. package/dist/{types-DM3vioBY.mjs.map → types-c9GP7Dj5.mjs.map} +1 -1
  724. package/dist/{types-DHxzBjbD.d.mts → types-tJWDK__M.d.mts} +14 -1
  725. package/dist/types-tJWDK__M.d.mts.map +1 -0
  726. package/dist/{upload-attempts-CNyGSepg.mjs → upload-attempts-C6S2y-lp.mjs} +1 -1
  727. package/dist/{upload-attempts-CNyGSepg.mjs.map → upload-attempts-C6S2y-lp.mjs.map} +1 -1
  728. package/dist/{url-pattern-K-KdXcSe.mjs → url-pattern-UYtxVTuj.mjs} +1 -1
  729. package/dist/{url-pattern-K-KdXcSe.mjs.map → url-pattern-UYtxVTuj.mjs.map} +1 -1
  730. package/dist/{user-CtYY0tp2.mjs → user-DIsIXogT.mjs} +2 -2
  731. package/dist/{user-CtYY0tp2.mjs.map → user-DIsIXogT.mjs.map} +1 -1
  732. package/dist/{utils-HztC73hq.mjs → utils-BicP5Qbg.mjs} +2 -2
  733. package/dist/{utils-HztC73hq.mjs.map → utils-BicP5Qbg.mjs.map} +1 -1
  734. package/dist/{validate-Dd-IUjnZ.mjs → validate-D8VPn4Hv.mjs} +8 -3
  735. package/dist/validate-D8VPn4Hv.mjs.map +1 -0
  736. package/dist/{validate-DlqdOZXB.d.mts → validate-Df6Dvwbw.d.mts} +12 -7
  737. package/dist/validate-Df6Dvwbw.d.mts.map +1 -0
  738. package/dist/{validation-D83n7Npi.mjs → validation-CzMJn9Ku.mjs} +13 -11
  739. package/dist/{validation-D83n7Npi.mjs.map → validation-CzMJn9Ku.mjs.map} +1 -1
  740. package/dist/version-CK67_SXX.mjs +7 -0
  741. package/dist/{version-ri-sCyAp.mjs.map → version-CK67_SXX.mjs.map} +1 -1
  742. package/dist/{widgets-CpmZd9Q-.mjs → widgets-RFVAxQl3.mjs} +18 -5
  743. package/dist/widgets-RFVAxQl3.mjs.map +1 -0
  744. package/dist/{wxr-taxonomies-BFd0y72_.d.mts → wxr-taxonomies-BX4yQL9s.d.mts} +1 -1
  745. package/dist/{wxr-taxonomies-BFd0y72_.d.mts.map → wxr-taxonomies-BX4yQL9s.d.mts.map} +1 -1
  746. package/dist/{wxr-taxonomies-Df4vxWcU.mjs → wxr-taxonomies-Csdp7yde.mjs} +4 -4
  747. package/dist/{wxr-taxonomies-Df4vxWcU.mjs.map → wxr-taxonomies-Csdp7yde.mjs.map} +1 -1
  748. package/dist/{zod-generator-DylzusHh.mjs → zod-generator-CNRGdnBY.mjs} +11 -7
  749. package/dist/zod-generator-CNRGdnBY.mjs.map +1 -0
  750. package/package.json +16 -11
  751. package/src/api/errors.ts +9 -0
  752. package/src/api/handlers/content.ts +115 -90
  753. package/src/api/handlers/entry-lock.ts +206 -0
  754. package/src/api/handlers/index.ts +1 -0
  755. package/src/api/handlers/manifest.ts +162 -12
  756. package/src/api/handlers/marketplace.ts +28 -20
  757. package/src/api/handlers/media.ts +30 -0
  758. package/src/api/handlers/menus.ts +9 -0
  759. package/src/api/handlers/registry.ts +406 -297
  760. package/src/api/handlers/revision.ts +2 -1
  761. package/src/api/handlers/seo.ts +10 -1
  762. package/src/api/handlers/snapshot.ts +84 -72
  763. package/src/api/handlers/taxonomies.ts +25 -9
  764. package/src/api/openapi/document.ts +196 -11
  765. package/src/api/parse.ts +1 -1
  766. package/src/api/schemas/auth.ts +4 -4
  767. package/src/api/schemas/bylines.ts +3 -3
  768. package/src/api/schemas/comments.ts +1 -1
  769. package/src/api/schemas/common.ts +3 -2
  770. package/src/api/schemas/content.ts +86 -22
  771. package/src/api/schemas/entry-lock.ts +48 -0
  772. package/src/api/schemas/index.ts +1 -0
  773. package/src/api/schemas/media.ts +52 -0
  774. package/src/api/schemas/redirects.ts +6 -1
  775. package/src/api/schemas/schema.ts +14 -1
  776. package/src/api/schemas/setup.ts +1 -1
  777. package/src/api/schemas/taxonomies.ts +2 -2
  778. package/src/api/schemas/users.ts +1 -1
  779. package/src/api/types.ts +25 -10
  780. package/src/astro/dev-typegen.ts +35 -0
  781. package/src/astro/image-endpoint.ts +2 -2
  782. package/src/astro/integration/dev-typegen.ts +91 -0
  783. package/src/astro/integration/index.ts +18 -50
  784. package/src/astro/integration/routes.ts +10 -0
  785. package/src/astro/integration/runtime.ts +13 -5
  786. package/src/astro/integration/vite-config.ts +51 -2
  787. package/src/astro/middleware.ts +21 -0
  788. package/src/astro/routes/api/admin/api-tokens/index.ts +4 -1
  789. package/src/astro/routes/api/admin/oauth-clients/[id].ts +1 -1
  790. package/src/astro/routes/api/admin/oauth-clients/index.ts +1 -1
  791. package/src/astro/routes/api/admin/plugins/registry/[id]/update.ts +4 -0
  792. package/src/astro/routes/api/admin/plugins/registry/artifact.ts +3 -7
  793. package/src/astro/routes/api/admin/plugins/registry/install.ts +4 -0
  794. package/src/astro/routes/api/admin/plugins/registry/verify.ts +60 -0
  795. package/src/astro/routes/api/content/[collection]/[id]/discard-draft.ts +18 -2
  796. package/src/astro/routes/api/content/[collection]/[id]/lock.ts +133 -0
  797. package/src/astro/routes/api/content/[collection]/[id]/publish.ts +12 -1
  798. package/src/astro/routes/api/content/[collection]/[id]/schedule.ts +20 -0
  799. package/src/astro/routes/api/content/[collection]/[id]/unpublish.ts +16 -2
  800. package/src/astro/routes/api/content/[collection]/[id].ts +27 -2
  801. package/src/astro/routes/api/content/[collection]/index.ts +3 -0
  802. package/src/astro/routes/api/manifest.ts +1 -1
  803. package/src/astro/routes/api/media/[id]/replace.ts +114 -0
  804. package/src/astro/routes/api/media/file/[...key].ts +4 -1
  805. package/src/astro/routes/api/media/upload-url.ts +8 -4
  806. package/src/astro/routes/api/media.ts +54 -8
  807. package/src/astro/routes/api/menus/[name]/items/[id].ts +7 -2
  808. package/src/astro/routes/api/menus/[name]/items.ts +4 -1
  809. package/src/astro/routes/api/menus/[name]/reorder.ts +4 -1
  810. package/src/astro/routes/api/menus/[name]/translations.ts +4 -1
  811. package/src/astro/routes/api/menus/[name].ts +7 -2
  812. package/src/astro/routes/api/menus/index.ts +4 -1
  813. package/src/astro/routes/api/settings/email.ts +1 -1
  814. package/src/astro/routes/api/settings.ts +4 -1
  815. package/src/astro/routes/api/taxonomies/[name]/reorder.ts +4 -1
  816. package/src/astro/routes/api/taxonomies/[name]/terms/[slug]/translations.ts +4 -1
  817. package/src/astro/routes/api/taxonomies/[name]/terms/[slug].ts +7 -2
  818. package/src/astro/routes/api/taxonomies/[name]/terms/index.ts +4 -1
  819. package/src/astro/routes/api/taxonomies/[name].ts +7 -2
  820. package/src/astro/routes/api/taxonomies/index.ts +4 -1
  821. package/src/astro/routes/api/widget-areas/[name]/reorder.ts +3 -1
  822. package/src/astro/routes/api/widget-areas/[name]/widgets/[id].ts +5 -2
  823. package/src/astro/routes/api/widget-areas/[name]/widgets.ts +3 -1
  824. package/src/astro/routes/api/widget-areas/[name].ts +3 -1
  825. package/src/astro/routes/api/widget-areas/index.ts +3 -1
  826. package/src/astro/routes/sitemap-[collection].xml.ts +4 -0
  827. package/src/astro/types.ts +36 -8
  828. package/src/auth/challenge-store.ts +3 -1
  829. package/src/aws-sdk.d.ts +1 -0
  830. package/src/cache/chrome-tags.ts +24 -0
  831. package/src/cli/commands/content.ts +31 -5
  832. package/src/cli/commands/export-seed.ts +2 -0
  833. package/src/client/index.ts +34 -7
  834. package/src/components/EmDashBodyEnd.astro +4 -1
  835. package/src/components/EmDashBodyStart.astro +4 -1
  836. package/src/components/EmDashHead.astro +35 -16
  837. package/src/components/EmDashImage.astro +2 -1
  838. package/src/components/EmDashMedia.astro +2 -1
  839. package/src/components/Gallery.astro +18 -4
  840. package/src/components/InlineEditor.astro +3 -1
  841. package/src/components/InlinePortableTextEditor.tsx +112 -12
  842. package/src/components/PortableText.astro +4 -0
  843. package/src/components/Table.astro +147 -62
  844. package/src/components/widgets/Archives.astro +2 -37
  845. package/src/config/errors.ts +13 -0
  846. package/src/content/converters/index.ts +2 -0
  847. package/src/content/converters/mark-safety.ts +1 -0
  848. package/src/content/converters/portable-text-identity.ts +139 -0
  849. package/src/content/converters/portable-text-to-prosemirror.ts +226 -69
  850. package/src/content/converters/prosemirror-to-portable-text.ts +128 -28
  851. package/src/content/converters/types.ts +11 -0
  852. package/src/database/dialect-helpers.ts +125 -0
  853. package/src/database/migrations/017_authorization_codes.ts +14 -4
  854. package/src/database/migrations/074_content_deleted_scheduled_index.ts +55 -0
  855. package/src/database/migrations/075_entry_edit_locks.ts +44 -0
  856. package/src/database/migrations/076_collection_nav_group.ts +22 -0
  857. package/src/database/migrations/077_plugin_storage_revisions.ts +89 -0
  858. package/src/database/migrations/runner.ts +9 -1
  859. package/src/database/repositories/byline.ts +32 -16
  860. package/src/database/repositories/content.ts +284 -48
  861. package/src/database/repositories/entry-locks.ts +257 -0
  862. package/src/database/repositories/media-usage.ts +66 -37
  863. package/src/database/repositories/media.ts +60 -1
  864. package/src/database/repositories/options.ts +69 -5
  865. package/src/database/repositories/plugin-storage.ts +233 -9
  866. package/src/database/repositories/redirect.ts +17 -6
  867. package/src/database/repositories/taxonomy.ts +8 -0
  868. package/src/database/repositories/types.ts +11 -7
  869. package/src/database/types.ts +15 -1
  870. package/src/db/adapters.ts +8 -1
  871. package/src/db/postgres.ts +23 -0
  872. package/src/emdash-runtime.ts +196 -199
  873. package/src/fields/boolean.ts +1 -1
  874. package/src/fields/datetime.ts +1 -1
  875. package/src/fields/file.ts +1 -1
  876. package/src/fields/integer.ts +1 -1
  877. package/src/fields/json.ts +1 -1
  878. package/src/fields/multiselect.ts +1 -1
  879. package/src/fields/number.ts +1 -1
  880. package/src/fields/portable-text.ts +1 -1
  881. package/src/fields/richtext.ts +1 -1
  882. package/src/fields/select.ts +1 -1
  883. package/src/fields/slug.ts +1 -1
  884. package/src/fields/text.ts +1 -1
  885. package/src/fields/textarea.ts +1 -1
  886. package/src/fields/types.ts +2 -2
  887. package/src/i18n/resolve.ts +44 -4
  888. package/src/index.ts +39 -3
  889. package/src/loader.ts +96 -12
  890. package/src/mcp/server.ts +251 -29
  891. package/src/media/image-endpoint.ts +5 -2
  892. package/src/media/normalize.ts +15 -4
  893. package/src/media/responsive.ts +23 -0
  894. package/src/media/usage/cleanup.ts +9 -8
  895. package/src/media/usage/content-refresh.ts +2 -1
  896. package/src/menus/index.ts +33 -21
  897. package/src/object-cache/index.ts +44 -2
  898. package/src/page/seo-contributions.ts +78 -1
  899. package/src/page/seo-panel.ts +47 -0
  900. package/src/plugin-types.ts +27 -1
  901. package/src/plugins/conditional-storage.ts +30 -0
  902. package/src/plugins/context.ts +49 -17
  903. package/src/plugins/hooks.ts +10 -1
  904. package/src/plugins/index.ts +15 -0
  905. package/src/plugins/manager.ts +6 -2
  906. package/src/plugins/manifest-schema.ts +1 -1
  907. package/src/plugins/routes.ts +3 -1
  908. package/src/plugins/sandbox/hook-result.ts +52 -0
  909. package/src/plugins/sandbox/index.ts +10 -0
  910. package/src/plugins/sandbox/types.ts +16 -2
  911. package/src/plugins/storage-query.ts +45 -0
  912. package/src/plugins/storage-update.ts +96 -0
  913. package/src/plugins/types.ts +120 -0
  914. package/src/query.ts +29 -3
  915. package/src/registry/artifact-checksum.ts +15 -0
  916. package/src/registry/artifact-verification.ts +85 -0
  917. package/src/registry/authoritative-records.ts +180 -0
  918. package/src/registry/config.ts +130 -27
  919. package/src/registry/record-labels.ts +28 -0
  920. package/src/registry/types.ts +5 -6
  921. package/src/schema/collection-slugs-cache.ts +157 -0
  922. package/src/schema/registry.ts +45 -3
  923. package/src/schema/types.ts +25 -6
  924. package/src/schema/zod-generator.ts +16 -13
  925. package/src/security/ssrf.ts +172 -143
  926. package/src/seed/apply.ts +4 -0
  927. package/src/seed/types.ts +7 -2
  928. package/src/seed/validate.ts +18 -1
  929. package/src/seo/hreflang.ts +1 -0
  930. package/src/seo/index.ts +5 -10
  931. package/src/seo/media-url.ts +26 -0
  932. package/src/settings/index.ts +16 -0
  933. package/src/storage/local.ts +1 -0
  934. package/src/storage/s3.ts +2 -0
  935. package/src/storage/types.ts +2 -0
  936. package/src/taxonomies/index.ts +40 -20
  937. package/src/taxonomies/term-counts.ts +22 -5
  938. package/src/widgets/archives.ts +67 -0
  939. package/src/widgets/index.ts +16 -0
  940. package/dist/api-B0w3uBiG.mjs +0 -2269
  941. package/dist/api-B0w3uBiG.mjs.map +0 -1
  942. package/dist/apply-B_VMpJ2P.mjs.map +0 -1
  943. package/dist/byline-Cpnwrje1.mjs.map +0 -1
  944. package/dist/challenge-store-D5pSY2S1.mjs.map +0 -1
  945. package/dist/content-CP-SeXNa.mjs.map +0 -1
  946. package/dist/content-refresh-DLOfIhYc.mjs.map +0 -1
  947. package/dist/context-BR5hRWiK.mjs.map +0 -1
  948. package/dist/dialect-helpers-BSbfaO3F.mjs.map +0 -1
  949. package/dist/errors-n2j49uNf.mjs.map +0 -1
  950. package/dist/index-DWbJrsAg.d.mts.map +0 -1
  951. package/dist/loader-ZsjE4paL.mjs.map +0 -1
  952. package/dist/manifest-schema-CUYPfCEH.mjs.map +0 -1
  953. package/dist/media-BjwNuLEu.mjs.map +0 -1
  954. package/dist/media-D6SeAfBl.mjs.map +0 -1
  955. package/dist/media-url-DH7giMx_.mjs.map +0 -1
  956. package/dist/menus-CNg0QlDt.mjs.map +0 -1
  957. package/dist/normalize-CSxdKBVa.mjs.map +0 -1
  958. package/dist/object-cache-71tPfV4A.mjs.map +0 -1
  959. package/dist/options-BHPeIbBd.mjs.map +0 -1
  960. package/dist/options-BhZIeFY1.d.mts.map +0 -1
  961. package/dist/query-D18vTdha.mjs.map +0 -1
  962. package/dist/redirect-CZkbozu9.mjs.map +0 -1
  963. package/dist/redirects-CRIM55KH.mjs.map +0 -1
  964. package/dist/registry-BiO5WwPq.mjs +0 -2716
  965. package/dist/registry-BiO5WwPq.mjs.map +0 -1
  966. package/dist/registry-Cx-jEJOS.mjs.map +0 -1
  967. package/dist/relations-BTPM2saV.mjs.map +0 -1
  968. package/dist/relations-C7B46bcU.d.mts.map +0 -1
  969. package/dist/resolve-DxUpTMmE.mjs.map +0 -1
  970. package/dist/runner-77GOZCnH.mjs.map +0 -1
  971. package/dist/runner-zgqA_CqP.d.mts.map +0 -1
  972. package/dist/seo-BSiTIXzd.mjs.map +0 -1
  973. package/dist/settings-BgN-0DT-.mjs.map +0 -1
  974. package/dist/snapshot-DSB8P7Lm.mjs.map +0 -1
  975. package/dist/ssrf-DqebVE34.mjs.map +0 -1
  976. package/dist/taxonomies-CPGxo-bn.mjs.map +0 -1
  977. package/dist/taxonomies-kmyudNGP.mjs.map +0 -1
  978. package/dist/types-75KIqzL9.mjs.map +0 -1
  979. package/dist/types-Br-ERaxh.d.mts.map +0 -1
  980. package/dist/types-D6OcIp2P.mjs +0 -3
  981. package/dist/types-DHxzBjbD.d.mts.map +0 -1
  982. package/dist/types-DJQxln7q.d.mts.map +0 -1
  983. package/dist/types-D_DWe7k9.d.mts.map +0 -1
  984. package/dist/types-Vg6f5i3s.d.mts.map +0 -1
  985. package/dist/validate-Dd-IUjnZ.mjs.map +0 -1
  986. package/dist/validate-DlqdOZXB.d.mts.map +0 -1
  987. package/dist/version-ri-sCyAp.mjs +0 -7
  988. package/dist/widgets-CpmZd9Q-.mjs.map +0 -1
  989. package/dist/zod-generator-DylzusHh.mjs.map +0 -1
  990. /package/dist/{api-tokens-B5NHLNUN.mjs → api-tokens-B_lfpmH3.mjs} +0 -0
  991. /package/dist/{ssrf-BPKzkm6O.mjs → ssrf-TQhaljuI.mjs} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"file":"byline-Cpnwrje1.mjs","names":[],"sources":["../src/database/repositories/byline.ts"],"sourcesContent":["import { sql, type Kysely, type Selectable } from \"kysely\";\nimport { ulid } from \"ulidx\";\n\nimport { getBylineFieldDefs } from \"../../bylines/field-defs-cache.js\";\nimport {\n\tinvalidateBylineObjectCache,\n\tinvalidateCollectionCache,\n} from \"../../object-cache/index.js\";\nimport {\n\tclearRequestCacheEntry,\n\tpeekRequestCache,\n\tsetRequestCacheEntry,\n} from \"../../request-cache.js\";\nimport type { BylineFieldDefinition, CustomFieldValue } from \"../../schema/types.js\";\nimport { chunks, SQL_BATCH_SIZE } from \"../../utils/chunks.js\";\nimport { listTablesLike } from \"../dialect-helpers.js\";\nimport { withTransaction } from \"../transaction.js\";\nimport type { BylineTable, Database } from \"../types.js\";\nimport { validateIdentifier } from \"../validate.js\";\nimport {\n\tdecodeCursor,\n\tEmDashValidationError,\n\tencodeCursor,\n\ttype BylineSummary,\n\ttype ContentBylineCredit,\n\ttype FindManyResult,\n} from \"./types.js\";\n\ntype BylineRow = Selectable<BylineTable>;\n\n/**\n * A byline row optionally augmented with the avatar's media columns, folded in\n * by the `LEFT JOIN media` in the content-credit hydration queries. The plain\n * `selectAll()` finders produce rows without these keys, so they're optional\n * and `rowToByline` defaults them to null.\n */\ntype BylineRowWithAvatar = BylineRow & {\n\tavatar_storage_key?: string | null;\n\tavatar_alt?: string | null;\n\tavatar_blurhash?: string | null;\n\tavatar_dominant_color?: string | null;\n};\n\nexport interface CreateBylineInput {\n\tslug: string;\n\tdisplayName: string;\n\tbio?: string | null;\n\tavatarMediaId?: string | null;\n\twebsiteUrl?: string | null;\n\tuserId?: string | null;\n\tisGuest?: boolean;\n\t/**\n\t * Locale this byline row belongs to. When omitted, the DB DEFAULT (the\n\t * configured `defaultLocale` after migration 040) is used. Keeps behaviour\n\t * consistent with `TaxonomyRepository.create`.\n\t */\n\tlocale?: string;\n\t/**\n\t * When set, the new row joins the source byline's translation_group rather\n\t * than minting a fresh one. The source must exist; otherwise the create\n\t * throws. Mirrors `TaxonomyRepository.create`.\n\t */\n\ttranslationOf?: string;\n\t/**\n\t * Byline custom-field values to seed on the new row (Phase 6 of\n\t * Discussion #1174). Same semantics as `UpdateBylineInput.customFields`:\n\t * keys must match registered slugs in `_emdash_byline_fields`, values\n\t * are validated against the field's type, and writes route to\n\t * `_emdash_byline_field_values` (translatable) or\n\t * `_emdash_byline_field_group_values` (group-shared). Validation runs\n\t * before the row insert so a bad value can't leave a bare byline behind.\n\t */\n\tcustomFields?: Record<string, unknown>;\n}\n\nexport interface UpdateBylineInput {\n\tslug?: string;\n\tdisplayName?: string;\n\tbio?: string | null;\n\tavatarMediaId?: string | null;\n\twebsiteUrl?: string | null;\n\tuserId?: string | null;\n\tisGuest?: boolean;\n\t/**\n\t * Byline custom-field values to write (Phase 3 of Discussion #1174).\n\t *\n\t * Each key must match a registered slug in `_emdash_byline_fields`;\n\t * unknown keys throw `EmDashValidationError`. Per-field writes route\n\t * to `_emdash_byline_field_values` (when the field's `translatable`\n\t * flag is true) or `_emdash_byline_field_group_values` (when false).\n\t * A value of `null` clears the row.\n\t *\n\t * Values are validated against the field's type:\n\t * - `string` / `text` / `url` accept a `string`\n\t * - `boolean` accepts a `boolean`\n\t * - `select` accepts a `string` that appears in `validation.options`\n\t *\n\t * Writes are idempotent (`INSERT … ON CONFLICT DO UPDATE`), so\n\t * retrying the same update produces the same DB state.\n\t */\n\tcustomFields?: Record<string, unknown>;\n}\n\nexport interface ContentBylineInput {\n\tbylineId: string;\n\troleLabel?: string | null;\n}\n\nfunction rowToByline(row: BylineRowWithAvatar): BylineSummary {\n\treturn {\n\t\tid: row.id,\n\t\tslug: row.slug,\n\t\tdisplayName: row.display_name,\n\t\tbio: row.bio,\n\t\tavatarMediaId: row.avatar_media_id,\n\t\tavatarStorageKey: row.avatar_storage_key ?? null,\n\t\tavatarAlt: row.avatar_alt ?? null,\n\t\tavatarBlurhash: row.avatar_blurhash ?? null,\n\t\tavatarDominantColor: row.avatar_dominant_color ?? null,\n\t\twebsiteUrl: row.website_url,\n\t\tuserId: row.user_id,\n\t\tisGuest: row.is_guest === 1,\n\t\tcreatedAt: row.created_at,\n\t\tupdatedAt: row.updated_at,\n\t\tlocale: row.locale,\n\t\ttranslationGroup: row.translation_group,\n\t};\n}\n\n/**\n * Merge a single decoded value into a `BylineSummary.customFields` map.\n * Centralised so the merge semantics (null storage, JSON.parse failure\n * handling) live in one place across both translatable and group-shared\n * paths.\n *\n * A stored row with `value = NULL` (representing an explicit null) is\n * surfaced as `null` in `customFields`. A row with a malformed JSON\n * payload is dropped silently with a `console.warn` — a corrupted\n * payload shouldn't break the entire byline hydration; the field-defs\n * cache will let admins replace the value, and the warning makes the\n * issue debuggable. (Storage path uses `JSON.stringify`, so the only\n * way to get malformed JSON is direct DB tampering or a future\n * migration bug.)\n */\nfunction assignCustomFieldValue(\n\tsummary: BylineSummary,\n\tfield: BylineFieldDefinition,\n\tstored: string | null,\n): void {\n\tconst target = summary.customFields ?? {};\n\tif (stored === null) {\n\t\ttarget[field.slug] = null;\n\t} else {\n\t\ttry {\n\t\t\t// eslint-disable-next-line typescript/no-unsafe-type-assertion -- coerceFieldValue ran at write time, see field-defs-cache.ts\n\t\t\ttarget[field.slug] = JSON.parse(stored) as CustomFieldValue;\n\t\t} catch {\n\t\t\tconsole.warn(\n\t\t\t\t`[BylineRepository] dropping malformed JSON for byline=${summary.id} ` +\n\t\t\t\t\t`field=${field.slug}: ${stored.slice(0, 60)}`,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t}\n\tsummary.customFields = target;\n}\n\n/**\n * Coerce a raw write-path value to `CustomFieldValue`, throwing\n * `EmDashValidationError` on type mismatch. `null` clears the field\n * (DELETE in the write path).\n *\n * TODO: `field.required` is not enforced. The admin UI exposes the\n * toggle but the backend accepts missing values; design pass needed\n * on the enforcement model.\n */\nfunction coerceFieldValue(field: BylineFieldDefinition, raw: unknown): CustomFieldValue {\n\tif (raw === null) return null;\n\n\tswitch (field.type) {\n\t\tcase \"string\":\n\t\tcase \"text\": {\n\t\t\tif (typeof raw !== \"string\") {\n\t\t\t\tthrow new EmDashValidationError(\n\t\t\t\t\t`Byline field \"${field.slug}\" expects a string value (received ${typeof raw})`,\n\t\t\t\t\t{ slug: field.slug, type: field.type, received: typeof raw },\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn raw;\n\t\t}\n\t\tcase \"url\": {\n\t\t\tif (typeof raw !== \"string\") {\n\t\t\t\tthrow new EmDashValidationError(\n\t\t\t\t\t`Byline field \"${field.slug}\" expects a string value (received ${typeof raw})`,\n\t\t\t\t\t{ slug: field.slug, type: field.type, received: typeof raw },\n\t\t\t\t);\n\t\t\t}\n\t\t\t// Empty string round-trips as a clear from the admin UI; any\n\t\t\t// non-empty value must be a valid http(s) URL. The scheme\n\t\t\t// allowlist mirrors `httpUrl` in `api/schemas/common.ts` —\n\t\t\t// `new URL` alone would accept `javascript:`/`data:` etc.\n\t\t\tif (raw === \"\") return raw;\n\t\t\tlet parsed: URL;\n\t\t\ttry {\n\t\t\t\tparsed = new URL(raw);\n\t\t\t} catch {\n\t\t\t\tthrow new EmDashValidationError(\n\t\t\t\t\t`Byline field \"${field.slug}\" expects a valid URL (received \"${raw}\")`,\n\t\t\t\t\t{ slug: field.slug, type: field.type, received: raw },\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (parsed.protocol !== \"http:\" && parsed.protocol !== \"https:\") {\n\t\t\t\tthrow new EmDashValidationError(\n\t\t\t\t\t`Byline field \"${field.slug}\" must use http or https scheme (received \"${parsed.protocol}\")`,\n\t\t\t\t\t{ slug: field.slug, type: field.type, received: raw, protocol: parsed.protocol },\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn raw;\n\t\t}\n\t\tcase \"boolean\": {\n\t\t\tif (typeof raw !== \"boolean\") {\n\t\t\t\tthrow new EmDashValidationError(\n\t\t\t\t\t`Byline field \"${field.slug}\" expects a boolean value (received ${typeof raw})`,\n\t\t\t\t\t{ slug: field.slug, type: field.type, received: typeof raw },\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn raw;\n\t\t}\n\t\tcase \"select\": {\n\t\t\tif (typeof raw !== \"string\") {\n\t\t\t\tthrow new EmDashValidationError(\n\t\t\t\t\t`Byline field \"${field.slug}\" expects a string value (received ${typeof raw})`,\n\t\t\t\t\t{ slug: field.slug, type: field.type, received: typeof raw },\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst options = field.validation?.options ?? [];\n\t\t\tif (!options.includes(raw)) {\n\t\t\t\tthrow new EmDashValidationError(\n\t\t\t\t\t`Byline field \"${field.slug}\" value \"${raw}\" is not one of the registered choices`,\n\t\t\t\t\t{ slug: field.slug, value: raw, options },\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn raw;\n\t\t}\n\t}\n}\n\n/**\n * Byline repository for content credits.\n *\n * Bylines are per-locale (migration 040). Translations of the same byline\n * share a `translation_group` ULID. `_emdash_content_bylines.byline_id` and\n * `ec_*.primary_byline_id` store the translation_group (not a row id) so a\n * single credit spans every locale variant of a byline.\n *\n * The repository does not resolve locale fallbacks on its own — callers\n * supply the locale they want. Hydration is strict per locale: a credit at\n * locale X renders iff a byline row exists at locale X within the credited\n * translation group. This mirrors `TaxonomyRepository.getTermsForEntry` and\n * the convention established by PR #916.\n *\n * Runtime helpers in `packages/core/src/bylines/index.ts` may layer fallback\n * resolution on top for the \"look up one byline by slug\" path, but the\n * relation-hydration methods on this class are always strict.\n */\nexport class BylineRepository {\n\tconstructor(private db: Kysely<Database>) {}\n\n\t// ============================================\n\t// Custom-field hydration (Phase 3 of #1174)\n\t// ============================================\n\n\t/**\n\t * Merge `customFields` onto each `BylineSummary` produced from the\n\t * given rows. Two batched queries total — one against\n\t * `_emdash_byline_field_values` (keyed by `byline_id`), one against\n\t * `_emdash_byline_field_group_values` (keyed by `translation_group`)\n\t * — both chunked at `SQL_BATCH_SIZE` for D1's bound-parameter cap.\n\t *\n\t * When zero fields are registered, every row gets `customFields = {}`\n\t * with no value-table reads (the field-defs cache returns `[]`).\n\t * Group-shared values are looked up via the row's `translation_group`,\n\t * so every locale sibling of the same byline identity sees the same\n\t * non-translatable value without re-reading per row.\n\t *\n\t * **Duplicate-row handling.** Callers (notably `getContentBylinesMany`\n\t * for list views with repeated authors) can pass the same byline row\n\t * multiple times. We assign values by *iterating both `rows` and\n\t * `summaries` in lockstep by index*, not by deduping into a Map keyed\n\t * on byline id. A Map approach silently drops earlier duplicates' merge\n\t * step (last writer wins, earlier instances keep their initial `{}`).\n\t * Iterating by index gives every duplicate its own merged copy.\n\t *\n\t * Hydration is *strict per row* — values are merged onto whichever\n\t * `BylineRow` produced them. Fallback semantics (e.g. \"if no value\n\t * for this locale, show the default-locale value\") are not the\n\t * repository's concern; consumers layer them on top if wanted, the\n\t * same way `BylineRepository` doesn't resolve locale fallback for\n\t * the base byline lookup.\n\t */\n\tprivate async withCustomFields(rows: BylineRow[]): Promise<BylineSummary[]> {\n\t\tconst summaries = rows.map(rowToByline);\n\t\t// Always populate `customFields = {}` (PR plan AC #6) — even when\n\t\t// no fields are registered, every BylineSummary carries the empty\n\t\t// object. A fresh object per summary so duplicate rows don't share\n\t\t// state.\n\t\tfor (const summary of summaries) {\n\t\t\tsummary.customFields = {};\n\t\t}\n\t\tawait this.applyCustomFieldsTo(summaries);\n\t\treturn summaries;\n\t}\n\n\tprivate async withCustomFieldsOne(row: BylineRow | undefined): Promise<BylineSummary | null> {\n\t\tif (!row) return null;\n\t\tconst [result] = await this.withCustomFields([row]);\n\t\treturn result ?? null;\n\t}\n\n\t/**\n\t * Hydrate `customFields` on each `BylineSummary`, mutating in place.\n\t *\n\t * The public entry point for callers that fetch byline rows in\n\t * multiple passes (e.g. `getBylinesForEntries`, which buckets by\n\t * locale and calls `getContentBylinesMany` per bucket) and want a\n\t * single batched hydration over the union of bylines, not one per\n\t * pass. Use with the `skipHydration` option on the read methods to\n\t * defer customFields work to a single call here.\n\t *\n\t * Two batched queries total (translatable + group-shared) regardless\n\t * of how many bylines, locales, or translation_groups are in the\n\t * input — meets the Phase 3 query-count envelope for mixed-locale\n\t * list views even when sibling locales reference disjoint\n\t * translation_groups.\n\t *\n\t * Replaces any existing `customFields` on each summary with a freshly\n\t * fetched map. Callers that want to merge rather than replace should\n\t * not use this entry point.\n\t */\n\tasync hydrateBylineCustomFields(summaries: BylineSummary[]): Promise<void> {\n\t\tfor (const summary of summaries) {\n\t\t\tsummary.customFields = {};\n\t\t}\n\t\tawait this.applyCustomFieldsTo(summaries);\n\t}\n\n\t/**\n\t * Shared merge engine for `withCustomFields` and\n\t * `hydrateBylineCustomFields`. Reads field defs (cached), batches the\n\t * translatable + group-shared fetches, and walks `summaries` directly\n\t * to apply values.\n\t *\n\t * Iterates `summaries` (not a `summaryById` map) so duplicate\n\t * `BylineSummary` objects sharing the same `id` — e.g. the same\n\t * author credited to multiple entries — each get their own merged\n\t * values. The previous Map-based dedup silently dropped earlier\n\t * duplicates' merge step.\n\t */\n\tprivate async applyCustomFieldsTo(summaries: BylineSummary[]): Promise<void> {\n\t\tif (summaries.length === 0) return;\n\n\t\tconst defs = await getBylineFieldDefs(this.db);\n\t\tif (defs.length === 0) return;\n\n\t\tconst fieldById = new Map(defs.map((d) => [d.id, d]));\n\n\t\t// Translatable values, batched by byline_id (unique per locale, so\n\t\t// IDs across different locale buckets don't collide — one batched\n\t\t// query covers everything).\n\t\tconst translatableByByline = new Map<string, Map<string, string | null>>();\n\t\tconst bylineIds = [...new Set(summaries.map((s) => s.id))];\n\t\tfor (const chunk of chunks(bylineIds, SQL_BATCH_SIZE)) {\n\t\t\tconst trRows = await this.db\n\t\t\t\t.selectFrom(\"_emdash_byline_field_values\")\n\t\t\t\t.select([\"byline_id\", \"field_id\", \"value\"])\n\t\t\t\t.where(\"byline_id\", \"in\", chunk)\n\t\t\t\t.execute();\n\t\t\tfor (const trRow of trRows) {\n\t\t\t\tlet fieldMap = translatableByByline.get(trRow.byline_id);\n\t\t\t\tif (!fieldMap) {\n\t\t\t\t\tfieldMap = new Map();\n\t\t\t\t\ttranslatableByByline.set(trRow.byline_id, fieldMap);\n\t\t\t\t}\n\t\t\t\tfieldMap.set(trRow.field_id, trRow.value);\n\t\t\t}\n\t\t}\n\n\t\t// Group-shared values, batched over the union of translation_groups,\n\t\t// with per-group request-cache priming so subsequent calls within\n\t\t// the same request share the lookup. Together with the\n\t\t// `hydrateBylineCustomFields` + `skipHydration` flow in\n\t\t// `getBylinesForEntries`, this keeps mixed-locale list views to\n\t\t// **one** group-shared query per request, even for disjoint\n\t\t// translation_groups across locale buckets.\n\t\tconst groups = [\n\t\t\t...new Set(\n\t\t\t\tsummaries\n\t\t\t\t\t.map((s) => s.translationGroup)\n\t\t\t\t\t.filter((g): g is string => typeof g === \"string\" && g.length > 0),\n\t\t\t),\n\t\t];\n\t\tconst groupByGroup = await this.loadGroupValuesByIds(groups);\n\n\t\t// Each loop gates on `field.translatable` so a row in the wrong\n\t\t// owner table (e.g. left over from a translatable flip) can't\n\t\t// leak into hydration.\n\t\tfor (const summary of summaries) {\n\t\t\tconst trValues = translatableByByline.get(summary.id);\n\t\t\tif (trValues) {\n\t\t\t\tfor (const [fieldId, value] of trValues) {\n\t\t\t\t\tconst field = fieldById.get(fieldId);\n\t\t\t\t\tif (!field || !field.translatable) continue;\n\t\t\t\t\tassignCustomFieldValue(summary, field, value);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (summary.translationGroup) {\n\t\t\t\tconst grpValues = groupByGroup.get(summary.translationGroup);\n\t\t\t\tif (grpValues) {\n\t\t\t\t\tfor (const [fieldId, value] of grpValues) {\n\t\t\t\t\t\tconst field = fieldById.get(fieldId);\n\t\t\t\t\t\tif (!field || field.translatable) continue;\n\t\t\t\t\t\tassignCustomFieldValue(summary, field, value);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Resolve the group-shared custom-field values for a set of\n\t * translation_groups, sharing work across hydration calls within the\n\t * same request via per-group `requestCached` entries.\n\t *\n\t * The non-translatable storage table (`_emdash_byline_field_group_values`)\n\t * is keyed by `translation_group`, which is locale-agnostic. Combining\n\t * this method with `skipHydration` on `getContentBylinesMany` and a\n\t * single `hydrateBylineCustomFields` call (see\n\t * `getBylinesForEntries`) keeps mixed-locale list hydration to **one**\n\t * batched group-shared SQL per request — even with disjoint\n\t * translation_groups across locale buckets. Solo callers (`findById`,\n\t * `findMany`, etc.) still get the same per-call batching they had\n\t * before; the cache simply means a second call in the same request\n\t * for an overlapping group is free.\n\t *\n\t * Cache key: `byline-field-group-values:${groupId}` — one entry per\n\t * group. Writes use `setRequestCacheEntry` (idempotent, doesn't\n\t * overwrite); `BylineRepository.update` calls `clearRequestCacheEntry`\n\t * after a group-shared write to keep the cache fresh within the same\n\t * request.\n\t */\n\tprivate async loadGroupValuesByIds(\n\t\tgroups: string[],\n\t): Promise<Map<string, Map<string, string | null>>> {\n\t\tconst result = new Map<string, Map<string, string | null>>();\n\t\tif (groups.length === 0) return result;\n\n\t\t// First pass: pull any already-cached groups from the request scope.\n\t\tconst missing: string[] = [];\n\t\tfor (const g of groups) {\n\t\t\tconst cached = peekRequestCache<Map<string, string | null>>(`byline-field-group-values:${g}`);\n\t\t\tif (cached) {\n\t\t\t\tresult.set(g, await cached);\n\t\t\t} else {\n\t\t\t\tmissing.push(g);\n\t\t\t}\n\t\t}\n\n\t\tif (missing.length === 0) return result;\n\n\t\t// Second pass: one batched SQL for the union of all missing groups\n\t\t// (chunked for D1's bound-parameter cap). Initialise empty maps for\n\t\t// missing groups so the primed cache covers \"this group has no\n\t\t// values\" — preventing a re-fetch on subsequent calls.\n\t\tconst fetched = new Map<string, Map<string, string | null>>();\n\t\tfor (const g of missing) fetched.set(g, new Map());\n\t\tfor (const chunk of chunks(missing, SQL_BATCH_SIZE)) {\n\t\t\tconst grpRows = await this.db\n\t\t\t\t.selectFrom(\"_emdash_byline_field_group_values\")\n\t\t\t\t.select([\"translation_group\", \"field_id\", \"value\"])\n\t\t\t\t.where(\"translation_group\", \"in\", chunk)\n\t\t\t\t.execute();\n\t\t\tfor (const grpRow of grpRows) {\n\t\t\t\tconst fieldMap = fetched.get(grpRow.translation_group);\n\t\t\t\tif (!fieldMap) continue;\n\t\t\t\tfieldMap.set(grpRow.field_id, grpRow.value);\n\t\t\t}\n\t\t}\n\n\t\tfor (const g of missing) {\n\t\t\tconst m = fetched.get(g);\n\t\t\tif (!m) continue;\n\t\t\tsetRequestCacheEntry(`byline-field-group-values:${g}`, m);\n\t\t\tresult.set(g, m);\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t// ============================================\n\t// Reads\n\t// ============================================\n\n\tasync findById(id: string): Promise<BylineSummary | null> {\n\t\tconst row = await this.db\n\t\t\t.selectFrom(\"_emdash_bylines\")\n\t\t\t.selectAll()\n\t\t\t.where(\"id\", \"=\", id)\n\t\t\t.executeTakeFirst();\n\t\treturn this.withCustomFieldsOne(row);\n\t}\n\n\t/**\n\t * Find a byline by slug. When `locale` is provided, filter by it strictly.\n\t * When omitted, returns the lowest-locale-code match (deterministic across\n\t * calls). Mirrors `TaxonomyRepository.findBySlug`.\n\t */\n\tasync findBySlug(slug: string, options?: { locale?: string }): Promise<BylineSummary | null> {\n\t\tlet query = this.db.selectFrom(\"_emdash_bylines\").selectAll().where(\"slug\", \"=\", slug);\n\t\tif (options?.locale !== undefined) query = query.where(\"locale\", \"=\", options.locale);\n\t\tconst row = await query.orderBy(\"locale\", \"asc\").executeTakeFirst();\n\t\treturn this.withCustomFieldsOne(row);\n\t}\n\n\t/**\n\t * Find the byline linked to a CMS user. Post-migration 040 the partial\n\t * unique on user_id is `(user_id, locale)`, so `locale` is required to\n\t * disambiguate when multiple locale variants exist. When omitted, returns\n\t * the lowest-locale-code match.\n\t */\n\tasync findByUserId(userId: string, options?: { locale?: string }): Promise<BylineSummary | null> {\n\t\tlet query = this.db.selectFrom(\"_emdash_bylines\").selectAll().where(\"user_id\", \"=\", userId);\n\t\tif (options?.locale !== undefined) query = query.where(\"locale\", \"=\", options.locale);\n\t\tconst row = await query.orderBy(\"locale\", \"asc\").executeTakeFirst();\n\t\treturn this.withCustomFieldsOne(row);\n\t}\n\n\tasync findMany(options?: {\n\t\tsearch?: string;\n\t\tisGuest?: boolean;\n\t\tuserId?: string;\n\t\tlocale?: string;\n\t\tcursor?: string;\n\t\tlimit?: number;\n\t}): Promise<FindManyResult<BylineSummary>> {\n\t\tconst limit = Math.min(Math.max(options?.limit ?? 50, 1), 100);\n\n\t\tlet query = this.db\n\t\t\t.selectFrom(\"_emdash_bylines\")\n\t\t\t.selectAll()\n\t\t\t.orderBy(\"created_at\", \"desc\")\n\t\t\t.orderBy(\"id\", \"desc\")\n\t\t\t.limit(limit + 1);\n\n\t\tif (options?.search) {\n\t\t\tconst escaped = options.search\n\t\t\t\t.replaceAll(\"\\\\\", \"\\\\\\\\\")\n\t\t\t\t.replaceAll(\"%\", \"\\\\%\")\n\t\t\t\t.replaceAll(\"_\", \"\\\\_\");\n\t\t\tconst term = `%${escaped}%`;\n\t\t\tquery = query.where((eb) =>\n\t\t\t\teb.or([eb(\"display_name\", \"like\", term), eb(\"slug\", \"like\", term)]),\n\t\t\t);\n\t\t}\n\n\t\tif (options?.isGuest !== undefined) {\n\t\t\tquery = query.where(\"is_guest\", \"=\", options.isGuest ? 1 : 0);\n\t\t}\n\n\t\tif (options?.userId !== undefined) {\n\t\t\tquery = query.where(\"user_id\", \"=\", options.userId);\n\t\t}\n\n\t\tif (options?.locale !== undefined) {\n\t\t\tquery = query.where(\"locale\", \"=\", options.locale);\n\t\t}\n\n\t\tif (options?.cursor) {\n\t\t\tconst decoded = decodeCursor(options.cursor);\n\t\t\tquery = query.where((eb) =>\n\t\t\t\teb.or([\n\t\t\t\t\teb(\"created_at\", \"<\", decoded.orderValue),\n\t\t\t\t\teb.and([eb(\"created_at\", \"=\", decoded.orderValue), eb(\"id\", \"<\", decoded.id)]),\n\t\t\t\t]),\n\t\t\t);\n\t\t}\n\n\t\tconst rows = await query.execute();\n\t\tconst pageRows = rows.slice(0, limit);\n\t\tconst items = await this.withCustomFields(pageRows);\n\t\tconst result: FindManyResult<BylineSummary> = { items };\n\n\t\tif (rows.length > limit) {\n\t\t\tconst last = items.at(-1);\n\t\t\tif (last) {\n\t\t\t\tresult.nextCursor = encodeCursor(last.createdAt, last.id);\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * List every sibling row in `translation_group`. Used by the admin\n\t * `TranslationsPanel` to render one entry per configured locale.\n\t */\n\tasync listTranslations(id: string): Promise<BylineSummary[]> {\n\t\tconst anchor = await this.findById(id);\n\t\tif (!anchor) return [];\n\t\tconst group = anchor.translationGroup ?? anchor.id;\n\t\treturn this.findByTranslationGroup(group);\n\t}\n\n\t/**\n\t * Direct lookup by `translation_group`. Returns every locale variant of a\n\t * byline, ordered by locale code (deterministic).\n\t */\n\tasync findByTranslationGroup(translationGroup: string): Promise<BylineSummary[]> {\n\t\tconst rows = await this.db\n\t\t\t.selectFrom(\"_emdash_bylines\")\n\t\t\t.selectAll()\n\t\t\t.where(\"translation_group\", \"=\", translationGroup)\n\t\t\t.orderBy(\"locale\", \"asc\")\n\t\t\t.execute();\n\t\treturn this.withCustomFields(rows);\n\t}\n\n\t/**\n\t * Validate a `customFields` input map into a write list before any row\n\t * write — throws `EmDashValidationError` on unknown slugs, type\n\t * mismatches, or select-choice misses.\n\t */\n\tprivate async resolveCustomFieldWrites(\n\t\tcustomFields: Record<string, unknown> | undefined,\n\t): Promise<Array<{ field: BylineFieldDefinition; value: CustomFieldValue }>> {\n\t\tif (!customFields || Object.keys(customFields).length === 0) return [];\n\t\tconst defs = await getBylineFieldDefs(this.db);\n\t\tconst bySlug = new Map(defs.map((d) => [d.slug, d]));\n\t\tconst writes: Array<{ field: BylineFieldDefinition; value: CustomFieldValue }> = [];\n\t\tfor (const [slug, raw] of Object.entries(customFields)) {\n\t\t\tconst field = bySlug.get(slug);\n\t\t\tif (!field) {\n\t\t\t\tthrow new EmDashValidationError(`Unknown byline custom field \"${slug}\"`, {\n\t\t\t\t\tslug,\n\t\t\t\t\tregistered: defs.map((d) => d.slug),\n\t\t\t\t});\n\t\t\t}\n\t\t\twrites.push({ field, value: coerceFieldValue(field, raw) });\n\t\t}\n\t\treturn writes;\n\t}\n\n\t/**\n\t * Write a validated custom-field list against a byline row inside the\n\t * caller's transaction. Per-field writes route to\n\t * `_emdash_byline_field_values` (translatable) or\n\t * `_emdash_byline_field_group_values` (group-shared); `null` clears.\n\t * Returns `true` when any group-shared row was touched so the caller\n\t * can invalidate the per-request cache post-commit.\n\t */\n\tprivate async applyCustomFieldWritesInTrx(\n\t\ttrx: Kysely<Database>,\n\t\tbylineId: string,\n\t\ttranslationGroup: string,\n\t\twrites: Array<{ field: BylineFieldDefinition; value: CustomFieldValue }>,\n\t\tnow: string,\n\t): Promise<boolean> {\n\t\tif (writes.length === 0) return false;\n\t\tlet touchedGroupShared = false;\n\t\tfor (const { field, value } of writes) {\n\t\t\tif (!field.translatable) touchedGroupShared = true;\n\t\t\tif (field.translatable) {\n\t\t\t\tif (value === null) {\n\t\t\t\t\tawait trx\n\t\t\t\t\t\t.deleteFrom(\"_emdash_byline_field_values\")\n\t\t\t\t\t\t.where(\"byline_id\", \"=\", bylineId)\n\t\t\t\t\t\t.where(\"field_id\", \"=\", field.id)\n\t\t\t\t\t\t.execute();\n\t\t\t\t} else {\n\t\t\t\t\tconst encoded = JSON.stringify(value);\n\t\t\t\t\tawait trx\n\t\t\t\t\t\t.insertInto(\"_emdash_byline_field_values\")\n\t\t\t\t\t\t.values({\n\t\t\t\t\t\t\tbyline_id: bylineId,\n\t\t\t\t\t\t\tfield_id: field.id,\n\t\t\t\t\t\t\tvalue: encoded,\n\t\t\t\t\t\t\tcreated_at: now,\n\t\t\t\t\t\t\tupdated_at: now,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.onConflict((oc) =>\n\t\t\t\t\t\t\toc.columns([\"byline_id\", \"field_id\"]).doUpdateSet({\n\t\t\t\t\t\t\t\tvalue: encoded,\n\t\t\t\t\t\t\t\tupdated_at: now,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.execute();\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (value === null) {\n\t\t\t\t\tawait trx\n\t\t\t\t\t\t.deleteFrom(\"_emdash_byline_field_group_values\")\n\t\t\t\t\t\t.where(\"translation_group\", \"=\", translationGroup)\n\t\t\t\t\t\t.where(\"field_id\", \"=\", field.id)\n\t\t\t\t\t\t.execute();\n\t\t\t\t} else {\n\t\t\t\t\tconst encoded = JSON.stringify(value);\n\t\t\t\t\tawait trx\n\t\t\t\t\t\t.insertInto(\"_emdash_byline_field_group_values\")\n\t\t\t\t\t\t.values({\n\t\t\t\t\t\t\ttranslation_group: translationGroup,\n\t\t\t\t\t\t\tfield_id: field.id,\n\t\t\t\t\t\t\tvalue: encoded,\n\t\t\t\t\t\t\tcreated_at: now,\n\t\t\t\t\t\t\tupdated_at: now,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.onConflict((oc) =>\n\t\t\t\t\t\t\toc.columns([\"translation_group\", \"field_id\"]).doUpdateSet({\n\t\t\t\t\t\t\t\tvalue: encoded,\n\t\t\t\t\t\t\t\tupdated_at: now,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.execute();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn touchedGroupShared;\n\t}\n\n\tasync create(input: CreateBylineInput): Promise<BylineSummary> {\n\t\tconst id = ulid();\n\t\tconst now = new Date().toISOString();\n\n\t\t// Validate customFields before opening the transaction so a bad\n\t\t// value surfaces as VALIDATION_ERROR without aborting an insert.\n\t\tconst customFieldWrites = await this.resolveCustomFieldWrites(input.customFields);\n\n\t\t// translationOf joins the source's group; otherwise mint a fresh\n\t\t// group = id (matches migration 040's backfill pattern).\n\t\tlet translationGroup: string = id;\n\t\tif (input.translationOf) {\n\t\t\tconst source = await this.findById(input.translationOf);\n\t\t\tif (!source) throw new Error(\"Source byline for translation not found\");\n\t\t\ttranslationGroup = source.translationGroup ?? source.id;\n\t\t}\n\n\t\t// Wrap insert + custom-field writes in one transaction so a\n\t\t// partial failure rolls both back on Node/PG. D1 still has its\n\t\t// own no-transactions limitation — recovery for that path lives\n\t\t// in `handleBylineCreate`.\n\t\tlet touchedGroupShared = false;\n\t\tawait withTransaction(this.db, async (trx) => {\n\t\t\tawait trx\n\t\t\t\t.insertInto(\"_emdash_bylines\")\n\t\t\t\t.values({\n\t\t\t\t\tid,\n\t\t\t\t\tslug: input.slug,\n\t\t\t\t\tdisplay_name: input.displayName,\n\t\t\t\t\tbio: input.bio ?? null,\n\t\t\t\t\tavatar_media_id: input.avatarMediaId ?? null,\n\t\t\t\t\twebsite_url: input.websiteUrl ?? null,\n\t\t\t\t\tuser_id: input.userId ?? null,\n\t\t\t\t\tis_guest: input.isGuest ? 1 : 0,\n\t\t\t\t\tcreated_at: now,\n\t\t\t\t\tupdated_at: now,\n\t\t\t\t\t// Omit `locale` so the DB DEFAULT (configured defaultLocale)\n\t\t\t\t\t// applies — matches TaxonomyRepository.create.\n\t\t\t\t\t...(input.locale !== undefined ? { locale: input.locale } : {}),\n\t\t\t\t\ttranslation_group: translationGroup,\n\t\t\t\t})\n\t\t\t\t.execute();\n\n\t\t\ttouchedGroupShared = await this.applyCustomFieldWritesInTrx(\n\t\t\t\ttrx,\n\t\t\t\tid,\n\t\t\t\ttranslationGroup,\n\t\t\t\tcustomFieldWrites,\n\t\t\t\tnow,\n\t\t\t);\n\t\t});\n\n\t\tif (touchedGroupShared) {\n\t\t\tclearRequestCacheEntry(`byline-field-group-values:${translationGroup}`);\n\t\t}\n\t\tinvalidateBylineObjectCache();\n\n\t\tconst byline = await this.findById(id);\n\t\tif (!byline) {\n\t\t\tthrow new Error(\"Failed to create byline\");\n\t\t}\n\t\treturn byline;\n\t}\n\n\tasync update(id: string, input: UpdateBylineInput): Promise<BylineSummary | null> {\n\t\tconst existing = await this.findById(id);\n\t\tif (!existing) return null;\n\n\t\t// Validate customFields before opening the transaction so a bad\n\t\t// value surfaces as VALIDATION_ERROR without aborting an update.\n\t\tconst customFieldWrites = await this.resolveCustomFieldWrites(input.customFields);\n\n\t\tconst now = new Date().toISOString();\n\t\tconst updates: Record<string, unknown> = { updated_at: now };\n\n\t\tif (input.slug !== undefined) updates.slug = input.slug;\n\t\tif (input.displayName !== undefined) updates.display_name = input.displayName;\n\t\tif (input.bio !== undefined) updates.bio = input.bio;\n\t\tif (input.avatarMediaId !== undefined) updates.avatar_media_id = input.avatarMediaId;\n\t\tif (input.websiteUrl !== undefined) updates.website_url = input.websiteUrl;\n\t\tif (input.userId !== undefined) updates.user_id = input.userId;\n\t\tif (input.isGuest !== undefined) updates.is_guest = input.isGuest ? 1 : 0;\n\n\t\tconst group = existing.translationGroup ?? existing.id;\n\t\t// Wrap row update + custom-field writes in one transaction so a\n\t\t// partial failure rolls both back on Node/PG. The post-commit\n\t\t// invalidation below clears the per-request cache that the\n\t\t// top-of-method `findById` populated for this group.\n\t\tlet touchedGroupShared = false;\n\t\tawait withTransaction(this.db, async (trx) => {\n\t\t\tawait trx.updateTable(\"_emdash_bylines\").set(updates).where(\"id\", \"=\", id).execute();\n\t\t\ttouchedGroupShared = await this.applyCustomFieldWritesInTrx(\n\t\t\t\ttrx,\n\t\t\t\tid,\n\t\t\t\tgroup,\n\t\t\t\tcustomFieldWrites,\n\t\t\t\tnow,\n\t\t\t);\n\t\t});\n\n\t\tif (touchedGroupShared) {\n\t\t\tclearRequestCacheEntry(`byline-field-group-values:${group}`);\n\t\t}\n\t\tinvalidateBylineObjectCache();\n\n\t\treturn await this.findById(id);\n\t}\n\n\t/**\n\t * Delete a byline row. When this row is the last sibling in its\n\t * translation group, also drops every junction row pointing at the group,\n\t * clears `primary_byline_id` references, and removes the byline's\n\t * non-translatable custom-field values. When other siblings remain in\n\t * the group, junctions, `primary_byline_id` pointers, and group-shared\n\t * custom-field values stay intact — the credit (and its shared metadata)\n\t * lives on at other locales.\n\t *\n\t * **Application-level cascade.** The byline domain has standardised on\n\t * app-level cascade rather than trusting FK ON DELETE CASCADE, partly\n\t * because migration 040 had to strip its own FK to support the\n\t * translation_group remap (#1021), and partly so cleanup doesn't\n\t * depend on `PRAGMA foreign_keys = ON` (set in production via\n\t * `connection.ts:60`, but easy to bypass in tests, scripts, and\n\t * one-off tools). Every byline-related deletion table is cleared\n\t * explicitly here:\n\t *\n\t * - `_emdash_byline_field_values` (per-byline translatable values) —\n\t * migration 041 declares FK ON DELETE CASCADE on `byline_id`; the\n\t * explicit DELETE removes the dependency on that pragma.\n\t * - `_emdash_content_bylines` — migration 040 dropped its FK.\n\t * - `ec_*.primary_byline_id` — never had an FK.\n\t * - `_emdash_byline_field_group_values` (translation-group-keyed) —\n\t * keyed by a text column with no FK to bylines, so app-level cleanup\n\t * is the only path.\n\t *\n\t * The FKs that remain (migration 041) serve as defense-in-depth.\n\t */\n\tasync delete(id: string): Promise<boolean> {\n\t\tconst existing = await this.findById(id);\n\t\tif (!existing) return false;\n\n\t\tconst group = existing.translationGroup ?? existing.id;\n\n\t\tawait withTransaction(this.db, async (trx) => {\n\t\t\t// Per-row translatable custom-field values. Done BEFORE the\n\t\t\t// byline row delete so the application-level cleanup is\n\t\t\t// observable in the transaction log even if FK enforcement is\n\t\t\t// off; migration 041's FK ON DELETE CASCADE would catch any\n\t\t\t// row we miss, but the explicit DELETE is what the rest of\n\t\t\t// the byline domain expects to see.\n\t\t\tawait trx.deleteFrom(\"_emdash_byline_field_values\").where(\"byline_id\", \"=\", id).execute();\n\n\t\t\tawait trx.deleteFrom(\"_emdash_bylines\").where(\"id\", \"=\", id).execute();\n\n\t\t\t// Count remaining siblings in the translation group. If none\n\t\t\t// remain, purge dependent rows; otherwise leave them intact so\n\t\t\t// the credit still resolves at other locales.\n\t\t\tconst remaining = await trx\n\t\t\t\t.selectFrom(\"_emdash_bylines\")\n\t\t\t\t.select(({ fn }) => [fn.count<number>(\"id\").as(\"count\")])\n\t\t\t\t.where(\"translation_group\", \"=\", group)\n\t\t\t\t.executeTakeFirst();\n\t\t\tconst remainingCount = Number(remaining?.count ?? 0);\n\t\t\tif (remainingCount > 0) return;\n\n\t\t\t// Last sibling gone: cascade in application code.\n\t\t\tawait trx.deleteFrom(\"_emdash_content_bylines\").where(\"byline_id\", \"=\", group).execute();\n\n\t\t\t// Group-shared custom-field values are keyed by translation_group\n\t\t\t// (no FK to bylines), so they don't cascade with the byline row.\n\t\t\t// Clean them up explicitly so deleting the last sibling of an\n\t\t\t// identity doesn't leave orphan group values pointing at a\n\t\t\t// vanished translation group. Per-row translatable values\n\t\t\t// (`_emdash_byline_field_values` keyed by byline_id) already\n\t\t\t// cascaded when each sibling row was deleted, so no extra\n\t\t\t// cleanup is needed for that table.\n\t\t\tawait trx\n\t\t\t\t.deleteFrom(\"_emdash_byline_field_group_values\")\n\t\t\t\t.where(\"translation_group\", \"=\", group)\n\t\t\t\t.execute();\n\n\t\t\tconst tableNames = await listTablesLike(trx, \"ec_%\");\n\t\t\tfor (const tableName of tableNames) {\n\t\t\t\tvalidateIdentifier(tableName, \"content table\");\n\t\t\t\tawait sql`\n\t\t\t\t\tUPDATE ${sql.ref(tableName)}\n\t\t\t\t\tSET primary_byline_id = NULL\n\t\t\t\t\tWHERE primary_byline_id = ${group}\n\t\t\t\t`.execute(trx);\n\t\t\t}\n\t\t});\n\n\t\tinvalidateBylineObjectCache();\n\t\treturn true;\n\t}\n\n\t/**\n\t * Strict per-locale credit hydration. Joins `_emdash_content_bylines` to\n\t * `_emdash_bylines` on `translation_group = byline_id`, then filters to\n\t * the requested locale. Credits whose translation group lacks a row at\n\t * the requested locale are omitted — callers wanting fallback behaviour\n\t * apply it themselves. Mirrors `TaxonomyRepository.getTermsForEntry`.\n\t */\n\tasync getContentBylines(\n\t\tcollectionSlug: string,\n\t\tcontentId: string,\n\t\toptions?: { locale?: string },\n\t): Promise<ContentBylineCredit[]> {\n\t\tlet query = this.db\n\t\t\t.selectFrom(\"_emdash_content_bylines as cb\")\n\t\t\t.innerJoin(\"_emdash_bylines as b\", \"b.translation_group\", \"cb.byline_id\")\n\t\t\t.leftJoin(\"media as m\", \"m.id\", \"b.avatar_media_id\")\n\t\t\t.select([\n\t\t\t\t\"cb.sort_order as sort_order\",\n\t\t\t\t\"cb.role_label as role_label\",\n\t\t\t\t\"b.id as id\",\n\t\t\t\t\"b.slug as slug\",\n\t\t\t\t\"b.display_name as display_name\",\n\t\t\t\t\"b.bio as bio\",\n\t\t\t\t\"b.avatar_media_id as avatar_media_id\",\n\t\t\t\t\"m.storage_key as avatar_storage_key\",\n\t\t\t\t\"m.alt as avatar_alt\",\n\t\t\t\t\"m.blurhash as avatar_blurhash\",\n\t\t\t\t\"m.dominant_color as avatar_dominant_color\",\n\t\t\t\t\"b.website_url as website_url\",\n\t\t\t\t\"b.user_id as user_id\",\n\t\t\t\t\"b.is_guest as is_guest\",\n\t\t\t\t\"b.created_at as created_at\",\n\t\t\t\t\"b.updated_at as updated_at\",\n\t\t\t\t\"b.locale as locale\",\n\t\t\t\t\"b.translation_group as translation_group\",\n\t\t\t])\n\t\t\t.where(\"cb.collection_slug\", \"=\", collectionSlug)\n\t\t\t.where(\"cb.content_id\", \"=\", contentId)\n\t\t\t.orderBy(\"cb.sort_order\", \"asc\");\n\t\tif (options?.locale !== undefined) query = query.where(\"b.locale\", \"=\", options.locale);\n\n\t\tconst rows = await query.execute();\n\t\t// Reconstruct byline rows to feed `withCustomFields`. The JOIN selects\n\t\t// the `BylineRow` columns under the `b.` alias plus the avatar media\n\t\t// columns from the `media` LEFT JOIN; carry both through so\n\t\t// `rowToByline` can populate `avatarStorageKey`/`avatarAlt` (otherwise\n\t\t// the join runs but its values are dropped here).\n\t\tconst bylineRows: BylineRowWithAvatar[] = rows.map((row) => ({\n\t\t\tid: row.id,\n\t\t\tslug: row.slug,\n\t\t\tdisplay_name: row.display_name,\n\t\t\tbio: row.bio,\n\t\t\tavatar_media_id: row.avatar_media_id,\n\t\t\tavatar_storage_key: row.avatar_storage_key,\n\t\t\tavatar_alt: row.avatar_alt,\n\t\t\tavatar_blurhash: row.avatar_blurhash,\n\t\t\tavatar_dominant_color: row.avatar_dominant_color,\n\t\t\twebsite_url: row.website_url,\n\t\t\tuser_id: row.user_id,\n\t\t\tis_guest: row.is_guest,\n\t\t\tcreated_at: row.created_at,\n\t\t\tupdated_at: row.updated_at,\n\t\t\tlocale: row.locale,\n\t\t\ttranslation_group: row.translation_group,\n\t\t}));\n\t\tconst hydrated = await this.withCustomFields(bylineRows);\n\t\treturn rows.map((row, i) => {\n\t\t\tconst byline = hydrated[i];\n\t\t\tif (!byline) {\n\t\t\t\t// Defensive: hydrated and rows are produced in lock-step;\n\t\t\t\t// this branch is unreachable unless `withCustomFields`\n\t\t\t\t// breaks its contract.\n\t\t\t\tthrow new Error(\"getContentBylines: hydration row count mismatch\");\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tbyline,\n\t\t\t\tsortOrder: row.sort_order,\n\t\t\t\troleLabel: row.role_label,\n\t\t\t};\n\t\t});\n\t}\n\n\t/**\n\t * Does this entry have any explicit byline credits — at any locale?\n\t *\n\t * Used to disambiguate \"no credits exist\" (fall back to author-linked\n\t * byline) from \"credits exist but don't resolve at the requested locale\"\n\t * (strict per-locale model: render no byline). Without this check the\n\t * locale-strict hydration would silently turn a missing translation into\n\t * an author-inferred byline, contradicting editorial intent.\n\t */\n\tasync hasContentBylines(collectionSlug: string, contentId: string): Promise<boolean> {\n\t\tconst row = await this.db\n\t\t\t.selectFrom(\"_emdash_content_bylines\")\n\t\t\t.select(\"id\")\n\t\t\t.where(\"collection_slug\", \"=\", collectionSlug)\n\t\t\t.where(\"content_id\", \"=\", contentId)\n\t\t\t.limit(1)\n\t\t\t.executeTakeFirst();\n\t\treturn row !== undefined;\n\t}\n\n\t/**\n\t * Batch variant of `hasContentBylines`. Returns the set of content IDs\n\t * that have at least one junction row (locale-agnostic).\n\t */\n\tasync hasContentBylinesMany(collectionSlug: string, contentIds: string[]): Promise<Set<string>> {\n\t\tconst result = new Set<string>();\n\t\tif (contentIds.length === 0) return result;\n\n\t\tconst uniqueContentIds = [...new Set(contentIds)];\n\t\tfor (const chunk of chunks(uniqueContentIds, SQL_BATCH_SIZE)) {\n\t\t\tconst rows = await this.db\n\t\t\t\t.selectFrom(\"_emdash_content_bylines\")\n\t\t\t\t.select(\"content_id\")\n\t\t\t\t.distinct()\n\t\t\t\t.where(\"collection_slug\", \"=\", collectionSlug)\n\t\t\t\t.where(\"content_id\", \"in\", chunk)\n\t\t\t\t.execute();\n\t\t\tfor (const row of rows) result.add(row.content_id);\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Batch variant of `getContentBylines`. Same strict-per-locale semantics\n\t * applied to the requested locale (single value, not per-entry).\n\t *\n\t * When callers need per-entry-locale filtering (e.g. a list endpoint\n\t * returning entries at mixed locales), they should group the input ids by\n\t * the entry's locale and call this method once per group.\n\t *\n\t * When the caller will issue multiple `getContentBylinesMany` calls in\n\t * one request (e.g. per locale bucket) and wants a *single* batched\n\t * customFields hydration over the union of returned bylines, pass\n\t * `skipHydration: true` on each call and finish with\n\t * `hydrateBylineCustomFields(allBylines)`. The returned bylines carry\n\t * `customFields = {}` until that hydration call runs — matching the\n\t * \"always populated\" invariant from AC #6 — so callers that forget to\n\t * hydrate get an empty map rather than `undefined`.\n\t */\n\tasync getContentBylinesMany(\n\t\tcollectionSlug: string,\n\t\tcontentIds: string[],\n\t\toptions?: { locale?: string; skipHydration?: boolean },\n\t): Promise<Map<string, ContentBylineCredit[]>> {\n\t\tconst result = new Map<string, ContentBylineCredit[]>();\n\t\tif (contentIds.length === 0) return result;\n\n\t\tconst uniqueContentIds = [...new Set(contentIds)];\n\t\tfor (const chunk of chunks(uniqueContentIds, SQL_BATCH_SIZE)) {\n\t\t\tlet query = this.db\n\t\t\t\t.selectFrom(\"_emdash_content_bylines as cb\")\n\t\t\t\t.innerJoin(\"_emdash_bylines as b\", \"b.translation_group\", \"cb.byline_id\")\n\t\t\t\t.leftJoin(\"media as m\", \"m.id\", \"b.avatar_media_id\")\n\t\t\t\t.select([\n\t\t\t\t\t\"cb.content_id as content_id\",\n\t\t\t\t\t\"cb.sort_order as sort_order\",\n\t\t\t\t\t\"cb.role_label as role_label\",\n\t\t\t\t\t\"b.id as id\",\n\t\t\t\t\t\"b.slug as slug\",\n\t\t\t\t\t\"b.display_name as display_name\",\n\t\t\t\t\t\"b.bio as bio\",\n\t\t\t\t\t\"b.avatar_media_id as avatar_media_id\",\n\t\t\t\t\t\"m.storage_key as avatar_storage_key\",\n\t\t\t\t\t\"m.alt as avatar_alt\",\n\t\t\t\t\t\"m.blurhash as avatar_blurhash\",\n\t\t\t\t\t\"m.dominant_color as avatar_dominant_color\",\n\t\t\t\t\t\"b.website_url as website_url\",\n\t\t\t\t\t\"b.user_id as user_id\",\n\t\t\t\t\t\"b.is_guest as is_guest\",\n\t\t\t\t\t\"b.created_at as created_at\",\n\t\t\t\t\t\"b.updated_at as updated_at\",\n\t\t\t\t\t\"b.locale as locale\",\n\t\t\t\t\t\"b.translation_group as translation_group\",\n\t\t\t\t])\n\t\t\t\t.where(\"cb.collection_slug\", \"=\", collectionSlug)\n\t\t\t\t.where(\"cb.content_id\", \"in\", chunk)\n\t\t\t\t.orderBy(\"cb.sort_order\", \"asc\");\n\t\t\tif (options?.locale !== undefined) query = query.where(\"b.locale\", \"=\", options.locale);\n\n\t\t\tconst rows = await query.execute();\n\t\t\t// Carry the avatar media columns from the LEFT JOIN through the\n\t\t\t// reshape so `rowToByline` can populate avatarStorageKey/avatarAlt.\n\t\t\tconst bylineRows: BylineRowWithAvatar[] = rows.map((row) => ({\n\t\t\t\tid: row.id,\n\t\t\t\tslug: row.slug,\n\t\t\t\tdisplay_name: row.display_name,\n\t\t\t\tbio: row.bio,\n\t\t\t\tavatar_media_id: row.avatar_media_id,\n\t\t\t\tavatar_storage_key: row.avatar_storage_key,\n\t\t\t\tavatar_alt: row.avatar_alt,\n\t\t\t\tavatar_blurhash: row.avatar_blurhash,\n\t\t\t\tavatar_dominant_color: row.avatar_dominant_color,\n\t\t\t\twebsite_url: row.website_url,\n\t\t\t\tuser_id: row.user_id,\n\t\t\t\tis_guest: row.is_guest,\n\t\t\t\tcreated_at: row.created_at,\n\t\t\t\tupdated_at: row.updated_at,\n\t\t\t\tlocale: row.locale,\n\t\t\t\ttranslation_group: row.translation_group,\n\t\t\t}));\n\n\t\t\t// When `skipHydration` is set, return BylineSummary objects with\n\t\t\t// `customFields = {}`. The caller is responsible for batching\n\t\t\t// `hydrateBylineCustomFields` across multiple\n\t\t\t// `getContentBylinesMany` calls. Otherwise hydrate per-call —\n\t\t\t// the historical behaviour for solo callers.\n\t\t\tlet bylines: BylineSummary[];\n\t\t\tif (options?.skipHydration === true) {\n\t\t\t\tbylines = bylineRows.map(rowToByline);\n\t\t\t\tfor (const b of bylines) b.customFields = {};\n\t\t\t} else {\n\t\t\t\tbylines = await this.withCustomFields(bylineRows);\n\t\t\t}\n\n\t\t\tfor (let i = 0; i < rows.length; i++) {\n\t\t\t\tconst row = rows[i];\n\t\t\t\tconst byline = bylines[i];\n\t\t\t\tif (!row || !byline) continue;\n\t\t\t\tconst contentId = row.content_id;\n\t\t\t\tconst credit: ContentBylineCredit = {\n\t\t\t\t\tbyline,\n\t\t\t\t\tsortOrder: row.sort_order,\n\t\t\t\t\troleLabel: row.role_label,\n\t\t\t\t};\n\t\t\t\tconst existing = result.get(contentId);\n\t\t\t\tif (existing) {\n\t\t\t\t\texisting.push(credit);\n\t\t\t\t} else {\n\t\t\t\t\tresult.set(contentId, [credit]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Batch-fetch byline profiles linked to user IDs in a single query.\n\t * Strict-locale variant of `findByUserId`.\n\t *\n\t * `skipHydration: true` returns bylines with `customFields = {}` so\n\t * callers issuing multiple `findByUserIds` calls in one request (e.g.\n\t * the per-locale-bucket author-fallback path in `getBylinesForEntries`)\n\t * can defer customFields hydration to a single batched\n\t * `hydrateBylineCustomFields` call across the union — keeping the\n\t * Phase 3 query-count envelope at \"+1 group-shared query per\n\t * hydration pass\" even when buckets fetch disjoint author bylines.\n\t */\n\tasync findByUserIds(\n\t\tuserIds: string[],\n\t\toptions?: { locale?: string; skipHydration?: boolean },\n\t): Promise<Map<string, BylineSummary>> {\n\t\tconst result = new Map<string, BylineSummary>();\n\t\tif (userIds.length === 0) return result;\n\n\t\tfor (const chunk of chunks(userIds, SQL_BATCH_SIZE)) {\n\t\t\t// LEFT JOIN media so author-inferred bylines (the fallback path in\n\t\t\t// `getBylinesForEntries`) carry the same render-ready avatar storage\n\t\t\t// key as explicitly-credited bylines do.\n\t\t\tlet query = this.db\n\t\t\t\t.selectFrom(\"_emdash_bylines as b\")\n\t\t\t\t.leftJoin(\"media as m\", \"m.id\", \"b.avatar_media_id\")\n\t\t\t\t.select([\n\t\t\t\t\t\"b.id as id\",\n\t\t\t\t\t\"b.slug as slug\",\n\t\t\t\t\t\"b.display_name as display_name\",\n\t\t\t\t\t\"b.bio as bio\",\n\t\t\t\t\t\"b.avatar_media_id as avatar_media_id\",\n\t\t\t\t\t\"m.storage_key as avatar_storage_key\",\n\t\t\t\t\t\"m.alt as avatar_alt\",\n\t\t\t\t\t\"m.blurhash as avatar_blurhash\",\n\t\t\t\t\t\"m.dominant_color as avatar_dominant_color\",\n\t\t\t\t\t\"b.website_url as website_url\",\n\t\t\t\t\t\"b.user_id as user_id\",\n\t\t\t\t\t\"b.is_guest as is_guest\",\n\t\t\t\t\t\"b.created_at as created_at\",\n\t\t\t\t\t\"b.updated_at as updated_at\",\n\t\t\t\t\t\"b.locale as locale\",\n\t\t\t\t\t\"b.translation_group as translation_group\",\n\t\t\t\t])\n\t\t\t\t.where(\"b.user_id\", \"in\", chunk);\n\t\t\tif (options?.locale !== undefined) query = query.where(\"b.locale\", \"=\", options.locale);\n\n\t\t\tconst rows = await query.execute();\n\t\t\tlet bylines: BylineSummary[];\n\t\t\tif (options?.skipHydration === true) {\n\t\t\t\tbylines = rows.map(rowToByline);\n\t\t\t\tfor (const b of bylines) b.customFields = {};\n\t\t\t} else {\n\t\t\t\tbylines = await this.withCustomFields(rows);\n\t\t\t}\n\n\t\t\tfor (let i = 0; i < rows.length; i++) {\n\t\t\t\tconst row = rows[i];\n\t\t\t\tconst summary = bylines[i];\n\t\t\t\tif (!row || !summary || !row.user_id) continue;\n\t\t\t\tresult.set(row.user_id, summary);\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Clone every junction row from `sourceContentId` to `targetContentId`,\n\t * preserving `sort_order` and `role_label`. Used by the content\n\t * translation flow: a newly created translation inherits the source's\n\t * byline credits at the storage level. Because the junction stores\n\t * `translation_group` (not a row id), the copy is locale-agnostic — the\n\t * credits resolve to whichever locale variants of each byline exist when\n\t * the translated entry is hydrated.\n\t *\n\t * No-op when the source has no credits. Skips when the target already\n\t * has credits (idempotent for re-runs).\n\t */\n\tasync copyContentBylines(\n\t\tcollection: string,\n\t\tsourceContentId: string,\n\t\ttargetContentId: string,\n\t): Promise<void> {\n\t\tvalidateIdentifier(collection, \"collection slug\");\n\t\tconst tableName = `ec_${collection}`;\n\t\tvalidateIdentifier(tableName, \"content table\");\n\n\t\t// Like `setContentBylines`, this method is expected to be called\n\t\t// within a transaction context (content handlers wrap in\n\t\t// withTransaction). All operations use `this.db` directly so an\n\t\t// outer transaction can serialise the copy alongside the create.\n\t\tconst existing = await this.db\n\t\t\t.selectFrom(\"_emdash_content_bylines\")\n\t\t\t.select(\"id\")\n\t\t\t.where(\"collection_slug\", \"=\", collection)\n\t\t\t.where(\"content_id\", \"=\", targetContentId)\n\t\t\t.executeTakeFirst();\n\t\tif (existing) return;\n\n\t\tconst sourceRows = await this.db\n\t\t\t.selectFrom(\"_emdash_content_bylines\")\n\t\t\t.select([\"byline_id\", \"sort_order\", \"role_label\"])\n\t\t\t.where(\"collection_slug\", \"=\", collection)\n\t\t\t.where(\"content_id\", \"=\", sourceContentId)\n\t\t\t.orderBy(\"sort_order\", \"asc\")\n\t\t\t.execute();\n\t\tif (sourceRows.length === 0) return;\n\n\t\tconst now = new Date().toISOString();\n\t\tawait this.db\n\t\t\t.insertInto(\"_emdash_content_bylines\")\n\t\t\t.values(\n\t\t\t\tsourceRows.map((row) => ({\n\t\t\t\t\tid: ulid(),\n\t\t\t\t\tcollection_slug: collection,\n\t\t\t\t\tcontent_id: targetContentId,\n\t\t\t\t\tbyline_id: row.byline_id,\n\t\t\t\t\tsort_order: row.sort_order,\n\t\t\t\t\trole_label: row.role_label,\n\t\t\t\t\tcreated_at: now,\n\t\t\t\t})),\n\t\t\t)\n\t\t\t.execute();\n\n\t\t// Mirror primary_byline_id from source so the cached pointer on the\n\t\t// target row matches the junction state we just wrote.\n\t\tconst firstByline = sourceRows[0]?.byline_id ?? null;\n\t\tawait sql`\n\t\t\tUPDATE ${sql.ref(tableName)}\n\t\t\tSET primary_byline_id = ${firstByline}\n\t\t\tWHERE id = ${targetContentId}\n\t\t`.execute(this.db);\n\n\t\t// Byline credits are folded into the target entry's cached payload.\n\t\tinvalidateCollectionCache(collection);\n\t}\n\n\t/**\n\t * Replace the set of byline credits on a content entry. Accepts row ids\n\t * at the wire (consistent with how the admin sends them), translates\n\t * each to its `translation_group` on write, and stores the group in\n\t * `_emdash_content_bylines.byline_id` and `ec_*.primary_byline_id`.\n\t *\n\t * The returned credits are hydrated with strict-locale matching at the\n\t * locale of the rows the caller supplied (i.e. the locale of the byline\n\t * each `bylineId` resolves to) — adequate for the autosave round-trip,\n\t * which then re-hydrates the entry against its own locale separately.\n\t */\n\tasync setContentBylines(\n\t\tcollectionSlug: string,\n\t\tcontentId: string,\n\t\tinputBylines: ContentBylineInput[],\n\t): Promise<ContentBylineCredit[]> {\n\t\tvalidateIdentifier(collectionSlug, \"collection slug\");\n\t\tconst tableName = `ec_${collectionSlug}`;\n\t\tvalidateIdentifier(tableName, \"content table\");\n\n\t\t// Resolve each wire row id to its translation_group up front so we\n\t\t// can (a) validate the rows exist and (b) dedupe by the value that\n\t\t// actually lands in the junction. Deduping by wire row id BEFORE\n\t\t// resolving would let two locale siblings of the same byline slip\n\t\t// through and trigger a UNIQUE(collection, content, byline_id)\n\t\t// failure at insert time. A single SELECT keeps this O(1) DB\n\t\t// calls regardless of how many credits are being set.\n\t\tconst idToGroup = new Map<string, string>();\n\t\tif (inputBylines.length > 0) {\n\t\t\tconst wireIds = [...new Set(inputBylines.map((item) => item.bylineId))];\n\t\t\tconst rows = await this.db\n\t\t\t\t.selectFrom(\"_emdash_bylines\")\n\t\t\t\t.select([\"id\", \"translation_group\"])\n\t\t\t\t.where(\"id\", \"in\", wireIds)\n\t\t\t\t.execute();\n\t\t\tif (rows.length !== wireIds.length) {\n\t\t\t\tthrow new Error(\"One or more byline IDs do not exist\");\n\t\t\t}\n\t\t\tfor (const row of rows) {\n\t\t\t\tidToGroup.set(row.id, row.translation_group ?? row.id);\n\t\t\t}\n\t\t}\n\n\t\t// Dedupe by translation_group. Preserves the order of first\n\t\t// occurrence so the editor's intent (which sibling appears first)\n\t\t// is honored. `roleLabel` follows the first occurrence too.\n\t\tconst seenGroups = new Set<string>();\n\t\tconst bylines: Array<ContentBylineInput & { group: string }> = [];\n\t\tfor (const item of inputBylines) {\n\t\t\tconst group = idToGroup.get(item.bylineId);\n\t\t\tif (!group) {\n\t\t\t\tthrow new Error(`Missing translation_group for byline ${item.bylineId}`);\n\t\t\t}\n\t\t\tif (seenGroups.has(group)) continue;\n\t\t\tseenGroups.add(group);\n\t\t\tbylines.push({ ...item, group });\n\t\t}\n\n\t\t// This method is expected to be called within a transaction context\n\t\t// (content handlers wrap in withTransaction, seed applies sequentially).\n\t\t// All operations use this.db directly -- callers are responsible for\n\t\t// wrapping in a transaction when atomicity is required.\n\t\tawait this.db\n\t\t\t.deleteFrom(\"_emdash_content_bylines\")\n\t\t\t.where(\"collection_slug\", \"=\", collectionSlug)\n\t\t\t.where(\"content_id\", \"=\", contentId)\n\t\t\t.execute();\n\n\t\tfor (let i = 0; i < bylines.length; i++) {\n\t\t\tconst item = bylines[i];\n\t\t\tif (!item) continue;\n\t\t\tawait this.db\n\t\t\t\t.insertInto(\"_emdash_content_bylines\")\n\t\t\t\t.values({\n\t\t\t\t\tid: ulid(),\n\t\t\t\t\tcollection_slug: collectionSlug,\n\t\t\t\t\tcontent_id: contentId,\n\t\t\t\t\tbyline_id: item.group,\n\t\t\t\t\tsort_order: i,\n\t\t\t\t\trole_label: item.roleLabel ?? null,\n\t\t\t\t\tcreated_at: new Date().toISOString(),\n\t\t\t\t})\n\t\t\t\t.execute();\n\t\t}\n\n\t\tconst primaryGroup = bylines[0]?.group ?? null;\n\t\tawait sql`\n\t\t\tUPDATE ${sql.ref(tableName)}\n\t\t\tSET primary_byline_id = ${primaryGroup}\n\t\t\tWHERE id = ${contentId}\n\t\t`.execute(this.db);\n\n\t\t// Byline credits are folded into this entry's cached payload.\n\t\tinvalidateCollectionCache(collectionSlug);\n\n\t\treturn await this.getContentBylines(collectionSlug, contentId);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;AA4GA,SAAS,YAAY,KAAyC;AAC7D,QAAO;EACN,IAAI,IAAI;EACR,MAAM,IAAI;EACV,aAAa,IAAI;EACjB,KAAK,IAAI;EACT,eAAe,IAAI;EACnB,kBAAkB,IAAI,sBAAsB;EAC5C,WAAW,IAAI,cAAc;EAC7B,gBAAgB,IAAI,mBAAmB;EACvC,qBAAqB,IAAI,yBAAyB;EAClD,YAAY,IAAI;EAChB,QAAQ,IAAI;EACZ,SAAS,IAAI,aAAa;EAC1B,WAAW,IAAI;EACf,WAAW,IAAI;EACf,QAAQ,IAAI;EACZ,kBAAkB,IAAI;EACtB;;;;;;;;;;;;;;;;;AAkBF,SAAS,uBACR,SACA,OACA,QACO;CACP,MAAM,SAAS,QAAQ,gBAAgB,EAAE;AACzC,KAAI,WAAW,KACd,QAAO,MAAM,QAAQ;KAErB,KAAI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GAChC,MAAM,QAAQ,UAAU,IAAI,KAAK,SAAS;AAC1C,OAAI,CAAC,MACJ,OAAM,IAAI,MAAM,wCAAwC,KAAK,WAAW;AAEzE,OAAI,WAAW,IAAI,MAAM,CAAE;AAC3B,cAAW,IAAI,MAAM;AACrB,WAAQ,KAAK;IAAE,GAAG;IAAM;IAAO,CAAC;;AAOjC,QAAM,KAAK,GACT,WAAW,0BAA0B,CACrC,MAAM,mBAAmB,KAAK,eAAe,CAC7C,MAAM,cAAc,KAAK,UAAU,CACnC,SAAS;AAEX,OAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;GACxC,MAAM,OAAO,QAAQ;AACrB,OAAI,CAAC,KAAM;AACX,SAAM,KAAK,GACT,WAAW,0BAA0B,CACrC,OAAO;IACP,IAAI,MAAM;IACV,iBAAiB;IACjB,YAAY;IACZ,WAAW,KAAK;IAChB,YAAY;IACZ,YAAY,KAAK,aAAa;IAC9B,6BAAY,IAAI,MAAM,EAAC,aAAa;IACpC,CAAC,CACD,SAAS;;EAGZ,MAAM,eAAe,QAAQ,IAAI,SAAS;AAC1C,QAAM,GAAG;YACC,IAAI,IAAI,UAAU,CAAC;6BACF,aAAa;gBAC1B,UAAU;IACtB,QAAQ,KAAK,GAAG;AAGlB,4BAA0B,eAAe;AAEzC,SAAO,MAAM,KAAK,kBAAkB,gBAAgB,UAAU"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"challenge-store-D5pSY2S1.mjs","names":[],"sources":["../src/auth/challenge-store.ts"],"sourcesContent":["/**\n * Challenge store for WebAuthn\n *\n * Stores WebAuthn challenges in a dedicated table with automatic expiration.\n */\n\nimport type { ChallengeStore, ChallengeData } from \"@emdash-cms/auth/passkey\";\nimport type { Kysely } from \"kysely\";\n\nimport type { Database } from \"../database/types.js\";\n\nexport function createChallengeStore(db: Kysely<Database>): ChallengeStore {\n\treturn {\n\t\tasync set(challenge: string, data: ChallengeData): Promise<void> {\n\t\t\tconst expiresAt = new Date(data.expiresAt).toISOString();\n\n\t\t\tawait db\n\t\t\t\t.insertInto(\"auth_challenges\")\n\t\t\t\t.values({\n\t\t\t\t\tchallenge,\n\t\t\t\t\ttype: data.type,\n\t\t\t\t\tuser_id: data.userId ?? null,\n\t\t\t\t\tdata: null, // Could store additional context if needed\n\t\t\t\t\texpires_at: expiresAt,\n\t\t\t\t})\n\t\t\t\t.onConflict((oc) =>\n\t\t\t\t\toc.column(\"challenge\").doUpdateSet({\n\t\t\t\t\t\ttype: data.type,\n\t\t\t\t\t\tuser_id: data.userId ?? null,\n\t\t\t\t\t\texpires_at: expiresAt,\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.execute();\n\t\t},\n\n\t\tasync get(challenge: string): Promise<ChallengeData | null> {\n\t\t\tconst row = await db\n\t\t\t\t.selectFrom(\"auth_challenges\")\n\t\t\t\t.selectAll()\n\t\t\t\t.where(\"challenge\", \"=\", challenge)\n\t\t\t\t.executeTakeFirst();\n\n\t\t\tif (!row) return null;\n\n\t\t\tconst expiresAt = new Date(row.expires_at).getTime();\n\n\t\t\t// Check expiration\n\t\t\tif (expiresAt < Date.now()) {\n\t\t\t\t// Expired, delete and return null\n\t\t\t\tawait this.delete(challenge);\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\ttype: row.type === \"registration\" ? \"registration\" : \"authentication\",\n\t\t\t\tuserId: row.user_id ?? undefined,\n\t\t\t\texpiresAt,\n\t\t\t};\n\t\t},\n\n\t\tasync delete(challenge: string): Promise<void> {\n\t\t\tawait db.deleteFrom(\"auth_challenges\").where(\"challenge\", \"=\", challenge).execute();\n\t\t},\n\t};\n}\n\n/**\n * Clean up expired challenges.\n * Should be called periodically (e.g., on startup, or via cron).\n */\nexport async function cleanupExpiredChallenges(db: Kysely<Database>): Promise<number> {\n\tconst now = new Date().toISOString();\n\n\tconst result = await db\n\t\t.deleteFrom(\"auth_challenges\")\n\t\t.where(\"expires_at\", \"<\", now)\n\t\t.executeTakeFirst();\n\n\treturn Number(result.numDeletedRows ?? 0);\n}\n"],"mappings":";AAWA,SAAgB,qBAAqB,IAAsC;AAC1E,QAAO;EACN,MAAM,IAAI,WAAmB,MAAoC;GAChE,MAAM,YAAY,IAAI,KAAK,KAAK,UAAU,CAAC,aAAa;AAExD,SAAM,GACJ,WAAW,kBAAkB,CAC7B,OAAO;IACP;IACA,MAAM,KAAK;IACX,SAAS,KAAK,UAAU;IACxB,MAAM;IACN,YAAY;IACZ,CAAC,CACD,YAAY,OACZ,GAAG,OAAO,YAAY,CAAC,YAAY;IAClC,MAAM,KAAK;IACX,SAAS,KAAK,UAAU;IACxB,YAAY;IACZ,CAAC,CACF,CACA,SAAS;;EAGZ,MAAM,IAAI,WAAkD;GAC3D,MAAM,MAAM,MAAM,GAChB,WAAW,kBAAkB,CAC7B,WAAW,CACX,MAAM,aAAa,KAAK,UAAU,CAClC,kBAAkB;AAEpB,OAAI,CAAC,IAAK,QAAO;GAEjB,MAAM,YAAY,IAAI,KAAK,IAAI,WAAW,CAAC,SAAS;AAGpD,OAAI,YAAY,KAAK,KAAK,EAAE;AAE3B,UAAM,KAAK,OAAO,UAAU;AAC5B,WAAO;;AAGR,UAAO;IACN,MAAM,IAAI,SAAS,iBAAiB,iBAAiB;IACrD,QAAQ,IAAI,WAAW;IACvB;IACA;;EAGF,MAAM,OAAO,WAAkC;AAC9C,SAAM,GAAG,WAAW,kBAAkB,CAAC,MAAM,aAAa,KAAK,UAAU,CAAC,SAAS;;EAEpF;;;;;;AAOF,eAAsB,yBAAyB,IAAuC;CACrF,MAAM,uBAAM,IAAI,MAAM,EAAC,aAAa;CAEpC,MAAM,SAAS,MAAM,GACnB,WAAW,kBAAkB,CAC7B,MAAM,cAAc,KAAK,IAAI,CAC7B,kBAAkB;AAEpB,QAAO,OAAO,OAAO,kBAAkB,EAAE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"content-CP-SeXNa.mjs","names":[],"sources":["../src/search/match.ts","../src/database/repositories/revision.ts","../src/database/repositories/content.ts"],"sourcesContent":["/**\n * FTS5 match-expression builder for structured (non-user-syntax) queries.\n *\n * Unlike `escapeQuery` in `query.ts` (which powers the public search API and\n * deliberately passes through FTS5 operators like AND/OR/NOT), this builder\n * treats the input as plain words: every term is double-quoted with interior\n * quotes escaped, so the result can never produce an FTS5 syntax error. Used\n * by the admin content-list filter, where the input is a filter box, not a\n * search-syntax field.\n */\n\nconst WHITESPACE_RE = /\\s+/;\nconst DOUBLE_QUOTE_RE = /\"/g;\nconst GLOB_SPECIAL_RE = /[[\\]*?]/g;\n\n/**\n * Build a prefix-matching FTS5 MATCH expression from free-form input.\n *\n * `hello wor` becomes `\"hello\"* \"wor\"*` — implicit AND with per-term prefix\n * matching. Returns `\"\"` when the input contains no usable terms; callers\n * must fall back to their non-FTS path in that case.\n */\nexport function buildFtsPrefixMatch(input: string): string {\n\tconst terms = input\n\t\t.trim()\n\t\t.split(WHITESPACE_RE)\n\t\t.map((term) => term.replace(DOUBLE_QUOTE_RE, '\"\"'))\n\t\t.filter((term) => term.length > 0);\n\n\tif (terms.length === 0) return \"\";\n\treturn terms.map((term) => `\"${term}\"*`).join(\" \");\n}\n\n/**\n * Build a GLOB prefix pattern from free-form input, treating GLOB\n * metacharacters (`* ? [ ]`) literally by wrapping each in a character\n * class (GLOB has no ESCAPE clause).\n *\n * GLOB (unlike default LIKE) is case-sensitive, so with a lowercased\n * pattern it matches slugs (lowercase by construction) while staying\n * servable by the ordinary BINARY-collated slug index — SQLite's GLOB\n * optimization turns a `prefix*` pattern into an index range scan.\n */\nexport function buildSlugGlobPrefix(input: string): string {\n\tconst escaped = input\n\t\t.trim()\n\t\t.toLowerCase()\n\t\t.replace(GLOB_SPECIAL_RE, (c) => `[${c}]`);\n\treturn `${escaped}*`;\n}\n","import { sql, type Kysely } from \"kysely\";\nimport { monotonicFactory } from \"ulidx\";\n\nimport type { Database, RevisionTable } from \"../types.js\";\nimport { validateIdentifier } from \"../validate.js\";\n\nconst monotonic = monotonicFactory();\n\nexport interface Revision {\n\tid: string;\n\tcollection: string;\n\tentryId: string;\n\tdata: Record<string, unknown>;\n\tauthorId: string | null;\n\tcreatedAt: string;\n}\n\nexport interface CreateRevisionInput {\n\tcollection: string;\n\tentryId: string;\n\tdata: Record<string, unknown>;\n\tauthorId?: string;\n}\n\n/**\n * Revision repository for version history\n *\n * Each revision stores a JSON snapshot of the content at a point in time.\n * Used when collection has `supports: [\"revisions\"]` enabled.\n */\nexport class RevisionRepository {\n\tconstructor(private db: Kysely<Database>) {}\n\n\t/**\n\t * Create a new revision\n\t */\n\tasync create(input: CreateRevisionInput): Promise<Revision> {\n\t\tconst id = monotonic();\n\n\t\tconst row: Omit<RevisionTable, \"created_at\"> = {\n\t\t\tid,\n\t\t\tcollection: input.collection,\n\t\t\tentry_id: input.entryId,\n\t\t\tdata: JSON.stringify(input.data),\n\t\t\tauthor_id: input.authorId ?? null,\n\t\t};\n\n\t\tawait this.db.insertInto(\"revisions\").values(row).execute();\n\n\t\tconst revision = await this.findById(id);\n\t\tif (!revision) {\n\t\t\tthrow new Error(\"Failed to create revision\");\n\t\t}\n\n\t\ttry {\n\t\t\tawait this.db\n\t\t\t\t.insertInto(\"_emdash_revision_prune_queue\")\n\t\t\t\t.values({\n\t\t\t\t\tcollection: input.collection,\n\t\t\t\t\tentry_id: input.entryId,\n\t\t\t\t\trevision_id: id,\n\t\t\t\t})\n\t\t\t\t.onConflict((conflict) =>\n\t\t\t\t\tconflict.columns([\"collection\", \"entry_id\"]).doUpdateSet({ revision_id: id }),\n\t\t\t\t)\n\t\t\t\t.execute();\n\t\t} catch (error) {\n\t\t\tconsole.error(\n\t\t\t\t`[revisions] Failed to queue revision pruning for ${input.collection}/${input.entryId}:`,\n\t\t\t\terror,\n\t\t\t);\n\t\t}\n\n\t\treturn revision;\n\t}\n\n\t/**\n\t * Find revision by ID\n\t */\n\tasync findById(id: string): Promise<Revision | null> {\n\t\tconst row = await this.db\n\t\t\t.selectFrom(\"revisions\")\n\t\t\t.selectAll()\n\t\t\t.where(\"id\", \"=\", id)\n\t\t\t.executeTakeFirst();\n\n\t\treturn row ? this.rowToRevision(row) : null;\n\t}\n\n\t/**\n\t * Get all revisions for an entry (newest first)\n\t *\n\t * Orders by monotonic ULID (descending). The monotonic factory\n\t * guarantees strictly increasing IDs even within the same millisecond.\n\t */\n\tasync findByEntry(\n\t\tcollection: string,\n\t\tentryId: string,\n\t\toptions: { limit?: number } = {},\n\t): Promise<Revision[]> {\n\t\tlet query = this.db\n\t\t\t.selectFrom(\"revisions\")\n\t\t\t.selectAll()\n\t\t\t.where(\"collection\", \"=\", collection)\n\t\t\t.where(\"entry_id\", \"=\", entryId)\n\t\t\t.orderBy(\"id\", \"desc\");\n\n\t\tif (options.limit) {\n\t\t\tquery = query.limit(options.limit);\n\t\t}\n\n\t\tconst rows = await query.execute();\n\t\treturn rows.map((row) => this.rowToRevision(row));\n\t}\n\n\t/**\n\t * Get the most recent revision for an entry\n\t */\n\tasync findLatest(collection: string, entryId: string): Promise<Revision | null> {\n\t\tconst row = await this.db\n\t\t\t.selectFrom(\"revisions\")\n\t\t\t.selectAll()\n\t\t\t.where(\"collection\", \"=\", collection)\n\t\t\t.where(\"entry_id\", \"=\", entryId)\n\t\t\t.orderBy(\"id\", \"desc\")\n\t\t\t.limit(1)\n\t\t\t.executeTakeFirst();\n\n\t\treturn row ? this.rowToRevision(row) : null;\n\t}\n\n\t/**\n\t * Count revisions for an entry\n\t */\n\tasync countByEntry(collection: string, entryId: string): Promise<number> {\n\t\tconst result = await this.db\n\t\t\t.selectFrom(\"revisions\")\n\t\t\t.select((eb) => eb.fn.count(\"id\").as(\"count\"))\n\t\t\t.where(\"collection\", \"=\", collection)\n\t\t\t.where(\"entry_id\", \"=\", entryId)\n\t\t\t.executeTakeFirst();\n\n\t\treturn Number(result?.count || 0);\n\t}\n\n\t/**\n\t * Delete all revisions for an entry (use when entry is deleted)\n\t */\n\tasync deleteByEntry(collection: string, entryId: string): Promise<number> {\n\t\tconst result = await this.db\n\t\t\t.deleteFrom(\"revisions\")\n\t\t\t.where(\"collection\", \"=\", collection)\n\t\t\t.where(\"entry_id\", \"=\", entryId)\n\t\t\t.executeTakeFirst();\n\n\t\ttry {\n\t\t\tawait this.db\n\t\t\t\t.deleteFrom(\"_emdash_revision_prune_queue\")\n\t\t\t\t.where(\"collection\", \"=\", collection)\n\t\t\t\t.where(\"entry_id\", \"=\", entryId)\n\t\t\t\t.execute();\n\t\t} catch (error) {\n\t\t\tconsole.error(\n\t\t\t\t`[revisions] Failed to clear queued revision pruning for ${collection}/${entryId}:`,\n\t\t\t\terror,\n\t\t\t);\n\t\t}\n\n\t\treturn Number(result.numDeletedRows ?? 0);\n\t}\n\n\t/**\n\t * Delete old revisions, keeping the most recent N\n\t */\n\tasync pruneOldRevisions(\n\t\tcollection: string,\n\t\tentryId: string,\n\t\tkeepCount: number,\n\t\tthroughRevisionId?: string,\n\t): Promise<number> {\n\t\tvalidateIdentifier(collection, \"collection\");\n\t\tconst tableName = `ec_${collection}`;\n\t\tlet keepQuery = this.db\n\t\t\t.selectFrom(\"revisions\")\n\t\t\t.select(\"id\")\n\t\t\t.where(\"collection\", \"=\", collection)\n\t\t\t.where(\"entry_id\", \"=\", entryId)\n\t\t\t.orderBy(\"created_at\", \"desc\")\n\t\t\t.orderBy(\"id\", \"desc\") // ULID tiebreaker\n\t\t\t.limit(keepCount);\n\n\t\tif (throughRevisionId) {\n\t\t\tkeepQuery = keepQuery.where(\"id\", \"<=\", throughRevisionId);\n\t\t}\n\n\t\tconst keep = await keepQuery.execute();\n\n\t\tconst keepIds = keep.map((r) => r.id);\n\n\t\tif (keepIds.length === 0) return 0;\n\t\tconst revisionBoundary = throughRevisionId ? sql`AND id <= ${throughRevisionId}` : sql``;\n\n\t\tconst result = await sql`\n\t\t\tDELETE FROM revisions\n\t\t\tWHERE collection = ${collection}\n\t\t\tAND entry_id = ${entryId}\n\t\t\t${revisionBoundary}\n\t\t\tAND id NOT IN (${sql.join(keepIds.map((id) => sql`${id}`))})\n\t\t\tAND NOT EXISTS (\n\t\t\t\tSELECT 1 FROM ${sql.ref(tableName)} AS content\n\t\t\t\tWHERE content.live_revision_id = revisions.id\n\t\t\t\tOR content.draft_revision_id = revisions.id\n\t\t\t)\n\t\t`.execute(this.db);\n\n\t\treturn Number(result.numAffectedRows ?? 0);\n\t}\n\n\tasync pruneQueuedEntry(\n\t\tcollection: string,\n\t\tentryId: string,\n\t\tqueuedRevisionId: string,\n\t\tkeepCount: number,\n\t): Promise<number> {\n\t\tconst pruned = await this.pruneOldRevisions(collection, entryId, keepCount, queuedRevisionId);\n\t\tawait this.db\n\t\t\t.deleteFrom(\"_emdash_revision_prune_queue\")\n\t\t\t.where(\"collection\", \"=\", collection)\n\t\t\t.where(\"entry_id\", \"=\", entryId)\n\t\t\t.where(\"revision_id\", \"=\", queuedRevisionId)\n\t\t\t.execute();\n\t\treturn pruned;\n\t}\n\n\tasync deleteIfUnreferenced(\n\t\tcollection: string,\n\t\tentryId: string,\n\t\trevisionId: string,\n\t): Promise<boolean> {\n\t\tvalidateIdentifier(collection, \"collection\");\n\t\tconst tableName = `ec_${collection}`;\n\t\tconst result = await sql`\n\t\t\tDELETE FROM revisions\n\t\t\tWHERE id = ${revisionId}\n\t\t\tAND collection = ${collection}\n\t\t\tAND entry_id = ${entryId}\n\t\t\tAND NOT EXISTS (\n\t\t\t\tSELECT 1 FROM ${sql.ref(tableName)} AS content\n\t\t\t\tWHERE content.live_revision_id = revisions.id\n\t\t\t\tOR content.draft_revision_id = revisions.id\n\t\t\t)\n\t\t`.execute(this.db);\n\t\treturn (result.numAffectedRows ?? 0n) > 0n;\n\t}\n\n\t/**\n\t * Convert database row to Revision object\n\t */\n\tprivate rowToRevision(row: {\n\t\tid: string;\n\t\tcollection: string;\n\t\tentry_id: string;\n\t\tdata: string;\n\t\tauthor_id: string | null;\n\t\tcreated_at: string;\n\t}): Revision {\n\t\treturn {\n\t\t\tid: row.id,\n\t\t\tcollection: row.collection,\n\t\t\tentryId: row.entry_id,\n\t\t\tdata: JSON.parse(row.data),\n\t\t\tauthorId: row.author_id,\n\t\t\tcreatedAt: row.created_at,\n\t\t};\n\t}\n}\n","import { sql, type Kysely } from \"kysely\";\nimport { ulid } from \"ulidx\";\n\nimport type { ContentFieldFilterValue, ContentFieldFilters } from \"../../content-list-query.js\";\nimport { invalidateCollectionCache } from \"../../object-cache/index.js\";\nimport { isIndexableFieldType, type FieldType } from \"../../schema/types.js\";\nimport { buildFtsPrefixMatch, buildSlugGlobPrefix } from \"../../search/match.js\";\nimport { chunks, SQL_BATCH_SIZE } from \"../../utils/chunks.js\";\nimport { isMissingTableError } from \"../../utils/db-errors.js\";\nimport { slugify } from \"../../utils/slugify.js\";\nimport type { Database } from \"../types.js\";\nimport { validateIdentifier } from \"../validate.js\";\nimport { RevisionRepository } from \"./revision.js\";\nimport type {\n\tCreateContentInput,\n\tUpdateContentInput,\n\tFindManyOptions,\n\tFindManyResult,\n\tContentItem,\n\tContentDateField,\n\tContentBylineFilter,\n} from \"./types.js\";\nimport {\n\tContentCollectionNotFoundError,\n\tContentMutationConflictError,\n\tEmDashValidationError,\n\tInvalidCursorError,\n\tScheduledNotDueError,\n\tencodeCursor,\n\tdecodeCursor,\n} from \"./types.js\";\n\n// Regex pattern for ULID validation\nconst ULID_PATTERN = /^[0-9A-Z]{26}$/;\nconst SQLSTATE_PATTERN = /^[0-9A-Z]{5}$/;\nconst MAX_DRAFT_STAGE_ATTEMPTS = 32;\n\n// LIKE wildcards that must be escaped so user search input is matched literally.\nconst LIKE_WILDCARD_RE = /[\\\\%_]/g;\nconst MAX_INDEXED_FIELD_FILTERS = 20;\nconst MAX_IN_FILTER_VALUES = SQL_BATCH_SIZE;\nconst MAX_FILTER_STRING_LENGTH = 2048;\n\ntype NormalizedFilterScalar = string | number;\n\ntype ResolvedFieldFilter =\n\t| { column: string; kind: \"null\" }\n\t| { column: string; kind: \"exact\"; value: NormalizedFilterScalar }\n\t| { column: string; kind: \"in\"; values: NormalizedFilterScalar[] }\n\t| {\n\t\t\tcolumn: string;\n\t\t\tkind: \"range\";\n\t\t\tbounds: Partial<Record<\"gt\" | \"gte\" | \"lt\" | \"lte\", NormalizedFilterScalar>>;\n\t };\n\nfunction nullableColumnMatch(column: string, value: string | null): ReturnType<typeof sql> {\n\tvalidateIdentifier(column, \"content column\");\n\treturn value === null ? sql`${sql.ref(column)} IS NULL` : sql`${sql.ref(column)} = ${value}`;\n}\n\nfunction sameStoredValue(left: unknown, right: unknown): boolean {\n\treturn Object.is(serializeValue(left), serializeValue(right));\n}\n\nfunction matchesPublication(\n\tobserved: ContentItem,\n\texisting: ContentItem,\n\trevision: { data: Record<string, unknown> },\n\trevisionId: string,\n\tslug: string | null,\n\tpublishedAt: string,\n\tupdatedAt: string,\n): boolean {\n\tif (\n\t\tobserved.version !== existing.version + 1 ||\n\t\tobserved.status !== \"published\" ||\n\t\tobserved.slug !== slug ||\n\t\tobserved.liveRevisionId !== revisionId ||\n\t\tobserved.draftRevisionId !== null ||\n\t\tobserved.scheduledAt !== null ||\n\t\tobserved.publishedAt !== publishedAt ||\n\t\tobserved.updatedAt !== updatedAt\n\t) {\n\t\treturn false;\n\t}\n\n\treturn Object.entries(revision.data).every(\n\t\t([key, value]) =>\n\t\t\tSYSTEM_COLUMNS.has(key) || key.startsWith(\"_\") || sameStoredValue(observed.data[key], value),\n\t);\n}\n\nfunction matchesLifecyclePublication(\n\tobserved: ContentItem,\n\texisting: ContentItem,\n\tliveRevisionId: string,\n\tpublishedAt: string,\n\tupdatedAt: string,\n): boolean {\n\tif (\n\t\tobserved.version !== existing.version + 1 ||\n\t\tobserved.status !== \"published\" ||\n\t\tobserved.slug !== existing.slug ||\n\t\tobserved.liveRevisionId !== liveRevisionId ||\n\t\tobserved.draftRevisionId !== null ||\n\t\tobserved.scheduledAt !== null ||\n\t\tobserved.publishedAt !== publishedAt ||\n\t\tobserved.updatedAt !== updatedAt\n\t) {\n\t\treturn false;\n\t}\n\n\treturn Object.entries(existing.data).every(([key, value]) =>\n\t\tsameStoredValue(observed.data[key], value),\n\t);\n}\n\nfunction matchesPublicationFence(observed: ContentItem, existing: ContentItem): boolean {\n\treturn (\n\t\tobserved.version === existing.version &&\n\t\tobserved.status === existing.status &&\n\t\tobserved.liveRevisionId === existing.liveRevisionId &&\n\t\tobserved.draftRevisionId === existing.draftRevisionId &&\n\t\tobserved.scheduledAt === existing.scheduledAt\n\t);\n}\n\nexport function isConfirmedStatementFailure(error: unknown): boolean {\n\tif (typeof error !== \"object\" || error === null || !(\"code\" in error)) return false;\n\tconst code = (error as { code?: unknown }).code;\n\treturn (\n\t\ttypeof code === \"string\" &&\n\t\t(code === \"ERR_SQLITE_ERROR\" || code.startsWith(\"SQLITE_\") || SQLSTATE_PATTERN.test(code))\n\t);\n}\n\ninterface ResolvedOrderField {\n\tcolumn: string;\n\tindexedCustomField: boolean;\n}\n\ntype IndexedOrderValue = string | number | null;\n\ninterface IndexedFieldCursorPayload {\n\tversion: 1;\n\tfield: string;\n\tvalue: IndexedOrderValue;\n}\n\nfunction encodeIndexedFieldCursor(field: string, value: IndexedOrderValue, id: string): string {\n\tconst payload: IndexedFieldCursorPayload = { version: 1, field, value };\n\treturn encodeCursor(JSON.stringify(payload), id);\n}\n\nfunction decodeIndexedFieldCursor(\n\tcursor: string,\n\tfield: string,\n): { value: IndexedOrderValue; id: string } {\n\tconst { orderValue, id } = decodeCursor(cursor);\n\tlet payload: unknown;\n\ttry {\n\t\tpayload = JSON.parse(orderValue);\n\t} catch {\n\t\tthrow new InvalidCursorError(cursor);\n\t}\n\n\tif (payload === null || typeof payload !== \"object\") {\n\t\tthrow new InvalidCursorError(cursor);\n\t}\n\tconst candidate = payload as Partial<IndexedFieldCursorPayload>;\n\tconst validValue =\n\t\tcandidate.value === null ||\n\t\ttypeof candidate.value === \"string\" ||\n\t\ttypeof candidate.value === \"number\";\n\tif (candidate.version !== 1 || candidate.field !== field || !validValue) {\n\t\tthrow new InvalidCursorError(cursor);\n\t}\n\n\treturn { value: candidate.value as IndexedOrderValue, id };\n}\n\n/**\n * Whitelist mapping a public date-filter field to its physical column. Keeping\n * this separate from `mapOrderField` makes the filterable set explicit and\n * prevents filtering on arbitrary columns.\n */\nconst DATE_FILTER_COLUMNS: Record<ContentDateField, \"created_at\" | \"updated_at\" | \"published_at\"> =\n\t{\n\t\tcreatedAt: \"created_at\",\n\t\tupdatedAt: \"updated_at\",\n\t\tpublishedAt: \"published_at\",\n\t};\n\n/**\n * Built-in sort fields → their physical columns. A closed set that blocks\n * sorting by arbitrary columns; per-collection fields are allowed\n * separately via `mapOrderField`'s `sortableExtras`.\n */\nconst ORDER_FIELD_COLUMNS: Record<string, string> = {\n\tcreatedAt: \"created_at\",\n\tupdatedAt: \"updated_at\",\n\tpublishedAt: \"published_at\",\n\tscheduledAt: \"scheduled_at\",\n\tdeletedAt: \"deleted_at\",\n\ttitle: \"title\",\n\tname: \"name\",\n\tslug: \"slug\",\n\tstatus: \"status\",\n\tlocale: \"locale\",\n};\n\n/** True when `field` maps to a system column and needs no per-collection resolution. */\nexport function isSystemOrderField(field: string): boolean {\n\treturn field in ORDER_FIELD_COLUMNS;\n}\n\n/**\n * System columns that exist in every ec_* table\n */\nconst SYSTEM_COLUMNS = new Set([\n\t\"id\",\n\t\"slug\",\n\t\"status\",\n\t\"author_id\",\n\t\"primary_byline_id\",\n\t\"created_at\",\n\t\"updated_at\",\n\t\"published_at\",\n\t\"scheduled_at\",\n\t\"deleted_at\",\n\t\"version\",\n\t\"live_revision_id\",\n\t\"draft_revision_id\",\n\t\"locale\",\n\t\"translation_group\",\n]);\n\n/**\n * Get the table name for a collection type\n */\nfunction getTableName(type: string): string {\n\tvalidateIdentifier(type, \"collection type\");\n\treturn `ec_${type}`;\n}\n\n/**\n * Serialize a value for database storage\n * Objects/arrays are JSON-stringified\n * Booleans are converted to 0/1 for SQLite\n */\nfunction serializeValue(value: unknown): unknown {\n\tif (value === null || value === undefined) {\n\t\treturn null;\n\t}\n\tif (typeof value === \"boolean\") {\n\t\treturn value ? 1 : 0;\n\t}\n\tif (typeof value === \"object\") {\n\t\treturn JSON.stringify(value);\n\t}\n\treturn value;\n}\n\nfunction writableContentData(data: Record<string, unknown>): Record<string, unknown> {\n\tconst writable: Record<string, unknown> = {};\n\tfor (const [key, value] of Object.entries(data)) {\n\t\tif (SYSTEM_COLUMNS.has(key)) continue;\n\t\tvalidateIdentifier(key, \"content field name\");\n\t\twritable[key] = value;\n\t}\n\treturn writable;\n}\n\n/**\n * Deserialize a value from database storage\n * Attempts to parse JSON strings that look like objects/arrays\n */\nfunction deserializeValue(value: unknown): unknown {\n\tif (typeof value === \"string\") {\n\t\t// Try to parse if it looks like JSON\n\t\tif (value.startsWith(\"{\") || value.startsWith(\"[\")) {\n\t\t\ttry {\n\t\t\t\treturn JSON.parse(value);\n\t\t\t} catch {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t}\n\t}\n\treturn value;\n}\n\n/** Pattern for escaping special regex characters */\nconst REGEX_ESCAPE_PATTERN = /[.*+?^${}()|[\\]\\\\]/g;\n\n/**\n * Escape special regex characters in a string for use in `new RegExp()`\n */\nfunction escapeRegExp(s: string): string {\n\treturn s.replace(REGEX_ESCAPE_PATTERN, \"\\\\$&\");\n}\n\n/**\n * Repository for content CRUD operations\n *\n * Content is stored in per-collection tables (ec_posts, ec_pages, etc.)\n * Each field becomes a real column in the table.\n */\nexport class ContentRepository {\n\tconstructor(private db: Kysely<Database>) {}\n\n\t/**\n\t * Create a new content item\n\t */\n\tasync create(input: CreateContentInput): Promise<ContentItem> {\n\t\tconst id = input.id ?? ulid();\n\t\tconst now = new Date().toISOString();\n\n\t\tconst {\n\t\t\ttype,\n\t\t\tslug,\n\t\t\tdata,\n\t\t\tstatus = \"draft\",\n\t\t\tauthorId,\n\t\t\tprimaryBylineId,\n\t\t\tlocale,\n\t\t\ttranslationOf,\n\t\t\tpublishedAt,\n\t\t\tcreatedAt,\n\t\t} = input;\n\n\t\t// Validate required fields\n\t\tif (!type) {\n\t\t\tthrow new EmDashValidationError(\"Content type is required\");\n\t\t}\n\n\t\tconst tableName = getTableName(type);\n\n\t\t// Resolve translation_group: if translationOf is set, look up the source item's group\n\t\tlet translationGroup: string = id; // default: self-reference\n\t\tif (translationOf) {\n\t\t\tconst source = await this.findById(type, translationOf);\n\t\t\tif (!source) {\n\t\t\t\tthrow new EmDashValidationError(\"Translation source content not found\");\n\t\t\t}\n\t\t\ttranslationGroup = source.translationGroup || source.id;\n\t\t}\n\n\t\t// Build column names and values\n\t\tconst columns: string[] = [\n\t\t\t\"id\",\n\t\t\t\"slug\",\n\t\t\t\"status\",\n\t\t\t\"author_id\",\n\t\t\t\"primary_byline_id\",\n\t\t\t\"created_at\",\n\t\t\t\"updated_at\",\n\t\t\t\"published_at\",\n\t\t\t\"version\",\n\t\t\t\"locale\",\n\t\t\t\"translation_group\",\n\t\t];\n\t\tconst values: unknown[] = [\n\t\t\tid,\n\t\t\tslug || null,\n\t\t\tstatus,\n\t\t\tauthorId || null,\n\t\t\tprimaryBylineId ?? null,\n\t\t\tcreatedAt || now,\n\t\t\tnow,\n\t\t\tpublishedAt || null,\n\t\t\t1,\n\t\t\tlocale || \"en\",\n\t\t\ttranslationGroup,\n\t\t];\n\n\t\t// Add data fields as columns (skip system columns to prevent injection via data)\n\t\tif (data && typeof data === \"object\") {\n\t\t\tfor (const [key, value] of Object.entries(data)) {\n\t\t\t\tif (!SYSTEM_COLUMNS.has(key)) {\n\t\t\t\t\tvalidateIdentifier(key, \"content field name\");\n\t\t\t\t\tcolumns.push(key);\n\t\t\t\t\tvalues.push(serializeValue(value));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Build dynamic INSERT using raw SQL\n\t\tconst columnRefs = columns.map((c) => sql.ref(c));\n\t\tconst valuePlaceholders = values.map((v) => (v === null ? sql`NULL` : sql`${v}`));\n\n\t\tawait sql`\n\t\t\tINSERT INTO ${sql.ref(tableName)} (${sql.join(columnRefs, sql`, `)})\n\t\t\tVALUES (${sql.join(valuePlaceholders, sql`, `)})\n\t\t`.execute(this.db);\n\n\t\tinvalidateCollectionCache(type);\n\n\t\t// Fetch and return the created item\n\t\tconst item = await this.findById(type, id);\n\t\tif (!item) {\n\t\t\tthrow new Error(\"Failed to create content\");\n\t\t}\n\t\treturn item;\n\t}\n\n\t/**\n\t * Generate a unique slug for a content item within a collection.\n\t *\n\t * Checks the collection table for existing slugs that match `baseSlug`\n\t * (optionally scoped to a locale) and appends a numeric suffix (`-1`,\n\t * `-2`, etc.) on collision to guarantee uniqueness.\n\t *\n\t * Returns null when slug normalization cannot produce a value.\n\t */\n\tasync generateUniqueSlug(type: string, text: string, locale?: string): Promise<string | null> {\n\t\tconst baseSlug = slugify(text);\n\t\tif (!baseSlug) return null;\n\n\t\tconst tableName = getTableName(type);\n\n\t\t// Check if the base slug is available\n\t\tconst existing = locale\n\t\t\t? await sql<{ slug: string }>`\n\t\t\t\t\tSELECT slug FROM ${sql.ref(tableName)}\n\t\t\t\t\tWHERE slug = ${baseSlug}\n\t\t\t\t\tAND locale = ${locale}\n\t\t\t\t\tLIMIT 1\n\t\t\t\t`.execute(this.db)\n\t\t\t: await sql<{ slug: string }>`\n\t\t\t\t\tSELECT slug FROM ${sql.ref(tableName)}\n\t\t\t\t\tWHERE slug = ${baseSlug}\n\t\t\t\t\tLIMIT 1\n\t\t\t\t`.execute(this.db);\n\n\t\tif (existing.rows.length === 0) {\n\t\t\treturn baseSlug;\n\t\t}\n\n\t\t// Find all slugs matching the pattern `baseSlug` or `baseSlug-N`\n\t\tconst pattern = `${baseSlug}-%`;\n\t\tconst candidates = locale\n\t\t\t? await sql<{ slug: string }>`\n\t\t\t\t\tSELECT slug FROM ${sql.ref(tableName)}\n\t\t\t\t\tWHERE (slug = ${baseSlug} OR slug LIKE ${pattern})\n\t\t\t\t\tAND locale = ${locale}\n\t\t\t\t`.execute(this.db)\n\t\t\t: await sql<{ slug: string }>`\n\t\t\t\t\tSELECT slug FROM ${sql.ref(tableName)}\n\t\t\t\t\tWHERE slug = ${baseSlug} OR slug LIKE ${pattern}\n\t\t\t\t`.execute(this.db);\n\n\t\t// Find the highest numeric suffix in use\n\t\tlet maxSuffix = 0;\n\t\tconst suffixPattern = new RegExp(`^${escapeRegExp(baseSlug)}-(\\\\d+)$`);\n\t\tfor (const row of candidates.rows) {\n\t\t\tconst match = suffixPattern.exec(row.slug);\n\t\t\tif (match) {\n\t\t\t\tconst n = parseInt(match[1], 10);\n\t\t\t\tif (n > maxSuffix) maxSuffix = n;\n\t\t\t}\n\t\t}\n\n\t\treturn `${baseSlug}-${maxSuffix + 1}`;\n\t}\n\n\t/**\n\t * Duplicate a content item\n\t * Creates a new draft copy with \"(Copy)\" appended to the title.\n\t * A slug is auto-generated from the new title by the handler layer.\n\t */\n\tasync duplicate(type: string, id: string, authorId?: string): Promise<ContentItem> {\n\t\t// Fetch the original item\n\t\tconst original = await this.findById(type, id);\n\t\tif (!original) {\n\t\t\tthrow new EmDashValidationError(\"Content item not found\");\n\t\t}\n\n\t\t// Prepare the new data\n\t\tconst newData = { ...original.data };\n\n\t\t// Append \"(Copy)\" to title if present\n\t\tif (typeof newData.title === \"string\") {\n\t\t\tnewData.title = `${newData.title} (Copy)`;\n\t\t} else if (typeof newData.name === \"string\") {\n\t\t\tnewData.name = `${newData.name} (Copy)`;\n\t\t}\n\n\t\t// Auto-generate a unique slug from the new title/name\n\t\tconst slugSource =\n\t\t\ttypeof newData.title === \"string\"\n\t\t\t\t? newData.title\n\t\t\t\t: typeof newData.name === \"string\"\n\t\t\t\t\t? newData.name\n\t\t\t\t\t: null;\n\n\t\tconst slug = slugSource\n\t\t\t? await this.generateUniqueSlug(type, slugSource, original.locale ?? undefined)\n\t\t\t: null;\n\n\t\t// Create the duplicate as a draft — use override authorId if provided (caller owns the copy)\n\t\treturn this.create({\n\t\t\ttype,\n\t\t\tslug,\n\t\t\tdata: newData,\n\t\t\tstatus: \"draft\",\n\t\t\tauthorId: authorId || original.authorId || undefined,\n\t\t\tlocale: original.locale ?? undefined,\n\t\t});\n\t}\n\n\t/**\n\t * Find content by ID\n\t */\n\tasync findById(type: string, id: string): Promise<ContentItem | null> {\n\t\tconst tableName = getTableName(type);\n\n\t\tconst result = await sql<Record<string, unknown>>`\n\t\t\tSELECT * FROM ${sql.ref(tableName)}\n\t\t\tWHERE id = ${id}\n\t\t\tAND deleted_at IS NULL\n\t\t`.execute(this.db);\n\n\t\tconst row = result.rows[0];\n\t\tif (!row) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn this.mapRow(type, row);\n\t}\n\n\t/**\n\t * Find content by id, including trashed (soft-deleted) items.\n\t * Used by restore endpoint for ownership checks.\n\t */\n\tasync findByIdIncludingTrashed(type: string, id: string): Promise<ContentItem | null> {\n\t\tconst tableName = getTableName(type);\n\n\t\tconst result = await sql<Record<string, unknown>>`\n\t\t\tSELECT * FROM ${sql.ref(tableName)}\n\t\t\tWHERE id = ${id}\n\t\t`.execute(this.db);\n\n\t\tconst row = result.rows[0];\n\t\tif (!row) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn this.mapRow(type, row);\n\t}\n\n\t/**\n\t * Find content by ID or slug. Tries ID first if it looks like a ULID,\n\t * otherwise tries slug. Falls back to the other if the first lookup misses.\n\t */\n\tasync findByIdOrSlug(\n\t\ttype: string,\n\t\tidentifier: string,\n\t\tlocale?: string,\n\t): Promise<ContentItem | null> {\n\t\treturn this._findByIdOrSlug(type, identifier, false, locale);\n\t}\n\n\t/**\n\t * Find content by ID or slug, including trashed (soft-deleted) items.\n\t * Used by restore/permanent-delete endpoints.\n\t */\n\tasync findByIdOrSlugIncludingTrashed(\n\t\ttype: string,\n\t\tidentifier: string,\n\t\tlocale?: string,\n\t): Promise<ContentItem | null> {\n\t\treturn this._findByIdOrSlug(type, identifier, true, locale);\n\t}\n\n\tprivate async _findByIdOrSlug(\n\t\ttype: string,\n\t\tidentifier: string,\n\t\tincludeTrashed: boolean,\n\t\tlocale?: string,\n\t): Promise<ContentItem | null> {\n\t\t// ULIDs are 26 uppercase alphanumeric chars\n\t\tconst looksLikeUlid = ULID_PATTERN.test(identifier);\n\n\t\tconst findById = includeTrashed\n\t\t\t? (t: string, id: string) => this.findByIdIncludingTrashed(t, id)\n\t\t\t: (t: string, id: string) => this.findById(t, id);\n\t\tconst findBySlug = includeTrashed\n\t\t\t? (t: string, s: string) => this.findBySlugIncludingTrashed(t, s, locale)\n\t\t\t: (t: string, s: string) => this.findBySlug(t, s, locale);\n\n\t\ttry {\n\t\t\tif (looksLikeUlid) {\n\t\t\t\t// Try ID first, fall back to slug\n\t\t\t\tconst byId = await findById(type, identifier);\n\t\t\t\tif (byId) return byId;\n\t\t\t\treturn await findBySlug(type, identifier);\n\t\t\t}\n\t\t\t// Try slug first, fall back to ID\n\t\t\tconst bySlug = await findBySlug(type, identifier);\n\t\t\tif (bySlug) return bySlug;\n\t\t\treturn await findById(type, identifier);\n\t\t} catch (error) {\n\t\t\t// A collection dropped out from under a still-referencing caller (e.g. a\n\t\t\t// relation whose collection was deleted without cascading) leaves the\n\t\t\t// ec_* table missing. Treat that as \"not found\", matching\n\t\t\t// findManyByIdOrSlug and findTranslationsForGroups, so callers surface a\n\t\t\t// structured NOT_FOUND instead of a 500.\n\t\t\tif (isMissingTableError(error)) return null;\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Find content by slug\n\t */\n\tasync findBySlug(type: string, slug: string, locale?: string): Promise<ContentItem | null> {\n\t\tconst tableName = getTableName(type);\n\n\t\tconst result = locale\n\t\t\t? await sql<Record<string, unknown>>`\n\t\t\t\t\tSELECT * FROM ${sql.ref(tableName)}\n\t\t\t\t\tWHERE slug = ${slug}\n\t\t\t\t\tAND locale = ${locale}\n\t\t\t\t\tAND deleted_at IS NULL\n\t\t\t\t`.execute(this.db)\n\t\t\t: await sql<Record<string, unknown>>`\n\t\t\t\t\tSELECT * FROM ${sql.ref(tableName)}\n\t\t\t\t\tWHERE slug = ${slug}\n\t\t\t\t\tAND deleted_at IS NULL\n\t\t\t\t\tORDER BY locale ASC\n\t\t\t\t\tLIMIT 1\n\t\t\t\t`.execute(this.db);\n\n\t\tconst row = result.rows[0];\n\t\tif (!row) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn this.mapRow(type, row);\n\t}\n\n\t/**\n\t * Find content by slug, including trashed (soft-deleted) items.\n\t * Used by restore/permanent-delete endpoints.\n\t */\n\tasync findBySlugIncludingTrashed(\n\t\ttype: string,\n\t\tslug: string,\n\t\tlocale?: string,\n\t): Promise<ContentItem | null> {\n\t\tconst tableName = getTableName(type);\n\n\t\tconst result = locale\n\t\t\t? await sql<Record<string, unknown>>`\n\t\t\t\t\tSELECT * FROM ${sql.ref(tableName)}\n\t\t\t\t\tWHERE slug = ${slug}\n\t\t\t\t\tAND locale = ${locale}\n\t\t\t\t`.execute(this.db)\n\t\t\t: await sql<Record<string, unknown>>`\n\t\t\t\t\tSELECT * FROM ${sql.ref(tableName)}\n\t\t\t\t\tWHERE slug = ${slug}\n\t\t\t\t\tORDER BY locale ASC\n\t\t\t\t\tLIMIT 1\n\t\t\t\t`.execute(this.db);\n\n\t\tconst row = result.rows[0];\n\t\tif (!row) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn this.mapRow(type, row);\n\t}\n\n\t/**\n\t * Find many content items with filtering and pagination\n\t */\n\tasync findMany(\n\t\ttype: string,\n\t\toptions: FindManyOptions = {},\n\t): Promise<FindManyResult<ContentItem>> {\n\t\tconst tableName = getTableName(type);\n\t\tconst limit = Math.min(options.limit || 50, 100);\n\n\t\t// Determine ordering\n\t\tconst orderField = options.orderBy?.field || \"createdAt\";\n\t\tconst orderDirection = options.orderBy?.direction || \"desc\";\n\t\tconst resolvedOrderField = await this.resolveOrderField(\n\t\t\ttype,\n\t\t\torderField,\n\t\t\toptions.sortableExtras,\n\t\t);\n\t\tconst dbField = resolvedOrderField.column;\n\t\tconst resolvedFieldFilters = await this.resolveFieldFilters(type, options.where?.fieldFilters);\n\n\t\t// Validate order direction to prevent injection\n\t\tconst safeOrderDirection = orderDirection.toLowerCase() === \"asc\" ? \"ASC\" : \"DESC\";\n\n\t\t// Build query with parameterized values (no string interpolation)\n\t\t// Note: Dynamic content tables have deleted_at column, cast needed for Kysely\n\t\tlet query = this.db\n\t\t\t.selectFrom(tableName as keyof Database)\n\t\t\t.selectAll()\n\t\t\t.where(\"deleted_at\" as never, \"is\", null);\n\n\t\t// Apply filters with parameterized queries\n\t\tif (options.where?.status) {\n\t\t\tquery = query.where(\"status\", \"=\", options.where.status);\n\t\t}\n\n\t\tif (options.where?.authorId) {\n\t\t\tquery = query.where(\"author_id\", \"=\", options.where.authorId);\n\t\t}\n\n\t\tif (options.where?.locale) {\n\t\t\tquery = query.where(\"locale\" as any, \"=\", options.where.locale);\n\t\t}\n\n\t\tquery = this.applySearchFilter(query, options.where, type);\n\t\tquery = this.applyDateFilter(query, options.where);\n\t\tquery = this.applyBylineFilter(query, options.where, type);\n\t\tquery = this.applyFieldFilters(query, resolvedFieldFilters);\n\n\t\t// Handle cursor pagination — decodeCursor throws InvalidCursorError\n\t\t// on malformed input; let it propagate so handlers surface a\n\t\t// structured INVALID_CURSOR rather than silently returning page 1.\n\t\tif (options.cursor) {\n\t\t\tif (resolvedOrderField.indexedCustomField) {\n\t\t\t\tconst { value, id: cursorId } = decodeIndexedFieldCursor(options.cursor, orderField);\n\t\t\t\tconst isPresent = sql<boolean>`${sql.ref(dbField)} IS NOT NULL`;\n\t\t\t\tconst falseLiteral = sql<boolean>`FALSE`;\n\t\t\t\tconst trueLiteral = sql<boolean>`TRUE`;\n\t\t\t\tif (safeOrderDirection === \"ASC\" && value === null) {\n\t\t\t\t\tquery = query.where(sql<boolean>`\n\t\t\t\t\t\t(${isPresent}) > ${falseLiteral}\n\t\t\t\t\t\tOR ((${isPresent}) = ${falseLiteral} AND ${sql.ref(\"id\")} > ${cursorId})\n\t\t\t\t\t`);\n\t\t\t\t} else if (safeOrderDirection === \"DESC\" && value === null) {\n\t\t\t\t\tquery = query.where(sql<boolean>`\n\t\t\t\t\t\t(${isPresent}) = ${falseLiteral} AND ${sql.ref(\"id\")} < ${cursorId}\n\t\t\t\t\t`);\n\t\t\t\t} else if (safeOrderDirection === \"ASC\") {\n\t\t\t\t\tquery = query.where(sql<boolean>`\n\t\t\t\t\t\t(${isPresent}, ${sql.ref(dbField)}, ${sql.ref(\"id\")})\n\t\t\t\t\t\t\t> (${trueLiteral}, ${value}, ${cursorId})\n\t\t\t\t\t`);\n\t\t\t\t} else {\n\t\t\t\t\tquery = query.where(sql<boolean>`\n\t\t\t\t\t\t(${isPresent}, ${sql.ref(dbField)}, ${sql.ref(\"id\")})\n\t\t\t\t\t\t\t< (${trueLiteral}, ${value}, ${cursorId})\n\t\t\t\t\t`);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst { orderValue, id: cursorId } = decodeCursor(options.cursor);\n\n\t\t\t\tif (safeOrderDirection === \"DESC\") {\n\t\t\t\t\tquery = query.where((eb) =>\n\t\t\t\t\t\teb.or([\n\t\t\t\t\t\t\teb(dbField as any, \"<\", orderValue),\n\t\t\t\t\t\t\teb.and([eb(dbField as any, \"=\", orderValue), eb(\"id\", \"<\", cursorId)]),\n\t\t\t\t\t\t]),\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tquery = query.where((eb) =>\n\t\t\t\t\t\teb.or([\n\t\t\t\t\t\t\teb(dbField as any, \">\", orderValue),\n\t\t\t\t\t\t\teb.and([eb(dbField as any, \"=\", orderValue), eb(\"id\", \">\", cursorId)]),\n\t\t\t\t\t\t]),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Apply ordering and limit\n\t\tconst indexedOrderFilter = resolvedOrderField.indexedCustomField\n\t\t\t? resolvedFieldFilters.find((filter) => filter.column === dbField)\n\t\t\t: undefined;\n\t\tif (resolvedOrderField.indexedCustomField && !indexedOrderFilter) {\n\t\t\tquery = query.orderBy(\n\t\t\t\tsql<boolean>`${sql.ref(dbField)} IS NOT NULL`,\n\t\t\t\tsafeOrderDirection === \"ASC\" ? \"asc\" : \"desc\",\n\t\t\t);\n\t\t}\n\t\tif (indexedOrderFilter?.kind !== \"null\") {\n\t\t\tquery = query.orderBy(dbField as any, safeOrderDirection === \"ASC\" ? \"asc\" : \"desc\");\n\t\t}\n\t\tquery = query.orderBy(\"id\", safeOrderDirection === \"ASC\" ? \"asc\" : \"desc\").limit(limit + 1);\n\n\t\t// Run the page fetch and the unbounded count together — the UI needs\n\t\t// both to render a stable denominator (kept on every page intentionally),\n\t\t// and issuing them in parallel on SQLite is essentially free.\n\t\t//\n\t\t// Settled rather than raced: a collection whose table is missing rejects\n\t\t// both, and `Promise.all` returns on the first. The loser stays in flight\n\t\t// holding a pooled connection, so a Postgres pool destroyed in that window\n\t\t// never finishes closing.\n\t\tconst [rowsResult, countResult] = await Promise.allSettled([\n\t\t\tquery.execute(),\n\t\t\tthis.countWithResolvedFilters(type, options.where, resolvedFieldFilters),\n\t\t]);\n\t\tif (rowsResult.status === \"rejected\") throw rowsResult.reason;\n\t\tif (countResult.status === \"rejected\") throw countResult.reason;\n\t\tconst rows = rowsResult.value;\n\t\tconst total = countResult.value;\n\t\tconst hasMore = rows.length > limit;\n\t\tconst items = rows.slice(0, limit);\n\n\t\tconst mappedResult: FindManyResult<ContentItem> = {\n\t\t\titems: items.map((row) => this.mapRow(type, row as Record<string, unknown>)),\n\t\t\ttotal,\n\t\t};\n\n\t\tif (hasMore && items.length > 0) {\n\t\t\tconst lastRow = items.at(-1) as Record<string, unknown>;\n\t\t\tconst lastOrderValue = lastRow[dbField];\n\t\t\tif (resolvedOrderField.indexedCustomField) {\n\t\t\t\tif (\n\t\t\t\t\tlastOrderValue !== null &&\n\t\t\t\t\ttypeof lastOrderValue !== \"string\" &&\n\t\t\t\t\ttypeof lastOrderValue !== \"number\"\n\t\t\t\t) {\n\t\t\t\t\tthrow new EmDashValidationError(`Invalid indexed value for order field: ${orderField}`);\n\t\t\t\t}\n\t\t\t\tmappedResult.nextCursor = encodeIndexedFieldCursor(\n\t\t\t\t\torderField,\n\t\t\t\t\tlastOrderValue,\n\t\t\t\t\tString(lastRow.id),\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tconst orderStr =\n\t\t\t\t\ttypeof lastOrderValue === \"string\" || typeof lastOrderValue === \"number\"\n\t\t\t\t\t\t? String(lastOrderValue)\n\t\t\t\t\t\t: \"\";\n\t\t\t\tmappedResult.nextCursor = encodeCursor(orderStr, String(lastRow.id));\n\t\t\t}\n\t\t}\n\n\t\treturn mappedResult;\n\t}\n\n\t/**\n\t * Update content\n\t */\n\tasync update(type: string, id: string, input: UpdateContentInput): Promise<ContentItem> {\n\t\tconst tableName = getTableName(type);\n\t\tconst now = new Date().toISOString();\n\n\t\t// Every update advances the optimistic-concurrency version. updated_at\n\t\t// advances only when a content-row column actually changes.\n\t\tconst updates: Record<string, unknown> = {};\n\n\t\tif (input.status !== undefined) {\n\t\t\tupdates.status = input.status;\n\t\t}\n\n\t\tif (input.slug !== undefined) {\n\t\t\tupdates.slug = input.slug;\n\t\t}\n\n\t\tif (input.publishedAt !== undefined) {\n\t\t\tupdates.published_at = input.publishedAt;\n\t\t}\n\n\t\tif (input.scheduledAt !== undefined) {\n\t\t\tupdates.scheduled_at = input.scheduledAt;\n\t\t}\n\n\t\tif (input.authorId !== undefined) {\n\t\t\tupdates.author_id = input.authorId;\n\t\t}\n\n\t\tif (input.primaryBylineId !== undefined) {\n\t\t\tupdates.primary_byline_id = input.primaryBylineId;\n\t\t}\n\n\t\t// Update data fields (skip system columns to prevent injection via data)\n\t\tif (input.data !== undefined && typeof input.data === \"object\") {\n\t\t\tfor (const [key, value] of Object.entries(writableContentData(input.data))) {\n\t\t\t\tupdates[key] = serializeValue(value);\n\t\t\t}\n\t\t}\n\n\t\tconst hasColumnWrites = Object.keys(updates).length > 0;\n\t\tif (hasColumnWrites) {\n\t\t\tupdates.updated_at = now;\n\t\t}\n\t\tupdates.version = sql`version + 1`;\n\n\t\tawait this.db\n\t\t\t.updateTable(tableName as keyof Database)\n\t\t\t.set(updates)\n\t\t\t.where(\"id\", \"=\", id)\n\t\t\t.where(\"deleted_at\" as never, \"is\", null)\n\t\t\t.execute();\n\n\t\tif (hasColumnWrites) invalidateCollectionCache(type);\n\n\t\tconst updated = await this.findById(type, id);\n\t\tif (!updated) {\n\t\t\tthrow new Error(\"Content not found\");\n\t\t}\n\n\t\treturn updated;\n\t}\n\n\t/**\n\t * Update plugin-authored fields without letting content columns diverge\n\t * from the revision pointers that publication promotes.\n\t */\n\tasync updateDraftAware(\n\t\ttype: string,\n\t\tid: string,\n\t\tinput: UpdateContentInput,\n\t): Promise<ContentItem> {\n\t\tconst data = input.data ? writableContentData(input.data) : {};\n\t\tconst stagedSlug = typeof input.slug === \"string\" ? input.slug : undefined;\n\t\tconst hasDraftUpdate = Object.keys(data).length > 0 || stagedSlug !== undefined;\n\n\t\tif (!hasDraftUpdate) {\n\t\t\treturn this.update(type, id, { ...input, data });\n\t\t}\n\n\t\tconst collectionRows = await this.db\n\t\t\t.selectFrom(\"_emdash_collections as collection\")\n\t\t\t.leftJoin(\"_emdash_fields as field\", \"field.collection_id\", \"collection.id\")\n\t\t\t.select([\"collection.supports\", \"field.slug as fieldSlug\"])\n\t\t\t.where(\"collection.slug\", \"=\", type)\n\t\t\t.execute();\n\t\tconst supportsRaw = collectionRows[0]?.supports;\n\t\tconst supports: unknown = supportsRaw ? JSON.parse(supportsRaw) : [];\n\t\tif (!Array.isArray(supports) || !supports.includes(\"revisions\")) {\n\t\t\treturn this.update(type, id, { ...input, data });\n\t\t}\n\n\t\tconst fieldSlugs = new Set(collectionRows.map((row) => row.fieldSlug).filter(Boolean));\n\t\tfor (const field of Object.keys(data)) {\n\t\t\tif (!fieldSlugs.has(field)) {\n\t\t\t\tthrow new EmDashValidationError(`Unknown field '${field}' in collection '${type}'`);\n\t\t\t}\n\t\t}\n\n\t\tconst revisionRepo = new RevisionRepository(this.db);\n\t\tlet existing = await this.findById(type, id);\n\n\t\tfor (let attempt = 0; existing && attempt < MAX_DRAFT_STAGE_ATTEMPTS; attempt++) {\n\t\t\tlet baseData = existing.data;\n\t\t\tif (existing.draftRevisionId) {\n\t\t\t\tconst draft = await revisionRepo.findById(existing.draftRevisionId);\n\t\t\t\tif (draft) baseData = draft.data;\n\t\t\t}\n\n\t\t\tconst mergedData = { ...baseData, ...data };\n\t\t\tif (stagedSlug !== undefined) mergedData._slug = stagedSlug;\n\t\t\tconst revision = await revisionRepo.create({\n\t\t\t\tcollection: type,\n\t\t\t\tentryId: id,\n\t\t\t\tdata: mergedData,\n\t\t\t\t...(input.authorId ? { authorId: input.authorId } : {}),\n\t\t\t});\n\n\t\t\tlet staged: boolean;\n\t\t\ttry {\n\t\t\t\tstaged = await this.replaceDraftRevisionForUpdate(type, id, revision.id, existing, input);\n\t\t\t} catch (error) {\n\t\t\t\tawait this.deleteUnstagedRevision(revisionRepo, type, id, revision.id);\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tif (staged) {\n\t\t\t\tconst updated = await this.findById(type, id);\n\t\t\t\tif (!updated) throw new Error(\"Content not found\");\n\t\t\t\tconst draftData: Record<string, unknown> = {};\n\t\t\t\tfor (const [key, value] of Object.entries(mergedData)) {\n\t\t\t\t\tif (!key.startsWith(\"_\")) draftData[key] = value;\n\t\t\t\t}\n\t\t\t\treturn { ...updated, data: { ...updated.data, ...draftData } };\n\t\t\t}\n\n\t\t\tawait this.deleteUnstagedRevision(revisionRepo, type, id, revision.id);\n\t\t\texisting = await this.findById(type, id);\n\t\t}\n\n\t\tif (!existing) throw new Error(\"Content not found\");\n\t\tthrow new ContentMutationConflictError();\n\t}\n\n\tprivate async deleteUnstagedRevision(\n\t\trevisionRepo: RevisionRepository,\n\t\ttype: string,\n\t\tid: string,\n\t\trevisionId: string,\n\t): Promise<void> {\n\t\ttry {\n\t\t\tawait revisionRepo.deleteIfUnreferenced(type, id, revisionId);\n\t\t} catch (error) {\n\t\t\tconsole.error(`[content] Failed to clean up unstaged revision ${revisionId}:`, error);\n\t\t}\n\t}\n\n\tprivate async replaceDraftRevisionForUpdate(\n\t\ttype: string,\n\t\tid: string,\n\t\trevisionId: string,\n\t\texpected: ContentItem,\n\t\tinput: UpdateContentInput,\n\t): Promise<boolean> {\n\t\tconst tableName = getTableName(type);\n\t\tconst assignments = [sql`draft_revision_id = ${revisionId}`];\n\t\tlet liveMetadataChanged = false;\n\n\t\tif (input.status !== undefined) {\n\t\t\tassignments.push(sql`status = ${input.status}`);\n\t\t\tliveMetadataChanged = true;\n\t\t}\n\t\tif (input.slug === null) {\n\t\t\tassignments.push(sql`slug = NULL`);\n\t\t\tliveMetadataChanged = true;\n\t\t}\n\t\tif (input.publishedAt !== undefined) {\n\t\t\tassignments.push(sql`published_at = ${input.publishedAt}`);\n\t\t\tliveMetadataChanged = true;\n\t\t}\n\t\tif (input.scheduledAt !== undefined) {\n\t\t\tassignments.push(sql`scheduled_at = ${input.scheduledAt}`);\n\t\t\tliveMetadataChanged = true;\n\t\t}\n\t\tif (input.authorId !== undefined) {\n\t\t\tassignments.push(sql`author_id = ${input.authorId}`);\n\t\t\tliveMetadataChanged = true;\n\t\t}\n\t\tif (input.primaryBylineId !== undefined) {\n\t\t\tassignments.push(sql`primary_byline_id = ${input.primaryBylineId}`);\n\t\t\tliveMetadataChanged = true;\n\t\t}\n\t\tif (liveMetadataChanged) assignments.push(sql`updated_at = ${new Date().toISOString()}`);\n\t\tassignments.push(sql`version = version + 1`);\n\n\t\tconst result = await sql`\n\t\t\tUPDATE ${sql.ref(tableName)}\n\t\t\tSET ${sql.join(assignments, sql`, `)}\n\t\t\tWHERE id = ${id}\n\t\t\tAND deleted_at IS NULL\n\t\t\tAND version = ${expected.version}\n\t\t\tAND ${nullableColumnMatch(\"live_revision_id\", expected.liveRevisionId)}\n\t\t\tAND ${nullableColumnMatch(\"draft_revision_id\", expected.draftRevisionId)}\n\t\t\tAND EXISTS (\n\t\t\t\tSELECT 1 FROM revisions\n\t\t\t\tWHERE revisions.id = ${revisionId}\n\t\t\t\tAND revisions.collection = ${type}\n\t\t\t\tAND revisions.entry_id = ${id}\n\t\t\t)\n\t\t`.execute(this.db);\n\n\t\tconst changed = (result.numAffectedRows ?? 0n) > 0n;\n\t\tif (changed && liveMetadataChanged) invalidateCollectionCache(type);\n\t\treturn changed;\n\t}\n\n\t/**\n\t * Delete content (soft delete - moves to trash)\n\t */\n\tasync delete(type: string, id: string): Promise<boolean> {\n\t\tconst tableName = getTableName(type);\n\t\tconst now = new Date().toISOString();\n\n\t\tconst result = await sql`\n\t\t\tUPDATE ${sql.ref(tableName)}\n\t\t\tSET deleted_at = ${now}\n\t\t\tWHERE id = ${id}\n\t\t\tAND deleted_at IS NULL\n\t\t`.execute(this.db);\n\n\t\tconst changed = (result.numAffectedRows ?? 0n) > 0n;\n\t\tif (changed) {\n\t\t\tinvalidateCollectionCache(type);\n\t\t}\n\t\treturn changed;\n\t}\n\n\t/**\n\t * Restore content from trash\n\t */\n\tasync restore(type: string, id: string): Promise<ContentItem | null> {\n\t\tconst tableName = getTableName(type);\n\n\t\tconst result = await sql<Record<string, unknown>>`\n\t\t\tUPDATE ${sql.ref(tableName)}\n\t\t\tSET deleted_at = NULL\n\t\t\tWHERE id = ${id}\n\t\t\tAND deleted_at IS NOT NULL\n\t\t\tRETURNING *\n\t\t`.execute(this.db);\n\n\t\tconst restored = result.rows[0];\n\t\tif (!restored) return null;\n\n\t\tinvalidateCollectionCache(type);\n\t\treturn this.mapRow(type, restored);\n\t}\n\n\t/**\n\t * Permanently delete content (cannot be undone)\n\t */\n\t/**\n\t * Permanently delete a soft-deleted content row.\n\t *\n\t * Returns `true` only when a soft-deleted (trashed) row was removed.\n\t * Returns `false` when no row exists OR when the row exists but is live —\n\t * the caller is responsible for distinguishing these cases (typically via\n\t * a follow-up `findByIdOrSlugIncludingTrashed` to surface NOT_FOUND vs\n\t * NOT_TRASHED). The `AND deleted_at IS NOT NULL` clause is the safety net\n\t * that prevents permanent delete from bypassing the trash workflow.\n\t */\n\tasync permanentDelete(type: string, id: string): Promise<boolean> {\n\t\tconst tableName = getTableName(type);\n\n\t\tconst result = await sql`\n\t\t\tDELETE FROM ${sql.ref(tableName)}\n\t\t\tWHERE id = ${id}\n\t\t\tAND deleted_at IS NOT NULL\n\t\t`.execute(this.db);\n\n\t\tconst changed = (result.numAffectedRows ?? 0n) > 0n;\n\t\tif (changed) invalidateCollectionCache(type);\n\t\treturn changed;\n\t}\n\n\t/**\n\t * Find trashed content items\n\t */\n\tasync findTrashed(\n\t\ttype: string,\n\t\toptions: Omit<FindManyOptions, \"where\"> = {},\n\t): Promise<FindManyResult<ContentItem & { deletedAt: string }>> {\n\t\tconst tableName = getTableName(type);\n\t\tconst limit = Math.min(options.limit || 50, 100);\n\n\t\t// Determine ordering - default to most recently deleted\n\t\tconst orderField = options.orderBy?.field || \"deletedAt\";\n\t\tconst orderDirection = options.orderBy?.direction || \"desc\";\n\t\tconst dbField = this.mapOrderField(orderField);\n\n\t\tconst safeOrderDirection = orderDirection.toLowerCase() === \"asc\" ? \"ASC\" : \"DESC\";\n\n\t\tlet query = this.db\n\t\t\t.selectFrom(tableName as keyof Database)\n\t\t\t.selectAll()\n\t\t\t.where(\"deleted_at\" as never, \"is not\", null);\n\n\t\t// Handle cursor pagination — decodeCursor throws on invalid input.\n\t\tif (options.cursor) {\n\t\t\tconst { orderValue, id: cursorId } = decodeCursor(options.cursor);\n\n\t\t\tif (safeOrderDirection === \"DESC\") {\n\t\t\t\tquery = query.where((eb) =>\n\t\t\t\t\teb.or([\n\t\t\t\t\t\teb(dbField as any, \"<\", orderValue),\n\t\t\t\t\t\teb.and([eb(dbField as any, \"=\", orderValue), eb(\"id\", \"<\", cursorId)]),\n\t\t\t\t\t]),\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tquery = query.where((eb) =>\n\t\t\t\t\teb.or([\n\t\t\t\t\t\teb(dbField as any, \">\", orderValue),\n\t\t\t\t\t\teb.and([eb(dbField as any, \"=\", orderValue), eb(\"id\", \">\", cursorId)]),\n\t\t\t\t\t]),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tquery = query\n\t\t\t.orderBy(dbField as any, safeOrderDirection === \"ASC\" ? \"asc\" : \"desc\")\n\t\t\t.orderBy(\"id\", safeOrderDirection === \"ASC\" ? \"asc\" : \"desc\")\n\t\t\t.limit(limit + 1);\n\n\t\tconst rows = await query.execute();\n\t\tconst hasMore = rows.length > limit;\n\t\tconst items = rows.slice(0, limit);\n\n\t\tconst mappedResult: FindManyResult<ContentItem & { deletedAt: string }> = {\n\t\t\titems: items.map((row) => {\n\t\t\t\tconst record = row as Record<string, unknown>;\n\t\t\t\treturn {\n\t\t\t\t\t...this.mapRow(type, record),\n\t\t\t\t\tdeletedAt: typeof record.deleted_at === \"string\" ? record.deleted_at : \"\",\n\t\t\t\t};\n\t\t\t}),\n\t\t};\n\n\t\tif (hasMore && items.length > 0) {\n\t\t\tconst lastRow = items.at(-1) as Record<string, unknown>;\n\t\t\tconst lastOrderValue = lastRow[dbField];\n\t\t\tconst orderStr =\n\t\t\t\ttypeof lastOrderValue === \"string\" || typeof lastOrderValue === \"number\"\n\t\t\t\t\t? String(lastOrderValue)\n\t\t\t\t\t: \"\";\n\t\t\tmappedResult.nextCursor = encodeCursor(orderStr, String(lastRow.id));\n\t\t}\n\n\t\treturn mappedResult;\n\t}\n\n\t/**\n\t * Count trashed content items\n\t */\n\tasync countTrashed(type: string): Promise<number> {\n\t\tconst tableName = getTableName(type);\n\n\t\tconst result = await this.db\n\t\t\t.selectFrom(tableName as keyof Database)\n\t\t\t.select((eb) => eb.fn.count(\"id\").as(\"count\"))\n\t\t\t.where(\"deleted_at\" as never, \"is not\", null)\n\t\t\t.executeTakeFirst();\n\n\t\treturn Number(result?.count || 0);\n\t}\n\n\t/**\n\t * Apply the optional `q` filter.\n\t *\n\t * When the handler sets `useFts` (collection has a healthy FTS5 index\n\t * covering the display columns; SQLite only), the filter is served from\n\t * the index: a token-prefix MATCH against `_emdash_fts_<slug>` OR'd with\n\t * an index-served `slug GLOB 'term*'` prefix (the slug is not in the FTS\n\t * index). Both sides are index-backed, so SQLite's OR optimization avoids\n\t * the full-table scan the LIKE fallback needs (#1517). The trade-off is\n\t * search semantics: token-prefix matching instead of arbitrary substring.\n\t *\n\t * Fallback (Postgres, search disabled, or no usable terms): case-\n\t * insensitive substring LIKE across the handler-resolved `searchColumns`\n\t * (OR'd). User input is treated literally (LIKE wildcards escaped) and\n\t * `lower()` is applied on both sides for SQLite/Postgres parity.\n\t */\n\tprivate applySearchFilter<QB extends { where: (cb: (eb: any) => unknown) => QB }>(\n\t\tquery: QB,\n\t\twhere: { q?: string; searchColumns?: string[]; useFts?: boolean } | undefined,\n\t\ttype: string,\n\t): QB {\n\t\tconst term = where?.q?.trim();\n\t\tconst columns = where?.searchColumns;\n\t\tif (!term || !columns || columns.length === 0) return query;\n\n\t\tif (where.useFts) {\n\t\t\tconst match = buildFtsPrefixMatch(term);\n\t\t\tif (match) {\n\t\t\t\tvalidateIdentifier(type, \"collection slug\");\n\t\t\t\tconst ftsTable = `_emdash_fts_${type}`;\n\t\t\t\tconst slugPrefix = buildSlugGlobPrefix(term);\n\t\t\t\treturn query.where((eb) =>\n\t\t\t\t\teb.or([\n\t\t\t\t\t\tsql<boolean>`id IN (SELECT id FROM ${sql.ref(ftsTable)} WHERE ${sql.ref(ftsTable)} MATCH ${match})`,\n\t\t\t\t\t\tsql<boolean>`slug GLOB ${slugPrefix}`,\n\t\t\t\t\t]),\n\t\t\t\t);\n\t\t\t}\n\t\t\t// No usable terms (e.g. quotes only) — fall through to LIKE.\n\t\t}\n\n\t\tconst escaped = term.replace(LIKE_WILDCARD_RE, (c) => `\\\\${c}`);\n\t\tconst pattern = `%${escaped}%`;\n\n\t\treturn query.where((eb) =>\n\t\t\teb.or(\n\t\t\t\tcolumns.map((col) => {\n\t\t\t\t\tvalidateIdentifier(col, \"search column\");\n\t\t\t\t\treturn sql<boolean>`lower(CAST(${sql.ref(col)} AS TEXT)) LIKE lower(${pattern}) ESCAPE '\\\\'`;\n\t\t\t\t}),\n\t\t\t),\n\t\t);\n\t}\n\n\t/**\n\t * Apply the optional inclusive date-range filter. The field is mapped\n\t * through `DATE_FILTER_COLUMNS` (a closed whitelist), and bounds compare\n\t * lexicographically against the stored ISO 8601 timestamps. A `publishedAt`\n\t * range naturally excludes never-published rows (their column is NULL).\n\t */\n\tprivate applyDateFilter<QB extends { where: (cb: (eb: any) => unknown) => QB }>(\n\t\tquery: QB,\n\t\twhere?: { dateFilter?: { field: string; from?: string; to?: string } },\n\t): QB {\n\t\tconst filter = where?.dateFilter;\n\t\tif (!filter) return query;\n\t\tconst column = DATE_FILTER_COLUMNS[filter.field as ContentDateField];\n\t\tif (!column) {\n\t\t\tthrow new EmDashValidationError(`Invalid date filter field: ${filter.field}`);\n\t\t}\n\t\tconst { from, to } = filter;\n\t\tif (!from && !to) return query;\n\n\t\tlet next = query;\n\t\tif (from) next = next.where((eb) => eb(column as any, \">=\", from));\n\t\tif (to) next = next.where((eb) => eb(column as any, \"<=\", to));\n\t\treturn next;\n\t}\n\n\t/**\n\t * Apply the optional byline filter as a correlated (NOT) EXISTS against\n\t * `_emdash_content_bylines`.\n\t *\n\t * Correlating from the content table preserves the outer sort index so\n\t * `LIMIT` can short-circuit. `mode: \"none\"` tests the junction rather than\n\t * `primary_byline_id` because the two are written in the same call but\n\t * are not atomically consistent, so the junction is authoritative.\n\t *\n\t * Whether a credit *renders* is locale-scoped; whether one *exists* is\n\t * not. Both are needed: the first decides what the filter matches, the\n\t * second decides whether the author fallback applies at all.\n\t */\n\tprivate applyBylineFilter<QB extends { where: (cb: (eb: any) => unknown) => QB }>(\n\t\tquery: QB,\n\t\twhere: { bylineFilter?: ContentBylineFilter } | undefined,\n\t\ttype: string,\n\t): QB {\n\t\tconst filter = where?.bylineFilter;\n\t\tif (!filter) return query;\n\t\tconst tableName = getTableName(type);\n\t\tconst idColumn = `${tableName}.id`;\n\t\tconst authorColumn = `${tableName}.author_id`;\n\t\tconst localeColumn = `${tableName}.locale`;\n\n\t\t// An explicit credit that actually renders — optionally within a given\n\t\t// set of translation groups. The junction stores a group, but a credit\n\t\t// resolves only where that group has a byline row at the locale the\n\t\t// list is scoped to, so this repeats the join `getContentBylinesMany`\n\t\t// makes. `locale` falls back to each entry's own when the list spans\n\t\t// locales.\n\t\tconst creditRenders = (eb: any, bylineIds?: string[]) => {\n\t\t\tlet sub = eb\n\t\t\t\t.selectFrom(\"_emdash_content_bylines as cb\")\n\t\t\t\t.innerJoin(\"_emdash_bylines as b\", \"b.translation_group\", \"cb.byline_id\")\n\t\t\t\t.select(\"cb.id\")\n\t\t\t\t.where(\"cb.collection_slug\", \"=\", type)\n\t\t\t\t.whereRef(\"cb.content_id\", \"=\", idColumn);\n\t\t\tsub = filter.locale\n\t\t\t\t? sub.where(\"b.locale\", \"=\", filter.locale)\n\t\t\t\t: sub.whereRef(\"b.locale\", \"=\", localeColumn);\n\t\t\tif (bylineIds) sub = sub.where(\"cb.byline_id\", \"in\", bylineIds);\n\t\t\treturn eb.exists(sub);\n\t\t};\n\n\t\t// Whether the entry carries an explicit credit at all, at any locale.\n\t\t// Deliberately not locale-scoped: the author fallback is suppressed by\n\t\t// the presence of a junction row, even one that renders nothing here\n\t\t// (`hydrateBylinesMany` gates inference on `primaryBylineId`).\n\t\tconst hasExplicitCredit = (eb: any) =>\n\t\t\teb.exists(\n\t\t\t\teb\n\t\t\t\t\t.selectFrom(\"_emdash_content_bylines as cb\")\n\t\t\t\t\t.select(\"cb.id\")\n\t\t\t\t\t.where(\"cb.collection_slug\", \"=\", type)\n\t\t\t\t\t.whereRef(\"cb.content_id\", \"=\", idColumn),\n\t\t\t);\n\n\t\t// The entry's author owns a byline row — optionally within a given set\n\t\t// of translation groups — at the locale the list is scoped to. Matching\n\t\t// the locale is what keeps the filter agreeing with the list: an\n\t\t// inferred credit renders only when the author's byline has a row at\n\t\t// that locale (`hydrateBylinesMany` -> `findByUserIds`), and byline\n\t\t// translations start life with a null `user_id`, so a group translated\n\t\t// into the locale but not re-linked resolves to no credit. `locale`\n\t\t// falls back to each entry's own when the list spans locales.\n\t\tconst authorHasByline = (eb: any, bylineIds?: string[]) => {\n\t\t\tlet sub = eb\n\t\t\t\t.selectFrom(\"_emdash_bylines as b\")\n\t\t\t\t.select(\"b.id\")\n\t\t\t\t.whereRef(\"b.user_id\", \"=\", authorColumn);\n\t\t\tsub = filter.locale\n\t\t\t\t? sub.where(\"b.locale\", \"=\", filter.locale)\n\t\t\t\t: sub.whereRef(\"b.locale\", \"=\", localeColumn);\n\t\t\tif (bylineIds) sub = sub.where(\"b.translation_group\", \"in\", bylineIds);\n\t\t\treturn eb.exists(sub);\n\t\t};\n\n\t\tif (filter.mode === \"none\") {\n\t\t\treturn query.where((eb: any) => {\n\t\t\t\tconst uncredited = eb.not(creditRenders(eb));\n\t\t\t\t// With inference on, \"no byline\" means none is rendered, so an\n\t\t\t\t// entry that falls through to an author byline is excluded too.\n\t\t\t\treturn filter.includeInferred\n\t\t\t\t\t? eb.and([uncredited, eb.or([hasExplicitCredit(eb), eb.not(authorHasByline(eb))])])\n\t\t\t\t\t: uncredited;\n\t\t\t});\n\t\t}\n\n\t\tconst bylineIds = filter.bylineIds ?? [];\n\t\tif (bylineIds.length === 0) {\n\t\t\t// A filter that resolved to no ids must match nothing rather than\n\t\t\t// silently degrade to \"no filter\" and return the whole collection.\n\t\t\treturn query.where(() => sql<boolean>`1 = 0`);\n\t\t}\n\n\t\treturn query.where((eb: any) => {\n\t\t\tif (!filter.includeInferred) return creditRenders(eb, bylineIds);\n\t\t\t// Inference applies only where no explicit credit exists, so an\n\t\t\t// entry credited to someone else never matches on its author.\n\t\t\treturn eb.or([\n\t\t\t\tcreditRenders(eb, bylineIds),\n\t\t\t\teb.and([eb.not(hasExplicitCredit(eb)), authorHasByline(eb, bylineIds)]),\n\t\t\t]);\n\t\t});\n\t}\n\n\t/**\n\t * Count content items\n\t */\n\tasync count(type: string, where?: FindManyOptions[\"where\"]): Promise<number> {\n\t\tconst resolvedFieldFilters = await this.resolveFieldFilters(type, where?.fieldFilters);\n\t\treturn this.countWithResolvedFilters(type, where, resolvedFieldFilters);\n\t}\n\n\tprivate async countWithResolvedFilters(\n\t\ttype: string,\n\t\twhere: FindManyOptions[\"where\"] | undefined,\n\t\tresolvedFieldFilters: ResolvedFieldFilter[],\n\t): Promise<number> {\n\t\tconst tableName = getTableName(type);\n\n\t\tlet query = this.db\n\t\t\t.selectFrom(tableName as keyof Database)\n\t\t\t.select((eb) => eb.fn.count(\"id\").as(\"count\"))\n\t\t\t.where(\"deleted_at\" as never, \"is\", null);\n\n\t\tif (where?.status) {\n\t\t\tquery = query.where(\"status\", \"=\", where.status);\n\t\t}\n\n\t\tif (where?.authorId) {\n\t\t\tquery = query.where(\"author_id\", \"=\", where.authorId);\n\t\t}\n\n\t\tif (where?.locale) {\n\t\t\tquery = query.where(\"locale\" as any, \"=\", where.locale);\n\t\t}\n\n\t\tquery = this.applySearchFilter(query, where, type);\n\t\tquery = this.applyDateFilter(query, where);\n\t\tquery = this.applyBylineFilter(query, where, type);\n\t\tquery = this.applyFieldFilters(query, resolvedFieldFilters);\n\n\t\tconst result = await query.executeTakeFirst();\n\t\treturn Number(result?.count || 0);\n\t}\n\n\t/**\n\t * Distinct, non-null `author_id` values across the collection's live\n\t * (non-trashed) content. Used to populate the admin author filter with\n\t * only the users who have actually authored entries, rather than the\n\t * full user directory (which requires admin privileges to read).\n\t */\n\tasync findDistinctAuthorIds(type: string): Promise<string[]> {\n\t\tconst tableName = getTableName(type);\n\n\t\tconst rows = await this.db\n\t\t\t.selectFrom(tableName as keyof Database)\n\t\t\t.select(\"author_id\")\n\t\t\t.distinct()\n\t\t\t.where(\"deleted_at\" as never, \"is\", null)\n\t\t\t.where(\"author_id\" as never, \"is not\", null)\n\t\t\t.execute();\n\n\t\treturn rows.map((row) => row.author_id).filter((id): id is string => id !== null);\n\t}\n\n\t// get overall statistics for a content type in a single query\n\tasync getStats(\n\t\ttype: string,\n\t\tnow = new Date(),\n\t): Promise<{\n\t\ttotal: number;\n\t\tpublished: number;\n\t\tdraft: number;\n\t\tscheduled: number;\n\t\toverdueScheduled: number;\n\t}> {\n\t\tconst tableName = getTableName(type);\n\t\tconst nowIso = now.toISOString();\n\n\t\tconst result = await this.db\n\t\t\t.selectFrom(tableName as keyof Database)\n\t\t\t.select((eb) => [\n\t\t\t\teb.fn.count(\"id\").as(\"total\"),\n\t\t\t\teb.fn.sum(eb.case().when(\"status\", \"=\", \"published\").then(1).else(0).end()).as(\"published\"),\n\t\t\t\teb.fn.sum(eb.case().when(\"status\", \"=\", \"draft\").then(1).else(0).end()).as(\"draft\"),\n\t\t\t\tsql<number>`SUM(CASE WHEN scheduled_at IS NOT NULL THEN 1 ELSE 0 END)`.as(\"scheduled\"),\n\t\t\t\tsql<number>`SUM(CASE WHEN scheduled_at IS NOT NULL AND scheduled_at <= ${nowIso} THEN 1 ELSE 0 END)`.as(\n\t\t\t\t\t\"overdue_scheduled\",\n\t\t\t\t),\n\t\t\t])\n\t\t\t.where(\"deleted_at\" as never, \"is\", null)\n\t\t\t.executeTakeFirst();\n\n\t\treturn {\n\t\t\ttotal: Number(result?.total || 0),\n\t\t\tpublished: Number(result?.published || 0),\n\t\t\tdraft: Number(result?.draft || 0),\n\t\t\tscheduled: Number(result?.scheduled || 0),\n\t\t\toverdueScheduled: Number(result?.overdue_scheduled || 0),\n\t\t};\n\t}\n\n\t/**\n\t * Schedule content for future publishing\n\t *\n\t * Sets status to 'scheduled' and stores the scheduled publish time.\n\t * The content will be auto-published when the scheduled time is reached.\n\t */\n\tasync schedule(type: string, id: string, scheduledAt: string): Promise<ContentItem> {\n\t\tconst tableName = getTableName(type);\n\t\tconst now = new Date().toISOString();\n\n\t\t// Validate scheduledAt is in the future\n\t\tconst scheduledDate = new Date(scheduledAt);\n\t\tif (isNaN(scheduledDate.getTime())) {\n\t\t\tthrow new EmDashValidationError(\"Invalid scheduled date\");\n\t\t}\n\t\tif (scheduledDate <= new Date()) {\n\t\t\tthrow new EmDashValidationError(\"Scheduled date must be in the future\");\n\t\t}\n\n\t\tconst existing = await this.findById(type, id);\n\t\tif (!existing) {\n\t\t\tthrow new EmDashValidationError(\"Content item not found\");\n\t\t}\n\n\t\t// Published posts keep their status — the schedule applies to the\n\t\t// pending draft, not the currently-live revision. Unpublished posts\n\t\t// transition to 'scheduled' so they aren't visible before the time.\n\t\tconst newStatus = existing.status === \"published\" ? \"published\" : \"scheduled\";\n\n\t\tawait sql`\n\t\t\tUPDATE ${sql.ref(tableName)}\n\t\t\tSET status = ${newStatus},\n\t\t\t\tscheduled_at = ${scheduledAt},\n\t\t\t\tupdated_at = ${now}\n\t\t\tWHERE id = ${id}\n\t\t\tAND deleted_at IS NULL\n\t\t`.execute(this.db);\n\n\t\tinvalidateCollectionCache(type);\n\n\t\tconst updated = await this.findById(type, id);\n\t\tif (!updated) {\n\t\t\tthrow new Error(\"Content not found\");\n\t\t}\n\n\t\treturn updated;\n\t}\n\n\t/**\n\t * Unschedule content\n\t *\n\t * Clears the scheduled time. Published posts stay published;\n\t * draft/scheduled posts revert to 'draft'.\n\t */\n\tasync unschedule(type: string, id: string): Promise<ContentItem> {\n\t\tconst tableName = getTableName(type);\n\t\tconst now = new Date().toISOString();\n\n\t\tconst existing = await this.findById(type, id);\n\t\tif (!existing) {\n\t\t\tthrow new EmDashValidationError(\"Content item not found\");\n\t\t}\n\n\t\t// Published posts keep their status — just clear the pending schedule.\n\t\t// Draft/scheduled posts revert to 'draft'.\n\t\tconst newStatus = existing.status === \"published\" ? \"published\" : \"draft\";\n\n\t\tawait sql`\n\t\t\tUPDATE ${sql.ref(tableName)}\n\t\t\tSET status = ${newStatus},\n\t\t\t\tscheduled_at = NULL,\n\t\t\t\tupdated_at = ${now}\n\t\t\tWHERE id = ${id}\n\t\t\tAND scheduled_at IS NOT NULL\n\t\t\tAND deleted_at IS NULL\n\t\t`.execute(this.db);\n\n\t\tinvalidateCollectionCache(type);\n\n\t\tconst updated = await this.findById(type, id);\n\t\tif (!updated) {\n\t\t\tthrow new Error(\"Content not found\");\n\t\t}\n\n\t\treturn updated;\n\t}\n\n\t/**\n\t * Find content that is ready to be published\n\t *\n\t * Returns all content where scheduled_at <= now, regardless of status.\n\t * This covers both draft-scheduled posts (status='scheduled') and\n\t * published posts with scheduled draft changes (status='published').\n\t *\n\t * `limit` (optional) caps how many due rows are returned, oldest-due first.\n\t * The scheduled-publishing sweep passes a limit so a large backlog can't\n\t * fan out unbounded publish/webhook work in a single tick (and blow a Worker\n\t * invocation's CPU/subrequest budget); the remainder drains on later ticks.\n\t */\n\tasync findReadyToPublish(type: string, limit?: number): Promise<ContentItem[]> {\n\t\tconst tableName = getTableName(type);\n\t\tconst now = new Date().toISOString();\n\n\t\t// Embed an empty fragment when unbounded so callers that want every due\n\t\t// row (manual flows, tests) keep the original behaviour.\n\t\tconst limitClause =\n\t\t\ttypeof limit === \"number\" && Number.isInteger(limit) && limit > 0\n\t\t\t\t? sql`LIMIT ${limit}`\n\t\t\t\t: sql``;\n\n\t\tconst result = await sql<Record<string, unknown>>`\n\t\t\tSELECT * FROM ${sql.ref(tableName)}\n\t\t\tWHERE scheduled_at IS NOT NULL\n\t\t\tAND scheduled_at <= ${now}\n\t\t\tAND deleted_at IS NULL\n\t\t\tORDER BY scheduled_at ASC\n\t\t\t${limitClause}\n\t\t`.execute(this.db);\n\n\t\treturn result.rows.map((row) => this.mapRow(type, row));\n\t}\n\n\t/**\n\t * Find all translations in a translation group\n\t */\n\tasync findTranslations(type: string, translationGroup: string): Promise<ContentItem[]> {\n\t\tconst tableName = getTableName(type);\n\n\t\tconst result = await sql<Record<string, unknown>>`\n\t\t\tSELECT * FROM ${sql.ref(tableName)}\n\t\t\tWHERE translation_group = ${translationGroup}\n\t\t\tAND deleted_at IS NULL\n\t\t\tORDER BY locale ASC\n\t\t`.execute(this.db);\n\n\t\treturn result.rows.map((row) => this.mapRow(type, row));\n\t}\n\n\t/**\n\t * Batch variant of {@link findTranslations}: every (non-deleted) locale\n\t * variant for any of `translationGroups`, in one `WHERE translation_group IN\n\t * (...)` query chunked at `SQL_BATCH_SIZE` for D1's bind-parameter limit.\n\t * Lets callers resolve many edge groups without an N+1 per group. The caller\n\t * groups the flat result by `translationGroup` itself.\n\t *\n\t * `translation_group` leads the sort so the ordering follows\n\t * `idx_{table}_del_tg_locale` past its `deleted_at` equality; callers group by\n\t * `translationGroup`, so the per-group locale order they rely on is preserved.\n\t *\n\t * `publishedOnly` restricts the result to `status = 'published'` — reference\n\t * reads pass this for callers without `content:read_drafts` so draft/scheduled\n\t * entries never leak through an edge traversal.\n\t *\n\t * A reference edge stores only a collection slug (no SQL FK), so the table may\n\t * have been dropped since the edge was written. That is a tolerated dangling\n\t * state, not an error: a missing table resolves to no rows, mirroring how the\n\t * content read handlers treat `isMissingTableError`.\n\t */\n\tasync findTranslationsForGroups(\n\t\ttype: string,\n\t\ttranslationGroups: string[],\n\t\toptions: { publishedOnly?: boolean } = {},\n\t): Promise<ContentItem[]> {\n\t\tif (translationGroups.length === 0) return [];\n\t\tconst tableName = getTableName(type);\n\t\tconst publishedFilter = options.publishedOnly ? sql`AND status = 'published'` : sql``;\n\n\t\tconst items: ContentItem[] = [];\n\t\ttry {\n\t\t\tfor (const chunk of chunks(translationGroups, SQL_BATCH_SIZE)) {\n\t\t\t\tconst result = await sql<Record<string, unknown>>`\n\t\t\t\t\tSELECT * FROM ${sql.ref(tableName)}\n\t\t\t\t\tWHERE translation_group IN (${sql.join(chunk)})\n\t\t\t\t\tAND deleted_at IS NULL\n\t\t\t\t\t${publishedFilter}\n\t\t\t\t\tORDER BY translation_group ASC, locale ASC\n\t\t\t\t`.execute(this.db);\n\t\t\t\tfor (const row of result.rows) items.push(this.mapRow(type, row));\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (isMissingTableError(error)) return [];\n\t\t\tthrow error;\n\t\t}\n\t\treturn items;\n\t}\n\n\t/**\n\t * Batch variant of {@link findByIdOrSlug}: resolve many identifiers (each an\n\t * id OR a slug) within `type` in a constant number of queries — one `WHERE id\n\t * IN (...)` and one `WHERE slug IN (...)`, each chunked at `SQL_BATCH_SIZE`.\n\t * Returns a map from the input identifier to its resolved item; identifiers\n\t * that match nothing are absent. Used on write paths that accept a list of\n\t * references, so a single request doesn't fan out to an N+1 of point lookups.\n\t *\n\t * Resolution mirrors {@link findByIdOrSlug}: a ULID-shaped identifier prefers\n\t * the id match and falls back to slug; anything else prefers the slug match\n\t * and falls back to id. Slug matches collapse to the lowest-locale variant\n\t * (`ORDER BY locale ASC`), matching the slug-without-locale lookup.\n\t */\n\tasync findManyByIdOrSlug(type: string, identifiers: string[]): Promise<Map<string, ContentItem>> {\n\t\tconst resolved = new Map<string, ContentItem>();\n\t\tconst unique = [...new Set(identifiers)];\n\t\tif (unique.length === 0) return resolved;\n\n\t\tconst tableName = getTableName(type);\n\t\tconst byId = new Map<string, ContentItem>();\n\t\tconst bySlug = new Map<string, ContentItem>();\n\n\t\ttry {\n\t\t\tfor (const chunk of chunks(unique, SQL_BATCH_SIZE)) {\n\t\t\t\tconst idRows = await sql<Record<string, unknown>>`\n\t\t\t\t\tSELECT * FROM ${sql.ref(tableName)}\n\t\t\t\t\tWHERE id IN (${sql.join(chunk)})\n\t\t\t\t\tAND deleted_at IS NULL\n\t\t\t\t`.execute(this.db);\n\t\t\t\tfor (const row of idRows.rows) {\n\t\t\t\t\tconst item = this.mapRow(type, row);\n\t\t\t\t\tbyId.set(item.id, item);\n\t\t\t\t}\n\n\t\t\t\tconst slugRows = await sql<Record<string, unknown>>`\n\t\t\t\t\tSELECT * FROM ${sql.ref(tableName)}\n\t\t\t\t\tWHERE slug IN (${sql.join(chunk)})\n\t\t\t\t\tAND deleted_at IS NULL\n\t\t\t\t\tORDER BY locale ASC\n\t\t\t\t`.execute(this.db);\n\t\t\t\tfor (const row of slugRows.rows) {\n\t\t\t\t\tconst item = this.mapRow(type, row);\n\t\t\t\t\t// First write wins → lowest locale, matching findBySlug without a locale.\n\t\t\t\t\tif (item.slug != null && !bySlug.has(item.slug)) bySlug.set(item.slug, item);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\t// A collection dropped after a relation was created leaves the relation\n\t\t\t// pointing at a missing table. Treat it like an empty collection (no\n\t\t\t// matches) so callers surface a structured NOT_FOUND, not a 500 —\n\t\t\t// mirroring findTranslationsForGroups.\n\t\t\tif (isMissingTableError(error)) return resolved;\n\t\t\tthrow error;\n\t\t}\n\n\t\tfor (const identifier of unique) {\n\t\t\tconst looksLikeUlid = ULID_PATTERN.test(identifier);\n\t\t\tconst item = looksLikeUlid\n\t\t\t\t? (byId.get(identifier) ?? bySlug.get(identifier))\n\t\t\t\t: (bySlug.get(identifier) ?? byId.get(identifier));\n\t\t\tif (item) resolved.set(identifier, item);\n\t\t}\n\t\treturn resolved;\n\t}\n\n\t/**\n\t * Publish the current draft\n\t *\n\t * Promotes draft_revision_id to live_revision_id and clears draft pointer.\n\t * Syncs the draft revision's data into the content table columns so the\n\t * content table always reflects the published version.\n\t * If no draft revision exists, creates one from current data and publishes it.\n\t * When `promoteRevision` is false, publishes the current content-table data\n\t * by changing lifecycle metadata only.\n\t *\n\t * `publishedAt` (optional) overrides the publication timestamp. If omitted,\n\t * the existing `published_at` is preserved (idempotent re-publish keeps the\n\t * original date) and falls back to the current time on first publish. Pass\n\t * an explicit value to backdate a publish (e.g. when migrating content from\n\t * another CMS).\n\t *\n\t * `requireDue` gates the final update on the row still being due.\n\t * `expectedScheduledAt` additionally fences changes made after a sweep\n\t * selected the row but before publication preparation began.\n\t */\n\tasync publish(\n\t\ttype: string,\n\t\tid: string,\n\t\tpublishedAt?: string,\n\t\trequireDue = false,\n\t\texpectedScheduledAt?: string,\n\t\tpromoteRevision = true,\n\t\trequireSlug = true,\n\t): Promise<ContentItem> {\n\t\tconst tableName = getTableName(type);\n\t\tconst now = new Date().toISOString();\n\n\t\tconst existing = await this.findById(type, id);\n\t\tif (!existing) {\n\t\t\tthrow new EmDashValidationError(\"Content item not found\");\n\t\t}\n\t\tif (\n\t\t\trequireDue &&\n\t\t\texpectedScheduledAt !== undefined &&\n\t\t\texisting.scheduledAt !== expectedScheduledAt\n\t\t) {\n\t\t\tthrow new ScheduledNotDueError();\n\t\t}\n\t\tif (!promoteRevision && requireSlug && !existing.slug?.trim()) {\n\t\t\tthrow new EmDashValidationError(\"Cannot publish routable content without a slug\");\n\t\t}\n\n\t\tif (!promoteRevision) {\n\t\t\tconst revisionRepo = new RevisionRepository(this.db);\n\t\t\tlet provisionalRevisionId: string | null = null;\n\t\t\ttry {\n\t\t\t\tlet liveRevisionId = existing.liveRevisionId;\n\t\t\t\tif (!liveRevisionId) {\n\t\t\t\t\tconst revision = await revisionRepo.create({\n\t\t\t\t\t\tcollection: type,\n\t\t\t\t\t\tentryId: id,\n\t\t\t\t\t\tdata: existing.data,\n\t\t\t\t\t});\n\t\t\t\t\tliveRevisionId = revision.id;\n\t\t\t\t\tprovisionalRevisionId = revision.id;\n\t\t\t\t}\n\n\t\t\t\tconst intendedPublishedAt = publishedAt ?? existing.publishedAt ?? now;\n\t\t\t\tconst duePredicate = requireDue\n\t\t\t\t\t? sql`AND scheduled_at IS NOT NULL AND scheduled_at <= ${now}`\n\t\t\t\t\t: sql``;\n\t\t\t\tlet published = false;\n\t\t\t\ttry {\n\t\t\t\t\tconst result = await sql`\n\t\t\t\t\t\tUPDATE ${sql.ref(tableName)}\n\t\t\t\t\t\tSET live_revision_id = ${liveRevisionId},\n\t\t\t\t\t\t\tdraft_revision_id = NULL,\n\t\t\t\t\t\t\tstatus = 'published',\n\t\t\t\t\t\t\tscheduled_at = NULL,\n\t\t\t\t\t\t\tpublished_at = ${intendedPublishedAt},\n\t\t\t\t\t\t\tupdated_at = ${now},\n\t\t\t\t\t\t\tversion = version + 1\n\t\t\t\t\t\tWHERE id = ${id}\n\t\t\t\t\t\tAND deleted_at IS NULL\n\t\t\t\t\t\tAND version = ${existing.version}\n\t\t\t\t\t\tAND status = ${existing.status}\n\t\t\t\t\t\tAND ${nullableColumnMatch(\"live_revision_id\", existing.liveRevisionId)}\n\t\t\t\t\t\tAND ${nullableColumnMatch(\"draft_revision_id\", existing.draftRevisionId)}\n\t\t\t\t\t\tAND ${nullableColumnMatch(\"scheduled_at\", existing.scheduledAt)}\n\t\t\t\t\t\t${duePredicate}\n\t\t\t\t\t`.execute(this.db);\n\t\t\t\t\tpublished = (result.numAffectedRows ?? 0n) > 0n;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (isConfirmedStatementFailure(error)) throw error;\n\t\t\t\t\tlet observed: ContentItem | null;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tobserved = await this.findById(type, id);\n\t\t\t\t\t} catch (reconciliationError) {\n\t\t\t\t\t\tthrow new Error(\"Unable to confirm whether content publication completed\", {\n\t\t\t\t\t\t\tcause: reconciliationError,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tif (!observed) {\n\t\t\t\t\t\tthrow new Error(\"Unable to confirm whether content publication completed\", {\n\t\t\t\t\t\t\tcause: error,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tpublished = matchesLifecyclePublication(\n\t\t\t\t\t\tobserved,\n\t\t\t\t\t\texisting,\n\t\t\t\t\t\tliveRevisionId,\n\t\t\t\t\t\tintendedPublishedAt,\n\t\t\t\t\t\tnow,\n\t\t\t\t\t);\n\t\t\t\t\tif (!published && matchesPublicationFence(observed, existing)) throw error;\n\t\t\t\t\tif (!published) {\n\t\t\t\t\t\tthrow new Error(\"Unable to confirm whether content publication completed\", {\n\t\t\t\t\t\t\tcause: error,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!published) {\n\t\t\t\t\tthrow requireDue ? new ScheduledNotDueError() : new ContentMutationConflictError();\n\t\t\t\t}\n\n\t\t\t\tinvalidateCollectionCache(type);\n\t\t\t\tconst updated = await this.findById(type, id);\n\t\t\t\tif (!updated) throw new Error(\"Content not found\");\n\t\t\t\treturn updated;\n\t\t\t} catch (error) {\n\t\t\t\tif (provisionalRevisionId) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait revisionRepo.deleteIfUnreferenced(type, id, provisionalRevisionId);\n\t\t\t\t\t} catch (cleanupError) {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`[content] Failed to clean up provisional revision ${provisionalRevisionId}:`,\n\t\t\t\t\t\t\tcleanupError,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\n\t\tconst revisionRepo = new RevisionRepository(this.db);\n\t\tlet provisionalRevisionId: string | null = null;\n\t\ttry {\n\t\t\tlet revisionToPublish = existing.draftRevisionId || existing.liveRevisionId;\n\n\t\t\tif (!revisionToPublish) {\n\t\t\t\tconst revision = await revisionRepo.create({\n\t\t\t\t\tcollection: type,\n\t\t\t\t\tentryId: id,\n\t\t\t\t\tdata: existing.data,\n\t\t\t\t});\n\t\t\t\trevisionToPublish = revision.id;\n\t\t\t\tprovisionalRevisionId = revision.id;\n\t\t\t}\n\n\t\t\tconst revision = await revisionRepo.findById(revisionToPublish);\n\t\t\tif (!revision || revision.collection !== type || revision.entryId !== id) {\n\t\t\t\tthrow new EmDashValidationError(\"Revision does not belong to the specified content item\");\n\t\t\t}\n\n\t\t\tconst stagedSlug = typeof revision.data._slug === \"string\" ? revision.data._slug : null;\n\t\t\tconst intendedSlug = stagedSlug ?? existing.slug;\n\t\t\tif (requireSlug && !intendedSlug?.trim()) {\n\t\t\t\tthrow new EmDashValidationError(\"Cannot publish routable content without a slug\");\n\t\t\t}\n\t\t\tconst intendedPublishedAt = publishedAt ?? existing.publishedAt ?? now;\n\t\t\tif (stagedSlug !== null && stagedSlug !== existing.slug && existing.locale !== null) {\n\t\t\t\tconst conflict = await this.findBySlugIncludingTrashed(type, stagedSlug, existing.locale);\n\t\t\t\tif (conflict && conflict.id !== id) {\n\t\t\t\t\tthrow new EmDashValidationError(\n\t\t\t\t\t\t`Cannot publish: slug '${stagedSlug}' is already used by another entry` +\n\t\t\t\t\t\t\t` in this collection (id: ${conflict.id}). Choose a different slug.`,\n\t\t\t\t\t\t{ code: \"SLUG_CONFLICT\" },\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst assignments: ReturnType<typeof sql>[] = [];\n\t\t\tif (stagedSlug !== null) assignments.push(sql`slug = ${stagedSlug}`);\n\t\t\tfor (const [key, value] of Object.entries(revision.data)) {\n\t\t\t\tif (SYSTEM_COLUMNS.has(key) || key.startsWith(\"_\")) continue;\n\t\t\t\tvalidateIdentifier(key, \"content field name\");\n\t\t\t\tassignments.push(sql`${sql.ref(key)} = ${serializeValue(value)}`);\n\t\t\t}\n\t\t\tassignments.push(\n\t\t\t\tsql`live_revision_id = ${revisionToPublish}`,\n\t\t\t\tsql`draft_revision_id = NULL`,\n\t\t\t\tsql`status = 'published'`,\n\t\t\t\tsql`scheduled_at = NULL`,\n\t\t\t\tsql`published_at = ${intendedPublishedAt}`,\n\t\t\t\tsql`updated_at = ${now}`,\n\t\t\t\tsql`version = version + 1`,\n\t\t\t);\n\n\t\t\tconst duePredicate = requireDue\n\t\t\t\t? sql`AND scheduled_at IS NOT NULL AND scheduled_at <= ${now}`\n\t\t\t\t: sql``;\n\t\t\tlet promoted = false;\n\t\t\ttry {\n\t\t\t\tconst result = await sql`\n\t\t\t\t\tUPDATE ${sql.ref(tableName)}\n\t\t\t\t\tSET ${sql.join(assignments, sql`, `)}\n\t\t\t\t\tWHERE id = ${id}\n\t\t\t\t\tAND deleted_at IS NULL\n\t\t\t\t\tAND version = ${existing.version}\n\t\t\t\t\tAND status = ${existing.status}\n\t\t\t\t\tAND ${nullableColumnMatch(\"live_revision_id\", existing.liveRevisionId)}\n\t\t\t\t\tAND ${nullableColumnMatch(\"draft_revision_id\", existing.draftRevisionId)}\n\t\t\t\t\tAND ${nullableColumnMatch(\"scheduled_at\", existing.scheduledAt)}\n\t\t\t\t\t${duePredicate}\n\t\t\t\t\tAND EXISTS (\n\t\t\t\t\t\tSELECT 1 FROM revisions\n\t\t\t\t\t\tWHERE revisions.id = ${revisionToPublish}\n\t\t\t\t\t\tAND revisions.collection = ${type}\n\t\t\t\t\t\tAND revisions.entry_id = ${id}\n\t\t\t\t\t)\n\t\t\t\t`.execute(this.db);\n\t\t\t\tpromoted = (result.numAffectedRows ?? 0n) > 0n;\n\t\t\t} catch (error) {\n\t\t\t\tif (isConfirmedStatementFailure(error)) throw error;\n\t\t\t\tlet observed: ContentItem | null;\n\t\t\t\ttry {\n\t\t\t\t\tobserved = await this.findById(type, id);\n\t\t\t\t} catch (reconciliationError) {\n\t\t\t\t\tthrow new Error(\"Unable to confirm whether content publication completed\", {\n\t\t\t\t\t\tcause: reconciliationError,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (!observed) {\n\t\t\t\t\tthrow new Error(\"Unable to confirm whether content publication completed\", {\n\t\t\t\t\t\tcause: error,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tpromoted = matchesPublication(\n\t\t\t\t\tobserved,\n\t\t\t\t\texisting,\n\t\t\t\t\trevision,\n\t\t\t\t\trevisionToPublish,\n\t\t\t\t\tintendedSlug,\n\t\t\t\t\tintendedPublishedAt,\n\t\t\t\t\tnow,\n\t\t\t\t);\n\t\t\t\tif (!promoted && matchesPublicationFence(observed, existing)) throw error;\n\t\t\t\tif (!promoted) {\n\t\t\t\t\tthrow new Error(\"Unable to confirm whether content publication completed\", {\n\t\t\t\t\t\tcause: error,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!promoted) {\n\t\t\t\tthrow requireDue ? new ScheduledNotDueError() : new ContentMutationConflictError();\n\t\t\t}\n\n\t\t\tinvalidateCollectionCache(type);\n\t\t\tconst updated = await this.findById(type, id);\n\t\t\tif (!updated) {\n\t\t\t\tthrow new Error(\"Content not found\");\n\t\t\t}\n\n\t\t\treturn updated;\n\t\t} catch (error) {\n\t\t\tif (provisionalRevisionId) {\n\t\t\t\ttry {\n\t\t\t\t\tawait revisionRepo.deleteIfUnreferenced(type, id, provisionalRevisionId);\n\t\t\t\t} catch (cleanupError) {\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t`[content] Failed to clean up provisional revision ${provisionalRevisionId}:`,\n\t\t\t\t\t\tcleanupError,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Unpublish content\n\t *\n\t * Removes live pointer but preserves draft. If no draft exists,\n\t * creates one from the live version so the content isn't lost.\n\t */\n\tasync unpublish(type: string, id: string): Promise<ContentItem> {\n\t\tconst tableName = getTableName(type);\n\t\tconst now = new Date().toISOString();\n\n\t\tconst existing = await this.findById(type, id);\n\t\tif (!existing) {\n\t\t\tthrow new EmDashValidationError(\"Content item not found\");\n\t\t}\n\n\t\t// If no draft exists, create one from the live version\n\t\tif (!existing.draftRevisionId && existing.liveRevisionId) {\n\t\t\tconst revisionRepo = new RevisionRepository(this.db);\n\t\t\tconst liveRevision = await revisionRepo.findById(existing.liveRevisionId);\n\t\t\tif (liveRevision) {\n\t\t\t\tconst draft = await revisionRepo.create({\n\t\t\t\t\tcollection: type,\n\t\t\t\t\tentryId: id,\n\t\t\t\t\tdata: liveRevision.data,\n\t\t\t\t});\n\n\t\t\t\tawait sql`\n\t\t\t\t\tUPDATE ${sql.ref(tableName)}\n\t\t\t\t\tSET draft_revision_id = ${draft.id}\n\t\t\t\t\tWHERE id = ${id}\n\t\t\t\t`.execute(this.db);\n\t\t\t}\n\t\t}\n\n\t\tawait sql`\n\t\t\tUPDATE ${sql.ref(tableName)}\n\t\t\tSET live_revision_id = NULL,\n\t\t\t\tstatus = 'draft',\n\t\t\t\tpublished_at = NULL,\n\t\t\t\tupdated_at = ${now}\n\t\t\tWHERE id = ${id}\n\t\t\tAND deleted_at IS NULL\n\t\t`.execute(this.db);\n\n\t\tinvalidateCollectionCache(type);\n\n\t\tconst updated = await this.findById(type, id);\n\t\tif (!updated) {\n\t\t\tthrow new Error(\"Content not found\");\n\t\t}\n\n\t\treturn updated;\n\t}\n\n\t/**\n\t * Set the draft revision pointer for a content item.\n\t *\n\t * Used by seed/import paths that stage a new revision's data before\n\t * promoting it to live via `publish()`.\n\t *\n\t * Validates that the content item exists and is not soft-deleted, that\n\t * the revision exists, and that the revision belongs to the same\n\t * collection and entry. Without these checks, a caller could leave the\n\t * content row pointing at a missing or unrelated revision.\n\t */\n\tasync setDraftRevision(type: string, id: string, revisionId: string): Promise<void> {\n\t\tconst existing = await this.findById(type, id);\n\t\tif (!existing) {\n\t\t\tthrow new EmDashValidationError(\"Content item not found\");\n\t\t}\n\n\t\tconst revisionRepo = new RevisionRepository(this.db);\n\t\tconst revision = await revisionRepo.findById(revisionId);\n\t\tif (!revision) {\n\t\t\tthrow new EmDashValidationError(\"Revision not found\");\n\t\t}\n\n\t\tif (revision.collection !== type || revision.entryId !== id) {\n\t\t\tthrow new EmDashValidationError(\"Revision does not belong to the specified content item\");\n\t\t}\n\n\t\tif (!(await this.replaceDraftRevision(type, id, revisionId, existing))) {\n\t\t\tthrow new ContentMutationConflictError();\n\t\t}\n\t}\n\n\tasync replaceDraftRevision(\n\t\ttype: string,\n\t\tid: string,\n\t\trevisionId: string,\n\t\texpected: Pick<ContentItem, \"version\" | \"liveRevisionId\" | \"draftRevisionId\">,\n\t): Promise<boolean> {\n\t\tconst tableName = getTableName(type);\n\t\tconst result = await sql`\n\t\t\tUPDATE ${sql.ref(tableName)}\n\t\t\tSET draft_revision_id = ${revisionId},\n\t\t\t\tversion = version + 1\n\t\t\tWHERE id = ${id}\n\t\t\tAND deleted_at IS NULL\n\t\t\tAND version = ${expected.version}\n\t\t\tAND ${nullableColumnMatch(\"live_revision_id\", expected.liveRevisionId)}\n\t\t\tAND ${nullableColumnMatch(\"draft_revision_id\", expected.draftRevisionId)}\n\t\t\tAND EXISTS (\n\t\t\t\tSELECT 1 FROM revisions\n\t\t\t\tWHERE revisions.id = ${revisionId}\n\t\t\t\tAND revisions.collection = ${type}\n\t\t\t\tAND revisions.entry_id = ${id}\n\t\t\t)\n\t\t`.execute(this.db);\n\t\treturn (result.numAffectedRows ?? 0n) > 0n;\n\t}\n\n\t/**\n\t * Discard pending draft changes\n\t *\n\t * Clears draft_revision_id. The content table columns already hold the\n\t * published version, so no data sync is needed.\n\t */\n\tasync discardDraft(type: string, id: string): Promise<ContentItem> {\n\t\tconst tableName = getTableName(type);\n\n\t\tconst existing = await this.findById(type, id);\n\t\tif (!existing) {\n\t\t\tthrow new EmDashValidationError(\"Content item not found\");\n\t\t}\n\n\t\tif (!existing.draftRevisionId) {\n\t\t\t// No draft to discard\n\t\t\treturn existing;\n\t\t}\n\n\t\t// Discarding a draft restores the state from before the draft was\n\t\t// staged — nothing about the live entry changed in between, so\n\t\t// updated_at stays at its pre-draft value (#2143).\n\t\tawait sql`\n\t\t\tUPDATE ${sql.ref(tableName)}\n\t\t\tSET draft_revision_id = NULL\n\t\t\tWHERE id = ${id}\n\t\t\tAND deleted_at IS NULL\n\t\t`.execute(this.db);\n\n\t\tconst updated = await this.findById(type, id);\n\t\tif (!updated) {\n\t\t\tthrow new Error(\"Content not found\");\n\t\t}\n\n\t\treturn updated;\n\t}\n\n\t/**\n\t * Count content items with a pending schedule.\n\t * Includes both draft-scheduled (status='scheduled') and published\n\t * posts with scheduled draft changes (status='published', scheduled_at set).\n\t */\n\tasync countScheduled(type: string): Promise<number> {\n\t\tconst tableName = getTableName(type);\n\n\t\tconst result = await sql<{ count: number }>`\n\t\t\tSELECT COUNT(id) as count FROM ${sql.ref(tableName)}\n\t\t\tWHERE scheduled_at IS NOT NULL\n\t\t\tAND deleted_at IS NULL\n\t\t`.execute(this.db);\n\n\t\treturn Number(result.rows[0]?.count || 0);\n\t}\n\n\t/**\n\t * Map database row to ContentItem\n\t * Extracts system columns and puts content fields in data\n\t * Excludes null values from data to match input semantics\n\t */\n\tprivate mapRow(type: string, row: Record<string, unknown>): ContentItem {\n\t\tconst data: Record<string, unknown> = {};\n\n\t\tfor (const [key, value] of Object.entries(row)) {\n\t\t\tif (!SYSTEM_COLUMNS.has(key) && value !== null) {\n\t\t\t\tdata[key] = deserializeValue(value);\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tid: row.id as string,\n\t\t\ttype,\n\t\t\tslug: row.slug as string | null,\n\t\t\tstatus: row.status as string,\n\t\t\tdata,\n\t\t\tauthorId: row.author_id as string | null,\n\t\t\tprimaryBylineId: (row.primary_byline_id as string | null) ?? null,\n\t\t\tcreatedAt: row.created_at as string,\n\t\t\tupdatedAt: row.updated_at as string,\n\t\t\tpublishedAt: row.published_at as string | null,\n\t\t\tscheduledAt: row.scheduled_at as string | null,\n\t\t\tliveRevisionId: (row.live_revision_id as string | null) ?? null,\n\t\t\tdraftRevisionId: (row.draft_revision_id as string | null) ?? null,\n\t\t\tversion: typeof row.version === \"number\" ? row.version : 1,\n\t\t\tlocale: (row.locale as string) ?? null,\n\t\t\ttranslationGroup: (row.translation_group as string) ?? null,\n\t\t};\n\t}\n\n\tprivate normalizeFilterScalar(\n\t\tfield: string,\n\t\ttype: FieldType,\n\t\tvalue: unknown,\n\t): NormalizedFilterScalar {\n\t\tif (type === \"number\" || type === \"integer\") {\n\t\t\tif (typeof value !== \"number\" || !Number.isFinite(value)) {\n\t\t\t\tthrow new EmDashValidationError(`Filter for field \"${field}\" must use a finite number`);\n\t\t\t}\n\t\t\tif (type === \"integer\" && !Number.isInteger(value)) {\n\t\t\t\tthrow new EmDashValidationError(`Filter for field \"${field}\" must use an integer`);\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\n\t\tif (type === \"boolean\") {\n\t\t\tif (typeof value !== \"boolean\") {\n\t\t\t\tthrow new EmDashValidationError(`Filter for field \"${field}\" must use a boolean`);\n\t\t\t}\n\t\t\treturn value ? 1 : 0;\n\t\t}\n\n\t\tif (typeof value !== \"string\") {\n\t\t\tthrow new EmDashValidationError(`Filter for field \"${field}\" must use a string`);\n\t\t}\n\t\tif (value.length > MAX_FILTER_STRING_LENGTH) {\n\t\t\tthrow new EmDashValidationError(\n\t\t\t\t`Filter value for field \"${field}\" exceeds ${MAX_FILTER_STRING_LENGTH} characters`,\n\t\t\t);\n\t\t}\n\t\treturn value;\n\t}\n\n\tprivate normalizeFieldFilter(\n\t\tfield: string,\n\t\ttype: FieldType,\n\t\tvalue: ContentFieldFilterValue,\n\t): ResolvedFieldFilter {\n\t\tif (value === null) return { column: field, kind: \"null\" };\n\t\tif (typeof value !== \"object\") {\n\t\t\treturn {\n\t\t\t\tcolumn: field,\n\t\t\t\tkind: \"exact\",\n\t\t\t\tvalue: this.normalizeFilterScalar(field, type, value),\n\t\t\t};\n\t\t}\n\t\tif (Array.isArray(value)) {\n\t\t\tthrow new EmDashValidationError(`Invalid filter for field \"${field}\"`);\n\t\t}\n\n\t\tconst record = value as Record<string, unknown>;\n\t\tconst keys = Object.keys(record);\n\t\tif (keys.length === 1 && keys[0] === \"in\") {\n\t\t\tif (!Array.isArray(record.in) || record.in.length === 0) {\n\t\t\t\tthrow new EmDashValidationError(`IN filter for field \"${field}\" must not be empty`);\n\t\t\t}\n\t\t\tif (record.in.length > MAX_IN_FILTER_VALUES) {\n\t\t\t\tthrow new EmDashValidationError(\n\t\t\t\t\t`IN filter for field \"${field}\" exceeds ${MAX_IN_FILTER_VALUES} values`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tcolumn: field,\n\t\t\t\tkind: \"in\",\n\t\t\t\tvalues: record.in.map((entry) => this.normalizeFilterScalar(field, type, entry)),\n\t\t\t};\n\t\t}\n\n\t\tconst rangeKeys = new Set([\"gt\", \"gte\", \"lt\", \"lte\"]);\n\t\tif (keys.length === 0 || keys.some((key) => !rangeKeys.has(key))) {\n\t\t\tthrow new EmDashValidationError(`Invalid filter operator for field \"${field}\"`);\n\t\t}\n\t\tif (type === \"boolean\") {\n\t\t\tthrow new EmDashValidationError(`Boolean field \"${field}\" does not support range filters`);\n\t\t}\n\n\t\tconst bounds: Partial<Record<\"gt\" | \"gte\" | \"lt\" | \"lte\", NormalizedFilterScalar>> = {};\n\t\tfor (const key of keys as Array<\"gt\" | \"gte\" | \"lt\" | \"lte\">) {\n\t\t\tif (record[key] === undefined) continue;\n\t\t\tbounds[key] = this.normalizeFilterScalar(field, type, record[key]);\n\t\t}\n\t\tif (Object.keys(bounds).length === 0) {\n\t\t\tthrow new EmDashValidationError(`Range filter for field \"${field}\" has no bounds`);\n\t\t}\n\t\treturn { column: field, kind: \"range\", bounds };\n\t}\n\n\tprivate async collectionExists(type: string): Promise<boolean> {\n\t\tconst collection = await this.db\n\t\t\t.selectFrom(\"_emdash_collections\")\n\t\t\t.where(\"slug\", \"=\", type)\n\t\t\t.select(\"id\")\n\t\t\t.executeTakeFirst();\n\t\treturn collection !== undefined;\n\t}\n\n\tprivate async resolveFieldFilters(\n\t\ttype: string,\n\t\tfilters: ContentFieldFilters | undefined,\n\t): Promise<ResolvedFieldFilter[]> {\n\t\tconst resolvedFilters = filters ?? {};\n\t\tconst fields = Object.keys(resolvedFilters);\n\t\tif (fields.length === 0) return [];\n\t\tif (fields.length > MAX_INDEXED_FIELD_FILTERS) {\n\t\t\tif (!(await this.collectionExists(type))) return [];\n\t\t\tthrow new EmDashValidationError(\n\t\t\t\t`Content list queries support at most ${MAX_INDEXED_FIELD_FILTERS} indexed field filters`,\n\t\t\t);\n\t\t}\n\t\tconst rows = await this.db\n\t\t\t.selectFrom(\"_emdash_fields as field\")\n\t\t\t.innerJoin(\"_emdash_collections as collection\", \"collection.id\", \"field.collection_id\")\n\t\t\t.where(\"collection.slug\", \"=\", type)\n\t\t\t.where(\"field.slug\", \"in\", fields)\n\t\t\t.where(\"field.indexed\", \"=\", 1)\n\t\t\t.select([\"field.slug\", \"field.type\"])\n\t\t\t.execute();\n\t\tconst metadata = new Map(rows.map((row) => [row.slug, row.type as FieldType]));\n\n\t\tif (metadata.size === 0 && !(await this.collectionExists(type))) return [];\n\n\t\tfor (const field of fields) {\n\t\t\ttry {\n\t\t\t\tvalidateIdentifier(field, \"content filter field\");\n\t\t\t} catch {\n\t\t\t\tthrow new EmDashValidationError(`Invalid content filter field: ${field}`);\n\t\t\t}\n\t\t}\n\n\t\tconst normalized = fields.map((field) => {\n\t\t\tconst fieldType = metadata.get(field);\n\t\t\tif (!fieldType || !isIndexableFieldType(fieldType)) {\n\t\t\t\tthrow new EmDashValidationError(\n\t\t\t\t\t`Cannot filter by field \"${field}\". Custom fields must be indexed before filtering.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn this.normalizeFieldFilter(field, fieldType, resolvedFilters[field]);\n\t\t});\n\t\tconst operandCount = normalized.reduce((total, filter) => {\n\t\t\tif (filter.kind === \"null\") return total;\n\t\t\tif (filter.kind === \"exact\") return total + 1;\n\t\t\tif (filter.kind === \"in\") return total + filter.values.length;\n\t\t\treturn total + Object.keys(filter.bounds).length;\n\t\t}, 0);\n\t\tif (operandCount > SQL_BATCH_SIZE) {\n\t\t\tthrow new EmDashValidationError(\n\t\t\t\t`Indexed field filters have a total operand budget of ${SQL_BATCH_SIZE}`,\n\t\t\t);\n\t\t}\n\t\treturn normalized;\n\t}\n\n\tprivate applyFieldFilters<QB extends { where: (cb: (eb: any) => unknown) => QB }>(\n\t\tquery: QB,\n\t\tfilters: ResolvedFieldFilter[],\n\t): QB {\n\t\tlet next = query;\n\t\tfor (const filter of filters) {\n\t\t\tconst column = sql.ref(filter.column);\n\t\t\tconst isPresent = sql<boolean>`${column} IS NOT NULL`;\n\t\t\tif (filter.kind === \"null\") {\n\t\t\t\tnext = next.where(() => sql<boolean>`(${isPresent}) = FALSE AND ${column} IS NULL`);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (filter.kind === \"exact\") {\n\t\t\t\tnext = next.where(\n\t\t\t\t\t() => sql<boolean>`(${isPresent}) = TRUE AND ${column} = ${filter.value}`,\n\t\t\t\t);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (filter.kind === \"in\") {\n\t\t\t\tconst values = sql.join(\n\t\t\t\t\tfilter.values.map((value) => sql`${value}`),\n\t\t\t\t\tsql`, `,\n\t\t\t\t);\n\t\t\t\tnext = next.where(() => sql<boolean>`(${isPresent}) = TRUE AND ${column} IN (${values})`);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tnext = next.where(() => sql<boolean>`(${isPresent}) = TRUE`);\n\t\t\tif (filter.bounds.gt !== undefined) {\n\t\t\t\tnext = next.where(() => sql<boolean>`${column} > ${filter.bounds.gt}`);\n\t\t\t}\n\t\t\tif (filter.bounds.gte !== undefined) {\n\t\t\t\tnext = next.where(() => sql<boolean>`${column} >= ${filter.bounds.gte}`);\n\t\t\t}\n\t\t\tif (filter.bounds.lt !== undefined) {\n\t\t\t\tnext = next.where(() => sql<boolean>`${column} < ${filter.bounds.lt}`);\n\t\t\t}\n\t\t\tif (filter.bounds.lte !== undefined) {\n\t\t\t\tnext = next.where(() => sql<boolean>`${column} <= ${filter.bounds.lte}`);\n\t\t\t}\n\t\t}\n\t\treturn next;\n\t}\n\n\t/**\n\t * Map order field names to database columns.\n\t * Only allows known fields to prevent column enumeration via crafted orderBy values.\n\t */\n\tprivate mapOrderField(field: string, sortableExtras: readonly string[] = []): string {\n\t\tconst mapped = ORDER_FIELD_COLUMNS[field];\n\t\tif (mapped) return mapped;\n\n\t\t// A collection's configured titleField/dateField are allowed as\n\t\t// sort columns. The caller passes the collection's *actual* values (resolved\n\t\t// server-side, never client-supplied), so this stays a closed set per\n\t\t// request and doesn't reopen the column-enumeration hole. The slug is a\n\t\t// validated identifier that maps directly to the column.\n\t\tif (sortableExtras.includes(field)) {\n\t\t\tvalidateIdentifier(field, \"order field\");\n\t\t\treturn field;\n\t\t}\n\n\t\tthrow new EmDashValidationError(`Invalid order field: ${field}`);\n\t}\n\n\tprivate async resolveOrderField(\n\t\ttype: string,\n\t\tfield: string,\n\t\tsortableExtras: readonly string[] = [],\n\t): Promise<ResolvedOrderField> {\n\t\ttry {\n\t\t\treturn { column: this.mapOrderField(field, sortableExtras), indexedCustomField: false };\n\t\t} catch (error) {\n\t\t\tif (!(error instanceof EmDashValidationError)) throw error;\n\t\t}\n\n\t\tconst customField = await this.db\n\t\t\t.selectFrom(\"_emdash_collections as collection\")\n\t\t\t.leftJoin(\"_emdash_fields as field\", (join) =>\n\t\t\t\tjoin\n\t\t\t\t\t.onRef(\"field.collection_id\", \"=\", \"collection.id\")\n\t\t\t\t\t.on(\"field.slug\", \"=\", field)\n\t\t\t\t\t.on(\"field.indexed\", \"=\", 1),\n\t\t\t)\n\t\t\t.where(\"collection.slug\", \"=\", type)\n\t\t\t.select([\"collection.id as collectionId\", \"field.slug as fieldSlug\"])\n\t\t\t.executeTakeFirst();\n\n\t\tif (!customField) {\n\t\t\tthrow new ContentCollectionNotFoundError(type);\n\t\t}\n\n\t\tif (!customField.fieldSlug) {\n\t\t\tthrow new EmDashValidationError(\n\t\t\t\t`Invalid order field: ${field}. Custom fields must be indexed before sorting.`,\n\t\t\t);\n\t\t}\n\n\t\tvalidateIdentifier(customField.fieldSlug, \"content order field\");\n\t\treturn { column: customField.fieldSlug, indexedCustomField: true };\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAWA,MAAM,gBAAgB;AACtB,MAAM,kBAAkB;AACxB,MAAM,kBAAkB;;;;;;;;AASxB,SAAgB,oBAAoB,OAAuB;CAC1D,MAAM,QAAQ,MACZ,MAAM,CACN,MAAM,cAAc,CACpB,KAAK,SAAS,KAAK,QAAQ,iBAAiB,OAAK,CAAC,CAClD,QAAQ,SAAS,KAAK,SAAS,EAAE;AAEnC,KAAI,MAAM,WAAW,EAAG,QAAO;AAC/B,QAAO,MAAM,KAAK,SAAS,IAAI,KAAK,IAAI,CAAC,KAAK,IA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