emdash 1.3.0 → 1.4.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 (970) hide show
  1. package/dist/{activation-Dim4YMM7.mjs → activation-CGlyigmg.mjs} +3 -3
  2. package/dist/{activation-Dim4YMM7.mjs.map → activation-CGlyigmg.mjs.map} +1 -1
  3. package/dist/{adapters-F_xorvWv.d.mts → adapters-D9a1PfqH.d.mts} +1 -1
  4. package/dist/{adapters-F_xorvWv.d.mts.map → adapters-D9a1PfqH.d.mts.map} +1 -1
  5. package/dist/{after-PcEvMY_6.mjs → after-32yNRvd2.mjs} +5 -2
  6. package/dist/{after-PcEvMY_6.mjs.map → after-32yNRvd2.mjs.map} +1 -1
  7. package/dist/api/route-utils.d.mts +4 -4
  8. package/dist/api/route-utils.mjs +50 -49
  9. package/dist/api/route-utils.mjs.map +1 -1
  10. package/dist/api/schemas/index.d.mts +1 -1
  11. package/dist/api/schemas/index.mjs +7 -7
  12. package/dist/{api-D-7BNHoz.mjs → api--PYoyeTo.mjs} +121 -48
  13. package/dist/api--PYoyeTo.mjs.map +1 -0
  14. package/dist/api-tokens-DqSlkDVI.mjs +9 -0
  15. package/dist/api-tokens-DqSlkDVI.mjs.map +1 -0
  16. package/dist/{api-tokens-Bx38ZCQp.mjs → api-tokens-GNCsIegW.mjs} +3 -3
  17. package/dist/{api-tokens-Bx38ZCQp.mjs.map → api-tokens-GNCsIegW.mjs.map} +1 -1
  18. package/dist/{apply-T7ATgzCh.mjs → apply-DVnupNeS.mjs} +149 -91
  19. package/dist/apply-DVnupNeS.mjs.map +1 -0
  20. package/dist/{approvals-D-m6wvGl.mjs → approvals-DTtYSB27.mjs} +2 -2
  21. package/dist/{approvals-D-m6wvGl.mjs.map → approvals-DTtYSB27.mjs.map} +1 -1
  22. package/dist/{artifacts-htGyfCSt.mjs → artifacts-Dvdp2KK-.mjs} +29 -13
  23. package/dist/artifacts-Dvdp2KK-.mjs.map +1 -0
  24. package/dist/astro/image-endpoint.mjs +12 -2
  25. package/dist/astro/image-endpoint.mjs.map +1 -1
  26. package/dist/astro/index.d.mts +15 -14
  27. package/dist/astro/index.d.mts.map +1 -1
  28. package/dist/astro/index.mjs +59 -8
  29. package/dist/astro/index.mjs.map +1 -1
  30. package/dist/astro/middleware/auth.d.mts +13 -12
  31. package/dist/astro/middleware/auth.d.mts.map +1 -1
  32. package/dist/astro/middleware/auth.mjs +10 -8
  33. package/dist/astro/middleware/auth.mjs.map +1 -1
  34. package/dist/astro/middleware/media-usage-write-fence.mjs +5 -5
  35. package/dist/astro/middleware/redirect.d.mts.map +1 -1
  36. package/dist/astro/middleware/redirect.mjs +129 -49
  37. package/dist/astro/middleware/redirect.mjs.map +1 -1
  38. package/dist/astro/middleware/request-context.d.mts.map +1 -1
  39. package/dist/astro/middleware/request-context.mjs +18 -9
  40. package/dist/astro/middleware/request-context.mjs.map +1 -1
  41. package/dist/astro/middleware.d.mts +13 -12
  42. package/dist/astro/middleware.d.mts.map +1 -1
  43. package/dist/astro/middleware.mjs +111 -101
  44. package/dist/astro/middleware.mjs.map +1 -1
  45. package/dist/astro/routes/api/admin/allowed-domains/_domain_.mjs +11 -11
  46. package/dist/astro/routes/api/admin/allowed-domains/index.mjs +11 -11
  47. package/dist/astro/routes/api/admin/api-tokens/_id_.mjs +6 -6
  48. package/dist/astro/routes/api/admin/api-tokens/index.mjs +7 -7
  49. package/dist/astro/routes/api/admin/byline-fields/_slug_/usage.mjs +6 -6
  50. package/dist/astro/routes/api/admin/byline-fields/_slug_.mjs +14 -14
  51. package/dist/astro/routes/api/admin/byline-fields/index.mjs +14 -14
  52. package/dist/astro/routes/api/admin/byline-fields/reorder.mjs +14 -14
  53. package/dist/astro/routes/api/admin/bylines/_id_/index.mjs +25 -25
  54. package/dist/astro/routes/api/admin/bylines/_id_/translations.mjs +25 -25
  55. package/dist/astro/routes/api/admin/bylines/index.mjs +25 -25
  56. package/dist/astro/routes/api/admin/comments/_id_/status.mjs +17 -17
  57. package/dist/astro/routes/api/admin/comments/_id_.mjs +8 -8
  58. package/dist/astro/routes/api/admin/comments/bulk.mjs +16 -16
  59. package/dist/astro/routes/api/admin/comments/counts.mjs +8 -8
  60. package/dist/astro/routes/api/admin/comments/index.mjs +16 -16
  61. package/dist/astro/routes/api/admin/core-update.mjs +6 -6
  62. package/dist/astro/routes/api/admin/hooks/exclusive/_hookName_.mjs +5 -5
  63. package/dist/astro/routes/api/admin/hooks/exclusive/index.mjs +4 -4
  64. package/dist/astro/routes/api/admin/media-usage/activation.mjs +18 -18
  65. package/dist/astro/routes/api/admin/media-usage/collection-deletions/index.mjs +19 -19
  66. package/dist/astro/routes/api/admin/media-usage/collection-deletions/retry.mjs +19 -19
  67. package/dist/astro/routes/api/admin/media-usage/progress.mjs +22 -21
  68. package/dist/astro/routes/api/admin/media-usage/progress.mjs.map +1 -1
  69. package/dist/astro/routes/api/admin/media-usage/repair.mjs +26 -25
  70. package/dist/astro/routes/api/admin/media-usage/repair.mjs.map +1 -1
  71. package/dist/astro/routes/api/admin/media-usage/work/index.mjs +19 -19
  72. package/dist/astro/routes/api/admin/media-usage/work/retry.mjs +19 -19
  73. package/dist/astro/routes/api/admin/oauth-clients/_id_.mjs +4 -4
  74. package/dist/astro/routes/api/admin/oauth-clients/index.mjs +4 -4
  75. package/dist/astro/routes/api/admin/plugins/_id_/disable.mjs +7 -7
  76. package/dist/astro/routes/api/admin/plugins/_id_/enable.mjs +7 -7
  77. package/dist/astro/routes/api/admin/plugins/_id_/index.mjs +66 -65
  78. package/dist/astro/routes/api/admin/plugins/_id_/index.mjs.map +1 -1
  79. package/dist/astro/routes/api/admin/plugins/_id_/mcp.mjs +5 -5
  80. package/dist/astro/routes/api/admin/plugins/_id_/settings.mjs +66 -65
  81. package/dist/astro/routes/api/admin/plugins/_id_/settings.mjs.map +1 -1
  82. package/dist/astro/routes/api/admin/plugins/_id_/uninstall.mjs +66 -65
  83. package/dist/astro/routes/api/admin/plugins/_id_/uninstall.mjs.map +1 -1
  84. package/dist/astro/routes/api/admin/plugins/_id_/update.mjs +73 -72
  85. package/dist/astro/routes/api/admin/plugins/_id_/update.mjs.map +1 -1
  86. package/dist/astro/routes/api/admin/plugins/index.mjs +66 -65
  87. package/dist/astro/routes/api/admin/plugins/index.mjs.map +1 -1
  88. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/icon.mjs +4 -4
  89. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/index.mjs +66 -65
  90. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/index.mjs.map +1 -1
  91. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.mjs +73 -72
  92. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.mjs.map +1 -1
  93. package/dist/astro/routes/api/admin/plugins/marketplace/index.mjs +66 -65
  94. package/dist/astro/routes/api/admin/plugins/marketplace/index.mjs.map +1 -1
  95. package/dist/astro/routes/api/admin/plugins/registry/_id_/uninstall.mjs +66 -65
  96. package/dist/astro/routes/api/admin/plugins/registry/_id_/uninstall.mjs.map +1 -1
  97. package/dist/astro/routes/api/admin/plugins/registry/_id_/update.mjs +74 -73
  98. package/dist/astro/routes/api/admin/plugins/registry/_id_/update.mjs.map +1 -1
  99. package/dist/astro/routes/api/admin/plugins/registry/artifact.mjs +4 -4
  100. package/dist/astro/routes/api/admin/plugins/registry/install.mjs +68 -67
  101. package/dist/astro/routes/api/admin/plugins/registry/install.mjs.map +1 -1
  102. package/dist/astro/routes/api/admin/plugins/registry/publisher-handle.mjs +4 -4
  103. package/dist/astro/routes/api/admin/plugins/registry/verify.mjs +67 -66
  104. package/dist/astro/routes/api/admin/plugins/registry/verify.mjs.map +1 -1
  105. package/dist/astro/routes/api/admin/plugins/updates.mjs +66 -65
  106. package/dist/astro/routes/api/admin/plugins/updates.mjs.map +1 -1
  107. package/dist/astro/routes/api/admin/scheduled-policy-rejections/_collection_/_id_.mjs +5 -5
  108. package/dist/astro/routes/api/admin/themes/marketplace/_id_/index.mjs +66 -65
  109. package/dist/astro/routes/api/admin/themes/marketplace/_id_/index.mjs.map +1 -1
  110. package/dist/astro/routes/api/admin/themes/marketplace/_id_/thumbnail.mjs +4 -4
  111. package/dist/astro/routes/api/admin/themes/marketplace/index.mjs +66 -65
  112. package/dist/astro/routes/api/admin/themes/marketplace/index.mjs.map +1 -1
  113. package/dist/astro/routes/api/admin/transfer/_...path_.mjs +3 -3
  114. package/dist/astro/routes/api/admin/transfer/approvals/_id_/approve.mjs +33 -32
  115. package/dist/astro/routes/api/admin/transfer/approvals/_id_/approve.mjs.map +1 -1
  116. package/dist/astro/routes/api/admin/transfer/approvals/_id_/deny.mjs +33 -32
  117. package/dist/astro/routes/api/admin/transfer/approvals/_id_/deny.mjs.map +1 -1
  118. package/dist/astro/routes/api/admin/transfer/approvals/index.mjs +35 -34
  119. package/dist/astro/routes/api/admin/transfer/approvals/index.mjs.map +1 -1
  120. package/dist/astro/routes/api/admin/transfer/capabilities.mjs +35 -34
  121. package/dist/astro/routes/api/admin/transfer/capabilities.mjs.map +1 -1
  122. package/dist/astro/routes/api/admin/transfer/exports/_id_/advance.mjs +35 -34
  123. package/dist/astro/routes/api/admin/transfer/exports/_id_/advance.mjs.map +1 -1
  124. package/dist/astro/routes/api/admin/transfer/exports/_id_/archive.mjs +36 -35
  125. package/dist/astro/routes/api/admin/transfer/exports/_id_/archive.mjs.map +1 -1
  126. package/dist/astro/routes/api/admin/transfer/exports/_id_/files/_...path_.mjs +36 -35
  127. package/dist/astro/routes/api/admin/transfer/exports/_id_/files/_...path_.mjs.map +1 -1
  128. package/dist/astro/routes/api/admin/transfer/exports/_id_/index.mjs +35 -34
  129. package/dist/astro/routes/api/admin/transfer/exports/_id_/index.mjs.map +1 -1
  130. package/dist/astro/routes/api/admin/transfer/exports/_id_/manifest.mjs +36 -35
  131. package/dist/astro/routes/api/admin/transfer/exports/_id_/manifest.mjs.map +1 -1
  132. package/dist/astro/routes/api/admin/transfer/exports/index.mjs +37 -36
  133. package/dist/astro/routes/api/admin/transfer/exports/index.mjs.map +1 -1
  134. package/dist/astro/routes/api/admin/transfer/imports/_id_/abandon.mjs +35 -34
  135. package/dist/astro/routes/api/admin/transfer/imports/_id_/abandon.mjs.map +1 -1
  136. package/dist/astro/routes/api/admin/transfer/imports/_id_/advance.mjs +35 -34
  137. package/dist/astro/routes/api/admin/transfer/imports/_id_/advance.mjs.map +1 -1
  138. package/dist/astro/routes/api/admin/transfer/imports/_id_/analyze.mjs +37 -36
  139. package/dist/astro/routes/api/admin/transfer/imports/_id_/analyze.mjs.map +1 -1
  140. package/dist/astro/routes/api/admin/transfer/imports/_id_/cancel.mjs +35 -34
  141. package/dist/astro/routes/api/admin/transfer/imports/_id_/cancel.mjs.map +1 -1
  142. package/dist/astro/routes/api/admin/transfer/imports/_id_/execute.mjs +37 -36
  143. package/dist/astro/routes/api/admin/transfer/imports/_id_/execute.mjs.map +1 -1
  144. package/dist/astro/routes/api/admin/transfer/imports/_id_/files/_...path_.mjs +35 -34
  145. package/dist/astro/routes/api/admin/transfer/imports/_id_/files/_...path_.mjs.map +1 -1
  146. package/dist/astro/routes/api/admin/transfer/imports/_id_/index.mjs +35 -34
  147. package/dist/astro/routes/api/admin/transfer/imports/_id_/index.mjs.map +1 -1
  148. package/dist/astro/routes/api/admin/transfer/imports/_id_/missing.mjs +37 -36
  149. package/dist/astro/routes/api/admin/transfer/imports/_id_/missing.mjs.map +1 -1
  150. package/dist/astro/routes/api/admin/transfer/imports/_id_/plan.mjs +35 -34
  151. package/dist/astro/routes/api/admin/transfer/imports/_id_/plan.mjs.map +1 -1
  152. package/dist/astro/routes/api/admin/transfer/imports/_id_/receipt.mjs +35 -34
  153. package/dist/astro/routes/api/admin/transfer/imports/_id_/receipt.mjs.map +1 -1
  154. package/dist/astro/routes/api/admin/transfer/imports/index.mjs +37 -36
  155. package/dist/astro/routes/api/admin/transfer/imports/index.mjs.map +1 -1
  156. package/dist/astro/routes/api/admin/users/_id_/disable.mjs +4 -4
  157. package/dist/astro/routes/api/admin/users/_id_/enable.mjs +3 -3
  158. package/dist/astro/routes/api/admin/users/_id_/index.mjs +12 -12
  159. package/dist/astro/routes/api/admin/users/_id_/send-recovery.mjs +4 -4
  160. package/dist/astro/routes/api/admin/users/index.mjs +11 -11
  161. package/dist/astro/routes/api/auth/dev-bypass.mjs +3 -3
  162. package/dist/astro/routes/api/auth/handover.mjs +5 -5
  163. package/dist/astro/routes/api/auth/invite/accept.mjs +3 -3
  164. package/dist/astro/routes/api/auth/invite/complete.mjs +15 -15
  165. package/dist/astro/routes/api/auth/invite/index.mjs +12 -12
  166. package/dist/astro/routes/api/auth/invite/register-options.mjs +13 -13
  167. package/dist/astro/routes/api/auth/logout.mjs +3 -3
  168. package/dist/astro/routes/api/auth/magic-link/send.mjs +14 -14
  169. package/dist/astro/routes/api/auth/magic-link/verify.mjs +13 -13
  170. package/dist/astro/routes/api/auth/me.mjs +12 -12
  171. package/dist/astro/routes/api/auth/mode.mjs +3 -3
  172. package/dist/astro/routes/api/auth/oauth/_provider_/callback.mjs +8 -8
  173. package/dist/astro/routes/api/auth/oauth/_provider_.mjs +1 -1
  174. package/dist/astro/routes/api/auth/passkey/_id_.mjs +11 -11
  175. package/dist/astro/routes/api/auth/passkey/index.mjs +3 -3
  176. package/dist/astro/routes/api/auth/passkey/options.mjs +15 -15
  177. package/dist/astro/routes/api/auth/passkey/register/options.mjs +13 -13
  178. package/dist/astro/routes/api/auth/passkey/register/verify.mjs +13 -13
  179. package/dist/astro/routes/api/auth/passkey/verify.mjs +15 -15
  180. package/dist/astro/routes/api/auth/signup/complete.mjs +15 -15
  181. package/dist/astro/routes/api/auth/signup/request.mjs +13 -13
  182. package/dist/astro/routes/api/auth/signup/verify.mjs +3 -3
  183. package/dist/astro/routes/api/calendar.mjs +12 -12
  184. package/dist/astro/routes/api/comments/_collection_/_contentId_/index.mjs +12 -12
  185. package/dist/astro/routes/api/comments/_collection_/_contentId_/reactions.mjs +17 -17
  186. package/dist/astro/routes/api/content/_collection_/_id_/compare.mjs +4 -4
  187. package/dist/astro/routes/api/content/_collection_/_id_/discard-draft.mjs +15 -15
  188. package/dist/astro/routes/api/content/_collection_/_id_/duplicate.mjs +4 -4
  189. package/dist/astro/routes/api/content/_collection_/_id_/lock.mjs +15 -15
  190. package/dist/astro/routes/api/content/_collection_/_id_/permanent.mjs +4 -4
  191. package/dist/astro/routes/api/content/_collection_/_id_/plugin-extensions/_pluginId_/_kind_/_extensionId_.mjs +9 -9
  192. package/dist/astro/routes/api/content/_collection_/_id_/preview-url.mjs +29 -28
  193. package/dist/astro/routes/api/content/_collection_/_id_/preview-url.mjs.map +1 -1
  194. package/dist/astro/routes/api/content/_collection_/_id_/publish.mjs +15 -15
  195. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/children.mjs +34 -33
  196. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/children.mjs.map +1 -1
  197. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/parents.mjs +34 -33
  198. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/parents.mjs.map +1 -1
  199. package/dist/astro/routes/api/content/_collection_/_id_/restore.mjs +4 -4
  200. package/dist/astro/routes/api/content/_collection_/_id_/revisions.mjs +4 -4
  201. package/dist/astro/routes/api/content/_collection_/_id_/schedule.mjs +15 -15
  202. package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.d.mts.map +1 -1
  203. package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.mjs +35 -27
  204. package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.mjs.map +1 -1
  205. package/dist/astro/routes/api/content/_collection_/_id_/translations.d.mts.map +1 -1
  206. package/dist/astro/routes/api/content/_collection_/_id_/translations.mjs +8 -4
  207. package/dist/astro/routes/api/content/_collection_/_id_/translations.mjs.map +1 -1
  208. package/dist/astro/routes/api/content/_collection_/_id_/unpublish.mjs +15 -15
  209. package/dist/astro/routes/api/content/_collection_/_id_.mjs +15 -15
  210. package/dist/astro/routes/api/content/_collection_/authors.mjs +4 -4
  211. package/dist/astro/routes/api/content/_collection_/index.mjs +12 -12
  212. package/dist/astro/routes/api/content/_collection_/trash.mjs +12 -12
  213. package/dist/astro/routes/api/dashboard.mjs +22 -16
  214. package/dist/astro/routes/api/dashboard.mjs.map +1 -1
  215. package/dist/astro/routes/api/dev/emails.mjs +3 -3
  216. package/dist/astro/routes/api/dev/scheduled-tasks.mjs +97 -95
  217. package/dist/astro/routes/api/dev/scheduled-tasks.mjs.map +1 -1
  218. package/dist/astro/routes/api/health.mjs +4 -4
  219. package/dist/astro/routes/api/import/probe.d.mts +4 -3
  220. package/dist/astro/routes/api/import/probe.d.mts.map +1 -1
  221. package/dist/astro/routes/api/import/probe.mjs +27 -25
  222. package/dist/astro/routes/api/import/probe.mjs.map +1 -1
  223. package/dist/astro/routes/api/import/wordpress/analyze.d.mts +4 -3
  224. package/dist/astro/routes/api/import/wordpress/analyze.d.mts.map +1 -1
  225. package/dist/astro/routes/api/import/wordpress/analyze.mjs +7 -29
  226. package/dist/astro/routes/api/import/wordpress/analyze.mjs.map +1 -1
  227. package/dist/astro/routes/api/import/wordpress/execute.d.mts +14 -13
  228. package/dist/astro/routes/api/import/wordpress/execute.d.mts.map +1 -1
  229. package/dist/astro/routes/api/import/wordpress/execute.mjs +29 -29
  230. package/dist/astro/routes/api/import/wordpress/execute.mjs.map +1 -1
  231. package/dist/astro/routes/api/import/wordpress/media.d.mts +13 -12
  232. package/dist/astro/routes/api/import/wordpress/media.d.mts.map +1 -1
  233. package/dist/astro/routes/api/import/wordpress/media.mjs +14 -14
  234. package/dist/astro/routes/api/import/wordpress/prepare.mjs +19 -19
  235. package/dist/astro/routes/api/import/wordpress/prepare.mjs.map +1 -1
  236. package/dist/astro/routes/api/import/wordpress/rewrite-urls.d.mts +14 -13
  237. package/dist/astro/routes/api/import/wordpress/rewrite-urls.d.mts.map +1 -1
  238. package/dist/astro/routes/api/import/wordpress/rewrite-urls.mjs +25 -24
  239. package/dist/astro/routes/api/import/wordpress/rewrite-urls.mjs.map +1 -1
  240. package/dist/astro/routes/api/import/wordpress-plugin/analyze.d.mts +1 -1
  241. package/dist/astro/routes/api/import/wordpress-plugin/analyze.mjs +27 -25
  242. package/dist/astro/routes/api/import/wordpress-plugin/analyze.mjs.map +1 -1
  243. package/dist/astro/routes/api/import/wordpress-plugin/execute.d.mts +14 -13
  244. package/dist/astro/routes/api/import/wordpress-plugin/execute.d.mts.map +1 -1
  245. package/dist/astro/routes/api/import/wordpress-plugin/execute.mjs +39 -38
  246. package/dist/astro/routes/api/import/wordpress-plugin/execute.mjs.map +1 -1
  247. package/dist/astro/routes/api/manifest.mjs +4 -4
  248. package/dist/astro/routes/api/mcp.mjs +99 -83
  249. package/dist/astro/routes/api/mcp.mjs.map +1 -1
  250. package/dist/astro/routes/api/media/_id_/confirm.mjs +16 -16
  251. package/dist/astro/routes/api/media/_id_/replace.mjs +12 -12
  252. package/dist/astro/routes/api/media/_id_/upload.mjs +6 -6
  253. package/dist/astro/routes/api/media/_id_/usage.mjs +28 -27
  254. package/dist/astro/routes/api/media/_id_/usage.mjs.map +1 -1
  255. package/dist/astro/routes/api/media/_id_.mjs +26 -25
  256. package/dist/astro/routes/api/media/_id_.mjs.map +1 -1
  257. package/dist/astro/routes/api/media/asset/_id_/_filename_.mjs +5 -5
  258. package/dist/astro/routes/api/media/file/_...key_.d.mts.map +1 -1
  259. package/dist/astro/routes/api/media/file/_...key_.mjs +62 -8
  260. package/dist/astro/routes/api/media/file/_...key_.mjs.map +1 -1
  261. package/dist/astro/routes/api/media/folders/_id_.mjs +13 -13
  262. package/dist/astro/routes/api/media/folders/index.mjs +13 -13
  263. package/dist/astro/routes/api/media/providers/_providerId_/_itemId_.mjs +4 -4
  264. package/dist/astro/routes/api/media/providers/_providerId_/index.mjs +4 -4
  265. package/dist/astro/routes/api/media/providers/index.mjs +4 -4
  266. package/dist/astro/routes/api/media/upload-url.mjs +15 -15
  267. package/dist/astro/routes/api/media.mjs +30 -29
  268. package/dist/astro/routes/api/media.mjs.map +1 -1
  269. package/dist/astro/routes/api/menus/_name_/items/_id_.mjs +17 -15
  270. package/dist/astro/routes/api/menus/_name_/items/_id_.mjs.map +1 -1
  271. package/dist/astro/routes/api/menus/_name_/items.mjs +17 -15
  272. package/dist/astro/routes/api/menus/_name_/items.mjs.map +1 -1
  273. package/dist/astro/routes/api/menus/_name_/reorder.mjs +17 -15
  274. package/dist/astro/routes/api/menus/_name_/reorder.mjs.map +1 -1
  275. package/dist/astro/routes/api/menus/_name_/translations.mjs +17 -15
  276. package/dist/astro/routes/api/menus/_name_/translations.mjs.map +1 -1
  277. package/dist/astro/routes/api/menus/_name_.mjs +17 -15
  278. package/dist/astro/routes/api/menus/_name_.mjs.map +1 -1
  279. package/dist/astro/routes/api/menus/index.mjs +17 -15
  280. package/dist/astro/routes/api/menus/index.mjs.map +1 -1
  281. package/dist/astro/routes/api/oauth/authorize.mjs +2 -2
  282. package/dist/astro/routes/api/oauth/device/authorize.mjs +6 -6
  283. package/dist/astro/routes/api/oauth/device/code.mjs +8 -8
  284. package/dist/astro/routes/api/oauth/device/token.mjs +8 -8
  285. package/dist/astro/routes/api/oauth/register.mjs +5 -5
  286. package/dist/astro/routes/api/oauth/token/refresh.mjs +6 -6
  287. package/dist/astro/routes/api/oauth/token/revoke.mjs +6 -6
  288. package/dist/astro/routes/api/oauth/token.d.mts.map +1 -1
  289. package/dist/astro/routes/api/oauth/token.mjs +7 -7
  290. package/dist/astro/routes/api/oauth/token.mjs.map +1 -1
  291. package/dist/astro/routes/api/openapi.json.mjs +12 -12
  292. package/dist/astro/routes/api/plugins/_pluginId_/_...path_.mjs +9 -9
  293. package/dist/astro/routes/api/redirects/404s/index.mjs +20 -19
  294. package/dist/astro/routes/api/redirects/404s/index.mjs.map +1 -1
  295. package/dist/astro/routes/api/redirects/404s/summary.mjs +20 -19
  296. package/dist/astro/routes/api/redirects/404s/summary.mjs.map +1 -1
  297. package/dist/astro/routes/api/redirects/_id_.mjs +21 -20
  298. package/dist/astro/routes/api/redirects/_id_.mjs.map +1 -1
  299. package/dist/astro/routes/api/redirects/index.mjs +21 -20
  300. package/dist/astro/routes/api/redirects/index.mjs.map +1 -1
  301. package/dist/astro/routes/api/relations/_id_/index.mjs +34 -33
  302. package/dist/astro/routes/api/relations/_id_/index.mjs.map +1 -1
  303. package/dist/astro/routes/api/relations/index.mjs +34 -33
  304. package/dist/astro/routes/api/relations/index.mjs.map +1 -1
  305. package/dist/astro/routes/api/revisions/_revisionId_/index.mjs +4 -4
  306. package/dist/astro/routes/api/revisions/_revisionId_/restore.mjs +15 -15
  307. package/dist/astro/routes/api/schema/block-types/_slug_/index.mjs +66 -65
  308. package/dist/astro/routes/api/schema/block-types/_slug_/index.mjs.map +1 -1
  309. package/dist/astro/routes/api/schema/block-types/_slug_/versions/_version_/activate.mjs +66 -65
  310. package/dist/astro/routes/api/schema/block-types/_slug_/versions/_version_/activate.mjs.map +1 -1
  311. package/dist/astro/routes/api/schema/block-types/index.mjs +66 -65
  312. package/dist/astro/routes/api/schema/block-types/index.mjs.map +1 -1
  313. package/dist/astro/routes/api/schema/collections/_slug_/fields/_fieldSlug_.mjs +66 -65
  314. package/dist/astro/routes/api/schema/collections/_slug_/fields/_fieldSlug_.mjs.map +1 -1
  315. package/dist/astro/routes/api/schema/collections/_slug_/fields/index.mjs +66 -65
  316. package/dist/astro/routes/api/schema/collections/_slug_/fields/index.mjs.map +1 -1
  317. package/dist/astro/routes/api/schema/collections/_slug_/fields/reorder.mjs +66 -65
  318. package/dist/astro/routes/api/schema/collections/_slug_/fields/reorder.mjs.map +1 -1
  319. package/dist/astro/routes/api/schema/collections/_slug_/index.mjs +66 -65
  320. package/dist/astro/routes/api/schema/collections/_slug_/index.mjs.map +1 -1
  321. package/dist/astro/routes/api/schema/collections/index.mjs +66 -65
  322. package/dist/astro/routes/api/schema/collections/index.mjs.map +1 -1
  323. package/dist/astro/routes/api/schema/collections/reorder.mjs +66 -65
  324. package/dist/astro/routes/api/schema/collections/reorder.mjs.map +1 -1
  325. package/dist/astro/routes/api/schema/index.mjs +17 -16
  326. package/dist/astro/routes/api/schema/index.mjs.map +1 -1
  327. package/dist/astro/routes/api/schema/orphans/_slug_.mjs +66 -65
  328. package/dist/astro/routes/api/schema/orphans/_slug_.mjs.map +1 -1
  329. package/dist/astro/routes/api/schema/orphans/index.mjs +66 -65
  330. package/dist/astro/routes/api/schema/orphans/index.mjs.map +1 -1
  331. package/dist/astro/routes/api/search/enable.mjs +20 -18
  332. package/dist/astro/routes/api/search/enable.mjs.map +1 -1
  333. package/dist/astro/routes/api/search/index.mjs +19 -17
  334. package/dist/astro/routes/api/search/index.mjs.map +1 -1
  335. package/dist/astro/routes/api/search/rebuild.mjs +20 -18
  336. package/dist/astro/routes/api/search/rebuild.mjs.map +1 -1
  337. package/dist/astro/routes/api/search/stats.mjs +13 -11
  338. package/dist/astro/routes/api/search/stats.mjs.map +1 -1
  339. package/dist/astro/routes/api/search/suggest.mjs +19 -17
  340. package/dist/astro/routes/api/search/suggest.mjs.map +1 -1
  341. package/dist/astro/routes/api/sections/_slug_.mjs +19 -17
  342. package/dist/astro/routes/api/sections/_slug_.mjs.map +1 -1
  343. package/dist/astro/routes/api/sections/index.mjs +19 -17
  344. package/dist/astro/routes/api/sections/index.mjs.map +1 -1
  345. package/dist/astro/routes/api/settings/backups/archives/_name_.mjs +7 -7
  346. package/dist/astro/routes/api/settings/backups/archives/index.mjs +7 -7
  347. package/dist/astro/routes/api/settings/backups/export.mjs +7 -7
  348. package/dist/astro/routes/api/settings/backups/index.mjs +8 -8
  349. package/dist/astro/routes/api/settings/domain-notify.mjs +7 -7
  350. package/dist/astro/routes/api/settings/domain.mjs +19 -17
  351. package/dist/astro/routes/api/settings/domain.mjs.map +1 -1
  352. package/dist/astro/routes/api/settings/email.mjs +5 -5
  353. package/dist/astro/routes/api/settings.mjs +25 -23
  354. package/dist/astro/routes/api/settings.mjs.map +1 -1
  355. package/dist/astro/routes/api/setup/admin-verify.mjs +18 -18
  356. package/dist/astro/routes/api/setup/admin.mjs +14 -14
  357. package/dist/astro/routes/api/setup/dev-bypass.mjs +45 -44
  358. package/dist/astro/routes/api/setup/dev-bypass.mjs.map +1 -1
  359. package/dist/astro/routes/api/setup/dev-reset.mjs +3 -3
  360. package/dist/astro/routes/api/setup/index.mjs +48 -47
  361. package/dist/astro/routes/api/setup/index.mjs.map +1 -1
  362. package/dist/astro/routes/api/setup/status.mjs +4 -4
  363. package/dist/astro/routes/api/site/domain-proof.mjs +17 -15
  364. package/dist/astro/routes/api/site/domain-proof.mjs.map +1 -1
  365. package/dist/astro/routes/api/snapshot.mjs +9 -9
  366. package/dist/astro/routes/api/taxonomies/_name_/reorder.mjs +25 -24
  367. package/dist/astro/routes/api/taxonomies/_name_/reorder.mjs.map +1 -1
  368. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_/translations.mjs +25 -24
  369. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_/translations.mjs.map +1 -1
  370. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_.mjs +25 -24
  371. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_.mjs.map +1 -1
  372. package/dist/astro/routes/api/taxonomies/_name_/terms/index.mjs +25 -24
  373. package/dist/astro/routes/api/taxonomies/_name_/terms/index.mjs.map +1 -1
  374. package/dist/astro/routes/api/taxonomies/_name_/translations.mjs +25 -24
  375. package/dist/astro/routes/api/taxonomies/_name_/translations.mjs.map +1 -1
  376. package/dist/astro/routes/api/taxonomies/_name_.mjs +25 -24
  377. package/dist/astro/routes/api/taxonomies/_name_.mjs.map +1 -1
  378. package/dist/astro/routes/api/taxonomies/bulk-tag.mjs +35 -34
  379. package/dist/astro/routes/api/taxonomies/bulk-tag.mjs.map +1 -1
  380. package/dist/astro/routes/api/taxonomies/index.mjs +25 -24
  381. package/dist/astro/routes/api/taxonomies/index.mjs.map +1 -1
  382. package/dist/astro/routes/api/themes/preview.mjs +6 -6
  383. package/dist/astro/routes/api/typegen.mjs +5 -5
  384. package/dist/astro/routes/api/visual-editing/action-token.mjs +5 -5
  385. package/dist/astro/routes/api/visual-editing/content/_collection_/_id_/publish.mjs +17 -17
  386. package/dist/astro/routes/api/visual-editing/toolbar-labels.mjs +3 -3
  387. package/dist/astro/routes/api/well-known/oauth-authorization-server.mjs +1 -1
  388. package/dist/astro/routes/api/well-known/oauth-protected-resource.mjs +1 -1
  389. package/dist/astro/routes/api/widget-areas/_name_/reorder.d.mts.map +1 -1
  390. package/dist/astro/routes/api/widget-areas/_name_/reorder.mjs +24 -13
  391. package/dist/astro/routes/api/widget-areas/_name_/reorder.mjs.map +1 -1
  392. package/dist/astro/routes/api/widget-areas/_name_/widgets/_id_.d.mts.map +1 -1
  393. package/dist/astro/routes/api/widget-areas/_name_/widgets/_id_.mjs +22 -17
  394. package/dist/astro/routes/api/widget-areas/_name_/widgets/_id_.mjs.map +1 -1
  395. package/dist/astro/routes/api/widget-areas/_name_/widgets.mjs +21 -17
  396. package/dist/astro/routes/api/widget-areas/_name_/widgets.mjs.map +1 -1
  397. package/dist/astro/routes/api/widget-areas/_name_.mjs +14 -10
  398. package/dist/astro/routes/api/widget-areas/_name_.mjs.map +1 -1
  399. package/dist/astro/routes/api/widget-areas/index.mjs +21 -17
  400. package/dist/astro/routes/api/widget-areas/index.mjs.map +1 -1
  401. package/dist/astro/routes/api/widget-components.mjs +3 -3
  402. package/dist/astro/routes/robots.txt.mjs +16 -14
  403. package/dist/astro/routes/robots.txt.mjs.map +1 -1
  404. package/dist/astro/routes/sitemap-_collection_.xml.mjs +18 -16
  405. package/dist/astro/routes/sitemap-_collection_.xml.mjs.map +1 -1
  406. package/dist/astro/routes/sitemap.xml.mjs +16 -14
  407. package/dist/astro/routes/sitemap.xml.mjs.map +1 -1
  408. package/dist/astro/types.d.mts +22 -20
  409. package/dist/astro/types.d.mts.map +1 -1
  410. package/dist/{audit-_gieLVGU.mjs → audit-B8XE-0UV.mjs} +2 -2
  411. package/dist/{audit-_gieLVGU.mjs.map → audit-B8XE-0UV.mjs.map} +1 -1
  412. package/dist/auth/providers/github.d.mts +1 -1
  413. package/dist/auth/providers/google.d.mts +1 -1
  414. package/dist/auth/providers/microsoft.d.mts +1 -1
  415. package/dist/{authorize-DPFBGbE6.mjs → authorize-NJgp8kLI.mjs} +2 -2
  416. package/dist/{authorize-DPFBGbE6.mjs.map → authorize-NJgp8kLI.mjs.map} +1 -1
  417. package/dist/{backup-3FgVxiDJ.mjs → backup-8rPSJ28a.mjs} +4 -4
  418. package/dist/{backup-3FgVxiDJ.mjs.map → backup-8rPSJ28a.mjs.map} +1 -1
  419. package/dist/{block-types-CYcG56JB.mjs → block-types-BbOrfnWs.mjs} +5 -5
  420. package/dist/{block-types-CYcG56JB.mjs.map → block-types-BbOrfnWs.mjs.map} +1 -1
  421. package/dist/{block-values-gCX4HBSl.mjs → block-values-Dg0-8PPS.mjs} +4 -4
  422. package/dist/{block-values-gCX4HBSl.mjs.map → block-values-Dg0-8PPS.mjs.map} +1 -1
  423. package/dist/{byline-BR1qhyiw.mjs → byline-DHJS-GGb.mjs} +123 -38
  424. package/dist/byline-DHJS-GGb.mjs.map +1 -0
  425. package/dist/{byline-fields-BLXZnX7N.mjs → byline-fields-CiR8FvvF.mjs} +3 -3
  426. package/dist/{byline-fields-BLXZnX7N.mjs.map → byline-fields-CiR8FvvF.mjs.map} +1 -1
  427. package/dist/{byline-fields-4ClDC88c.mjs → byline-fields-D6KYsEa7.mjs} +2 -2
  428. package/dist/{byline-fields-4ClDC88c.mjs.map → byline-fields-D6KYsEa7.mjs.map} +1 -1
  429. package/dist/{byline-registry-dvt4N3xV.mjs → byline-registry-BhzpO41z.mjs} +3 -3
  430. package/dist/{byline-registry-dvt4N3xV.mjs.map → byline-registry-BhzpO41z.mjs.map} +1 -1
  431. package/dist/{bylines-CVOvRUL7.mjs → bylines-Bsg5cH4S.mjs} +7 -7
  432. package/dist/bylines-Bsg5cH4S.mjs.map +1 -0
  433. package/dist/{bylines-DxOs9B7z.mjs → bylines-f_ZEc6Sn.mjs} +8 -8
  434. package/dist/{bylines-DxOs9B7z.mjs.map → bylines-f_ZEc6Sn.mjs.map} +1 -1
  435. package/dist/{cache-CEU9wo_h.mjs → cache-5DHbpEWu.mjs} +4 -4
  436. package/dist/{cache-CEU9wo_h.mjs.map → cache-5DHbpEWu.mjs.map} +1 -1
  437. package/dist/{capture-triggers-CT6dK9zd.mjs → capture-triggers-BezAvWcB.mjs} +2 -2
  438. package/dist/{capture-triggers-CT6dK9zd.mjs.map → capture-triggers-BezAvWcB.mjs.map} +1 -1
  439. package/dist/{challenge-store-C17BYx2-.mjs → challenge-store-B1C0V4b3.mjs} +1 -1
  440. package/dist/{challenge-store-C17BYx2-.mjs.map → challenge-store-B1C0V4b3.mjs.map} +1 -1
  441. package/dist/{chunks-xC4UD5-S.mjs → chunks-DiW8VMwz.mjs} +2 -2
  442. package/dist/{chunks-xC4UD5-S.mjs.map → chunks-DiW8VMwz.mjs.map} +1 -1
  443. package/dist/cli/index.mjs +53 -52
  444. package/dist/cli/index.mjs.map +1 -1
  445. package/dist/client/cf-access.d.mts +1 -1
  446. package/dist/client/index.d.mts +61 -61
  447. package/dist/client/index.d.mts.map +1 -1
  448. package/dist/client/index.mjs +3 -2
  449. package/dist/client/index.mjs.map +1 -1
  450. package/dist/{collection-slugs-cache-e09QeJQt.mjs → collection-slugs-cache-DIrLjqH-.mjs} +20 -14
  451. package/dist/collection-slugs-cache-DIrLjqH-.mjs.map +1 -0
  452. package/dist/{comment-UvIWDKcW.mjs → comment-DB74Zpa4.mjs} +18 -8
  453. package/dist/comment-DB74Zpa4.mjs.map +1 -0
  454. package/dist/{comment-reaction-dGp6_FRo.mjs → comment-reaction-BScxIWUn.mjs} +2 -2
  455. package/dist/{comment-reaction-dGp6_FRo.mjs.map → comment-reaction-BScxIWUn.mjs.map} +1 -1
  456. package/dist/{comments-pej-_BUO.mjs → comments-Cor_zKml.mjs} +3 -3
  457. package/dist/{comments-pej-_BUO.mjs.map → comments-Cor_zKml.mjs.map} +1 -1
  458. package/dist/config-Cs_AwWXI.mjs +106 -0
  459. package/dist/config-Cs_AwWXI.mjs.map +1 -0
  460. package/dist/{config-CFMojMFK.d.mts → config-D44_8G9J.d.mts} +3 -1
  461. package/dist/config-D44_8G9J.d.mts.map +1 -0
  462. package/dist/{config-Bsm_u_oE.d.mts → config-sDhZvkLR.d.mts} +56 -20
  463. package/dist/config-sDhZvkLR.d.mts.map +1 -0
  464. package/dist/{content-DQSRZTVw.mjs → content-BKHUVsE5.mjs} +67 -30
  465. package/dist/content-BKHUVsE5.mjs.map +1 -0
  466. package/dist/{content-list-query-CYKcY6Vi.d.mts → content-list-query-ByP4jRpZ.d.mts} +1 -1
  467. package/dist/{content-list-query-CYKcY6Vi.d.mts.map → content-list-query-ByP4jRpZ.d.mts.map} +1 -1
  468. package/dist/{content-policy-Dm32n9C6.mjs → content-policy-BmE0MPZY.mjs} +1 -1
  469. package/dist/{content-policy-Dm32n9C6.mjs.map → content-policy-BmE0MPZY.mjs.map} +1 -1
  470. package/dist/{content-repair-DNh5--x5.mjs → content-repair-Ukdxoq-R.mjs} +4 -4
  471. package/dist/{content-repair-DNh5--x5.mjs.map → content-repair-Ukdxoq-R.mjs.map} +1 -1
  472. package/dist/{context-BYptmCN0.mjs → context-CzjejcsE.mjs} +32 -33
  473. package/dist/context-CzjejcsE.mjs.map +1 -0
  474. package/dist/{credits-B9iORdWB.mjs → credits-BKREepht.mjs} +3 -3
  475. package/dist/{credits-B9iORdWB.mjs.map → credits-BKREepht.mjs.map} +1 -1
  476. package/dist/{dashboard-D0jcgBD7.mjs → dashboard-ynr1qJWM.mjs} +10 -9
  477. package/dist/dashboard-ynr1qJWM.mjs.map +1 -0
  478. package/dist/database/migration-lock.mjs +1 -1
  479. package/dist/db/index.d.mts +3 -3
  480. package/dist/db/index.mjs +3 -3
  481. package/dist/db/libsql-migrations.d.mts +1 -1
  482. package/dist/db/libsql-migrations.mjs +5 -5
  483. package/dist/db/libsql.d.mts +1 -1
  484. package/dist/db/postgres-migrations.d.mts +1 -1
  485. package/dist/db/postgres-migrations.mjs +5 -5
  486. package/dist/db/postgres.d.mts +1 -1
  487. package/dist/db/sqlite-migrations.d.mts +1 -1
  488. package/dist/db/sqlite-migrations.mjs +5 -5
  489. package/dist/db/sqlite.d.mts +1 -1
  490. package/dist/{db-errors-CBD5yMro.mjs → db-errors-unnO6yiZ.mjs} +12 -2
  491. package/dist/db-errors-unnO6yiZ.mjs.map +1 -0
  492. package/dist/deferred-tasks-wlMFJL95.d.mts +10 -0
  493. package/dist/deferred-tasks-wlMFJL95.d.mts.map +1 -0
  494. package/dist/{destination-r2zIAZ2S.mjs → destination-DR3IHjmy.mjs} +1 -1
  495. package/dist/{destination-r2zIAZ2S.mjs.map → destination-DR3IHjmy.mjs.map} +1 -1
  496. package/dist/{device-flow-BkFKBoAn.mjs → device-flow-D1U392GC.mjs} +3 -5
  497. package/dist/device-flow-D1U392GC.mjs.map +1 -0
  498. package/dist/{dialect-helpers-7_IqPdh9.mjs → dialect-helpers-B1XN2HGB.mjs} +10 -3
  499. package/dist/dialect-helpers-B1XN2HGB.mjs.map +1 -0
  500. package/dist/{direct-executor-Cbxzg4qe.mjs → direct-executor-Bs2g0ake.mjs} +4 -4
  501. package/dist/{direct-executor-Cbxzg4qe.mjs.map → direct-executor-Bs2g0ake.mjs.map} +1 -1
  502. package/dist/{dist-Cfu8mMBs.mjs → dist-BUmWMTbN.mjs} +1 -1
  503. package/dist/{dist-Cfu8mMBs.mjs.map → dist-BUmWMTbN.mjs.map} +1 -1
  504. package/dist/{email-locale-BJ8DjTzZ.mjs → email-locale-Bs3HFdnq.mjs} +1 -1
  505. package/dist/{email-locale-BJ8DjTzZ.mjs.map → email-locale-Bs3HFdnq.mjs.map} +1 -1
  506. package/dist/{emdash-runtime-DVi7vtXC.mjs → emdash-runtime-C8T-pZpS.mjs} +108 -62
  507. package/dist/emdash-runtime-C8T-pZpS.mjs.map +1 -0
  508. package/dist/{enrich-Duu4sV3a.mjs → enrich-DFlfnd3u.mjs} +3 -3
  509. package/dist/{enrich-Duu4sV3a.mjs.map → enrich-DFlfnd3u.mjs.map} +1 -1
  510. package/dist/{entry-lock-C7VX0NGK.d.mts → entry-lock-BulbgPBX.d.mts} +23 -23
  511. package/dist/{entry-lock-C7VX0NGK.d.mts.map → entry-lock-BulbgPBX.d.mts.map} +1 -1
  512. package/dist/{entry-lock-Df6-XhIu.mjs → entry-lock-CRVmruM0.mjs} +4 -4
  513. package/dist/{entry-lock-Df6-XhIu.mjs.map → entry-lock-CRVmruM0.mjs.map} +1 -1
  514. package/dist/{entry-lock-DLxCffFW.mjs → entry-lock-D-zJQ4q6.mjs} +3 -3
  515. package/dist/{entry-lock-DLxCffFW.mjs.map → entry-lock-D-zJQ4q6.mjs.map} +1 -1
  516. package/dist/{entry-locks-DJAqVweV.mjs → entry-locks-CJ9uhqg1.mjs} +2 -2
  517. package/dist/{entry-locks-DJAqVweV.mjs.map → entry-locks-CJ9uhqg1.mjs.map} +1 -1
  518. package/dist/{env-types-C3FCVBWe.mjs → env-types-BE3bCvfP.mjs} +5 -5
  519. package/dist/{env-types-C3FCVBWe.mjs.map → env-types-BE3bCvfP.mjs.map} +1 -1
  520. package/dist/{error-CVWeIOku.mjs → error-BCMgPxdn.mjs} +3 -3
  521. package/dist/{error-CVWeIOku.mjs.map → error-BCMgPxdn.mjs.map} +1 -1
  522. package/dist/{errors-BOYNdIo3.mjs → errors-8gJqv-XV.mjs} +15 -2
  523. package/dist/{errors-BOYNdIo3.mjs.map → errors-8gJqv-XV.mjs.map} +1 -1
  524. package/dist/{fence-C3MUitUN.mjs → fence-Dagicj14.mjs} +4 -4
  525. package/dist/{fence-C3MUitUN.mjs.map → fence-Dagicj14.mjs.map} +1 -1
  526. package/dist/{field-map-Bft9LKak.mjs → field-map-BSXdNGt5.mjs} +11 -10
  527. package/dist/field-map-BSXdNGt5.mjs.map +1 -0
  528. package/dist/{focal-point-JX8kcOTQ.mjs → focal-point-CgCcr1Ca.mjs} +1 -1
  529. package/dist/{focal-point-JX8kcOTQ.mjs.map → focal-point-CgCcr1Ca.mjs.map} +1 -1
  530. package/dist/{fts-manager-Beg3e4bI.mjs → fts-manager-6861qcwk.mjs} +68 -22
  531. package/dist/fts-manager-6861qcwk.mjs.map +1 -0
  532. package/dist/{gc-ByyAYiYE.mjs → gc-CNkXB3mE.mjs} +8 -8
  533. package/dist/{gc-ByyAYiYE.mjs.map → gc-CNkXB3mE.mjs.map} +1 -1
  534. package/dist/{hook-result-BrdLyOdI.d.mts → hook-result-f8t7hIuu.d.mts} +1 -1
  535. package/dist/{hook-result-BrdLyOdI.d.mts.map → hook-result-f8t7hIuu.d.mts.map} +1 -1
  536. package/dist/{hreflang-CY_F5OjF.d.mts → hreflang-8dUOJAPJ.d.mts} +2 -2
  537. package/dist/{hreflang-CY_F5OjF.d.mts.map → hreflang-8dUOJAPJ.d.mts.map} +1 -1
  538. package/dist/{hreflang-C8Jb-hrf.mjs → hreflang-BW5A4FLK.mjs} +8 -8
  539. package/dist/{hreflang-C8Jb-hrf.mjs.map → hreflang-BW5A4FLK.mjs.map} +1 -1
  540. package/dist/{http-route-dispatch-CyeW6iPv.mjs → http-route-dispatch-rXKvTNm9.mjs} +5 -5
  541. package/dist/{http-route-dispatch-CyeW6iPv.mjs.map → http-route-dispatch-rXKvTNm9.mjs.map} +1 -1
  542. package/dist/{identity-Cael5uTT.mjs → identity-CPRRSovU.mjs} +3 -3
  543. package/dist/{identity-Cael5uTT.mjs.map → identity-CPRRSovU.mjs.map} +1 -1
  544. package/dist/{import-BUXjdZUn.mjs → import-yVbfPyfd.mjs} +5 -5
  545. package/dist/{import-BUXjdZUn.mjs.map → import-yVbfPyfd.mjs.map} +1 -1
  546. package/dist/index-VM7Fzxwe.d.mts +260 -0
  547. package/dist/index-VM7Fzxwe.d.mts.map +1 -0
  548. package/dist/index.d.mts +25 -24
  549. package/dist/index.mjs +89 -88
  550. package/dist/{install-finalization-3JX5qQEA.mjs → install-finalization-RU6VrHOX.mjs} +1 -1
  551. package/dist/{install-finalization-3JX5qQEA.mjs.map → install-finalization-RU6VrHOX.mjs.map} +1 -1
  552. package/dist/{json-recordset-BUjxhr77.mjs → json-recordset-D0WhN2UA.mjs} +2 -2
  553. package/dist/{json-recordset-BUjxhr77.mjs.map → json-recordset-D0WhN2UA.mjs.map} +1 -1
  554. package/dist/{lifecycle-7vUJeFRe.mjs → lifecycle-B8d7Rdqx.mjs} +1 -1
  555. package/dist/{lifecycle-7vUJeFRe.mjs.map → lifecycle-B8d7Rdqx.mjs.map} +1 -1
  556. package/dist/{load-CdAG9wz-.mjs → load-D4xtzm6h.mjs} +2 -2
  557. package/dist/{load-CdAG9wz-.mjs.map → load-D4xtzm6h.mjs.map} +1 -1
  558. package/dist/{loader-CswroUbe.mjs → loader-DhnedqY4.mjs} +199 -101
  559. package/dist/loader-DhnedqY4.mjs.map +1 -0
  560. package/dist/{loops-uA4iTOzd.mjs → loops-B2YS-Zzr.mjs} +2 -2
  561. package/dist/{loops-uA4iTOzd.mjs.map → loops-B2YS-Zzr.mjs.map} +1 -1
  562. package/dist/{manifest-builder-B8zjuH3f.mjs → manifest-builder-g1FLviel.mjs} +10 -3
  563. package/dist/manifest-builder-g1FLviel.mjs.map +1 -0
  564. package/dist/media/image-endpoint.d.mts +3 -2
  565. package/dist/media/image-endpoint.d.mts.map +1 -1
  566. package/dist/media/image-endpoint.mjs +17 -8
  567. package/dist/media/image-endpoint.mjs.map +1 -1
  568. package/dist/media/index.d.mts +1 -1
  569. package/dist/media/index.mjs +7 -6
  570. package/dist/media/index.mjs.map +1 -1
  571. package/dist/media/local-runtime.d.mts +15 -14
  572. package/dist/media/local-runtime.d.mts.map +1 -1
  573. package/dist/media/local-runtime.mjs +20 -15
  574. package/dist/media/local-runtime.mjs.map +1 -1
  575. package/dist/{media-1WC65OCB.mjs → media-BR4_t-Wd.mjs} +3 -3
  576. package/dist/{media-1WC65OCB.mjs.map → media-BR4_t-Wd.mjs.map} +1 -1
  577. package/dist/{media--dJRU6i2.mjs → media-CikS-q6E.mjs} +4 -4
  578. package/dist/{media--dJRU6i2.mjs.map → media-CikS-q6E.mjs.map} +1 -1
  579. package/dist/{media-Bws9f18T.mjs → media-DepNLhPq.mjs} +14 -4
  580. package/dist/media-DepNLhPq.mjs.map +1 -0
  581. package/dist/{media-allowlist-BJB7MFx6.mjs → media-allowlist-BMBLqyWh.mjs} +2 -2
  582. package/dist/{media-allowlist-BJB7MFx6.mjs.map → media-allowlist-BMBLqyWh.mjs.map} +1 -1
  583. package/dist/{media-folders-Dn3C16B8.mjs → media-folders-CI0Wydfo.mjs} +2 -2
  584. package/dist/{media-folders-Dn3C16B8.mjs.map → media-folders-CI0Wydfo.mjs.map} +1 -1
  585. package/dist/{media-usage-CF0WVcLO.mjs → media-usage-X1_20MY-.mjs} +8 -8
  586. package/dist/{media-usage-CF0WVcLO.mjs.map → media-usage-X1_20MY-.mjs.map} +1 -1
  587. package/dist/{media-usage-activation-C9HwVw5w.mjs → media-usage-activation-bWusy3M2.mjs} +3 -3
  588. package/dist/{media-usage-activation-C9HwVw5w.mjs.map → media-usage-activation-bWusy3M2.mjs.map} +1 -1
  589. package/dist/{media-usage-work-m3AWTmmC.mjs → media-usage-work-B2RaoJIa.mjs} +4 -4
  590. package/dist/{media-usage-work-m3AWTmmC.mjs.map → media-usage-work-B2RaoJIa.mjs.map} +1 -1
  591. package/dist/{media-usage-work-CkLa5-nc.mjs → media-usage-work-BCK2J-v_.mjs} +7 -7
  592. package/dist/{media-usage-work-CkLa5-nc.mjs.map → media-usage-work-BCK2J-v_.mjs.map} +1 -1
  593. package/dist/{menus-BCVSSp1z.mjs → menus-B0Qqv_cS.mjs} +176 -92
  594. package/dist/menus-B0Qqv_cS.mjs.map +1 -0
  595. package/dist/{menus-Cl4kwdt7.mjs → menus-oypxT1pI.mjs} +134 -53
  596. package/dist/menus-oypxT1pI.mjs.map +1 -0
  597. package/dist/{menus-BSzwObhV.mjs → menus-uEAxWAm1.mjs} +3 -3
  598. package/dist/{menus-BSzwObhV.mjs.map → menus-uEAxWAm1.mjs.map} +1 -1
  599. package/dist/migrations/index.d.mts +1 -1
  600. package/dist/migrations/index.mjs +5 -5
  601. package/dist/{mime-B5M9R53H.mjs → mime-D1We9jUx.mjs} +1 -1
  602. package/dist/{mime-B5M9R53H.mjs.map → mime-D1We9jUx.mjs.map} +1 -1
  603. package/dist/{normalize-BuWa0lvd.mjs → normalize-Cx-bNwhP.mjs} +41 -12
  604. package/dist/normalize-Cx-bNwhP.mjs.map +1 -0
  605. package/dist/{oauth-authorization-TpEJrYB7.mjs → oauth-authorization-CPLgBrdo.mjs} +19 -6
  606. package/dist/oauth-authorization-CPLgBrdo.mjs.map +1 -0
  607. package/dist/{oauth-state-store-CHMn_mwc.mjs → oauth-state-store-BndCfRum.mjs} +1 -1
  608. package/dist/{oauth-state-store-CHMn_mwc.mjs.map → oauth-state-store-BndCfRum.mjs.map} +1 -1
  609. package/dist/object-cache/memory.d.mts +1 -1
  610. package/dist/{object-cache-Bo6DGaC9.mjs → object-cache-DmKr09La.mjs} +21 -4
  611. package/dist/{object-cache-Bo6DGaC9.mjs.map → object-cache-DmKr09La.mjs.map} +1 -1
  612. package/dist/{options-DJWaq3Ie.d.mts → options-BUUgroHg.d.mts} +3 -3
  613. package/dist/{options-DJWaq3Ie.d.mts.map → options-BUUgroHg.d.mts.map} +1 -1
  614. package/dist/page/index.d.mts +2 -2
  615. package/dist/page/index.mjs +16 -14
  616. package/dist/page/index.mjs.map +1 -1
  617. package/dist/{parse-DgQ2NABT.mjs → parse-B_b6gZxG.mjs} +2 -2
  618. package/dist/{parse-DgQ2NABT.mjs.map → parse-B_b6gZxG.mjs.map} +1 -1
  619. package/dist/{parse-CWHOFc6z.d.mts → parse-Dndx1QmN.d.mts} +3 -3
  620. package/dist/{parse-CWHOFc6z.d.mts.map → parse-Dndx1QmN.d.mts.map} +1 -1
  621. package/dist/{passkey-config-D0kdzEao.mjs → passkey-config-D2Lua5__.mjs} +1 -1
  622. package/dist/{passkey-config-D0kdzEao.mjs.map → passkey-config-D2Lua5__.mjs.map} +1 -1
  623. package/dist/{patterns-CMNnYCgf.mjs → patterns-CryGz_EV.mjs} +1 -1
  624. package/dist/{patterns-CMNnYCgf.mjs.map → patterns-CryGz_EV.mjs.map} +1 -1
  625. package/dist/{placeholder-D41vk11_.d.mts → placeholder-CSKu5OkD.d.mts} +9 -1
  626. package/dist/placeholder-CSKu5OkD.d.mts.map +1 -0
  627. package/dist/plugin-test-runtime.d.mts +17 -15
  628. package/dist/plugin-test-runtime.d.mts.map +1 -1
  629. package/dist/plugin-test-runtime.mjs +99 -98
  630. package/dist/plugin-types.d.mts +2 -2
  631. package/dist/plugin-utils.d.mts +13 -12
  632. package/dist/plugin-utils.d.mts.map +1 -1
  633. package/dist/plugins/adapt-sandbox-entry.d.mts +13 -12
  634. package/dist/plugins/adapt-sandbox-entry.d.mts.map +1 -1
  635. package/dist/plugins/host.d.mts +5 -5
  636. package/dist/plugins/host.mjs +48 -47
  637. package/dist/{policy-DLQ--Hnm.mjs → policy-BPugqmeV.mjs} +13 -5
  638. package/dist/policy-BPugqmeV.mjs.map +1 -0
  639. package/dist/{protocol-79kUO7jP.d.mts → protocol-PoAfD_9W.d.mts} +2 -2
  640. package/dist/{protocol-79kUO7jP.d.mts.map → protocol-PoAfD_9W.d.mts.map} +1 -1
  641. package/dist/{public-plugin-api-routes-BuAMJ8nN.mjs → public-plugin-api-routes-CMljrTby.mjs} +9 -9
  642. package/dist/{public-plugin-api-routes-BuAMJ8nN.mjs.map → public-plugin-api-routes-CMljrTby.mjs.map} +1 -1
  643. package/dist/{public-submission-Di3TsgzX.mjs → public-submission-ayqoyee4.mjs} +10 -10
  644. package/dist/{public-submission-Di3TsgzX.mjs.map → public-submission-ayqoyee4.mjs.map} +1 -1
  645. package/dist/query-BFHjCzSh.mjs +37 -0
  646. package/dist/query-BFHjCzSh.mjs.map +1 -0
  647. package/dist/{query-CpnRlBh8.mjs → query-D62NntCZ.mjs} +55 -65
  648. package/dist/query-D62NntCZ.mjs.map +1 -0
  649. package/dist/{query-haKvLAWl.mjs → query-LmPY2y0C.mjs} +5 -5
  650. package/dist/{query-haKvLAWl.mjs.map → query-LmPY2y0C.mjs.map} +1 -1
  651. package/dist/{rate-limit-Xp4d0NBY.mjs → rate-limit-C04Llsoc.mjs} +3 -3
  652. package/dist/{rate-limit-Xp4d0NBY.mjs.map → rate-limit-C04Llsoc.mjs.map} +1 -1
  653. package/dist/{redirect-DiS_3mA4.mjs → redirect-DjLdw427.mjs} +6 -6
  654. package/dist/{redirect-DiS_3mA4.mjs.map → redirect-DjLdw427.mjs.map} +1 -1
  655. package/dist/{redirect-paths-CNYq7w80.mjs → redirect-paths-DOaVBp6E.mjs} +1 -1
  656. package/dist/{redirect-paths-CNYq7w80.mjs.map → redirect-paths-DOaVBp6E.mjs.map} +1 -1
  657. package/dist/{redirects-BHpy-VsZ.mjs → redirects-Cpq1catN.mjs} +6 -6
  658. package/dist/{redirects-BHpy-VsZ.mjs.map → redirects-Cpq1catN.mjs.map} +1 -1
  659. package/dist/{redirects-BEVSRMa2.mjs → redirects-CyvvZrCJ.mjs} +2 -2
  660. package/dist/{redirects-BEVSRMa2.mjs.map → redirects-CyvvZrCJ.mjs.map} +1 -1
  661. package/dist/{registry-TUVaid9Z.mjs → registry-B0-O575m.mjs} +25 -20
  662. package/dist/registry-B0-O575m.mjs.map +1 -0
  663. package/dist/{relations-CA_QuMTU.mjs → relations-WIOojTL4.mjs} +24 -11
  664. package/dist/relations-WIOojTL4.mjs.map +1 -0
  665. package/dist/{request-cache-C4CIo5ad.mjs → request-cache-5z2WzWmh.mjs} +1 -1
  666. package/dist/{request-cache-C4CIo5ad.mjs.map → request-cache-5z2WzWmh.mjs.map} +1 -1
  667. package/dist/request-context.d.mts +12 -1
  668. package/dist/request-context.d.mts.map +1 -1
  669. package/dist/request-context.mjs.map +1 -1
  670. package/dist/{resolve-DwNM-CXl.mjs → resolve-BNnm8EkB.mjs} +14 -13
  671. package/dist/{resolve-DwNM-CXl.mjs.map → resolve-BNnm8EkB.mjs.map} +1 -1
  672. package/dist/{resolve-D-kqyKns.mjs → resolve-DdNXBJSr.mjs} +4 -4
  673. package/dist/resolve-DdNXBJSr.mjs.map +1 -0
  674. package/dist/{revision-BVp8S0e_.mjs → revision-Dx7Uth1X.mjs} +5 -5
  675. package/dist/{revision-BVp8S0e_.mjs.map → revision-Dx7Uth1X.mjs.map} +1 -1
  676. package/dist/{routes-BerZFrvV.mjs → routes-avqgc-8r.mjs} +3 -3
  677. package/dist/{routes-BerZFrvV.mjs.map → routes-avqgc-8r.mjs.map} +1 -1
  678. package/dist/{runner-C5NeAkBQ.mjs → runner-Bkkfk4O8.mjs} +78 -4
  679. package/dist/runner-Bkkfk4O8.mjs.map +1 -0
  680. package/dist/{runner-BObHz5FC.d.mts → runner-Dfgp6-S_.d.mts} +7 -2
  681. package/dist/runner-Dfgp6-S_.d.mts.map +1 -0
  682. package/dist/runtime.d.mts +14 -13
  683. package/dist/runtime.d.mts.map +1 -1
  684. package/dist/runtime.mjs +8 -6
  685. package/dist/runtime.mjs.map +1 -1
  686. package/dist/schema/project-env-types.mjs +43 -42
  687. package/dist/schema/project-env-types.mjs.map +1 -1
  688. package/dist/{schema-DJRfvM_o.mjs → schema-B-3rntlX.mjs} +11 -11
  689. package/dist/{schema-DJRfvM_o.mjs.map → schema-B-3rntlX.mjs.map} +1 -1
  690. package/dist/{schema-C4OBuv6Z.mjs → schema-BqBlUZtb.mjs} +4 -4
  691. package/dist/{schema-C4OBuv6Z.mjs.map → schema-BqBlUZtb.mjs.map} +1 -1
  692. package/dist/{scopes-BU03K7Uo.mjs → scopes-DNaY7Ey0.mjs} +3 -3
  693. package/dist/{scopes-BU03K7Uo.mjs.map → scopes-DNaY7Ey0.mjs.map} +1 -1
  694. package/dist/{search-DfVzks89.mjs → search-BPWTnpnD.mjs} +32 -32
  695. package/dist/search-BPWTnpnD.mjs.map +1 -0
  696. package/dist/{secrets-Cc_O3Kp-.mjs → secrets-Dswzrz3k.mjs} +2 -2
  697. package/dist/{secrets-Cc_O3Kp-.mjs.map → secrets-Dswzrz3k.mjs.map} +1 -1
  698. package/dist/{sections-BMy4JVUz.mjs → sections-rSao6rBG.mjs} +3 -3
  699. package/dist/{sections-BMy4JVUz.mjs.map → sections-rSao6rBG.mjs.map} +1 -1
  700. package/dist/seed/index.d.mts +2 -2
  701. package/dist/seed/index.mjs +42 -41
  702. package/dist/seo/index.d.mts +3 -3
  703. package/dist/seo/index.mjs +30 -28
  704. package/dist/seo/index.mjs.map +1 -1
  705. package/dist/{seo-VZYOEy8f.mjs → seo-B_H_pqOd.mjs} +3 -3
  706. package/dist/{seo-VZYOEy8f.mjs.map → seo-B_H_pqOd.mjs.map} +1 -1
  707. package/dist/{service-Bo_usgSk.mjs → service-DpiUQVpp.mjs} +2 -2
  708. package/dist/{service-Bo_usgSk.mjs.map → service-DpiUQVpp.mjs.map} +1 -1
  709. package/dist/{session-user-DlpPdf8L.mjs → session-user-DiE4JKPP.mjs} +4 -4
  710. package/dist/{session-user-DlpPdf8L.mjs.map → session-user-DiE4JKPP.mjs.map} +1 -1
  711. package/dist/{settings-DS914jjE.mjs → settings--XlUdUaI.mjs} +3 -3
  712. package/dist/{settings-DS914jjE.mjs.map → settings--XlUdUaI.mjs.map} +1 -1
  713. package/dist/{settings-CWb84sDm.mjs → settings-D932YP2-.mjs} +111 -44
  714. package/dist/settings-D932YP2-.mjs.map +1 -0
  715. package/dist/{setup-complete-BuNxAUiN.mjs → setup-complete-qsJYWutC.mjs} +2 -2
  716. package/dist/{setup-complete-BuNxAUiN.mjs.map → setup-complete-qsJYWutC.mjs.map} +1 -1
  717. package/dist/{setup-nonce-BnEAX0iy.mjs → setup-nonce-CBFgUFXw.mjs} +1 -1
  718. package/dist/{setup-nonce-BnEAX0iy.mjs.map → setup-nonce-CBFgUFXw.mjs.map} +1 -1
  719. package/dist/{site-domain-Bq5j5bVg.mjs → site-domain-oRGS_JfA.mjs} +2 -2
  720. package/dist/{site-domain-Bq5j5bVg.mjs.map → site-domain-oRGS_JfA.mjs.map} +1 -1
  721. package/dist/{sitemap-name-BTg2NJJv.mjs → sitemap-name-B8QP8wud.mjs} +1 -1
  722. package/dist/{sitemap-name-BTg2NJJv.mjs.map → sitemap-name-B8QP8wud.mjs.map} +1 -1
  723. package/dist/{slugify-bu2-jKia.mjs → slugify-BDEG9pLk.mjs} +1 -1
  724. package/dist/{slugify-bu2-jKia.mjs.map → slugify-BDEG9pLk.mjs.map} +1 -1
  725. package/dist/{snapshot-DYsG4uOq.mjs → snapshot-BjaXDZQ5.mjs} +2 -2
  726. package/dist/{snapshot-DYsG4uOq.mjs.map → snapshot-BjaXDZQ5.mjs.map} +1 -1
  727. package/dist/{stage-D8DWgPcO.mjs → stage-CZQnXM_G.mjs} +3 -3
  728. package/dist/{stage-D8DWgPcO.mjs.map → stage-CZQnXM_G.mjs.map} +1 -1
  729. package/dist/{staged-CD_imitH.mjs → staged-ByBmPFtX.mjs} +3 -3
  730. package/dist/{staged-CD_imitH.mjs.map → staged-ByBmPFtX.mjs.map} +1 -1
  731. package/dist/storage/local.d.mts +1 -1
  732. package/dist/storage/s3.d.mts +1 -1
  733. package/dist/{storage-query-DRyu3bSU.d.mts → storage-query-BFp06Y0s.d.mts} +22 -10
  734. package/dist/storage-query-BFp06Y0s.d.mts.map +1 -0
  735. package/dist/{taxonomies-Dd9JJv_a.mjs → taxonomies-5SR76j11.mjs} +15 -17
  736. package/dist/taxonomies-5SR76j11.mjs.map +1 -0
  737. package/dist/{taxonomies-ChnU7Mc8.mjs → taxonomies-B__VmCKQ.mjs} +64 -58
  738. package/dist/taxonomies-B__VmCKQ.mjs.map +1 -0
  739. package/dist/{taxonomy-C_C_LBAU.mjs → taxonomy-CMI5fczd.mjs} +30 -17
  740. package/dist/taxonomy-CMI5fczd.mjs.map +1 -0
  741. package/dist/{transaction-BVYIo_yu.mjs → transaction-CkoQ5wqQ.mjs} +1 -1
  742. package/dist/{transaction-BVYIo_yu.mjs.map → transaction-CkoQ5wqQ.mjs.map} +1 -1
  743. package/dist/{transfer-WmWiR3xf.mjs → transfer-BbKfufJ4.mjs} +2 -2
  744. package/dist/{transfer-WmWiR3xf.mjs.map → transfer-BbKfufJ4.mjs.map} +1 -1
  745. package/dist/{transfer-ClH6w6BV.mjs → transfer-DTGblAj2.mjs} +71 -34
  746. package/dist/{transfer-ClH6w6BV.mjs.map → transfer-DTGblAj2.mjs.map} +1 -1
  747. package/dist/{transfer-download--ofRj9Cw.mjs → transfer-download-D9LQEDX0.mjs} +1 -1
  748. package/dist/{transfer-download--ofRj9Cw.mjs.map → transfer-download-D9LQEDX0.mjs.map} +1 -1
  749. package/dist/{transport-DxiXnbXk.d.mts → transport-Dm5QzpT_.d.mts} +1 -1
  750. package/dist/{transport-DxiXnbXk.d.mts.map → transport-Dm5QzpT_.d.mts.map} +1 -1
  751. package/dist/{transport-BjbqNiPI.mjs → transport-Dzpn5b3i.mjs} +4 -3
  752. package/dist/transport-Dzpn5b3i.mjs.map +1 -0
  753. package/dist/{turnstile-CJwvsOqw.mjs → turnstile-Cs2wfkJG.mjs} +1 -1
  754. package/dist/{turnstile-CJwvsOqw.mjs.map → turnstile-Cs2wfkJG.mjs.map} +1 -1
  755. package/dist/{types-BA3ey2QH.d.mts → types-BAsCk5KU.d.mts} +1 -1
  756. package/dist/{types-BA3ey2QH.d.mts.map → types-BAsCk5KU.d.mts.map} +1 -1
  757. package/dist/{types-RLgeIpnF.d.mts → types-BuvSwT9Y.d.mts} +8 -7
  758. package/dist/{types-RLgeIpnF.d.mts.map → types-BuvSwT9Y.d.mts.map} +1 -1
  759. package/dist/{types-CNB-dj6F.d.mts → types-C4KT3Md2.d.mts} +10 -6
  760. package/dist/types-C4KT3Md2.d.mts.map +1 -0
  761. package/dist/{types-DvqVxZXa.d.mts → types-CVXHwIBB.d.mts} +1 -1
  762. package/dist/{types-DvqVxZXa.d.mts.map → types-CVXHwIBB.d.mts.map} +1 -1
  763. package/dist/{types-BGmQ0uXs.mjs → types-C_asjp1J.mjs} +1 -1
  764. package/dist/types-C_asjp1J.mjs.map +1 -0
  765. package/dist/{types-DHO7Pd25.d.mts → types-CadaL_k8.d.mts} +1 -1
  766. package/dist/{types-DHO7Pd25.d.mts.map → types-CadaL_k8.d.mts.map} +1 -1
  767. package/dist/{types-QoPHm-2w.d.mts → types-CjftrmZR.d.mts} +3 -3
  768. package/dist/{types-QoPHm-2w.d.mts.map → types-CjftrmZR.d.mts.map} +1 -1
  769. package/dist/{types-DCFavOii.d.mts → types-DKwRUA-x.d.mts} +1 -1
  770. package/dist/{types-DCFavOii.d.mts.map → types-DKwRUA-x.d.mts.map} +1 -1
  771. package/dist/{types-D2NEXtgB.mjs → types-DwhEvIVb.mjs} +8 -2
  772. package/dist/types-DwhEvIVb.mjs.map +1 -0
  773. package/dist/{types-Bwpzb5o6.d.mts → types-GwAyS5SH.d.mts} +1 -1
  774. package/dist/{types-Bwpzb5o6.d.mts.map → types-GwAyS5SH.d.mts.map} +1 -1
  775. package/dist/{types-slSqujQL.d.mts → types-uU2YNYSt.d.mts} +6 -1
  776. package/dist/types-uU2YNYSt.d.mts.map +1 -0
  777. package/dist/{update-check-BxNg9T6N.mjs → update-check-ABBJgg6M.mjs} +4 -4
  778. package/dist/{update-check-BxNg9T6N.mjs.map → update-check-ABBJgg6M.mjs.map} +1 -1
  779. package/dist/{url-Dn3IStq8.mjs → url-DTfGDJhI.mjs} +1 -1
  780. package/dist/{url-Dn3IStq8.mjs.map → url-DTfGDJhI.mjs.map} +1 -1
  781. package/dist/{user-BlCTKVAm.mjs → user-By8SzQxS.mjs} +3 -3
  782. package/dist/{user-BlCTKVAm.mjs.map → user-By8SzQxS.mjs.map} +1 -1
  783. package/dist/{utils-TPt7w2cS.mjs → utils-D5uOi6WS.mjs} +13 -5
  784. package/dist/utils-D5uOi6WS.mjs.map +1 -0
  785. package/dist/{index-BB9sVisO.d.mts → utils-Szp4iBQB.d.mts} +9 -256
  786. package/dist/utils-Szp4iBQB.d.mts.map +1 -0
  787. package/dist/{validate-emKxGC5F.d.mts → validate-DDvxy6qG.d.mts} +8 -8
  788. package/dist/{validate-emKxGC5F.d.mts.map → validate-DDvxy6qG.d.mts.map} +1 -1
  789. package/dist/{validate-DxYhJQA-.mjs → validate-Dz-TIOFB.mjs} +7 -7
  790. package/dist/{validate-DxYhJQA-.mjs.map → validate-Dz-TIOFB.mjs.map} +1 -1
  791. package/dist/{validation-Ckq4vsVg.mjs → validation-Fc9ZSUS_.mjs} +17 -16
  792. package/dist/{validation-Ckq4vsVg.mjs.map → validation-Fc9ZSUS_.mjs.map} +1 -1
  793. package/dist/version-Bu6Nlbb5.mjs +7 -0
  794. package/dist/{version-DHmGpcch.mjs.map → version-Bu6Nlbb5.mjs.map} +1 -1
  795. package/dist/version-DqB7LIO7.mjs +49 -0
  796. package/dist/version-DqB7LIO7.mjs.map +1 -0
  797. package/dist/{widgets-DA5XmvVC.mjs → widgets-BUx_Mf2q.mjs} +18 -5
  798. package/dist/widgets-BUx_Mf2q.mjs.map +1 -0
  799. package/dist/{wxr-taxonomies-RgRG0d5e.mjs → wxr-taxonomies-DbJtWrWM.mjs} +7 -6
  800. package/dist/wxr-taxonomies-DbJtWrWM.mjs.map +1 -0
  801. package/dist/{wxr-taxonomies-CrMonejI.d.mts → wxr-taxonomies-Dy2i2ON3.d.mts} +1 -1
  802. package/dist/wxr-taxonomies-Dy2i2ON3.d.mts.map +1 -0
  803. package/dist/{zod-generator-D0JKy94C.mjs → zod-generator--nlM0930.mjs} +5 -4
  804. package/dist/zod-generator--nlM0930.mjs.map +1 -0
  805. package/package.json +5 -5
  806. package/src/api/handlers/bulk-tag.ts +11 -3
  807. package/src/api/handlers/bylines.ts +6 -2
  808. package/src/api/handlers/content.ts +154 -23
  809. package/src/api/handlers/dashboard.ts +13 -6
  810. package/src/api/handlers/device-flow.ts +1 -3
  811. package/src/api/handlers/menus.ts +27 -13
  812. package/src/api/handlers/oauth-authorization.ts +1 -3
  813. package/src/api/handlers/relations.ts +15 -1
  814. package/src/api/handlers/taxonomies.ts +27 -17
  815. package/src/astro/image-endpoint.ts +23 -2
  816. package/src/astro/integration/admin-nav.ts +52 -0
  817. package/src/astro/integration/index.ts +7 -0
  818. package/src/astro/integration/runtime.ts +14 -0
  819. package/src/astro/integration/shims/use-sync-external-store-with-selector.js +2 -0
  820. package/src/astro/integration/shims/use-sync-external-store.js +4 -1
  821. package/src/astro/integration/vite-config.ts +16 -8
  822. package/src/astro/middleware/auth.ts +9 -2
  823. package/src/astro/middleware/redirect.ts +158 -63
  824. package/src/astro/middleware/request-context.ts +1 -0
  825. package/src/astro/middleware.ts +17 -4
  826. package/src/astro/routes/api/content/[collection]/[id]/terms/[taxonomy].ts +4 -1
  827. package/src/astro/routes/api/content/[collection]/[id]/translations.ts +14 -1
  828. package/src/astro/routes/api/dashboard.ts +2 -0
  829. package/src/astro/routes/api/import/wordpress/analyze.ts +5 -29
  830. package/src/astro/routes/api/import/wordpress-plugin/execute.ts +3 -3
  831. package/src/astro/routes/api/media/file/[...key].ts +31 -7
  832. package/src/astro/routes/api/oauth/token.ts +5 -1
  833. package/src/astro/routes/api/widget-areas/[name]/reorder.ts +7 -1
  834. package/src/astro/routes/api/widget-areas/[name]/widgets/[id].ts +3 -1
  835. package/src/astro/routes/api/widget-areas/[name]/widgets.ts +2 -1
  836. package/src/astro/routes/api/widget-areas/[name].ts +2 -1
  837. package/src/astro/routes/api/widget-areas/index.ts +2 -1
  838. package/src/astro/types.ts +4 -3
  839. package/src/auth/api-tokens.ts +3 -0
  840. package/src/auth/types.ts +6 -0
  841. package/src/cleanup.ts +44 -0
  842. package/src/cli/commands/export-seed.ts +6 -4
  843. package/src/cli/commands/login.ts +2 -4
  844. package/src/client/index.ts +1 -0
  845. package/src/client/transport.ts +11 -7
  846. package/src/components/EmDashImage.astro +14 -2
  847. package/src/components/InlinePortableTextEditor.tsx +4 -1
  848. package/src/components/inline-bubble-menu.tsx +109 -95
  849. package/src/components/inline-image.tsx +54 -48
  850. package/src/database/dialect-helpers.ts +10 -3
  851. package/src/database/migrations/content-sized.ts +82 -0
  852. package/src/database/migrations/policy.ts +28 -2
  853. package/src/database/migrations/runner.ts +48 -0
  854. package/src/database/repositories/byline.ts +95 -31
  855. package/src/database/repositories/comment.ts +17 -7
  856. package/src/database/repositories/content.ts +96 -23
  857. package/src/database/repositories/media.ts +17 -0
  858. package/src/database/repositories/menu.ts +236 -139
  859. package/src/database/repositories/taxonomy-def.ts +9 -2
  860. package/src/database/repositories/taxonomy.ts +47 -14
  861. package/src/database/repositories/types.ts +14 -3
  862. package/src/database/types.ts +1 -1
  863. package/src/emdash-runtime.ts +60 -17
  864. package/src/fields/image.ts +1 -0
  865. package/src/i18n/config.ts +58 -10
  866. package/src/i18n/normalize.ts +16 -2
  867. package/src/i18n/query.ts +47 -0
  868. package/src/i18n/resolve.ts +8 -3
  869. package/src/import/utils.ts +15 -2
  870. package/src/import/wxr-taxonomies.ts +3 -2
  871. package/src/index.ts +1 -0
  872. package/src/loader.ts +183 -114
  873. package/src/mcp/server.ts +28 -1
  874. package/src/media/caption.ts +30 -0
  875. package/src/media/content-disposition.ts +56 -0
  876. package/src/media/image-endpoint.ts +13 -6
  877. package/src/media/local-runtime.ts +3 -0
  878. package/src/media/normalize.ts +17 -8
  879. package/src/media/responsive.ts +12 -2
  880. package/src/media/types.ts +16 -3
  881. package/src/media/usage/content-fields.ts +2 -1
  882. package/src/menus/index.ts +158 -36
  883. package/src/migrations/manifest.ts +1 -0
  884. package/src/object-cache/index.ts +22 -0
  885. package/src/plugin-test-runtime.ts +1 -0
  886. package/src/plugins/byline-access.ts +3 -1
  887. package/src/plugins/context.ts +1 -2
  888. package/src/plugins/storage-indexes.ts +7 -3
  889. package/src/query.ts +67 -53
  890. package/src/redirects/artifacts.ts +39 -5
  891. package/src/references/field-map.ts +6 -4
  892. package/src/request-context.ts +8 -0
  893. package/src/schema/collection-slugs-cache.ts +31 -17
  894. package/src/schema/registry.ts +9 -0
  895. package/src/schema/types.ts +7 -6
  896. package/src/schema/zod-generator.ts +2 -1
  897. package/src/search/fts-manager.ts +103 -31
  898. package/src/search/query.ts +31 -64
  899. package/src/seed/apply.ts +221 -109
  900. package/src/seed/types.ts +6 -4
  901. package/src/settings/index.ts +135 -35
  902. package/src/settings/version.ts +54 -0
  903. package/src/taxonomies/index.ts +99 -85
  904. package/src/taxonomies/term-counts.ts +2 -1
  905. package/src/transfer/import/advance.ts +12 -1
  906. package/src/transfer/import/scaffold.ts +7 -1
  907. package/src/transfer/import/stages.ts +53 -2
  908. package/src/utils/db-errors.ts +15 -0
  909. package/src/utils/revalidating-cache.ts +85 -0
  910. package/src/virtual-modules.d.ts +1 -0
  911. package/src/visual-editing/toolbar.ts +7 -2
  912. package/src/widgets/index.ts +27 -13
  913. package/dist/api-D-7BNHoz.mjs.map +0 -1
  914. package/dist/api-tokens-CdP49zVF.mjs +0 -3
  915. package/dist/apply-T7ATgzCh.mjs.map +0 -1
  916. package/dist/artifacts-htGyfCSt.mjs.map +0 -1
  917. package/dist/byline-BR1qhyiw.mjs.map +0 -1
  918. package/dist/bylines-CVOvRUL7.mjs.map +0 -1
  919. package/dist/collection-slugs-cache-e09QeJQt.mjs.map +0 -1
  920. package/dist/comment-UvIWDKcW.mjs.map +0 -1
  921. package/dist/config-Bsm_u_oE.d.mts.map +0 -1
  922. package/dist/config-CFMojMFK.d.mts.map +0 -1
  923. package/dist/config-CvmjJcVw.mjs +0 -73
  924. package/dist/config-CvmjJcVw.mjs.map +0 -1
  925. package/dist/content-DQSRZTVw.mjs.map +0 -1
  926. package/dist/context-BYptmCN0.mjs.map +0 -1
  927. package/dist/dashboard-D0jcgBD7.mjs.map +0 -1
  928. package/dist/db-errors-CBD5yMro.mjs.map +0 -1
  929. package/dist/deferred-tasks-ZvUECSzI.d.mts +0 -9
  930. package/dist/deferred-tasks-ZvUECSzI.d.mts.map +0 -1
  931. package/dist/device-flow-BkFKBoAn.mjs.map +0 -1
  932. package/dist/dialect-helpers-7_IqPdh9.mjs.map +0 -1
  933. package/dist/emdash-runtime-DVi7vtXC.mjs.map +0 -1
  934. package/dist/field-defs-cache-Dez5iWJJ.mjs +0 -77
  935. package/dist/field-defs-cache-Dez5iWJJ.mjs.map +0 -1
  936. package/dist/field-map-Bft9LKak.mjs.map +0 -1
  937. package/dist/fts-manager-Beg3e4bI.mjs.map +0 -1
  938. package/dist/index-BB9sVisO.d.mts.map +0 -1
  939. package/dist/loader-CswroUbe.mjs.map +0 -1
  940. package/dist/manifest-builder-B8zjuH3f.mjs.map +0 -1
  941. package/dist/media-Bws9f18T.mjs.map +0 -1
  942. package/dist/menus-BCVSSp1z.mjs.map +0 -1
  943. package/dist/menus-Cl4kwdt7.mjs.map +0 -1
  944. package/dist/normalize-BuWa0lvd.mjs.map +0 -1
  945. package/dist/oauth-authorization-TpEJrYB7.mjs.map +0 -1
  946. package/dist/placeholder-D41vk11_.d.mts.map +0 -1
  947. package/dist/policy-DLQ--Hnm.mjs.map +0 -1
  948. package/dist/query-CpnRlBh8.mjs.map +0 -1
  949. package/dist/registry-TUVaid9Z.mjs.map +0 -1
  950. package/dist/relations-CA_QuMTU.mjs.map +0 -1
  951. package/dist/resolve-D-kqyKns.mjs.map +0 -1
  952. package/dist/runner-BObHz5FC.d.mts.map +0 -1
  953. package/dist/runner-C5NeAkBQ.mjs.map +0 -1
  954. package/dist/search-DfVzks89.mjs.map +0 -1
  955. package/dist/settings-CWb84sDm.mjs.map +0 -1
  956. package/dist/storage-query-DRyu3bSU.d.mts.map +0 -1
  957. package/dist/taxonomies-ChnU7Mc8.mjs.map +0 -1
  958. package/dist/taxonomies-Dd9JJv_a.mjs.map +0 -1
  959. package/dist/taxonomy-C_C_LBAU.mjs.map +0 -1
  960. package/dist/transport-BjbqNiPI.mjs.map +0 -1
  961. package/dist/types-BGmQ0uXs.mjs.map +0 -1
  962. package/dist/types-CNB-dj6F.d.mts.map +0 -1
  963. package/dist/types-D2NEXtgB.mjs.map +0 -1
  964. package/dist/types-slSqujQL.d.mts.map +0 -1
  965. package/dist/utils-TPt7w2cS.mjs.map +0 -1
  966. package/dist/version-DHmGpcch.mjs +0 -7
  967. package/dist/widgets-DA5XmvVC.mjs.map +0 -1
  968. package/dist/wxr-taxonomies-CrMonejI.d.mts.map +0 -1
  969. package/dist/wxr-taxonomies-RgRG0d5e.mjs.map +0 -1
  970. package/dist/zod-generator-D0JKy94C.mjs.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"taxonomy-C_C_LBAU.mjs","names":[],"sources":["../src/database/repositories/taxonomy.ts"],"sourcesContent":["import { sql, type Kysely, type Selectable } from \"kysely\";\nimport { ulid } from \"ulidx\";\n\nimport { invalidateTaxonomyObjectCache } from \"../../object-cache/index.js\";\nimport { chunks, SQL_BATCH_SIZE } from \"../../utils/chunks.js\";\nimport { slugify } from \"../../utils/slugify.js\";\nimport { withTransaction } from \"../transaction.js\";\nimport type { Database, TaxonomyTable } from \"../types.js\";\nimport { validateIdentifier } from \"../validate.js\";\n\n/** A member of one sibling group and the position it currently holds. */\nexport interface SiblingPosition {\n\tgroup: string;\n\tposition: number;\n}\n\n/**\n * Translation groups per reorder `UPDATE`. Each costs three bound parameters —\n * a CASE `WHEN`/`THEN` pair plus one slot in the `IN` list — which keeps a\n * statement inside D1's 100-parameter ceiling.\n */\nconst GROUPS_PER_UPDATE = 32;\n/** Rows per `content_taxonomies` insert. Each row binds three parameters. */\nconst ASSIGNMENTS_PER_INSERT = 32;\nconst NUMERIC_SUFFIX_PATTERN = /^\\d+$/;\n\n/** Deal the listed groups back out over the slots they hold, in the order given. */\nfunction permuteWithinSlots(\n\tlisted: readonly string[],\n\toccupied: readonly number[],\n): Map<string, number> {\n\tconst slots = occupied.toSorted((a, b) => a - b);\n\tconst target = new Map<string, number>();\n\tlisted.forEach((group, index) => {\n\t\tconst position = slots[index];\n\t\tif (position !== undefined) target.set(group, position);\n\t});\n\treturn target;\n}\n\n/**\n * Renumber a whole sibling group 0..n-1, with the listed groups in the order\n * given and every other member left in the place it already held.\n *\n * Works off each member's index in the sequence rather than its stored value,\n * which is what lets it resolve positions that tie. The sort is stable, so\n * tied members keep the order `siblings` arrives in — deterministic, but a\n * listing that mixes locales breaks a tie on whichever locale's label sorts\n * first, not on the order any one caller rendered.\n */\nfunction renumberSiblings(\n\tlisted: readonly string[],\n\tsiblings: readonly SiblingPosition[],\n): Map<string, number> {\n\tconst sequence = siblings.toSorted((a, b) => a.position - b.position);\n\tconst wanted = new Set(listed);\n\tconst target = new Map<string, number>();\n\tlet next = 0;\n\tsequence.forEach(({ group }, index) => {\n\t\tconst replacement = wanted.has(group) ? listed[next++] : undefined;\n\t\ttarget.set(replacement ?? group, index);\n\t});\n\treturn target;\n}\n\nexport interface Taxonomy {\n\tid: string;\n\tname: string;\n\tslug: string;\n\tlabel: string;\n\tparentId: string | null;\n\tdata: Record<string, unknown> | null;\n\tlocale: string;\n\ttranslationGroup: string | null;\n\t/**\n\t * Position among siblings. Shared by every row of a `translation_group` —\n\t * a term sits in the same place in every locale it is translated into.\n\t */\n\tsortOrder: number;\n}\n\nexport interface CreateTaxonomyInput {\n\tname: string;\n\tslug: string;\n\tlabel: string;\n\tparentId?: string;\n\tdata?: Record<string, unknown>;\n\t/** Omit to let the DB default (current value: 'en') apply. Higher layers\n\t * resolve the locale from the request context / i18n config. */\n\tlocale?: string;\n\t/** When set, links the new term into the source term's translation_group. */\n\ttranslationOf?: string;\n}\n\nexport interface UpdateTaxonomyInput {\n\tslug?: string;\n\tlabel?: string;\n\tparentId?: string | null;\n\tdata?: Record<string, unknown>;\n}\n\nexport interface FindOptions {\n\tparentId?: string | null;\n\tlocale?: string;\n}\n\nexport interface TaxonomyManualPageCursor {\n\tsortOrder: number;\n\tlabel: string;\n\tid: string;\n}\n\nexport interface TaxonomyPageOptions extends FindOptions {\n\tcursor?: TaxonomyManualPageCursor;\n\tlimit?: number;\n}\n\nexport interface TaxonomyPage {\n\titems: Taxonomy[];\n\thasMore: boolean;\n}\n\nexport interface TaxonomyAssignmentTranslation {\n\tid: string;\n\tslug: string;\n\tlocale: string;\n}\n\nexport interface TaxonomyAssignmentResolution {\n\ttranslationGroup: string;\n\tterm: Taxonomy | null;\n\tavailableLocales: string[];\n\ttranslations: TaxonomyAssignmentTranslation[];\n}\n\n/**\n * Taxonomy repository for categories, tags, and other classification.\n *\n * Terms are per-locale. Translations of the same term share a `translation_group`\n * ULID. `content_taxonomies` stores translation_groups on both sides so a single\n * association spans every locale of a post and term.\n *\n * Strict lookup methods use only the locale callers supply. The explicitly\n * resolved methods accept both the preferred and default locales so their\n * fallback policy stays visible at the call site.\n *\n * `sort_order` is per translation_group, not per row: every row sharing a\n * translation_group carries the same value, so a term holds one position across\n * all its locales. Sibling groups are keyed on the raw `parent_id` column, which\n * is locale-agnostic for the same reason (it stores the parent's\n * translation_group). Writes must preserve both invariants.\n */\nexport class TaxonomyRepository {\n\tconstructor(private db: Kysely<Database>) {}\n\n\t/**\n\t * Create a new taxonomy term. When `translationOf` is set the new row joins\n\t * the source term's translation_group; otherwise a fresh group is minted\n\t * (matching the migration backfill pattern `translation_group = id`).\n\t */\n\tasync create(input: CreateTaxonomyInput): Promise<Taxonomy> {\n\t\tconst id = ulid();\n\n\t\t// Empty-string parentId counts as omitted. Higher layers also normalize\n\t\t// this — see handleTermCreate / handleTermUpdate.\n\t\t// `parent_id` stores the parent's locale-agnostic translation_group (not a\n\t\t// row id), mirroring content_taxonomies.taxonomy_id, so a child stays\n\t\t// nested in every locale's tree. resolveTranslationGroup accepts either a\n\t\t// row id or an already-resolved group, so this is idempotent.\n\t\tconst parentInput = input.parentId === \"\" ? undefined : input.parentId;\n\t\tlet parentId = parentInput ? await this.resolveParentRef(parentInput) : null;\n\n\t\tlet translationGroup = id;\n\t\tlet sortOrder: number | null = null;\n\t\tlet movesGroup = false;\n\t\tif (input.translationOf) {\n\t\t\tconst source = await this.findById(input.translationOf);\n\t\t\tif (source?.translationGroup) translationGroup = source.translationGroup;\n\t\t\t// A translation is the same term in another locale, so it takes the\n\t\t\t// group's parent and position. Naming a different parent moves the whole\n\t\t\t// group there, as an update through any locale does, and appends it to\n\t\t\t// the siblings it lands among.\n\t\t\tif (source && (parentInput === undefined || source.parentId === parentId)) {\n\t\t\t\tparentId = source.parentId;\n\t\t\t\tsortOrder = source.sortOrder;\n\t\t\t} else if (source) {\n\t\t\t\tmovesGroup = true;\n\t\t\t}\n\t\t}\n\t\tsortOrder ??= await this.nextSortOrder(input.name, parentId);\n\n\t\tawait withTransaction(this.db, async (trx) => {\n\t\t\tawait trx\n\t\t\t\t.insertInto(\"taxonomies\")\n\t\t\t\t.values({\n\t\t\t\t\tid,\n\t\t\t\t\tname: input.name,\n\t\t\t\t\tslug: input.slug,\n\t\t\t\t\tlabel: input.label,\n\t\t\t\t\tparent_id: parentId,\n\t\t\t\t\tdata: input.data ? JSON.stringify(input.data) : null,\n\t\t\t\t\tsort_order: sortOrder,\n\t\t\t\t\t// When omitted, the DB DEFAULT 'en' is used — keeps behaviour\n\t\t\t\t\t// consistent with ContentRepository and lets higher layers\n\t\t\t\t\t// supply an explicit locale from request context.\n\t\t\t\t\t...(input.locale !== undefined ? { locale: input.locale } : {}),\n\t\t\t\t\ttranslation_group: translationGroup,\n\t\t\t\t})\n\t\t\t\t.execute();\n\t\t\tif (movesGroup) {\n\t\t\t\tawait trx\n\t\t\t\t\t.updateTable(\"taxonomies\")\n\t\t\t\t\t.set({ parent_id: parentId, sort_order: sortOrder })\n\t\t\t\t\t.where(\"translation_group\", \"=\", translationGroup)\n\t\t\t\t\t.execute();\n\t\t\t}\n\t\t});\n\n\t\tinvalidateTaxonomyObjectCache();\n\n\t\tconst taxonomy = await this.findById(id);\n\t\tif (!taxonomy) throw new Error(\"Failed to create taxonomy\");\n\t\treturn taxonomy;\n\t}\n\n\tasync findById(id: string): Promise<Taxonomy | null> {\n\t\tconst row = await this.db\n\t\t\t.selectFrom(\"taxonomies\")\n\t\t\t.selectAll()\n\t\t\t.where(\"id\", \"=\", id)\n\t\t\t.executeTakeFirst();\n\t\treturn row ? this.rowToTaxonomy(row) : null;\n\t}\n\n\t/** Resolve either a locale row id or a locale-agnostic translation group. */\n\tasync findByIdOrTranslationGroup(id: string): Promise<Taxonomy | null> {\n\t\tconst row = await this.db\n\t\t\t.selectFrom(\"taxonomies\")\n\t\t\t.selectAll()\n\t\t\t.where((eb) => eb.or([eb(\"id\", \"=\", id), eb(\"translation_group\", \"=\", id)]))\n\t\t\t.orderBy(\"locale\", \"asc\")\n\t\t\t.orderBy(\"id\", \"asc\")\n\t\t\t.executeTakeFirst();\n\t\treturn row ? this.rowToTaxonomy(row) : null;\n\t}\n\n\t/**\n\t * Find a term by (name, slug). When `locale` is provided, filter by it.\n\t * When omitted, returns the lowest-locale-code match (deterministic across\n\t * calls). Mirrors `ContentRepository.findBySlug`.\n\t */\n\tasync findBySlug(name: string, slug: string, locale?: string): Promise<Taxonomy | null> {\n\t\tlet query = this.db\n\t\t\t.selectFrom(\"taxonomies\")\n\t\t\t.selectAll()\n\t\t\t.where(\"name\", \"=\", name)\n\t\t\t.where(\"slug\", \"=\", slug);\n\t\tif (locale !== undefined) query = query.where(\"locale\", \"=\", locale);\n\t\tconst row = await query.orderBy(\"locale\", \"asc\").executeTakeFirst();\n\t\treturn row ? this.rowToTaxonomy(row) : null;\n\t}\n\n\t/** Generate a locale-scoped term slug, adding a numeric suffix when needed. */\n\tasync generateUniqueSlug(name: string, text: string, locale?: string): Promise<string> {\n\t\tconst baseSlug = slugify(text);\n\t\tlet query = this.db\n\t\t\t.selectFrom(\"taxonomies\")\n\t\t\t.select(\"slug\")\n\t\t\t.where(\"name\", \"=\", name)\n\t\t\t.where((eb) => eb.or([eb(\"slug\", \"=\", baseSlug), eb(\"slug\", \"like\", `${baseSlug}-%`)]));\n\t\tif (locale !== undefined) query = query.where(\"locale\", \"=\", locale);\n\t\tconst candidates = await query.execute();\n\t\tif (!candidates.some((candidate) => candidate.slug === baseSlug)) return baseSlug;\n\n\t\tlet maxSuffix = 0;\n\t\tconst prefix = `${baseSlug}-`;\n\t\tfor (const candidate of candidates) {\n\t\t\tif (!candidate.slug.startsWith(prefix)) continue;\n\t\t\tconst suffix = candidate.slug.slice(prefix.length);\n\t\t\tif (!NUMERIC_SUFFIX_PATTERN.test(suffix)) continue;\n\t\t\tmaxSuffix = Math.max(maxSuffix, Number.parseInt(suffix, 10));\n\t\t}\n\t\treturn `${baseSlug}-${maxSuffix + 1}`;\n\t}\n\n\t/**\n\t * Get all terms for a taxonomy (e.g., all categories).\n\t *\n\t * `sort_order` carries the manual order set from the admin; it is 0 for\n\t * terms nobody has reordered, so an untouched taxonomy still comes back\n\t * alphabetically. `id asc` is a stable tiebreaker for terms that share both\n\t * values. Without it the SQL ordering is implementation-defined when they match.\n\t */\n\tasync findByName(name: string, options: FindOptions = {}): Promise<Taxonomy[]> {\n\t\tlet query = this.db\n\t\t\t.selectFrom(\"taxonomies\")\n\t\t\t.selectAll()\n\t\t\t.where(\"name\", \"=\", name)\n\t\t\t.orderBy(\"sort_order\", \"asc\")\n\t\t\t.orderBy(\"label\", \"asc\")\n\t\t\t.orderBy(\"id\", \"asc\");\n\n\t\tif (options.locale !== undefined) query = query.where(\"locale\", \"=\", options.locale);\n\n\t\tif (options.parentId !== undefined) {\n\t\t\tif (options.parentId === null) {\n\t\t\t\tquery = query.where(\"parent_id\", \"is\", null);\n\t\t\t} else {\n\t\t\t\tquery = query.where(\"parent_id\", \"=\", options.parentId);\n\t\t\t}\n\t\t}\n\n\t\tconst rows = await query.execute();\n\t\treturn rows.map((row) => this.rowToTaxonomy(row));\n\t}\n\n\tasync findByNameResolved(\n\t\tname: string,\n\t\tlocale: string,\n\t\tdefaultLocale: string,\n\t): Promise<Taxonomy[]> {\n\t\tconst locales = [...new Set([locale, defaultLocale])];\n\t\tconst rows = await this.db\n\t\t\t.selectFrom(\"taxonomies\")\n\t\t\t.selectAll()\n\t\t\t.where(\"name\", \"=\", name)\n\t\t\t.where(\"locale\", \"in\", locales)\n\t\t\t.orderBy(\"sort_order\", \"asc\")\n\t\t\t.orderBy(\"label\", \"asc\")\n\t\t\t.orderBy(\"id\", \"asc\")\n\t\t\t.execute();\n\n\t\tconst selected = new Map<string, Taxonomy>();\n\t\tfor (const row of rows) {\n\t\t\tconst term = this.rowToTaxonomy(row);\n\t\t\tconst group = term.translationGroup ?? term.id;\n\t\t\tconst current = selected.get(group);\n\t\t\tif (!current || term.locale === locale) selected.set(group, term);\n\t\t}\n\t\treturn [...selected.values()].toSorted(\n\t\t\t(a, b) =>\n\t\t\t\ta.sortOrder - b.sortOrder || a.label.localeCompare(b.label) || a.id.localeCompare(b.id),\n\t\t);\n\t}\n\n\tasync findPageByName(name: string, options: TaxonomyPageOptions = {}): Promise<TaxonomyPage> {\n\t\tconst limit = Math.max(1, Math.min(options.limit ?? 50, 100));\n\t\tlet query = this.db.selectFrom(\"taxonomies\").selectAll().where(\"name\", \"=\", name);\n\n\t\tif (options.locale !== undefined) query = query.where(\"locale\", \"=\", options.locale);\n\n\t\tif (options.parentId !== undefined) {\n\t\t\tquery =\n\t\t\t\toptions.parentId === null\n\t\t\t\t\t? query.where(\"parent_id\", \"is\", null)\n\t\t\t\t\t: query.where(\"parent_id\", \"=\", options.parentId);\n\t\t}\n\n\t\tif (options.cursor) {\n\t\t\tconst cursor = options.cursor;\n\t\t\tquery = query.where((eb) =>\n\t\t\t\teb.or([\n\t\t\t\t\teb(\"sort_order\", \">\", cursor.sortOrder),\n\t\t\t\t\teb.and([eb(\"sort_order\", \"=\", cursor.sortOrder), eb(\"label\", \">\", cursor.label)]),\n\t\t\t\t\teb.and([\n\t\t\t\t\t\teb(\"sort_order\", \"=\", cursor.sortOrder),\n\t\t\t\t\t\teb(\"label\", \"=\", cursor.label),\n\t\t\t\t\t\teb(\"id\", \">\", cursor.id),\n\t\t\t\t\t]),\n\t\t\t\t]),\n\t\t\t);\n\t\t}\n\t\tquery = query.orderBy(\"sort_order\", \"asc\").orderBy(\"label\", \"asc\").orderBy(\"id\", \"asc\");\n\n\t\tconst rows = await query.limit(limit + 1).execute();\n\t\treturn {\n\t\t\titems: rows.slice(0, limit).map((row) => this.rowToTaxonomy(row)),\n\t\t\thasMore: rows.length > limit,\n\t\t};\n\t}\n\n\t/**\n\t * Children of a term. Accepts a term id OR a translation_group and resolves\n\t * to the group, since `parent_id` stores the parent's translation_group.\n\t * Pass `locale` to scope to one locale's tree (children share the parent's\n\t * group across locales); omit it to find children in every locale (used to\n\t * block deletes that would orphan a sibling translation's subtree).\n\t */\n\tasync findChildren(parentIdOrGroup: string, locale?: string): Promise<Taxonomy[]> {\n\t\tconst group = await this.resolveTranslationGroup(parentIdOrGroup);\n\t\tif (!group) return [];\n\n\t\tlet query = this.db\n\t\t\t.selectFrom(\"taxonomies\")\n\t\t\t.selectAll()\n\t\t\t.where(\"parent_id\", \"=\", group)\n\t\t\t.orderBy(\"sort_order\", \"asc\")\n\t\t\t.orderBy(\"label\", \"asc\")\n\t\t\t.orderBy(\"id\", \"asc\");\n\t\tif (locale !== undefined) query = query.where(\"locale\", \"=\", locale);\n\n\t\tconst rows = await query.execute();\n\t\treturn rows.map((row) => this.rowToTaxonomy(row));\n\t}\n\n\t/**\n\t * Every translation sibling of a term (including itself), identified by\n\t * their shared `translation_group`.\n\t */\n\tasync findTranslations(translationGroup: string): Promise<Taxonomy[]> {\n\t\tconst rows = await this.db\n\t\t\t.selectFrom(\"taxonomies\")\n\t\t\t.selectAll()\n\t\t\t.where(\"translation_group\", \"=\", translationGroup)\n\t\t\t.orderBy(\"locale\", \"asc\")\n\t\t\t.execute();\n\t\treturn rows.map((row) => this.rowToTaxonomy(row));\n\t}\n\n\tasync update(id: string, input: UpdateTaxonomyInput): Promise<Taxonomy | null> {\n\t\tconst existing = await this.findById(id);\n\t\tif (!existing) return null;\n\n\t\t// Per-row display fields. `parent_id` and `sort_order` are not here: both\n\t\t// belong to the translation_group and are written across it below.\n\t\tconst updates: Record<string, unknown> = {};\n\t\tif (input.slug !== undefined) updates.slug = input.slug;\n\t\tif (input.label !== undefined) updates.label = input.label;\n\t\tif (input.data !== undefined) updates.data = JSON.stringify(input.data);\n\n\t\tconst group: { parent_id?: string | null; sort_order?: number } = {};\n\t\tif (input.parentId !== undefined) {\n\t\t\t// Defense in depth: empty-string parentId means null (no parent).\n\t\t\t// Otherwise persist the parent's translation_group (locale-agnostic),\n\t\t\t// matching create() — see the note there.\n\t\t\tconst parentId =\n\t\t\t\tinput.parentId === \"\" || input.parentId === null\n\t\t\t\t\t? null\n\t\t\t\t\t: await this.resolveParentRef(input.parentId);\n\n\t\t\tif (parentId !== existing.parentId) {\n\t\t\t\tgroup.parent_id = parentId;\n\t\t\t\t// A position only means anything within one sibling group, so a term\n\t\t\t\t// that changes parent is appended to the group it lands in.\n\t\t\t\tgroup.sort_order = await this.nextSortOrder(existing.name, parentId);\n\t\t\t} else if (\n\t\t\t\tawait this.groupHasOtherParent(existing.translationGroup ?? existing.id, parentId)\n\t\t\t) {\n\t\t\t\t// Other locales of the term sit elsewhere; bring them to this row's\n\t\t\t\t// parent and position.\n\t\t\t\tgroup.parent_id = parentId;\n\t\t\t\tgroup.sort_order = existing.sortOrder;\n\t\t\t}\n\t\t}\n\n\t\tconst hasRowUpdates = Object.keys(updates).length > 0;\n\t\tconst hasGroupUpdates = Object.keys(group).length > 0;\n\t\tif (hasRowUpdates || hasGroupUpdates) {\n\t\t\tawait withTransaction(this.db, async (trx) => {\n\t\t\t\tif (hasRowUpdates) {\n\t\t\t\t\tawait trx.updateTable(\"taxonomies\").set(updates).where(\"id\", \"=\", id).execute();\n\t\t\t\t}\n\t\t\t\tif (hasGroupUpdates) {\n\t\t\t\t\tawait trx\n\t\t\t\t\t\t.updateTable(\"taxonomies\")\n\t\t\t\t\t\t.set(group)\n\t\t\t\t\t\t.where(\"translation_group\", \"=\", existing.translationGroup ?? existing.id)\n\t\t\t\t\t\t.execute();\n\t\t\t\t}\n\t\t\t});\n\t\t\tinvalidateTaxonomyObjectCache();\n\t\t}\n\n\t\treturn this.findById(id);\n\t}\n\n\t/**\n\t * Move `groups` (translation_groups, in the desired order) into the positions\n\t * those same groups already occupy, leaving every other member of the sibling\n\t * group where it is.\n\t *\n\t * `groups` may be a subset: a locale renders only the terms translated into\n\t * it, so an admin in `fr` often cannot name every member. A group left out\n\t * keeps its place, which is also what makes a stale list harmless.\n\t *\n\t * `siblings` is every member of the group with the position it holds, in a\n\t * listing's order — tied positions are resolved by that order, so pass it as\n\t * read. Groups already at their target are skipped, so one swap rewrites two\n\t * groups rather than the whole list.\n\t */\n\tasync reorder(groups: string[], siblings: readonly SiblingPosition[]): Promise<void> {\n\t\tconst current = new Map(siblings.map(({ group, position }) => [group, position]));\n\n\t\tconst listed: string[] = [];\n\t\tconst occupied: number[] = [];\n\t\tfor (const group of groups) {\n\t\t\tconst position = current.get(group);\n\t\t\tif (position === undefined) continue;\n\t\t\tlisted.push(group);\n\t\t\toccupied.push(position);\n\t\t}\n\t\tif (listed.length === 0) return;\n\n\t\t// Tied positions have no distinct order to permute into, so the requested\n\t\t// one would be dropped without a word. Renumbering is the only way to\n\t\t// honour it, and it repairs the tie on the way through.\n\t\tconst target =\n\t\t\tnew Set(occupied).size === occupied.length\n\t\t\t\t? permuteWithinSlots(listed, occupied)\n\t\t\t\t: renumberSiblings(listed, siblings);\n\n\t\tconst changed = [...target].filter(([group, position]) => current.get(group) !== position);\n\t\tif (changed.length === 0) return;\n\n\t\tawait this.applyPositions(changed);\n\n\t\tinvalidateTaxonomyObjectCache();\n\t}\n\n\t/**\n\t * Write one position per translation_group, GROUPS_PER_UPDATE at a time so\n\t * each statement stays inside D1's parameter ceiling.\n\t *\n\t * D1 has no transactions — `withTransaction` runs its callback bare there —\n\t * so a chunk is the unit that can't tear. A reorder spanning several chunks\n\t * can, and leaves ties, which the next reorder renumbers away.\n\t */\n\tprivate async applyPositions(positions: readonly (readonly [string, number])[]): Promise<void> {\n\t\tfor (let index = 0; index < positions.length; index += GROUPS_PER_UPDATE) {\n\t\t\tconst chunk = positions.slice(index, index + GROUPS_PER_UPDATE);\n\t\t\t// The CAST types the bound position. Postgres resolves a CASE whose THEN\n\t\t\t// arms are all untyped parameters to text, then refuses to assign text to\n\t\t\t// an integer column.\n\t\t\tconst arms = sql.join(\n\t\t\t\tchunk.map(([group, position]) => sql`WHEN ${group} THEN CAST(${position} AS INTEGER)`),\n\t\t\t\tsql` `,\n\t\t\t);\n\t\t\tconst keys = sql.join(chunk.map(([group]) => sql`${group}`));\n\t\t\tawait sql`\n\t\t\t\tUPDATE taxonomies\n\t\t\t\tSET sort_order = CASE translation_group ${arms} END\n\t\t\t\tWHERE translation_group IN (${keys})\n\t\t\t`.execute(this.db);\n\t\t}\n\t}\n\n\t/**\n\t * Position for a term joining a sibling group: one past the last member, or\n\t * 0 when the group is empty.\n\t *\n\t * Bounds are taken across every locale because a position belongs to the\n\t * translation_group, not to a row — a term translated into only one locale\n\t * still occupies its slot for all of them.\n\t */\n\tprivate async nextSortOrder(name: string, parentId: string | null): Promise<number> {\n\t\tlet query = this.db\n\t\t\t.selectFrom(\"taxonomies\")\n\t\t\t.select((eb) => eb.fn.max(\"sort_order\").as(\"max\"))\n\t\t\t.where(\"name\", \"=\", name);\n\t\tquery =\n\t\t\tparentId === null\n\t\t\t\t? query.where(\"parent_id\", \"is\", null)\n\t\t\t\t: query.where(\"parent_id\", \"=\", parentId);\n\n\t\tconst bounds = await query.executeTakeFirst();\n\t\t// Null only when the group is empty.\n\t\tif (!bounds || bounds.max === null) return 0;\n\t\treturn bounds.max + 1;\n\t}\n\n\t/** Whether any row of `translationGroup` has a parent other than `parentId`. */\n\tprivate async groupHasOtherParent(\n\t\ttranslationGroup: string,\n\t\tparentId: string | null,\n\t): Promise<boolean> {\n\t\tconst row = await this.db\n\t\t\t.selectFrom(\"taxonomies\")\n\t\t\t.select(\"id\")\n\t\t\t.where(\"translation_group\", \"=\", translationGroup)\n\t\t\t.where((eb) =>\n\t\t\t\tparentId === null\n\t\t\t\t\t? eb(\"parent_id\", \"is not\", null)\n\t\t\t\t\t: eb.or([eb(\"parent_id\", \"is\", null), eb(\"parent_id\", \"!=\", parentId)]),\n\t\t\t)\n\t\t\t.executeTakeFirst();\n\t\treturn row !== undefined;\n\t}\n\n\tasync delete(id: string): Promise<boolean> {\n\t\tconst term = await this.findById(id);\n\t\tif (!term) return false;\n\n\t\t// When deleting the last translation of a group the pivot rows that\n\t\t// reference that translation_group become orphaned — purge them.\n\t\tif (term.translationGroup) {\n\t\t\tconst siblings = await this.db\n\t\t\t\t.selectFrom(\"taxonomies\")\n\t\t\t\t.select(\"id\")\n\t\t\t\t.where(\"translation_group\", \"=\", term.translationGroup)\n\t\t\t\t.where(\"id\", \"!=\", id)\n\t\t\t\t.execute();\n\t\t\tif (siblings.length === 0) {\n\t\t\t\tawait this.db\n\t\t\t\t\t.deleteFrom(\"content_taxonomies\")\n\t\t\t\t\t.where(\"taxonomy_id\", \"=\", term.translationGroup)\n\t\t\t\t\t.execute();\n\t\t\t}\n\t\t}\n\n\t\tconst result = await this.db.deleteFrom(\"taxonomies\").where(\"id\", \"=\", id).executeTakeFirst();\n\t\tinvalidateTaxonomyObjectCache();\n\t\treturn (result.numDeletedRows ?? 0n) > 0n;\n\t}\n\n\t// --- Content-Taxonomy Junction (both ids store translation_groups) ---\n\n\tasync attachToEntry(collection: string, entryId: string, taxonomyId: string): Promise<void> {\n\t\tconst taxonomyGroup = await this.resolveTranslationGroup(taxonomyId);\n\t\tif (!taxonomyGroup) return;\n\t\tawait this.attachGroupsToEntry(collection, entryId, [taxonomyGroup]);\n\t}\n\n\t/**\n\t * Attach already-resolved term translation groups and return the number of\n\t * assignments that did not already exist.\n\t */\n\tasync attachGroupsToEntry(\n\t\tcollection: string,\n\t\tentryId: string,\n\t\ttaxonomyGroups: string[],\n\t): Promise<number> {\n\t\tconst uniqueGroups = [...new Set(taxonomyGroups)];\n\t\tif (uniqueGroups.length === 0) return 0;\n\t\tconst entryGroup = await this.resolveEntryTranslationGroup(collection, entryId);\n\t\tif (!entryGroup) return 0;\n\n\t\tconst inserted = await this.insertAssignments(collection, entryGroup, uniqueGroups);\n\t\tif (inserted > 0) invalidateTaxonomyObjectCache();\n\t\treturn inserted;\n\t}\n\n\tprivate async insertAssignments(\n\t\tcollection: string,\n\t\tentryGroup: string,\n\t\ttaxonomyGroups: string[],\n\t): Promise<number> {\n\t\tlet inserted = 0;\n\t\ttry {\n\t\t\tfor (const batch of chunks(taxonomyGroups, ASSIGNMENTS_PER_INSERT)) {\n\t\t\t\t// oxlint-disable-next-line no-await-in-loop -- one statement per D1-safe batch\n\t\t\t\tconst result = await this.db\n\t\t\t\t\t.insertInto(\"content_taxonomies\")\n\t\t\t\t\t.values(batch.map((taxonomy_id) => ({ collection, entry_id: entryGroup, taxonomy_id })))\n\t\t\t\t\t.onConflict((oc) => oc.doNothing())\n\t\t\t\t\t.executeTakeFirst();\n\t\t\t\tinserted += Number(result.numInsertedOrUpdatedRows ?? 0n);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\t// Earlier batches are already written.\n\t\t\tif (inserted > 0) invalidateTaxonomyObjectCache();\n\t\t\tthrow error;\n\t\t}\n\t\treturn inserted;\n\t}\n\n\tprivate async deleteAssignments(\n\t\tcollection: string,\n\t\tentryGroup: string,\n\t\ttaxonomyGroups: string[],\n\t): Promise<number> {\n\t\tlet removed = 0;\n\t\ttry {\n\t\t\tfor (const batch of chunks(taxonomyGroups, SQL_BATCH_SIZE)) {\n\t\t\t\t// oxlint-disable-next-line no-await-in-loop -- one statement per D1-safe batch\n\t\t\t\tconst result = await this.db\n\t\t\t\t\t.deleteFrom(\"content_taxonomies\")\n\t\t\t\t\t.where(\"collection\", \"=\", collection)\n\t\t\t\t\t.where(\"entry_id\", \"=\", entryGroup)\n\t\t\t\t\t.where(\"taxonomy_id\", \"in\", batch)\n\t\t\t\t\t.executeTakeFirst();\n\t\t\t\tremoved += Number(result.numDeletedRows ?? 0n);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\t// Earlier batches are already deleted.\n\t\t\tif (removed > 0) invalidateTaxonomyObjectCache();\n\t\t\tthrow error;\n\t\t}\n\t\treturn removed;\n\t}\n\n\tasync detachFromEntry(collection: string, entryId: string, taxonomyId: string): Promise<void> {\n\t\tconst [entryGroup, taxonomyGroup] = await Promise.all([\n\t\t\tthis.resolveEntryTranslationGroup(collection, entryId),\n\t\t\tthis.resolveTranslationGroup(taxonomyId),\n\t\t]);\n\t\tif (!entryGroup || !taxonomyGroup) return;\n\n\t\tawait this.db\n\t\t\t.deleteFrom(\"content_taxonomies\")\n\t\t\t.where(\"collection\", \"=\", collection)\n\t\t\t.where(\"entry_id\", \"=\", entryGroup)\n\t\t\t.where(\"taxonomy_id\", \"=\", taxonomyGroup)\n\t\t\t.execute();\n\t\tinvalidateTaxonomyObjectCache();\n\t}\n\n\t/** Remove already-resolved term groups without replacing concurrent assignments. */\n\tasync detachGroupsFromEntry(\n\t\tcollection: string,\n\t\tentryId: string,\n\t\ttaxonomyGroups: string[],\n\t): Promise<number> {\n\t\tconst uniqueGroups = [...new Set(taxonomyGroups)];\n\t\tif (uniqueGroups.length === 0) return 0;\n\t\tconst entryGroup = await this.resolveEntryTranslationGroup(collection, entryId);\n\t\tif (!entryGroup) return 0;\n\n\t\tconst removed = await this.deleteAssignments(collection, entryGroup, uniqueGroups);\n\t\tif (removed > 0) invalidateTaxonomyObjectCache();\n\t\treturn removed;\n\t}\n\n\t/**\n\t * Taxonomy terms assigned to a content entry, resolved into a specific locale.\n\t * Terms whose translation_group lacks a row in the requested locale are\n\t * omitted — callers wanting fallback behaviour apply it themselves.\n\t */\n\tasync getTermsForEntry(\n\t\tcollection: string,\n\t\tentryId: string,\n\t\ttaxonomyName?: string,\n\t\tlocale?: string,\n\t): Promise<Taxonomy[]> {\n\t\tconst entryGroup = await this.resolveEntryTranslationGroup(collection, entryId);\n\t\tif (!entryGroup) return [];\n\n\t\tlet query = this.db\n\t\t\t.selectFrom(\"content_taxonomies\")\n\t\t\t.innerJoin(\"taxonomies\", \"taxonomies.translation_group\", \"content_taxonomies.taxonomy_id\")\n\t\t\t.selectAll(\"taxonomies\")\n\t\t\t.where(\"content_taxonomies.collection\", \"=\", collection)\n\t\t\t.where(\"content_taxonomies.entry_id\", \"=\", entryGroup);\n\n\t\tif (taxonomyName) query = query.where(\"taxonomies.name\", \"=\", taxonomyName);\n\t\tif (locale !== undefined) query = query.where(\"taxonomies.locale\", \"=\", locale);\n\n\t\tconst rows = await query.orderBy(\"taxonomies.locale\", \"asc\").execute();\n\t\treturn rows.map((row) => this.rowToTaxonomy(row));\n\t}\n\n\tasync getTermAssignmentsForEntry(\n\t\tcollection: string,\n\t\tentryId: string,\n\t\ttaxonomyName: string,\n\t\tlocale: string,\n\t\tdefaultLocale: string,\n\t): Promise<TaxonomyAssignmentResolution[]> {\n\t\tconst entryGroup = await this.resolveEntryTranslationGroup(collection, entryId);\n\t\tif (!entryGroup) return [];\n\n\t\tconst rows = await this.db\n\t\t\t.selectFrom(\"content_taxonomies\")\n\t\t\t.innerJoin(\"taxonomies\", \"taxonomies.translation_group\", \"content_taxonomies.taxonomy_id\")\n\t\t\t.selectAll(\"taxonomies\")\n\t\t\t.select(\"content_taxonomies.taxonomy_id as assignment_group\")\n\t\t\t.where(\"content_taxonomies.collection\", \"=\", collection)\n\t\t\t.where(\"content_taxonomies.entry_id\", \"=\", entryGroup)\n\t\t\t.where(\"taxonomies.name\", \"=\", taxonomyName)\n\t\t\t.orderBy(\"content_taxonomies.taxonomy_id\", \"asc\")\n\t\t\t.orderBy(\"taxonomies.locale\", \"asc\")\n\t\t\t.execute();\n\n\t\tconst byGroup = new Map<string, Taxonomy[]>();\n\t\tfor (const row of rows) {\n\t\t\tconst variants = byGroup.get(row.assignment_group) ?? [];\n\t\t\tvariants.push(this.rowToTaxonomy(row));\n\t\t\tbyGroup.set(row.assignment_group, variants);\n\t\t}\n\n\t\treturn Array.from(byGroup, ([translationGroup, variants]) => {\n\t\t\tconst term =\n\t\t\t\tvariants.find((variant) => variant.locale === locale) ??\n\t\t\t\tvariants.find((variant) => variant.locale === defaultLocale) ??\n\t\t\t\tnull;\n\t\t\treturn {\n\t\t\t\ttranslationGroup,\n\t\t\t\tterm,\n\t\t\t\tavailableLocales: variants.map((variant) => variant.locale),\n\t\t\t\ttranslations: variants.map((variant) => ({\n\t\t\t\t\tid: variant.id,\n\t\t\t\t\tslug: variant.slug,\n\t\t\t\t\tlocale: variant.locale,\n\t\t\t\t})),\n\t\t\t};\n\t\t});\n\t}\n\n\t/**\n\t * Replace all assignments of a given taxonomy for one content entry.\n\t * Term ids OR translation_groups are accepted and normalised to groups.\n\t */\n\tasync setTermsForEntry(\n\t\tcollection: string,\n\t\tentryId: string,\n\t\ttaxonomyName: string,\n\t\ttermIds: string[],\n\t): Promise<void> {\n\t\tconst entryGroup = await this.resolveEntryTranslationGroup(collection, entryId);\n\t\tif (!entryGroup) return;\n\n\t\tconst groups: string[] = [];\n\t\tfor (const id of termIds) {\n\t\t\tconst group = await this.resolveTranslationGroup(id);\n\t\t\tif (group) groups.push(group);\n\t\t}\n\t\tconst newGroups = new Set(groups);\n\n\t\tconst current = await this.db\n\t\t\t.selectFrom(\"content_taxonomies\")\n\t\t\t.innerJoin(\"taxonomies\", \"taxonomies.translation_group\", \"content_taxonomies.taxonomy_id\")\n\t\t\t.select([\"content_taxonomies.taxonomy_id as group\"])\n\t\t\t.distinct()\n\t\t\t.where(\"content_taxonomies.collection\", \"=\", collection)\n\t\t\t.where(\"content_taxonomies.entry_id\", \"=\", entryGroup)\n\t\t\t.where(\"taxonomies.name\", \"=\", taxonomyName)\n\t\t\t.execute();\n\t\tconst currentGroups = new Set(current.map((r) => r.group));\n\n\t\tconst toRemove = [...currentGroups].filter((g) => !newGroups.has(g));\n\t\tconst toAdd = [...newGroups].filter((g) => !currentGroups.has(g));\n\t\ttry {\n\t\t\tif (toRemove.length > 0) await this.deleteAssignments(collection, entryGroup, toRemove);\n\t\t\tif (toAdd.length > 0) await this.insertAssignments(collection, entryGroup, toAdd);\n\t\t} finally {\n\t\t\tif (toRemove.length > 0 || toAdd.length > 0) invalidateTaxonomyObjectCache();\n\t\t}\n\t}\n\n\tasync clearEntryTerms(collection: string, entryId: string): Promise<number> {\n\t\tconst entryGroup = await this.resolveEntryTranslationGroup(collection, entryId);\n\t\tif (!entryGroup) return 0;\n\t\treturn this.clearEntryGroupTerms(collection, entryGroup);\n\t}\n\n\t/**\n\t * Remove every term assignment held by an entry translation group. Takes the\n\t * group rather than an entry id, so it still works after the group's last\n\t * row has been deleted.\n\t */\n\tasync clearEntryGroupTerms(collection: string, entryGroup: string): Promise<number> {\n\t\tconst result = await this.db\n\t\t\t.deleteFrom(\"content_taxonomies\")\n\t\t\t.where(\"collection\", \"=\", collection)\n\t\t\t.where(\"entry_id\", \"=\", entryGroup)\n\t\t\t.executeTakeFirst();\n\t\tconst removed = Number(result.numDeletedRows ?? 0);\n\t\tif (removed > 0) invalidateTaxonomyObjectCache();\n\t\treturn removed;\n\t}\n\n\tprivate async resolveEntryTranslationGroup(\n\t\tcollection: string,\n\t\tentryIdOrGroup: string,\n\t): Promise<string | null> {\n\t\tvalidateIdentifier(collection, \"collection type\");\n\t\tconst tableName = `ec_${collection}`;\n\t\tconst result = await sql<{ translation_group: string }>`\n\t\t\tSELECT translation_group\n\t\t\tFROM ${sql.ref(tableName)}\n\t\t\tWHERE id = ${entryIdOrGroup} OR translation_group = ${entryIdOrGroup}\n\t\t\tLIMIT 1\n\t\t`.execute(this.db);\n\t\treturn result.rows[0]?.translation_group ?? null;\n\t}\n\n\t/**\n\t * Count content entries that use any translation of this term. Accepts\n\t * either a term id or a translation_group — we normalise to the group.\n\t *\n\t * Counts raw pivot rows regardless of the entry's status or deletion —\n\t * drafts and trashed entries are included. User-facing counts (admin term\n\t * list/get, public widget and term pages) use `fetchVisibleTermCounts`\n\t * from `taxonomies/term-counts.ts` instead, which counts only publicly\n\t * visible entries.\n\t */\n\tasync countEntriesWithTerm(termIdOrGroup: string): Promise<number> {\n\t\tconst group = await this.resolveTranslationGroup(termIdOrGroup);\n\t\tif (!group) return 0;\n\n\t\tconst result = await this.db\n\t\t\t.selectFrom(\"content_taxonomies\")\n\t\t\t.select((eb) => eb.fn.count(\"entry_id\").as(\"count\"))\n\t\t\t.where(\"taxonomy_id\", \"=\", group)\n\t\t\t.executeTakeFirst();\n\t\treturn Number(result?.count ?? 0);\n\t}\n\n\t/**\n\t * Resolve a parent reference (a row id or a translation_group) to the value\n\t * persisted in `parent_id`: the parent's translation_group, which is\n\t * locale-agnostic so the child stays nested in every locale. A\n\t * translation_group normally equals its anchor row's id, which satisfies the\n\t * self-FK on `parent_id`. If that anchor row is missing (a translation whose\n\t * anchor was deleted), fall back to the id we were given so we never write a\n\t * dangling FK value.\n\t */\n\tprivate async resolveParentRef(idOrGroup: string): Promise<string> {\n\t\tconst group = await this.resolveTranslationGroup(idOrGroup);\n\t\tif (!group) return idOrGroup;\n\t\tconst anchor = await this.db\n\t\t\t.selectFrom(\"taxonomies\")\n\t\t\t.select(\"id\")\n\t\t\t.where(\"id\", \"=\", group)\n\t\t\t.executeTakeFirst();\n\t\treturn anchor ? group : idOrGroup;\n\t}\n\n\tprivate async resolveTranslationGroup(idOrGroup: string): Promise<string | null> {\n\t\tconst row = await this.db\n\t\t\t.selectFrom(\"taxonomies\")\n\t\t\t.select([\"translation_group\"])\n\t\t\t.where((eb) => eb.or([eb(\"id\", \"=\", idOrGroup), eb(\"translation_group\", \"=\", idOrGroup)]))\n\t\t\t.executeTakeFirst();\n\t\treturn row?.translation_group ?? null;\n\t}\n\n\t/**\n\t * Batch count entries for multiple taxonomy translation_groups.\n\t * Chunks the query at SQL_BATCH_SIZE to stay below D1's bind-parameter limit.\n\t * Returns a Map from translation_group to count.\n\t *\n\t * Pass translation_groups (not term ids) — `content_taxonomies.taxonomy_id`\n\t * stores the translation_group so a single assignment spans every locale.\n\t *\n\t * Like `countEntriesWithTerm`, this counts raw pivot rows regardless of\n\t * status/deletion; user-facing counts go through `fetchVisibleTermCounts`.\n\t */\n\tasync countEntriesForTerms(translationGroups: string[]): Promise<Map<string, number>> {\n\t\tif (translationGroups.length === 0) return new Map();\n\n\t\tconst counts = new Map<string, number>();\n\t\tfor (const chunk of chunks(translationGroups, SQL_BATCH_SIZE)) {\n\t\t\tconst rows = await this.db\n\t\t\t\t.selectFrom(\"content_taxonomies\")\n\t\t\t\t.select([\"taxonomy_id\", (eb) => eb.fn.count(\"entry_id\").as(\"count\")])\n\t\t\t\t.where(\"taxonomy_id\", \"in\", chunk)\n\t\t\t\t.groupBy(\"taxonomy_id\")\n\t\t\t\t.execute();\n\n\t\t\tfor (const row of rows) {\n\t\t\t\tcounts.set(row.taxonomy_id, Number(row.count || 0));\n\t\t\t}\n\t\t}\n\t\treturn counts;\n\t}\n\n\tprivate rowToTaxonomy(row: Selectable<TaxonomyTable>): Taxonomy {\n\t\treturn {\n\t\t\tid: row.id,\n\t\t\tname: row.name,\n\t\t\tslug: row.slug,\n\t\t\tlabel: row.label,\n\t\t\tparentId: row.parent_id,\n\t\t\tdata: row.data ? JSON.parse(row.data) : null,\n\t\t\tlocale: row.locale,\n\t\t\ttranslationGroup: row.translation_group,\n\t\t\tsortOrder: row.sort_order,\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAqBA,MAAM,oBAAoB;;AAE1B,MAAM,yBAAyB;AAC/B,MAAM,yBAAyB;;AAG/B,SAAS,mBACR,QACA,UACsB;CACtB,MAAM,QAAQ,SAAS,UAAU,GAAG,MAAM,IAAI,EAAE;CAChD,MAAM,yBAAS,IAAI,KAAqB;AACxC,QAAO,SAAS,OAAO,UAAU;EAChC,MAAM,WAAW,MAAM;AACvB,MAAI,aAAa,OAAW,QAAO,IAAI,OAAO,SAAS;GACtD;AACF,QAAO;;;;;;;;;;;;AAaR,SAAS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port.ts"],"sourcesContent":["/**\n * Transport layer for the EmDash client.\n *\n * Implements a composable interceptor pipeline that modifies requests\n * and responses. The client calls `transport.fetch(request)` — everything\n * else (auth, CSRF, retry) is handled by interceptors.\n */\n\n// Regex patterns for transport utilities\nconst COOKIE_NAME_VALUE_PATTERN = /^([^;]+)/;\n\n/**\n * An interceptor can modify the request, call next(), inspect\n * the response, and optionally retry.\n */\nexport type Interceptor = (\n\trequest: Request,\n\tnext: (request: Request) => Promise<Response>,\n) => Promise<Response>;\n\nexport interface TransportOptions {\n\tinterceptors?: Interceptor[];\n}\n\nfunction baseFetch(request: Request): Promise<Response> {\n\treturn globalThis.fetch(request);\n}\n\n/**\n * Creates a fetch function that runs requests through an interceptor pipeline.\n */\nexport function createTransport(options: TransportOptions = {}): {\n\tfetch: (request: Request) => Promise<Response>;\n} {\n\tconst interceptors = options.interceptors ?? [];\n\n\t// Build the chain once — interceptors don't change after construction\n\tlet chain: (request: Request) => Promise<Response> = baseFetch;\n\tfor (let i = interceptors.length - 1; i >= 0; i--) {\n\t\tconst interceptor = interceptors[i];\n\t\tconst next = chain;\n\t\tchain = (req) => interceptor(req, next);\n\t}\n\n\treturn { fetch: chain };\n}\n\n// ---------------------------------------------------------------------------\n// Built-in interceptors\n// ---------------------------------------------------------------------------\n\n/**\n * Adds X-EmDash-Request: 1 and Origin headers to mutation requests\n * (POST, PUT, DELETE). The custom header satisfies EmDash's CSRF check;\n * the Origin header satisfies Astro's built-in origin verification which\n * rejects server-side POST requests that lack a matching Origin.\n */\nexport function csrfInterceptor(): Interceptor {\n\tconst MUTATION_METHODS = new Set([\"POST\", \"PUT\", \"DELETE\", \"PATCH\"]);\n\n\treturn (request, next) => {\n\t\tif (MUTATION_METHODS.has(request.method)) {\n\t\t\tconst headers = new Headers(request.headers);\n\t\t\theaders.set(\"X-EmDash-Request\", \"1\");\n\t\t\tif (!headers.has(\"Origin\")) {\n\t\t\t\tconst url = new URL(request.url);\n\t\t\t\theaders.set(\"Origin\", url.origin);\n\t\t\t}\n\t\t\treturn next(new Request(request, { headers }));\n\t\t}\n\t\treturn next(request);\n\t};\n}\n\n/**\n * Adds Authorization: Bearer header from a static token.\n */\nexport function tokenInterceptor(token: string): Interceptor {\n\treturn (request, next) => {\n\t\tconst headers = new Headers(request.headers);\n\t\theaders.set(\"Authorization\", `Bearer ${token}`);\n\t\treturn next(new Request(request, { headers }));\n\t};\n}\n\n/**\n * Dev bypass interceptor. Calls the dev-bypass endpoint on first request\n * to establish a session, then forwards the session cookie on subsequent\n * requests.\n */\nexport function devBypassInterceptor(baseUrl: string): Interceptor {\n\tlet sessionCookie: string | null = null;\n\tlet initializing: Promise<void> | null = null;\n\n\tasync function init(): Promise<void> {\n\t\tconst bypassUrl = new URL(\"/_emdash/api/auth/dev-bypass\", baseUrl);\n\t\tconst res = await globalThis.fetch(bypassUrl, { redirect: \"manual\" });\n\n\t\t// Extract session cookie from Set-Cookie header\n\t\tconst setCookie = res.headers.get(\"set-cookie\");\n\t\tif (setCookie) {\n\t\t\t// Extract just the cookie name=value part\n\t\t\tconst match = setCookie.match(COOKIE_NAME_VALUE_PATTERN);\n\t\t\tif (match) {\n\t\t\t\tsessionCookie = match[1]!;\n\t\t\t}\n\t\t}\n\n\t\t// Consume the response body\n\t\tif (res.body) {\n\t\t\tawait res.text().catch(() => {});\n\t\t}\n\t}\n\n\treturn async (request, next) => {\n\t\t// Ensure we've initialized (only once, even with concurrent requests)\n\t\tif (!sessionCookie) {\n\t\t\tif (!initializing) {\n\t\t\t\tinitializing = init();\n\t\t\t}\n\t\t\tawait initializing;\n\t\t}\n\n\t\tif (sessionCookie) {\n\t\t\tconst headers = new Headers(request.headers);\n\t\t\tconst existing = headers.get(\"cookie\");\n\t\t\theaders.set(\"cookie\", existing ? `${existing}; ${sessionCookie}` : sessionCookie);\n\t\t\treturn next(new Request(request, { headers }));\n\t\t}\n\n\t\treturn next(request);\n\t};\n}\n\n/**\n * Auto-refreshes expired OAuth tokens on 401 responses.\n * Requires a refresh token and the token endpoint URL.\n */\nexport function refreshInterceptor(options: {\n\trefreshToken: string;\n\ttokenEndpoint: string;\n\tonTokenRefreshed?: (accessToken: string, refreshToken: string, expiresAt: string) => void;\n}): Interceptor {\n\tlet refreshing: Promise<string | null> | null = null;\n\n\tasync function refresh(): Promise<string | null> {\n\t\tconst res = await globalThis.fetch(options.tokenEndpoint, {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: { \"Content-Type\": \"application/json\" },\n\t\t\tbody: JSON.stringify({\n\t\t\t\tgrant_type: \"refresh_token\",\n\t\t\t\trefresh_token: options.refreshToken,\n\t\t\t}),\n\t\t});\n\n\t\tif (!res.ok) return null;\n\n\t\tinterface TokenFields {\n\t\t\taccess_token: string;\n\t\t\trefresh_token?: string;\n\t\t\texpires_in?: number;\n\t\t}\n\n\t\tconst json = (await res.json()) as Record<string, unknown>;\n\n\t\t// The token endpoint wraps the response in { success, data: ... } via apiSuccess.\n\t\t// Handle both wrapped and bare shapes for robustness.\n\t\tconst tokenData: TokenFields =\n\t\t\tjson.data && typeof json.data === \"object\" && \"access_token\" in json.data\n\t\t\t\t? (json.data as TokenFields)\n\t\t\t\t: (json as unknown as TokenFields);\n\n\t\tconst expiresAt = tokenData.expires_in\n\t\t\t? new Date(Date.now() + tokenData.expires_in * 1000).toISOString()\n\t\t\t: new Date(Date.now() + 3600_000).toISOString();\n\n\t\tif (options.onTokenRefreshed) {\n\t\t\toptions.onTokenRefreshed(\n\t\t\t\ttokenData.access_token,\n\t\t\t\ttokenData.refresh_token ?? options.refreshToken,\n\t\t\t\texpiresAt,\n\t\t\t);\n\t\t}\n\n\t\treturn tokenData.access_token;\n\t}\n\n\treturn async (request, next) => {\n\t\t// A request body can only be read once; clone before sending so the\n\t\t// 401 retry has an unconsumed request to rebuild from.\n\t\tconst retryTemplate = request.body ? request.clone() : request;\n\n\t\tconst response = await next(request);\n\n\t\tif (response.status === 401) {\n\t\t\t// Try to refresh\n\t\t\tif (!refreshing) {\n\t\t\t\trefreshing = refresh().finally(() => {\n\t\t\t\t\trefreshing = null;\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst newToken = await refreshing;\n\t\t\tif (newToken) {\n\t\t\t\t// Retry with new token\n\t\t\t\tconst headers = new Headers(retryTemplate.headers);\n\t\t\t\theaders.set(\"Authorization\", `Bearer ${newToken}`);\n\t\t\t\treturn next(new Request(retryTemplate, { headers }));\n\t\t\t}\n\t\t}\n\n\t\treturn response;\n\t};\n}\n"],"mappings":";;;;;;;;AASA,MAAM,4BAA4B;AAelC,SAAS,UAAU,SAAqC;AACvD,QAAO,WAAW,MAAM,QAAQ;;;;;AAMjC,SAAgB,gBAAgB,UAA4B,EAAE,EAE5D;CACD,MAAM,eAAe,QAAQ,gBAAgB,EAAE;CAG/C,IAAI,QAAiD;AACrD,MAAK,IAAI,IAAI,aAAa,SAAS,GAAG,KAAK,GAAG,KAAK;EAClD,MAAM,cAAc,aAAa;EACjC,MAAM,OAAO;AACb,WAAS,QAAQ,YAAY,KAAK,KAAK;;AAGxC,QAAO,EAAE,OAAO,OAAO;;;;;;;;AAaxB,SAAgB,kBAA+B;CAC9C,MAAM,mBAAmB,IAAI,IAAI;EAAC;EAAQ;EAAO;EAAU;EAAQ,CAAC;AAEpE,SAAQ,SAAS,SAAS;AACzB,MAAI,iBAAiB,IAAI,QAAQ,OAAO,EAAE;GACzC,MAAM,UAAU,IAAI,QAAQ,QAAQ,QAAQ;AAC5C,WAAQ,IAAI,oBAAoB,IAAI;AACpC,OAAI,CAAC,QAAQ,IAAI,SAAS,EAAE;IAC3B,MAAM,MAAM,IAAI,IAAI,QAAQ,IAAI;AAChC,YAAQ,IAAI,UAAU,IAAI,OAAO;;AAElC,UAAO,KAAK,IAAI,QAAQ,SAAS,EAAE,SAAS,CAAC,CAAC;;AAE/C,SAAO,KAAK,QAAQ;;;;;;AAOtB,SAAgB,iBAAiB,OAA4B;AAC5D,SAAQ,SAAS,SAAS;EACzB,MAAM,UAAU,IAAI,QAAQ,QA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AK,QAAQ,OAAO,KAAK,SAAS,YAAY,kBAAkB,KAAK,OACjE,KAAK,OACL;EAEL,MAAM,YAAY,UAAU,aACzB,IAAI,KAAK,KAAK,KAAK,GAAG,UAAU,aAAa,IAAK,CAAC,aAAa,GAChE,IAAI,KAAK,KAAK,KAAK,GAAG,KAAS,CAAC,aAAa;AAEhD,MAAI,QAAQ,iBACX,SAAQ,iBACP,UAAU,cACV,UAAU,iBAAiB,QAAQ,cACnC,UACA;AAGF,SAAO,UAAU;;AAGlB,QAAO,OAAO,SAAS,SAAS;EAG/B,MAAM,gBAAgB,QAAQ,OAAO,QAAQ,OAAO,GAAG;EAEvD,MAAM,WAAW,MAAM,KAAK,QAAQ;AAEpC,MAAI,SAAS,WAAW,KAAK;AAE5B,OAAI,CAAC,WACJ,cAAa,SAAS,CAAC,cAAc;AACpC,iBAAa;KACZ;GAGH,MAAM,WAAW,MAAM;AACvB,OAAI,UAAU;IAEb,MAAM,UAAU,IAAI,QAAQ,cAAc,QAAQ;AAClD,YAAQ,IAAI,iBAAiB,UAAU,WAAW;AAClD,WAAO,KAAK,IAAI,QAAQ,eAAe,EAAE,SAAS,CAAC,CAAC;;;AAItD,SAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types-BGmQ0uXs.mjs","names":[],"sources":["../src/schema/types.ts"],"sourcesContent":["/**\n * Schema Registry Types\n *\n * These types represent the schema definitions stored in D1.\n * They are the source of truth for all collections and fields.\n */\n\nimport type { BlockType } from \"./block-types.js\";\n\n/**\n * Supported field types\n */\nexport type FieldType =\n\t| \"string\"\n\t| \"text\"\n\t| \"url\"\n\t| \"number\"\n\t| \"integer\"\n\t| \"boolean\"\n\t| \"datetime\"\n\t| \"select\"\n\t| \"multiSelect\"\n\t| \"portableText\"\n\t| \"image\"\n\t| \"file\"\n\t| \"reference\"\n\t| \"json\"\n\t| \"slug\"\n\t| \"repeater\"\n\t| \"blocks\";\n\n/**\n * Array of all field types for validation\n */\nexport const FIELD_TYPES: readonly FieldType[] = [\n\t\"string\",\n\t\"text\",\n\t\"url\",\n\t\"number\",\n\t\"integer\",\n\t\"boolean\",\n\t\"datetime\",\n\t\"select\",\n\t\"multiSelect\",\n\t\"portableText\",\n\t\"image\",\n\t\"file\",\n\t\"reference\",\n\t\"json\",\n\t\"slug\",\n\t\"repeater\",\n\t\"blocks\",\n] as const;\n\n/** Scalar field types that can be backed by a content-list query index. */\nexport const INDEXABLE_FIELD_TYPES: ReadonlySet<FieldType> = new Set([\n\t\"string\",\n\t\"url\",\n\t\"number\",\n\t\"integer\",\n\t\"boolean\",\n\t\"datetime\",\n\t\"select\",\n\t\"reference\",\n\t\"slug\",\n]);\n\nexport function isIndexableFieldType(type: FieldType): boolean {\n\treturn INDEXABLE_FIELD_TYPES.has(type);\n}\n\n/**\n * SQLite column types that map from field types\n */\nexport type ColumnType = \"TEXT\" | \"REAL\" | \"INTEGER\" | \"JSON\";\n\n/**\n * Map field types to their SQLite column types\n */\nexport const FIELD_TYPE_TO_COLUMN: Record<FieldType, ColumnType> = {\n\tstring: \"TEXT\",\n\ttext: \"TEXT\",\n\tnumber: \"REAL\",\n\tinteger: \"INTEGER\",\n\tboolean: \"INTEGER\",\n\tdatetime: \"TEXT\",\n\tselect: \"TEXT\",\n\tmultiSelect: \"JSON\",\n\tportableText: \"JSON\",\n\timage: \"TEXT\",\n\tfile: \"TEXT\",\n\treference: \"TEXT\",\n\tjson: \"JSON\",\n\tslug: \"TEXT\",\n\turl: \"TEXT\",\n\trepeater: \"JSON\",\n\tblocks: \"JSON\",\n};\n\nexport const MAX_BLOCKS_ITEMS = 100;\n\n/**\n * Field types that *can* persist no `ec_*` column — see `isStoragelessField`\n * for whether a given row actually does. The `FIELD_TYPE_TO_COLUMN` entry above\n * is retained deliberately: it doubles as the `isFieldType` guard.\n */\nexport const STORAGELESS_FIELD_TYPES: ReadonlySet<string> = new Set<FieldType>([\"reference\"]);\n\n/**\n * Whether a field row keeps its values outside the content table.\n *\n * Storage-less is a property of the row, not of the type. A `reference` field\n * is storage-less once it is bound to a relation: the selection lives as edges\n * in `_emdash_content_references`. A reference field created before relations\n * existed — or one whose target collection could not be resolved — still owns a\n * TEXT column holding an entry id, and behaves like a string field until\n * something wires it.\n */\nexport function isStoragelessField(field: {\n\ttype: string;\n\tvalidation?: FieldValidation | null;\n}): boolean {\n\tif (!STORAGELESS_FIELD_TYPES.has(field.type)) return false;\n\treturn typeof field.validation?.relation === \"string\" && field.validation.relation.length > 0;\n}\n\n/**\n * `isStoragelessField` for a raw `_emdash_fields` row, whose `validation` is\n * unparsed JSON. Malformed JSON reads as unwired: a field nothing can resolve a\n * relation for keeps its column.\n */\nexport function isStoragelessFieldRow(row: { type: string; validation: string | null }): boolean {\n\tif (!STORAGELESS_FIELD_TYPES.has(row.type) || !row.validation) return false;\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(row.validation);\n\t} catch {\n\t\treturn false;\n\t}\n\tif (typeof parsed !== \"object\" || parsed === null) return false;\n\treturn isStoragelessField({ type: row.type, validation: parsed });\n}\n\n/**\n * Features a collection can support\n */\nexport type CollectionSupport =\n\t| \"drafts\"\n\t| \"revisions\"\n\t| \"preview\"\n\t| \"scheduling\"\n\t| \"search\"\n\t| \"seo\";\n\n/**\n * Sources for how a collection was created\n */\nexport type CollectionSource =\n\t| `template:${string}`\n\t| `import:${string}`\n\t| \"manual\"\n\t| \"discovered\"\n\t| \"seed\";\n\n/**\n * Validation rules for a field\n */\n/** Sub-field definition for repeater fields */\nexport interface RepeaterSubField {\n\tslug: string;\n\ttype:\n\t\t| \"string\"\n\t\t| \"text\"\n\t\t| \"url\"\n\t\t| \"number\"\n\t\t| \"integer\"\n\t\t| \"boolean\"\n\t\t| \"datetime\"\n\t\t| \"select\"\n\t\t| \"image\";\n\tlabel: string;\n\trequired?: boolean;\n\toptions?: string[]; // For select sub-fields\n}\n\n/** Allowed types for repeater sub-fields (no nesting, no complex types) */\nexport const REPEATER_SUB_FIELD_TYPES = [\n\t\"string\",\n\t\"text\",\n\t\"url\",\n\t\"number\",\n\t\"integer\",\n\t\"boolean\",\n\t\"datetime\",\n\t\"select\",\n\t\"image\",\n] as const;\n\nexport interface FieldValidation {\n\trequired?: boolean;\n\tmin?: number;\n\tmax?: number;\n\tminLength?: number;\n\tmaxLength?: number;\n\tpattern?: string;\n\toptions?: string[]; // For select/multiSelect\n\tsubFields?: RepeaterSubField[]; // For repeater fields\n\tminItems?: number; // For repeater fields\n\tmaxItems?: number; // For repeater fields\n\tallowedMimeTypes?: string[];\n\t/** Reference fields: the relation's slug. */\n\trelation?: string;\n\t/**\n\t * Reference fields: which end of the relation this collection sits on.\n\t * `parent` picks children and controls their order; `child` picks parents\n\t * and is unordered, since `sort_order` is scoped to a parent.\n\t */\n\trelationSide?: \"parent\" | \"child\";\n\t/** Reference fields: the collection on the *other* end (derived from the\n\t * relation and the side, denormalized here). */\n\ttargetCollection?: string;\n\t/** Reference fields: allow selecting more than one entry (UI constraint). */\n\tmultiple?: boolean;\n\tallowedTypes?: string[]; // For blocks fields\n\tretiredTypes?: string[]; // Server-owned retained types for blocks fields\n}\n\n/**\n * Widget options for field rendering\n */\nexport interface FieldWidgetOptions {\n\trows?: number; // For textarea\n\tshowPreview?: boolean; // For image/file\n\tdarkVariant?: boolean; // For image: offer a second slot for a dark-color-scheme counterpart\n\tcollection?: string; // For reference - which collection to reference\n\tallowMultiple?: boolean; // For reference\n\t[key: string]: unknown;\n}\n\nexport interface UnsupportedFieldType {\n\ttype: string;\n\tpath: string;\n}\n\nexport const MAX_COLLECTION_LIST_COLUMNS = 4;\n\n/** Longest admin sidebar folder label a collection may declare. */\nexport const MAX_COLLECTION_GROUP_LENGTH = 100;\n\n/** Longest Phosphor icon name a collection may declare. */\nexport const MAX_COLLECTION_ICON_LENGTH = 64;\n\n/** Collection-level admin presentation options. */\nexport interface CollectionAdminConfig {\n\t/** Custom field slugs to show in the content list. */\n\tlistColumns?: string[];\n\t/** Show a \"new entry\" quick action on the dashboard. Defaults to true. */\n\tquickCreate?: boolean;\n}\n\n/**\n * A collection definition\n */\nexport interface Collection {\n\tid: string;\n\tslug: string;\n\tlabel: string;\n\tlabelSingular?: string;\n\tdescription?: string;\n\ticon?: string;\n\tadmin?: CollectionAdminConfig;\n\tsupports: CollectionSupport[];\n\tsource?: CollectionSource;\n\t/** Whether this collection has SEO metadata fields enabled */\n\thasSeo: boolean;\n\t/** Field slug powering the admin list Title column. Defaults to the standard title display. */\n\ttitleField?: string;\n\t/** Field slug powering the admin list Date column. Must be a `datetime` field. Defaults to last-updated. */\n\tdateField?: string;\n\t/** URL pattern with {slug} placeholder (e.g. \"/{slug}\", \"/blog/{slug}\") */\n\turlPattern?: string;\n\t/** Whether published entries require a public slug. Defaults to true. */\n\troutable?: boolean;\n\t/**\n\t * Omit this collection's auto-generated sidebar entry and dashboard quick\n\t * action. The collection stays fully functional everywhere else (API, MCP,\n\t * hooks, direct `/content/:collection` URLs), so a plugin that owns the\n\t * collection can point editors at its own admin UI.\n\t */\n\thidden: boolean;\n\t/**\n\t * Explicit position in the admin sidebar. Collections with a `sortOrder`\n\t * come first, in ascending order; the rest keep the alphabetical-by-slug\n\t * order and follow. `undefined` means \"no explicit position\".\n\t */\n\tsortOrder?: number;\n\t/**\n\t * Admin sidebar folder. Collections sharing a group render under one\n\t * collapsible entry labelled with the group; `undefined` keeps the\n\t * collection inline.\n\t */\n\tgroup?: string;\n\t/** Whether comments are enabled for this collection */\n\tcommentsEnabled: boolean;\n\t/** Moderation strategy: \"all\" | \"first_time\" | \"none\" */\n\tcommentsModeration: \"all\" | \"first_time\" | \"none\";\n\t/** Auto-close comments after N days. 0 = never close. */\n\tcommentsClosedAfterDays: number;\n\t/** Auto-approve comments from authenticated CMS users */\n\tcommentsAutoApproveUsers: boolean;\n\t/** Whether opening an entry takes an edit lock. Defaults to true. */\n\teditLocking: boolean;\n\tcreatedAt: string;\n\tupdatedAt: string;\n}\n\n/**\n * A field definition\n */\nexport interface Field {\n\tid: string;\n\tcollectionId: string;\n\tslug: string;\n\tlabel: string;\n\ttype: FieldType;\n\t/** Raw stored type metadata that this runtime cannot safely interpret. */\n\tunsupportedType?: UnsupportedFieldType;\n\tblockTypes?: BlockType[];\n\tblockTypeFingerprint?: string;\n\tcolumnType: ColumnType;\n\trequired: boolean;\n\tunique: boolean;\n\tdefaultValue?: unknown;\n\tvalidation?: FieldValidation;\n\twidget?: string;\n\toptions?: FieldWidgetOptions;\n\tsortOrder: number;\n\tsearchable: boolean;\n\t/** Whether this field has a physical index for structured list queries. */\n\tindexed: boolean;\n\t/** Whether this field is translatable (default true). Non-translatable fields are synced across locales. */\n\ttranslatable: boolean;\n\tcreatedAt: string;\n}\n\n/**\n * Input for creating a collection\n */\nexport interface CreateCollectionInput {\n\tslug: string;\n\tlabel: string;\n\tlabelSingular?: string;\n\tdescription?: string;\n\ticon?: string;\n\tadmin?: CollectionAdminConfig;\n\tsupports?: CollectionSupport[];\n\tsource?: CollectionSource;\n\turlPattern?: string;\n\troutable?: boolean;\n\thasSeo?: boolean;\n\t/** Omit the auto-generated sidebar entry and dashboard quick action (defaults to false) */\n\thidden?: boolean;\n\t/** Explicit admin sidebar position (omit for the alphabetical fallback) */\n\tsortOrder?: number | null;\n\t/** Admin sidebar folder shared with other collections of the same group */\n\tgroup?: string | null;\n\tcommentsEnabled?: boolean;\n\t/** Take an edit lock when an entry is opened (defaults to true) */\n\teditLocking?: boolean;\n}\n\n/**\n * Input for updating a collection\n */\nexport interface UpdateCollectionInput {\n\tlabel?: string;\n\tlabelSingular?: string;\n\tdescription?: string;\n\ticon?: string;\n\tadmin?: CollectionAdminConfig;\n\tsupports?: CollectionSupport[];\n\turlPattern?: string | null;\n\troutable?: boolean;\n\thasSeo?: boolean;\n\t/** Omit the auto-generated sidebar entry and dashboard quick action */\n\thidden?: boolean;\n\t/** Explicit admin sidebar position; `null` clears it back to alphabetical */\n\tsortOrder?: number | null;\n\t/** Admin sidebar folder; `null` moves the collection back inline */\n\tgroup?: string | null;\n\tcommentsEnabled?: boolean;\n\tcommentsModeration?: \"all\" | \"first_time\" | \"none\";\n\tcommentsClosedAfterDays?: number;\n\tcommentsAutoApproveUsers?: boolean;\n\t/** Take an edit lock when an entry is opened */\n\teditLocking?: boolean;\n\t/** Field slug for the Title column; `null`/`\"\"` clears back to the default. */\n\ttitleField?: string | null;\n\t/** Datetime field slug for the Date column; `null`/`\"\"` clears back to the default. */\n\tdateField?: string | null;\n}\n\n/**\n * Input for creating a field\n */\nexport interface CreateFieldInput {\n\tslug: string;\n\tlabel: string;\n\ttype: FieldType;\n\trequired?: boolean;\n\tunique?: boolean;\n\tdefaultValue?: unknown;\n\tvalidation?: FieldValidation | null;\n\twidget?: string;\n\toptions?: FieldWidgetOptions;\n\tsortOrder?: number;\n\t/** Whether this field should be indexed for search */\n\tsearchable?: boolean;\n\t/** Create a physical index for structured sorting. */\n\tindexed?: boolean;\n\t/** Whether this field is translatable (default true). Non-translatable fields are synced across locales. */\n\ttranslatable?: boolean;\n}\n\n/**\n * Input for updating a field\n */\nexport interface UpdateFieldInput {\n\tlabel?: string;\n\t/**\n\t * Change the field's type. Only storage-compatible text aliases (`string`,\n\t * `text`, and `slug`) can be changed in place. Other changes require an\n\t * explicit content migration. Omit to keep the current type.\n\t */\n\ttype?: FieldType;\n\trequired?: boolean;\n\tunique?: boolean;\n\tdefaultValue?: unknown;\n\tvalidation?: FieldValidation | null;\n\twidget?: string;\n\toptions?: FieldWidgetOptions;\n\tsortOrder?: number;\n\t/** Whether this field should be indexed for search */\n\tsearchable?: boolean;\n\t/** Create or remove the physical index used by structured sorting. */\n\tindexed?: boolean;\n\t/** Whether this field is translatable (default true). Non-translatable fields are synced across locales. */\n\ttranslatable?: boolean;\n}\n\n/**\n * A collection with its fields\n */\nexport interface CollectionWithFields extends Collection {\n\tfields: Field[];\n}\n\n/**\n * Reserved field slugs that cannot be used.\n *\n * Includes names reserved for runtime hydration (`terms`, `bylines`, `byline`)\n * so user-defined fields never shadow the auto-hydrated values on entry.data.\n */\nexport const RESERVED_FIELD_SLUGS = [\n\t\"id\",\n\t\"slug\",\n\t\"status\",\n\t\"author_id\",\n\t\"primary_byline_id\",\n\t\"created_at\",\n\t\"updated_at\",\n\t\"published_at\",\n\t\"scheduled_at\",\n\t\"deleted_at\",\n\t\"version\",\n\t\"live_revision_id\",\n\t\"draft_revision_id\",\n\t// Runtime-hydrated fields\n\t\"terms\",\n\t\"bylines\",\n\t\"byline\",\n];\n\n/**\n * Reserved collection slugs that cannot be used\n */\nexport const RESERVED_COLLECTION_SLUGS = [\n\t\"content\",\n\t\"media\",\n\t\"users\",\n\t\"revisions\",\n\t\"taxonomies\",\n\t\"options\",\n\t\"audit_logs\",\n\t// Shadowed by the static POST /schema/collections/reorder route: a\n\t// collection with this slug could never be addressed at its own URL.\n\t\"reorder\",\n\t// Shadowed by the static /content-types/relations admin route, for the same\n\t// reason: a collection with this slug would be unreachable in the admin.\n\t\"relations\",\n];\n\n/**\n * Byline custom fields (Discussion #1174).\n *\n * Sites declare site-specific byline metadata (`job_title`, `pronouns`,\n * `twitter_handle`, `company`, …) without touching emdash core. Definitions\n * live in `_emdash_byline_fields`; values in either\n * `_emdash_byline_field_values` (translatable, keyed by `byline_id`) or\n * `_emdash_byline_field_group_values` (non-translatable, keyed by\n * `translation_group`). The per-field `translatable` flag decides which\n * value table is used. See migration 041.\n */\n\n/**\n * The five v1 field types supported on byline custom fields. Deliberately\n * narrower than the content `FieldType` union — bylines don't need\n * `portableText`, `reference`, `image`, etc. v2 may extend this; v1 keeps\n * the storage and UI surfaces small.\n */\nexport type BylineFieldType = \"string\" | \"text\" | \"url\" | \"boolean\" | \"select\";\n\nexport const BYLINE_FIELD_TYPES: readonly BylineFieldType[] = [\n\t\"string\",\n\t\"text\",\n\t\"url\",\n\t\"boolean\",\n\t\"select\",\n] as const;\n\n/**\n * Validation rules for a byline custom field. v1 only exposes `options`\n * (the choice list for `select` fields). The shape mirrors the content-\n * field convention so the admin UI patterns transfer.\n */\nexport interface BylineFieldValidation {\n\t/** Choices for `select`-type fields. Ignored for other types. */\n\toptions?: string[];\n}\n\n/**\n * Runtime shape of a registered byline custom field. Stored in\n * `_emdash_byline_fields` (see migration 041).\n */\nexport interface BylineFieldDefinition {\n\tid: string;\n\tslug: string;\n\tlabel: string;\n\ttype: BylineFieldType;\n\trequired: boolean;\n\t/**\n\t * Whether values are stored per-locale (`true`, in\n\t * `_emdash_byline_field_values` keyed by `byline_id`) or shared across\n\t * every locale variant of the same byline identity (`false`, in\n\t * `_emdash_byline_field_group_values` keyed by `translation_group`).\n\t * Defaults to `true` at the DB level.\n\t */\n\ttranslatable: boolean;\n\tvalidation: BylineFieldValidation | null;\n\tsortOrder: number;\n\tcreatedAt: string;\n\tupdatedAt: string;\n}\n\n/**\n * Input for creating a byline custom field. `slug` and `type` are not\n * updatable post-create — changing either would invalidate stored values.\n */\nexport interface CreateBylineFieldInput {\n\tslug: string;\n\tlabel: string;\n\ttype: BylineFieldType;\n\trequired?: boolean;\n\ttranslatable?: boolean;\n\tvalidation?: BylineFieldValidation | null;\n\tsortOrder?: number;\n}\n\n/**\n * Input for updating a byline custom field. `slug` and `type` are\n * intentionally not present — see `CreateBylineFieldInput`.\n */\nexport interface UpdateBylineFieldInput {\n\tlabel?: string;\n\trequired?: boolean;\n\ttranslatable?: boolean;\n\tvalidation?: BylineFieldValidation | null;\n\tsortOrder?: number;\n}\n\n/**\n * Runtime value type for a byline custom field. The narrow union mirrors\n * what the five v1 field types can produce: `string`/`text`/`url`/`select`\n * → string, `boolean` → boolean, plus `null` for cleared values.\n */\nexport type CustomFieldValue = string | boolean | null;\n\n/**\n * Reserved byline-field slugs. Two reasons a slug ends up here:\n *\n * 1. **Column collision.** Slugs that match a fixed column on\n * `_emdash_bylines` (migrations 031 + 040) would shadow that column\n * on hydration. The first 12 entries cover this.\n * 2. **Route collision.** Static file routes under\n * `/_emdash/api/admin/byline-fields/` take precedence over the\n * `[slug].ts` dynamic route in Astro, so a custom field whose slug\n * matches a sibling static file (e.g. `reorder.ts`) is unreachable\n * via single-field CRUD — the static route handles only its own\n * method (POST for `reorder`) and 405s everything else.\n * `reorder` is the only such sibling today; new sibling routes\n * (e.g. a hypothetical `import.ts`) must be added here.\n * `[slug]/usage.ts` lives a level deeper so a slug of `usage` does\n * not collide — it resolves cleanly to `[slug].ts`.\n *\n * Enforced at the registry layer (Phase 2) and the admin API zod layer\n * (Phase 4) so non-HTTP callers (seeds, scripts) get the same guarantee.\n */\nexport const RESERVED_BYLINE_FIELD_SLUGS = [\n\t// 1. Column-collision slugs (matches `_emdash_bylines` fixed columns).\n\t\"id\",\n\t\"slug\",\n\t\"display_name\",\n\t\"bio\",\n\t\"avatar_media_id\",\n\t\"website_url\",\n\t\"user_id\",\n\t\"is_guest\",\n\t\"locale\",\n\t\"translation_group\",\n\t\"created_at\",\n\t\"updated_at\",\n\t// 2. Route-collision slugs (matches static sibling files of `[slug].ts`).\n\t\"reorder\",\n] as const;\n"],"mappings":";;;;AAkCA,MAAa,cAAoC;CAChD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;AAGD,MAAa,wBAAgD,IAAI,IAAI;CACpE;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,CAAC;AAEF,SAAgB,qBAAqB,MAA0B;AAC9D,QAAO,sBAAsB,IAAI,KAAK;;;;;AAWvC,MAAa,uBAAsD;CAClE,QAAQ;CACR,MAAM;CACN,QAAQ;CACR,SAAS;CACT,SAAS;CACT,UAAU;CACV,QAAQ;CACR,aAAa;CACb,cAAc;CACd,OAAO;CACP,MAAM;CACN,WAAW;CACX,MAAM;CACN,MAAM;CACN,KAAK;CACL,UAAU;CACV,QAAQ;CACR;AAED,MAAa,mBAAmB;;;;;;AAOhC,MAAa,0BAA+C,IAAI,IAAe,CAAC,YAAY,CAAC;;;;;;;;;;;AAY7F,SAAgB,mBAAmB,OAGvB;AACX,KAAI,CAAC,wBAAwB,IAAI,MAAM,KAAK,CAAE,QAAO;AACrD,QAAO,OAAO,MAAM,YAAY,aAAa,YAAY,MAAM,WAAW,SAAS,SAAS;;;;;;;AAQ7F,SAAgB,sBAAsB,KAA2D;AAChG,KAAI,CAAC,wBAAwB,IAAI,IAAI,KAAK,IAAI,CAAC,IAAI,WAAY,QAAO;CACtE,IAAI;AACJ,KAAI;AACH,WAAS,KAAK,MAAM,IAAI,WAAW;SAC5B;AACP,SAAO;;AAER,KAAI,OAAO,WAAW,YAAY,WAAW,KAAM,QAAO;AAC1D,QAAO,mBAAmB;EAAE,MAAM,IAAI;EAAM,YAAY;EAAQ,CAAC;;;AA8ClE,MAAa,2BAA2B;CACvC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AAgDD,MAAa,8BAA8B;;AAG3C,MAAa,8BAA8B;;AAG3C,MAAa,6BAA6B;;;;;;;AAqN1C,MAAa,uBAAuB;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;;;;AAKD,MAAa,4BAA4B;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CAGA;CACA;AAsBD,MAAa,qBAAiD;CAC7D;CACA;CACA;CACA;CACA;CACA;;;;;;;;;;;;;;;;;;;;;AAyFD,MAAa,8BAA8B;CAE1C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types-CNB-dj6F.d.mts","names":[],"sources":["../src/database/repositories/types.ts"],"mappings":";;;;UAciB,kBAAA;EAKV;EAHN,EAAA;EACA,IAAA;EACA,IAAA;EACA,IAAA,EAAM,MAAA;EACN,MAAA;EACA,QAAA;EACA,eAAA;EACA,MAAA;EACA,aAAA;EAKS;EAHT,aAAA;EACA,WAAA;;EAEA,SAAA;AAAA;AAAA,UAGgB,kBAAA;EAChB,IAAA,GAAO,MAAA;EACP,MAAA;EACA,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G;EAlLH,MAAA;AAAA;AAAA,UAGgB,cAAA;EAChB,KAAA,EAAO,CAAA;EACP,UAAA;EAoLE;;;AAKH;;EAnLC,KAAA;AAAA;;;;;;;;;cAoDY,kBAAA,SAA2B,KAAA;cAC3B,MAAA;AAAA;AAAA,UAkEI,WAAA;EAChB,EAAA;EACA,IAAA;EACA,IAAA;EACA,MAAA;EACA,IAAA,EAAM,MAAA;EACN,QAAA;EACA,eAAA;EACA,MAAA,GAAS,aAAA;EACT,OAAA,GAAU,mBAAA;EACV,SAAA;EACA,SAAA;EACA,WAAA;EACA,WAAA;EACA,cAAA;EACA,eAAA;EACA,OAAA;EACA,MAAA;EACA,gBAAA;;EAEA,GAAA,GAAM,UAAA;;;;;;;;;;;EAWN,QAAA,GAAW,MAAA;;;;;;;;;;;;EAYX,UAAA,GAAa,MAAA;IAGX,QAAA,EAAU,KAAA;MACT,EAAA;MACA,IAAA;MACA,UAAA;MACA,KAAA;MACA,MAAA;MACA,gBAAA;MACA,SAAA;IAAA;IAED,UAAA;EAAA;AAAA;AAAA,cAKU,qBAAA,SAA8B,KAAA;EAGlC,OAAA;cADP,OAAA,UACO,OAAA;AAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types-D2NEXtgB.mjs","names":[],"sources":["../src/database/repositories/types.ts"],"sourcesContent":["import type { ContentFieldFilters } from \"../../content-list-query.js\";\nimport type { CustomFieldValue } from \"../../schema/types.js\";\nimport { encodeBase64, decodeBase64 } from \"../../utils/base64.js\";\n\n/**\n * Hard cap on cursor length. Cursors we issue are short JSON-in-base64\n * blobs; a real cursor is well under 200 chars. This guards against\n * malicious callers passing megabyte-sized strings to force the base64\n * decoder to allocate (decodeBase64 is O(N) in input size). The MCP and\n * REST schemas also clamp at 2048 — this 4096 cap is a defense-in-depth\n * floor inside the repository helpers.\n */\nexport const MAX_CURSOR_LENGTH = 4096;\n\nexport interface CreateContentInput {\n\t/** Explicit content ID for stable seed imports. Omit to generate a ULID. */\n\tid?: string;\n\ttype: string;\n\tslug?: string | null;\n\tdata: Record<string, unknown>;\n\tstatus?: string;\n\tauthorId?: string;\n\tprimaryBylineId?: string | null;\n\tlocale?: string;\n\ttranslationOf?: string;\n\t/** Field columns selected atomically from `translationOf` during the insert. */\n\tinheritFields?: string[];\n\tpublishedAt?: string | null;\n\t/** Override created_at (ISO 8601). Used by importers to preserve original dates. */\n\tcreatedAt?: string | null;\n}\n\nexport interface UpdateContentInput {\n\tdata?: Record<string, unknown>;\n\tstatus?: string;\n\tslug?: string | null;\n\tpublishedAt?: string | null;\n\tscheduledAt?: string | null;\n\t/** Entry owner (`ec_{collection}.author_id`). */\n\tauthorId?: string | null;\n\t/** Revision author, separate from entry ownership. */\n\trevisionAuthorId?: string | null;\n\tprimaryBylineId?: string | null;\n}\n\n/** SEO fields for content items */\nexport interface ContentSeo {\n\ttitle: string | null;\n\tdescription: string | null;\n\timage: string | null;\n\tcanonical: string | null;\n\tnoIndex: boolean;\n}\n\n/** Input for updating SEO fields on content */\nexport interface ContentSeoInput {\n\ttitle?: string | null;\n\tdescription?: string | null;\n\timage?: string | null;\n\tcanonical?: string | null;\n\tnoIndex?: boolean;\n}\n\nexport interface BylineSummary {\n\tid: string;\n\tslug: string;\n\tdisplayName: string;\n\tbio: string | null;\n\tavatarMediaId: string | null;\n\t/**\n\t * The avatar media's storage key, folded in by a LEFT JOIN on the\n\t * `media` table. Populated by the content-credit hydration path\n\t * (`getContentBylines` / `getContentBylinesMany`, i.e. the\n\t * `entry.data.bylines` populated by `getEmDashCollection` /\n\t * `getEmDashEntry`) and by the single-row finders (`findById`,\n\t * `findBySlug`, `findByUserId`, `findByUserIds`). `findMany` doesn't\n\t * join media, so it leaves this null.\n\t *\n\t * Lets a page build a direct storage URL for an author avatar without a\n\t * per-byline `MediaRepository.findById`, avoiding an N+1 when many distinct\n\t * authors appear on one page.\n\t *\n\t * Optional so adding it is a non-breaking change for existing code that\n\t * constructs a `BylineSummary` literal; the repositories always populate it\n\t * (to `null` when there's no avatar or no media join).\n\t */\n\tavatarStorageKey?: string | null;\n\t/** Avatar media alt text, from the same media join. Null when not joined. */\n\tavatarAlt?: string | null;\n\t/**\n\t * Avatar media blurhash (LQIP placeholder, migration 024), folded in by the\n\t * same media join as `avatarStorageKey`. Lets a renderer paint a blurred\n\t * placeholder while the full avatar loads, with no extra media lookup.\n\t * Null when the byline has no avatar, the media row has no blurhash, or the\n\t * byline came from `findMany`, which doesn't join media.\n\t */\n\tavatarBlurhash?: string | null;\n\t/**\n\t * Avatar media dominant colour (LQIP placeholder, migration 024), from the\n\t * same media join. Null under the same conditions as `avatarBlurhash`.\n\t */\n\tavatarDominantColor?: string | null;\n\twebsiteUrl: string | null;\n\tuserId: string | null;\n\tisGuest: boolean;\n\tcreatedAt: string;\n\tupdatedAt: string;\n\t/**\n\t * Locale this byline row is presented in. Added by migration 040.\n\t * `(slug, locale)` is unique; a single slug can repeat across locales.\n\t */\n\tlocale: string;\n\t/**\n\t * Shared across translations of the same byline. Added by migration 040.\n\t * `_emdash_content_bylines.byline_id` and `ec_*.primary_byline_id` store\n\t * this value, so a credit spans every locale variant of a byline.\n\t * Nullable in storage for backwards compatibility; new rows always\n\t * populate it.\n\t */\n\ttranslationGroup: string | null;\n\t/**\n\t * Custom field values registered via the byline-fields schema (migration\n\t * 041, Discussion #1174). Optional in the TypeScript shape so existing\n\t * object-literal consumers (test fixtures, plugin renderers) stay\n\t * source-compatible; the runtime always returns `{}` when no fields are\n\t * registered. Translatable values reflect this row's locale; non-\n\t * translatable values are shared across every locale variant of the\n\t * byline's `translation_group`.\n\t */\n\tcustomFields?: Record<string, CustomFieldValue>;\n}\n\nexport interface ContentBylineCredit {\n\tbyline: BylineSummary;\n\tsortOrder: number;\n\troleLabel: string | null;\n\t/** Whether this credit was explicitly assigned or inferred from authorId */\n\tsource?: \"explicit\" | \"inferred\";\n}\n\n/** A whitelisted timestamp column a content-list date range can filter on. */\nexport type ContentDateField = \"createdAt\" | \"updatedAt\" | \"publishedAt\";\n\n/**\n * Inclusive date-range filter for a single whitelisted timestamp column.\n * Bounds are compared lexicographically against the stored ISO 8601 strings,\n * which is correct because every timestamp is written via `toISOString()`.\n * Callers wanting an inclusive upper bound should pass an end-of-day value\n * (e.g. `2024-12-31T23:59:59.999Z`); the repository does not widen `to`.\n */\nexport interface ContentDateFilter {\n\tfield: ContentDateField;\n\tfrom?: string;\n\tto?: string;\n}\n\n/**\n * Byline filter for a content list.\n *\n * `mode: \"any\"` matches entries credited to at least one of `bylineIds`;\n * `mode: \"none\"` matches entries with no credit at all.\n *\n * `bylineIds` are `translation_group` values — what\n * `_emdash_content_bylines.byline_id` stores since migration 040 — so a filter\n * matches a byline across every locale variant.\n *\n * By default only explicit credits count. `includeInferred` widens the filter\n * to the byline the list actually renders, which for an entry with no credits\n * is the one linked to its `author_id` (see `hydrateBylinesMany`).\n */\nexport interface ContentBylineFilter {\n\tmode: \"any\" | \"none\";\n\t/** Ignored when `mode` is `\"none\"`. An empty list matches nothing. */\n\tbylineIds?: string[];\n\tincludeInferred?: boolean;\n\t/**\n\t * Locale a credit has to resolve at — the locale the list is scoped to.\n\t * Applies to explicit credits as well as inferred ones, since a byline\n\t * group credited to an entry renders only where it has a row at that\n\t * locale. Defaults to each entry's own locale when the list spans locales.\n\t */\n\tlocale?: string;\n}\n\nexport interface FindManyOptions {\n\twhere?: {\n\t\tstatus?: string;\n\t\tauthorId?: string;\n\t\tlocale?: string;\n\t\t/** Case-insensitive substring to match against `searchColumns`. */\n\t\tq?: string;\n\t\t/**\n\t\t * Columns the `q` substring filter is applied to (OR'd together).\n\t\t * Resolved by the handler from the collection's display fields, slug,\n\t\t * and any field marked searchable. Each name is validated as a SQL\n\t\t * identifier.\n\t\t */\n\t\tsearchColumns?: string[];\n\t\t/**\n\t\t * Serve `q` from the collection's FTS5 index (`_emdash_fts_<slug>`)\n\t\t * instead of an unindexable substring LIKE. Set by the handler only\n\t\t * when the collection has search enabled and the index exists\n\t\t * (SQLite only). The repository combines a token-prefix MATCH with\n\t\t * an index-served slug prefix so slug lookups keep working.\n\t\t */\n\t\tuseFts?: boolean;\n\t\t/** Inclusive date range over a whitelisted timestamp column. */\n\t\tdateFilter?: ContentDateFilter;\n\t\t/** Restrict to entries by their byline credits. */\n\t\tbylineFilter?: ContentBylineFilter;\n\t\t/** AND-combined filters over custom fields explicitly marked as indexed. */\n\t\tfieldFilters?: ContentFieldFilters;\n\t};\n\torderBy?: {\n\t\tfield: string;\n\t\tdirection: \"asc\" | \"desc\";\n\t};\n\t/**\n\t * Extra field slugs allowed as `orderBy` beyond the system columns — the\n\t * collection's configured titleField/dateField. Resolved by the\n\t * handler server-side so `orderBy` stays a closed set per request.\n\t */\n\tsortableExtras?: string[];\n\tlimit?: number;\n\tcursor?: string; // Base64-encoded JSON: {orderValue: string, id: string}\n\t/** Rows to skip before the page, for numbered pages. Cannot be combined with `cursor`. */\n\toffset?: number;\n}\n\nexport interface FindManyResult<T> {\n\titems: T[];\n\tnextCursor?: string; // Base64-encoded JSON: {orderValue: string, id: string}\n\t/**\n\t * Total number of rows matching the where clause (ignoring pagination).\n\t * Optional because not every caller needs it; repositories that compute\n\t * it should set it so the UI can render a stable pagination denominator.\n\t */\n\ttotal?: number;\n}\n\n/**\n * Order value stamped into a cursor over a *staged* reference selection, whose\n * anchor is a translation group rather than a row in the link table.\n *\n * A preview and a public render page the same field from different places, so a\n * cursor can cross that boundary in either direction — the draft publishes, or\n * the preview session ends, mid-pagination. Both sides recognise this marker so\n * they can tell a foreign cursor from a malformed one and restart the field's\n * page rather than failing or silently emptying it.\n */\nexport const STAGED_CURSOR_MARKER = \"staged\";\n\n/**\n * Boundary for a single ordered field inside a cursor.\n *\n * `missing` distinguishes \"the document has no value for this field\" from\n * \"the document stores JSON `null`\". SQLite can only tell these apart at the\n * SQL layer, but PostgreSQL orders `data::jsonb->'field'` differently for the\n * two cases, so the seek boundary must carry both possibilities.\n */\nexport interface SortFieldBoundary {\n\tvalue?: unknown;\n\tmissing?: boolean;\n}\n\n/** Encode a cursor from order value + id, optionally carrying the ordered field values. */\nexport function encodeCursor(\n\torderValue: string,\n\tid: string,\n\tsortValues?: SortFieldBoundary[],\n): string {\n\tconst payload: { orderValue: string; id: string; sortValues?: SortFieldBoundary[] } = {\n\t\torderValue,\n\t\tid,\n\t};\n\tif (sortValues !== undefined && sortValues.length > 0) {\n\t\tpayload.sortValues = sortValues;\n\t}\n\treturn encodeBase64(JSON.stringify(payload));\n}\n\n/**\n * Thrown when a pagination cursor cannot be decoded.\n *\n * Repository callers should let this propagate; handler catch blocks\n * map it to a structured `INVALID_CURSOR` error so client pagination\n * bugs surface immediately rather than silently re-fetching the first\n * page.\n */\nexport class InvalidCursorError extends Error {\n\tconstructor(cursor: string) {\n\t\tconst display = cursor.length > 50 ? `${cursor.slice(0, 47)}...` : cursor;\n\t\tsuper(`Invalid pagination cursor: ${display}`);\n\t\tthis.name = \"InvalidCursorError\";\n\t}\n}\n\nfunction isSortFieldBoundary(item: unknown): item is SortFieldBoundary {\n\tif (item === null || typeof item !== \"object\") {\n\t\treturn false;\n\t}\n\tconst candidate = item as { value?: unknown; missing?: unknown };\n\tif (candidate.missing !== undefined && typeof candidate.missing !== \"boolean\") {\n\t\treturn false;\n\t}\n\treturn true;\n}\n\nfunction normalizeSortBoundary(item: unknown): SortFieldBoundary {\n\tif (isSortFieldBoundary(item)) {\n\t\treturn { value: item.value, missing: item.missing };\n\t}\n\t// Fall back for plain values that predate the structured boundary format.\n\treturn { value: item, missing: false };\n}\n\n/**\n * Decode a cursor to order value + id.\n *\n * Throws `InvalidCursorError` if the cursor is empty, not valid base64,\n * not valid JSON, or doesn't contain string `orderValue` and `id` fields.\n */\nexport function decodeCursor(cursor: string): {\n\torderValue: string;\n\tid: string;\n\tsortValues?: SortFieldBoundary[];\n} {\n\tif (!cursor) throw new InvalidCursorError(cursor);\n\tif (cursor.length > MAX_CURSOR_LENGTH) throw new InvalidCursorError(cursor);\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(decodeBase64(cursor));\n\t} catch {\n\t\tthrow new InvalidCursorError(cursor);\n\t}\n\tif (parsed === null || typeof parsed !== \"object\") {\n\t\tthrow new InvalidCursorError(cursor);\n\t}\n\tconst candidate = parsed as { orderValue?: unknown; id?: unknown; sortValues?: unknown };\n\tif (typeof candidate.orderValue !== \"string\" || typeof candidate.id !== \"string\") {\n\t\tthrow new InvalidCursorError(cursor);\n\t}\n\tlet sortValues: SortFieldBoundary[] | undefined;\n\tif (candidate.sortValues !== undefined) {\n\t\tif (!Array.isArray(candidate.sortValues)) {\n\t\t\tthrow new InvalidCursorError(cursor);\n\t\t}\n\t\tsortValues = candidate.sortValues.map(normalizeSortBoundary);\n\t}\n\treturn {\n\t\torderValue: candidate.orderValue,\n\t\tid: candidate.id,\n\t\tsortValues,\n\t};\n}\n\nexport interface ContentItem {\n\tid: string;\n\ttype: string;\n\tslug: string | null;\n\tstatus: string;\n\tdata: Record<string, unknown>;\n\tauthorId: string | null;\n\tprimaryBylineId: string | null;\n\tbyline?: BylineSummary | null;\n\tbylines?: ContentBylineCredit[];\n\tcreatedAt: string;\n\tupdatedAt: string;\n\tpublishedAt: string | null;\n\tscheduledAt: string | null;\n\tliveRevisionId: string | null;\n\tdraftRevisionId: string | null;\n\tversion: number;\n\tlocale: string | null;\n\ttranslationGroup: string | null;\n\t/** SEO metadata — only populated for collections with `has_seo` enabled */\n\tseo?: ContentSeo;\n\t/**\n\t * For collections that support `revisions`: when a draft revision exists,\n\t * `data` reflects the unsaved draft and `liveData` carries the currently-\n\t * published values. When no draft exists, `liveData` is undefined.\n\t *\n\t * Hydrated by `EmDashRuntime.hydrateDraftData()` — repositories themselves\n\t * never set this field; it's purely a runtime-overlay concept that gives\n\t * agents a clear picture of \"draft vs. live\" without re-fetching the\n\t * revision history.\n\t */\n\tliveData?: Record<string, unknown>;\n\t/**\n\t * First page of each reference field's resolved selection, keyed by field\n\t * slug. Only populated when the caller opts in via `handleContentGet`'s\n\t * `referenceOptions` param (see content.ts) — hydration is never\n\t * unconditional because it can leak draft ids/slugs to callers without\n\t * `content:read_drafts`.\n\t *\n\t * Shape mirrors `EntryRef` from `api/handlers/relations.ts`, duplicated\n\t * here (rather than imported) so the database layer doesn't depend on\n\t * the api/handlers layer.\n\t */\n\treferences?: Record<\n\t\tstring,\n\t\t{\n\t\t\tchildren: Array<{\n\t\t\t\tid: string;\n\t\t\t\tslug: string | null;\n\t\t\t\tcollection: string;\n\t\t\t\ttitle: string | null;\n\t\t\t\tlocale: string | null;\n\t\t\t\ttranslationGroup: string | null;\n\t\t\t\tsortOrder?: number;\n\t\t\t}>;\n\t\t\tnextCursor?: string;\n\t\t}\n\t>;\n}\n\nexport class EmDashValidationError extends Error {\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic details?: unknown,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = \"EmDashValidationError\";\n\t}\n}\n\nexport class ContentCollectionNotFoundError extends Error {\n\tconstructor(collection: string) {\n\t\tsuper(`Collection '${collection}' not found`);\n\t\tthis.name = \"ContentCollectionNotFoundError\";\n\t}\n}\n\n/**\n * Thrown by `publish()` when called with `requireDue` for a row that is no\n * longer due (its `scheduled_at` was cleared or pushed into the future between\n * selection and publish — e.g. an editor unscheduled it). Lets the scheduled\n * sweep skip the row silently rather than treating it as a publish failure.\n */\nexport class ScheduledNotDueError extends Error {\n\tconstructor(message = \"Content is no longer scheduled to publish\") {\n\t\tsuper(message);\n\t\tthis.name = \"ScheduledNotDueError\";\n\t}\n}\n\nexport class ContentMutationConflictError extends Error {\n\tconstructor(message = \"Content changed while the operation was in progress\") {\n\t\tsuper(message);\n\t\tthis.name = \"ContentMutationConflictError\";\n\t}\n}\n"],"mappings":";;;;;;;;;;;AAYA,MAAa,oBAAoB;;;;;;;;;;;AA8OjC,MAAa,uBAAuB;;AAgBpC,SAAgB,aACf,YACA,IACA,YACS;CACT,MAAM,UAAgF;EACrF;EACA;EACA;AACD,KAAI,eAAe,UAAa,WAAW,SAAS,EACnD,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wC,KAAA,CAMV,aAAA;;;;;;EAO9B,SAAA,GAP2C,KAAA,CAOf,aAAA;;;;;;EAO5B,SAAA,GAPyC,KAAA,CAOb,aAAA;IAAgB,UAAA;EAAA;AAAA;;;;UAM5B,kBAAA;;;;;EAKhB,aAAA;;;;;EAMA,WAAA;;;;;;EAOA,SAAA;;;;;;EAOA,QAAA;;;;;;;;;;;;;;EAeA,WAAA,GAAc,MAAA;AAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils-TPt7w2cS.mjs","names":["slugifyFn"],"sources":["../src/import/utils.ts"],"sourcesContent":["/**\n * Shared import utilities\n *\n * Common constants and functions used across all WordPress import sources.\n */\n\nimport type { PortableTextBlock } from \"@emdash-cms/gutenberg-to-portable-text\";\nimport mime from \"mime/lite\";\n\nimport { RESERVED_FIELD_SLUGS } from \"../schema/types.js\";\nimport type { ImportFieldDef, CollectionSchemaStatus } from \"./types.js\";\n\n// =============================================================================\n// Constants\n// =============================================================================\n\n/** Internal WordPress post types that should be excluded from import */\nexport const INTERNAL_POST_TYPES = [\n\t\"revision\",\n\t\"nav_menu_item\",\n\t\"custom_css\",\n\t\"customize_changeset\",\n\t\"oembed_cache\",\n\t\"wp_global_styles\",\n\t\"wp_navigation\",\n\t\"wp_template\",\n\t\"wp_template_part\",\n\t\"attachment\", // Handled separately as media\n\t\"wp_block\", // Handled separately as sections (reusable blocks)\n\t\"acf-field-group\",\n\t\"acf-field\",\n\t\"acf-post-type\",\n\t\"acf-taxonomy\",\n\t\"acf-ui-options-page\",\n];\n\n/** Internal meta key prefixes to filter out */\nexport const INTERNAL_META_PREFIXES = [\"_edit_\", \"_wp_\"];\n\nconst NUMERIC_PATTERN = /^-?\\d+(\\.\\d+)?$/;\nconst TRAILING_SLASHES = /\\/+$/;\nconst WP_JSON_SUFFIX = /\\/wp-json\\/?.*$/;\n\n/** Specific internal meta keys */\nexport const INTERNAL_META_KEYS = [\"_edit_last\", \"_edit_lock\", \"_pingme\", \"_encloseme\"];\n\n/** Base fields required for any WordPress import */\nexport const BASE_REQUIRED_FIELDS: ImportFieldDef[] = [\n\t{ slug: \"title\", label: \"Title\", type: \"string\", required: true, searchable: true },\n\t{ slug: \"content\", label: \"Content\", type: \"portableText\", required: false, searchable: true },\n\t{ slug: \"excerpt\", label: \"Excerpt\", type: \"text\", required: false },\n];\n\n/** Featured image field - only added to post types that have _thumbnail_id */\nexport const FEATURED_IMAGE_FIELD: ImportFieldDef = {\n\tslug: \"featured_image\",\n\tlabel: \"Featured Image\",\n\ttype: \"image\",\n\trequired: false,\n};\n\n// =============================================================================\n// Type Guards\n// =============================================================================\n\n/**\n * Check if a post type is internal/should be excluded\n */\nexport function isInternalPostType(type: string): boolean {\n\treturn INTERNAL_POST_TYPES.includes(type);\n}\n\n/**\n * Check if a meta key is internal/should be filtered out\n */\nexport function isInternalMetaKey(key: string): boolean {\n\t// Check specific keys\n\tif (INTERNAL_META_KEYS.includes(key)) return true;\n\n\t// Check prefixes\n\tfor (const prefix of INTERNAL_META_PREFIXES) {\n\t\tif (key.startsWith(prefix)) return true;\n\t}\n\n\t// Keep these useful ones\n\tif (key === \"_thumbnail_id\") return false;\n\tif (key.startsWith(\"_yoast_\")) return false;\n\tif (key.startsWith(\"_rank_math_\")) return false;\n\n\t// Other underscore prefixes are usually internal\n\tif (key.startsWith(\"_\")) return true;\n\n\treturn false;\n}\n\n// =============================================================================\n// Status Mapping\n// =============================================================================\n\n/** Valid WordPress statuses */\nexport type WpStatus = \"publish\" | \"draft\" | \"pending\" | \"private\" | \"future\";\n\n/**\n * Map WordPress status to normalized status\n */\nexport function mapWpStatus(status: string | undefined): WpStatus {\n\tswitch (status) {\n\t\tcase \"publish\":\n\t\t\treturn \"publish\";\n\t\tcase \"draft\":\n\t\t\treturn \"draft\";\n\t\tcase \"pending\":\n\t\t\treturn \"pending\";\n\t\tcase \"private\":\n\t\t\treturn \"private\";\n\t\tcase \"future\":\n\t\t\treturn \"future\";\n\t\tdefault:\n\t\t\treturn \"draft\";\n\t}\n}\n\n// =============================================================================\n// Collection Mapping\n// =============================================================================\n\n/** Default mappings from WordPress post types to EmDash collections */\nconst POST_TYPE_TO_COLLECTION: Record<string, string> = {\n\tpost: \"posts\",\n\tpage: \"pages\",\n\tattachment: \"media\",\n\tproduct: \"products\",\n\tportfolio: \"portfolio\",\n\ttestimonial: \"testimonials\",\n\tteam: \"team\",\n\tevent: \"events\",\n\tfaq: \"faqs\",\n};\n\n/**\n * Map WordPress post type to EmDash collection name\n */\nexport function mapPostTypeToCollection(postType: string): string {\n\treturn POST_TYPE_TO_COLLECTION[postType] || postType;\n}\n\n// =============================================================================\n// Meta Key Mapping\n// =============================================================================\n\n/**\n * Map WordPress meta key to EmDash field slug\n */\nexport function mapMetaKeyToField(key: string): string {\n\t// SEO plugins\n\tif (key === \"_yoast_wpseo_title\") return \"seo_title\";\n\tif (key === \"_yoast_wpseo_metadesc\") return \"seo_description\";\n\tif (key === \"_rank_math_title\") return \"seo_title\";\n\tif (key === \"_rank_math_description\") return \"seo_description\";\n\tif (key === \"_thumbnail_id\") return \"featured_image\";\n\n\t// Remove leading underscore\n\tif (key.startsWith(\"_\")) return key.slice(1);\n\n\treturn key;\n}\n\n/**\n * Infer field type from meta key name and sample value\n */\nexport function inferMetaType(\n\tkey: string,\n\tvalue: string | undefined,\n): \"string\" | \"number\" | \"boolean\" | \"date\" | \"json\" {\n\tif (key.endsWith(\"_id\") || key === \"_thumbnail_id\") return \"string\";\n\tif (key.endsWith(\"_date\") || key.endsWith(\"_time\")) return \"date\";\n\tif (key.endsWith(\"_count\") || key.endsWith(\"_number\")) return \"number\";\n\n\tif (!value) return \"string\";\n\n\t// Serialized PHP or JSON\n\tif (value.startsWith(\"a:\") || value.startsWith(\"{\") || value.startsWith(\"[\")) return \"json\";\n\n\t// Number\n\tif (NUMERIC_PATTERN.test(value)) return \"number\";\n\n\t// Boolean\n\tif ([\"0\", \"1\", \"true\", \"false\"].includes(value)) return \"boolean\";\n\n\treturn \"string\";\n}\n\n// =============================================================================\n// Plugin Bookkeeping Meta\n// =============================================================================\n\n/**\n * Meta prefixes written by well-known WordPress plugins as operational\n * bookkeeping (sync state, counters, cache keys) — not content. Without\n * this filter, a mature site's analysis suggests dozens of junk fields\n * per post type and the real content fields drown in them.\n *\n * ponytail: curated list of the plugins we've seen in the wild, not a\n * taxonomy of the WP ecosystem. Unknown plugins' meta still gets through;\n * extend the list as real sites surface new offenders.\n */\nconst PLUGIN_META_PREFIXES = [\n\t\"aawp_\", // AAWP (Amazon affiliate)\n\t\"algolia_\", // Algolia / WP Search with Algolia\n\t\"amazon_polly_\", // Amazon Polly\n\t\"ampforwp_\", // AMP for WP\n\t\"classifai_\", // ClassifAI\n\t\"essb_\", // Easy Social Share Buttons\n\t\"eg_\", // Essential Grid\n\t\"gnpub_\", // Google News publisher tools\n\t\"jetpack_\", // Jetpack\n\t\"mashsb_\", // MashShare\n\t\"monsterinsights_\", // MonsterInsights\n\t\"onesignal_\", // OneSignal push\n\t\"penci_\", // Penci themes\n\t\"perfmatters_\", // Perfmatters\n\t\"pys_\", // PixelYourSite\n\t\"rank_math_\", // Rank Math internals (title/description go through the SEO pass)\n\t\"rp4wp_\", // Related Posts for WP\n\t\"saswp_\", // Schema & Structured Data for WP\n\t\"sbg_\", // Simple Blog Grid\n\t\"snap_\", // SNAP auto-poster\n\t\"spay_\", // Simple Pay\n\t\"tie_\", // TieLabs themes\n\t\"wl_\", // WordLift\n\t\"wpil_\", // Link Whisper\n\t\"wprm_\", // WP Recipe Maker internals\n\t\"wpswa_\", // WP Search with Algolia\n\t\"wpuf_\", // WP User Frontend\n\t\"yarpp_\", // YARPP\n];\n\n/** Exact meta keys that are plugin/core bookkeeping, not content. */\nconst PLUGIN_META_KEYS = new Set([\n\t\"entity_same_as\", // WordLift\n\t\"exclude_from_search\", // search exclusion plugins\n\t\"footnotes\", // Gutenberg core footnotes store\n\t\"inline_featured_image\", // inline featured image plugin\n\t\"os_meta\", // theme option stores\n\t\"thirstydata\", // ThirstyAffiliates\n]);\n\n/**\n * Check whether a meta key is well-known plugin bookkeeping that should\n * not become a content field. Hyphens are normalized to underscores\n * before matching (e.g. `ampforwp-amp-on-off`).\n */\nexport function isPluginBookkeepingMeta(key: string): boolean {\n\tconst normalized = key.replaceAll(\"-\", \"_\");\n\tif (PLUGIN_META_KEYS.has(normalized)) return true;\n\treturn PLUGIN_META_PREFIXES.some((prefix) => normalized.startsWith(prefix));\n}\n\n// =============================================================================\n// Field Slug Sanitization\n// =============================================================================\n\nconst INVALID_FIELD_SLUG_CHARS = /[^a-z0-9_]+/g;\nconst LEADING_NON_ALPHA_CHARS = /^[^a-z]+/;\n\n/**\n * Sanitize a WordPress meta/ACF key into a valid EmDash field slug\n * (`/^[a-z][a-z0-9_]*$/`, max 63 chars, not reserved).\n *\n * Must be applied consistently on both sides of an import: once when\n * creating fields from the analysis, and again when matching incoming\n * meta keys onto schema fields — otherwise keys like `my-field` create\n * `my_field` but never receive values.\n */\nexport function sanitizeFieldSlug(key: string): string {\n\tconst sanitized = key\n\t\t.toLowerCase()\n\t\t.replace(INVALID_FIELD_SLUG_CHARS, \"_\")\n\t\t.replace(LEADING_NON_ALPHA_CHARS, \"\")\n\t\t.slice(0, 63);\n\tif (!sanitized) return \"field\";\n\tif (RESERVED_FIELD_SLUGS.includes(sanitized)) return `wp_${sanitized}`;\n\treturn sanitized;\n}\n\n// =============================================================================\n// Internal Link Relativization\n// =============================================================================\n\nconst REGEX_SPECIALS = /[.*+?^${}()|[\\]\\\\]/g;\nconst LEADING_WWW = /^www\\./;\n\n/**\n * Turn an absolute URL into a root-relative one when it points at the\n * source site (www-insensitive). Returns null when the URL should be\n * left alone: external links, non-http(s) schemes, and `/wp-content/`\n * media files — those stay absolute so the later media pass can match\n * them against its old-URL -> new-URL map.\n */\nfunction relativizeUrl(url: string, sourceHost: string): string | null {\n\tif (!url.startsWith(\"http://\") && !url.startsWith(\"https://\")) return null;\n\ttry {\n\t\tconst parsed = new URL(url);\n\t\tif (parsed.hostname.replace(LEADING_WWW, \"\") !== sourceHost) return null;\n\t\tif (parsed.pathname.startsWith(\"/wp-content/\")) return null;\n\t\treturn `${parsed.pathname}${parsed.search}${parsed.hash}` || \"/\";\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction relativizeMarkDefs(\n\tmarkDefs: Array<{ _type: string; [key: string]: unknown }> | undefined,\n\tsourceHost: string,\n): void {\n\tfor (const def of markDefs ?? []) {\n\t\tif (def._type === \"link\" && typeof def.href === \"string\") {\n\t\t\tdef.href = relativizeUrl(def.href, sourceHost) ?? def.href;\n\t\t}\n\t}\n}\n\n/**\n * Rewrite internal links in imported content to root-relative URLs, in\n * place. Without this, imported posts keep linking back to the old\n * WordPress domain (e.g. `https://oldsite.com/companies/google/`)\n * instead of staying on the new site.\n *\n * ponytail: path structures are kept as-is (WP permalink /2024/05/slug/\n * stays /2024/05/slug/) — mapping old paths onto the new site's routes\n * is the planned permalink->redirect-map feature.\n */\nexport function relativizeContentLinks(blocks: PortableTextBlock[], siteUrl: string): void {\n\tlet sourceHost: string;\n\ttry {\n\t\tsourceHost = new URL(siteUrl).hostname.replace(LEADING_WWW, \"\");\n\t} catch {\n\t\treturn;\n\t}\n\t// Raw HTML in the wild uses double-quoted, single-quoted, and unquoted\n\t// href values; the backreference \\1 matches the closing quote (or\n\t// nothing, for unquoted). Rewritten links are normalized to href=\"...\".\n\tconst hrefPattern = new RegExp(\n\t\t`href=([\"']?)https?://(?:www\\\\.)?${sourceHost.replace(REGEX_SPECIALS, \"\\\\$&\")}(/[^\"'\\\\s>]*)?\\\\1`,\n\t\t\"gi\",\n\t);\n\n\tfor (const block of blocks) {\n\t\tswitch (block._type) {\n\t\t\tcase \"block\":\n\t\t\t\trelativizeMarkDefs(block.markDefs, sourceHost);\n\t\t\t\tbreak;\n\t\t\tcase \"image\":\n\t\t\t\t// asset.url stays absolute (media pass), only the click-through link\n\t\t\t\tif (typeof block.link === \"string\") {\n\t\t\t\t\tblock.link = relativizeUrl(block.link, sourceHost) ?? block.link;\n\t\t\t\t} else if (block.link?.href) {\n\t\t\t\t\tblock.link = {\n\t\t\t\t\t\t...block.link,\n\t\t\t\t\t\thref: relativizeUrl(block.link.href, sourceHost) ?? block.link.href,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase \"table\":\n\t\t\t\tfor (const row of block.rows) {\n\t\t\t\t\tfor (const cell of row.cells) relativizeMarkDefs(cell.markDefs, sourceHost);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase \"columns\":\n\t\t\t\tfor (const column of block.columns) relativizeContentLinks(column.content, siteUrl);\n\t\t\t\tbreak;\n\t\t\tcase \"cover\":\n\t\t\t\trelativizeContentLinks(block.content, siteUrl);\n\t\t\t\tbreak;\n\t\t\tcase \"button\":\n\t\t\t\tif (block.url) block.url = relativizeUrl(block.url, sourceHost) ?? block.url;\n\t\t\t\tbreak;\n\t\t\tcase \"buttons\":\n\t\t\t\tfor (const button of block.buttons) {\n\t\t\t\t\tif (button.url) button.url = relativizeUrl(button.url, sourceHost) ?? button.url;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase \"htmlBlock\":\n\t\t\t\tblock.html = block.html.replace(\n\t\t\t\t\threfPattern,\n\t\t\t\t\t(match, _quote: string, path: string | undefined) =>\n\t\t\t\t\t\tpath?.startsWith(\"/wp-content/\") ? match : `href=\"${path || \"/\"}\"`,\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\t// URL-less or media-only blocks: media URLs are the media pass's job\n\t\t\tcase \"code\":\n\t\t\tcase \"embed\":\n\t\t\tcase \"gallery\":\n\t\t\tcase \"break\":\n\t\t\tcase \"file\":\n\t\t\tcase \"pullquote\":\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tblock satisfies never;\n\t\t}\n\t}\n}\n\n// =============================================================================\n// String Utilities\n// =============================================================================\n\nexport { slugify } from \"../utils/slugify.js\";\n\n/**\n * Normalize URL for API requests\n */\nexport function normalizeUrl(url: string): string {\n\tlet normalized = url.trim();\n\n\t// Add protocol if missing\n\tif (!normalized.startsWith(\"http\")) {\n\t\tnormalized = `https://${normalized}`;\n\t}\n\n\t// Remove trailing slash\n\tnormalized = normalized.replace(TRAILING_SLASHES, \"\");\n\n\t// Remove /wp-json if included\n\tnormalized = normalized.replace(WP_JSON_SUFFIX, \"\");\n\n\treturn normalized;\n}\n\n// =============================================================================\n// File Utilities\n// =============================================================================\n\n/**\n * Extract filename from URL\n */\nexport function getFilenameFromUrl(url: string): string | undefined {\n\ttry {\n\t\tconst parsed = new URL(url);\n\t\tconst segments = parsed.pathname.split(\"/\").filter(Boolean);\n\t\treturn segments.pop();\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Guess MIME type from filename\n */\nexport function guessMimeType(filename: string): string | undefined {\n\treturn mime.getType(filename) ?? undefined;\n}\n\n// =============================================================================\n// Attachment Map Builder\n// =============================================================================\n\n/**\n * Build a map of attachment IDs to URLs for resolving featured images\n */\nexport function buildAttachmentMap(\n\tattachments: Array<{ id?: number | string; url?: string }>,\n): Map<string, string> {\n\tconst map = new Map<string, string>();\n\tfor (const att of attachments) {\n\t\tif (att.id && att.url) {\n\t\t\tmap.set(String(att.id), att.url);\n\t\t}\n\t}\n\treturn map;\n}\n\n// =============================================================================\n// Schema Compatibility\n// =============================================================================\n\n/**\n * Check if two field types are compatible for import\n */\nexport function isTypeCompatible(requiredType: string, existingType: string): boolean {\n\tif (requiredType === existingType) return true;\n\n\tconst compatibleTypes: Record<string, string[]> = {\n\t\tstring: [\"string\", \"text\", \"slug\"],\n\t\ttext: [\"string\", \"text\"],\n\t\tportableText: [\"portableText\", \"json\"],\n\t\tnumber: [\"number\", \"integer\"],\n\t\tinteger: [\"number\", \"integer\"],\n\t};\n\n\tconst compatible = compatibleTypes[requiredType];\n\treturn compatible?.includes(existingType) ?? false;\n}\n\n// =============================================================================\n// Byline Import Utilities\n// =============================================================================\n\nimport type { BylineRepository } from \"../database/repositories/byline.js\";\nimport { slugify as slugifyFn } from \"../utils/slugify.js\";\n\nconst MAX_SLUG_COLLISION_ATTEMPTS = 1000;\n\n/**\n * Find or create a unique byline slug, capped at MAX_SLUG_COLLISION_ATTEMPTS.\n */\nexport async function ensureUniqueBylineSlug(\n\tbylineRepo: BylineRepository,\n\tbaseSlug: string,\n): Promise<string> {\n\tlet candidate = baseSlug;\n\tlet suffix = 2;\n\twhile (await bylineRepo.findBySlug(candidate)) {\n\t\tif (suffix > MAX_SLUG_COLLISION_ATTEMPTS) {\n\t\t\tthrow new Error(\n\t\t\t\t`Byline slug collision limit exceeded for base slug \"${baseSlug}\". ` +\n\t\t\t\t\t`Tried ${MAX_SLUG_COLLISION_ATTEMPTS} variants.`,\n\t\t\t);\n\t\t}\n\t\tcandidate = `${baseSlug}-${suffix}`;\n\t\tsuffix++;\n\t}\n\treturn candidate;\n}\n\n/**\n * Resolve (find-or-create) a byline for an imported WordPress author.\n * Caches results in `cache` keyed by `authorLogin:mappedUserId`.\n */\nexport async function resolveImportByline(\n\tauthorLogin: string | undefined,\n\tdisplayName: string | undefined,\n\tmappedUserId: string | undefined,\n\tbylineRepo: BylineRepository,\n\tcache: Map<string, string>,\n): Promise<string | undefined> {\n\tif (!authorLogin) return undefined;\n\tconst cacheKey = `${authorLogin}:${mappedUserId ?? \"\"}`;\n\tconst cached = cache.get(cacheKey);\n\tif (cached) return cached;\n\n\tif (mappedUserId) {\n\t\tconst existingForUser = await bylineRepo.findByUserId(mappedUserId);\n\t\tif (existingForUser) {\n\t\t\tcache.set(cacheKey, existingForUser.id);\n\t\t\treturn existingForUser.id;\n\t\t}\n\t}\n\n\tconst name = displayName || authorLogin;\n\tconst slugBase = slugifyFn(authorLogin);\n\tconst slug = await ensureUniqueBylineSlug(bylineRepo, slugBase || \"author\");\n\tconst created = await bylineRepo.create({\n\t\tslug,\n\t\tdisplayName: name,\n\t\tuserId: mappedUserId ?? null,\n\t\tisGuest: !mappedUserId,\n\t});\n\n\tcache.set(cacheKey, created.id);\n\treturn created.id;\n}\n\n// =============================================================================\n// Schema Compatibility\n// =============================================================================\n\n/**\n * Check schema compatibility between required fields and existing collection\n */\nexport function checkSchemaCompatibility(\n\trequiredFields: ImportFieldDef[],\n\texistingCollection: { slug: string; fields: Map<string, { type: string }> } | undefined,\n): CollectionSchemaStatus {\n\tif (!existingCollection) {\n\t\t// Collection doesn't exist - will need to create it\n\t\tconst fieldStatus: CollectionSchemaStatus[\"fieldStatus\"] = {};\n\t\tfor (const field of requiredFields) {\n\t\t\tfieldStatus[field.slug] = {\n\t\t\t\tstatus: \"missing\",\n\t\t\t\trequiredType: field.type,\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\texists: false,\n\t\t\tfieldStatus,\n\t\t\tcanImport: true,\n\t\t};\n\t}\n\n\t// Collection exists - check field compatibility\n\tconst fieldStatus: CollectionSchemaStatus[\"fieldStatus\"] = {};\n\tconst incompatibleFields: string[] = [];\n\n\tfor (const field of requiredFields) {\n\t\tconst existingField = existingCollection.fields.get(field.slug);\n\n\t\tif (!existingField) {\n\t\t\tfieldStatus[field.slug] = {\n\t\t\t\tstatus: \"missing\",\n\t\t\t\trequiredType: field.type,\n\t\t\t};\n\t\t} else if (isTypeCompatible(field.type, existingField.type)) {\n\t\t\tfieldStatus[field.slug] = {\n\t\t\t\tstatus: \"compatible\",\n\t\t\t\texistingType: existingField.type,\n\t\t\t\trequiredType: field.type,\n\t\t\t};\n\t\t} else {\n\t\t\tfieldStatus[field.slug] = {\n\t\t\t\tstatus: \"type_mismatch\",\n\t\t\t\texistingType: existingField.type,\n\t\t\t\trequiredType: field.type,\n\t\t\t};\n\t\t\tincompatibleFields.push(field.slug);\n\t\t}\n\t}\n\n\tconst canImport = incompatibleFields.length === 0;\n\tconst reason = canImport\n\t\t? undefined\n\t\t: `Incompatible field types: ${incompatibleFields.join(\", \")}`;\n\n\treturn {\n\t\texists: true,\n\t\tfieldStatus,\n\t\tcanImport,\n\t\treason,\n\t};\n}\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QAAU,YAAY,IAC2B,SAAS;CAC3E,MAAM,UAAU,MAAM,WAAW,OAAO;EACvC;EACA,aAAa;EACb,QAAQ,gBAAgB;EACxB,SAAS,CAAC;EACV,CAAC;AAEF,OAAM,IAAI,UAAU,QAAQ,GAAG;AAC/B,QAAO,QAAQ;;;;;AAUhB,SAAgB,yBACf,gBACA,oBACyB;AACzB,KAAI,CAAC,oBAAoB;EAExB,MAAM,cAAqD,EAAE;AAC7D,OAAK,MAAM,SAAS,eACnB,aAAY,MAAM,QAAQ;GACzB,QAAQ;GACR,cAAc,MAAM;GACpB;AAEF,SAAO;GACN,QAAQ;GACR;GACA,WAAW;GACX;;CAIF,MAAM,cAAqD,EAAE;CAC7D,MAAM,qBAA+B,EAAE;AAEvC,MAAK,MAAM,SAAS,gBAAgB;EACnC,MAAM,gBAAgB,mBAAmB,OAAO,IAAI,MAAM,KAAK;AAE/D,MAAI,CAAC,cACJ,aAAY,MAAM,QAAQ;GACzB,QAAQ;GACR,cAAc,MAAM;GACpB;WACS,iBAAiB,MAAM,MAAM,cAAc,KAAK,CAC1D,aAAY,MAAM,QAAQ;GACzB,QAAQ;GACR,cAAc,cAAc;GAC5B,cAAc,MAAM;GACpB;OACK;AACN,eAAY,MAAM,QAAQ;IACzB,QAAQ;IACR,cAAc,cAAc;IAC5B,cAAc,MAAM;IACpB;AACD,sBAAmB,KAAK,MAAM,KAAK;;;CAIrC,MAAM,YAAY,mBAAmB,WAAW;AAKhD,QAAO;EACN,QAAQ;EACR;EACA;EACA,QARc,YACZ,SACA,6BAA6B,mBAAmB,KAAK,KAAK;EAO5D"}
