@murumets-ee/content 0.87.0 → 0.89.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/admin.d.mts.map +1 -1
  2. package/dist/admin.mjs +1 -1
  3. package/dist/block-resolver.mjs +1 -1
  4. package/dist/client.d.mts +1 -1
  5. package/dist/client.mjs +1 -1
  6. package/dist/client.mjs.map +1 -1
  7. package/dist/{enumerate-CBqu63Kp.mjs → enumerate-CYHJKQz6.mjs} +2 -2
  8. package/dist/{enumerate-CBqu63Kp.mjs.map → enumerate-CYHJKQz6.mjs.map} +1 -1
  9. package/dist/{index-C2G4IJck.d.mts → index-C3VyZLjf.d.mts} +55 -2
  10. package/dist/{index-C2G4IJck.d.mts.map → index-C3VyZLjf.d.mts.map} +1 -1
  11. package/dist/index.d.mts +3 -3
  12. package/dist/index.mjs +1 -1
  13. package/dist/index.mjs.map +1 -1
  14. package/dist/locale-entity-CoSq3C77.mjs +2 -0
  15. package/dist/locale-entity-CoSq3C77.mjs.map +1 -0
  16. package/dist/locale-registry-Bn6e_nM7.mjs +2 -0
  17. package/dist/locale-registry-Bn6e_nM7.mjs.map +1 -0
  18. package/dist/plugin-BmxghXzV.mjs +2 -0
  19. package/dist/plugin-BmxghXzV.mjs.map +1 -0
  20. package/dist/plugin.d.mts +4 -4
  21. package/dist/plugin.mjs +1 -1
  22. package/dist/resolve-context-Cvc1aNJe.mjs +2 -0
  23. package/dist/resolve-context-Cvc1aNJe.mjs.map +1 -0
  24. package/dist/resolve.d.mts +54 -16
  25. package/dist/resolve.d.mts.map +1 -1
  26. package/dist/resolve.mjs +6 -6
  27. package/dist/resolve.mjs.map +1 -1
  28. package/dist/routes-BmNSYyuT.mjs +2 -0
  29. package/dist/{routes-C9I1iZw8.mjs.map → routes-BmNSYyuT.mjs.map} +1 -1
  30. package/dist/routing-strategy-D6B4ngT9.mjs +2 -0
  31. package/dist/routing-strategy-D6B4ngT9.mjs.map +1 -0
  32. package/dist/{routing-strategy-D3Qowm3D.d.mts → routing-strategy-DV7KGarX.d.mts} +4 -4
  33. package/dist/{routing-strategy-D3Qowm3D.d.mts.map → routing-strategy-DV7KGarX.d.mts.map} +1 -1
  34. package/dist/schema-BYrYzsmO.mjs +2 -0
  35. package/dist/schema-BYrYzsmO.mjs.map +1 -0
  36. package/dist/schema-IML1rRU_.mjs +2 -0
  37. package/dist/{schema-0zayzpD_.mjs.map → schema-IML1rRU_.mjs.map} +1 -1
  38. package/dist/seed.d.mts.map +1 -1
  39. package/dist/seed.mjs +1 -1
  40. package/dist/seed.mjs.map +1 -1
  41. package/dist/{versions-C9A4rUAR.mjs → versions-DLrR7hIZ.mjs} +2 -2
  42. package/dist/{versions-C9A4rUAR.mjs.map → versions-DLrR7hIZ.mjs.map} +1 -1
  43. package/package.json +9 -9
  44. package/dist/plugin-D0i6odXQ.mjs +0 -2
  45. package/dist/plugin-D0i6odXQ.mjs.map +0 -1
  46. package/dist/resolve-context-MRZZ3rQl.mjs +0 -2
  47. package/dist/resolve-context-MRZZ3rQl.mjs.map +0 -1
  48. package/dist/routes-C9I1iZw8.mjs +0 -2
  49. package/dist/routing-strategy-CQdu1qV7.mjs +0 -2
  50. package/dist/routing-strategy-CQdu1qV7.mjs.map +0 -1
  51. package/dist/schema-0zayzpD_.mjs +0 -2
  52. package/dist/schema-D8sBQozw.mjs +0 -2
  53. package/dist/schema-D8sBQozw.mjs.map +0 -1
@@ -1,8 +1,6 @@
1
1
  import { Entity } from "@murumets-ee/entity";
2
2
  import { Logger, ToolkitApp } from "@murumets-ee/core";
3
3
  import { z } from "zod";
4
- import { PostgresJsDatabase } from "drizzle-orm/postgres-js";
5
-
6
4
  //#region src/redirects/target.d.ts
7
5
  /** The stored shape of `toolkit_redirects.target`. */
