emdash 0.30.0 → 0.31.1

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 (392) hide show
  1. package/dist/api/route-utils.mjs +13 -13
  2. package/dist/api/schemas/index.d.mts +1 -1
  3. package/dist/api/schemas/index.mjs +3 -3
  4. package/dist/{api-b8WIiGU4.mjs → api-BkqFzIu4.mjs} +23 -23
  5. package/dist/api-BkqFzIu4.mjs.map +1 -0
  6. package/dist/{apply-CmIJK9j8.mjs → apply-DuXsqll7.mjs} +26 -25
  7. package/dist/apply-DuXsqll7.mjs.map +1 -0
  8. package/dist/astro/index.d.mts +2 -2
  9. package/dist/astro/index.mjs +1 -1
  10. package/dist/astro/middleware/auth.d.mts +2 -2
  11. package/dist/astro/middleware/auth.mjs +2 -2
  12. package/dist/astro/middleware/redirect.mjs +5 -5
  13. package/dist/astro/middleware/request-context.mjs +1 -1
  14. package/dist/astro/middleware.d.mts +2 -2
  15. package/dist/astro/middleware.mjs +146 -70
  16. package/dist/astro/middleware.mjs.map +1 -1
  17. package/dist/astro/routes/api/admin/allowed-domains/_domain_.mjs +6 -6
  18. package/dist/astro/routes/api/admin/allowed-domains/index.mjs +6 -6
  19. package/dist/astro/routes/api/admin/api-tokens/_id_.mjs +2 -2
  20. package/dist/astro/routes/api/admin/api-tokens/index.mjs +3 -3
  21. package/dist/astro/routes/api/admin/byline-fields/_slug_/usage.mjs +3 -3
  22. package/dist/astro/routes/api/admin/byline-fields/_slug_.mjs +7 -7
  23. package/dist/astro/routes/api/admin/byline-fields/index.mjs +7 -7
  24. package/dist/astro/routes/api/admin/byline-fields/reorder.mjs +7 -7
  25. package/dist/astro/routes/api/admin/bylines/_id_/index.mjs +14 -14
  26. package/dist/astro/routes/api/admin/bylines/_id_/translations.mjs +14 -14
  27. package/dist/astro/routes/api/admin/bylines/index.d.mts.map +1 -1
  28. package/dist/astro/routes/api/admin/bylines/index.mjs +18 -17
  29. package/dist/astro/routes/api/admin/bylines/index.mjs.map +1 -1
  30. package/dist/astro/routes/api/admin/comments/_id_/status.mjs +10 -10
  31. package/dist/astro/routes/api/admin/comments/_id_.mjs +5 -5
  32. package/dist/astro/routes/api/admin/comments/bulk.mjs +9 -9
  33. package/dist/astro/routes/api/admin/comments/counts.mjs +5 -5
  34. package/dist/astro/routes/api/admin/comments/index.mjs +9 -9
  35. package/dist/astro/routes/api/admin/hooks/exclusive/_hookName_.mjs +4 -4
  36. package/dist/astro/routes/api/admin/hooks/exclusive/index.mjs +3 -3
  37. package/dist/astro/routes/api/admin/media-usage/repair.mjs +10 -10
  38. package/dist/astro/routes/api/admin/oauth-clients/_id_.mjs +3 -3
  39. package/dist/astro/routes/api/admin/oauth-clients/index.mjs +3 -3
  40. package/dist/astro/routes/api/admin/plugins/_id_/disable.mjs +34 -34
  41. package/dist/astro/routes/api/admin/plugins/_id_/enable.mjs +34 -34
  42. package/dist/astro/routes/api/admin/plugins/_id_/index.mjs +34 -34
  43. package/dist/astro/routes/api/admin/plugins/_id_/mcp.mjs +4 -4
  44. package/dist/astro/routes/api/admin/plugins/_id_/settings.mjs +34 -34
  45. package/dist/astro/routes/api/admin/plugins/_id_/uninstall.mjs +34 -34
  46. package/dist/astro/routes/api/admin/plugins/_id_/update.mjs +34 -34
  47. package/dist/astro/routes/api/admin/plugins/index.mjs +34 -34
  48. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/icon.mjs +3 -3
  49. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/index.mjs +34 -34
  50. package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.mjs +34 -34
  51. package/dist/astro/routes/api/admin/plugins/marketplace/index.mjs +34 -34
  52. package/dist/astro/routes/api/admin/plugins/registry/_id_/uninstall.mjs +34 -34
  53. package/dist/astro/routes/api/admin/plugins/registry/_id_/update.mjs +35 -35
  54. package/dist/astro/routes/api/admin/plugins/registry/artifact.mjs +34 -34
  55. package/dist/astro/routes/api/admin/plugins/registry/install.mjs +35 -35
  56. package/dist/astro/routes/api/admin/plugins/updates.mjs +34 -34
  57. package/dist/astro/routes/api/admin/themes/marketplace/_id_/index.mjs +34 -34
  58. package/dist/astro/routes/api/admin/themes/marketplace/_id_/thumbnail.mjs +3 -3
  59. package/dist/astro/routes/api/admin/themes/marketplace/index.mjs +34 -34
  60. package/dist/astro/routes/api/admin/users/_id_/disable.mjs +2 -2
  61. package/dist/astro/routes/api/admin/users/_id_/enable.mjs +2 -2
  62. package/dist/astro/routes/api/admin/users/_id_/index.mjs +6 -6
  63. package/dist/astro/routes/api/admin/users/_id_/send-recovery.mjs +2 -2
  64. package/dist/astro/routes/api/admin/users/index.mjs +6 -6
  65. package/dist/astro/routes/api/auth/dev-bypass.mjs +4 -4
  66. package/dist/astro/routes/api/auth/invite/accept.mjs +2 -2
  67. package/dist/astro/routes/api/auth/invite/complete.mjs +6 -6
  68. package/dist/astro/routes/api/auth/invite/index.mjs +6 -6
  69. package/dist/astro/routes/api/auth/invite/register-options.mjs +6 -6
  70. package/dist/astro/routes/api/auth/logout.mjs +2 -2
  71. package/dist/astro/routes/api/auth/magic-link/send.mjs +7 -7
  72. package/dist/astro/routes/api/auth/magic-link/verify.mjs +2 -2
  73. package/dist/astro/routes/api/auth/me.mjs +7 -7
  74. package/dist/astro/routes/api/auth/mode.mjs +2 -2
  75. package/dist/astro/routes/api/auth/passkey/_id_.mjs +6 -6
  76. package/dist/astro/routes/api/auth/passkey/index.mjs +2 -2
  77. package/dist/astro/routes/api/auth/passkey/options.mjs +7 -7
  78. package/dist/astro/routes/api/auth/passkey/register/options.mjs +6 -6
  79. package/dist/astro/routes/api/auth/passkey/register/verify.mjs +6 -6
  80. package/dist/astro/routes/api/auth/passkey/verify.mjs +6 -6
  81. package/dist/astro/routes/api/auth/signup/complete.mjs +6 -6
  82. package/dist/astro/routes/api/auth/signup/request.mjs +7 -7
  83. package/dist/astro/routes/api/auth/signup/verify.mjs +2 -2
  84. package/dist/astro/routes/api/comments/_collection_/_contentId_/index.mjs +10 -10
  85. package/dist/astro/routes/api/comments/_collection_/_contentId_/reactions.mjs +10 -10
  86. package/dist/astro/routes/api/content/_collection_/_id_/compare.mjs +3 -3
  87. package/dist/astro/routes/api/content/_collection_/_id_/discard-draft.mjs +3 -3
  88. package/dist/astro/routes/api/content/_collection_/_id_/duplicate.mjs +3 -3
  89. package/dist/astro/routes/api/content/_collection_/_id_/permanent.mjs +3 -3
  90. package/dist/astro/routes/api/content/_collection_/_id_/preview-url.mjs +9 -9
  91. package/dist/astro/routes/api/content/_collection_/_id_/publish.mjs +7 -7
  92. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/children.mjs +14 -14
  93. package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/parents.mjs +14 -14
  94. package/dist/astro/routes/api/content/_collection_/_id_/restore.mjs +3 -3
  95. package/dist/astro/routes/api/content/_collection_/_id_/revisions.mjs +3 -3
  96. package/dist/astro/routes/api/content/_collection_/_id_/schedule.mjs +7 -7
  97. package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.mjs +13 -13
  98. package/dist/astro/routes/api/content/_collection_/_id_/translations.mjs +3 -3
  99. package/dist/astro/routes/api/content/_collection_/_id_/unpublish.mjs +3 -3
  100. package/dist/astro/routes/api/content/_collection_/_id_.mjs +7 -7
  101. package/dist/astro/routes/api/content/_collection_/authors.mjs +3 -3
  102. package/dist/astro/routes/api/content/_collection_/index.mjs +7 -7
  103. package/dist/astro/routes/api/content/_collection_/trash.mjs +7 -7
  104. package/dist/astro/routes/api/dashboard.mjs +7 -7
  105. package/dist/astro/routes/api/dev/emails.mjs +2 -2
  106. package/dist/astro/routes/api/import/probe.mjs +12 -12
  107. package/dist/astro/routes/api/import/wordpress/analyze.mjs +3 -3
  108. package/dist/astro/routes/api/import/wordpress/execute.d.mts +2 -2
  109. package/dist/astro/routes/api/import/wordpress/execute.mjs +11 -11
  110. package/dist/astro/routes/api/import/wordpress/media.d.mts +2 -2
  111. package/dist/astro/routes/api/import/wordpress/media.mjs +7 -7
  112. package/dist/astro/routes/api/import/wordpress/prepare.mjs +9 -9
  113. package/dist/astro/routes/api/import/wordpress/rewrite-urls.d.mts +2 -2
  114. package/dist/astro/routes/api/import/wordpress/rewrite-urls.mjs +9 -9
  115. package/dist/astro/routes/api/import/wordpress-plugin/analyze.mjs +12 -12
  116. package/dist/astro/routes/api/import/wordpress-plugin/execute.d.mts +2 -2
  117. package/dist/astro/routes/api/import/wordpress-plugin/execute.mjs +19 -19
  118. package/dist/astro/routes/api/manifest.mjs +3 -3
  119. package/dist/astro/routes/api/mcp.mjs +39 -39
  120. package/dist/astro/routes/api/media/_id_/confirm.mjs +7 -7
  121. package/dist/astro/routes/api/media/_id_/usage.mjs +11 -11
  122. package/dist/astro/routes/api/media/_id_.mjs +10 -10
  123. package/dist/astro/routes/api/media/file/_...key_.mjs +2 -2
  124. package/dist/astro/routes/api/media/providers/_providerId_/_itemId_.mjs +3 -3
  125. package/dist/astro/routes/api/media/providers/_providerId_/index.mjs +3 -3
  126. package/dist/astro/routes/api/media/providers/index.mjs +3 -3
  127. package/dist/astro/routes/api/media/upload-url.mjs +7 -7
  128. package/dist/astro/routes/api/media.mjs +10 -10
  129. package/dist/astro/routes/api/menus/_name_/items/_id_.mjs +8 -8
  130. package/dist/astro/routes/api/menus/_name_/items.mjs +8 -8
  131. package/dist/astro/routes/api/menus/_name_/reorder.mjs +8 -8
  132. package/dist/astro/routes/api/menus/_name_/translations.mjs +8 -8
  133. package/dist/astro/routes/api/menus/_name_.mjs +8 -8
  134. package/dist/astro/routes/api/menus/index.mjs +8 -8
  135. package/dist/astro/routes/api/oauth/authorize.d.mts.map +1 -1
  136. package/dist/astro/routes/api/oauth/authorize.mjs +23 -9
  137. package/dist/astro/routes/api/oauth/authorize.mjs.map +1 -1
  138. package/dist/astro/routes/api/oauth/device/authorize.mjs +3 -3
  139. package/dist/astro/routes/api/oauth/device/code.mjs +4 -4
  140. package/dist/astro/routes/api/oauth/device/token.mjs +4 -4
  141. package/dist/astro/routes/api/oauth/register.mjs +2 -2
  142. package/dist/astro/routes/api/oauth/token/refresh.mjs +3 -3
  143. package/dist/astro/routes/api/oauth/token/revoke.mjs +3 -3
  144. package/dist/astro/routes/api/oauth/token.mjs +2 -2
  145. package/dist/astro/routes/api/openapi.json.mjs +4 -4
  146. package/dist/astro/routes/api/plugins/_pluginId_/_...path_.mjs +4 -4
  147. package/dist/astro/routes/api/redirects/404s/index.mjs +10 -10
  148. package/dist/astro/routes/api/redirects/404s/summary.mjs +10 -10
  149. package/dist/astro/routes/api/redirects/_id_.mjs +11 -11
  150. package/dist/astro/routes/api/redirects/index.mjs +11 -11
  151. package/dist/astro/routes/api/relations/_id_/index.mjs +14 -14
  152. package/dist/astro/routes/api/relations/_id_/translations.mjs +10 -10
  153. package/dist/astro/routes/api/relations/index.mjs +14 -14
  154. package/dist/astro/routes/api/revisions/_revisionId_/index.mjs +3 -3
  155. package/dist/astro/routes/api/revisions/_revisionId_/restore.mjs +3 -3
  156. package/dist/astro/routes/api/schema/collections/_slug_/fields/_fieldSlug_.mjs +34 -34
  157. package/dist/astro/routes/api/schema/collections/_slug_/fields/index.mjs +34 -34
  158. package/dist/astro/routes/api/schema/collections/_slug_/fields/reorder.mjs +34 -34
  159. package/dist/astro/routes/api/schema/collections/_slug_/index.mjs +34 -34
  160. package/dist/astro/routes/api/schema/collections/index.mjs +34 -34
  161. package/dist/astro/routes/api/schema/index.mjs +8 -8
  162. package/dist/astro/routes/api/schema/orphans/_slug_.mjs +34 -34
  163. package/dist/astro/routes/api/schema/orphans/index.mjs +34 -34
  164. package/dist/astro/routes/api/search/enable.mjs +11 -11
  165. package/dist/astro/routes/api/search/index.mjs +10 -10
  166. package/dist/astro/routes/api/search/rebuild.mjs +11 -11
  167. package/dist/astro/routes/api/search/stats.mjs +7 -7
  168. package/dist/astro/routes/api/search/suggest.mjs +10 -10
  169. package/dist/astro/routes/api/sections/_slug_.mjs +10 -10
  170. package/dist/astro/routes/api/sections/index.mjs +10 -10
  171. package/dist/astro/routes/api/settings/backups/archives/_name_.mjs +4 -4
  172. package/dist/astro/routes/api/settings/backups/archives/index.mjs +4 -4
  173. package/dist/astro/routes/api/settings/backups/export.mjs +4 -4
  174. package/dist/astro/routes/api/settings/backups/index.mjs +5 -5
  175. package/dist/astro/routes/api/settings/email.mjs +4 -4
  176. package/dist/astro/routes/api/settings.mjs +12 -12
  177. package/dist/astro/routes/api/setup/admin-verify.mjs +6 -6
  178. package/dist/astro/routes/api/setup/admin.mjs +6 -6
  179. package/dist/astro/routes/api/setup/dev-bypass.mjs +18 -18
  180. package/dist/astro/routes/api/setup/dev-reset.mjs +2 -2
  181. package/dist/astro/routes/api/setup/index.mjs +22 -22
  182. package/dist/astro/routes/api/setup/status.mjs +3 -3
  183. package/dist/astro/routes/api/snapshot.mjs +4 -4
  184. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_/translations.mjs +13 -13
  185. package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_.mjs +13 -13
  186. package/dist/astro/routes/api/taxonomies/_name_/terms/index.mjs +13 -13
  187. package/dist/astro/routes/api/taxonomies/index.mjs +13 -13
  188. package/dist/astro/routes/api/themes/preview.mjs +4 -4
  189. package/dist/astro/routes/api/typegen.mjs +5 -5
  190. package/dist/astro/routes/api/widget-areas/_name_/reorder.mjs +7 -7
  191. package/dist/astro/routes/api/widget-areas/_name_/widgets/_id_.mjs +10 -10
  192. package/dist/astro/routes/api/widget-areas/_name_/widgets.mjs +10 -10
  193. package/dist/astro/routes/api/widget-areas/_name_.mjs +6 -6
  194. package/dist/astro/routes/api/widget-areas/index.mjs +10 -10
  195. package/dist/astro/routes/api/widget-components.mjs +2 -2
  196. package/dist/astro/routes/robots.txt.mjs +5 -5
  197. package/dist/astro/routes/sitemap-_collection_.xml.mjs +7 -7
  198. package/dist/astro/routes/sitemap.xml.mjs +5 -5
  199. package/dist/astro/types.d.mts +2 -2
  200. package/dist/{authorize-WxsiePzy.mjs → authorize-6WPZa1xZ.mjs} +2 -2
  201. package/dist/{authorize-WxsiePzy.mjs.map → authorize-6WPZa1xZ.mjs.map} +1 -1
  202. package/dist/{backup-S8kFWtwD.mjs → backup-DoW-H0r4.mjs} +2 -2
  203. package/dist/{backup-S8kFWtwD.mjs.map → backup-DoW-H0r4.mjs.map} +1 -1
  204. package/dist/{byline-XEjchwzZ.mjs → byline-BTOxUlFF.mjs} +6 -6
  205. package/dist/{byline-XEjchwzZ.mjs.map → byline-BTOxUlFF.mjs.map} +1 -1
  206. package/dist/{bylines-czseViYo.mjs → bylines-Bc-3xtpz.mjs} +6 -6
  207. package/dist/{bylines-czseViYo.mjs.map → bylines-Bc-3xtpz.mjs.map} +1 -1
  208. package/dist/{bylines-BJbT4gKS.mjs → bylines-oVN0iPwX.mjs} +12 -8
  209. package/dist/bylines-oVN0iPwX.mjs.map +1 -0
  210. package/dist/{cache-CGCd6AVM.mjs → cache-DDwy3JDW.mjs} +2 -2
  211. package/dist/{cache-CGCd6AVM.mjs.map → cache-DDwy3JDW.mjs.map} +1 -1
  212. package/dist/{chunks-BxXyunY-.mjs → chunks-Bq-5DPrD.mjs} +2 -2
  213. package/dist/{chunks-BxXyunY-.mjs.map → chunks-Bq-5DPrD.mjs.map} +1 -1
  214. package/dist/cli/index.mjs +18 -18
  215. package/dist/{comment-DPT0WKyd.mjs → comment-B9cUud8H.mjs} +2 -2
  216. package/dist/{comment-DPT0WKyd.mjs.map → comment-B9cUud8H.mjs.map} +1 -1
  217. package/dist/{comment-reaction-C65MldIB.mjs → comment-reaction-VUXO981F.mjs} +2 -2
  218. package/dist/{comment-reaction-C65MldIB.mjs.map → comment-reaction-VUXO981F.mjs.map} +1 -1
  219. package/dist/{comments-Bz6sCbgD.mjs → comments-PXj1E9Si.mjs} +3 -3
  220. package/dist/{comments-Bz6sCbgD.mjs.map → comments-PXj1E9Si.mjs.map} +1 -1
  221. package/dist/{config-CVssduLe.mjs → config-B6b_BobR.mjs} +6 -2
  222. package/dist/config-B6b_BobR.mjs.map +1 -0
  223. package/dist/{content-Ci04z2z-.mjs → content-BC43pICM.mjs} +4 -4
  224. package/dist/{content-Ci04z2z-.mjs.map → content-BC43pICM.mjs.map} +1 -1
  225. package/dist/{content-refresh-D4khvC0R.mjs → content-refresh-CPMSauD3.mjs} +4 -4
  226. package/dist/{content-refresh-D4khvC0R.mjs.map → content-refresh-CPMSauD3.mjs.map} +1 -1
  227. package/dist/{context-B6hc7zJL.mjs → context-DOurRIrb.mjs} +10 -10
  228. package/dist/{context-B6hc7zJL.mjs.map → context-DOurRIrb.mjs.map} +1 -1
  229. package/dist/{dashboard-C5NkXFbi.mjs → dashboard-CBm4zhc3.mjs} +4 -4
  230. package/dist/{dashboard-C5NkXFbi.mjs.map → dashboard-CBm4zhc3.mjs.map} +1 -1
  231. package/dist/database/pg-migration-lock.d.mts.map +1 -1
  232. package/dist/database/pg-migration-lock.mjs +1 -4
  233. package/dist/database/pg-migration-lock.mjs.map +1 -1
  234. package/dist/db/index.mjs +2 -2
  235. package/dist/{dialect-helpers-HxEQGl_1.mjs → dialect-helpers-BtOwo2us.mjs} +4 -4
  236. package/dist/dialect-helpers-BtOwo2us.mjs.map +1 -0
  237. package/dist/{error-CEGF6UZb.mjs → error-DJ98TRbQ.mjs} +2 -2
  238. package/dist/{error-CEGF6UZb.mjs.map → error-DJ98TRbQ.mjs.map} +1 -1
  239. package/dist/{field-defs-cache-DvmlgP-D.mjs → field-defs-cache-KfNJ_qLQ.mjs} +2 -2
  240. package/dist/{field-defs-cache-DvmlgP-D.mjs.map → field-defs-cache-KfNJ_qLQ.mjs.map} +1 -1
  241. package/dist/{fts-manager-DzqIBrrW.mjs → fts-manager-hyCU9OOp.mjs} +3 -3
  242. package/dist/{fts-manager-DzqIBrrW.mjs.map → fts-manager-hyCU9OOp.mjs.map} +1 -1
  243. package/dist/{hreflang-db2Tpb2o.mjs → hreflang-CbYeCzl9.mjs} +7 -7
  244. package/dist/{hreflang-db2Tpb2o.mjs.map → hreflang-CbYeCzl9.mjs.map} +1 -1
  245. package/dist/{import-Dmkm8S1W.mjs → import-oDYCgNYQ.mjs} +2 -2
  246. package/dist/{import-Dmkm8S1W.mjs.map → import-oDYCgNYQ.mjs.map} +1 -1
  247. package/dist/{index-wYnC6u4o.d.mts → index-BZJ_5FOX.d.mts} +50 -4
  248. package/dist/index-BZJ_5FOX.d.mts.map +1 -0
  249. package/dist/index.d.mts +2 -2
  250. package/dist/index.mjs +48 -48
  251. package/dist/{load-Cx27ki1l.mjs → load-Dg5gtWma.mjs} +2 -2
  252. package/dist/{load-Cx27ki1l.mjs.map → load-Dg5gtWma.mjs.map} +1 -1
  253. package/dist/{loader-Be3ouI5L.mjs → loader-D4rigvjR.mjs} +4 -4
  254. package/dist/{loader-Be3ouI5L.mjs.map → loader-D4rigvjR.mjs.map} +1 -1
  255. package/dist/media/local-runtime.d.mts +2 -2
  256. package/dist/media/local-runtime.mjs +5 -5
  257. package/dist/{media-kIV1IxFf.mjs → media-BJ6SRY3g.mjs} +8 -4
  258. package/dist/media-BJ6SRY3g.mjs.map +1 -0
  259. package/dist/{media-BjhhENaJ.mjs → media-its1WLYv.mjs} +2 -2
  260. package/dist/{media-BjhhENaJ.mjs.map → media-its1WLYv.mjs.map} +1 -1
  261. package/dist/{media-upload-D2wk3EIt.mjs → media-upload-DNu3QySc.mjs} +4 -4
  262. package/dist/{media-upload-D2wk3EIt.mjs.map → media-upload-DNu3QySc.mjs.map} +1 -1
  263. package/dist/{media-usage-CljdO1mc.mjs → media-usage-DPQ3K4xB.mjs} +6 -6
  264. package/dist/{media-usage-CljdO1mc.mjs.map → media-usage-DPQ3K4xB.mjs.map} +1 -1
  265. package/dist/{menus-CZyG6rvx.mjs → menus-BMGzWyWH.mjs} +15 -8
  266. package/dist/menus-BMGzWyWH.mjs.map +1 -0
  267. package/dist/{menus-BcyElFtI.mjs → menus-CPf_SW7u.mjs} +86 -8
  268. package/dist/menus-CPf_SW7u.mjs.map +1 -0
  269. package/dist/{parse-C_-6klII.mjs → parse-53zyxlpv.mjs} +2 -2
  270. package/dist/{parse-C_-6klII.mjs.map → parse-53zyxlpv.mjs.map} +1 -1
  271. package/dist/plugin-utils.d.mts +2 -2
  272. package/dist/plugins/adapt-sandbox-entry.d.mts +2 -2
  273. package/dist/{query-DR73ZNfm.mjs → query-Bz9bWZfm.mjs} +14 -14
  274. package/dist/{query-DR73ZNfm.mjs.map → query-Bz9bWZfm.mjs.map} +1 -1
  275. package/dist/{query-Di7DOmPV.mjs → query-DdFGHzQF.mjs} +3 -3
  276. package/dist/{query-Di7DOmPV.mjs.map → query-DdFGHzQF.mjs.map} +1 -1
  277. package/dist/{rate-limit-CMj83JNW.mjs → rate-limit-D3IEiUi2.mjs} +2 -2
  278. package/dist/{rate-limit-CMj83JNW.mjs.map → rate-limit-D3IEiUi2.mjs.map} +1 -1
  279. package/dist/{redirect-CgLPYflR.mjs → redirect-BoUac4NT.mjs} +3 -3
  280. package/dist/{redirect-CgLPYflR.mjs.map → redirect-BoUac4NT.mjs.map} +1 -1
  281. package/dist/{redirects-B7t9bKsL.mjs → redirects-ChbpqKiS.mjs} +3 -3
  282. package/dist/{redirects-B7t9bKsL.mjs.map → redirects-ChbpqKiS.mjs.map} +1 -1
  283. package/dist/{redirects-BBq3n2Rj.mjs → redirects-D457qwt0.mjs} +8 -8
  284. package/dist/redirects-D457qwt0.mjs.map +1 -0
  285. package/dist/{registry-FV15nLge.mjs → registry-y21kjhfG.mjs} +6 -6
  286. package/dist/{registry-FV15nLge.mjs.map → registry-y21kjhfG.mjs.map} +1 -1
  287. package/dist/{relation-9M9j_UWo.mjs → relation-Du0r04E0.mjs} +3 -3
  288. package/dist/{relation-9M9j_UWo.mjs.map → relation-Du0r04E0.mjs.map} +1 -1
  289. package/dist/{relations-5_avdrN_.mjs → relations-CZMpBqEd.mjs} +3 -3
  290. package/dist/{relations-5_avdrN_.mjs.map → relations-CZMpBqEd.mjs.map} +1 -1
  291. package/dist/{relations-BKvO39-9.mjs → relations-DtX1UMBH.mjs} +13 -7
  292. package/dist/relations-DtX1UMBH.mjs.map +1 -0
  293. package/dist/{relations-Bh8jlFsU.d.mts → relations-qKmSj9KM.d.mts} +27 -23
  294. package/dist/relations-qKmSj9KM.d.mts.map +1 -0
  295. package/dist/{resolve-Cd9dzclN.mjs → resolve-DFr4kq72.mjs} +2 -2
  296. package/dist/{resolve-Cd9dzclN.mjs.map → resolve-DFr4kq72.mjs.map} +1 -1
  297. package/dist/{runner-DfnZ5eUr.mjs → runner-BdeLEgad.mjs} +3 -3
  298. package/dist/{runner-DfnZ5eUr.mjs.map → runner-BdeLEgad.mjs.map} +1 -1
  299. package/dist/runtime.d.mts +2 -2
  300. package/dist/runtime.mjs +3 -3
  301. package/dist/{schema-BXxlHeAf.mjs → schema-BH8P8vaC.mjs} +3 -3
  302. package/dist/{schema-BXxlHeAf.mjs.map → schema-BH8P8vaC.mjs.map} +1 -1
  303. package/dist/{scopes-Bl4IwHA-.mjs → scopes-DTIkIaGA.mjs} +2 -2
  304. package/dist/{scopes-Bl4IwHA-.mjs.map → scopes-DTIkIaGA.mjs.map} +1 -1
  305. package/dist/{search-Bff-7jFt.mjs → search-D-Yhpmvs.mjs} +8 -7
  306. package/dist/search-D-Yhpmvs.mjs.map +1 -0
  307. package/dist/{secrets-CSwQIl4q.mjs → secrets-CQ-69kF9.mjs} +23 -17
  308. package/dist/secrets-CQ-69kF9.mjs.map +1 -0
  309. package/dist/{sections-CwW4s1al.mjs → sections-CzVBAKjw.mjs} +3 -3
  310. package/dist/{sections-CwW4s1al.mjs.map → sections-CzVBAKjw.mjs.map} +1 -1
  311. package/dist/seed/index.mjs +16 -16
  312. package/dist/seo/index.mjs +12 -12
  313. package/dist/{seo-2cmFHZns.mjs → seo-kJzVAmmu.mjs} +2 -2
  314. package/dist/{seo-2cmFHZns.mjs.map → seo-kJzVAmmu.mjs.map} +1 -1
  315. package/dist/{service-DkGTWGIi.mjs → service-CQnc276a.mjs} +2 -2
  316. package/dist/{service-DkGTWGIi.mjs.map → service-CQnc276a.mjs.map} +1 -1
  317. package/dist/{settings-CpA4lQFt.mjs → settings-C2PaBS49.mjs} +3 -3
  318. package/dist/{settings-CpA4lQFt.mjs.map → settings-C2PaBS49.mjs.map} +1 -1
  319. package/dist/{settings-C4s8hFQm.mjs → settings-Dtc0DU31.mjs} +3 -3
  320. package/dist/{settings-C4s8hFQm.mjs.map → settings-Dtc0DU31.mjs.map} +1 -1
  321. package/dist/{taxonomies-Ce49uIzY.mjs → taxonomies-BN6M9Nrv.mjs} +26 -17
  322. package/dist/taxonomies-BN6M9Nrv.mjs.map +1 -0
  323. package/dist/{taxonomies-DjSKBZpq.mjs → taxonomies-r7pqLBCn.mjs} +53 -24
  324. package/dist/taxonomies-r7pqLBCn.mjs.map +1 -0
  325. package/dist/{taxonomy-DfVooU4W.mjs → taxonomy-0mCI25HN.mjs} +3 -3
  326. package/dist/{taxonomy-DfVooU4W.mjs.map → taxonomy-0mCI25HN.mjs.map} +1 -1
  327. package/dist/{types-D1iJ3DpO.mjs → types-CrRUFdej.mjs} +2 -2
  328. package/dist/{types-D1iJ3DpO.mjs.map → types-CrRUFdej.mjs.map} +1 -1
  329. package/dist/{user-Bh-L1qo6.mjs → user-aTXqmXBz.mjs} +3 -3
  330. package/dist/{user-Bh-L1qo6.mjs.map → user-aTXqmXBz.mjs.map} +1 -1
  331. package/dist/{validate-V9nCwq_-.mjs → validate-CDT1jl6_.mjs} +11 -6
  332. package/dist/validate-CDT1jl6_.mjs.map +1 -0
  333. package/dist/validate-DULfgpJP.d.mts.map +1 -1
  334. package/dist/{validation-BsVUJfsP.mjs → validation-DlD0E35W.mjs} +8 -8
  335. package/dist/{validation-BsVUJfsP.mjs.map → validation-DlD0E35W.mjs.map} +1 -1
  336. package/dist/version-BRMngh9I.mjs +7 -0
  337. package/dist/{version-907opKac.mjs.map → version-BRMngh9I.mjs.map} +1 -1
  338. package/dist/{widgets-DGv1Z04V.mjs → widgets-5fipNkMT.mjs} +2 -2
  339. package/dist/{widgets-DGv1Z04V.mjs.map → widgets-5fipNkMT.mjs.map} +1 -1
  340. package/dist/{wxr-taxonomies-Cs1N6O8z.mjs → wxr-taxonomies-DrihupaC.mjs} +4 -4
  341. package/dist/{wxr-taxonomies-Cs1N6O8z.mjs.map → wxr-taxonomies-DrihupaC.mjs.map} +1 -1
  342. package/dist/{zod-generator-B5prQ5M4.mjs → zod-generator-CwkHWz4f.mjs} +2 -2
  343. package/dist/{zod-generator-B5prQ5M4.mjs.map → zod-generator-CwkHWz4f.mjs.map} +1 -1
  344. package/package.json +7 -7
  345. package/src/api/handlers/bylines.ts +5 -4
  346. package/src/api/handlers/content.ts +25 -7
  347. package/src/api/handlers/menus.ts +11 -6
  348. package/src/api/handlers/relations.ts +7 -2
  349. package/src/api/handlers/taxonomies.ts +22 -14
  350. package/src/api/schemas/bylines.ts +4 -4
  351. package/src/api/schemas/common.ts +7 -6
  352. package/src/api/schemas/menus.ts +2 -1
  353. package/src/api/schemas/relations.ts +3 -1
  354. package/src/api/schemas/taxonomies.ts +4 -2
  355. package/src/astro/prefetch.ts +7 -2
  356. package/src/astro/routes/api/admin/bylines/index.ts +5 -8
  357. package/src/astro/routes/api/oauth/authorize.ts +42 -10
  358. package/src/components/Gallery.astro +141 -26
  359. package/src/components/widgets/Categories.astro +1 -1
  360. package/src/components/widgets/Tags.astro +1 -1
  361. package/src/config/secrets.ts +25 -19
  362. package/src/content/converters/gallery.ts +61 -0
  363. package/src/content/converters/portable-text-to-prosemirror.ts +19 -0
  364. package/src/content/converters/prosemirror-to-portable-text.ts +18 -0
  365. package/src/content/converters/types.ts +36 -0
  366. package/src/database/dialect-helpers.ts +3 -4
  367. package/src/database/pg-migration-lock.ts +1 -4
  368. package/src/emdash-runtime.ts +55 -17
  369. package/src/i18n/config.ts +8 -0
  370. package/src/i18n/repair-locale-casing.ts +51 -0
  371. package/src/search/query.ts +3 -2
  372. package/src/seed/apply.ts +9 -7
  373. package/src/seed/validate.ts +15 -4
  374. package/src/taxonomies/index.ts +64 -23
  375. package/dist/api-b8WIiGU4.mjs.map +0 -1
  376. package/dist/apply-CmIJK9j8.mjs.map +0 -1
  377. package/dist/bylines-BJbT4gKS.mjs.map +0 -1
  378. package/dist/config-CVssduLe.mjs.map +0 -1
  379. package/dist/dialect-helpers-HxEQGl_1.mjs.map +0 -1
  380. package/dist/index-wYnC6u4o.d.mts.map +0 -1
  381. package/dist/media-kIV1IxFf.mjs.map +0 -1
  382. package/dist/menus-BcyElFtI.mjs.map +0 -1
  383. package/dist/menus-CZyG6rvx.mjs.map +0 -1
  384. package/dist/redirects-BBq3n2Rj.mjs.map +0 -1
  385. package/dist/relations-BKvO39-9.mjs.map +0 -1
  386. package/dist/relations-Bh8jlFsU.d.mts.map +0 -1
  387. package/dist/search-Bff-7jFt.mjs.map +0 -1
  388. package/dist/secrets-CSwQIl4q.mjs.map +0 -1
  389. package/dist/taxonomies-Ce49uIzY.mjs.map +0 -1
  390. package/dist/taxonomies-DjSKBZpq.mjs.map +0 -1
  391. package/dist/validate-V9nCwq_-.mjs.map +0 -1
  392. package/dist/version-907opKac.mjs +0 -7
