emdash 0.33.0 → 0.35.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 (916) hide show
  1. package/dist/{adapters-BMyNSSZi.d.mts → adapters-Bb1vG41D.d.mts} +33 -2
  2. package/dist/adapters-Bb1vG41D.d.mts.map +1 -0
  3. package/dist/{allowed-origins-CG1pACtS.mjs → allowed-origins-DW7sYyqg.mjs} +2 -2
  4. package/dist/{allowed-origins-CG1pACtS.mjs.map → allowed-origins-DW7sYyqg.mjs.map} +1 -1
  5. package/dist/api/route-utils.d.mts +3 -3
  6. package/dist/api/route-utils.mjs +22 -21
  7. package/dist/api/route-utils.mjs.map +1 -1
  8. package/dist/api/schemas/index.d.mts +2 -2
  9. package/dist/api/schemas/index.mjs +6 -5
  10. package/dist/{api-D2hunekQ.mjs → api-BeBglVxU.mjs} +98 -407
  11. package/dist/api-BeBglVxU.mjs.map +1 -0
  12. package/dist/{api-tokens-CSND0i1z.mjs → api-tokens-KO24G1Fd.mjs} +2 -2
  13. package/dist/{api-tokens-CSND0i1z.mjs.map → api-tokens-KO24G1Fd.mjs.map} +1 -1
  14. package/dist/{apply-kwNEJW2l.mjs → apply-kUDt80-G.mjs} +131 -107
  15. package/dist/apply-kUDt80-G.mjs.map +1 -0
  16. package/dist/astro/index.d.mts +12 -12
  17. package/dist/astro/index.d.mts.map +1 -1
  18. package/dist/astro/index.mjs +163 -49
  19. package/dist/astro/index.mjs.map +1 -1
  20. package/dist/astro/middleware/auth.d.mts +10 -10
  21. package/dist/astro/middleware/auth.mjs +8 -8
  22. package/dist/astro/middleware/media-usage-write-fence.d.mts +7 -0
  23. package/dist/astro/middleware/media-usage-write-fence.d.mts.map +1 -0
  24. package/dist/astro/middleware/media-usage-write-fence.mjs +35 -0
  25. package/dist/astro/middleware/media-usage-write-fence.mjs.map +1 -0
  26. package/dist/astro/middleware/redirect.d.mts.map +1 -1
  27. package/dist/astro/middleware/redirect.mjs +10 -7
  28. package/dist/astro/middleware/redirect.mjs.map +1 -1
  29. package/dist/astro/middleware/request-context.mjs +3 -3
  30. package/dist/astro/middleware/setup.mjs +1 -1
  31. package/dist/astro/middleware.d.mts +12 -11
  32. package/dist/astro/middleware.d.mts.map +1 -1
  33. package/dist/astro/middleware.mjs +1763 -173
  34. package/dist/astro/middleware.mjs.map +1 -1
  35. package/dist/astro/routes/api/admin/allowed-domains/_domain_.mjs +9 -8
  36. package/dist/astro/routes/api/admin/allowed-domains/_domain_.mjs.map +1 -1
  37. package/dist/astro/routes/api/admin/allowed-domains/index.mjs +9 -8
  38. package/dist/astro/routes/api/admin/allowed-domains/index.mjs.map +1 -1
  39. package/dist/astro/routes/api/admin/api-tokens/_id_.mjs +5 -5
  40. package/dist/astro/routes/api/admin/api-tokens/index.mjs +6 -6
  41. package/dist/astro/routes/api/admin/byline-fields/_slug_/usage.mjs +6 -6
  42. package/dist/astro/routes/api/admin/byline-fields/_slug_.mjs +12 -11
  43. package/dist/astro/routes/api/admin/byline-fields/_slug_.mjs.map +1 -1
  44. package/dist/astro/routes/api/admin/byline-fields/index.mjs +12 -11
  45. package/dist/astro/routes/api/admin/byline-fields/index.mjs.map +1 -1
  46. package/dist/astro/routes/api/admin/byline-fields/reorder.mjs +12 -11
  47. package/dist/astro/routes/api/admin/byline-fields/reorder.mjs.map +1 -1
  48. package/dist/astro/routes/api/admin/bylines/_id_/index.mjs +17 -17
  49. package/dist/astro/routes/api/admin/bylines/_id_/translations.mjs +17 -17
  50. package/dist/astro/routes/api/admin/bylines/index.mjs +17 -17
  51. package/dist/astro/routes/api/admin/comments/_id_/status.mjs +14 -13
  52. package/dist/astro/routes/api/admin/comments/_id_/status.mjs.map +1 -1
  53. package/dist/astro/routes/api/admin/comments/_id_.mjs +6 -6
  54. package/dist/astro/routes/api/admin/comments/bulk.mjs +12 -11
  55. package/dist/astro/routes/api/admin/comments/bulk.mjs.map +1 -1
  56. package/dist/astro/routes/api/admin/comments/counts.mjs +6 -6
  57. package/dist/astro/routes/api/admin/comments/index.mjs +12 -11
  58. package/dist/astro/routes/api/admin/comments/index.mjs.map +1 -1
  59. package/dist/astro/routes/api/admin/hooks/exclusive/_hookName_.mjs +5 -5
  60. package/dist/astro/routes/api/admin/hooks/exclusive/index.mjs +4 -4
  61. package/dist/astro/routes/api/admin/media-usage/collection-deletions/index.d.mts +8 -0
  62. package/dist/astro/routes/api/admin/media-usage/collection-deletions/index.d.mts.map +1 -0
  63. package/dist/astro/routes/api/admin/media-usage/collection-deletions/index.mjs +36 -0
  64. package/dist/astro/routes/api/admin/media-usage/collection-deletions/index.mjs.map +1 -0
  65. package/dist/astro/routes/api/admin/media-usage/collection-deletions/retry.d.mts +8 -0
  66. package/dist/astro/routes/api/admin/media-usage/collection-deletions/retry.d.mts.map +1 -0
  67. package/dist/astro/routes/api/admin/media-usage/collection-deletions/retry.mjs +36 -0
  68. package/dist/astro/routes/api/admin/media-usage/collection-deletions/retry.mjs.map +1 -0
  69. package/dist/astro/routes/api/admin/media-usage/repair.mjs +15 -14
  70. package/dist/astro/routes/api/admin/media-usage/repair.mjs.map +1 -1
  71. package/dist/astro/routes/api/admin/media-usage/work/index.d.mts +8 -0
  72. package/dist/astro/routes/api/admin/media-usage/work/index.d.mts.map +1 -0
  73. package/dist/astro/routes/api/admin/media-usage/work/index.mjs +37 -0
  74. package/dist/astro/routes/api/admin/media-usage/work/index.mjs.map +1 -0
  75. package/dist/astro/routes/api/admin/media-usage/work/retry.d.mts +8 -0
  76. package/dist/astro/routes/api/admin/media-usage/work/retry.d.mts.map +1 -0
  77. package/dist/astro/routes/api/admin/media-usage/work/retry.mjs +37 -0
  78. package/dist/astro/routes/api/admin/media-usage/work/retry.mjs.map +1 -0
  79. package/dist/astro/routes/api/admin/oauth-clients/_id_.mjs +5 -5
  80. package/dist/astro/routes/api/admin/oauth-clients/index.mjs +5 -5
  81. package/dist/astro/routes/api/admin/plugins/_id_/disable.d.mts.map +1 -1
  82. package/dist/astro/routes/api/admin/plugins/_id_/disable.mjs +51 -43
  83. package/dist/astro/routes/api/admin/plugins/_id_/disable.mjs.map +1 -1
  84. package/dist/astro/routes/api/admin/plugins/_id_/enable.d.mts.map +1 -1
  85. package/dist/astro/routes/api/admin/plugins/_id_/enable.mjs +51 -43
  86. package/dist/astro/routes/api/admin/plugins/_id_/enable.mjs.map +1 -1
  87. package/dist/astro/routes/api/admin/plugins/_id_/index.mjs +47 -42
  88. package/dist/astro/routes/api/admin/plugins/_id_/index.mjs.map +1 -1
  89. package/dist/astro/routes/api/admin/plugins/_id_/mcp.mjs +6 -6
  90. package/dist/astro/routes/api/admin/plugins/_id_/settings.mjs +47 -42
  91. package/dist/astro/routes/api/admin/plugins/_id_/settings.mjs.map +1 -1
  92. package/dist/astro/routes/api/admin/plugins/_id_/uninstall.d.mts.map +1 -1
  93. package/dist/astro/routes/api/admin/plugins/_id_/uninstall.mjs +50 -42
  94. package/dist/astro/routes/api/admin/plugins/_id_/uninstall.mjs.map +1 -1
  95. package/dist/astro/routes/api/admin/plugins/_id_/update.d.mts.map +1 -1
  96. package/dist/astro/routes/api/admin/plugins/_id_/update.mjs +50 -42
  97. package/dist/astro/routes/api/admin/plugins/_id_/update.mjs.map +1 -1
  98. package/dist/astro/routes/api/admin/plugins/index.mjs +47 -42
  99. package/dist/astro/routes/api/admin/plugins/index.mjs.map +1 -1
  100. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/icon.mjs +4 -4
  101. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/index.mjs +47 -42
  102. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/index.mjs.map +1 -1
  103. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.d.mts.map +1 -1
  104. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.mjs +50 -42
  105. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.mjs.map +1 -1
  106. package/dist/astro/routes/api/admin/plugins/marketplace/index.mjs +47 -42
  107. package/dist/astro/routes/api/admin/plugins/marketplace/index.mjs.map +1 -1
  108. package/dist/astro/routes/api/admin/plugins/registry/_id_/uninstall.d.mts.map +1 -1
  109. package/dist/astro/routes/api/admin/plugins/registry/_id_/uninstall.mjs +50 -42
  110. package/dist/astro/routes/api/admin/plugins/registry/_id_/uninstall.mjs.map +1 -1
  111. package/dist/astro/routes/api/admin/plugins/registry/_id_/update.d.mts.map +1 -1
  112. package/dist/astro/routes/api/admin/plugins/registry/_id_/update.mjs +51 -43
  113. package/dist/astro/routes/api/admin/plugins/registry/_id_/update.mjs.map +1 -1
  114. package/dist/astro/routes/api/admin/plugins/registry/artifact.mjs +47 -42
  115. package/dist/astro/routes/api/admin/plugins/registry/artifact.mjs.map +1 -1
  116. package/dist/astro/routes/api/admin/plugins/registry/install.d.mts.map +1 -1
  117. package/dist/astro/routes/api/admin/plugins/registry/install.mjs +51 -43
  118. package/dist/astro/routes/api/admin/plugins/registry/install.mjs.map +1 -1
  119. package/dist/astro/routes/api/admin/plugins/updates.mjs +47 -42
  120. package/dist/astro/routes/api/admin/plugins/updates.mjs.map +1 -1
  121. package/dist/astro/routes/api/admin/themes/marketplace/_id_/index.mjs +47 -42
  122. package/dist/astro/routes/api/admin/themes/marketplace/_id_/index.mjs.map +1 -1
  123. package/dist/astro/routes/api/admin/themes/marketplace/_id_/thumbnail.mjs +4 -4
  124. package/dist/astro/routes/api/admin/themes/marketplace/index.mjs +47 -42
  125. package/dist/astro/routes/api/admin/themes/marketplace/index.mjs.map +1 -1
  126. package/dist/astro/routes/api/admin/users/_id_/disable.mjs +3 -3
  127. package/dist/astro/routes/api/admin/users/_id_/enable.mjs +3 -3
  128. package/dist/astro/routes/api/admin/users/_id_/index.mjs +9 -8
  129. package/dist/astro/routes/api/admin/users/_id_/index.mjs.map +1 -1
  130. package/dist/astro/routes/api/admin/users/_id_/send-recovery.mjs +4 -4
  131. package/dist/astro/routes/api/admin/users/index.mjs +9 -8
  132. package/dist/astro/routes/api/admin/users/index.mjs.map +1 -1
  133. package/dist/astro/routes/api/auth/dev-bypass.d.mts.map +1 -1
  134. package/dist/astro/routes/api/auth/dev-bypass.mjs +5 -9
  135. package/dist/astro/routes/api/auth/dev-bypass.mjs.map +1 -1
  136. package/dist/astro/routes/api/auth/invite/accept.mjs +3 -3
  137. package/dist/astro/routes/api/auth/invite/complete.mjs +13 -12
  138. package/dist/astro/routes/api/auth/invite/complete.mjs.map +1 -1
  139. package/dist/astro/routes/api/auth/invite/index.mjs +10 -9
  140. package/dist/astro/routes/api/auth/invite/index.mjs.map +1 -1
  141. package/dist/astro/routes/api/auth/invite/register-options.mjs +12 -11
  142. package/dist/astro/routes/api/auth/invite/register-options.mjs.map +1 -1
  143. package/dist/astro/routes/api/auth/logout.mjs +4 -4
  144. package/dist/astro/routes/api/auth/magic-link/send.mjs +12 -11
  145. package/dist/astro/routes/api/auth/magic-link/send.mjs.map +1 -1
  146. package/dist/astro/routes/api/auth/magic-link/verify.mjs +4 -4
  147. package/dist/astro/routes/api/auth/me.mjs +10 -9
  148. package/dist/astro/routes/api/auth/me.mjs.map +1 -1
  149. package/dist/astro/routes/api/auth/mode.mjs +4 -4
  150. package/dist/astro/routes/api/auth/oauth/_provider_/callback.mjs +3 -3
  151. package/dist/astro/routes/api/auth/oauth/_provider_.mjs +2 -2
  152. package/dist/astro/routes/api/auth/passkey/_id_.mjs +9 -8
  153. package/dist/astro/routes/api/auth/passkey/_id_.mjs.map +1 -1
  154. package/dist/astro/routes/api/auth/passkey/index.mjs +3 -3
  155. package/dist/astro/routes/api/auth/passkey/options.mjs +14 -13
  156. package/dist/astro/routes/api/auth/passkey/options.mjs.map +1 -1
  157. package/dist/astro/routes/api/auth/passkey/register/options.mjs +12 -11
  158. package/dist/astro/routes/api/auth/passkey/register/options.mjs.map +1 -1
  159. package/dist/astro/routes/api/auth/passkey/register/verify.mjs +13 -12
  160. package/dist/astro/routes/api/auth/passkey/register/verify.mjs.map +1 -1
  161. package/dist/astro/routes/api/auth/passkey/verify.mjs +13 -12
  162. package/dist/astro/routes/api/auth/passkey/verify.mjs.map +1 -1
  163. package/dist/astro/routes/api/auth/signup/complete.mjs +13 -12
  164. package/dist/astro/routes/api/auth/signup/complete.mjs.map +1 -1
  165. package/dist/astro/routes/api/auth/signup/request.mjs +12 -11
  166. package/dist/astro/routes/api/auth/signup/request.mjs.map +1 -1
  167. package/dist/astro/routes/api/auth/signup/verify.mjs +3 -3
  168. package/dist/astro/routes/api/comments/_collection_/_contentId_/index.mjs +15 -14
  169. package/dist/astro/routes/api/comments/_collection_/_contentId_/index.mjs.map +1 -1
  170. package/dist/astro/routes/api/comments/_collection_/_contentId_/reactions.mjs +14 -13
  171. package/dist/astro/routes/api/comments/_collection_/_contentId_/reactions.mjs.map +1 -1
  172. package/dist/astro/routes/api/content/_collection_/_id_/compare.mjs +4 -4
  173. package/dist/astro/routes/api/content/_collection_/_id_/discard-draft.mjs +5 -5
  174. package/dist/astro/routes/api/content/_collection_/_id_/duplicate.mjs +5 -5
  175. package/dist/astro/routes/api/content/_collection_/_id_/permanent.mjs +4 -4
  176. package/dist/astro/routes/api/content/_collection_/_id_/preview-url.mjs +13 -13
  177. package/dist/astro/routes/api/content/_collection_/_id_/publish.mjs +11 -10
  178. package/dist/astro/routes/api/content/_collection_/_id_/publish.mjs.map +1 -1
  179. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/children.mjs +18 -17
  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 -5
  184. package/dist/astro/routes/api/content/_collection_/_id_/revisions.mjs +4 -4
  185. package/dist/astro/routes/api/content/_collection_/_id_/schedule.mjs +11 -10
  186. package/dist/astro/routes/api/content/_collection_/_id_/schedule.mjs.map +1 -1
  187. package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.d.mts.map +1 -1
  188. package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.mjs +44 -31
  189. package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.mjs.map +1 -1
  190. package/dist/astro/routes/api/content/_collection_/_id_/translations.mjs +4 -4
  191. package/dist/astro/routes/api/content/_collection_/_id_/unpublish.mjs +5 -5
  192. package/dist/astro/routes/api/content/_collection_/_id_.mjs +11 -10
  193. package/dist/astro/routes/api/content/_collection_/_id_.mjs.map +1 -1
  194. package/dist/astro/routes/api/content/_collection_/authors.mjs +4 -4
  195. package/dist/astro/routes/api/content/_collection_/index.mjs +11 -10
  196. package/dist/astro/routes/api/content/_collection_/index.mjs.map +1 -1
  197. package/dist/astro/routes/api/content/_collection_/trash.mjs +10 -9
  198. package/dist/astro/routes/api/content/_collection_/trash.mjs.map +1 -1
  199. package/dist/astro/routes/api/dashboard.mjs +10 -8
  200. package/dist/astro/routes/api/dashboard.mjs.map +1 -1
  201. package/dist/astro/routes/api/dev/emails.mjs +4 -4
  202. package/dist/astro/routes/api/import/probe.d.mts +3 -3
  203. package/dist/astro/routes/api/import/probe.mjs +18 -16
  204. package/dist/astro/routes/api/import/probe.mjs.map +1 -1
  205. package/dist/astro/routes/api/import/wordpress/analyze.mjs +5 -5
  206. package/dist/astro/routes/api/import/wordpress/execute.d.mts +11 -11
  207. package/dist/astro/routes/api/import/wordpress/execute.mjs +15 -15
  208. package/dist/astro/routes/api/import/wordpress/execute.mjs.map +1 -1
  209. package/dist/astro/routes/api/import/wordpress/media.d.mts +10 -10
  210. package/dist/astro/routes/api/import/wordpress/media.mjs +14 -12
  211. package/dist/astro/routes/api/import/wordpress/media.mjs.map +1 -1
  212. package/dist/astro/routes/api/import/wordpress/prepare.mjs +13 -12
  213. package/dist/astro/routes/api/import/wordpress/prepare.mjs.map +1 -1
  214. package/dist/astro/routes/api/import/wordpress/rewrite-urls.d.mts +11 -11
  215. package/dist/astro/routes/api/import/wordpress/rewrite-urls.mjs +14 -14
  216. package/dist/astro/routes/api/import/wordpress-plugin/analyze.d.mts +1 -1
  217. package/dist/astro/routes/api/import/wordpress-plugin/analyze.mjs +18 -16
  218. package/dist/astro/routes/api/import/wordpress-plugin/analyze.mjs.map +1 -1
  219. package/dist/astro/routes/api/import/wordpress-plugin/callback.mjs +1 -1
  220. package/dist/astro/routes/api/import/wordpress-plugin/execute.d.mts +11 -11
  221. package/dist/astro/routes/api/import/wordpress-plugin/execute.mjs +28 -27
  222. package/dist/astro/routes/api/import/wordpress-plugin/execute.mjs.map +1 -1
  223. package/dist/astro/routes/api/manifest.mjs +5 -5
  224. package/dist/astro/routes/api/mcp.d.mts.map +1 -1
  225. package/dist/astro/routes/api/mcp.mjs +174 -72
  226. package/dist/astro/routes/api/mcp.mjs.map +1 -1
  227. package/dist/astro/routes/api/media/_id_/confirm.mjs +13 -11
  228. package/dist/astro/routes/api/media/_id_/confirm.mjs.map +1 -1
  229. package/dist/astro/routes/api/media/_id_/upload.mjs +6 -6
  230. package/dist/astro/routes/api/media/_id_/usage.mjs +17 -16
  231. package/dist/astro/routes/api/media/_id_/usage.mjs.map +1 -1
  232. package/dist/astro/routes/api/media/_id_.mjs +16 -15
  233. package/dist/astro/routes/api/media/_id_.mjs.map +1 -1
  234. package/dist/astro/routes/api/media/file/_...key_.mjs +3 -3
  235. package/dist/astro/routes/api/media/providers/_providerId_/_itemId_.mjs +4 -4
  236. package/dist/astro/routes/api/media/providers/_providerId_/index.mjs +4 -4
  237. package/dist/astro/routes/api/media/providers/index.mjs +4 -4
  238. package/dist/astro/routes/api/media/upload-url.mjs +11 -10
  239. package/dist/astro/routes/api/media/upload-url.mjs.map +1 -1
  240. package/dist/astro/routes/api/media.mjs +18 -15
  241. package/dist/astro/routes/api/media.mjs.map +1 -1
  242. package/dist/astro/routes/api/menus/_name_/items/_id_.mjs +11 -11
  243. package/dist/astro/routes/api/menus/_name_/items.mjs +11 -11
  244. package/dist/astro/routes/api/menus/_name_/reorder.mjs +11 -11
  245. package/dist/astro/routes/api/menus/_name_/translations.mjs +11 -11
  246. package/dist/astro/routes/api/menus/_name_.mjs +11 -11
  247. package/dist/astro/routes/api/menus/index.mjs +11 -11
  248. package/dist/astro/routes/api/oauth/authorize.mjs +6 -6
  249. package/dist/astro/routes/api/oauth/device/authorize.mjs +7 -7
  250. package/dist/astro/routes/api/oauth/device/code.mjs +10 -10
  251. package/dist/astro/routes/api/oauth/device/token.mjs +9 -9
  252. package/dist/astro/routes/api/oauth/register.mjs +4 -4
  253. package/dist/astro/routes/api/oauth/token/refresh.mjs +7 -7
  254. package/dist/astro/routes/api/oauth/token/revoke.mjs +7 -7
  255. package/dist/astro/routes/api/oauth/token.mjs +7 -7
  256. package/dist/astro/routes/api/openapi.json.mjs +152 -6
  257. package/dist/astro/routes/api/openapi.json.mjs.map +1 -1
  258. package/dist/astro/routes/api/plugins/_pluginId_/_...path_.d.mts.map +1 -1
  259. package/dist/astro/routes/api/plugins/_pluginId_/_...path_.mjs +8 -7
  260. package/dist/astro/routes/api/plugins/_pluginId_/_...path_.mjs.map +1 -1
  261. package/dist/astro/routes/api/redirects/404s/index.mjs +12 -11
  262. package/dist/astro/routes/api/redirects/404s/index.mjs.map +1 -1
  263. package/dist/astro/routes/api/redirects/404s/summary.mjs +12 -11
  264. package/dist/astro/routes/api/redirects/404s/summary.mjs.map +1 -1
  265. package/dist/astro/routes/api/redirects/_id_.mjs +13 -12
  266. package/dist/astro/routes/api/redirects/_id_.mjs.map +1 -1
  267. package/dist/astro/routes/api/redirects/index.mjs +13 -12
  268. package/dist/astro/routes/api/redirects/index.mjs.map +1 -1
  269. package/dist/astro/routes/api/relations/_id_/index.mjs +18 -17
  270. package/dist/astro/routes/api/relations/_id_/index.mjs.map +1 -1
  271. package/dist/astro/routes/api/relations/_id_/translations.mjs +13 -12
  272. package/dist/astro/routes/api/relations/_id_/translations.mjs.map +1 -1
  273. package/dist/astro/routes/api/relations/index.mjs +18 -17
  274. package/dist/astro/routes/api/relations/index.mjs.map +1 -1
  275. package/dist/astro/routes/api/revisions/_revisionId_/index.mjs +4 -4
  276. package/dist/astro/routes/api/revisions/_revisionId_/restore.mjs +5 -5
  277. package/dist/astro/routes/api/schema/collections/_slug_/fields/_fieldSlug_.mjs +47 -42
  278. package/dist/astro/routes/api/schema/collections/_slug_/fields/_fieldSlug_.mjs.map +1 -1
  279. package/dist/astro/routes/api/schema/collections/_slug_/fields/index.mjs +47 -42
  280. package/dist/astro/routes/api/schema/collections/_slug_/fields/index.mjs.map +1 -1
  281. package/dist/astro/routes/api/schema/collections/_slug_/fields/reorder.mjs +47 -42
  282. package/dist/astro/routes/api/schema/collections/_slug_/fields/reorder.mjs.map +1 -1
  283. package/dist/astro/routes/api/schema/collections/_slug_/index.d.mts.map +1 -1
  284. package/dist/astro/routes/api/schema/collections/_slug_/index.mjs +47 -42
  285. package/dist/astro/routes/api/schema/collections/_slug_/index.mjs.map +1 -1
  286. package/dist/astro/routes/api/schema/collections/index.mjs +47 -42
  287. package/dist/astro/routes/api/schema/collections/index.mjs.map +1 -1
  288. package/dist/astro/routes/api/schema/collections/reorder.mjs +47 -42
  289. package/dist/astro/routes/api/schema/collections/reorder.mjs.map +1 -1
  290. package/dist/astro/routes/api/schema/index.mjs +10 -9
  291. package/dist/astro/routes/api/schema/index.mjs.map +1 -1
  292. package/dist/astro/routes/api/schema/orphans/_slug_.mjs +47 -42
  293. package/dist/astro/routes/api/schema/orphans/_slug_.mjs.map +1 -1
  294. package/dist/astro/routes/api/schema/orphans/index.mjs +47 -42
  295. package/dist/astro/routes/api/schema/orphans/index.mjs.map +1 -1
  296. package/dist/astro/routes/api/search/enable.mjs +13 -13
  297. package/dist/astro/routes/api/search/index.mjs +12 -12
  298. package/dist/astro/routes/api/search/rebuild.mjs +13 -13
  299. package/dist/astro/routes/api/search/stats.mjs +8 -8
  300. package/dist/astro/routes/api/search/suggest.mjs +12 -12
  301. package/dist/astro/routes/api/sections/_slug_.mjs +12 -11
  302. package/dist/astro/routes/api/sections/_slug_.mjs.map +1 -1
  303. package/dist/astro/routes/api/sections/index.mjs +12 -11
  304. package/dist/astro/routes/api/sections/index.mjs.map +1 -1
  305. package/dist/astro/routes/api/settings/backups/archives/_name_.mjs +7 -7
  306. package/dist/astro/routes/api/settings/backups/archives/index.mjs +6 -6
  307. package/dist/astro/routes/api/settings/backups/export.mjs +7 -7
  308. package/dist/astro/routes/api/settings/backups/index.mjs +8 -8
  309. package/dist/astro/routes/api/settings/email.mjs +5 -5
  310. package/dist/astro/routes/api/settings.mjs +14 -13
  311. package/dist/astro/routes/api/settings.mjs.map +1 -1
  312. package/dist/astro/routes/api/setup/admin-verify.mjs +14 -13
  313. package/dist/astro/routes/api/setup/admin-verify.mjs.map +1 -1
  314. package/dist/astro/routes/api/setup/admin.mjs +13 -12
  315. package/dist/astro/routes/api/setup/admin.mjs.map +1 -1
  316. package/dist/astro/routes/api/setup/dev-bypass.d.mts.map +1 -1
  317. package/dist/astro/routes/api/setup/dev-bypass.mjs +30 -31
  318. package/dist/astro/routes/api/setup/dev-bypass.mjs.map +1 -1
  319. package/dist/astro/routes/api/setup/dev-reset.mjs +3 -3
  320. package/dist/astro/routes/api/setup/index.d.mts.map +1 -1
  321. package/dist/astro/routes/api/setup/index.mjs +31 -35
  322. package/dist/astro/routes/api/setup/index.mjs.map +1 -1
  323. package/dist/astro/routes/api/setup/status.mjs +5 -5
  324. package/dist/astro/routes/api/snapshot.mjs +8 -8
  325. package/dist/astro/routes/api/taxonomies/_name_/reorder.mjs +16 -15
  326. package/dist/astro/routes/api/taxonomies/_name_/reorder.mjs.map +1 -1
  327. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_/translations.mjs +16 -15
  328. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_/translations.mjs.map +1 -1
  329. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_.mjs +16 -15
  330. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_.mjs.map +1 -1
  331. package/dist/astro/routes/api/taxonomies/_name_/terms/index.d.mts.map +1 -1
  332. package/dist/astro/routes/api/taxonomies/_name_/terms/index.mjs +18 -16
  333. package/dist/astro/routes/api/taxonomies/_name_/terms/index.mjs.map +1 -1
  334. package/dist/astro/routes/api/taxonomies/_name_/translations.d.mts +8 -0
  335. package/dist/astro/routes/api/taxonomies/_name_/translations.d.mts.map +1 -0
  336. package/dist/astro/routes/api/taxonomies/_name_/translations.mjs +46 -0
  337. package/dist/astro/routes/api/taxonomies/_name_/translations.mjs.map +1 -0
  338. package/dist/astro/routes/api/taxonomies/_name_.d.mts +19 -0
  339. package/dist/astro/routes/api/taxonomies/_name_.d.mts.map +1 -0
  340. package/dist/astro/routes/api/taxonomies/_name_.mjs +88 -0
  341. package/dist/astro/routes/api/taxonomies/_name_.mjs.map +1 -0
  342. package/dist/astro/routes/api/taxonomies/index.mjs +16 -15
  343. package/dist/astro/routes/api/taxonomies/index.mjs.map +1 -1
  344. package/dist/astro/routes/api/themes/preview.mjs +6 -6
  345. package/dist/astro/routes/api/typegen.mjs +6 -6
  346. package/dist/astro/routes/api/well-known/auth.mjs +1 -1
  347. package/dist/astro/routes/api/well-known/oauth-authorization-server.mjs +2 -2
  348. package/dist/astro/routes/api/well-known/oauth-protected-resource.mjs +2 -2
  349. package/dist/astro/routes/api/widget-areas/_name_/reorder.mjs +10 -9
  350. package/dist/astro/routes/api/widget-areas/_name_/reorder.mjs.map +1 -1
  351. package/dist/astro/routes/api/widget-areas/_name_/widgets/_id_.mjs +12 -11
  352. package/dist/astro/routes/api/widget-areas/_name_/widgets/_id_.mjs.map +1 -1
  353. package/dist/astro/routes/api/widget-areas/_name_/widgets.mjs +12 -11
  354. package/dist/astro/routes/api/widget-areas/_name_/widgets.mjs.map +1 -1
  355. package/dist/astro/routes/api/widget-areas/_name_.mjs +7 -6
  356. package/dist/astro/routes/api/widget-areas/_name_.mjs.map +1 -1
  357. package/dist/astro/routes/api/widget-areas/index.mjs +12 -11
  358. package/dist/astro/routes/api/widget-areas/index.mjs.map +1 -1
  359. package/dist/astro/routes/api/widget-components.mjs +4 -4
  360. package/dist/astro/routes/robots.txt.mjs +7 -6
  361. package/dist/astro/routes/robots.txt.mjs.map +1 -1
  362. package/dist/astro/routes/sitemap-_collection_.xml.mjs +10 -10
  363. package/dist/astro/routes/sitemap.xml.mjs +8 -7
  364. package/dist/astro/routes/sitemap.xml.mjs.map +1 -1
  365. package/dist/astro/types.d.mts +35 -17
  366. package/dist/astro/types.d.mts.map +1 -1
  367. package/dist/auth/providers/github.d.mts +1 -1
  368. package/dist/auth/providers/google.d.mts +1 -1
  369. package/dist/{authorize-qRhWQnel.mjs → authorize-DUElxgOQ.mjs} +2 -2
  370. package/dist/{authorize-qRhWQnel.mjs.map → authorize-DUElxgOQ.mjs.map} +1 -1
  371. package/dist/{backup-CtA6LDNw.mjs → backup-DWYpJlLj.mjs} +4 -4
  372. package/dist/{backup-CtA6LDNw.mjs.map → backup-DWYpJlLj.mjs.map} +1 -1
  373. package/dist/{base64-B-PsqheR.mjs → base64-CvLhUKQv.mjs} +1 -1
  374. package/dist/{base64-B-PsqheR.mjs.map → base64-CvLhUKQv.mjs.map} +1 -1
  375. package/dist/bundle-vn56sLos.mjs +663 -0
  376. package/dist/bundle-vn56sLos.mjs.map +1 -0
  377. package/dist/{byline-fields-CNc0Yq5i.mjs → byline-fields-txaLGoME.mjs} +2 -2
  378. package/dist/{byline-fields-CNc0Yq5i.mjs.map → byline-fields-txaLGoME.mjs.map} +1 -1
  379. package/dist/{byline-registry-ZkPKqEwC.mjs → byline-registry-DDun8sxh.mjs} +2 -2
  380. package/dist/{byline-registry-ZkPKqEwC.mjs.map → byline-registry-DDun8sxh.mjs.map} +1 -1
  381. package/dist/{byline-Cp6csL84.mjs → byline-yjvWq4ip.mjs} +5 -5
  382. package/dist/{byline-Cp6csL84.mjs.map → byline-yjvWq4ip.mjs.map} +1 -1
  383. package/dist/{bylines-cf-C9lmF.mjs → bylines-Bu7pchQ4.mjs} +5 -5
  384. package/dist/{bylines-cf-C9lmF.mjs.map → bylines-Bu7pchQ4.mjs.map} +1 -1
  385. package/dist/{bylines-CEj5CdT4.mjs → bylines-DjXS5p0P.mjs} +7 -7
  386. package/dist/{bylines-CEj5CdT4.mjs.map → bylines-DjXS5p0P.mjs.map} +1 -1
  387. package/dist/{cache-C9FptTFR.mjs → cache-C46-3Irl.mjs} +3 -3
  388. package/dist/{cache-C9FptTFR.mjs.map → cache-C46-3Irl.mjs.map} +1 -1
  389. package/dist/{challenge-store-D9VNKELo.mjs → challenge-store-SIL5DsF2.mjs} +1 -1
  390. package/dist/{challenge-store-D9VNKELo.mjs.map → challenge-store-SIL5DsF2.mjs.map} +1 -1
  391. package/dist/{chunks-DbYzib_k.mjs → chunks-fiZ8G9RJ.mjs} +2 -2
  392. package/dist/{chunks-DbYzib_k.mjs.map → chunks-fiZ8G9RJ.mjs.map} +1 -1
  393. package/dist/cli/index.mjs +655 -677
  394. package/dist/cli/index.mjs.map +1 -1
  395. package/dist/client/cf-access.d.mts +1 -1
  396. package/dist/client/index.d.mts +74 -4
  397. package/dist/client/index.d.mts.map +1 -1
  398. package/dist/client/index.mjs +25 -2
  399. package/dist/client/index.mjs.map +1 -1
  400. package/dist/collection-deletion-DQPvMD8R.mjs +779 -0
  401. package/dist/collection-deletion-DQPvMD8R.mjs.map +1 -0
  402. package/dist/{comment-BIkJ6Fil.mjs → comment-Dxlep6cE.mjs} +2 -2
  403. package/dist/{comment-BIkJ6Fil.mjs.map → comment-Dxlep6cE.mjs.map} +1 -1
  404. package/dist/{comment-reaction-D-laEceb.mjs → comment-reaction-D-2J84UE.mjs} +2 -2
  405. package/dist/{comment-reaction-D-laEceb.mjs.map → comment-reaction-D-2J84UE.mjs.map} +1 -1
  406. package/dist/{comments-0_w6KChA.mjs → comments-CTfZtLmM.mjs} +3 -3
  407. package/dist/{comments-0_w6KChA.mjs.map → comments-CTfZtLmM.mjs.map} +1 -1
  408. package/dist/{components-BPxrRjpE.mjs → components-CQy3lh9x.mjs} +1 -1
  409. package/dist/{components-BPxrRjpE.mjs.map → components-CQy3lh9x.mjs.map} +1 -1
  410. package/dist/{config-DyF3OKg_.mjs → config-C3EBstHi.mjs} +18 -2
  411. package/dist/config-C3EBstHi.mjs.map +1 -0
  412. package/dist/config-COQzTe5Q.d.mts +34 -0
  413. package/dist/config-COQzTe5Q.d.mts.map +1 -0
  414. package/dist/{content-CJ94NEx5.mjs → content-ZHCc1ngN.mjs} +509 -78
  415. package/dist/content-ZHCc1ngN.mjs.map +1 -0
  416. package/dist/content-list-query-wJ2WN8Vp.d.mts +26 -0
  417. package/dist/content-list-query-wJ2WN8Vp.d.mts.map +1 -0
  418. package/dist/content-refresh-B_8SJzuU.mjs +2560 -0
  419. package/dist/content-refresh-B_8SJzuU.mjs.map +1 -0
  420. package/dist/{context-C_1nrqnW.mjs → context-ZldbZcle.mjs} +25 -17
  421. package/dist/context-ZldbZcle.mjs.map +1 -0
  422. package/dist/{cron-DRV-UC4K.mjs → cron-Y9aLtgrA.mjs} +1 -1
  423. package/dist/{cron-DRV-UC4K.mjs.map → cron-Y9aLtgrA.mjs.map} +1 -1
  424. package/dist/{dashboard-DINnNVVU.mjs → dashboard-DvHbk_cv.mjs} +44 -10
  425. package/dist/dashboard-DvHbk_cv.mjs.map +1 -0
  426. package/dist/db/index.d.mts +4 -4
  427. package/dist/db/index.mjs +31 -8
  428. package/dist/db/index.mjs.map +1 -1
  429. package/dist/db/libsql-migrations.d.mts +11 -0
  430. package/dist/db/libsql-migrations.d.mts.map +1 -0
  431. package/dist/db/libsql-migrations.mjs +57 -0
  432. package/dist/db/libsql-migrations.mjs.map +1 -0
  433. package/dist/db/libsql.d.mts +1 -1
  434. package/dist/db/postgres-migrations.d.mts +10 -0
  435. package/dist/db/postgres-migrations.d.mts.map +1 -0
  436. package/dist/db/postgres-migrations.mjs +47 -0
  437. package/dist/db/postgres-migrations.mjs.map +1 -0
  438. package/dist/db/postgres.d.mts +1 -1
  439. package/dist/db/sqlite-migrations.d.mts +10 -0
  440. package/dist/db/sqlite-migrations.d.mts.map +1 -0
  441. package/dist/db/sqlite-migrations.mjs +28 -0
  442. package/dist/db/sqlite-migrations.mjs.map +1 -0
  443. package/dist/db/sqlite.d.mts +1 -1
  444. package/dist/{db-errors-CcWLaRiR.mjs → db-errors-Cl-sKYTm.mjs} +1 -1
  445. package/dist/{db-errors-CcWLaRiR.mjs.map → db-errors-Cl-sKYTm.mjs.map} +1 -1
  446. package/dist/{default-BD2FG0xV.mjs → default-DdDl3fxv.mjs} +1 -1
  447. package/dist/{default-BD2FG0xV.mjs.map → default-DdDl3fxv.mjs.map} +1 -1
  448. package/dist/{deferred-tasks-C-WRCcKo.d.mts → deferred-tasks-SDWxrgzJ.d.mts} +1 -1
  449. package/dist/{deferred-tasks-C-WRCcKo.d.mts.map → deferred-tasks-SDWxrgzJ.d.mts.map} +1 -1
  450. package/dist/{device-flow-CTqd8mud.mjs → device-flow-C0GdD_z8.mjs} +4 -4
  451. package/dist/{device-flow-CTqd8mud.mjs.map → device-flow-C0GdD_z8.mjs.map} +1 -1
  452. package/dist/direct-executor-CDXeJCSs.mjs +85 -0
  453. package/dist/direct-executor-CDXeJCSs.mjs.map +1 -0
  454. package/dist/dist-D_6CKR8z.mjs +810 -0
  455. package/dist/dist-D_6CKR8z.mjs.map +1 -0
  456. package/dist/{email-console-C6WdcWbL.mjs → email-console-BHNjIwiB.mjs} +1 -1
  457. package/dist/{email-console-C6WdcWbL.mjs.map → email-console-BHNjIwiB.mjs.map} +1 -1
  458. package/dist/{enrich-CFJJgxs_.mjs → enrich-_ySMEvEE.mjs} +2 -2
  459. package/dist/{enrich-CFJJgxs_.mjs.map → enrich-_ySMEvEE.mjs.map} +1 -1
  460. package/dist/{error-oh_9i6bR.mjs → error-DupyJZE2.mjs} +3 -3
  461. package/dist/{error-oh_9i6bR.mjs.map → error-DupyJZE2.mjs.map} +1 -1
  462. package/dist/{errors-BucQ8VYz.mjs → errors-CLUPm7aD.mjs} +14 -2
  463. package/dist/errors-CLUPm7aD.mjs.map +1 -0
  464. package/dist/{escape-CXps5F_v.mjs → escape-DUY2r2Zs.mjs} +1 -1
  465. package/dist/{escape-CXps5F_v.mjs.map → escape-DUY2r2Zs.mjs.map} +1 -1
  466. package/dist/{field-defs-cache-WD82dMQq.mjs → field-defs-cache-BzwBlJrR.mjs} +4 -4
  467. package/dist/{field-defs-cache-WD82dMQq.mjs.map → field-defs-cache-BzwBlJrR.mjs.map} +1 -1
  468. package/dist/{fts-manager-BITakW_R.mjs → fts-manager-DyZEohZC.mjs} +76 -50
  469. package/dist/fts-manager-DyZEohZC.mjs.map +1 -0
  470. package/dist/{hreflang-BdZuVBhL.mjs → hreflang-BBe83kKa.mjs} +7 -7
  471. package/dist/{hreflang-BdZuVBhL.mjs.map → hreflang-BBe83kKa.mjs.map} +1 -1
  472. package/dist/{hreflang-BaLCNcDx.d.mts → hreflang-DwT2E0Sa.d.mts} +2 -2
  473. package/dist/{hreflang-BaLCNcDx.d.mts.map → hreflang-DwT2E0Sa.d.mts.map} +1 -1
  474. package/dist/identity-Ys6Dlc9C.mjs +35 -0
  475. package/dist/identity-Ys6Dlc9C.mjs.map +1 -0
  476. package/dist/{import-C-9uqyT3.mjs → import-DPkLmeXO.mjs} +5 -5
  477. package/dist/{import-C-9uqyT3.mjs.map → import-DPkLmeXO.mjs.map} +1 -1
  478. package/dist/{index-M37iz29I.d.mts → index-BVBZj4-7.d.mts} +236 -104
  479. package/dist/index-BVBZj4-7.d.mts.map +1 -0
  480. package/dist/{index-MGw47uWq.d.mts → index-C9KuQyO-.d.mts} +5 -10
  481. package/dist/index-C9KuQyO-.d.mts.map +1 -0
  482. package/dist/index.d.mts +21 -19
  483. package/dist/index.mjs +73 -67
  484. package/dist/{init-lock-DJkX6Hto.mjs → init-lock-6b309ZrF.mjs} +1 -1
  485. package/dist/{init-lock-DJkX6Hto.mjs.map → init-lock-6b309ZrF.mjs.map} +1 -1
  486. package/dist/{load-DV1DZuUJ.mjs → load-YJ2xl3ra.mjs} +2 -2
  487. package/dist/{load-DV1DZuUJ.mjs.map → load-YJ2xl3ra.mjs.map} +1 -1
  488. package/dist/{loader-CGugY7Zl.mjs → loader-CdG_Ci3H.mjs} +95 -53
  489. package/dist/loader-CdG_Ci3H.mjs.map +1 -0
  490. package/dist/manifest-builder-B252yQUf.mjs +189 -0
  491. package/dist/manifest-builder-B252yQUf.mjs.map +1 -0
  492. package/dist/{manifest-schema-Da7kj23y.mjs → manifest-schema-BXbUAHod.mjs} +1 -1
  493. package/dist/{manifest-schema-Da7kj23y.mjs.map → manifest-schema-BXbUAHod.mjs.map} +1 -1
  494. package/dist/media/image-endpoint.mjs +1 -1
  495. package/dist/media/index.d.mts +1 -1
  496. package/dist/media/index.mjs +3 -2
  497. package/dist/media/index.mjs.map +1 -1
  498. package/dist/media/local-runtime.d.mts +12 -12
  499. package/dist/media/local-runtime.mjs +6 -5
  500. package/dist/media/local-runtime.mjs.map +1 -1
  501. package/dist/{media-OhYL-7Io.mjs → media-BWWWb8kg.mjs} +92 -3
  502. package/dist/media-BWWWb8kg.mjs.map +1 -0
  503. package/dist/{media-BP7S-nHT.mjs → media-CzhAn2--.mjs} +2 -2
  504. package/dist/{media-BP7S-nHT.mjs.map → media-CzhAn2--.mjs.map} +1 -1
  505. package/dist/{media-allowlist-D-peH1H5.mjs → media-allowlist-D6x-Us02.mjs} +14 -3
  506. package/dist/media-allowlist-D6x-Us02.mjs.map +1 -0
  507. package/dist/{media-upload-DtrwU2B0.mjs → media-upload-CHBVn6m-.mjs} +10 -8
  508. package/dist/{media-upload-DtrwU2B0.mjs.map → media-upload-CHBVn6m-.mjs.map} +1 -1
  509. package/dist/{media-url-DYs_YLOx.mjs → media-url-BvoX88FA.mjs} +1 -1
  510. package/dist/{media-url-DYs_YLOx.mjs.map → media-url-BvoX88FA.mjs.map} +1 -1
  511. package/dist/{media-usage-BlxfTkN0.mjs → media-usage-BZCydfvu.mjs} +137 -60
  512. package/dist/media-usage-BZCydfvu.mjs.map +1 -0
  513. package/dist/media-usage-work-CLo_6tct.mjs +152 -0
  514. package/dist/media-usage-work-CLo_6tct.mjs.map +1 -0
  515. package/dist/media-usage-work-DrCbqBcl.mjs +424 -0
  516. package/dist/media-usage-work-DrCbqBcl.mjs.map +1 -0
  517. package/dist/media-usage-write-fence-aHEgN1zB.mjs +42 -0
  518. package/dist/media-usage-write-fence-aHEgN1zB.mjs.map +1 -0
  519. package/dist/{menus-Y54RDPIN.mjs → menus-DSo5QeW0.mjs} +351 -95
  520. package/dist/menus-DSo5QeW0.mjs.map +1 -0
  521. package/dist/{menus-BcQWxeXu.mjs → menus-TCNSd2vp.mjs} +3 -3
  522. package/dist/{menus-BcQWxeXu.mjs.map → menus-TCNSd2vp.mjs.map} +1 -1
  523. package/dist/migrations/index.d.mts +22 -0
  524. package/dist/migrations/index.d.mts.map +1 -0
  525. package/dist/migrations/index.mjs +7 -0
  526. package/dist/{mode-BWyTBe3I.mjs → mode-BDoH_WcF.mjs} +1 -1
  527. package/dist/{mode-BWyTBe3I.mjs.map → mode-BDoH_WcF.mjs.map} +1 -1
  528. package/dist/{normalize-C-SHXmra.mjs → normalize-Bc-s_r-a.mjs} +1 -1
  529. package/dist/{normalize-C-SHXmra.mjs.map → normalize-Bc-s_r-a.mjs.map} +1 -1
  530. package/dist/{oauth-authorization-ClvktmrL.mjs → oauth-authorization-iOikmrJd.mjs} +4 -4
  531. package/dist/{oauth-authorization-ClvktmrL.mjs.map → oauth-authorization-iOikmrJd.mjs.map} +1 -1
  532. package/dist/{oauth-clients-8ao-U66l.mjs → oauth-clients-CvI0nHMJ.mjs} +1 -1
  533. package/dist/{oauth-clients-8ao-U66l.mjs.map → oauth-clients-CvI0nHMJ.mjs.map} +1 -1
  534. package/dist/{oauth-state-store-B1ofdTiQ.mjs → oauth-state-store-Ba8KZlwW.mjs} +1 -1
  535. package/dist/{oauth-state-store-B1ofdTiQ.mjs.map → oauth-state-store-Ba8KZlwW.mjs.map} +1 -1
  536. package/dist/{oauth-user-lookup-CscEuIiR.mjs → oauth-user-lookup-C5SQwGYC.mjs} +1 -1
  537. package/dist/{oauth-user-lookup-CscEuIiR.mjs.map → oauth-user-lookup-C5SQwGYC.mjs.map} +1 -1
  538. package/dist/object-cache/memory.d.mts +1 -1
  539. package/dist/{options-CA4eVX6P.d.mts → options--hhz-jZ1.d.mts} +4 -3
  540. package/dist/options--hhz-jZ1.d.mts.map +1 -0
  541. package/dist/page/index.d.mts +2 -2
  542. package/dist/{parse-CJKNuewM.mjs → parse-DFbuc-Fh.mjs} +2 -2
  543. package/dist/{parse-CJKNuewM.mjs.map → parse-DFbuc-Fh.mjs.map} +1 -1
  544. package/dist/{passkey-config-D-zrzMJI.mjs → passkey-config-DFAmUyuE.mjs} +1 -1
  545. package/dist/{passkey-config-D-zrzMJI.mjs.map → passkey-config-DFAmUyuE.mjs.map} +1 -1
  546. package/dist/{placeholder-DaeNS-VG.d.mts → placeholder-Dp0K3RkD.d.mts} +1 -1
  547. package/dist/{placeholder-DaeNS-VG.d.mts.map → placeholder-Dp0K3RkD.d.mts.map} +1 -1
  548. package/dist/plugin-types.d.mts +8 -1
  549. package/dist/plugin-types.d.mts.map +1 -1
  550. package/dist/plugin-utils.d.mts +10 -10
  551. package/dist/plugins/adapt-sandbox-entry.d.mts +10 -10
  552. package/dist/plugins/adapt-sandbox-entry.mjs +7 -4
  553. package/dist/plugins/adapt-sandbox-entry.mjs.map +1 -1
  554. package/dist/policy-TluUIxuu.mjs +45 -0
  555. package/dist/policy-TluUIxuu.mjs.map +1 -0
  556. package/dist/{portable-text-B_kqBmXB.mjs → portable-text-imBW5cHK.mjs} +1 -1
  557. package/dist/{portable-text-B_kqBmXB.mjs.map → portable-text-imBW5cHK.mjs.map} +1 -1
  558. package/dist/{preview-BU6PaLpM.mjs → preview-PW-nOnq4.mjs} +2 -2
  559. package/dist/{preview-BU6PaLpM.mjs.map → preview-PW-nOnq4.mjs.map} +1 -1
  560. package/dist/protocol-DjsJHTlK.d.mts +52 -0
  561. package/dist/protocol-DjsJHTlK.d.mts.map +1 -0
  562. package/dist/{public-url-Ox9oOlgp.mjs → public-url-CWoFhQT8.mjs} +1 -1
  563. package/dist/{public-url-Ox9oOlgp.mjs.map → public-url-CWoFhQT8.mjs.map} +1 -1
  564. package/dist/{query-rC9HKv1N.mjs → query-BWs7O5Il.mjs} +3 -3
  565. package/dist/{query-rC9HKv1N.mjs.map → query-BWs7O5Il.mjs.map} +1 -1
  566. package/dist/{query-C5w7PsRQ.mjs → query-zTVAR1Sl.mjs} +31 -49
  567. package/dist/query-zTVAR1Sl.mjs.map +1 -0
  568. package/dist/{rate-limit-kug6q99V.mjs → rate-limit-Bx4g9m3p.mjs} +2 -2
  569. package/dist/{rate-limit-kug6q99V.mjs.map → rate-limit-Bx4g9m3p.mjs.map} +1 -1
  570. package/dist/{redirect-Egf2R9yP.mjs → redirect-BgAOGHDq.mjs} +1 -1
  571. package/dist/{redirect-Egf2R9yP.mjs.map → redirect-BgAOGHDq.mjs.map} +1 -1
  572. package/dist/{redirect-DIJxXKOG.mjs → redirect-COsS6SWJ.mjs} +2 -2
  573. package/dist/{redirect-DIJxXKOG.mjs.map → redirect-COsS6SWJ.mjs.map} +1 -1
  574. package/dist/{redirects-G8wAhWAf.mjs → redirects-DTDHWH31.mjs} +133 -14
  575. package/dist/redirects-DTDHWH31.mjs.map +1 -0
  576. package/dist/{redirects-Bzm812bY.mjs → redirects-DyChwDkG.mjs} +4 -4
  577. package/dist/{redirects-Bzm812bY.mjs.map → redirects-DyChwDkG.mjs.map} +1 -1
  578. package/dist/registry-Cqa2I749.mjs +1275 -0
  579. package/dist/registry-Cqa2I749.mjs.map +1 -0
  580. package/dist/{relation-Cbe3Sd3m.mjs → relation-BnHB0T4J.mjs} +3 -3
  581. package/dist/{relation-Cbe3Sd3m.mjs.map → relation-BnHB0T4J.mjs.map} +1 -1
  582. package/dist/{relations-Bw_E1TXo.mjs → relations-BBApI4e2.mjs} +3 -3
  583. package/dist/{relations-Bw_E1TXo.mjs.map → relations-BBApI4e2.mjs.map} +1 -1
  584. package/dist/{relations-G2ta7GIl.d.mts → relations-BHo5A8Zf.d.mts} +367 -33
  585. package/dist/relations-BHo5A8Zf.d.mts.map +1 -0
  586. package/dist/{relations-qHwpUe66.mjs → relations-D5sM5fW0.mjs} +6 -6
  587. package/dist/{relations-qHwpUe66.mjs.map → relations-D5sM5fW0.mjs.map} +1 -1
  588. package/dist/request-context.d.mts +1 -1
  589. package/dist/{request-meta-Df-jFbAd.mjs → request-meta-DgZJh3zG.mjs} +2 -2
  590. package/dist/{request-meta-Df-jFbAd.mjs.map → request-meta-DgZJh3zG.mjs.map} +1 -1
  591. package/dist/{resolve-DZzG4HqM.mjs → resolve-DOhVEvty.mjs} +2 -2
  592. package/dist/{resolve-DZzG4HqM.mjs.map → resolve-DOhVEvty.mjs.map} +1 -1
  593. package/dist/{runner-BaADli8l.d.mts → runner-BYHZn3Jy.d.mts} +16 -3
  594. package/dist/runner-BYHZn3Jy.d.mts.map +1 -0
  595. package/dist/{runner-BFTrkYhu.mjs → runner-C1T11CfC.mjs} +1190 -257
  596. package/dist/runner-C1T11CfC.mjs.map +1 -0
  597. package/dist/runtime.d.mts +11 -11
  598. package/dist/runtime.mjs +4 -3
  599. package/dist/runtime.mjs.map +1 -1
  600. package/dist/schema-2AOsSn2v.mjs +390 -0
  601. package/dist/schema-2AOsSn2v.mjs.map +1 -0
  602. package/dist/{schema-CiQXr6_F.mjs → schema-DZ5YVVZj.mjs} +3 -3
  603. package/dist/{schema-CiQXr6_F.mjs.map → schema-DZ5YVVZj.mjs.map} +1 -1
  604. package/dist/{scopes-CNJVT5i5.mjs → scopes-8ClPF2bC.mjs} +3 -3
  605. package/dist/{scopes-CNJVT5i5.mjs.map → scopes-8ClPF2bC.mjs.map} +1 -1
  606. package/dist/{search-FZhx5dDU.mjs → search-u1QYdOCG.mjs} +25 -15
  607. package/dist/search-u1QYdOCG.mjs.map +1 -0
  608. package/dist/{secrets-DLd8RXee.mjs → secrets-BEgsAQEU.mjs} +3 -3
  609. package/dist/{secrets-DLd8RXee.mjs.map → secrets-BEgsAQEU.mjs.map} +1 -1
  610. package/dist/{sections-BrIrMUCn.mjs → sections-DmHviGyM.mjs} +3 -3
  611. package/dist/{sections-BrIrMUCn.mjs.map → sections-DmHviGyM.mjs.map} +1 -1
  612. package/dist/seed/index.d.mts +2 -2
  613. package/dist/seed/index.mjs +24 -22
  614. package/dist/seo/index.d.mts +3 -3
  615. package/dist/seo/index.mjs +16 -15
  616. package/dist/seo/index.mjs.map +1 -1
  617. package/dist/{seo-CobNfOvb.mjs → seo-AFpVvTqr.mjs} +5 -3
  618. package/dist/seo-AFpVvTqr.mjs.map +1 -0
  619. package/dist/{seo-DTHRntNC.mjs → seo-Dq4G-RrO.mjs} +2 -2
  620. package/dist/{seo-DTHRntNC.mjs.map → seo-Dq4G-RrO.mjs.map} +1 -1
  621. package/dist/{service-B-pYGPgR.mjs → service-BpArayPr.mjs} +3 -3
  622. package/dist/{service-B-pYGPgR.mjs.map → service-BpArayPr.mjs.map} +1 -1
  623. package/dist/{session-user-BvM9-zNl.mjs → session-user-BEorKVT-.mjs} +1 -1
  624. package/dist/{session-user-BvM9-zNl.mjs.map → session-user-BEorKVT-.mjs.map} +1 -1
  625. package/dist/{settings-DPHau-WH.mjs → settings-DE9xtzqd.mjs} +3 -3
  626. package/dist/{settings-DPHau-WH.mjs.map → settings-DE9xtzqd.mjs.map} +1 -1
  627. package/dist/{settings-kJhGiQ4z.mjs → settings-xRdoUZr0.mjs} +4 -4
  628. package/dist/{settings-kJhGiQ4z.mjs.map → settings-xRdoUZr0.mjs.map} +1 -1
  629. package/dist/{setup-complete-u50Qm8rY.mjs → setup-complete-BnT8pq_C.mjs} +1 -1
  630. package/dist/{setup-complete-u50Qm8rY.mjs.map → setup-complete-BnT8pq_C.mjs.map} +1 -1
  631. package/dist/{setup-nonce-DCjiiOD2.mjs → setup-nonce-CBitf_oQ.mjs} +1 -1
  632. package/dist/{setup-nonce-DCjiiOD2.mjs.map → setup-nonce-CBitf_oQ.mjs.map} +1 -1
  633. package/dist/{single-flight-cache-DW3w11Pu.mjs → single-flight-cache-B0eLKS6K.mjs} +2 -2
  634. package/dist/{single-flight-cache-DW3w11Pu.mjs.map → single-flight-cache-B0eLKS6K.mjs.map} +1 -1
  635. package/dist/{site-url-I-lJ5kma.mjs → site-url-DjpIXMXJ.mjs} +2 -2
  636. package/dist/{site-url-I-lJ5kma.mjs.map → site-url-DjpIXMXJ.mjs.map} +1 -1
  637. package/dist/slugify-B994zkXC.mjs +17 -0
  638. package/dist/slugify-B994zkXC.mjs.map +1 -0
  639. package/dist/{snapshot-I_fjLDaD.mjs → snapshot-BBlGkb2q.mjs} +1 -1
  640. package/dist/{snapshot-I_fjLDaD.mjs.map → snapshot-BBlGkb2q.mjs.map} +1 -1
  641. package/dist/{ssrf-CTa6v21i.mjs → ssrf-Cpvg_n3A.mjs} +1 -1
  642. package/dist/{ssrf-CTa6v21i.mjs.map → ssrf-Cpvg_n3A.mjs.map} +1 -1
  643. package/dist/{state-CQvoefYP.mjs → state-DYwPue40.mjs} +1 -1
  644. package/dist/{state-CQvoefYP.mjs.map → state-DYwPue40.mjs.map} +1 -1
  645. package/dist/{status-CIsmlC1E.mjs → status-CWVYpbD8.mjs} +1 -1
  646. package/dist/{status-CIsmlC1E.mjs.map → status-CWVYpbD8.mjs.map} +1 -1
  647. package/dist/storage/local.d.mts +1 -1
  648. package/dist/storage/local.mjs +3 -3
  649. package/dist/storage/s3.d.mts +1 -1
  650. package/dist/storage/s3.mjs +1 -1
  651. package/dist/target-DixqqV5i.mjs +27 -0
  652. package/dist/target-DixqqV5i.mjs.map +1 -0
  653. package/dist/{taxonomies-CLN1N92E.mjs → taxonomies-BlrncHi9.mjs} +75 -64
  654. package/dist/taxonomies-BlrncHi9.mjs.map +1 -0
  655. package/dist/{taxonomies-CKuaZER5.mjs → taxonomies-OHUIiIpI.mjs} +280 -56
  656. package/dist/taxonomies-OHUIiIpI.mjs.map +1 -0
  657. package/dist/{taxonomy-pOrB2kZe.mjs → taxonomy-BqCZ1TdU.mjs} +131 -78
  658. package/dist/taxonomy-BqCZ1TdU.mjs.map +1 -0
  659. package/dist/{tokens-DagaJGK8.mjs → tokens-C39klX8R.mjs} +2 -2
  660. package/dist/{tokens-DagaJGK8.mjs.map → tokens-C39klX8R.mjs.map} +1 -1
  661. package/dist/{transport-DVsa5YYo.mjs → transport-DBJwa-Si.mjs} +1 -1
  662. package/dist/{transport-DVsa5YYo.mjs.map → transport-DBJwa-Si.mjs.map} +1 -1
  663. package/dist/{transport-CAwTaTp_.d.mts → transport-RQE36APG.d.mts} +1 -1
  664. package/dist/{transport-CAwTaTp_.d.mts.map → transport-RQE36APG.d.mts.map} +1 -1
  665. package/dist/{trusted-proxy-D20_7fyX.mjs → trusted-proxy-CEVekpby.mjs} +1 -1
  666. package/dist/{trusted-proxy-D20_7fyX.mjs.map → trusted-proxy-CEVekpby.mjs.map} +1 -1
  667. package/dist/{types-NBI3rF-_.mjs → types-75KIqzL9.mjs} +18 -2
  668. package/dist/types-75KIqzL9.mjs.map +1 -0
  669. package/dist/{types-BjxTKxrZ.mjs → types-BW1syrlw.mjs} +1 -1
  670. package/dist/{types-BjxTKxrZ.mjs.map → types-BW1syrlw.mjs.map} +1 -1
  671. package/dist/{types-DLG4IFEQ.d.mts → types-BcqdcT-r.d.mts} +1 -1
  672. package/dist/{types-DLG4IFEQ.d.mts.map → types-BcqdcT-r.d.mts.map} +1 -1
  673. package/dist/{types-LoagAGzH.d.mts → types-BntycPTF.d.mts} +1 -1
  674. package/dist/{types-LoagAGzH.d.mts.map → types-BntycPTF.d.mts.map} +1 -1
  675. package/dist/{types-BnFP1M3J.d.mts → types-C2pMvO62.d.mts} +32 -10
  676. package/dist/types-C2pMvO62.d.mts.map +1 -0
  677. package/dist/{types-Cd8iuS1J.mjs → types-CQPWhPxE.mjs} +9 -12
  678. package/dist/types-CQPWhPxE.mjs.map +1 -0
  679. package/dist/{types-C8oz_ayJ.d.mts → types-CXnOzDe1.d.mts} +1 -1
  680. package/dist/{types-C8oz_ayJ.d.mts.map → types-CXnOzDe1.d.mts.map} +1 -1
  681. package/dist/types-CtzytVXn.mjs.map +1 -1
  682. package/dist/{types-BGWPMiBO.d.mts → types-DN64_zzZ.d.mts} +44 -5
  683. package/dist/types-DN64_zzZ.d.mts.map +1 -0
  684. package/dist/{types-Dc4ntQjQ.d.mts → types-DQIDRKF2.d.mts} +124 -1
  685. package/dist/types-DQIDRKF2.d.mts.map +1 -0
  686. package/dist/{types-CbUcuxxc.d.mts → types-DWRhk9xZ.d.mts} +1 -1
  687. package/dist/{types-CbUcuxxc.d.mts.map → types-DWRhk9xZ.d.mts.map} +1 -1
  688. package/dist/{types-BK6U01Ro.d.mts → types-Dfk8KI5R.d.mts} +1 -1
  689. package/dist/{types-BK6U01Ro.d.mts.map → types-Dfk8KI5R.d.mts.map} +1 -1
  690. package/dist/{types-Cz8hNch2.d.mts → types-DrJrVCT1.d.mts} +25 -5
  691. package/dist/types-DrJrVCT1.d.mts.map +1 -0
  692. package/dist/{upload-attempts-D8QAFLUJ.mjs → upload-attempts-D4FS8LT6.mjs} +1 -1
  693. package/dist/{upload-attempts-D8QAFLUJ.mjs.map → upload-attempts-D4FS8LT6.mjs.map} +1 -1
  694. package/dist/url-pattern-BHS0V5Ng.mjs +33 -0
  695. package/dist/url-pattern-BHS0V5Ng.mjs.map +1 -0
  696. package/dist/{user-DBrq4UVq.mjs → user-DJZfUJVE.mjs} +3 -3
  697. package/dist/{user-DBrq4UVq.mjs.map → user-DJZfUJVE.mjs.map} +1 -1
  698. package/dist/{utils-hLzi_2Fn.mjs → utils-D4vD_Y98.mjs} +3 -3
  699. package/dist/{utils-hLzi_2Fn.mjs.map → utils-D4vD_Y98.mjs.map} +1 -1
  700. package/dist/{validate-mKo3RxBM.mjs → validate-BMLBvxOC.mjs} +24 -5
  701. package/dist/validate-BMLBvxOC.mjs.map +1 -0
  702. package/dist/{validate-C3oSmA7F.d.mts → validate-CTqt5nuE.d.mts} +15 -7
  703. package/dist/validate-CTqt5nuE.d.mts.map +1 -0
  704. package/dist/{validation-BgpucsvF.mjs → validation-npvENUCB.mjs} +11 -10
  705. package/dist/{validation-BgpucsvF.mjs.map → validation-npvENUCB.mjs.map} +1 -1
  706. package/dist/version-DB_fqCSI.mjs +7 -0
  707. package/dist/{version-C4PnpmoV.mjs.map → version-DB_fqCSI.mjs.map} +1 -1
  708. package/dist/{widgets-CJJtkiKh.mjs → widgets-BD3ho7Rq.mjs} +3 -3
  709. package/dist/{widgets-CJJtkiKh.mjs.map → widgets-BD3ho7Rq.mjs.map} +1 -1
  710. package/dist/{wxr-taxonomies-9PPSy8X6.mjs → wxr-taxonomies-B1R3vBoD.mjs} +13 -32
  711. package/dist/{wxr-taxonomies-9PPSy8X6.mjs.map → wxr-taxonomies-B1R3vBoD.mjs.map} +1 -1
  712. package/dist/{wxr-taxonomies-Bkpp_2tK.d.mts → wxr-taxonomies-Ca68766D.d.mts} +1 -1
  713. package/dist/{wxr-taxonomies-Bkpp_2tK.d.mts.map → wxr-taxonomies-Ca68766D.d.mts.map} +1 -1
  714. package/dist/{zod-generator-CG64Hnbh.mjs → zod-generator-LC-on_Vb.mjs} +52 -5
  715. package/dist/zod-generator-LC-on_Vb.mjs.map +1 -0
  716. package/package.json +32 -8
  717. package/src/api/errors.ts +12 -0
  718. package/src/api/handlers/content.ts +127 -29
  719. package/src/api/handlers/dashboard.ts +12 -2
  720. package/src/api/handlers/index.ts +16 -0
  721. package/src/api/handlers/manifest.ts +2 -0
  722. package/src/api/handlers/media-allowlist.ts +13 -2
  723. package/src/api/handlers/media-usage-work.ts +188 -0
  724. package/src/api/handlers/media-usage.ts +5 -3
  725. package/src/api/handlers/schema.ts +9 -3
  726. package/src/api/handlers/seo.ts +5 -2
  727. package/src/api/handlers/taxonomies.ts +345 -82
  728. package/src/api/media-usage-write-fence.ts +64 -0
  729. package/src/api/openapi/document.ts +199 -0
  730. package/src/api/schemas/common.ts +3 -1
  731. package/src/api/schemas/content.ts +122 -1
  732. package/src/api/schemas/media-usage.ts +133 -0
  733. package/src/api/schemas/schema.ts +78 -3
  734. package/src/api/schemas/taxonomies.ts +40 -8
  735. package/src/api/types.ts +1 -0
  736. package/src/astro/integration/index.ts +101 -56
  737. package/src/astro/integration/routes.ts +34 -4
  738. package/src/astro/integration/runtime.ts +18 -0
  739. package/src/astro/integration/virtual-modules.ts +25 -1
  740. package/src/astro/integration/vite-config.ts +16 -1
  741. package/src/astro/middleware/media-usage-write-fence.ts +30 -0
  742. package/src/astro/middleware/redirect.ts +12 -2
  743. package/src/astro/middleware/scoped-db.ts +21 -0
  744. package/src/astro/middleware.ts +140 -16
  745. package/src/astro/routes/api/admin/media-usage/collection-deletions/index.ts +22 -0
  746. package/src/astro/routes/api/admin/media-usage/collection-deletions/retry.ts +22 -0
  747. package/src/astro/routes/api/admin/media-usage/work/index.ts +26 -0
  748. package/src/astro/routes/api/admin/media-usage/work/retry.ts +26 -0
  749. package/src/astro/routes/api/admin/plugins/[id]/disable.ts +4 -0
  750. package/src/astro/routes/api/admin/plugins/[id]/enable.ts +4 -0
  751. package/src/astro/routes/api/admin/plugins/[id]/uninstall.ts +4 -0
  752. package/src/astro/routes/api/admin/plugins/[id]/update.ts +4 -0
  753. package/src/astro/routes/api/admin/plugins/marketplace/[id]/install.ts +4 -0
  754. package/src/astro/routes/api/admin/plugins/registry/[id]/uninstall.ts +4 -0
  755. package/src/astro/routes/api/admin/plugins/registry/[id]/update.ts +4 -0
  756. package/src/astro/routes/api/admin/plugins/registry/install.ts +4 -0
  757. package/src/astro/routes/api/auth/dev-bypass.ts +0 -4
  758. package/src/astro/routes/api/content/[collection]/[id]/terms/[taxonomy].ts +67 -31
  759. package/src/astro/routes/api/import/wordpress/execute.ts +3 -10
  760. package/src/astro/routes/api/mcp.ts +1 -0
  761. package/src/astro/routes/api/plugins/[pluginId]/[...path].ts +7 -1
  762. package/src/astro/routes/api/schema/collections/[slug]/index.ts +1 -7
  763. package/src/astro/routes/api/setup/dev-bypass.ts +2 -7
  764. package/src/astro/routes/api/setup/index.ts +5 -13
  765. package/src/astro/routes/api/taxonomies/[name]/terms/index.ts +1 -0
  766. package/src/astro/routes/api/taxonomies/[name]/translations.ts +48 -0
  767. package/src/astro/routes/api/taxonomies/[name].ts +102 -0
  768. package/src/astro/types.ts +25 -4
  769. package/src/cleanup.ts +6 -12
  770. package/src/cli/commands/doctor.ts +193 -6
  771. package/src/cli/commands/export-seed.ts +4 -1
  772. package/src/cli/commands/migrate.ts +593 -0
  773. package/src/cli/index.ts +2 -23
  774. package/src/client/index.ts +119 -0
  775. package/src/components/Block.astro +12 -0
  776. package/src/components/InlinePortableTextEditor.tsx +89 -1
  777. package/src/content/converters/mark-safety.ts +120 -0
  778. package/src/content/converters/portable-text-to-prosemirror.ts +25 -16
  779. package/src/content/converters/prosemirror-to-portable-text.ts +12 -2
  780. package/src/content-list-query.ts +29 -0
  781. package/src/database/index.ts +8 -2
  782. package/src/database/migrations/060_collection_admin_config.ts +16 -0
  783. package/src/database/migrations/061_media_usage_cleanup.ts +77 -0
  784. package/src/database/migrations/062_media_usage_cleanup_fence.ts +295 -0
  785. package/src/database/migrations/063_media_usage_incremental_work.ts +397 -0
  786. package/src/database/migrations/064_fts_plain_text.ts +253 -0
  787. package/src/database/migrations/065_media_usage_collection_deletion.ts +85 -0
  788. package/src/database/migrations/066_media_usage_reconciliation.ts +115 -0
  789. package/src/database/migrations/067_indexed_content_fields.ts +39 -0
  790. package/src/database/migrations/068_content_taxonomy_entry_groups.ts +61 -0
  791. package/src/database/migrations/069_collection_title_date_fields.ts +45 -0
  792. package/src/database/migrations/070_collection_routable.ts +18 -0
  793. package/src/database/migrations/policy.ts +70 -0
  794. package/src/database/migrations/runner.ts +71 -3
  795. package/src/database/repositories/content.ts +861 -96
  796. package/src/database/repositories/media-usage-work.ts +848 -0
  797. package/src/database/repositories/media-usage.ts +1502 -138
  798. package/src/database/repositories/revision.ts +17 -6
  799. package/src/database/repositories/taxonomy.ts +234 -103
  800. package/src/database/repositories/types.ts +51 -2
  801. package/src/database/types.ts +134 -16
  802. package/src/db/adapters.ts +78 -2
  803. package/src/db/index.ts +6 -1
  804. package/src/db/libsql-migrations.ts +72 -0
  805. package/src/db/postgres-migrations.ts +59 -0
  806. package/src/db/sqlite-migrations.ts +37 -0
  807. package/src/emdash-runtime.ts +271 -35
  808. package/src/fields/file.ts +7 -4
  809. package/src/fields/image.ts +8 -1
  810. package/src/fields/types.ts +18 -5
  811. package/src/i18n/config.ts +32 -0
  812. package/src/i18n/normalize.ts +31 -0
  813. package/src/i18n/repair-locale-casing.ts +0 -14
  814. package/src/i18n/taxonomy-locale-diagnostic.ts +47 -0
  815. package/src/import/wxr-taxonomies.ts +7 -47
  816. package/src/index.ts +32 -3
  817. package/src/loader.ts +119 -65
  818. package/src/mcp/server.ts +242 -34
  819. package/src/media/usage/activation.ts +626 -0
  820. package/src/media/usage/capture-triggers.ts +543 -0
  821. package/src/media/usage/cleanup.ts +305 -0
  822. package/src/media/usage/collection-deletion-processor.ts +356 -0
  823. package/src/media/usage/collection-deletion.ts +836 -0
  824. package/src/media/usage/content-fields.ts +40 -3
  825. package/src/media/usage/content-refresh.ts +356 -47
  826. package/src/media/usage/content-repair.ts +180 -61
  827. package/src/media/usage/content-snapshots.ts +85 -105
  828. package/src/media/usage/projection-fingerprint.ts +129 -0
  829. package/src/media/usage/reconciliation-processor.ts +372 -0
  830. package/src/media/usage/reconciliation.ts +1117 -0
  831. package/src/media/usage/source-key.ts +4 -0
  832. package/src/media/usage/types.ts +2 -0
  833. package/src/media/usage/work-processor.ts +248 -0
  834. package/src/menus/index.ts +246 -141
  835. package/src/migrations/config-loader.ts +205 -0
  836. package/src/migrations/direct-executor.ts +141 -0
  837. package/src/migrations/identity.ts +46 -0
  838. package/src/migrations/index.ts +19 -0
  839. package/src/migrations/integration-metadata.ts +67 -0
  840. package/src/migrations/manifest-builder.ts +55 -0
  841. package/src/migrations/manifest-writer.ts +63 -0
  842. package/src/migrations/manifest.ts +197 -0
  843. package/src/migrations/protocol.ts +59 -0
  844. package/src/migrations/target.ts +35 -0
  845. package/src/plugin-types.ts +8 -0
  846. package/src/plugins/adapt-sandbox-entry.ts +24 -5
  847. package/src/plugins/context.ts +24 -7
  848. package/src/plugins/index.ts +9 -0
  849. package/src/plugins/routes.ts +43 -1
  850. package/src/plugins/sandbox/index.ts +10 -1
  851. package/src/plugins/sandbox/types.ts +78 -1
  852. package/src/plugins/scheduler/node.ts +13 -1
  853. package/src/plugins/scheduler/types.ts +2 -0
  854. package/src/plugins/types.ts +39 -2
  855. package/src/query.ts +29 -37
  856. package/src/scheduler-health.ts +46 -0
  857. package/src/schema/registry.ts +777 -255
  858. package/src/schema/types.ts +50 -8
  859. package/src/schema/url-pattern.ts +33 -0
  860. package/src/schema/zod-generator.ts +77 -5
  861. package/src/search/fts-manager.ts +117 -76
  862. package/src/search/query.ts +32 -11
  863. package/src/search/types.ts +2 -0
  864. package/src/seed/apply.ts +68 -15
  865. package/src/seed/types.ts +11 -3
  866. package/src/seed/validate.ts +52 -2
  867. package/src/taxonomies/index.ts +77 -75
  868. package/src/taxonomies/term-counts.ts +21 -8
  869. package/src/utils/slugify.ts +1 -29
  870. package/src/virtual-modules.d.ts +24 -0
  871. package/dist/adapters-BMyNSSZi.d.mts.map +0 -1
  872. package/dist/api-D2hunekQ.mjs.map +0 -1
  873. package/dist/apply-kwNEJW2l.mjs.map +0 -1
  874. package/dist/config-DyF3OKg_.mjs.map +0 -1
  875. package/dist/content-CJ94NEx5.mjs.map +0 -1
  876. package/dist/content-refresh-Xw7aKmou.mjs +0 -1629
  877. package/dist/content-refresh-Xw7aKmou.mjs.map +0 -1
  878. package/dist/context-C_1nrqnW.mjs.map +0 -1
  879. package/dist/dashboard-DINnNVVU.mjs.map +0 -1
  880. package/dist/errors-BucQ8VYz.mjs.map +0 -1
  881. package/dist/fts-manager-BITakW_R.mjs.map +0 -1
  882. package/dist/index-M37iz29I.d.mts.map +0 -1
  883. package/dist/index-MGw47uWq.d.mts.map +0 -1
  884. package/dist/loader-CGugY7Zl.mjs.map +0 -1
  885. package/dist/media-OhYL-7Io.mjs.map +0 -1
  886. package/dist/media-allowlist-D-peH1H5.mjs.map +0 -1
  887. package/dist/media-usage-BlxfTkN0.mjs.map +0 -1
  888. package/dist/menus-Y54RDPIN.mjs.map +0 -1
  889. package/dist/options-CA4eVX6P.d.mts.map +0 -1
  890. package/dist/query-C5w7PsRQ.mjs.map +0 -1
  891. package/dist/redirects-G8wAhWAf.mjs.map +0 -1
  892. package/dist/registry-Dbodb4Uo.mjs +0 -840
  893. package/dist/registry-Dbodb4Uo.mjs.map +0 -1
  894. package/dist/relations-G2ta7GIl.d.mts.map +0 -1
  895. package/dist/runner-BFTrkYhu.mjs.map +0 -1
  896. package/dist/runner-BaADli8l.d.mts.map +0 -1
  897. package/dist/search-FZhx5dDU.mjs.map +0 -1
  898. package/dist/seo-CobNfOvb.mjs.map +0 -1
  899. package/dist/slugify-C_tqlU4G.mjs +0 -30
  900. package/dist/slugify-C_tqlU4G.mjs.map +0 -1
  901. package/dist/taxonomies-CKuaZER5.mjs.map +0 -1
  902. package/dist/taxonomies-CLN1N92E.mjs.map +0 -1
  903. package/dist/taxonomy-pOrB2kZe.mjs.map +0 -1
  904. package/dist/types-BGWPMiBO.d.mts.map +0 -1
  905. package/dist/types-BnFP1M3J.d.mts.map +0 -1
  906. package/dist/types-Cd8iuS1J.mjs.map +0 -1
  907. package/dist/types-Cz8hNch2.d.mts.map +0 -1
  908. package/dist/types-Dc4ntQjQ.d.mts.map +0 -1
  909. package/dist/types-NBI3rF-_.mjs.map +0 -1
  910. package/dist/validate-C3oSmA7F.d.mts.map +0 -1
  911. package/dist/validate-mKo3RxBM.mjs.map +0 -1
  912. package/dist/version-C4PnpmoV.mjs +0 -7
  913. package/dist/zod-generator-CG64Hnbh.mjs.map +0 -1
  914. /package/dist/{api-tokens-Dai9dND0.mjs → api-tokens-rIXC6LdE.mjs} +0 -0
  915. /package/dist/{ssrf-Cj568Dgs.mjs → ssrf-DpXgKsna.mjs} +0 -0
  916. /package/dist/{types-DKuWPYV5.mjs → types-CP1CflWf.mjs} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"file":"runner-BaADli8l.d.mts","names":[],"sources":["../src/database/migrations/runner.ts"],"mappings":";;;;UA2IiB,eAAA;EAChB,OAAA;EACA,OAAA;AAAA;AAAA,UAyBgB,gBAAA;EAChB,oBAAA;EAyBE;;;;;EAnBF,UAAA;AAAA;;;;iBAgBqB,kBAAA,CACrB,EAAA,EAAI,MAAA,CAAO,QAAA,GACX,OAAA,GAAU,gBAAA,GACR,OAAA,CAAQ,eAAA;;;;;;;;;;;;;AAoOX;;;;;;;;iBA7DsB,aAAA,CACrB,EAAA,EAAI,MAAA,CAAO,QAAA,GACX,OAAA,GAAU,gBAAA,GACR,OAAA;EAAU,OAAA;AAAA;;;;iBA0DS,iBAAA,CACrB,EAAA,EAAI,MAAA,CAAO,QAAA,GACX,OAAA,GAAU,gBAAA,GACR,OAAA;EAAU,UAAA;AAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"search-FZhx5dDU.mjs","names":[],"sources":["../src/search/query.ts","../src/search/text-extraction.ts","../src/search/index.ts"],"sourcesContent":["/**\n * Search Query Functions\n *\n * Programmatic API for searching content using FTS5.\n */\n\nimport type { Kysely } from \"kysely\";\nimport { sql } from \"kysely\";\n\nimport { encodeCursor, decodeCursor, InvalidCursorError } from \"../database/repositories/types.js\";\nimport type { Database } from \"../database/types.js\";\nimport { validateIdentifier } from \"../database/validate.js\";\nimport { resolveConfiguredLocale } from \"../i18n/config.js\";\nimport { getDb } from \"../loader.js\";\nimport { FTSManager } from \"./fts-manager.js\";\nimport type {\n\tSearchOptions,\n\tCollectionSearchOptions,\n\tSearchResult,\n\tSearchResponse,\n\tSuggestOptions,\n\tSuggestion,\n\tSearchStats,\n} from \"./types.js\";\n\n/**\n * Marker stored in the `id` slot of a search pagination cursor.\n *\n * Search results are merged from per-collection FTS queries and re-sorted by\n * score, so there is no single stable keyset column to encode (the way\n * `getEmDashCollection` encodes `(orderValue, id)`). We page over the merged,\n * score-sorted set by offset instead, carried as the cursor's `orderValue`.\n * Reusing `encodeCursor`/`decodeCursor` keeps the opaque base64-JSON shape and\n * the `InvalidCursorError` handling consistent with the rest of the API.\n */\nconst SEARCH_CURSOR_MARKER = \"search\";\n\n/** Encode the next-page offset into an opaque search cursor. */\nfunction encodeSearchCursor(offset: number): string {\n\treturn encodeCursor(String(offset), SEARCH_CURSOR_MARKER);\n}\n\n/**\n * Decode a search cursor back to its offset. Throws `InvalidCursorError` for a\n * malformed cursor or one that doesn't carry a non-negative integer offset, so\n * a client pagination bug surfaces immediately rather than silently restarting\n * from the first page.\n */\n/** Upper bound on a decoded search offset, to cap the per-collection row fetch a forged cursor can trigger. */\nconst MAX_SEARCH_OFFSET = 10_000;\n\nfunction decodeSearchOffset(cursor: string): number {\n\tconst { orderValue, id } = decodeCursor(cursor);\n\tif (id !== SEARCH_CURSOR_MARKER) {\n\t\tthrow new InvalidCursorError(cursor);\n\t}\n\tconst offset = Number(orderValue);\n\tif (!Number.isInteger(offset) || offset < 0 || offset > MAX_SEARCH_OFFSET) {\n\t\tthrow new InvalidCursorError(cursor);\n\t}\n\treturn offset;\n}\n\n/** Pattern to split on whitespace for query term extraction */\nconst WHITESPACE_SPLIT_PATTERN = /\\s+/;\nconst FTS_OPERATORS_PATTERN = /\\b(AND|OR|NOT|NEAR)\\b/i;\nconst DOUBLE_QUOTE_PATTERN = /\"/g;\n\n/**\n * Detect FTS5 query syntax errors. Match specifically on the SQLite FTS5\n * error fingerprints rather than a broad \"fts5\" / \"syntax error\" filter\n * (which would also swallow internal table-corruption errors). The two\n * fingerprints we care about are:\n *\n * - \"fts5: syntax error near …\" — unbalanced quotes, stray operators,\n * other malformed user input\n * - \"unknown special query: …\" — bare special tokens like `^*` that\n * parse but don't resolve to a real FTS5 directive\n */\nfunction isFts5SyntaxError(error: unknown): boolean {\n\tif (!(error instanceof Error)) return false;\n\tconst message = error.message.toLowerCase();\n\treturn message.includes(\"fts5: syntax error\") || message.includes(\"unknown special query\");\n}\n\n/**\n * Search across multiple collections\n *\n * Public API that auto-injects the database.\n *\n * @param query - Search query (FTS5 syntax supported)\n * @param options - Search options\n * @returns Search results with pagination\n *\n * @example\n * ```typescript\n * import { search } from \"emdash\";\n *\n * const results = await search(\"hello world\", {\n * collections: [\"posts\", \"pages\"],\n * limit: 20\n * });\n * ```\n */\nexport async function search(query: string, options: SearchOptions = {}): Promise<SearchResponse> {\n\tconst db = await getDb();\n\treturn searchWithDb(db, query, options);\n}\n\n/**\n * Search across multiple collections (with explicit db)\n *\n * @internal Use `search()` in templates. This variant is for admin routes\n * that already have a database handle.\n *\n * @param db - Kysely database instance\n * @param query - Search query (FTS5 syntax supported)\n * @param options - Search options\n * @returns Search results with pagination\n */\nexport async function searchWithDb(\n\tdb: Kysely<Database>,\n\tquery: string,\n\toptions: SearchOptions = {},\n): Promise<SearchResponse> {\n\tconst ftsManager = new FTSManager(db);\n\tconst limit = options.limit ?? 20;\n\tconst status = options.status ?? \"published\";\n\tconst offset = options.cursor ? decodeSearchOffset(options.cursor) : 0;\n\n\t// Get searchable collections\n\tlet collections = options.collections;\n\tif (!collections || collections.length === 0) {\n\t\tcollections = await getSearchableCollections(db);\n\t}\n\n\tif (collections.length === 0) {\n\t\treturn { items: [] };\n\t}\n\n\t// To rank the merged window [offset, offset + limit) correctly, each\n\t// collection must contribute its own top (offset + limit) rows — in the\n\t// worst case the entire window comes from one collection. The extra +1\n\t// row detects whether a further page exists.\n\tconst perCollectionLimit = offset + limit + 1;\n\n\t// Search each collection and merge results\n\tconst allResults: SearchResult[] = [];\n\tconst titleColumns = await ftsManager.getCollectionsWithTitleColumn(collections);\n\n\tfor (const collection of collections) {\n\t\tconst config = await ftsManager.getSearchConfig(collection);\n\t\tif (!config?.enabled) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst collectionResults = await searchSingleCollection(\n\t\t\tdb,\n\t\t\tcollection,\n\t\t\tquery,\n\t\t\t{\n\t\t\t\tstatus,\n\t\t\t\tlocale: options.locale,\n\t\t\t\tlimit: perCollectionLimit,\n\t\t\t},\n\t\t\tconfig.weights,\n\t\t\ttitleColumns.has(collection),\n\t\t);\n\n\t\tallResults.push(...collectionResults);\n\t}\n\n\t// Sort by score descending\n\tallResults.sort((a, b) => b.score - a.score);\n\n\t// Page the merged set by offset. A nextCursor is issued only when at least\n\t// one result exists past this page.\n\tconst items = allResults.slice(offset, offset + limit);\n\tconst hasMore = allResults.length > offset + limit;\n\tconst nextCursor = hasMore ? encodeSearchCursor(offset + limit) : undefined;\n\n\treturn { items, nextCursor };\n}\n\n/**\n * Search within a single collection\n *\n * @param db - Kysely database instance\n * @param collection - Collection slug\n * @param query - Search query (FTS5 syntax supported)\n * @param options - Search options\n * @returns Search results with pagination\n *\n * @example\n * ```typescript\n * const results = await searchCollection(db, \"posts\", \"hello world\", {\n * limit: 10\n * });\n * ```\n */\nexport async function searchCollection(\n\tdb: Kysely<Database>,\n\tcollection: string,\n\tquery: string,\n\toptions: CollectionSearchOptions = {},\n): Promise<SearchResponse> {\n\tconst ftsManager = new FTSManager(db);\n\tconst config = await ftsManager.getSearchConfig(collection);\n\n\tif (!config?.enabled) {\n\t\treturn { items: [] };\n\t}\n\n\tconst limit = options.limit ?? 20;\n\tconst offset = options.cursor ? decodeSearchOffset(options.cursor) : 0;\n\n\t// Over-fetch the [offset, offset + limit) window plus one row to detect a\n\t// further page, then slice. Keeps the FTS SQL (LIMIT-only) unchanged and\n\t// the cursor contract identical to the cross-collection path.\n\tconst fetched = await searchSingleCollection(\n\t\tdb,\n\t\tcollection,\n\t\tquery,\n\t\t{ status: options.status, locale: options.locale, limit: offset + limit + 1 },\n\t\tconfig.weights,\n\t);\n\n\tconst items = fetched.slice(offset, offset + limit);\n\tconst hasMore = fetched.length > offset + limit;\n\tconst nextCursor = hasMore ? encodeSearchCursor(offset + limit) : undefined;\n\n\treturn { items, nextCursor };\n}\n\n/**\n * Internal function to search a single collection\n */\nasync function searchSingleCollection(\n\tdb: Kysely<Database>,\n\tcollection: string,\n\tquery: string,\n\toptions: CollectionSearchOptions,\n\tweights?: Record<string, number>,\n\thasTitle?: boolean,\n): Promise<SearchResult[]> {\n\t// Validate before any raw SQL interpolation\n\tvalidateIdentifier(collection, \"collection slug\");\n\n\tconst ftsManager = new FTSManager(db);\n\tconst ftsTable = ftsManager.getFtsTableName(collection);\n\tconst contentTable = ftsManager.getContentTableName(collection);\n\tconst limit = options.limit ?? 20;\n\tconst status = options.status ?? \"published\";\n\tconst locale = options.locale ? resolveConfiguredLocale(options.locale) : undefined;\n\n\t// Check if FTS table exists\n\tif (!(await ftsManager.ftsTableExists(collection))) {\n\t\treturn [];\n\t}\n\n\t// Escape the query for FTS5\n\tconst escapedQuery = escapeQuery(query);\n\tif (!escapedQuery) {\n\t\treturn [];\n\t}\n\n\t// Get searchable fields for snippet generation\n\tconst searchableFields = await ftsManager.getSearchableFields(collection);\n\n\t// `title` is an optional user-defined field, not a system column. Only\n\t// select it when the collection actually has one; otherwise the query\n\t// errors with \"no such column: c.title\" (#1178). Multi-collection callers\n\t// precompute this in bulk and pass it in; single-collection callers fall\n\t// back to the per-collection check.\n\tconst collectionHasTitle = hasTitle ?? (await ftsManager.hasTitleColumn(collection));\n\tconst titleExpr = collectionHasTitle ? sql`c.title` : sql`NULL`;\n\n\t// Build weight string for bm25 if weights provided\n\t// Format: bm25(table, weight1, weight2, ...)\n\t// First two weights are for 'id' and 'locale' columns (UNINDEXED, so 0)\n\tlet bm25Args = \"\";\n\tif (weights && searchableFields.length > 0) {\n\t\tconst weightValues = [\"0\", \"0\"]; // id column, locale column\n\t\tfor (const field of searchableFields) {\n\t\t\tweightValues.push(String(weights[field] ?? 1));\n\t\t}\n\t\tbm25Args = weightValues.join(\", \");\n\t}\n\n\t// Build and execute the search query\n\t// Using raw SQL because Kysely doesn't have FTS5 support\n\tconst bm25Expr = bm25Args ? `bm25(\"${ftsTable}\", ${bm25Args})` : `bm25(\"${ftsTable}\")`;\n\n\t// Snippet column index is 2 (after id=0, locale=1, first searchable field=2)\n\tlet results;\n\ttry {\n\t\tresults = await sql<{\n\t\t\tid: string;\n\t\t\tslug: string | null;\n\t\t\tlocale: string;\n\t\t\ttitle: string | null;\n\t\t\tsnippet: string | null;\n\t\t\tscore: number;\n\t\t}>`\n\t\tSELECT\n\t\t\tc.id,\n\t\t\tc.slug,\n\t\t\tc.locale,\n\t\t\t${titleExpr} as title,\n\t\t\tsnippet(\"${sql.raw(ftsTable)}\", 2, '<mark>', '</mark>', '...', 32) as snippet,\n\t\t\t${sql.raw(bm25Expr)} as score\n\t\tFROM \"${sql.raw(ftsTable)}\" f\n\t\tJOIN \"${sql.raw(contentTable)}\" c ON f.id = c.id\n\t\tWHERE \"${sql.raw(ftsTable)}\" MATCH ${escapedQuery}\n\t\tAND c.status = ${status}\n\t\tAND c.deleted_at IS NULL\n\t\t${locale ? sql`AND c.locale = ${locale}` : sql``}\n\t\tORDER BY score\n\t\tLIMIT ${limit}\n\t`.execute(db);\n\t} catch (error) {\n\t\t// FTS5 returns syntax errors for queries with unbalanced quotes,\n\t\t// stray operators, or other malformed input. Treat these as\n\t\t// \"no matches\" so the user gets an empty result rather than an\n\t\t// internals-leaking error. Other errors (table missing, IO) still\n\t\t// propagate. Intentionally not logged: any anonymous client can\n\t\t// trigger this path, and the underlying error message embeds the\n\t\t// raw query, so logging would be both noisy and a log-injection\n\t\t// vector.\n\t\tif (isFts5SyntaxError(error)) {\n\t\t\treturn [];\n\t\t}\n\t\tthrow error;\n\t}\n\n\treturn results.rows.map((row) => ({\n\t\tcollection,\n\t\tid: row.id,\n\t\tslug: row.slug,\n\t\tlocale: row.locale,\n\t\ttitle: row.title ?? undefined,\n\t\t// SQLite's snippet() returns NULL when the targeted column is\n\t\t// NULL for that row — even if the row matched via a different\n\t\t// searchable column. Skip sanitization in that case so we don't\n\t\t// throw on `null.replace`. The SearchResult.snippet field is\n\t\t// already optional, so omitting it is the documented contract.\n\t\tsnippet: row.snippet === null ? undefined : sanitizeSnippet(row.snippet),\n\t\tscore: Math.abs(row.score), // bm25 returns negative scores\n\t}));\n}\n\n// Module-scope regexes so the engine doesn't recompile per call —\n// snippet sanitization runs on every search result.\nconst SNIPPET_AMP_RE = /&/g;\nconst SNIPPET_LT_RE = /</g;\nconst SNIPPET_GT_RE = />/g;\nconst SNIPPET_QUOT_RE = /\"/g;\nconst SNIPPET_APOS_RE = /'/g;\n\n/**\n * Make an FTS5 snippet safe to render with `set:html` / `innerHTML`.\n *\n * SQLite's `snippet()` function splices literal `<mark>` and `</mark>`\n * markers around matched terms but does not escape the surrounding\n * source text. Posts that legitimately contain `<`, `>`, `&`, `\"` or\n * `'` would render as broken markup, and a `<script>` literal in a\n * title (or any other indexed field) would execute when displayed.\n *\n * The fix: HTML-escape the whole string, which turns the markers into\n * `&lt;mark&gt;` / `&lt;/mark&gt;`. Then restore those two patterns to\n * their original tag form. The result is \"the indexed text with all\n * HTML metacharacters escaped, plus a small set of literal `<mark>`\n * highlight tags around matched terms\" — which matches the API's\n * documented contract.\n */\nfunction sanitizeSnippet(snippet: string): string {\n\treturn snippet\n\t\t.replace(SNIPPET_AMP_RE, \"&amp;\")\n\t\t.replace(SNIPPET_LT_RE, \"&lt;\")\n\t\t.replace(SNIPPET_GT_RE, \"&gt;\")\n\t\t.replace(SNIPPET_QUOT_RE, \"&quot;\")\n\t\t.replace(SNIPPET_APOS_RE, \"&#39;\")\n\t\t.replaceAll(\"&lt;mark&gt;\", \"<mark>\")\n\t\t.replaceAll(\"&lt;/mark&gt;\", \"</mark>\");\n}\n\n/**\n * Get search suggestions for autocomplete\n *\n * @param db - Kysely database instance\n * @param query - Partial search query\n * @param options - Suggestion options\n * @returns Array of suggestions\n */\nexport async function getSuggestions(\n\tdb: Kysely<Database>,\n\tquery: string,\n\toptions: SuggestOptions = {},\n): Promise<Suggestion[]> {\n\tconst limit = options.limit ?? 5;\n\tconst locale = options.locale ? resolveConfiguredLocale(options.locale) : undefined;\n\n\t// Get searchable collections\n\tlet collections = options.collections;\n\tif (!collections || collections.length === 0) {\n\t\tcollections = await getSearchableCollections(db);\n\t}\n\n\tif (collections.length === 0) {\n\t\treturn [];\n\t}\n\n\tconst suggestions: Suggestion[] = [];\n\tconst ftsManager = new FTSManager(db);\n\tconst titleColumns = await ftsManager.getCollectionsWithTitleColumn(collections);\n\n\tfor (const collection of collections) {\n\t\tconst config = await ftsManager.getSearchConfig(collection);\n\t\tif (!config?.enabled) {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Suggestions are title-based (Suggestion.title is required and the\n\t\t// query filters on `c.title IS NOT NULL`). Collections without a\n\t\t// `title` field can't produce one, and selecting `c.title` would\n\t\t// error, so skip them. See #1178.\n\t\tif (!titleColumns.has(collection)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Validate before raw SQL interpolation\n\t\tvalidateIdentifier(collection, \"collection slug\");\n\n\t\tconst ftsTable = ftsManager.getFtsTableName(collection);\n\t\tconst contentTable = ftsManager.getContentTableName(collection);\n\n\t\t// Use prefix search for autocomplete. `escapeQuery` already appends `*`\n\t\t// to each term for prefix matching, so we must not append another one.\n\t\tconst prefixQuery = escapeQuery(query);\n\t\tif (!prefixQuery) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet results;\n\t\ttry {\n\t\t\tresults = await sql<{\n\t\t\t\tid: string;\n\t\t\t\tslug: string | null;\n\t\t\t\ttitle: string;\n\t\t\t}>`\n\t\t\t\tSELECT \n\t\t\t\t\tc.id,\n\t\t\t\t\tc.slug,\n\t\t\t\t\tc.title\n\t\t\t\tFROM \"${sql.raw(ftsTable)}\" f\n\t\t\t\tJOIN \"${sql.raw(contentTable)}\" c ON f.id = c.id\n\t\t\t\tWHERE \"${sql.raw(ftsTable)}\" MATCH ${prefixQuery}\n\t\t\t\tAND c.status = 'published'\n\t\t\t\tAND c.deleted_at IS NULL\n\t\t\t\tAND c.title IS NOT NULL\n\t\t\t\t${locale ? sql`AND c.locale = ${locale}` : sql``}\n\t\t\t\tORDER BY bm25(\"${sql.raw(ftsTable)}\")\n\t\t\t\tLIMIT ${limit}\n\t\t\t`.execute(db);\n\t\t} catch (error) {\n\t\t\t// Same swallow as searchSingleCollection: malformed prefix\n\t\t\t// queries should yield no suggestions, not surface DB errors.\n\t\t\t// Intentionally not logged (anonymous-triggerable, echoes\n\t\t\t// user input -- see searchSingleCollection for rationale).\n\t\t\tif (isFts5SyntaxError(error)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\n\t\tfor (const row of results.rows) {\n\t\t\tsuggestions.push({\n\t\t\t\tcollection,\n\t\t\t\tid: row.id,\n\t\t\t\tslug: row.slug,\n\t\t\t\ttitle: row.title,\n\t\t\t});\n\t\t}\n\t}\n\n\treturn suggestions.slice(0, limit);\n}\n\n/**\n * Get search statistics for all collections\n */\nexport async function getSearchStats(db: Kysely<Database>): Promise<SearchStats> {\n\tconst ftsManager = new FTSManager(db);\n\tconst collections = await getSearchableCollections(db);\n\tconst stats: SearchStats = { collections: {} };\n\n\tfor (const collection of collections) {\n\t\tconst collectionStats = await ftsManager.getIndexStats(collection);\n\t\tif (collectionStats) {\n\t\t\tstats.collections[collection] = collectionStats;\n\t\t}\n\t}\n\n\treturn stats;\n}\n\n/**\n * Get list of collections with search enabled\n */\nasync function getSearchableCollections(db: Kysely<Database>): Promise<string[]> {\n\tconst results = await db\n\t\t.selectFrom(\"_emdash_collections\")\n\t\t.select([\"slug\", \"search_config\"])\n\t\t.execute();\n\n\treturn results\n\t\t.filter((r) => {\n\t\t\tif (!r.search_config) return false;\n\t\t\ttry {\n\t\t\t\tconst config = JSON.parse(r.search_config);\n\t\t\t\treturn config.enabled === true;\n\t\t\t} catch {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t})\n\t\t.map((r) => r.slug);\n}\n\n/**\n * Escape a query string for FTS5\n *\n * Handles special characters and prevents injection.\n */\nfunction escapeQuery(query: string): string {\n\tif (!query || typeof query !== \"string\") {\n\t\treturn \"\";\n\t}\n\n\t// Trim whitespace\n\tquery = query.trim();\n\n\tif (query.length === 0) {\n\t\treturn \"\";\n\t}\n\n\t// If already a quoted phrase, escape only interior quotes and preserve phrase syntax\n\tif (query.startsWith('\"') && query.endsWith('\"') && query.length >= 2) {\n\t\tconst inner = query.slice(1, -1);\n\t\treturn `\"${inner.replace(DOUBLE_QUOTE_PATTERN, '\"\"')}\"`;\n\t}\n\n\t// Escape any existing quotes\n\tconst escaped = query.replace(DOUBLE_QUOTE_PATTERN, '\"\"');\n\n\t// If the query contains FTS5 operators (AND, OR, NOT, NEAR),\n\t// pass through with quotes escaped but operators preserved\n\tif (FTS_OPERATORS_PATTERN.test(query)) {\n\t\treturn escaped;\n\t}\n\n\t// For simple queries, wrap each word to handle special chars\n\tconst terms = escaped.split(WHITESPACE_SPLIT_PATTERN).filter((t) => t.length > 0);\n\tif (terms.length === 0) {\n\t\treturn \"\";\n\t}\n\n\t// Join with implicit AND, add prefix matching (*) to all terms\n\t// This allows \"hel wor\" to match \"hello world\"\n\treturn terms.map((t) => `\"${t}\"*`).join(\" \");\n}\n","/**\n * Text Extraction\n *\n * Extracts plain text from Portable Text blocks for FTS indexing.\n * Uses @portabletext/toolkit as base with extensions for custom block types.\n */\n\nimport { toPlainText } from \"@portabletext/toolkit\";\n\nimport type { PortableTextBlock } from \"../content/converters/types.js\";\n\n/**\n * Validate that a value looks like a Portable Text block array.\n * Each element must have at least a `_type` string property.\n */\nfunction isPortableTextArray(value: unknown[]): value is PortableTextBlock[] {\n\treturn value.every(\n\t\t(item) =>\n\t\t\ttypeof item === \"object\" &&\n\t\t\titem !== null &&\n\t\t\t\"_type\" in item &&\n\t\t\ttypeof item._type === \"string\",\n\t);\n}\n\n/**\n * Extract additional text from custom block types that toPlainText doesn't handle\n */\nfunction extractCustomBlockText(block: PortableTextBlock): string {\n\t// Code blocks - include the code content\n\tif (block._type === \"code\" && \"code\" in block && typeof block.code === \"string\") {\n\t\treturn block.code;\n\t}\n\n\t// Image blocks - include alt text and caption\n\tif (block._type === \"image\") {\n\t\tconst parts: string[] = [];\n\t\tif (\"alt\" in block && typeof block.alt === \"string\" && block.alt) {\n\t\t\tparts.push(block.alt);\n\t\t}\n\t\tif (\"caption\" in block && typeof block.caption === \"string\" && block.caption) {\n\t\t\tparts.push(block.caption);\n\t\t}\n\t\treturn parts.join(\" \");\n\t}\n\n\treturn \"\";\n}\n\n/**\n * Extract plain text from Portable Text blocks\n *\n * Uses @portabletext/toolkit's toPlainText for standard blocks,\n * plus extracts text from custom block types (code, images with alt/caption).\n *\n * @param blocks - Array of Portable Text blocks (or a JSON string)\n * @returns Plain text content\n *\n * @example\n * ```typescript\n * const text = extractPlainText([\n * {\n * _type: \"block\",\n * _key: \"abc\",\n * children: [{ _type: \"span\", _key: \"s1\", text: \"Hello World\" }]\n * }\n * ]);\n * // Returns: \"Hello World\"\n * ```\n */\nexport function extractPlainText(blocks: PortableTextBlock[] | string | null | undefined): string {\n\tif (!blocks) {\n\t\treturn \"\";\n\t}\n\n\t// Handle JSON string input\n\tlet parsedBlocks: PortableTextBlock[];\n\tif (typeof blocks === \"string\") {\n\t\ttry {\n\t\t\tparsedBlocks = JSON.parse(blocks);\n\t\t} catch {\n\t\t\t// If it's not valid JSON, treat as plain text\n\t\t\treturn blocks;\n\t\t}\n\t} else {\n\t\tparsedBlocks = blocks;\n\t}\n\n\tif (!Array.isArray(parsedBlocks)) {\n\t\treturn \"\";\n\t}\n\n\t// Use official toPlainText for standard blocks.\n\t// toPlainText expects `{ _type: string; [key: string]: any }[]` but our blocks use\n\t// `unknown` index sigs. They're structurally compatible at runtime — spread each block\n\t// to satisfy the wider index signature without an unsafe cast.\n\tconst toolkitBlocks = parsedBlocks.map((b) => {\n\t\tconst obj: Record<string, unknown> & { _type: string } = { _type: b._type };\n\t\tfor (const [key, val] of Object.entries(b)) {\n\t\t\tobj[key] = val;\n\t\t}\n\t\treturn obj;\n\t});\n\tconst standardText = toPlainText(toolkitBlocks);\n\n\t// Extract text from custom block types that toPlainText doesn't handle\n\tconst customTexts = parsedBlocks.map(extractCustomBlockText).filter((text) => text.length > 0);\n\n\t// Combine both\n\tconst allTexts = [standardText, ...customTexts].filter((t) => t.length > 0);\n\treturn allTexts.join(\"\\n\");\n}\n\n/**\n * Extract searchable text from a content entry\n *\n * Extracts text from specified fields, handling both plain text and Portable Text.\n *\n * @param entry - Content entry data\n * @param fields - Field names to extract text from\n * @returns Object mapping field names to extracted text\n */\nexport function extractSearchableFields(\n\tentry: Record<string, unknown>,\n\tfields: string[],\n): Record<string, string> {\n\tconst result: Record<string, string> = {};\n\n\tfor (const field of fields) {\n\t\tconst value = entry[field];\n\n\t\tif (value === null || value === undefined) {\n\t\t\tresult[field] = \"\";\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (typeof value === \"string\") {\n\t\t\t// Could be plain text or JSON Portable Text\n\t\t\tif (value.startsWith(\"[\")) {\n\t\t\t\tresult[field] = extractPlainText(value);\n\t\t\t} else {\n\t\t\t\tresult[field] = value;\n\t\t\t}\n\t\t} else if (Array.isArray(value)) {\n\t\t\t// Validate the array looks like Portable Text before treating it as such\n\t\t\tif (isPortableTextArray(value)) {\n\t\t\t\tresult[field] = extractPlainText(value);\n\t\t\t} else {\n\t\t\t\tresult[field] = JSON.stringify(value);\n\t\t\t}\n\t\t} else if (typeof value === \"object\") {\n\t\t\t// Object — serialize to JSON for searchable text\n\t\t\tresult[field] = JSON.stringify(value);\n\t\t} else if (typeof value === \"number\" || typeof value === \"boolean\") {\n\t\t\tresult[field] = `${value}`;\n\t\t} else {\n\t\t\tresult[field] = \"\";\n\t\t}\n\t}\n\n\treturn result;\n}\n","/**\n * Search Module\n *\n * Full-text search for EmDash using SQLite FTS5.\n */\n\n// Types\nexport type {\n\tSearchConfig,\n\tSearchTokenizer,\n\tSearchOptions,\n\tCollectionSearchOptions,\n\tSearchResult,\n\tSearchResponse,\n\tSuggestOptions,\n\tSuggestion,\n\tSearchStats,\n} from \"./types.js\";\nexport { SEARCH_TOKENIZERS } from \"./types.js\";\n\n// FTS Manager\nexport { FTSManager } from \"./fts-manager.js\";\n\n// Query functions (public API uses getDb() internally)\nexport { search, searchWithDb, searchCollection, getSuggestions, getSearchStats } from \"./query.js\";\n\n// Text extraction\nexport { extractPlainText, extractSearchableFields } from \"./text-extraction.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmCA,MAAM,uBAAuB;;AAG7B,SAAS,mBAAmB,QAAwB;AACnD,QAAO,aAAa,OAAO,OAAO,EAAE,qBAAqB;;;;;;;;;AAU1D,MAAM,oBAAoB;AAE1B,SAAS,mBAAmB,QAAwB;CACnD,MAAM,EAAE,YAAY,OAAO,aAAa,OAAO;AAC/C,KAAI,OAAO,qBACV,OAAM,IAAI,mBAAmB,OAAO;CAErC,MAAM,SAAS,OAAO,WAAW;AACjC,KAAI,CAAC,OAAO,UAAU,OAAO,IAAI,SAAS,KAAK,SAAS,kBACvD,OAAM,IAAI,mBAAmB,OAAO;AAErC,QAAO;;;AAIR,MAAM,2BAA2B;AACjC,MAAM,wBAAwB;AAC9B,MAAM,uBAAuB;;;;;;;;;;;;AAa7B,SAAS,kBAAkB,OAAyB;AACnD,KAAI,EAAE,iBAAiB,OAAQ,QAAO;CACtC,MAAM,UAAU,MAAM,QAAQ,aAAa;AAC3C,QAAO,QAAQ,SAAS,qBAAqB,IAAI,QAAQ,SAAS,wBAAwB;;;;;;;;;;;;;;;;;;;;;AAsB3F,eAAsB,OAAO,OAAe,UAAyB,EAAE,EAA2B;AAEjG,QAAO,aADI,MAAM,OAAO,EACA,OAAO,QAAQ;;;;;;;;;;;;;AAcxC,eAAsB,aACrB,IACA,OACA,UAAyB,EAAE,EACD;CAC1B,MAAM,aAAa,IAAI,WAAW,GA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AI,OAAO,WAAW,SACrB,KAAI;AACH,iBAAe,KAAK,MAAM,OAAO;SAC1B;AAEP,SAAO;;KAGR,gBAAe;AAGhB,KAAI,CAAC,MAAM,QAAQ,aAAa,CAC/B,QAAO;AAqBR,QADiB,CANI,YAPC,aAAa,KAAK,MAAM;EAC7C,MAAM,MAAmD,EAAE,OAAO,EAAE,OAAO;AAC3E,OAAK,MAAM,CAAC,KAAK,QAAQ,OAAO,QAAQ,EAAE,CACzC,KAAI,OAAO;AAEZ,SAAO;GACN,CAC6C,EAMf,GAHZ,aAAa,IAAI,uBAAuB,CAAC,QAAQ,SAAS,KAAK,SAAS,EAAE,CAG/C,CAAC,QAAQ,MAAM,EAAE,SAAS,EAAE,CAC3D,KAAK,KAAK;;;;;;;;;;;AAY3B,SAAgB,wBACf,OACA,QACyB;CACzB,MAAM,SAAiC,EAAE;AAEzC,MAAK,MAAM,SAAS,QAAQ;EAC3B,MAAM,QAAQ,MAAM;AAEpB,MAAI,UAAU,QAAQ,UAAU,QAAW;AAC1C,UAAO,SAAS;AAChB;;AAGD,MAAI,OAAO,UAAU,SAEpB,KAAI,MAAM,WAAW,IAAI,CACxB,QAAO,SAAS,iBAAiB,MAAM;MAEvC,QAAO,SAAS;WAEP,MAAM,QAAQ,MAAM,CAE9B,KAAI,oBAAoB,MAAM,CAC7B,QAAO,SAAS,iBAAiB,MAAM;MAEvC,QAAO,SAAS,KAAK,UAAU,MAAM;WAE5B,OAAO,UAAU,SAE3B,QAAO,SAAS,KAAK,UAAU,MAAM;WAC3B,OAAO,UAAU,YAAY,OAAO,UAAU,UACxD,QAAO,SAAS,GAAG;MAEnB,QAAO,SAAS;;AAIlB,QAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"seo-CobNfOvb.mjs","names":[],"sources":["../src/api/handlers/seo.ts"],"sourcesContent":["/**\n * SEO Handlers\n *\n * Business logic for sitemap generation and robots.txt.\n */\n\nimport { sql, type Kysely } from \"kysely\";\n\nimport type { Database } from \"../../database/types.js\";\nimport { validateIdentifier } from \"../../database/validate.js\";\nimport type { ApiResult } from \"../types.js\";\n\n/** Raw content data for sitemap generation — the route builds the actual URLs */\nexport interface SitemapContentEntry {\n\t/** Content ID (ULID) */\n\tid: string;\n\t/** Content slug, or null when the entry has no slug */\n\tslug: string | null;\n\t/** ISO date of last modification */\n\tupdatedAt: string;\n\t/**\n\t * Locale of this row (e.g. `\"en\"`, `\"fr\"`). Always present — rows in\n\t * pre-i18n databases are backfilled to the configured `defaultLocale`.\n\t */\n\tlocale: string;\n\t/**\n\t * `translation_group` ULID shared across all locale variants of the\n\t * same content. Used by the sitemap route to emit `hreflang`\n\t * alternates between siblings.\n\t */\n\ttranslationGroup: string | null;\n\t/**\n\t * Stored SEO image reference (`_emdash_seo.seo_image`), or null when\n\t * the entry has no SEO image. The route resolves it to an absolute\n\t * URL and emits it as an `<image:image>` sitemap entry.\n\t */\n\timage: string | null;\n}\n\n/** Per-collection sitemap data with entries and URL pattern */\nexport interface SitemapCollectionData {\n\t/** Collection slug (e.g., \"post\", \"page\") */\n\tcollection: string;\n\t/** URL pattern with {slug} placeholder, or null for default /{collection}/{slug} */\n\turlPattern: string | null;\n\t/** Most recent updated_at across all entries (for sitemap index lastmod) */\n\tlastmod: string;\n\t/** Individual content entries */\n\tentries: SitemapContentEntry[];\n}\n\nexport interface SitemapDataResponse {\n\tcollections: SitemapCollectionData[];\n}\n\n/** Maximum entries per sitemap (per spec) */\nconst SITEMAP_MAX_ENTRIES = 50_000;\n\n/** Matches a trailing timezone designator (`Z` or `±HH`, `±HHMM`, `±HH:MM`). */\nconst TZ_SUFFIX_RE = /([zZ]|[+-]\\d{2}(:?\\d{2})?)$/;\n\n/**\n * Normalize a stored timestamp to W3C Datetime (ISO 8601) for sitemaps.\n *\n * `updated_at` is not guaranteed to be ISO: the column default is\n * `datetime('now')` on SQLite and `CURRENT_TIMESTAMP` on Postgres, both of\n * which store a space-separated `YYYY-MM-DD HH:MM:SS` string (and imported\n * content can carry other shapes). The sitemap `<lastmod>` field requires\n * W3C Datetime, and Google Search Console rejects the space-separated form\n * as \"Invalid date\". Normalize defensively, assuming UTC when no offset is\n * present (matches SQLite's `datetime('now')`). Valid date strings are\n * normalized to UTC ISO 8601; unparseable values are returned as-is.\n */\nfunction toW3CDate(value: string): string {\n\tif (!value) return value;\n\tlet normalized = value.trim();\n\tif (normalized.includes(\" \") && !normalized.includes(\"T\")) {\n\t\tnormalized = normalized.replace(\" \", \"T\");\n\t}\n\tif (!TZ_SUFFIX_RE.test(normalized)) {\n\t\tnormalized += \"Z\";\n\t}\n\tconst parsed = Date.parse(normalized);\n\treturn Number.isNaN(parsed) ? value : new Date(parsed).toISOString();\n}\n\n/**\n * Collect all published, indexable content across SEO-enabled collections\n * for sitemap generation, grouped by collection.\n *\n * Only includes content from collections with `has_seo = 1`.\n * Excludes content with `seo_no_index = 1` in the `_emdash_seo` table.\n *\n * Returns raw data grouped per collection. The caller (route) is\n * responsible for building absolute URLs — this handler does NOT\n * assume a URL structure.\n */\nexport async function handleSitemapData(\n\tdb: Kysely<Database>,\n\t/** When set, only return data for this collection. */\n\tcollectionSlug?: string,\n): Promise<ApiResult<SitemapDataResponse>> {\n\ttry {\n\t\t// Find SEO-enabled collections (optionally filtered)\n\t\tlet query = db\n\t\t\t.selectFrom(\"_emdash_collections\")\n\t\t\t.select([\"slug\", \"url_pattern\"])\n\t\t\t.where(\"has_seo\", \"=\", 1);\n\n\t\tif (collectionSlug) {\n\t\t\tquery = query.where(\"slug\", \"=\", collectionSlug);\n\t\t}\n\n\t\tconst collections = await query.execute();\n\n\t\tconst result: SitemapCollectionData[] = [];\n\n\t\tfor (const col of collections) {\n\t\t\t// Validate the slug before using it as a table name identifier.\n\t\t\t// Should always pass (slugs are validated on creation), but\n\t\t\t// guards against corrupted DB data.\n\t\t\ttry {\n\t\t\t\tvalidateIdentifier(col.slug, \"collection slug\");\n\t\t\t} catch {\n\t\t\t\tconsole.warn(`[SITEMAP] Skipping collection with invalid slug: ${col.slug}`);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst tableName = `ec_${col.slug}`;\n\n\t\t\t// Query published, non-deleted content.\n\t\t\t// LEFT JOIN _emdash_seo to check noindex flag.\n\t\t\t// Content without an SEO row is assumed indexable (default).\n\t\t\t// Wrapped in try/catch so a missing/broken table doesn't fail the\n\t\t\t// entire sitemap — we skip that collection and continue.\n\t\t\ttry {\n\t\t\t\tconst rows = await sql<{\n\t\t\t\t\tslug: string | null;\n\t\t\t\t\tid: string;\n\t\t\t\t\tupdated_at: string;\n\t\t\t\t\tlocale: string;\n\t\t\t\t\ttranslation_group: string | null;\n\t\t\t\t\tseo_image: string | null;\n\t\t\t\t}>`\n\t\t\t\t\tSELECT c.slug, c.id, c.updated_at, c.locale, c.translation_group, s.seo_image\n\t\t\t\t\tFROM ${sql.ref(tableName)} c\n\t\t\t\t\tLEFT JOIN _emdash_seo s\n\t\t\t\t\t\tON s.collection = ${col.slug}\n\t\t\t\t\t\tAND s.content_id = c.id\n\t\t\t\t\tWHERE c.status = 'published'\n\t\t\t\t\tAND c.deleted_at IS NULL\n\t\t\t\t\tAND (s.seo_no_index IS NULL OR s.seo_no_index = 0)\n\t\t\t\t\tORDER BY c.updated_at DESC\n\t\t\t\t\tLIMIT ${SITEMAP_MAX_ENTRIES}\n\t\t\t\t`.execute(db);\n\n\t\t\t\tif (rows.rows.length === 0) continue;\n\n\t\t\t\tconst entries: SitemapContentEntry[] = [];\n\t\t\t\tfor (const row of rows.rows) {\n\t\t\t\t\tentries.push({\n\t\t\t\t\t\tid: row.id,\n\t\t\t\t\t\tslug: row.slug,\n\t\t\t\t\t\tupdatedAt: toW3CDate(row.updated_at),\n\t\t\t\t\t\tlocale: row.locale,\n\t\t\t\t\t\ttranslationGroup: row.translation_group,\n\t\t\t\t\t\timage: row.seo_image ?? null,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tresult.push({\n\t\t\t\t\tcollection: col.slug,\n\t\t\t\t\turlPattern: col.url_pattern,\n\t\t\t\t\t// Rows are ordered by updated_at DESC, so first row is the latest\n\t\t\t\t\tlastmod: toW3CDate(rows.rows[0].updated_at),\n\t\t\t\t\tentries,\n\t\t\t\t});\n\t\t\t} catch (err) {\n\t\t\t\t// Table missing or query error — skip this collection\n\t\t\t\tconsole.warn(`[SITEMAP] Failed to query collection \"${col.slug}\":`, err);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\treturn { success: true, data: { collections: result } };\n\t} catch (error) {\n\t\tconsole.error(\"[SITEMAP_ERROR]\", error);\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: { code: \"SITEMAP_ERROR\", message: \"Failed to generate sitemap data\" },\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;AAwDA,MAAM,sBAAsB;;AAG5B,MAAM,eAAe;;;;;;;;;;;;;AAcrB,SAAS,UAAU,OAAuB;AACzC,KAAI,CAAC,MAAO,QAAO;CACnB,IAAI,aAAa,MAAM,MAAM;AAC7B,KAAI,WAAW,SAAS,IAAI,IAAI,CAAC,WAAW,SAAS,IAAI,CACxD,cAAa,WAAW,QAAQ,KAAK,IAAI;AAE1C,KAAI,CAAC,aAAa,KAAK,WAAW,CACjC,eAAc;CAEf,MAAM,SAAS,KAAK,MAAM,WAAW;AACrC,QAAO,OAAO,MAAM,OAAO,GAAG,QAAQ,IAAI,KAAK,OAAO,CAAC,aAAa;;;;;;;;;;;;;AAcrE,eAAsB,kBACrB,IAEA,gBAC0C;AAC1C,KAAI;EAEH,IAAI,QAAQ,GACV,WAAW,sBAAsB,CACjC,OAAO,CAAC,QAAQ,cAAc,CAAC,CAC/B,MAAM,WAAW,KAAK,EAAE;AAE1B,MAAI,eACH,SAAQ,MAAM,MAAM,QAAQ,KAAK,eAAe;EAGjD,MAAM,cAAc,MAAM,MAAM,SAAS;EAEzC,MAAM,SAAkC,EAAE;AAE1C,OAAK,MAAM,OAAO,aAAa;AAI9B,OAAI;AACH,uBAAmB,IAAI,MAAM,kBAAkB;WACxC;AACP,YAAQ,KAAK,oDAAoD,IAAI,OAAO;AAC5E;;GAGD,MAAM,YAAY,MAAM,IAAI;AAO5B,OAAI;IACH,MAAM,OAAO,MAAM,GAOjB;;YAEM,IAAI,IAAI,UAAU,CAAC;;0BAEL,IAAI,KAAK;;;;;;aAMtB,oBAAoB;MAC3B,QAAQ,GAAG;AAEb,QAAI,KAAK,KAAK,WAAW,EAAG;IAE5B,MAAM,UAAiC,EAAE;AACzC,SAAK,MAAM,OAAO,KAAK,KACtB,SAAQ,KAAK;KACZ,IAAI,IAAI;KACR,MAAM,IAAI;KACV,WAAW,UAAU,IAAI,WAAW;KACpC,QAAQ,IAAI;KACZ,kBAAkB,IAAI;KACtB,OAAO,IAAI,aAAa;KACxB,CAAC;AAGH,WAAO,KAAK;KACX,YAAY,IAAI;KAChB,YAAY,IAAI;KAEhB,SAAS,UAAU,KAAK,KAAK,GAAG,WAAW;KAC3C;KACA,CAAC;YACM,KAAK;AAEb,YAAQ,KAAK,yCAAyC,IAAI,KAAK,KAAK,IAAI;AACxE;;;AAIF,SAAO;GAAE,SAAS;GAAM,MAAM,EAAE,aAAa,QAAQ;GAAE;UAC/C,OAAO;AACf,UAAQ,MAAM,mBAAmB,MAAM;AACvC,SAAO;GACN,SAAS;GACT,OAAO;IAAE,MAAM;IAAiB,SAAS;IAAmC;GAC5E"}
