emdash 0.28.1 → 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (946) hide show
  1. package/dist/{adapters-hUy8vOB-.d.mts → adapters-C0ONzkUP.d.mts} +10 -1
  2. package/dist/adapters-C0ONzkUP.d.mts.map +1 -0
  3. package/dist/{allowed-origins-CRsJ6BPM.mjs → allowed-origins-CCEi9bPI.mjs} +2 -2
  4. package/dist/{allowed-origins-CRsJ6BPM.mjs.map → allowed-origins-CCEi9bPI.mjs.map} +1 -1
  5. package/dist/api/route-utils.d.mts +3 -3
  6. package/dist/api/route-utils.d.mts.map +1 -1
  7. package/dist/api/route-utils.mjs +22 -21
  8. package/dist/api/route-utils.mjs.map +1 -1
  9. package/dist/api/schemas/index.d.mts +2 -2
  10. package/dist/api/schemas/index.mjs +5 -4
  11. package/dist/{api-DxFSorgk.mjs → api-b8WIiGU4.mjs} +306 -154
  12. package/dist/api-b8WIiGU4.mjs.map +1 -0
  13. package/dist/api-tokens-Cvmixds7.mjs +3 -0
  14. package/dist/{api-tokens-DvqeZmVq.mjs → api-tokens-uPt8UDpx.mjs} +2 -2
  15. package/dist/{api-tokens-DvqeZmVq.mjs.map → api-tokens-uPt8UDpx.mjs.map} +1 -1
  16. package/dist/{apply-CDJqIjPU.mjs → apply-CmIJK9j8.mjs} +35 -38
  17. package/dist/apply-CmIJK9j8.mjs.map +1 -0
  18. package/dist/astro/index.d.mts +12 -12
  19. package/dist/astro/index.d.mts.map +1 -1
  20. package/dist/astro/index.mjs +97 -13
  21. package/dist/astro/index.mjs.map +1 -1
  22. package/dist/astro/middleware/auth.d.mts +10 -10
  23. package/dist/astro/middleware/auth.d.mts.map +1 -1
  24. package/dist/astro/middleware/auth.mjs +56 -107
  25. package/dist/astro/middleware/auth.mjs.map +1 -1
  26. package/dist/astro/middleware/redirect.mjs +7 -7
  27. package/dist/astro/middleware/request-context.d.mts +3 -0
  28. package/dist/astro/middleware/request-context.d.mts.map +1 -1
  29. package/dist/astro/middleware/request-context.mjs +258 -31
  30. package/dist/astro/middleware/request-context.mjs.map +1 -1
  31. package/dist/astro/middleware/setup.mjs +1 -1
  32. package/dist/astro/middleware.d.mts +47 -3
  33. package/dist/astro/middleware.d.mts.map +1 -1
  34. package/dist/astro/middleware.mjs +379 -117
  35. package/dist/astro/middleware.mjs.map +1 -1
  36. package/dist/astro/routes/PluginRegistry.d.mts +5 -1
  37. package/dist/astro/routes/PluginRegistry.d.mts.map +1 -1
  38. package/dist/astro/routes/PluginRegistry.mjs +2 -1
  39. package/dist/astro/routes/PluginRegistry.mjs.map +1 -1
  40. package/dist/astro/routes/api/admin/allowed-domains/_domain_.mjs +9 -8
  41. package/dist/astro/routes/api/admin/allowed-domains/_domain_.mjs.map +1 -1
  42. package/dist/astro/routes/api/admin/allowed-domains/index.mjs +9 -8
  43. package/dist/astro/routes/api/admin/allowed-domains/index.mjs.map +1 -1
  44. package/dist/astro/routes/api/admin/api-tokens/_id_.mjs +5 -5
  45. package/dist/astro/routes/api/admin/api-tokens/index.mjs +7 -7
  46. package/dist/astro/routes/api/admin/api-tokens/index.mjs.map +1 -1
  47. package/dist/astro/routes/api/admin/byline-fields/_slug_/usage.mjs +6 -6
  48. package/dist/astro/routes/api/admin/byline-fields/_slug_.mjs +11 -10
  49. package/dist/astro/routes/api/admin/byline-fields/_slug_.mjs.map +1 -1
  50. package/dist/astro/routes/api/admin/byline-fields/index.mjs +11 -10
  51. package/dist/astro/routes/api/admin/byline-fields/index.mjs.map +1 -1
  52. package/dist/astro/routes/api/admin/byline-fields/reorder.mjs +11 -10
  53. package/dist/astro/routes/api/admin/byline-fields/reorder.mjs.map +1 -1
  54. package/dist/astro/routes/api/admin/bylines/_id_/index.mjs +18 -17
  55. package/dist/astro/routes/api/admin/bylines/_id_/index.mjs.map +1 -1
  56. package/dist/astro/routes/api/admin/bylines/_id_/translations.mjs +19 -24
  57. package/dist/astro/routes/api/admin/bylines/_id_/translations.mjs.map +1 -1
  58. package/dist/astro/routes/api/admin/bylines/index.mjs +18 -17
  59. package/dist/astro/routes/api/admin/bylines/index.mjs.map +1 -1
  60. package/dist/astro/routes/api/admin/comments/_id_/status.d.mts.map +1 -1
  61. package/dist/astro/routes/api/admin/comments/_id_/status.mjs +14 -13
  62. package/dist/astro/routes/api/admin/comments/_id_/status.mjs.map +1 -1
  63. package/dist/astro/routes/api/admin/comments/_id_.mjs +6 -6
  64. package/dist/astro/routes/api/admin/comments/bulk.mjs +11 -10
  65. package/dist/astro/routes/api/admin/comments/bulk.mjs.map +1 -1
  66. package/dist/astro/routes/api/admin/comments/counts.mjs +6 -6
  67. package/dist/astro/routes/api/admin/comments/index.d.mts.map +1 -1
  68. package/dist/astro/routes/api/admin/comments/index.mjs +11 -10
  69. package/dist/astro/routes/api/admin/comments/index.mjs.map +1 -1
  70. package/dist/astro/routes/api/admin/hooks/exclusive/_hookName_.mjs +6 -6
  71. package/dist/astro/routes/api/admin/hooks/exclusive/index.mjs +5 -5
  72. package/dist/astro/routes/api/admin/media-usage/repair.d.mts +8 -0
  73. package/dist/astro/routes/api/admin/media-usage/repair.d.mts.map +1 -0
  74. package/dist/astro/routes/api/admin/media-usage/repair.mjs +30 -0
  75. package/dist/astro/routes/api/admin/media-usage/repair.mjs.map +1 -0
  76. package/dist/astro/routes/api/admin/oauth-clients/_id_.mjs +5 -5
  77. package/dist/astro/routes/api/admin/oauth-clients/index.mjs +5 -5
  78. package/dist/astro/routes/api/admin/plugins/_id_/disable.mjs +44 -41
  79. package/dist/astro/routes/api/admin/plugins/_id_/disable.mjs.map +1 -1
  80. package/dist/astro/routes/api/admin/plugins/_id_/enable.mjs +44 -41
  81. package/dist/astro/routes/api/admin/plugins/_id_/enable.mjs.map +1 -1
  82. package/dist/astro/routes/api/admin/plugins/_id_/index.mjs +49 -41
  83. package/dist/astro/routes/api/admin/plugins/_id_/index.mjs.map +1 -1
  84. package/dist/astro/routes/api/admin/plugins/_id_/mcp.d.mts +8 -0
  85. package/dist/astro/routes/api/admin/plugins/_id_/mcp.d.mts.map +1 -0
  86. package/dist/astro/routes/api/admin/plugins/_id_/mcp.mjs +39 -0
  87. package/dist/astro/routes/api/admin/plugins/_id_/mcp.mjs.map +1 -0
  88. package/dist/astro/routes/api/admin/plugins/_id_/settings.d.mts +9 -0
  89. package/dist/astro/routes/api/admin/plugins/_id_/settings.d.mts.map +1 -0
  90. package/dist/astro/routes/api/admin/plugins/_id_/settings.mjs +78 -0
  91. package/dist/astro/routes/api/admin/plugins/_id_/settings.mjs.map +1 -0
  92. package/dist/astro/routes/api/admin/plugins/_id_/uninstall.mjs +43 -40
  93. package/dist/astro/routes/api/admin/plugins/_id_/uninstall.mjs.map +1 -1
  94. package/dist/astro/routes/api/admin/plugins/_id_/update.d.mts.map +1 -1
  95. package/dist/astro/routes/api/admin/plugins/_id_/update.mjs +46 -41
  96. package/dist/astro/routes/api/admin/plugins/_id_/update.mjs.map +1 -1
  97. package/dist/astro/routes/api/admin/plugins/index.mjs +49 -41
  98. package/dist/astro/routes/api/admin/plugins/index.mjs.map +1 -1
  99. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/icon.mjs +4 -4
  100. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/index.mjs +43 -40
  101. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/index.mjs.map +1 -1
  102. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.d.mts.map +1 -1
  103. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.mjs +49 -42
  104. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.mjs.map +1 -1
  105. package/dist/astro/routes/api/admin/plugins/marketplace/index.mjs +43 -40
  106. package/dist/astro/routes/api/admin/plugins/marketplace/index.mjs.map +1 -1
  107. package/dist/astro/routes/api/admin/plugins/registry/_id_/uninstall.mjs +43 -40
  108. package/dist/astro/routes/api/admin/plugins/registry/_id_/uninstall.mjs.map +1 -1
  109. package/dist/astro/routes/api/admin/plugins/registry/_id_/update.d.mts.map +1 -1
  110. package/dist/astro/routes/api/admin/plugins/registry/_id_/update.mjs +47 -42
  111. package/dist/astro/routes/api/admin/plugins/registry/_id_/update.mjs.map +1 -1
  112. package/dist/astro/routes/api/admin/plugins/registry/artifact.mjs +43 -40
  113. package/dist/astro/routes/api/admin/plugins/registry/artifact.mjs.map +1 -1
  114. package/dist/astro/routes/api/admin/plugins/registry/install.d.mts.map +1 -1
  115. package/dist/astro/routes/api/admin/plugins/registry/install.mjs +48 -43
  116. package/dist/astro/routes/api/admin/plugins/registry/install.mjs.map +1 -1
  117. package/dist/astro/routes/api/admin/plugins/updates.mjs +44 -41
  118. package/dist/astro/routes/api/admin/plugins/updates.mjs.map +1 -1
  119. package/dist/astro/routes/api/admin/themes/marketplace/_id_/index.mjs +43 -40
  120. package/dist/astro/routes/api/admin/themes/marketplace/_id_/index.mjs.map +1 -1
  121. package/dist/astro/routes/api/admin/themes/marketplace/_id_/thumbnail.mjs +4 -4
  122. package/dist/astro/routes/api/admin/themes/marketplace/index.mjs +43 -40
  123. package/dist/astro/routes/api/admin/themes/marketplace/index.mjs.map +1 -1
  124. package/dist/astro/routes/api/admin/users/_id_/disable.mjs +5 -5
  125. package/dist/astro/routes/api/admin/users/_id_/enable.mjs +4 -4
  126. package/dist/astro/routes/api/admin/users/_id_/index.mjs +10 -9
  127. package/dist/astro/routes/api/admin/users/_id_/index.mjs.map +1 -1
  128. package/dist/astro/routes/api/admin/users/_id_/send-recovery.mjs +6 -6
  129. package/dist/astro/routes/api/admin/users/index.mjs +9 -8
  130. package/dist/astro/routes/api/admin/users/index.mjs.map +1 -1
  131. package/dist/astro/routes/api/auth/dev-bypass.mjs +7 -7
  132. package/dist/astro/routes/api/auth/invite/accept.mjs +4 -4
  133. package/dist/astro/routes/api/auth/invite/complete.mjs +14 -13
  134. package/dist/astro/routes/api/auth/invite/complete.mjs.map +1 -1
  135. package/dist/astro/routes/api/auth/invite/index.mjs +11 -10
  136. package/dist/astro/routes/api/auth/invite/index.mjs.map +1 -1
  137. package/dist/astro/routes/api/auth/invite/register-options.mjs +13 -12
  138. package/dist/astro/routes/api/auth/invite/register-options.mjs.map +1 -1
  139. package/dist/astro/routes/api/auth/logout.mjs +4 -4
  140. package/dist/astro/routes/api/auth/magic-link/send.mjs +13 -12
  141. package/dist/astro/routes/api/auth/magic-link/send.mjs.map +1 -1
  142. package/dist/astro/routes/api/auth/magic-link/verify.mjs +5 -5
  143. package/dist/astro/routes/api/auth/me.mjs +9 -8
  144. package/dist/astro/routes/api/auth/me.mjs.map +1 -1
  145. package/dist/astro/routes/api/auth/mode.d.mts.map +1 -1
  146. package/dist/astro/routes/api/auth/mode.mjs +6 -3
  147. package/dist/astro/routes/api/auth/mode.mjs.map +1 -1
  148. package/dist/astro/routes/api/auth/oauth/_provider_/callback.mjs +16 -6
  149. package/dist/astro/routes/api/auth/oauth/_provider_/callback.mjs.map +1 -1
  150. package/dist/astro/routes/api/auth/oauth/_provider_.d.mts.map +1 -1
  151. package/dist/astro/routes/api/auth/oauth/_provider_.mjs +11 -5
  152. package/dist/astro/routes/api/auth/oauth/_provider_.mjs.map +1 -1
  153. package/dist/astro/routes/api/auth/passkey/_id_.mjs +8 -7
  154. package/dist/astro/routes/api/auth/passkey/_id_.mjs.map +1 -1
  155. package/dist/astro/routes/api/auth/passkey/index.mjs +3 -3
  156. package/dist/astro/routes/api/auth/passkey/options.mjs +14 -13
  157. package/dist/astro/routes/api/auth/passkey/options.mjs.map +1 -1
  158. package/dist/astro/routes/api/auth/passkey/register/options.mjs +12 -11
  159. package/dist/astro/routes/api/auth/passkey/register/options.mjs.map +1 -1
  160. package/dist/astro/routes/api/auth/passkey/register/verify.mjs +13 -12
  161. package/dist/astro/routes/api/auth/passkey/register/verify.mjs.map +1 -1
  162. package/dist/astro/routes/api/auth/passkey/verify.mjs +13 -12
  163. package/dist/astro/routes/api/auth/passkey/verify.mjs.map +1 -1
  164. package/dist/astro/routes/api/auth/signup/complete.mjs +14 -13
  165. package/dist/astro/routes/api/auth/signup/complete.mjs.map +1 -1
  166. package/dist/astro/routes/api/auth/signup/request.mjs +13 -12
  167. package/dist/astro/routes/api/auth/signup/request.mjs.map +1 -1
  168. package/dist/astro/routes/api/auth/signup/verify.mjs +4 -4
  169. package/dist/astro/routes/api/comments/_collection_/_contentId_/index.d.mts.map +1 -1
  170. package/dist/astro/routes/api/comments/_collection_/_contentId_/index.mjs +70 -14
  171. package/dist/astro/routes/api/comments/_collection_/_contentId_/index.mjs.map +1 -1
  172. package/dist/astro/routes/api/comments/_collection_/_contentId_/reactions.mjs +14 -13
  173. package/dist/astro/routes/api/comments/_collection_/_contentId_/reactions.mjs.map +1 -1
  174. package/dist/astro/routes/api/content/_collection_/_id_/compare.mjs +5 -5
  175. package/dist/astro/routes/api/content/_collection_/_id_/compare.mjs.map +1 -1
  176. package/dist/astro/routes/api/content/_collection_/_id_/discard-draft.mjs +5 -4
  177. package/dist/astro/routes/api/content/_collection_/_id_/discard-draft.mjs.map +1 -1
  178. package/dist/astro/routes/api/content/_collection_/_id_/duplicate.mjs +6 -5
  179. package/dist/astro/routes/api/content/_collection_/_id_/duplicate.mjs.map +1 -1
  180. package/dist/astro/routes/api/content/_collection_/_id_/permanent.mjs +5 -5
  181. package/dist/astro/routes/api/content/_collection_/_id_/permanent.mjs.map +1 -1
  182. package/dist/astro/routes/api/content/_collection_/_id_/preview-url.mjs +14 -13
  183. package/dist/astro/routes/api/content/_collection_/_id_/preview-url.mjs.map +1 -1
  184. package/dist/astro/routes/api/content/_collection_/_id_/publish.mjs +10 -8
  185. package/dist/astro/routes/api/content/_collection_/_id_/publish.mjs.map +1 -1
  186. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/children.d.mts +9 -0
  187. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/children.d.mts.map +1 -0
  188. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/children.mjs +72 -0
  189. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/children.mjs.map +1 -0
  190. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/parents.d.mts +8 -0
  191. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/parents.d.mts.map +1 -0
  192. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/parents.mjs +51 -0
  193. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/parents.mjs.map +1 -0
  194. package/dist/astro/routes/api/content/_collection_/_id_/restore.mjs +5 -4
  195. package/dist/astro/routes/api/content/_collection_/_id_/restore.mjs.map +1 -1
  196. package/dist/astro/routes/api/content/_collection_/_id_/revisions.mjs +5 -5
  197. package/dist/astro/routes/api/content/_collection_/_id_/revisions.mjs.map +1 -1
  198. package/dist/astro/routes/api/content/_collection_/_id_/schedule.mjs +10 -8
  199. package/dist/astro/routes/api/content/_collection_/_id_/schedule.mjs.map +1 -1
  200. package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.d.mts.map +1 -1
  201. package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.mjs +20 -19
  202. package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.mjs.map +1 -1
  203. package/dist/astro/routes/api/content/_collection_/_id_/translations.mjs +5 -5
  204. package/dist/astro/routes/api/content/_collection_/_id_/translations.mjs.map +1 -1
  205. package/dist/astro/routes/api/content/_collection_/_id_/unpublish.mjs +5 -4
  206. package/dist/astro/routes/api/content/_collection_/_id_/unpublish.mjs.map +1 -1
  207. package/dist/astro/routes/api/content/_collection_/_id_.d.mts.map +1 -1
  208. package/dist/astro/routes/api/content/_collection_/_id_.mjs +11 -9
  209. package/dist/astro/routes/api/content/_collection_/_id_.mjs.map +1 -1
  210. package/dist/astro/routes/api/content/_collection_/authors.mjs +5 -5
  211. package/dist/astro/routes/api/content/_collection_/authors.mjs.map +1 -1
  212. package/dist/astro/routes/api/content/_collection_/index.d.mts.map +1 -1
  213. package/dist/astro/routes/api/content/_collection_/index.mjs +12 -10
  214. package/dist/astro/routes/api/content/_collection_/index.mjs.map +1 -1
  215. package/dist/astro/routes/api/content/_collection_/trash.mjs +10 -9
  216. package/dist/astro/routes/api/content/_collection_/trash.mjs.map +1 -1
  217. package/dist/astro/routes/api/dashboard.mjs +8 -8
  218. package/dist/astro/routes/api/dev/emails.mjs +4 -4
  219. package/dist/astro/routes/api/import/probe.d.mts +3 -3
  220. package/dist/astro/routes/api/import/probe.mjs +19 -18
  221. package/dist/astro/routes/api/import/probe.mjs.map +1 -1
  222. package/dist/astro/routes/api/import/wordpress/analyze.mjs +5 -5
  223. package/dist/astro/routes/api/import/wordpress/execute.d.mts +11 -11
  224. package/dist/astro/routes/api/import/wordpress/execute.mjs +16 -16
  225. package/dist/astro/routes/api/import/wordpress/media.d.mts +10 -10
  226. package/dist/astro/routes/api/import/wordpress/media.mjs +12 -11
  227. package/dist/astro/routes/api/import/wordpress/media.mjs.map +1 -1
  228. package/dist/astro/routes/api/import/wordpress/prepare.mjs +12 -11
  229. package/dist/astro/routes/api/import/wordpress/prepare.mjs.map +1 -1
  230. package/dist/astro/routes/api/import/wordpress/rewrite-urls.d.mts +11 -16
  231. package/dist/astro/routes/api/import/wordpress/rewrite-urls.d.mts.map +1 -1
  232. package/dist/astro/routes/api/import/wordpress/rewrite-urls.mjs +12 -11
  233. package/dist/astro/routes/api/import/wordpress/rewrite-urls.mjs.map +1 -1
  234. package/dist/astro/routes/api/import/wordpress-plugin/analyze.d.mts +1 -1
  235. package/dist/astro/routes/api/import/wordpress-plugin/analyze.mjs +19 -18
  236. package/dist/astro/routes/api/import/wordpress-plugin/analyze.mjs.map +1 -1
  237. package/dist/astro/routes/api/import/wordpress-plugin/callback.mjs +1 -1
  238. package/dist/astro/routes/api/import/wordpress-plugin/execute.d.mts +11 -11
  239. package/dist/astro/routes/api/import/wordpress-plugin/execute.mjs +29 -28
  240. package/dist/astro/routes/api/import/wordpress-plugin/execute.mjs.map +1 -1
  241. package/dist/astro/routes/api/manifest.mjs +8 -9
  242. package/dist/astro/routes/api/manifest.mjs.map +1 -1
  243. package/dist/astro/routes/api/mcp.d.mts.map +1 -1
  244. package/dist/astro/routes/api/mcp.mjs +165 -52
  245. package/dist/astro/routes/api/mcp.mjs.map +1 -1
  246. package/dist/astro/routes/api/media/_id_/confirm.mjs +10 -9
  247. package/dist/astro/routes/api/media/_id_/confirm.mjs.map +1 -1
  248. package/dist/astro/routes/api/media/_id_/usage.d.mts +8 -0
  249. package/dist/astro/routes/api/media/_id_/usage.d.mts.map +1 -0
  250. package/dist/astro/routes/api/media/_id_/usage.mjs +37 -0
  251. package/dist/astro/routes/api/media/_id_/usage.mjs.map +1 -0
  252. package/dist/astro/routes/api/media/_id_.d.mts.map +1 -1
  253. package/dist/astro/routes/api/media/_id_.mjs +26 -10
  254. package/dist/astro/routes/api/media/_id_.mjs.map +1 -1
  255. package/dist/astro/routes/api/media/file/_...key_.mjs +4 -3
  256. package/dist/astro/routes/api/media/file/_...key_.mjs.map +1 -1
  257. package/dist/astro/routes/api/media/providers/_providerId_/_itemId_.mjs +4 -4
  258. package/dist/astro/routes/api/media/providers/_providerId_/index.mjs +4 -4
  259. package/dist/astro/routes/api/media/providers/index.mjs +4 -4
  260. package/dist/astro/routes/api/media/upload-url.mjs +11 -10
  261. package/dist/astro/routes/api/media/upload-url.mjs.map +1 -1
  262. package/dist/astro/routes/api/media.d.mts.map +1 -1
  263. package/dist/astro/routes/api/media.mjs +34 -14
  264. package/dist/astro/routes/api/media.mjs.map +1 -1
  265. package/dist/astro/routes/api/menus/_name_/items/_id_.mjs +10 -9
  266. package/dist/astro/routes/api/menus/_name_/items/_id_.mjs.map +1 -1
  267. package/dist/astro/routes/api/menus/_name_/items.mjs +10 -9
  268. package/dist/astro/routes/api/menus/_name_/items.mjs.map +1 -1
  269. package/dist/astro/routes/api/menus/_name_/reorder.mjs +10 -9
  270. package/dist/astro/routes/api/menus/_name_/reorder.mjs.map +1 -1
  271. package/dist/astro/routes/api/menus/_name_/translations.mjs +10 -9
  272. package/dist/astro/routes/api/menus/_name_/translations.mjs.map +1 -1
  273. package/dist/astro/routes/api/menus/_name_.mjs +10 -9
  274. package/dist/astro/routes/api/menus/_name_.mjs.map +1 -1
  275. package/dist/astro/routes/api/menus/index.mjs +10 -9
  276. package/dist/astro/routes/api/menus/index.mjs.map +1 -1
  277. package/dist/astro/routes/api/oauth/authorize.d.mts.map +1 -1
  278. package/dist/astro/routes/api/oauth/authorize.mjs +7 -8
  279. package/dist/astro/routes/api/oauth/authorize.mjs.map +1 -1
  280. package/dist/astro/routes/api/oauth/device/authorize.mjs +7 -7
  281. package/dist/astro/routes/api/oauth/device/code.mjs +10 -10
  282. package/dist/astro/routes/api/oauth/device/token.mjs +9 -9
  283. package/dist/astro/routes/api/oauth/register.mjs +4 -4
  284. package/dist/astro/routes/api/oauth/token/refresh.mjs +7 -7
  285. package/dist/astro/routes/api/oauth/token/revoke.mjs +7 -7
  286. package/dist/astro/routes/api/oauth/token.mjs +7 -7
  287. package/dist/astro/routes/api/openapi.json.mjs +71 -24
  288. package/dist/astro/routes/api/openapi.json.mjs.map +1 -1
  289. package/dist/astro/routes/api/plugins/_pluginId_/_...path_.d.mts.map +1 -1
  290. package/dist/astro/routes/api/plugins/_pluginId_/_...path_.mjs +20 -32
  291. package/dist/astro/routes/api/plugins/_pluginId_/_...path_.mjs.map +1 -1
  292. package/dist/astro/routes/api/redirects/404s/index.mjs +13 -12
  293. package/dist/astro/routes/api/redirects/404s/index.mjs.map +1 -1
  294. package/dist/astro/routes/api/redirects/404s/summary.mjs +13 -12
  295. package/dist/astro/routes/api/redirects/404s/summary.mjs.map +1 -1
  296. package/dist/astro/routes/api/redirects/_id_.mjs +14 -13
  297. package/dist/astro/routes/api/redirects/_id_.mjs.map +1 -1
  298. package/dist/astro/routes/api/redirects/index.mjs +14 -13
  299. package/dist/astro/routes/api/redirects/index.mjs.map +1 -1
  300. package/dist/astro/routes/api/relations/_id_/index.d.mts +10 -0
  301. package/dist/astro/routes/api/relations/_id_/index.d.mts.map +1 -0
  302. package/dist/astro/routes/api/relations/_id_/index.mjs +70 -0
  303. package/dist/astro/routes/api/relations/_id_/index.mjs.map +1 -0
  304. package/dist/astro/routes/api/relations/_id_/translations.d.mts +8 -0
  305. package/dist/astro/routes/api/relations/_id_/translations.d.mts.map +1 -0
  306. package/dist/astro/routes/api/relations/_id_/translations.mjs +34 -0
  307. package/dist/astro/routes/api/relations/_id_/translations.mjs.map +1 -0
  308. package/dist/astro/routes/api/relations/index.d.mts +9 -0
  309. package/dist/astro/routes/api/relations/index.d.mts.map +1 -0
  310. package/dist/astro/routes/api/relations/index.mjs +54 -0
  311. package/dist/astro/routes/api/relations/index.mjs.map +1 -0
  312. package/dist/astro/routes/api/revisions/_revisionId_/index.mjs +4 -4
  313. package/dist/astro/routes/api/revisions/_revisionId_/restore.mjs +5 -4
  314. package/dist/astro/routes/api/revisions/_revisionId_/restore.mjs.map +1 -1
  315. package/dist/astro/routes/api/schema/collections/_slug_/fields/_fieldSlug_.d.mts.map +1 -1
  316. package/dist/astro/routes/api/schema/collections/_slug_/fields/_fieldSlug_.mjs +43 -40
  317. package/dist/astro/routes/api/schema/collections/_slug_/fields/_fieldSlug_.mjs.map +1 -1
  318. package/dist/astro/routes/api/schema/collections/_slug_/fields/index.d.mts.map +1 -1
  319. package/dist/astro/routes/api/schema/collections/_slug_/fields/index.mjs +43 -40
  320. package/dist/astro/routes/api/schema/collections/_slug_/fields/index.mjs.map +1 -1
  321. package/dist/astro/routes/api/schema/collections/_slug_/fields/reorder.mjs +43 -40
  322. package/dist/astro/routes/api/schema/collections/_slug_/fields/reorder.mjs.map +1 -1
  323. package/dist/astro/routes/api/schema/collections/_slug_/index.mjs +43 -40
  324. package/dist/astro/routes/api/schema/collections/_slug_/index.mjs.map +1 -1
  325. package/dist/astro/routes/api/schema/collections/index.mjs +43 -40
  326. package/dist/astro/routes/api/schema/collections/index.mjs.map +1 -1
  327. package/dist/astro/routes/api/schema/index.mjs +9 -9
  328. package/dist/astro/routes/api/schema/orphans/_slug_.mjs +43 -40
  329. package/dist/astro/routes/api/schema/orphans/_slug_.mjs.map +1 -1
  330. package/dist/astro/routes/api/schema/orphans/index.mjs +43 -40
  331. package/dist/astro/routes/api/schema/orphans/index.mjs.map +1 -1
  332. package/dist/astro/routes/api/search/enable.mjs +13 -12
  333. package/dist/astro/routes/api/search/enable.mjs.map +1 -1
  334. package/dist/astro/routes/api/search/index.mjs +14 -12
  335. package/dist/astro/routes/api/search/index.mjs.map +1 -1
  336. package/dist/astro/routes/api/search/rebuild.mjs +13 -12
  337. package/dist/astro/routes/api/search/rebuild.mjs.map +1 -1
  338. package/dist/astro/routes/api/search/stats.mjs +8 -8
  339. package/dist/astro/routes/api/search/suggest.mjs +12 -11
  340. package/dist/astro/routes/api/search/suggest.mjs.map +1 -1
  341. package/dist/astro/routes/api/sections/_slug_.mjs +12 -11
  342. package/dist/astro/routes/api/sections/_slug_.mjs.map +1 -1
  343. package/dist/astro/routes/api/sections/index.mjs +12 -11
  344. package/dist/astro/routes/api/sections/index.mjs.map +1 -1
  345. package/dist/astro/routes/api/settings/backups/archives/_name_.d.mts +9 -0
  346. package/dist/astro/routes/api/settings/backups/archives/_name_.d.mts.map +1 -0
  347. package/dist/astro/routes/api/settings/backups/archives/_name_.mjs +48 -0
  348. package/dist/astro/routes/api/settings/backups/archives/_name_.mjs.map +1 -0
  349. package/dist/astro/routes/api/settings/backups/archives/index.d.mts +8 -0
  350. package/dist/astro/routes/api/settings/backups/archives/index.d.mts.map +1 -0
  351. package/dist/astro/routes/api/settings/backups/archives/index.mjs +23 -0
  352. package/dist/astro/routes/api/settings/backups/archives/index.mjs.map +1 -0
  353. package/dist/astro/routes/api/settings/backups/export.d.mts +8 -0
  354. package/dist/astro/routes/api/settings/backups/export.d.mts.map +1 -0
  355. package/dist/astro/routes/api/settings/backups/export.mjs +35 -0
  356. package/dist/astro/routes/api/settings/backups/export.mjs.map +1 -0
  357. package/dist/astro/routes/api/settings/backups/index.d.mts +9 -0
  358. package/dist/astro/routes/api/settings/backups/index.d.mts.map +1 -0
  359. package/dist/astro/routes/api/settings/backups/index.mjs +52 -0
  360. package/dist/astro/routes/api/settings/backups/index.mjs.map +1 -0
  361. package/dist/astro/routes/api/settings/email.mjs +6 -6
  362. package/dist/astro/routes/api/settings.mjs +16 -15
  363. package/dist/astro/routes/api/settings.mjs.map +1 -1
  364. package/dist/astro/routes/api/setup/admin-verify.mjs +20 -16
  365. package/dist/astro/routes/api/setup/admin-verify.mjs.map +1 -1
  366. package/dist/astro/routes/api/setup/admin.mjs +19 -15
  367. package/dist/astro/routes/api/setup/admin.mjs.map +1 -1
  368. package/dist/astro/routes/api/setup/dev-bypass.mjs +29 -29
  369. package/dist/astro/routes/api/setup/dev-reset.mjs +4 -4
  370. package/dist/astro/routes/api/setup/index.mjs +31 -30
  371. package/dist/astro/routes/api/setup/index.mjs.map +1 -1
  372. package/dist/astro/routes/api/setup/status.mjs +5 -5
  373. package/dist/astro/routes/api/snapshot.mjs +9 -216
  374. package/dist/astro/routes/api/snapshot.mjs.map +1 -1
  375. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_/translations.mjs +16 -15
  376. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_/translations.mjs.map +1 -1
  377. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_.mjs +16 -15
  378. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_.mjs.map +1 -1
  379. package/dist/astro/routes/api/taxonomies/_name_/terms/index.mjs +16 -15
  380. package/dist/astro/routes/api/taxonomies/_name_/terms/index.mjs.map +1 -1
  381. package/dist/astro/routes/api/taxonomies/index.mjs +16 -15
  382. package/dist/astro/routes/api/taxonomies/index.mjs.map +1 -1
  383. package/dist/astro/routes/api/themes/preview.mjs +7 -7
  384. package/dist/astro/routes/api/typegen.mjs +6 -6
  385. package/dist/astro/routes/api/well-known/auth.mjs +2 -2
  386. package/dist/astro/routes/api/well-known/oauth-authorization-server.d.mts.map +1 -1
  387. package/dist/astro/routes/api/well-known/oauth-authorization-server.mjs +4 -3
  388. package/dist/astro/routes/api/well-known/oauth-authorization-server.mjs.map +1 -1
  389. package/dist/astro/routes/api/well-known/oauth-protected-resource.d.mts.map +1 -1
  390. package/dist/astro/routes/api/well-known/oauth-protected-resource.mjs +4 -3
  391. package/dist/astro/routes/api/well-known/oauth-protected-resource.mjs.map +1 -1
  392. package/dist/astro/routes/api/widget-areas/_name_/reorder.mjs +9 -8
  393. package/dist/astro/routes/api/widget-areas/_name_/reorder.mjs.map +1 -1
  394. package/dist/astro/routes/api/widget-areas/_name_/widgets/_id_.mjs +13 -12
  395. package/dist/astro/routes/api/widget-areas/_name_/widgets/_id_.mjs.map +1 -1
  396. package/dist/astro/routes/api/widget-areas/_name_/widgets.mjs +13 -12
  397. package/dist/astro/routes/api/widget-areas/_name_/widgets.mjs.map +1 -1
  398. package/dist/astro/routes/api/widget-areas/_name_.mjs +8 -8
  399. package/dist/astro/routes/api/widget-areas/index.mjs +13 -12
  400. package/dist/astro/routes/api/widget-areas/index.mjs.map +1 -1
  401. package/dist/astro/routes/api/widget-components.mjs +4 -4
  402. package/dist/astro/routes/robots.txt.mjs +9 -9
  403. package/dist/astro/routes/sitemap-_collection_.xml.mjs +12 -12
  404. package/dist/astro/routes/sitemap.xml.mjs +10 -10
  405. package/dist/astro/types.d.mts +40 -16
  406. package/dist/astro/types.d.mts.map +1 -1
  407. package/dist/auth/providers/github.d.mts +1 -1
  408. package/dist/auth/providers/google.d.mts +1 -1
  409. package/dist/{authorize-Dz88F_Fw.mjs → authorize-WxsiePzy.mjs} +7 -4
  410. package/dist/authorize-WxsiePzy.mjs.map +1 -0
  411. package/dist/backup-S8kFWtwD.mjs +241 -0
  412. package/dist/backup-S8kFWtwD.mjs.map +1 -0
  413. package/dist/{base64-CmWvODNW.mjs → base64-B-PsqheR.mjs} +8 -4
  414. package/dist/base64-B-PsqheR.mjs.map +1 -0
  415. package/dist/{byline-Bm8ZgUP9.mjs → byline-XEjchwzZ.mjs} +8 -8
  416. package/dist/{byline-Bm8ZgUP9.mjs.map → byline-XEjchwzZ.mjs.map} +1 -1
  417. package/dist/{byline-fields-CIx_GuN4.mjs → byline-fields-CdU_LTF1.mjs} +2 -2
  418. package/dist/{byline-fields-CIx_GuN4.mjs.map → byline-fields-CdU_LTF1.mjs.map} +1 -1
  419. package/dist/{byline-registry-BOjqDOim.mjs → byline-registry-BCuOp4UF.mjs} +3 -3
  420. package/dist/{byline-registry-BOjqDOim.mjs.map → byline-registry-BCuOp4UF.mjs.map} +1 -1
  421. package/dist/{bylines-6tm9mgQb.mjs → bylines-BJbT4gKS.mjs} +4 -4
  422. package/dist/{bylines-6tm9mgQb.mjs.map → bylines-BJbT4gKS.mjs.map} +1 -1
  423. package/dist/{bylines-CAZxGSrm.mjs → bylines-czseViYo.mjs} +8 -8
  424. package/dist/{bylines-CAZxGSrm.mjs.map → bylines-czseViYo.mjs.map} +1 -1
  425. package/dist/{cache-CEBAZjir.mjs → cache-CGCd6AVM.mjs} +3 -3
  426. package/dist/{cache-CEBAZjir.mjs.map → cache-CGCd6AVM.mjs.map} +1 -1
  427. package/dist/{challenge-store-anhwVER0.mjs → challenge-store-BFzgFRog.mjs} +1 -1
  428. package/dist/{challenge-store-anhwVER0.mjs.map → challenge-store-BFzgFRog.mjs.map} +1 -1
  429. package/dist/{chunks-B2isWQhr.mjs → chunks-BxXyunY-.mjs} +2 -2
  430. package/dist/{chunks-B2isWQhr.mjs.map → chunks-BxXyunY-.mjs.map} +1 -1
  431. package/dist/cli/index.mjs +142 -35
  432. package/dist/cli/index.mjs.map +1 -1
  433. package/dist/client/cf-access.d.mts +1 -1
  434. package/dist/client/index.d.mts +86 -3
  435. package/dist/client/index.d.mts.map +1 -1
  436. package/dist/client/index.mjs +20 -4
  437. package/dist/client/index.mjs.map +1 -1
  438. package/dist/{comment-CzeatwBV.mjs → comment-DPT0WKyd.mjs} +2 -2
  439. package/dist/{comment-CzeatwBV.mjs.map → comment-DPT0WKyd.mjs.map} +1 -1
  440. package/dist/{comment-reaction-Cj9QJY7I.mjs → comment-reaction-C65MldIB.mjs} +2 -2
  441. package/dist/{comment-reaction-Cj9QJY7I.mjs.map → comment-reaction-C65MldIB.mjs.map} +1 -1
  442. package/dist/{comments-BLE-jv5k.mjs → comments-Bz6sCbgD.mjs} +3 -3
  443. package/dist/{comments-BLE-jv5k.mjs.map → comments-Bz6sCbgD.mjs.map} +1 -1
  444. package/dist/{components-B_sATNUc.mjs → components-DZkL4Fx0.mjs} +1 -1
  445. package/dist/{components-B_sATNUc.mjs.map → components-DZkL4Fx0.mjs.map} +1 -1
  446. package/dist/{content-DhgEth4k.mjs → content-Ci04z2z-.mjs} +227 -34
  447. package/dist/content-Ci04z2z-.mjs.map +1 -0
  448. package/dist/{content-refresh-Br4gMzh8.mjs → content-refresh-D4khvC0R.mjs} +100 -8
  449. package/dist/content-refresh-D4khvC0R.mjs.map +1 -0
  450. package/dist/{context-BRIpHARC.mjs → context-B6hc7zJL.mjs} +156 -76
  451. package/dist/context-B6hc7zJL.mjs.map +1 -0
  452. package/dist/{cron-v4FTEFR_.mjs → cron-BlKIMD_e.mjs} +1 -1
  453. package/dist/{cron-v4FTEFR_.mjs.map → cron-BlKIMD_e.mjs.map} +1 -1
  454. package/dist/{dashboard-EvEKF5en.mjs → dashboard-C5NkXFbi.mjs} +6 -5
  455. package/dist/dashboard-C5NkXFbi.mjs.map +1 -0
  456. package/dist/database/pg-migration-lock.d.mts +21 -0
  457. package/dist/database/pg-migration-lock.d.mts.map +1 -0
  458. package/dist/database/pg-migration-lock.mjs +45 -0
  459. package/dist/database/pg-migration-lock.mjs.map +1 -0
  460. package/dist/db/index.d.mts +3 -3
  461. package/dist/db/index.mjs +2 -2
  462. package/dist/db/index.mjs.map +1 -1
  463. package/dist/db/libsql.d.mts +1 -1
  464. package/dist/db/postgres.d.mts +1 -1
  465. package/dist/db/postgres.d.mts.map +1 -1
  466. package/dist/db/postgres.mjs +2 -8
  467. package/dist/db/postgres.mjs.map +1 -1
  468. package/dist/db/sqlite.d.mts +1 -1
  469. package/dist/{db-errors-CK46D-ly.mjs → db-errors-CcWLaRiR.mjs} +4 -2
  470. package/dist/db-errors-CcWLaRiR.mjs.map +1 -0
  471. package/dist/{default-CM_D83Mg.mjs → default-C4v9KP56.mjs} +1 -1
  472. package/dist/{default-CM_D83Mg.mjs.map → default-C4v9KP56.mjs.map} +1 -1
  473. package/dist/{device-flow-CfGP18Uw.mjs → device-flow-BeA6lUS1.mjs} +6 -7
  474. package/dist/device-flow-BeA6lUS1.mjs.map +1 -0
  475. package/dist/dialect-helpers-HxEQGl_1.mjs +175 -0
  476. package/dist/dialect-helpers-HxEQGl_1.mjs.map +1 -0
  477. package/dist/{email-console-CIf4Lfvv.mjs → email-console-C-9Ng8DM.mjs} +1 -1
  478. package/dist/{email-console-CIf4Lfvv.mjs.map → email-console-C-9Ng8DM.mjs.map} +1 -1
  479. package/dist/{enrich-BQ0mxJRs.mjs → enrich-CFJJgxs_.mjs} +2 -2
  480. package/dist/{enrich-BQ0mxJRs.mjs.map → enrich-CFJJgxs_.mjs.map} +1 -1
  481. package/dist/error-CEGF6UZb.mjs +90 -0
  482. package/dist/error-CEGF6UZb.mjs.map +1 -0
  483. package/dist/{error-CkAseSqZ.mjs → errors-DtEXIQQV.mjs} +24 -84
  484. package/dist/errors-DtEXIQQV.mjs.map +1 -0
  485. package/dist/{escape-DqD0aCKu.mjs → escape-CFedIB1C.mjs} +1 -1
  486. package/dist/{escape-DqD0aCKu.mjs.map → escape-CFedIB1C.mjs.map} +1 -1
  487. package/dist/{field-defs-cache-WUI88LX5.mjs → field-defs-cache-DvmlgP-D.mjs} +5 -5
  488. package/dist/{field-defs-cache-WUI88LX5.mjs.map → field-defs-cache-DvmlgP-D.mjs.map} +1 -1
  489. package/dist/{fts-manager-BbFaF_V8.mjs → fts-manager-DzqIBrrW.mjs} +27 -3
  490. package/dist/{fts-manager-BbFaF_V8.mjs.map → fts-manager-DzqIBrrW.mjs.map} +1 -1
  491. package/dist/{hash-DrvzIXcz.mjs → hash-DFFrkivP.mjs} +1 -1
  492. package/dist/{hash-DrvzIXcz.mjs.map → hash-DFFrkivP.mjs.map} +1 -1
  493. package/dist/hreflang-CIxH_LKz.d.mts +48 -0
  494. package/dist/hreflang-CIxH_LKz.d.mts.map +1 -0
  495. package/dist/hreflang-db2Tpb2o.mjs +102 -0
  496. package/dist/hreflang-db2Tpb2o.mjs.map +1 -0
  497. package/dist/{import-fYLf14Co.mjs → import-Dmkm8S1W.mjs} +6 -6
  498. package/dist/{import-fYLf14Co.mjs.map → import-Dmkm8S1W.mjs.map} +1 -1
  499. package/dist/{index-Bm-Gy8Mh.d.mts → index-BEui-cRd.d.mts} +3 -3
  500. package/dist/{index-Bm-Gy8Mh.d.mts.map → index-BEui-cRd.d.mts.map} +1 -1
  501. package/dist/{index-B9sIxwe4.d.mts → index-wYnC6u4o.d.mts} +881 -22
  502. package/dist/index-wYnC6u4o.d.mts.map +1 -0
  503. package/dist/index.d.mts +19 -19
  504. package/dist/index.mjs +69 -64
  505. package/dist/{init-lock-6b309ZrF.mjs → init-lock-DJkX6Hto.mjs} +1 -1
  506. package/dist/{init-lock-6b309ZrF.mjs.map → init-lock-DJkX6Hto.mjs.map} +1 -1
  507. package/dist/{load-Djn3HWQS.mjs → load-Cx27ki1l.mjs} +2 -2
  508. package/dist/{load-Djn3HWQS.mjs.map → load-Cx27ki1l.mjs.map} +1 -1
  509. package/dist/{loader-CB6YHeul.mjs → loader-Be3ouI5L.mjs} +170 -21
  510. package/dist/loader-Be3ouI5L.mjs.map +1 -0
  511. package/dist/{manifest-schema-BHlgZM1W.mjs → manifest-schema-bCq54i7F.mjs} +18 -2
  512. package/dist/manifest-schema-bCq54i7F.mjs.map +1 -0
  513. package/dist/media/image-endpoint.d.mts +30 -2
  514. package/dist/media/image-endpoint.d.mts.map +1 -1
  515. package/dist/media/image-endpoint.mjs +30 -4
  516. package/dist/media/image-endpoint.mjs.map +1 -1
  517. package/dist/media/index.d.mts +1 -1
  518. package/dist/media/index.mjs +2 -2
  519. package/dist/media/local-runtime.d.mts +12 -12
  520. package/dist/media/local-runtime.mjs +8 -8
  521. package/dist/{media-BrXIaMFN.mjs → media-BjhhENaJ.mjs} +2 -2
  522. package/dist/media-BjhhENaJ.mjs.map +1 -0
  523. package/dist/{media-allowlist-CRHEeJ_i.mjs → media-allowlist-jUppPWFy.mjs} +2 -2
  524. package/dist/{media-allowlist-CRHEeJ_i.mjs.map → media-allowlist-jUppPWFy.mjs.map} +1 -1
  525. package/dist/media-kIV1IxFf.mjs +243 -0
  526. package/dist/media-kIV1IxFf.mjs.map +1 -0
  527. package/dist/media-upload-D2wk3EIt.mjs +145 -0
  528. package/dist/media-upload-D2wk3EIt.mjs.map +1 -0
  529. package/dist/{media-url-CKi5XSw4.mjs → media-url-BCm5vBn6.mjs} +1 -1
  530. package/dist/{media-url-CKi5XSw4.mjs.map → media-url-BCm5vBn6.mjs.map} +1 -1
  531. package/dist/media-usage-CljdO1mc.mjs +554 -0
  532. package/dist/media-usage-CljdO1mc.mjs.map +1 -0
  533. package/dist/{menus-b2T4clbO.mjs → menus-BcyElFtI.mjs} +177 -15
  534. package/dist/menus-BcyElFtI.mjs.map +1 -0
  535. package/dist/{menus-Cfivc2Ad.mjs → menus-CZyG6rvx.mjs} +3 -3
  536. package/dist/{menus-Cfivc2Ad.mjs.map → menus-CZyG6rvx.mjs.map} +1 -1
  537. package/dist/{mime-CCEzze7W.mjs → mime-DfIVjNkr.mjs} +1 -1
  538. package/dist/{mime-CCEzze7W.mjs.map → mime-DfIVjNkr.mjs.map} +1 -1
  539. package/dist/{mode-BM9QgEmt.mjs → mode-fiXRMfeA.mjs} +1 -1
  540. package/dist/{mode-BM9QgEmt.mjs.map → mode-fiXRMfeA.mjs.map} +1 -1
  541. package/dist/{normalize-CeglrBT9.mjs → normalize-C-SHXmra.mjs} +1 -1
  542. package/dist/{normalize-CeglrBT9.mjs.map → normalize-C-SHXmra.mjs.map} +1 -1
  543. package/dist/{oauth-authorization-CXWkIGT4.mjs → oauth-authorization-oqfbBuMH.mjs} +6 -7
  544. package/dist/oauth-authorization-oqfbBuMH.mjs.map +1 -0
  545. package/dist/{oauth-clients-BmTI5rsl.mjs → oauth-clients-BlrUHAsf.mjs} +1 -1
  546. package/dist/{oauth-clients-BmTI5rsl.mjs.map → oauth-clients-BlrUHAsf.mjs.map} +1 -1
  547. package/dist/{oauth-state-store-YLFLcH5F.mjs → oauth-state-store-DnvjRMy6.mjs} +2 -1
  548. package/dist/{oauth-state-store-YLFLcH5F.mjs.map → oauth-state-store-DnvjRMy6.mjs.map} +1 -1
  549. package/dist/{oauth-user-lookup-Bsc_GsX-.mjs → oauth-user-lookup-oUllxvAv.mjs} +1 -1
  550. package/dist/{oauth-user-lookup-Bsc_GsX-.mjs.map → oauth-user-lookup-oUllxvAv.mjs.map} +1 -1
  551. package/dist/object-cache/memory.d.mts +1 -1
  552. package/dist/{options-DTTML-Tx.mjs → options-BlmBHTvX.mjs} +1 -1
  553. package/dist/{options-DTTML-Tx.mjs.map → options-BlmBHTvX.mjs.map} +1 -1
  554. package/dist/{options-iMpRRxIe.d.mts → options-BqMkWfYa.d.mts} +6 -6
  555. package/dist/{options-iMpRRxIe.d.mts.map → options-BqMkWfYa.d.mts.map} +1 -1
  556. package/dist/page/index.d.mts +2 -2
  557. package/dist/page/index.d.mts.map +1 -1
  558. package/dist/page/index.mjs.map +1 -1
  559. package/dist/{parse-GmjecGct.mjs → parse-C_-6klII.mjs} +4 -12
  560. package/dist/{parse-GmjecGct.mjs.map → parse-C_-6klII.mjs.map} +1 -1
  561. package/dist/{passkey-config-De0ahnRg.mjs → passkey-config-C-SKpc0-.mjs} +1 -1
  562. package/dist/{passkey-config-De0ahnRg.mjs.map → passkey-config-C-SKpc0-.mjs.map} +1 -1
  563. package/dist/{patterns-BKmjvM7K.mjs → patterns-CiyXeDgr.mjs} +1 -1
  564. package/dist/{patterns-BKmjvM7K.mjs.map → patterns-CiyXeDgr.mjs.map} +1 -1
  565. package/dist/{placeholder-BSKwzRe4.d.mts → placeholder-Dop47JMM.d.mts} +1 -1
  566. package/dist/{placeholder-BSKwzRe4.d.mts.map → placeholder-Dop47JMM.d.mts.map} +1 -1
  567. package/dist/plugin-types.d.mts +21 -2
  568. package/dist/plugin-types.d.mts.map +1 -1
  569. package/dist/plugin-utils.d.mts +18 -16
  570. package/dist/plugin-utils.d.mts.map +1 -1
  571. package/dist/plugin-utils.mjs +8 -6
  572. package/dist/plugin-utils.mjs.map +1 -1
  573. package/dist/plugins/adapt-sandbox-entry.d.mts +10 -10
  574. package/dist/plugins/adapt-sandbox-entry.d.mts.map +1 -1
  575. package/dist/plugins/adapt-sandbox-entry.mjs +15 -3
  576. package/dist/plugins/adapt-sandbox-entry.mjs.map +1 -1
  577. package/dist/{portable-text-cCa0cGV6.mjs → portable-text-sDj92Kxv.mjs} +1 -1
  578. package/dist/{portable-text-cCa0cGV6.mjs.map → portable-text-sDj92Kxv.mjs.map} +1 -1
  579. package/dist/{preview-SSXNVPAC.mjs → preview-D4Jnbfx7.mjs} +2 -2
  580. package/dist/{preview-SSXNVPAC.mjs.map → preview-D4Jnbfx7.mjs.map} +1 -1
  581. package/dist/{public-url-Danv47cS.mjs → public-url-DSGTnJFw.mjs} +5 -3
  582. package/dist/public-url-DSGTnJFw.mjs.map +1 -0
  583. package/dist/{query-1Cp6U9oo.mjs → query-DR73ZNfm.mjs} +15 -15
  584. package/dist/query-DR73ZNfm.mjs.map +1 -0
  585. package/dist/{schema-CX9cfNkZ.mjs → query-Di7DOmPV.mjs} +5 -10
  586. package/dist/query-Di7DOmPV.mjs.map +1 -0
  587. package/dist/{rate-limit-C_Lf63Dd.mjs → rate-limit-CMj83JNW.mjs} +2 -2
  588. package/dist/{rate-limit-C_Lf63Dd.mjs.map → rate-limit-CMj83JNW.mjs.map} +1 -1
  589. package/dist/{redirect-CoW3G-0U.mjs → redirect-Botom7X6.mjs} +1 -1
  590. package/dist/{redirect-CoW3G-0U.mjs.map → redirect-Botom7X6.mjs.map} +1 -1
  591. package/dist/{redirect-IyfNirgS.mjs → redirect-CgLPYflR.mjs} +11 -5
  592. package/dist/redirect-CgLPYflR.mjs.map +1 -0
  593. package/dist/{redirects-Bs1g42Ri.mjs → redirects-B7t9bKsL.mjs} +6 -6
  594. package/dist/{redirects-Bs1g42Ri.mjs.map → redirects-B7t9bKsL.mjs.map} +1 -1
  595. package/dist/{redirects-DXEXBAII.mjs → redirects-BBq3n2Rj.mjs} +10 -143
  596. package/dist/redirects-BBq3n2Rj.mjs.map +1 -0
  597. package/dist/{registry-B57vp_X9.mjs → registry-FV15nLge.mjs} +99 -10
  598. package/dist/registry-FV15nLge.mjs.map +1 -0
  599. package/dist/relation-9M9j_UWo.mjs +334 -0
  600. package/dist/relation-9M9j_UWo.mjs.map +1 -0
  601. package/dist/{byline-fields-2Lp5Hbgf.mjs → relations-5_avdrN_.mjs} +60 -4
  602. package/dist/relations-5_avdrN_.mjs.map +1 -0
  603. package/dist/relations-BKvO39-9.mjs +397 -0
  604. package/dist/relations-BKvO39-9.mjs.map +1 -0
  605. package/dist/{byline-fields-CHE8UStY.d.mts → relations-Bh8jlFsU.d.mts} +486 -31
  606. package/dist/relations-Bh8jlFsU.d.mts.map +1 -0
  607. package/dist/{request-cache-KCNHp_RJ.mjs → request-cache-BSUptuJR.mjs} +1 -1
  608. package/dist/{request-cache-KCNHp_RJ.mjs.map → request-cache-BSUptuJR.mjs.map} +1 -1
  609. package/dist/{request-meta-DbvXaAvU.mjs → request-meta-DzXYYI-n.mjs} +2 -2
  610. package/dist/{request-meta-DbvXaAvU.mjs.map → request-meta-DzXYYI-n.mjs.map} +1 -1
  611. package/dist/{resolve-DR3wqMTy.mjs → resolve-Cd9dzclN.mjs} +1 -1
  612. package/dist/{resolve-DR3wqMTy.mjs.map → resolve-Cd9dzclN.mjs.map} +1 -1
  613. package/dist/{runner-DvFWoz8-.d.mts → runner-Dd8m8k9F.d.mts} +8 -2
  614. package/dist/runner-Dd8m8k9F.d.mts.map +1 -0
  615. package/dist/{runner-K8XK101B.mjs → runner-DfnZ5eUr.mjs} +355 -204
  616. package/dist/runner-DfnZ5eUr.mjs.map +1 -0
  617. package/dist/runtime.d.mts +11 -11
  618. package/dist/runtime.mjs +4 -4
  619. package/dist/schema-BXxlHeAf.mjs +9 -0
  620. package/dist/schema-BXxlHeAf.mjs.map +1 -0
  621. package/dist/scopes-Bl4IwHA-.mjs +27 -0
  622. package/dist/scopes-Bl4IwHA-.mjs.map +1 -0
  623. package/dist/{search-DZN2HZ-V.mjs → search-Bff-7jFt.mjs} +62 -12
  624. package/dist/search-Bff-7jFt.mjs.map +1 -0
  625. package/dist/{secrets-kp760LlD.mjs → secrets-CSwQIl4q.mjs} +4 -4
  626. package/dist/{secrets-kp760LlD.mjs.map → secrets-CSwQIl4q.mjs.map} +1 -1
  627. package/dist/{sections-CpF5SaGr.mjs → sections-CwW4s1al.mjs} +3 -3
  628. package/dist/{sections-CpF5SaGr.mjs.map → sections-CwW4s1al.mjs.map} +1 -1
  629. package/dist/seed/index.d.mts +2 -2
  630. package/dist/seed/index.mjs +23 -23
  631. package/dist/seo/index.d.mts +15 -2
  632. package/dist/seo/index.d.mts.map +1 -1
  633. package/dist/seo/index.mjs +22 -5
  634. package/dist/seo/index.mjs.map +1 -1
  635. package/dist/{seo-DXu2UQnC.mjs → seo-2cmFHZns.mjs} +2 -2
  636. package/dist/{seo-DXu2UQnC.mjs.map → seo-2cmFHZns.mjs.map} +1 -1
  637. package/dist/{seo-89-53DDs.mjs → seo-C3GDfT0V.mjs} +1 -1
  638. package/dist/{seo-89-53DDs.mjs.map → seo-C3GDfT0V.mjs.map} +1 -1
  639. package/dist/{service-DQmiBMzt.mjs → service-DkGTWGIi.mjs} +3 -3
  640. package/dist/{service-DQmiBMzt.mjs.map → service-DkGTWGIi.mjs.map} +1 -1
  641. package/dist/{session-user-Cascbax7.mjs → session-user-DbHqKDKe.mjs} +1 -1
  642. package/dist/{session-user-Cascbax7.mjs.map → session-user-DbHqKDKe.mjs.map} +1 -1
  643. package/dist/{settings-rZyHEcNT.mjs → settings-C4s8hFQm.mjs} +3 -3
  644. package/dist/{settings-rZyHEcNT.mjs.map → settings-C4s8hFQm.mjs.map} +1 -1
  645. package/dist/{settings-zhmdKyJQ.mjs → settings-CpA4lQFt.mjs} +6 -6
  646. package/dist/{settings-zhmdKyJQ.mjs.map → settings-CpA4lQFt.mjs.map} +1 -1
  647. package/dist/{setup-complete-Cb3LRyzy.mjs → setup-complete-CdIlqloh.mjs} +2 -2
  648. package/dist/{setup-complete-Cb3LRyzy.mjs.map → setup-complete-CdIlqloh.mjs.map} +1 -1
  649. package/dist/{setup-nonce-Z8x0tHf8.mjs → setup-nonce-DqiIPr-J.mjs} +1 -1
  650. package/dist/{setup-nonce-Z8x0tHf8.mjs.map → setup-nonce-DqiIPr-J.mjs.map} +1 -1
  651. package/dist/{single-flight-cache-BG3B_GhN.mjs → single-flight-cache-C2exrGAi.mjs} +2 -2
  652. package/dist/{single-flight-cache-BG3B_GhN.mjs.map → single-flight-cache-C2exrGAi.mjs.map} +1 -1
  653. package/dist/{site-url-BBfDTgZB.mjs → site-url-NGJT6NTU.mjs} +2 -2
  654. package/dist/{site-url-BBfDTgZB.mjs.map → site-url-NGJT6NTU.mjs.map} +1 -1
  655. package/dist/{slugify-Cce3dTdg.mjs → slugify-C_tqlU4G.mjs} +1 -1
  656. package/dist/{slugify-Cce3dTdg.mjs.map → slugify-C_tqlU4G.mjs.map} +1 -1
  657. package/dist/snapshot-BdpUJKD-.mjs +216 -0
  658. package/dist/snapshot-BdpUJKD-.mjs.map +1 -0
  659. package/dist/{ssrf-1g7usGBg.mjs → ssrf-CviKqWmq.mjs} +1 -1
  660. package/dist/{ssrf-1g7usGBg.mjs.map → ssrf-CviKqWmq.mjs.map} +1 -1
  661. package/dist/state-xxv6ZTMv.mjs +128 -0
  662. package/dist/state-xxv6ZTMv.mjs.map +1 -0
  663. package/dist/{status-CqJQX1QN.mjs → status-COfycGIU.mjs} +1 -1
  664. package/dist/{status-CqJQX1QN.mjs.map → status-COfycGIU.mjs.map} +1 -1
  665. package/dist/storage/local.d.mts +1 -1
  666. package/dist/storage/local.mjs +1 -1
  667. package/dist/storage/s3.d.mts +1 -1
  668. package/dist/storage/s3.mjs +1 -1
  669. package/dist/{taxonomies-Bs13SN-F.mjs → taxonomies-Ce49uIzY.mjs} +13 -9
  670. package/dist/taxonomies-Ce49uIzY.mjs.map +1 -0
  671. package/dist/{taxonomies-kH9ABDUF.mjs → taxonomies-DjSKBZpq.mjs} +115 -36
  672. package/dist/taxonomies-DjSKBZpq.mjs.map +1 -0
  673. package/dist/{taxonomy-BxGxZZdu.mjs → taxonomy-DfVooU4W.mjs} +60 -13
  674. package/dist/taxonomy-DfVooU4W.mjs.map +1 -0
  675. package/dist/{tokens-BGT0TUUo.mjs → tokens-DVltpO2D.mjs} +2 -2
  676. package/dist/{tokens-BGT0TUUo.mjs.map → tokens-DVltpO2D.mjs.map} +1 -1
  677. package/dist/{transaction-qfqpPVpu.mjs → transaction-D0FOsb3X.mjs} +1 -1
  678. package/dist/{transaction-qfqpPVpu.mjs.map → transaction-D0FOsb3X.mjs.map} +1 -1
  679. package/dist/{transport-DPefPMcz.mjs → transport-CKrlqSpD.mjs} +1 -1
  680. package/dist/{transport-DPefPMcz.mjs.map → transport-CKrlqSpD.mjs.map} +1 -1
  681. package/dist/{transport-BMDWHSgZ.d.mts → transport-Vd7VdqHv.d.mts} +1 -1
  682. package/dist/{transport-BMDWHSgZ.d.mts.map → transport-Vd7VdqHv.d.mts.map} +1 -1
  683. package/dist/{trusted-proxy-VTPRiX2s.mjs → trusted-proxy-CwjQj0YG.mjs} +1 -1
  684. package/dist/{trusted-proxy-VTPRiX2s.mjs.map → trusted-proxy-CwjQj0YG.mjs.map} +1 -1
  685. package/dist/{types-CgvhU-hF.d.mts → types-B4vm81VH.d.mts} +1 -1
  686. package/dist/{types-CgvhU-hF.d.mts.map → types-B4vm81VH.d.mts.map} +1 -1
  687. package/dist/{types-ea9sAPck.d.mts → types-B97jg3aW.d.mts} +6 -1
  688. package/dist/{types-ea9sAPck.d.mts.map → types-B97jg3aW.d.mts.map} +1 -1
  689. package/dist/{types-Jo3UYd6b.mjs → types-BD40g7zz.mjs} +1 -1
  690. package/dist/{types-Jo3UYd6b.mjs.map → types-BD40g7zz.mjs.map} +1 -1
  691. package/dist/{types-DmHk7vAt.d.mts → types-BNfPHfay.d.mts} +1 -1
  692. package/dist/{types-DmHk7vAt.d.mts.map → types-BNfPHfay.d.mts.map} +1 -1
  693. package/dist/{types-BcLUUbbR.d.mts → types-BfYUPJdP.d.mts} +11 -3
  694. package/dist/{types-BcLUUbbR.d.mts.map → types-BfYUPJdP.d.mts.map} +1 -1
  695. package/dist/{types-CGbYowGQ.d.mts → types-BvB7gDOD.d.mts} +90 -4
  696. package/dist/types-BvB7gDOD.d.mts.map +1 -0
  697. package/dist/{types-vgEWF18A.d.mts → types-C7U0HlEr.d.mts} +1 -1
  698. package/dist/{types-vgEWF18A.d.mts.map → types-C7U0HlEr.d.mts.map} +1 -1
  699. package/dist/{types-CuW0zWDA.mjs → types-D1iJ3DpO.mjs} +3 -3
  700. package/dist/{types-CuW0zWDA.mjs.map → types-D1iJ3DpO.mjs.map} +1 -1
  701. package/dist/{types-_HFLRzTn.d.mts → types-DPKhI5ib.d.mts} +9 -1
  702. package/dist/types-DPKhI5ib.d.mts.map +1 -0
  703. package/dist/{types-g_aFIdW0.d.mts → types-Kmaxdarz.d.mts} +1 -1
  704. package/dist/{types-g_aFIdW0.d.mts.map → types-Kmaxdarz.d.mts.map} +1 -1
  705. package/dist/{types-ClUkdbWb.d.mts → types-iVeZ5g6N.d.mts} +1 -1
  706. package/dist/{types-ClUkdbWb.d.mts.map → types-iVeZ5g6N.d.mts.map} +1 -1
  707. package/dist/{types-tM44hEcf.mjs → types-o7xo7VgH.mjs} +1 -1
  708. package/dist/{types-tM44hEcf.mjs.map → types-o7xo7VgH.mjs.map} +1 -1
  709. package/dist/{user-BjAOvU3Z.mjs → user-Bh-L1qo6.mjs} +3 -3
  710. package/dist/{user-BjAOvU3Z.mjs.map → user-Bh-L1qo6.mjs.map} +1 -1
  711. package/dist/{utils-BJXElxdw.mjs → utils-BbUgmeZG.mjs} +3 -3
  712. package/dist/{utils-BJXElxdw.mjs.map → utils-BbUgmeZG.mjs.map} +1 -1
  713. package/dist/{validate-Z1b86_3B.d.mts → validate-DULfgpJP.d.mts} +5 -5
  714. package/dist/{validate-Z1b86_3B.d.mts.map → validate-DULfgpJP.d.mts.map} +1 -1
  715. package/dist/{validate-CWSnKVIJ.mjs → validate-V9nCwq_-.mjs} +3 -3
  716. package/dist/{validate-CWSnKVIJ.mjs.map → validate-V9nCwq_-.mjs.map} +1 -1
  717. package/dist/{validation-0l8-RYj4.mjs → validation-BsVUJfsP.mjs} +10 -10
  718. package/dist/{validation-0l8-RYj4.mjs.map → validation-BsVUJfsP.mjs.map} +1 -1
  719. package/dist/version-907opKac.mjs +7 -0
  720. package/dist/{version-qmeO1XZY.mjs.map → version-907opKac.mjs.map} +1 -1
  721. package/dist/{widgets-hWcIicX8.mjs → widgets-DGv1Z04V.mjs} +4 -4
  722. package/dist/{widgets-hWcIicX8.mjs.map → widgets-DGv1Z04V.mjs.map} +1 -1
  723. package/dist/{wxr-taxonomies-0_uxSrmf.d.mts → wxr-taxonomies-B4tMuN5T.d.mts} +1 -1
  724. package/dist/{wxr-taxonomies-0_uxSrmf.d.mts.map → wxr-taxonomies-B4tMuN5T.d.mts.map} +1 -1
  725. package/dist/{wxr-taxonomies-CNFcsNCr.mjs → wxr-taxonomies-Cs1N6O8z.mjs} +4 -4
  726. package/dist/{wxr-taxonomies-CNFcsNCr.mjs.map → wxr-taxonomies-Cs1N6O8z.mjs.map} +1 -1
  727. package/dist/{zod-generator-CacrR-i8.mjs → zod-generator-B5prQ5M4.mjs} +3 -3
  728. package/dist/{zod-generator-CacrR-i8.mjs.map → zod-generator-B5prQ5M4.mjs.map} +1 -1
  729. package/package.json +12 -8
  730. package/src/api/authorize.ts +10 -1
  731. package/src/api/error.ts +5 -5
  732. package/src/api/errors.ts +25 -0
  733. package/src/api/handlers/backup.ts +312 -0
  734. package/src/api/handlers/content.ts +147 -3
  735. package/src/api/handlers/dashboard.ts +2 -0
  736. package/src/api/handlers/device-flow.ts +2 -3
  737. package/src/api/handlers/index.ts +22 -0
  738. package/src/api/handlers/marketplace.ts +38 -0
  739. package/src/api/handlers/media-upload.ts +210 -0
  740. package/src/api/handlers/media-usage.ts +289 -0
  741. package/src/api/handlers/oauth-authorization.ts +2 -6
  742. package/src/api/handlers/plugin-settings.ts +218 -0
  743. package/src/api/handlers/plugins.ts +41 -0
  744. package/src/api/handlers/registry.ts +39 -0
  745. package/src/api/handlers/relations.ts +474 -0
  746. package/src/api/handlers/snapshot.ts +21 -3
  747. package/src/api/handlers/taxonomies.ts +26 -4
  748. package/src/api/handlers/validate-media-fields.ts +1 -1
  749. package/src/api/openapi/document.ts +72 -5
  750. package/src/api/parse.ts +2 -16
  751. package/src/api/public-url.ts +4 -2
  752. package/src/api/schemas/comments.ts +6 -0
  753. package/src/api/schemas/common.ts +6 -2
  754. package/src/api/schemas/content.ts +8 -0
  755. package/src/api/schemas/index.ts +2 -0
  756. package/src/api/schemas/media-usage.ts +120 -0
  757. package/src/api/schemas/media.ts +32 -1
  758. package/src/api/schemas/relations.ts +109 -0
  759. package/src/api/schemas/search.ts +1 -0
  760. package/src/astro/integration/index.ts +39 -0
  761. package/src/astro/integration/routes.ts +40 -0
  762. package/src/astro/integration/runtime.ts +30 -0
  763. package/src/astro/integration/virtual-modules.ts +41 -7
  764. package/src/astro/integration/vite-config.ts +17 -1
  765. package/src/astro/middleware/auth.ts +70 -78
  766. package/src/astro/middleware/csp.ts +5 -2
  767. package/src/astro/middleware/request-context.ts +162 -20
  768. package/src/astro/middleware.ts +108 -40
  769. package/src/astro/public-plugin-api-routes.ts +2 -1
  770. package/src/astro/routes/PluginRegistry.tsx +5 -2
  771. package/src/astro/routes/admin.astro +56 -16
  772. package/src/astro/routes/api/admin/api-tokens/index.ts +2 -2
  773. package/src/astro/routes/api/admin/bylines/[id]/translations.ts +2 -5
  774. package/src/astro/routes/api/admin/comments/[id]/status.ts +1 -2
  775. package/src/astro/routes/api/admin/comments/index.ts +1 -2
  776. package/src/astro/routes/api/admin/media-usage/repair.ts +24 -0
  777. package/src/astro/routes/api/admin/plugins/[id]/index.ts +6 -0
  778. package/src/astro/routes/api/admin/plugins/[id]/mcp.ts +42 -0
  779. package/src/astro/routes/api/admin/plugins/[id]/settings.ts +80 -0
  780. package/src/astro/routes/api/admin/plugins/[id]/update.ts +2 -0
  781. package/src/astro/routes/api/admin/plugins/index.ts +9 -0
  782. package/src/astro/routes/api/admin/plugins/marketplace/[id]/install.ts +2 -0
  783. package/src/astro/routes/api/admin/plugins/registry/[id]/update.ts +2 -0
  784. package/src/astro/routes/api/admin/plugins/registry/install.ts +2 -0
  785. package/src/astro/routes/api/admin/plugins/updates.ts +2 -4
  786. package/src/astro/routes/api/auth/mode.ts +6 -14
  787. package/src/astro/routes/api/auth/oauth/[provider]/callback.ts +21 -5
  788. package/src/astro/routes/api/auth/oauth/[provider].ts +24 -7
  789. package/src/astro/routes/api/comments/[collection]/[contentId]/index.ts +13 -0
  790. package/src/astro/routes/api/content/[collection]/[id]/compare.ts +3 -4
  791. package/src/astro/routes/api/content/[collection]/[id]/duplicate.ts +2 -3
  792. package/src/astro/routes/api/content/[collection]/[id]/permanent.ts +2 -3
  793. package/src/astro/routes/api/content/[collection]/[id]/preview-url.ts +3 -4
  794. package/src/astro/routes/api/content/[collection]/[id]/references/[relation]/children.ts +95 -0
  795. package/src/astro/routes/api/content/[collection]/[id]/references/[relation]/parents.ts +47 -0
  796. package/src/astro/routes/api/content/[collection]/[id]/revisions.ts +3 -4
  797. package/src/astro/routes/api/content/[collection]/[id]/terms/[taxonomy].ts +4 -6
  798. package/src/astro/routes/api/content/[collection]/[id]/translations.ts +3 -4
  799. package/src/astro/routes/api/content/[collection]/[id].ts +3 -4
  800. package/src/astro/routes/api/content/[collection]/authors.ts +2 -3
  801. package/src/astro/routes/api/content/[collection]/index.ts +6 -8
  802. package/src/astro/routes/api/content/[collection]/trash.ts +2 -3
  803. package/src/astro/routes/api/manifest.ts +2 -9
  804. package/src/astro/routes/api/mcp.ts +2 -1
  805. package/src/astro/routes/api/media/[id]/usage.ts +30 -0
  806. package/src/astro/routes/api/media/[id].ts +17 -6
  807. package/src/astro/routes/api/media/file/[...key].ts +8 -0
  808. package/src/astro/routes/api/media.ts +21 -2
  809. package/src/astro/routes/api/oauth/authorize.ts +2 -6
  810. package/src/astro/routes/api/plugins/[pluginId]/[...path].ts +17 -3
  811. package/src/astro/routes/api/relations/[id]/index.ts +84 -0
  812. package/src/astro/routes/api/relations/[id]/translations.ts +33 -0
  813. package/src/astro/routes/api/relations/index.ts +56 -0
  814. package/src/astro/routes/api/schema/collections/[slug]/fields/[fieldSlug].ts +1 -7
  815. package/src/astro/routes/api/schema/collections/[slug]/fields/index.ts +1 -2
  816. package/src/astro/routes/api/search/index.ts +2 -0
  817. package/src/astro/routes/api/settings/backups/archives/[name].ts +78 -0
  818. package/src/astro/routes/api/settings/backups/archives/index.ts +33 -0
  819. package/src/astro/routes/api/settings/backups/export.ts +43 -0
  820. package/src/astro/routes/api/settings/backups/index.ts +76 -0
  821. package/src/astro/routes/api/setup/admin-verify.ts +8 -4
  822. package/src/astro/routes/api/setup/admin.ts +11 -4
  823. package/src/astro/routes/api/well-known/oauth-authorization-server.ts +4 -1
  824. package/src/astro/routes/api/well-known/oauth-protected-resource.ts +5 -1
  825. package/src/astro/types.ts +50 -2
  826. package/src/auth/api-tokens.ts +1 -0
  827. package/src/auth/oauth-state-store.ts +3 -0
  828. package/src/auth/providers/github-admin.tsx +5 -6
  829. package/src/auth/providers/google-admin.tsx +5 -6
  830. package/src/auth/scopes.ts +3 -9
  831. package/src/cli/client-factory.ts +0 -1
  832. package/src/cli/commands/bundle-utils.ts +50 -1
  833. package/src/cli/commands/bundle.ts +9 -2
  834. package/src/cli/commands/export-seed.ts +1 -10
  835. package/src/cli/commands/media.ts +127 -0
  836. package/src/client/index.ts +123 -2
  837. package/src/client/transport.ts +1 -1
  838. package/src/comments/service.ts +1 -1
  839. package/src/comments/turnstile.ts +64 -0
  840. package/src/components/BlockquoteGroup.astro +34 -0
  841. package/src/components/CommentForm.astro +12 -5
  842. package/src/components/EmDashHead.astro +31 -9
  843. package/src/components/InlinePortableTextEditor.tsx +88 -33
  844. package/src/components/PortableText.astro +7 -1
  845. package/src/components/index.ts +2 -0
  846. package/src/components/marks/Link.astro +5 -1
  847. package/src/components/portable-text-blockquote-group.ts +68 -0
  848. package/src/content/converters/portable-text-to-prosemirror.ts +32 -1
  849. package/src/database/dialect-helpers.ts +111 -3
  850. package/src/database/migrations/039_fix_fts5_triggers.ts +1 -1
  851. package/src/database/migrations/051_content_taxonomies_denorm.ts +120 -0
  852. package/src/database/migrations/052_media_usage_read_index.ts +26 -0
  853. package/src/database/migrations/053_plugin_mcp_tools.ts +21 -0
  854. package/src/database/migrations/runner.ts +52 -6
  855. package/src/database/pg-migration-lock.ts +72 -0
  856. package/src/database/repositories/audit.ts +2 -1
  857. package/src/database/repositories/comment.ts +1 -1
  858. package/src/database/repositories/content.ts +270 -37
  859. package/src/database/repositories/media-usage.ts +250 -1
  860. package/src/database/repositories/media.ts +1 -1
  861. package/src/database/repositories/plugin-storage.ts +29 -32
  862. package/src/database/repositories/redirect.ts +14 -2
  863. package/src/database/repositories/relation.ts +130 -5
  864. package/src/database/repositories/taxonomy.ts +66 -8
  865. package/src/database/repositories/types.ts +8 -0
  866. package/src/database/types.ts +23 -0
  867. package/src/db/adapters.ts +9 -0
  868. package/src/db/postgres.ts +5 -2
  869. package/src/emdash-runtime.ts +382 -70
  870. package/src/index.ts +6 -2
  871. package/src/loader.ts +293 -32
  872. package/src/mcp/server.ts +251 -8
  873. package/src/media/image-endpoint.ts +38 -2
  874. package/src/page/metadata.ts +27 -0
  875. package/src/plugin-types.ts +19 -0
  876. package/src/plugin-utils.ts +8 -6
  877. package/src/plugins/adapt-sandbox-entry.ts +30 -1
  878. package/src/plugins/context.ts +92 -0
  879. package/src/plugins/define-plugin.ts +17 -0
  880. package/src/plugins/index.ts +4 -0
  881. package/src/plugins/manifest-schema.ts +30 -1
  882. package/src/plugins/routes.ts +27 -1
  883. package/src/plugins/sandbox/runner-options.ts +16 -0
  884. package/src/plugins/sandbox/types.ts +6 -1
  885. package/src/plugins/state.ts +17 -1
  886. package/src/plugins/storage-query.ts +67 -33
  887. package/src/plugins/types.ts +100 -0
  888. package/src/schema/byline-registry.ts +1 -1
  889. package/src/schema/registry.ts +141 -5
  890. package/src/search/fts-manager.ts +34 -0
  891. package/src/search/match.ts +50 -0
  892. package/src/search/query.ts +94 -9
  893. package/src/seed/apply.ts +28 -29
  894. package/src/seo/hreflang.ts +192 -0
  895. package/src/seo/index.ts +22 -4
  896. package/src/storage/types.ts +6 -0
  897. package/src/taxonomies/index.ts +62 -45
  898. package/src/taxonomies/term-counts.ts +117 -0
  899. package/src/utils/base64.ts +7 -2
  900. package/src/utils/db-errors.ts +3 -1
  901. package/src/virtual-modules.d.ts +14 -0
  902. package/src/visual-editing/editable.ts +41 -35
  903. package/src/visual-editing/toolbar-bootstrap.ts +120 -0
  904. package/src/visual-editing/toolbar.ts +47 -1
  905. package/dist/adapters-hUy8vOB-.d.mts.map +0 -1
  906. package/dist/api-DxFSorgk.mjs.map +0 -1
  907. package/dist/api-tokens-DsvvCtdh.mjs +0 -3
  908. package/dist/apply-CDJqIjPU.mjs.map +0 -1
  909. package/dist/authorize-Dz88F_Fw.mjs.map +0 -1
  910. package/dist/base64-CmWvODNW.mjs.map +0 -1
  911. package/dist/byline-fields-2Lp5Hbgf.mjs.map +0 -1
  912. package/dist/byline-fields-CHE8UStY.d.mts.map +0 -1
  913. package/dist/content-DhgEth4k.mjs.map +0 -1
  914. package/dist/content-refresh-Br4gMzh8.mjs.map +0 -1
  915. package/dist/context-BRIpHARC.mjs.map +0 -1
  916. package/dist/dashboard-EvEKF5en.mjs.map +0 -1
  917. package/dist/db-errors-CK46D-ly.mjs.map +0 -1
  918. package/dist/device-flow-CfGP18Uw.mjs.map +0 -1
  919. package/dist/dialect-helpers-DRI5pyY3.mjs +0 -110
  920. package/dist/dialect-helpers-DRI5pyY3.mjs.map +0 -1
  921. package/dist/error-CkAseSqZ.mjs.map +0 -1
  922. package/dist/index-B9sIxwe4.d.mts.map +0 -1
  923. package/dist/loader-CB6YHeul.mjs.map +0 -1
  924. package/dist/manifest-schema-BHlgZM1W.mjs.map +0 -1
  925. package/dist/media-BrXIaMFN.mjs.map +0 -1
  926. package/dist/menus-b2T4clbO.mjs.map +0 -1
  927. package/dist/oauth-authorization-CXWkIGT4.mjs.map +0 -1
  928. package/dist/public-url-Danv47cS.mjs.map +0 -1
  929. package/dist/query-1Cp6U9oo.mjs.map +0 -1
  930. package/dist/redirect-IyfNirgS.mjs.map +0 -1
  931. package/dist/redirects-DXEXBAII.mjs.map +0 -1
  932. package/dist/registry-B57vp_X9.mjs.map +0 -1
  933. package/dist/runner-DvFWoz8-.d.mts.map +0 -1
  934. package/dist/runner-K8XK101B.mjs.map +0 -1
  935. package/dist/scheduled-publish-Drffrf2a.d.mts +0 -11
  936. package/dist/scheduled-publish-Drffrf2a.d.mts.map +0 -1
  937. package/dist/schema-CX9cfNkZ.mjs.map +0 -1
  938. package/dist/search-DZN2HZ-V.mjs.map +0 -1
  939. package/dist/taxonomies-Bs13SN-F.mjs.map +0 -1
  940. package/dist/taxonomies-kH9ABDUF.mjs.map +0 -1
  941. package/dist/taxonomy-BxGxZZdu.mjs.map +0 -1
  942. package/dist/types-CGbYowGQ.d.mts.map +0 -1
  943. package/dist/types-_HFLRzTn.d.mts.map +0 -1
  944. package/dist/version-qmeO1XZY.mjs +0 -7
  945. /package/dist/{ssrf-CmuGgCq3.mjs → ssrf-BB__xfNM.mjs} +0 -0
  946. /package/dist/{types-DROWRxYV.mjs → types-CK0LxPUQ.mjs} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state-xxv6ZTMv.mjs","names":[],"sources":["../src/plugins/state.ts"],"sourcesContent":["/**\n * Plugin State Repository\n *\n * Database-backed storage for plugin activation state.\n * Used by the admin API to persist plugin enable/disable across restarts.\n */\n\nimport type { Kysely } from \"kysely\";\n\nimport type { Database } from \"../database/types.js\";\n\nexport type PluginStatus = \"active\" | \"inactive\";\nexport type PluginSource = \"config\" | \"marketplace\" | \"registry\";\n\nfunction toPluginStatus(value: string): PluginStatus {\n\tif (value === \"active\") return \"active\";\n\treturn \"inactive\";\n}\n\nfunction toPluginSource(value: string | undefined | null): PluginSource {\n\tif (value === \"marketplace\") return \"marketplace\";\n\tif (value === \"registry\") return \"registry\";\n\treturn \"config\";\n}\n\nexport interface PluginState {\n\tpluginId: string;\n\tstatus: PluginStatus;\n\tversion: string;\n\tinstalledAt: Date;\n\tactivatedAt: Date | null;\n\tdeactivatedAt: Date | null;\n\tsource: PluginSource;\n\tmarketplaceVersion: string | null;\n\tdisplayName: string | null;\n\tdescription: string | null;\n\t/**\n\t * Publisher DID this plugin was published under. Populated only when\n\t * `source === \"registry\"`; null otherwise.\n\t */\n\tregistryPublisherDid: string | null;\n\t/**\n\t * Slug under which the plugin was published in the publisher's repo\n\t * (the rkey of the `pm.fair.package.profile` record). Populated only\n\t * when `source === \"registry\"`; null otherwise.\n\t *\n\t * The opaque `pluginId` for registry installs is derived from\n\t * `(registryPublisherDid, registrySlug)` -- see\n\t * `packages/core/src/registry/plugin-id.ts`.\n\t */\n\tregistrySlug: string | null;\n\tmcpToolsEnabled: boolean;\n\tmcpToolsConsent: string | null;\n}\n\n/**\n * Repository for plugin state in the database\n */\nexport class PluginStateRepository {\n\tconstructor(private db: Kysely<Database>) {}\n\n\t/**\n\t * Get state for a specific plugin\n\t */\n\tasync get(pluginId: string): Promise<PluginState | null> {\n\t\tconst row = await this.db\n\t\t\t.selectFrom(\"_plugin_state\")\n\t\t\t.selectAll()\n\t\t\t.where(\"plugin_id\", \"=\", pluginId)\n\t\t\t.executeTakeFirst();\n\n\t\tif (!row) return null;\n\n\t\treturn rowToPluginState(row);\n\t}\n\n\t/**\n\t * Get all plugin states\n\t */\n\tasync getAll(): Promise<PluginState[]> {\n\t\tconst rows = await this.db.selectFrom(\"_plugin_state\").selectAll().execute();\n\t\treturn rows.map(rowToPluginState);\n\t}\n\n\t/**\n\t * Get all marketplace-installed plugin states\n\t */\n\tasync getMarketplacePlugins(): Promise<PluginState[]> {\n\t\tconst rows = await this.db\n\t\t\t.selectFrom(\"_plugin_state\")\n\t\t\t.selectAll()\n\t\t\t.where(\"source\", \"=\", \"marketplace\")\n\t\t\t.execute();\n\t\treturn rows.map(rowToPluginState);\n\t}\n\n\t/**\n\t * Get all registry-installed plugin states.\n\t *\n\t * The runtime's registry sync path uses this to discover which\n\t * registry plugins should be loaded into the sandbox on this worker.\n\t */\n\tasync getRegistryPlugins(): Promise<PluginState[]> {\n\t\tconst rows = await this.db\n\t\t\t.selectFrom(\"_plugin_state\")\n\t\t\t.selectAll()\n\t\t\t.where(\"source\", \"=\", \"registry\")\n\t\t\t.execute();\n\t\treturn rows.map(rowToPluginState);\n\t}\n\n\t/**\n\t * Create or update plugin state\n\t */\n\tasync upsert(\n\t\tpluginId: string,\n\t\tversion: string,\n\t\tstatus: PluginStatus,\n\t\topts?: {\n\t\t\tsource?: PluginSource;\n\t\t\tmarketplaceVersion?: string;\n\t\t\tdisplayName?: string;\n\t\t\tdescription?: string;\n\t\t\tregistryPublisherDid?: string;\n\t\t\tregistrySlug?: string;\n\t\t\tmcpToolsEnabled?: boolean;\n\t\t\tmcpToolsConsent?: string | null;\n\t\t},\n\t): Promise<PluginState> {\n\t\tconst now = new Date().toISOString();\n\t\tconst existing = await this.get(pluginId);\n\n\t\tif (existing) {\n\t\t\t// Update existing state\n\t\t\tconst updates: Record<string, string | number | null> = {\n\t\t\t\tstatus,\n\t\t\t\tversion,\n\t\t\t};\n\n\t\t\tif (status === \"active\" && existing.status !== \"active\") {\n\t\t\t\tupdates.activated_at = now;\n\t\t\t} else if (status === \"inactive\" && existing.status !== \"inactive\") {\n\t\t\t\tupdates.deactivated_at = now;\n\t\t\t}\n\n\t\t\tif (opts?.source) updates.source = opts.source;\n\t\t\tif (opts?.marketplaceVersion !== undefined) {\n\t\t\t\tupdates.marketplace_version = opts.marketplaceVersion;\n\t\t\t}\n\t\t\tif (opts?.displayName !== undefined) {\n\t\t\t\tupdates.display_name = opts.displayName;\n\t\t\t}\n\t\t\tif (opts?.description !== undefined) {\n\t\t\t\tupdates.description = opts.description;\n\t\t\t}\n\t\t\tif (opts?.registryPublisherDid !== undefined) {\n\t\t\t\tupdates.registry_publisher_did = opts.registryPublisherDid;\n\t\t\t}\n\t\t\tif (opts?.registrySlug !== undefined) {\n\t\t\t\tupdates.registry_slug = opts.registrySlug;\n\t\t\t}\n\t\t\tif (opts?.mcpToolsEnabled !== undefined) {\n\t\t\t\tupdates.mcp_tools_enabled = opts.mcpToolsEnabled ? 1 : 0;\n\t\t\t}\n\t\t\tif (opts?.mcpToolsConsent !== undefined) {\n\t\t\t\tupdates.mcp_tools_consent = opts.mcpToolsConsent;\n\t\t\t}\n\n\t\t\tawait this.db\n\t\t\t\t.updateTable(\"_plugin_state\")\n\t\t\t\t.set(updates)\n\t\t\t\t.where(\"plugin_id\", \"=\", pluginId)\n\t\t\t\t.execute();\n\t\t} else {\n\t\t\t// Create new state\n\t\t\tawait this.db\n\t\t\t\t.insertInto(\"_plugin_state\")\n\t\t\t\t.values({\n\t\t\t\t\tplugin_id: pluginId,\n\t\t\t\t\tstatus,\n\t\t\t\t\tversion,\n\t\t\t\t\tinstalled_at: now,\n\t\t\t\t\tactivated_at: status === \"active\" ? now : null,\n\t\t\t\t\tdeactivated_at: null,\n\t\t\t\t\tdata: null,\n\t\t\t\t\tsource: opts?.source ?? \"config\",\n\t\t\t\t\tmarketplace_version: opts?.marketplaceVersion ?? null,\n\t\t\t\t\tdisplay_name: opts?.displayName ?? null,\n\t\t\t\t\tdescription: opts?.description ?? null,\n\t\t\t\t\tregistry_publisher_did: opts?.registryPublisherDid ?? null,\n\t\t\t\t\tregistry_slug: opts?.registrySlug ?? null,\n\t\t\t\t\tmcp_tools_enabled: opts?.mcpToolsEnabled ? 1 : 0,\n\t\t\t\t\tmcp_tools_consent: opts?.mcpToolsConsent ?? null,\n\t\t\t\t})\n\t\t\t\t.execute();\n\t\t}\n\n\t\treturn (await this.get(pluginId))!;\n\t}\n\n\t/**\n\t * Enable a plugin\n\t */\n\tasync enable(pluginId: string, version: string): Promise<PluginState> {\n\t\treturn this.upsert(pluginId, version, \"active\");\n\t}\n\n\t/**\n\t * Disable a plugin\n\t */\n\tasync disable(pluginId: string, version: string): Promise<PluginState> {\n\t\treturn this.upsert(pluginId, version, \"inactive\");\n\t}\n\n\t/**\n\t * Delete plugin state\n\t */\n\tasync delete(pluginId: string): Promise<boolean> {\n\t\tconst result = await this.db\n\t\t\t.deleteFrom(\"_plugin_state\")\n\t\t\t.where(\"plugin_id\", \"=\", pluginId)\n\t\t\t.executeTakeFirst();\n\n\t\treturn (result.numDeletedRows ?? 0) > 0;\n\t}\n}\n\n/**\n * Internal: map a `_plugin_state` row to the public `PluginState` shape.\n *\n * Kept at module scope so the three select paths (`get`, `getAll`,\n * `getMarketplacePlugins`, `getRegistryPlugins`) stay byte-identical in\n * their handling of nullable columns -- adding a new column to the table\n * means changing this function and nothing else.\n */\ninterface PluginStateRow {\n\tplugin_id: string;\n\tstatus: string;\n\tversion: string;\n\tinstalled_at: string;\n\tactivated_at: string | null;\n\tdeactivated_at: string | null;\n\tsource: string;\n\tmarketplace_version: string | null;\n\tdisplay_name: string | null;\n\tdescription: string | null;\n\tregistry_publisher_did: string | null;\n\tregistry_slug: string | null;\n\tmcp_tools_enabled: number;\n\tmcp_tools_consent: string | null;\n}\n\nfunction rowToPluginState(row: PluginStateRow): PluginState {\n\treturn {\n\t\tpluginId: row.plugin_id,\n\t\tstatus: toPluginStatus(row.status),\n\t\tversion: row.version,\n\t\tinstalledAt: new Date(row.installed_at),\n\t\tactivatedAt: row.activated_at ? new Date(row.activated_at) : null,\n\t\tdeactivatedAt: row.deactivated_at ? new Date(row.deactivated_at) : null,\n\t\tsource: toPluginSource(row.source),\n\t\tmarketplaceVersion: row.marketplace_version ?? null,\n\t\tdisplayName: row.display_name ?? null,\n\t\tdescription: row.description ?? null,\n\t\tregistryPublisherDid: row.registry_publisher_did ?? null,\n\t\tregistrySlug: row.registry_slug ?? null,\n\t\tmcpToolsEnabled: row.mcp_tools_enabled === 1,\n\t\tmcpToolsConsent: row.mcp_tools_consent ?? null,\n\t};\n}\n"],"mappings":";AAcA,SAAS,eAAe,OAA6B;AACpD,KAAI,UAAU,SAAU,QAAO;AAC/B,QAAO;;AAGR,SAAS,eAAe,OAAgD;AACvE,KAAI,UAAU,cAAe,QAAO;AACpC,KAAI,UAAU,WAAY,QAAO;AACjC,QAAO;;;;;AAoCR,IAAa,wBAAb,MAAmC;CAClC,YAAY,AAAQ,IAAsB;EAAtB;;;;;CAKpB,MAAM,IAAI,UAA+C;EACxD,MAAM,MAAM,MAAM,KAAK,GACrB,WAAW,gBAAgB,CAC3B,WAAW,CACX,MAAM,aAAa,KAAK,SAAS,CACjC,kBAAkB;AAEpB,MAAI,CAAC,IAAK,QAAO;AAEjB,SAAO,iBAAiB,IAAI;;;;;CAM7B,MAAM,SAAiC;AAEtC,UADa,MAAM,KAAK,GAAG,WAAW,gBAAgB,CAAC,WAAW,CAAC,SAAS,EAChE,IAAI,iBAAiB;;;;;CAMlC,MAAM,wBAAgD;AAMrD,UALa,MAAM,KAAK,GACtB,WAAW,gBAAgB,CAC3B,WAAW,CACX,MAAM,UAAU,KAAK,cAAc,CACnC,SAAS,EACC,IAAI,iBAAiB;;;;;;;;CASlC,MAAM,qBAA6C;AAMlD,UALa,MAAM,KAAK,GAC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mB,MAAM,kBAAkB,IAAI;GAC/C,mBAAmB,MAAM,mBAAmB;GAC5C,CAAC,CACD,SAAS;AAGZ,SAAQ,MAAM,KAAK,IAAI,SAAS;;;;;CAMjC,MAAM,OAAO,UAAkB,SAAuC;AACrE,SAAO,KAAK,OAAO,UAAU,SAAS,SAAS;;;;;CAMhD,MAAM,QAAQ,UAAkB,SAAuC;AACtE,SAAO,KAAK,OAAO,UAAU,SAAS,WAAW;;;;;CAMlD,MAAM,OAAO,UAAoC;AAMhD,WALe,MAAM,KAAK,GACxB,WAAW,gBAAgB,CAC3B,MAAM,aAAa,KAAK,SAAS,CACjC,kBAAkB,EAEL,kBAAkB,KAAK;;;AA6BxC,SAAS,iBAAiB,KAAkC;AAC3D,QAAO;EACN,UAAU,IAAI;EACd,QAAQ,eAAe,IAAI,OAAO;EAClC,SAAS,IAAI;EACb,aAAa,IAAI,KAAK,IAAI,aAAa;EACvC,aAAa,IAAI,eAAe,IAAI,KAAK,IAAI,aAAa,GAAG;EAC7D,eAAe,IAAI,iBAAiB,IAAI,KAAK,IAAI,eAAe,GAAG;EACnE,QAAQ,eAAe,IAAI,OAAO;EAClC,oBAAoB,IAAI,uBAAuB;EAC/C,aAAa,IAAI,gBAAgB;EACjC,aAAa,IAAI,eAAe;EAChC,sBAAsB,IAAI,0BAA0B;EACpD,cAAc,IAAI,iBAAiB;EACnC,iBAAiB,IAAI,sBAAsB;EAC3C,iBAAiB,IAAI,qBAAqB;EAC1C"}