8
6
  type RedirectTarget = {
@@ -81,7 +79,7 @@ interface HomepagePointer {
81
79
  id: string;
82
80
  }
83
81
  /**
84
- * Shape of the `site.homeDocument` JSONB value. `id` is a UUID — entity row ids
82
+ * Shape of the `homeDocument` JSONB value. `id` is a UUID — entity row ids
85
83
  * are UUIDs across this codebase (only USER ids are varchar; CLAUDE.md).
86
84
  */
87
85
  declare const homepagePointerSchema: z.ZodObject<{
@@ -95,7 +93,7 @@ declare const homepagePointerSchema: z.ZodObject<{
95
93
  entity: string;
96
94
  }>;
97
95
  /**
98
- * Parse a raw `site.homeDocument` value into a {@link HomepagePointer}, or `null`
96
+ * Parse a raw `homeDocument` value into a {@link HomepagePointer}, or `null`
99
97
  * when it's unset / malformed. Never throws.
100
98
  */
101
99
  declare function parseHomepagePointer(value: unknown): HomepagePointer | null;
@@ -459,6 +457,20 @@ declare const SITEMAP_INDEX_FILENAME = "sitemap.xml";
459
457
  */
460
458
  declare function generateSitemap(opts: SitemapOptions, deps: SitemapDeps, tuning?: SitemapTuning): AsyncGenerator<SitemapFile>;
461
459
  //#endregion
460
+ //#region src/paths/site-sitemap.d.ts
461
+ /** Options for {@link generateSiteSitemap} — everything else comes from the site record. */
462
+ interface SiteSitemapOptions {
463
+ /** Per-locale URL prefix rule — the frontend owns it (routing D002). Omitted → none. */
464
+ prefix?: (locale: string) => string;
465
+ /** Max `<url>` entries per file (see `generateSitemap`). */
466
+ maxUrlsPerFile?: number;
467
+ }
468
+ /**
469
+ * Stream `site`'s sitemap document set. Throws when the site does not exist or
470
+ * declares no public origin (a sitemap of relative URLs is not a sitemap).
471
+ */
472
+ declare function generateSiteSitemap(app: ToolkitApp, site: string, options?: SiteSitemapOptions, tuning?: SitemapTuning): AsyncGenerator<SitemapFile>;
473
+ //#endregion
462
474
  //#region src/paths/redirects-list.d.ts
463
475
  /** The projected `toolkit_redirects` row the manual-redirect enumeration reads. */
464
476
  type RedirectListRow = {
@@ -533,24 +545,50 @@ interface RedirectsListTuning {
533
545
  */
534
546
  declare function getRedirects(opts: RedirectsListOptions, deps: RedirectsListDeps, tuning?: RedirectsListTuning): AsyncGenerator<RedirectEntry>;
535
547
  //#endregion
548
+ //#region src/paths/site-scope.d.ts
549
+ /** Resolves the site an access acts on — see the module docblock. */
550
+ type SiteSource = () => Promise<string>;
551
+ //#endregion
536
552
  //#region src/paths/resolve-context.d.ts
553
+ /**
554
+ * Every builder below is SITE-CONFINED (plan `multisite` phase 03): its
555
+ * `toolkit_paths` / `toolkit_redirects` readers, its publish checks and its
556
+ * homepage reader all act on ONE site.
557
+ *
558
+ * - Omit `site` and that is the site of the request RUNNING the call (resolved
559
+ * at call time, so a bundle built once per app still follows each request) —
560
+ * its explicit `RequestContext.site`, else the single-site answer, else a
561
+ * `SiteRequiredError`. This is every existing caller, unchanged.
562
+ * - Pass `site` to pin one explicitly (a per-site sitemap or warmer run from a
563
+ * site-less job). Pinning inside a request confined to another site throws.
564
+ */
565
+ interface SiteScopeOptions {
566
+ site?: string;
567
+ }
537
568
  /**
538
569
  * Build the minimal deps for {@link import('./resolve.js').getCanonicalPath} —
539
570
  * just the `toolkit_paths` reader. Task 2's `resolveEntityHref` / search
540
571
  * url-builder re-points use this (no publish checker / settings machinery).
541
572
  */
542
- declare function buildCanonicalPathDeps(app: ToolkitApp): CanonicalPathDeps;
573
+ declare function buildCanonicalPathDeps(app: ToolkitApp, options?: SiteScopeOptions): CanonicalPathDeps;
543
574
  /**
544
575
  * Build a live {@link PublishChecker} that reads through an elevated-context
545
576
  * `QueryClient` per entity (publish filter auto-applied). See file header.
546
577
  */
547
- declare function buildPublishChecker(app: ToolkitApp): PublishChecker;
578
+ declare function buildPublishChecker(app: ToolkitApp, options?: SiteScopeOptions): PublishChecker;
548
579
  /**
549
- * Build the homepage reader — a single indexed `toolkit_settings` lookup for
550
- * `site.homeDocument` (global scope, default locale), zod-parsed defensively
551
- * (unset / malformed → `null`, never a throw). No cache in v1 (phase 05 §5).
580
+ * Build the homepage reader for a site (plan `multisite` D007): the site
581
+ * registry row's `homeDocument` (`readSiteRecord` — read with reach, cached
582
+ * briefly), zod-parsed defensively (unset / malformed → `null`, never a throw
583
+ * — this runs on every `/` request).
584
+ *
585
+ * The pointer is only as good as the resolution that follows it: `/` publish-
586
+ * checks the document through a client confined to the SAME site, so a pointer
587
+ * at another site's document (legacy data, a hand-edited row) resolves to
588
+ * `none` instead of serving it (D006, defence in depth — writes are refused
589
+ * by `setSiteHomepage`).
552
590
  */
553
- declare function createHomepageReader(db: PostgresJsDatabase): HomepageReader;
591
+ declare function createHomepageReader(app: ToolkitApp, siteOf: SiteSource): HomepageReader;
554
592
  /**
555
593
  * Build the deps for {@link import('./enumerate.js').enumeratePaths} — the
556
594
  * `toolkit_paths` reader plus a BATCHED publish filter. `filterPublished` runs
@@ -561,14 +599,14 @@ declare function createHomepageReader(db: PostgresJsDatabase): HomepageReader;
561
599
  * unpublished/trashed id is returned. An unknown/unregistered entity type yields the empty set (its
562
600
  * rows are treated as unpublished → dropped, fail-closed).
563
601
  */
564
- declare function buildEnumerateDeps(app: ToolkitApp): EnumeratePathsDeps;
602
+ declare function buildEnumerateDeps(app: ToolkitApp, options?: SiteScopeOptions): EnumeratePathsDeps;
565
603
  /**
566
604
  * Build the deps for {@link import('./enumerate.js').getCanonicalPaths} — just
567
605
  * the `toolkit_paths` reader (batched, NO publish filter, like
568
606
  * {@link buildCanonicalPathDeps}). Task 2's search url re-point uses this to
569
607
  * resolve a search page's result urls from the index in one query.
570
608
  */
571
- declare function buildCanonicalPathsBatchDeps(app: ToolkitApp): CanonicalPathsBatchDeps;
609
+ declare function buildCanonicalPathsBatchDeps(app: ToolkitApp, options?: SiteScopeOptions): CanonicalPathsBatchDeps;
572
610
  /**
573
611
  * Build the deps for {@link import('./sitemap.js').generateSitemap} — the
574
612
  * one-stop bundle of {@link buildEnumerateDeps} (per-locale enumeration + its
@@ -577,7 +615,7 @@ declare function buildCanonicalPathsBatchDeps(app: ToolkitApp): CanonicalPathsBa
577
615
  * read), and {@link buildNoIndexFilter} (PR 11's batched `noIndex` exclusion).
578
616
  * Mirrors `buildResolveDeps`'s one-stop-deps pattern.
579
617
  */
580
- declare function buildSitemapDeps(app: ToolkitApp): SitemapDeps;
618
+ declare function buildSitemapDeps(app: ToolkitApp, options?: SiteScopeOptions): SitemapDeps;
581
619
  /**
582
620
  * Build the deps for {@link import('./redirects-list.js').getRedirects} — the
583
621
  * one-stop bundle for the build-time redirect list (PR08). Composes
@@ -588,7 +626,7 @@ declare function buildSitemapDeps(app: ToolkitApp): SitemapDeps;
588
626
  * `toolkit_redirects` reader for the manual-redirect keyset. Mirrors
589
627
  * {@link buildSitemapDeps}'s one-stop-deps style.
590
628
  */
591
- declare function buildRedirectsListDeps(app: ToolkitApp): RedirectsListDeps;
629
+ declare function buildRedirectsListDeps(app: ToolkitApp, options?: SiteScopeOptions): RedirectsListDeps;
592
630
  /**
593
631
  * Build the full {@link ResolvePathDeps} (+ {@link AlternatesDeps}) from an app —
594
632
  * the one-stop deps for `resolvePath` / `resolveDraftPath` / `getAlternates`.
@@ -596,7 +634,7 @@ declare function buildRedirectsListDeps(app: ToolkitApp): RedirectsListDeps;
596
634
  * redirect routes' own configured-locale source; DB-merged locale overrides are
597
635
  * a later refinement).
598
636
  */
599
- declare function buildResolveDeps(app: ToolkitApp): ResolvePathDeps & AlternatesDeps;
637
+ declare function buildResolveDeps(app: ToolkitApp, options?: SiteScopeOptions): ResolvePathDeps & AlternatesDeps;
600
638
  //#endregion
601
- export { type AlternatesDeps, type CanonicalPathDeps, type CanonicalPathsBatchDeps, DEFAULT_MAX_URLS_PER_FILE, type EntityResolver, type EnumeratePathsDeps, type EnumeratePathsOptions, type EnumeratePathsTuning, type HomepagePointer, type HomepageReader, MAX_REDIRECT_HOPS, type PathEntry, type PathEnumReader, type PathEnumRow, type PathEnumWhere, type PathIndexReader, type PathIndexRow, type PathIndexWhere, type PublishChecker, type PublishFilter, type PublishQueryClient, type QueryClientFactory, type RedirectEntry, type RedirectListReader, type RedirectListRow, type RedirectListWhere, type RedirectLookupReader, type RedirectsListDeps, type RedirectsListOptions, type RedirectsListTuning, type ResolveDocumentResult, type ResolveNoneResult, type ResolvePathDeps, type ResolveRedirectResult, type ResolveResult, SITEMAP_INDEX_FILENAME, type SitemapDeps, type SitemapFile, type SitemapOptions, type SitemapTuning, buildCanonicalPathDeps, buildCanonicalPathsBatchDeps, buildEnumerateDeps, buildPublishChecker, buildRedirectsListDeps, buildResolveDeps, buildSitemapDeps, createHomepageReader, createPublishChecker, enumeratePaths, generateSitemap, getAlternates, getCanonicalPath, getCanonicalPaths, getRedirects, homepagePointerSchema, parseHomepagePointer, resolveDraftPath, resolvePath };
639
+ export { type AlternatesDeps, type CanonicalPathDeps, type CanonicalPathsBatchDeps, DEFAULT_MAX_URLS_PER_FILE, type EntityResolver, type EnumeratePathsDeps, type EnumeratePathsOptions, type EnumeratePathsTuning, type HomepagePointer, type HomepageReader, MAX_REDIRECT_HOPS, type PathEntry, type PathEnumReader, type PathEnumRow, type PathEnumWhere, type PathIndexReader, type PathIndexRow, type PathIndexWhere, type PublishChecker, type PublishFilter, type PublishQueryClient, type QueryClientFactory, type RedirectEntry, type RedirectListReader, type RedirectListRow, type RedirectListWhere, type RedirectLookupReader, type RedirectsListDeps, type RedirectsListOptions, type RedirectsListTuning, type ResolveDocumentResult, type ResolveNoneResult, type ResolvePathDeps, type ResolveRedirectResult, type ResolveResult, SITEMAP_INDEX_FILENAME, type SiteScopeOptions, type SiteSitemapOptions, type SitemapDeps, type SitemapFile, type SitemapOptions, type SitemapTuning, buildCanonicalPathDeps, buildCanonicalPathsBatchDeps, buildEnumerateDeps, buildPublishChecker, buildRedirectsListDeps, buildResolveDeps, buildSitemapDeps, createHomepageReader, createPublishChecker, enumeratePaths, generateSiteSitemap, generateSitemap, getAlternates, getCanonicalPath, getCanonicalPaths, getRedirects, homepagePointerSchema, parseHomepagePointer, resolveDraftPath, resolvePath };
602
640
  //# sourceMappingURL=resolve.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolve.d.mts","names":[],"sources":["../src/redirects/target.ts","../src/paths/index-reader.ts","../src/paths/homepage.ts","../src/paths/resolve.ts","../src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CxFF,sBAAA,CAAuB,GAAA,EAAK,UAAA,GAAa,iBAAiB;;ANrC7D;AAIb;;iBMyCgB,mBAAA,CAAoB,GAAA,EAAK,UAAA,GAAa,cAAc;;;;;;iBAkBpD,oBAAA,CAAqB,EAAA,EAAI,kBAAA,GAAqB,cAAc;;;;;;;;;;;iBAyB5D,kBAAA,CAAmB,GAAA,EAAK,UAAA,GAAa,kBAAkB;;;;;;;iBAmCvD,4BAAA,CAA6B,GAAA,EAAK,UAAA,GAAa,uBAAuB;;;ANhH5D;;;;AClC1B;;iBK0MgB,gBAAA,CAAiB,GAAA,EAAK,UAAA,GAAa,WAAW;;ALxM1D;AAOJ;;;;;;;;iBKmNgB,sBAAA,CAAuB,GAAA,EAAK,UAAA,GAAa,iBAAiB;;;;;;;;iBAiB1D,gBAAA,CAAiB,GAAA,EAAK,UAAA,GAAa,eAAA,GAAkB,cAAA"}
1
+ {"version":3,"file":"resolve.d.mts","names":[],"sources":["../src/redirects/target.ts","../src/paths/index-reader.ts","../src/paths/homepage.ts","../src/paths/resolve.ts","../src/paths/enumerate.ts","../src/paths/sitemap.ts","../src/paths/site-sitemap.ts","../src/paths/redirects-list.ts","../src/paths/site-scope.ts","../src/paths/resolve-context.ts"],"mappings":";;;;;KA8BY,cAAA;EACN,IAAA;EAAgB,MAAA;EAAgB,EAAA;AAAA;EAChC,IAAA;EAAa,GAAA;AAAA;EACb,IAAA;EAAc,IAAA;AAAA;;;;;;;;;AAHpB;;;;;;;;;;;;AAGwB;;;;ACJxB;;;;;;ADIwB,KCJZ,YAAA;EACV,UAAA;EACA,QAAA;EACA,MAAA;EACA,IAAA;EACA,WAAA;AAAA;;KAIU,cAAA;EACV,UAAA;EACA,QAAA;EACA,MAAA;EACA,IAAA;EACA,WAAA;AAAA;AAAW;AAAA,KAID,eAAA;EACV,OAAA,CAAQ,KAAA,EAAO,cAAA,GAAiB,OAAA,CAAQ,YAAA;EACxC,QAAA,CAAS,OAAA;IACP,KAAA,GAAQ,cAAA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AAA;;;AP3H3E;;;;AAEI;AAOJ;;;iBO0IgB,kBAAA,CACd,GAAA,EAAK,UAAA,EACL,OAAA,GAAS,gBAAA,GACR,kBAAA;;;;;;;iBAoCa,4BAAA,CACd,GAAA,EAAK,UAAA,EACL,OAAA,GAAS,gBAAA,GACR,uBAAA;;;;;;;;;iBAyDa,gBAAA,CAAiB,GAAA,EAAK,UAAA,EAAY,OAAA,GAAS,gBAAA,GAAwB,WAAA;;;;;;APpOnF;;;;AAAqE;iBOsPrD,sBAAA,CACd,GAAA,EAAK,UAAA,EACL,OAAA,GAAS,gBAAA,GACR,iBAAA;;;ANtPH;;;;;iBMuQgB,gBAAA,CACd,GAAA,EAAK,UAAA,EACL,OAAA,GAAS,gBAAA,GACR,eAAA,GAAkB,cAAA"}
package/dist/resolve.mjs CHANGED
@@ -1,9 +1,9 @@
1
- import{a as e}from"./schema-D8sBQozw.mjs";import{a as t,c as n,d as r,i,o as a,r as o,s}from"./schema-0zayzpD_.mjs";import{a as c,c as l,d as u,i as d,n as f,o as p,r as m,s as h,t as g,u as _}from"./resolve-context-MRZZ3rQl.mjs";import{r as v,t as y}from"./enumerate-CBqu63Kp.mjs";const b=4e4,x=`sitemap.xml`;async function*S(e,t,n={}){let r=N(e.maxUrlsPerFile,b),i=N(n.batchSize,200),a=A(e.baseUrl),o=[];for(let s of e.locales){let c=[],l=null,u=0,d=()=>{if(c.length===0)return null;let e=M(s,u),t=(l??new Date).toISOString(),n={kind:`urlset`,filename:e,xml:T(c)};return o.push({filename:e,lastmod:t}),c=[],l=null,u+=1,n},f=y({locale:s},t.enumerate,n.enumerate);for await(let n of P(f,i)){let i=await w(n,s,t);if(i.length===0)continue;let o=await C(i,s,e,t);for(let t of i){let n=o.get(t.id)??[{locale:s,path:t.path}];if(c.push(E(t,s,n,e,a)),(l===null||t.updatedAt>l)&&(l=t.updatedAt),c.length>=r){let e=d();e&&(yield e)}}}let p=d();p&&(yield p)}o.length>1&&(yield{kind:`index`,filename:x,xml:D(o,a)})}async function C(e,t,n,r){let i=new Map;for(let n of e)i.set(n.id,[{locale:t,path:n.path}]);let a=n.locales.filter(e=>e!==t);if(a.length===0)return i;let o=new Map;for(let t of e){let e=o.get(t.entityType);e?e.push(t.id):o.set(t.entityType,[t.id])}for(let e of a)for(let[t,n]of o){let a=await v(t,n,e,r.canonicalBatch);if(a.size===0)continue;let o=[...a.keys()],s=await r.enumerate.filterPublished(t,o,e),c=r.filterNoIndex===void 0?void 0:await r.filterNoIndex(t,o,e);for(let[t,n]of a){if(!s.has(t)||c?.has(t))continue;let r=i.get(t);r&&r.push({locale:e,path:n})}}return i}async function w(t,n,r){let i=r.filterNoIndex;if(i===void 0)return[...t];let a=new Map;for(let e of t){let t=a.get(e.entityType);t?t.push(e.id):a.set(e.entityType,[e.id])}let o=new Map;return await e([...a.entries()],5,async([e,t])=>{o.set(e,await i(e,t,n))}),t.filter(e=>!o.get(e.entityType)?.has(e.id))}function T(e){return`<?xml version="1.0" encoding="UTF-8"?>
1
+ import{i as e,t}from"./locale-registry-Bn6e_nM7.mjs";import{c as n}from"./schema-BYrYzsmO.mjs";import{a as r,c as i,d as a,i as o,o as s,r as c,s as l}from"./schema-IML1rRU_.mjs";import{a as u,c as d,d as f,i as p,n as m,o as h,r as g,s as _,t as v,u as y}from"./resolve-context-Cvc1aNJe.mjs";import{r as b,t as x}from"./enumerate-CYHJKQz6.mjs";import{readSiteRecord as S}from"@murumets-ee/core";const C=4e4,w=`sitemap.xml`;async function*T(e,t,n={}){let r=I(e.maxUrlsPerFile,C),i=I(n.batchSize,200),a=N(e.baseUrl),o=[];for(let s of e.locales){let c=[],l=null,u=0,d=()=>{if(c.length===0)return null;let e=F(s,u),t=(l??new Date).toISOString(),n={kind:`urlset`,filename:e,xml:O(c)};return o.push({filename:e,lastmod:t}),c=[],l=null,u+=1,n},f=x({locale:s},t.enumerate,n.enumerate);for await(let n of L(f,i)){let i=await D(n,s,t);if(i.length===0)continue;let o=await E(i,s,e,t);for(let t of i){let n=o.get(t.id)??[{locale:s,path:t.path}];if(c.push(k(t,s,n,e,a)),(l===null||t.updatedAt>l)&&(l=t.updatedAt),c.length>=r){let e=d();e&&(yield e)}}}let p=d();p&&(yield p)}o.length>1&&(yield{kind:`index`,filename:w,xml:A(o,a)})}async function E(e,t,n,r){let i=new Map;for(let n of e)i.set(n.id,[{locale:t,path:n.path}]);let a=n.locales.filter(e=>e!==t);if(a.length===0)return i;let o=new Map;for(let t of e){let e=o.get(t.entityType);e?e.push(t.id):o.set(t.entityType,[t.id])}for(let e of a)for(let[t,n]of o){let a=await b(t,n,e,r.canonicalBatch);if(a.size===0)continue;let o=[...a.keys()],s=await r.enumerate.filterPublished(t,o,e),c=r.filterNoIndex===void 0?void 0:await r.filterNoIndex(t,o,e);for(let[t,n]of a){if(!s.has(t)||c?.has(t))continue;let r=i.get(t);r&&r.push({locale:e,path:n})}}return i}async function D(e,t,r){let i=r.filterNoIndex;if(i===void 0)return[...e];let a=new Map;for(let t of e){let e=a.get(t.entityType);e?e.push(t.id):a.set(t.entityType,[t.id])}let o=new Map;return await n([...a.entries()],5,async([e,n])=>{o.set(e,await i(e,n,t))}),e.filter(e=>!o.get(e.entityType)?.has(e.id))}function O(e){return`<?xml version="1.0" encoding="UTF-8"?>
2
2
  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">\n${e.join(`
3
- `)}\n</urlset>\n`}function E(e,t,n,r,i){let a=k(i,r.prefix,t,e.path),o=n.map(e=>` ${O(e.locale,k(i,r.prefix,e.locale,e.path))}`),s=n.find(e=>e.locale===r.defaultLocale);return s&&o.push(` ${O(`x-default`,k(i,r.prefix,s.locale,s.path))}`),` <url>
4
- <loc>${j(a)}</loc>\n <lastmod>${e.updatedAt.toISOString()}</lastmod>\n${o.join(`
5
- `)}\n </url>`}function D(e,t){return`<?xml version="1.0" encoding="UTF-8"?>
3
+ `)}\n</urlset>\n`}function k(e,t,n,r,i){let a=M(i,r.prefix,t,e.path),o=n.map(e=>` ${j(e.locale,M(i,r.prefix,e.locale,e.path))}`),s=n.find(e=>e.locale===r.defaultLocale);return s&&o.push(` ${j(`x-default`,M(i,r.prefix,s.locale,s.path))}`),` <url>
4
+ <loc>${P(a)}</loc>\n <lastmod>${e.updatedAt.toISOString()}</lastmod>\n${o.join(`
5
+ `)}\n </url>`}function A(e,t){return`<?xml version="1.0" encoding="UTF-8"?>
6
6
  <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${e.map(e=>` <sitemap>
7
- <loc>${j(`${t}/${e.filename}`)}</loc>\n <lastmod>${e.lastmod}</lastmod>\n </sitemap>`).join(`
8
- `)}\n</sitemapindex>\n`}function O(e,t){return`<xhtml:link rel="alternate" hreflang="${j(e)}" href="${j(t)}"/>`}function k(e,t,n,r){return`${e}${t?t(n):``}${r}`}function A(e){return e.replace(/\/+$/,``)}function j(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&apos;`)}function M(e,t){return t===0?`sitemap-${e}.xml`:`sitemap-${e}-${t+1}.xml`}function N(e,t){if(e===void 0||!Number.isFinite(e))return t;let n=Math.floor(e);return n>=1?n:t}async function*P(e,t){let n=[];for await(let r of e)n.push(r),n.length>=t&&(yield n,n=[]);n.length>0&&(yield n)}async function*F(e,t,n={}){let{locale:r}=e,i=n.pageSize??200,a=new Set;yield*I(r,r,t,i,a),yield*I(r,null,t,i,a),yield*z(r,t,i,a)}async function*I(e,t,n,i,a){let o;for(;;){let s={locale:t};o!==void 0&&(s.id={gt:o});let c=await n.redirectsClient.findMany({where:s,orderBy:[{column:`id`,dir:`asc`}],limit:i});if(c.length===0)break;let l=[];for(let e of c)a.has(e.fromPath)||(a.add(e.fromPath),l.push(e));let u=await L(l,e,n);for(let t of l){let i=B(t.status),a=t.target;if(a.kind===`url`){yield{from:t.fromPath,to:a.url,status:i};continue}if(a.kind===`entity`){let e=u.get(t.id);e!==void 0&&e!==t.fromPath&&(yield{from:t.fromPath,to:e,status:i});continue}let o=r(a.path);o!==t.fromPath&&await R(n.pathsClient,e,o)&&(yield{from:t.fromPath,to:o,status:i})}let d=c[c.length-1];if(!d||(o=d.id,c.length<i))break}}async function L(e,t,n){let r=new Map,i=new Map;for(let t of e){if(t.target.kind!==`entity`)continue;let e={rowId:t.id,targetId:t.target.id},n=i.get(t.target.entity);n?n.push(e):i.set(t.target.entity,[e])}for(let[e,a]of i){let i=await v(e,a.map(e=>e.targetId),t,n.canonicalBatch),o=[...i.keys()];if(o.length===0)continue;let s=await n.filterPublished(e,o,t);for(let{rowId:e,targetId:t}of a){let n=i.get(t);n!==void 0&&s.has(t)&&r.set(e,n)}}return r}async function R(e,t,n){return(await e.findMany({where:{locale:t,path:n,isCanonical:!0},limit:1})).length>0}async function*z(e,t,n,r){let i=new Set,a;for(;;){let o={locale:e,isCanonical:!1};a!==void 0&&(o.id={gt:a});let s=await t.pathsClient.findMany({where:o,orderBy:[{column:`id`,dir:`asc`}],limit:n});if(s.length===0)break;let c=new Map;for(let e of s){let t=c.get(e.entityType);t?t.push(e):c.set(e.entityType,[e])}let l=new Map;for(let[n,r]of c){let i=await v(n,r.map(e=>e.entityId),e,t.canonicalBatch),a=[...i.keys()];if(a.length===0)continue;let o=await t.filterPublished(n,a,e);for(let[e,t]of i)o.has(e)&&l.set(e,t)}for(let e of s){if(r.has(e.path)||i.has(e.path))continue;let t=l.get(e.entityId);t!==void 0&&t!==e.path&&(i.add(e.path),yield{from:e.path,to:t,status:301})}let u=s[s.length-1];if(!u||(a=u.id,s.length<n))break}}function B(e){return e===302?302:301}export{b as DEFAULT_MAX_URLS_PER_FILE,o as MAX_REDIRECT_HOPS,x as SITEMAP_INDEX_FILENAME,g as buildCanonicalPathDeps,f as buildCanonicalPathsBatchDeps,m as buildEnumerateDeps,d as buildPublishChecker,c as buildRedirectsListDeps,p as buildResolveDeps,h as buildSitemapDeps,l as createHomepageReader,i as createPublishChecker,y as enumeratePaths,S as generateSitemap,t as getAlternates,a as getCanonicalPath,v as getCanonicalPaths,F as getRedirects,_ as homepagePointerSchema,u as parseHomepagePointer,s as resolveDraftPath,n as resolvePath};
7
+ <loc>${P(`${t}/${e.filename}`)}</loc>\n <lastmod>${e.lastmod}</lastmod>\n </sitemap>`).join(`
8
+ `)}\n</sitemapindex>\n`}function j(e,t){return`<xhtml:link rel="alternate" hreflang="${P(e)}" href="${P(t)}"/>`}function M(e,t,n,r){return`${e}${t?t(n):``}${r}`}function N(e){return e.replace(/\/+$/,``)}function P(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&apos;`)}function F(e,t){return t===0?`sitemap-${e}.xml`:`sitemap-${e}-${t+1}.xml`}function I(e,t){if(e===void 0||!Number.isFinite(e))return t;let n=Math.floor(e);return n>=1?n:t}async function*L(e,t){let n=[];for await(let r of e)n.push(r),n.length>=t&&(yield n,n=[]);n.length>0&&(yield n)}async function*R(n,r,i={},a={}){let o=await S(n,r);if(!o)throw Error(`There is no site '${r}'`);let s=o.origins[0];if(s===void 0)throw Error(`Site '${r}' declares no public origin — its sitemap has no URLs to give`);let{entries:c,i18n:l}=await e(n,{site:r});yield*T({locales:t(c),defaultLocale:l.defaultLocale,baseUrl:s,...i.prefix!==void 0&&{prefix:i.prefix},...i.maxUrlsPerFile!==void 0&&{maxUrlsPerFile:i.maxUrlsPerFile}},_(n,{site:r}),a)}async function*z(e,t,n={}){let{locale:r}=e,i=n.pageSize??200,a=new Set;yield*B(r,r,t,i,a),yield*B(r,null,t,i,a),yield*U(r,t,i,a)}async function*B(e,t,n,r,i){let o;for(;;){let s={locale:t};o!==void 0&&(s.id={gt:o});let c=await n.redirectsClient.findMany({where:s,orderBy:[{column:`id`,dir:`asc`}],limit:r});if(c.length===0)break;let l=[];for(let e of c)i.has(e.fromPath)||(i.add(e.fromPath),l.push(e));let u=await V(l,e,n);for(let t of l){let r=W(t.status),i=t.target;if(i.kind===`url`){yield{from:t.fromPath,to:i.url,status:r};continue}if(i.kind===`entity`){let e=u.get(t.id);e!==void 0&&e!==t.fromPath&&(yield{from:t.fromPath,to:e,status:r});continue}let o=a(i.path);o!==t.fromPath&&await H(n.pathsClient,e,o)&&(yield{from:t.fromPath,to:o,status:r})}let d=c[c.length-1];if(!d||(o=d.id,c.length<r))break}}async function V(e,t,n){let r=new Map,i=new Map;for(let t of e){if(t.target.kind!==`entity`)continue;let e={rowId:t.id,targetId:t.target.id},n=i.get(t.target.entity);n?n.push(e):i.set(t.target.entity,[e])}for(let[e,a]of i){let i=await b(e,a.map(e=>e.targetId),t,n.canonicalBatch),o=[...i.keys()];if(o.length===0)continue;let s=await n.filterPublished(e,o,t);for(let{rowId:e,targetId:t}of a){let n=i.get(t);n!==void 0&&s.has(t)&&r.set(e,n)}}return r}async function H(e,t,n){return(await e.findMany({where:{locale:t,path:n,isCanonical:!0},limit:1})).length>0}async function*U(e,t,n,r){let i=new Set,a;for(;;){let o={locale:e,isCanonical:!1};a!==void 0&&(o.id={gt:a});let s=await t.pathsClient.findMany({where:o,orderBy:[{column:`id`,dir:`asc`}],limit:n});if(s.length===0)break;let c=new Map;for(let e of s){let t=c.get(e.entityType);t?t.push(e):c.set(e.entityType,[e])}let l=new Map;for(let[n,r]of c){let i=await b(n,r.map(e=>e.entityId),e,t.canonicalBatch),a=[...i.keys()];if(a.length===0)continue;let o=await t.filterPublished(n,a,e);for(let[e,t]of i)o.has(e)&&l.set(e,t)}for(let e of s){if(r.has(e.path)||i.has(e.path))continue;let t=l.get(e.entityId);t!==void 0&&t!==e.path&&(i.add(e.path),yield{from:e.path,to:t,status:301})}let u=s[s.length-1];if(!u||(a=u.id,s.length<n))break}}function W(e){return e===302?302:301}export{C as DEFAULT_MAX_URLS_PER_FILE,c as MAX_REDIRECT_HOPS,w as SITEMAP_INDEX_FILENAME,v as buildCanonicalPathDeps,m as buildCanonicalPathsBatchDeps,g as buildEnumerateDeps,p as buildPublishChecker,u as buildRedirectsListDeps,h as buildResolveDeps,_ as buildSitemapDeps,d as createHomepageReader,o as createPublishChecker,x as enumeratePaths,R as generateSiteSitemap,T as generateSitemap,r as getAlternates,s as getCanonicalPath,b as getCanonicalPaths,z as getRedirects,y as homepagePointerSchema,f as parseHomepagePointer,l as resolveDraftPath,i as resolvePath};
9
9
  //# sourceMappingURL=resolve.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolve.mjs","names":[],"sources":["../src/paths/sitemap.ts","../src/paths/redirects-list.ts"],"sourcesContent":["/**\n * Sitemap generation for the routed content surface (plan/routing PR07; phase\n * `05-resolution-and-enumeration-api.md` §4).\n *\n * `generateSitemap` streams the standard-protocol sitemap document set for the\n * configured locales: one `<urlset>` per locale (split into numbered files at\n * {@link SitemapOptions.maxUrlsPerFile}), plus a `<sitemapindex>` when the run\n * produced more than one file. Each `<url>` carries a `<lastmod>` (from the\n * enumerated `updatedAt`) and the full `xhtml:link` hreflang-alternates set —\n * including an `x-default` pointing at the default-locale URL. It is a PURE\n * generator, NOT an HTTP endpoint: the frontend recipe (PR08) mounts it in a\n * route handler; this module only produces the documents.\n *\n * **Security (CLAUDE.md #1).** The output feeds a public build artifact, so it\n * must NEVER leak an unpublished / trashed document. Two independent publish\n * gates apply:\n * 1. The primary rows come from {@link enumeratePaths}, which publish-filters\n * each page against the entity (unpublished/trashed dropped) for the\n * sitemap's OWN locale.\n * 2. The cross-locale hreflang alternates come from {@link getCanonicalPaths},\n * which does NOT publish-filter (it is a display-only forward index read).\n * So this module ADDITIONALLY runs the same batched `filterPublished` over\n * every candidate other-locale alternate before linking it — an\n * unpublished-in-that-locale document is never emitted as an alternate.\n *\n * **No unbounded fan-out (CLAUDE.md \"no amplification\").** The cross-locale\n * alternate lookup is BATCHED exactly like `enumeratePaths`'s own publish check:\n * per {@link SITEMAP_ALTERNATES_BATCH_SIZE}-sized chunk of enumerated rows, the\n * work is ONE `getCanonicalPaths` + ONE `filterPublished` per (entity-type\n * group × other locale) — bounded by (batch size × distinct routable types ×\n * locale count), NEVER one query per document. `getAlternates` (the per-document\n * N-locale function) is deliberately NOT used here — calling it per enumerated\n * row would be the O(rows × locales) amplification this bound forbids.\n *\n * **`noIndex` exclusion (PR 11's `seoMeta()`).** `SitemapDeps.filterNoIndex` is\n * an OPTIONAL batched dep, same shape as `filterPublished` (a `PublishFilter`)\n * but semantics-inverted: it returns the subset of ids that ARE `noIndex` in\n * the given locale. It lives on `deps`, not `opts`, because — like\n * `filterPublished` — a real implementation needs a DB read, and `noIndex` is\n * `translatable: true`, so the SAME callback must be invoked once per\n * (locale, entity-type group, batch) to see the right per-locale value; a\n * per-entry (locale-blind) predicate could not express this correctly. Omitted\n * → nothing excluded (current default). See `excludeNoIndexed`.\n *\n * **Leaf module.** Every cross-package dependency is injected via `deps`\n * ({@link SitemapDeps}); this module imports no `@murumets-ee/core` and no\n * `server-only` graph. Concrete deps are built from an app in\n * `./resolve-context.ts` (`buildSitemapDeps`).\n */\n\nimport { mapBounded } from './apply-path.js'\nimport {\n type CanonicalPathsBatchDeps,\n enumeratePaths,\n type EnumeratePathsDeps,\n type EnumeratePathsTuning,\n getCanonicalPaths,\n type PathEntry,\n type PublishFilter,\n} from './enumerate.js'\n\n// ---------------------------------------------------------------------------\n// Public surface\n// ---------------------------------------------------------------------------\n\n/** Options for {@link generateSitemap}. */\nexport interface SitemapOptions {\n /** The locales to emit a `<urlset>` for (configured content locales). */\n locales: readonly string[]\n /**\n * The default locale — its URL is the `x-default` hreflang target. Explicit\n * (NOT inferred from `locales` order) so callers stay unambiguous.\n */\n defaultLocale: string\n /** Absolute site origin, e.g. `https://example.com` (trailing slash tolerated). */\n baseUrl: string\n /**\n * Per-locale URL prefix rule (e.g. `(l) => l === 'en' ? '' : '/' + l`). The\n * frontend owns the locale-prefix convention (D002); omitted → no prefix.\n */\n prefix?: (locale: string) => string\n /**\n * Max `<url>` entries per file before splitting (sitemap protocol caps at\n * 50 000). Defaults to {@link DEFAULT_MAX_URLS_PER_FILE}.\n */\n maxUrlsPerFile?: number\n}\n\n/** Injected dependencies for {@link generateSitemap}. */\nexport interface SitemapDeps {\n /**\n * Deps for {@link enumeratePaths} — the `toolkit_paths` reader plus the\n * batched `filterPublished`. `filterPublished` is REUSED for the cross-locale\n * alternate publish gate (same batched shape), so no second publish surface is\n * needed.\n */\n enumerate: EnumeratePathsDeps\n /**\n * Deps for {@link getCanonicalPaths} — the batched cross-locale forward index\n * read (NO publish filter; this module applies `enumerate.filterPublished` on\n * top).\n */\n canonicalBatch: CanonicalPathsBatchDeps\n /**\n * Optional: batched `noIndex` check, same shape as `filterPublished` but\n * semantics-inverted — returns the subset of `entityIds` that ARE `noIndex`\n * in `locale` (PR 11's `seoMeta()`). Called at most once per (entity-type\n * group, batch), never once per entry — see `excludeNoIndexed`. Omitted →\n * nothing excluded (current default).\n */\n filterNoIndex?: PublishFilter\n}\n\n/** Internal tuning seam (batch size / enumerate page size). Real callers omit it. */\nexport interface SitemapTuning {\n /**\n * Enumerated rows per cross-locale alternate batch. Defaults to\n * {@link SITEMAP_ALTERNATES_BATCH_SIZE}. Tests force a small value to span\n * multiple batches. Bounds the per-batch fan-out (see module header).\n */\n batchSize?: number\n /** Passed through to {@link enumeratePaths} for its own paging/publish tuning. */\n enumerate?: EnumeratePathsTuning\n}\n\n/** One emitted sitemap document. */\nexport interface SitemapFile {\n /** `'urlset'` for a per-locale URL set, `'index'` for the sitemap index. */\n kind: 'urlset' | 'index'\n /**\n * Suggested filename served at `${baseUrl}/${filename}`. Per-locale urlsets are\n * `sitemap-<locale>.xml` (first) / `sitemap-<locale>-<n>.xml` (splits, n≥2);\n * the index is {@link SITEMAP_INDEX_FILENAME}.\n */\n filename: string\n /** The complete, well-formed XML document text (trailing newline included). */\n xml: string\n}\n\n/** Default `<url>` cap per file — under the sitemap protocol's 50 000 hard limit. */\nexport const DEFAULT_MAX_URLS_PER_FILE = 40_000\n\n/** Filename of the emitted sitemap index (referenced by the mounting route). */\nexport const SITEMAP_INDEX_FILENAME = 'sitemap.xml'\n\n/**\n * Enumerated rows per cross-locale alternate batch. Aligned with\n * `enumeratePaths`'s own page size so a batch is ~one enumeration page; the\n * exact value only affects HOW MANY batched lookups run, never their per-batch\n * bound (see module header). Never per-row.\n */\nconst SITEMAP_ALTERNATES_BATCH_SIZE = 200\n\n// ---------------------------------------------------------------------------\n// Generator\n// ---------------------------------------------------------------------------\n\n/** One resolved hreflang alternate (a published, canonical per-locale URL). */\ninterface Alternate {\n locale: string\n path: string\n}\n\n/**\n * Stream the sitemap document set for `opts.locales`. See the module header for\n * the security + fan-out guarantees. Yields each `<urlset>` file as it fills,\n * then a `<sitemapindex>` LAST iff more than one file was produced.\n */\nexport async function* generateSitemap(\n opts: SitemapOptions,\n deps: SitemapDeps,\n tuning: SitemapTuning = {},\n): AsyncGenerator<SitemapFile> {\n const maxUrls = normalizePositiveInt(opts.maxUrlsPerFile, DEFAULT_MAX_URLS_PER_FILE)\n const batchSize = normalizePositiveInt(tuning.batchSize, SITEMAP_ALTERNATES_BATCH_SIZE)\n const base = stripTrailingSlash(opts.baseUrl)\n\n /** (filename, lastmod) of every urlset file produced — feeds the index. */\n const producedFiles: Array<{ filename: string; lastmod: string }> = []\n\n for (const locale of opts.locales) {\n let buffer: string[] = []\n let bufferMaxUpdatedAt: Date | null = null\n let fileIndex = 0\n\n /** Flush the current buffer as a numbered urlset file (or return null if empty). */\n const flush = (): SitemapFile | null => {\n if (buffer.length === 0) return null\n const filename = urlsetFilename(locale, fileIndex)\n const lastmod = (bufferMaxUpdatedAt ?? new Date()).toISOString()\n const file: SitemapFile = { kind: 'urlset', filename, xml: buildUrlset(buffer) }\n producedFiles.push({ filename, lastmod })\n buffer = []\n bufferMaxUpdatedAt = null\n fileIndex += 1\n return file\n }\n\n const source = enumeratePaths({ locale }, deps.enumerate, tuning.enumerate)\n for await (const batch of chunkAsync(source, batchSize)) {\n // Exclude noIndex rows FIRST so they're never fetched cross-locale.\n const kept = await excludeNoIndexed(batch, locale, deps)\n if (kept.length === 0) continue\n\n // ONE batched cross-locale lookup per (entity-type group × other locale).\n const alternatesByEntry = await resolveAlternates(kept, locale, opts, deps)\n\n for (const entry of kept) {\n const alternates = alternatesByEntry.get(entry.id) ?? [{ locale, path: entry.path }]\n buffer.push(buildUrlEntry(entry, locale, alternates, opts, base))\n if (bufferMaxUpdatedAt === null || entry.updatedAt > bufferMaxUpdatedAt) {\n bufferMaxUpdatedAt = entry.updatedAt\n }\n if (buffer.length >= maxUrls) {\n const full = flush()\n if (full) yield full\n }\n }\n }\n\n const tail = flush()\n if (tail) yield tail\n }\n\n // The index is only meaningful when it references more than one file.\n if (producedFiles.length > 1) {\n yield { kind: 'index', filename: SITEMAP_INDEX_FILENAME, xml: buildIndex(producedFiles, base) }\n }\n}\n\n/**\n * Resolve the full hreflang-alternate set for a batch of same-locale entries.\n * The current locale is always a self-alternate (`enumeratePaths` already proved\n * it published + canonical there). Every OTHER locale is resolved with ONE\n * batched `getCanonicalPaths` (forward index) + ONE batched `filterPublished`\n * (publish gate) per (entity-type group × locale) — never per row.\n */\nasync function resolveAlternates(\n entries: readonly PathEntry[],\n currentLocale: string,\n opts: SitemapOptions,\n deps: SitemapDeps,\n): Promise<Map<string, Alternate[]>> {\n const result = new Map<string, Alternate[]>()\n // Seed each entry with its self-alternate (its own published canonical URL).\n for (const entry of entries) result.set(entry.id, [{ locale: currentLocale, path: entry.path }])\n\n const otherLocales = opts.locales.filter((l) => l !== currentLocale)\n if (otherLocales.length === 0) return result\n\n // Group the batch's ids by entity type (bounded: routable types are few + config-fixed).\n const idsByType = new Map<string, string[]>()\n for (const entry of entries) {\n const bucket = idsByType.get(entry.entityType)\n if (bucket) bucket.push(entry.id)\n else idsByType.set(entry.entityType, [entry.id])\n }\n\n for (const otherLocale of otherLocales) {\n for (const [type, ids] of idsByType) {\n // (1) Forward index: which of these ids have a canonical row in otherLocale?\n const pathMap = await getCanonicalPaths(type, ids, otherLocale, deps.canonicalBatch)\n if (pathMap.size === 0) continue\n // (2) Publish gate: of THOSE, which are actually published in otherLocale?\n // getCanonicalPaths does NOT publish-filter — this is the required\n // no-unpublished-leak step, batched (never per-row).\n const candidateIds = [...pathMap.keys()]\n const publishedIds = await deps.enumerate.filterPublished(type, candidateIds, otherLocale)\n // (3) noIndex gate — same shape, other-locale value. Without this, a\n // document marked noIndex in `otherLocale` (excluded from ITS OWN\n // urlset by `excludeNoIndexed` below) still gets published as an\n // hreflang alternate on every OTHER locale's urlset, publishing the\n // exact URL the editor asked to hide.\n const noIndexIds =\n deps.filterNoIndex !== undefined\n ? await deps.filterNoIndex(type, candidateIds, otherLocale)\n : undefined\n for (const [id, path] of pathMap) {\n if (!publishedIds.has(id)) continue\n if (noIndexIds?.has(id)) continue\n const alternates = result.get(id)\n if (alternates) alternates.push({ locale: otherLocale, path })\n }\n }\n }\n\n return result\n}\n\n/**\n * Peak concurrent `noIndex`-check groups per batch — mirrors `enumerate.ts`'s\n * `PUBLISH_CHECK_CONCURRENCY` bound (CLAUDE.md \"no amplification\"): a batch\n * holds a handful of distinct entity types at most, so this is rarely reached\n * — it exists so the fan-out is EXPLICITLY capped, never unbounded.\n */\nconst NOINDEX_CHECK_CONCURRENCY = 5\n\n/**\n * Keep the entries `deps.filterNoIndex` does NOT report as `noIndex` in\n * `locale` (all of them when the dep is omitted — current default: nothing\n * excluded). Groups the batch by entity type (mirrors `enumeratePaths`'s own\n * `byType` grouping) and calls `deps.filterNoIndex` ONCE per (entity-type\n * group, batch) — never once per entry — bounded to\n * {@link NOINDEX_CHECK_CONCURRENCY} concurrent groups.\n *\n * FAIL-CLOSED, deliberately, unlike `loadMetaPanelData`'s fail-open contract\n * (`packages/admin-ui/src/server/meta-panel-data.ts`): `mapBounded` does not\n * catch per-item errors (see its own doc comment in `apply-path.ts`), so a\n * `deps.filterNoIndex` rejection aborts the whole `generateSitemap` run rather\n * than silently including a possibly-noIndexed row. A build-time sitemap\n * generator failing loudly is preferable to a build succeeding with a leaked\n * noIndex URL.\n */\nasync function excludeNoIndexed(\n entries: readonly PathEntry[],\n locale: string,\n deps: SitemapDeps,\n): Promise<PathEntry[]> {\n const filterNoIndex = deps.filterNoIndex\n if (filterNoIndex === undefined) return [...entries]\n\n // Group this batch's ids by entity type (bounded: routable types are few).\n const idsByType = new Map<string, string[]>()\n for (const entry of entries) {\n const bucket = idsByType.get(entry.entityType)\n if (bucket) bucket.push(entry.id)\n else idsByType.set(entry.entityType, [entry.id])\n }\n\n const noIndexedByType = new Map<string, ReadonlySet<string>>()\n await mapBounded([...idsByType.entries()], NOINDEX_CHECK_CONCURRENCY, async ([type, ids]) => {\n noIndexedByType.set(type, await filterNoIndex(type, ids, locale))\n })\n\n return entries.filter((entry) => !noIndexedByType.get(entry.entityType)?.has(entry.id))\n}\n\n// ---------------------------------------------------------------------------\n// XML builders\n// ---------------------------------------------------------------------------\n\nconst URLSET_HEADER =\n '<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n' +\n '<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" ' +\n 'xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">'\n\nconst INDEX_HEADER =\n '<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n' +\n '<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">'\n\n/** Wrap the buffered `<url>` blocks in a `<urlset>` envelope. */\nfunction buildUrlset(urlBlocks: readonly string[]): string {\n return `${URLSET_HEADER}\\n${urlBlocks.join('\\n')}\\n</urlset>\\n`\n}\n\n/** Build one `<url>` block: `<loc>`, `<lastmod>`, one `xhtml:link` per alternate + x-default. */\nfunction buildUrlEntry(\n entry: PathEntry,\n currentLocale: string,\n alternates: readonly Alternate[],\n opts: SitemapOptions,\n base: string,\n): string {\n const loc = absoluteUrl(base, opts.prefix, currentLocale, entry.path)\n const links = alternates.map(\n (alt) => ` ${hreflangLink(alt.locale, absoluteUrl(base, opts.prefix, alt.locale, alt.path))}`,\n )\n // x-default → the default-locale URL, when the document is published there.\n const defaultAlt = alternates.find((alt) => alt.locale === opts.defaultLocale)\n if (defaultAlt) {\n links.push(\n ` ${hreflangLink('x-default', absoluteUrl(base, opts.prefix, defaultAlt.locale, defaultAlt.path))}`,\n )\n }\n return (\n ' <url>\\n' +\n ` <loc>${escapeXml(loc)}</loc>\\n` +\n ` <lastmod>${entry.updatedAt.toISOString()}</lastmod>\\n` +\n `${links.join('\\n')}\\n` +\n ' </url>'\n )\n}\n\n/** Build the `<sitemapindex>` referencing every produced urlset file. */\nfunction buildIndex(files: ReadonlyArray<{ filename: string; lastmod: string }>, base: string): string {\n const entries = files.map(\n (f) =>\n ' <sitemap>\\n' +\n ` <loc>${escapeXml(`${base}/${f.filename}`)}</loc>\\n` +\n ` <lastmod>${f.lastmod}</lastmod>\\n` +\n ' </sitemap>',\n )\n return `${INDEX_HEADER}\\n${entries.join('\\n')}\\n</sitemapindex>\\n`\n}\n\n/** One `<xhtml:link rel=\"alternate\" hreflang=... href=.../>` tag (both values escaped). */\nfunction hreflangLink(hreflang: string, href: string): string {\n return `<xhtml:link rel=\"alternate\" hreflang=\"${escapeXml(hreflang)}\" href=\"${escapeXml(href)}\"/>`\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\n/** `baseUrl` + optional `prefix(locale)` + `path` — the absolute, un-escaped URL. */\nfunction absoluteUrl(\n base: string,\n prefix: SitemapOptions['prefix'],\n locale: string,\n path: string,\n): string {\n return `${base}${prefix ? prefix(locale) : ''}${path}`\n}\n\n/** Strip any trailing slash(es) so `base + '/' + file` / `base + path` never doubles up. */\nfunction stripTrailingSlash(url: string): string {\n return url.replace(/\\/+$/, '')\n}\n\n/**\n * Escape the five XML predefined entities. `&` MUST be replaced first so the\n * entity ampersands it introduces are not re-escaped.\n */\nfunction escapeXml(value: string): string {\n return value\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;')\n .replace(/'/g, '&apos;')\n}\n\n/** `sitemap-<locale>.xml` (index 0) / `sitemap-<locale>-<n>.xml` (splits, n≥2). */\nfunction urlsetFilename(locale: string, index: number): string {\n return index === 0 ? `sitemap-${locale}.xml` : `sitemap-${locale}-${index + 1}.xml`\n}\n\n/**\n * A finite, ≥1 integer from a config-derived value, else `fallback`. Guards a 0 /\n * negative / fractional / NaN `maxUrlsPerFile` or `batchSize` from producing a\n * zero-length split loop.\n */\nfunction normalizePositiveInt(value: number | undefined, fallback: number): number {\n if (value === undefined || !Number.isFinite(value)) return fallback\n const floored = Math.floor(value)\n return floored >= 1 ? floored : fallback\n}\n\n/**\n * Buffer an async source into fixed-size chunks — bounds the per-batch\n * cross-locale fan-out (see module header). The final chunk may be short.\n */\nasync function* chunkAsync<T>(source: AsyncIterable<T>, size: number): AsyncGenerator<T[]> {\n let buffer: T[] = []\n for await (const item of source) {\n buffer.push(item)\n if (buffer.length >= size) {\n yield buffer\n buffer = []\n }\n }\n if (buffer.length > 0) yield buffer\n}\n","/**\n * Build-time redirect list for SSG frontends (plan/routing PR08; phase\n * `06-frontend-adapters.md` §3, finding F037 point 3).\n *\n * `getRedirects` streams the full `(from, to, status)` redirect set for one\n * locale — the manual (`toolkit_redirects`) rows PLUS the automatic historical\n * (`toolkit_paths` non-canonical) rows — so a frontend can materialize a static\n * redirect map (`_redirects` / `vercel.json` / an nginx include) at build time.\n * It is a PURE generator, not an HTTP endpoint: the frontend recipe (PR08 Task\n * 2b) maps the yielded entries into its host's adapter format.\n *\n * **Security (CLAUDE.md #1).** The output feeds a public, static build artifact,\n * so a redirect must NEVER point at content the live site would 404 — a static\n * 301 to unpublished content has no request-time fallback to catch it (unlike\n * `resolvePath`, where the target's own canonical tier re-checks). So every\n * redirect whose target is a resolved DOCUMENT (entity-kind manual + all\n * historical) is publish-gated with the SAME batched `filterPublished` primitive\n * `enumeratePaths` / `generateSitemap` use, and an unpublished target is DROPPED\n * — mirroring `resolvePath`'s tier-4 `checkPublished` gate. `url`-kind targets\n * are admin-authored external URLs (never a public write); `path`-kind targets\n * are gated on the target path currently serving canonical content, matching\n * `resolveManualRedirect`'s own path-kind branch.\n *\n * **No unbounded fan-out (CLAUDE.md \"no amplification\").** Both halves are\n * keyset-paginated on the immutable `id` PK (one index query per page), and the\n * document resolution + publish check are BATCHED — one `getCanonicalPaths` +\n * one `filterPublished` per (page × distinct entity-type group), never one query\n * per row (mirrors `enumeratePaths`'s / the sitemap's own bound). Manual redirects\n * are admin-authored (bounded volume, not content-scaled) but are still paginated\n * on principle. The only inherently per-row read is the `path`-kind existence\n * check — one bounded `limit: 1` lookup per surviving `path`-kind manual row —\n * which can't be batched (it keys on the target PATH, not an id set) and rides on\n * the same bounded admin-authored volume.\n *\n * **Precedence, mirroring `resolvePath`.** `resolvePath` resolves\n * canonical → manual → historical, and within manual a locale-specific row wins\n * over the catch-all (`locale IS NULL`) row (`lookupManualRedirect`). This list\n * reproduces that ordering: locale-specific manual rows first (claiming their\n * `from`), then catch-all manual rows (skipped where a locale-specific row\n * already claimed the path), then historical rows (skipped where ANY manual\n * redirect claimed the path — matching resolvePath's tier-3-before-tier-4\n * short-circuit, which fires even when the manual row itself resolves to nothing).\n *\n * **Not reproduced (deliberate, deps stay minimal).** (1) The homepage-collision\n * collapse (`resolvePath` sends a redirect that targets the homepage document\n * straight to `/`): a manual/historical redirect targeting the homepage instead\n * emits its pattern URL, which the live `resolvePath` then 301s to `/` — one\n * extra hop for a rare case, not a broken link, and it avoids threading a\n * `homepageReader` dep. (2) `path`-kind live multi-hop walking: `path` targets are\n * collapsed to ≤1 hop at save time (`collapsePathTarget`, phase 04 §3), so a\n * single existence lookup suffices; a rebuild re-runs this generator whenever\n * redirects change. (3) The multi-document historical collision (two docs holding\n * a historical row at the same path — findRedirectTarget's documented\n * approximate/self-healing edge, F014): this list emits at most one rule per\n * `from` (first that resolves, in id order) rather than most-recent-updated wins.\n *\n * **Leaf module.** Every cross-package dependency is injected via `deps`; this\n * module imports no `@murumets-ee/core` and no `server-only` graph. Concrete deps\n * are built from an app in `./resolve-context.ts` (`buildRedirectsListDeps`).\n */\n\nimport {\n type CanonicalPathsBatchDeps,\n getCanonicalPaths,\n type PathEnumReader,\n type PathEnumRow,\n type PathEnumWhere,\n type PublishFilter,\n} from './enumerate.js'\nimport { normalizePath } from './generate-path.js'\nimport type { RedirectTarget } from '../redirects/target.js'\n\n// ---------------------------------------------------------------------------\n// Read surface — `type` aliases (not interfaces) so the real\n// `ToolkitRedirectsClient`, typed against `WhereClause`'s template-literal index\n// signature, stays assignable without a cast (same rationale as\n// `PathEnumReader` / `index-reader.ts`'s Deviation-1).\n// ---------------------------------------------------------------------------\n\n/** The projected `toolkit_redirects` row the manual-redirect enumeration reads. */\nexport type RedirectListRow = {\n id: string\n fromPath: string\n /** BCP47 locale, or `null` for the catch-all (all-locales) row. */\n locale: string | null\n target: RedirectTarget\n status: number\n}\n\n/**\n * The (operator-carrying) where shapes the manual enumeration issues: a keyset\n * `id > cursor` plus a `locale` equality (a concrete locale, or `null` for the\n * catch-all stratum). A subset of the real client's `WhereClause`, so the real\n * `ToolkitRedirectsClient` is assignable to {@link RedirectListReader}.\n */\nexport type RedirectListWhere = {\n id?: { gt: string }\n locale?: string | null\n}\n\n/**\n * The batched keyset read surface the manual half needs over `toolkit_redirects`.\n * Construct the real client directly (`toolkitRedirectsTable.makeClient(db)`) —\n * it satisfies this type.\n */\nexport type RedirectListReader = {\n findMany(options: {\n where?: RedirectListWhere\n orderBy?: Array<{ column: 'id'; dir?: 'asc' | 'desc' }>\n limit?: number\n }): Promise<RedirectListRow[]>\n}\n\n// ---------------------------------------------------------------------------\n// Public surface\n// ---------------------------------------------------------------------------\n\n/** One emitted redirect. `301` permanent, `302` temporary (phase 05 §2 shape). */\nexport interface RedirectEntry {\n from: string\n to: string\n status: 301 | 302\n}\n\n/** Options for {@link getRedirects}. */\nexport interface RedirectsListOptions {\n /** Emit this locale's redirects only (mirrors `enumeratePaths` / `generateSitemap`). */\n locale: string\n}\n\n/** Injected dependencies for {@link getRedirects}. */\nexport interface RedirectsListDeps {\n /** Keyset reader over `toolkit_redirects` (manual redirects). */\n redirectsClient: RedirectListReader\n /**\n * Keyset reader over `toolkit_paths` — the historical (non-canonical) rows AND\n * the `path`-kind existence check. Reuses `enumeratePaths`'s exact reader shape.\n */\n pathsClient: PathEnumReader\n /** Batched forward index read for owning-document current-canonical resolution. */\n canonicalBatch: CanonicalPathsBatchDeps\n /** The SAME batched publish filter `enumeratePaths` / `generateSitemap` use. */\n filterPublished: PublishFilter\n}\n\n/** Internal tuning seam (page size). Real callers omit it. */\nexport interface RedirectsListTuning {\n /** Rows per keyset page. Defaults to {@link REDIRECTS_PAGE_SIZE}. Tests force a small value. */\n pageSize?: number\n}\n\n/**\n * Redirect-list page size — same order of magnitude as `enumeratePaths`'s\n * `ENUMERATE_PAGE_SIZE` (200). Must stay ≤ the `defineTable` `MAX_LIMIT` (1000),\n * which THROWS rather than clamps.\n */\nconst REDIRECTS_PAGE_SIZE = 200\n\n/**\n * Stream the redirect list for `opts.locale`: manual redirects (locale-specific\n * then catch-all, deduped by precedence) followed by historical redirects\n * (skipping any `from` a manual redirect already claimed). See the module header\n * for the security + fan-out + precedence guarantees.\n */\nexport async function* getRedirects(\n opts: RedirectsListOptions,\n deps: RedirectsListDeps,\n tuning: RedirectsListTuning = {},\n): AsyncGenerator<RedirectEntry> {\n const { locale } = opts\n const pageSize = tuning.pageSize ?? REDIRECTS_PAGE_SIZE\n\n /**\n * Every `from` a manual redirect (either stratum) OWNS for this locale. Serves\n * two roles: (1) a locale-specific row shadows a catch-all row at the same\n * path; (2) ANY manual redirect at a path shadows the historical tier there —\n * even when the manual row itself resolves to nothing (resolvePath tier-3\n * short-circuit). Populated for EVERY manual row seen (dropped or emitted).\n */\n const manualFrom = new Set<string>()\n\n // ── Tier 3a: locale-specific manual redirects ──────────────────────────────\n yield* manualRedirects(locale, locale, deps, pageSize, manualFrom)\n // ── Tier 3b: catch-all (locale IS NULL) manual redirects ───────────────────\n // `manualFrom` now holds every locale-specific `from`, so catch-all rows at\n // those paths are suppressed inside `manualRedirects`.\n yield* manualRedirects(locale, null, deps, pageSize, manualFrom)\n\n // ── Tier 4: historical (automatic rename) redirects ────────────────────────\n yield* historicalRedirects(locale, deps, pageSize, manualFrom)\n}\n\n// ---------------------------------------------------------------------------\n// Manual redirects\n// ---------------------------------------------------------------------------\n\n/**\n * Stream one `locale` stratum of `toolkit_redirects` (a concrete locale, or\n * `null` for the catch-all rows), keyset-paginated. Records every surviving\n * `from` in `manualFrom` (for precedence + historical shadowing) and yields the\n * resolved, publish-gated entries in id-ascending order.\n */\nasync function* manualRedirects(\n locale: string,\n whereLocale: string | null,\n deps: RedirectsListDeps,\n pageSize: number,\n manualFrom: Set<string>,\n): AsyncGenerator<RedirectEntry> {\n let cursorId: string | undefined\n for (;;) {\n const where: RedirectListWhere = { locale: whereLocale }\n if (cursorId !== undefined) where.id = { gt: cursorId }\n\n const page = await deps.redirectsClient.findMany({\n where,\n orderBy: [{ column: 'id', dir: 'asc' }],\n limit: pageSize,\n })\n if (page.length === 0) break\n\n // Drop rows whose `from` a higher-precedence manual redirect already claimed\n // (a locale-specific row shadowing a catch-all one). Record every surviving\n // `from` — even one we go on to DROP — so precedence + historical shadowing\n // hold regardless of resolution outcome (matches resolvePath's short-circuit).\n const survivors: RedirectListRow[] = []\n for (const row of page) {\n if (manualFrom.has(row.fromPath)) continue\n manualFrom.add(row.fromPath)\n survivors.push(row)\n }\n\n // Batched entity-kind resolution: group by target entity type, then ONE\n // getCanonicalPaths + ONE filterPublished per type group (never per row).\n const resolvedEntityTo = await resolveEntityTargets(survivors, locale, deps)\n\n // Emit in survivor (id) order.\n for (const row of survivors) {\n const status = toRedirectStatus(row.status)\n const target = row.target\n\n if (target.kind === 'url') {\n // Terminal external URL — admin-authored, no publish gate, no self-loop.\n yield { from: row.fromPath, to: target.url, status }\n continue\n }\n\n if (target.kind === 'entity') {\n const to = resolvedEntityTo.get(row.id)\n // Dropped when unpublished / no canonical row (matches resolvePath's\n // tier-3 `{kind:'none'}`). Skip a degenerate self-redirect too.\n if (to !== undefined && to !== row.fromPath) {\n yield { from: row.fromPath, to, status }\n }\n continue\n }\n\n // target.kind === 'path' — collapsed to ≤1 hop at save time, so one bounded\n // existence lookup suffices. Emit only when the target path currently serves\n // canonical content (matches resolveManualRedirect's path-kind branch).\n const to = normalizePath(target.path)\n if (to === row.fromPath) continue\n if (await pathServesCanonical(deps.pathsClient, locale, to)) {\n yield { from: row.fromPath, to, status }\n }\n }\n\n const lastRow = page[page.length - 1]\n if (!lastRow) break\n cursorId = lastRow.id\n if (page.length < pageSize) break\n }\n}\n\n/**\n * Resolve the entity-kind targets in a page to their published canonical path,\n * BATCHED by entity type: one `getCanonicalPaths` (forward index) + one\n * `filterPublished` (publish gate) per distinct target type — never per row\n * (mirrors the sitemap's `resolveAlternates` bucketing). Returns a\n * `redirectRowId → path` map holding only the rows that resolve AND publish.\n */\nasync function resolveEntityTargets(\n rows: readonly RedirectListRow[],\n locale: string,\n deps: RedirectsListDeps,\n): Promise<Map<string, string>> {\n const result = new Map<string, string>()\n\n // Group entity-kind rows by target entity type (bounded: routable types are\n // few + config-fixed). Capture `(redirectRowId, targetId)` while the union arm\n // is still narrowed, so no discriminant re-cast is needed downstream.\n const targetsByType = new Map<string, Array<{ rowId: string; targetId: string }>>()\n for (const row of rows) {\n if (row.target.kind !== 'entity') continue\n const pair = { rowId: row.id, targetId: row.target.id }\n const bucket = targetsByType.get(row.target.entity)\n if (bucket) bucket.push(pair)\n else targetsByType.set(row.target.entity, [pair])\n }\n\n for (const [type, targets] of targetsByType) {\n const ids = targets.map((t) => t.targetId)\n // (1) Forward index: which target ids have a canonical row in `locale`?\n const pathMap = await getCanonicalPaths(type, ids, locale, deps.canonicalBatch)\n const candidateIds = [...pathMap.keys()]\n if (candidateIds.length === 0) continue\n // (2) Publish gate: of THOSE, which are actually published in `locale`?\n const published = await deps.filterPublished(type, candidateIds, locale)\n for (const { rowId, targetId } of targets) {\n const path = pathMap.get(targetId)\n if (path !== undefined && published.has(targetId)) result.set(rowId, path)\n }\n }\n\n return result\n}\n\n/** True iff `path` currently serves a canonical document in `locale` (one bounded lookup). */\nasync function pathServesCanonical(\n pathsClient: PathEnumReader,\n locale: string,\n path: string,\n): Promise<boolean> {\n const rows = await pathsClient.findMany({\n where: { locale, path, isCanonical: true },\n limit: 1,\n })\n return rows.length > 0\n}\n\n// ---------------------------------------------------------------------------\n// Historical redirects\n// ---------------------------------------------------------------------------\n\n/**\n * Stream the historical (automatic rename) redirects for `locale`: the demoted\n * (`is_canonical = false`) `toolkit_paths` rows, each resolved to its owning\n * document's CURRENT canonical path. Keyset-paginated; per page, ONE\n * `getCanonicalPaths` + ONE `filterPublished` per entity-type group (never per\n * row). Drops rows whose document has no live published canonical variant\n * anymore (matches `findRedirectTarget`'s `null`), and any `from` a manual\n * redirect already claimed (tier-3 wins) or an already-emitted historical `from`\n * (at most one rule per `from`).\n */\nasync function* historicalRedirects(\n locale: string,\n deps: RedirectsListDeps,\n pageSize: number,\n manualFrom: ReadonlySet<string>,\n): AsyncGenerator<RedirectEntry> {\n /** Historical `from`s already emitted — dedup the documented multi-doc collision. */\n const emittedFrom = new Set<string>()\n let cursorId: string | undefined\n for (;;) {\n const where: PathEnumWhere = { locale, isCanonical: false }\n if (cursorId !== undefined) where.id = { gt: cursorId }\n\n const page = await deps.pathsClient.findMany({\n where,\n orderBy: [{ column: 'id', dir: 'asc' }],\n limit: pageSize,\n })\n if (page.length === 0) break\n\n // Group this page's rows by entity type, then ONE batched canonical lookup +\n // ONE publish check per group. `entityId → current published canonical path`.\n const byType = new Map<string, PathEnumRow[]>()\n for (const row of page) {\n const bucket = byType.get(row.entityType)\n if (bucket) bucket.push(row)\n else byType.set(row.entityType, [row])\n }\n\n const currentPath = new Map<string, string>()\n for (const [type, rows] of byType) {\n const ids = rows.map((r) => r.entityId)\n const pathMap = await getCanonicalPaths(type, ids, locale, deps.canonicalBatch)\n const candidateIds = [...pathMap.keys()]\n if (candidateIds.length === 0) continue\n const published = await deps.filterPublished(type, candidateIds, locale)\n for (const [id, path] of pathMap) {\n if (published.has(id)) currentPath.set(id, path)\n }\n }\n\n for (const row of page) {\n // A manual redirect at this path wins (tier 3 before tier 4).\n if (manualFrom.has(row.path)) continue\n // Already emitted a historical rule at this `from` (multi-doc collision).\n if (emittedFrom.has(row.path)) continue\n const to = currentPath.get(row.entityId)\n if (to === undefined) continue // no live published canonical → dropped\n if (to === row.path) continue // self-redirect (from == to) → skip\n emittedFrom.add(row.path)\n yield { from: row.path, to, status: 301 }\n }\n\n const lastRow = page[page.length - 1]\n if (!lastRow) break\n cursorId = lastRow.id\n if (page.length < pageSize) break\n }\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Narrow the DB `status` integer (validated `301 | 302` at write time) to the\n * result union. Defaults to `301` for any unexpected value — never a raw number\n * leaking into the typed entry (mirrors `resolve.ts`'s `toRedirectStatus`).\n */\nfunction toRedirectStatus(status: number): 301 | 302 {\n return status === 302 ? 302 : 301\n}\n"],"mappings":"0RA4IA,MAAa,EAA4B,IAG5B,EAAyB,cAyBtC,eAAuB,EACrB,EACA,EACA,EAAwB,CAAC,EACI,CAC7B,IAAM,EAAU,EAAqB,EAAK,eAAgB,CAAyB,EAC7E,EAAY,EAAqB,EAAO,UAAW,GAA6B,EAChF,EAAO,EAAmB,EAAK,OAAO,EAGtC,EAA8D,CAAC,EAErE,IAAK,IAAM,KAAU,EAAK,QAAS,CACjC,IAAI,EAAmB,CAAC,EACpB,EAAkC,KAClC,EAAY,EAGV,MAAkC,CACtC,GAAI,EAAO,SAAW,EAAG,OAAO,KAChC,IAAM,EAAW,EAAe,EAAQ,CAAS,EAC3C,GAAW,GAAsB,IAAI,KAAK,CAAG,YAAY,EACzD,EAAoB,CAAE,KAAM,SAAU,WAAU,IAAK,EAAY,CAAM,CAAE,EAK/E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EAAU,IAAI,CAAE,GAAG,EAAY,IAAI,EAAI,CAAI,CAEnD,CAEA,IAAK,IAAM,KAAO,EAAM,CAItB,GAFI,EAAW,IAAI,EAAI,IAAI,GAEvB,EAAY,IAAI,EAAI,IAAI,EAAG,SAC/B,IAAM,EAAK,EAAY,IAAI,EAAI,QAAQ,EACnC,IAAO,IAAA,IACP,IAAO,EAAI,OACf,EAAY,IAAI,EAAI,IAAI,EACxB,KAAM,CAAE,KAAM,EAAI,KAAM,KAAI,OAAQ,GAAI,EAC1C,CAEA,IAAM,EAAU,EAAK,EAAK,OAAS,GAGnC,GAFI,CAAC,IACL,EAAW,EAAQ,GACf,EAAK,OAAS,GAAU,KAC9B,CACF,CAWA,SAAS,EAAiB,EAA2B,CACnD,OAAO,IAAW,IAAM,IAAM,GAChC"}
1
+ {"version":3,"file":"resolve.mjs","names":[],"sources":["../src/paths/sitemap.ts","../src/paths/site-sitemap.ts","../src/paths/redirects-list.ts"],"sourcesContent":["/**\n * Sitemap generation for the routed content surface (plan/routing PR07; phase\n * `05-resolution-and-enumeration-api.md` §4).\n *\n * `generateSitemap` streams the standard-protocol sitemap document set for the\n * configured locales: one `<urlset>` per locale (split into numbered files at\n * {@link SitemapOptions.maxUrlsPerFile}), plus a `<sitemapindex>` when the run\n * produced more than one file. Each `<url>` carries a `<lastmod>` (from the\n * enumerated `updatedAt`) and the full `xhtml:link` hreflang-alternates set —\n * including an `x-default` pointing at the default-locale URL. It is a PURE\n * generator, NOT an HTTP endpoint: the frontend recipe (PR08) mounts it in a\n * route handler; this module only produces the documents.\n *\n * **Security (CLAUDE.md #1).** The output feeds a public build artifact, so it\n * must NEVER leak an unpublished / trashed document. Two independent publish\n * gates apply:\n * 1. The primary rows come from {@link enumeratePaths}, which publish-filters\n * each page against the entity (unpublished/trashed dropped) for the\n * sitemap's OWN locale.\n * 2. The cross-locale hreflang alternates come from {@link getCanonicalPaths},\n * which does NOT publish-filter (it is a display-only forward index read).\n * So this module ADDITIONALLY runs the same batched `filterPublished` over\n * every candidate other-locale alternate before linking it — an\n * unpublished-in-that-locale document is never emitted as an alternate.\n *\n * **No unbounded fan-out (CLAUDE.md \"no amplification\").** The cross-locale\n * alternate lookup is BATCHED exactly like `enumeratePaths`'s own publish check:\n * per {@link SITEMAP_ALTERNATES_BATCH_SIZE}-sized chunk of enumerated rows, the\n * work is ONE `getCanonicalPaths` + ONE `filterPublished` per (entity-type\n * group × other locale) — bounded by (batch size × distinct routable types ×\n * locale count), NEVER one query per document. `getAlternates` (the per-document\n * N-locale function) is deliberately NOT used here — calling it per enumerated\n * row would be the O(rows × locales) amplification this bound forbids.\n *\n * **`noIndex` exclusion (PR 11's `seoMeta()`).** `SitemapDeps.filterNoIndex` is\n * an OPTIONAL batched dep, same shape as `filterPublished` (a `PublishFilter`)\n * but semantics-inverted: it returns the subset of ids that ARE `noIndex` in\n * the given locale. It lives on `deps`, not `opts`, because — like\n * `filterPublished` — a real implementation needs a DB read, and `noIndex` is\n * `translatable: true`, so the SAME callback must be invoked once per\n * (locale, entity-type group, batch) to see the right per-locale value; a\n * per-entry (locale-blind) predicate could not express this correctly. Omitted\n * → nothing excluded (current default). See `excludeNoIndexed`.\n *\n * **Leaf module.** Every cross-package dependency is injected via `deps`\n * ({@link SitemapDeps}); this module imports no `@murumets-ee/core` and no\n * `server-only` graph. Concrete deps are built from an app in\n * `./resolve-context.ts` (`buildSitemapDeps`).\n */\n\nimport { mapBounded } from './apply-path.js'\nimport {\n type CanonicalPathsBatchDeps,\n enumeratePaths,\n type EnumeratePathsDeps,\n type EnumeratePathsTuning,\n getCanonicalPaths,\n type PathEntry,\n type PublishFilter,\n} from './enumerate.js'\n\n// ---------------------------------------------------------------------------\n// Public surface\n// ---------------------------------------------------------------------------\n\n/** Options for {@link generateSitemap}. */\nexport interface SitemapOptions {\n /** The locales to emit a `<urlset>` for (configured content locales). */\n locales: readonly string[]\n /**\n * The default locale — its URL is the `x-default` hreflang target. Explicit\n * (NOT inferred from `locales` order) so callers stay unambiguous.\n */\n defaultLocale: string\n /** Absolute site origin, e.g. `https://example.com` (trailing slash tolerated). */\n baseUrl: string\n /**\n * Per-locale URL prefix rule (e.g. `(l) => l === 'en' ? '' : '/' + l`). The\n * frontend owns the locale-prefix convention (D002); omitted → no prefix.\n */\n prefix?: (locale: string) => string\n /**\n * Max `<url>` entries per file before splitting (sitemap protocol caps at\n * 50 000). Defaults to {@link DEFAULT_MAX_URLS_PER_FILE}.\n */\n maxUrlsPerFile?: number\n}\n\n/** Injected dependencies for {@link generateSitemap}. */\nexport interface SitemapDeps {\n /**\n * Deps for {@link enumeratePaths} — the `toolkit_paths` reader plus the\n * batched `filterPublished`. `filterPublished` is REUSED for the cross-locale\n * alternate publish gate (same batched shape), so no second publish surface is\n * needed.\n */\n enumerate: EnumeratePathsDeps\n /**\n * Deps for {@link getCanonicalPaths} — the batched cross-locale forward index\n * read (NO publish filter; this module applies `enumerate.filterPublished` on\n * top).\n */\n canonicalBatch: CanonicalPathsBatchDeps\n /**\n * Optional: batched `noIndex` check, same shape as `filterPublished` but\n * semantics-inverted — returns the subset of `entityIds` that ARE `noIndex`\n * in `locale` (PR 11's `seoMeta()`). Called at most once per (entity-type\n * group, batch), never once per entry — see `excludeNoIndexed`. Omitted →\n * nothing excluded (current default).\n */\n filterNoIndex?: PublishFilter\n}\n\n/** Internal tuning seam (batch size / enumerate page size). Real callers omit it. */\nexport interface SitemapTuning {\n /**\n * Enumerated rows per cross-locale alternate batch. Defaults to\n * {@link SITEMAP_ALTERNATES_BATCH_SIZE}. Tests force a small value to span\n * multiple batches. Bounds the per-batch fan-out (see module header).\n */\n batchSize?: number\n /** Passed through to {@link enumeratePaths} for its own paging/publish tuning. */\n enumerate?: EnumeratePathsTuning\n}\n\n/** One emitted sitemap document. */\nexport interface SitemapFile {\n /** `'urlset'` for a per-locale URL set, `'index'` for the sitemap index. */\n kind: 'urlset' | 'index'\n /**\n * Suggested filename served at `${baseUrl}/${filename}`. Per-locale urlsets are\n * `sitemap-<locale>.xml` (first) / `sitemap-<locale>-<n>.xml` (splits, n≥2);\n * the index is {@link SITEMAP_INDEX_FILENAME}.\n */\n filename: string\n /** The complete, well-formed XML document text (trailing newline included). */\n xml: string\n}\n\n/** Default `<url>` cap per file — under the sitemap protocol's 50 000 hard limit. */\nexport const DEFAULT_MAX_URLS_PER_FILE = 40_000\n\n/** Filename of the emitted sitemap index (referenced by the mounting route). */\nexport const SITEMAP_INDEX_FILENAME = 'sitemap.xml'\n\n/**\n * Enumerated rows per cross-locale alternate batch. Aligned with\n * `enumeratePaths`'s own page size so a batch is ~one enumeration page; the\n * exact value only affects HOW MANY batched lookups run, never their per-batch\n * bound (see module header). Never per-row.\n */\nconst SITEMAP_ALTERNATES_BATCH_SIZE = 200\n\n// ---------------------------------------------------------------------------\n// Generator\n// ---------------------------------------------------------------------------\n\n/** One resolved hreflang alternate (a published, canonical per-locale URL). */\ninterface Alternate {\n locale: string\n path: string\n}\n\n/**\n * Stream the sitemap document set for `opts.locales`. See the module header for\n * the security + fan-out guarantees. Yields each `<urlset>` file as it fills,\n * then a `<sitemapindex>` LAST iff more than one file was produced.\n */\nexport async function* generateSitemap(\n opts: SitemapOptions,\n deps: SitemapDeps,\n tuning: SitemapTuning = {},\n): AsyncGenerator<SitemapFile> {\n const maxUrls = normalizePositiveInt(opts.maxUrlsPerFile, DEFAULT_MAX_URLS_PER_FILE)\n const batchSize = normalizePositiveInt(tuning.batchSize, SITEMAP_ALTERNATES_BATCH_SIZE)\n const base = stripTrailingSlash(opts.baseUrl)\n\n /** (filename, lastmod) of every urlset file produced — feeds the index. */\n const producedFiles: Array<{ filename: string; lastmod: string }> = []\n\n for (const locale of opts.locales) {\n let buffer: string[] = []\n let bufferMaxUpdatedAt: Date | null = null\n let fileIndex = 0\n\n /** Flush the current buffer as a numbered urlset file (or return null if empty). */\n const flush = (): SitemapFile | null => {\n if (buffer.length === 0) return null\n const filename = urlsetFilename(locale, fileIndex)\n const lastmod = (bufferMaxUpdatedAt ?? new Date()).toISOString()\n const file: SitemapFile = { kind: 'urlset', filename, xml: buildUrlset(buffer) }\n producedFiles.push({ filename, lastmod })\n buffer = []\n bufferMaxUpdatedAt = null\n fileIndex += 1\n return file\n }\n\n const source = enumeratePaths({ locale }, deps.enumerate, tuning.enumerate)\n for await (const batch of chunkAsync(source, batchSize)) {\n // Exclude noIndex rows FIRST so they're never fetched cross-locale.\n const kept = await excludeNoIndexed(batch, locale, deps)\n if (kept.length === 0) continue\n\n // ONE batched cross-locale lookup per (entity-type group × other locale).\n const alternatesByEntry = await resolveAlternates(kept, locale, opts, deps)\n\n for (const entry of kept) {\n const alternates = alternatesByEntry.get(entry.id) ?? [{ locale, path: entry.path }]\n buffer.push(buildUrlEntry(entry, locale, alternates, opts, base))\n if (bufferMaxUpdatedAt === null || entry.updatedAt > bufferMaxUpdatedAt) {\n bufferMaxUpdatedAt = entry.updatedAt\n }\n if (buffer.length >= maxUrls) {\n const full = flush()\n if (full) yield full\n }\n }\n }\n\n const tail = flush()\n if (tail) yield tail\n }\n\n // The index is only meaningful when it references more than one file.\n if (producedFiles.length > 1) {\n yield { kind: 'index', filename: SITEMAP_INDEX_FILENAME, xml: buildIndex(producedFiles, base) }\n }\n}\n\n/**\n * Resolve the full hreflang-alternate set for a batch of same-locale entries.\n * The current locale is always a self-alternate (`enumeratePaths` already proved\n * it published + canonical there). Every OTHER locale is resolved with ONE\n * batched `getCanonicalPaths` (forward index) + ONE batched `filterPublished`\n * (publish gate) per (entity-type group × locale) — never per row.\n */\nasync function resolveAlternates(\n entries: readonly PathEntry[],\n currentLocale: string,\n opts: SitemapOptions,\n deps: SitemapDeps,\n): Promise<Map<string, Alternate[]>> {\n const result = new Map<string, Alternate[]>()\n // Seed each entry with its self-alternate (its own published canonical URL).\n for (const entry of entries) result.set(entry.id, [{ locale: currentLocale, path: entry.path }])\n\n const otherLocales = opts.locales.filter((l) => l !== currentLocale)\n if (otherLocales.length === 0) return result\n\n // Group the batch's ids by entity type (bounded: routable types are few + config-fixed).\n const idsByType = new Map<string, string[]>()\n for (const entry of entries) {\n const bucket = idsByType.get(entry.entityType)\n if (bucket) bucket.push(entry.id)\n else idsByType.set(entry.entityType, [entry.id])\n }\n\n for (const otherLocale of otherLocales) {\n for (const [type, ids] of idsByType) {\n // (1) Forward index: which of these ids have a canonical row in otherLocale?\n const pathMap = await getCanonicalPaths(type, ids, otherLocale, deps.canonicalBatch)\n if (pathMap.size === 0) continue\n // (2) Publish gate: of THOSE, which are actually published in otherLocale?\n // getCanonicalPaths does NOT publish-filter — this is the required\n // no-unpublished-leak step, batched (never per-row).\n const candidateIds = [...pathMap.keys()]\n const publishedIds = await deps.enumerate.filterPublished(type, candidateIds, otherLocale)\n // (3) noIndex gate — same shape, other-locale value. Without this, a\n // document marked noIndex in `otherLocale` (excluded from ITS OWN\n // urlset by `excludeNoIndexed` below) still gets published as an\n // hreflang alternate on every OTHER locale's urlset, publishing the\n // exact URL the editor asked to hide.\n const noIndexIds =\n deps.filterNoIndex !== undefined\n ? await deps.filterNoIndex(type, candidateIds, otherLocale)\n : undefined\n for (const [id, path] of pathMap) {\n if (!publishedIds.has(id)) continue\n if (noIndexIds?.has(id)) continue\n const alternates = result.get(id)\n if (alternates) alternates.push({ locale: otherLocale, path })\n }\n }\n }\n\n return result\n}\n\n/**\n * Peak concurrent `noIndex`-check groups per batch — mirrors `enumerate.ts`'s\n * `PUBLISH_CHECK_CONCURRENCY` bound (CLAUDE.md \"no amplification\"): a batch\n * holds a handful of distinct entity types at most, so this is rarely reached\n * — it exists so the fan-out is EXPLICITLY capped, never unbounded.\n */\nconst NOINDEX_CHECK_CONCURRENCY = 5\n\n/**\n * Keep the entries `deps.filterNoIndex` does NOT report as `noIndex` in\n * `locale` (all of them when the dep is omitted — current default: nothing\n * excluded). Groups the batch by entity type (mirrors `enumeratePaths`'s own\n * `byType` grouping) and calls `deps.filterNoIndex` ONCE per (entity-type\n * group, batch) — never once per entry — bounded to\n * {@link NOINDEX_CHECK_CONCURRENCY} concurrent groups.\n *\n * FAIL-CLOSED, deliberately, unlike `loadMetaPanelData`'s fail-open contract\n * (`packages/admin-ui/src/server/meta-panel-data.ts`): `mapBounded` does not\n * catch per-item errors (see its own doc comment in `apply-path.ts`), so a\n * `deps.filterNoIndex` rejection aborts the whole `generateSitemap` run rather\n * than silently including a possibly-noIndexed row. A build-time sitemap\n * generator failing loudly is preferable to a build succeeding with a leaked\n * noIndex URL.\n */\nasync function excludeNoIndexed(\n entries: readonly PathEntry[],\n locale: string,\n deps: SitemapDeps,\n): Promise<PathEntry[]> {\n const filterNoIndex = deps.filterNoIndex\n if (filterNoIndex === undefined) return [...entries]\n\n // Group this batch's ids by entity type (bounded: routable types are few).\n const idsByType = new Map<string, string[]>()\n for (const entry of entries) {\n const bucket = idsByType.get(entry.entityType)\n if (bucket) bucket.push(entry.id)\n else idsByType.set(entry.entityType, [entry.id])\n }\n\n const noIndexedByType = new Map<string, ReadonlySet<string>>()\n await mapBounded([...idsByType.entries()], NOINDEX_CHECK_CONCURRENCY, async ([type, ids]) => {\n noIndexedByType.set(type, await filterNoIndex(type, ids, locale))\n })\n\n return entries.filter((entry) => !noIndexedByType.get(entry.entityType)?.has(entry.id))\n}\n\n// ---------------------------------------------------------------------------\n// XML builders\n// ---------------------------------------------------------------------------\n\nconst URLSET_HEADER =\n '<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n' +\n '<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" ' +\n 'xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">'\n\nconst INDEX_HEADER =\n '<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n' +\n '<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">'\n\n/** Wrap the buffered `<url>` blocks in a `<urlset>` envelope. */\nfunction buildUrlset(urlBlocks: readonly string[]): string {\n return `${URLSET_HEADER}\\n${urlBlocks.join('\\n')}\\n</urlset>\\n`\n}\n\n/** Build one `<url>` block: `<loc>`, `<lastmod>`, one `xhtml:link` per alternate + x-default. */\nfunction buildUrlEntry(\n entry: PathEntry,\n currentLocale: string,\n alternates: readonly Alternate[],\n opts: SitemapOptions,\n base: string,\n): string {\n const loc = absoluteUrl(base, opts.prefix, currentLocale, entry.path)\n const links = alternates.map(\n (alt) => ` ${hreflangLink(alt.locale, absoluteUrl(base, opts.prefix, alt.locale, alt.path))}`,\n )\n // x-default → the default-locale URL, when the document is published there.\n const defaultAlt = alternates.find((alt) => alt.locale === opts.defaultLocale)\n if (defaultAlt) {\n links.push(\n ` ${hreflangLink('x-default', absoluteUrl(base, opts.prefix, defaultAlt.locale, defaultAlt.path))}`,\n )\n }\n return (\n ' <url>\\n' +\n ` <loc>${escapeXml(loc)}</loc>\\n` +\n ` <lastmod>${entry.updatedAt.toISOString()}</lastmod>\\n` +\n `${links.join('\\n')}\\n` +\n ' </url>'\n )\n}\n\n/** Build the `<sitemapindex>` referencing every produced urlset file. */\nfunction buildIndex(files: ReadonlyArray<{ filename: string; lastmod: string }>, base: string): string {\n const entries = files.map(\n (f) =>\n ' <sitemap>\\n' +\n ` <loc>${escapeXml(`${base}/${f.filename}`)}</loc>\\n` +\n ` <lastmod>${f.lastmod}</lastmod>\\n` +\n ' </sitemap>',\n )\n return `${INDEX_HEADER}\\n${entries.join('\\n')}\\n</sitemapindex>\\n`\n}\n\n/** One `<xhtml:link rel=\"alternate\" hreflang=... href=.../>` tag (both values escaped). */\nfunction hreflangLink(hreflang: string, href: string): string {\n return `<xhtml:link rel=\"alternate\" hreflang=\"${escapeXml(hreflang)}\" href=\"${escapeXml(href)}\"/>`\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\n/** `baseUrl` + optional `prefix(locale)` + `path` — the absolute, un-escaped URL. */\nfunction absoluteUrl(\n base: string,\n prefix: SitemapOptions['prefix'],\n locale: string,\n path: string,\n): string {\n return `${base}${prefix ? prefix(locale) : ''}${path}`\n}\n\n/** Strip any trailing slash(es) so `base + '/' + file` / `base + path` never doubles up. */\nfunction stripTrailingSlash(url: string): string {\n return url.replace(/\\/+$/, '')\n}\n\n/**\n * Escape the five XML predefined entities. `&` MUST be replaced first so the\n * entity ampersands it introduces are not re-escaped.\n */\nfunction escapeXml(value: string): string {\n return value\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;')\n .replace(/'/g, '&apos;')\n}\n\n/** `sitemap-<locale>.xml` (index 0) / `sitemap-<locale>-<n>.xml` (splits, n≥2). */\nfunction urlsetFilename(locale: string, index: number): string {\n return index === 0 ? `sitemap-${locale}.xml` : `sitemap-${locale}-${index + 1}.xml`\n}\n\n/**\n * A finite, ≥1 integer from a config-derived value, else `fallback`. Guards a 0 /\n * negative / fractional / NaN `maxUrlsPerFile` or `batchSize` from producing a\n * zero-length split loop.\n */\nfunction normalizePositiveInt(value: number | undefined, fallback: number): number {\n if (value === undefined || !Number.isFinite(value)) return fallback\n const floored = Math.floor(value)\n return floored >= 1 ? floored : fallback\n}\n\n/**\n * Buffer an async source into fixed-size chunks — bounds the per-batch\n * cross-locale fan-out (see module header). The final chunk may be short.\n */\nasync function* chunkAsync<T>(source: AsyncIterable<T>, size: number): AsyncGenerator<T[]> {\n let buffer: T[] = []\n for await (const item of source) {\n buffer.push(item)\n if (buffer.length >= size) {\n yield buffer\n buffer = []\n }\n }\n if (buffer.length > 0) yield buffer\n}\n","/**\n * One site's sitemap (plan `multisite` phase 03) — `generateSitemap` bound to a\n * site: only that site's paths (the deps are pinned to it, so the path index,\n * the publish gate and the noIndex check all read that one site), under that\n * site's first public origin, in the locales that site serves.\n *\n * There is deliberately no \"every site\" variant: a sitemap is per site, a\n * caller that wants several asks once per site (off the request path — C5).\n */\n\nimport { readSiteRecord, type ToolkitApp } from '@murumets-ee/core'\nimport { enabledLocaleCodes, resolveSiteI18n } from '../locale-registry.js'\nimport { buildSitemapDeps } from './resolve-context.js'\nimport { generateSitemap, type SitemapFile, type SitemapTuning } from './sitemap.js'\n\n/** Options for {@link generateSiteSitemap} — everything else comes from the site record. */\nexport interface SiteSitemapOptions {\n /** Per-locale URL prefix rule — the frontend owns it (routing D002). Omitted → none. */\n prefix?: (locale: string) => string\n /** Max `<url>` entries per file (see `generateSitemap`). */\n maxUrlsPerFile?: number\n}\n\n/**\n * Stream `site`'s sitemap document set. Throws when the site does not exist or\n * declares no public origin (a sitemap of relative URLs is not a sitemap).\n */\nexport async function* generateSiteSitemap(\n app: ToolkitApp,\n site: string,\n options: SiteSitemapOptions = {},\n tuning: SitemapTuning = {},\n): AsyncGenerator<SitemapFile> {\n const record = await readSiteRecord(app, site)\n if (!record) throw new Error(`There is no site '${site}'`)\n const origin = record.origins[0]\n if (origin === undefined) {\n throw new Error(`Site '${site}' declares no public origin — its sitemap has no URLs to give`)\n }\n const { entries, i18n } = await resolveSiteI18n(app, { site })\n yield* generateSitemap(\n {\n locales: enabledLocaleCodes(entries),\n defaultLocale: i18n.defaultLocale,\n baseUrl: origin,\n ...(options.prefix !== undefined && { prefix: options.prefix }),\n ...(options.maxUrlsPerFile !== undefined && { maxUrlsPerFile: options.maxUrlsPerFile }),\n },\n buildSitemapDeps(app, { site }),\n tuning,\n )\n}\n","/**\n * Build-time redirect list for SSG frontends (plan/routing PR08; phase\n * `06-frontend-adapters.md` §3, finding F037 point 3).\n *\n * `getRedirects` streams the full `(from, to, status)` redirect set for one\n * locale — the manual (`toolkit_redirects`) rows PLUS the automatic historical\n * (`toolkit_paths` non-canonical) rows — so a frontend can materialize a static\n * redirect map (`_redirects` / `vercel.json` / an nginx include) at build time.\n * It is a PURE generator, not an HTTP endpoint: the frontend recipe (PR08 Task\n * 2b) maps the yielded entries into its host's adapter format.\n *\n * **Security (CLAUDE.md #1).** The output feeds a public, static build artifact,\n * so a redirect must NEVER point at content the live site would 404 — a static\n * 301 to unpublished content has no request-time fallback to catch it (unlike\n * `resolvePath`, where the target's own canonical tier re-checks). So every\n * redirect whose target is a resolved DOCUMENT (entity-kind manual + all\n * historical) is publish-gated with the SAME batched `filterPublished` primitive\n * `enumeratePaths` / `generateSitemap` use, and an unpublished target is DROPPED\n * — mirroring `resolvePath`'s tier-4 `checkPublished` gate. `url`-kind targets\n * are admin-authored external URLs (never a public write); `path`-kind targets\n * are gated on the target path currently serving canonical content, matching\n * `resolveManualRedirect`'s own path-kind branch.\n *\n * **No unbounded fan-out (CLAUDE.md \"no amplification\").** Both halves are\n * keyset-paginated on the immutable `id` PK (one index query per page), and the\n * document resolution + publish check are BATCHED — one `getCanonicalPaths` +\n * one `filterPublished` per (page × distinct entity-type group), never one query\n * per row (mirrors `enumeratePaths`'s / the sitemap's own bound). Manual redirects\n * are admin-authored (bounded volume, not content-scaled) but are still paginated\n * on principle. The only inherently per-row read is the `path`-kind existence\n * check — one bounded `limit: 1` lookup per surviving `path`-kind manual row —\n * which can't be batched (it keys on the target PATH, not an id set) and rides on\n * the same bounded admin-authored volume.\n *\n * **Precedence, mirroring `resolvePath`.** `resolvePath` resolves\n * canonical → manual → historical, and within manual a locale-specific row wins\n * over the catch-all (`locale IS NULL`) row (`lookupManualRedirect`). This list\n * reproduces that ordering: locale-specific manual rows first (claiming their\n * `from`), then catch-all manual rows (skipped where a locale-specific row\n * already claimed the path), then historical rows (skipped where ANY manual\n * redirect claimed the path — matching resolvePath's tier-3-before-tier-4\n * short-circuit, which fires even when the manual row itself resolves to nothing).\n *\n * **Not reproduced (deliberate, deps stay minimal).** (1) The homepage-collision\n * collapse (`resolvePath` sends a redirect that targets the homepage document\n * straight to `/`): a manual/historical redirect targeting the homepage instead\n * emits its pattern URL, which the live `resolvePath` then 301s to `/` — one\n * extra hop for a rare case, not a broken link, and it avoids threading a\n * `homepageReader` dep. (2) `path`-kind live multi-hop walking: `path` targets are\n * collapsed to ≤1 hop at save time (`collapsePathTarget`, phase 04 §3), so a\n * single existence lookup suffices; a rebuild re-runs this generator whenever\n * redirects change. (3) The multi-document historical collision (two docs holding\n * a historical row at the same path — findRedirectTarget's documented\n * approximate/self-healing edge, F014): this list emits at most one rule per\n * `from` (first that resolves, in id order) rather than most-recent-updated wins.\n *\n * **Leaf module.** Every cross-package dependency is injected via `deps`; this\n * module imports no `@murumets-ee/core` and no `server-only` graph. Concrete deps\n * are built from an app in `./resolve-context.ts` (`buildRedirectsListDeps`).\n */\n\nimport {\n type CanonicalPathsBatchDeps,\n getCanonicalPaths,\n type PathEnumReader,\n type PathEnumRow,\n type PathEnumWhere,\n type PublishFilter,\n} from './enumerate.js'\nimport { normalizePath } from './generate-path.js'\nimport type { RedirectTarget } from '../redirects/target.js'\n\n// ---------------------------------------------------------------------------\n// Read surface — `type` aliases (not interfaces) so the real\n// `ToolkitRedirectsClient`, typed against `WhereClause`'s template-literal index\n// signature, stays assignable without a cast (same rationale as\n// `PathEnumReader` / `index-reader.ts`'s Deviation-1).\n// ---------------------------------------------------------------------------\n\n/** The projected `toolkit_redirects` row the manual-redirect enumeration reads. */\nexport type RedirectListRow = {\n id: string\n fromPath: string\n /** BCP47 locale, or `null` for the catch-all (all-locales) row. */\n locale: string | null\n target: RedirectTarget\n status: number\n}\n\n/**\n * The (operator-carrying) where shapes the manual enumeration issues: a keyset\n * `id > cursor` plus a `locale` equality (a concrete locale, or `null` for the\n * catch-all stratum). A subset of the real client's `WhereClause`, so the real\n * `ToolkitRedirectsClient` is assignable to {@link RedirectListReader}.\n */\nexport type RedirectListWhere = {\n id?: { gt: string }\n locale?: string | null\n}\n\n/**\n * The batched keyset read surface the manual half needs over `toolkit_redirects`.\n * Construct the real client directly (`toolkitRedirectsTable.makeClient(db)`) —\n * it satisfies this type.\n */\nexport type RedirectListReader = {\n findMany(options: {\n where?: RedirectListWhere\n orderBy?: Array<{ column: 'id'; dir?: 'asc' | 'desc' }>\n limit?: number\n }): Promise<RedirectListRow[]>\n}\n\n// ---------------------------------------------------------------------------\n// Public surface\n// ---------------------------------------------------------------------------\n\n/** One emitted redirect. `301` permanent, `302` temporary (phase 05 §2 shape). */\nexport interface RedirectEntry {\n from: string\n to: string\n status: 301 | 302\n}\n\n/** Options for {@link getRedirects}. */\nexport interface RedirectsListOptions {\n /** Emit this locale's redirects only (mirrors `enumeratePaths` / `generateSitemap`). */\n locale: string\n}\n\n/** Injected dependencies for {@link getRedirects}. */\nexport interface RedirectsListDeps {\n /** Keyset reader over `toolkit_redirects` (manual redirects). */\n redirectsClient: RedirectListReader\n /**\n * Keyset reader over `toolkit_paths` — the historical (non-canonical) rows AND\n * the `path`-kind existence check. Reuses `enumeratePaths`'s exact reader shape.\n */\n pathsClient: PathEnumReader\n /** Batched forward index read for owning-document current-canonical resolution. */\n canonicalBatch: CanonicalPathsBatchDeps\n /** The SAME batched publish filter `enumeratePaths` / `generateSitemap` use. */\n filterPublished: PublishFilter\n}\n\n/** Internal tuning seam (page size). Real callers omit it. */\nexport interface RedirectsListTuning {\n /** Rows per keyset page. Defaults to {@link REDIRECTS_PAGE_SIZE}. Tests force a small value. */\n pageSize?: number\n}\n\n/**\n * Redirect-list page size — same order of magnitude as `enumeratePaths`'s\n * `ENUMERATE_PAGE_SIZE` (200). Must stay ≤ the `defineTable` `MAX_LIMIT` (1000),\n * which THROWS rather than clamps.\n */\nconst REDIRECTS_PAGE_SIZE = 200\n\n/**\n * Stream the redirect list for `opts.locale`: manual redirects (locale-specific\n * then catch-all, deduped by precedence) followed by historical redirects\n * (skipping any `from` a manual redirect already claimed). See the module header\n * for the security + fan-out + precedence guarantees.\n */\nexport async function* getRedirects(\n opts: RedirectsListOptions,\n deps: RedirectsListDeps,\n tuning: RedirectsListTuning = {},\n): AsyncGenerator<RedirectEntry> {\n const { locale } = opts\n const pageSize = tuning.pageSize ?? REDIRECTS_PAGE_SIZE\n\n /**\n * Every `from` a manual redirect (either stratum) OWNS for this locale. Serves\n * two roles: (1) a locale-specific row shadows a catch-all row at the same\n * path; (2) ANY manual redirect at a path shadows the historical tier there —\n * even when the manual row itself resolves to nothing (resolvePath tier-3\n * short-circuit). Populated for EVERY manual row seen (dropped or emitted).\n */\n const manualFrom = new Set<string>()\n\n // ── Tier 3a: locale-specific manual redirects ──────────────────────────────\n yield* manualRedirects(locale, locale, deps, pageSize, manualFrom)\n // ── Tier 3b: catch-all (locale IS NULL) manual redirects ───────────────────\n // `manualFrom` now holds every locale-specific `from`, so catch-all rows at\n // those paths are suppressed inside `manualRedirects`.\n yield* manualRedirects(locale, null, deps, pageSize, manualFrom)\n\n // ── Tier 4: historical (automatic rename) redirects ────────────────────────\n yield* historicalRedirects(locale, deps, pageSize, manualFrom)\n}\n\n// ---------------------------------------------------------------------------\n// Manual redirects\n// ---------------------------------------------------------------------------\n\n/**\n * Stream one `locale` stratum of `toolkit_redirects` (a concrete locale, or\n * `null` for the catch-all rows), keyset-paginated. Records every surviving\n * `from` in `manualFrom` (for precedence + historical shadowing) and yields the\n * resolved, publish-gated entries in id-ascending order.\n */\nasync function* manualRedirects(\n locale: string,\n whereLocale: string | null,\n deps: RedirectsListDeps,\n pageSize: number,\n manualFrom: Set<string>,\n): AsyncGenerator<RedirectEntry> {\n let cursorId: string | undefined\n for (;;) {\n const where: RedirectListWhere = { locale: whereLocale }\n if (cursorId !== undefined) where.id = { gt: cursorId }\n\n const page = await deps.redirectsClient.findMany({\n where,\n orderBy: [{ column: 'id', dir: 'asc' }],\n limit: pageSize,\n })\n if (page.length === 0) break\n\n // Drop rows whose `from` a higher-precedence manual redirect already claimed\n // (a locale-specific row shadowing a catch-all one). Record every surviving\n // `from` — even one we go on to DROP — so precedence + historical shadowing\n // hold regardless of resolution outcome (matches resolvePath's short-circuit).\n const survivors: RedirectListRow[] = []\n for (const row of page) {\n if (manualFrom.has(row.fromPath)) continue\n manualFrom.add(row.fromPath)\n survivors.push(row)\n }\n\n // Batched entity-kind resolution: group by target entity type, then ONE\n // getCanonicalPaths + ONE filterPublished per type group (never per row).\n const resolvedEntityTo = await resolveEntityTargets(survivors, locale, deps)\n\n // Emit in survivor (id) order.\n for (const row of survivors) {\n const status = toRedirectStatus(row.status)\n const target = row.target\n\n if (target.kind === 'url') {\n // Terminal external URL — admin-authored, no publish gate, no self-loop.\n yield { from: row.fromPath, to: target.url, status }\n continue\n }\n\n if (target.kind === 'entity') {\n const to = resolvedEntityTo.get(row.id)\n // Dropped when unpublished / no canonical row (matches resolvePath's\n // tier-3 `{kind:'none'}`). Skip a degenerate self-redirect too.\n if (to !== undefined && to !== row.fromPath) {\n yield { from: row.fromPath, to, status }\n }\n continue\n }\n\n // target.kind === 'path' — collapsed to ≤1 hop at save time, so one bounded\n // existence lookup suffices. Emit only when the target path currently serves\n // canonical content (matches resolveManualRedirect's path-kind branch).\n const to = normalizePath(target.path)\n if (to === row.fromPath) continue\n if (await pathServesCanonical(deps.pathsClient, locale, to)) {\n yield { from: row.fromPath, to, status }\n }\n }\n\n const lastRow = page[page.length - 1]\n if (!lastRow) break\n cursorId = lastRow.id\n if (page.length < pageSize) break\n }\n}\n\n/**\n * Resolve the entity-kind targets in a page to their published canonical path,\n * BATCHED by entity type: one `getCanonicalPaths` (forward index) + one\n * `filterPublished` (publish gate) per distinct target type — never per row\n * (mirrors the sitemap's `resolveAlternates` bucketing). Returns a\n * `redirectRowId → path` map holding only the rows that resolve AND publish.\n */\nasync function resolveEntityTargets(\n rows: readonly RedirectListRow[],\n locale: string,\n deps: RedirectsListDeps,\n): Promise<Map<string, string>> {\n const result = new Map<string, string>()\n\n // Group entity-kind rows by target entity type (bounded: routable types are\n // few + config-fixed). Capture `(redirectRowId, targetId)` while the union arm\n // is still narrowed, so no discriminant re-cast is needed downstream.\n const targetsByType = new Map<string, Array<{ rowId: string; targetId: string }>>()\n for (const row of rows) {\n if (row.target.kind !== 'entity') continue\n const pair = { rowId: row.id, targetId: row.target.id }\n const bucket = targetsByType.get(row.target.entity)\n if (bucket) bucket.push(pair)\n else targetsByType.set(row.target.entity, [pair])\n }\n\n for (const [type, targets] of targetsByType) {\n const ids = targets.map((t) => t.targetId)\n // (1) Forward index: which target ids have a canonical row in `locale`?\n const pathMap = await getCanonicalPaths(type, ids, locale, deps.canonicalBatch)\n const candidateIds = [...pathMap.keys()]\n if (candidateIds.length === 0) continue\n // (2) Publish gate: of THOSE, which are actually published in `locale`?\n const published = await deps.filterPublished(type, candidateIds, locale)\n for (const { rowId, targetId } of targets) {\n const path = pathMap.get(targetId)\n if (path !== undefined && published.has(targetId)) result.set(rowId, path)\n }\n }\n\n return result\n}\n\n/** True iff `path` currently serves a canonical document in `locale` (one bounded lookup). */\nasync function pathServesCanonical(\n pathsClient: PathEnumReader,\n locale: string,\n path: string,\n): Promise<boolean> {\n const rows = await pathsClient.findMany({\n where: { locale, path, isCanonical: true },\n limit: 1,\n })\n return rows.length > 0\n}\n\n// ---------------------------------------------------------------------------\n// Historical redirects\n// ---------------------------------------------------------------------------\n\n/**\n * Stream the historical (automatic rename) redirects for `locale`: the demoted\n * (`is_canonical = false`) `toolkit_paths` rows, each resolved to its owning\n * document's CURRENT canonical path. Keyset-paginated; per page, ONE\n * `getCanonicalPaths` + ONE `filterPublished` per entity-type group (never per\n * row). Drops rows whose document has no live published canonical variant\n * anymore (matches `findRedirectTarget`'s `null`), and any `from` a manual\n * redirect already claimed (tier-3 wins) or an already-emitted historical `from`\n * (at most one rule per `from`).\n */\nasync function* historicalRedirects(\n locale: string,\n deps: RedirectsListDeps,\n pageSize: number,\n manualFrom: ReadonlySet<string>,\n): AsyncGenerator<RedirectEntry> {\n /** Historical `from`s already emitted — dedup the documented multi-doc collision. */\n const emittedFrom = new Set<string>()\n let cursorId: string | undefined\n for (;;) {\n const where: PathEnumWhere = { locale, isCanonical: false }\n if (cursorId !== undefined) where.id = { gt: cursorId }\n\n const page = await deps.pathsClient.findMany({\n where,\n orderBy: [{ column: 'id', dir: 'asc' }],\n limit: pageSize,\n })\n if (page.length === 0) break\n\n // Group this page's rows by entity type, then ONE batched canonical lookup +\n // ONE publish check per group. `entityId → current published canonical path`.\n const byType = new Map<string, PathEnumRow[]>()\n for (const row of page) {\n const bucket = byType.get(row.entityType)\n if (bucket) bucket.push(row)\n else byType.set(row.entityType, [row])\n }\n\n const currentPath = new Map<string, string>()\n for (const [type, rows] of byType) {\n const ids = rows.map((r) => r.entityId)\n const pathMap = await getCanonicalPaths(type, ids, locale, deps.canonicalBatch)\n const candidateIds = [...pathMap.keys()]\n if (candidateIds.length === 0) continue\n const published = await deps.filterPublished(type, candidateIds, locale)\n for (const [id, path] of pathMap) {\n if (published.has(id)) currentPath.set(id, path)\n }\n }\n\n for (const row of page) {\n // A manual redirect at this path wins (tier 3 before tier 4).\n if (manualFrom.has(row.path)) continue\n // Already emitted a historical rule at this `from` (multi-doc collision).\n if (emittedFrom.has(row.path)) continue\n const to = currentPath.get(row.entityId)\n if (to === undefined) continue // no live published canonical → dropped\n if (to === row.path) continue // self-redirect (from == to) → skip\n emittedFrom.add(row.path)\n yield { from: row.path, to, status: 301 }\n }\n\n const lastRow = page[page.length - 1]\n if (!lastRow) break\n cursorId = lastRow.id\n if (page.length < pageSize) break\n }\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Narrow the DB `status` integer (validated `301 | 302` at write time) to the\n * result union. Defaults to `301` for any unexpected value — never a raw number\n * leaking into the typed entry (mirrors `resolve.ts`'s `toRedirectStatus`).\n */\nfunction toRedirectStatus(status: number): 301 | 302 {\n return status === 302 ? 302 : 301\n}\n"],"mappings":"4YA4IA,MAAa,EAA4B,IAG5B,EAAyB,cAyBtC,eAAuB,EACrB,EACA,EACA,EAAwB,CAAC,EACI,CAC7B,IAAM,EAAU,EAAqB,EAAK,eAAgB,CAAyB,EAC7E,EAAY,EAAqB,EAAO,UAAW,GAA6B,EAChF,EAAO,EAAmB,EAAK,OAAO,EAGtC,EAA8D,CAAC,EAErE,IAAK,IAAM,KAAU,EAAK,QAAS,CACjC,IAAI,EAAmB,CAAC,EACpB,EAAkC,KAClC,EAAY,EAGV,MAAkC,CACtC,GAAI,EAAO,SAAW,EAAG,OAAO,KAChC,IAAM,EAAW,EAAe,EAAQ,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@
1
+ import{t as e}from"./content-config-store-8omQF5p5.mjs";import{n as t,s as n}from"./schema-BYrYzsmO.mjs";import{d as r,n as i,s as a}from"./schema-IML1rRU_.mjs";import{matchReservedPrefix as o}from"@murumets-ee/entity";import{combineAdminRoutes as s,defineAdminRoute as c,getContext as l,requireRequestSite as u,safeAudit as d}from"@murumets-ee/core";import{and as f,eq as p}from"drizzle-orm";import{z as m}from"zod";import{entityRefs as h}from"@murumets-ee/entity/refs";const g=`path:resolve`,ee=[`admin`,`editor`];function _(e,t=200){return new Response(JSON.stringify(e),{status:t,headers:{"Content-Type":`application/json`}})}const v={kind:`none`};function y(e){return e===null||e.length===0?{error:`query param 'path' is required`}:e.length>2048?{error:`query param 'path' is too long`}:e.startsWith(`/`)?e.startsWith(`//`)?{error:`query param 'path' must not be protocol-relative`}:e.includes(`?`)||e.includes(`#`)?{error:`query param 'path' must not include a query or fragment`}:{path:e}:{error:`query param 'path' must start with '/'`}}function b(t,n){let r=e(),i=t??n??r.defaultLocale;return(l()?.availableLocales??r.locales.map(e=>e.code)).includes(i)?{locale:i}:{error:`query param 'locale' is not a content locale`}}const x=async(e,t)=>{let n=new URL(e.url).searchParams,r=y(n.get(`path`));if(`error`in r)return _({error:r.error},400);let i=b(n.get(`locale`),t.locale??t.defaultLocale);if(`error`in i)return _({error:i.error},400);let{locale:o}=i,{buildResolveDeps:s}=await import(`./resolve-context-Cvc1aNJe.mjs`).then(e=>e.l),c=s(t.app),l=(e,n)=>t.checkPermission(e,`view`)?{kind:`document`,entityType:e,id:n}:v,u=await a(r.path,o,c);if(u.kind===`document`)return _(l(u.entityType,u.id));if(u.kind===`none`)return _(v);if(!(u.to.startsWith(`/`)&&!u.to.startsWith(`//`)))return _({kind:`redirect`,to:u.to});let d=await a(u.to,o,c);return _(d.kind===`document`?l(d.entityType,d.id):v)};function S(){return s([c({prefix:`paths`,path:`resolve`,method:`GET`,permission:g,defaultRoles:ee,description:`Resolve a site URL path to the CMS document that serves it (editor canvas link navigation).`,handler:x})])}var C=class extends Error{fromPath;prefix;constructor(e,t){super(`Redirect source "${e}" falls under the reserved prefix "${t}" and cannot be used — that path range is owned by the framework.`),this.name=`RedirectReservedPrefixError`,this.fromPath=e,this.prefix=t}},w=class extends Error{fromPath;locale;conflictingLocale;constructor(e,t,n){super(`Redirect source "${e}" already serves content in locale "${n}" (it is a live canonical URL). Choose a different source path, or unpublish/rename the content first.`),this.name=`RedirectServesContentError`,this.fromPath=e,this.locale=t,this.conflictingLocale=n}},T=class extends Error{entity;constructor(e){super(`Redirect target references entity type "${e}", which is not a registered entity. Check the entity name.`),this.name=`RedirectUnknownEntityError`,this.entity=e}},E=class extends Error{entity;id;constructor(e,t){super(`Redirect target ${e} "${t}" does not exist. Redirect to a document that exists, or use a URL/path target instead.`),this.name=`RedirectTargetNotFoundError`,this.entity=e,this.id=t}},D=class extends Error{fromPath;locale;constructor(e,t){super(`Redirect source "${e}"${t===null?``:` (locale "${t}")`} resolves back to itself — a redirect cannot point at its own source path. Choose a different destination.`),this.name=`RedirectSelfReferenceError`,this.fromPath=e,this.locale=t}};const O=`toolkit_redirects`;async function k(e,t,n){n.kind===`entity`&&await e.insert(h).values({sourceEntity:O,sourceId:t,sourceField:`target`,targetEntity:n.entity,targetId:n.id,relationKind:`link`}).onConflictDoNothing()}async function A(e,t){await e.delete(h).where(f(p(h.sourceEntity,O),p(h.sourceId,t)))}const j=m.discriminatedUnion(`kind`,[m.object({kind:m.literal(`entity`),entity:m.string().min(1),id:m.string().uuid()}),m.object({kind:m.literal(`url`),url:m.string().max(2048).url()}),m.object({kind:m.literal(`path`),path:m.string().min(1).max(2048).startsWith(`/`)})]);function M(e){return r(e)}function N(e){let t=M(e.fromPath),n=o(t,e.reservedPathPrefixes);if(n!==void 0)throw new C(t,n)}async function te(e){let t=M(e.fromPath);if(e.locale!==null){let n=await e.pathsClient.findOne({path:t,isCanonical:!0,locale:e.locale});if(n)throw new w(t,e.locale,n.locale);return}let n=await e.pathsClient.findOne({path:t,isCanonical:!0,locale:{in:[...e.configuredLocales]}});if(n)throw new w(t,null,n.locale)}async function ne(e){if(e.target.kind!==`path`)return e.target;let t=M(e.target.path),n=e.excludeId===void 0?{}:{id:{ne:e.excludeId}};if(e.locale!==null){let r=await e.redirectsClient.findOne({fromPath:t,locale:e.locale,...n});if(r)return r.target}let r=await e.redirectsClient.findOne({fromPath:t,locale:null,...n});return r?r.target:{kind:`path`,path:t}}async function P(e){if(e.target.kind!==`entity`)return;let{entity:t,id:n}=e.target,r=e.resolveClient(t);if(r===void 0)throw new T(t);if(await r.findById(n)==null)throw new E(t,n)}function F(){return u(`toolkit_redirects`)}const I=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,L=/^[a-zA-Z0-9:_.-]{1,100}$/,R=`redirect:manage`,z=[`admin`];function B(e,t=200){return new Response(JSON.stringify(e),{status:t,headers:{"Content-Type":`application/json`}})}function V(e,t){return B({error:e},t)}async function H(e,t){let n;try{n=await e.json()}catch{return{response:V(`Invalid JSON body`,400)}}let r=t.safeParse(n);if(!r.success){let e=r.error.issues[0];return{response:V(e?`${e.path.join(`.`)||`body`}: ${e.message}`:`Invalid body`,400)}}return{data:r.data}}function U(e,t){if(e===null||!/^\d+$/.test(e))return t;let n=Number(e);return Number.isSafeInteger(n)?n:t}function W(e){return e.name===void 0?{userId:e.id}:{userId:e.id,userName:e.name}}async function G(){let{getApp:e}=await import(`@murumets-ee/core`);return e()}async function K(){return(await G()).db.readWrite}async function q(){let e=await G();return t=>{let n=e.entities.get(t);return n?e.getClient(n):void 0}}function J(e){return e}const Y=m.union([m.literal(301),m.literal(302)]),X=m.string().min(1).max(2048).startsWith(`/`),re=m.object({locale:m.string().min(1).nullable(),fromPath:X,target:j,status:Y.default(301)}),ie=m.object({locale:m.string().min(1).nullable().optional(),fromPath:X.optional(),target:j.optional(),status:Y.optional()});function Z(t){return t===null||e().locales.map(e=>e.code).includes(t)?null:V(`Unknown locale "${t}" — not one of the configured content locales.`,400)}function Q(e){if(e instanceof C)return B({error:e.message,fromPath:e.fromPath,prefix:e.prefix},409);if(e instanceof w)return B({error:e.message,fromPath:e.fromPath,locale:e.locale,conflictingLocale:e.conflictingLocale},409);if(e instanceof D)return B({error:e.message,fromPath:e.fromPath,locale:e.locale},409);if(e instanceof T)return B({error:e.message,entity:e.entity},400);if(e instanceof E)return B({error:e.message,entity:e.entity,id:e.id},400);if(n(e))return B({error:`A redirect already exists for this locale + source path.`},409);throw e}async function $(n){let r=e(),a=r.reservedPathPrefixes??[],o=r.locales.map(e=>e.code),s=M(n.fromPath);N({fromPath:s,reservedPathPrefixes:a}),await P({target:n.target,resolveClient:n.resolveClient});let c=await K(),l=await F();return c.transaction(async e=>{let r=J(e),a=i.makeClient(r,l),c=t.makeClient(r,l);await te({fromPath:s,locale:n.locale,configuredLocales:o,pathsClient:c});let u=await ne({target:n.target,locale:n.locale,redirectsClient:a,...n.id===null?{}:{excludeId:n.id}});if(u.kind===`path`&&M(u.path)===s)throw new D(s,n.locale);if(n.id===null){let e=await a.insert({locale:n.locale,fromPath:s,target:u,status:n.status,createdBy:n.userId});return await k(r,e.id,u),e}let d=await a.update({id:n.id},{locale:n.locale,fromPath:s,target:u,status:n.status,updatedAt:new Date});return d?(await A(r,n.id),await k(r,n.id,u),d):null})}const ae=async e=>{let t=new URL(e.url),n=t.searchParams.get(`locale`),r=Math.min(Math.max(U(t.searchParams.get(`limit`),50),1),200),a=Math.min(U(t.searchParams.get(`offset`),0),1e5),o;if(n!==null&&n!==``){let e=Z(n);if(e)return e;o=n}let s=i.makeClient(await K(),await F());return B({items:o===void 0?await s.findMany({orderBy:[{column:`createdAt`,dir:`desc`}],limit:r,offset:a}):await s.findMany({where:{locale:o},orderBy:[{column:`createdAt`,dir:`desc`}],limit:r,offset:a}),total:o===void 0?await s.count():await s.count({locale:o})})},oe=async(e,t)=>{let n=await H(e,re);if(`response`in n)return n.response;let r=n.data,i=Z(r.locale);if(i)return i;try{let e=await q(),n=await $({id:null,locale:r.locale,fromPath:r.fromPath,target:r.target,status:r.status,userId:t.user.id,resolveClient:e});return n?(d(t,{action:`redirect.created`,entityType:`redirect`,entityId:n.id,...W(t.user),metadata:{locale:n.locale,fromPath:n.fromPath,targetKind:n.target.kind}}),B({item:n},201)):V(`Failed to create redirect`,500)}catch(e){return Q(e)}},se=async(e,t)=>{let n=t.segments[0];if(!n||!I.test(n))return V(`Invalid id`,400);let r=await H(e,ie);if(`response`in r)return r.response;let a=r.data,o=await i.makeClient(await K(),await F()).findOne({id:n});if(!o)return V(`Not found`,404);let s=a.locale===void 0?o.locale:a.locale,c=a.fromPath===void 0?o.fromPath:a.fromPath,l=a.target===void 0?o.target:a.target,u=a.status===void 0?o.status:a.status,f=Z(s);if(f)return f;try{let e=await q(),r=await $({id:n,locale:s,fromPath:c,target:l,status:u,userId:t.user.id,resolveClient:e});return r?(d(t,{action:`redirect.updated`,entityType:`redirect`,entityId:r.id,...W(t.user),metadata:{locale:r.locale,fromPath:r.fromPath,targetKind:r.target.kind}}),B({item:r})):V(`Not found`,404)}catch(e){return Q(e)}},ce=async(e,t)=>{let n=t.segments[0];if(!n||!I.test(n))return V(`Invalid id`,400);let r=await K(),a=await F(),o=await r.transaction(async e=>{let t=J(e),r=await i.makeClient(t,a).delete({id:n});return r&&await A(t,n),r});return o?(d(t,{action:`redirect.deleted`,entityType:`redirect`,entityId:n,...W(t.user),metadata:{locale:o.locale,fromPath:o.fromPath}}),B({ok:!0})):V(`Not found`,404)},le=async e=>{let n=new URL(e.url),r=n.searchParams.get(`entityType`),i=n.searchParams.get(`entityId`);if(!r||!L.test(r))return V(`entityType is required`,400);if(!i||!I.test(i))return V(`entityId is required and must be a UUID`,400);let a=n.searchParams.get(`locale`),o;if(a!==null&&a!==``){let e=Z(a);if(e)return e;o=a}return B({items:await t.makeClient(await K(),await F()).findMany({where:{entityType:r,entityId:i,isCanonical:!1,...o!==void 0&&{locale:o}},orderBy:[{column:`updatedAt`,dir:`desc`}],limit:100})})};function ue(){return s([c({prefix:`redirects`,path:``,method:`GET`,permission:R,defaultRoles:z,description:`List manual URL redirects (paginated, optional locale filter).`,handler:ae}),c({prefix:`redirects`,path:`history`,method:`GET`,permission:R,defaultRoles:z,description:`Read-only automatic-redirect (rename) history for one document.`,handler:le}),c({prefix:`redirects`,path:``,method:`POST`,permission:R,defaultRoles:z,description:`Create a manual URL redirect.`,handler:oe}),c({prefix:`redirects`,path:``,method:`PATCH`,matchAnyPath:!0,permission:R,defaultRoles:z,description:`Update a manual URL redirect by id.`,handler:se}),c({prefix:`redirects`,path:``,method:`DELETE`,matchAnyPath:!0,permission:R,defaultRoles:z,description:`Delete a manual URL redirect by id.`,handler:ce})])}export{g as n,S as r,ue as t};
2
+ //# sourceMappingURL=routes-BmNSYyuT.mjs.map