@@ -1,7 +0,0 @@
1
- //#region src/version.ts
2
- const VERSION = "1.3.0";
3
- const COMMIT = "d10d7ae1b";
4
-
5
- //#endregion
6
- export { VERSION as n, COMMIT as t };
7
- //# sourceMappingURL=version-DHmGpcch.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"widgets-DA5XmvVC.mjs","names":["getComponentRegistry"],"sources":["../src/widgets/index.ts"],"sourcesContent":["import type { Kysely } from \"kysely\";\n\nimport { widgetAreaTag } from \"../cache/chrome-tags.js\";\nimport type { Database } from \"../database/types.js\";\nimport { getDb } from \"../loader.js\";\nimport type { CacheHint } from \"../query.js\";\nimport { peekRequestCache, requestCached } from \"../request-cache.js\";\nimport { getWidgetComponents as getComponentRegistry } from \"./components.js\";\nimport type { Widget, WidgetArea, WidgetRow, WidgetComponentDef } from \"./types.js\";\n\nexport type {\n\tWidget,\n\tWidgetArea,\n\tWidgetType,\n\tWidgetComponentDef,\n\tPropDef,\n\tCreateWidgetAreaInput,\n\tCreateWidgetInput,\n\tUpdateWidgetInput,\n\tReorderWidgetsInput,\n} from \"./types.js\";\n\n/**\n * Get a widget area by name, with all its widgets.\n */\nexport async function getWidgetArea(name: string): Promise<WidgetArea | null> {\n\treturn requestCached(`widget-area:${name}`, async () => {\n\t\tconst prefetched = peekRequestCache<WidgetArea[]>(\"widget-areas\");\n\t\tif (prefetched) {\n\t\t\ttry {\n\t\t\t\tconst areas = await prefetched;\n\t\t\t\treturn areas.find((area) => area.name === name) ?? null;\n\t\t\t} catch {\n\t\t\t\t// Optional prefetch failure must still allow the scoped read.\n\t\t\t}\n\t\t}\n\n\t\tconst db = await getDb();\n\t\tconst rows = await selectAreasWithWidgets(db)\n\t\t\t.where(\"a.name\", \"=\", name)\n\t\t\t.orderBy(\"w.sort_order\", \"asc\")\n\t\t\t.execute();\n\t\treturn groupAreaRows(rows)[0] ?? null;\n\t});\n}\n\n/**\n * Areas left-joined with their widgets, so areas and widgets load in one\n * round trip. An area with no widgets yields one row with null widget columns.\n */\nfunction selectAreasWithWidgets(db: Kysely<Database>) {\n\treturn db\n\t\t.selectFrom(\"_emdash_widget_areas as a\")\n\t\t.leftJoin(\"_emdash_widgets as w\", \"w.area_id\", \"a.id\")\n\t\t.select([\n\t\t\t\"a.id as a_id\",\n\t\t\t\"a.name as a_name\",\n\t\t\t\"a.label as a_label\",\n\t\t\t\"a.description as a_description\",\n\t\t\t\"w.id as w_id\",\n\t\t\t\"w.type as w_type\",\n\t\t\t\"w.title as w_title\",\n\t\t\t\"w.content as w_content\",\n\t\t\t\"w.menu_name as w_menu_name\",\n\t\t\t\"w.component_id as w_component_id\",\n\t\t\t\"w.component_props as w_component_props\",\n\t\t\t\"w.area_id as w_area_id\",\n\t\t\t\"w.sort_order as w_sort_order\",\n\t\t\t\"w.created_at as w_created_at\",\n\t\t]);\n}\n\ntype AreaWidgetRow = Awaited<\n\tReturnType<ReturnType<typeof selectAreasWithWidgets>[\"execute\"]>\n>[number];\n\n/** Group joined rows into areas, keeping row order for areas and widgets. */\nfunction groupAreaRows(rows: AreaWidgetRow[]): WidgetArea[] {\n\tconst areas = new Map<string, WidgetArea>();\n\tfor (const row of rows) {\n\t\tlet area = areas.get(row.a_id);\n\t\tif (!area) {\n\t\t\tarea = {\n\t\t\t\tid: row.a_id,\n\t\t\t\tname: row.a_name,\n\t\t\t\tlabel: row.a_label,\n\t\t\t\tdescription: row.a_description ?? undefined,\n\t\t\t\twidgets: [],\n\t\t\t};\n\t\t\tareas.set(row.a_id, area);\n\t\t}\n\t\tif (row.w_id === null) continue;\n\t\t// Every w_* column is non-null whenever w_id is set.\n\t\t// eslint-disable-next-line typescript/no-unsafe-type-assertion -- left-join row is non-null when w_id is set; see above\n\t\tconst widgetRow = {\n\t\t\tid: row.w_id,\n\t\t\ttype: row.w_type,\n\t\t\ttitle: row.w_title,\n\t\t\tcontent: row.w_content,\n\t\t\tmenu_name: row.w_menu_name,\n\t\t\tcomponent_id: row.w_component_id,\n\t\t\tcomponent_props: row.w_component_props,\n\t\t\tarea_id: row.w_area_id,\n\t\t\tsort_order: row.w_sort_order,\n\t\t\tcreated_at: row.w_created_at,\n\t\t} as WidgetRow;\n\t\tarea.widgets.push(rowToWidget(widgetRow));\n\t}\n\treturn [...areas.values()];\n}\n\n/**\n * Get a widget area by name with a Workers edge-cache hint.\n *\n * Use the returned `cacheHint` with `Astro.cache.set()` so pages that render\n * this widget area can be purged automatically when its widgets change.\n */\nexport async function getWidgetAreaWithCacheHint(name: string): Promise<{\n\tdata: WidgetArea | null;\n\tcacheHint: CacheHint;\n}> {\n\tconst data = await getWidgetArea(name);\n\treturn { data, cacheHint: { tags: [widgetAreaTag(name)] } };\n}\n\n/**\n * Get all widget areas with their widgets\n */\nexport async function getWidgetAreas(): Promise<WidgetArea[]> {\n\tconst db = await getDb();\n\tconst rows = await selectAreasWithWidgets(db)\n\t\t.orderBy(\"a.created_at\", \"asc\")\n\t\t.orderBy(\"a.id\", \"asc\")\n\t\t.orderBy(\"w.sort_order\", \"asc\")\n\t\t.execute();\n\treturn groupAreaRows(rows);\n}\n\n/**\n * Get available widget components (for admin UI)\n */\nexport function getWidgetComponents(): WidgetComponentDef[] {\n\treturn getComponentRegistry();\n}\n\n/**\n * Convert a widget row to the API type\n */\nexport function rowToWidget(row: WidgetRow): Widget {\n\tconst widget: Widget = {\n\t\tid: row.id,\n\t\ttype: row.type,\n\t\ttitle: row.title ?? undefined,\n\t};\n\n\t// Type-specific fields\n\tif (row.type === \"content\" && row.content) {\n\t\ttry {\n\t\t\twidget.content = JSON.parse(row.content);\n\t\t} catch {\n\t\t\t// Invalid JSON, ignore\n\t\t}\n\t}\n\n\tif (row.type === \"menu\" && row.menu_name) {\n\t\twidget.menuName = row.menu_name;\n\t}\n\n\tif (row.type === \"component\" && row.component_id) {\n\t\twidget.componentId = row.component_id;\n\t\tif (row.component_props) {\n\t\t\ttry {\n\t\t\t\twidget.componentProps = JSON.parse(row.component_props);\n\t\t\t} catch {\n\t\t\t\t// Invalid JSON, ignore\n\t\t\t}\n\t\t}\n\t}\n\n\treturn widget;\n}\n"],"mappings":";;;;;;;;;AAyBA,eAAsB,cAAc,MAA0C;AAC7E,QAAO,cAAc,eAAe,QAAQ,YAAY;EACvD,MAAM,aAAa,iBAA+B,eAAe;AACjE,MAAI,WACH,KAAI;AAEH,WADc,MAAM,YACP,MAAM,SAAS,KAAK,SAAS,KAAK,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QAAQ,MAAM,CACtB,QAAQ,gBAAgB,MAAM,CAC9B,SAAS,CACe;;;;;AAM3B,SAAgB,sBAA4C;AAC3D,QAAOA,uBAAsB;;;;;AAM9B,SAAgB,YAAY,KAAwB;CACnD,MAAM,SAAiB;EACtB,IAAI,IAAI;EACR,MAAM,IAAI;EACV,OAAO,IAAI,SAAS;EACpB;AAGD,KAAI,IAAI,SAAS,aAAa,IAAI,QACjC,KAAI;AACH,SAAO,UAAU,KAAK,MAAM,IAAI,QAAQ;SACjC;AAKT,KAAI,IAAI,SAAS,UAAU,IAAI,UAC9B,QAAO,WAAW,IAAI;AAGvB,KAAI,IAAI,SAAS,eAAe,IAAI,cAAc;AACjD,SAAO,cAAc,IAAI;AACzB,MAAI,IAAI,gBACP,KAAI;AACH,UAAO,iBAAiB,KAAK,MAAM,IAAI,gBAAgB;UAChD;;AAMV,QAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"wxr-taxonomies-CrMonejI.d.mts","names":[],"sources":["../src/import/wxr-taxonomies.ts"],"mappings":";;;;;;UAiEiB,kBAAA;;EAEhB,YAAA,EAAc,MAAA;;EAEd,WAAA,EAAa,MAAA;;EAEb,iBAAA;;;;;EAKA,mBAAA,EAAqB,GAAA,SAAY,GAAA;;;;;;EAMjC,qBAAA,EAAuB,GAAA,SAAY,GAAA;;;;;;EAMnC,wBAAA,EAA0B,GAAA;AAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"wxr-taxonomies-RgRG0d5e.mjs","names":[],"sources":["../src/import/wxr-taxonomies.ts"],"sourcesContent":["/**\n * WXR taxonomy import helpers.\n *\n * Bridges parsed WordPress taxonomy data (`WxrCategory`, `WxrTag`, `WxrTerm`,\n * and per-item `WxrPost.categories` / `WxrPost.tags` / `WxrPost.customTaxonomies`)\n * onto EmDash's term + content_taxonomies tables.\n *\n * Why this isn't inline in `execute.ts`: pre-creating all terms before any\n * post is created lets us (a) build a lookup once for every (taxonomy, slug)\n * the import needs, and (b) keep the per-post attachment loop cheap. It also\n * makes the logic testable without spinning up an Astro request.\n *\n * Behaviour:\n * - `wp:category` -> EmDash `category` taxonomy (seeded by migration 006).\n * - `wp:tag` -> EmDash `tag` taxonomy.\n * - `wp:term` -> matching EmDash taxonomy by `name` (case-sensitive).\n * If the taxonomy isn't defined in any locale, the\n * term is skipped — we don't auto-create defs because\n * the user controls their schema through the admin.\n * - Terms are created idempotently by `(taxonomy, slug, locale)`. Existing\n * terms are reused.\n * - Assignments respect the def's `collections` array. If the post's target\n * collection isn't listed on the taxonomy def, the assignment is skipped\n * (matches admin UI behaviour: you can't tag a \"products\" post with a\n * \"category\" if `category.collections` only includes \"posts\").\n */\n\nimport type { Kysely } from \"kysely\";\n\nimport type { WxrCategory, WxrPost, WxrTag, WxrTerm } from \"../cli/wxr/parser.js\";\nimport {\n\tfindTaxonomyStructure,\n\tselectTaxonomyDefs,\n} from \"../database/repositories/taxonomy-def.js\";\nimport { TaxonomyRepository } from \"../database/repositories/taxonomy.js\";\nimport type { Database } from \"../database/types.js\";\nimport { invalidateTermCache } from \"../taxonomies/index.js\";\n\n/**\n * Thrown by `mirrorTermsToLocales` when a pre-existing locale row at the\n * same `(taxonomy, slug)` belongs to a different `translation_group` than\n * the canonical term. Callers in the route layer surface\n * `publicMessage` to the operator (no internal data) while logging\n * `cause` server-side.\n *\n * Marker class so the route layer can distinguish \"operator-actionable\n * taxonomy conflict\" from any other DB / repository error that might\n * escape the helper.\n */\nexport class WxrTaxonomyConflictError extends Error {\n\treadonly publicMessage: string;\n\tconstructor(publicMessage: string, options?: { cause?: unknown }) {\n\t\tsuper(publicMessage, options);\n\t\tthis.name = \"WxrTaxonomyConflictError\";\n\t\tthis.publicMessage = publicMessage;\n\t}\n}\n\nexport function isWxrTaxonomyConflictError(error: unknown): error is WxrTaxonomyConflictError {\n\treturn error instanceof WxrTaxonomyConflictError;\n}\n\n/**\n * Result of pre-importing taxonomy terms from a WXR file.\n */\nexport interface TaxonomyImportPlan {\n\t/** terms created during this run (per taxonomy name) */\n\ttermsCreated: Record<string, number>;\n\t/** terms that already existed and were reused (per taxonomy name) */\n\ttermsReused: Record<string, number>;\n\t/** custom taxonomies (`wp:term`) skipped because no matching EmDash def exists */\n\tmissingTaxonomies: string[];\n\t/**\n\t * Lookup table: `taxonomy name` -> `term slug` -> term id.\n\t * Used by `attachPostTaxonomies` to translate WXR assignments into pivot rows.\n\t */\n\ttermIdByNameAndSlug: Map<string, Map<string, string>>;\n\t/**\n\t * Lookup table: `taxonomy name` -> set of collection slugs the def allows.\n\t * Empty (or missing) means \"any collection\" — we only enforce the filter\n\t * when the def explicitly lists collections.\n\t */\n\tcollectionsByTaxonomy: Map<string, Set<string>>;\n\t/**\n\t * Lookup table: `term id` -> the term's `translation_group` (or `null`\n\t * if the term doesn't exist any more). Populated lazily by helpers that\n\t * need to check pivot existence without repeating per-term DB reads.\n\t */\n\ttranslationGroupByTermId: Map<string, string | null>;\n}\n\n/**\n * Track running counts plus the lookup maps.\n */\ninterface TaxonomyImportState {\n\tplan: TaxonomyImportPlan;\n}\n\nfunction makeState(): TaxonomyImportState {\n\treturn {\n\t\tplan: {\n\t\t\ttermsCreated: {},\n\t\t\ttermsReused: {},\n\t\t\tmissingTaxonomies: [],\n\t\t\ttermIdByNameAndSlug: new Map(),\n\t\t\tcollectionsByTaxonomy: new Map(),\n\t\t\ttranslationGroupByTermId: new Map(),\n\t\t},\n\t};\n}\n\n/**\n * Record-keeping helpers — keep mutations centralised so the result object\n * stays consistent.\n */\nfunction bump(record: Record<string, number>, key: string): void {\n\trecord[key] = (record[key] ?? 0) + 1;\n}\n\nfunction rememberTerm(\n\tstate: TaxonomyImportState,\n\ttaxonomyName: string,\n\tslug: string,\n\ttermId: string,\n): void {\n\tlet bySlug = state.plan.termIdByNameAndSlug.get(taxonomyName);\n\tif (!bySlug) {\n\t\tbySlug = new Map();\n\t\tstate.plan.termIdByNameAndSlug.set(taxonomyName, bySlug);\n\t}\n\tbySlug.set(slug, termId);\n}\n\nfunction parseDefCollections(raw: string | null): string[] {\n\tif (!raw) return [];\n\ttry {\n\t\tconst parsed: unknown = JSON.parse(raw);\n\t\tif (Array.isArray(parsed)) {\n\t\t\treturn parsed.filter((c): c is string => typeof c === \"string\");\n\t\t}\n\t} catch {\n\t\t// malformed JSON in the def -- treat as \"no collection filter\"\n\t}\n\treturn [];\n}\n\n/**\n * Rebuild the taxonomy lookup maps from the database without creating\n * anything. The chunked WP import runs term creation once (first content\n * chunk); every later chunk only needs the maps to attach per-post\n * assignments, and two SELECTs are far cheaper than re-walking every term\n * through the ensure path.\n *\n * ponytail: first row wins per (name, slug), ordered by locale asc — the\n * same row `findBySlug` without a locale resolves to. Per-locale term\n * variants beyond that are the mirror pass's job, not the importer's.\n */\nexport async function loadTaxonomyPlanFromDb(db: Kysely<Database>): Promise<TaxonomyImportPlan> {\n\tconst state = makeState();\n\n\tconst defs = await selectTaxonomyDefs(db).orderBy(\"d.locale\", \"asc\").execute();\n\tfor (const def of defs) {\n\t\tif (!state.plan.collectionsByTaxonomy.has(def.name)) {\n\t\t\tstate.plan.collectionsByTaxonomy.set(def.name, new Set(parseDefCollections(def.collections)));\n\t\t}\n\t}\n\n\tconst terms = await db\n\t\t.selectFrom(\"taxonomies\")\n\t\t.select([\"name\", \"slug\", \"id\"])\n\t\t.orderBy(\"locale\", \"asc\")\n\t\t.execute();\n\tfor (const term of terms) {\n\t\tif (!state.plan.termIdByNameAndSlug.get(term.name)?.has(term.slug)) {\n\t\t\trememberTerm(state, term.name, term.slug, term.id);\n\t\t}\n\t}\n\n\treturn state.plan;\n}\n\ninterface TermDescriptor {\n\ttaxonomyName: string;\n\tslug: string;\n\tlabel: string;\n\tdescription?: string;\n}\n\nfunction termKey(taxonomyName: string, slug: string): string {\n\treturn `${taxonomyName}\\u0000${slug}`;\n}\n\n/**\n * Find or create many terms in a small number of batched SELECTs instead of\n * one SELECT per term. This is the dominant fixed cost for WXR imports with\n * large category/tag vocabularies: a site with 100+ categories would otherwise\n * spend one D1 round-trip per category before writing any posts.\n *\n * Batching rules:\n * - Descriptors already resolved in `state.plan.termIdByNameAndSlug` are\n * skipped (same idempotency as the old per-term loop).\n * - Remaining descriptors are deduplicated by `(taxonomy, slug)`; the first\n * label/description seen wins, matching the old behaviour where the first\n * `ensureTerm` call cached the id.\n * - One batched SELECT resolves existing rows at the requested locale.\n * - One batched SELECT resolves any-locale rows for use as `translationOf`.\n * - Missing rows are still created one at a time because each insert needs\n * its own ULID/translation_group/sort_order bookkeeping, but the reads are\n * where the round-trip bottleneck lives.\n */\nasync function ensureTermsBatch(\n\tdb: Kysely<Database>,\n\tstate: TaxonomyImportState,\n\tdescriptors: TermDescriptor[],\n\tlocale: string | undefined,\n): Promise<void> {\n\tif (descriptors.length === 0) return;\n\n\tconst repo = new TaxonomyRepository(db);\n\n\tconst needed: TermDescriptor[] = [];\n\tconst seenKeys = new Set<string>();\n\tfor (const d of descriptors) {\n\t\tif (state.plan.termIdByNameAndSlug.get(d.taxonomyName)?.has(d.slug)) continue;\n\t\tconst key = termKey(d.taxonomyName, d.slug);\n\t\tif (seenKeys.has(key)) continue;\n\t\tseenKeys.add(key);\n\t\tneeded.push(d);\n\t}\n\tif (needed.length === 0) return;\n\n\t// Resolve existing rows at the requested locale in one round-trip.\n\tconst existingAtLocale = await findExistingTerms(db, needed, locale);\n\tfor (const row of existingAtLocale) {\n\t\tbump(state.plan.termsReused, row.name);\n\t\trememberTerm(state, row.name, row.slug, row.id);\n\t}\n\n\t// Build the list of descriptors that still need creation.\n\tconst stillNeeded: TermDescriptor[] = [];\n\tfor (const d of needed) {\n\t\tif (!state.plan.termIdByNameAndSlug.get(d.taxonomyName)?.has(d.slug)) {\n\t\t\tstillNeeded.push(d);\n\t\t}\n\t}\n\tif (stillNeeded.length === 0) return;\n\n\t// Resolve any-locale rows once for translationOf linking.\n\tconst anyLocaleRows = await findExistingTerms(db, stillNeeded, undefined);\n\tconst translationOfByKey = new Map<string, string>();\n\tfor (const row of anyLocaleRows) {\n\t\tconst key = termKey(row.name, row.slug);\n\t\tif (!translationOfByKey.has(key)) translationOfByKey.set(key, row.id);\n\t}\n\n\tfor (const d of stillNeeded) {\n\t\tconst created = await repo.create({\n\t\t\tname: d.taxonomyName,\n\t\t\tslug: d.slug,\n\t\t\tlabel: d.label,\n\t\t\tdata: d.description ? { description: d.description } : undefined,\n\t\t\tlocale,\n\t\t\ttranslationOf: translationOfByKey.get(termKey(d.taxonomyName, d.slug)),\n\t\t});\n\t\tbump(state.plan.termsCreated, d.taxonomyName);\n\t\trememberTerm(state, d.taxonomyName, d.slug, created.id);\n\t}\n}\n\n/**\n * Batched lookup of term rows for a list of `(taxonomy, slug)` pairs.\n * Chunks at `SQL_BATCH_SIZE / 2` because each pair consumes two bind\n * parameters (`name` and `slug`). When `locale` is omitted, returns rows\n * for all locales ordered by locale ascending so callers can pick the first\n * row per pair (mirroring `TaxonomyRepository.findBySlug` without a locale\n * argument).\n */\nasync function findExistingTerms(\n\tdb: Kysely<Database>,\n\tdescriptors: TermDescriptor[],\n\tlocale: string | undefined,\n): Promise<Array<{ id: string; name: string; slug: string }>> {\n\tconst { chunks, SQL_BATCH_SIZE } = await import(\"../utils/chunks.js\");\n\tconst rows: Array<{ id: string; name: string; slug: string }> = [];\n\tconst seenKeys = new Set<string>();\n\n\t// Each pair uses 2 bind params, so limit each batch to SQL_BATCH_SIZE / 2 pairs.\n\tfor (const batch of chunks(descriptors, Math.floor(SQL_BATCH_SIZE / 2))) {\n\t\tconst batchRows = await db\n\t\t\t.selectFrom(\"taxonomies\")\n\t\t\t.select([\"id\", \"name\", \"slug\"])\n\t\t\t.where((eb) =>\n\t\t\t\teb.or(batch.map((d) => eb.and([eb(\"name\", \"=\", d.taxonomyName), eb(\"slug\", \"=\", d.slug)]))),\n\t\t\t)\n\t\t\t.$if(locale !== undefined, (qb) => qb.where(\"locale\", \"=\", locale!))\n\t\t\t.orderBy(\"locale\", \"asc\")\n\t\t\t.execute();\n\n\t\tfor (const row of batchRows) {\n\t\t\tconst key = termKey(row.name, row.slug);\n\t\t\tif (seenKeys.has(key)) continue;\n\t\t\tseenKeys.add(key);\n\t\t\trows.push(row);\n\t\t}\n\t}\n\n\treturn rows;\n}\n\n/**\n * Retrieve the human label captured by the parser for a per-item\n * `<category>` text body, falling back to the slug when the parser didn't\n * see a label (e.g. self-closing tags or whitespace-only bodies).\n */\nfunction labelFor(post: WxrPost, taxonomy: string, slug: string): string {\n\tconst key = `${taxonomy}\\u0000${slug}`;\n\treturn post.taxonomyLabels?.get(key) ?? slug;\n}\n\n/**\n * Pre-import every term referenced by the WXR file.\n *\n * Pass 1: `wp:category` blocks. Each becomes a term in EmDash's seeded\n * `category` taxonomy.\n * Pass 2: `wp:tag` blocks. Each becomes a term in `tag`.\n * Pass 3: `wp:term` blocks (custom taxonomies). Skipped when no matching\n * EmDash def exists.\n * Pass 4: per-item `<category domain=\"…\" nicename=\"…\">` assignments. WXR\n * exports sometimes reference taxonomies/terms that weren't declared\n * at the top level (older exports especially), so we backfill terms\n * from per-item assignments. Categories and tags use the seeded defs\n * and pick up the assignment text as the label; custom domains fall\n * back to the same \"def must exist\" rule.\n */\nexport async function preImportWxrTaxonomies(\n\tdb: Kysely<Database>,\n\tposts: WxrPost[],\n\tcategories: WxrCategory[],\n\ttags: WxrTag[],\n\tterms: WxrTerm[],\n\tlocale: string | undefined,\n): Promise<TaxonomyImportPlan> {\n\tconst state = makeState();\n\n\t// Cache def lookups for the duration of the import. Keyed by name; value\n\t// is `null` when we've already determined the taxonomy is missing (so we\n\t// only report the \"missing\" warning once per taxonomy).\n\tconst defCache = new Map<string, { id: string; collections: string[] } | null>();\n\tconst lookupDef = async (name: string): Promise<{ id: string; collections: string[] } | null> => {\n\t\tif (defCache.has(name)) return defCache.get(name) ?? null;\n\t\t// A taxonomy's structure is the same in every locale, so a definition in\n\t\t// any locale counts, as it does for the runtime's `getTaxonomyDef`.\n\t\tconst def = await findTaxonomyStructure(db, name);\n\t\tdefCache.set(name, def);\n\t\tif (def) {\n\t\t\tstate.plan.collectionsByTaxonomy.set(name, new Set(def.collections));\n\t\t}\n\t\treturn def;\n\t};\n\n\t// Pass 1-3: collect every term declared at the top of the WXR, then\n\t// resolve them in a few batched queries instead of one round-trip per term.\n\tconst categoryDef = await lookupDef(\"category\");\n\tconst tagDef = await lookupDef(\"tag\");\n\tconst topLevel: TermDescriptor[] = [];\n\n\tif (categoryDef) {\n\t\tfor (const cat of categories) {\n\t\t\tif (!cat.nicename || !cat.name) continue;\n\t\t\ttopLevel.push({\n\t\t\t\ttaxonomyName: \"category\",\n\t\t\t\tslug: cat.nicename,\n\t\t\t\tlabel: cat.name,\n\t\t\t\tdescription: cat.description,\n\t\t\t});\n\t\t}\n\t} else if (categories.length > 0) {\n\t\tstate.plan.missingTaxonomies.push(\"category\");\n\t}\n\n\tif (tagDef) {\n\t\tfor (const tag of tags) {\n\t\t\tif (!tag.slug || !tag.name) continue;\n\t\t\ttopLevel.push({\n\t\t\t\ttaxonomyName: \"tag\",\n\t\t\t\tslug: tag.slug,\n\t\t\t\tlabel: tag.name,\n\t\t\t\tdescription: tag.description,\n\t\t\t});\n\t\t}\n\t} else if (tags.length > 0) {\n\t\tstate.plan.missingTaxonomies.push(\"tag\");\n\t}\n\n\tfor (const term of terms) {\n\t\tif (term.taxonomy === \"nav_menu\" || term.taxonomy === \"language\") continue;\n\t\t// Normalize WordPress' `post_tag` synonym -> EmDash `tag`. WordPress\n\t\t// emits `<wp:tag>` for some exports and `<wp:term wp:term_taxonomy=\"post_tag\">`\n\t\t// for others; both must land in the same EmDash taxonomy.\n\t\tconst taxonomyName = term.taxonomy === \"post_tag\" ? \"tag\" : term.taxonomy;\n\t\tconst def = await lookupDef(taxonomyName);\n\t\tif (!def) {\n\t\t\tif (!state.plan.missingTaxonomies.includes(taxonomyName)) {\n\t\t\t\tstate.plan.missingTaxonomies.push(taxonomyName);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\ttopLevel.push({\n\t\t\ttaxonomyName,\n\t\t\tslug: term.slug,\n\t\t\tlabel: term.name,\n\t\t\tdescription: term.description,\n\t\t});\n\t}\n\n\tawait ensureTermsBatch(db, state, topLevel, locale);\n\n\t// Pass 4: per-item assignments. Backfills terms missing from the top-\n\t// level blocks (rare, but observed in hand-edited or partial exports).\n\t// Collect every assignment first so we can batch-resolve them too.\n\tconst fromPosts: TermDescriptor[] = [];\n\tlet recordedMissingCategoryFromPosts = false;\n\tlet recordedMissingTagFromPosts = false;\n\n\tfor (const post of posts) {\n\t\tfor (const slug of post.categories) {\n\t\t\tif (!categoryDef) {\n\t\t\t\tif (\n\t\t\t\t\t!recordedMissingCategoryFromPosts &&\n\t\t\t\t\t!state.plan.missingTaxonomies.includes(\"category\")\n\t\t\t\t) {\n\t\t\t\t\tstate.plan.missingTaxonomies.push(\"category\");\n\t\t\t\t\trecordedMissingCategoryFromPosts = true;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (state.plan.termIdByNameAndSlug.get(\"category\")?.has(slug)) continue;\n\t\t\tfromPosts.push({\n\t\t\t\ttaxonomyName: \"category\",\n\t\t\t\tslug,\n\t\t\t\tlabel: labelFor(post, \"category\", slug),\n\t\t\t});\n\t\t}\n\t\tfor (const slug of post.tags) {\n\t\t\tif (!tagDef) {\n\t\t\t\tif (!recordedMissingTagFromPosts && !state.plan.missingTaxonomies.includes(\"tag\")) {\n\t\t\t\t\tstate.plan.missingTaxonomies.push(\"tag\");\n\t\t\t\t\trecordedMissingTagFromPosts = true;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (state.plan.termIdByNameAndSlug.get(\"tag\")?.has(slug)) continue;\n\t\t\tfromPosts.push({\n\t\t\t\ttaxonomyName: \"tag\",\n\t\t\t\tslug,\n\t\t\t\tlabel: labelFor(post, \"tag\", slug),\n\t\t\t});\n\t\t}\n\t\tif (post.customTaxonomies) {\n\t\t\tfor (const [rawName, slugs] of post.customTaxonomies) {\n\t\t\t\tif (rawName === \"nav_menu\" || rawName === \"language\") continue;\n\t\t\t\tconst taxonomyName = rawName === \"post_tag\" ? \"tag\" : rawName;\n\t\t\t\tconst def = await lookupDef(taxonomyName);\n\t\t\t\tif (!def) {\n\t\t\t\t\tif (!state.plan.missingTaxonomies.includes(taxonomyName)) {\n\t\t\t\t\t\tstate.plan.missingTaxonomies.push(taxonomyName);\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tfor (const slug of slugs) {\n\t\t\t\t\tif (state.plan.termIdByNameAndSlug.get(taxonomyName)?.has(slug)) continue;\n\t\t\t\t\tfromPosts.push({\n\t\t\t\t\t\ttaxonomyName,\n\t\t\t\t\t\tslug,\n\t\t\t\t\t\tlabel: labelFor(post, taxonomyName, slug),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tawait ensureTermsBatch(db, state, fromPosts, locale);\n\n\t// `content_taxonomies` writes happen later in `attachPostTaxonomies`, but\n\t// term inserts above already invalidate the in-memory \"has any terms\" probe.\n\t// We flush once at the end of the pre-import to keep the runtime cache hot.\n\tinvalidateTermCache();\n\n\treturn state.plan;\n}\n\n/**\n * Walk a parsed WXR post's per-item taxonomy assignments and return only\n * the ones that resolve to a real EmDash term AND aren't filtered out by\n * the taxonomy def's `collections` allowlist. Grouped by EmDash taxonomy\n * name (so `post_tag` is already folded into `tag`). Deduplicated.\n *\n * This is the single source of truth for \"what will the importer try to\n * write for this post\". Both the anchor (additive `attachToEntry`) and\n * translation (per-taxonomy `setTermsForEntry`) paths drive from this map\n * so they agree on which taxonomies need touching. In particular, the\n * translation path uses the keys here -- not `postAssignedTaxonomies` --\n * to decide which inherited pivot rows to clear, so a translation whose\n * only assignment is filtered out by `collections` doesn't lose its\n * inherited terms (see #1087 review feedback).\n *\n * Skipped taxonomies: `nav_menu` (handled by the menu importer) and\n * `language` (Polylang's locale signal, already promoted to `post.locale`\n * by the parser).\n */\nexport function resolvePostTermAssignments(\n\tcollection: string,\n\tpost: WxrPost,\n\tplan: TaxonomyImportPlan,\n): Map<string, string[]> {\n\tconst result = new Map<string, string[]>();\n\tconst seen = new Set<string>();\n\n\tconst tryResolve = (taxonomyName: string, slug: string): void => {\n\t\tconst termId = plan.termIdByNameAndSlug.get(taxonomyName)?.get(slug);\n\t\tif (!termId) return;\n\t\tconst collectionFilter = plan.collectionsByTaxonomy.get(taxonomyName);\n\t\t// Empty set means \"no filter\" (def has no collections array). A\n\t\t// non-empty set is enforced: skip assignments to collections the\n\t\t// def doesn't list. Matches admin UI: a `category` term linked\n\t\t// only to `posts` shouldn't end up on a `products` row just\n\t\t// because the WXR happened to mention it.\n\t\tif (collectionFilter && collectionFilter.size > 0 && !collectionFilter.has(collection)) {\n\t\t\treturn;\n\t\t}\n\t\tconst dedupeKey = `${taxonomyName}\\u0000${termId}`;\n\t\tif (seen.has(dedupeKey)) return;\n\t\tseen.add(dedupeKey);\n\t\tconst existing = result.get(taxonomyName);\n\t\tif (existing) existing.push(termId);\n\t\telse result.set(taxonomyName, [termId]);\n\t};\n\n\tfor (const slug of post.categories) tryResolve(\"category\", slug);\n\tfor (const slug of post.tags) tryResolve(\"tag\", slug);\n\tif (post.customTaxonomies) {\n\t\tfor (const [rawName, slugs] of post.customTaxonomies) {\n\t\t\tif (rawName === \"nav_menu\" || rawName === \"language\") continue;\n\t\t\tconst taxonomyName = rawName === \"post_tag\" ? \"tag\" : rawName;\n\t\t\tfor (const slug of slugs) tryResolve(taxonomyName, slug);\n\t\t}\n\t}\n\n\treturn result;\n}\n\n/**\n * Attach the taxonomy assignments parsed for a single WXR post to a freshly-\n * created EmDash content row. Additive (`attachToEntry` + `ON CONFLICT DO\n * NOTHING`). Used for anchors -- translations need replace-semantics per\n * taxonomy and should use `setPostTermAssignmentsReplacing` instead.\n *\n * Returns the number of pivot rows actually inserted (excludes rows that\n * already existed via the `ON CONFLICT DO NOTHING` path), so the caller can\n * roll them up into the import summary without over-counting on re-imports.\n */\nexport async function attachPostTaxonomies(\n\tdb: Kysely<Database>,\n\tcollection: string,\n\tentryId: string,\n\tpost: WxrPost,\n\tplan: TaxonomyImportPlan,\n): Promise<number> {\n\tconst repo = new TaxonomyRepository(db);\n\tconst resolved = resolvePostTermAssignments(collection, post, plan);\n\tconst groups = new Set<string>();\n\tfor (const [, termIds] of resolved) {\n\t\tfor (const termId of termIds) {\n\t\t\tconst group = await termTranslationGroup(repo, plan, termId);\n\t\t\tif (group) groups.add(group);\n\t\t}\n\t}\n\treturn repo.attachGroupsToEntry(collection, entryId, [...groups]);\n}\n\n/**\n * Replace assignments per-taxonomy from a parsed WXR post. Used for\n * translations. Assignments belong to the content translation_group, so a\n * translated item's explicit taxonomy replaces that taxonomy for every\n * locale. Taxonomies with no resolvable permitted terms are left unchanged.\n *\n * Returns the number of pivot rows after replacement (sum of `termIds`\n * lists across taxonomies actually touched). Note this counts logical\n * assignments, not the delta from the prior state; the import summary\n * treats this as an additive count for compatibility with `attachPost-\n * Taxonomies`.\n */\nexport async function setPostTermAssignmentsReplacing(\n\tdb: Kysely<Database>,\n\tcollection: string,\n\tentryId: string,\n\tpost: WxrPost,\n\tplan: TaxonomyImportPlan,\n): Promise<number> {\n\tconst repo = new TaxonomyRepository(db);\n\tconst resolved = resolvePostTermAssignments(collection, post, plan);\n\n\tlet attached = 0;\n\tfor (const [taxonomyName, termIds] of resolved) {\n\t\tawait repo.setTermsForEntry(collection, entryId, taxonomyName, termIds);\n\t\tattached += termIds.length;\n\t}\n\treturn attached;\n}\n\n/**\n * Resolve a term id to its `translation_group` (the value\n * `content_taxonomies` stores). Caches the result on the plan so\n * repeated attaches of the same term don't repeat the lookup.\n */\nasync function termTranslationGroup(\n\trepo: TaxonomyRepository,\n\tplan: TaxonomyImportPlan,\n\ttermId: string,\n): Promise<string | null> {\n\tconst cached = plan.translationGroupByTermId.get(termId);\n\tif (cached !== undefined) return cached;\n\tconst term = await repo.findById(termId);\n\tconst group = term?.translationGroup ?? null;\n\tplan.translationGroupByTermId.set(termId, group);\n\treturn group;\n}\n\n/**\n * Mirror every term in the plan into each additional locale used by the\n * incoming posts. New rows share the canonical term's `translation_group`\n * so per-locale lookups (`getTermsForEntry(..., locale)`) resolve correctly\n * for translations whose locale differs from the import-wide one.\n *\n * Without this pass, multilingual WXR imports (#1080) write all term rows\n * at the upload-wide locale; the `content_taxonomies` pivot is correct (it\n * stores `translation_group`, not `term id`), but\n * `getTermsForEntry(collection, arabicPostId, \"category\", \"ar\")` filters on\n * `taxonomies.locale = \"ar\"` and returns zero rows. Users see \"no tags\" on\n * every non-canonical translation.\n *\n * Idempotent: skips a locale when a row already exists at `(name, slug,\n * locale)`. Safe to call after `preImportWxrTaxonomies` on subsequent\n * imports.\n */\nexport async function mirrorTermsToLocales(\n\tdb: Kysely<Database>,\n\tplan: TaxonomyImportPlan,\n\tpostLocales: Iterable<string>,\n\tcanonicalLocale: string | undefined,\n): Promise<void> {\n\tconst localeSet = new Set<string>();\n\tfor (const locale of postLocales) {\n\t\tif (!locale || locale === canonicalLocale) continue;\n\t\tlocaleSet.add(locale);\n\t}\n\tif (localeSet.size === 0) return;\n\n\tconst repo = new TaxonomyRepository(db);\n\n\tfor (const [taxonomyName, bySlug] of plan.termIdByNameAndSlug) {\n\t\tfor (const [slug, canonicalTermId] of bySlug) {\n\t\t\t// Resolve the canonical's translation_group once; we'll compare\n\t\t\t// against any pre-existing rows we find at the target locales.\n\t\t\t// Cache on the plan so subsequent attaches (which also need\n\t\t\t// this resolution) don't repeat the lookup.\n\t\t\tconst cachedGroup = await termTranslationGroup(repo, plan, canonicalTermId);\n\t\t\tif (!cachedGroup) {\n\t\t\t\t// The canonical term id is in the plan but the row is no\n\t\t\t\t// longer in the DB. Shouldn't happen during a single\n\t\t\t\t// import run; skip rather than crash so the rest of the\n\t\t\t\t// import can complete.\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst canonicalGroup = cachedGroup;\n\n\t\t\tfor (const locale of localeSet) {\n\t\t\t\tconst existing = await repo.findBySlug(taxonomyName, slug, locale);\n\t\t\t\tif (existing) {\n\t\t\t\t\t// `ensureTerm` resolves cross-locale grouping when it\n\t\t\t\t\t// creates the canonical row, so a pre-existing sibling\n\t\t\t\t\t// row at this locale should already share the\n\t\t\t\t\t// canonical's `translation_group`. If it doesn't, the\n\t\t\t\t\t// import would write pivots pointing at a group that\n\t\t\t\t\t// has no row in this locale -- a silent data-integrity\n\t\t\t\t\t// bug. Fail closed: throw so the operator reconciles\n\t\t\t\t\t// the existing rows in the admin before retrying. This\n\t\t\t\t\t// happens when the canonical row was created in an\n\t\t\t\t\t// earlier import and a sibling-locale row was added\n\t\t\t\t\t// manually afterwards (or vice versa) without linking\n\t\t\t\t\t// them via translationOf.\n\t\t\t\t\tif (existing.translationGroup !== canonicalGroup) {\n\t\t\t\t\t\tthrow new WxrTaxonomyConflictError(\n\t\t\t\t\t\t\t`Cannot import: term \"${taxonomyName}/${slug}\" already exists at locale \"${locale}\" in a different translation group than the canonical row at this import's locale. Reconcile the rows in the admin (re-link via translationOf, or delete one) and retry.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tawait repo.create({\n\t\t\t\t\t\tname: taxonomyName,\n\t\t\t\t\t\tslug,\n\t\t\t\t\t\tlabel: slug, // we don't have a per-locale label from the WXR\n\t\t\t\t\t\tlocale,\n\t\t\t\t\t\ttranslationOf: canonicalTermId,\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// `findBySlug` + `create` is not atomic. A concurrent\n\t\t\t\t\t// import racing us into the same `(name, slug, locale)`\n\t\t\t\t\t// will trip the UNIQUE constraint. Re-read the row that\n\t\t\t\t\t// won the race and verify its `translation_group`\n\t\t\t\t\t// matches the canonical's; if not, the pivot will\n\t\t\t\t\t// resolve to a group that has no row in this locale\n\t\t\t\t\t// (silent data-integrity bug) so we surface that loudly\n\t\t\t\t\t// rather than continue.\n\t\t\t\t\t//\n\t\t\t\t\t// Other errors (validation, connectivity) re-throw so\n\t\t\t\t\t// the import fails closed rather than silently shipping\n\t\t\t\t\t// translations that resolve to empty taxonomy queries.\n\t\t\t\t\tconst message = error instanceof Error ? error.message.toLowerCase() : \"\";\n\t\t\t\t\tconst isUniqueRace =\n\t\t\t\t\t\tmessage.includes(\"unique constraint failed\") || message.includes(\"duplicate key\");\n\t\t\t\t\tif (!isUniqueRace) throw error;\n\n\t\t\t\t\tconst winner = await repo.findBySlug(taxonomyName, slug, locale);\n\t\t\t\t\tif (!winner) {\n\t\t\t\t\t\t// UNIQUE conflict but no row visible? Shouldn't\n\t\t\t\t\t\t// happen unless the racing transaction rolled back;\n\t\t\t\t\t\t// fail loudly so the operator can investigate.\n\t\t\t\t\t\tthrow new WxrTaxonomyConflictError(\n\t\t\t\t\t\t\t`Cannot import: term \"${taxonomyName}/${slug}\" raced UNIQUE at locale \"${locale}\" but no row is visible afterwards. The concurrent transaction may have rolled back; retry the import.`,\n\t\t\t\t\t\t\t{ cause: error },\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tif (winner.translationGroup !== canonicalGroup) {\n\t\t\t\t\t\tthrow new WxrTaxonomyConflictError(\n\t\t\t\t\t\t\t`Cannot import: term \"${taxonomyName}/${slug}\" raced UNIQUE at locale \"${locale}\" with a different translation group. Reconcile the rows in the admin and retry.`,\n\t\t\t\t\t\t\t{ cause: error },\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`[WXR import] concurrent writer beat us to term \"${taxonomyName}/${slug}\" at locale \"${locale}\"; using existing row (same group).`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAiDA,IAAa,2BAAb,cAA8C,MAAM;CACnD,AAAS;CACT,YAAY,eAAuB,SAA+B;AACjE,QAAM,eAAe,QAAQ;AAC7B,OAAK,OA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C,MAAK,MAAM,CAAC,MAAM,oBAAoB,QAAQ;EAK7C,MAAM,cAAc,MAAM,qBAAqB,MAAM,MAAM,gBAAgB;AAC3E,MAAI,CAAC,YAKJ;EAED,MAAM,iBAAiB;AAEvB,OAAK,MAAM,UAAU,WAAW;GAC/B,MAAM,WAAW,MAAM,KAAK,WAAW,cAAc,MAAM,OAAO;AAClE,OAAI,UAAU;AAab,QAAI,SAAS,qBAAqB,eACjC,OAAM,IAAI,yBACT,wBAAwB,aAAa,GAAG,KAAK,8BAA8B,OAAO,0KAClF;AAEF;;AAED,OAAI;AACH,UAAM,KAAK,OAAO;KACjB,MAAM;KACN;KACA,OAAO;KACP;KACA,eAAe;KACf,CAAC;YACM,OAAO;IAaf,MAAM,UAAU,iBAAiB,QAAQ,MAAM,QAAQ,aAAa,GAAG;AAGvE,QAAI,EADH,QAAQ,SAAS,2BAA2B,IAAI,QAAQ,SAAS,gBAAgB,EAC/D,OAAM;IAEzB,MAAM,SAAS,MAAM,KAAK,WAAW,cAAc,MAAM,OAAO;AAChE,QAAI,CAAC,OAIJ,OAAM,IAAI,yBACT,wBAAwB,aAAa,GAAG,KAAK,4BAA4B,OAAO,yGAChF,EAAE,OAAO,OAAO,CAChB;AAEF,QAAI,OAAO,qBAAqB,eAC/B,OAAM,IAAI,yBACT,wBAAwB,aAAa,GAAG,KAAK,4BAA4B,OAAO,mFAChF,EAAE,OAAO,OAAO,CAChB;AAEF,YAAQ,KACP,mDAAmD,aAAa,GAAG,KAAK,eAAe,OAAO,qCAC9F"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"zod-generator-D0JKy94C.mjs","names":[],"sources":["../src/schema/zod-generator.ts"],"sourcesContent":["import { z, type ZodType } from \"zod\";\n\nimport { hashString } from \"../utils/hash.js\";\nimport { isSafeUrlFieldValue } from \"../utils/url.js\";\nimport type { BlockFieldDefinition } from \"./block-types.js\";\nimport {\n\tisStoragelessField,\n\ttype CollectionWithFields,\n\ttype Field,\n\ttype FieldType,\n\ttype RepeaterSubField,\n} from \"./types.js\";\n\n/** Pattern to split on underscores, hyphens, and spaces for PascalCase conversion */\nconst PASCAL_CASE_SPLIT_PATTERN = /[_\\-\\s]+/;\n\n/**\n * Generate a Zod schema from a collection's field definitions\n *\n * This allows runtime validation of content based on dynamically\n * defined schemas stored in D1.\n */\nexport function generateZodSchema(\n\tcollection: CollectionWithFields,\n): z.ZodObject<Record<string, ZodType>> {\n\tconst shape: Record<string, ZodType> = {};\n\n\tfor (const field of collection.fields) {\n\t\tif (isStoragelessField(field)) continue;\n\t\tshape[field.slug] = generateFieldSchema(field);\n\t}\n\n\treturn z.object(shape);\n}\n\n/**\n * Generate Zod schema for a single field\n */\ntype RuntimeFieldDefinition = Pick<Field, \"type\" | \"validation\" | \"required\" | \"defaultValue\">;\n\nexport function generateFieldSchema(field: RuntimeFieldDefinition): ZodType {\n\tlet schema = getBaseSchema(field.type, field);\n\n\t// Apply validation rules\n\tif (field.validation) {\n\t\tschema = applyValidation(schema, field);\n\t}\n\n\t// Apply required/optional. Non-required fields use `.nullish()` rather\n\t// than `.optional()` because the underlying SQLite columns are nullable\n\t// (see `SchemaRegistry.addFieldColumn` -- non-required fields are added\n\t// without `NOT NULL`). The admin re-sends what it loaded from the\n\t// server on autosave, so any field that's actually `null` in the DB\n\t// must round-trip cleanly through the validator. `.optional()` only\n\t// accepts `undefined`; `.nullish()` accepts both `undefined` and\n\t// `null`. (#867 — autosave failures on seeded entries.)\n\tif (!field.required) {\n\t\tschema = schema.nullish();\n\t}\n\n\t// Apply default value\n\tif (field.defaultValue !== undefined) {\n\t\tschema = schema.default(field.defaultValue);\n\t}\n\n\treturn schema;\n}\n\nexport function generateBlockFieldSchema(field: BlockFieldDefinition): ZodType {\n\treturn generateFieldSchema({\n\t\ttype: field.type,\n\t\tvalidation: field.validation,\n\t\trequired: field.required ?? false,\n\t\tdefaultValue: field.defaultValue,\n\t});\n}\n\n/**\n * Get base Zod schema for a field type\n */\nfunction getBaseSchema(type: FieldType, field: Pick<Field, \"validation\">): ZodType {\n\tswitch (type) {\n\t\tcase \"url\":\n\t\t\t// The admin localizes `invalid_format` issues with `format: \"url\"`.\n\t\t\treturn z.string().check((ctx) => {\n\t\t\t\tif (isSafeUrlFieldValue(ctx.value)) return;\n\t\t\t\tctx.issues.push({\n\t\t\t\t\tcode: \"invalid_format\",\n\t\t\t\t\tformat: \"url\",\n\t\t\t\t\tinput: ctx.value,\n\t\t\t\t\tmessage: \"URL must use http, https, mailto, or tel, or be a site-relative path\",\n\t\t\t\t});\n\t\t\t});\n\n\t\tcase \"string\":\n\t\tcase \"text\":\n\t\tcase \"slug\":\n\t\t\treturn z.string();\n\n\t\tcase \"number\":\n\t\t\treturn z.number();\n\n\t\tcase \"integer\":\n\t\t\treturn z.number().int();\n\n\t\tcase \"boolean\":\n\t\t\t// Boolean fields map to `INTEGER` columns (`FIELD_TYPE_TO_COLUMN`\n\t\t\t// in `schema/types.ts`) and `serializeValue` in\n\t\t\t// `database/repositories/content.ts` writes booleans as 0/1.\n\t\t\t// `deserializeValue` never converts them back, so reads return\n\t\t\t// numbers. Coerce the stored 0/1 shape here so a GET → POST\n\t\t\t// round-trip on a boolean field passes validation. Other inputs\n\t\t\t// (strings, other numbers) fall through to `z.boolean()` and\n\t\t\t// produce its standard rejection.\n\t\t\treturn z.preprocess((v) => (v === 0 || v === 1 ? Boolean(v) : v), z.boolean());\n\n\t\tcase \"datetime\":\n\t\t\treturn z.iso.datetime({ offset: true }).or(z.iso.datetime({ offset: true, precision: -1 }));\n\n\t\tcase \"select\": {\n\t\t\tconst options = field.validation?.options;\n\t\t\tif (options && options.length > 0) {\n\t\t\t\tconst [first, ...rest] = options;\n\t\t\t\treturn z.enum([first, ...rest]);\n\t\t\t}\n\t\t\treturn z.string();\n\t\t}\n\n\t\tcase \"multiSelect\": {\n\t\t\tconst multiOptions = field.validation?.options;\n\t\t\tif (multiOptions && multiOptions.length > 0) {\n\t\t\t\tconst [first, ...rest] = multiOptions;\n\t\t\t\treturn z.array(z.enum([first, ...rest]));\n\t\t\t}\n\t\t\treturn z.array(z.string());\n\t\t}\n\n\t\tcase \"repeater\":\n\t\t\treturn z.array(generateRepeaterRowSchema(field.validation?.subFields ?? []));\n\n\t\tcase \"blocks\":\n\t\t\treturn z.array(z.unknown());\n\n\t\tcase \"portableText\":\n\t\t\t// Portable Text is an array of blocks. We require `_type` because\n\t\t\t// renderers dispatch on it, but `_key` is intentionally optional:\n\t\t\t// it's a UI-layer concern that the editor regenerates on every\n\t\t\t// change (see `PortableTextEditor`), and the rest of this schema\n\t\t\t// uses `.loose()` for everything below the top level. Making\n\t\t\t// `_key` strictly required here was an accidentally tight invariant\n\t\t\t// that rejected any seed/import data not authored against the\n\t\t\t// editor (#867 — autosave failures on seeded template content).\n\t\t\treturn z.array(\n\t\t\t\tz\n\t\t\t\t\t.object({\n\t\t\t\t\t\t_type: z.string(),\n\t\t\t\t\t\t_key: z.string().optional(),\n\t\t\t\t\t})\n\t\t\t\t\t.loose(),\n\t\t\t);\n\n\t\tcase \"image\": {\n\t\t\tconst mediaSchema = z.object({\n\t\t\t\tid: z.string(),\n\t\t\t\tsrc: z.string().optional(),\n\t\t\t\talt: z.string().optional(),\n\t\t\t\twidth: z.number().optional(),\n\t\t\t\theight: z.number().optional(),\n\t\t\t\tfilename: z.string().optional(),\n\t\t\t\tmimeType: z.string().optional(),\n\t\t\t\tblurhash: z.string().optional(),\n\t\t\t\tdominantColor: z.string().optional(),\n\t\t\t\t/** Focal point as 0..1 fractions of width and height */\n\t\t\t\tfocalX: z.number().optional(),\n\t\t\t\tfocalY: z.number().optional(),\n\t\t\t\t/** Provider ID (e.g. \"local\", \"cloudflare-images\") */\n\t\t\t\tprovider: z.string().optional(),\n\t\t\t\t/** Admin-side preview URL for external providers (not persisted by plugins) */\n\t\t\t\tpreviewUrl: z.string().optional(),\n\t\t\t\t/** Provider-specific metadata; for local media this carries storageKey */\n\t\t\t\tmeta: z.record(z.string(), z.unknown()).optional(),\n\t\t\t});\n\t\t\treturn mediaSchema.extend({\n\t\t\t\t/** Counterpart shown when the page renders in a dark color scheme */\n\t\t\t\tdarkVariant: mediaSchema.optional(),\n\t\t\t});\n\t\t}\n\n\t\tcase \"file\":\n\t\t\treturn z.object({\n\t\t\t\tid: z.string(),\n\t\t\t\turl: z.string().optional(),\n\t\t\t\tsrc: z.string().optional(),\n\t\t\t\tfilename: z.string().optional(),\n\t\t\t\tmimeType: z.string().optional(),\n\t\t\t\tsize: z.number().optional(),\n\t\t\t\t/** Provider ID (e.g. \"local\", \"s3\") */\n\t\t\t\tprovider: z.string().optional(),\n\t\t\t\t/** Provider-specific metadata; for local media this carries storageKey */\n\t\t\t\tmeta: z.record(z.string(), z.unknown()).optional(),\n\t\t\t});\n\n\t\tcase \"reference\":\n\t\t\treturn z.string(); // Reference ID\n\n\t\tcase \"json\":\n\t\t\treturn z.unknown();\n\n\t\tdefault:\n\t\t\treturn z.unknown();\n\t}\n}\n\nfunction generateRepeaterRowSchema(\n\tsubFields: readonly RepeaterSubField[],\n): z.ZodObject<Record<string, ZodType>> {\n\tconst shape: Record<string, ZodType> = {};\n\n\tfor (const subField of subFields) {\n\t\tlet schema = getBaseSchema(subField.type, {\n\t\t\tvalidation: subField.options ? { options: subField.options } : undefined,\n\t\t});\n\n\t\tif (subField.required && schema instanceof z.ZodString) {\n\t\t\tschema = schema.min(1, \"required (empty value not allowed)\");\n\t\t}\n\t\tif (!subField.required) {\n\t\t\tschema = schema.nullish();\n\t\t}\n\n\t\tshape[subField.slug] = schema;\n\t}\n\n\treturn z.object(shape).loose();\n}\n\n/**\n * Apply validation rules to a schema\n */\nfunction applyValidation(\n\tschema: ZodType,\n\tfield: Pick<RuntimeFieldDefinition, \"type\" | \"validation\">,\n): ZodType {\n\tconst validation = field.validation;\n\tif (!validation) return schema;\n\n\t// String validations\n\tif (schema instanceof z.ZodString) {\n\t\tlet strSchema = schema;\n\t\tif (validation.minLength !== undefined) {\n\t\t\tstrSchema = strSchema.min(validation.minLength);\n\t\t}\n\t\tif (validation.maxLength !== undefined) {\n\t\t\tstrSchema = strSchema.max(validation.maxLength);\n\t\t}\n\t\tif (validation.pattern) {\n\t\t\tstrSchema = strSchema.regex(new RegExp(validation.pattern));\n\t\t}\n\t\treturn strSchema;\n\t}\n\n\t// Number validations\n\tif (schema instanceof z.ZodNumber) {\n\t\tlet numSchema = schema;\n\t\tif (validation.min !== undefined) {\n\t\t\tnumSchema = numSchema.min(validation.min);\n\t\t}\n\t\tif (validation.max !== undefined) {\n\t\t\tnumSchema = numSchema.max(validation.max);\n\t\t}\n\t\treturn numSchema;\n\t}\n\n\tif ((field.type === \"repeater\" || field.type === \"blocks\") && schema instanceof z.ZodArray) {\n\t\tlet arraySchema = schema;\n\t\tif (validation.minItems !== undefined) {\n\t\t\tarraySchema = arraySchema.min(validation.minItems);\n\t\t}\n\t\tif (validation.maxItems !== undefined) {\n\t\t\tarraySchema = arraySchema.max(validation.maxItems);\n\t\t}\n\t\treturn arraySchema;\n\t}\n\n\treturn schema;\n}\n\n/**\n * Schema cache to avoid regenerating schemas on every request\n */\nconst schemaCache = new Map<string, { schema: z.ZodObject<any>; version: string }>();\n\n/**\n * Get or generate a cached schema for a collection\n */\nexport function getCachedSchema(\n\tcollection: CollectionWithFields,\n\tversion?: string,\n): z.ZodObject<any> {\n\tconst cacheKey = collection.slug;\n\tconst cached = schemaCache.get(cacheKey);\n\n\t// If version matches, return cached schema\n\tif (cached && (!version || cached.version === version)) {\n\t\treturn cached.schema;\n\t}\n\n\t// Generate new schema\n\tconst schema = generateZodSchema(collection);\n\n\t// Cache it\n\tschemaCache.set(cacheKey, {\n\t\tschema,\n\t\tversion: version || collection.updatedAt,\n\t});\n\n\treturn schema;\n}\n\n/**\n * Invalidate cached schema for a collection\n */\nexport function invalidateSchemaCache(slug: string): void {\n\tschemaCache.delete(slug);\n}\n\n/**\n * Clear all cached schemas\n */\nexport function clearSchemaCache(): void {\n\tschemaCache.clear();\n}\n\n/**\n * Validate data against a collection's schema\n */\nexport function validateContent(\n\tcollection: CollectionWithFields,\n\tdata: unknown,\n): { success: true; data: unknown } | { success: false; errors: z.ZodError } {\n\tconst schema = getCachedSchema(collection);\n\n\tconst result = schema.safeParse(data);\n\n\tif (result.success) {\n\t\treturn { success: true, data: result.data };\n\t}\n\n\treturn { success: false, errors: result.error };\n}\n\n/**\n * Generate TypeScript interface from field definitions\n * Used by CLI `emdash types` to generate types\n */\nexport function generateTypeScript(\n\tcollection: CollectionWithFields,\n\tinterfaceName: string = getInterfaceName(collection),\n\tblockFieldTypes: ReadonlyMap<string, string> = new Map(),\n): string {\n\tconst lines: string[] = [];\n\n\tlines.push(`export interface ${interfaceName} {`);\n\tlines.push(` id: string;`);\n\tlines.push(` slug: string | null;`);\n\tlines.push(` status: string;`);\n\n\tfor (const field of collection.fields) {\n\t\t// A storage-less field holds no value in `data`; a reference field bound to\n\t\t// a relation resolves through `references` instead. One that predates\n\t\t// relations still owns its column, so it stays an entry id string.\n\t\tif (isStoragelessField(field)) continue;\n\t\tconst tsType = blockFieldTypes.get(field.slug) ?? fieldTypeToTypeScript(field);\n\t\tconst optional = field.required ? \"\" : \"?\";\n\t\tlines.push(` ${field.slug}${optional}: ${tsType};`);\n\t}\n\n\tlines.push(` createdAt: Date;`);\n\tlines.push(` updatedAt: Date;`);\n\tlines.push(` publishedAt: Date | null;`);\n\t// Bylines are eagerly loaded by getEmDashCollection/getEmDashEntry\n\tlines.push(` byline?: BylineSummary | null;`);\n\tlines.push(` bylines?: ContentBylineCredit[];`);\n\t// Taxonomy terms are eagerly loaded by getEmDashCollection/getEmDashEntry,\n\t// keyed by taxonomy name (e.g. data.terms?.tag)\n\tlines.push(` terms?: Record<string, TaxonomyTerm[]>;`);\n\tlines.push(`}`);\n\n\treturn lines.join(\"\\n\");\n}\n\nfunction generateBlockTypeDeclarations(\n\tcollection: CollectionWithFields,\n\tinterfaceName: string,\n): { lines: string[]; fieldTypes: Map<string, string> } {\n\tconst lines: string[] = [];\n\tconst fieldTypes = new Map<string, string>();\n\tfor (const field of collection.fields) {\n\t\tif (field.type !== \"blocks\") continue;\n\t\tconst fieldName = `${interfaceName}${pascalCase(field.slug)}`;\n\t\tconst typeNames: string[] = [];\n\t\tfor (const blockType of field.blockTypes ?? []) {\n\t\t\tconst typeName = `${fieldName}${pascalCase(blockType.slug)}`;\n\t\t\tconst versionNames: string[] = [];\n\t\t\tfor (const version of blockType.versions) {\n\t\t\t\tconst versionName = `${typeName}V${version.version}Block`;\n\t\t\t\tversionNames.push(versionName);\n\t\t\t\tlines.push(`export interface ${versionName} {`);\n\t\t\t\tlines.push(` _type: ${JSON.stringify(blockType.slug)};`);\n\t\t\t\tlines.push(` _version: ${version.version};`);\n\t\t\t\tlines.push(` _key: string;`);\n\t\t\t\tfor (const nestedField of version.fields) {\n\t\t\t\t\tconst nestedType = fieldTypeToTypeScript({\n\t\t\t\t\t\ttype: nestedField.type,\n\t\t\t\t\t\tvalidation: nestedField.validation,\n\t\t\t\t\t});\n\t\t\t\t\tconst name = JSON.stringify(nestedField.slug);\n\t\t\t\t\tlines.push(\n\t\t\t\t\t\tnestedField.required\n\t\t\t\t\t\t\t? ` ${name}: ${nestedType};`\n\t\t\t\t\t\t\t: ` ${name}?: ${nestedType} | null;`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tlines.push(`}`);\n\t\t\t\tlines.push(``);\n\t\t\t}\n\t\t\tconst unionName = `${typeName}Block`;\n\t\t\tlines.push(`export type ${unionName} = ${versionNames.join(\" | \") || \"never\"};`);\n\t\t\tlines.push(``);\n\t\t\ttypeNames.push(unionName);\n\t\t}\n\t\tconst fieldUnion = `${fieldName}Block`;\n\t\tlines.push(`export type ${fieldUnion} = ${typeNames.join(\" | \") || \"never\"};`);\n\t\tlines.push(``);\n\t\tfieldTypes.set(field.slug, `${fieldUnion}[]`);\n\t}\n\treturn { lines, fieldTypes };\n}\n\n/**\n * Generate a complete types file with module augmentation\n * This produces emdash-env.d.ts content that provides typed query functions\n */\nexport function generateTypesFile(collections: CollectionWithFields[]): string {\n\tconst lines: string[] = [];\n\n\t// Header\n\tlines.push(`// Generated by EmDash on dev server start`);\n\tlines.push(`// Do not edit manually`);\n\tlines.push(``);\n\tlines.push(`/// <reference types=\"emdash/locals\" />`);\n\tlines.push(``);\n\n\t// Check if we need PortableTextBlock import\n\tconst needsPortableText = collections.some((collection) =>\n\t\tcollection.fields.some(\n\t\t\t(field) =>\n\t\t\t\tfield.type === \"portableText\" ||\n\t\t\t\tfield.blockTypes?.some((blockType) =>\n\t\t\t\t\tblockType.versions.some((version) =>\n\t\t\t\t\t\tversion.fields.some((nestedField) => nestedField.type === \"portableText\"),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t),\n\t);\n\n\tconst withReferences = collections.filter((c) => c.fields.some(isStoragelessField));\n\n\t// Build imports - BylineSummary, ContentBylineCredit and TaxonomyTerm are always needed\n\t// for the hydrated bylines/terms fields\n\tconst imports = [\"BylineSummary\", \"ContentBylineCredit\", \"TaxonomyTerm\"];\n\tif (needsPortableText) {\n\t\timports.push(\"PortableTextBlock\");\n\t}\n\tif (withReferences.length > 0) {\n\t\timports.push(\"ReferencePage\");\n\t}\n\tlines.push(`import type { ${imports.join(\", \")} } from \"emdash\";`);\n\tlines.push(``);\n\n\t// Singularizing the slug can map two distinct slugs to the same name\n\t// (e.g. `book` and `books` both -> `Book`), so resolve collisions up front\n\t// to keep every interface identifier unique within the file.\n\tconst interfaceNames = uniqueInterfaceNames(collections);\n\t// `{Collection}References`, built on an already-unique name. No slug can\n\t// produce a data interface name ending in `References` -- `singularize`\n\t// always strips the trailing `s` of a final `references` segment -- so the\n\t// suffix cannot collide with one.\n\tconst referenceInterfaces: [CollectionWithFields, string][] = withReferences.map((c) => [\n\t\tc,\n\t\t`${interfaceNames.get(c.slug)}References`,\n\t]);\n\n\t// Generate individual interfaces\n\tfor (const collection of collections) {\n\t\tconst interfaceName = interfaceNames.get(collection.slug) ?? getInterfaceName(collection);\n\t\tconst blocks = generateBlockTypeDeclarations(collection, interfaceName);\n\t\tlines.push(...blocks.lines);\n\t\tlines.push(generateTypeScript(collection, interfaceName, blocks.fieldTypes));\n\t\tlines.push(``);\n\t}\n\n\tfor (const [collection, name] of referenceInterfaces) {\n\t\tlines.push(generateReferencesTypeScript(collection, name, interfaceNames));\n\t\tlines.push(``);\n\t}\n\n\t// Generate the Collections interface for module augmentation\n\tlines.push(`declare module \"emdash\" {`);\n\tlines.push(` interface EmDashCollections {`);\n\tfor (const collection of collections) {\n\t\tlines.push(` ${collection.slug}: ${interfaceNames.get(collection.slug)};`);\n\t}\n\tlines.push(` }`);\n\tif (referenceInterfaces.length > 0) {\n\t\tlines.push(` interface EmDashCollectionReferences {`);\n\t\tfor (const [collection, name] of referenceInterfaces) {\n\t\t\tlines.push(` ${collection.slug}: ${name};`);\n\t\t}\n\t\tlines.push(` }`);\n\t}\n\tlines.push(`}`);\n\n\treturn lines.join(\"\\n\");\n}\n\n/**\n * Generate the references interface for one collection: a page per reference\n * field bound to a relation, keyed by field slug, which is how\n * `getEmDashEntry({ references })` both asks for and returns them.\n *\n * A field is always present on the interface, not optional -- a selection that\n * names it always yields a page, empty when nothing is linked. The narrowing in\n * `getEmDashEntry` picks out the fields the caller asked for.\n */\nfunction generateReferencesTypeScript(\n\tcollection: CollectionWithFields,\n\tinterfaceName: string,\n\tinterfaceNames: Map<string, string>,\n): string {\n\tconst lines: string[] = [`export interface ${interfaceName} {`];\n\n\tfor (const field of collection.fields) {\n\t\tif (!isStoragelessField(field)) continue;\n\t\t// A target outside this file (dropped collection, or a relation whose\n\t\t// other end has not been created) leaves the page's data un-narrowed\n\t\t// rather than referring to an identifier that does not exist.\n\t\tconst target = field.validation?.targetCollection;\n\t\tconst targetName = target ? interfaceNames.get(target) : undefined;\n\t\tlines.push(` ${field.slug}: ReferencePage${targetName ? `<${targetName}>` : \"\"};`);\n\t}\n\n\tlines.push(`}`);\n\treturn lines.join(\"\\n\");\n}\n\n/**\n * Generate schema hash for cache invalidation\n */\nexport async function generateSchemaHash(collections: CollectionWithFields[]): Promise<string> {\n\tconst str = JSON.stringify(\n\t\tcollections.map((c) => ({\n\t\t\tslug: c.slug,\n\t\t\tfields: c.fields.map((f) => ({\n\t\t\t\tslug: f.slug,\n\t\t\t\ttype: f.type,\n\t\t\t\trequired: f.required,\n\t\t\t\tvalidation: f.validation,\n\t\t\t\tblockTypeFingerprint: f.blockTypeFingerprint,\n\t\t\t})),\n\t\t})),\n\t);\n\treturn hashString(str);\n}\n\n/**\n * Map field type to TypeScript type\n */\nfunction fieldTypeToTypeScript(field: {\n\ttype: Field[\"type\"];\n\tvalidation?: Field[\"validation\"];\n}): string {\n\tswitch (field.type) {\n\t\tcase \"string\":\n\t\tcase \"text\":\n\t\tcase \"slug\":\n\t\tcase \"url\":\n\t\tcase \"datetime\":\n\t\t\treturn \"string\";\n\n\t\tcase \"number\":\n\t\tcase \"integer\":\n\t\t\treturn \"number\";\n\n\t\tcase \"boolean\":\n\t\t\treturn \"boolean\";\n\n\t\tcase \"select\":\n\t\t\tconst options = field.validation?.options;\n\t\t\tif (options && options.length > 0) {\n\t\t\t\treturn options.map((o) => `\"${o}\"`).join(\" | \");\n\t\t\t}\n\t\t\treturn \"string\";\n\n\t\tcase \"multiSelect\":\n\t\t\tconst multiOptions = field.validation?.options;\n\t\t\tif (multiOptions && multiOptions.length > 0) {\n\t\t\t\treturn `(${multiOptions.map((o) => `\"${o}\"`).join(\" | \")})[]`;\n\t\t\t}\n\t\t\treturn \"string[]\";\n\n\t\tcase \"repeater\": {\n\t\t\tconst subFields = field.validation?.subFields;\n\t\t\t// `validation` is unvalidated JSON on the seed and registry paths.\n\t\t\tif (!Array.isArray(subFields) || subFields.length === 0) return \"unknown\";\n\n\t\t\t// A duplicated slug keeps its first position and last declaration, as\n\t\t\t// `generateRepeaterRowSchema`'s `shape[subField.slug]` does.\n\t\t\tconst members = new Map<string, string>();\n\n\t\t\tfor (const subField of subFields) {\n\t\t\t\tconst type = fieldTypeToTypeScript({\n\t\t\t\t\ttype: subField.type,\n\t\t\t\t\tvalidation: subField.options ? { options: subField.options } : undefined,\n\t\t\t\t});\n\t\t\t\t// A sub-field slug is not guaranteed to be a valid identifier, so it is\n\t\t\t\t// quoted rather than emitted bare.\n\t\t\t\tconst name = JSON.stringify(subField.slug);\n\t\t\t\t// A sub-field that is not required may be null at runtime.\n\t\t\t\tmembers.set(\n\t\t\t\t\tsubField.slug,\n\t\t\t\t\tsubField.required ? `${name}: ${type}` : `${name}?: ${type} | null`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn `{ ${[...members.values()].join(\"; \")} }[]`;\n\t\t}\n\n\t\tcase \"portableText\":\n\t\t\treturn \"PortableTextBlock[]\";\n\n\t\tcase \"image\": {\n\t\t\tconst media =\n\t\t\t\t\"{ id: string; src?: string; alt?: string; width?: number; height?: number; filename?: string; mimeType?: string; blurhash?: string; dominantColor?: string; focalX?: number; focalY?: number; provider?: string; previewUrl?: string; meta?: Record<string, unknown> }\";\n\t\t\treturn `${media.slice(0, -2)}; darkVariant?: ${media} }`;\n\t\t}\n\n\t\tcase \"file\":\n\t\t\treturn \"{ id: string; url?: string; src?: string; filename?: string; mimeType?: string; size?: number; provider?: string; meta?: Record<string, unknown> }\";\n\n\t\tcase \"reference\":\n\t\t\t// Could be enhanced to include the referenced collection type\n\t\t\treturn \"string\";\n\n\t\tcase \"json\":\n\t\t\treturn \"unknown\";\n\n\t\tcase \"blocks\":\n\t\t\treturn \"unknown[]\";\n\n\t\tdefault:\n\t\t\treturn \"unknown\";\n\t}\n}\n\n/**\n * Convert string to PascalCase (handles slugs, spaces, etc.)\n */\nfunction pascalCase(str: string): string {\n\treturn str\n\t\t.split(PASCAL_CASE_SPLIT_PATTERN)\n\t\t.filter(Boolean)\n\t\t.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())\n\t\t.join(\"\");\n}\n\n/**\n * Naive singularization for slug-derived interface names. Handles the common\n * English plural endings; intentionally simple, not a full inflector.\n */\nfunction singularize(str: string): string {\n\tif (str.endsWith(\"ies\")) {\n\t\treturn str.slice(0, -3) + \"y\";\n\t}\n\tif (\n\t\tstr.endsWith(\"es\") &&\n\t\t(str.endsWith(\"sses\") || str.endsWith(\"xes\") || str.endsWith(\"ches\") || str.endsWith(\"shes\"))\n\t) {\n\t\treturn str.slice(0, -2);\n\t}\n\tif (str.endsWith(\"s\") && !str.endsWith(\"ss\")) {\n\t\treturn str.slice(0, -1);\n\t}\n\treturn str;\n}\n\n/**\n * Get the interface name for a collection.\n *\n * Derived from the slug, not the human label. Slugs are constrained to\n * `/^[a-z][a-z0-9_]*$/`, so PascalCasing one always yields a valid TS\n * identifier; labels are arbitrary and user-controlled (punctuation, spaces,\n * duplicates across collections), which produced syntactically invalid or\n * duplicate interface names. The slug is singularized first because the\n * interface describes a single entry, not the collection (`posts` -> `Post`).\n *\n * Singularization can map two distinct slugs onto the same name, so callers\n * generating more than one interface must dedupe -- see `uniqueInterfaceNames`.\n */\nfunction getInterfaceName(collection: CollectionWithFields): string {\n\treturn pascalCase(singularize(collection.slug));\n}\n\n/**\n * Resolve interface names for a set of collections, guaranteeing each is\n * unique within the file. Collisions (from singularization or PascalCasing\n * collapsing distinct slugs) get a numeric suffix in collection order, so the\n * generated `.d.ts` never declares two interfaces with the same identifier.\n *\n * The suffix is chosen against the set of names already emitted, not a\n * per-base counter, so a generated name can't collide with another slug's\n * base name (e.g. slugs `book`, `books`, `book2`: `books` -> `Book2` would\n * clash with `book2`, so it advances to `Book3`).\n */\nexport function uniqueInterfaceNames(collections: CollectionWithFields[]): Map<string, string> {\n\tconst used = new Set<string>();\n\tconst names = new Map<string, string>();\n\tfor (const collection of collections) {\n\t\tconst base = getInterfaceName(collection);\n\t\tlet name = base;\n\t\tlet suffix = 2;\n\t\twhile (used.has(name)) {\n\t\t\tname = `${base}${suffix}`;\n\t\t\tsuffix++;\n\t\t}\n\t\tused.add(name);\n\t\tnames.set(collection.slug, name);\n\t}\n\treturn names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