@@ -1 +1 @@
1
- {"version":3,"file":"relation-9M9j_UWo.mjs","names":[],"sources":["../src/database/repositories/relation.ts"],"sourcesContent":["import type { Kysely, Selectable } from \"kysely\";\nimport { ulid } from \"ulidx\";\n\nimport { chunks, SQL_BATCH_SIZE } from \"../../utils/chunks.js\";\nimport type { Database, RelationTable, ContentReferenceTable } from \"../types.js\";\nimport { decodeCursor, encodeCursor, InvalidCursorError, type FindManyResult } from \"./types.js\";\n\nexport interface Relation {\n\tid: string;\n\tname: string;\n\tparentCollection: string;\n\tchildCollection: string;\n\tparentLabel: string;\n\tchildLabel: string;\n\tlocale: string;\n\ttranslationGroup: string;\n}\n\nexport interface CreateRelationInput {\n\tname: string;\n\t/** Required for a base relation; ignored (inherited from the source) when\n\t * `translationOf` is set. */\n\tparentCollection?: string;\n\t/** Required for a base relation; ignored (inherited from the source) when\n\t * `translationOf` is set. */\n\tchildCollection?: string;\n\tparentLabel: string;\n\tchildLabel: string;\n\t/** Omit to let the DB default (current value: 'en') apply. Higher layers\n\t * resolve locale from request context / i18n config. */\n\tlocale?: string;\n\t/** When set, joins the source relation's translation_group AND inherits its\n\t * structural fields (name, parentCollection, childCollection). Only locale +\n\t * labels may differ on a translation. */\n\ttranslationOf?: string;\n}\n\nexport interface UpdateRelationInput {\n\t/** Only localized fields are mutable per row. Changing structural fields\n\t * (name/collections) is a cross-group operation deferred to a later slice. */\n\tparentLabel?: string;\n\tchildLabel?: string;\n}\n\nexport interface ContentReference {\n\tid: string;\n\trelationGroup: string;\n\tparentGroup: string;\n\tchildGroup: string;\n\tsortOrder: number;\n}\n\n/**\n * Content-references repository.\n *\n * Owns relation *definitions* (`_emdash_relations`, row-per-locale, mirroring\n * `_emdash_taxonomy_defs`) and the *edge* junction (`_emdash_content_references`,\n * keyed by `translation_group` so edges are locale-agnostic, mirroring\n * `content_taxonomies`).\n *\n * Like `TaxonomyRepository`, this is not the validation boundary: it trusts its\n * typed inputs. The API slice supplies Zod schemas at the route and enforces\n * collection-agreement / relation-existence invariants in the handler. The repo\n * does not resolve locale fallbacks — callers pass the locale they want.\n */\nexport class RelationRepository {\n\tconstructor(private db: Kysely<Database>) {}\n\n\t/**\n\t * Create a relation. Without `translationOf`, mints a fresh group\n\t * (`translation_group = id`, matching the migration backfill pattern). With\n\t * `translationOf`, the structural fields (name, parentCollection,\n\t * childCollection) and the translation_group are inherited from the source;\n\t * locale and the two labels are taken from `input`.\n\t */\n\tasync create(input: CreateRelationInput): Promise<Relation> {\n\t\tconst id = ulid();\n\t\tconst now = new Date().toISOString();\n\n\t\tlet translationGroup = id;\n\t\tlet name: string;\n\t\tlet parentCollection: string;\n\t\tlet childCollection: string;\n\n\t\tif (input.translationOf) {\n\t\t\tconst source = await this.findById(input.translationOf);\n\t\t\t// translation_group is NOT NULL here, so we cannot fall back to a\n\t\t\t// fresh group like TaxonomyRepository does — a bad translationOf must\n\t\t\t// fail loudly rather than silently mint an unlinked relation.\n\t\t\tif (!source) throw new Error(\"Source relation for translation not found\");\n\t\t\ttranslationGroup = source.translationGroup;\n\t\t\tname = source.name;\n\t\t\tparentCollection = source.parentCollection;\n\t\t\tchildCollection = source.childCollection;\n\t\t} else {\n\t\t\t// A base relation carries its own structural fields. The API layer's Zod\n\t\t\t// schema enforces this; guard here too since the repo trusts its inputs\n\t\t\t// and the columns are NOT NULL.\n\t\t\tif (input.parentCollection === undefined || input.childCollection === undefined) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"parentCollection and childCollection are required unless translationOf is set\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tname = input.name;\n\t\t\tparentCollection = input.parentCollection;\n\t\t\tchildCollection = input.childCollection;\n\t\t}\n\n\t\tawait this.db\n\t\t\t.insertInto(\"_emdash_relations\")\n\t\t\t.values({\n\t\t\t\tid,\n\t\t\t\tname,\n\t\t\t\tparent_collection: parentCollection,\n\t\t\t\tchild_collection: childCollection,\n\t\t\t\tparent_label: input.parentLabel,\n\t\t\t\tchild_label: input.childLabel,\n\t\t\t\tcreated_at: now,\n\t\t\t\tupdated_at: now,\n\t\t\t\t// Omit `locale` so the DB DEFAULT (configured defaultLocale)\n\t\t\t\t// applies — matches TaxonomyRepository.create.\n\t\t\t\t...(input.locale !== undefined ? { locale: input.locale } : {}),\n\t\t\t\ttranslation_group: translationGroup,\n\t\t\t})\n\t\t\t.execute();\n\n\t\tconst relation = await this.findById(id);\n\t\tif (!relation) throw new Error(\"Failed to create relation\");\n\t\treturn relation;\n\t}\n\n\tasync findById(id: string): Promise<Relation | null> {\n\t\tconst row = await this.db\n\t\t\t.selectFrom(\"_emdash_relations\")\n\t\t\t.selectAll()\n\t\t\t.where(\"id\", \"=\", id)\n\t\t\t.executeTakeFirst();\n\t\treturn row ? this.rowToRelation(row) : null;\n\t}\n\n\t/**\n\t * Find a relation by name. With `locale`, filter by it; without, return the\n\t * lowest-locale-code match deterministically. Mirrors\n\t * `TaxonomyRepository.findBySlug` — note this returns a single row, unlike\n\t * `TaxonomyRepository.findByName` which returns every term in a taxonomy.\n\t */\n\tasync findByName(name: string, locale?: string): Promise<Relation | null> {\n\t\tlet query = this.db.selectFrom(\"_emdash_relations\").selectAll().where(\"name\", \"=\", name);\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.rowToRelation(row) : null;\n\t}\n\n\t/** Every translation sibling (including itself) sharing a translation_group. */\n\tasync findTranslations(translationGroup: string): Promise<Relation[]> {\n\t\tconst rows = await this.db\n\t\t\t.selectFrom(\"_emdash_relations\")\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.rowToRelation(row));\n\t}\n\n\t/**\n\t * All relations, ordered by name then id (id is a stable tiebreak for\n\t * relations sharing a name across locales). Optionally filtered by locale.\n\t */\n\tasync list(locale?: string): Promise<Relation[]> {\n\t\tlet query = this.db\n\t\t\t.selectFrom(\"_emdash_relations\")\n\t\t\t.selectAll()\n\t\t\t.orderBy(\"name\", \"asc\")\n\t\t\t.orderBy(\"id\", \"asc\");\n\t\tif (locale !== undefined) query = query.where(\"locale\", \"=\", locale);\n\t\tconst rows = await query.execute();\n\t\treturn rows.map((row) => this.rowToRelation(row));\n\t}\n\n\t/** Relations where `collection` is the parent OR the child side. */\n\tasync findForCollection(collection: string, locale?: string): Promise<Relation[]> {\n\t\tlet query = this.db\n\t\t\t.selectFrom(\"_emdash_relations\")\n\t\t\t.selectAll()\n\t\t\t.where((eb) =>\n\t\t\t\teb.or([eb(\"parent_collection\", \"=\", collection), eb(\"child_collection\", \"=\", collection)]),\n\t\t\t)\n\t\t\t.orderBy(\"name\", \"asc\")\n\t\t\t.orderBy(\"id\", \"asc\");\n\t\tif (locale !== undefined) query = query.where(\"locale\", \"=\", locale);\n\t\tconst rows = await query.execute();\n\t\treturn rows.map((row) => this.rowToRelation(row));\n\t}\n\n\t/**\n\t * Update the localized labels of one relation row. Structural fields are\n\t * immutable here (a cross-group concern). No-ops when nothing is supplied.\n\t */\n\tasync update(id: string, input: UpdateRelationInput): Promise<Relation | null> {\n\t\tconst existing = await this.findById(id);\n\t\tif (!existing) return null;\n\n\t\tconst updates: Record<string, unknown> = {};\n\t\tif (input.parentLabel !== undefined) updates.parent_label = input.parentLabel;\n\t\tif (input.childLabel !== undefined) updates.child_label = input.childLabel;\n\n\t\tif (Object.keys(updates).length > 0) {\n\t\t\tupdates.updated_at = new Date().toISOString();\n\t\t\tawait this.db.updateTable(\"_emdash_relations\").set(updates).where(\"id\", \"=\", id).execute();\n\t\t}\n\n\t\treturn this.findById(id);\n\t}\n\n\t/**\n\t * Delete one relation row. When it is the *last* translation of its group,\n\t * purge edges referencing that group (application-layer cascade — group\n\t * linking precludes a SQL FK). Mirrors `TaxonomyRepository.delete`.\n\t */\n\tasync delete(id: string): Promise<boolean> {\n\t\tconst relation = await this.findById(id);\n\t\tif (!relation) return false;\n\n\t\tconst siblings = await this.db\n\t\t\t.selectFrom(\"_emdash_relations\")\n\t\t\t.select(\"id\")\n\t\t\t.where(\"translation_group\", \"=\", relation.translationGroup)\n\t\t\t.where(\"id\", \"!=\", id)\n\t\t\t.execute();\n\t\tif (siblings.length === 0) {\n\t\t\tawait this.db\n\t\t\t\t.deleteFrom(\"_emdash_content_references\")\n\t\t\t\t.where(\"relation_group\", \"=\", relation.translationGroup)\n\t\t\t\t.execute();\n\t\t}\n\n\t\tconst result = await this.db\n\t\t\t.deleteFrom(\"_emdash_relations\")\n\t\t\t.where(\"id\", \"=\", id)\n\t\t\t.executeTakeFirst();\n\t\treturn (result.numDeletedRows ?? 0n) > 0n;\n\t}\n\n\t/** Normalize a relation id OR group to its translation_group. Returns null\n\t * for an unknown relation (edge methods then no-op, matching\n\t * `TaxonomyRepository.attachToEntry`). */\n\tprivate async resolveRelationGroup(idOrGroup: string): Promise<string | null> {\n\t\tconst row = await this.db\n\t\t\t.selectFrom(\"_emdash_relations\")\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\tprivate rowToReference(row: Selectable<ContentReferenceTable>): ContentReference {\n\t\treturn {\n\t\t\tid: row.id,\n\t\t\trelationGroup: row.relation_group,\n\t\t\tparentGroup: row.parent_group,\n\t\t\tchildGroup: row.child_group,\n\t\t\tsortOrder: row.sort_order,\n\t\t};\n\t}\n\n\t/**\n\t * Link `parentGroup → childGroup` under a relation. `relation` is a relation\n\t * id or group. Idempotent (onConflict doNothing against the unique edge).\n\t * `sortOrder` defaults to append: max(sort_order)+1 within (relation, parent).\n\t *\n\t * The default-append MAX→INSERT is not atomic: concurrent appends without an\n\t * explicit `sortOrder` may both read the same max and collide on sort_order,\n\t * and onConflict silently drops the loser. Callers needing strict ordering\n\t * under concurrency should pass `sortOrder` explicitly (or serialize).\n\t */\n\tasync addReference(\n\t\trelation: string,\n\t\tparentGroup: string,\n\t\tchildGroup: string,\n\t\tsortOrder?: number,\n\t): Promise<void> {\n\t\tconst relationGroup = await this.resolveRelationGroup(relation);\n\t\tif (!relationGroup) return;\n\n\t\tlet order = sortOrder;\n\t\tif (order === undefined) {\n\t\t\tconst max = await this.db\n\t\t\t\t.selectFrom(\"_emdash_content_references\")\n\t\t\t\t.select((eb) => eb.fn.max(\"sort_order\").as(\"max\"))\n\t\t\t\t.where(\"relation_group\", \"=\", relationGroup)\n\t\t\t\t.where(\"parent_group\", \"=\", parentGroup)\n\t\t\t\t.executeTakeFirst();\n\t\t\torder = max?.max === null || max?.max === undefined ? 0 : Number(max.max) + 1;\n\t\t}\n\n\t\tawait this.db\n\t\t\t.insertInto(\"_emdash_content_references\")\n\t\t\t.values({\n\t\t\t\tid: ulid(),\n\t\t\t\trelation_group: relationGroup,\n\t\t\t\tparent_group: parentGroup,\n\t\t\t\tchild_group: childGroup,\n\t\t\t\tsort_order: order,\n\t\t\t\tcreated_at: new Date().toISOString(),\n\t\t\t})\n\t\t\t.onConflict((oc) => oc.doNothing())\n\t\t\t.execute();\n\t}\n\n\t/** Remove one `parentGroup → childGroup` edge under a relation. */\n\tasync removeReference(relation: string, parentGroup: string, childGroup: string): Promise<void> {\n\t\tconst relationGroup = await this.resolveRelationGroup(relation);\n\t\tif (!relationGroup) return;\n\n\t\tawait this.db\n\t\t\t.deleteFrom(\"_emdash_content_references\")\n\t\t\t.where(\"relation_group\", \"=\", relationGroup)\n\t\t\t.where(\"parent_group\", \"=\", parentGroup)\n\t\t\t.where(\"child_group\", \"=\", childGroup)\n\t\t\t.execute();\n\t}\n\n\t/** Forward traversal: a parent's children for a relation, ordered. */\n\tasync getChildren(relation: string, parentGroup: string): Promise<ContentReference[]> {\n\t\tconst relationGroup = await this.resolveRelationGroup(relation);\n\t\tif (!relationGroup) return [];\n\n\t\tconst rows = await this.db\n\t\t\t.selectFrom(\"_emdash_content_references\")\n\t\t\t.selectAll()\n\t\t\t.where(\"relation_group\", \"=\", relationGroup)\n\t\t\t.where(\"parent_group\", \"=\", parentGroup)\n\t\t\t.orderBy(\"sort_order\", \"asc\")\n\t\t\t.orderBy(\"id\", \"asc\")\n\t\t\t.execute();\n\t\treturn rows.map((row) => this.rowToReference(row));\n\t}\n\n\t/**\n\t * Forward traversal, paginated: one page of a parent's children for a\n\t * relation, ordered by `(sort_order, id)`. Use this on request paths — a\n\t * parent's children are capped but still up to 1000, and an unbounded read\n\t * scales poorly. Returns `{ items, nextCursor? }`; the cursor's order value is\n\t * the row's `sort_order`. Default limit 50, max 100.\n\t */\n\tasync getChildrenPage(\n\t\trelation: string,\n\t\tparentGroup: string,\n\t\toptions: { limit?: number; cursor?: string } = {},\n\t): Promise<FindManyResult<ContentReference>> {\n\t\tconst relationGroup = await this.resolveRelationGroup(relation);\n\t\tif (!relationGroup) return { items: [] };\n\n\t\tconst limit = Math.min(options.limit || 50, 100);\n\n\t\tlet query = this.db\n\t\t\t.selectFrom(\"_emdash_content_references\")\n\t\t\t.selectAll()\n\t\t\t.where(\"relation_group\", \"=\", relationGroup)\n\t\t\t.where(\"parent_group\", \"=\", parentGroup);\n\n\t\tif (options.cursor) {\n\t\t\tconst decoded = decodeCursor(options.cursor);\n\t\t\tconst sortOrder = Number(decoded.orderValue);\n\t\t\t// `decodeCursor` only guarantees `orderValue` is a string; a hand-crafted\n\t\t\t// cursor with a non-numeric order value would coerce to NaN and blow up at\n\t\t\t// the driver bind as a 500. A bad cursor is a client error — surface it as\n\t\t\t// INVALID_CURSOR (400). Server-issued cursors are always numeric here.\n\t\t\tif (!Number.isFinite(sortOrder)) throw new InvalidCursorError(options.cursor);\n\t\t\tquery = query.where((eb) =>\n\t\t\t\teb.or([\n\t\t\t\t\teb(\"sort_order\", \">\", sortOrder),\n\t\t\t\t\teb.and([eb(\"sort_order\", \"=\", sortOrder), eb(\"id\", \">\", decoded.id)]),\n\t\t\t\t]),\n\t\t\t);\n\t\t}\n\n\t\tconst rows = await query\n\t\t\t.orderBy(\"sort_order\", \"asc\")\n\t\t\t.orderBy(\"id\", \"asc\")\n\t\t\t.limit(limit + 1)\n\t\t\t.execute();\n\n\t\tconst hasMore = rows.length > limit;\n\t\tconst items = rows.slice(0, limit).map((row) => this.rowToReference(row));\n\t\tconst result: FindManyResult<ContentReference> = { items };\n\t\tconst last = items.at(-1);\n\t\tif (hasMore && last) {\n\t\t\tresult.nextCursor = encodeCursor(String(last.sortOrder), last.id);\n\t\t}\n\t\treturn result;\n\t}\n\n\t/** Backlink traversal: the parents that reference a child for a relation. */\n\tasync getParents(relation: string, childGroup: string): Promise<ContentReference[]> {\n\t\tconst relationGroup = await this.resolveRelationGroup(relation);\n\t\tif (!relationGroup) return [];\n\n\t\tconst rows = await this.db\n\t\t\t.selectFrom(\"_emdash_content_references\")\n\t\t\t.selectAll()\n\t\t\t.where(\"relation_group\", \"=\", relationGroup)\n\t\t\t.where(\"child_group\", \"=\", childGroup)\n\t\t\t.orderBy(\"id\", \"asc\")\n\t\t\t.execute();\n\t\treturn rows.map((row) => this.rowToReference(row));\n\t}\n\n\t/**\n\t * Replace all children of `parentGroup` under a relation with `childGroups`,\n\t * assigning positional sort_order (index in the deduped array). Deletes the\n\t * old set for this (relation, parent) and re-inserts — simple and correct;\n\t * the set is small (one parent's children). Mirrors the intent of\n\t * `TaxonomyRepository.setTermsForEntry`.\n\t *\n\t * A parent references a given child at most once (the unique edge), so\n\t * duplicate `childGroups` are collapsed first-occurrence-wins rather than\n\t * relying on the insert's onConflict to silently drop them. Not wrapped in a\n\t * transaction: a crash between the delete and insert leaves the parent with\n\t * no children — acceptable for a replace-all, since a retry restores state.\n\t *\n\t * Concurrency: two simultaneous replace-all calls for the same (relation,\n\t * parent) can interleave their deletes and inserts and merge into the union of\n\t * both sets (a lost update — neither \"replace\" wins). This is non-corrupting —\n\t * keyset pagination stays totally ordered via the `(sort_order, id)` tiebreak\n\t * even with duplicate sort_orders — and a single client editing one parent's\n\t * children serially never hits it. A D1-portable fix isn't available (no\n\t * multi-statement transactions), so concurrent replace-all on one parent is\n\t * unsupported by design rather than guarded here.\n\t */\n\tasync setChildren(relation: string, parentGroup: string, childGroups: string[]): Promise<void> {\n\t\tconst relationGroup = await this.resolveRelationGroup(relation);\n\t\tif (!relationGroup) return;\n\n\t\tawait this.db\n\t\t\t.deleteFrom(\"_emdash_content_references\")\n\t\t\t.where(\"relation_group\", \"=\", relationGroup)\n\t\t\t.where(\"parent_group\", \"=\", parentGroup)\n\t\t\t.execute();\n\n\t\t// Collapse duplicates so positional sort_order has no gaps.\n\t\tconst uniqueChildGroups = [...new Set(childGroups)];\n\t\tif (uniqueChildGroups.length === 0) return;\n\n\t\tconst now = new Date().toISOString();\n\t\tawait this.db\n\t\t\t.insertInto(\"_emdash_content_references\")\n\t\t\t.values(\n\t\t\t\tuniqueChildGroups.map((childGroup, index) => ({\n\t\t\t\t\tid: ulid(),\n\t\t\t\t\trelation_group: relationGroup,\n\t\t\t\t\tparent_group: parentGroup,\n\t\t\t\t\tchild_group: childGroup,\n\t\t\t\t\tsort_order: index,\n\t\t\t\t\tcreated_at: now,\n\t\t\t\t})),\n\t\t\t)\n\t\t\t// Belt-and-suspenders: the DELETE above already cleared this\n\t\t\t// (relation, parent), so no conflict is possible within one call.\n\t\t\t// This is NOT a concurrency guarantee — delete-then-insert is not atomic.\n\t\t\t.onConflict((oc) => oc.doNothing())\n\t\t\t.execute();\n\t}\n\n\t/**\n\t * Backlink traversal, paginated: one page of the parents that reference a\n\t * child for a relation, ordered by `id`. Unlike a parent's children, a\n\t * child's backlinks are *unbounded* — one popular entry can be referenced by\n\t * arbitrarily many parents — so this read must paginate. Returns\n\t * `{ items, nextCursor? }`; the cursor's order value is the row `id`. Default\n\t * limit 50, max 100.\n\t */\n\tasync getParentsPage(\n\t\trelation: string,\n\t\tchildGroup: string,\n\t\toptions: { limit?: number; cursor?: string } = {},\n\t): Promise<FindManyResult<ContentReference>> {\n\t\tconst relationGroup = await this.resolveRelationGroup(relation);\n\t\tif (!relationGroup) return { items: [] };\n\n\t\tconst limit = Math.min(options.limit || 50, 100);\n\n\t\tlet query = this.db\n\t\t\t.selectFrom(\"_emdash_content_references\")\n\t\t\t.selectAll()\n\t\t\t.where(\"relation_group\", \"=\", relationGroup)\n\t\t\t.where(\"child_group\", \"=\", childGroup);\n\n\t\tif (options.cursor) {\n\t\t\tconst decoded = decodeCursor(options.cursor);\n\t\t\tquery = query.where(\"id\", \">\", decoded.id);\n\t\t}\n\n\t\tconst rows = await query\n\t\t\t.orderBy(\"id\", \"asc\")\n\t\t\t.limit(limit + 1)\n\t\t\t.execute();\n\n\t\tconst hasMore = rows.length > limit;\n\t\tconst items = rows.slice(0, limit).map((row) => this.rowToReference(row));\n\t\tconst result: FindManyResult<ContentReference> = { items };\n\t\tconst last = items.at(-1);\n\t\tif (hasMore && last) {\n\t\t\tresult.nextCursor = encodeCursor(last.id, last.id);\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Remove every edge where `group` is the parent OR the child — i.e. ensure no\n\t * orphaned reference edges survive when a content entry is deleted. The\n\t * application-layer cascade that group-linking precludes at the SQL level.\n\t * Wiring this into the content-delete path is a later (handler) slice.\n\t * Returns the number of edges removed.\n\t */\n\tasync clearReferencesForGroup(group: string): Promise<number> {\n\t\tconst result = await this.db\n\t\t\t.deleteFrom(\"_emdash_content_references\")\n\t\t\t.where((eb) => eb.or([eb(\"parent_group\", \"=\", group), eb(\"child_group\", \"=\", group)]))\n\t\t\t.executeTakeFirst();\n\t\treturn Number(result.numDeletedRows ?? 0);\n\t}\n\n\t/** Count a parent's children under a relation. */\n\tasync countChildren(relation: string, parentGroup: string): Promise<number> {\n\t\tconst relationGroup = await this.resolveRelationGroup(relation);\n\t\tif (!relationGroup) return 0;\n\t\tconst result = await this.db\n\t\t\t.selectFrom(\"_emdash_content_references\")\n\t\t\t.select((eb) => eb.fn.count(\"id\").as(\"count\"))\n\t\t\t.where(\"relation_group\", \"=\", relationGroup)\n\t\t\t.where(\"parent_group\", \"=\", parentGroup)\n\t\t\t.executeTakeFirst();\n\t\treturn Number(result?.count ?? 0);\n\t}\n\n\t/** Count a child's parents (backlinks) under a relation. */\n\tasync countParents(relation: string, childGroup: string): Promise<number> {\n\t\tconst relationGroup = await this.resolveRelationGroup(relation);\n\t\tif (!relationGroup) return 0;\n\t\tconst result = await this.db\n\t\t\t.selectFrom(\"_emdash_content_references\")\n\t\t\t.select((eb) => eb.fn.count(\"id\").as(\"count\"))\n\t\t\t.where(\"relation_group\", \"=\", relationGroup)\n\t\t\t.where(\"child_group\", \"=\", childGroup)\n\t\t\t.executeTakeFirst();\n\t\treturn Number(result?.count ?? 0);\n\t}\n\n\t/**\n\t * Batch child-counts for many parents under a relation. Chunks at\n\t * SQL_BATCH_SIZE for D1's bind-parameter limit. Returns parent_group → count\n\t * (parents with no children are absent from the map). Mirrors\n\t * `TaxonomyRepository.countEntriesForTerms`.\n\t */\n\tasync countChildrenForParents(\n\t\trelation: string,\n\t\tparentGroups: string[],\n\t): Promise<Map<string, number>> {\n\t\tconst counts = new Map<string, number>();\n\t\tif (parentGroups.length === 0) return counts;\n\t\tconst relationGroup = await this.resolveRelationGroup(relation);\n\t\tif (!relationGroup) return counts;\n\n\t\tfor (const chunk of chunks(parentGroups, SQL_BATCH_SIZE)) {\n\t\t\tconst rows = await this.db\n\t\t\t\t.selectFrom(\"_emdash_content_references\")\n\t\t\t\t.select([\"parent_group\", (eb) => eb.fn.count(\"id\").as(\"count\")])\n\t\t\t\t.where(\"relation_group\", \"=\", relationGroup)\n\t\t\t\t.where(\"parent_group\", \"in\", chunk)\n\t\t\t\t.groupBy(\"parent_group\")\n\t\t\t\t.execute();\n\t\t\tfor (const row of rows) {\n\t\t\t\tcounts.set(row.parent_group, Number(row.count ?? 0));\n\t\t\t}\n\t\t}\n\t\treturn counts;\n\t}\n\n\tprivate rowToRelation(row: Selectable<RelationTable>): Relation {\n\t\treturn {\n\t\t\tid: row.id,\n\t\t\tname: row.name,\n\t\t\tparentCollection: row.parent_collection,\n\t\t\tchildCollection: row.child_collection,\n\t\t\tparentLabel: row.parent_label,\n\t\t\tchildLabel: row.child_label,\n\t\t\tlocale: row.locale,\n\t\t\ttranslationGroup: row.translation_group,\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiEA,IAAa,qBAAb,MAAgC;CAC/B,YAAY,AAAQ,IAAsB;EAAtB;;;;;;;;;CASpB,MAAM,OAAO,OAA+C;EAC3D,MAAM,KAAK,MAAM;EACjB,MAAM,uBAAM,IAAI,MAAM,EAAC,aAAa;EAEpC,IAAI,mBAAmB;EACvB,IAAI;EACJ,IAAI;EACJ,IAAI;AAEJ,MAAI,MAAM,eAAe;GACxB,MAAM,SAAS,MAAM,KAAK,SAAS,MAAM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K,GACtB,WAAW,6BAA6B,CACxC,OAAO,CAAC,iBAAiB,OAAO,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,QAAQ,CAAC,CAAC,CAC/D,MAAM,kBAAkB,KAAK,cAAc,CAC3C,MAAM,gBAAgB,MAAM,MAAM,CAClC,QAAQ,eAAe,CACvB,SAAS;AACX,QAAK,MAAM,OAAO,KACjB,QAAO,IAAI,IAAI,cAAc,OAAO,IAAI,SAAS,EAAE,CAAC;;AAGtD,SAAO;;CAGR,AAAQ,cAAc,KAA0C;AAC/D,SAAO;GACN,IAAI,IAAI;GACR,MAAM,IAAI;GACV,kBAAkB,IAAI;GACtB,iBAAiB,IAAI;GACrB,aAAa,IAAI;GACjB,YAAY,IAAI;GAChB,QAAQ,IAAI;GACZ,kBAAkB,IAAI;GACtB"}
1
+ {"version":3,"file":"relation-Du0r04E0.mjs","names":[],"sources":["../src/database/repositories/relation.ts"],"sourcesContent":["import type { Kysely, Selectable } from \"kysely\";\nimport { ulid } from \"ulidx\";\n\nimport { chunks, SQL_BATCH_SIZE } from \"../../utils/chunks.js\";\nimport type { Database, RelationTable, ContentReferenceTable } from \"../types.js\";\nimport { decodeCursor, encodeCursor, InvalidCursorError, type FindManyResult } from \"./types.js\";\n\nexport interface Relation {\n\tid: string;\n\tname: string;\n\tparentCollection: string;\n\tchildCollection: string;\n\tparentLabel: string;\n\tchildLabel: string;\n\tlocale: string;\n\ttranslationGroup: string;\n}\n\nexport interface CreateRelationInput {\n\tname: string;\n\t/** Required for a base relation; ignored (inherited from the source) when\n\t * `translationOf` is set. */\n\tparentCollection?: string;\n\t/** Required for a base relation; ignored (inherited from the source) when\n\t * `translationOf` is set. */\n\tchildCollection?: string;\n\tparentLabel: string;\n\tchildLabel: string;\n\t/** Omit to let the DB default (current value: 'en') apply. Higher layers\n\t * resolve locale from request context / i18n config. */\n\tlocale?: string;\n\t/** When set, joins the source relation's translation_group AND inherits its\n\t * structural fields (name, parentCollection, childCollection). Only locale +\n\t * labels may differ on a translation. */\n\ttranslationOf?: string;\n}\n\nexport interface UpdateRelationInput {\n\t/** Only localized fields are mutable per row. Changing structural fields\n\t * (name/collections) is a cross-group operation deferred to a later slice. */\n\tparentLabel?: string;\n\tchildLabel?: string;\n}\n\nexport interface ContentReference {\n\tid: string;\n\trelationGroup: string;\n\tparentGroup: string;\n\tchildGroup: string;\n\tsortOrder: number;\n}\n\n/**\n * Content-references repository.\n *\n * Owns relation *definitions* (`_emdash_relations`, row-per-locale, mirroring\n * `_emdash_taxonomy_defs`) and the *edge* junction (`_emdash_content_references`,\n * keyed by `translation_group` so edges are locale-agnostic, mirroring\n * `content_taxonomies`).\n *\n * Like `TaxonomyRepository`, this is not the validation boundary: it trusts its\n * typed inputs. The API slice supplies Zod schemas at the route and enforces\n * collection-agreement / relation-existence invariants in the handler. The repo\n * does not resolve locale fallbacks — callers pass the locale they want.\n */\nexport class RelationRepository {\n\tconstructor(private db: Kysely<Database>) {}\n\n\t/**\n\t * Create a relation. Without `translationOf`, mints a fresh group\n\t * (`translation_group = id`, matching the migration backfill pattern). With\n\t * `translationOf`, the structural fields (name, parentCollection,\n\t * childCollection) and the translation_group are inherited from the source;\n\t * locale and the two labels are taken from `input`.\n\t */\n\tasync create(input: CreateRelationInput): Promise<Relation> {\n\t\tconst id = ulid();\n\t\tconst now = new Date().toISOString();\n\n\t\tlet translationGroup = id;\n\t\tlet name: string;\n\t\tlet parentCollection: string;\n\t\tlet childCollection: string;\n\n\t\tif (input.translationOf) {\n\t\t\tconst source = await this.findById(input.translationOf);\n\t\t\t// translation_group is NOT NULL here, so we cannot fall back to a\n\t\t\t// fresh group like TaxonomyRepository does — a bad translationOf must\n\t\t\t// fail loudly rather than silently mint an unlinked relation.\n\t\t\tif (!source) throw new Error(\"Source relation for translation not found\");\n\t\t\ttranslationGroup = source.translationGroup;\n\t\t\tname = source.name;\n\t\t\tparentCollection = source.parentCollection;\n\t\t\tchildCollection = source.childCollection;\n\t\t} else {\n\t\t\t// A base relation carries its own structural fields. The API layer's Zod\n\t\t\t// schema enforces this; guard here too since the repo trusts its inputs\n\t\t\t// and the columns are NOT NULL.\n\t\t\tif (input.parentCollection === undefined || input.childCollection === undefined) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"parentCollection and childCollection are required unless translationOf is set\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tname = input.name;\n\t\t\tparentCollection = input.parentCollection;\n\t\t\tchildCollection = input.childCollection;\n\t\t}\n\n\t\tawait this.db\n\t\t\t.insertInto(\"_emdash_relations\")\n\t\t\t.values({\n\t\t\t\tid,\n\t\t\t\tname,\n\t\t\t\tparent_collection: parentCollection,\n\t\t\t\tchild_collection: childCollection,\n\t\t\t\tparent_label: input.parentLabel,\n\t\t\t\tchild_label: input.childLabel,\n\t\t\t\tcreated_at: now,\n\t\t\t\tupdated_at: now,\n\t\t\t\t// Omit `locale` so the DB DEFAULT (configured defaultLocale)\n\t\t\t\t// applies — matches TaxonomyRepository.create.\n\t\t\t\t...(input.locale !== undefined ? { locale: input.locale } : {}),\n\t\t\t\ttranslation_group: translationGroup,\n\t\t\t})\n\t\t\t.execute();\n\n\t\tconst relation = await this.findById(id);\n\t\tif (!relation) throw new Error(\"Failed to create relation\");\n\t\treturn relation;\n\t}\n\n\tasync findById(id: string): Promise<Relation | null> {\n\t\tconst row = await this.db\n\t\t\t.selectFrom(\"_emdash_relations\")\n\t\t\t.selectAll()\n\t\t\t.where(\"id\", \"=\", id)\n\t\t\t.executeTakeFirst();\n\t\treturn row ? this.rowToRelation(row) : null;\n\t}\n\n\t/**\n\t * Find a relation by name. With `locale`, filter by it; without, return the\n\t * lowest-locale-code match deterministically. Mirrors\n\t * `TaxonomyRepository.findBySlug` — note this returns a single row, unlike\n\t * `TaxonomyRepository.findByName` which returns every term in a taxonomy.\n\t */\n\tasync findByName(name: string, locale?: string): Promise<Relation | null> {\n\t\tlet query = this.db.selectFrom(\"_emdash_relations\").selectAll().where(\"name\", \"=\", name);\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.rowToRelation(row) : null;\n\t}\n\n\t/** Every translation sibling (including itself) sharing a translation_group. */\n\tasync findTranslations(translationGroup: string): Promise<Relation[]> {\n\t\tconst rows = await this.db\n\t\t\t.selectFrom(\"_emdash_relations\")\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.rowToRelation(row));\n\t}\n\n\t/**\n\t * All relations, ordered by name then id (id is a stable tiebreak for\n\t * relations sharing a name across locales). Optionally filtered by locale.\n\t */\n\tasync list(locale?: string): Promise<Relation[]> {\n\t\tlet query = this.db\n\t\t\t.selectFrom(\"_emdash_relations\")\n\t\t\t.selectAll()\n\t\t\t.orderBy(\"name\", \"asc\")\n\t\t\t.orderBy(\"id\", \"asc\");\n\t\tif (locale !== undefined) query = query.where(\"locale\", \"=\", locale);\n\t\tconst rows = await query.execute();\n\t\treturn rows.map((row) => this.rowToRelation(row));\n\t}\n\n\t/** Relations where `collection` is the parent OR the child side. */\n\tasync findForCollection(collection: string, locale?: string): Promise<Relation[]> {\n\t\tlet query = this.db\n\t\t\t.selectFrom(\"_emdash_relations\")\n\t\t\t.selectAll()\n\t\t\t.where((eb) =>\n\t\t\t\teb.or([eb(\"parent_collection\", \"=\", collection), eb(\"child_collection\", \"=\", collection)]),\n\t\t\t)\n\t\t\t.orderBy(\"name\", \"asc\")\n\t\t\t.orderBy(\"id\", \"asc\");\n\t\tif (locale !== undefined) query = query.where(\"locale\", \"=\", locale);\n\t\tconst rows = await query.execute();\n\t\treturn rows.map((row) => this.rowToRelation(row));\n\t}\n\n\t/**\n\t * Update the localized labels of one relation row. Structural fields are\n\t * immutable here (a cross-group concern). No-ops when nothing is supplied.\n\t */\n\tasync update(id: string, input: UpdateRelationInput): Promise<Relation | null> {\n\t\tconst existing = await this.findById(id);\n\t\tif (!existing) return null;\n\n\t\tconst updates: Record<string, unknown> = {};\n\t\tif (input.parentLabel !== undefined) updates.parent_label = input.parentLabel;\n\t\tif (input.childLabel !== undefined) updates.child_label = input.childLabel;\n\n\t\tif (Object.keys(updates).length > 0) {\n\t\t\tupdates.updated_at = new Date().toISOString();\n\t\t\tawait this.db.updateTable(\"_emdash_relations\").set(updates).where(\"id\", \"=\", id).execute();\n\t\t}\n\n\t\treturn this.findById(id);\n\t}\n\n\t/**\n\t * Delete one relation row. When it is the *last* translation of its group,\n\t * purge edges referencing that group (application-layer cascade — group\n\t * linking precludes a SQL FK). Mirrors `TaxonomyRepository.delete`.\n\t */\n\tasync delete(id: string): Promise<boolean> {\n\t\tconst relation = await this.findById(id);\n\t\tif (!relation) return false;\n\n\t\tconst siblings = await this.db\n\t\t\t.selectFrom(\"_emdash_relations\")\n\t\t\t.select(\"id\")\n\t\t\t.where(\"translation_group\", \"=\", relation.translationGroup)\n\t\t\t.where(\"id\", \"!=\", id)\n\t\t\t.execute();\n\t\tif (siblings.length === 0) {\n\t\t\tawait this.db\n\t\t\t\t.deleteFrom(\"_emdash_content_references\")\n\t\t\t\t.where(\"relation_group\", \"=\", relation.translationGroup)\n\t\t\t\t.execute();\n\t\t}\n\n\t\tconst result = await this.db\n\t\t\t.deleteFrom(\"_emdash_relations\")\n\t\t\t.where(\"id\", \"=\", id)\n\t\t\t.executeTakeFirst();\n\t\treturn (result.numDeletedRows ?? 0n) > 0n;\n\t}\n\n\t/** Normalize a relation id OR group to its translation_group. Returns null\n\t * for an unknown relation (edge methods then no-op, matching\n\t * `TaxonomyRepository.attachToEntry`). */\n\tprivate async resolveRelationGroup(idOrGroup: string): Promise<string | null> {\n\t\tconst row = await this.db\n\t\t\t.selectFrom(\"_emdash_relations\")\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\tprivate rowToReference(row: Selectable<ContentReferenceTable>): ContentReference {\n\t\treturn {\n\t\t\tid: row.id,\n\t\t\trelationGroup: row.relation_group,\n\t\t\tparentGroup: row.parent_group,\n\t\t\tchildGroup: row.child_group,\n\t\t\tsortOrder: row.sort_order,\n\t\t};\n\t}\n\n\t/**\n\t * Link `parentGroup → childGroup` under a relation. `relation` is a relation\n\t * id or group. Idempotent (onConflict doNothing against the unique edge).\n\t * `sortOrder` defaults to append: max(sort_order)+1 within (relation, parent).\n\t *\n\t * The default-append MAX→INSERT is not atomic: concurrent appends without an\n\t * explicit `sortOrder` may both read the same max and collide on sort_order,\n\t * and onConflict silently drops the loser. Callers needing strict ordering\n\t * under concurrency should pass `sortOrder` explicitly (or serialize).\n\t */\n\tasync addReference(\n\t\trelation: string,\n\t\tparentGroup: string,\n\t\tchildGroup: string,\n\t\tsortOrder?: number,\n\t): Promise<void> {\n\t\tconst relationGroup = await this.resolveRelationGroup(relation);\n\t\tif (!relationGroup) return;\n\n\t\tlet order = sortOrder;\n\t\tif (order === undefined) {\n\t\t\tconst max = await this.db\n\t\t\t\t.selectFrom(\"_emdash_content_references\")\n\t\t\t\t.select((eb) => eb.fn.max(\"sort_order\").as(\"max\"))\n\t\t\t\t.where(\"relation_group\", \"=\", relationGroup)\n\t\t\t\t.where(\"parent_group\", \"=\", parentGroup)\n\t\t\t\t.executeTakeFirst();\n\t\t\torder = max?.max === null || max?.max === undefined ? 0 : Number(max.max) + 1;\n\t\t}\n\n\t\tawait this.db\n\t\t\t.insertInto(\"_emdash_content_references\")\n\t\t\t.values({\n\t\t\t\tid: ulid(),\n\t\t\t\trelation_group: relationGroup,\n\t\t\t\tparent_group: parentGroup,\n\t\t\t\tchild_group: childGroup,\n\t\t\t\tsort_order: order,\n\t\t\t\tcreated_at: new Date().toISOString(),\n\t\t\t})\n\t\t\t.onConflict((oc) => oc.doNothing())\n\t\t\t.execute();\n\t}\n\n\t/** Remove one `parentGroup → childGroup` edge under a relation. */\n\tasync removeReference(relation: string, parentGroup: string, childGroup: string): Promise<void> {\n\t\tconst relationGroup = await this.resolveRelationGroup(relation);\n\t\tif (!relationGroup) return;\n\n\t\tawait this.db\n\t\t\t.deleteFrom(\"_emdash_content_references\")\n\t\t\t.where(\"relation_group\", \"=\", relationGroup)\n\t\t\t.where(\"parent_group\", \"=\", parentGroup)\n\t\t\t.where(\"child_group\", \"=\", childGroup)\n\t\t\t.execute();\n\t}\n\n\t/** Forward traversal: a parent's children for a relation, ordered. */\n\tasync getChildren(relation: string, parentGroup: string): Promise<ContentReference[]> {\n\t\tconst relationGroup = await this.resolveRelationGroup(relation);\n\t\tif (!relationGroup) return [];\n\n\t\tconst rows = await this.db\n\t\t\t.selectFrom(\"_emdash_content_references\")\n\t\t\t.selectAll()\n\t\t\t.where(\"relation_group\", \"=\", relationGroup)\n\t\t\t.where(\"parent_group\", \"=\", parentGroup)\n\t\t\t.orderBy(\"sort_order\", \"asc\")\n\t\t\t.orderBy(\"id\", \"asc\")\n\t\t\t.execute();\n\t\treturn rows.map((row) => this.rowToReference(row));\n\t}\n\n\t/**\n\t * Forward traversal, paginated: one page of a parent's children for a\n\t * relation, ordered by `(sort_order, id)`. Use this on request paths — a\n\t * parent's children are capped but still up to 1000, and an unbounded read\n\t * scales poorly. Returns `{ items, nextCursor? }`; the cursor's order value is\n\t * the row's `sort_order`. Default limit 50, max 100.\n\t */\n\tasync getChildrenPage(\n\t\trelation: string,\n\t\tparentGroup: string,\n\t\toptions: { limit?: number; cursor?: string } = {},\n\t): Promise<FindManyResult<ContentReference>> {\n\t\tconst relationGroup = await this.resolveRelationGroup(relation);\n\t\tif (!relationGroup) return { items: [] };\n\n\t\tconst limit = Math.min(options.limit || 50, 100);\n\n\t\tlet query = this.db\n\t\t\t.selectFrom(\"_emdash_content_references\")\n\t\t\t.selectAll()\n\t\t\t.where(\"relation_group\", \"=\", relationGroup)\n\t\t\t.where(\"parent_group\", \"=\", parentGroup);\n\n\t\tif (options.cursor) {\n\t\t\tconst decoded = decodeCursor(options.cursor);\n\t\t\tconst sortOrder = Number(decoded.orderValue);\n\t\t\t// `decodeCursor` only guarantees `orderValue` is a string; a hand-crafted\n\t\t\t// cursor with a non-numeric order value would coerce to NaN and blow up at\n\t\t\t// the driver bind as a 500. A bad cursor is a client error — surface it as\n\t\t\t// INVALID_CURSOR (400). Server-issued cursors are always numeric here.\n\t\t\tif (!Number.isFinite(sortOrder)) throw new InvalidCursorError(options.cursor);\n\t\t\tquery = query.where((eb) =>\n\t\t\t\teb.or([\n\t\t\t\t\teb(\"sort_order\", \">\", sortOrder),\n\t\t\t\t\teb.and([eb(\"sort_order\", \"=\", sortOrder), eb(\"id\", \">\", decoded.id)]),\n\t\t\t\t]),\n\t\t\t);\n\t\t}\n\n\t\tconst rows = await query\n\t\t\t.orderBy(\"sort_order\", \"asc\")\n\t\t\t.orderBy(\"id\", \"asc\")\n\t\t\t.limit(limit + 1)\n\t\t\t.execute();\n\n\t\tconst hasMore = rows.length > limit;\n\t\tconst items = rows.slice(0, limit).map((row) => this.rowToReference(row));\n\t\tconst result: FindManyResult<ContentReference> = { items };\n\t\tconst last = items.at(-1);\n\t\tif (hasMore && last) {\n\t\t\tresult.nextCursor = encodeCursor(String(last.sortOrder), last.id);\n\t\t}\n\t\treturn result;\n\t}\n\n\t/** Backlink traversal: the parents that reference a child for a relation. */\n\tasync getParents(relation: string, childGroup: string): Promise<ContentReference[]> {\n\t\tconst relationGroup = await this.resolveRelationGroup(relation);\n\t\tif (!relationGroup) return [];\n\n\t\tconst rows = await this.db\n\t\t\t.selectFrom(\"_emdash_content_references\")\n\t\t\t.selectAll()\n\t\t\t.where(\"relation_group\", \"=\", relationGroup)\n\t\t\t.where(\"child_group\", \"=\", childGroup)\n\t\t\t.orderBy(\"id\", \"asc\")\n\t\t\t.execute();\n\t\treturn rows.map((row) => this.rowToReference(row));\n\t}\n\n\t/**\n\t * Replace all children of `parentGroup` under a relation with `childGroups`,\n\t * assigning positional sort_order (index in the deduped array). Deletes the\n\t * old set for this (relation, parent) and re-inserts — simple and correct;\n\t * the set is small (one parent's children). Mirrors the intent of\n\t * `TaxonomyRepository.setTermsForEntry`.\n\t *\n\t * A parent references a given child at most once (the unique edge), so\n\t * duplicate `childGroups` are collapsed first-occurrence-wins rather than\n\t * relying on the insert's onConflict to silently drop them. Not wrapped in a\n\t * transaction: a crash between the delete and insert leaves the parent with\n\t * no children — acceptable for a replace-all, since a retry restores state.\n\t *\n\t * Concurrency: two simultaneous replace-all calls for the same (relation,\n\t * parent) can interleave their deletes and inserts and merge into the union of\n\t * both sets (a lost update — neither \"replace\" wins). This is non-corrupting —\n\t * keyset pagination stays totally ordered via the `(sort_order, id)` tiebreak\n\t * even with duplicate sort_orders — and a single client editing one parent's\n\t * children serially never hits it. A D1-portable fix isn't available (no\n\t * multi-statement transactions), so concurrent replace-all on one parent is\n\t * unsupported by design rather than guarded here.\n\t */\n\tasync setChildren(relation: string, parentGroup: string, childGroups: string[]): Promise<void> {\n\t\tconst relationGroup = await this.resolveRelationGroup(relation);\n\t\tif (!relationGroup) return;\n\n\t\tawait this.db\n\t\t\t.deleteFrom(\"_emdash_content_references\")\n\t\t\t.where(\"relation_group\", \"=\", relationGroup)\n\t\t\t.where(\"parent_group\", \"=\", parentGroup)\n\t\t\t.execute();\n\n\t\t// Collapse duplicates so positional sort_order has no gaps.\n\t\tconst uniqueChildGroups = [...new Set(childGroups)];\n\t\tif (uniqueChildGroups.length === 0) return;\n\n\t\tconst now = new Date().toISOString();\n\t\tawait this.db\n\t\t\t.insertInto(\"_emdash_content_references\")\n\t\t\t.values(\n\t\t\t\tuniqueChildGroups.map((childGroup, index) => ({\n\t\t\t\t\tid: ulid(),\n\t\t\t\t\trelation_group: relationGroup,\n\t\t\t\t\tparent_group: parentGroup,\n\t\t\t\t\tchild_group: childGroup,\n\t\t\t\t\tsort_order: index,\n\t\t\t\t\tcreated_at: now,\n\t\t\t\t})),\n\t\t\t)\n\t\t\t// Belt-and-suspenders: the DELETE above already cleared this\n\t\t\t// (relation, parent), so no conflict is possible within one call.\n\t\t\t// This is NOT a concurrency guarantee — delete-then-insert is not atomic.\n\t\t\t.onConflict((oc) => oc.doNothing())\n\t\t\t.execute();\n\t}\n\n\t/**\n\t * Backlink traversal, paginated: one page of the parents that reference a\n\t * child for a relation, ordered by `id`. Unlike a parent's children, a\n\t * child's backlinks are *unbounded* — one popular entry can be referenced by\n\t * arbitrarily many parents — so this read must paginate. Returns\n\t * `{ items, nextCursor? }`; the cursor's order value is the row `id`. Default\n\t * limit 50, max 100.\n\t */\n\tasync getParentsPage(\n\t\trelation: string,\n\t\tchildGroup: string,\n\t\toptions: { limit?: number; cursor?: string } = {},\n\t): Promise<FindManyResult<ContentReference>> {\n\t\tconst relationGroup = await this.resolveRelationGroup(relation);\n\t\tif (!relationGroup) return { items: [] };\n\n\t\tconst limit = Math.min(options.limit || 50, 100);\n\n\t\tlet query = this.db\n\t\t\t.selectFrom(\"_emdash_content_references\")\n\t\t\t.selectAll()\n\t\t\t.where(\"relation_group\", \"=\", relationGroup)\n\t\t\t.where(\"child_group\", \"=\", childGroup);\n\n\t\tif (options.cursor) {\n\t\t\tconst decoded = decodeCursor(options.cursor);\n\t\t\tquery = query.where(\"id\", \">\", decoded.id);\n\t\t}\n\n\t\tconst rows = await query\n\t\t\t.orderBy(\"id\", \"asc\")\n\t\t\t.limit(limit + 1)\n\t\t\t.execute();\n\n\t\tconst hasMore = rows.length > limit;\n\t\tconst items = rows.slice(0, limit).map((row) => this.rowToReference(row));\n\t\tconst result: FindManyResult<ContentReference> = { items };\n\t\tconst last = items.at(-1);\n\t\tif (hasMore && last) {\n\t\t\tresult.nextCursor = encodeCursor(last.id, last.id);\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Remove every edge where `group` is the parent OR the child — i.e. ensure no\n\t * orphaned reference edges survive when a content entry is deleted. The\n\t * application-layer cascade that group-linking precludes at the SQL level.\n\t * Wiring this into the content-delete path is a later (handler) slice.\n\t * Returns the number of edges removed.\n\t */\n\tasync clearReferencesForGroup(group: string): Promise<number> {\n\t\tconst result = await this.db\n\t\t\t.deleteFrom(\"_emdash_content_references\")\n\t\t\t.where((eb) => eb.or([eb(\"parent_group\", \"=\", group), eb(\"child_group\", \"=\", group)]))\n\t\t\t.executeTakeFirst();\n\t\treturn Number(result.numDeletedRows ?? 0);\n\t}\n\n\t/** Count a parent's children under a relation. */\n\tasync countChildren(relation: string, parentGroup: string): Promise<number> {\n\t\tconst relationGroup = await this.resolveRelationGroup(relation);\n\t\tif (!relationGroup) return 0;\n\t\tconst result = await this.db\n\t\t\t.selectFrom(\"_emdash_content_references\")\n\t\t\t.select((eb) => eb.fn.count(\"id\").as(\"count\"))\n\t\t\t.where(\"relation_group\", \"=\", relationGroup)\n\t\t\t.where(\"parent_group\", \"=\", parentGroup)\n\t\t\t.executeTakeFirst();\n\t\treturn Number(result?.count ?? 0);\n\t}\n\n\t/** Count a child's parents (backlinks) under a relation. */\n\tasync countParents(relation: string, childGroup: string): Promise<number> {\n\t\tconst relationGroup = await this.resolveRelationGroup(relation);\n\t\tif (!relationGroup) return 0;\n\t\tconst result = await this.db\n\t\t\t.selectFrom(\"_emdash_content_references\")\n\t\t\t.select((eb) => eb.fn.count(\"id\").as(\"count\"))\n\t\t\t.where(\"relation_group\", \"=\", relationGroup)\n\t\t\t.where(\"child_group\", \"=\", childGroup)\n\t\t\t.executeTakeFirst();\n\t\treturn Number(result?.count ?? 0);\n\t}\n\n\t/**\n\t * Batch child-counts for many parents under a relation. Chunks at\n\t * SQL_BATCH_SIZE for D1's bind-parameter limit. Returns parent_group → count\n\t * (parents with no children are absent from the map). Mirrors\n\t * `TaxonomyRepository.countEntriesForTerms`.\n\t */\n\tasync countChildrenForParents(\n\t\trelation: string,\n\t\tparentGroups: string[],\n\t): Promise<Map<string, number>> {\n\t\tconst counts = new Map<string, number>();\n\t\tif (parentGroups.length === 0) return counts;\n\t\tconst relationGroup = await this.resolveRelationGroup(relation);\n\t\tif (!relationGroup) return counts;\n\n\t\tfor (const chunk of chunks(parentGroups, SQL_BATCH_SIZE)) {\n\t\t\tconst rows = await this.db\n\t\t\t\t.selectFrom(\"_emdash_content_references\")\n\t\t\t\t.select([\"parent_group\", (eb) => eb.fn.count(\"id\").as(\"count\")])\n\t\t\t\t.where(\"relation_group\", \"=\", relationGroup)\n\t\t\t\t.where(\"parent_group\", \"in\", chunk)\n\t\t\t\t.groupBy(\"parent_group\")\n\t\t\t\t.execute();\n\t\t\tfor (const row of rows) {\n\t\t\t\tcounts.set(row.parent_group, Number(row.count ?? 0));\n\t\t\t}\n\t\t}\n\t\treturn counts;\n\t}\n\n\tprivate rowToRelation(row: Selectable<RelationTable>): Relation {\n\t\treturn {\n\t\t\tid: row.id,\n\t\t\tname: row.name,\n\t\t\tparentCollection: row.parent_collection,\n\t\t\tchildCollection: row.child_collection,\n\t\t\tparentLabel: row.parent_label,\n\t\t\tchildLabel: row.child_label,\n\t\t\tlocale: row.locale,\n\t\t\ttranslationGroup: row.translation_group,\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiEA,IAAa,qBAAb,MAAgC;CAC/B,YAAY,AAAQ,IAAsB;EAAtB;;;;;;;;;CASpB,MAAM,OAAO,OAA+C;EAC3D,MAAM,KAAK,MAAM;EACjB,MAAM,uBAAM,IAAI,MAAM,EAAC,aAAa;EAEpC,IAAI,mBAAmB;EACvB,IAAI;EACJ,IAAI;EACJ,IAAI;AAEJ,MAAI,MAAM,eAAe;GACxB,MAAM,SAAS,MAAM,KAAK,SAAS,MAAM,cAAc;AAIvD,OAAI,CAAC,OAAQ,OAAM,IAAI,MAAM,4CAA4C;AACzE,sBAAmB,OAAO;AAC1B,UAAO,OAAO;AACd,sBAAmB,OAAO;AAC1B,qBAAkB,OAAO;SACnB;AAIN,OAAI,MAAM,qBAAqB,UAAa,MAAM,oBAAoB,OACrE,OAAM,I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S;AACX,QAAK,MAAM,OAAO,KACjB,QAAO,IAAI,IAAI,cAAc,OAAO,IAAI,SAAS,EAAE,CAAC;;AAGtD,SAAO;;CAGR,AAAQ,cAAc,KAA0C;AAC/D,SAAO;GACN,IAAI,IAAI;GACR,MAAM,IAAI;GACV,kBAAkB,IAAI;GACtB,iBAAiB,IAAI;GACrB,aAAa,IAAI;GACjB,YAAY,IAAI;GAChB,QAAQ,IAAI;GACZ,kBAAkB,IAAI;GACtB"}
@@ -1,5 +1,5 @@
1
1
  import { i as RESERVED_BYLINE_FIELD_SLUGS } from "./types-o7xo7VgH.mjs";
2
- import { L as httpUrl, V as roleLevel } from "./media-kIV1IxFf.mjs";
2
+ import { L as httpUrl, R as localeCode, V as roleLevel } from "./media-BJ6SRY3g.mjs";
3
3
  import { z } from "zod";
4
4
 
5
5
  //#region src/api/schemas/auth.ts
@@ -258,7 +258,7 @@ const createRelationBody = z.object({
258
258
  childCollection: collectionSlug.optional(),
259
259
  parentLabel: z.string().min(1).max(200),
260
260
  childLabel: z.string().min(1).max(200),
261
- locale: z.string().min(1).optional(),
261
+ locale: localeCode.optional(),
262
262
  translationOf: z.string().min(1).optional()
263
263
  }).refine((body) => body.translationOf !== void 0 || body.parentCollection !== void 0 && body.childCollection !== void 0, { message: "parentCollection and childCollection are required unless translationOf is set" }).meta({ id: "CreateRelationBody" });
264
264
  const updateRelationBody = z.object({
@@ -306,4 +306,4 @@ const referenceParentsResponseSchema = z.object({
306
306
 
307
307
  //#endregion
308
308
  export { inviteCreateBody as A, wpMediaImportBody as C, wpRewriteUrlsBody as D, wpPrepareBody as E, passkeyRegisterVerifyBody as F, passkeyRenameBody as I, passkeyVerifyBody as L, magicLinkSendBody as M, passkeyOptionsBody as N, authMeActionBody as O, passkeyRegisterOptionsBody as P, signupCompleteBody as R, importProbeBody as S, wpPluginExecuteBody as T, atprotoLoginBody as _, relationDefSchema as a, setupAtprotoAdminBody as b, relationTranslationsSchema as c, bylineFieldCreateBody as d, bylineFieldDefinitionSchema as f, bylineFieldUsageResponseSchema as g, bylineFieldUpdateBody as h, referenceParentsResponseSchema as i, inviteRegisterOptionsBody as j, inviteCompleteBody as k, setReferenceChildrenBody as l, bylineFieldReorderBody as m, entryRefSchema as n, relationListResponseSchema as o, bylineFieldListResponseSchema as p, referenceChildrenResponseSchema as r, relationResponseSchema as s, createRelationBody as t, updateRelationBody as u, setupAdminBody as v, wpPluginAnalyzeBody as w, setupBody as x, setupAdminVerifyBody as y, signupRequestBody as z };
309
- //# sourceMappingURL=relations-5_avdrN_.mjs.map
309
+ //# sourceMappingURL=relations-CZMpBqEd.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"relations-5_avdrN_.mjs","names":["authenticatorTransport","registrationCredential"],"sources":["../src/api/schemas/auth.ts","../src/api/schemas/import.ts","../src/api/schemas/setup.ts","../src/api/schemas/byline-fields.ts","../src/api/schemas/relations.ts"],"sourcesContent":["import { z } from \"zod\";\n\nimport { roleLevel } from \"./common.js\";\n\n// ---------------------------------------------------------------------------\n// WebAuthn credential schemas (matching @emdash-cms/auth/passkey types)\n// ---------------------------------------------------------------------------\n\nconst authenticatorTransport = z.enum([\"usb\", \"nfc\", \"ble\", \"internal\", \"hybrid\"]);\n\n/** RegistrationResponse — sent by the browser after navigator.credentials.create() */\nconst registrationCredential = z.object({\n\tid: z.string(),\n\trawId: z.string(),\n\ttype: z.literal(\"public-key\"),\n\tresponse: z.object({\n\t\tclientDataJSON: z.string(),\n\t\tattestationObject: z.string(),\n\t\ttransports: z.array(authenticatorTransport).optional(),\n\t}),\n\tauthenticatorAttachment: z.enum([\"platform\", \"cross-platform\"]).optional(),\n});\n\n/** AuthenticationResponse — sent by the browser after navigator.credentials.get() */\nconst authenticationCredential = z.object({\n\tid: z.string(),\n\trawId: z.string(),\n\ttype: z.literal(\"public-key\"),\n\tresponse: z.object({\n\t\tclientDataJSON: z.string(),\n\t\tauthenticatorData: z.string(),\n\t\tsignature: z.string(),\n\t\tuserHandle: z.string().optional(),\n\t}),\n\tauthenticatorAttachment: z.enum([\"platform\", \"cross-platform\"]).optional(),\n});\n\n// ---------------------------------------------------------------------------\n// Auth: Input schemas\n// ---------------------------------------------------------------------------\n\nexport const signupRequestBody = z\n\t.object({\n\t\temail: z.string().email(),\n\t})\n\t.meta({ id: \"SignupRequestBody\" });\n\nexport const signupCompleteBody = z\n\t.object({\n\t\ttoken: z.string().min(1),\n\t\tcredential: registrationCredential,\n\t\tname: z.string().optional(),\n\t})\n\t.meta({ id: \"SignupCompleteBody\" });\n\nexport const inviteCreateBody = z\n\t.object({\n\t\temail: z.string().email(),\n\t\trole: roleLevel.optional(),\n\t})\n\t.meta({ id: \"InviteCreateBody\" });\n\nexport const inviteRegisterOptionsBody = z\n\t.object({\n\t\ttoken: z.string().min(1),\n\t\tname: z.string().optional(),\n\t})\n\t.meta({ id: \"InviteRegisterOptionsBody\" });\n\nexport const inviteCompleteBody = z\n\t.object({\n\t\ttoken: z.string().min(1),\n\t\tcredential: registrationCredential,\n\t\tname: z.string().optional(),\n\t})\n\t.meta({ id: \"InviteCompleteBody\" });\n\nexport const magicLinkSendBody = z\n\t.object({\n\t\temail: z.string().email(),\n\t})\n\t.meta({ id: \"MagicLinkSendBody\" });\n\nexport const passkeyOptionsBody = z\n\t.object({\n\t\temail: z.string().email().optional(),\n\t})\n\t.meta({ id: \"PasskeyOptionsBody\" });\n\nexport const passkeyVerifyBody = z\n\t.object({\n\t\tcredential: authenticationCredential,\n\t})\n\t.meta({ id: \"PasskeyVerifyBody\" });\n\nexport const passkeyRegisterOptionsBody = z\n\t.object({\n\t\tname: z.string().optional(),\n\t})\n\t.meta({ id: \"PasskeyRegisterOptionsBody\" });\n\nexport const passkeyRegisterVerifyBody = z\n\t.object({\n\t\tcredential: registrationCredential,\n\t\tname: z.string().optional(),\n\t})\n\t.meta({ id: \"PasskeyRegisterVerifyBody\" });\n\nexport const passkeyRenameBody = z\n\t.object({\n\t\tname: z.string().min(1),\n\t})\n\t.meta({ id: \"PasskeyRenameBody\" });\n\nexport const authMeActionBody = z\n\t.object({\n\t\taction: z.string().min(1),\n\t})\n\t.meta({ id: \"AuthMeActionBody\" });\n","import { z } from \"zod\";\n\nimport { httpUrl } from \"./common.js\";\n\n// ---------------------------------------------------------------------------\n// Import\n// ---------------------------------------------------------------------------\n\nexport const importProbeBody = z.object({\n\turl: httpUrl,\n});\n\nexport const wpPluginAnalyzeBody = z.object({\n\turl: httpUrl,\n\ttoken: z.string().min(1),\n});\n\nexport const wpPluginExecuteBody = z.object({\n\turl: httpUrl,\n\ttoken: z.string().min(1),\n\tconfig: z.record(z.string(), z.unknown()),\n\t// --- Chunked mode (issue #475). Absent phase = single-shot legacy run. ---\n\t// The admin drives the import in a loop of bounded requests; cross-chunk\n\t// state travels with the client so the server stays stateless.\n\tphase: z.enum([\"content\", \"comments\", \"finalize\"]).optional(),\n\t/** Position within the phase: post-type index + WP page (content), page (comments) */\n\tcursor: z\n\t\t.object({\n\t\t\tpostTypeIndex: z.number().int().min(0).default(0),\n\t\t\tpage: z.number().int().min(1).default(1),\n\t\t})\n\t\t.optional(),\n\t/** WP post ID -> created EmDash item, accumulated across content chunks */\n\tidMap: z\n\t\t.record(z.string(), z.object({ id: z.string().min(1), collection: z.string().min(1) }))\n\t\t.optional(),\n\t/** Source translation group -> EmDash item ID, accumulated across content chunks */\n\ttranslationGroups: z.record(z.string(), z.string().min(1)).optional(),\n\t/** WP comment ID -> EmDash root comment ID, accumulated across comment chunks */\n\tcommentRoots: z.record(z.string(), z.string().min(1)).optional(),\n});\n\nexport const wpPrepareBody = z.object({\n\tpostTypes: z.array(\n\t\tz.object({\n\t\t\tname: z.string().min(1),\n\t\t\tcollection: z.string().min(1),\n\t\t\tfields: z\n\t\t\t\t.array(\n\t\t\t\t\tz.object({\n\t\t\t\t\t\tslug: z.string().min(1),\n\t\t\t\t\t\tlabel: z.string().min(1),\n\t\t\t\t\t\ttype: z.string().min(1),\n\t\t\t\t\t\trequired: z.boolean(),\n\t\t\t\t\t\tsearchable: z.boolean().optional(),\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.optional(),\n\t\t}),\n\t),\n});\n\nexport const wpMediaImportBody = z.object({\n\tattachments: z.array(z.record(z.string(), z.unknown())),\n\tstream: z.boolean().optional(),\n});\n\nexport const wpRewriteUrlsBody = z.object({\n\turlMap: z.record(z.string(), z.string()),\n\tcollections: z.array(z.string()).optional(),\n});\n","import { z } from \"zod\";\n\n// ---------------------------------------------------------------------------\n// Setup\n// ---------------------------------------------------------------------------\n\n/** Registration credential — duplicated reference for setup flow.\n * The canonical definition lives in auth.ts but setup needs it independently\n * because setup runs before auth is configured. */\nconst authenticatorTransport = z.enum([\"usb\", \"nfc\", \"ble\", \"internal\", \"hybrid\"]);\n\nconst registrationCredential = z.object({\n\tid: z.string(),\n\trawId: z.string(),\n\ttype: z.literal(\"public-key\"),\n\tresponse: z.object({\n\t\tclientDataJSON: z.string(),\n\t\tattestationObject: z.string(),\n\t\ttransports: z.array(authenticatorTransport).optional(),\n\t}),\n\tauthenticatorAttachment: z.enum([\"platform\", \"cross-platform\"]).optional(),\n});\n\nexport const setupBody = z.object({\n\ttitle: z.string().min(1),\n\ttagline: z.string().optional(),\n\tincludeContent: z.boolean(),\n});\n\nexport const setupAdminBody = z.object({\n\temail: z.string().email(),\n\tname: z.string().optional(),\n});\n\nexport const setupAdminVerifyBody = z.object({\n\tcredential: registrationCredential,\n});\n\nexport const atprotoLoginBody = z.object({\n\thandle: z.string().trim().min(1),\n});\n\nexport const setupAtprotoAdminBody = z.object({\n\thandle: z.string().trim().min(1),\n});\n","/**\n * Zod schemas for the byline-fields admin API (Discussion #1174, Phase 4).\n *\n * Reserved-slug + identifier validation runs at the zod layer so the\n * route returns a clean 400 (`VALIDATION_ERROR` from `parseBody`) rather\n * than bubbling a registry-level `BylineSchemaError` (\"RESERVED_SLUG\" /\n * \"INVALID_SLUG\"). The registry repeats the same checks for non-HTTP\n * callers (seeds, scripts) — see `BylineSchemaRegistry.validateSlug`.\n *\n * Field types are constrained to the v1 subset declared in\n * `BYLINE_FIELD_TYPES`. Adding a type to the union there will require a\n * corresponding update to this enum.\n */\n\nimport { z } from \"zod\";\n\nimport { BYLINE_FIELD_TYPES, RESERVED_BYLINE_FIELD_SLUGS } from \"../../schema/types.js\";\n\n/**\n * Slug pattern for byline field definitions — matches the identifier rule\n * used by `validateIdentifier` (and `slugPattern` in `common.ts`).\n * Lowercase letters, digits, and underscores; must start with a letter.\n */\nconst bylineFieldSlugPattern = /^[a-z][a-z0-9_]*$/;\n\n/** Hard cap on a slug — mirrors `BylineSchemaRegistry.MAX_SLUG_LENGTH`. */\nconst MAX_SLUG_LENGTH = 63;\n/** Hard cap on a label — mirrors `BylineSchemaRegistry.MAX_LABEL_LENGTH`. */\nconst MAX_LABEL_LENGTH = 200;\n/** Hard cap on a select field's `options` list. */\nconst MAX_SELECT_OPTIONS = 200;\n\nconst RESERVED_SET: ReadonlySet<string> = new Set(RESERVED_BYLINE_FIELD_SLUGS);\n\n// Enumerate the v1 byline field types explicitly so zod gets the exact\n// literal union for `z.infer<>`. Mirrors `BYLINE_FIELD_TYPES`; CI's\n// type-checker catches drift via the satisfies/import below.\nconst bylineFieldTypeValues = z.enum([\"string\", \"text\", \"url\", \"boolean\", \"select\"]);\n// Compile-time guard: a drift here trips the satisfies check.\ntype _BylineFieldTypeDriftCheck =\n\t(typeof BYLINE_FIELD_TYPES)[number] extends z.infer<typeof bylineFieldTypeValues>\n\t\t? z.infer<typeof bylineFieldTypeValues> extends (typeof BYLINE_FIELD_TYPES)[number]\n\t\t\t? true\n\t\t\t: never\n\t\t: never;\nconst _bylineFieldTypeDriftCheck: _BylineFieldTypeDriftCheck = true;\nvoid _bylineFieldTypeDriftCheck;\n\n/**\n * Validation payload for a byline custom field. v1 only exposes\n * `options` (used by `select`-type fields). Empty/duplicate options are\n * rejected at the registry layer; the zod layer only enforces shape and\n * caps. Future field types may add keys here.\n */\nconst bylineFieldValidationSchema = z\n\t.object({\n\t\toptions: z\n\t\t\t.array(z.string().min(1))\n\t\t\t.min(1, \"select options must contain at least one entry\")\n\t\t\t.max(MAX_SELECT_OPTIONS, `select options cannot exceed ${MAX_SELECT_OPTIONS} entries`)\n\t\t\t.optional(),\n\t})\n\t.strict()\n\t.nullable();\n\n/**\n * Slug validation chain shared by create + reorder bodies. Centralised so\n * the reserved-slug message and pattern are identical everywhere.\n */\nconst bylineFieldSlug = z\n\t.string()\n\t.min(1, \"Byline field slug is required\")\n\t.max(MAX_SLUG_LENGTH, `Byline field slug must be ${MAX_SLUG_LENGTH} characters or less`)\n\t.regex(\n\t\tbylineFieldSlugPattern,\n\t\t\"Byline field slug must contain only lowercase letters, digits, and underscores, and start with a letter\",\n\t)\n\t.refine((slug) => !RESERVED_SET.has(slug), {\n\t\t// Surface the offending slug in the validation issue path-message\n\t\t// for easier debugging from the admin UI's error toast.\n\t\tmessage: \"Byline field slug is reserved\",\n\t});\n\nconst bylineFieldLabel = z\n\t.string()\n\t.min(1, \"Byline field label is required\")\n\t.max(MAX_LABEL_LENGTH, `Byline field label must be ${MAX_LABEL_LENGTH} characters or less`);\n\n// ---------------------------------------------------------------------------\n// Request bodies\n// ---------------------------------------------------------------------------\n\nexport const bylineFieldCreateBody = z\n\t.object({\n\t\tslug: bylineFieldSlug,\n\t\tlabel: bylineFieldLabel,\n\t\ttype: bylineFieldTypeValues,\n\t\trequired: z.boolean().optional(),\n\t\t/**\n\t\t * Whether values are stored per-locale (translatable, default) or\n\t\t * shared across the translation group. See `BylineFieldDefinition`.\n\t\t */\n\t\ttranslatable: z.boolean().optional(),\n\t\tvalidation: bylineFieldValidationSchema.optional(),\n\t\tsortOrder: z.number().int().min(0).optional(),\n\t})\n\t.strict()\n\t.meta({ id: \"BylineFieldCreateBody\" });\n\n/**\n * Update body. `slug` and `type` are intentionally absent — both are\n * immutable post-create (changing them would invalidate stored values).\n * `translatable` flips are gated at the registry layer when value rows\n * exist (`TRANSLATABLE_LOCKED`).\n */\nexport const bylineFieldUpdateBody = z\n\t.object({\n\t\tlabel: bylineFieldLabel.optional(),\n\t\trequired: z.boolean().optional(),\n\t\ttranslatable: z.boolean().optional(),\n\t\tvalidation: bylineFieldValidationSchema.optional(),\n\t\tsortOrder: z.number().int().min(0).optional(),\n\t})\n\t.strict()\n\t.meta({ id: \"BylineFieldUpdateBody\" });\n\nexport const bylineFieldReorderBody = z\n\t.object({\n\t\t/**\n\t\t * Exact set of currently registered slugs in the desired order.\n\t\t * The registry rejects any drift (`REORDER_MISMATCH`); the zod\n\t\t * layer enforces slug shape only. An empty array is permitted —\n\t\t * `reorderFields([])` is a valid no-op when zero fields are\n\t\t * registered (registry contract). Rejecting empty here would\n\t\t * produce a spurious 400 for an admin UI that submits a reorder\n\t\t * after deleting the last field.\n\t\t */\n\t\tslugs: z.array(bylineFieldSlug),\n\t})\n\t.strict()\n\t.meta({ id: \"BylineFieldReorderBody\" });\n\n// ---------------------------------------------------------------------------\n// Response shapes\n// ---------------------------------------------------------------------------\n\nexport const bylineFieldDefinitionSchema = z\n\t.object({\n\t\tid: z.string(),\n\t\tslug: z.string(),\n\t\tlabel: z.string(),\n\t\ttype: bylineFieldTypeValues,\n\t\trequired: z.boolean(),\n\t\ttranslatable: z.boolean(),\n\t\tvalidation: z\n\t\t\t.object({\n\t\t\t\toptions: z.array(z.string()).optional(),\n\t\t\t})\n\t\t\t.nullable(),\n\t\tsortOrder: z.number().int(),\n\t\tcreatedAt: z.string(),\n\t\tupdatedAt: z.string(),\n\t})\n\t.meta({ id: \"BylineFieldDefinition\" });\n\nexport const bylineFieldListResponseSchema = z\n\t.object({\n\t\titems: z.array(bylineFieldDefinitionSchema),\n\t})\n\t.meta({ id: \"BylineFieldListResponse\" });\n\n/**\n * Response shape for `GET /api/admin/byline-fields/[slug]/usage`.\n *\n * `translatableValueCount` counts rows in `_emdash_byline_field_values`.\n * `groupValueCount` counts rows in `_emdash_byline_field_group_values`.\n * `totalAffectedRows` is the sum — what the destructive-delete confirm\n * dialog surfaces. Both individual counts are exposed for diagnostic\n * value (e.g. inconsistency with the field's current `translatable`\n * flag would show non-zero on the \"wrong\" side).\n */\nexport const bylineFieldUsageResponseSchema = z\n\t.object({\n\t\ttranslatableValueCount: z.number().int().nonnegative(),\n\t\tgroupValueCount: z.number().int().nonnegative(),\n\t\ttotalAffectedRows: z.number().int().nonnegative(),\n\t})\n\t.meta({ id: \"BylineFieldUsageResponse\" });\n","import { z } from \"zod\";\n\nconst slugPattern = /^[a-z][a-z0-9_]*$/;\nconst collectionSlug = z\n\t.string()\n\t.min(1)\n\t.max(63)\n\t.regex(slugPattern, \"Invalid collection slug format\");\n\nexport const createRelationBody = z\n\t.object({\n\t\tname: z\n\t\t\t.string()\n\t\t\t.min(1)\n\t\t\t.max(63)\n\t\t\t.regex(slugPattern, \"Name must be lowercase alphanumeric with underscores\"),\n\t\tparentCollection: collectionSlug.optional(),\n\t\tchildCollection: collectionSlug.optional(),\n\t\tparentLabel: z.string().min(1).max(200),\n\t\tchildLabel: z.string().min(1).max(200),\n\t\tlocale: z.string().min(1).optional(),\n\t\ttranslationOf: z.string().min(1).optional(),\n\t})\n\t// A translation inherits its structural fields (name, parentCollection,\n\t// childCollection) from the source relation, so the handler ignores any\n\t// collections supplied alongside `translationOf`. Require them only when\n\t// minting a base relation, so callers aren't forced to pass discarded values.\n\t.refine(\n\t\t(body) =>\n\t\t\tbody.translationOf !== undefined ||\n\t\t\t(body.parentCollection !== undefined && body.childCollection !== undefined),\n\t\t{ message: \"parentCollection and childCollection are required unless translationOf is set\" },\n\t)\n\t.meta({ id: \"CreateRelationBody\" });\n\nexport const updateRelationBody = z\n\t.object({\n\t\tparentLabel: z.string().min(1).max(200).optional(),\n\t\tchildLabel: z.string().min(1).max(200).optional(),\n\t})\n\t// Reject empty payloads: an update touching no field is a client mistake, not\n\t// a successful no-op. Without this, `{}` validates and the handler returns 200\n\t// with the unchanged row, so a typo'd payload looks like it landed.\n\t.refine((body) => body.parentLabel !== undefined || body.childLabel !== undefined, {\n\t\tmessage: \"At least one of parentLabel or childLabel is required\",\n\t})\n\t.meta({ id: \"UpdateRelationBody\" });\n\nexport const setReferenceChildrenBody = z\n\t.object({ childIds: z.array(z.string().min(1)).max(1000) })\n\t.meta({ id: \"SetReferenceChildrenBody\" });\n\nexport const relationDefSchema = z\n\t.object({\n\t\tid: z.string(),\n\t\tname: z.string(),\n\t\tparentCollection: z.string(),\n\t\tchildCollection: z.string(),\n\t\tparentLabel: z.string(),\n\t\tchildLabel: z.string(),\n\t\tlocale: z.string(),\n\t\ttranslationGroup: z.string(),\n\t})\n\t.meta({ id: \"RelationDef\" });\n\nexport const relationListResponseSchema = z\n\t.object({ relations: z.array(relationDefSchema) })\n\t.meta({ id: \"RelationListResponse\" });\n\nexport const relationResponseSchema = z\n\t.object({ relation: relationDefSchema })\n\t.meta({ id: \"RelationResponse\" });\n\nexport const relationTranslationsSchema = z\n\t.object({\n\t\ttranslationGroup: z.string(),\n\t\ttranslations: z.array(\n\t\t\tz.object({\n\t\t\t\tid: z.string(),\n\t\t\t\tname: z.string(),\n\t\t\t\tlocale: z.string(),\n\t\t\t\tparentLabel: z.string(),\n\t\t\t\tchildLabel: z.string(),\n\t\t\t}),\n\t\t),\n\t})\n\t.meta({ id: \"RelationTranslations\" });\n\nexport const entryRefSchema = z\n\t.object({\n\t\tid: z.string(),\n\t\tslug: z.string().nullable(),\n\t\tcollection: z.string(),\n\t\t// The actual locale of the resolved variant. When no variant matches the\n\t\t// requesting entry's locale, the ref falls back to another locale's row;\n\t\t// this field makes that substitution explicit instead of silently\n\t\t// presenting a wrong-locale entry under the requested context.\n\t\tlocale: z.string().nullable(),\n\t\tsortOrder: z.number().int().optional(),\n\t})\n\t.meta({ id: \"ReferenceEntryRef\" });\n\nexport const referenceChildrenResponseSchema = z\n\t.object({ children: z.array(entryRefSchema), nextCursor: z.string().optional() })\n\t.meta({ id: \"ReferenceChildrenResponse\" });\n\nexport const referenceParentsResponseSchema = z\n\t.object({ parents: z.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C,CAC/E,KAAK,EAAE,IAAI,4BAA4B,CAAC"}
1
+ {"version":3,"file":"relations-CZMpBqEd.mjs","names":["authenticatorTransport","registrationCredential"],"sources":["../src/api/schemas/auth.ts","../src/api/schemas/import.ts","../src/api/schemas/setup.ts","../src/api/schemas/byline-fields.ts","../src/api/schemas/relations.ts"],"sourcesContent":["import { z } from \"zod\";\n\nimport { roleLevel } from \"./common.js\";\n\n// ---------------------------------------------------------------------------\n// WebAuthn credential schemas (matching @emdash-cms/auth/passkey types)\n// ---------------------------------------------------------------------------\n\nconst authenticatorTransport = z.enum([\"usb\", \"nfc\", \"ble\", \"internal\", \"hybrid\"]);\n\n/** RegistrationResponse — sent by the browser after navigator.credentials.create() */\nconst registrationCredential = z.object({\n\tid: z.string(),\n\trawId: z.string(),\n\ttype: z.literal(\"public-key\"),\n\tresponse: z.object({\n\t\tclientDataJSON: z.string(),\n\t\tattestationObject: z.string(),\n\t\ttransports: z.array(authenticatorTransport).optional(),\n\t}),\n\tauthenticatorAttachment: z.enum([\"platform\", \"cross-platform\"]).optional(),\n});\n\n/** AuthenticationResponse — sent by the browser after navigator.credentials.get() */\nconst authenticationCredential = z.object({\n\tid: z.string(),\n\trawId: z.string(),\n\ttype: z.literal(\"public-key\"),\n\tresponse: z.object({\n\t\tclientDataJSON: z.string(),\n\t\tauthenticatorData: z.string(),\n\t\tsignature: z.string(),\n\t\tuserHandle: z.string().optional(),\n\t}),\n\tauthenticatorAttachment: z.enum([\"platform\", \"cross-platform\"]).optional(),\n});\n\n// ---------------------------------------------------------------------------\n// Auth: Input schemas\n// ---------------------------------------------------------------------------\n\nexport const signupRequestBody = z\n\t.object({\n\t\temail: z.string().email(),\n\t})\n\t.meta({ id: \"SignupRequestBody\" });\n\nexport const signupCompleteBody = z\n\t.object({\n\t\ttoken: z.string().min(1),\n\t\tcredential: registrationCredential,\n\t\tname: z.string().optional(),\n\t})\n\t.meta({ id: \"SignupCompleteBody\" });\n\nexport const inviteCreateBody = z\n\t.object({\n\t\temail: z.string().email(),\n\t\trole: roleLevel.optional(),\n\t})\n\t.meta({ id: \"InviteCreateBody\" });\n\nexport const inviteRegisterOptionsBody = z\n\t.object({\n\t\ttoken: z.string().min(1),\n\t\tname: z.string().optional(),\n\t})\n\t.meta({ id: \"InviteRegisterOptionsBody\" });\n\nexport const inviteCompleteBody = z\n\t.object({\n\t\ttoken: z.string().min(1),\n\t\tcredential: registrationCredential,\n\t\tname: z.string().optional(),\n\t})\n\t.meta({ id: \"InviteCompleteBody\" });\n\nexport const magicLinkSendBody = z\n\t.object({\n\t\temail: z.string().email(),\n\t})\n\t.meta({ id: \"MagicLinkSendBody\" });\n\nexport const passkeyOptionsBody = z\n\t.object({\n\t\temail: z.string().email().optional(),\n\t})\n\t.meta({ id: \"PasskeyOptionsBody\" });\n\nexport const passkeyVerifyBody = z\n\t.object({\n\t\tcredential: authenticationCredential,\n\t})\n\t.meta({ id: \"PasskeyVerifyBody\" });\n\nexport const passkeyRegisterOptionsBody = z\n\t.object({\n\t\tname: z.string().optional(),\n\t})\n\t.meta({ id: \"PasskeyRegisterOptionsBody\" });\n\nexport const passkeyRegisterVerifyBody = z\n\t.object({\n\t\tcredential: registrationCredential,\n\t\tname: z.string().optional(),\n\t})\n\t.meta({ id: \"PasskeyRegisterVerifyBody\" });\n\nexport const passkeyRenameBody = z\n\t.object({\n\t\tname: z.string().min(1),\n\t})\n\t.meta({ id: \"PasskeyRenameBody\" });\n\nexport const authMeActionBody = z\n\t.object({\n\t\taction: z.string().min(1),\n\t})\n\t.meta({ id: \"AuthMeActionBody\" });\n","import { z } from \"zod\";\n\nimport { httpUrl } from \"./common.js\";\n\n// ---------------------------------------------------------------------------\n// Import\n// ---------------------------------------------------------------------------\n\nexport const importProbeBody = z.object({\n\turl: httpUrl,\n});\n\nexport const wpPluginAnalyzeBody = z.object({\n\turl: httpUrl,\n\ttoken: z.string().min(1),\n});\n\nexport const wpPluginExecuteBody = z.object({\n\turl: httpUrl,\n\ttoken: z.string().min(1),\n\tconfig: z.record(z.string(), z.unknown()),\n\t// --- Chunked mode (issue #475). Absent phase = single-shot legacy run. ---\n\t// The admin drives the import in a loop of bounded requests; cross-chunk\n\t// state travels with the client so the server stays stateless.\n\tphase: z.enum([\"content\", \"comments\", \"finalize\"]).optional(),\n\t/** Position within the phase: post-type index + WP page (content), page (comments) */\n\tcursor: z\n\t\t.object({\n\t\t\tpostTypeIndex: z.number().int().min(0).default(0),\n\t\t\tpage: z.number().int().min(1).default(1),\n\t\t})\n\t\t.optional(),\n\t/** WP post ID -> created EmDash item, accumulated across content chunks */\n\tidMap: z\n\t\t.record(z.string(), z.object({ id: z.string().min(1), collection: z.string().min(1) }))\n\t\t.optional(),\n\t/** Source translation group -> EmDash item ID, accumulated across content chunks */\n\ttranslationGroups: z.record(z.string(), z.string().min(1)).optional(),\n\t/** WP comment ID -> EmDash root comment ID, accumulated across comment chunks */\n\tcommentRoots: z.record(z.string(), z.string().min(1)).optional(),\n});\n\nexport const wpPrepareBody = z.object({\n\tpostTypes: z.array(\n\t\tz.object({\n\t\t\tname: z.string().min(1),\n\t\t\tcollection: z.string().min(1),\n\t\t\tfields: z\n\t\t\t\t.array(\n\t\t\t\t\tz.object({\n\t\t\t\t\t\tslug: z.string().min(1),\n\t\t\t\t\t\tlabel: z.string().min(1),\n\t\t\t\t\t\ttype: z.string().min(1),\n\t\t\t\t\t\trequired: z.boolean(),\n\t\t\t\t\t\tsearchable: z.boolean().optional(),\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.optional(),\n\t\t}),\n\t),\n});\n\nexport const wpMediaImportBody = z.object({\n\tattachments: z.array(z.record(z.string(), z.unknown())),\n\tstream: z.boolean().optional(),\n});\n\nexport const wpRewriteUrlsBody = z.object({\n\turlMap: z.record(z.string(), z.string()),\n\tcollections: z.array(z.string()).optional(),\n});\n","import { z } from \"zod\";\n\n// ---------------------------------------------------------------------------\n// Setup\n// ---------------------------------------------------------------------------\n\n/** Registration credential — duplicated reference for setup flow.\n * The canonical definition lives in auth.ts but setup needs it independently\n * because setup runs before auth is configured. */\nconst authenticatorTransport = z.enum([\"usb\", \"nfc\", \"ble\", \"internal\", \"hybrid\"]);\n\nconst registrationCredential = z.object({\n\tid: z.string(),\n\trawId: z.string(),\n\ttype: z.literal(\"public-key\"),\n\tresponse: z.object({\n\t\tclientDataJSON: z.string(),\n\t\tattestationObject: z.string(),\n\t\ttransports: z.array(authenticatorTransport).optional(),\n\t}),\n\tauthenticatorAttachment: z.enum([\"platform\", \"cross-platform\"]).optional(),\n});\n\nexport const setupBody = z.object({\n\ttitle: z.string().min(1),\n\ttagline: z.string().optional(),\n\tincludeContent: z.boolean(),\n});\n\nexport const setupAdminBody = z.object({\n\temail: z.string().email(),\n\tname: z.string().optional(),\n});\n\nexport const setupAdminVerifyBody = z.object({\n\tcredential: registrationCredential,\n});\n\nexport const atprotoLoginBody = z.object({\n\thandle: z.string().trim().min(1),\n});\n\nexport const setupAtprotoAdminBody = z.object({\n\thandle: z.string().trim().min(1),\n});\n","/**\n * Zod schemas for the byline-fields admin API (Discussion #1174, Phase 4).\n *\n * Reserved-slug + identifier validation runs at the zod layer so the\n * route returns a clean 400 (`VALIDATION_ERROR` from `parseBody`) rather\n * than bubbling a registry-level `BylineSchemaError` (\"RESERVED_SLUG\" /\n * \"INVALID_SLUG\"). The registry repeats the same checks for non-HTTP\n * callers (seeds, scripts) — see `BylineSchemaRegistry.validateSlug`.\n *\n * Field types are constrained to the v1 subset declared in\n * `BYLINE_FIELD_TYPES`. Adding a type to the union there will require a\n * corresponding update to this enum.\n */\n\nimport { z } from \"zod\";\n\nimport { BYLINE_FIELD_TYPES, RESERVED_BYLINE_FIELD_SLUGS } from \"../../schema/types.js\";\n\n/**\n * Slug pattern for byline field definitions — matches the identifier rule\n * used by `validateIdentifier` (and `slugPattern` in `common.ts`).\n * Lowercase letters, digits, and underscores; must start with a letter.\n */\nconst bylineFieldSlugPattern = /^[a-z][a-z0-9_]*$/;\n\n/** Hard cap on a slug — mirrors `BylineSchemaRegistry.MAX_SLUG_LENGTH`. */\nconst MAX_SLUG_LENGTH = 63;\n/** Hard cap on a label — mirrors `BylineSchemaRegistry.MAX_LABEL_LENGTH`. */\nconst MAX_LABEL_LENGTH = 200;\n/** Hard cap on a select field's `options` list. */\nconst MAX_SELECT_OPTIONS = 200;\n\nconst RESERVED_SET: ReadonlySet<string> = new Set(RESERVED_BYLINE_FIELD_SLUGS);\n\n// Enumerate the v1 byline field types explicitly so zod gets the exact\n// literal union for `z.infer<>`. Mirrors `BYLINE_FIELD_TYPES`; CI's\n// type-checker catches drift via the satisfies/import below.\nconst bylineFieldTypeValues = z.enum([\"string\", \"text\", \"url\", \"boolean\", \"select\"]);\n// Compile-time guard: a drift here trips the satisfies check.\ntype _BylineFieldTypeDriftCheck =\n\t(typeof BYLINE_FIELD_TYPES)[number] extends z.infer<typeof bylineFieldTypeValues>\n\t\t? z.infer<typeof bylineFieldTypeValues> extends (typeof BYLINE_FIELD_TYPES)[number]\n\t\t\t? true\n\t\t\t: never\n\t\t: never;\nconst _bylineFieldTypeDriftCheck: _BylineFieldTypeDriftCheck = true;\nvoid _bylineFieldTypeDriftCheck;\n\n/**\n * Validation payload for a byline custom field. v1 only exposes\n * `options` (used by `select`-type fields). Empty/duplicate options are\n * rejected at the registry layer; the zod layer only enforces shape and\n * caps. Future field types may add keys here.\n */\nconst bylineFieldValidationSchema = z\n\t.object({\n\t\toptions: z\n\t\t\t.array(z.string().min(1))\n\t\t\t.min(1, \"select options must contain at least one entry\")\n\t\t\t.max(MAX_SELECT_OPTIONS, `select options cannot exceed ${MAX_SELECT_OPTIONS} entries`)\n\t\t\t.optional(),\n\t})\n\t.strict()\n\t.nullable();\n\n/**\n * Slug validation chain shared by create + reorder bodies. Centralised so\n * the reserved-slug message and pattern are identical everywhere.\n */\nconst bylineFieldSlug = z\n\t.string()\n\t.min(1, \"Byline field slug is required\")\n\t.max(MAX_SLUG_LENGTH, `Byline field slug must be ${MAX_SLUG_LENGTH} characters or less`)\n\t.regex(\n\t\tbylineFieldSlugPattern,\n\t\t\"Byline field slug must contain only lowercase letters, digits, and underscores, and start with a letter\",\n\t)\n\t.refine((slug) => !RESERVED_SET.has(slug), {\n\t\t// Surface the offending slug in the validation issue path-message\n\t\t// for easier debugging from the admin UI's error toast.\n\t\tmessage: \"Byline field slug is reserved\",\n\t});\n\nconst bylineFieldLabel = z\n\t.string()\n\t.min(1, \"Byline field label is required\")\n\t.max(MAX_LABEL_LENGTH, `Byline field label must be ${MAX_LABEL_LENGTH} characters or less`);\n\n// ---------------------------------------------------------------------------\n// Request bodies\n// ---------------------------------------------------------------------------\n\nexport const bylineFieldCreateBody = z\n\t.object({\n\t\tslug: bylineFieldSlug,\n\t\tlabel: bylineFieldLabel,\n\t\ttype: bylineFieldTypeValues,\n\t\trequired: z.boolean().optional(),\n\t\t/**\n\t\t * Whether values are stored per-locale (translatable, default) or\n\t\t * shared across the translation group. See `BylineFieldDefinition`.\n\t\t */\n\t\ttranslatable: z.boolean().optional(),\n\t\tvalidation: bylineFieldValidationSchema.optional(),\n\t\tsortOrder: z.number().int().min(0).optional(),\n\t})\n\t.strict()\n\t.meta({ id: \"BylineFieldCreateBody\" });\n\n/**\n * Update body. `slug` and `type` are intentionally absent — both are\n * immutable post-create (changing them would invalidate stored values).\n * `translatable` flips are gated at the registry layer when value rows\n * exist (`TRANSLATABLE_LOCKED`).\n */\nexport const bylineFieldUpdateBody = z\n\t.object({\n\t\tlabel: bylineFieldLabel.optional(),\n\t\trequired: z.boolean().optional(),\n\t\ttranslatable: z.boolean().optional(),\n\t\tvalidation: bylineFieldValidationSchema.optional(),\n\t\tsortOrder: z.number().int().min(0).optional(),\n\t})\n\t.strict()\n\t.meta({ id: \"BylineFieldUpdateBody\" });\n\nexport const bylineFieldReorderBody = z\n\t.object({\n\t\t/**\n\t\t * Exact set of currently registered slugs in the desired order.\n\t\t * The registry rejects any drift (`REORDER_MISMATCH`); the zod\n\t\t * layer enforces slug shape only. An empty array is permitted —\n\t\t * `reorderFields([])` is a valid no-op when zero fields are\n\t\t * registered (registry contract). Rejecting empty here would\n\t\t * produce a spurious 400 for an admin UI that submits a reorder\n\t\t * after deleting the last field.\n\t\t */\n\t\tslugs: z.array(bylineFieldSlug),\n\t})\n\t.strict()\n\t.meta({ id: \"BylineFieldReorderBody\" });\n\n// ---------------------------------------------------------------------------\n// Response shapes\n// ---------------------------------------------------------------------------\n\nexport const bylineFieldDefinitionSchema = z\n\t.object({\n\t\tid: z.string(),\n\t\tslug: z.string(),\n\t\tlabel: z.string(),\n\t\ttype: bylineFieldTypeValues,\n\t\trequired: z.boolean(),\n\t\ttranslatable: z.boolean(),\n\t\tvalidation: z\n\t\t\t.object({\n\t\t\t\toptions: z.array(z.string()).optional(),\n\t\t\t})\n\t\t\t.nullable(),\n\t\tsortOrder: z.number().int(),\n\t\tcreatedAt: z.string(),\n\t\tupdatedAt: z.string(),\n\t})\n\t.meta({ id: \"BylineFieldDefinition\" });\n\nexport const bylineFieldListResponseSchema = z\n\t.object({\n\t\titems: z.array(bylineFieldDefinitionSchema),\n\t})\n\t.meta({ id: \"BylineFieldListResponse\" });\n\n/**\n * Response shape for `GET /api/admin/byline-fields/[slug]/usage`.\n *\n * `translatableValueCount` counts rows in `_emdash_byline_field_values`.\n * `groupValueCount` counts rows in `_emdash_byline_field_group_values`.\n * `totalAffectedRows` is the sum — what the destructive-delete confirm\n * dialog surfaces. Both individual counts are exposed for diagnostic\n * value (e.g. inconsistency with the field's current `translatable`\n * flag would show non-zero on the \"wrong\" side).\n */\nexport const bylineFieldUsageResponseSchema = z\n\t.object({\n\t\ttranslatableValueCount: z.number().int().nonnegative(),\n\t\tgroupValueCount: z.number().int().nonnegative(),\n\t\ttotalAffectedRows: z.number().int().nonnegative(),\n\t})\n\t.meta({ id: \"BylineFieldUsageResponse\" });\n","import { z } from \"zod\";\n\nimport { localeCode } from \"./common.js\";\n\nconst slugPattern = /^[a-z][a-z0-9_]*$/;\nconst collectionSlug = z\n\t.string()\n\t.min(1)\n\t.max(63)\n\t.regex(slugPattern, \"Invalid collection slug format\");\n\nexport const createRelationBody = z\n\t.object({\n\t\tname: z\n\t\t\t.string()\n\t\t\t.min(1)\n\t\t\t.max(63)\n\t\t\t.regex(slugPattern, \"Name must be lowercase alphanumeric with underscores\"),\n\t\tparentCollection: collectionSlug.optional(),\n\t\tchildCollection: collectionSlug.optional(),\n\t\tparentLabel: z.string().min(1).max(200),\n\t\tchildLabel: z.string().min(1).max(200),\n\t\tlocale: localeCode.optional(),\n\t\ttranslationOf: z.string().min(1).optional(),\n\t})\n\t// A translation inherits its structural fields (name, parentCollection,\n\t// childCollection) from the source relation, so the handler ignores any\n\t// collections supplied alongside `translationOf`. Require them only when\n\t// minting a base relation, so callers aren't forced to pass discarded values.\n\t.refine(\n\t\t(body) =>\n\t\t\tbody.translationOf !== undefined ||\n\t\t\t(body.parentCollection !== undefined && body.childCollection !== undefined),\n\t\t{ message: \"parentCollection and childCollection are required unless translationOf is set\" },\n\t)\n\t.meta({ id: \"CreateRelationBody\" });\n\nexport const updateRelationBody = z\n\t.object({\n\t\tparentLabel: z.string().min(1).max(200).optional(),\n\t\tchildLabel: z.string().min(1).max(200).optional(),\n\t})\n\t// Reject empty payloads: an update touching no field is a client mistake, not\n\t// a successful no-op. Without this, `{}` validates and the handler returns 200\n\t// with the unchanged row, so a typo'd payload looks like it landed.\n\t.refine((body) => body.parentLabel !== undefined || body.childLabel !== undefined, {\n\t\tmessage: \"At least one of parentLabel or childLabel is required\",\n\t})\n\t.meta({ id: \"UpdateRelationBody\" });\n\nexport const setReferenceChildrenBody = z\n\t.object({ childIds: z.array(z.string().min(1)).max(1000) })\n\t.meta({ id: \"SetReferenceChildrenBody\" });\n\nexport const relationDefSchema = z\n\t.object({\n\t\tid: z.string(),\n\t\tname: z.string(),\n\t\tparentCollection: z.string(),\n\t\tchildCollection: z.string(),\n\t\tparentLabel: z.string(),\n\t\tchildLabel: z.string(),\n\t\tlocale: z.string(),\n\t\ttranslationGroup: z.string(),\n\t})\n\t.meta({ id: \"RelationDef\" });\n\nexport const relationListResponseSchema = z\n\t.object({ relations: z.array(relationDefSchema) })\n\t.meta({ id: \"RelationListResponse\" });\n\nexport const relationResponseSchema = z\n\t.object({ relation: relationDefSchema })\n\t.meta({ id: \"RelationResponse\" });\n\nexport const relationTranslationsSchema = z\n\t.object({\n\t\ttranslationGroup: z.string(),\n\t\ttranslations: z.array(\n\t\t\tz.object({\n\t\t\t\tid: z.string(),\n\t\t\t\tname: z.string(),\n\t\t\t\tlocale: z.string(),\n\t\t\t\tparentLabel: z.string(),\n\t\t\t\tchildLabel: z.string(),\n\t\t\t}),\n\t\t),\n\t})\n\t.meta({ id: \"RelationTranslations\" });\n\nexport const entryRefSchema = z\n\t.object({\n\t\tid: z.string(),\n\t\tslug: z.string().nullable(),\n\t\tcollection: z.string(),\n\t\t// The actual locale of the resolved variant. When no variant matches the\n\t\t// requesting entry's locale, the ref falls back to another locale's row;\n\t\t// this field makes that substitution explicit instead of silently\n\t\t// presenting a wrong-locale entry under the requested context.\n\t\tlocale: z.string().nullable(),\n\t\tsortOrder: z.number().int().optional(),\n\t})\n\t.meta({ id: \"ReferenceEntryRef\" });\n\nexport const referenceChildrenResponseSchema = z\n\t.object({ children: z.array(entryRefSchema), nextCursor: z.string().optional() })\n\t.meta({ id: \"ReferenceChildrenResponse\" });\n\nexport const referenceParentsResponseSchema = z\n\t.object({ parents: z.array(entryRefSchema), nextCursor: z.string().optional() })\n\t.meta({ id: \"ReferenceParentsResponse\" });\n"],"mappings":";;;;;AAQA,MAAMA,2BAAyB,EAAE,KAAK;CAAC;CAAO;CAAO;CAAO;CAAY;CAAS,CAAC;;AAGlF,MAAMC,2BAAyB,EAAE,OAAO;CACvC,IAAI,EAAE,QAAQ;CACd,OAAO,EAAE,QAAQ;CACjB,MAAM,EAAE,QAAQ,aAAa;CAC7B,UAAU,EAAE,OAAO;EAClB,gBAAgB,EAAE,QAAQ;EAC1B,mB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AAU,mBAAmB,CAAC,CACvC,KAAK,EAAE,IAAI,oBAAoB,CAAC;AAElC,MAAa,6BAA6B,EACxC,OAAO;CACP,kBAAkB,EAAE,QAAQ;CAC5B,cAAc,EAAE,MACf,EAAE,OAAO;EACR,IAAI,EAAE,QAAQ;EACd,MAAM,EAAE,QAAQ;EAChB,QAAQ,EAAE,QAAQ;EAClB,aAAa,EAAE,QAAQ;EACvB,YAAY,EAAE,QAAQ;EACtB,CAAC,CACF;CACD,CAAC,CACD,KAAK,EAAE,IAAI,wBAAwB,CAAC;AAEtC,MAAa,iBAAiB,EAC5B,OAAO;CACP,IAAI,EAAE,QAAQ;CACd,MAAM,EAAE,QAAQ,CAAC,UAAU;CAC3B,YAAY,EAAE,QAAQ;CAKtB,QAAQ,EAAE,QAAQ,CAAC,UAAU;CAC7B,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,UAAU;CACtC,CAAC,CACD,KAAK,EAAE,IAAI,qBAAqB,CAAC;AAEnC,MAAa,kCAAkC,EAC7C,OAAO;CAAE,UAAU,EAAE,MAAM,eAAe;CAAE,YAAY,EAAE,QAAQ,CAAC,UAAU;CAAE,CAAC,CAChF,KAAK,EAAE,IAAI,6BAA6B,CAAC;AAE3C,MAAa,iCAAiC,EAC5C,OAAO;CAAE,SAAS,EAAE,MAAM,eAAe;CAAE,YAAY,EAAE,QAAQ,CAAC,UAAU;CAAE,CAAC,CAC/E,KAAK,EAAE,IAAI,4BAA4B,CAAC"}
@@ -1,7 +1,8 @@
1
- import { t as ContentRepository } from "./content-Ci04z2z-.mjs";
2
- import { n as InvalidCursorError } from "./types-D1iJ3DpO.mjs";
3
- import { t as RelationRepository } from "./relation-9M9j_UWo.mjs";
4
- import { n as SchemaRegistry } from "./registry-FV15nLge.mjs";
1
+ import { i as resolveConfiguredLocale } from "./config-B6b_BobR.mjs";
2
+ import { t as ContentRepository } from "./content-BC43pICM.mjs";
3
+ import { n as InvalidCursorError } from "./types-CrRUFdej.mjs";
4
+ import { t as RelationRepository } from "./relation-Du0r04E0.mjs";
5
+ import { n as SchemaRegistry } from "./registry-y21kjhfG.mjs";
5
6
 
6
7
  //#region src/api/handlers/relations.ts
7
8
  /** Map an edge-read failure: a bad pagination cursor is a 400 client error,
@@ -51,7 +52,10 @@ async function handleRelationCreate(db, input) {
51
52
  }
52
53
  return {
53
54
  success: true,
54
- data: { relation: await repo.create(input) }
55
+ data: { relation: await repo.create({
56
+ ...input,
57
+ locale: input.locale ? resolveConfiguredLocale(input.locale) : void 0
58
+ }) }
55
59
  };
56
60
  } catch (error) {
57
61
  if (error instanceof Error && error.message.includes("Source relation for translation not found")) return {
@@ -103,9 +107,11 @@ async function handleRelationGet(db, id) {
103
107
  }
104
108
  async function handleRelationList(db, opts) {
105
109
  try {
110
+ const repo = new RelationRepository(db);
111
+ const locale = opts.locale ? resolveConfiguredLocale(opts.locale) : void 0;
106
112
  return {
107
113
  success: true,
108
- data: { relations: await new RelationRepository(db).list(opts.locale) }
114
+ data: { relations: await repo.list(locale) }
109
115
  };
110
116
  } catch {
111
117
  return {
@@ -394,4 +400,4 @@ async function handleReferenceParentsGet(db, collection, entryId, relation, page
394
400
 
395
401
  //#endregion
396
402
  export { handleRelationDelete as a, handleRelationTranslations as c, handleRelationCreate as i, handleRelationUpdate as l, handleReferenceChildrenSet as n, handleRelationGet as o, handleReferenceParentsGet as r, handleRelationList as s, handleReferenceChildrenGet as t };
397
- //# sourceMappingURL=relations-BKvO39-9.mjs.map
403
+ //# sourceMappingURL=relations-DtX1UMBH.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relations-DtX1UMBH.mjs","names":[],"sources":["../src/api/handlers/relations.ts"],"sourcesContent":["import type { Kysely } from \"kysely\";\n\nimport { ContentRepository } from \"../../database/repositories/content.js\";\nimport {\n\tRelationRepository,\n\ttype ContentReference,\n\ttype CreateRelationInput,\n\ttype Relation,\n} from \"../../database/repositories/relation.js\";\nimport { InvalidCursorError } from \"../../database/repositories/types.js\";\nimport type { ContentItem } from \"../../database/repositories/types.js\";\nimport type { Database } from \"../../database/types.js\";\nimport { resolveConfiguredLocale } from \"../../i18n/config.js\";\nimport { SchemaRegistry } from \"../../schema/registry.js\";\nimport type { ApiResult } from \"../types.js\";\n\n/** Map an edge-read failure: a bad pagination cursor is a 400 client error,\n * everything else is the generic 500-shaped reference-read error. */\nfunction referencesGetError(error: unknown): ApiResult<never> {\n\tif (error instanceof InvalidCursorError) {\n\t\treturn { success: false, error: { code: \"INVALID_CURSOR\", message: error.message } };\n\t}\n\treturn {\n\t\tsuccess: false,\n\t\terror: { code: \"REFERENCES_GET_ERROR\", message: \"Failed to get references\" },\n\t};\n}\n\n/** True for SQLite UNIQUE / Postgres unique_violation messages (matches the\n * fingerprint used in the content handlers). Narrow enough not to catch NOT\n * NULL / CHECK violations whose messages also say \"constraint\". */\nfunction isUniqueViolation(error: unknown): boolean {\n\tconst message = error instanceof Error ? error.message.toLowerCase() : \"\";\n\treturn message.includes(\"unique constraint failed\") || message.includes(\"duplicate key\");\n}\n\nexport async function handleRelationCreate(\n\tdb: Kysely<Database>,\n\tinput: CreateRelationInput,\n): Promise<ApiResult<{ relation: Relation }>> {\n\ttry {\n\t\tconst repo = new RelationRepository(db);\n\n\t\t// Invariant: a relation must point at collections that exist. There is no\n\t\t// SQL FK (group-linking precludes it), so a ghost collection would yield a\n\t\t// structurally-valid-but-permanently-useless relation. Skip when\n\t\t// `translationOf` is set — structural fields are then inherited from an\n\t\t// already-validated source, and the input collections are ignored.\n\t\tif (!input.translationOf) {\n\t\t\tif (!input.parentCollection || !input.childCollection) {\n\t\t\t\treturn {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: {\n\t\t\t\t\t\tcode: \"VALIDATION_ERROR\",\n\t\t\t\t\t\tmessage:\n\t\t\t\t\t\t\t\"parentCollection and childCollection are required unless translationOf is set\",\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst registry = new SchemaRegistry(db);\n\t\t\tfor (const collection of [input.parentCollection, input.childCollection]) {\n\t\t\t\tif (!(await registry.getCollection(collection))) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\tcode: \"COLLECTION_NOT_FOUND\",\n\t\t\t\t\t\t\tmessage: `Collection '${collection}' not found`,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst relation = await repo.create({\n\t\t\t...input,\n\t\t\tlocale: input.locale ? resolveConfiguredLocale(input.locale) : undefined,\n\t\t});\n\t\treturn { success: true, data: { relation } };\n\t} catch (error) {\n\t\t// A bad `translationOf` makes the repo throw loudly rather than mint an\n\t\t// unlinked relation — surface it as 404, not a generic 500.\n\t\tif (\n\t\t\terror instanceof Error &&\n\t\t\terror.message.includes(\"Source relation for translation not found\")\n\t\t) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: { code: \"NOT_FOUND\", message: \"Source relation for translation not found\" },\n\t\t\t};\n\t\t}\n\t\t// UNIQUE(name, locale) collision, or a second translation for an\n\t\t// already-present (translation_group, locale) — both are client conflicts.\n\t\tif (isUniqueViolation(error)) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: {\n\t\t\t\t\tcode: \"CONFLICT\",\n\t\t\t\t\tmessage: \"A relation with this name or locale already exists\",\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: { code: \"RELATION_CREATE_ERROR\", message: \"Failed to create relation\" },\n\t\t};\n\t}\n}\n\nexport async function handleRelationGet(\n\tdb: Kysely<Database>,\n\tid: string,\n): Promise<ApiResult<{ relation: Relation }>> {\n\ttry {\n\t\tconst repo = new RelationRepository(db);\n\t\tconst relation = await repo.findById(id);\n\t\tif (!relation) {\n\t\t\treturn { success: false, error: { code: \"NOT_FOUND\", message: \"Relation not found\" } };\n\t\t}\n\t\treturn { success: true, data: { relation } };\n\t} catch {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: { code: \"RELATION_GET_ERROR\", message: \"Failed to get relation\" },\n\t\t};\n\t}\n}\n\nexport async function handleRelationList(\n\tdb: Kysely<Database>,\n\topts: { locale?: string },\n): Promise<ApiResult<{ relations: Relation[] }>> {\n\ttry {\n\t\tconst repo = new RelationRepository(db);\n\t\tconst locale = opts.locale ? resolveConfiguredLocale(opts.locale) : undefined;\n\t\tconst relations = await repo.list(locale);\n\t\treturn { success: true, data: { relations } };\n\t} catch {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: { code: \"RELATION_LIST_ERROR\", message: \"Failed to list relations\" },\n\t\t};\n\t}\n}\n\nexport async function handleRelationUpdate(\n\tdb: Kysely<Database>,\n\tid: string,\n\tinput: { parentLabel?: string; childLabel?: string },\n): Promise<ApiResult<{ relation: Relation }>> {\n\ttry {\n\t\tconst repo = new RelationRepository(db);\n\t\tconst relation = await repo.update(id, input);\n\t\tif (!relation) {\n\t\t\treturn { success: false, error: { code: \"NOT_FOUND\", message: \"Relation not found\" } };\n\t\t}\n\t\treturn { success: true, data: { relation } };\n\t} catch {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: { code: \"RELATION_UPDATE_ERROR\", message: \"Failed to update relation\" },\n\t\t};\n\t}\n}\n\nexport async function handleRelationDelete(\n\tdb: Kysely<Database>,\n\tid: string,\n): Promise<ApiResult<{ deleted: true }>> {\n\ttry {\n\t\tconst repo = new RelationRepository(db);\n\t\tconst deleted = await repo.delete(id);\n\t\tif (!deleted) {\n\t\t\treturn { success: false, error: { code: \"NOT_FOUND\", message: \"Relation not found\" } };\n\t\t}\n\t\treturn { success: true, data: { deleted: true } };\n\t} catch {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: { code: \"RELATION_DELETE_ERROR\", message: \"Failed to delete relation\" },\n\t\t};\n\t}\n}\n\nexport async function handleRelationTranslations(\n\tdb: Kysely<Database>,\n\tid: string,\n): Promise<\n\tApiResult<{\n\t\ttranslationGroup: string;\n\t\ttranslations: {\n\t\t\tid: string;\n\t\t\tname: string;\n\t\t\tlocale: string;\n\t\t\tparentLabel: string;\n\t\t\tchildLabel: string;\n\t\t}[];\n\t}>\n> {\n\ttry {\n\t\tconst repo = new RelationRepository(db);\n\t\tconst relation = await repo.findById(id);\n\t\tif (!relation) {\n\t\t\treturn { success: false, error: { code: \"NOT_FOUND\", message: \"Relation not found\" } };\n\t\t}\n\t\tconst siblings = await repo.findTranslations(relation.translationGroup);\n\t\treturn {\n\t\t\tsuccess: true,\n\t\t\tdata: {\n\t\t\t\ttranslationGroup: relation.translationGroup,\n\t\t\t\ttranslations: siblings.map((r) => ({\n\t\t\t\t\tid: r.id,\n\t\t\t\t\tname: r.name,\n\t\t\t\t\tlocale: r.locale,\n\t\t\t\t\tparentLabel: r.parentLabel,\n\t\t\t\t\tchildLabel: r.childLabel,\n\t\t\t\t})),\n\t\t\t},\n\t\t};\n\t} catch {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: { code: \"RELATION_TRANSLATIONS_ERROR\", message: \"Failed to get translations\" },\n\t\t};\n\t}\n}\n\nexport type EntryRef = {\n\tid: string;\n\tslug: string | null;\n\tcollection: string;\n\t/** The actual locale of the resolved variant — see `pickVariant`. */\n\tlocale: string | null;\n\tsortOrder?: number;\n};\n\n/** Resolve a relation from an id OR its translation_group. */\nasync function resolveRelation(\n\trepo: RelationRepository,\n\tidOrGroup: string,\n): Promise<Relation | null> {\n\tconst byId = await repo.findById(idOrGroup);\n\tif (byId) return byId;\n\tconst group = await repo.findTranslations(idOrGroup);\n\treturn group[0] ?? null;\n}\n\n/**\n * Pick the locale variant matching `locale`, falling back to the first entry\n * (lowest locale code). The fallback is intentional — an edge is keyed by\n * `translation_group`, so a referenced entry that exists only in another locale\n * is still a real reference — but the returned ref carries the variant's actual\n * `locale` so callers never mistake a fallback for the requested locale.\n */\nfunction pickVariant(items: ContentItem[], locale: string | null): ContentItem | undefined {\n\treturn items.find((i) => i.locale === locale) ?? items[0];\n}\n\n/**\n * Resolve edge groups to loadable entries in `collection` at `locale`.\n * Dangling groups (no surviving entry) are skipped — cleanup is a later slice.\n *\n * All groups are loaded in one batched query (chunked at `SQL_BATCH_SIZE`)\n * rather than a `findTranslations` per edge, so a parent with N children costs\n * a constant number of queries, not N+1. Edge order (the caller's `sort_order`)\n * is preserved by iterating `edges`.\n *\n * `includeDrafts` is false for callers without `content:read_drafts`: the load\n * is restricted to published entries so a draft/scheduled entry referenced by an\n * edge is skipped exactly like a dangling one, never leaking its id/slug/locale.\n */\nasync function resolveEntries(\n\tcontent: ContentRepository,\n\tcollection: string,\n\tedges: ContentReference[],\n\tpick: (e: ContentReference) => string,\n\tlocale: string | null,\n\tincludeDrafts: boolean,\n): Promise<EntryRef[]> {\n\tconst groups = edges.map(pick);\n\tconst all = await content.findTranslationsForGroups(collection, groups, {\n\t\tpublishedOnly: !includeDrafts,\n\t});\n\n\t// Group the flat variant list by translation_group so each edge can pick its\n\t// own locale variant.\n\tconst variantsByGroup = new Map<string, ContentItem[]>();\n\tfor (const item of all) {\n\t\tif (item.translationGroup == null) continue;\n\t\tconst list = variantsByGroup.get(item.translationGroup);\n\t\tif (list) list.push(item);\n\t\telse variantsByGroup.set(item.translationGroup, [item]);\n\t}\n\n\tconst refs: EntryRef[] = [];\n\tfor (const edge of edges) {\n\t\tconst variants = variantsByGroup.get(pick(edge));\n\t\tif (!variants) continue;\n\t\tconst entry = pickVariant(variants, locale);\n\t\tif (!entry) continue;\n\t\trefs.push({\n\t\t\tid: entry.id,\n\t\t\tslug: entry.slug,\n\t\t\tcollection,\n\t\t\tlocale: entry.locale,\n\t\t\tsortOrder: edge.sortOrder,\n\t\t});\n\t}\n\treturn refs;\n}\n\n/** Pagination inputs for the edge read endpoints. */\nexport type PageOptions = { limit?: number; cursor?: string };\n\nexport async function handleReferenceChildrenGet(\n\tdb: Kysely<Database>,\n\tcollection: string,\n\tentryId: string,\n\trelation: string,\n\tpage: PageOptions = {},\n\tincludeDrafts = false,\n): Promise<ApiResult<{ children: EntryRef[]; nextCursor?: string }>> {\n\ttry {\n\t\tconst repo = new RelationRepository(db);\n\t\tconst content = new ContentRepository(db);\n\n\t\tconst rel = await resolveRelation(repo, relation);\n\t\tif (!rel)\n\t\t\treturn { success: false, error: { code: \"NOT_FOUND\", message: \"Relation not found\" } };\n\t\tif (collection !== rel.parentCollection) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: {\n\t\t\t\t\tcode: \"VALIDATION_ERROR\",\n\t\t\t\t\tmessage: \"Entry is not the parent side of this relation\",\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\tconst entry = await content.findByIdOrSlug(collection, entryId);\n\t\t// A caller without draft access must not anchor on a non-published entry —\n\t\t// return NOT_FOUND (not 403) so they can't probe draft ids by status code,\n\t\t// mirroring the single-item content read.\n\t\tif (!entry?.translationGroup || (!includeDrafts && entry.status !== \"published\")) {\n\t\t\treturn { success: false, error: { code: \"NOT_FOUND\", message: \"Content entry not found\" } };\n\t\t}\n\n\t\tconst edges = await repo.getChildrenPage(rel.translationGroup, entry.translationGroup, page);\n\t\tconst children = await resolveEntries(\n\t\t\tcontent,\n\t\t\trel.childCollection,\n\t\t\tedges.items,\n\t\t\t(e) => e.childGroup,\n\t\t\tentry.locale,\n\t\t\tincludeDrafts,\n\t\t);\n\t\treturn { success: true, data: { children, nextCursor: edges.nextCursor } };\n\t} catch (error) {\n\t\treturn referencesGetError(error);\n\t}\n}\n\nexport async function handleReferenceChildrenSet(\n\tdb: Kysely<Database>,\n\tcollection: string,\n\tentryId: string,\n\trelation: string,\n\tchildIds: string[],\n): Promise<ApiResult<{ children: EntryRef[]; nextCursor?: string }>> {\n\ttry {\n\t\tconst repo = new RelationRepository(db);\n\t\tconst content = new ContentRepository(db);\n\n\t\tconst rel = await resolveRelation(repo, relation);\n\t\tif (!rel)\n\t\t\treturn { success: false, error: { code: \"NOT_FOUND\", message: \"Relation not found\" } };\n\t\tif (collection !== rel.parentCollection) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: {\n\t\t\t\t\tcode: \"VALIDATION_ERROR\",\n\t\t\t\t\tmessage: \"Entry is not the parent side of this relation\",\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\tconst entry = await content.findByIdOrSlug(collection, entryId);\n\t\tif (!entry?.translationGroup) {\n\t\t\treturn { success: false, error: { code: \"NOT_FOUND\", message: \"Content entry not found\" } };\n\t\t}\n\n\t\t// Resolve every child within the relation's child_collection in one batch\n\t\t// (constant queries, not an N+1 of point lookups for a set up to 1000). A\n\t\t// child id that does not resolve there fails collection-agreement\n\t\t// (invariant 3); order is preserved by iterating the caller's `childIds`.\n\t\tconst resolvedChildren = await content.findManyByIdOrSlug(rel.childCollection, childIds);\n\t\tconst childGroups: string[] = [];\n\t\tfor (const childId of childIds) {\n\t\t\tconst child = resolvedChildren.get(childId);\n\t\t\tif (!child?.translationGroup) {\n\t\t\t\treturn {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: {\n\t\t\t\t\t\tcode: \"NOT_FOUND\",\n\t\t\t\t\t\tmessage: `Child entry '${childId}' not found in ${rel.childCollection}`,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t\tchildGroups.push(child.translationGroup);\n\t\t}\n\n\t\tawait repo.setChildren(rel.translationGroup, entry.translationGroup, childGroups);\n\n\t\t// Return the first page of the new set, mirroring the GET shape. The actor\n\t\t// holds an edit permission (gated by the route), so draft children are\n\t\t// included in the echo.\n\t\tconst edges = await repo.getChildrenPage(rel.translationGroup, entry.translationGroup);\n\t\tconst children = await resolveEntries(\n\t\t\tcontent,\n\t\t\trel.childCollection,\n\t\t\tedges.items,\n\t\t\t(e) => e.childGroup,\n\t\t\tentry.locale,\n\t\t\ttrue,\n\t\t);\n\t\treturn { success: true, data: { children, nextCursor: edges.nextCursor } };\n\t} catch {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: { code: \"REFERENCES_SET_ERROR\", message: \"Failed to set references\" },\n\t\t};\n\t}\n}\n\nexport async function handleReferenceParentsGet(\n\tdb: Kysely<Database>,\n\tcollection: string,\n\tentryId: string,\n\trelation: string,\n\tpage: PageOptions = {},\n\tincludeDrafts = false,\n): Promise<ApiResult<{ parents: EntryRef[]; nextCursor?: string }>> {\n\ttry {\n\t\tconst repo = new RelationRepository(db);\n\t\tconst content = new ContentRepository(db);\n\n\t\tconst rel = await resolveRelation(repo, relation);\n\t\tif (!rel)\n\t\t\treturn { success: false, error: { code: \"NOT_FOUND\", message: \"Relation not found\" } };\n\t\tif (collection !== rel.childCollection) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: {\n\t\t\t\t\tcode: \"VALIDATION_ERROR\",\n\t\t\t\t\tmessage: \"Entry is not the child side of this relation\",\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\tconst entry = await content.findByIdOrSlug(collection, entryId);\n\t\t// Same draft-anchor guard as the children read: a non-draft-reader anchoring\n\t\t// on an unpublished entry gets NOT_FOUND, not its backlinks.\n\t\tif (!entry?.translationGroup || (!includeDrafts && entry.status !== \"published\")) {\n\t\t\treturn { success: false, error: { code: \"NOT_FOUND\", message: \"Content entry not found\" } };\n\t\t}\n\n\t\tconst edges = await repo.getParentsPage(rel.translationGroup, entry.translationGroup, page);\n\t\tconst parents = await resolveEntries(\n\t\t\tcontent,\n\t\t\trel.parentCollection,\n\t\t\tedges.items,\n\t\t\t(e) => e.parentGroup,\n\t\t\tentry.locale,\n\t\t\tincludeDrafts,\n\t\t);\n\t\treturn { success: true, data: { parents, nextCursor: edges.nextCursor } };\n\t} catch (error) {\n\t\treturn referencesGetError(error);\n\t}\n}\n"],"mappings":";;;;;;;;;AAkBA,SAAS,mBAAmB,OAAkC;AAC7D,KAAI,iBAAiB,mBACpB,QAAO;EAAE,SAAS;EAAO,OAAO;GAAE,MAAM;GAAkB,SAAS,MAAM;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