@@ -1,30 +0,0 @@
1
- //#region src/utils/slugify.ts
2
- const DIACRITICS_PATTERN = /[\u0300-\u036f]/g;
3
- const WHITESPACE_UNDERSCORE_PATTERN = /[\s_]+/g;
4
- const NON_ALPHANUMERIC_HYPHEN_PATTERN = /[^a-z0-9-]/g;
5
- const MULTIPLE_HYPHENS_PATTERN = /-+/g;
6
- const LEADING_TRAILING_HYPHEN_PATTERN = /^-|-$/g;
7
- const TRAILING_HYPHEN_PATTERN = /-$/;
8
- /**
9
- * Convert a string to a URL-friendly slug.
10
- *
11
- * Handles unicode by normalizing to NFD and stripping diacritics,
12
- * so "café" becomes "cafe", "naïve" becomes "naive", etc.
13
- */
14
- /**
15
- * Decode a URI-encoded slug parameter.
16
- *
17
- * Browsers percent-encode non-ASCII characters in URLs, so a slug like
18
- * "మేష-రాసి" arrives as "%e0%b0%ae%e0%b1%87%e0%b0%b7-%e0%b0%b0%e0%b0%be%e0%b0%b8%e0%b0%bf".
19
- * Call this on `Astro.params.slug` before using it in database lookups.
20
- */
21
- function decodeSlug(raw) {
22
- return raw ? decodeURIComponent(raw) : void 0;
23
- }
24
- function slugify(text, maxLength = 80) {
25
- return text.toLowerCase().normalize("NFD").replace(DIACRITICS_PATTERN, "").replace(WHITESPACE_UNDERSCORE_PATTERN, "-").replace(NON_ALPHANUMERIC_HYPHEN_PATTERN, "").replace(MULTIPLE_HYPHENS_PATTERN, "-").replace(LEADING_TRAILING_HYPHEN_PATTERN, "").slice(0, maxLength).replace(TRAILING_HYPHEN_PATTERN, "");
26
- }
27
-
28
- //#endregion
29
- export { slugify as n, decodeSlug as t };
30
- //# sourceMappingURL=slugify-C_tqlU4G.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"slugify-C_tqlU4G.mjs","names":[],"sources":["../src/utils/slugify.ts"],"sourcesContent":["// Regex patterns for slug normalization\nconst DIACRITICS_PATTERN = /[\\u0300-\\u036f]/g;\nconst WHITESPACE_UNDERSCORE_PATTERN = /[\\s_]+/g;\nconst NON_ALPHANUMERIC_HYPHEN_PATTERN = /[^a-z0-9-]/g;\nconst MULTIPLE_HYPHENS_PATTERN = /-+/g;\nconst LEADING_TRAILING_HYPHEN_PATTERN = /^-|-$/g;\nconst TRAILING_HYPHEN_PATTERN = /-$/;\n\n/**\n * Convert a string to a URL-friendly slug.\n *\n * Handles unicode by normalizing to NFD and stripping diacritics,\n * so \"café\" becomes \"cafe\", \"naïve\" becomes \"naive\", etc.\n */\n/**\n * Decode a URI-encoded slug parameter.\n *\n * Browsers percent-encode non-ASCII characters in URLs, so a slug like\n * \"మేష-రాసి\" arrives as \"%e0%b0%ae%e0%b1%87%e0%b0%b7-%e0%b0%b0%e0%b0%be%e0%b0%b8%e0%b0%bf\".\n * Call this on `Astro.params.slug` before using it in database lookups.\n */\nexport function decodeSlug(raw: string | undefined): string | undefined {\n\treturn raw ? decodeURIComponent(raw) : undefined;\n}\n\nexport function slugify(text: string, maxLength: number = 80): string {\n\treturn (\n\t\ttext\n\t\t\t.toLowerCase()\n\t\t\t.normalize(\"NFD\")\n\t\t\t.replace(DIACRITICS_PATTERN, \"\")\n\t\t\t.replace(WHITESPACE_UNDERSCORE_PATTERN, \"-\")\n\t\t\t.replace(NON_ALPHANUMERIC_HYPHEN_PATTERN, \"\")\n\t\t\t.replace(MULTIPLE_HYPHENS_PATTERN, \"-\")\n\t\t\t.replace(LEADING_TRAILING_HYPHEN_PATTERN, \"\")\n\t\t\t.slice(0, maxLength)\n\t\t\t// Clean trailing hyphen from truncation\n\t\t\t.replace(TRAILING_HYPHEN_PATTERN, \"\")\n\t);\n}\n"],"mappings":";AACA,MAAM,qBAAqB;AAC3B,MAAM,gCAAgC;AACtC,MAAM,kCAAkC;AACxC,MAAM,2BAA2B;AACjC,MAAM,kCAAkC;AACxC,MAAM,0BAA0B;;;;;;;;;;;;;;AAehC,SAAgB,WAAW,KAA6C;AACvE,QAAO,MAAM,mBAAmB,IAAI,GAAG;;AAGxC,SAAgB,QAAQ,MAAc,YAAoB,IAAY;AACrE,QACC,KACE,aAAa,CACb,UAAU,MAAM,CAChB,QAAQ,oBAAoB,GAAG,CAC/B,QAAQ,+BAA+B,IAAI,CAC3C,QAAQ,iCAAiC,GAAG,CAC5C,QAAQ,0BAA0B,IAAI,CACtC,QAAQ,iCAAiC,GAAG,CAC5C,MAAM,GAAG,UAAU,CAEnB,QAAQ,yBAAyB,GAAG"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"taxonomies-CKuaZER5.mjs","names":[],"sources":["../src/api/handlers/taxonomies.ts"],"sourcesContent":["/**\n * Taxonomy and term CRUD handlers.\n *\n * i18n: terms and defs are per-locale. `(name, slug, locale)` is unique for\n * terms; `(name, locale)` for defs. Translations of the same term/def share a\n * `translation_group`. The content_taxonomies pivot stores translation_groups\n * so assignments span every locale of a post.\n */\n\nimport type { Kysely, Selectable } from \"kysely\";\nimport { ulid } from \"ulidx\";\n\nimport { TaxonomyRepository, type SiblingPosition } from \"../../database/repositories/taxonomy.js\";\nimport type { Database, TaxonomyDefTable } from \"../../database/types.js\";\nimport { resolveConfiguredLocale } from \"../../i18n/config.js\";\nimport { invalidateTaxonomyDefsCache, invalidateTermCache } from \"../../taxonomies/index.js\";\nimport { fetchVisibleTermCounts } from \"../../taxonomies/term-counts.js\";\nimport type { ApiResult } from \"../types.js\";\n\nconst NAME_PATTERN = /^[a-z][a-z0-9_]*$/;\n\n// ---------------------------------------------------------------------------\n// Response types\n// ---------------------------------------------------------------------------\n\nexport interface TaxonomyDef {\n\tid: string;\n\tname: string;\n\tlabel: string;\n\tlabelSingular?: string;\n\thierarchical: boolean;\n\tcollections: string[];\n\tlocale: string;\n\ttranslationGroup: string | null;\n}\n\nexport interface TaxonomyListResponse {\n\ttaxonomies: TaxonomyDef[];\n}\n\nexport interface TermData {\n\tid: string;\n\tname: string;\n\tslug: string;\n\tlabel: string;\n\tparentId: string | null;\n\tdescription?: string;\n\tlocale: string;\n\ttranslationGroup: string | null;\n}\n\nexport interface TermWithCount extends TermData {\n\t/** Absent when the caller opted out of counts (`includeCounts: false`). */\n\tcount?: number;\n\tchildren: TermWithCount[];\n}\n\nexport interface TermListResponse {\n\tterms: TermWithCount[];\n}\n\nexport interface TermReorderResponse {\n\treordered: true;\n}\n\nexport interface TermResponse {\n\tterm: TermData;\n}\n\nexport interface TermGetResponse {\n\tterm: TermData & {\n\t\tcount: number;\n\t\tchildren: Array<{ id: string; slug: string; label: string }>;\n\t};\n}\n\nexport interface TermTranslationsResponse {\n\ttranslationGroup: string | null;\n\ttranslations: Array<{\n\t\tid: string;\n\t\tslug: string;\n\t\tlabel: string;\n\t\tlocale: string;\n\t}>;\n}\n\nexport interface TaxonomyDefTranslationsResponse {\n\ttranslationGroup: string | null;\n\ttranslations: Array<{\n\t\tid: string;\n\t\tname: string;\n\t\tlabel: string;\n\t\tlocale: string;\n\t}>;\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Build tree structure from flat terms\n */\nfunction buildTree(flatTerms: TermWithCount[]): TermWithCount[] {\n\t// `parentId` holds the parent's translation_group, so resolve links by group.\n\t// Key by (locale, group): a child's parent lives in the same locale, and an\n\t// unfiltered list mixes locales whose translated siblings share a group —\n\t// keying by group alone would collide and misattach children across locales.\n\tconst byLocaleGroup = new Map<string, TermWithCount>();\n\tconst roots: TermWithCount[] = [];\n\tfor (const term of flatTerms) {\n\t\tbyLocaleGroup.set(`${term.locale}::${term.translationGroup ?? term.id}`, term);\n\t}\n\tfor (const term of flatTerms) {\n\t\tconst parent = term.parentId\n\t\t\t? byLocaleGroup.get(`${term.locale}::${term.parentId}`)\n\t\t\t: undefined;\n\t\tif (parent) {\n\t\t\tparent.children.push(term);\n\t\t} else {\n\t\t\troots.push(term);\n\t\t}\n\t}\n\treturn roots;\n}\n\n/**\n * Look up a taxonomy definition by name (optionally scoped to a locale).\n * Returns the lowest-locale match when no locale is provided.\n */\nasync function requireTaxonomyDef(\n\tdb: Kysely<Database>,\n\tname: string,\n\tlocale?: string,\n): Promise<\n\t| { success: true; def: Selectable<TaxonomyDefTable> }\n\t| { success: false; error: { code: string; message: string } }\n> {\n\tlet query = db.selectFrom(\"_emdash_taxonomy_defs\").selectAll().where(\"name\", \"=\", name);\n\tif (locale !== undefined) query = query.where(\"locale\", \"=\", locale);\n\tconst def = await query.orderBy(\"locale\", \"asc\").executeTakeFirst();\n\tif (!def) {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: { code: \"NOT_FOUND\", message: `Taxonomy '${name}' not found` },\n\t\t};\n\t}\n\treturn { success: true, def };\n}\n\n/** Declared collections of a taxonomy def row (deduped, parsed from JSON). */\nfunction defCollections(def: Selectable<TaxonomyDefTable>): string[] {\n\t// eslint-disable-next-line typescript/no-unsafe-type-assertion -- column stores a JSON string[] written by handleTaxonomyCreate\n\tconst parsed = def.collections ? (JSON.parse(def.collections) as string[]) : [];\n\treturn [...new Set(parsed)];\n}\n\nfunction rowToDef(row: Selectable<TaxonomyDefTable>): TaxonomyDef {\n\treturn {\n\t\tid: row.id,\n\t\tname: row.name,\n\t\tlabel: row.label,\n\t\tlabelSingular: row.label_singular ?? undefined,\n\t\thierarchical: row.hierarchical === 1,\n\t\tcollections: row.collections ? JSON.parse(row.collections) : [],\n\t\tlocale: row.locale,\n\t\ttranslationGroup: row.translation_group,\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Taxonomy definition handlers\n// ---------------------------------------------------------------------------\n\n/**\n * List all taxonomy definitions\n */\nexport async function handleTaxonomyList(\n\tdb: Kysely<Database>,\n\toptions: { locale?: string } = {},\n): Promise<ApiResult<TaxonomyListResponse>> {\n\ttry {\n\t\tconst locale = options.locale ? resolveConfiguredLocale(options.locale) : undefined;\n\t\tlet query = db.selectFrom(\"_emdash_taxonomy_defs\").selectAll();\n\t\tif (locale !== undefined) query = query.where(\"locale\", \"=\", locale);\n\t\tconst [rows, collectionRows] = await Promise.all([\n\t\t\tquery.execute(),\n\t\t\tdb.selectFrom(\"_emdash_collections\").select(\"slug\").execute(),\n\t\t]);\n\n\t\t// Filter orphan collection references on read so the response stays\n\t\t// consistent with `schema_list_collections`. Storage is untouched —\n\t\t// re-creating the collection re-links automatically.\n\t\tconst realCollections = new Set(collectionRows.map((r) => r.slug));\n\n\t\tconst taxonomies: TaxonomyDef[] = rows.map((row) => {\n\t\t\tconst def = rowToDef(row);\n\t\t\treturn { ...def, collections: def.collections.filter((slug) => realCollections.has(slug)) };\n\t\t});\n\n\t\treturn { success: true, data: { taxonomies } };\n\t} catch {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: { code: \"TAXONOMY_LIST_ERROR\", message: \"Failed to list taxonomies\" },\n\t\t};\n\t}\n}\n\n/**\n * Create a new taxonomy definition\n */\nexport async function handleTaxonomyCreate(\n\tdb: Kysely<Database>,\n\tinput: {\n\t\tname: string;\n\t\tlabel: string;\n\t\tlabelSingular?: string;\n\t\thierarchical?: boolean;\n\t\tcollections?: string[];\n\t\tlocale?: string;\n\t\ttranslationOf?: string;\n\t},\n): Promise<ApiResult<{ taxonomy: TaxonomyDef }>> {\n\ttry {\n\t\tconst locale = input.locale ? resolveConfiguredLocale(input.locale) : undefined;\n\t\tif (!NAME_PATTERN.test(input.name)) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: {\n\t\t\t\t\tcode: \"VALIDATION_ERROR\",\n\t\t\t\t\tmessage:\n\t\t\t\t\t\t\"Taxonomy name must start with a letter and contain only lowercase letters, numbers, and underscores\",\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\tconst collections = [...new Set(input.collections ?? [])];\n\t\tif (collections.length > 0) {\n\t\t\tconst existingCollections = await db\n\t\t\t\t.selectFrom(\"_emdash_collections\")\n\t\t\t\t.select(\"slug\")\n\t\t\t\t.where(\"slug\", \"in\", collections)\n\t\t\t\t.execute();\n\t\t\tconst existingSlugs = new Set(existingCollections.map((c) => c.slug));\n\t\t\tconst invalid = collections.filter((c) => !existingSlugs.has(c));\n\t\t\tif (invalid.length > 0) {\n\t\t\t\treturn {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: {\n\t\t\t\t\t\tcode: \"VALIDATION_ERROR\",\n\t\t\t\t\t\tmessage: `Unknown collection(s): ${invalid.join(\", \")}`,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\tlet translationGroup: string | null = null;\n\t\tif (input.translationOf) {\n\t\t\tconst source = await db\n\t\t\t\t.selectFrom(\"_emdash_taxonomy_defs\")\n\t\t\t\t.selectAll()\n\t\t\t\t.where(\"id\", \"=\", input.translationOf)\n\t\t\t\t.executeTakeFirst();\n\t\t\tif (!source) {\n\t\t\t\treturn {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: { code: \"NOT_FOUND\", message: \"Source taxonomy for translation not found\" },\n\t\t\t\t};\n\t\t\t}\n\t\t\ttranslationGroup = source.translation_group ?? source.id;\n\t\t}\n\n\t\t// Duplicate guard scoped to locale (so the same name can exist in ES\n\t\t// and EN).\n\t\tif (locale !== undefined) {\n\t\t\tconst existing = await db\n\t\t\t\t.selectFrom(\"_emdash_taxonomy_defs\")\n\t\t\t\t.select(\"id\")\n\t\t\t\t.where(\"name\", \"=\", input.name)\n\t\t\t\t.where(\"locale\", \"=\", locale)\n\t\t\t\t.executeTakeFirst();\n\t\t\tif (existing) {\n\t\t\t\treturn {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: {\n\t\t\t\t\t\tcode: \"CONFLICT\",\n\t\t\t\t\t\tmessage: `Taxonomy '${input.name}' already exists in locale '${locale}'`,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\tconst id = ulid();\n\t\tawait db\n\t\t\t.insertInto(\"_emdash_taxonomy_defs\")\n\t\t\t.values({\n\t\t\t\tid,\n\t\t\t\tname: input.name,\n\t\t\t\tlabel: input.label,\n\t\t\t\tlabel_singular: input.labelSingular ?? null,\n\t\t\t\thierarchical: input.hierarchical ? 1 : 0,\n\t\t\t\tcollections: JSON.stringify(collections),\n\t\t\t\t...(locale !== undefined ? { locale } : {}),\n\t\t\t\ttranslation_group: translationGroup ?? id,\n\t\t\t})\n\t\t\t.execute();\n\n\t\t// A new def changes which taxonomies exist — drop the isolate-wide\n\t\t// defs/names caches so this isolate reflects it immediately.\n\t\tinvalidateTaxonomyDefsCache();\n\n\t\tconst row = await db\n\t\t\t.selectFrom(\"_emdash_taxonomy_defs\")\n\t\t\t.selectAll()\n\t\t\t.where(\"id\", \"=\", id)\n\t\t\t.executeTakeFirstOrThrow();\n\t\treturn { success: true, data: { taxonomy: rowToDef(row) } };\n\t} catch (error) {\n\t\tif (error instanceof Error && error.message.includes(\"UNIQUE constraint failed\")) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: { code: \"CONFLICT\", message: `Taxonomy '${input.name}' already exists` },\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: { code: \"TAXONOMY_CREATE_ERROR\", message: \"Failed to create taxonomy\" },\n\t\t};\n\t}\n}\n\n/**\n * List every locale translation of a taxonomy def (by id or translation_group).\n */\nexport async function handleTaxonomyDefTranslations(\n\tdb: Kysely<Database>,\n\tidOrGroup: string,\n): Promise<ApiResult<TaxonomyDefTranslationsResponse>> {\n\ttry {\n\t\tconst anchor = await db\n\t\t\t.selectFrom(\"_emdash_taxonomy_defs\")\n\t\t\t.selectAll()\n\t\t\t.where((eb) => eb.or([eb(\"id\", \"=\", idOrGroup), eb(\"translation_group\", \"=\", idOrGroup)]))\n\t\t\t.executeTakeFirst();\n\t\tif (!anchor) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: { code: \"NOT_FOUND\", message: \"Taxonomy not found\" },\n\t\t\t};\n\t\t}\n\t\tconst group = anchor.translation_group ?? anchor.id;\n\t\tconst rows = await db\n\t\t\t.selectFrom(\"_emdash_taxonomy_defs\")\n\t\t\t.selectAll()\n\t\t\t.where(\"translation_group\", \"=\", group)\n\t\t\t.orderBy(\"locale\", \"asc\")\n\t\t\t.execute();\n\t\treturn {\n\t\t\tsuccess: true,\n\t\t\tdata: {\n\t\t\t\ttranslationGroup: group,\n\t\t\t\ttranslations: rows.map((r) => ({\n\t\t\t\t\tid: r.id,\n\t\t\t\t\tname: r.name,\n\t\t\t\t\tlabel: r.label,\n\t\t\t\t\tlocale: r.locale,\n\t\t\t\t})),\n\t\t\t},\n\t\t};\n\t} catch {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: {\n\t\t\t\tcode: \"TAXONOMY_TRANSLATIONS_ERROR\",\n\t\t\t\tmessage: \"Failed to list taxonomy translations\",\n\t\t\t},\n\t\t};\n\t}\n}\n\n// ---------------------------------------------------------------------------\n// Term handlers\n// ---------------------------------------------------------------------------\n\n/**\n * List all terms for a taxonomy (returns tree for hierarchical taxonomies)\n */\nexport async function handleTermList(\n\tdb: Kysely<Database>,\n\ttaxonomyName: string,\n\toptions: { locale?: string; includeCounts?: boolean } = {},\n): Promise<ApiResult<TermListResponse>> {\n\ttry {\n\t\t// Definitions are per-locale but terms aren't bound to the def's locale —\n\t\t// just ensure the taxonomy exists somewhere.\n\t\tconst lookup = await requireTaxonomyDef(db, taxonomyName);\n\t\tif (!lookup.success) return lookup;\n\n\t\tconst repo = new TaxonomyRepository(db);\n\t\tconst locale = options.locale ? resolveConfiguredLocale(options.locale) : undefined;\n\t\tconst terms = await repo.findByName(taxonomyName, { locale });\n\n\t\t// Counts match what visitors see on the public site: published (or\n\t\t// scheduled-and-due) entries that aren't soft-deleted, scoped to the\n\t\t// taxonomy's declared collections — one query for the whole list.\n\t\t// content_taxonomies.taxonomy_id stores the translation_group, so we\n\t\t// look up by group and map back to each term's id.\n\t\tconst includeCounts = options.includeCounts ?? true;\n\t\tconst countsByGroup = includeCounts\n\t\t\t? await fetchVisibleTermCounts(db, taxonomyName, defCollections(lookup.def))\n\t\t\t: undefined;\n\n\t\tconst termData: TermWithCount[] = terms.map((term) => ({\n\t\t\tid: term.id,\n\t\t\tname: term.name,\n\t\t\tslug: term.slug,\n\t\t\tlabel: term.label,\n\t\t\tparentId: term.parentId,\n\t\t\tdescription: typeof term.data?.description === \"string\" ? term.data.description : undefined,\n\t\t\tchildren: [],\n\t\t\t...(countsByGroup && { count: countsByGroup.get(term.translationGroup ?? term.id) ?? 0 }),\n\t\t\tlocale: term.locale,\n\t\t\ttranslationGroup: term.translationGroup,\n\t\t}));\n\n\t\tconst isHierarchical = lookup.def.hierarchical === 1;\n\t\tconst result = isHierarchical ? buildTree(termData) : termData;\n\t\treturn { success: true, data: { terms: result } };\n\t} catch (error) {\n\t\tconsole.error(\"[taxonomies] term list failed:\", error);\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: { code: \"TERM_LIST_ERROR\", message: \"Failed to list terms\" },\n\t\t};\n\t}\n}\n\n/**\n * Set the manual order of one sibling group.\n *\n * `ids` names the terms to move, in the desired order; each is a row id or a\n * translation_group and resolves to the latter, because a position belongs to a\n * term rather than to one of its locales. Reordering never reparents — moving a\n * term under a different parent is a term update.\n *\n * The group is `(taxonomy, parentId)` and has no locale: `parentId` is the\n * parent's translation_group (a row id is accepted and resolved), and `null`\n * selects the top level — which for a flat taxonomy is every term.\n *\n * `ids` may be a *subset* of the group, and the listed terms are permuted\n * within the positions they already occupy. A locale only renders the terms\n * translated into it, so a caller often cannot name every member; a member left\n * out keeps its place, which is also what makes a stale list harmless.\n */\nexport async function handleTermReorder(\n\tdb: Kysely<Database>,\n\ttaxonomyName: string,\n\tinput: { parentId?: string | null; ids: string[] },\n): Promise<ApiResult<TermReorderResponse>> {\n\ttry {\n\t\tconst lookup = await requireTaxonomyDef(db, taxonomyName);\n\t\tif (!lookup.success) return lookup;\n\n\t\tconst repo = new TaxonomyRepository(db);\n\n\t\tlet parentId = input.parentId ?? null;\n\t\tif (parentId !== null) {\n\t\t\t// Children store the parent's translation_group, so a caller passing a\n\t\t\t// row id still addresses the right group. A parent whose anchor row is\n\t\t\t// gone keeps the value as given (see TaxonomyRepository.resolveParentRef).\n\t\t\tconst parent = await repo.findById(parentId);\n\t\t\tif (parent) parentId = parent.translationGroup ?? parent.id;\n\t\t}\n\n\t\t// Every locale's rows: membership is locale-agnostic, and a term the\n\t\t// caller can't see still holds its slot.\n\t\t// The order carries into how ties are resolved, so it must be stable\n\t\t// across calls; with locales interleaved a tie falls to whichever\n\t\t// locale's label sorts first, not to the order the caller rendered.\n\t\tconst members = await repo.findByName(taxonomyName, { parentId });\n\t\tconst siblings: SiblingPosition[] = [];\n\t\tconst seen = new Set<string>();\n\t\tconst resolve = new Map<string, string>();\n\t\tfor (const term of members) {\n\t\t\tconst group = term.translationGroup ?? term.id;\n\t\t\tif (!seen.has(group)) {\n\t\t\t\tseen.add(group);\n\t\t\t\tsiblings.push({ group, position: term.sortOrder });\n\t\t\t}\n\t\t\t// Both spellings resolve to the group: a row id, and the group itself for\n\t\t\t// a caller that already holds one — including when its anchor row is gone\n\t\t\t// and no member's id matches it.\n\t\t\tresolve.set(group, group);\n\t\t\tresolve.set(term.id, group);\n\t\t}\n\n\t\tconst groups: string[] = [];\n\t\tfor (const id of input.ids) {\n\t\t\tconst group = resolve.get(id);\n\t\t\tif (!group) {\n\t\t\t\treturn {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: {\n\t\t\t\t\t\tcode: \"REORDER_MISMATCH\",\n\t\t\t\t\t\tmessage: `Term \"${id}\" is not in the sibling group being reordered`,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (groups.includes(group)) {\n\t\t\t\treturn {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: {\n\t\t\t\t\t\tcode: \"REORDER_MISMATCH\",\n\t\t\t\t\t\tmessage: `Term \"${id}\" is listed more than once`,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t\tgroups.push(group);\n\t\t}\n\n\t\tawait repo.reorder(groups, siblings);\n\t\tinvalidateTermCache();\n\n\t\treturn { success: true, data: { reordered: true } };\n\t} catch (error) {\n\t\tconsole.error(\"[taxonomies] term reorder failed:\", error);\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: { code: \"TERM_REORDER_ERROR\", message: \"Failed to reorder terms\" },\n\t\t};\n\t}\n}\n\n/**\n * Validate a parent term reference for create/update.\n *\n * Returns `null` on success or a structured error message that callers\n * wrap in their own ApiResult.\n *\n * - `parentId === undefined` -> no-op (no parent change requested).\n * - `parentId === null` -> caller intends to detach; no-op here.\n * - parent must exist (FK exists -> term row not soft-deleted).\n * - parent must live in the same taxonomy.\n * - reject a parent in the term's own translation_group (self-parent),\n * including the create path: a translation inherits its source's group, so\n * `selfGroup` carries that prospective group when `termId` is absent.\n * - on update, walk up the parent chain to detect cycles.\n */\nasync function validateParentTerm(\n\trepo: TaxonomyRepository,\n\ttaxonomyName: string,\n\ttermId: string | undefined,\n\tparentId: string | null | undefined,\n\tselfGroup?: string | null,\n): Promise<{ code: \"VALIDATION_ERROR\"; message: string } | null> {\n\tif (parentId === undefined || parentId === null) return null;\n\n\tconst parent = await repo.findById(parentId);\n\tif (!parent) {\n\t\treturn {\n\t\t\tcode: \"VALIDATION_ERROR\",\n\t\t\tmessage: `Parent term '${parentId}' not found`,\n\t\t};\n\t}\n\tif (parent.name !== taxonomyName) {\n\t\treturn {\n\t\t\tcode: \"VALIDATION_ERROR\",\n\t\t\tmessage: `Parent term '${parentId}' belongs to taxonomy '${parent.name}', not '${taxonomyName}'`,\n\t\t};\n\t}\n\n\t// Parentage keys off translation_group (what `parent_id` persists), so the\n\t// self-parent and cycle checks compare groups, not row ids — picking a\n\t// sibling translation of the term as its parent is still self-parenting.\n\tconst parentGroup = parent.translationGroup ?? parent.id;\n\tlet termGroup: string | null = selfGroup ?? null;\n\tif (termId !== undefined) {\n\t\tconst term = await repo.findById(termId);\n\t\ttermGroup = term ? (term.translationGroup ?? term.id) : termId;\n\t}\n\tif (termGroup !== null && parentGroup === termGroup) {\n\t\treturn {\n\t\t\tcode: \"VALIDATION_ERROR\",\n\t\t\tmessage: \"A term cannot be its own parent\",\n\t\t};\n\t}\n\n\t// Walk up the parent chain. Two checks fold into one walk:\n\t// - Cycle detection (only on update — a non-existent term-being-\n\t// created can't be its own ancestor): if the walk revisits termId\n\t// the proposed parent makes the term a descendant of itself.\n\t// - Depth bound: refuse to extend a chain past MAX_DEPTH ancestors.\n\t// Runs on both create and update so a malicious or buggy caller\n\t// can't grow the tree without limit.\n\t//\n\t// The depth-exceeded error fires only when we hit the limit AND there\n\t// was still chain to walk — a legitimate chain of exactly MAX_DEPTH\n\t// ancestors exits with `cursor === null` and is accepted.\n\t// `parent_id` stores a translation_group, which always equals the anchor\n\t// row's id, so findById(cursor) still resolves each ancestor.\n\tconst MAX_DEPTH = 100;\n\tlet cursor: string | null = parent.parentId;\n\tlet steps = 0;\n\twhile (cursor !== null && steps < MAX_DEPTH) {\n\t\tif (termGroup !== null && cursor === termGroup) {\n\t\t\treturn {\n\t\t\t\tcode: \"VALIDATION_ERROR\",\n\t\t\t\tmessage: \"Cycle detected: cannot make a descendant the parent\",\n\t\t\t};\n\t\t}\n\t\tconst next = await repo.findById(cursor);\n\t\tif (!next) break;\n\t\tcursor = next.parentId;\n\t\tsteps++;\n\t}\n\tif (cursor !== null && steps >= MAX_DEPTH) {\n\t\treturn {\n\t\t\tcode: \"VALIDATION_ERROR\",\n\t\t\tmessage: \"Parent chain exceeds maximum depth\",\n\t\t};\n\t}\n\n\treturn null;\n}\n\n/**\n * Create a new term in a taxonomy\n */\nexport async function handleTermCreate(\n\tdb: Kysely<Database>,\n\ttaxonomyName: string,\n\tinput: {\n\t\tslug: string;\n\t\tlabel: string;\n\t\tparentId?: string | null;\n\t\tdescription?: string;\n\t\tlocale?: string;\n\t\ttranslationOf?: string;\n\t},\n): Promise<ApiResult<TermResponse>> {\n\ttry {\n\t\tconst locale = input.locale ? resolveConfiguredLocale(input.locale) : undefined;\n\t\t// Taxonomy definitions are per-locale, but terms can exist in any locale\n\t\t// regardless of whether the def has been translated there. Look up the\n\t\t// def across all locales — we only care that it *exists*.\n\t\tconst lookup = await requireTaxonomyDef(db, taxonomyName);\n\t\tif (!lookup.success) return lookup;\n\n\t\tconst repo = new TaxonomyRepository(db);\n\n\t\t// Coerce empty-string parentId to undefined (treat as \"no parent\").\n\t\tconst parentId =\n\t\t\tinput.parentId === \"\" || input.parentId === undefined ? undefined : input.parentId;\n\n\t\t// Conflict check is scoped to locale (per-locale slugs are unique).\n\t\tconst existing = await repo.findBySlug(taxonomyName, input.slug, locale);\n\t\tif (existing) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: {\n\t\t\t\t\tcode: \"CONFLICT\",\n\t\t\t\t\tmessage: locale\n\t\t\t\t\t\t? `Term '${input.slug}' already exists in '${taxonomyName}' (${locale})`\n\t\t\t\t\t\t: `Term with slug '${input.slug}' already exists in taxonomy '${taxonomyName}'`,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\t// No locale re-pointing needed: `repo.create` persists the parent's\n\t\t// translation_group in `parent_id`, so a child stays nested under the\n\t\t// parent in every locale automatically — including parents translated\n\t\t// after the child was created.\n\n\t\t// A translation inherits its source's translation_group; pass that\n\t\t// prospective group so validateParentTerm can reject a parent in the same\n\t\t// group (cross-locale self-parent) even though the term doesn't exist yet.\n\t\tlet selfGroup: string | null = null;\n\t\tif (input.translationOf) {\n\t\t\tconst source = await repo.findById(input.translationOf);\n\t\t\tselfGroup = source ? (source.translationGroup ?? source.id) : null;\n\t\t}\n\n\t\t// Validate parentId: must exist AND belong to the same taxonomy.\n\t\t// (Cycle check is N/A on create — the term doesn't exist yet.)\n\t\tconst parentError = await validateParentTerm(\n\t\t\trepo,\n\t\t\ttaxonomyName,\n\t\t\tundefined,\n\t\t\tparentId,\n\t\t\tselfGroup,\n\t\t);\n\t\tif (parentError) {\n\t\t\treturn { success: false, error: parentError };\n\t\t}\n\n\t\tconst term = await repo.create({\n\t\t\tname: taxonomyName,\n\t\t\tslug: input.slug,\n\t\t\tlabel: input.label,\n\t\t\tparentId: parentId ?? undefined,\n\t\t\tdata: input.description ? { description: input.description } : undefined,\n\t\t\tlocale,\n\t\t\ttranslationOf: input.translationOf,\n\t\t});\n\n\t\tinvalidateTermCache();\n\n\t\treturn {\n\t\t\tsuccess: true,\n\t\t\tdata: {\n\t\t\t\tterm: {\n\t\t\t\t\tid: term.id,\n\t\t\t\t\tname: term.name,\n\t\t\t\t\tslug: term.slug,\n\t\t\t\t\tlabel: term.label,\n\t\t\t\t\tparentId: term.parentId,\n\t\t\t\t\tdescription:\n\t\t\t\t\t\ttypeof term.data?.description === \"string\" ? term.data.description : undefined,\n\t\t\t\t\tlocale: term.locale,\n\t\t\t\t\ttranslationGroup: term.translationGroup,\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t} catch {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: { code: \"TERM_CREATE_ERROR\", message: \"Failed to create term\" },\n\t\t};\n\t}\n}\n\n/**\n * Get a single term by slug\n */\nexport async function handleTermGet(\n\tdb: Kysely<Database>,\n\ttaxonomyName: string,\n\ttermSlug: string,\n\toptions: { locale?: string } = {},\n): Promise<ApiResult<TermGetResponse>> {\n\ttry {\n\t\tconst repo = new TaxonomyRepository(db);\n\t\tconst locale = options.locale ? resolveConfiguredLocale(options.locale) : undefined;\n\t\tconst term = await repo.findBySlug(taxonomyName, termSlug, locale);\n\n\t\tif (!term) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: {\n\t\t\t\t\tcode: \"NOT_FOUND\",\n\t\t\t\t\tmessage: `Term '${termSlug}' not found in taxonomy '${taxonomyName}'`,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\t// Count matches public visibility (published or scheduled-and-due, not\n\t\t// soft-deleted) scoped to the def's declared collections. The def lookup\n\t\t// is lenient: a term whose def is missing still resolves, with count 0.\n\t\tconst lookup = await requireTaxonomyDef(db, taxonomyName);\n\t\tconst counts = await fetchVisibleTermCounts(\n\t\t\tdb,\n\t\t\ttaxonomyName,\n\t\t\tlookup.success ? defCollections(lookup.def) : [],\n\t\t);\n\t\tconst count = counts.get(term.translationGroup ?? term.id) ?? 0;\n\t\t// Children share this term's translation_group as their parent_id; scope\n\t\t// to the term's own locale so the response stays within one locale's tree.\n\t\tconst children = await repo.findChildren(term.id, term.locale);\n\n\t\treturn {\n\t\t\tsuccess: true,\n\t\t\tdata: {\n\t\t\t\tterm: {\n\t\t\t\t\tid: term.id,\n\t\t\t\t\tname: term.name,\n\t\t\t\t\tslug: term.slug,\n\t\t\t\t\tlabel: term.label,\n\t\t\t\t\tparentId: term.parentId,\n\t\t\t\t\tdescription:\n\t\t\t\t\t\ttypeof term.data?.description === \"string\" ? term.data.description : undefined,\n\t\t\t\t\tcount,\n\t\t\t\t\tchildren: children.map((c) => ({ id: c.id, slug: c.slug, label: c.label })),\n\t\t\t\t\tlocale: term.locale,\n\t\t\t\t\ttranslationGroup: term.translationGroup,\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t} catch {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: { code: \"TERM_GET_ERROR\", message: \"Failed to get term\" },\n\t\t};\n\t}\n}\n\n/** List every translation of a term (by id or translation_group). */\nexport async function handleTermTranslations(\n\tdb: Kysely<Database>,\n\tidOrGroup: string,\n): Promise<ApiResult<TermTranslationsResponse>> {\n\ttry {\n\t\tconst anchor = await db\n\t\t\t.selectFrom(\"taxonomies\")\n\t\t\t.selectAll()\n\t\t\t.where((eb) => eb.or([eb(\"id\", \"=\", idOrGroup), eb(\"translation_group\", \"=\", idOrGroup)]))\n\t\t\t.executeTakeFirst();\n\t\tif (!anchor) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: { code: \"NOT_FOUND\", message: \"Term not found\" },\n\t\t\t};\n\t\t}\n\t\tconst group = anchor.translation_group ?? anchor.id;\n\t\tconst rows = await db\n\t\t\t.selectFrom(\"taxonomies\")\n\t\t\t.selectAll()\n\t\t\t.where(\"translation_group\", \"=\", group)\n\t\t\t.orderBy(\"locale\", \"asc\")\n\t\t\t.execute();\n\t\treturn {\n\t\t\tsuccess: true,\n\t\t\tdata: {\n\t\t\t\ttranslationGroup: group,\n\t\t\t\ttranslations: rows.map((r) => ({\n\t\t\t\t\tid: r.id,\n\t\t\t\t\tslug: r.slug,\n\t\t\t\t\tlabel: r.label,\n\t\t\t\t\tlocale: r.locale,\n\t\t\t\t})),\n\t\t\t},\n\t\t};\n\t} catch {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: { code: \"TERM_TRANSLATIONS_ERROR\", message: \"Failed to list term translations\" },\n\t\t};\n\t}\n}\n\n/**\n * Update a term\n */\nexport async function handleTermUpdate(\n\tdb: Kysely<Database>,\n\ttaxonomyName: string,\n\ttermSlug: string,\n\tinput: { slug?: string; label?: string; parentId?: string | null; description?: string },\n\toptions: { locale?: string } = {},\n): Promise<ApiResult<TermResponse>> {\n\ttry {\n\t\tconst repo = new TaxonomyRepository(db);\n\t\tconst locale = options.locale ? resolveConfiguredLocale(options.locale) : undefined;\n\t\tconst term = await repo.findBySlug(taxonomyName, termSlug, locale);\n\n\t\tif (!term) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: {\n\t\t\t\t\tcode: \"NOT_FOUND\",\n\t\t\t\t\tmessage: `Term '${termSlug}' not found in taxonomy '${taxonomyName}'`,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\t// Coerce empty-string slug/parentId to undefined (treat as \"no change\").\n\t\t// `null` parentId is a valid request meaning \"detach from parent\".\n\t\tconst newSlug = input.slug === \"\" || input.slug === undefined ? undefined : input.slug;\n\t\tconst newParentId =\n\t\t\tinput.parentId === \"\" || input.parentId === undefined ? undefined : input.parentId;\n\n\t\t// Check if new slug conflicts (per-locale uniqueness).\n\t\tif (newSlug !== undefined && newSlug !== termSlug) {\n\t\t\tconst existing = await repo.findBySlug(taxonomyName, newSlug, locale);\n\t\t\tif (existing && existing.id !== term.id) {\n\t\t\t\treturn {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: {\n\t\t\t\t\t\tcode: \"CONFLICT\",\n\t\t\t\t\t\tmessage: `Term with slug '${newSlug}' already exists in taxonomy '${taxonomyName}'`,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\t// Validate parentId: existence, same-taxonomy, no self-parent, no cycle.\n\t\tconst parentError = await validateParentTerm(repo, taxonomyName, term.id, newParentId);\n\t\tif (parentError) {\n\t\t\treturn { success: false, error: parentError };\n\t\t}\n\n\t\tconst updated = await repo.update(term.id, {\n\t\t\tslug: newSlug,\n\t\t\tlabel: input.label,\n\t\t\tparentId: newParentId,\n\t\t\tdata: input.description !== undefined ? { description: input.description } : undefined,\n\t\t});\n\n\t\tinvalidateTermCache();\n\n\t\tif (!updated) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: { code: \"TERM_UPDATE_ERROR\", message: \"Failed to update term\" },\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\tsuccess: true,\n\t\t\tdata: {\n\t\t\t\tterm: {\n\t\t\t\t\tid: updated.id,\n\t\t\t\t\tname: updated.name,\n\t\t\t\t\tslug: updated.slug,\n\t\t\t\t\tlabel: updated.label,\n\t\t\t\t\tparentId: updated.parentId,\n\t\t\t\t\tdescription:\n\t\t\t\t\t\ttypeof updated.data?.description === \"string\" ? updated.data.description : undefined,\n\t\t\t\t\tlocale: updated.locale,\n\t\t\t\t\ttranslationGroup: updated.translationGroup,\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t} catch {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: { code: \"TERM_UPDATE_ERROR\", message: \"Failed to update term\" },\n\t\t};\n\t}\n}\n\n/**\n * Delete a term\n */\nexport async function handleTermDelete(\n\tdb: Kysely<Database>,\n\ttaxonomyName: string,\n\ttermSlug: string,\n\toptions: { locale?: string } = {},\n): Promise<ApiResult<{ deleted: true }>> {\n\ttry {\n\t\tconst repo = new TaxonomyRepository(db);\n\t\tconst locale = options.locale ? resolveConfiguredLocale(options.locale) : undefined;\n\t\tconst term = await repo.findBySlug(taxonomyName, termSlug, locale);\n\n\t\tif (!term) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: {\n\t\t\t\t\tcode: \"NOT_FOUND\",\n\t\t\t\t\tmessage: `Term '${termSlug}' not found in taxonomy '${taxonomyName}'`,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\t// Block deletion if the term's group still parents any child in any\n\t\t// locale — children store this group in parent_id, so removing the term\n\t\t// would orphan them (or null their parent_id via the self-FK).\n\t\tconst children = await repo.findChildren(term.id);\n\t\tif (children.length > 0) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: {\n\t\t\t\t\tcode: \"VALIDATION_ERROR\",\n\t\t\t\t\tmessage: \"Cannot delete term with children. Delete children first.\",\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\tconst deleted = await repo.delete(term.id);\n\t\tif (!deleted) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: { code: \"TERM_DELETE_ERROR\", message: \"Failed to delete term\" },\n\t\t\t};\n\t\t}\n\n\t\tinvalidateTermCache();\n\t\treturn { success: true, data: { deleted: true } };\n\t} catch {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: { code: \"TERM_DELETE_ERROR\", message: \"Failed to delete term\" },\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmBA,MAAM,eAAe;;;;AAoFrB,SAAS,UAAU,WAA6C;CAK/D,MAAM,gCAAgB,IAAI,KAA4B;CACtD,MAAM,QAAyB,EAAE;AACjC,MAAK,MAAM,QAAQ,UAClB,eAAc,IAAI,GAAG,KAAK,OAAO,IAAI,KAAK,oBAAoB,KAAK,MAAM,KAAK;AAE/E,MAAK,MAAM,QAAQ,WAAW;EAC7B,MAAM,SAAS,KAAK,WACjB,cAAc,IAAI,GAAG,KAAK,OAAO,IAAI,KAAK,WAAW,GACrD;AACH,MAAI,OACH,QAAO,SAAS,KAAK,KAAK;MAE1B,OAAM,KAAK,KAAK;;AAGlB,QAAO;;;;;;AAOR,eAAe,mBACd,IACA,MACA,QAIC;CACD,IAAI,QAAQ,GAAG,WAAW,wBAAwB,CAAC,WAAW,CAAC,MAAM,QAAQ,KAAK,KAAK;AACvF,KAAI,WAAW,OAAW,SAAQ,MAAM,MAAM,UAAU,KAAK,OAAO;CACpE,MAAM,MAAM,MAAM,MAAM,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AS;GACT,OAAO;IACN,MAAM;IACN,SAAS,SAAS,SAAS,2BAA2B,aAAa;IACnE;GACD;AAOF,OADiB,MAAM,KAAK,aAAa,KAAK,GAAG,EACpC,SAAS,EACrB,QAAO;GACN,SAAS;GACT,OAAO;IACN,MAAM;IACN,SAAS;IACT;GACD;AAIF,MAAI,CADY,MAAM,KAAK,OAAO,KAAK,GAAG,CAEzC,QAAO;GACN,SAAS;GACT,OAAO;IAAE,MAAM;IAAqB,SAAS;IAAyB;GACtE;AAGF,uBAAqB;AACrB,SAAO;GAAE,SAAS;GAAM,MAAM,EAAE,SAAS,MAAM;GAAE;SAC1C;AACP,SAAO;GACN,SAAS;GACT,OAAO;IAAE,MAAM;IAAqB,SAAS;IAAyB;GACtE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"taxonomies-CLN1N92E.mjs","names":[],"sources":["../src/taxonomies/term-counts.ts","../src/taxonomies/index.ts"],"sourcesContent":["/**\n * Shared visible-usage counts for taxonomy terms (issue #581).\n *\n * `content_taxonomies` rows are written for every entry regardless of status\n * and are never pruned on unpublish/trash, so counting the pivot directly\n * inflates counts with drafts and soft-deleted entries. Every user-facing\n * count (public widget, single-term page, admin term list) must instead count\n * only entries that have completed publication:\n * `status = 'published'` AND `deleted_at IS NULL`.\n *\n * The public render path is latency-sensitive on D1, so per-collection counts\n * are combined with UNION ALL — one query per taxonomy, never one per\n * collection, split only where the backend caps compound-SELECT terms.\n */\n\nimport type { Kysely } from \"kysely\";\nimport { sql } from \"kysely\";\n\nimport { buildStatusCondition, compoundSelectLimit } from \"../database/dialect-helpers.js\";\nimport type { Database } from \"../database/types.js\";\nimport { validateIdentifier } from \"../database/validate.js\";\nimport { chunks } from \"../utils/chunks.js\";\nimport { isMissingTableError } from \"../utils/db-errors.js\";\n\ninterface CountRow {\n\ttaxonomy_id: string;\n\tcount: number | string | bigint;\n}\n\n/**\n * Per-collection count branch. `taxonomy_id` stores the term's\n * translation_group, so results are keyed by group (locale-independent) and\n * each assignment is counted once no matter how many locales the term has.\n *\n * Scoping to the taxonomy uses `translation_group IN (...)` rather than a\n * join on `taxonomies.id` — the anchor row (id == group) can be deleted while\n * sibling translations survive, and a plain join on `translation_group` would\n * multiply counts by the number of locales.\n *\n * CROSS JOIN with the join predicate in WHERE keeps stats-blind SQLite/D1 from\n * reordering content_taxonomies out of the outer position; it touches ec_* only\n * by primary key. Postgres treats this as an ordinary inner join and plans freely.\n */\nfunction collectionBranch(\n\tdb: Kysely<Database>,\n\ttaxonomyName: string,\n\tcollection: string,\n): ReturnType<typeof sql> {\n\treturn sql`\n\t\tSELECT ct.taxonomy_id AS taxonomy_id, COUNT(*) AS count\n\t\tFROM content_taxonomies AS ct\n\t\tCROSS JOIN ${sql.ref(`ec_${collection}`)} AS e\n\t\tWHERE e.id = ct.entry_id\n\t\t\tAND ct.collection = ${collection}\n\t\t\tAND ct.taxonomy_id IN (SELECT translation_group FROM taxonomies WHERE name = ${taxonomyName})\n\t\t\tAND ${buildStatusCondition(db, \"published\", \"e\")}\n\t\t\tAND e.deleted_at IS NULL\n\t\tGROUP BY ct.taxonomy_id`;\n}\n\nasync function runCounts(\n\tdb: Kysely<Database>,\n\ttaxonomyName: string,\n\tcollections: string[],\n): Promise<Map<string, number>> {\n\tconst branches = collections.map((collection) => collectionBranch(db, taxonomyName, collection));\n\tconst union = sql.join(branches, sql` UNION ALL `);\n\tconst result = await sql<CountRow>`\n\t\tSELECT taxonomy_id, SUM(count) AS count\n\t\tFROM (${union}) AS per_collection\n\t\tGROUP BY taxonomy_id`.execute(db);\n\n\tconst counts = new Map<string, number>();\n\tfor (const row of result.rows) counts.set(row.taxonomy_id, Number(row.count));\n\treturn counts;\n}\n\nfunction addCounts(into: Map<string, number>, from: Map<string, number>): void {\n\tfor (const [group, count] of from) into.set(group, (into.get(group) ?? 0) + count);\n}\n\n/**\n * Counts for one batch of collections, degrading to a query per collection\n * when a declared collection has no ec_* table so the rest still contribute.\n */\nasync function runBatch(\n\tdb: Kysely<Database>,\n\ttaxonomyName: string,\n\tcollections: string[],\n): Promise<Map<string, number>> {\n\ttry {\n\t\treturn await runCounts(db, taxonomyName, collections);\n\t} catch (error) {\n\t\tif (!isMissingTableError(error)) throw error;\n\t}\n\n\tconst counts = new Map<string, number>();\n\tfor (const collection of collections) {\n\t\ttry {\n\t\t\taddCounts(counts, await runCounts(db, taxonomyName, [collection]));\n\t\t} catch (error) {\n\t\t\tif (!isMissingTableError(error)) throw error;\n\t\t}\n\t}\n\treturn counts;\n}\n\n/**\n * Count publicly-visible term assignments for one taxonomy, keyed by the\n * term's translation_group (what `content_taxonomies.taxonomy_id` stores).\n *\n * Counts are scoped to the taxonomy's declared collections — pass\n * `TaxonomyDef.collections` (`_emdash_taxonomy_defs.collections`). Collections\n * whose `ec_*` table doesn't exist (pre-migration drift, a declared collection\n * that was never created) are skipped, yielding a partial-but-correct count\n * rather than a throw.\n *\n * One database round-trip for the whole taxonomy (UNION ALL across\n * collections). On a backend that caps compound-SELECT terms — D1 allows five\n * — the branches are split into one statement per batch, since a taxonomy\n * declaring more collections than that would otherwise take down every path\n * that shows counts. Per-collection sums are commutative, so batching cannot\n * change the total.\n *\n * Callers on the public render path should go through the request-cached\n * wrapper in `taxonomies/index.ts` so a page rendering both the widget and a\n * term detail shares one computation.\n */\nexport async function fetchVisibleTermCounts(\n\tdb: Kysely<Database>,\n\ttaxonomyName: string,\n\tcollections: string[],\n): Promise<Map<string, number>> {\n\tconst unique = [...new Set(collections)];\n\tfor (const collection of unique) validateIdentifier(collection, \"collection slug\");\n\tif (unique.length === 0) return new Map();\n\n\tconst limit = compoundSelectLimit(db);\n\tconst batched = limit === null ? [unique] : chunks(unique, limit);\n\tconst batches = await Promise.all(batched.map((batch) => runBatch(db, taxonomyName, batch)));\n\n\tconst counts = new Map<string, number>();\n\tfor (const batch of batches) addCounts(counts, batch);\n\treturn counts;\n}\n","/**\n * Runtime API for taxonomies.\n *\n * All helpers are locale-aware. When a locale is not passed explicitly we fall\n * back to the request context or the configured `defaultLocale` (see\n * `i18n/resolve.ts`).\n *\n * Because `content_taxonomies.taxonomy_id` stores the translation_group (not a\n * specific term id), the joins here are `taxonomies.translation_group =\n * content_taxonomies.taxonomy_id` + filter by `taxonomies.locale`, which picks\n * the right per-locale term.\n */\n\nimport { resolveLocale, resolveLocaleChain } from \"../i18n/resolve.js\";\nimport { getDb, resetTaxonomyNamesCache } from \"../loader.js\";\nimport {\n\tcachedQuery,\n\tCacheNamespace,\n\tcontentCacheNamespaces,\n\tinvalidateTaxonomyObjectCache,\n\tisObjectCacheActive,\n} from \"../object-cache/index.js\";\nimport { peekRequestCache, requestCached, setRequestCacheEntry } from \"../request-cache.js\";\nimport { getRequestContext } from \"../request-context.js\";\nimport { chunks, SQL_BATCH_SIZE } from \"../utils/chunks.js\";\nimport { isMissingTableError } from \"../utils/db-errors.js\";\nimport { fetchVisibleTermCounts } from \"./term-counts.js\";\nimport type { TaxonomyDef, TaxonomyTerm, TaxonomyTermRow } from \"./types.js\";\n\nexport interface TaxonomyQueryOptions {\n\tlocale?: string;\n}\n\nexport interface TaxonomyTermsOptions extends TaxonomyQueryOptions {\n\t/**\n\t * Populate each term's `count`. Counts aggregate the whole\n\t * `content_taxonomies` pivot against every declared collection, so callers\n\t * that don't render a count should opt out. Defaults to `true`.\n\t */\n\tincludeCounts?: boolean;\n}\n\n/** Invalidate cached taxonomy term data and any content that hydrates terms. */\nexport function invalidateTermCache(): void {\n\tinvalidateTaxonomyObjectCache();\n}\n\n/**\n * Worker-isolate cache for taxonomy definitions, keyed by resolved locale.\n *\n * Taxonomy *definitions* (the \"category\"/\"tag\" taxonomies themselves, not\n * their terms) are read on every public render that hydrates entry terms —\n * `getAllTermsForEntries` → `getCollectionTaxonomyNames` → `getTaxonomyDefs` —\n * but change extremely rarely: they're created via the admin API or applied\n * from a seed, and there is no edit/delete-def path. Caching them across the\n * isolate lifetime drops the per-render `SELECT * FROM _emdash_taxonomy_defs`\n * to once-per-isolate.\n *\n * Stored on globalThis behind a Symbol key (same pattern as\n * `settings/index.ts`) so the bundler duplicating this module across SSR\n * chunks can't produce two independent caches.\n *\n * When the distributed object cache is configured, it is authoritative and this\n * fallback is bypassed so cross-isolate epoch invalidation cannot be undercut\n * by stale per-isolate data on an object-cache miss.\n *\n * **Isolated databases bypass the cache.** Playground / DO preview requests\n * set `requestContext.dbIsIsolated`; they point at a divergent schema, so we\n * skip both reading and writing the global holder and fall back to the\n * per-request cache (same precedent as `getTaxonomyNames` / byline field defs).\n */\ninterface TaxonomyDefsHolder {\n\tversion: number;\n\t/** locale key (\"*\" for \"all locales\") → { version it was fetched at, promise }. */\n\tcache: Map<string, { version: number; promise: Promise<TaxonomyDef[]> }>;\n}\n\nconst TAXONOMY_DEFS_CACHE_KEY = Symbol.for(\"emdash:taxonomy-defs\");\nconst taxonomyDefsStore = globalThis as Record<symbol, unknown>;\nconst defsHolder: TaxonomyDefsHolder =\n\t// eslint-disable-next-line typescript/no-unsafe-type-assertion -- globalThis singleton pattern (see settings/index.ts)\n\t(taxonomyDefsStore[TAXONOMY_DEFS_CACHE_KEY] as TaxonomyDefsHolder | undefined) ??\n\t(() => {\n\t\tconst h: TaxonomyDefsHolder = { version: 0, cache: new Map() };\n\t\ttaxonomyDefsStore[TAXONOMY_DEFS_CACHE_KEY] = h;\n\t\treturn h;\n\t})();\n\n/**\n * Invalidate the isolate-wide taxonomy-definitions cache (and the related\n * loader taxonomy-names cache). Called from every taxonomy-def write path\n * (`handleTaxonomyCreate`, seed application). Other isolates refresh on their\n * next recycle — staleness bounded by isolate lifetime.\n */\nexport function invalidateTaxonomyDefsCache(): void {\n\tdefsHolder.version++;\n\tdefsHolder.cache.clear();\n\tresetTaxonomyNamesCache();\n\tinvalidateTaxonomyObjectCache();\n}\n\n/**\n * Test/internal helper: clear the per-isolate taxonomy-defs cache. Useful for\n * unit tests that insert defs directly and need to force a refetch without\n * going through a write path. Production code should rely on\n * `invalidateTaxonomyDefsCache()`.\n */\nexport function resetTaxonomyDefsCacheForTests(): void {\n\tdefsHolder.version++;\n\tdefsHolder.cache.clear();\n}\n\n/**\n * Fetch taxonomy definitions straight from the database (no caching).\n */\nasync function fetchTaxonomyDefs(locale: string | undefined): Promise<TaxonomyDef[]> {\n\tconst db = await getDb();\n\tlet query = db.selectFrom(\"_emdash_taxonomy_defs\").selectAll();\n\tif (locale !== undefined) query = query.where(\"locale\", \"=\", locale);\n\tconst rows = await query.execute();\n\treturn rows.map(rowToTaxonomyDef);\n}\n\n/**\n * Resolve taxonomy defs through the isolate fallback cache, bypassing it for\n * isolated databases. The returned promise is cached (not the resolved value)\n * so concurrent cold-isolate readers share one in-flight query; a rejection\n * evicts the entry so the next caller retries.\n */\nfunction loadTaxonomyDefs(localeKey: string, locale: string | undefined): Promise<TaxonomyDef[]> {\n\tif (getRequestContext()?.dbIsIsolated === true) {\n\t\treturn fetchTaxonomyDefs(locale);\n\t}\n\tconst existing = defsHolder.cache.get(localeKey);\n\tif (existing && existing.version === defsHolder.version) {\n\t\treturn existing.promise;\n\t}\n\tconst version = defsHolder.version;\n\tconst promise = fetchTaxonomyDefs(locale).catch((error: unknown) => {\n\t\tconst current = defsHolder.cache.get(localeKey);\n\t\tif (current && current.promise === promise) {\n\t\t\tdefsHolder.cache.delete(localeKey);\n\t\t}\n\t\tthrow error;\n\t});\n\tdefsHolder.cache.set(localeKey, { version, promise });\n\treturn promise;\n}\n\n/**\n * Get every taxonomy definition. Definitions are per-locale (one row per\n * locale inside the same translation_group) — by default we resolve to the\n * active locale.\n *\n * Two-tier cache: per-request via `requestCached` (so a single render that\n * hydrates terms for several collections pays at most one call), then\n * per-isolate via the global holder (so warm renders issue zero queries).\n * The `requestCached` key is unchanged so `getTaxonomyDef`'s peek still hits.\n */\nexport async function getTaxonomyDefs(options: TaxonomyQueryOptions = {}): Promise<TaxonomyDef[]> {\n\tconst locale = resolveLocale(options.locale);\n\tconst localeKey = locale ?? \"*\";\n\treturn requestCached(`taxonomy-defs:${localeKey}`, async () => {\n\t\tif (await isObjectCacheActive()) {\n\t\t\treturn cachedQuery({\n\t\t\t\tnamespace: CacheNamespace.TAXONOMIES,\n\t\t\t\tkey: `defs:${localeKey}`,\n\t\t\t\tload: () => fetchTaxonomyDefs(locale),\n\t\t\t});\n\t\t}\n\t\treturn loadTaxonomyDefs(localeKey, locale);\n\t});\n}\n\n/**\n * Get a single taxonomy definition by name. Uses the fallback chain so even\n * if there is no translation for the active locale we still return something.\n *\n * If `getTaxonomyDefs()` has already loaded the full list in this request\n * (which happens during entry-term hydration on every page that renders a\n * collection), search the matching def in memory rather than running a\n * second query against `_emdash_taxonomy_defs`.\n */\nexport async function getTaxonomyDef(\n\tname: string,\n\toptions: TaxonomyQueryOptions = {},\n): Promise<TaxonomyDef | null> {\n\tconst chain = resolveLocaleChain(options.locale);\n\tconst peekKey = `taxonomy-defs:${resolveLocale(options.locale) ?? \"*\"}`;\n\tconst allDefs = peekRequestCache<TaxonomyDef[]>(peekKey);\n\tif (allDefs) {\n\t\tconst defs = await allDefs;\n\t\tif (chain.length === 0) return defs.find((d) => d.name === name) ?? null;\n\t\tfor (const locale of chain) {\n\t\t\tconst found = defs.find((d) => d.name === name && d.locale === locale);\n\t\t\tif (found) return found;\n\t\t}\n\t\treturn null;\n\t}\n\n\treturn requestCached(`taxonomy-def:${name}:${chain.join(\",\")}`, async () => {\n\t\tconst db = await getDb();\n\n\t\tif (chain.length === 0) {\n\t\t\tconst row = await db\n\t\t\t\t.selectFrom(\"_emdash_taxonomy_defs\")\n\t\t\t\t.selectAll()\n\t\t\t\t.where(\"name\", \"=\", name)\n\t\t\t\t.orderBy(\"locale\", \"asc\")\n\t\t\t\t.executeTakeFirst();\n\t\t\treturn row ? rowToTaxonomyDef(row) : null;\n\t\t}\n\n\t\tfor (const locale of chain) {\n\t\t\tconst row = await db\n\t\t\t\t.selectFrom(\"_emdash_taxonomy_defs\")\n\t\t\t\t.selectAll()\n\t\t\t\t.where(\"name\", \"=\", name)\n\t\t\t\t.where(\"locale\", \"=\", locale)\n\t\t\t\t.executeTakeFirst();\n\t\t\tif (row) return rowToTaxonomyDef(row);\n\t\t}\n\t\treturn null;\n\t});\n}\n\n/**\n * Object-cache namespaces for values that embed visible term counts: the\n * taxonomy epoch (term/assignment writes) plus each counted collection's\n * content epoch, so publishing, unpublishing, or trashing an entry\n * invalidates the cached count promptly. Both content namespace generations\n * participate so rolling deployments preserve invalidation in either direction.\n */\nfunction termCountNamespaces(collections: string[]): string[] {\n\treturn [\n\t\t...[...new Set(collections)].flatMap((collection) => contentCacheNamespaces(collection)),\n\t\tCacheNamespace.TAXONOMIES,\n\t];\n}\n\n/**\n * All terms of a taxonomy in a specific locale (flat for non-hierarchical,\n * tree for hierarchical).\n *\n * The term list and the visible-entry counts are loaded and cached separately:\n * the list depends only on the taxonomy epoch, while the counts additionally\n * depend on every counted collection's content epoch and cost an aggregate over\n * the whole assignment pivot. Callers that don't render counts pass\n * `includeCounts: false` and skip that aggregate entirely, while still sharing\n * the term list with callers that do.\n */\nexport async function getTaxonomyTerms(\n\ttaxonomyName: string,\n\toptions: TaxonomyTermsOptions = {},\n): Promise<TaxonomyTerm[]> {\n\tconst locale = resolveLocale(options.locale);\n\tconst def = await getTaxonomyDef(taxonomyName, options);\n\tif (!def) return [];\n\tif (options.includeCounts === false) return getTermList(def, locale);\n\n\t// The two are independent, so run them concurrently to save a round trip.\n\tconst [terms, counts] = await Promise.all([\n\t\tgetTermList(def, locale),\n\t\tgetVisibleTermCounts(def.name, def.collections),\n\t]);\n\treturn withCounts(terms, counts);\n}\n\n/** Terms without counts, under the cache keys the layout prefetch warms. */\nfunction getTermList(def: TaxonomyDef, locale: string | undefined): Promise<TaxonomyTerm[]> {\n\tconst localeKey = locale ?? \"*\";\n\treturn requestCached(`taxonomy-terms:${def.name}:${localeKey}`, () =>\n\t\tcachedQuery({\n\t\t\tnamespace: CacheNamespace.TAXONOMIES,\n\t\t\tkey: `termList:${def.name}:${localeKey}`,\n\t\t\tload: () => loadTaxonomyTerms(def, locale),\n\t\t}),\n\t);\n}\n\n/**\n * Copy a term list with counts attached. Counts are keyed by translation_group\n * (what the pivot stores) and are locale-independent. Rebuilds every node so\n * the shared, cached count-free list is never mutated.\n */\nfunction withCounts(terms: TaxonomyTerm[], counts: Map<string, number>): TaxonomyTerm[] {\n\treturn terms.map((term) => ({\n\t\t...term,\n\t\tcount: counts.get(term.translationGroup ?? term.id) ?? 0,\n\t\tchildren: withCounts(term.children, counts),\n\t}));\n}\n\nasync function loadTaxonomyTerms(\n\tdef: TaxonomyDef,\n\tlocale: string | undefined,\n): Promise<TaxonomyTerm[]> {\n\tconst db = await getDb();\n\n\tlet termsQuery = db\n\t\t.selectFrom(\"taxonomies\")\n\t\t.selectAll()\n\t\t.where(\"name\", \"=\", def.name)\n\t\t.orderBy(\"sort_order\", \"asc\")\n\t\t.orderBy(\"label\", \"asc\");\n\tif (locale !== undefined) termsQuery = termsQuery.where(\"locale\", \"=\", locale);\n\n\tconst rows = await termsQuery.execute();\n\n\tconst flatTerms: TaxonomyTermRow[] = rows.map((row) => ({\n\t\tid: row.id,\n\t\tname: row.name,\n\t\tslug: row.slug,\n\t\tlabel: row.label,\n\t\tparent_id: row.parent_id,\n\t\tdata: row.data,\n\t\tlocale: row.locale,\n\t\ttranslation_group: row.translation_group,\n\t}));\n\n\tif (def.hierarchical) return buildTree(flatTerms);\n\n\treturn flatTerms.map((term) => ({\n\t\tid: term.id,\n\t\tname: term.name,\n\t\tslug: term.slug,\n\t\tlabel: term.label,\n\t\tdescription: term.data ? JSON.parse(term.data).description : undefined,\n\t\tchildren: [],\n\t\tlocale: term.locale,\n\t\ttranslationGroup: term.translation_group,\n\t}));\n}\n\n/**\n * Per-translation-group visible-usage counts for one taxonomy, in a single\n * round-trip (see `fetchVisibleTermCounts`). Counts are locale-independent\n * (the pivot stores translation_group), and the request-cached map is shared\n * by every consumer in the render — the widget (`getTaxonomyTerms`) and the\n * single-term page (`getTerm`) never issue separate count queries.\n */\nfunction getVisibleTermCounts(\n\ttaxonomyName: string,\n\tcollections: string[],\n): Promise<Map<string, number>> {\n\t// The collection scope is part of the key: per-locale rows of the same def\n\t// can drift in their declared collections, and a caller may pass a narrower\n\t// scope. Identical inputs (the widget + term-page hot path) still share one\n\t// entry.\n\tconst scope = [...new Set(collections)].toSorted().join(\",\");\n\treturn requestCached(`taxonomy-term-counts:${taxonomyName}:${scope}`, async () => {\n\t\t// A Map is not JSON-representable — cache the entries, rebuild on read.\n\t\tconst entries = await cachedQuery({\n\t\t\tnamespace: termCountNamespaces(collections),\n\t\t\tkey: `termCounts:${taxonomyName}:${scope}`,\n\t\t\tload: async (): Promise<Array<[string, number]>> => {\n\t\t\t\tconst db = await getDb();\n\t\t\t\treturn [...(await fetchVisibleTermCounts(db, taxonomyName, collections))];\n\t\t\t},\n\t\t});\n\t\treturn new Map(entries);\n\t});\n}\n\n/**\n * Get a single term by (taxonomy, slug). Honours the fallback chain — if the\n * slug exists in a fallback locale, we return that row (useful for deep-linking\n * to a term page when the translation is missing).\n */\nexport async function getTerm(\n\ttaxonomyName: string,\n\tslug: string,\n\toptions: TaxonomyQueryOptions = {},\n): Promise<TaxonomyTerm | null> {\n\tconst chain = resolveLocaleChain(options.locale);\n\t// The def supplies the collections the visible count is scoped to. It is\n\t// resolved before cachedQuery so the entry lives under each collection's\n\t// content namespace — publishing or unpublishing an entry invalidates the\n\t// embedded count (see termCountNamespaces).\n\tconst def = await getTaxonomyDef(taxonomyName, options);\n\tconst collections = def?.collections ?? [];\n\treturn cachedQuery({\n\t\tnamespace: termCountNamespaces(collections),\n\t\tkey: `term:${taxonomyName}:${slug}:${chain.join(\",\")}`,\n\t\tload: () => loadTerm(taxonomyName, slug, chain, collections),\n\t});\n}\n\nasync function loadTerm(\n\ttaxonomyName: string,\n\tslug: string,\n\tchain: string[],\n\tcollections: string[],\n): Promise<TaxonomyTerm | null> {\n\tconst db = await getDb();\n\n\tlet row: Awaited<ReturnType<ReturnType<typeof selectTerm>[\"executeTakeFirst\"]>>;\n\tconst selectTerm = () =>\n\t\tdb\n\t\t\t.selectFrom(\"taxonomies\")\n\t\t\t.selectAll()\n\t\t\t.where(\"name\", \"=\", taxonomyName)\n\t\t\t.where(\"slug\", \"=\", slug);\n\n\tif (chain.length === 0) {\n\t\trow = await selectTerm().orderBy(\"locale\", \"asc\").executeTakeFirst();\n\t} else {\n\t\trow = undefined;\n\t\tfor (const locale of chain) {\n\t\t\trow = await selectTerm().where(\"locale\", \"=\", locale).executeTakeFirst();\n\t\t\tif (row) break;\n\t\t}\n\t}\n\n\tif (!row) return null;\n\n\tlet childrenQuery = db\n\t\t.selectFrom(\"taxonomies\")\n\t\t.selectAll()\n\t\t// Children store the parent's translation_group in parent_id (not a row\n\t\t// id), so a translated parent still owns its children in its own locale.\n\t\t.where(\"parent_id\", \"=\", row.translation_group ?? row.id)\n\t\t.orderBy(\"sort_order\", \"asc\")\n\t\t.orderBy(\"label\", \"asc\");\n\tconst termLocale = row.locale;\n\tif (termLocale) childrenQuery = childrenQuery.where(\"locale\", \"=\", termLocale);\n\n\t// The visible-usage counts and children queries both depend only on the\n\t// term row, so run them concurrently to save a round trip on remote\n\t// databases. The counts map is request-cached per taxonomy — on a page\n\t// that also renders the taxonomy widget it's a free Map lookup.\n\tconst [counts, childRows] = await Promise.all([\n\t\tgetVisibleTermCounts(taxonomyName, collections),\n\t\tchildrenQuery.execute(),\n\t]);\n\tconst count = counts.get(row.translation_group ?? row.id) ?? 0;\n\n\tconst children = childRows.map<TaxonomyTerm>((child) => ({\n\t\tid: child.id,\n\t\tname: child.name,\n\t\tslug: child.slug,\n\t\tlabel: child.label,\n\t\tparentId: child.parent_id ?? undefined,\n\t\tchildren: [],\n\t\tlocale: child.locale,\n\t\ttranslationGroup: child.translation_group,\n\t}));\n\n\treturn {\n\t\tid: row.id,\n\t\tname: row.name,\n\t\tslug: row.slug,\n\t\tlabel: row.label,\n\t\tparentId: row.parent_id ?? undefined,\n\t\tdescription: row.data ? JSON.parse(row.data).description : undefined,\n\t\tchildren,\n\t\tcount,\n\t\tlocale: row.locale,\n\t\ttranslationGroup: row.translation_group,\n\t};\n}\n\n/**\n * Terms assigned to a content entry, resolved into the active locale. Terms\n * whose translation_group lacks a row in the requested locale are omitted.\n */\nexport function getEntryTerms(\n\tcollection: string,\n\tentryId: string,\n\ttaxonomyName?: string,\n\toptions: TaxonomyQueryOptions = {},\n): Promise<TaxonomyTerm[]> {\n\tconst locale = resolveLocale(options.locale);\n\t// requestCached short-circuits to values primed by getAllTermsForEntries\n\t// during entry hydration (same key shape). On a warm content-cache hit\n\t// hydration doesn't run, so the inner cachedQuery serves this from KV\n\t// instead of falling through to D1 on every request.\n\treturn requestCached(\n\t\t`terms:${collection}:${entryId}:${taxonomyName ?? \"*\"}:${locale ?? \"*\"}`,\n\t\t() =>\n\t\t\tcachedQuery({\n\t\t\t\tnamespace: [...contentCacheNamespaces(collection), CacheNamespace.TAXONOMIES],\n\t\t\t\tkey: `entryTerms:${collection}:${entryId}:${taxonomyName ?? \"*\"}:${locale ?? \"*\"}`,\n\t\t\t\tload: async () => {\n\t\t\t\t\tconst db = await getDb();\n\n\t\t\t\t\tlet query = db\n\t\t\t\t\t\t.selectFrom(\"content_taxonomies\")\n\t\t\t\t\t\t.innerJoin(\n\t\t\t\t\t\t\t\"taxonomies\",\n\t\t\t\t\t\t\t\"taxonomies.translation_group\",\n\t\t\t\t\t\t\t\"content_taxonomies.taxonomy_id\",\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.selectAll(\"taxonomies\")\n\t\t\t\t\t\t.where(\"content_taxonomies.collection\", \"=\", collection)\n\t\t\t\t\t\t.where(\"content_taxonomies.entry_id\", \"=\", entryId);\n\n\t\t\t\t\tif (taxonomyName) query = query.where(\"taxonomies.name\", \"=\", taxonomyName);\n\t\t\t\t\tif (locale !== undefined) query = query.where(\"taxonomies.locale\", \"=\", locale);\n\n\t\t\t\t\tconst rows = await query.execute();\n\t\t\t\t\treturn rows.map<TaxonomyTerm>((row) => ({\n\t\t\t\t\t\tid: row.id,\n\t\t\t\t\t\tname: row.name,\n\t\t\t\t\t\tslug: row.slug,\n\t\t\t\t\t\tlabel: row.label,\n\t\t\t\t\t\tparentId: row.parent_id ?? undefined,\n\t\t\t\t\t\tchildren: [],\n\t\t\t\t\t\tlocale: row.locale,\n\t\t\t\t\t\ttranslationGroup: row.translation_group,\n\t\t\t\t\t}));\n\t\t\t\t},\n\t\t\t}),\n\t);\n}\n\n/**\n * Terms for multiple entries of one taxonomy, single query.\n */\nexport async function getTermsForEntries(\n\tcollection: string,\n\tentryIds: string[],\n\ttaxonomyName: string,\n\toptions: TaxonomyQueryOptions = {},\n): Promise<Map<string, TaxonomyTerm[]>> {\n\tconst uniqueIds = [...new Set(entryIds)];\n\tif (uniqueIds.length === 0) return new Map();\n\tconst locale = resolveLocale(options.locale);\n\tconst localeKey = locale ?? \"*\";\n\n\t// The query result is a Map, which JSON can't represent — cache it as an\n\t// array of [entryId, terms] pairs and rebuild the Map on read.\n\tconst load = async (): Promise<Array<[string, TaxonomyTerm[]]>> => {\n\t\tconst result = new Map<string, TaxonomyTerm[]>();\n\t\tfor (const id of uniqueIds) result.set(id, []);\n\n\t\t// Entry-term hydration (getAllTermsForEntries -> primeEntryTermsCache)\n\t\t// seeds the per-entry cache under the same key getEntryTerms uses:\n\t\t// `terms:${collection}:${entryId}:${taxonomyName}:${localeKey}`, storing a\n\t\t// TaxonomyTerm[] (including `[]` for entries with no terms). Satisfy those\n\t\t// from cache and run the batched query only for the ids that missed.\n\t\tconst missedIds: string[] = [];\n\t\ttype CacheRead = { id: string; terms: TaxonomyTerm[] } | { id: string; miss: true };\n\t\tconst cacheReads: Array<Promise<CacheRead>> = [];\n\t\tfor (const id of uniqueIds) {\n\t\t\tconst cached = peekRequestCache<TaxonomyTerm[]>(\n\t\t\t\t`terms:${collection}:${id}:${taxonomyName}:${localeKey}`,\n\t\t\t);\n\t\t\tif (cached) {\n\t\t\t\t// A peeked promise can reject (e.g. a sibling getEntryTerms hit a\n\t\t\t\t// missing table). Treat a rejection as a cache miss so the batched\n\t\t\t\t// query path -- and its isMissingTableError guard below -- still runs,\n\t\t\t\t// rather than propagating an uncaught error.\n\t\t\t\tcacheReads.push(\n\t\t\t\t\tcached.then(\n\t\t\t\t\t\t(terms): CacheRead => ({ id, terms }),\n\t\t\t\t\t\t(): CacheRead => ({ id, miss: true }),\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tmissedIds.push(id);\n\t\t\t}\n\t\t}\n\t\tfor (const read of await Promise.all(cacheReads)) {\n\t\t\tif (\"miss\" in read) {\n\t\t\t\tmissedIds.push(read.id);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// Return a private copy. The cached array and its term objects are shared\n\t\t\t// with getEntryTerms/getAllTermsForEntries (primeEntryTermsCache stores\n\t\t\t// the same references), so a caller that mutates the result -- sorting in\n\t\t\t// place, pushing into `children` -- must not poison the cache. The\n\t\t\t// pre-cache implementation always returned freshly built arrays.\n\t\t\tresult.set(\n\t\t\t\tread.id,\n\t\t\t\tread.terms.map((t) => ({ ...t, children: [...t.children] })),\n\t\t\t);\n\t\t}\n\n\t\tif (missedIds.length === 0) return [...result.entries()];\n\n\t\tconst db = await getDb();\n\t\tfor (const chunk of chunks(missedIds, SQL_BATCH_SIZE)) {\n\t\t\tlet rows;\n\t\t\ttry {\n\t\t\t\tlet query = db\n\t\t\t\t\t.selectFrom(\"content_taxonomies\")\n\t\t\t\t\t.innerJoin(\"taxonomies\", \"taxonomies.translation_group\", \"content_taxonomies.taxonomy_id\")\n\t\t\t\t\t.select([\n\t\t\t\t\t\t\"content_taxonomies.entry_id\",\n\t\t\t\t\t\t\"taxonomies.id\",\n\t\t\t\t\t\t\"taxonomies.name\",\n\t\t\t\t\t\t\"taxonomies.slug\",\n\t\t\t\t\t\t\"taxonomies.label\",\n\t\t\t\t\t\t\"taxonomies.parent_id\",\n\t\t\t\t\t\t\"taxonomies.locale\",\n\t\t\t\t\t\t\"taxonomies.translation_group\",\n\t\t\t\t\t])\n\t\t\t\t\t.where(\"content_taxonomies.collection\", \"=\", collection)\n\t\t\t\t\t.where(\"content_taxonomies.entry_id\", \"in\", chunk)\n\t\t\t\t\t.where(\"taxonomies.name\", \"=\", taxonomyName)\n\t\t\t\t\t// Match the order getAllTermsForEntries (the cache primer) uses, so\n\t\t\t\t\t// cache-hit and DB-miss entries in one result are ordered consistently.\n\t\t\t\t\t.orderBy(\"taxonomies.label\", \"asc\");\n\t\t\t\tif (locale !== undefined) query = query.where(\"taxonomies.locale\", \"=\", locale);\n\t\t\t\trows = await query.execute();\n\t\t\t} catch (error) {\n\t\t\t\tif (isMissingTableError(error)) return [...result.entries()];\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tfor (const row of rows) {\n\t\t\t\tconst term: TaxonomyTerm = {\n\t\t\t\t\tid: row.id,\n\t\t\t\t\tname: row.name,\n\t\t\t\t\tslug: row.slug,\n\t\t\t\t\tlabel: row.label,\n\t\t\t\t\tparentId: row.parent_id ?? undefined,\n\t\t\t\t\tchildren: [],\n\t\t\t\t\tlocale: row.locale,\n\t\t\t\t\ttranslationGroup: row.translation_group,\n\t\t\t\t};\n\t\t\t\tconst terms = result.get(row.entry_id);\n\t\t\t\tif (terms) terms.push(term);\n\t\t\t}\n\t\t}\n\n\t\treturn [...result.entries()];\n\t};\n\n\t// Key on the sorted unique ids. Bound the key length: very large batches\n\t// (rare; they come from collection hydration, already served by the content\n\t// cache) bypass the object cache rather than blow past KV's key limit.\n\tconst idKey = uniqueIds.toSorted().join(\",\");\n\tconst pairs =\n\t\tidKey.length <= 256\n\t\t\t? await cachedQuery({\n\t\t\t\t\tnamespace: [...contentCacheNamespaces(collection), CacheNamespace.TAXONOMIES],\n\t\t\t\t\tkey: `termsForEntries:${collection}:${taxonomyName}:${locale ?? \"*\"}:${idKey}`,\n\t\t\t\t\tload,\n\t\t\t\t})\n\t\t\t: await load();\n\n\treturn new Map(pairs);\n}\n\n/**\n * Batch-fetch terms for multiple entries across ALL taxonomies in one query.\n * Primes the request-cache for subsequent per-entry calls to `getEntryTerms`.\n */\nexport async function getAllTermsForEntries(\n\tcollection: string,\n\tentryIds: string[],\n\toptions: TaxonomyQueryOptions = {},\n): Promise<Map<string, Record<string, TaxonomyTerm[]>>> {\n\tconst result = new Map<string, Record<string, TaxonomyTerm[]>>();\n\tconst uniqueIds = [...new Set(entryIds)];\n\tfor (const id of uniqueIds) result.set(id, {});\n\tif (uniqueIds.length === 0) return result;\n\n\tconst db = await getDb();\n\tconst locale = resolveLocale(options.locale);\n\tconst applicableTaxonomyNames = await getCollectionTaxonomyNames(collection, { locale });\n\n\tfor (const chunk of chunks(uniqueIds, SQL_BATCH_SIZE)) {\n\t\tlet rows;\n\t\ttry {\n\t\t\tlet query = db\n\t\t\t\t.selectFrom(\"content_taxonomies\")\n\t\t\t\t.innerJoin(\"taxonomies\", \"taxonomies.translation_group\", \"content_taxonomies.taxonomy_id\")\n\t\t\t\t.select([\n\t\t\t\t\t\"content_taxonomies.entry_id\",\n\t\t\t\t\t\"taxonomies.id\",\n\t\t\t\t\t\"taxonomies.name\",\n\t\t\t\t\t\"taxonomies.slug\",\n\t\t\t\t\t\"taxonomies.label\",\n\t\t\t\t\t\"taxonomies.parent_id\",\n\t\t\t\t\t\"taxonomies.locale\",\n\t\t\t\t\t\"taxonomies.translation_group\",\n\t\t\t\t])\n\t\t\t\t.where(\"content_taxonomies.collection\", \"=\", collection)\n\t\t\t\t.where(\"content_taxonomies.entry_id\", \"in\", chunk)\n\t\t\t\t.orderBy(\"taxonomies.label\", \"asc\");\n\t\t\tif (locale !== undefined) query = query.where(\"taxonomies.locale\", \"=\", locale);\n\t\t\trows = await query.execute();\n\t\t} catch (error) {\n\t\t\tif (isMissingTableError(error)) {\n\t\t\t\tfor (const id of uniqueIds) {\n\t\t\t\t\tprimeEntryTermsCache(collection, id, {}, applicableTaxonomyNames, locale);\n\t\t\t\t}\n\t\t\t\treturn result;\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\n\t\tfor (const row of rows) {\n\t\t\tconst term: TaxonomyTerm = {\n\t\t\t\tid: row.id,\n\t\t\t\tname: row.name,\n\t\t\t\tslug: row.slug,\n\t\t\t\tlabel: row.label,\n\t\t\t\tparentId: row.parent_id ?? undefined,\n\t\t\t\tchildren: [],\n\t\t\t\tlocale: row.locale,\n\t\t\t\ttranslationGroup: row.translation_group,\n\t\t\t};\n\t\t\tconst byTaxonomy = result.get(row.entry_id);\n\t\t\tif (!byTaxonomy) continue;\n\t\t\tconst existing = byTaxonomy[row.name];\n\t\t\tif (existing) existing.push(term);\n\t\t\telse byTaxonomy[row.name] = [term];\n\t\t}\n\t}\n\n\tfor (const [entryId, byTaxonomy] of result) {\n\t\tprimeEntryTermsCache(collection, entryId, byTaxonomy, applicableTaxonomyNames, locale);\n\t}\n\n\treturn result;\n}\n\n/**\n * Return the list of taxonomy names applicable to a collection, request-\n * cached so a page render only pays for it once.\n *\n * Returns an empty list when taxonomies haven't been defined yet.\n */\nasync function getCollectionTaxonomyNames(\n\tcollection: string,\n\toptions: TaxonomyQueryOptions,\n): Promise<string[]> {\n\ttry {\n\t\tconst defs = await getTaxonomyDefs(options);\n\t\treturn defs.filter((d) => d.collections.includes(collection)).map((d) => d.name);\n\t} catch (error) {\n\t\tif (isMissingTableError(error)) return [];\n\t\tthrow error;\n\t}\n}\n\n/**\n * Pre-populate the request-cache for every getEntryTerms call-shape that\n * could hit this entry:\n *\n * getEntryTerms(collection, entryId) -> key `terms:C:E:*`\n * getEntryTerms(collection, entryId, \"tag\") -> key `terms:C:E:tag`\n * getEntryTerms(collection, entryId, \"category\") -> key `terms:C:E:category`\n * ...one per taxonomy that applies to this collection\n *\n * Taxonomies with no rows on this entry are seeded with `[]` so legacy\n * callers short-circuit to the cached empty array instead of re-querying.\n */\nfunction primeEntryTermsCache(\n\tcollection: string,\n\tentryId: string,\n\tbyTaxonomy: Record<string, TaxonomyTerm[]>,\n\tapplicableTaxonomyNames: string[],\n\tlocale: string | undefined,\n): void {\n\tconst localeKey = locale ?? \"*\";\n\tfor (const name of applicableTaxonomyNames) {\n\t\tsetRequestCacheEntry(\n\t\t\t`terms:${collection}:${entryId}:${name}:${localeKey}`,\n\t\t\tbyTaxonomy[name] ?? [],\n\t\t);\n\t}\n\tfor (const [name, terms] of Object.entries(byTaxonomy)) {\n\t\tsetRequestCacheEntry(`terms:${collection}:${entryId}:${name}:${localeKey}`, terms);\n\t}\n\tconst allTerms = Object.values(byTaxonomy).flat();\n\tsetRequestCacheEntry(`terms:${collection}:${entryId}:*:${localeKey}`, allTerms);\n}\n\n/**\n * Prime the per-entry request cache from terms that were folded into the\n * content query (query.ts `hydrateEntryTerms` fast path), so subsequent\n * `getEntryTerms` calls in the same render hit the cache instead of issuing an\n * N+1 query. Seeds the wildcard key and one key per taxonomy present on the\n * entry — purely from the folded data, with no DB lookup.\n *\n * Unlike `getAllTermsForEntries`, this deliberately does NOT seed `[]` for\n * taxonomies that apply to the collection but have no rows on the entry: doing\n * so would require a `getTaxonomyDefs` query, adding a round trip to every fold\n * render to serve the rarer `getEntryTerms(id, absentTaxonomy)` case from cache.\n * That call simply falls through to its own cached query. Keeping the key shape\n * here (rather than in query.ts) prevents the two from drifting.\n */\nexport function primeFoldedEntryTerms(\n\tcollection: string,\n\tperEntry: Array<{ entryId: string; byTaxonomy: Record<string, TaxonomyTerm[]> }>,\n\toptions: TaxonomyQueryOptions = {},\n): void {\n\tif (perEntry.length === 0) return;\n\tconst locale = resolveLocale(options.locale);\n\tfor (const { entryId, byTaxonomy } of perEntry) {\n\t\tprimeEntryTermsCache(collection, entryId, byTaxonomy, [], locale);\n\t}\n}\n\n/**\n * Get entries by term. Both the lookup (term slug in the active locale) and\n * the content query respect the active locale.\n */\nexport async function getEntriesByTerm(\n\tcollection: string,\n\ttaxonomyName: string,\n\ttermSlug: string,\n\toptions: TaxonomyQueryOptions = {},\n): Promise<Array<{ id: string; data: Record<string, unknown> }>> {\n\tconst { getEmDashCollection } = await import(\"../query.js\");\n\n\tconst queryOptions: Record<string, unknown> = {\n\t\twhere: { [taxonomyName]: termSlug },\n\t};\n\tif (options.locale !== undefined) queryOptions.locale = options.locale;\n\tconst { entries } = await getEmDashCollection(collection, queryOptions);\n\treturn entries;\n}\n\nfunction rowToTaxonomyDef(row: {\n\tid: string;\n\tname: string;\n\tlabel: string;\n\tlabel_singular: string | null;\n\thierarchical: number;\n\tcollections: string | null;\n\tlocale: string;\n\ttranslation_group: string | null;\n}): TaxonomyDef {\n\treturn {\n\t\tid: row.id,\n\t\tname: row.name,\n\t\tlabel: row.label,\n\t\tlabelSingular: row.label_singular ?? undefined,\n\t\thierarchical: row.hierarchical === 1,\n\t\tcollections: row.collections ? JSON.parse(row.collections) : [],\n\t\tlocale: row.locale,\n\t\ttranslationGroup: row.translation_group,\n\t};\n}\n\n/**\n * Build tree structure from flat terms\n */\nfunction buildTree(flatTerms: TaxonomyTermRow[]): TaxonomyTerm[] {\n\t// parent_id holds the parent's translation_group, so link children by it.\n\t// Key by (locale, group): a child's parent lives in the same locale, and an\n\t// unfiltered set mixes locales whose translated siblings share a group —\n\t// keying by group alone would collide and misattach children across locales.\n\tconst byLocaleGroup = new Map<string, TaxonomyTerm>();\n\tconst nodes: TaxonomyTerm[] = [];\n\tconst roots: TaxonomyTerm[] = [];\n\n\tfor (const term of flatTerms) {\n\t\tconst node: TaxonomyTerm = {\n\t\t\tid: term.id,\n\t\t\tname: term.name,\n\t\t\tslug: term.slug,\n\t\t\tlabel: term.label,\n\t\t\tparentId: term.parent_id ?? undefined,\n\t\t\tdescription: term.data ? JSON.parse(term.data).description : undefined,\n\t\t\tchildren: [],\n\t\t\tlocale: term.locale,\n\t\t\ttranslationGroup: term.translation_group,\n\t\t};\n\t\tbyLocaleGroup.set(`${term.locale}::${term.translation_group ?? term.id}`, node);\n\t\tnodes.push(node);\n\t}\n\n\tfor (const node of nodes) {\n\t\tconst parent = node.parentId\n\t\t\t? byLocaleGroup.get(`${node.locale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Q,WAAW;EAC7B,MAAM,OAAqB;GAC1B,IAAI,KAAK;GACT,MAAM,KAAK;GACX,MAAM,KAAK;GACX,OAAO,KAAK;GACZ,UAAU,KAAK,aAAa;GAC5B,aAAa,KAAK,OAAO,KAAK,MAAM,KAAK,KAAK,CAAC,cAAc;GAC7D,UAAU,EAAE;GACZ,QAAQ,KAAK;GACb,kBAAkB,KAAK;GACvB;AACD,gBAAc,IAAI,GAAG,KAAK,OAAO,IAAI,KAAK,qBAAqB,KAAK,MAAM,KAAK;AAC/E,QAAM,KAAK,KAAK;;AAGjB,MAAK,MAAM,QAAQ,OAAO;EACzB,MAAM,SAAS,KAAK,WACjB,cAAc,IAAI,GAAG,KAAK,OAAO,IAAI,KAAK,WAAW,GACrD;AACH,MAAI,OACH,QAAO,SAAS,KAAK,KAAK;MAE1B,OAAM,KAAK,KAAK;;AAIlB,QAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"taxonomy-pOrB2kZe.mjs","names":[],"sources":["../src/database/repositories/taxonomy.ts"],"sourcesContent":["import { sql, type Kysely, type Selectable } from \"kysely\";\nimport { ulid } from \"ulidx\";\n\nimport { invalidateTaxonomyObjectCache } from \"../../object-cache/index.js\";\nimport { isMissingTableError } from \"../../utils/db-errors.js\";\nimport { withTransaction } from \"../transaction.js\";\nimport type { Database, TaxonomyTable } from \"../types.js\";\nimport { validateIdentifier } from \"../validate.js\";\n\n/**\n * Filter + sort columns denormalized from an entry's `ec_*` row onto its\n * `content_taxonomies` pivot rows (migration 051). Stamped at insert time so a\n * newly-tagged entry is immediately seekable by a taxonomy-filtered listing.\n */\ninterface PivotDenorm {\n\tstatus: string | null;\n\tscheduled_at: string | null;\n\tdeleted_at: string | null;\n\tlocale: string | null;\n\tpublished_at: string | null;\n\tcreated_at: string | null;\n}\n\nconst EMPTY_DENORM: PivotDenorm = {\n\tstatus: null,\n\tscheduled_at: null,\n\tdeleted_at: null,\n\tlocale: null,\n\tpublished_at: null,\n\tcreated_at: null,\n};\n\n/** A member of one sibling group and the position it currently holds. */\nexport interface SiblingPosition {\n\tgroup: string;\n\tposition: number;\n}\n\n/**\n * Translation groups per reorder `UPDATE`. Each costs three bound parameters —\n * a CASE `WHEN`/`THEN` pair plus one slot in the `IN` list — which keeps a\n * statement inside D1's 100-parameter ceiling.\n */\nconst GROUPS_PER_UPDATE = 32;\n\n/** Deal the listed groups back out over the slots they hold, in the order given. */\nfunction permuteWithinSlots(\n\tlisted: readonly string[],\n\toccupied: readonly number[],\n): Map<string, number> {\n\tconst slots = occupied.toSorted((a, b) => a - b);\n\tconst target = new Map<string, number>();\n\tlisted.forEach((group, index) => {\n\t\tconst position = slots[index];\n\t\tif (position !== undefined) target.set(group, position);\n\t});\n\treturn target;\n}\n\n/**\n * Renumber a whole sibling group 0..n-1, with the listed groups in the order\n * given and every other member left in the place it already held.\n *\n * Works off each member's index in the sequence rather than its stored value,\n * which is what lets it resolve positions that tie. The sort is stable, so\n * tied members keep the order `siblings` arrives in — deterministic, but a\n * listing that mixes locales breaks a tie on whichever locale's label sorts\n * first, not on the order any one caller rendered.\n */\nfunction renumberSiblings(\n\tlisted: readonly string[],\n\tsiblings: readonly SiblingPosition[],\n): Map<string, number> {\n\tconst sequence = siblings.toSorted((a, b) => a.position - b.position);\n\tconst wanted = new Set(listed);\n\tconst target = new Map<string, number>();\n\tlet next = 0;\n\tsequence.forEach(({ group }, index) => {\n\t\tconst replacement = wanted.has(group) ? listed[next++] : undefined;\n\t\ttarget.set(replacement ?? group, index);\n\t});\n\treturn target;\n}\n\nexport interface Taxonomy {\n\tid: string;\n\tname: string;\n\tslug: string;\n\tlabel: string;\n\tparentId: string | null;\n\tdata: Record<string, unknown> | null;\n\tlocale: string;\n\ttranslationGroup: string | null;\n\t/**\n\t * Position among siblings. Shared by every row of a `translation_group` —\n\t * a term sits in the same place in every locale it is translated into.\n\t */\n\tsortOrder: number;\n}\n\nexport interface CreateTaxonomyInput {\n\tname: string;\n\tslug: string;\n\tlabel: string;\n\tparentId?: string;\n\tdata?: Record<string, unknown>;\n\t/** Omit to let the DB default (current value: 'en') apply. Higher layers\n\t * resolve the locale from the request context / i18n config. */\n\tlocale?: string;\n\t/** When set, links the new term into the source term's translation_group. */\n\ttranslationOf?: string;\n}\n\nexport interface UpdateTaxonomyInput {\n\tslug?: string;\n\tlabel?: string;\n\tparentId?: string | null;\n\tdata?: Record<string, unknown>;\n}\n\nexport interface FindOptions {\n\tparentId?: string | null;\n\tlocale?: string;\n}\n\n/**\n * Taxonomy repository for categories, tags, and other classification.\n *\n * Terms are per-locale. Translations of the same term share a `translation_group`\n * ULID. `content_taxonomies.taxonomy_id` stores the translation_group so a single\n * association spans every locale of a post.\n *\n * The repository does not resolve locale fallbacks on its own — callers supply\n * the locale they want. Runtime helpers and handlers use `getFallbackChain()`\n * from `i18n/config` when they need fallback behaviour.\n *\n * `sort_order` is per translation_group, not per row: every row sharing a\n * translation_group carries the same value, so a term holds one position across\n * all its locales. Sibling groups are keyed on the raw `parent_id` column, which\n * is locale-agnostic for the same reason (it stores the parent's\n * translation_group). Writes must preserve both invariants.\n */\nexport class TaxonomyRepository {\n\tconstructor(private db: Kysely<Database>) {}\n\n\t/**\n\t * Create a new taxonomy term. When `translationOf` is set the new row joins\n\t * the source term's translation_group; otherwise a fresh group is minted\n\t * (matching the migration backfill pattern `translation_group = id`).\n\t */\n\tasync create(input: CreateTaxonomyInput): Promise<Taxonomy> {\n\t\tconst id = ulid();\n\n\t\t// Empty-string parentId is coerced to null defensively. Higher layers\n\t\t// also normalize this — see handleTermCreate / handleTermUpdate.\n\t\t// `parent_id` stores the parent's locale-agnostic translation_group (not a\n\t\t// row id), mirroring content_taxonomies.taxonomy_id, so a child stays\n\t\t// nested in every locale's tree. resolveTranslationGroup accepts either a\n\t\t// row id or an already-resolved group, so this is idempotent.\n\t\tconst parentInput =\n\t\t\tinput.parentId === undefined || input.parentId === \"\" ? null : input.parentId;\n\t\tconst parentId = parentInput ? await this.resolveParentRef(parentInput) : null;\n\n\t\tlet translationGroup = id;\n\t\tlet sortOrder: number | null = null;\n\t\tif (input.translationOf) {\n\t\t\tconst source = await this.findById(input.translationOf);\n\t\t\tif (source?.translationGroup) translationGroup = source.translationGroup;\n\t\t\t// A translation is the same term in another locale, so it takes the\n\t\t\t// group's position — but only while it stays in the group that position\n\t\t\t// belongs to. Landing under a different parent makes it a new member of\n\t\t\t// that sibling group, and the source's position means nothing there.\n\t\t\tif (source && source.parentId === parentId) sortOrder = source.sortOrder;\n\t\t}\n\t\tsortOrder ??= await this.nextSortOrder(input.name, parentId);\n\n\t\tawait this.db\n\t\t\t.insertInto(\"taxonomies\")\n\t\t\t.values({\n\t\t\t\tid,\n\t\t\t\tname: input.name,\n\t\t\t\tslug: input.slug,\n\t\t\t\tlabel: input.label,\n\t\t\t\tparent_id: parentId,\n\t\t\t\tdata: input.data ? JSON.stringify(input.data) : null,\n\t\t\t\tsort_order: sortOrder,\n\t\t\t\t// When omitted, the DB DEFAULT 'en' is used — keeps behaviour\n\t\t\t\t// consistent with ContentRepository and lets higher layers\n\t\t\t\t// supply an explicit locale from request context.\n\t\t\t\t...(input.locale !== undefined ? { locale: input.locale } : {}),\n\t\t\t\ttranslation_group: translationGroup,\n\t\t\t})\n\t\t\t.execute();\n\n\t\tinvalidateTaxonomyObjectCache();\n\n\t\tconst taxonomy = await this.findById(id);\n\t\tif (!taxonomy) throw new Error(\"Failed to create taxonomy\");\n\t\treturn taxonomy;\n\t}\n\n\tasync findById(id: string): Promise<Taxonomy | null> {\n\t\tconst row = await this.db\n\t\t\t.selectFrom(\"taxonomies\")\n\t\t\t.selectAll()\n\t\t\t.where(\"id\", \"=\", id)\n\t\t\t.executeTakeFirst();\n\t\treturn row ? this.rowToTaxonomy(row) : null;\n\t}\n\n\t/**\n\t * Find a term by (name, slug). When `locale` is provided, filter by it.\n\t * When omitted, returns the lowest-locale-code match (deterministic across\n\t * calls). Mirrors `ContentRepository.findBySlug`.\n\t */\n\tasync findBySlug(name: string, slug: string, locale?: string): Promise<Taxonomy | null> {\n\t\tlet query = this.db\n\t\t\t.selectFrom(\"taxonomies\")\n\t\t\t.selectAll()\n\t\t\t.where(\"name\", \"=\", name)\n\t\t\t.where(\"slug\", \"=\", slug);\n\t\tif (locale !== undefined) query = query.where(\"locale\", \"=\", locale);\n\t\tconst row = await query.orderBy(\"locale\", \"asc\").executeTakeFirst();\n\t\treturn row ? this.rowToTaxonomy(row) : null;\n\t}\n\n\t/**\n\t * Get all terms for a taxonomy (e.g., all categories).\n\t *\n\t * `sort_order` carries the manual order set from the admin; it is 0 for\n\t * terms nobody has reordered, so an untouched taxonomy still comes back\n\t * alphabetically. `id asc` is a stable tiebreaker for terms that share both\n\t * — without it the SQL ordering is implementation-defined when they match,\n\t * which breaks keyset pagination over `(label, id)`.\n\t */\n\tasync findByName(name: string, options: FindOptions = {}): Promise<Taxonomy[]> {\n\t\tlet query = this.db\n\t\t\t.selectFrom(\"taxonomies\")\n\t\t\t.selectAll()\n\t\t\t.where(\"name\", \"=\", name)\n\t\t\t.orderBy(\"sort_order\", \"asc\")\n\t\t\t.orderBy(\"label\", \"asc\")\n\t\t\t.orderBy(\"id\", \"asc\");\n\n\t\tif (options.locale !== undefined) query = query.where(\"locale\", \"=\", options.locale);\n\n\t\tif (options.parentId !== undefined) {\n\t\t\tif (options.parentId === null) {\n\t\t\t\tquery = query.where(\"parent_id\", \"is\", null);\n\t\t\t} else {\n\t\t\t\tquery = query.where(\"parent_id\", \"=\", options.parentId);\n\t\t\t}\n\t\t}\n\n\t\tconst rows = await query.execute();\n\t\treturn rows.map((row) => this.rowToTaxonomy(row));\n\t}\n\n\t/**\n\t * Children of a term. Accepts a term id OR a translation_group and resolves\n\t * to the group, since `parent_id` stores the parent's translation_group.\n\t * Pass `locale` to scope to one locale's tree (children share the parent's\n\t * group across locales); omit it to find children in every locale (used to\n\t * block deletes that would orphan a sibling translation's subtree).\n\t */\n\tasync findChildren(parentIdOrGroup: string, locale?: string): Promise<Taxonomy[]> {\n\t\tconst group = await this.resolveTranslationGroup(parentIdOrGroup);\n\t\tif (!group) return [];\n\n\t\tlet query = this.db\n\t\t\t.selectFrom(\"taxonomies\")\n\t\t\t.selectAll()\n\t\t\t.where(\"parent_id\", \"=\", group)\n\t\t\t.orderBy(\"sort_order\", \"asc\")\n\t\t\t.orderBy(\"label\", \"asc\")\n\t\t\t.orderBy(\"id\", \"asc\");\n\t\tif (locale !== undefined) query = query.where(\"locale\", \"=\", locale);\n\n\t\tconst rows = await query.execute();\n\t\treturn rows.map((row) => this.rowToTaxonomy(row));\n\t}\n\n\t/**\n\t * Every translation sibling of a term (including itself), identified by\n\t * their shared `translation_group`.\n\t */\n\tasync findTranslations(translationGroup: string): Promise<Taxonomy[]> {\n\t\tconst rows = await this.db\n\t\t\t.selectFrom(\"taxonomies\")\n\t\t\t.selectAll()\n\t\t\t.where(\"translation_group\", \"=\", translationGroup)\n\t\t\t.orderBy(\"locale\", \"asc\")\n\t\t\t.execute();\n\t\treturn rows.map((row) => this.rowToTaxonomy(row));\n\t}\n\n\tasync update(id: string, input: UpdateTaxonomyInput): Promise<Taxonomy | null> {\n\t\tconst existing = await this.findById(id);\n\t\tif (!existing) return null;\n\n\t\t// Per-row display fields. `parent_id` and `sort_order` are not here: both\n\t\t// belong to the translation_group and are written across it below.\n\t\tconst updates: Record<string, unknown> = {};\n\t\tif (input.slug !== undefined) updates.slug = input.slug;\n\t\tif (input.label !== undefined) updates.label = input.label;\n\t\tif (input.data !== undefined) updates.data = JSON.stringify(input.data);\n\n\t\tconst group: { parent_id?: string | null; sort_order?: number } = {};\n\t\tif (input.parentId !== undefined) {\n\t\t\t// Defense in depth: empty-string parentId means null (no parent).\n\t\t\t// Otherwise persist the parent's translation_group (locale-agnostic),\n\t\t\t// matching create() — see the note there.\n\t\t\tconst parentId =\n\t\t\t\tinput.parentId === \"\" || input.parentId === null\n\t\t\t\t\t? null\n\t\t\t\t\t: await this.resolveParentRef(input.parentId);\n\n\t\t\tif (parentId !== existing.parentId) {\n\t\t\t\tgroup.parent_id = parentId;\n\t\t\t\t// A position only means anything within one sibling group, so a term\n\t\t\t\t// that changes parent is appended to the group it lands in.\n\t\t\t\tgroup.sort_order = await this.nextSortOrder(existing.name, parentId);\n\t\t\t}\n\t\t}\n\n\t\tconst hasRowUpdates = Object.keys(updates).length > 0;\n\t\tconst hasGroupUpdates = Object.keys(group).length > 0;\n\t\tif (hasRowUpdates || hasGroupUpdates) {\n\t\t\tawait withTransaction(this.db, async (trx) => {\n\t\t\t\tif (hasRowUpdates) {\n\t\t\t\t\tawait trx.updateTable(\"taxonomies\").set(updates).where(\"id\", \"=\", id).execute();\n\t\t\t\t}\n\t\t\t\tif (hasGroupUpdates) {\n\t\t\t\t\tawait trx\n\t\t\t\t\t\t.updateTable(\"taxonomies\")\n\t\t\t\t\t\t.set(group)\n\t\t\t\t\t\t.where(\"translation_group\", \"=\", existing.translationGroup ?? existing.id)\n\t\t\t\t\t\t.execute();\n\t\t\t\t}\n\t\t\t});\n\t\t\tinvalidateTaxonomyObjectCache();\n\t\t}\n\n\t\treturn this.findById(id);\n\t}\n\n\t/**\n\t * Move `groups` (translation_groups, in the desired order) into the positions\n\t * those same groups already occupy, leaving every other member of the sibling\n\t * group where it is.\n\t *\n\t * `groups` may be a subset: a locale renders only the terms translated into\n\t * it, so an admin in `fr` often cannot name every member. A group left out\n\t * keeps its place, which is also what makes a stale list harmless.\n\t *\n\t * `siblings` is every member of the group with the position it holds, in a\n\t * listing's order — tied positions are resolved by that order, so pass it as\n\t * read. Groups already at their target are skipped, so one swap rewrites two\n\t * groups rather than the whole list.\n\t */\n\tasync reorder(groups: string[], siblings: readonly SiblingPosition[]): Promise<void> {\n\t\tconst current = new Map(siblings.map(({ group, position }) => [group, position]));\n\n\t\tconst listed: string[] = [];\n\t\tconst occupied: number[] = [];\n\t\tfor (const group of groups) {\n\t\t\tconst position = current.get(group);\n\t\t\tif (position === undefined) continue;\n\t\t\tlisted.push(group);\n\t\t\toccupied.push(position);\n\t\t}\n\t\tif (listed.length === 0) return;\n\n\t\t// Tied positions have no distinct order to permute into, so the requested\n\t\t// one would be dropped without a word. Renumbering is the only way to\n\t\t// honour it, and it repairs the tie on the way through.\n\t\tconst target =\n\t\t\tnew Set(occupied).size === occupied.length\n\t\t\t\t? permuteWithinSlots(listed, occupied)\n\t\t\t\t: renumberSiblings(listed, siblings);\n\n\t\tconst changed = [...target].filter(([group, position]) => current.get(group) !== position);\n\t\tif (changed.length === 0) return;\n\n\t\tawait this.applyPositions(changed);\n\n\t\tinvalidateTaxonomyObjectCache();\n\t}\n\n\t/**\n\t * Write one position per translation_group, GROUPS_PER_UPDATE at a time so\n\t * each statement stays inside D1's parameter ceiling.\n\t *\n\t * D1 has no transactions — `withTransaction` runs its callback bare there —\n\t * so a chunk is the unit that can't tear. A reorder spanning several chunks\n\t * can, and leaves ties, which the next reorder renumbers away.\n\t */\n\tprivate async applyPositions(positions: readonly (readonly [string, number])[]): Promise<void> {\n\t\tfor (let index = 0; index < positions.length; index += GROUPS_PER_UPDATE) {\n\t\t\tconst chunk = positions.slice(index, index + GROUPS_PER_UPDATE);\n\t\t\t// The CAST types the bound position. Postgres resolves a CASE whose THEN\n\t\t\t// arms are all untyped parameters to text, then refuses to assign text to\n\t\t\t// an integer column.\n\t\t\tconst arms = sql.join(\n\t\t\t\tchunk.map(([group, position]) => sql`WHEN ${group} THEN CAST(${position} AS INTEGER)`),\n\t\t\t\tsql` `,\n\t\t\t);\n\t\t\tconst keys = sql.join(chunk.map(([group]) => sql`${group}`));\n\t\t\tawait sql`\n\t\t\t\tUPDATE taxonomies\n\t\t\t\tSET sort_order = CASE translation_group ${arms} END\n\t\t\t\tWHERE translation_group IN (${keys})\n\t\t\t`.execute(this.db);\n\t\t}\n\t}\n\n\t/**\n\t * Position for a term joining a sibling group: one past the last member, or\n\t * 0 when the group is empty.\n\t *\n\t * Bounds are taken across every locale because a position belongs to the\n\t * translation_group, not to a row — a term translated into only one locale\n\t * still occupies its slot for all of them.\n\t */\n\tprivate async nextSortOrder(name: string, parentId: string | null): Promise<number> {\n\t\tlet query = this.db\n\t\t\t.selectFrom(\"taxonomies\")\n\t\t\t.select((eb) => eb.fn.max(\"sort_order\").as(\"max\"))\n\t\t\t.where(\"name\", \"=\", name);\n\t\tquery =\n\t\t\tparentId === null\n\t\t\t\t? query.where(\"parent_id\", \"is\", null)\n\t\t\t\t: query.where(\"parent_id\", \"=\", parentId);\n\n\t\tconst bounds = await query.executeTakeFirst();\n\t\t// Null only when the group is empty.\n\t\tif (!bounds || bounds.max === null) return 0;\n\t\treturn bounds.max + 1;\n\t}\n\n\tasync delete(id: string): Promise<boolean> {\n\t\tconst term = await this.findById(id);\n\t\tif (!term) return false;\n\n\t\t// When deleting the last translation of a group the pivot rows that\n\t\t// reference that translation_group become orphaned — purge them.\n\t\tif (term.translationGroup) {\n\t\t\tconst siblings = await this.db\n\t\t\t\t.selectFrom(\"taxonomies\")\n\t\t\t\t.select(\"id\")\n\t\t\t\t.where(\"translation_group\", \"=\", term.translationGroup)\n\t\t\t\t.where(\"id\", \"!=\", id)\n\t\t\t\t.execute();\n\t\t\tif (siblings.length === 0) {\n\t\t\t\tawait this.db\n\t\t\t\t\t.deleteFrom(\"content_taxonomies\")\n\t\t\t\t\t.where(\"taxonomy_id\", \"=\", term.translationGroup)\n\t\t\t\t\t.execute();\n\t\t\t}\n\t\t}\n\n\t\tconst result = await this.db.deleteFrom(\"taxonomies\").where(\"id\", \"=\", id).executeTakeFirst();\n\t\tinvalidateTaxonomyObjectCache();\n\t\treturn (result.numDeletedRows ?? 0n) > 0n;\n\t}\n\n\t// --- Content-Taxonomy Junction (taxonomy_id stores the translation_group) ---\n\n\tasync attachToEntry(collection: string, entryId: string, taxonomyId: string): Promise<void> {\n\t\tconst group = await this.resolveTranslationGroup(taxonomyId);\n\t\tif (!group) return;\n\n\t\tconst denorm = await this.fetchEntryDenorm(collection, entryId);\n\t\tawait this.db\n\t\t\t.insertInto(\"content_taxonomies\")\n\t\t\t.values({ collection, entry_id: entryId, taxonomy_id: group, ...denorm })\n\t\t\t.onConflict((oc) => oc.doNothing())\n\t\t\t.execute();\n\t\tinvalidateTaxonomyObjectCache();\n\t}\n\n\tasync detachFromEntry(collection: string, entryId: string, taxonomyId: string): Promise<void> {\n\t\tconst group = await this.resolveTranslationGroup(taxonomyId);\n\t\tif (!group) return;\n\n\t\tawait this.db\n\t\t\t.deleteFrom(\"content_taxonomies\")\n\t\t\t.where(\"collection\", \"=\", collection)\n\t\t\t.where(\"entry_id\", \"=\", entryId)\n\t\t\t.where(\"taxonomy_id\", \"=\", group)\n\t\t\t.execute();\n\t\tinvalidateTaxonomyObjectCache();\n\t}\n\n\t/**\n\t * Taxonomy terms assigned to a content entry, resolved into a specific locale.\n\t * Terms whose translation_group lacks a row in the requested locale are\n\t * omitted — callers wanting fallback behaviour apply it themselves.\n\t */\n\tasync getTermsForEntry(\n\t\tcollection: string,\n\t\tentryId: string,\n\t\ttaxonomyName?: string,\n\t\tlocale?: string,\n\t): Promise<Taxonomy[]> {\n\t\tlet query = this.db\n\t\t\t.selectFrom(\"content_taxonomies\")\n\t\t\t.innerJoin(\"taxonomies\", \"taxonomies.translation_group\", \"content_taxonomies.taxonomy_id\")\n\t\t\t.selectAll(\"taxonomies\")\n\t\t\t.where(\"content_taxonomies.collection\", \"=\", collection)\n\t\t\t.where(\"content_taxonomies.entry_id\", \"=\", entryId);\n\n\t\tif (taxonomyName) query = query.where(\"taxonomies.name\", \"=\", taxonomyName);\n\t\tif (locale !== undefined) query = query.where(\"taxonomies.locale\", \"=\", locale);\n\n\t\tconst rows = await query.orderBy(\"taxonomies.locale\", \"asc\").execute();\n\t\treturn rows.map((row) => this.rowToTaxonomy(row));\n\t}\n\n\t/**\n\t * Replace all assignments of a given taxonomy for one content entry.\n\t * Term ids OR translation_groups are accepted and normalised to groups.\n\t */\n\tasync setTermsForEntry(\n\t\tcollection: string,\n\t\tentryId: string,\n\t\ttaxonomyName: string,\n\t\ttermIds: string[],\n\t): Promise<void> {\n\t\tconst groups: string[] = [];\n\t\tfor (const id of termIds) {\n\t\t\tconst group = await this.resolveTranslationGroup(id);\n\t\t\tif (group) groups.push(group);\n\t\t}\n\t\tconst newGroups = new Set(groups);\n\n\t\tconst current = await this.db\n\t\t\t.selectFrom(\"content_taxonomies\")\n\t\t\t.innerJoin(\"taxonomies\", \"taxonomies.translation_group\", \"content_taxonomies.taxonomy_id\")\n\t\t\t.select([\"content_taxonomies.taxonomy_id as group\"])\n\t\t\t.distinct()\n\t\t\t.where(\"content_taxonomies.collection\", \"=\", collection)\n\t\t\t.where(\"content_taxonomies.entry_id\", \"=\", entryId)\n\t\t\t.where(\"taxonomies.name\", \"=\", taxonomyName)\n\t\t\t.execute();\n\t\tconst currentGroups = new Set(current.map((r) => r.group));\n\n\t\tconst toRemove = [...currentGroups].filter((g) => !newGroups.has(g));\n\t\tif (toRemove.length > 0) {\n\t\t\tawait this.db\n\t\t\t\t.deleteFrom(\"content_taxonomies\")\n\t\t\t\t.where(\"collection\", \"=\", collection)\n\t\t\t\t.where(\"entry_id\", \"=\", entryId)\n\t\t\t\t.where(\"taxonomy_id\", \"in\", toRemove)\n\t\t\t\t.execute();\n\t\t}\n\n\t\tconst toAdd = [...newGroups].filter((g) => !currentGroups.has(g));\n\t\tif (toAdd.length > 0) {\n\t\t\tconst denorm = await this.fetchEntryDenorm(collection, entryId);\n\t\t\tawait this.db\n\t\t\t\t.insertInto(\"content_taxonomies\")\n\t\t\t\t.values(\n\t\t\t\t\ttoAdd.map((taxonomy_id) => ({\n\t\t\t\t\t\tcollection,\n\t\t\t\t\t\tentry_id: entryId,\n\t\t\t\t\t\ttaxonomy_id,\n\t\t\t\t\t\t...denorm,\n\t\t\t\t\t})),\n\t\t\t\t)\n\t\t\t\t.onConflict((oc) => oc.doNothing())\n\t\t\t\t.execute();\n\t\t}\n\n\t\tif (toRemove.length > 0 || toAdd.length > 0) invalidateTaxonomyObjectCache();\n\t}\n\n\tasync clearEntryTerms(collection: string, entryId: string): Promise<number> {\n\t\tconst result = await this.db\n\t\t\t.deleteFrom(\"content_taxonomies\")\n\t\t\t.where(\"collection\", \"=\", collection)\n\t\t\t.where(\"entry_id\", \"=\", entryId)\n\t\t\t.executeTakeFirst();\n\t\tconst removed = Number(result.numDeletedRows ?? 0);\n\t\tif (removed > 0) invalidateTaxonomyObjectCache();\n\t\treturn removed;\n\t}\n\n\t/**\n\t * Copy every term assignment from one content entry to another. Used when\n\t * creating a translation of a post so the new translation inherits the\n\t * source's term assignments. Safe to call when the source has no terms.\n\t */\n\tasync copyEntryTerms(\n\t\tcollection: string,\n\t\tsourceEntryId: string,\n\t\ttargetEntryId: string,\n\t): Promise<void> {\n\t\tconst rows = await this.db\n\t\t\t.selectFrom(\"content_taxonomies\")\n\t\t\t.select([\"taxonomy_id\"])\n\t\t\t.where(\"collection\", \"=\", collection)\n\t\t\t.where(\"entry_id\", \"=\", sourceEntryId)\n\t\t\t.execute();\n\t\tif (rows.length === 0) return;\n\n\t\t// Stamp the TARGET entry's current values — the copy inherits the source's\n\t\t// term memberships but the target's own status/dates/locale.\n\t\tconst denorm = await this.fetchEntryDenorm(collection, targetEntryId);\n\t\tawait this.db\n\t\t\t.insertInto(\"content_taxonomies\")\n\t\t\t.values(\n\t\t\t\trows.map((r) => ({\n\t\t\t\t\tcollection,\n\t\t\t\t\tentry_id: targetEntryId,\n\t\t\t\t\ttaxonomy_id: r.taxonomy_id,\n\t\t\t\t\t...denorm,\n\t\t\t\t})),\n\t\t\t)\n\t\t\t.onConflict((oc) => oc.doNothing())\n\t\t\t.execute();\n\t\tinvalidateTaxonomyObjectCache();\n\t}\n\n\t/**\n\t * Read the denormalized filter + sort columns from an entry's `ec_*` row so\n\t * they can be stamped onto new pivot rows (migration 051). A missing table or\n\t * missing row yields all-nulls: the pivot columns are advisory, and the\n\t * listing read path re-checks the authoritative `ec_*` row regardless.\n\t */\n\tprivate async fetchEntryDenorm(collection: string, entryId: string): Promise<PivotDenorm> {\n\t\tvalidateIdentifier(collection, \"collection type\");\n\t\tconst tableName = `ec_${collection}`;\n\t\ttry {\n\t\t\tconst result = await sql<PivotDenorm>`\n\t\t\t\tSELECT status, scheduled_at, deleted_at, locale, published_at, created_at\n\t\t\t\tFROM ${sql.ref(tableName)}\n\t\t\t\tWHERE id = ${entryId}\n\t\t\t`.execute(this.db);\n\t\t\treturn result.rows[0] ?? EMPTY_DENORM;\n\t\t} catch (error) {\n\t\t\tif (isMissingTableError(error)) return EMPTY_DENORM;\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Count content entries that use any translation of this term. Accepts\n\t * either a term id or a translation_group — we normalise to the group.\n\t *\n\t * Counts raw pivot rows regardless of the entry's status or deletion —\n\t * drafts and trashed entries are included. User-facing counts (admin term\n\t * list/get, public widget and term pages) use `fetchVisibleTermCounts`\n\t * from `taxonomies/term-counts.ts` instead, which counts only publicly\n\t * visible entries.\n\t */\n\tasync countEntriesWithTerm(termIdOrGroup: string): Promise<number> {\n\t\tconst group = await this.resolveTranslationGroup(termIdOrGroup);\n\t\tif (!group) return 0;\n\n\t\tconst result = await this.db\n\t\t\t.selectFrom(\"content_taxonomies\")\n\t\t\t.select((eb) => eb.fn.count(\"entry_id\").as(\"count\"))\n\t\t\t.where(\"taxonomy_id\", \"=\", group)\n\t\t\t.executeTakeFirst();\n\t\treturn Number(result?.count ?? 0);\n\t}\n\n\t/**\n\t * Resolve a parent reference (a row id or a translation_group) to the value\n\t * persisted in `parent_id`: the parent's translation_group, which is\n\t * locale-agnostic so the child stays nested in every locale. A\n\t * translation_group normally equals its anchor row's id, which satisfies the\n\t * self-FK on `parent_id`. If that anchor row is missing (a translation whose\n\t * anchor was deleted), fall back to the id we were given so we never write a\n\t * dangling FK value.\n\t */\n\tprivate async resolveParentRef(idOrGroup: string): Promise<string> {\n\t\tconst group = await this.resolveTranslationGroup(idOrGroup);\n\t\tif (!group) return idOrGroup;\n\t\tconst anchor = await this.db\n\t\t\t.selectFrom(\"taxonomies\")\n\t\t\t.select(\"id\")\n\t\t\t.where(\"id\", \"=\", group)\n\t\t\t.executeTakeFirst();\n\t\treturn anchor ? group : idOrGroup;\n\t}\n\n\tprivate async resolveTranslationGroup(idOrGroup: string): Promise<string | null> {\n\t\tconst row = await this.db\n\t\t\t.selectFrom(\"taxonomies\")\n\t\t\t.select([\"translation_group\"])\n\t\t\t.where((eb) => eb.or([eb(\"id\", \"=\", idOrGroup), eb(\"translation_group\", \"=\", idOrGroup)]))\n\t\t\t.executeTakeFirst();\n\t\treturn row?.translation_group ?? null;\n\t}\n\n\t/**\n\t * Batch count entries for multiple taxonomy translation_groups.\n\t * Chunks the query at SQL_BATCH_SIZE to stay below D1's bind-parameter limit.\n\t * Returns a Map from translation_group to count.\n\t *\n\t * Pass translation_groups (not term ids) — `content_taxonomies.taxonomy_id`\n\t * stores the translation_group so a single assignment spans every locale.\n\t *\n\t * Like `countEntriesWithTerm`, this counts raw pivot rows regardless of\n\t * status/deletion; user-facing counts go through `fetchVisibleTermCounts`.\n\t */\n\tasync countEntriesForTerms(translationGroups: string[]): Promise<Map<string, number>> {\n\t\tif (translationGroups.length === 0) return new Map();\n\n\t\tconst { chunks, SQL_BATCH_SIZE } = await import(\"../../utils/chunks.js\");\n\n\t\tconst counts = new Map<string, number>();\n\t\tfor (const chunk of chunks(translationGroups, SQL_BATCH_SIZE)) {\n\t\t\tconst rows = await this.db\n\t\t\t\t.selectFrom(\"content_taxonomies\")\n\t\t\t\t.select([\"taxonomy_id\", (eb) => eb.fn.count(\"entry_id\").as(\"count\")])\n\t\t\t\t.where(\"taxonomy_id\", \"in\", chunk)\n\t\t\t\t.groupBy(\"taxonomy_id\")\n\t\t\t\t.execute();\n\n\t\t\tfor (const row of rows) {\n\t\t\t\tcounts.set(row.taxonomy_id, Number(row.count || 0));\n\t\t\t}\n\t\t}\n\t\treturn counts;\n\t}\n\n\tprivate rowToTaxonomy(row: Selectable<TaxonomyTable>): Taxonomy {\n\t\treturn {\n\t\t\tid: row.id,\n\t\t\tname: row.name,\n\t\t\tslug: row.slug,\n\t\t\tlabel: row.label,\n\t\t\tparentId: row.parent_id,\n\t\t\tdata: row.data ? JSON.parse(row.data) : null,\n\t\t\tlocale: row.locale,\n\t\t\ttranslationGroup: row.translation_group,\n\t\t\tsortOrder: row.sort_order,\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;AAuBA,MAAM,eAA4B;CACjC,QAAQ;CACR,cAAc;CACd,YAAY;CACZ,QAAQ;CACR,cAAc;CACd,YAAY;CACZ;;;;;;AAaD,MAAM,oBAAoB;;AAG1B,SAAS,mBACR,QACA,UACsB;CACtB,MAAM,QAAQ,SAAS,UAAU,GAAG,MAAM,IAAI,EAAE;CAChD,MAAM,yBAAS,IAAI,KAAqB;AACxC,QAAO,SAAS,OAAO,UAAU;EAChC,MAAM,WAAW,MAAM;AACvB,MAAI,aAAa,OAAW,QAAO,IAAI,OAAO,SAAS;GACtD;AACF,QAAO;;;;;;;;;;;;AAaR,SAAS,iBACR,QACA,UACsB;CACtB,MAAM,WAAW,SAAS,UAAU,GAAG,MAAM,EAAE,WAAW,EAAE,SAAS;CACrE,MAAM,SAAS,IAAI,IAAI,OAAO;CAC9B,MAAM,yBAAS,IAAI,KAAqB;CACxC,IAAI,OAAO;AACX,UAAS,SAAS,EAAE,SAAS,UAAU;EACtC,MAAM,cAAc,OAAO,IAAI,MAAM,GAAG,OAAO,UAAU;AACzD,SAAO,IAAI,eAAe,OAAO,MAAM;GACtC;AACF,QAAO;;;;;;;;;;;;;;;;;;;AA6DR,IAAa,qBAAb,MAAgC;CAC/B,YAAY,AAAQ,IAAsB;EAAtB;;;;;;;CAOpB,MAAM,OAAO,OAA+C;EAC3D,MAAM,KAAK,MAAM;EAQjB,MAAM,cACL,MAAM,aAAa,UAAa,MAAM,aAAa,KAAK,OAAO,MAAM;EACtE,MAAM,WAAW,cAAc,MAAM,KAAK,iBAAiB,YAAY,GAAG;EAE1E,IAAI,mBAAmB;EACvB,IA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GACV,MAAM,IAAI;GACV,OAAO,IAAI;GACX,UAAU,IAAI;GACd,MAAM,IAAI,OAAO,KAAK,MAAM,IAAI,KAAK,GAAG;GACxC,QAAQ,IAAI;GACZ,kBAAkB,IAAI;GACtB,WAAW,IAAI;GACf"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types-BGWPMiBO.d.mts","names":[],"sources":["../src/database/repositories/types.ts"],"mappings":";;;UAaiB,kBAAA;EAChB,IAAA;EACA,IAAA;EACA,IAAA,EAAM,MAAA;EACN,MAAA;EACA,QAAA;EACA,eAAA;EACA,MAAA;EACA,aAAA;EACA,WAAA;EALA;EAOA,SAAA;AAAA;AAAA,UAGgB,kBAAA;EAChB,IAAA,GAAO,MAAA;EACP,MAAA;EACA,IAAA;EACA,WAAA;EACA,WAAA;EACA,QAAA;EACA,eAAA;AAAA;;UAIgB,UAAA;EAChB,KAAA;EACA,WAAA;EACA,KAAA;EACA,SAAA;EACA,OAAA;AAAA;;UAIgB,eAAA;EAChB,KAAA;EACA,WAAA;EACA,KAAA;EACA,SAAA;EACA,OAAA;AAAA;AAAA,UAGgB,aAAA;EAChB,EAAA;EACA,IAAA;EACA,WAAA;EACA,GAAA;EACA,aAAA;EAbgB;;;;;;;;;;;AAQjB;;;;;EAsBC,gBAAA;EAnBA;EAqBA,SAAA;EAnBA;;;;;;;EA2BA,cAAA;EASA;;;;EAJA,mBAAA;EACA,UAAA;EACA,MAAA;EACA,OAAA;EACA,SAAA;EACA,SAAA;EA0BmC;;;;EArBnC,MAAA;EAuBA;;;;;AAOD;;EAtBC,gBAAA;EAsB2B;;AAS5B;;;;;;;EArBC,YAAA,GAAe,MAAA,SAAe,gBAAA;AAAA;AAAA,UAGd,mBAAA;EAChB,MAAA,EAAQ,aAAA;EACR,SAAA;EACA,SAAA;EA2C+B;EAzC/B,MAAA;AAAA;;KAIW,gBAAA;;;;;;;;UASK,iBAAA;EAChB,KAAA,EAAO,gBAAA;EACP,IAAA;EACA,EAAA;AAAA;AAAA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AAA;EACV,SAAA;EAPA;EASA,UAAA;EARA;EAUA,YAAA;AAAA;;;;UAMgB,gBAAA;EAChB,KAAA;EAXA;;;;;AAUD;;;;EAWC,IAAA,GAAO,SAAA;EACP,QAAA;EACA,MAAA;EACA,YAAA;EACA,UAAA,GAAa,eAAA;EACb,MAAA;EACA,OAAA,GAAU,kBAAA;EACV,SAAA;EALA;EAOA,UAAA;EALA;EAOA,YAAA;AAAA;;;;UAMgB,oBAAA,SAA6B,UAAA;EAC7C,MAAA,EAAQ,KAAA;AAAA;;AADT;;;;;cAUa,oBAAA;;;;cAuBA,yBAAA;;;;;;KA0GD,gBAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types-Cd8iuS1J.mjs","names":[],"sources":["../src/database/repositories/types.ts"],"sourcesContent":["import type { CustomFieldValue } from \"../../schema/types.js\";\nimport { encodeBase64, decodeBase64 } from \"../../utils/base64.js\";\n\n/**\n * Hard cap on cursor length. Cursors we issue are short JSON-in-base64\n * blobs; a real cursor is well under 200 chars. This guards against\n * malicious callers passing megabyte-sized strings to force the base64\n * decoder to allocate (decodeBase64 is O(N) in input size). The MCP and\n * REST schemas also clamp at 2048 — this 4096 cap is a defense-in-depth\n * floor inside the repository helpers.\n */\nconst MAX_CURSOR_LENGTH = 4096;\n\nexport interface CreateContentInput {\n\ttype: string;\n\tslug?: string | null;\n\tdata: Record<string, unknown>;\n\tstatus?: string;\n\tauthorId?: string;\n\tprimaryBylineId?: string | null;\n\tlocale?: string;\n\ttranslationOf?: string;\n\tpublishedAt?: string | null;\n\t/** Override created_at (ISO 8601). Used by importers to preserve original dates. */\n\tcreatedAt?: string | null;\n}\n\nexport interface UpdateContentInput {\n\tdata?: Record<string, unknown>;\n\tstatus?: string;\n\tslug?: string | null;\n\tpublishedAt?: string | null;\n\tscheduledAt?: string | null;\n\tauthorId?: string | null;\n\tprimaryBylineId?: string | null;\n}\n\n/** SEO fields for content items */\nexport interface ContentSeo {\n\ttitle: string | null;\n\tdescription: string | null;\n\timage: string | null;\n\tcanonical: string | null;\n\tnoIndex: boolean;\n}\n\n/** Input for updating SEO fields on content */\nexport interface ContentSeoInput {\n\ttitle?: string | null;\n\tdescription?: string | null;\n\timage?: string | null;\n\tcanonical?: string | null;\n\tnoIndex?: boolean;\n}\n\nexport interface BylineSummary {\n\tid: string;\n\tslug: string;\n\tdisplayName: string;\n\tbio: string | null;\n\tavatarMediaId: string | null;\n\t/**\n\t * The avatar media's storage key, folded in by a LEFT JOIN on the\n\t * `media` table during content byline hydration. Non-null only when the\n\t * byline has an avatar AND was loaded through the content-credit hydration\n\t * path (`getContentBylines` / `getContentBylinesMany`, i.e. the\n\t * `entry.data.bylines` populated by `getEmDashCollection` / `getEmDashEntry`).\n\t * The plain byline finders (`findById`, `findBySlug`, …) leave it null.\n\t *\n\t * Lets list pages build a direct storage URL for an author avatar without a\n\t * per-byline `MediaRepository.findById`, avoiding an N+1 when many distinct\n\t * authors appear on one page.\n\t *\n\t * Optional so adding it is a non-breaking change for existing code that\n\t * constructs a `BylineSummary` literal; the repositories always populate it\n\t * (to `null` when there's no avatar or no media join).\n\t */\n\tavatarStorageKey?: string | null;\n\t/** Avatar media alt text, from the same media join. Null when not joined. */\n\tavatarAlt?: string | null;\n\t/**\n\t * Avatar media blurhash (LQIP placeholder, migration 024), folded in by the\n\t * same media join as `avatarStorageKey`. Lets a renderer paint a blurred\n\t * placeholder while the full avatar loads, with no extra media lookup.\n\t * Null when the byline has no avatar, the media row has no blurhash, or the\n\t * byline was loaded through a finder that doesn't join media.\n\t */\n\tavatarBlurhash?: string | null;\n\t/**\n\t * Avatar media dominant colour (LQIP placeholder, migration 024), from the\n\t * same media join. Null under the same conditions as `avatarBlurhash`.\n\t */\n\tavatarDominantColor?: string | null;\n\twebsiteUrl: string | null;\n\tuserId: string | null;\n\tisGuest: boolean;\n\tcreatedAt: string;\n\tupdatedAt: string;\n\t/**\n\t * Locale this byline row is presented in. Added by migration 040.\n\t * `(slug, locale)` is unique; a single slug can repeat across locales.\n\t */\n\tlocale: string;\n\t/**\n\t * Shared across translations of the same byline. Added by migration 040.\n\t * `_emdash_content_bylines.byline_id` and `ec_*.primary_byline_id` store\n\t * this value, so a credit spans every locale variant of a byline.\n\t * Nullable in storage for backwards compatibility; new rows always\n\t * populate it.\n\t */\n\ttranslationGroup: string | null;\n\t/**\n\t * Custom field values registered via the byline-fields schema (migration\n\t * 041, Discussion #1174). Optional in the TypeScript shape so existing\n\t * object-literal consumers (test fixtures, plugin renderers) stay\n\t * source-compatible; the runtime always returns `{}` when no fields are\n\t * registered. Translatable values reflect this row's locale; non-\n\t * translatable values are shared across every locale variant of the\n\t * byline's `translation_group`.\n\t */\n\tcustomFields?: Record<string, CustomFieldValue>;\n}\n\nexport interface ContentBylineCredit {\n\tbyline: BylineSummary;\n\tsortOrder: number;\n\troleLabel: string | null;\n\t/** Whether this credit was explicitly assigned or inferred from authorId */\n\tsource?: \"explicit\" | \"inferred\";\n}\n\n/** A whitelisted timestamp column a content-list date range can filter on. */\nexport type ContentDateField = \"createdAt\" | \"updatedAt\" | \"publishedAt\";\n\n/**\n * Inclusive date-range filter for a single whitelisted timestamp column.\n * Bounds are compared lexicographically against the stored ISO 8601 strings,\n * which is correct because every timestamp is written via `toISOString()`.\n * Callers wanting an inclusive upper bound should pass an end-of-day value\n * (e.g. `2024-12-31T23:59:59.999Z`); the repository does not widen `to`.\n */\nexport interface ContentDateFilter {\n\tfield: ContentDateField;\n\tfrom?: string;\n\tto?: string;\n}\n\nexport interface FindManyOptions {\n\twhere?: {\n\t\tstatus?: string;\n\t\tauthorId?: string;\n\t\tlocale?: string;\n\t\t/** Case-insensitive substring to match against `searchColumns`. */\n\t\tq?: string;\n\t\t/**\n\t\t * Columns the `q` substring filter is applied to (OR'd together).\n\t\t * Resolved by the handler from the collection's display fields so the\n\t\t * repository stays generic. Each name is validated as a SQL identifier.\n\t\t */\n\t\tsearchColumns?: string[];\n\t\t/**\n\t\t * Serve `q` from the collection's FTS5 index (`_emdash_fts_<slug>`)\n\t\t * instead of an unindexable substring LIKE. Set by the handler only\n\t\t * when the collection has search enabled and the index exists\n\t\t * (SQLite only). The repository combines a token-prefix MATCH with\n\t\t * an index-served slug prefix so slug lookups keep working.\n\t\t */\n\t\tuseFts?: boolean;\n\t\t/** Inclusive date range over a whitelisted timestamp column. */\n\t\tdateFilter?: ContentDateFilter;\n\t};\n\torderBy?: {\n\t\tfield: string;\n\t\tdirection: \"asc\" | \"desc\";\n\t};\n\tlimit?: number;\n\tcursor?: string; // Base64-encoded JSON: {orderValue: string, id: string}\n}\n\nexport interface FindManyResult<T> {\n\titems: T[];\n\tnextCursor?: string; // Base64-encoded JSON: {orderValue: string, id: string}\n\t/**\n\t * Total number of rows matching the where clause (ignoring pagination).\n\t * Optional because not every caller needs it; repositories that compute\n\t * it should set it so the UI can render a stable pagination denominator.\n\t */\n\ttotal?: number;\n}\n\n/** Encode a cursor from order value + id */\nexport function encodeCursor(orderValue: string, id: string): string {\n\treturn encodeBase64(JSON.stringify({ orderValue, id }));\n}\n\n/**\n * Thrown when a pagination cursor cannot be decoded.\n *\n * Repository callers should let this propagate; handler catch blocks\n * map it to a structured `INVALID_CURSOR` error so client pagination\n * bugs surface immediately rather than silently re-fetching the first\n * page.\n */\nexport class InvalidCursorError extends Error {\n\tconstructor(cursor: string) {\n\t\tconst display = cursor.length > 50 ? `${cursor.slice(0, 47)}...` : cursor;\n\t\tsuper(`Invalid pagination cursor: ${display}`);\n\t\tthis.name = \"InvalidCursorError\";\n\t}\n}\n\n/**\n * Decode a cursor to order value + id.\n *\n * Throws `InvalidCursorError` if the cursor is empty, not valid base64,\n * not valid JSON, or doesn't contain string `orderValue` and `id` fields.\n */\nexport function decodeCursor(cursor: string): { orderValue: string; id: string } {\n\tif (!cursor) throw new InvalidCursorError(cursor);\n\tif (cursor.length > MAX_CURSOR_LENGTH) throw new InvalidCursorError(cursor);\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(decodeBase64(cursor));\n\t} catch {\n\t\tthrow new InvalidCursorError(cursor);\n\t}\n\tif (parsed === null || typeof parsed !== \"object\") {\n\t\tthrow new InvalidCursorError(cursor);\n\t}\n\tconst candidate = parsed as { orderValue?: unknown; id?: unknown };\n\tif (typeof candidate.orderValue !== \"string\" || typeof candidate.id !== \"string\") {\n\t\tthrow new InvalidCursorError(cursor);\n\t}\n\treturn { orderValue: candidate.orderValue, id: candidate.id };\n}\n\nexport interface ContentItem {\n\tid: string;\n\ttype: string;\n\tslug: string | null;\n\tstatus: string;\n\tdata: Record<string, unknown>;\n\tauthorId: string | null;\n\tprimaryBylineId: string | null;\n\tbyline?: BylineSummary | null;\n\tbylines?: ContentBylineCredit[];\n\tcreatedAt: string;\n\tupdatedAt: string;\n\tpublishedAt: string | null;\n\tscheduledAt: string | null;\n\tliveRevisionId: string | null;\n\tdraftRevisionId: string | null;\n\tversion: number;\n\tlocale: string | null;\n\ttranslationGroup: string | null;\n\t/** SEO metadata — only populated for collections with `has_seo` enabled */\n\tseo?: ContentSeo;\n\t/**\n\t * For collections that support `revisions`: when a draft revision exists,\n\t * `data` reflects the unsaved draft and `liveData` carries the currently-\n\t * published values. When no draft exists, `liveData` is undefined.\n\t *\n\t * Hydrated by `EmDashRuntime.hydrateDraftData()` — repositories themselves\n\t * never set this field; it's purely a runtime-overlay concept that gives\n\t * agents a clear picture of \"draft vs. live\" without re-fetching the\n\t * revision history.\n\t */\n\tliveData?: Record<string, unknown>;\n}\n\nexport class EmDashValidationError extends Error {\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic details?: unknown,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = \"EmDashValidationError\";\n\t}\n}\n\n/**\n * Thrown by `publish()` when called with `requireDue` for a row that is no\n * longer due (its `scheduled_at` was cleared or pushed into the future between\n * selection and publish — e.g. an editor unscheduled it). Lets the scheduled\n * sweep skip the row silently rather than treating it as a publish failure.\n */\nexport class ScheduledNotDueError extends Error {\n\tconstructor(message = \"Content is no longer scheduled to publish\") {\n\t\tsuper(message);\n\t\tthis.name = \"ScheduledNotDueError\";\n\t}\n}\n\nexport class ContentMutationConflictError extends Error {\n\tconstructor(message = \"Content changed while the operation was in progress\") {\n\t\tsuper(message);\n\t\tthis.name = \"ContentMutationConflictError\";\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAWA,MAAM,oBAAoB;;AAoL1B,SAAgB,aAAa,YAAoB,IAAoB;AACpE,QAAO,aAAa,KAAK,UAAU;EAAE;EAAY;EAAI,CAAC,CAAC;;;;;;;;;;AAWxD,IAAa,qBAAb,cAAwC,MAAM;CAC7C,YAAY,QAAgB;EAC3B,MAAM,UAAU,OAAO,SAAS,KAAK,GAAG,OAAO,MAAM,GAAG,GAAG,CAAC,OAAO;AACnE,QAAM,8BAA8B,UAAU;AAC9C,OAAK,OAAO;;;;;;;;;AAUd,SAAgB,aAAa,QAAoD;AAChF,KAAI,CAAC,OAAQ,OAAM,IAAI,mBAAmB,OAAO;AACjD,KAAI,OAAO,SAAS,kBAAmB,OAAM,IAAI,mBAAmB,OAAO;CAC3E,IAAI;AACJ,KAAI;AACH,WAAS,KAAK,MAAM,aAAa,OAAO,CAAC;SAClC;AACP,QAAM,IAAI,mBAAmB,OAAO;;AAErC,KAAI,WAAW,QAAQ,OAAO,WAAW,SACxC,OAAM,IAAI,mBAAmB,OAAO;CAErC,MAAM,YAAY;AAClB,KAAI,OAAO,UAAU,eAAe,YAAY,OAAO,UAAU,OAAO,SACvE,OAAM,IAAI,mBAAmB,OAAO;AAErC,QAAO;EAAE,YAAY,UAAU;EAAY,IAAI,UAAU;EAAI;;AAqC9D,IAAa,wBAAb,cAA2C,MAAM;CAChD,YACC,SACA,AAAO,SACN;AACD,QAAM,QAAQ;EAFP;AAGP,OAAK,OAAO;;;;;;;;;AAUd,IAAa,uBAAb,cAA0C,MAAM;CAC/C,YAAY,UAAU,6CAA6C;AAClE,QAAM,QAAQ;AACd,OAAK,OAAO;;;AAId,IAAa,+BAAb,cAAkD,MAAM;CACvD,YAAY,UAAU,uDAAuD;AAC5E,QAAM,QAAQ;AACd,OAAK,OAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types-Cz8hNch2.d.mts","names":["ConfirmDialog","title","text","confirm","deny","style","ButtonElement","type","action_id","label","value","TextInputElement","placeholder","initial_value","multiline","NumberInputElement","min","max","SelectElement","Array","options","optionsRoute","ToggleElement","description","SecretInputElement","has_value","CheckboxElement","DateInputElement","ComboboxElement","RadioElement","RepeaterSubField","RepeaterElement","Record","item_label","fields","min_items","max_items","MediaPickerElement","mime_type_filter","Element","FieldCondition","field","eq","neq","FormField","condition","TableColumn","key","format","sortable","StatItem","trend","ChartSeries","name","data","color","TimeseriesChartConfig","chart_type","series","x_axis_name","y_axis_name","height","gradient","CustomChartConfig","ChartConfig","BlockBase","block_id","HeaderBlock","SectionBlock","accessory","DividerBlock","FieldsBlock","TableBlock","columns","rows","next_cursor","page_action_id","empty_text","ActionsBlock","elements","StatsBlock","items","FormBlock","submit","ImageBlock","url","alt","ContextBlock","ColumnsBlock","Block","ChartBlock","config","BannerBlock","variant","MeterBlock","custom_value","CodeBlock","code","language","TabPanel","blocks","TabBlock","panels","default_tab","EmptyBlock","command_line","size","actions","AccordionBlock","default_open","BlockAction","FormSubmit","values","PageLoad","page","BlockInteraction","BlockResponse","toast","message","header","blockId","opts","section","divider","fieldsBlock","table","nextCursor","pageActionId","emptyText","actionsBlock","stats","form","actionId","image","context","columnsBlock","bannerBlock","textInput","initialValue","numberInput","select","toggle","button","secretInput","hasValue","checkbox","dateInput","combobox","radio","repeater","itemLabel","minItems","maxItems","mediaPicker","mimeTypeFilter","timeseriesChart","xAxisName","yAxisName","customChart","meter","customValue","codeBlock","tabBlock","defaultTab","empty","commandLine","accordion","defaultOpen","banner","tab","ValidationError","path","validateBlocks","valid","errors","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","R","S","T","U","V","W","X","Y","Z","_","a","b","c","d","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"],"sources":["../../blocks/dist/validation-5vL6669b.d.ts","../src/plugins/types.ts"],"mappings":";;;;;;;;;UACUA,aAAAA;EACRC,KAAAA;EACAC,IAAAA;EACAC,OAAAA;EACAC,IAAAA;EACAC,KAAAA;AAAAA;AAAAA,UAEQC,aAAAA;EACRC,IAAAA;EACAC,SAAAA;EACAC,KAAAA;EACAJ,KAAAA;EACAK,KAAAA;EACAP,OAAAA,GAAUH,aAAAA;AAAAA;AAAAA,UAEFW,gBAAAA;EACRJ,IAAAA;EACAC,SAAAA;EACAC,KAAAA;EACAG,WAAAA;EACAC,aAAAA;EACAC,SAAAA;AAAAA;AAAAA,UAEQC,kBAAAA;EACRR,IAAAA;EACAC,SAAAA;EACAC,KAAAA;EACAI,aAAAA;EACAG,GAAAA;EACAC,GAAAA;AAAAA;AAAAA,UAEQC,aAAAA;EACRX,IAAAA;EACAC,SAAAA;EACAC,KAAAA;EACAW,OAAAA,EAASD,KAAAA;IACPV,KAAAA;IACAC,KAAAA;EAAAA;EAEFG,aAAAA;EAlBAC;EAoBAO,YAAAA;AAAAA;AAAAA,UAEQC,aAAAA;EACRf,IAAAA;EACAC,SAAAA;EACAC,KAAAA;EACAc,WAAAA;EACAV,aAAAA;AAAAA;AAAAA,UAEQW,kBAAAA;EACRjB,IAAAA;EACAC,SAAAA;EACAC,KAAAA;EACAG,WAAAA;EACAa,SAAAA;AAAAA;AAAAA,UAEQC,eAAAA;EACRnB,IAAAA;EACAC,SAAAA;EACAC,KAAAA;EACAW,OAAAA,EAASD,KAAAA;IACPV,KAAAA;IACAC,KAAAA;EAAAA;EAEFG,aAAAA;AAAAA;AAAAA,UAEQc,gBAAAA;EACRpB,IAAAA;EACAC,SAAAA;EACAC,KAAAA;EACAI,aAAAA;EACAD,WAAAA;AAAAA;AAAAA,UAEQgB,eAAAA;EACRrB,IAAAA;EACAC,SAAAA;EACAC,KAAAA;EACAW,OAAAA,EAASD,KAAAA;IACPV,KAAAA;IACA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