emdash 0.29.0 → 0.30.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 (839) hide show
  1. package/dist/{adapters-DPAkL6QF.d.mts → adapters-C0ONzkUP.d.mts} +10 -1
  2. package/dist/adapters-C0ONzkUP.d.mts.map +1 -0
  3. package/dist/{allowed-origins-FXB-FplB.mjs → allowed-origins-CCEi9bPI.mjs} +2 -2
  4. package/dist/{allowed-origins-FXB-FplB.mjs.map → allowed-origins-CCEi9bPI.mjs.map} +1 -1
  5. package/dist/api/route-utils.d.mts +3 -3
  6. package/dist/api/route-utils.d.mts.map +1 -1
  7. package/dist/api/route-utils.mjs +19 -19
  8. package/dist/api/schemas/index.d.mts +2 -2
  9. package/dist/api/schemas/index.mjs +5 -4
  10. package/dist/{api-DVbHNApo.mjs → api-b8WIiGU4.mjs} +253 -153
  11. package/dist/api-b8WIiGU4.mjs.map +1 -0
  12. package/dist/api-tokens-Cvmixds7.mjs +3 -0
  13. package/dist/{api-tokens-UYBkl17d.mjs → api-tokens-uPt8UDpx.mjs} +2 -2
  14. package/dist/{api-tokens-UYBkl17d.mjs.map → api-tokens-uPt8UDpx.mjs.map} +1 -1
  15. package/dist/{apply-D23iUV4q.mjs → apply-CmIJK9j8.mjs} +34 -37
  16. package/dist/apply-CmIJK9j8.mjs.map +1 -0
  17. package/dist/astro/index.d.mts +12 -13
  18. package/dist/astro/index.d.mts.map +1 -1
  19. package/dist/astro/index.mjs +90 -11
  20. package/dist/astro/index.mjs.map +1 -1
  21. package/dist/astro/middleware/auth.d.mts +10 -11
  22. package/dist/astro/middleware/auth.d.mts.map +1 -1
  23. package/dist/astro/middleware/auth.mjs +56 -107
  24. package/dist/astro/middleware/auth.mjs.map +1 -1
  25. package/dist/astro/middleware/redirect.mjs +7 -7
  26. package/dist/astro/middleware/request-context.mjs +4 -4
  27. package/dist/astro/middleware/request-context.mjs.map +1 -1
  28. package/dist/astro/middleware/setup.mjs +1 -1
  29. package/dist/astro/middleware.d.mts +47 -3
  30. package/dist/astro/middleware.d.mts.map +1 -1
  31. package/dist/astro/middleware.mjs +326 -110
  32. package/dist/astro/middleware.mjs.map +1 -1
  33. package/dist/astro/routes/PluginRegistry.d.mts +5 -1
  34. package/dist/astro/routes/PluginRegistry.d.mts.map +1 -1
  35. package/dist/astro/routes/PluginRegistry.mjs +2 -1
  36. package/dist/astro/routes/PluginRegistry.mjs.map +1 -1
  37. package/dist/astro/routes/api/admin/allowed-domains/_domain_.mjs +9 -8
  38. package/dist/astro/routes/api/admin/allowed-domains/_domain_.mjs.map +1 -1
  39. package/dist/astro/routes/api/admin/allowed-domains/index.mjs +9 -8
  40. package/dist/astro/routes/api/admin/allowed-domains/index.mjs.map +1 -1
  41. package/dist/astro/routes/api/admin/api-tokens/_id_.mjs +5 -5
  42. package/dist/astro/routes/api/admin/api-tokens/index.mjs +7 -7
  43. package/dist/astro/routes/api/admin/api-tokens/index.mjs.map +1 -1
  44. package/dist/astro/routes/api/admin/byline-fields/_slug_/usage.mjs +5 -5
  45. package/dist/astro/routes/api/admin/byline-fields/_slug_.mjs +10 -9
  46. package/dist/astro/routes/api/admin/byline-fields/_slug_.mjs.map +1 -1
  47. package/dist/astro/routes/api/admin/byline-fields/index.mjs +10 -9
  48. package/dist/astro/routes/api/admin/byline-fields/index.mjs.map +1 -1
  49. package/dist/astro/routes/api/admin/byline-fields/reorder.mjs +10 -9
  50. package/dist/astro/routes/api/admin/byline-fields/reorder.mjs.map +1 -1
  51. package/dist/astro/routes/api/admin/bylines/_id_/index.mjs +15 -14
  52. package/dist/astro/routes/api/admin/bylines/_id_/index.mjs.map +1 -1
  53. package/dist/astro/routes/api/admin/bylines/_id_/translations.mjs +16 -21
  54. package/dist/astro/routes/api/admin/bylines/_id_/translations.mjs.map +1 -1
  55. package/dist/astro/routes/api/admin/bylines/index.mjs +15 -14
  56. package/dist/astro/routes/api/admin/bylines/index.mjs.map +1 -1
  57. package/dist/astro/routes/api/admin/comments/_id_/status.mjs +13 -12
  58. package/dist/astro/routes/api/admin/comments/_id_/status.mjs.map +1 -1
  59. package/dist/astro/routes/api/admin/comments/_id_.mjs +6 -6
  60. package/dist/astro/routes/api/admin/comments/bulk.mjs +11 -10
  61. package/dist/astro/routes/api/admin/comments/bulk.mjs.map +1 -1
  62. package/dist/astro/routes/api/admin/comments/counts.mjs +6 -6
  63. package/dist/astro/routes/api/admin/comments/index.mjs +11 -10
  64. package/dist/astro/routes/api/admin/comments/index.mjs.map +1 -1
  65. package/dist/astro/routes/api/admin/hooks/exclusive/_hookName_.mjs +5 -5
  66. package/dist/astro/routes/api/admin/hooks/exclusive/index.mjs +4 -4
  67. package/dist/astro/routes/api/admin/media-usage/repair.mjs +12 -10
  68. package/dist/astro/routes/api/admin/media-usage/repair.mjs.map +1 -1
  69. package/dist/astro/routes/api/admin/oauth-clients/_id_.mjs +5 -5
  70. package/dist/astro/routes/api/admin/oauth-clients/index.mjs +5 -5
  71. package/dist/astro/routes/api/admin/plugins/_id_/disable.mjs +40 -39
  72. package/dist/astro/routes/api/admin/plugins/_id_/disable.mjs.map +1 -1
  73. package/dist/astro/routes/api/admin/plugins/_id_/enable.mjs +40 -39
  74. package/dist/astro/routes/api/admin/plugins/_id_/enable.mjs.map +1 -1
  75. package/dist/astro/routes/api/admin/plugins/_id_/index.mjs +45 -39
  76. package/dist/astro/routes/api/admin/plugins/_id_/index.mjs.map +1 -1
  77. package/dist/astro/routes/api/admin/plugins/_id_/mcp.d.mts +8 -0
  78. package/dist/astro/routes/api/admin/plugins/_id_/mcp.d.mts.map +1 -0
  79. package/dist/astro/routes/api/admin/plugins/_id_/mcp.mjs +39 -0
  80. package/dist/astro/routes/api/admin/plugins/_id_/mcp.mjs.map +1 -0
  81. package/dist/astro/routes/api/admin/plugins/_id_/settings.d.mts +9 -0
  82. package/dist/astro/routes/api/admin/plugins/_id_/settings.d.mts.map +1 -0
  83. package/dist/astro/routes/api/admin/plugins/_id_/settings.mjs +78 -0
  84. package/dist/astro/routes/api/admin/plugins/_id_/settings.mjs.map +1 -0
  85. package/dist/astro/routes/api/admin/plugins/_id_/uninstall.mjs +39 -38
  86. package/dist/astro/routes/api/admin/plugins/_id_/uninstall.mjs.map +1 -1
  87. package/dist/astro/routes/api/admin/plugins/_id_/update.d.mts.map +1 -1
  88. package/dist/astro/routes/api/admin/plugins/_id_/update.mjs +42 -39
  89. package/dist/astro/routes/api/admin/plugins/_id_/update.mjs.map +1 -1
  90. package/dist/astro/routes/api/admin/plugins/index.mjs +45 -39
  91. package/dist/astro/routes/api/admin/plugins/index.mjs.map +1 -1
  92. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/icon.mjs +4 -4
  93. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/index.mjs +39 -38
  94. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/index.mjs.map +1 -1
  95. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.d.mts.map +1 -1
  96. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.mjs +45 -40
  97. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.mjs.map +1 -1
  98. package/dist/astro/routes/api/admin/plugins/marketplace/index.mjs +39 -38
  99. package/dist/astro/routes/api/admin/plugins/marketplace/index.mjs.map +1 -1
  100. package/dist/astro/routes/api/admin/plugins/registry/_id_/uninstall.mjs +39 -38
  101. package/dist/astro/routes/api/admin/plugins/registry/_id_/uninstall.mjs.map +1 -1
  102. package/dist/astro/routes/api/admin/plugins/registry/_id_/update.d.mts.map +1 -1
  103. package/dist/astro/routes/api/admin/plugins/registry/_id_/update.mjs +43 -40
  104. package/dist/astro/routes/api/admin/plugins/registry/_id_/update.mjs.map +1 -1
  105. package/dist/astro/routes/api/admin/plugins/registry/artifact.mjs +39 -38
  106. package/dist/astro/routes/api/admin/plugins/registry/artifact.mjs.map +1 -1
  107. package/dist/astro/routes/api/admin/plugins/registry/install.d.mts.map +1 -1
  108. package/dist/astro/routes/api/admin/plugins/registry/install.mjs +44 -41
  109. package/dist/astro/routes/api/admin/plugins/registry/install.mjs.map +1 -1
  110. package/dist/astro/routes/api/admin/plugins/updates.mjs +40 -39
  111. package/dist/astro/routes/api/admin/plugins/updates.mjs.map +1 -1
  112. package/dist/astro/routes/api/admin/themes/marketplace/_id_/index.mjs +39 -38
  113. package/dist/astro/routes/api/admin/themes/marketplace/_id_/index.mjs.map +1 -1
  114. package/dist/astro/routes/api/admin/themes/marketplace/_id_/thumbnail.mjs +4 -4
  115. package/dist/astro/routes/api/admin/themes/marketplace/index.mjs +39 -38
  116. package/dist/astro/routes/api/admin/themes/marketplace/index.mjs.map +1 -1
  117. package/dist/astro/routes/api/admin/users/_id_/disable.mjs +4 -4
  118. package/dist/astro/routes/api/admin/users/_id_/enable.mjs +4 -4
  119. package/dist/astro/routes/api/admin/users/_id_/index.mjs +9 -8
  120. package/dist/astro/routes/api/admin/users/_id_/index.mjs.map +1 -1
  121. package/dist/astro/routes/api/admin/users/_id_/send-recovery.mjs +5 -5
  122. package/dist/astro/routes/api/admin/users/index.mjs +9 -8
  123. package/dist/astro/routes/api/admin/users/index.mjs.map +1 -1
  124. package/dist/astro/routes/api/auth/dev-bypass.mjs +7 -7
  125. package/dist/astro/routes/api/auth/invite/accept.mjs +4 -4
  126. package/dist/astro/routes/api/auth/invite/complete.mjs +13 -12
  127. package/dist/astro/routes/api/auth/invite/complete.mjs.map +1 -1
  128. package/dist/astro/routes/api/auth/invite/index.mjs +10 -9
  129. package/dist/astro/routes/api/auth/invite/index.mjs.map +1 -1
  130. package/dist/astro/routes/api/auth/invite/register-options.mjs +12 -11
  131. package/dist/astro/routes/api/auth/invite/register-options.mjs.map +1 -1
  132. package/dist/astro/routes/api/auth/logout.mjs +4 -4
  133. package/dist/astro/routes/api/auth/magic-link/send.mjs +12 -11
  134. package/dist/astro/routes/api/auth/magic-link/send.mjs.map +1 -1
  135. package/dist/astro/routes/api/auth/magic-link/verify.mjs +5 -5
  136. package/dist/astro/routes/api/auth/me.mjs +9 -8
  137. package/dist/astro/routes/api/auth/me.mjs.map +1 -1
  138. package/dist/astro/routes/api/auth/mode.d.mts.map +1 -1
  139. package/dist/astro/routes/api/auth/mode.mjs +6 -3
  140. package/dist/astro/routes/api/auth/mode.mjs.map +1 -1
  141. package/dist/astro/routes/api/auth/oauth/_provider_/callback.mjs +15 -5
  142. package/dist/astro/routes/api/auth/oauth/_provider_/callback.mjs.map +1 -1
  143. package/dist/astro/routes/api/auth/oauth/_provider_.d.mts.map +1 -1
  144. package/dist/astro/routes/api/auth/oauth/_provider_.mjs +11 -5
  145. package/dist/astro/routes/api/auth/oauth/_provider_.mjs.map +1 -1
  146. package/dist/astro/routes/api/auth/passkey/_id_.mjs +8 -7
  147. package/dist/astro/routes/api/auth/passkey/_id_.mjs.map +1 -1
  148. package/dist/astro/routes/api/auth/passkey/index.mjs +3 -3
  149. package/dist/astro/routes/api/auth/passkey/options.mjs +13 -12
  150. package/dist/astro/routes/api/auth/passkey/options.mjs.map +1 -1
  151. package/dist/astro/routes/api/auth/passkey/register/options.mjs +11 -10
  152. package/dist/astro/routes/api/auth/passkey/register/options.mjs.map +1 -1
  153. package/dist/astro/routes/api/auth/passkey/register/verify.mjs +12 -11
  154. package/dist/astro/routes/api/auth/passkey/register/verify.mjs.map +1 -1
  155. package/dist/astro/routes/api/auth/passkey/verify.mjs +12 -11
  156. package/dist/astro/routes/api/auth/passkey/verify.mjs.map +1 -1
  157. package/dist/astro/routes/api/auth/signup/complete.mjs +13 -12
  158. package/dist/astro/routes/api/auth/signup/complete.mjs.map +1 -1
  159. package/dist/astro/routes/api/auth/signup/request.mjs +12 -11
  160. package/dist/astro/routes/api/auth/signup/request.mjs.map +1 -1
  161. package/dist/astro/routes/api/auth/signup/verify.mjs +4 -4
  162. package/dist/astro/routes/api/comments/_collection_/_contentId_/index.mjs +14 -13
  163. package/dist/astro/routes/api/comments/_collection_/_contentId_/index.mjs.map +1 -1
  164. package/dist/astro/routes/api/comments/_collection_/_contentId_/reactions.mjs +13 -12
  165. package/dist/astro/routes/api/comments/_collection_/_contentId_/reactions.mjs.map +1 -1
  166. package/dist/astro/routes/api/content/_collection_/_id_/compare.mjs +5 -5
  167. package/dist/astro/routes/api/content/_collection_/_id_/compare.mjs.map +1 -1
  168. package/dist/astro/routes/api/content/_collection_/_id_/discard-draft.mjs +5 -4
  169. package/dist/astro/routes/api/content/_collection_/_id_/discard-draft.mjs.map +1 -1
  170. package/dist/astro/routes/api/content/_collection_/_id_/duplicate.mjs +6 -5
  171. package/dist/astro/routes/api/content/_collection_/_id_/duplicate.mjs.map +1 -1
  172. package/dist/astro/routes/api/content/_collection_/_id_/permanent.mjs +5 -5
  173. package/dist/astro/routes/api/content/_collection_/_id_/permanent.mjs.map +1 -1
  174. package/dist/astro/routes/api/content/_collection_/_id_/preview-url.mjs +13 -12
  175. package/dist/astro/routes/api/content/_collection_/_id_/preview-url.mjs.map +1 -1
  176. package/dist/astro/routes/api/content/_collection_/_id_/publish.mjs +10 -8
  177. package/dist/astro/routes/api/content/_collection_/_id_/publish.mjs.map +1 -1
  178. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/children.d.mts.map +1 -1
  179. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/children.mjs +20 -19
  180. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/children.mjs.map +1 -1
  181. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/parents.mjs +18 -17
  182. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/parents.mjs.map +1 -1
  183. package/dist/astro/routes/api/content/_collection_/_id_/restore.mjs +5 -4
  184. package/dist/astro/routes/api/content/_collection_/_id_/restore.mjs.map +1 -1
  185. package/dist/astro/routes/api/content/_collection_/_id_/revisions.mjs +5 -5
  186. package/dist/astro/routes/api/content/_collection_/_id_/revisions.mjs.map +1 -1
  187. package/dist/astro/routes/api/content/_collection_/_id_/schedule.mjs +10 -8
  188. package/dist/astro/routes/api/content/_collection_/_id_/schedule.mjs.map +1 -1
  189. package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.d.mts.map +1 -1
  190. package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.mjs +18 -17
  191. package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.mjs.map +1 -1
  192. package/dist/astro/routes/api/content/_collection_/_id_/translations.mjs +5 -5
  193. package/dist/astro/routes/api/content/_collection_/_id_/translations.mjs.map +1 -1
  194. package/dist/astro/routes/api/content/_collection_/_id_/unpublish.mjs +5 -4
  195. package/dist/astro/routes/api/content/_collection_/_id_/unpublish.mjs.map +1 -1
  196. package/dist/astro/routes/api/content/_collection_/_id_.d.mts.map +1 -1
  197. package/dist/astro/routes/api/content/_collection_/_id_.mjs +11 -9
  198. package/dist/astro/routes/api/content/_collection_/_id_.mjs.map +1 -1
  199. package/dist/astro/routes/api/content/_collection_/authors.mjs +5 -5
  200. package/dist/astro/routes/api/content/_collection_/authors.mjs.map +1 -1
  201. package/dist/astro/routes/api/content/_collection_/index.d.mts.map +1 -1
  202. package/dist/astro/routes/api/content/_collection_/index.mjs +12 -10
  203. package/dist/astro/routes/api/content/_collection_/index.mjs.map +1 -1
  204. package/dist/astro/routes/api/content/_collection_/trash.mjs +10 -9
  205. package/dist/astro/routes/api/content/_collection_/trash.mjs.map +1 -1
  206. package/dist/astro/routes/api/dashboard.mjs +8 -8
  207. package/dist/astro/routes/api/dev/emails.mjs +4 -4
  208. package/dist/astro/routes/api/import/probe.d.mts +3 -3
  209. package/dist/astro/routes/api/import/probe.mjs +17 -16
  210. package/dist/astro/routes/api/import/probe.mjs.map +1 -1
  211. package/dist/astro/routes/api/import/wordpress/analyze.mjs +4 -4
  212. package/dist/astro/routes/api/import/wordpress/execute.d.mts +11 -12
  213. package/dist/astro/routes/api/import/wordpress/execute.d.mts.map +1 -1
  214. package/dist/astro/routes/api/import/wordpress/execute.mjs +12 -12
  215. package/dist/astro/routes/api/import/wordpress/media.d.mts +10 -11
  216. package/dist/astro/routes/api/import/wordpress/media.d.mts.map +1 -1
  217. package/dist/astro/routes/api/import/wordpress/media.mjs +11 -10
  218. package/dist/astro/routes/api/import/wordpress/media.mjs.map +1 -1
  219. package/dist/astro/routes/api/import/wordpress/prepare.mjs +11 -10
  220. package/dist/astro/routes/api/import/wordpress/prepare.mjs.map +1 -1
  221. package/dist/astro/routes/api/import/wordpress/rewrite-urls.d.mts +11 -12
  222. package/dist/astro/routes/api/import/wordpress/rewrite-urls.d.mts.map +1 -1
  223. package/dist/astro/routes/api/import/wordpress/rewrite-urls.mjs +11 -10
  224. package/dist/astro/routes/api/import/wordpress/rewrite-urls.mjs.map +1 -1
  225. package/dist/astro/routes/api/import/wordpress-plugin/analyze.d.mts +1 -1
  226. package/dist/astro/routes/api/import/wordpress-plugin/analyze.mjs +17 -16
  227. package/dist/astro/routes/api/import/wordpress-plugin/analyze.mjs.map +1 -1
  228. package/dist/astro/routes/api/import/wordpress-plugin/callback.mjs +1 -1
  229. package/dist/astro/routes/api/import/wordpress-plugin/execute.d.mts +11 -12
  230. package/dist/astro/routes/api/import/wordpress-plugin/execute.d.mts.map +1 -1
  231. package/dist/astro/routes/api/import/wordpress-plugin/execute.mjs +23 -22
  232. package/dist/astro/routes/api/import/wordpress-plugin/execute.mjs.map +1 -1
  233. package/dist/astro/routes/api/manifest.mjs +7 -8
  234. package/dist/astro/routes/api/manifest.mjs.map +1 -1
  235. package/dist/astro/routes/api/mcp.d.mts.map +1 -1
  236. package/dist/astro/routes/api/mcp.mjs +149 -45
  237. package/dist/astro/routes/api/mcp.mjs.map +1 -1
  238. package/dist/astro/routes/api/media/_id_/confirm.mjs +9 -8
  239. package/dist/astro/routes/api/media/_id_/confirm.mjs.map +1 -1
  240. package/dist/astro/routes/api/media/_id_/usage.d.mts +8 -0
  241. package/dist/astro/routes/api/media/_id_/usage.d.mts.map +1 -0
  242. package/dist/astro/routes/api/media/_id_/usage.mjs +37 -0
  243. package/dist/astro/routes/api/media/_id_/usage.mjs.map +1 -0
  244. package/dist/astro/routes/api/media/_id_.d.mts.map +1 -1
  245. package/dist/astro/routes/api/media/_id_.mjs +26 -10
  246. package/dist/astro/routes/api/media/_id_.mjs.map +1 -1
  247. package/dist/astro/routes/api/media/file/_...key_.mjs +4 -3
  248. package/dist/astro/routes/api/media/file/_...key_.mjs.map +1 -1
  249. package/dist/astro/routes/api/media/providers/_providerId_/_itemId_.mjs +4 -4
  250. package/dist/astro/routes/api/media/providers/_providerId_/index.mjs +4 -4
  251. package/dist/astro/routes/api/media/providers/index.mjs +4 -4
  252. package/dist/astro/routes/api/media/upload-url.mjs +10 -9
  253. package/dist/astro/routes/api/media/upload-url.mjs.map +1 -1
  254. package/dist/astro/routes/api/media.d.mts.map +1 -1
  255. package/dist/astro/routes/api/media.mjs +31 -11
  256. package/dist/astro/routes/api/media.mjs.map +1 -1
  257. package/dist/astro/routes/api/menus/_name_/items/_id_.mjs +10 -9
  258. package/dist/astro/routes/api/menus/_name_/items/_id_.mjs.map +1 -1
  259. package/dist/astro/routes/api/menus/_name_/items.mjs +10 -9
  260. package/dist/astro/routes/api/menus/_name_/items.mjs.map +1 -1
  261. package/dist/astro/routes/api/menus/_name_/reorder.mjs +10 -9
  262. package/dist/astro/routes/api/menus/_name_/reorder.mjs.map +1 -1
  263. package/dist/astro/routes/api/menus/_name_/translations.mjs +10 -9
  264. package/dist/astro/routes/api/menus/_name_/translations.mjs.map +1 -1
  265. package/dist/astro/routes/api/menus/_name_.mjs +10 -9
  266. package/dist/astro/routes/api/menus/_name_.mjs.map +1 -1
  267. package/dist/astro/routes/api/menus/index.mjs +10 -9
  268. package/dist/astro/routes/api/menus/index.mjs.map +1 -1
  269. package/dist/astro/routes/api/oauth/authorize.d.mts.map +1 -1
  270. package/dist/astro/routes/api/oauth/authorize.mjs +7 -8
  271. package/dist/astro/routes/api/oauth/authorize.mjs.map +1 -1
  272. package/dist/astro/routes/api/oauth/device/authorize.mjs +7 -7
  273. package/dist/astro/routes/api/oauth/device/code.mjs +10 -10
  274. package/dist/astro/routes/api/oauth/device/token.mjs +9 -9
  275. package/dist/astro/routes/api/oauth/register.mjs +4 -4
  276. package/dist/astro/routes/api/oauth/token/refresh.mjs +7 -7
  277. package/dist/astro/routes/api/oauth/token/revoke.mjs +7 -7
  278. package/dist/astro/routes/api/oauth/token.mjs +7 -7
  279. package/dist/astro/routes/api/openapi.json.mjs +52 -24
  280. package/dist/astro/routes/api/openapi.json.mjs.map +1 -1
  281. package/dist/astro/routes/api/plugins/_pluginId_/_...path_.d.mts.map +1 -1
  282. package/dist/astro/routes/api/plugins/_pluginId_/_...path_.mjs +20 -32
  283. package/dist/astro/routes/api/plugins/_pluginId_/_...path_.mjs.map +1 -1
  284. package/dist/astro/routes/api/redirects/404s/index.mjs +12 -11
  285. package/dist/astro/routes/api/redirects/404s/index.mjs.map +1 -1
  286. package/dist/astro/routes/api/redirects/404s/summary.mjs +12 -11
  287. package/dist/astro/routes/api/redirects/404s/summary.mjs.map +1 -1
  288. package/dist/astro/routes/api/redirects/_id_.mjs +13 -12
  289. package/dist/astro/routes/api/redirects/_id_.mjs.map +1 -1
  290. package/dist/astro/routes/api/redirects/index.mjs +13 -12
  291. package/dist/astro/routes/api/redirects/index.mjs.map +1 -1
  292. package/dist/astro/routes/api/relations/_id_/index.mjs +16 -15
  293. package/dist/astro/routes/api/relations/_id_/index.mjs.map +1 -1
  294. package/dist/astro/routes/api/relations/_id_/translations.mjs +11 -11
  295. package/dist/astro/routes/api/relations/index.mjs +16 -15
  296. package/dist/astro/routes/api/relations/index.mjs.map +1 -1
  297. package/dist/astro/routes/api/revisions/_revisionId_/index.mjs +4 -4
  298. package/dist/astro/routes/api/revisions/_revisionId_/restore.mjs +5 -4
  299. package/dist/astro/routes/api/revisions/_revisionId_/restore.mjs.map +1 -1
  300. package/dist/astro/routes/api/schema/collections/_slug_/fields/_fieldSlug_.mjs +39 -38
  301. package/dist/astro/routes/api/schema/collections/_slug_/fields/_fieldSlug_.mjs.map +1 -1
  302. package/dist/astro/routes/api/schema/collections/_slug_/fields/index.mjs +39 -38
  303. package/dist/astro/routes/api/schema/collections/_slug_/fields/index.mjs.map +1 -1
  304. package/dist/astro/routes/api/schema/collections/_slug_/fields/reorder.mjs +39 -38
  305. package/dist/astro/routes/api/schema/collections/_slug_/fields/reorder.mjs.map +1 -1
  306. package/dist/astro/routes/api/schema/collections/_slug_/index.mjs +39 -38
  307. package/dist/astro/routes/api/schema/collections/_slug_/index.mjs.map +1 -1
  308. package/dist/astro/routes/api/schema/collections/index.mjs +39 -38
  309. package/dist/astro/routes/api/schema/collections/index.mjs.map +1 -1
  310. package/dist/astro/routes/api/schema/index.mjs +9 -9
  311. package/dist/astro/routes/api/schema/orphans/_slug_.mjs +39 -38
  312. package/dist/astro/routes/api/schema/orphans/_slug_.mjs.map +1 -1
  313. package/dist/astro/routes/api/schema/orphans/index.mjs +39 -38
  314. package/dist/astro/routes/api/schema/orphans/index.mjs.map +1 -1
  315. package/dist/astro/routes/api/search/enable.mjs +13 -12
  316. package/dist/astro/routes/api/search/enable.mjs.map +1 -1
  317. package/dist/astro/routes/api/search/index.mjs +12 -11
  318. package/dist/astro/routes/api/search/index.mjs.map +1 -1
  319. package/dist/astro/routes/api/search/rebuild.mjs +13 -12
  320. package/dist/astro/routes/api/search/rebuild.mjs.map +1 -1
  321. package/dist/astro/routes/api/search/stats.mjs +8 -8
  322. package/dist/astro/routes/api/search/suggest.mjs +12 -11
  323. package/dist/astro/routes/api/search/suggest.mjs.map +1 -1
  324. package/dist/astro/routes/api/sections/_slug_.mjs +12 -11
  325. package/dist/astro/routes/api/sections/_slug_.mjs.map +1 -1
  326. package/dist/astro/routes/api/sections/index.mjs +12 -11
  327. package/dist/astro/routes/api/sections/index.mjs.map +1 -1
  328. package/dist/astro/routes/api/settings/backups/archives/_name_.d.mts +9 -0
  329. package/dist/astro/routes/api/settings/backups/archives/_name_.d.mts.map +1 -0
  330. package/dist/astro/routes/api/settings/backups/archives/_name_.mjs +48 -0
  331. package/dist/astro/routes/api/settings/backups/archives/_name_.mjs.map +1 -0
  332. package/dist/astro/routes/api/settings/backups/archives/index.d.mts +8 -0
  333. package/dist/astro/routes/api/settings/backups/archives/index.d.mts.map +1 -0
  334. package/dist/astro/routes/api/settings/backups/archives/index.mjs +23 -0
  335. package/dist/astro/routes/api/settings/backups/archives/index.mjs.map +1 -0
  336. package/dist/astro/routes/api/settings/backups/export.d.mts +8 -0
  337. package/dist/astro/routes/api/settings/backups/export.d.mts.map +1 -0
  338. package/dist/astro/routes/api/settings/backups/export.mjs +35 -0
  339. package/dist/astro/routes/api/settings/backups/export.mjs.map +1 -0
  340. package/dist/astro/routes/api/settings/backups/index.d.mts +9 -0
  341. package/dist/astro/routes/api/settings/backups/index.d.mts.map +1 -0
  342. package/dist/astro/routes/api/settings/backups/index.mjs +52 -0
  343. package/dist/astro/routes/api/settings/backups/index.mjs.map +1 -0
  344. package/dist/astro/routes/api/settings/email.mjs +5 -5
  345. package/dist/astro/routes/api/settings.mjs +14 -13
  346. package/dist/astro/routes/api/settings.mjs.map +1 -1
  347. package/dist/astro/routes/api/setup/admin-verify.mjs +19 -15
  348. package/dist/astro/routes/api/setup/admin-verify.mjs.map +1 -1
  349. package/dist/astro/routes/api/setup/admin.mjs +18 -14
  350. package/dist/astro/routes/api/setup/admin.mjs.map +1 -1
  351. package/dist/astro/routes/api/setup/dev-bypass.mjs +26 -26
  352. package/dist/astro/routes/api/setup/dev-reset.mjs +3 -3
  353. package/dist/astro/routes/api/setup/index.mjs +28 -27
  354. package/dist/astro/routes/api/setup/index.mjs.map +1 -1
  355. package/dist/astro/routes/api/setup/status.mjs +5 -5
  356. package/dist/astro/routes/api/snapshot.mjs +8 -215
  357. package/dist/astro/routes/api/snapshot.mjs.map +1 -1
  358. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_/translations.mjs +14 -13
  359. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_/translations.mjs.map +1 -1
  360. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_.mjs +14 -13
  361. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_.mjs.map +1 -1
  362. package/dist/astro/routes/api/taxonomies/_name_/terms/index.mjs +14 -13
  363. package/dist/astro/routes/api/taxonomies/_name_/terms/index.mjs.map +1 -1
  364. package/dist/astro/routes/api/taxonomies/index.mjs +14 -13
  365. package/dist/astro/routes/api/taxonomies/index.mjs.map +1 -1
  366. package/dist/astro/routes/api/themes/preview.mjs +6 -6
  367. package/dist/astro/routes/api/typegen.mjs +6 -6
  368. package/dist/astro/routes/api/well-known/auth.mjs +1 -1
  369. package/dist/astro/routes/api/well-known/oauth-authorization-server.d.mts.map +1 -1
  370. package/dist/astro/routes/api/well-known/oauth-authorization-server.mjs +4 -3
  371. package/dist/astro/routes/api/well-known/oauth-authorization-server.mjs.map +1 -1
  372. package/dist/astro/routes/api/well-known/oauth-protected-resource.d.mts.map +1 -1
  373. package/dist/astro/routes/api/well-known/oauth-protected-resource.mjs +4 -3
  374. package/dist/astro/routes/api/well-known/oauth-protected-resource.mjs.map +1 -1
  375. package/dist/astro/routes/api/widget-areas/_name_/reorder.mjs +9 -8
  376. package/dist/astro/routes/api/widget-areas/_name_/reorder.mjs.map +1 -1
  377. package/dist/astro/routes/api/widget-areas/_name_/widgets/_id_.mjs +12 -11
  378. package/dist/astro/routes/api/widget-areas/_name_/widgets/_id_.mjs.map +1 -1
  379. package/dist/astro/routes/api/widget-areas/_name_/widgets.mjs +12 -11
  380. package/dist/astro/routes/api/widget-areas/_name_/widgets.mjs.map +1 -1
  381. package/dist/astro/routes/api/widget-areas/_name_.mjs +7 -7
  382. package/dist/astro/routes/api/widget-areas/index.mjs +12 -11
  383. package/dist/astro/routes/api/widget-areas/index.mjs.map +1 -1
  384. package/dist/astro/routes/api/widget-components.mjs +4 -4
  385. package/dist/astro/routes/robots.txt.mjs +7 -7
  386. package/dist/astro/routes/sitemap-_collection_.xml.mjs +9 -9
  387. package/dist/astro/routes/sitemap.xml.mjs +8 -8
  388. package/dist/astro/types.d.mts +38 -17
  389. package/dist/astro/types.d.mts.map +1 -1
  390. package/dist/auth/providers/github.d.mts +1 -1
  391. package/dist/auth/providers/google.d.mts +1 -1
  392. package/dist/{authorize-BmCwQCib.mjs → authorize-WxsiePzy.mjs} +7 -4
  393. package/dist/authorize-WxsiePzy.mjs.map +1 -0
  394. package/dist/backup-S8kFWtwD.mjs +241 -0
  395. package/dist/backup-S8kFWtwD.mjs.map +1 -0
  396. package/dist/{base64-C74Msx8h.mjs → base64-B-PsqheR.mjs} +8 -4
  397. package/dist/base64-B-PsqheR.mjs.map +1 -0
  398. package/dist/{byline-BWb5H-65.mjs → byline-XEjchwzZ.mjs} +6 -6
  399. package/dist/{byline-BWb5H-65.mjs.map → byline-XEjchwzZ.mjs.map} +1 -1
  400. package/dist/{byline-fields-DO6bAYK8.mjs → byline-fields-CdU_LTF1.mjs} +1 -1
  401. package/dist/{byline-fields-DO6bAYK8.mjs.map → byline-fields-CdU_LTF1.mjs.map} +1 -1
  402. package/dist/{bylines-BGuKFaBy.mjs → bylines-BJbT4gKS.mjs} +4 -4
  403. package/dist/{bylines-BGuKFaBy.mjs.map → bylines-BJbT4gKS.mjs.map} +1 -1
  404. package/dist/{bylines-CHojDMpj.mjs → bylines-czseViYo.mjs} +6 -6
  405. package/dist/{bylines-CHojDMpj.mjs.map → bylines-czseViYo.mjs.map} +1 -1
  406. package/dist/{cache-BeR7RfN8.mjs → cache-CGCd6AVM.mjs} +2 -2
  407. package/dist/{cache-BeR7RfN8.mjs.map → cache-CGCd6AVM.mjs.map} +1 -1
  408. package/dist/{challenge-store-B426wQ6O.mjs → challenge-store-BFzgFRog.mjs} +1 -1
  409. package/dist/{challenge-store-B426wQ6O.mjs.map → challenge-store-BFzgFRog.mjs.map} +1 -1
  410. package/dist/{chunks-BU5_nrAC.mjs → chunks-BxXyunY-.mjs} +2 -2
  411. package/dist/{chunks-BU5_nrAC.mjs.map → chunks-BxXyunY-.mjs.map} +1 -1
  412. package/dist/cli/index.mjs +138 -31
  413. package/dist/cli/index.mjs.map +1 -1
  414. package/dist/client/cf-access.d.mts +1 -1
  415. package/dist/client/index.d.mts +54 -3
  416. package/dist/client/index.d.mts.map +1 -1
  417. package/dist/client/index.mjs +16 -4
  418. package/dist/client/index.mjs.map +1 -1
  419. package/dist/{comment-SWh31kS0.mjs → comment-DPT0WKyd.mjs} +2 -2
  420. package/dist/{comment-SWh31kS0.mjs.map → comment-DPT0WKyd.mjs.map} +1 -1
  421. package/dist/{comment-reaction-DgcpziXI.mjs → comment-reaction-C65MldIB.mjs} +2 -2
  422. package/dist/{comment-reaction-DgcpziXI.mjs.map → comment-reaction-C65MldIB.mjs.map} +1 -1
  423. package/dist/{comments-kZYGppMS.mjs → comments-Bz6sCbgD.mjs} +3 -3
  424. package/dist/{comments-kZYGppMS.mjs.map → comments-Bz6sCbgD.mjs.map} +1 -1
  425. package/dist/{components-CliOkZAs.mjs → components-DZkL4Fx0.mjs} +1 -1
  426. package/dist/{components-CliOkZAs.mjs.map → components-DZkL4Fx0.mjs.map} +1 -1
  427. package/dist/{content-BO61Sx4j.mjs → content-Ci04z2z-.mjs} +53 -19
  428. package/dist/content-Ci04z2z-.mjs.map +1 -0
  429. package/dist/{content-refresh-BkkApzeS.mjs → content-refresh-D4khvC0R.mjs} +95 -3
  430. package/dist/content-refresh-D4khvC0R.mjs.map +1 -0
  431. package/dist/{context-DtSFYFuS.mjs → context-B6hc7zJL.mjs} +97 -74
  432. package/dist/context-B6hc7zJL.mjs.map +1 -0
  433. package/dist/{cron-YFJ7uNVA.mjs → cron-BlKIMD_e.mjs} +1 -1
  434. package/dist/{cron-YFJ7uNVA.mjs.map → cron-BlKIMD_e.mjs.map} +1 -1
  435. package/dist/{dashboard-xo_gPs_D.mjs → dashboard-C5NkXFbi.mjs} +4 -4
  436. package/dist/{dashboard-xo_gPs_D.mjs.map → dashboard-C5NkXFbi.mjs.map} +1 -1
  437. package/dist/db/index.d.mts +3 -3
  438. package/dist/db/index.mjs +2 -2
  439. package/dist/db/index.mjs.map +1 -1
  440. package/dist/db/libsql.d.mts +1 -1
  441. package/dist/db/postgres.d.mts +1 -1
  442. package/dist/db/sqlite.d.mts +1 -1
  443. package/dist/{db-errors-BKuXh_fi.mjs → db-errors-CcWLaRiR.mjs} +4 -2
  444. package/dist/db-errors-CcWLaRiR.mjs.map +1 -0
  445. package/dist/{default-DY5ovGUG.mjs → default-C4v9KP56.mjs} +1 -1
  446. package/dist/{default-DY5ovGUG.mjs.map → default-C4v9KP56.mjs.map} +1 -1
  447. package/dist/{device-flow-CPXQ_QfW.mjs → device-flow-BeA6lUS1.mjs} +5 -6
  448. package/dist/device-flow-BeA6lUS1.mjs.map +1 -0
  449. package/dist/{dialect-helpers-Cue7QQOR.mjs → dialect-helpers-HxEQGl_1.mjs} +57 -11
  450. package/dist/{dialect-helpers-Cue7QQOR.mjs.map → dialect-helpers-HxEQGl_1.mjs.map} +1 -1
  451. package/dist/{email-console-CjkQc7oY.mjs → email-console-C-9Ng8DM.mjs} +1 -1
  452. package/dist/{email-console-CjkQc7oY.mjs.map → email-console-C-9Ng8DM.mjs.map} +1 -1
  453. package/dist/error-CEGF6UZb.mjs +90 -0
  454. package/dist/error-CEGF6UZb.mjs.map +1 -0
  455. package/dist/{error-CfJMLSkd.mjs → errors-DtEXIQQV.mjs} +15 -84
  456. package/dist/errors-DtEXIQQV.mjs.map +1 -0
  457. package/dist/{escape-r8_GbEU2.mjs → escape-CFedIB1C.mjs} +1 -1
  458. package/dist/{escape-r8_GbEU2.mjs.map → escape-CFedIB1C.mjs.map} +1 -1
  459. package/dist/{field-defs-cache-BVrNCgSj.mjs → field-defs-cache-DvmlgP-D.mjs} +2 -2
  460. package/dist/{field-defs-cache-BVrNCgSj.mjs.map → field-defs-cache-DvmlgP-D.mjs.map} +1 -1
  461. package/dist/{fts-manager-BD9s77qh.mjs → fts-manager-DzqIBrrW.mjs} +3 -3
  462. package/dist/{fts-manager-BD9s77qh.mjs.map → fts-manager-DzqIBrrW.mjs.map} +1 -1
  463. package/dist/{hreflang-CgIxhH4k.d.mts → hreflang-CIxH_LKz.d.mts} +2 -2
  464. package/dist/{hreflang-CgIxhH4k.d.mts.map → hreflang-CIxH_LKz.d.mts.map} +1 -1
  465. package/dist/{hreflang-pAWUiPd_.mjs → hreflang-db2Tpb2o.mjs} +5 -5
  466. package/dist/{hreflang-pAWUiPd_.mjs.map → hreflang-db2Tpb2o.mjs.map} +1 -1
  467. package/dist/{import-2jHtLzsO.mjs → import-Dmkm8S1W.mjs} +4 -4
  468. package/dist/{import-2jHtLzsO.mjs.map → import-Dmkm8S1W.mjs.map} +1 -1
  469. package/dist/{index-DxjWLKGT.d.mts → index-BEui-cRd.d.mts} +3 -3
  470. package/dist/{index-DxjWLKGT.d.mts.map → index-BEui-cRd.d.mts.map} +1 -1
  471. package/dist/{index-BXOCyLj0.d.mts → index-wYnC6u4o.d.mts} +780 -15
  472. package/dist/index-wYnC6u4o.d.mts.map +1 -0
  473. package/dist/index.d.mts +18 -19
  474. package/dist/index.mjs +59 -58
  475. package/dist/{load-DgoWMdRX.mjs → load-Cx27ki1l.mjs} +2 -2
  476. package/dist/{load-DgoWMdRX.mjs.map → load-Cx27ki1l.mjs.map} +1 -1
  477. package/dist/{loader-Rb8QlGZp.mjs → loader-Be3ouI5L.mjs} +170 -6
  478. package/dist/loader-Be3ouI5L.mjs.map +1 -0
  479. package/dist/{manifest-schema-DeGNma2O.mjs → manifest-schema-bCq54i7F.mjs} +16 -2
  480. package/dist/manifest-schema-bCq54i7F.mjs.map +1 -0
  481. package/dist/media/image-endpoint.d.mts +30 -2
  482. package/dist/media/image-endpoint.d.mts.map +1 -1
  483. package/dist/media/image-endpoint.mjs +29 -3
  484. package/dist/media/image-endpoint.mjs.map +1 -1
  485. package/dist/media/index.d.mts +1 -1
  486. package/dist/media/local-runtime.d.mts +12 -13
  487. package/dist/media/local-runtime.d.mts.map +1 -1
  488. package/dist/media/local-runtime.mjs +6 -6
  489. package/dist/{media-D2ZFowpn.mjs → media-BjhhENaJ.mjs} +2 -2
  490. package/dist/{media-D2ZFowpn.mjs.map → media-BjhhENaJ.mjs.map} +1 -1
  491. package/dist/{media-allowlist-Dc05vKtt.mjs → media-allowlist-jUppPWFy.mjs} +1 -1
  492. package/dist/{media-allowlist-Dc05vKtt.mjs.map → media-allowlist-jUppPWFy.mjs.map} +1 -1
  493. package/dist/media-kIV1IxFf.mjs +243 -0
  494. package/dist/media-kIV1IxFf.mjs.map +1 -0
  495. package/dist/media-upload-D2wk3EIt.mjs +145 -0
  496. package/dist/media-upload-D2wk3EIt.mjs.map +1 -0
  497. package/dist/{media-url-DgIEYZr4.mjs → media-url-BCm5vBn6.mjs} +1 -1
  498. package/dist/{media-url-DgIEYZr4.mjs.map → media-url-BCm5vBn6.mjs.map} +1 -1
  499. package/dist/{media-usage-B__v9NMm.mjs → media-usage-CljdO1mc.mjs} +138 -5
  500. package/dist/{media-usage-B__v9NMm.mjs.map → media-usage-CljdO1mc.mjs.map} +1 -1
  501. package/dist/{menus-BtvH7Z7t.mjs → menus-BcyElFtI.mjs} +155 -12
  502. package/dist/menus-BcyElFtI.mjs.map +1 -0
  503. package/dist/{menus-BpfevlJD.mjs → menus-CZyG6rvx.mjs} +2 -2
  504. package/dist/{menus-BpfevlJD.mjs.map → menus-CZyG6rvx.mjs.map} +1 -1
  505. package/dist/{mode-BVnhGZ2o.mjs → mode-fiXRMfeA.mjs} +1 -1
  506. package/dist/{mode-BVnhGZ2o.mjs.map → mode-fiXRMfeA.mjs.map} +1 -1
  507. package/dist/{oauth-authorization-BWqWTHBK.mjs → oauth-authorization-oqfbBuMH.mjs} +5 -6
  508. package/dist/oauth-authorization-oqfbBuMH.mjs.map +1 -0
  509. package/dist/{oauth-clients-43_XADoa.mjs → oauth-clients-BlrUHAsf.mjs} +1 -1
  510. package/dist/{oauth-clients-43_XADoa.mjs.map → oauth-clients-BlrUHAsf.mjs.map} +1 -1
  511. package/dist/{oauth-state-store-BRSUEkmx.mjs → oauth-state-store-DnvjRMy6.mjs} +2 -1
  512. package/dist/{oauth-state-store-BRSUEkmx.mjs.map → oauth-state-store-DnvjRMy6.mjs.map} +1 -1
  513. package/dist/{oauth-user-lookup-Ctgemb0k.mjs → oauth-user-lookup-oUllxvAv.mjs} +1 -1
  514. package/dist/{oauth-user-lookup-Ctgemb0k.mjs.map → oauth-user-lookup-oUllxvAv.mjs.map} +1 -1
  515. package/dist/object-cache/memory.d.mts +1 -1
  516. package/dist/{options-COXGTtqd.d.mts → options-BqMkWfYa.d.mts} +6 -6
  517. package/dist/{options-COXGTtqd.d.mts.map → options-BqMkWfYa.d.mts.map} +1 -1
  518. package/dist/page/index.d.mts +2 -2
  519. package/dist/page/index.d.mts.map +1 -1
  520. package/dist/page/index.mjs.map +1 -1
  521. package/dist/{parse-GLksnn-B.mjs → parse-C_-6klII.mjs} +4 -12
  522. package/dist/{parse-GLksnn-B.mjs.map → parse-C_-6klII.mjs.map} +1 -1
  523. package/dist/{passkey-config-CjA1UbDj.mjs → passkey-config-C-SKpc0-.mjs} +1 -1
  524. package/dist/{passkey-config-CjA1UbDj.mjs.map → passkey-config-C-SKpc0-.mjs.map} +1 -1
  525. package/dist/{placeholder-DR-eeZr-.d.mts → placeholder-Dop47JMM.d.mts} +1 -1
  526. package/dist/{placeholder-DR-eeZr-.d.mts.map → placeholder-Dop47JMM.d.mts.map} +1 -1
  527. package/dist/plugin-types.d.mts +21 -2
  528. package/dist/plugin-types.d.mts.map +1 -1
  529. package/dist/plugin-utils.d.mts +18 -17
  530. package/dist/plugin-utils.d.mts.map +1 -1
  531. package/dist/plugin-utils.mjs +8 -6
  532. package/dist/plugin-utils.mjs.map +1 -1
  533. package/dist/plugins/adapt-sandbox-entry.d.mts +10 -11
  534. package/dist/plugins/adapt-sandbox-entry.d.mts.map +1 -1
  535. package/dist/plugins/adapt-sandbox-entry.mjs +15 -3
  536. package/dist/plugins/adapt-sandbox-entry.mjs.map +1 -1
  537. package/dist/{portable-text-BAkgEKcv.mjs → portable-text-sDj92Kxv.mjs} +1 -1
  538. package/dist/{portable-text-BAkgEKcv.mjs.map → portable-text-sDj92Kxv.mjs.map} +1 -1
  539. package/dist/{preview-Rloa09Wp.mjs → preview-D4Jnbfx7.mjs} +2 -2
  540. package/dist/{preview-Rloa09Wp.mjs.map → preview-D4Jnbfx7.mjs.map} +1 -1
  541. package/dist/{public-url-C0cEvrRu.mjs → public-url-DSGTnJFw.mjs} +5 -3
  542. package/dist/public-url-DSGTnJFw.mjs.map +1 -0
  543. package/dist/{query-ZzvXyxWq.mjs → query-DR73ZNfm.mjs} +14 -14
  544. package/dist/{query-ZzvXyxWq.mjs.map → query-DR73ZNfm.mjs.map} +1 -1
  545. package/dist/{query-BxT95opY.mjs → query-Di7DOmPV.mjs} +3 -3
  546. package/dist/{query-BxT95opY.mjs.map → query-Di7DOmPV.mjs.map} +1 -1
  547. package/dist/{rate-limit-Cg4Rvc_-.mjs → rate-limit-CMj83JNW.mjs} +2 -2
  548. package/dist/{rate-limit-Cg4Rvc_-.mjs.map → rate-limit-CMj83JNW.mjs.map} +1 -1
  549. package/dist/{redirect-Ce_6Yb6z.mjs → redirect-Botom7X6.mjs} +1 -1
  550. package/dist/{redirect-Ce_6Yb6z.mjs.map → redirect-Botom7X6.mjs.map} +1 -1
  551. package/dist/{redirect-Ch3E98qZ.mjs → redirect-CgLPYflR.mjs} +10 -4
  552. package/dist/redirect-CgLPYflR.mjs.map +1 -0
  553. package/dist/{redirects-CXmVGRNZ.mjs → redirects-B7t9bKsL.mjs} +4 -4
  554. package/dist/{redirects-CXmVGRNZ.mjs.map → redirects-B7t9bKsL.mjs.map} +1 -1
  555. package/dist/{redirects-CeD7K7EX.mjs → redirects-BBq3n2Rj.mjs} +4 -175
  556. package/dist/redirects-BBq3n2Rj.mjs.map +1 -0
  557. package/dist/{registry-CyIXPi4E.mjs → registry-FV15nLge.mjs} +97 -8
  558. package/dist/registry-FV15nLge.mjs.map +1 -0
  559. package/dist/{relation-Ba68Tm4Z.mjs → relation-9M9j_UWo.mjs} +3 -3
  560. package/dist/{relation-Ba68Tm4Z.mjs.map → relation-9M9j_UWo.mjs.map} +1 -1
  561. package/dist/{relations-BmBmX4Eb.mjs → relations-5_avdrN_.mjs} +2 -2
  562. package/dist/{relations-BmBmX4Eb.mjs.map → relations-5_avdrN_.mjs.map} +1 -1
  563. package/dist/{relations-C8hVyEy0.mjs → relations-BKvO39-9.mjs} +5 -5
  564. package/dist/{relations-C8hVyEy0.mjs.map → relations-BKvO39-9.mjs.map} +1 -1
  565. package/dist/{relations-CbBpoOys.d.mts → relations-Bh8jlFsU.d.mts} +306 -4
  566. package/dist/relations-Bh8jlFsU.d.mts.map +1 -0
  567. package/dist/{request-meta-DCwktC5P.mjs → request-meta-DzXYYI-n.mjs} +2 -2
  568. package/dist/{request-meta-DCwktC5P.mjs.map → request-meta-DzXYYI-n.mjs.map} +1 -1
  569. package/dist/{runner-CiNdIk3y.d.mts → runner-Dd8m8k9F.d.mts} +2 -2
  570. package/dist/{runner-CiNdIk3y.d.mts.map → runner-Dd8m8k9F.d.mts.map} +1 -1
  571. package/dist/{runner-jt65bF7F.mjs → runner-DfnZ5eUr.mjs} +333 -199
  572. package/dist/runner-DfnZ5eUr.mjs.map +1 -0
  573. package/dist/runtime.d.mts +11 -12
  574. package/dist/runtime.d.mts.map +1 -1
  575. package/dist/runtime.mjs +4 -4
  576. package/dist/{schema-DwjufZ1S.mjs → schema-BXxlHeAf.mjs} +3 -3
  577. package/dist/{schema-DwjufZ1S.mjs.map → schema-BXxlHeAf.mjs.map} +1 -1
  578. package/dist/scopes-Bl4IwHA-.mjs +27 -0
  579. package/dist/scopes-Bl4IwHA-.mjs.map +1 -0
  580. package/dist/{search-Cl875CVE.mjs → search-Bff-7jFt.mjs} +5 -5
  581. package/dist/{search-Cl875CVE.mjs.map → search-Bff-7jFt.mjs.map} +1 -1
  582. package/dist/{secrets-CO_bEmII.mjs → secrets-CSwQIl4q.mjs} +3 -3
  583. package/dist/{secrets-CO_bEmII.mjs.map → secrets-CSwQIl4q.mjs.map} +1 -1
  584. package/dist/{sections-DTKzgoiS.mjs → sections-CwW4s1al.mjs} +3 -3
  585. package/dist/{sections-DTKzgoiS.mjs.map → sections-CwW4s1al.mjs.map} +1 -1
  586. package/dist/seed/index.d.mts +2 -2
  587. package/dist/seed/index.mjs +20 -20
  588. package/dist/seo/index.d.mts +14 -3
  589. package/dist/seo/index.d.mts.map +1 -1
  590. package/dist/seo/index.mjs +16 -16
  591. package/dist/seo/index.mjs.map +1 -1
  592. package/dist/{seo-BLm6SXzS.mjs → seo-2cmFHZns.mjs} +2 -2
  593. package/dist/{seo-BLm6SXzS.mjs.map → seo-2cmFHZns.mjs.map} +1 -1
  594. package/dist/{seo-BjrbXAd_.mjs → seo-C3GDfT0V.mjs} +1 -1
  595. package/dist/{seo-BjrbXAd_.mjs.map → seo-C3GDfT0V.mjs.map} +1 -1
  596. package/dist/{service-D6zDmKXy.mjs → service-DkGTWGIi.mjs} +3 -3
  597. package/dist/{service-D6zDmKXy.mjs.map → service-DkGTWGIi.mjs.map} +1 -1
  598. package/dist/{session-user-DoSs6YM8.mjs → session-user-DbHqKDKe.mjs} +1 -1
  599. package/dist/{session-user-DoSs6YM8.mjs.map → session-user-DbHqKDKe.mjs.map} +1 -1
  600. package/dist/{settings-CmS3TwXf.mjs → settings-C4s8hFQm.mjs} +3 -3
  601. package/dist/{settings-CmS3TwXf.mjs.map → settings-C4s8hFQm.mjs.map} +1 -1
  602. package/dist/{settings-BuQYvLfy.mjs → settings-CpA4lQFt.mjs} +4 -4
  603. package/dist/{settings-BuQYvLfy.mjs.map → settings-CpA4lQFt.mjs.map} +1 -1
  604. package/dist/{setup-complete-BPNgLHlU.mjs → setup-complete-CdIlqloh.mjs} +1 -1
  605. package/dist/{setup-complete-BPNgLHlU.mjs.map → setup-complete-CdIlqloh.mjs.map} +1 -1
  606. package/dist/{setup-nonce-DEPZX96T.mjs → setup-nonce-DqiIPr-J.mjs} +1 -1
  607. package/dist/{setup-nonce-DEPZX96T.mjs.map → setup-nonce-DqiIPr-J.mjs.map} +1 -1
  608. package/dist/{single-flight-cache-DEtW-OEG.mjs → single-flight-cache-C2exrGAi.mjs} +1 -1
  609. package/dist/{single-flight-cache-DEtW-OEG.mjs.map → single-flight-cache-C2exrGAi.mjs.map} +1 -1
  610. package/dist/{site-url-CcLy5D5s.mjs → site-url-NGJT6NTU.mjs} +1 -1
  611. package/dist/{site-url-CcLy5D5s.mjs.map → site-url-NGJT6NTU.mjs.map} +1 -1
  612. package/dist/snapshot-BdpUJKD-.mjs +216 -0
  613. package/dist/snapshot-BdpUJKD-.mjs.map +1 -0
  614. package/dist/{ssrf-TrKYJAy0.mjs → ssrf-CviKqWmq.mjs} +1 -1
  615. package/dist/{ssrf-TrKYJAy0.mjs.map → ssrf-CviKqWmq.mjs.map} +1 -1
  616. package/dist/state-xxv6ZTMv.mjs +128 -0
  617. package/dist/state-xxv6ZTMv.mjs.map +1 -0
  618. package/dist/{status-D3Gy1Zc6.mjs → status-COfycGIU.mjs} +1 -1
  619. package/dist/{status-D3Gy1Zc6.mjs.map → status-COfycGIU.mjs.map} +1 -1
  620. package/dist/storage/local.d.mts +1 -1
  621. package/dist/storage/local.mjs +1 -1
  622. package/dist/storage/s3.d.mts +1 -1
  623. package/dist/storage/s3.mjs +1 -1
  624. package/dist/{taxonomies-ClS4RKaZ.mjs → taxonomies-Ce49uIzY.mjs} +4 -4
  625. package/dist/{taxonomies-ClS4RKaZ.mjs.map → taxonomies-Ce49uIzY.mjs.map} +1 -1
  626. package/dist/{taxonomies-pUkuD6nj.mjs → taxonomies-DjSKBZpq.mjs} +7 -7
  627. package/dist/{taxonomies-pUkuD6nj.mjs.map → taxonomies-DjSKBZpq.mjs.map} +1 -1
  628. package/dist/{taxonomy-BkxbUMSw.mjs → taxonomy-DfVooU4W.mjs} +51 -13
  629. package/dist/taxonomy-DfVooU4W.mjs.map +1 -0
  630. package/dist/{tokens-BV6fgl5A.mjs → tokens-DVltpO2D.mjs} +2 -2
  631. package/dist/{tokens-BV6fgl5A.mjs.map → tokens-DVltpO2D.mjs.map} +1 -1
  632. package/dist/{transport-DTFhhPOg.mjs → transport-CKrlqSpD.mjs} +1 -1
  633. package/dist/{transport-DTFhhPOg.mjs.map → transport-CKrlqSpD.mjs.map} +1 -1
  634. package/dist/{transport-DmlmzD2U.d.mts → transport-Vd7VdqHv.d.mts} +1 -1
  635. package/dist/{transport-DmlmzD2U.d.mts.map → transport-Vd7VdqHv.d.mts.map} +1 -1
  636. package/dist/{trusted-proxy-CSgZVESw.mjs → trusted-proxy-CwjQj0YG.mjs} +1 -1
  637. package/dist/{trusted-proxy-CSgZVESw.mjs.map → trusted-proxy-CwjQj0YG.mjs.map} +1 -1
  638. package/dist/{types-B6-N9cBB.d.mts → types-B4vm81VH.d.mts} +1 -1
  639. package/dist/{types-B6-N9cBB.d.mts.map → types-B4vm81VH.d.mts.map} +1 -1
  640. package/dist/{types-Cm4Cz-8M.d.mts → types-B97jg3aW.d.mts} +6 -1
  641. package/dist/{types-Cm4Cz-8M.d.mts.map → types-B97jg3aW.d.mts.map} +1 -1
  642. package/dist/{types-BNZsPL9z.mjs → types-BD40g7zz.mjs} +1 -1
  643. package/dist/{types-BNZsPL9z.mjs.map → types-BD40g7zz.mjs.map} +1 -1
  644. package/dist/{types-QnlQIyPE.d.mts → types-BNfPHfay.d.mts} +1 -1
  645. package/dist/{types-QnlQIyPE.d.mts.map → types-BNfPHfay.d.mts.map} +1 -1
  646. package/dist/{types-DLIrNtv5.d.mts → types-BfYUPJdP.d.mts} +2 -2
  647. package/dist/{types-DLIrNtv5.d.mts.map → types-BfYUPJdP.d.mts.map} +1 -1
  648. package/dist/{types-CtDVagM4.d.mts → types-BvB7gDOD.d.mts} +38 -4
  649. package/dist/types-BvB7gDOD.d.mts.map +1 -0
  650. package/dist/{types-B_pmP7Yq.d.mts → types-C7U0HlEr.d.mts} +1 -1
  651. package/dist/{types-B_pmP7Yq.d.mts.map → types-C7U0HlEr.d.mts.map} +1 -1
  652. package/dist/{types-Ch8pFMEm.mjs → types-D1iJ3DpO.mjs} +3 -3
  653. package/dist/{types-Ch8pFMEm.mjs.map → types-D1iJ3DpO.mjs.map} +1 -1
  654. package/dist/{types-momGysZk.d.mts → types-DPKhI5ib.d.mts} +9 -1
  655. package/dist/types-DPKhI5ib.d.mts.map +1 -0
  656. package/dist/{types-BCVuUPrL.d.mts → types-Kmaxdarz.d.mts} +1 -1
  657. package/dist/{types-BCVuUPrL.d.mts.map → types-Kmaxdarz.d.mts.map} +1 -1
  658. package/dist/{types-qljd1hsL.d.mts → types-iVeZ5g6N.d.mts} +1 -1
  659. package/dist/{types-qljd1hsL.d.mts.map → types-iVeZ5g6N.d.mts.map} +1 -1
  660. package/dist/{user-DTxX_Fha.mjs → user-Bh-L1qo6.mjs} +3 -3
  661. package/dist/{user-DTxX_Fha.mjs.map → user-Bh-L1qo6.mjs.map} +1 -1
  662. package/dist/{utils-Cz8PVrl4.mjs → utils-BbUgmeZG.mjs} +1 -1
  663. package/dist/{utils-Cz8PVrl4.mjs.map → utils-BbUgmeZG.mjs.map} +1 -1
  664. package/dist/{validate-9jLuE301.d.mts → validate-DULfgpJP.d.mts} +5 -5
  665. package/dist/{validate-9jLuE301.d.mts.map → validate-DULfgpJP.d.mts.map} +1 -1
  666. package/dist/{validate-C3CpWlNt.mjs → validate-V9nCwq_-.mjs} +2 -2
  667. package/dist/{validate-C3CpWlNt.mjs.map → validate-V9nCwq_-.mjs.map} +1 -1
  668. package/dist/{validation-DM2K_NJC.mjs → validation-BsVUJfsP.mjs} +10 -10
  669. package/dist/{validation-DM2K_NJC.mjs.map → validation-BsVUJfsP.mjs.map} +1 -1
  670. package/dist/version-907opKac.mjs +7 -0
  671. package/dist/{version-BlIJvNAZ.mjs.map → version-907opKac.mjs.map} +1 -1
  672. package/dist/{widgets-B_X6_UXJ.mjs → widgets-DGv1Z04V.mjs} +3 -3
  673. package/dist/{widgets-B_X6_UXJ.mjs.map → widgets-DGv1Z04V.mjs.map} +1 -1
  674. package/dist/{wxr-taxonomies-tADW4KTa.d.mts → wxr-taxonomies-B4tMuN5T.d.mts} +1 -1
  675. package/dist/{wxr-taxonomies-tADW4KTa.d.mts.map → wxr-taxonomies-B4tMuN5T.d.mts.map} +1 -1
  676. package/dist/{wxr-taxonomies-oNJB2S81.mjs → wxr-taxonomies-Cs1N6O8z.mjs} +3 -3
  677. package/dist/{wxr-taxonomies-oNJB2S81.mjs.map → wxr-taxonomies-Cs1N6O8z.mjs.map} +1 -1
  678. package/dist/{zod-generator-CrfV79De.mjs → zod-generator-B5prQ5M4.mjs} +2 -2
  679. package/dist/{zod-generator-CrfV79De.mjs.map → zod-generator-B5prQ5M4.mjs.map} +1 -1
  680. package/package.json +8 -8
  681. package/src/api/authorize.ts +10 -1
  682. package/src/api/error.ts +5 -5
  683. package/src/api/errors.ts +14 -0
  684. package/src/api/handlers/backup.ts +312 -0
  685. package/src/api/handlers/content.ts +36 -2
  686. package/src/api/handlers/device-flow.ts +2 -3
  687. package/src/api/handlers/index.ts +16 -0
  688. package/src/api/handlers/marketplace.ts +38 -0
  689. package/src/api/handlers/media-upload.ts +210 -0
  690. package/src/api/handlers/media-usage.ts +211 -2
  691. package/src/api/handlers/oauth-authorization.ts +2 -6
  692. package/src/api/handlers/plugin-settings.ts +218 -0
  693. package/src/api/handlers/plugins.ts +41 -0
  694. package/src/api/handlers/registry.ts +39 -0
  695. package/src/api/handlers/snapshot.ts +21 -3
  696. package/src/api/openapi/document.ts +48 -6
  697. package/src/api/parse.ts +1 -15
  698. package/src/api/public-url.ts +4 -2
  699. package/src/api/schemas/common.ts +6 -2
  700. package/src/api/schemas/media-usage.ts +72 -0
  701. package/src/api/schemas/media.ts +32 -1
  702. package/src/astro/integration/index.ts +38 -0
  703. package/src/astro/integration/routes.ts +35 -0
  704. package/src/astro/integration/runtime.ts +6 -0
  705. package/src/astro/integration/virtual-modules.ts +41 -7
  706. package/src/astro/integration/vite-config.ts +17 -1
  707. package/src/astro/middleware/auth.ts +70 -78
  708. package/src/astro/middleware/csp.ts +5 -2
  709. package/src/astro/middleware.ts +86 -31
  710. package/src/astro/public-plugin-api-routes.ts +2 -1
  711. package/src/astro/routes/PluginRegistry.tsx +5 -2
  712. package/src/astro/routes/admin.astro +56 -16
  713. package/src/astro/routes/api/admin/api-tokens/index.ts +2 -2
  714. package/src/astro/routes/api/admin/bylines/[id]/translations.ts +2 -5
  715. package/src/astro/routes/api/admin/plugins/[id]/index.ts +6 -0
  716. package/src/astro/routes/api/admin/plugins/[id]/mcp.ts +42 -0
  717. package/src/astro/routes/api/admin/plugins/[id]/settings.ts +80 -0
  718. package/src/astro/routes/api/admin/plugins/[id]/update.ts +2 -0
  719. package/src/astro/routes/api/admin/plugins/index.ts +9 -0
  720. package/src/astro/routes/api/admin/plugins/marketplace/[id]/install.ts +2 -0
  721. package/src/astro/routes/api/admin/plugins/registry/[id]/update.ts +2 -0
  722. package/src/astro/routes/api/admin/plugins/registry/install.ts +2 -0
  723. package/src/astro/routes/api/admin/plugins/updates.ts +2 -4
  724. package/src/astro/routes/api/auth/mode.ts +6 -14
  725. package/src/astro/routes/api/auth/oauth/[provider]/callback.ts +21 -4
  726. package/src/astro/routes/api/auth/oauth/[provider].ts +24 -6
  727. package/src/astro/routes/api/content/[collection]/[id]/compare.ts +3 -4
  728. package/src/astro/routes/api/content/[collection]/[id]/duplicate.ts +2 -3
  729. package/src/astro/routes/api/content/[collection]/[id]/permanent.ts +2 -3
  730. package/src/astro/routes/api/content/[collection]/[id]/preview-url.ts +3 -4
  731. package/src/astro/routes/api/content/[collection]/[id]/references/[relation]/children.ts +4 -6
  732. package/src/astro/routes/api/content/[collection]/[id]/references/[relation]/parents.ts +2 -3
  733. package/src/astro/routes/api/content/[collection]/[id]/revisions.ts +3 -4
  734. package/src/astro/routes/api/content/[collection]/[id]/terms/[taxonomy].ts +4 -6
  735. package/src/astro/routes/api/content/[collection]/[id]/translations.ts +3 -4
  736. package/src/astro/routes/api/content/[collection]/[id].ts +3 -4
  737. package/src/astro/routes/api/content/[collection]/authors.ts +2 -3
  738. package/src/astro/routes/api/content/[collection]/index.ts +6 -8
  739. package/src/astro/routes/api/content/[collection]/trash.ts +2 -3
  740. package/src/astro/routes/api/manifest.ts +2 -9
  741. package/src/astro/routes/api/mcp.ts +2 -1
  742. package/src/astro/routes/api/media/[id]/usage.ts +30 -0
  743. package/src/astro/routes/api/media/[id].ts +17 -6
  744. package/src/astro/routes/api/media/file/[...key].ts +8 -0
  745. package/src/astro/routes/api/media.ts +21 -2
  746. package/src/astro/routes/api/oauth/authorize.ts +2 -6
  747. package/src/astro/routes/api/plugins/[pluginId]/[...path].ts +17 -3
  748. package/src/astro/routes/api/settings/backups/archives/[name].ts +78 -0
  749. package/src/astro/routes/api/settings/backups/archives/index.ts +33 -0
  750. package/src/astro/routes/api/settings/backups/export.ts +43 -0
  751. package/src/astro/routes/api/settings/backups/index.ts +76 -0
  752. package/src/astro/routes/api/setup/admin-verify.ts +8 -4
  753. package/src/astro/routes/api/setup/admin.ts +11 -4
  754. package/src/astro/routes/api/well-known/oauth-authorization-server.ts +4 -1
  755. package/src/astro/routes/api/well-known/oauth-protected-resource.ts +5 -1
  756. package/src/astro/types.ts +48 -2
  757. package/src/auth/api-tokens.ts +1 -0
  758. package/src/auth/oauth-state-store.ts +3 -0
  759. package/src/auth/providers/github-admin.tsx +5 -6
  760. package/src/auth/providers/google-admin.tsx +5 -6
  761. package/src/auth/scopes.ts +3 -9
  762. package/src/cli/client-factory.ts +0 -1
  763. package/src/cli/commands/bundle-utils.ts +50 -1
  764. package/src/cli/commands/bundle.ts +9 -2
  765. package/src/cli/commands/media.ts +127 -0
  766. package/src/client/index.ts +84 -2
  767. package/src/client/transport.ts +1 -1
  768. package/src/components/EmDashHead.astro +4 -8
  769. package/src/components/InlinePortableTextEditor.tsx +56 -35
  770. package/src/components/marks/Link.astro +5 -1
  771. package/src/database/dialect-helpers.ts +77 -3
  772. package/src/database/migrations/051_content_taxonomies_denorm.ts +120 -0
  773. package/src/database/migrations/052_media_usage_read_index.ts +26 -0
  774. package/src/database/migrations/053_plugin_mcp_tools.ts +21 -0
  775. package/src/database/migrations/runner.ts +6 -0
  776. package/src/database/repositories/audit.ts +2 -1
  777. package/src/database/repositories/content.ts +98 -16
  778. package/src/database/repositories/media-usage.ts +250 -1
  779. package/src/database/repositories/plugin-storage.ts +29 -32
  780. package/src/database/repositories/redirect.ts +14 -2
  781. package/src/database/repositories/taxonomy.ts +57 -8
  782. package/src/database/types.ts +23 -0
  783. package/src/db/adapters.ts +9 -0
  784. package/src/emdash-runtime.ts +310 -66
  785. package/src/loader.ts +292 -1
  786. package/src/mcp/server.ts +222 -5
  787. package/src/media/image-endpoint.ts +38 -2
  788. package/src/page/metadata.ts +27 -0
  789. package/src/plugin-types.ts +19 -0
  790. package/src/plugin-utils.ts +8 -6
  791. package/src/plugins/adapt-sandbox-entry.ts +30 -1
  792. package/src/plugins/context.ts +7 -0
  793. package/src/plugins/define-plugin.ts +16 -0
  794. package/src/plugins/manifest-schema.ts +28 -1
  795. package/src/plugins/routes.ts +27 -1
  796. package/src/plugins/sandbox/runner-options.ts +16 -0
  797. package/src/plugins/sandbox/types.ts +6 -1
  798. package/src/plugins/state.ts +17 -1
  799. package/src/plugins/storage-query.ts +67 -33
  800. package/src/plugins/types.ts +41 -0
  801. package/src/schema/registry.ts +141 -5
  802. package/src/seed/apply.ts +28 -29
  803. package/src/seo/index.ts +19 -4
  804. package/src/storage/types.ts +6 -0
  805. package/src/utils/base64.ts +7 -2
  806. package/src/utils/db-errors.ts +3 -1
  807. package/src/virtual-modules.d.ts +13 -0
  808. package/src/visual-editing/toolbar.ts +1 -1
  809. package/dist/adapters-DPAkL6QF.d.mts.map +0 -1
  810. package/dist/api-DVbHNApo.mjs.map +0 -1
  811. package/dist/api-tokens-Dk2GrJMY.mjs +0 -3
  812. package/dist/apply-D23iUV4q.mjs.map +0 -1
  813. package/dist/authorize-BmCwQCib.mjs.map +0 -1
  814. package/dist/base64-C74Msx8h.mjs.map +0 -1
  815. package/dist/content-BO61Sx4j.mjs.map +0 -1
  816. package/dist/content-refresh-BkkApzeS.mjs.map +0 -1
  817. package/dist/context-DtSFYFuS.mjs.map +0 -1
  818. package/dist/db-errors-BKuXh_fi.mjs.map +0 -1
  819. package/dist/device-flow-CPXQ_QfW.mjs.map +0 -1
  820. package/dist/error-CfJMLSkd.mjs.map +0 -1
  821. package/dist/index-BXOCyLj0.d.mts.map +0 -1
  822. package/dist/loader-Rb8QlGZp.mjs.map +0 -1
  823. package/dist/manifest-schema-DeGNma2O.mjs.map +0 -1
  824. package/dist/menus-BtvH7Z7t.mjs.map +0 -1
  825. package/dist/oauth-authorization-BWqWTHBK.mjs.map +0 -1
  826. package/dist/public-url-C0cEvrRu.mjs.map +0 -1
  827. package/dist/redirect-Ch3E98qZ.mjs.map +0 -1
  828. package/dist/redirects-CeD7K7EX.mjs.map +0 -1
  829. package/dist/registry-CyIXPi4E.mjs.map +0 -1
  830. package/dist/relations-CbBpoOys.d.mts.map +0 -1
  831. package/dist/runner-jt65bF7F.mjs.map +0 -1
  832. package/dist/scheduled-publish-DlJHGcuL.d.mts +0 -11
  833. package/dist/scheduled-publish-DlJHGcuL.d.mts.map +0 -1
  834. package/dist/taxonomy-BkxbUMSw.mjs.map +0 -1
  835. package/dist/types-CtDVagM4.d.mts.map +0 -1
  836. package/dist/types-momGysZk.d.mts.map +0 -1
  837. package/dist/version-BlIJvNAZ.mjs +0 -7
  838. /package/dist/{ssrf-B5DOv5E5.mjs → ssrf-BB__xfNM.mjs} +0 -0
  839. /package/dist/{types-DeCZBZxn.mjs → types-CK0LxPUQ.mjs} +0 -0