@@ -27,4 +27,4 @@ function isTerminalStatus(type) {
27
27
 
28
28
  //#endregion
29
29
  export { isTerminalStatus as n, REDIRECT_RULE_STATUSES as t };
30
- //# sourceMappingURL=status-CqJQX1QN.mjs.map
30
+ //# sourceMappingURL=status-COfycGIU.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"status-CqJQX1QN.mjs","names":[],"sources":["../src/redirects/status.ts"],"sourcesContent":["/**\n * Redirect rule status codes.\n *\n * A redirect rule's `type` is either a *redirect* status (issues a `Location`\n * header) or a *terminal* status (serves the status with no target). Terminal\n * statuses let editors mark a URL as intentionally gone:\n * - `410 Gone` — permanently and intentionally deleted (Google deindexes it\n * faster than a 404).\n * - `451 Unavailable For Legal Reasons`.\n */\n\n/** Statuses that issue an HTTP redirect (require a destination). */\nexport const REDIRECT_STATUSES = [301, 302, 307, 308] as const;\n\n/** Terminal statuses that serve a status with no `Location` / no destination. */\nexport const TERMINAL_STATUSES = [410, 451] as const;\n\n/** All values accepted as a redirect rule `type`. */\nexport const REDIRECT_RULE_STATUSES: readonly number[] = [\n\t...REDIRECT_STATUSES,\n\t...TERMINAL_STATUSES,\n];\n\n/** True for terminal statuses (410/451) — served directly, with no target. */\nexport function isTerminalStatus(type: number): boolean {\n\treturn (TERMINAL_STATUSES as readonly number[]).includes(type);\n}\n"],"mappings":";;;;;;;;;;;;AAYA,MAAa,oBAAoB;CAAC;CAAK;CAAK;CAAK;CAAI;;AAGrD,MAAa,oBAAoB,CAAC,KAAK,IAAI;;AAG3C,MAAa,yBAA4C,CACxD,GAAG,mBACH,GAAG,kBACH;;AAGD,SAAgB,iBAAiB,MAAuB;AACvD,QAAQ,kBAAwC,SAAS,KAAK"}
1
+ {"version":3,"file":"status-COfycGIU.mjs","names":[],"sources":["../src/redirects/status.ts"],"sourcesContent":["/**\n * Redirect rule status codes.\n *\n * A redirect rule's `type` is either a *redirect* status (issues a `Location`\n * header) or a *terminal* status (serves the status with no target). Terminal\n * statuses let editors mark a URL as intentionally gone:\n * - `410 Gone` — permanently and intentionally deleted (Google deindexes it\n * faster than a 404).\n * - `451 Unavailable For Legal Reasons`.\n */\n\n/** Statuses that issue an HTTP redirect (require a destination). */\nexport const REDIRECT_STATUSES = [301, 302, 307, 308] as const;\n\n/** Terminal statuses that serve a status with no `Location` / no destination. */\nexport const TERMINAL_STATUSES = [410, 451] as const;\n\n/** All values accepted as a redirect rule `type`. */\nexport const REDIRECT_RULE_STATUSES: readonly number[] = [\n\t...REDIRECT_STATUSES,\n\t...TERMINAL_STATUSES,\n];\n\n/** True for terminal statuses (410/451) — served directly, with no target. */\nexport function isTerminalStatus(type: number): boolean {\n\treturn (TERMINAL_STATUSES as readonly number[]).includes(type);\n}\n"],"mappings":";;;;;;;;;;;;AAYA,MAAa,oBAAoB;CAAC;CAAK;CAAK;CAAK;CAAI;;AAGrD,MAAa,oBAAoB,CAAC,KAAK,IAAI;;AAG3C,MAAa,yBAA4C,CACxD,GAAG,mBACH,GAAG,kBACH;;AAGD,SAAgB,iBAAiB,MAAuB;AACvD,QAAQ,kBAAwC,SAAS,KAAK"}
@@ -1,4 +1,4 @@
1
- import { a as ListOptions, d as Storage, l as SignedUploadOptions, n as DownloadResult, o as ListResult, p as UploadResult, s as LocalStorageConfig, u as SignedUploadUrl } from "../types-ea9sAPck.mjs";
1
+ import { a as ListOptions, d as Storage, l as SignedUploadOptions, n as DownloadResult, o as ListResult, p as UploadResult, s as LocalStorageConfig, u as SignedUploadUrl } from "../types-B97jg3aW.mjs";
2
2
 
3
3
  //#region src/storage/local.d.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { t as EmDashStorageError } from "../types-Jo3UYd6b.mjs";
1
+ import { t as EmDashStorageError } from "../types-BD40g7zz.mjs";
2
2
  import mime from "mime/lite";
3
3
  import { createReadStream, existsSync } from "node:fs";
4
4
  import * as path from "node:path";
@@ -1,4 +1,4 @@
1
- import { a as ListOptions, c as S3StorageConfig, d as Storage, l as SignedUploadOptions, n as DownloadResult, o as ListResult, p as UploadResult, u as SignedUploadUrl } from "../types-ea9sAPck.mjs";
1
+ import { a as ListOptions, c as S3StorageConfig, d as Storage, l as SignedUploadOptions, n as DownloadResult, o as ListResult, p as UploadResult, u as SignedUploadUrl } from "../types-B97jg3aW.mjs";
2
2
 
3
3
  //#region src/storage/s3.d.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { t as EmDashStorageError } from "../types-Jo3UYd6b.mjs";
1
+ import { t as EmDashStorageError } from "../types-BD40g7zz.mjs";
2
2
  import { z } from "zod";
3
3
  import { DeleteObjectCommand, GetObjectCommand, HeadObjectCommand, ListObjectsV2Command, PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
4
4
  import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
@@ -1,6 +1,6 @@
1
- import { a as __exportAll } from "./runner-K8XK101B.mjs";
2
- import { t as TaxonomyRepository } from "./taxonomy-BxGxZZdu.mjs";
3
- import { l as invalidateTaxonomyDefsCache, u as invalidateTermCache } from "./taxonomies-kH9ABDUF.mjs";
1
+ import { o as __exportAll } from "./runner-DfnZ5eUr.mjs";
2
+ import { t as TaxonomyRepository } from "./taxonomy-DfVooU4W.mjs";
3
+ import { f as fetchVisibleTermCounts, l as invalidateTaxonomyDefsCache, u as invalidateTermCache } from "./taxonomies-DjSKBZpq.mjs";
4
4
  import { ulid } from "ulidx";
5
5
 
6
6
  //#region src/api/handlers/taxonomies.ts
@@ -49,6 +49,11 @@ async function requireTaxonomyDef(db, name, locale) {
49
49
  def
50
50
  };
51
51
  }
52
+ /** Declared collections of a taxonomy def row (deduped, parsed from JSON). */
53
+ function defCollections(def) {
54
+ const parsed = def.collections ? JSON.parse(def.collections) : [];
55
+ return [...new Set(parsed)];
56
+ }
52
57
  function rowToDef(row) {
53
58
  return {
54
59
  id: row.id,
@@ -176,10 +181,8 @@ async function handleTermList(db, taxonomyName, options = {}) {
176
181
  try {
177
182
  const lookup = await requireTaxonomyDef(db, taxonomyName);
178
183
  if (!lookup.success) return lookup;
179
- const repo = new TaxonomyRepository(db);
180
- const terms = await repo.findByName(taxonomyName, { locale: options.locale });
181
- const groups = terms.map((t) => t.translationGroup ?? t.id);
182
- const countsByGroup = await repo.countEntriesForTerms(groups);
184
+ const terms = await new TaxonomyRepository(db).findByName(taxonomyName, { locale: options.locale });
185
+ const countsByGroup = await fetchVisibleTermCounts(db, taxonomyName, defCollections(lookup.def));
183
186
  const termData = terms.map((term) => ({
184
187
  id: term.id,
185
188
  name: term.name,
@@ -334,7 +337,8 @@ async function handleTermGet(db, taxonomyName, termSlug, options = {}) {
334
337
  message: `Term '${termSlug}' not found in taxonomy '${taxonomyName}'`
335
338
  }
336
339
  };
337
- const count = await repo.countEntriesWithTerm(term.id);
340
+ const lookup = await requireTaxonomyDef(db, taxonomyName);
341
+ const count = (await fetchVisibleTermCounts(db, taxonomyName, lookup.success ? defCollections(lookup.def) : [])).get(term.translationGroup ?? term.id) ?? 0;
338
342
  const children = await repo.findChildren(term.id, term.locale);
339
343
  return {
340
344
  success: true,
@@ -513,4 +517,4 @@ async function handleTermDelete(db, taxonomyName, termSlug, options = {}) {
513
517
 
514
518
  //#endregion
515
519
  export { handleTermGet as a, handleTermUpdate as c, handleTermDelete as i, taxonomies_exports as l, handleTaxonomyList as n, handleTermList as o, handleTermCreate as r, handleTermTranslations as s, handleTaxonomyCreate as t };
516
- //# sourceMappingURL=taxonomies-Bs13SN-F.mjs.map
520
+ //# sourceMappingURL=taxonomies-Ce49uIzY.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"taxonomies-Ce49uIzY.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 } from \"../../database/repositories/taxonomy.js\";\nimport type { Database, TaxonomyDefTable } from \"../../database/types.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\tcount: number;\n\tchildren: TermWithCount[];\n}\n\nexport interface TermListResponse {\n\tterms: TermWithCount[];\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\tlet query = db.selectFrom(\"_emdash_taxonomy_defs\").selectAll();\n\t\tif (options.locale !== undefined) query = query.where(\"locale\", \"=\", options.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\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 (input.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\", \"=\", input.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 '${input.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...(input.locale !== undefined ? { locale: input.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 } = {},\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 terms = await repo.findByName(taxonomyName, { locale: options.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 countsByGroup = await fetchVisibleTermCounts(\n\t\t\tdb,\n\t\t\ttaxonomyName,\n\t\t\tdefCollections(lookup.def),\n\t\t);\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\tcount: 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 {\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 * 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\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, input.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: input.locale\n\t\t\t\t\t\t? `Term '${input.slug}' already exists in '${taxonomyName}' (${input.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: input.locale,\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 term = await repo.findBySlug(taxonomyName, termSlug, options.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 term = await repo.findBySlug(taxonomyName, termSlug, options.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, options.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 term = await repo.findBySlug(taxonomyName, termSlug, options.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":";;;;;;;;;;;;;;;;AAkBA,MAAM,eAAe;;;;A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mB,GAAG;EACvC,MAAM,OAAO,MAAM,KAAK,WAAW,cAAc,UAAU,QAAQ,OAAO;AAE1E,MAAI,CAAC,KACJ,QAAO;GACN,SAAS;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,12 +1,81 @@
1
- import { a as __exportAll } from "./runner-K8XK101B.mjs";
1
+ import { o as __exportAll } from "./runner-DfnZ5eUr.mjs";
2
+ import { t as validateIdentifier } from "./validate-VPnKoIzW.mjs";
3
+ import { n as buildStatusCondition } from "./dialect-helpers-HxEQGl_1.mjs";
2
4
  import { getRequestContext } from "./request-context.mjs";
3
5
  import { d as invalidateTaxonomyObjectCache, f as isObjectCacheActive, n as cachedQuery, r as contentNamespace, t as CacheNamespace } from "./object-cache-Bok5j2ae.mjs";
4
- import { n as chunks, t as SQL_BATCH_SIZE } from "./chunks-B2isWQhr.mjs";
5
- import { i as setRequestCacheEntry, n as peekRequestCache, r as requestCached } from "./request-cache-KCNHp_RJ.mjs";
6
- import { n as isMissingTableError } from "./db-errors-CK46D-ly.mjs";
7
- import { a as getDb, s as resetTaxonomyNamesCache } from "./loader-CB6YHeul.mjs";
8
- import { i as resolveLocaleChain, r as resolveLocale } from "./resolve-DR3wqMTy.mjs";
6
+ import { n as chunks, t as SQL_BATCH_SIZE } from "./chunks-BxXyunY-.mjs";
7
+ import { n as isMissingTableError } from "./db-errors-CcWLaRiR.mjs";
8
+ import { i as setRequestCacheEntry, n as peekRequestCache, r as requestCached } from "./request-cache-BSUptuJR.mjs";
9
+ import { i as resolveLocaleChain, r as resolveLocale } from "./resolve-Cd9dzclN.mjs";
10
+ import { a as getDb, s as resetTaxonomyNamesCache } from "./loader-Be3ouI5L.mjs";
11
+ import { sql } from "kysely";
9
12
 
13
+ //#region src/taxonomies/term-counts.ts
14
+ /**
15
+ * Per-collection count branch. `taxonomy_id` stores the term's
16
+ * translation_group, so results are keyed by group (locale-independent) and
17
+ * each assignment is counted once no matter how many locales the term has.
18
+ *
19
+ * Scoping to the taxonomy uses `translation_group IN (...)` rather than a
20
+ * join on `taxonomies.id` — the anchor row (id == group) can be deleted while
21
+ * sibling translations survive, and a plain join on `translation_group` would
22
+ * multiply counts by the number of locales.
23
+ */
24
+ function collectionBranch(db, taxonomyName, collection) {
25
+ return sql`
26
+ SELECT ct.taxonomy_id AS taxonomy_id, COUNT(*) AS count
27
+ FROM content_taxonomies AS ct
28
+ INNER JOIN ${sql.ref(`ec_${collection}`)} AS e ON e.id = ct.entry_id
29
+ WHERE ct.collection = ${collection}
30
+ AND ct.taxonomy_id IN (SELECT translation_group FROM taxonomies WHERE name = ${taxonomyName})
31
+ AND ${buildStatusCondition(db, "published", "e")}
32
+ AND e.deleted_at IS NULL
33
+ GROUP BY ct.taxonomy_id`;
34
+ }
35
+ async function runCounts(db, taxonomyName, collections) {
36
+ const branches = collections.map((collection) => collectionBranch(db, taxonomyName, collection));
37
+ const result = await sql`
38
+ SELECT taxonomy_id, SUM(count) AS count
39
+ FROM (${sql.join(branches, sql` UNION ALL `)}) AS per_collection
40
+ GROUP BY taxonomy_id`.execute(db);
41
+ const counts = /* @__PURE__ */ new Map();
42
+ for (const row of result.rows) counts.set(row.taxonomy_id, Number(row.count));
43
+ return counts;
44
+ }
45
+ /**
46
+ * Count publicly-visible term assignments for one taxonomy, keyed by the
47
+ * term's translation_group (what `content_taxonomies.taxonomy_id` stores).
48
+ *
49
+ * Counts are scoped to the taxonomy's declared collections — pass
50
+ * `TaxonomyDef.collections` (`_emdash_taxonomy_defs.collections`). Collections
51
+ * whose `ec_*` table doesn't exist (pre-migration drift, a declared collection
52
+ * that was never created) are skipped, yielding a partial-but-correct count
53
+ * rather than a throw.
54
+ *
55
+ * One database round-trip for the whole taxonomy (UNION ALL across
56
+ * collections). Callers on the public render path should go through the
57
+ * request-cached wrapper in `taxonomies/index.ts` so a page rendering both the
58
+ * widget and a term detail shares one computation.
59
+ */
60
+ async function fetchVisibleTermCounts(db, taxonomyName, collections) {
61
+ const unique = [...new Set(collections)];
62
+ for (const collection of unique) validateIdentifier(collection, "collection slug");
63
+ if (unique.length === 0) return /* @__PURE__ */ new Map();
64
+ try {
65
+ return await runCounts(db, taxonomyName, unique);
66
+ } catch (error) {
67
+ if (!isMissingTableError(error)) throw error;
68
+ }
69
+ const counts = /* @__PURE__ */ new Map();
70
+ for (const collection of unique) try {
71
+ for (const [group, count] of await runCounts(db, taxonomyName, [collection])) counts.set(group, (counts.get(group) ?? 0) + count);
72
+ } catch (error) {
73
+ if (!isMissingTableError(error)) throw error;
74
+ }
75
+ return counts;
76
+ }
77
+
78
+ //#endregion
10
79
  //#region src/taxonomies/index.ts
11
80
  /**
12
81
  * Runtime API for taxonomies.
@@ -146,25 +215,36 @@ async function getTaxonomyDef(name, options = {}) {
146
215
  });
147
216
  }
148
217
  /**
218
+ * Object-cache namespaces for values that embed visible term counts: the
219
+ * taxonomy epoch (term/assignment writes) plus each counted collection's
220
+ * content epoch, so publishing, unpublishing, or trashing an entry
221
+ * invalidates the cached count promptly. A scheduled entry becoming due
222
+ * flips visibility without a write, so that staleness stays bounded by the
223
+ * cache entry's TTL.
224
+ */
225
+ function termCountNamespaces(collections) {
226
+ return [...Array.from(new Set(collections), contentNamespace), CacheNamespace.TAXONOMIES];
227
+ }
228
+ /**
149
229
  * All terms of a taxonomy in a specific locale (flat for non-hierarchical,
150
230
  * tree for hierarchical).
151
231
  */
152
232
  async function getTaxonomyTerms(taxonomyName, options = {}) {
153
233
  const locale = resolveLocale(options.locale);
154
- return requestCached(`taxonomy-terms:${taxonomyName}:${locale ?? "*"}`, () => cachedQuery({
155
- namespace: CacheNamespace.TAXONOMIES,
156
- key: `terms:${taxonomyName}:${locale ?? "*"}`,
157
- load: () => loadTaxonomyTerms(taxonomyName, locale, options)
158
- }));
234
+ return requestCached(`taxonomy-terms:${taxonomyName}:${locale ?? "*"}`, async () => {
235
+ const def = await getTaxonomyDef(taxonomyName, options);
236
+ if (!def) return [];
237
+ return cachedQuery({
238
+ namespace: termCountNamespaces(def.collections),
239
+ key: `terms:${taxonomyName}:${locale ?? "*"}`,
240
+ load: () => loadTaxonomyTerms(def, locale)
241
+ });
242
+ });
159
243
  }
160
- async function loadTaxonomyTerms(taxonomyName, locale, options) {
161
- const db = await getDb();
162
- const def = await getTaxonomyDef(taxonomyName, options);
163
- if (!def) return [];
164
- let termsQuery = db.selectFrom("taxonomies").selectAll().where("name", "=", taxonomyName).orderBy("label", "asc");
244
+ async function loadTaxonomyTerms(def, locale) {
245
+ let termsQuery = (await getDb()).selectFrom("taxonomies").selectAll().where("name", "=", def.name).orderBy("label", "asc");
165
246
  if (locale !== void 0) termsQuery = termsQuery.where("locale", "=", locale);
166
- const rows = await termsQuery.execute();
167
- const counts = await getTaxonomyTermCounts();
247
+ const [rows, counts] = await Promise.all([termsQuery.execute(), getVisibleTermCounts(def.name, def.collections)]);
168
248
  const flatTerms = rows.map((row) => ({
169
249
  id: row.id,
170
250
  name: row.name,
@@ -189,17 +269,15 @@ async function loadTaxonomyTerms(taxonomyName, locale, options) {
189
269
  }));
190
270
  }
191
271
  /**
192
- * Per-translation-group usage counts across all taxonomies, in one aggregate
193
- * scan of `content_taxonomies`. Counts are locale-independent (the pivot stores
194
- * translation_group), so a single request-cached entry serves every taxonomy
195
- * that renders during the request.
272
+ * Per-translation-group visible-usage counts for one taxonomy, in a single
273
+ * round-trip (see `fetchVisibleTermCounts`). Counts are locale-independent
274
+ * (the pivot stores translation_group), and the request-cached map is shared
275
+ * by every consumer in the render — the widget (`getTaxonomyTerms`) and the
276
+ * single-term page (`getTerm`) never issue separate count queries.
196
277
  */
197
- function getTaxonomyTermCounts() {
198
- return requestCached("taxonomy-term-counts", async () => {
199
- const countsResult = await (await getDb()).selectFrom("content_taxonomies").select(["taxonomy_id"]).select((eb) => eb.fn.count("entry_id").as("count")).groupBy("taxonomy_id").execute();
200
- const counts = /* @__PURE__ */ new Map();
201
- for (const row of countsResult) counts.set(row.taxonomy_id, row.count);
202
- return counts;
278
+ function getVisibleTermCounts(taxonomyName, collections) {
279
+ return requestCached(`taxonomy-term-counts:${taxonomyName}:${[...new Set(collections)].toSorted().join(",")}`, async () => {
280
+ return fetchVisibleTermCounts(await getDb(), taxonomyName, collections);
203
281
  });
204
282
  }
205
283
  /**
@@ -209,13 +287,14 @@ function getTaxonomyTermCounts() {
209
287
  */
210
288
  async function getTerm(taxonomyName, slug, options = {}) {
211
289
  const chain = resolveLocaleChain(options.locale);
290
+ const collections = (await getTaxonomyDef(taxonomyName, options))?.collections ?? [];
212
291
  return cachedQuery({
213
- namespace: CacheNamespace.TAXONOMIES,
292
+ namespace: termCountNamespaces(collections),
214
293
  key: `term:${taxonomyName}:${slug}:${chain.join(",")}`,
215
- load: () => loadTerm(taxonomyName, slug, chain)
294
+ load: () => loadTerm(taxonomyName, slug, chain, collections)
216
295
  });
217
296
  }
218
- async function loadTerm(taxonomyName, slug, chain) {
297
+ async function loadTerm(taxonomyName, slug, chain, collections) {
219
298
  const db = await getDb();
220
299
  let row;
221
300
  const selectTerm = () => db.selectFrom("taxonomies").selectAll().where("name", "=", taxonomyName).where("slug", "=", slug);
@@ -231,8 +310,8 @@ async function loadTerm(taxonomyName, slug, chain) {
231
310
  let childrenQuery = db.selectFrom("taxonomies").selectAll().where("parent_id", "=", row.translation_group ?? row.id).orderBy("label", "asc");
232
311
  const termLocale = row.locale;
233
312
  if (termLocale) childrenQuery = childrenQuery.where("locale", "=", termLocale);
234
- const [countResult, childRows] = await Promise.all([db.selectFrom("content_taxonomies").select((eb) => eb.fn.count("entry_id").as("count")).where("taxonomy_id", "=", row.translation_group ?? row.id).executeTakeFirst(), childrenQuery.execute()]);
235
- const count = countResult?.count ?? 0;
313
+ const [counts, childRows] = await Promise.all([getVisibleTermCounts(taxonomyName, collections), childrenQuery.execute()]);
314
+ const count = counts.get(row.translation_group ?? row.id) ?? 0;
236
315
  const children = childRows.map((child) => ({
237
316
  id: child.id,
238
317
  name: child.name,
@@ -474,7 +553,7 @@ function primeFoldedEntryTerms(collection, perEntry, options = {}) {
474
553
  * the content query respect the active locale.
475
554
  */
476
555
  async function getEntriesByTerm(collection, taxonomyName, termSlug, options = {}) {
477
- const { getEmDashCollection } = await import("./query-1Cp6U9oo.mjs").then((n) => n.o);
556
+ const { getEmDashCollection } = await import("./query-DR73ZNfm.mjs").then((n) => n.o);
478
557
  const queryOptions = { where: { [taxonomyName]: termSlug } };
479
558
  if (options.locale !== void 0) queryOptions.locale = options.locale;
480
559
  const { entries } = await getEmDashCollection(collection, queryOptions);
@@ -524,5 +603,5 @@ function buildTree(flatTerms, counts) {
524
603
  }
525
604
 
526
605
  //#endregion
527
- export { getTaxonomyDefs as a, getTermsForEntries as c, taxonomies_exports as d, getTaxonomyDef as i, invalidateTaxonomyDefsCache as l, getEntriesByTerm as n, getTaxonomyTerms as o, getEntryTerms as r, getTerm as s, getAllTermsForEntries as t, invalidateTermCache as u };
528
- //# sourceMappingURL=taxonomies-kH9ABDUF.mjs.map
606
+ export { getTaxonomyDefs as a, getTermsForEntries as c, taxonomies_exports as d, fetchVisibleTermCounts as f, getTaxonomyDef as i, invalidateTaxonomyDefsCache as l, getEntriesByTerm as n, getTaxonomyTerms as o, getEntryTerms as r, getTerm as s, getAllTermsForEntries as t, invalidateTermCache as u };
607
+ //# sourceMappingURL=taxonomies-DjSKBZpq.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"taxonomies-DjSKBZpq.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 are currently visible on the public site:\n * `status = 'published'` OR (`status = 'scheduled'` AND due), AND\n * `deleted_at IS NULL` — via `buildStatusCondition`, which computes scheduled\n * visibility at query time rather than trusting a literal status value.\n *\n * The public render path is latency-sensitive on D1, so per-collection counts\n * are combined into a single round-trip with UNION ALL — one query per\n * taxonomy, never one per collection.\n */\n\nimport type { Kysely } from \"kysely\";\nimport { sql } from \"kysely\";\n\nimport { buildStatusCondition } from \"../database/dialect-helpers.js\";\nimport type { Database } from \"../database/types.js\";\nimport { validateIdentifier } from \"../database/validate.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 */\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\tINNER JOIN ${sql.ref(`ec_${collection}`)} AS e ON e.id = ct.entry_id\n\t\tWHERE 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\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). Callers on the public render path should go through the\n * request-cached wrapper in `taxonomies/index.ts` so a page rendering both the\n * widget and a 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\ttry {\n\t\treturn await runCounts(db, taxonomyName, unique);\n\t} catch (error) {\n\t\tif (!isMissingTableError(error)) throw error;\n\t}\n\n\t// A declared collection has no ec_* table — retry per collection so the\n\t// existing tables still contribute (still scheduled-aware + deleted_at).\n\tconst counts = new Map<string, number>();\n\tfor (const collection of unique) {\n\t\ttry {\n\t\t\tfor (const [group, count] of await runCounts(db, taxonomyName, [collection])) {\n\t\t\t\tcounts.set(group, (counts.get(group) ?? 0) + count);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (!isMissingTableError(error)) throw error;\n\t\t}\n\t}\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\tcontentNamespace,\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\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. A scheduled entry becoming due\n * flips visibility without a write, so that staleness stays bounded by the\n * cache entry's TTL.\n */\nfunction termCountNamespaces(collections: string[]): string[] {\n\treturn [...Array.from(new Set(collections), contentNamespace), CacheNamespace.TAXONOMIES];\n}\n\n/**\n * All terms of a taxonomy in a specific locale (flat for non-hierarchical,\n * tree for hierarchical).\n */\nexport async function getTaxonomyTerms(\n\ttaxonomyName: string,\n\toptions: TaxonomyQueryOptions = {},\n): Promise<TaxonomyTerm[]> {\n\tconst locale = resolveLocale(options.locale);\n\treturn requestCached(`taxonomy-terms:${taxonomyName}:${locale ?? \"*\"}`, async () => {\n\t\tconst def = await getTaxonomyDef(taxonomyName, options);\n\t\tif (!def) return [];\n\t\treturn cachedQuery({\n\t\t\tnamespace: termCountNamespaces(def.collections),\n\t\t\tkey: `terms:${taxonomyName}:${locale ?? \"*\"}`,\n\t\t\tload: () => loadTaxonomyTerms(def, locale),\n\t\t});\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(\"label\", \"asc\");\n\tif (locale !== undefined) termsQuery = termsQuery.where(\"locale\", \"=\", locale);\n\n\t// Counts are keyed by translation_group (what the pivot stores) and are\n\t// locale-independent. Only publicly visible entries are counted (#581);\n\t// the map is request-cached so a term detail rendered on the same page\n\t// reuses it. Independent of the terms query, so run both concurrently.\n\tconst [rows, counts] = await Promise.all([\n\t\ttermsQuery.execute(),\n\t\tgetVisibleTermCounts(def.name, def.collections),\n\t]);\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, counts);\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\tcount: counts.get(term.translation_group ?? term.id) ?? 0,\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\tconst db = await getDb();\n\t\treturn fetchVisibleTermCounts(db, taxonomyName, collections);\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(\"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: [contentNamespace(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: [contentNamespace(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[], counts: Map<string, number>): 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\tcount: counts.get(term.translation_group ?? term.id) ?? 0,\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}::${node.parentId}`)\n\t\t\t: undefined;\n\t\tif (parent) {\n\t\t\tparent.children.push(node);\n\t\t} else {\n\t\t\troots.push(node);\n\t\t}\n\t}\n\n\treturn roots;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAwCA,SAAS,iBACR,IACA,cACA,YACyB;AACzB,QAAO,GAAG;;;eAGI,IAAI,IAAI,MAAM,aAAa,CAAC;0BACjB,WAAW;kFAC6C,aAAa;SACtF,qBAAqB,IAAI,aAAa,IAAI,CAAC;;;;AAKpD,eAAe,UACd,IACA,cACA,aAC+B;CAC/B,MAAM,WAAW,YAAY,KAAK,eAAe,iBAAiB,IAAI,cAAc,WAAW,CAAC;CAEhG,MAAM,SAAS,MAAM,GAAa;;UADpB,IAAI,KAAK,UAAU,GAAG,cAAc,CAGnC;wBACQ,QAAQ,GAAG;CAElC,MAAM,yBAAS,IAAI,KAAqB;AACxC,MAAK,MAAM,OAAO,OAAO,KAAM,QAAO,IAAI,IAAI,aAAa,OAAO,IAAI,MAAM,CAAC;AAC7E,QAAO;;;;;;;;;;;;;;;;;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