@@ -1,3 +0,0 @@
1
- import { TOKEN_PREFIXES, VALID_SCOPES, generatePrefixedToken, hasScope, hashPrefixedToken as hashApiToken } from "@emdash-cms/auth";
2
-
3
- export { hashApiToken as a, hasScope as i, VALID_SCOPES as n, generatePrefixedToken as r, TOKEN_PREFIXES as t };
@@ -1 +0,0 @@
1
- {"version":3,"file":"apply-D23iUV4q.mjs","names":[],"sources":["../src/seed/apply.ts"],"sourcesContent":["/**\n * Seed engine - applies seed files to database\n *\n * This is the core implementation that bootstraps an EmDash site from a seed file.\n * Apply order is critical for foreign keys and references.\n */\n\nimport { imageSize } from \"image-size\";\nimport type { Kysely } from \"kysely\";\nimport mime from \"mime/lite\";\nimport { ulid } from \"ulidx\";\n\nimport { BylineRepository } from \"../database/repositories/byline.js\";\nimport { ContentRepository } from \"../database/repositories/content.js\";\nimport { MediaRepository } from \"../database/repositories/media.js\";\nimport { RedirectRepository } from \"../database/repositories/redirect.js\";\nimport { RevisionRepository } from \"../database/repositories/revision.js\";\nimport { TaxonomyRepository } from \"../database/repositories/taxonomy.js\";\nimport { withTransaction } from \"../database/transaction.js\";\nimport type { Database } from \"../database/types.js\";\nimport type { MediaValue } from \"../fields/types.js\";\nimport { getI18nConfig } from \"../i18n/config.js\";\nimport { ssrfSafeFetch, validateExternalUrl } from \"../import/ssrf.js\";\nimport { markContentMediaUsageCollectionStaleSafely } from \"../media/usage/content-refresh.js\";\nimport { SchemaRegistry } from \"../schema/registry.js\";\nimport { FTSManager } from \"../search/fts-manager.js\";\nimport { setSiteSettings } from \"../settings/index.js\";\nimport type { Storage } from \"../storage/types.js\";\nimport type {\n\tSeedFile,\n\tSeedApplyOptions,\n\tSeedApplyResult,\n\tSeedTaxonomyTerm,\n\tSeedMenuItem,\n\tSeedWidget,\n\tSeedMediaReference,\n\tSeedBylineAvatar,\n} from \"./types.js\";\n\nconst FILE_EXTENSION_PATTERN = /\\.([a-z0-9]+)(?:\\?|$)/i;\nimport { validateSeed } from \"./validate.js\";\n\n/** Pattern to remove file extensions */\nconst EXTENSION_PATTERN = /\\.[^.]+$/;\n\n/** Pattern to remove query parameters */\nconst QUERY_PARAM_PATTERN = /\\?.*$/;\n\n/** Pattern to remove non-alphanumeric characters (except dash and underscore) */\nconst SANITIZE_PATTERN = /[^a-zA-Z0-9_-]/g;\n\n/** Pattern to collapse multiple hyphens */\nconst MULTIPLE_HYPHENS_PATTERN = /-+/g;\n\n/**\n * Apply a seed file to the database\n *\n * This function is idempotent - safe to run multiple times.\n *\n * @param db - Kysely database instance\n * @param seed - Seed file to apply\n * @param options - Application options\n * @returns Result summary\n */\nexport async function applySeed(\n\tdb: Kysely<Database>,\n\tseed: SeedFile,\n\toptions: SeedApplyOptions = {},\n): Promise<SeedApplyResult> {\n\t// Validate seed first\n\tconst validation = validateSeed(seed);\n\tif (!validation.valid) {\n\t\tthrow new Error(`Invalid seed file:\\n${validation.errors.join(\"\\n\")}`);\n\t}\n\n\tconst {\n\t\tincludeContent = false,\n\t\tstorage,\n\t\tskipMediaDownload = false,\n\t\tonConflict = \"skip\",\n\t} = options;\n\n\t// Result counters\n\tconst result: SeedApplyResult = {\n\t\tcollections: { created: 0, skipped: 0, updated: 0 },\n\t\tfields: { created: 0, skipped: 0, updated: 0 },\n\t\ttaxonomies: { created: 0, terms: 0 },\n\t\tbylines: { created: 0, skipped: 0, updated: 0 },\n\t\tmenus: { created: 0, items: 0 },\n\t\tredirects: { created: 0, skipped: 0, updated: 0 },\n\t\twidgetAreas: { created: 0, widgets: 0 },\n\t\tsections: { created: 0, skipped: 0, updated: 0 },\n\t\tsettings: { applied: 0 },\n\t\tcontent: { created: 0, skipped: 0, updated: 0 },\n\t\tmedia: { created: 0, skipped: 0 },\n\t};\n\n\t// Media context for $media resolution\n\tconst mediaContext: MediaContext = {\n\t\tdb,\n\t\tstorage: storage ?? null,\n\t\tskipMediaDownload,\n\t\tmediaCache: new Map(), // Cache downloaded media by URL to avoid re-downloading\n\t};\n\n\t// Apply order (critical for foreign keys and references):\n\t// 1. Site settings\n\t// 2. Collections + Fields\n\t// 3. Taxonomy definitions + Terms\n\t// 4. Content (so menu refs can resolve)\n\t// 5. Menus + Menu items (can now resolve content refs)\n\t// 6. Redirects\n\t// 7. Widget areas + Widgets\n\n\t// Track seed content IDs for reference resolution (shared across content and menus)\n\tconst seedIdMap = new Map<string, string>(); // seed id -> real entry id\n\tconst seedBylineIdMap = new Map<string, string>(); // seed byline id -> real byline id\n\tconst staleMarkedContentCollections = new Set<string>();\n\tconst failedStaleContentCollections = new Set<string>();\n\n\t// Fallback locale for rows that omit an explicit `locale`. Prefer the runtime\n\t// config (runtime-driven seeds), then the seed's self-described `defaultLocale`\n\t// (CLI exports run outside the runtime), and only then `en`. Without the\n\t// seed-carried default, a non-`en` single-locale project would be rewritten to\n\t// `en` on apply (#1421).\n\tconst defaultLocale = getI18nConfig()?.defaultLocale ?? seed.defaultLocale ?? \"en\";\n\tconst markSeedContentCollectionStale = async (collectionSlug: string): Promise<void> => {\n\t\tif (staleMarkedContentCollections.has(collectionSlug)) return;\n\t\tconst marked = await markContentMediaUsageCollectionStaleSafely(\n\t\t\tdb,\n\t\t\tcollectionSlug,\n\t\t\t\"CONTENT_USAGE_STALE\",\n\t\t);\n\t\tif (marked) {\n\t\t\tstaleMarkedContentCollections.add(collectionSlug);\n\t\t\tfailedStaleContentCollections.delete(collectionSlug);\n\t\t} else {\n\t\t\tfailedStaleContentCollections.add(collectionSlug);\n\t\t}\n\t};\n\tconst retryFailedSeedContentStaleMarks = async (): Promise<void> => {\n\t\tfor (const collectionSlug of failedStaleContentCollections) {\n\t\t\tconst marked = await markContentMediaUsageCollectionStaleSafely(\n\t\t\t\tdb,\n\t\t\t\tcollectionSlug,\n\t\t\t\t\"CONTENT_USAGE_STALE\",\n\t\t\t);\n\t\t\tif (marked) {\n\t\t\t\tstaleMarkedContentCollections.add(collectionSlug);\n\t\t\t\tfailedStaleContentCollections.delete(collectionSlug);\n\t\t\t}\n\t\t}\n\t};\n\n\t// 1. Site settings\n\tif (seed.settings) {\n\t\tawait setSiteSettings(seed.settings, db);\n\t\tresult.settings.applied = Object.keys(seed.settings).length;\n\t}\n\n\t// 2-3. Collections and Fields\n\tif (seed.collections) {\n\t\tconst registry = new SchemaRegistry(db);\n\n\t\tfor (const collection of seed.collections) {\n\t\t\t// Check if collection exists\n\t\t\tconst existing = await registry.getCollection(collection.slug);\n\n\t\t\tif (existing) {\n\t\t\t\tif (onConflict === \"error\") {\n\t\t\t\t\tthrow new Error(`Conflict: collection \"${collection.slug}\" already exists`);\n\t\t\t\t}\n\n\t\t\t\tif (onConflict === \"update\") {\n\t\t\t\t\tawait registry.updateCollection(collection.slug, {\n\t\t\t\t\t\tlabel: collection.label,\n\t\t\t\t\t\tlabelSingular: collection.labelSingular,\n\t\t\t\t\t\tdescription: collection.description,\n\t\t\t\t\t\ticon: collection.icon,\n\t\t\t\t\t\tsupports: collection.supports || [],\n\t\t\t\t\t\turlPattern: collection.urlPattern,\n\t\t\t\t\t\tcommentsEnabled: collection.commentsEnabled,\n\t\t\t\t\t});\n\t\t\t\t\tresult.collections.updated++;\n\n\t\t\t\t\t// Update or create fields\n\t\t\t\t\tfor (const field of collection.fields) {\n\t\t\t\t\t\tconst existingField = await registry.getField(collection.slug, field.slug);\n\t\t\t\t\t\tif (existingField) {\n\t\t\t\t\t\t\tawait registry.updateField(collection.slug, field.slug, {\n\t\t\t\t\t\t\t\tlabel: field.label,\n\t\t\t\t\t\t\t\ttype: field.type,\n\t\t\t\t\t\t\t\trequired: field.required || false,\n\t\t\t\t\t\t\t\tunique: field.unique || false,\n\t\t\t\t\t\t\t\tsearchable: field.searchable || false,\n\t\t\t\t\t\t\t\tdefaultValue: field.defaultValue,\n\t\t\t\t\t\t\t\tvalidation: field.validation,\n\t\t\t\t\t\t\t\twidget: field.widget,\n\t\t\t\t\t\t\t\toptions: field.options,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tresult.fields.updated++;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tawait registry.createField(collection.slug, {\n\t\t\t\t\t\t\t\tslug: field.slug,\n\t\t\t\t\t\t\t\tlabel: field.label,\n\t\t\t\t\t\t\t\ttype: field.type,\n\t\t\t\t\t\t\t\trequired: field.required || false,\n\t\t\t\t\t\t\t\tunique: field.unique || false,\n\t\t\t\t\t\t\t\tsearchable: field.searchable || false,\n\t\t\t\t\t\t\t\tdefaultValue: field.defaultValue,\n\t\t\t\t\t\t\t\tvalidation: field.validation,\n\t\t\t\t\t\t\t\twidget: field.widget,\n\t\t\t\t\t\t\t\toptions: field.options,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tresult.fields.created++;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// skip\n\t\t\t\tresult.collections.skipped++;\n\t\t\t\tresult.fields.skipped += collection.fields.length;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Create collection\n\t\t\tawait registry.createCollection({\n\t\t\t\tslug: collection.slug,\n\t\t\t\tlabel: collection.label,\n\t\t\t\tlabelSingular: collection.labelSingular,\n\t\t\t\tdescription: collection.description,\n\t\t\t\ticon: collection.icon,\n\t\t\t\tsupports: collection.supports || [],\n\t\t\t\tsource: \"seed\",\n\t\t\t\turlPattern: collection.urlPattern,\n\t\t\t\tcommentsEnabled: collection.commentsEnabled,\n\t\t\t});\n\t\t\tresult.collections.created++;\n\n\t\t\t// Create fields\n\t\t\tfor (const field of collection.fields) {\n\t\t\t\tawait registry.createField(collection.slug, {\n\t\t\t\t\tslug: field.slug,\n\t\t\t\t\tlabel: field.label,\n\t\t\t\t\ttype: field.type,\n\t\t\t\t\trequired: field.required || false,\n\t\t\t\t\tunique: field.unique || false,\n\t\t\t\t\tsearchable: field.searchable || false,\n\t\t\t\t\tdefaultValue: field.defaultValue,\n\t\t\t\t\tvalidation: field.validation,\n\t\t\t\t\twidget: field.widget,\n\t\t\t\t\toptions: field.options,\n\t\t\t\t});\n\t\t\t\tresult.fields.created++;\n\t\t\t}\n\t\t}\n\t}\n\n\t// 4-5. Taxonomies\n\tif (seed.taxonomies) {\n\t\t// seed-local id -> resolved info, used to wire `translationOf` refs.\n\t\tconst defSeedIdMap = new Map<string, { id: string; translationGroup: string }>();\n\t\tconst termSeedIdMap = new Map<string, string>();\n\n\t\tfor (const taxonomy of seed.taxonomies) {\n\t\t\tconst defLocale = taxonomy.locale ?? defaultLocale;\n\n\t\t\t// (name, locale) is the UNIQUE key after migration 036.\n\t\t\tconst existingDef = await db\n\t\t\t\t.selectFrom(\"_emdash_taxonomy_defs\")\n\t\t\t\t.selectAll()\n\t\t\t\t.where(\"name\", \"=\", taxonomy.name)\n\t\t\t\t.where(\"locale\", \"=\", defLocale)\n\t\t\t\t.executeTakeFirst();\n\n\t\t\tlet defId: string;\n\t\t\tlet defTranslationGroup: string;\n\n\t\t\tif (existingDef) {\n\t\t\t\tdefId = existingDef.id;\n\t\t\t\tdefTranslationGroup = existingDef.translation_group ?? existingDef.id;\n\t\t\t\tif (onConflict === \"error\") {\n\t\t\t\t\tthrow new Error(`Conflict: taxonomy \"${taxonomy.name}\" (${defLocale}) already exists`);\n\t\t\t\t}\n\t\t\t\tif (onConflict === \"update\") {\n\t\t\t\t\tawait db\n\t\t\t\t\t\t.updateTable(\"_emdash_taxonomy_defs\")\n\t\t\t\t\t\t.set({\n\t\t\t\t\t\t\tlabel: taxonomy.label,\n\t\t\t\t\t\t\tlabel_singular: taxonomy.labelSingular ?? null,\n\t\t\t\t\t\t\thierarchical: taxonomy.hierarchical ? 1 : 0,\n\t\t\t\t\t\t\tcollections: JSON.stringify(taxonomy.collections),\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.where(\"id\", \"=\", existingDef.id)\n\t\t\t\t\t\t.execute();\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tdefId = ulid();\n\t\t\t\tdefTranslationGroup = defId;\n\t\t\t\tif (taxonomy.translationOf) {\n\t\t\t\t\tconst source = defSeedIdMap.get(taxonomy.translationOf);\n\t\t\t\t\tif (source) defTranslationGroup = source.translationGroup;\n\t\t\t\t\telse\n\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t`taxonomy \"${taxonomy.name}\" (${defLocale}): translationOf \"${taxonomy.translationOf}\" not found yet; minting a fresh group.`,\n\t\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tawait db\n\t\t\t\t\t.insertInto(\"_emdash_taxonomy_defs\")\n\t\t\t\t\t.values({\n\t\t\t\t\t\tid: defId,\n\t\t\t\t\t\tname: taxonomy.name,\n\t\t\t\t\t\tlabel: taxonomy.label,\n\t\t\t\t\t\tlabel_singular: taxonomy.labelSingular ?? null,\n\t\t\t\t\t\thierarchical: taxonomy.hierarchical ? 1 : 0,\n\t\t\t\t\t\tcollections: JSON.stringify(taxonomy.collections),\n\t\t\t\t\t\tlocale: defLocale,\n\t\t\t\t\t\ttranslation_group: defTranslationGroup,\n\t\t\t\t\t})\n\t\t\t\t\t.execute();\n\t\t\t\tresult.taxonomies.created++;\n\t\t\t}\n\n\t\t\tif (taxonomy.id)\n\t\t\t\tdefSeedIdMap.set(taxonomy.id, { id: defId, translationGroup: defTranslationGroup });\n\n\t\t\t// Create terms (if provided)\n\t\t\tif (includeContent && taxonomy.terms && taxonomy.terms.length > 0) {\n\t\t\t\tconst termRepo = new TaxonomyRepository(db);\n\n\t\t\t\tif (taxonomy.hierarchical) {\n\t\t\t\t\tawait applyHierarchicalTerms(\n\t\t\t\t\t\ttermRepo,\n\t\t\t\t\t\ttaxonomy.name,\n\t\t\t\t\t\tdefLocale,\n\t\t\t\t\t\ttaxonomy.terms,\n\t\t\t\t\t\ttermSeedIdMap,\n\t\t\t\t\t\tresult,\n\t\t\t\t\t\tonConflict,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tfor (const term of taxonomy.terms) {\n\t\t\t\t\t\tconst termLocale = term.locale ?? defLocale;\n\t\t\t\t\t\tconst existing = await termRepo.findBySlug(taxonomy.name, term.slug, termLocale);\n\t\t\t\t\t\tif (existing) {\n\t\t\t\t\t\t\tif (onConflict === \"error\") {\n\t\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\t`Conflict: taxonomy term \"${term.slug}\" in \"${taxonomy.name}\" (${termLocale}) already exists`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (onConflict === \"update\") {\n\t\t\t\t\t\t\t\tawait termRepo.update(existing.id, {\n\t\t\t\t\t\t\t\t\tlabel: term.label,\n\t\t\t\t\t\t\t\t\tdata: term.description ? { description: term.description } : {},\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tresult.taxonomies.terms++;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (term.id) termSeedIdMap.set(term.id, existing.id);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconst translationOf = term.translationOf\n\t\t\t\t\t\t\t\t? termSeedIdMap.get(term.translationOf)\n\t\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\t\t\tconst created = await termRepo.create({\n\t\t\t\t\t\t\t\tname: taxonomy.name,\n\t\t\t\t\t\t\t\tslug: term.slug,\n\t\t\t\t\t\t\t\tlabel: term.label,\n\t\t\t\t\t\t\t\tdata: term.description ? { description: term.description } : undefined,\n\t\t\t\t\t\t\t\tlocale: termLocale,\n\t\t\t\t\t\t\t\ttranslationOf,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tif (term.id) termSeedIdMap.set(term.id, created.id);\n\t\t\t\t\t\t\tresult.taxonomies.terms++;\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// Seeded/updated defs change which taxonomies exist — clear the\n\t\t// isolate-wide defs + names caches so later reads in this isolate\n\t\t// (e.g. an auto-seed triggered mid-request) reflect them immediately.\n\t\tconst { invalidateTaxonomyDefsCache } = await import(\"../taxonomies/index.js\");\n\t\tinvalidateTaxonomyDefsCache();\n\t}\n\n\t// 6. Bylines\n\tif (includeContent && seed.bylines) {\n\t\tconst bylineRepo = new BylineRepository(db);\n\t\tfor (const byline of seed.bylines) {\n\t\t\tconst existing = await bylineRepo.findBySlug(byline.slug);\n\t\t\tif (existing) {\n\t\t\t\tif (onConflict === \"error\") {\n\t\t\t\t\tthrow new Error(`Conflict: byline \"${byline.slug}\" already exists`);\n\t\t\t\t}\n\n\t\t\t\tif (onConflict === \"update\") {\n\t\t\t\t\t// Resolve the avatar (reusing an existing media row by storage\n\t\t\t\t\t// key, so re-running an update stays idempotent). Only relink\n\t\t\t\t\t// when the seed supplies an avatar; otherwise leave the existing\n\t\t\t\t\t// one untouched.\n\t\t\t\t\tconst avatar = byline.avatar ? await resolveSeedBylineAvatar(db, byline.avatar) : null;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst updated = await bylineRepo.update(existing.id, {\n\t\t\t\t\t\t\tdisplayName: byline.displayName,\n\t\t\t\t\t\t\tbio: byline.bio ?? null,\n\t\t\t\t\t\t\twebsiteUrl: byline.websiteUrl ?? null,\n\t\t\t\t\t\t\tisGuest: byline.isGuest,\n\t\t\t\t\t\t\t...(avatar ? { avatarMediaId: avatar.id } : {}),\n\t\t\t\t\t\t});\n\t\t\t\t\t\t// update() returns null (no throw) if the row vanished between\n\t\t\t\t\t\t// findBySlug and here; treat that as a failure so the catch\n\t\t\t\t\t\t// cleans up any freshly-created avatar media instead of leaking it.\n\t\t\t\t\t\tif (!updated) {\n\t\t\t\t\t\t\tthrow new Error(`Byline \"${byline.slug}\" disappeared during update`);\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t// withTransaction is a no-op on D1, so undo a freshly-created\n\t\t\t\t\t\t// media row by hand to avoid orphaning it.\n\t\t\t\t\t\tif (avatar?.created) await deleteMediaRow(db, avatar.id);\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t}\n\t\t\t\t\tseedBylineIdMap.set(byline.id, existing.id);\n\t\t\t\t\tresult.bylines.updated++;\n\t\t\t\t\tif (avatar?.created) result.media.created++;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// skip\n\t\t\t\tseedBylineIdMap.set(byline.id, existing.id);\n\t\t\t\tresult.bylines.skipped++;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst avatar = byline.avatar ? await resolveSeedBylineAvatar(db, byline.avatar) : null;\n\t\t\tlet createdId: string;\n\t\t\ttry {\n\t\t\t\tconst created = await bylineRepo.create({\n\t\t\t\t\tslug: byline.slug,\n\t\t\t\t\tdisplayName: byline.displayName,\n\t\t\t\t\tbio: byline.bio ?? null,\n\t\t\t\t\twebsiteUrl: byline.websiteUrl ?? null,\n\t\t\t\t\tisGuest: byline.isGuest,\n\t\t\t\t\tavatarMediaId: avatar?.id ?? null,\n\t\t\t\t});\n\t\t\t\tcreatedId = created.id;\n\t\t\t} catch (error) {\n\t\t\t\tif (avatar?.created) await deleteMediaRow(db, avatar.id);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tseedBylineIdMap.set(byline.id, createdId);\n\t\t\tresult.bylines.created++;\n\t\t\tif (avatar?.created) result.media.created++;\n\t\t}\n\t}\n\n\t// 7. Content (created before menus so refs can resolve)\n\tif (includeContent && seed.content) {\n\t\tconst contentRepo = new ContentRepository(db);\n\n\t\ttry {\n\t\t\t// Create content entries\n\t\t\tfor (const [collectionSlug, entries] of Object.entries(seed.content)) {\n\t\t\t\tfor (const entry of entries) {\n\t\t\t\t\t// Resolve the entry's locale up front so a non-`en` single-locale\n\t\t\t\t\t// export (which omits `locale`) is filed under the project default\n\t\t\t\t\t// rather than `en` (#1421).\n\t\t\t\t\tconst entryLocale = entry.locale ?? defaultLocale;\n\n\t\t\t\t\t// Check if entry exists (by slug + locale for locale-aware lookup)\n\t\t\t\t\tconst existing = await contentRepo.findBySlug(collectionSlug, entry.slug, entryLocale);\n\n\t\t\t\t\tif (existing) {\n\t\t\t\t\t\tif (onConflict === \"error\") {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`Conflict: content \"${entry.slug}\" in \"${collectionSlug}\" already exists`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (onConflict === \"update\") {\n\t\t\t\t\t\t\t// Resolve $ref and $media in data\n\t\t\t\t\t\t\tconst resolvedData = await resolveReferences(\n\t\t\t\t\t\t\t\tentry.data,\n\t\t\t\t\t\t\t\tseedIdMap,\n\t\t\t\t\t\t\t\tmediaContext,\n\t\t\t\t\t\t\t\tresult,\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t// Update content + bylines + taxonomies atomically\n\t\t\t\t\t\t\tconst status = entry.status || \"published\";\n\t\t\t\t\t\t\tlet contentMutated = false;\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tawait withTransaction(db, async (trx) => {\n\t\t\t\t\t\t\t\t\tconst trxContentRepo = new ContentRepository(trx);\n\t\t\t\t\t\t\t\t\tconst trxBylineRepo = new BylineRepository(trx);\n\t\t\t\t\t\t\t\t\tconst trxRevisionRepo = new RevisionRepository(trx);\n\n\t\t\t\t\t\t\t\t\tawait trxContentRepo.update(collectionSlug, existing.id, {\n\t\t\t\t\t\t\t\t\t\tstatus,\n\t\t\t\t\t\t\t\t\t\tdata: resolvedData,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\tcontentMutated = true;\n\n\t\t\t\t\t\t\t\t\tawait applyContentBylines(\n\t\t\t\t\t\t\t\t\t\ttrxBylineRepo,\n\t\t\t\t\t\t\t\t\t\tcollectionSlug,\n\t\t\t\t\t\t\t\t\t\texisting.id,\n\t\t\t\t\t\t\t\t\t\tentry,\n\t\t\t\t\t\t\t\t\t\tseedBylineIdMap,\n\t\t\t\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\tawait applyContentTaxonomies(trx, collectionSlug, existing.id, entry, true);\n\n\t\t\t\t\t\t\t\t\t// Seed is declarative — when status is \"published\", promote to a live\n\t\t\t\t\t\t\t\t\t// revision so the admin UI shows \"Unpublish\" instead of \"Save & Publish\"\n\t\t\t\t\t\t\t\t\t// and `live_revision_id` is populated for downstream queries.\n\t\t\t\t\t\t\t\t\t//\n\t\t\t\t\t\t\t\t\t// Create a fresh revision from the updated data and stage it as the\n\t\t\t\t\t\t\t\t\t// draft so `publish()` picks it up instead of re-syncing stale data\n\t\t\t\t\t\t\t\t\t// from an existing live revision.\n\t\t\t\t\t\t\t\t\tif (status === \"published\") {\n\t\t\t\t\t\t\t\t\t\tconst draft = await trxRevisionRepo.create({\n\t\t\t\t\t\t\t\t\t\t\tcollection: collectionSlug,\n\t\t\t\t\t\t\t\t\t\t\tentryId: existing.id,\n\t\t\t\t\t\t\t\t\t\t\tdata: resolvedData,\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\tawait trxContentRepo.setDraftRevision(collectionSlug, existing.id, draft.id);\n\t\t\t\t\t\t\t\t\t\tawait trxContentRepo.publish(collectionSlug, existing.id);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\tif (contentMutated) await markSeedContentCollectionStale(collectionSlug);\n\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tseedIdMap.set(entry.id, existing.id);\n\t\t\t\t\t\t\tresult.content.updated++;\n\t\t\t\t\t\t\tawait markSeedContentCollectionStale(collectionSlug);\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// skip\n\t\t\t\t\t\tresult.content.skipped++;\n\t\t\t\t\t\tseedIdMap.set(entry.id, existing.id);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Resolve $ref and $media in data\n\t\t\t\t\tconst resolvedData = await resolveReferences(entry.data, seedIdMap, mediaContext, result);\n\n\t\t\t\t\t// Resolve translationOf: map from seed-local ID to real EmDash ID\n\t\t\t\t\tlet translationOf: string | undefined;\n\t\t\t\t\tif (entry.translationOf) {\n\t\t\t\t\t\tconst sourceId = seedIdMap.get(entry.translationOf);\n\t\t\t\t\t\tif (!sourceId) {\n\t\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t\t`content.${collectionSlug}: translationOf \"${entry.translationOf}\" not found (not yet created or missing). Skipping translation link.`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\ttranslationOf = sourceId;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// Create entry + bylines + taxonomies atomically\n\t\t\t\t\tconst status = entry.status || \"published\";\n\t\t\t\t\tlet contentMutated = false;\n\t\t\t\t\tlet created: Awaited<ReturnType<ContentRepository[\"create\"]>>;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tcreated = await withTransaction(db, async (trx) => {\n\t\t\t\t\t\t\tconst trxContentRepo = new ContentRepository(trx);\n\t\t\t\t\t\t\tconst trxBylineRepo = new BylineRepository(trx);\n\n\t\t\t\t\t\t\tconst item = await trxContentRepo.create({\n\t\t\t\t\t\t\t\ttype: collectionSlug,\n\t\t\t\t\t\t\t\tslug: entry.slug,\n\t\t\t\t\t\t\t\tstatus,\n\t\t\t\t\t\t\t\tdata: resolvedData,\n\t\t\t\t\t\t\t\tlocale: entryLocale,\n\t\t\t\t\t\t\t\ttranslationOf,\n\t\t\t\t\t\t\t\tpublishedAt: status === \"published\" ? new Date().toISOString() : null,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tcontentMutated = true;\n\n\t\t\t\t\t\t\tawait applyContentBylines(\n\t\t\t\t\t\t\t\ttrxBylineRepo,\n\t\t\t\t\t\t\t\tcollectionSlug,\n\t\t\t\t\t\t\t\titem.id,\n\t\t\t\t\t\t\t\tentry,\n\t\t\t\t\t\t\t\tseedBylineIdMap,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tawait applyContentTaxonomies(trx, collectionSlug, item.id, entry, false);\n\n\t\t\t\t\t\t\t// Seed is declarative — when status is \"published\", promote to a live\n\t\t\t\t\t\t\t// revision so the admin UI shows \"Unpublish\" instead of \"Save & Publish\"\n\t\t\t\t\t\t\t// and `live_revision_id` is populated for downstream queries.\n\t\t\t\t\t\t\tif (status === \"published\") {\n\t\t\t\t\t\t\t\tawait trxContentRepo.publish(collectionSlug, item.id);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\treturn item;\n\t\t\t\t\t\t});\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tif (contentMutated) await markSeedContentCollectionStale(collectionSlug);\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t}\n\n\t\t\t\t\tseedIdMap.set(entry.id, created.id);\n\t\t\t\t\tresult.content.created++;\n\t\t\t\t\tawait markSeedContentCollectionStale(collectionSlug);\n\t\t\t\t}\n\t\t\t}\n\t\t} finally {\n\t\t\tawait retryFailedSeedContentStaleMarks();\n\t\t}\n\t}\n\n\t// 8. Menus and Menu Items (after content so refs can resolve)\n\tif (seed.menus) {\n\t\t// seed-local id -> resolved info, used to wire `translationOf` refs.\n\t\tconst menuSeedIdMap = new Map<string, { id: string; translationGroup: string }>();\n\t\t// Shared across menus: translated items reference anchor items in sibling menus.\n\t\tconst itemSeedIdMap = new Map<string, { id: string; translationGroup: string }>();\n\n\t\tfor (const menu of seed.menus) {\n\t\t\tconst locale = menu.locale ?? defaultLocale;\n\t\t\tlet lookup = db\n\t\t\t\t.selectFrom(\"_emdash_menus\")\n\t\t\t\t.selectAll()\n\t\t\t\t.where(\"name\", \"=\", menu.name)\n\t\t\t\t.where(\"locale\", \"=\", locale);\n\t\t\tconst existingMenu = await lookup.executeTakeFirst();\n\n\t\t\tlet menuId: string;\n\t\t\tlet translationGroup: string;\n\n\t\t\tif (existingMenu) {\n\t\t\t\tmenuId = existingMenu.id;\n\t\t\t\ttranslationGroup = existingMenu.translation_group ?? existingMenu.id;\n\t\t\t\t// Clear existing items (menus are recreated)\n\t\t\t\tawait db.deleteFrom(\"_emdash_menu_items\").where(\"menu_id\", \"=\", menuId).execute();\n\t\t\t} else {\n\t\t\t\tmenuId = ulid();\n\t\t\t\t// Resolve translationOf to the source menu's translation_group.\n\t\t\t\ttranslationGroup = menuId;\n\t\t\t\tif (menu.translationOf) {\n\t\t\t\t\tconst source = menuSeedIdMap.get(menu.translationOf);\n\t\t\t\t\tif (source) translationGroup = source.translationGroup;\n\t\t\t\t\telse\n\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t`menu \"${menu.name}\" (${locale}): translationOf \"${menu.translationOf}\" not found yet; minting a fresh group.`,\n\t\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tawait db\n\t\t\t\t\t.insertInto(\"_emdash_menus\")\n\t\t\t\t\t.values({\n\t\t\t\t\t\tid: menuId,\n\t\t\t\t\t\tname: menu.name,\n\t\t\t\t\t\tlabel: menu.label,\n\t\t\t\t\t\tcreated_at: new Date().toISOString(),\n\t\t\t\t\t\tupdated_at: new Date().toISOString(),\n\t\t\t\t\t\tlocale,\n\t\t\t\t\t\ttranslation_group: translationGroup,\n\t\t\t\t\t})\n\t\t\t\t\t.execute();\n\t\t\t\tresult.menus.created++;\n\t\t\t}\n\n\t\t\tif (menu.id) menuSeedIdMap.set(menu.id, { id: menuId, translationGroup });\n\n\t\t\t// Create menu items\n\t\t\tconst itemCount = await applyMenuItems(\n\t\t\t\tdb,\n\t\t\t\tmenuId,\n\t\t\t\tlocale,\n\t\t\t\tmenu.items,\n\t\t\t\tnull, // parent_id\n\t\t\t\t0, // sort_order\n\t\t\t\tseedIdMap,\n\t\t\t\titemSeedIdMap,\n\t\t\t);\n\t\t\tresult.menus.items += itemCount;\n\t\t}\n\t}\n\n\t// 9. Redirects\n\tif (seed.redirects) {\n\t\tconst redirectRepo = new RedirectRepository(db);\n\n\t\tfor (const redirect of seed.redirects) {\n\t\t\tconst existing = await redirectRepo.findBySource(redirect.source);\n\t\t\tif (existing) {\n\t\t\t\tif (onConflict === \"error\") {\n\t\t\t\t\tthrow new Error(`Conflict: redirect \"${redirect.source}\" already exists`);\n\t\t\t\t}\n\n\t\t\t\tif (onConflict === \"update\") {\n\t\t\t\t\tawait redirectRepo.update(existing.id, {\n\t\t\t\t\t\tdestination: redirect.destination,\n\t\t\t\t\t\ttype: redirect.type,\n\t\t\t\t\t\tenabled: redirect.enabled,\n\t\t\t\t\t\tgroupName: redirect.groupName,\n\t\t\t\t\t});\n\t\t\t\t\tresult.redirects.updated++;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// skip\n\t\t\t\tresult.redirects.skipped++;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tawait redirectRepo.create({\n\t\t\t\tsource: redirect.source,\n\t\t\t\tdestination: redirect.destination,\n\t\t\t\ttype: redirect.type,\n\t\t\t\tenabled: redirect.enabled,\n\t\t\t\tgroupName: redirect.groupName,\n\t\t\t});\n\t\t\tresult.redirects.created++;\n\t\t}\n\t}\n\n\t// 10. Widget Areas and Widgets\n\tif (seed.widgetAreas) {\n\t\tfor (const area of seed.widgetAreas) {\n\t\t\t// Check if area exists\n\t\t\tconst existingArea = await db\n\t\t\t\t.selectFrom(\"_emdash_widget_areas\")\n\t\t\t\t.selectAll()\n\t\t\t\t.where(\"name\", \"=\", area.name)\n\t\t\t\t.executeTakeFirst();\n\n\t\t\tlet areaId: string;\n\n\t\t\tif (existingArea) {\n\t\t\t\tareaId = existingArea.id;\n\t\t\t\t// Clear existing widgets (areas are recreated)\n\t\t\t\tawait db.deleteFrom(\"_emdash_widgets\").where(\"area_id\", \"=\", areaId).execute();\n\t\t\t} else {\n\t\t\t\t// Create area\n\t\t\t\tareaId = ulid();\n\t\t\t\tawait db\n\t\t\t\t\t.insertInto(\"_emdash_widget_areas\")\n\t\t\t\t\t.values({\n\t\t\t\t\t\tid: areaId,\n\t\t\t\t\t\tname: area.name,\n\t\t\t\t\t\tlabel: area.label,\n\t\t\t\t\t\tdescription: area.description ?? null,\n\t\t\t\t\t})\n\t\t\t\t\t.execute();\n\t\t\t\tresult.widgetAreas.created++;\n\t\t\t}\n\n\t\t\t// Create widgets\n\t\t\tfor (let i = 0; i < area.widgets.length; i++) {\n\t\t\t\tconst widget = area.widgets[i];\n\t\t\t\tawait applyWidget(db, areaId, widget, i);\n\t\t\t\tresult.widgetAreas.widgets++;\n\t\t\t}\n\t\t}\n\t}\n\n\t// 11. Sections\n\tif (seed.sections) {\n\t\tfor (const section of seed.sections) {\n\t\t\t// Check if section exists\n\t\t\tconst existing = await db\n\t\t\t\t.selectFrom(\"_emdash_sections\")\n\t\t\t\t.select(\"id\")\n\t\t\t\t.where(\"slug\", \"=\", section.slug)\n\t\t\t\t.executeTakeFirst();\n\n\t\t\tif (existing) {\n\t\t\t\tif (onConflict === \"error\") {\n\t\t\t\t\tthrow new Error(`Conflict: section \"${section.slug}\" already exists`);\n\t\t\t\t}\n\n\t\t\t\tif (onConflict === \"update\") {\n\t\t\t\t\tawait db\n\t\t\t\t\t\t.updateTable(\"_emdash_sections\")\n\t\t\t\t\t\t.set({\n\t\t\t\t\t\t\ttitle: section.title,\n\t\t\t\t\t\t\tdescription: section.description ?? null,\n\t\t\t\t\t\t\tkeywords: section.keywords ? JSON.stringify(section.keywords) : null,\n\t\t\t\t\t\t\tcontent: JSON.stringify(section.content),\n\t\t\t\t\t\t\tsource: section.source || \"theme\",\n\t\t\t\t\t\t\tupdated_at: new Date().toISOString(),\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.where(\"id\", \"=\", existing.id)\n\t\t\t\t\t\t.execute();\n\t\t\t\t\tresult.sections.updated++;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// skip\n\t\t\t\tresult.sections.skipped++;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst id = ulid();\n\t\t\tconst now = new Date().toISOString();\n\n\t\t\tawait db\n\t\t\t\t.insertInto(\"_emdash_sections\")\n\t\t\t\t.values({\n\t\t\t\t\tid,\n\t\t\t\t\tslug: section.slug,\n\t\t\t\t\ttitle: section.title,\n\t\t\t\t\tdescription: section.description ?? null,\n\t\t\t\t\tkeywords: section.keywords ? JSON.stringify(section.keywords) : null,\n\t\t\t\t\tcontent: JSON.stringify(section.content),\n\t\t\t\t\tpreview_media_id: null,\n\t\t\t\t\tsource: section.source || \"theme\",\n\t\t\t\t\ttheme_id: section.source === \"theme\" ? section.slug : null,\n\t\t\t\t\tcreated_at: now,\n\t\t\t\t\tupdated_at: now,\n\t\t\t\t})\n\t\t\t\t.execute();\n\n\t\t\tresult.sections.created++;\n\t\t}\n\t}\n\n\t// 11. Enable search for collections that have `search` in supports\n\tif (seed.collections) {\n\t\tconst ftsManager = new FTSManager(db);\n\n\t\tfor (const collection of seed.collections) {\n\t\t\tif (collection.supports?.includes(\"search\")) {\n\t\t\t\t// Check if there are searchable fields\n\t\t\t\tconst searchableFields = await ftsManager.getSearchableFields(collection.slug);\n\t\t\t\tif (searchableFields.length > 0) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait ftsManager.enableSearch(collection.slug);\n\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\t// Log but don't fail - search can be enabled manually later\n\t\t\t\t\t\tconsole.warn(`Failed to enable search for ${collection.slug}:`, err);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// Invalidate caches that may have been affected by seed data.\n\t// Seed creates bylines, redirects, and collections, all of which\n\t// have module-level caches in the hot path.\n\tconst { invalidateBylineCache } = await import(\"../bylines/index.js\");\n\tconst { invalidateRedirectCache } = await import(\"../redirects/cache.js\");\n\tconst { invalidateUrlPatternCache } = await import(\"../query.js\");\n\tinvalidateBylineCache();\n\tinvalidateRedirectCache();\n\tinvalidateUrlPatternCache();\n\n\treturn result;\n}\n\n/**\n * Apply hierarchical taxonomy terms (parents before children)\n */\nasync function applyHierarchicalTerms(\n\ttermRepo: TaxonomyRepository,\n\ttaxonomyName: string,\n\tdefLocale: string,\n\tterms: SeedTaxonomyTerm[],\n\ttermSeedIdMap: Map<string, string>,\n\tresult: SeedApplyResult,\n\tonConflict: \"skip\" | \"update\" | \"error\" = \"skip\",\n): Promise<void> {\n\t// \"locale::slug\" -> id, so the same slug can resolve per locale.\n\tconst slugToId = new Map<string, string>();\n\n\t// Multiple passes — handles deep nesting and translationOf forward refs.\n\tlet remaining = [...terms];\n\tlet maxPasses = 10;\n\n\twhile (remaining.length > 0 && maxPasses > 0) {\n\t\tconst processedThisPass: string[] = [];\n\n\t\tfor (const term of remaining) {\n\t\t\tconst termLocale = term.locale ?? defLocale;\n\t\t\tconst parentReady = !term.parent || slugToId.has(`${termLocale}::${term.parent}`);\n\t\t\tconst translationReady = !term.translationOf || termSeedIdMap.has(term.translationOf);\n\n\t\t\tif (!parentReady || !translationReady) continue;\n\n\t\t\tconst parentId = term.parent ? slugToId.get(`${termLocale}::${term.parent}`) : undefined;\n\t\t\tconst translationOf = term.translationOf ? termSeedIdMap.get(term.translationOf) : undefined;\n\n\t\t\tconst existing = await termRepo.findBySlug(taxonomyName, term.slug, termLocale);\n\t\t\tif (existing) {\n\t\t\t\tif (onConflict === \"error\") {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Conflict: taxonomy term \"${term.slug}\" in \"${taxonomyName}\" (${termLocale}) already exists`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (onConflict === \"update\") {\n\t\t\t\t\tawait termRepo.update(existing.id, {\n\t\t\t\t\t\tlabel: term.label,\n\t\t\t\t\t\tparentId,\n\t\t\t\t\t\tdata: term.description ? { description: term.description } : {},\n\t\t\t\t\t});\n\t\t\t\t\tresult.taxonomies.terms++;\n\t\t\t\t}\n\t\t\t\tslugToId.set(`${termLocale}::${term.slug}`, existing.id);\n\t\t\t\tif (term.id) termSeedIdMap.set(term.id, existing.id);\n\t\t\t} else {\n\t\t\t\tconst created = await termRepo.create({\n\t\t\t\t\tname: taxonomyName,\n\t\t\t\t\tslug: term.slug,\n\t\t\t\t\tlabel: term.label,\n\t\t\t\t\tparentId,\n\t\t\t\t\tdata: term.description ? { description: term.description } : undefined,\n\t\t\t\t\tlocale: termLocale,\n\t\t\t\t\ttranslationOf,\n\t\t\t\t});\n\t\t\t\tslugToId.set(`${termLocale}::${term.slug}`, created.id);\n\t\t\t\tif (term.id) termSeedIdMap.set(term.id, created.id);\n\t\t\t\tresult.taxonomies.terms++;\n\t\t\t}\n\n\t\t\tprocessedThisPass.push(term.slug + \"::\" + termLocale);\n\t\t}\n\n\t\tremaining = remaining.filter(\n\t\t\t(t) => !processedThisPass.includes(t.slug + \"::\" + (t.locale ?? defLocale)),\n\t\t);\n\t\tmaxPasses--;\n\t}\n\n\tif (remaining.length > 0) {\n\t\tconsole.warn(`Could not process ${remaining.length} terms due to missing parents/translations`);\n\t}\n}\n\n/**\n * Apply byline credits to a content entry.\n * In update mode, clears existing credits even if the seed has none.\n */\nasync function applyContentBylines(\n\tbylineRepo: BylineRepository,\n\tcollectionSlug: string,\n\tcontentId: string,\n\tentry: { slug: string; bylines?: Array<{ byline: string; roleLabel?: string }> },\n\tseedBylineIdMap: Map<string, string>,\n\tisUpdate = false,\n): Promise<void> {\n\tif (!entry.bylines || entry.bylines.length === 0) {\n\t\t// In update mode, clear existing bylines when the seed entry has none\n\t\tif (isUpdate) {\n\t\t\tawait bylineRepo.setContentBylines(collectionSlug, contentId, []);\n\t\t}\n\t\treturn;\n\t}\n\n\tconst credits = entry.bylines\n\t\t.map((credit) => {\n\t\t\tconst bylineId = seedBylineIdMap.get(credit.byline);\n\t\t\tif (!bylineId) return null;\n\t\t\treturn {\n\t\t\t\tbylineId,\n\t\t\t\troleLabel: credit.roleLabel ?? null,\n\t\t\t};\n\t\t})\n\t\t.filter((credit): credit is { bylineId: string; roleLabel: string | null } => Boolean(credit));\n\n\tif (credits.length !== entry.bylines.length) {\n\t\tconsole.warn(\n\t\t\t`content.${collectionSlug}.${entry.slug}: one or more byline refs could not be resolved`,\n\t\t);\n\t}\n\n\t// In update mode, always call setContentBylines (even with empty credits)\n\t// to clear stale assignments when all byline refs fail to resolve.\n\t// In create mode, only call if there are credits to assign.\n\tif (credits.length > 0 || isUpdate) {\n\t\tawait bylineRepo.setContentBylines(collectionSlug, contentId, credits);\n\t}\n}\n\n/**\n * Apply taxonomy term assignments to a content entry.\n * In update mode, clears existing assignments before re-attaching.\n */\nasync function applyContentTaxonomies(\n\tdb: Kysely<Database>,\n\tcollectionSlug: string,\n\tcontentId: string,\n\tentry: { taxonomies?: Record<string, string[]> },\n\tisUpdate: boolean,\n): Promise<void> {\n\t// In update mode, clear existing taxonomy assignments first\n\tif (isUpdate) {\n\t\tawait db\n\t\t\t.deleteFrom(\"content_taxonomies\")\n\t\t\t.where(\"collection\", \"=\", collectionSlug)\n\t\t\t.where(\"entry_id\", \"=\", contentId)\n\t\t\t.execute();\n\t}\n\n\tif (!entry.taxonomies) {\n\t\t// In update mode we may have just deleted rows above; invalidate so\n\t\t// hydration doesn't serve stale \"has terms\" cached value.\n\t\tif (isUpdate) {\n\t\t\tconst { invalidateTermCache } = await import(\"../taxonomies/index.js\");\n\t\t\tinvalidateTermCache();\n\t\t}\n\t\treturn;\n\t}\n\n\tfor (const [taxonomyName, termSlugs] of Object.entries(entry.taxonomies)) {\n\t\tconst termRepo = new TaxonomyRepository(db);\n\n\t\tfor (const termSlug of termSlugs) {\n\t\t\tconst term = await termRepo.findBySlug(taxonomyName, termSlug);\n\t\t\tif (term) {\n\t\t\t\tawait termRepo.attachToEntry(collectionSlug, contentId, term.id);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Seed writes directly to content_taxonomies. Clear the cache so\n\t// the worker lifetime cached \"has any term assignments\" probe\n\t// re-runs on the next read.\n\tconst { invalidateTermCache } = await import(\"../taxonomies/index.js\");\n\tinvalidateTermCache();\n}\n\n/**\n * Apply menu items recursively.\n *\n * When a `SeedMenuItem` carries `id`/`translationOf`, the import resolves the\n * source item's `translation_group` so cross-locale \"same nav entry\" links\n * survive export → apply. Items without `translationOf` get a fresh group\n * (= their own id).\n */\nasync function applyMenuItems(\n\tdb: Kysely<Database>,\n\tmenuId: string,\n\tlocale: string,\n\titems: SeedMenuItem[],\n\tparentId: string | null,\n\tstartOrder: number,\n\tseedIdMap: Map<string, string>,\n\titemSeedIdMap: Map<string, { id: string; translationGroup: string }>,\n): Promise<number> {\n\tlet count = 0;\n\tlet order = startOrder;\n\n\tfor (const item of items) {\n\t\tconst itemId = ulid();\n\t\tconst itemLocale = item.locale ?? locale;\n\n\t\t// Resolve reference if needed\n\t\tlet referenceId: string | null = null;\n\t\tlet referenceCollection: string | null = null;\n\n\t\tif (item.type === \"page\" || item.type === \"post\") {\n\t\t\t// Try to resolve from seedIdMap\n\t\t\tif (item.ref && seedIdMap.has(item.ref)) {\n\t\t\t\treferenceId = seedIdMap.get(item.ref)!;\n\t\t\t\t// Default to plural collection name (pages/posts) if not specified\n\t\t\t\treferenceCollection = item.collection || `${item.type}s`;\n\t\t\t}\n\t\t\t// If not in map, the content might not exist yet (will be broken link)\n\t\t}\n\n\t\tlet translationGroup = itemId;\n\t\tif (item.translationOf) {\n\t\t\tconst source = itemSeedIdMap.get(item.translationOf);\n\t\t\tif (source) translationGroup = source.translationGroup;\n\t\t\telse\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`menu item \"${item.label ?? item.url ?? item.ref ?? \"(unlabeled)\"}\" (${itemLocale}): translationOf \"${item.translationOf}\" not found yet; minting a fresh group.`,\n\t\t\t\t);\n\t\t}\n\n\t\tawait db\n\t\t\t.insertInto(\"_emdash_menu_items\")\n\t\t\t.values({\n\t\t\t\tid: itemId,\n\t\t\t\tmenu_id: menuId,\n\t\t\t\tparent_id: parentId,\n\t\t\t\tsort_order: order,\n\t\t\t\ttype: item.type,\n\t\t\t\treference_collection: referenceCollection,\n\t\t\t\treference_id: referenceId,\n\t\t\t\tcustom_url: item.url ?? null,\n\t\t\t\tlabel: item.label || \"\",\n\t\t\t\ttitle_attr: item.titleAttr ?? null,\n\t\t\t\ttarget: item.target ?? null,\n\t\t\t\tcss_classes: item.cssClasses ?? null,\n\t\t\t\tcreated_at: new Date().toISOString(),\n\t\t\t\tlocale: itemLocale,\n\t\t\t\ttranslation_group: translationGroup,\n\t\t\t})\n\t\t\t.execute();\n\n\t\tif (item.id) itemSeedIdMap.set(item.id, { id: itemId, translationGroup });\n\n\t\tcount++;\n\t\torder++;\n\n\t\tif (item.children && item.children.length > 0) {\n\t\t\tconst childCount = await applyMenuItems(\n\t\t\t\tdb,\n\t\t\t\tmenuId,\n\t\t\t\titemLocale,\n\t\t\t\titem.children,\n\t\t\t\titemId,\n\t\t\t\t0,\n\t\t\t\tseedIdMap,\n\t\t\t\titemSeedIdMap,\n\t\t\t);\n\t\t\tcount += childCount;\n\t\t}\n\t}\n\n\treturn count;\n}\n\n/**\n * Apply a widget\n */\nasync function applyWidget(\n\tdb: Kysely<Database>,\n\tareaId: string,\n\twidget: SeedWidget,\n\tsortOrder: number,\n): Promise<void> {\n\tawait db\n\t\t.insertInto(\"_emdash_widgets\")\n\t\t.values({\n\t\t\tid: ulid(),\n\t\t\tarea_id: areaId,\n\t\t\tsort_order: sortOrder,\n\t\t\ttype: widget.type,\n\t\t\ttitle: widget.title ?? null,\n\t\t\t// `widget.content` is Portable Text for content-type widgets;\n\t\t\t// for other widget kinds it's null.\n\t\t\tcontent: widget.content ? JSON.stringify(widget.content) : null,\n\t\t\tmenu_name: widget.menuName ?? null,\n\t\t\tcomponent_id: widget.componentId ?? null,\n\t\t\tcomponent_props: widget.props ? JSON.stringify(widget.props) : null,\n\t\t})\n\t\t.execute();\n}\n\n/**\n * Context for media resolution during seed application\n */\ninterface MediaContext {\n\tdb: Kysely<Database>;\n\tstorage: Storage | null;\n\tskipMediaDownload: boolean;\n\tmediaCache: Map<string, MediaValue>; // URL -> resolved MediaValue\n}\n\n/**\n * Type guard for $media reference\n */\nfunction isSeedMediaReference(value: unknown): value is SeedMediaReference {\n\tif (typeof value !== \"object\" || value === null || !(\"$media\" in value)) {\n\t\treturn false;\n\t}\n\tconst media = (value as Record<string, unknown>).$media;\n\treturn (\n\t\ttypeof media === \"object\" &&\n\t\tmedia !== null &&\n\t\t\"url\" in media &&\n\t\ttypeof (media as Record<string, unknown>).url === \"string\"\n\t);\n}\n\n/**\n * Resolve $ref: and $media references in content data\n */\nasync function resolveReferences(\n\tdata: Record<string, unknown>,\n\tseedIdMap: Map<string, string>,\n\tmediaContext: MediaContext,\n\tresult: SeedApplyResult,\n): Promise<Record<string, unknown>> {\n\tconst resolved: Record<string, unknown> = {};\n\n\tfor (const [key, value] of Object.entries(data)) {\n\t\tresolved[key] = await resolveValue(value, seedIdMap, mediaContext, result);\n\t}\n\n\treturn resolved;\n}\n\n/**\n * Resolve a single value recursively\n */\nasync function resolveValue(\n\tvalue: unknown,\n\tseedIdMap: Map<string, string>,\n\tmediaContext: MediaContext,\n\tresult: SeedApplyResult,\n): Promise<unknown> {\n\t// Handle $ref: syntax\n\tif (typeof value === \"string\" && value.startsWith(\"$ref:\")) {\n\t\tconst seedId = value.slice(5);\n\t\treturn seedIdMap.get(seedId) ?? value; // Return unresolved if not found\n\t}\n\n\t// Handle $media syntax\n\tif (isSeedMediaReference(value)) {\n\t\treturn resolveMedia(value, mediaContext, result);\n\t}\n\n\t// Handle arrays\n\tif (Array.isArray(value)) {\n\t\treturn Promise.all(value.map((item) => resolveValue(item, seedIdMap, mediaContext, result)));\n\t}\n\n\t// Handle objects recursively\n\tif (typeof value === \"object\" && value !== null) {\n\t\tconst resolved: Record<string, unknown> = {};\n\t\tfor (const [k, v] of Object.entries(value)) {\n\t\t\tresolved[k] = await resolveValue(v, seedIdMap, mediaContext, result);\n\t\t}\n\t\treturn resolved;\n\t}\n\n\treturn value;\n}\n\n/**\n * Resolve a seeded byline avatar to a `media` row id. The file is assumed to\n * already exist in storage (the caller supplies its `storageKey`), so nothing\n * is downloaded or uploaded.\n *\n * Idempotent: if a media row with the same `storageKey` already exists it is\n * reused rather than duplicated, so re-applying a seed in `update` mode does\n * not leak rows. `created` reports whether a new row was inserted, so the\n * caller can both account for it and delete it if the subsequent byline write\n * fails (the only cross-dialect way to avoid an orphan — `withTransaction`\n * is a no-op on D1).\n */\nasync function resolveSeedBylineAvatar(\n\tdb: Kysely<Database>,\n\tavatar: SeedBylineAvatar,\n): Promise<{ id: string; created: boolean }> {\n\t// `media.storage_key` has no unique constraint, so order deterministically\n\t// to reuse the same row across runs if duplicates already exist. (Concurrent\n\t// seed applies against one DB are out of scope; seeding is a single-shot\n\t// init operation.)\n\tconst existing = await db\n\t\t.selectFrom(\"media\")\n\t\t.select(\"id\")\n\t\t.where(\"storage_key\", \"=\", avatar.storageKey)\n\t\t.orderBy(\"id\", \"asc\")\n\t\t.executeTakeFirst();\n\tif (existing) return { id: existing.id, created: false };\n\n\tconst basename = avatar.storageKey.split(\"/\").pop();\n\tconst filename =\n\t\tavatar.filename ?? (basename && basename.length > 0 ? basename : avatar.storageKey);\n\tconst created = await new MediaRepository(db).create({\n\t\tfilename,\n\t\tmimeType: avatar.mimeType ?? \"image/jpeg\",\n\t\tstorageKey: avatar.storageKey,\n\t\talt: avatar.alt,\n\t\twidth: avatar.width,\n\t\theight: avatar.height,\n\t\tstatus: \"ready\",\n\t});\n\treturn { id: created.id, created: true };\n}\n\n/**\n * Delete a media row by id. Best-effort cleanup for a failed byline write: a\n * failure here must not mask the original error that triggered the cleanup, so\n * it is logged and swallowed rather than thrown.\n */\nasync function deleteMediaRow(db: Kysely<Database>, id: string): Promise<void> {\n\ttry {\n\t\tawait db.deleteFrom(\"media\").where(\"id\", \"=\", id).execute();\n\t} catch (error) {\n\t\tconsole.warn(`[seed] failed to clean up orphaned avatar media ${id}:`, error);\n\t}\n}\n\n/**\n * Resolve a $media reference by downloading and uploading the media\n */\nasync function resolveMedia(\n\tref: SeedMediaReference,\n\tctx: MediaContext,\n\tresult: SeedApplyResult,\n): Promise<MediaValue | null> {\n\tconst { url, alt, filename, caption } = ref.$media;\n\n\t// Check cache first\n\tconst cached = ctx.mediaCache.get(url);\n\tif (cached) {\n\t\tresult.media.skipped++;\n\t\treturn { ...cached, alt: alt ?? cached.alt };\n\t}\n\n\t// When skipMediaDownload is set, resolve $media to an external URL reference\n\t// without downloading or storing anything. Used by playground mode.\n\tif (ctx.skipMediaDownload) {\n\t\tconst mediaValue: MediaValue = {\n\t\t\tprovider: \"external\",\n\t\t\tid: ulid(),\n\t\t\tsrc: url,\n\t\t\talt: alt ?? undefined,\n\t\t\tfilename: filename ?? undefined,\n\t\t};\n\t\tctx.mediaCache.set(url, mediaValue);\n\t\tresult.media.created++;\n\t\treturn mediaValue;\n\t}\n\n\t// Storage is required for $media resolution\n\tif (!ctx.storage) {\n\t\tconsole.warn(`Skipping $media reference (no storage configured): ${url}`);\n\t\tresult.media.skipped++;\n\t\treturn null;\n\t}\n\n\ttry {\n\t\t// SSRF protection: validate URL before downloading\n\t\tvalidateExternalUrl(url);\n\n\t\t// Download the media (ssrfSafeFetch re-validates redirect targets)\n\t\tconsole.log(` 📥 Downloading: ${url}`);\n\t\tconst response = await ssrfSafeFetch(url, {\n\t\t\theaders: {\n\t\t\t\t// Some services like Unsplash require a user-agent\n\t\t\t\t\"User-Agent\": \"EmDash-CMS/1.0\",\n\t\t\t},\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tconsole.warn(` ⚠️ Failed to download ${url}: ${response.status}`);\n\t\t\tresult.media.skipped++;\n\t\t\treturn null;\n\t\t}\n\n\t\t// Get content type and determine extension\n\t\tconst contentType = response.headers.get(\"content-type\") || \"application/octet-stream\";\n\t\tconst ext = getExtensionFromContentType(contentType) || getExtensionFromUrl(url) || \".bin\";\n\n\t\t// Generate filename and storage key\n\t\tconst id = ulid();\n\t\tconst finalFilename = filename || generateFilename(url, ext);\n\t\tconst storageKey = `${id}${ext}`;\n\n\t\t// Get the body as buffer\n\t\tconst arrayBuffer = await response.arrayBuffer();\n\t\tconst body = new Uint8Array(arrayBuffer);\n\n\t\t// Get image dimensions if it's an image\n\t\tlet width: number | undefined;\n\t\tlet height: number | undefined;\n\t\tif (contentType.startsWith(\"image/\")) {\n\t\t\tconst dimensions = getImageDimensions(body);\n\t\t\twidth = dimensions?.width;\n\t\t\theight = dimensions?.height;\n\t\t}\n\n\t\t// Upload to storage\n\t\tawait ctx.storage.upload({\n\t\t\tkey: storageKey,\n\t\t\tbody,\n\t\t\tcontentType,\n\t\t});\n\n\t\t// Create media record\n\t\tconst mediaRepo = new MediaRepository(ctx.db);\n\t\tawait mediaRepo.create({\n\t\t\tfilename: finalFilename,\n\t\t\tmimeType: contentType,\n\t\t\tsize: body.length,\n\t\t\twidth,\n\t\t\theight,\n\t\t\talt,\n\t\t\tcaption,\n\t\t\tstorageKey,\n\t\t\tstatus: \"ready\",\n\t\t});\n\n\t\t// Create the MediaValue - only store id, URL is built at runtime by EmDashMedia\n\t\tconst mediaValue: MediaValue = {\n\t\t\tprovider: \"local\",\n\t\t\tid,\n\t\t\talt: alt ?? undefined,\n\t\t\twidth,\n\t\t\theight,\n\t\t\tmimeType: contentType,\n\t\t\tfilename: finalFilename,\n\t\t\tmeta: { storageKey },\n\t\t};\n\n\t\t// Cache for reuse\n\t\tctx.mediaCache.set(url, mediaValue);\n\t\tresult.media.created++;\n\n\t\tconsole.log(` ✅ Uploaded: ${finalFilename}`);\n\t\treturn mediaValue;\n\t} catch (error) {\n\t\tconsole.warn(\n\t\t\t` ⚠️ Error processing $media ${url}:`,\n\t\t\terror instanceof Error ? error.message : error,\n\t\t);\n\t\tresult.media.skipped++;\n\t\treturn null;\n\t}\n}\n\n/**\n * Get file extension from content type\n */\nfunction getExtensionFromContentType(contentType: string): string | null {\n\t// Handle content-type with parameters like \"image/jpeg; charset=utf-8\"\n\tconst baseMime = contentType.split(\";\")[0].trim();\n\tconst ext = mime.getExtension(baseMime);\n\treturn ext ? `.${ext}` : null;\n}\n\n/**\n * Get file extension from URL\n */\nfunction getExtensionFromUrl(url: string): string | null {\n\ttry {\n\t\tconst pathname = new URL(url).pathname;\n\t\tconst match = pathname.match(FILE_EXTENSION_PATTERN);\n\t\treturn match ? `.${match[1]}` : null;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n/**\n * Generate a filename from URL\n */\nfunction generateFilename(url: string, ext: string): string {\n\ttry {\n\t\tconst pathname = new URL(url).pathname;\n\t\tconst basename = pathname.split(\"/\").pop() || \"media\";\n\t\t// Remove any existing extension and query params\n\t\tconst name = basename.replace(EXTENSION_PATTERN, \"\").replace(QUERY_PARAM_PATTERN, \"\");\n\t\t// Sanitize: only alphanumeric, dash, underscore\n\t\tconst sanitized = name.replace(SANITIZE_PATTERN, \"-\").replace(MULTIPLE_HYPHENS_PATTERN, \"-\");\n\t\treturn `${sanitized || \"media\"}${ext}`;\n\t} catch {\n\t\treturn `media${ext}`;\n\t}\n}\n\n/**\n * Get image dimensions from buffer using image-size.\n * Supports PNG, JPEG, GIF, WebP, AVIF, SVG, TIFF, and more.\n */\nfunction getImageDimensions(buffer: Uint8Array): { width: number; height: number } | null {\n\ttry {\n\t\tconst result = imageSize(buffer);\n\t\tif (result.width != null && result.height != null) {\n\t\t\treturn { width: result.width, height: result.height };\n\t\t}\n\t\treturn null;\n\t} catch {\n\t\treturn null;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,MAAM,yBAAyB;;AAI/B,MAAM,oBAAoB;;AAG1B,MAAM,sBAAsB;;AAG5B,MAAM,mBAAmB;;AAGzB,MAAM,2BAA2B;;;;;;;;;;;AAYjC,eAAsB,UACrB,IACA,MACA,UAA4B,EAAE,EACH;CAE3B,MAAM,aAAa,aAAa,KAAK;AACrC,KAAI,CAAC,WAAW,MACf,OAAM,IAAI,MAAM,uBAAuB,WAAW,OAAO,KAAK,KAAK,GAAG;CAGvE,MAAM,EACL,iBAAiB,OACjB,SACA,oBAAoB,OACpB,aAAa,WACV;CAGJ,MAAM,SAA0B;EAC/B,aAAa;GAAE,SAAS;GAAG,SAAS;GAAG,SAAS;GAAG;EACnD,QAAQ;GAAE,SAAS;GAAG,SAAS;GAAG,SAAS;GAAG;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AAC,QAAQ,qBAAqB,GAAG,CAE9D,QAAQ,kBAAkB,IAAI,CAAC,QAAQ,0BAA0B,IAAI,IACrE,UAAU;SAC1B;AACP,SAAO,QAAQ;;;;;;;AAQjB,SAAS,mBAAmB,QAA8D;AACzF,KAAI;EACH,MAAM,SAAS,UAAU,OAAO;AAChC,MAAI,OAAO,SAAS,QAAQ,OAAO,UAAU,KAC5C,QAAO;GAAE,OAAO,OAAO;GAAO,QAAQ,OAAO;GAAQ;AAEtD,SAAO;SACA;AACP,SAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"authorize-BmCwQCib.mjs","names":[],"sources":["../src/api/authorize.ts"],"sourcesContent":["/**\n * Authorization helpers for API routes\n *\n * Thin wrappers around @emdash-cms/auth RBAC that return HTTP responses.\n * Auth middleware handles authentication; these handle authorization.\n */\n\nimport type { Permission, RoleLevel } from \"@emdash-cms/auth\";\nimport { hasPermission, canActOnOwn } from \"@emdash-cms/auth\";\n\nimport { apiError } from \"./error.js\";\n\ninterface UserLike {\n\tid: string;\n\trole: RoleLevel;\n}\n\n/**\n * Check if user has a permission. Returns a 401/403 Response if not, or null if authorized.\n *\n * Usage:\n * ```ts\n * const denied = requirePerm(user, \"schema:manage\");\n * if (denied) return denied;\n * ```\n */\nexport function requirePerm(\n\tuser: UserLike | null | undefined,\n\tpermission: Permission,\n): Response | null {\n\tif (!user) {\n\t\treturn apiError(\"UNAUTHORIZED\", \"Authentication required\", 401);\n\t}\n\tif (!hasPermission(user, permission)) {\n\t\treturn apiError(\"FORBIDDEN\", \"Insufficient permissions\", 403);\n\t}\n\treturn null;\n}\n\n/**\n * Check if user can act on a resource, considering ownership.\n * Returns a 401/403 Response if not, or null if authorized.\n *\n * Usage:\n * ```ts\n * const denied = requireOwnerPerm(user, item.authorId, \"content:edit_own\", \"content:edit_any\");\n * if (denied) return denied;\n * ```\n */\nexport function requireOwnerPerm(\n\tuser: UserLike | null | undefined,\n\townerId: string,\n\townPermission: Permission,\n\tanyPermission: Permission,\n): Response | null {\n\tif (!user) {\n\t\treturn apiError(\"UNAUTHORIZED\", \"Authentication required\", 401);\n\t}\n\tif (!canActOnOwn(user, ownerId, ownPermission, anyPermission)) {\n\t\treturn apiError(\"FORBIDDEN\", \"Insufficient permissions\", 403);\n\t}\n\treturn null;\n}\n"],"mappings":";;;;;;;;;;;;;AA0BA,SAAgB,YACf,MACA,YACkB;AAClB,KAAI,CAAC,KACJ,QAAO,SAAS,gBAAgB,2BAA2B,IAAI;AAEhE,KAAI,CAAC,cAAc,MAAM,WAAW,CACnC,QAAO,SAAS,aAAa,4BAA4B,IAAI;AAE9D,QAAO;;;;;;;;;;;;AAaR,SAAgB,iBACf,MACA,SACA,eACA,eACkB;AAClB,KAAI,CAAC,KACJ,QAAO,SAAS,gBAAgB,2BAA2B,IAAI;AAEhE,KAAI,CAAC,YAAY,MAAM,SAAS,eAAe,cAAc,CAC5D,QAAO,SAAS,aAAa,4BAA4B,IAAI;AAE9D,QAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"base64-C74Msx8h.mjs","names":[],"sources":["../src/utils/base64.ts"],"sourcesContent":["/**\n * Base64 encoding/decoding utilities.\n *\n * Uses native Uint8Array.prototype.toBase64 / Uint8Array.fromBase64 when\n * available (workerd, Node 26+, modern browsers), falls back to btoa/atob.\n *\n * All base64url encoding uses the { alphabet: \"base64url\" } option natively\n * or manual character replacement as fallback.\n *\n * Delete the fallback paths when the minimum Node version supports these\n * methods natively.\n */\n\nconst hasNative =\n\ttypeof Uint8Array.prototype.toBase64 === \"function\" &&\n\ttypeof Uint8Array.fromBase64 === \"function\";\n\n// Regex patterns for base64url character replacement\nconst BASE64_PLUS_PATTERN = /\\+/g;\nconst BASE64_SLASH_PATTERN = /\\//g;\nconst BASE64_PADDING_PATTERN = /=+$/;\nconst BASE64URL_DASH_PATTERN = /-/g;\nconst BASE64URL_UNDERSCORE_PATTERN = /_/g;\n\n// ---------------------------------------------------------------------------\n// Standard base64 (for opaque tokens, cursors, Basic Auth, etc.)\n// ---------------------------------------------------------------------------\n\n/** Encode a UTF-8 string as standard base64. */\nexport function encodeBase64(str: string): string {\n\tconst bytes = new TextEncoder().encode(str);\n\tif (hasNative) return bytes.toBase64();\n\tlet binary = \"\";\n\tfor (const b of bytes) binary += String.fromCharCode(b);\n\treturn btoa(binary);\n}\n\n/** Decode a standard base64 string to a UTF-8 string. */\nexport function decodeBase64(base64: string): string {\n\tif (hasNative) return new TextDecoder().decode(Uint8Array.fromBase64(base64));\n\tconst binary = atob(base64);\n\tconst bytes = new Uint8Array(binary.length);\n\tfor (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);\n\treturn new TextDecoder().decode(bytes);\n}\n\n// ---------------------------------------------------------------------------\n// Base64url (for tokens, HMAC signatures, PKCE, etc.)\n// ---------------------------------------------------------------------------\n\n/** Encode bytes as base64url without padding. */\nexport function encodeBase64url(bytes: Uint8Array): string {\n\tif (hasNative) return bytes.toBase64({ alphabet: \"base64url\", omitPadding: true });\n\tlet binary = \"\";\n\tfor (const b of bytes) binary += String.fromCharCode(b);\n\treturn btoa(binary)\n\t\t.replace(BASE64_PLUS_PATTERN, \"-\")\n\t\t.replace(BASE64_SLASH_PATTERN, \"_\")\n\t\t.replace(BASE64_PADDING_PATTERN, \"\");\n}\n\n/** Decode a base64url string (with or without padding) to bytes. */\nexport function decodeBase64url(encoded: string): Uint8Array {\n\tif (hasNative) return Uint8Array.fromBase64(encoded, { alphabet: \"base64url\" });\n\tconst base64 = encoded\n\t\t.replace(BASE64URL_DASH_PATTERN, \"+\")\n\t\t.replace(BASE64URL_UNDERSCORE_PATTERN, \"/\");\n\tconst padded = base64 + \"=\".repeat((4 - (base64.length % 4)) % 4);\n\tconst binary = atob(padded);\n\tconst bytes = new Uint8Array(binary.length);\n\tfor (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);\n\treturn bytes;\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAM,YACL,OAAO,WAAW,UAAU,a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AI,WAAW,OAAO,OAAO;AAC3C,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,IAAK,OAAM,KAAK,OAAO,WAAW,EAAE;AACvE,QAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"content-BO61Sx4j.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 type { Kysely } from \"kysely\";\nimport { monotonicFactory } from \"ulidx\";\n\nimport type { Database, RevisionTable } from \"../types.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\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\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(collection: string, entryId: string, keepCount: number): Promise<number> {\n\t\t// Get IDs of revisions to keep\n\t\tconst keep = await 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\t\t\t.execute();\n\n\t\tconst keepIds = keep.map((r) => r.id);\n\n\t\tif (keepIds.length === 0) return 0;\n\n\t\t// Delete everything else for this entry\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.where(\"id\", \"not in\", keepIds)\n\t\t\t.executeTakeFirst();\n\n\t\treturn Number(result.numDeletedRows ?? 0);\n\t}\n\n\t/**\n\t * Update revision data in place\n\t * Used for autosave to avoid creating many small revisions.\n\t */\n\tasync updateData(id: string, data: Record<string, unknown>): Promise<void> {\n\t\tawait this.db\n\t\t\t.updateTable(\"revisions\")\n\t\t\t.set({ data: JSON.stringify(data) })\n\t\t\t.where(\"id\", \"=\", id)\n\t\t\t.execute();\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 { invalidateCollectionCache } from \"../../object-cache/index.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} from \"./types.js\";\nimport {\n\tEmDashValidationError,\n\tScheduledNotDueError,\n\tencodeCursor,\n\tdecodeCursor,\n} from \"./types.js\";\n\n// Regex pattern for ULID validation\nconst ULID_PATTERN = /^[0-9A-Z]{26}$/;\n\n// LIKE wildcards that must be escaped so user search input is matched literally.\nconst LIKE_WILDCARD_RE = /[\\\\%_]/g;\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 * 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\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 = 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` if `baseSlug` is empty after slugification.\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});\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 dbField = this.mapOrderField(orderField);\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\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\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\t// Apply ordering and limit\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\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\tconst [rows, total] = await Promise.all([query.execute(), this.count(type, options.where)]);\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\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 * 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// Build update object with parameterized values\n\t\tconst updates: Record<string, unknown> = {\n\t\t\tupdated_at: now,\n\t\t\tversion: sql`version + 1`,\n\t\t};\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(input.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\tupdates[key] = serializeValue(value);\n\t\t\t\t}\n\t\t\t}\n\t\t}\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\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 * 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) invalidateCollectionCache(type);\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 eb(sql`lower(${sql.ref(col)})`, \"like\", sql`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 * Count content items\n\t */\n\tasync count(type: string, where?: FindManyOptions[\"where\"]): 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\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): Promise<{ total: number; published: number; draft: number; scheduled: 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) => [\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])\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};\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 * `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 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 *\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` (optional) gates the publish on the row still being due:\n\t * `scheduled_at` non-null and in the past. Used by the scheduled-publishing\n\t * sweep to avoid publishing content an editor unscheduled or rescheduled\n\t * between selection and publish. It claims the row with a single conditional\n\t * UPDATE (clearing `scheduled_at`) before any other write, so it is atomic\n\t * even on D1 (no multi-statement transactions) and serialises against\n\t * `unschedule()` and concurrent sweeps — no TOCTOU and no double publish.\n\t */\n\tasync publish(\n\t\ttype: string,\n\t\tid: string,\n\t\tpublishedAt?: string,\n\t\trequireDue = false,\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\n\t\t// Scheduled sweep: atomically claim the row before any other write. A\n\t\t// single conditional UPDATE is atomic per-statement on every dialect\n\t\t// (it doesn't depend on a wrapping transaction, which D1 lacks). If the\n\t\t// schedule was cleared or pushed to the future (unschedule/reschedule)\n\t\t// or another sweep already claimed it, this affects 0 rows and we bail\n\t\t// before promoting any revision — so the row can't be double-published.\n\t\tlet claimedScheduledAt: string | null = null;\n\t\tlet claimedUpdatedAt: string | null = null;\n\t\tif (requireDue) {\n\t\t\tconst claim = await sql`\n\t\t\t\tUPDATE ${sql.ref(tableName)}\n\t\t\t\tSET scheduled_at = NULL,\n\t\t\t\t\tupdated_at = ${now}\n\t\t\t\tWHERE id = ${id}\n\t\t\t\tAND scheduled_at IS NOT NULL\n\t\t\t\tAND scheduled_at <= ${now}\n\t\t\t\tAND deleted_at IS NULL\n\t\t\t`.execute(this.db);\n\t\t\tif ((claim.numAffectedRows ?? 0n) === 0n) {\n\t\t\t\tthrow new ScheduledNotDueError();\n\t\t\t}\n\t\t\t// Remember what we cleared so we can put it back if the publish work\n\t\t\t// below fails on a driver without transactions (see catch). Both\n\t\t\t// values come from the pre-claim snapshot: if a concurrent\n\t\t\t// reschedule-to-a-different-past-time landed between findById and the\n\t\t\t// claim, the restore writes the snapshot value rather than the one the\n\t\t\t// claim actually cleared. That window is tiny and the restore is\n\t\t\t// best-effort retry bookkeeping, so the imprecision is acceptable.\n\t\t\tclaimedScheduledAt = existing.scheduledAt;\n\t\t\tclaimedUpdatedAt = existing.updatedAt;\n\t\t}\n\n\t\t// Track whether the final publish write committed. On D1 the claim above\n\t\t// is already durable (withTransaction is a no-op there), so if a later\n\t\t// step throws we must restore the schedule — otherwise the row is left\n\t\t// `scheduled` with `scheduled_at = NULL` and no sweep ever retries it.\n\t\tlet publishCommitted = false;\n\t\ttry {\n\t\t\tconst revisionRepo = new RevisionRepository(this.db);\n\t\t\tlet revisionToPublish = existing.draftRevisionId || existing.liveRevisionId;\n\n\t\t\tif (!revisionToPublish) {\n\t\t\t\t// No revision exists - create one from current data\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}\n\n\t\t\t// Sync the revision's data into the content table columns\n\t\t\t// so the content table always holds the published version\n\t\t\tconst revision = await revisionRepo.findById(revisionToPublish);\n\t\t\tif (revision) {\n\t\t\t\tawait this.syncDataColumns(type, id, revision.data);\n\n\t\t\t\t// Sync slug from revision if stored there\n\t\t\t\tif (typeof revision.data._slug === \"string\") {\n\t\t\t\t\tawait sql`\n\t\t\t\t\t\tUPDATE ${sql.ref(tableName)}\n\t\t\t\t\t\tSET slug = ${revision.data._slug}\n\t\t\t\t\t\tWHERE id = ${id}\n\t\t\t\t\t`.execute(this.db);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (publishedAt !== undefined) {\n\t\t\t\t// Caller supplied an explicit timestamp, so we overwrite published_at\n\t\t\t\t// directly (used to backdate a publish, e.g. for content migrations).\n\t\t\t\tawait sql`\n\t\t\t\t\tUPDATE ${sql.ref(tableName)}\n\t\t\t\t\tSET live_revision_id = ${revisionToPublish},\n\t\t\t\t\t\tdraft_revision_id = NULL,\n\t\t\t\t\t\tstatus = 'published',\n\t\t\t\t\t\tscheduled_at = NULL,\n\t\t\t\t\t\tpublished_at = ${publishedAt},\n\t\t\t\t\t\tupdated_at = ${now}\n\t\t\t\t\tWHERE id = ${id}\n\t\t\t\t\tAND deleted_at IS NULL\n\t\t\t\t`.execute(this.db);\n\t\t\t} else {\n\t\t\t\t// No timestamp supplied — preserve existing published_at on\n\t\t\t\t// idempotent re-publish, fall back to `now` on first publish.\n\t\t\t\tawait sql`\n\t\t\t\t\tUPDATE ${sql.ref(tableName)}\n\t\t\t\t\tSET live_revision_id = ${revisionToPublish},\n\t\t\t\t\t\tdraft_revision_id = NULL,\n\t\t\t\t\t\tstatus = 'published',\n\t\t\t\t\t\tscheduled_at = NULL,\n\t\t\t\t\t\tpublished_at = COALESCE(published_at, ${now}),\n\t\t\t\t\t\tupdated_at = ${now}\n\t\t\t\t\tWHERE id = ${id}\n\t\t\t\t\tAND deleted_at IS NULL\n\t\t\t\t`.execute(this.db);\n\t\t\t}\n\t\t\tpublishCommitted = true;\n\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\tinvalidateCollectionCache(type);\n\t\t\treturn updated;\n\t\t} catch (error) {\n\t\t\t// Best-effort schedule restore for the no-transaction (D1) case so a\n\t\t\t// failed publish stays retryable. Skipped when the publish actually\n\t\t\t// committed (the failure was afterwards). On SQLite/Postgres the\n\t\t\t// enclosing transaction rolls the claim back, so this restore also\n\t\t\t// rolls back — a harmless no-op. Never mask the original error.\n\t\t\tif (requireDue && claimedScheduledAt && !publishCommitted) {\n\t\t\t\ttry {\n\t\t\t\t\t// Only restore if the row still has pending work: either it's not\n\t\t\t\t\t// published, or it's a published row that still has a draft change\n\t\t\t\t\t// queued. This avoids re-adding a stale schedule (and triggering a\n\t\t\t\t\t// redundant republish) when another actor fully published the row\n\t\t\t\t\t// in the failure window — that publish clears draft_revision_id.\n\t\t\t\t\t// Restore updated_at to its pre-claim value too — the claim bumped\n\t\t\t\t\t// it to `now`, and a failed publish made no real change, so leaving\n\t\t\t\t\t// it advanced would be a phantom modification for \"changed since\"\n\t\t\t\t\t// consumers (sync, ETags, incremental indexers).\n\t\t\t\t\tawait sql`\n\t\t\t\t\t\tUPDATE ${sql.ref(tableName)}\n\t\t\t\t\t\tSET scheduled_at = ${claimedScheduledAt},\n\t\t\t\t\t\t\tupdated_at = ${claimedUpdatedAt ?? now}\n\t\t\t\t\t\tWHERE id = ${id}\n\t\t\t\t\t\tAND scheduled_at IS NULL\n\t\t\t\t\t\tAND deleted_at IS NULL\n\t\t\t\t\t\tAND (status != 'published' OR draft_revision_id IS NOT NULL)\n\t\t\t\t\t`.execute(this.db);\n\t\t\t\t} catch (restoreError) {\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t`[content] Failed to restore schedule for ${type}/${id} after publish failure:`,\n\t\t\t\t\t\trestoreError,\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 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\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\tawait sql`\n\t\t\tUPDATE ${sql.ref(tableName)}\n\t\t\tSET draft_revision_id = ${revisionId},\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\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\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\tif (!existing.draftRevisionId) {\n\t\t\t// No draft to discard\n\t\t\treturn existing;\n\t\t}\n\n\t\tawait sql`\n\t\t\tUPDATE ${sql.ref(tableName)}\n\t\t\tSET draft_revision_id = 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 * Sync data columns in the content table from a data object.\n\t * Used to promote revision data into the content table on publish.\n\t * Keys starting with _ are revision metadata (e.g. _slug) and are skipped.\n\t */\n\tprivate async syncDataColumns(\n\t\ttype: string,\n\t\tid: string,\n\t\tdata: Record<string, unknown>,\n\t): Promise<void> {\n\t\tconst tableName = getTableName(type);\n\t\tconst updates: Record<string, unknown> = {};\n\n\t\tfor (const [key, value] of Object.entries(data)) {\n\t\t\tif (SYSTEM_COLUMNS.has(key)) continue;\n\t\t\tif (key.startsWith(\"_\")) continue; // revision metadata\n\t\t\tvalidateIdentifier(key, \"content field name\");\n\t\t\tupdates[key] = serializeValue(value);\n\t\t}\n\n\t\tif (Object.keys(updates).length === 0) return;\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.execute();\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\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): string {\n\t\tconst mapping: Record<string, string> = {\n\t\t\tcreatedAt: \"created_at\",\n\t\t\tupdatedAt: \"updated_at\",\n\t\t\tpublishedAt: \"published_at\",\n\t\t\tscheduledAt: \"scheduled_at\",\n\t\t\tdeletedAt: \"deleted_at\",\n\t\t\ttitle: \"title\",\n\t\t\tname: \"name\",\n\t\t\tslug: \"slug\",\n\t\t\tstatus: \"status\",\n\t\t\tlocale: \"locale\",\n\t\t};\n\n\t\tconst mapped = mapping[field];\n\t\tif (!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