@murumets-ee/content 0.0.0-preview-20261014110621

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 (111) hide show
  1. package/LICENSE +94 -0
  2. package/README.md +15 -0
  3. package/dist/admin.d.mts +56 -0
  4. package/dist/admin.d.mts.map +1 -0
  5. package/dist/admin.mjs +1 -0
  6. package/dist/block-resolver.d.mts +320 -0
  7. package/dist/block-resolver.d.mts.map +1 -0
  8. package/dist/block-resolver.mjs +2 -0
  9. package/dist/block-resolver.mjs.map +1 -0
  10. package/dist/breadcrumbs-BqSuMNac.mjs +2 -0
  11. package/dist/breadcrumbs-BqSuMNac.mjs.map +1 -0
  12. package/dist/chrome-entity-names-zYJzP-_U.mjs +2 -0
  13. package/dist/chrome-entity-names-zYJzP-_U.mjs.map +1 -0
  14. package/dist/chrome-provider.d.mts +143 -0
  15. package/dist/chrome-provider.d.mts.map +1 -0
  16. package/dist/chrome-provider.mjs +2 -0
  17. package/dist/chrome-provider.mjs.map +1 -0
  18. package/dist/client.d.mts +89 -0
  19. package/dist/client.d.mts.map +1 -0
  20. package/dist/client.mjs +2 -0
  21. package/dist/client.mjs.map +1 -0
  22. package/dist/content-config-store-8omQF5p5.mjs +2 -0
  23. package/dist/content-config-store-8omQF5p5.mjs.map +1 -0
  24. package/dist/context-D7eEItCY.mjs +2 -0
  25. package/dist/context-D7eEItCY.mjs.map +1 -0
  26. package/dist/detail-template-names-CD1Y9n1U.mjs +2 -0
  27. package/dist/detail-template-names-CD1Y9n1U.mjs.map +1 -0
  28. package/dist/detail-template-provider.d.mts +28 -0
  29. package/dist/detail-template-provider.d.mts.map +1 -0
  30. package/dist/detail-template-provider.mjs +2 -0
  31. package/dist/detail-template-provider.mjs.map +1 -0
  32. package/dist/document-site-B8tmEqLw.mjs +2 -0
  33. package/dist/document-site-B8tmEqLw.mjs.map +1 -0
  34. package/dist/entities/index.d.mts +64 -0
  35. package/dist/entities/index.d.mts.map +1 -0
  36. package/dist/entities/index.mjs +2 -0
  37. package/dist/entities/index.mjs.map +1 -0
  38. package/dist/enumerate-CYHJKQz6.mjs +2 -0
  39. package/dist/enumerate-CYHJKQz6.mjs.map +1 -0
  40. package/dist/errors-NRNILhhm.mjs +2 -0
  41. package/dist/errors-NRNILhhm.mjs.map +1 -0
  42. package/dist/index-cT8Qk4gu.d.mts +275 -0
  43. package/dist/index-cT8Qk4gu.d.mts.map +1 -0
  44. package/dist/index.d.mts +5 -0
  45. package/dist/index.mjs +2 -0
  46. package/dist/index.mjs.map +1 -0
  47. package/dist/locale-entity-CoSq3C77.mjs +2 -0
  48. package/dist/locale-entity-CoSq3C77.mjs.map +1 -0
  49. package/dist/locale-registry-COsJrVZl.mjs +2 -0
  50. package/dist/locale-registry-COsJrVZl.mjs.map +1 -0
  51. package/dist/locale-utils-B0mFoV47.mjs +2 -0
  52. package/dist/locale-utils-B0mFoV47.mjs.map +1 -0
  53. package/dist/lock-service.d.mts +58 -0
  54. package/dist/lock-service.d.mts.map +1 -0
  55. package/dist/lock-service.mjs +2 -0
  56. package/dist/lock-service.mjs.map +1 -0
  57. package/dist/locks-5779ugSW.mjs +2 -0
  58. package/dist/locks-5779ugSW.mjs.map +1 -0
  59. package/dist/plugin-CjgqBSFy.mjs +2 -0
  60. package/dist/plugin-CjgqBSFy.mjs.map +1 -0
  61. package/dist/plugin.d.mts +41 -0
  62. package/dist/plugin.d.mts.map +1 -0
  63. package/dist/plugin.mjs +1 -0
  64. package/dist/query-client.d.mts +131 -0
  65. package/dist/query-client.d.mts.map +1 -0
  66. package/dist/query-client.mjs +2 -0
  67. package/dist/query-client.mjs.map +1 -0
  68. package/dist/registry-CaPbY5lm.mjs +2 -0
  69. package/dist/registry-CaPbY5lm.mjs.map +1 -0
  70. package/dist/resolve-context-DklN53BH.mjs +2 -0
  71. package/dist/resolve-context-DklN53BH.mjs.map +1 -0
  72. package/dist/resolve.d.mts +651 -0
  73. package/dist/resolve.d.mts.map +1 -0
  74. package/dist/resolve.mjs +9 -0
  75. package/dist/resolve.mjs.map +1 -0
  76. package/dist/rolldown-runtime-DK3Fl9T5.mjs +1 -0
  77. package/dist/routes-siXmjKDA.mjs +2 -0
  78. package/dist/routes-siXmjKDA.mjs.map +1 -0
  79. package/dist/routing-strategy-CAG3tZP0.d.mts +155 -0
  80. package/dist/routing-strategy-CAG3tZP0.d.mts.map +1 -0
  81. package/dist/routing-strategy-D6B4ngT9.mjs +2 -0
  82. package/dist/routing-strategy-D6B4ngT9.mjs.map +1 -0
  83. package/dist/schema-BYrYzsmO.mjs +2 -0
  84. package/dist/schema-BYrYzsmO.mjs.map +1 -0
  85. package/dist/schema-LlK6EkOJ.mjs +2 -0
  86. package/dist/schema-LlK6EkOJ.mjs.map +1 -0
  87. package/dist/seed.d.mts +177 -0
  88. package/dist/seed.d.mts.map +1 -0
  89. package/dist/seed.mjs +2 -0
  90. package/dist/seed.mjs.map +1 -0
  91. package/dist/site-chrome-BAtQaAqC.mjs +2 -0
  92. package/dist/site-chrome-BAtQaAqC.mjs.map +1 -0
  93. package/dist/site-chrome-DNCcePSR.d.mts +98 -0
  94. package/dist/site-chrome-DNCcePSR.d.mts.map +1 -0
  95. package/dist/translation-provenance-B41lEDM-.mjs +2 -0
  96. package/dist/translation-provenance-B41lEDM-.mjs.map +1 -0
  97. package/dist/translation-provenance-BZ0MlbFR.d.mts +253 -0
  98. package/dist/translation-provenance-BZ0MlbFR.d.mts.map +1 -0
  99. package/dist/translation.d.mts +144 -0
  100. package/dist/translation.d.mts.map +1 -0
  101. package/dist/translation.mjs +2 -0
  102. package/dist/translation.mjs.map +1 -0
  103. package/dist/types-BOk9tg_9.d.mts +150 -0
  104. package/dist/types-BOk9tg_9.d.mts.map +1 -0
  105. package/dist/versionable-Br_G5VGR.mjs +2 -0
  106. package/dist/versionable-Br_G5VGR.mjs.map +1 -0
  107. package/dist/versionable-CRvV87nZ.d.mts +18 -0
  108. package/dist/versionable-CRvV87nZ.d.mts.map +1 -0
  109. package/dist/versions-w2ui-Vzb.mjs +2 -0
  110. package/dist/versions-w2ui-Vzb.mjs.map +1 -0
  111. package/package.json +93 -0
@@ -0,0 +1,89 @@
1
+ import { d as TranslationReport, f as TranslationStatus, n as DraftEntry, p as VersionEntry, s as LocalePublishStatus } from "./types-BOk9tg_9.mjs";
2
+ import { h as FieldDiff } from "./index-cT8Qk4gu.mjs";
3
+ import { Entity, FieldConfig } from "@murumets-ee/entity";
4
+ import { Logger } from "@murumets-ee/core";
5
+ import { AdminClient, FindManyOptions, InferCreateInput, InferEntityDTO, InferUpdateInput } from "@murumets-ee/entity/admin";
6
+
7
+ //#region src/client.d.ts
8
+ interface ContentClientConfig<AllFields extends Record<string, FieldConfig> = Record<string, FieldConfig>> {
9
+ admin: AdminClient<AllFields>;
10
+ entity: Entity<AllFields>;
11
+ logger?: Logger;
12
+ }
13
+ declare class ContentClient<AllFields extends Record<string, FieldConfig> = Record<string, FieldConfig>> {
14
+ private ctx;
15
+ constructor(config: ContentClientConfig<AllFields>);
16
+ create(data: InferCreateInput<AllFields>): Promise<InferEntityDTO<AllFields>>;
17
+ findById(id: string, options?: {
18
+ locale?: string;
19
+ }): Promise<InferEntityDTO<AllFields> | null>;
20
+ findMany(options?: FindManyOptions): Promise<InferEntityDTO<AllFields>[]>;
21
+ /**
22
+ * Base-row update + version snapshot. Subject to AdminClient's
23
+ * cross-locale write guard (SD021): under a non-default request-context
24
+ * locale, translatable fields throw `CrossLocaleWriteError` — that's
25
+ * enforcement, not a gap. Locale-belonging writes go through the draft
26
+ * flow (`saveDraft` → `publishDraft`) or `admin.updateForLocale` directly.
27
+ */
28
+ update(id: string, data: InferUpdateInput<AllFields>): Promise<InferEntityDTO<AllFields>>;
29
+ delete(id: string): Promise<unknown>;
30
+ saveTranslation(entityId: string, locale: string, translations: Record<string, unknown>): Promise<void>;
31
+ deleteTranslation(entityId: string, locale?: string): Promise<void>;
32
+ getVersions(entityId: string, options?: {
33
+ limit?: number;
34
+ offset?: number;
35
+ locale?: string;
36
+ }): Promise<VersionEntry<InferEntityDTO<AllFields>>[]>;
37
+ getVersion(entityId: string, version: number, locale?: string): Promise<VersionEntry<InferEntityDTO<AllFields>> | null>;
38
+ compareVersions(entityId: string, v1: number, v2: number, locale?: string): Promise<{
39
+ diffs: FieldDiff[];
40
+ fromVersion: VersionEntry<InferEntityDTO<AllFields>>;
41
+ toVersion: VersionEntry<InferEntityDTO<AllFields>>;
42
+ } | null>;
43
+ restoreVersion(entityId: string, version: number, locale?: string): Promise<InferEntityDTO<AllFields>>;
44
+ pruneVersions(entityId: string, locale?: string): Promise<void>;
45
+ createVersionSnapshot(entityId: string, currentData: Record<string, unknown>, previousData?: Record<string, unknown> | null, locale?: string, user?: {
46
+ id: string;
47
+ name?: string;
48
+ }): Promise<void>;
49
+ getTranslationStatus(entityId: string): Promise<TranslationStatus>;
50
+ getTranslationStatusBatch(entityIds: string[]): Promise<Map<string, TranslationStatus>>;
51
+ getTranslationReport(options?: {
52
+ locale?: string;
53
+ }): Promise<TranslationReport>;
54
+ getLocaleStatus(entityId: string): Promise<LocalePublishStatus[]>;
55
+ setLocaleStatus(entityId: string, locale: string, status: 'draft' | 'published'): Promise<void>;
56
+ getLocaleStatusBatch(entityIds: string[]): Promise<Map<string, Record<string, LocalePublishStatus>>>;
57
+ saveDraft(entityId: string, data: InferUpdateInput<AllFields>, locale?: string, user?: {
58
+ id: string;
59
+ name?: string;
60
+ }): Promise<DraftEntry<InferUpdateInput<AllFields>>>;
61
+ mergeDraft(entityId: string, patch: InferUpdateInput<AllFields>, locale?: string, user?: {
62
+ id: string;
63
+ name?: string;
64
+ }): Promise<DraftEntry<InferUpdateInput<AllFields>> | null>;
65
+ getDraft(entityId: string, locale?: string): Promise<DraftEntry<InferUpdateInput<AllFields>> | null>;
66
+ deleteDraft(entityId: string, locale?: string): Promise<boolean>;
67
+ publishDraft(entityId: string, locale?: string, user?: {
68
+ id: string;
69
+ name?: string;
70
+ }): Promise<InferEntityDTO<AllFields>>;
71
+ hasDraft(entityId: string, locale?: string): Promise<boolean>;
72
+ countDrafts(locale?: string): Promise<number>;
73
+ hasDraftBatch(entityIds: string[], locale?: string): Promise<Set<string>>;
74
+ compareDraftWithCurrent(entityId: string, locale?: string): Promise<{
75
+ diffs: FieldDiff[];
76
+ current: InferEntityDTO<AllFields>;
77
+ draft: DraftEntry<InferUpdateInput<AllFields>>;
78
+ } | null>;
79
+ }
80
+ /**
81
+ * Factory — creates a ContentClient for an entity. Must be called
82
+ * after `createApp()`. Generic flows from the entity definition:
83
+ * `createContentClient(Article)` returns a `ContentClient<typeof
84
+ * Article['allFields']>` typed end-to-end.
85
+ */
86
+ declare function createContentClient<AllFields extends Record<string, FieldConfig>>(entity: Entity<AllFields>): ContentClient<AllFields>;
87
+ //#endregion
88
+ export { ContentClient, ContentClientConfig, createContentClient };
89
+ //# sourceMappingURL=client.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.mts","names":[],"sources":["../src/client.ts"],"mappings":";;;;;;;UAgEiB,mBAAA,mBACG,MAAA,SAAe,WAAA,IAAe,MAAA,SAAe,WAAA;EAE/D,KAAA,EAAO,WAAA,CAAY,SAAA;EACnB,MAAA,EAAQ,MAAA,CAAO,SAAA;EACf,MAAA,GAAS,MAAA;AAAA;AAAA,cAGE,aAAA,mBACO,MAAA,SAAe,WAAA,IAAe,MAAA,SAAe,WAAA;EAAA,QAEvD,GAAA;cAEI,MAAA,EAAQ,mBAAA,CAAoB,SAAA;EASlC,MAAA,CAAO,IAAA,EAAM,gBAAA,CAAiB,SAAA,IAAa,OAAA,CAAQ,cAAA,CAAe,SAAA;EAQxE,QAAA,CAAS,EAAA,UAAY,OAAA;IAAY,MAAA;EAAA,IAAoB,OAAA,CAAQ,cAAA,CAAe,SAAA;EAI5E,QAAA,CAAS,OAAA,GAAU,eAAA,GAAkB,OAAA,CAAQ,cAAA,CAAe,SAAA;EA1BjD;;;;;;;EAqCL,MAAA,CAAO,EAAA,UAAY,IAAA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,SAAA,CACE,QAAA,UACA,IAAA,EAAM,gBAAA,CAAiB,SAAA,GACvB,MAAA,WACA,IAAA;IAAS,EAAA;IAAY,IAAA;EAAA,IAAe,OAAA,CAAA,UAAA,CAAA,gBAAA,CAAA,SAAA;EAKtC,UAAA,CACE,QAAA,UACA,KAAA,EAAO,gBAAA,CAAiB,SAAA,GACxB,MAAA,WACA,IAAA;IAAS,EAAA;IAAY,IAAA;EAAA,IAAe,OAAA,CAAA,UAAA,CAAA,gBAAA,CAAA,SAAA;EAKtC,QAAA,CAAS,QAAA,UAAkB,MAAA,YAAe,OAAA,CAAA,UAAA,CAAA,gBAAA,CAAA,SAAA;EAI1C,WAAA,CAAY,QAAA,UAAkB,MAAA,YAAe,OAAA;EAI7C,YAAA,CAAa,QAAA,UAAkB,MAAA,WAAiB,IAAA;IAAS,EAAA;IAAY,IAAA;EAAA,IAAe,OAAA,CAAA,cAAA,CAAA,SAAA;EAIpF,QAAA,CAAS,QAAA,UAAkB,MAAA,YAAe,OAAA;EAI1C,WAAA,CAAY,MAAA,YAAe,OAAA;EAI3B,aAAA,CAAc,SAAA,YAAqB,MAAA,YAAe,OAAA,CAAA,GAAA;EAIlD,uBAAA,CAAwB,QAAA,UAAkB,MAAA,YAAe,OAAA;WAJP,SAAA;;;;;;;;;;;iBAepC,mBAAA,mBAAsC,MAAA,SAAe,WAAA,GACnE,MAAA,EAAQ,MAAA,CAAO,SAAA,IACd,aAAA,CAAc,SAAA"}
@@ -0,0 +1,2 @@
1
+ import{t as e}from"./versionable-Br_G5VGR.mjs";import{n as t,r as n,t as r}from"./errors-NRNILhhm.mjs";import{t as i}from"./content-config-store-8omQF5p5.mjs";import{a,d as o,f as s,h as c,i as l,l as u,m as d,n as f,o as p,p as m,r as h,s as g,t as _,u as v}from"./versions-w2ui-Vzb.mjs";import{n as y}from"./plugin-CjgqBSFy.mjs";import{t as b}from"./locale-utils-B0mFoV47.mjs";import{i as x,n as S,r as C}from"./context-D7eEItCY.mjs";import{c as w,f as T,r as E}from"./translation-provenance-B41lEDM-.mjs";import{blockTreeFieldsOf as D,buildPartitionCondition as O}from"@murumets-ee/entity";import{getApp as k,getContext as A,requireSiteFor as ee}from"@murumets-ee/core";import{schemaRegistry as te}from"@murumets-ee/db";import{and as ne,inArray as j}from"drizzle-orm";import"server-only";import{createAdminClient as M}from"@murumets-ee/core/clients";function N(e){return{id:e.id,entityId:e.entityId,locale:e.locale,data:e.data,createdBy:e.createdBy,createdByName:e.createdByName??null,createdAt:e.createdAt,updatedAt:e.updatedAt}}async function P(e,t,n){try{return await e.admin.findById(t,n===`_`?{}:{locale:n})??void 0}catch(n){e.logger?.warn({entity:e.entity.name,entityId:t,error:n},`draft: the live row could not be read to grandfather its block tree`);return}}async function F(e,t,n,r,i){let a=typeof i==`object`&&i?i:void 0;if(!D(e.entity).some(({name:e})=>Object.hasOwn(r,e)&&!Array.isArray(a?.[e])))return a;let o=await P(e,t,n);return o===void 0?a:{...o,...a}}async function I(e,n,r,i=`_`,a){b(i);let s=await C(e);if(!s)throw new t(e.entity.name,`drafts`);let c=o(e.entity,r);e.admin.assertBlockTreesValid(c);let l=D(e.entity).some(({name:e})=>Object.hasOwn(c,e))?await s.findOne({entityId:n,locale:i}):null;await e.admin.assertBlockTreesFitDocument(c,()=>F(e,n,i,c,l?.data),{loadAreaRow:()=>P(e,n,i)}),await e.admin.assertMediaKindsValid(c,l?.data);let u=new Date,d=a?.id??``,f=a?.name??null,p=await s.upsert({entityId:n,locale:i,data:c,createdBy:d,createdByName:f,createdAt:u,updatedAt:u},{target:[`entityId`,`locale`],set:{data:c,updatedAt:u}});return await w({entityName:e.entity.name,entityId:n,locale:i,userId:a?.id,draftData:p.data??{}}),N(p)}const L=[`slug`,`slugMode`,`parent`];async function R(e,n,r,i=`_`,a){b(i);let s=await C(e);if(!s)throw new t(e.entity.name,`drafts`);let c=o(e.entity,r);if(Object.keys(c).length===0){let e=await s.findOne({entityId:n,locale:i});return e?N(e):null}e.admin.assertBlockTreesValid(c),e.admin.assertUpdateValid(c);let l=D(e.entity).some(({name:e})=>Object.hasOwn(c,e)),u=e.entity.frontend?.path!==void 0&&L.some(e=>Object.hasOwn(c,e)),d=l||u?await s.findOne({entityId:n,locale:i}):null;if(await e.admin.assertBlockTreesFitDocument(c,()=>F(e,n,i,c,d?.data),{loadAreaRow:()=>P(e,n,i)}),await e.admin.assertMediaKindsValid(c,d?.data),u){let t={...d?.data??{},...c};if(i===`_`)await e.admin.assertPathAvailable(n,t);else{let r=e.entity.allFields,a={},o={};for(let[e,n]of Object.entries(t))r[e]?.translatable===!0?a[e]=n:o[e]=n;let s=e=>L.some(t=>Object.hasOwn(e,t)&&Object.hasOwn(c,t));s(a)&&await e.admin.assertPathAvailable(n,a,i),s(o)&&await e.admin.assertPathAvailable(n,o)}}let f=new Date,p=await s.upsert({entityId:n,locale:i,data:c,createdBy:a?.id??``,createdByName:a?.name??null,createdAt:f,updatedAt:f},{target:[`entityId`,`locale`],set:{updatedAt:f},mergeJsonb:[`data`]});return await w({entityName:e.entity.name,entityId:n,locale:i,userId:a?.id,draftData:p.data??{}}),N(p)}async function z(e,t,n=`_`){b(n);let r=await C(e);if(!r)return null;let i=await r.findOne({entityId:t,locale:n});return i?N(i):null}async function B(e,t,n=`_`){b(n);let r=await C(e);if(!r)return!1;let i=await r.deleteMany({entityId:t,locale:n});return i.length>0&&await w({entityName:e.entity.name,entityId:t,locale:n,reverted:!0}),i.length>0}async function V(e,n,i=`_`,a){if(b(i),!await C(e))throw new t(e.entity.name,`drafts`);let c=e.versionableOptions?await e.admin.findById(n,m(i)):null;return e.db.transaction(async l=>{let u={...e,db:l},d=await C(u);if(!d)throw new t(e.entity.name,`drafts`);let[p]=await d.deleteMany({entityId:n,locale:i});if(!p)throw new r(n,i);let{publishedAt:m,...h}=p.data??{},g=await s(u,n,o(e.entity,{...h,status:`published`}),i,l),_=H(e.entity,h);return _!==void 0&&await e.admin.updateInternal(n,{_overrides:_},{tx:l}),e.versionableOptions&&await f(u,n,g,c,i,a),g})}function H(e,t){if(!(e.behaviors??[]).some(e=>e.name===`withOverrides`))return;let n=e.allFields._overrides;if(n===void 0||n.internal!==!0)return;let r=t._overrides;if(!(typeof r!=`object`||!r||Array.isArray(r)))return r}async function U(e,t,n=`_`){b(n);let r=await C(e);return r?r.exists({entityId:t,locale:n}):!1}async function W(e,t=`_`){b(t);let n=await C(e);return n?n.count({locale:t}):0}async function G(e,t,n=`_`){b(n);let r=new Set;if(t.length===0)return r;let i=await C(e);if(!i)return r;let a=await i.findMany({where:{entityId:{in:t},locale:n}});for(let e of a)r.add(e.entityId);return r}async function K(e,t,n=`_`){b(n);let r=await z(e,t,n);if(!r)return null;let a=i().defaultLocale,o=n===`_`?{defaultLocale:a}:{locale:n,defaultLocale:a},s=await e.admin.findById(t,o);if(!s)return null;let l=e.entity.allFields,u=s,f=r.data,p={};for(let e of Object.keys(f))p[e]=u[e];let m=c(p,f,l);for(let e of m)e.type===`blockTree`&&(e.blockDiffs=d(Array.isArray(e.from)?e.from:[],Array.isArray(e.to)?e.to:[]));return{diffs:m,current:s,draft:r}}async function q(e,t){let n=(await Y(e,[t])).get(t);return n?Object.values(n):[]}async function J(e,n,r,a){b(r);let o=i();if(r===o.defaultLocale){let t={status:a};a===`published`&&(t.publishedAt=new Date),await e.admin.update(n,t);return}let s=await x(e);if(!s)throw new t(e.entity.name,`localeStatus`);let c={status:a};await e.admin.updateForLocale(n,c,r,{defaultLocale:o.defaultLocale,localeStatusWriter:(e,t,n)=>y(s,e,t,n)})}async function Y(e,t){let n=new Map;if(t.length===0)return n;let r=await x(e);if(!r)return n;let i=await r.findMany({where:{entityId:{in:t}}});for(let e of i){let t=e.entityId,r=e.locale,i=n.get(t);i||(i={},n.set(t,i)),i[r]={locale:r,status:e.status,publishedAt:e.publishedAt??null}}return n}function X(){let e=i(),t=A();return{locales:(t?.availableLocales??e.locales.map(e=>e.code)).map(e=>({code:e})),defaultLocale:t?.defaultLocale??e.defaultLocale}}function re(e,t,n,r){let i={};for(let a of n){if(a.code===r)continue;let n=t?.get(a.code)??{},o=[];for(let t of e)(n[t]===void 0||n[t]===null)&&o.push(t);i[a.code]={complete:o.length===0,total:e.length,translated:e.length-o.length,missing:o}}return i}async function ie(e,t){return(await Z(e,[t])).get(t)??{}}async function Z(e,t){let n=new Map;if(t.length===0)return n;let{locales:r,defaultLocale:i}=X(),a=Object.entries(e.entity.allFields).filter(([e,t])=>t.translatable).map(([e])=>e);if(a.length===0)return n;let o=te.get(`${e.entity.name}_translations`);if(!o)return n;let s=await ee(e.entity),c=j(o.entityId,t),l=await e.db.select().from(o).where(s===void 0?c:ne(c,O(o,{site:s},e.entity.name))),u=new Map;for(let e of l){let t=e,n=t.entityId,r=t.locale,i={};for(let e of a)i[e]=t[e];let o=u.get(n);o||(o=new Map,u.set(n,o)),o.set(r,i)}let d=await E(e.entity.name,t,e.db);for(let e of t){let t=re(a,u.get(e),r,i),o=d.get(e);for(let[e,n]of Object.entries(t)){let t=T(o,e);t&&(n.freshness=t)}n.set(e,t)}return n}const Q={total:0,complete:0,partial:0,missing:0,outdated:0,machineUnreviewed:0};async function ae(e,t){let{locales:r,defaultLocale:i}=X(),a=t?.locale??r.find(e=>e.code!==i)?.code;if(!a)return{...Q};if(!r.some(e=>e.code===a))throw new n(a,r.map(e=>e.code));let o=await e.admin.findMany();if(o.length===0)return{...Q};let s=await Z(e,o.map(e=>e.id)),c=0,l=0,u=0,d=0,f=0;for(let e of o){let t=s.get(e.id)?.[a];!t||t.translated===0?u++:t.complete?c++:l++,t?.freshness?.outdated===!0&&d++,t?.freshness?.machineUnreviewed===!0&&f++}return{total:o.length,complete:c,partial:l,missing:u,outdated:d,machineUnreviewed:f}}var $=class{ctx;constructor(t){let n=e(t.entity.behaviors);this.ctx=S(t,n)}async create(e){let t=await this.ctx.admin.create(e);return this.ctx.versionableOptions&&await g(this.ctx,t.id,t,null,!1),t}findById(e,t){return this.ctx.admin.findById(e,t)}findMany(e){return this.ctx.admin.findMany(e)}async update(e,t){let n=null;this.ctx.versionableOptions&&(n=await this.ctx.admin.findById(e));let r=await this.ctx.admin.update(e,t);if(this.ctx.versionableOptions&&n){let t=v(n,r),i=await g(this.ctx,e,r,t,!1);if(i!==void 0)return await u(this.ctx,e,i),await a(this.ctx,e),{...r,_version:i};await a(this.ctx,e)}return r}delete(e){return this.ctx.admin.delete(e)}saveTranslation(e,t,n){return this.ctx.admin.saveTranslation(e,t,n)}deleteTranslation(e,t){return this.ctx.admin.deleteTranslation(e,t)}getVersions(e,t){return l(this.ctx,e,t)}getVersion(e,t,n){return h(this.ctx,e,t,n)}compareVersions(e,t,n,r){return _(this.ctx,e,t,n,r)}restoreVersion(e,t,n){return p(this.ctx,e,t,n)}pruneVersions(e,t){return a(this.ctx,e,t)}createVersionSnapshot(e,t,n,r,i){return f(this.ctx,e,t,n,r,i)}getTranslationStatus(e){return ie(this.ctx,e)}getTranslationStatusBatch(e){return Z(this.ctx,e)}getTranslationReport(e){return ae(this.ctx,e)}getLocaleStatus(e){return q(this.ctx,e)}setLocaleStatus(e,t,n){return J(this.ctx,e,t,n)}getLocaleStatusBatch(e){return Y(this.ctx,e)}saveDraft(e,t,n,r){return I(this.ctx,e,t,n,r)}mergeDraft(e,t,n,r){return R(this.ctx,e,t,n,r)}getDraft(e,t){return z(this.ctx,e,t)}deleteDraft(e,t){return B(this.ctx,e,t)}publishDraft(e,t,n){return V(this.ctx,e,t,n)}hasDraft(e,t){return U(this.ctx,e,t)}countDrafts(e){return W(this.ctx,e)}hasDraftBatch(e,t){return G(this.ctx,e,t)}compareDraftWithCurrent(e,t){return K(this.ctx,e,t)}};function oe(e){return new $({admin:M(e),entity:e,logger:k().logger.child({content:e.name})})}export{$ as ContentClient,oe as createContentClient};
2
+ //# sourceMappingURL=client.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.mjs","names":[],"sources":["../src/drafts.ts","../src/locale-status.ts","../src/translation-status.ts","../src/client.ts"],"sourcesContent":["/**\n * Draft-overlay operations.\n *\n * Capability: requires the entity to declare `publishable()`. Reads\n * (`getDraft`, `hasDraft`, `countDrafts`, `hasDraftBatch`) silently\n * return falsy when the entity doesn't support drafts; writes\n * (`saveDraft`, `mergeDraft`, `publishDraft`) throw `EntityCapabilityError`.\n */\n\nimport 'server-only'\n\nimport { blockTreeFieldsOf, type FieldConfig } from '@murumets-ee/entity'\nimport type { InferEntityDTO, InferUpdateInput } from '@murumets-ee/entity/admin'\nimport { diffBlocks } from './diff/block-diff.js'\nimport { diffFields } from './diff/field-diff.js'\nimport type { FieldDiff } from './diff/types.js'\nimport { DraftNotFoundError, EntityCapabilityError } from './errors.js'\nimport {\n applyLocaleRoutedUpdate,\n localeFindOptions,\n} from './internal/apply-locale-routed-update.js'\nimport { type ContentContext, getDraftsClient } from './internal/context.js'\nimport { projectToEntityFields } from './internal/projection.js'\nimport { DEFAULT_LOCALE_SENTINEL, validateLocale } from './locale-utils.js'\nimport { getContentConfig } from './plugin.js'\nimport type { DraftsTable } from './schema/drafts.js'\nimport { recordLocaleSave } from './translation-provenance.js'\nimport type { DraftEntry } from './types.js'\nimport { createVersionSnapshot } from './versions.js'\n\ntype DraftRow = NonNullable<Awaited<ReturnType<ReturnType<DraftsTable['makeClient']>['findOne']>>>\n\nfunction toDraftEntry(row: DraftRow): DraftEntry {\n return {\n id: row.id,\n entityId: row.entityId,\n locale: row.locale,\n data: row.data,\n createdBy: row.createdBy,\n createdByName: row.createdByName ?? null,\n createdAt: row.createdAt,\n updatedAt: row.updatedAt,\n }\n}\n\n/**\n * The live row behind a draft, in the draft's locale — `undefined` when it\n * cannot be read. Never throws: the caller treats an unreadable row as \"no\n * stored copy\", which is the strict answer.\n */\nasync function liveRow<F extends Record<string, FieldConfig>>(\n ctx: ContentContext<F>,\n entityId: string,\n locale: string,\n): Promise<Record<string, unknown> | undefined> {\n try {\n const row = await ctx.admin.findById(\n entityId,\n locale === DEFAULT_LOCALE_SENTINEL ? {} : { locale },\n )\n return (row as Record<string, unknown> | null) ?? undefined\n } catch (error) {\n ctx.logger?.warn(\n { entity: ctx.entity.name, entityId, error },\n 'draft: the live row could not be read to grandfather its block tree',\n )\n return undefined\n }\n}\n\n/**\n * What a draft save's block trees are judged AGAINST: the stored draft's tree\n * for a field the draft already holds, the live row's for one it does not.\n * The live row is read only in the second case.\n */\nasync function storedTreesFor<F extends Record<string, FieldConfig>>(\n ctx: ContentContext<F>,\n entityId: string,\n locale: string,\n projected: Record<string, unknown>,\n draftData: unknown,\n): Promise<Record<string, unknown> | undefined> {\n const draft =\n draftData !== null && typeof draftData === 'object'\n ? (draftData as Record<string, unknown>)\n : undefined\n const missing = blockTreeFieldsOf(ctx.entity).some(\n ({ name }) => Object.hasOwn(projected, name) && !Array.isArray(draft?.[name]),\n )\n if (!missing) return draft\n const live = await liveRow(ctx, entityId, locale)\n if (live === undefined) return draft\n return { ...live, ...draft }\n}\n\n/**\n * Save (upsert) a draft for an entity+locale. One draft per\n * entity+locale — overwrites any existing draft.\n *\n * `data` is projected through the entity's declared field whitelist\n * BEFORE it is stored (same `projectToEntityFields` call `publishDraft`\n * makes on the way out). Storing the caller's JSON verbatim let a draft\n * carry keys the entity never declared, identity/audit columns and\n * `internal: true` fields; publishing filtered them, but `getDraft` and\n * `compareDraftWithCurrent` echoed them straight back to the admin UI,\n * and the drafts table accumulated arbitrary caller-controlled JSON\n * (`plan/admin-api-hardening` F002). Validating at the write closes the\n * asymmetry — the stored draft is now always a subset of what the entity\n * can actually hold.\n */\nexport async function saveDraft<F extends Record<string, FieldConfig>>(\n ctx: ContentContext<F>,\n entityId: string,\n data: InferUpdateInput<F>,\n locale = DEFAULT_LOCALE_SENTINEL,\n user?: { id: string; name?: string },\n): Promise<DraftEntry<InferUpdateInput<F>>> {\n validateLocale(locale)\n const client = await getDraftsClient(ctx)\n if (!client) throw new EntityCapabilityError(ctx.entity.name, 'drafts')\n\n const projected = projectToEntityFields(ctx.entity, data as Record<string, unknown>)\n\n // `projectToEntityFields` is a field-NAME whitelist — it never inspects a\n // value, so a `field.blockTree()` column in a draft took arbitrary JSON, and\n // `editor-state` hands the stored draft back as the CANVAS BASE STATE\n // (editor F002). Publishing is already gated by the entity write path, but\n // waiting until publish means the editor loads a tree it cannot represent.\n // Same validator, same judgement — asked here because the draft blob carries\n // no Zod schema of its own.\n ctx.admin.assertBlockTreesValid(projected)\n // …and the STRICT judgement for a token-derived caller (agent-access D014):\n // a draft is published later by whoever presses Publish, so a tree a machine\n // could not store directly must not be parked here for a person to promote.\n // F116, same reasoning — and this is precisely the write path the finding\n // was filed against: dava's home-page DRAFT already holds a mismatched\n // media reference. Grandfathering against the draft ALREADY STORED (rather\n // than validating strictly) is what keeps that draft's next autosave\n // working instead of turning \"a broken image\" into \"a draft that can never\n // be saved again\".\n //\n // The lookup is skipped entirely when the PROJECTED payload carries no\n // block-tree field at all — `assertMediaKindsValid` would no-op anyway\n // (same optimization as `saveTranslation`'s), and most entities with\n // drafts have no block-tree field to begin with.\n const hasBlockTreeValue = blockTreeFieldsOf(ctx.entity).some(({ name }) =>\n Object.hasOwn(projected, name),\n )\n const existing = hasBlockTreeValue ? await client.findOne({ entityId, locale }) : null\n // Grandfathered against the draft already stored, like the media-kind check\n // below: a tree that was there before this save is not what this save adds.\n // With no draft yet, against the live row — a first draft of a document\n // whose live tree holds a block no longer placeable there must still save\n // (davatoidud-toolkit D006).\n await ctx.admin.assertBlockTreesFitDocument(\n projected,\n () => storedTreesFor(ctx, entityId, locale, projected, existing?.data),\n { loadAreaRow: () => liveRow(ctx, entityId, locale) },\n )\n await ctx.admin.assertMediaKindsValid(\n projected,\n existing?.data as Record<string, unknown> | undefined,\n )\n\n const now = new Date()\n const createdBy = user?.id ?? ''\n const createdByName = user?.name ?? null\n\n const row = await client.upsert(\n {\n entityId,\n locale,\n data: projected,\n createdBy,\n createdByName,\n createdAt: now,\n updatedAt: now,\n },\n {\n target: ['entityId', 'locale'],\n // On conflict, only update the mutable fields — preserve createdBy/createdAt.\n set: { data: projected, updatedAt: now },\n },\n )\n\n // What this locale was saved from (agent-access D017) — never fails the save.\n await recordLocaleSave({\n entityName: ctx.entity.name,\n entityId,\n locale,\n userId: user?.id,\n draftData: (row.data as Record<string, unknown> | undefined) ?? {},\n })\n return toDraftEntry(row) as DraftEntry<InferUpdateInput<F>>\n}\n\n/**\n * The keys that move a document's canonical URL in the patterns the toolkit\n * ships (`[slug]`, `[parent.path]`) plus the slug mode that decides whether a\n * clash is refused or auto-suffixed. A merge naming one of them, on a ROUTABLE\n * entity, runs the path-conflict check (see `mergeDraft`); any other merge\n * skips its lookups — the staged draft, the row, and `toolkit_paths` (twice\n * under a parent).\n *\n * A pattern built from another field (`/[category]/[slug]`) is not covered:\n * staging only `category` is refused at Publish rather than here.\n */\nconst PATH_KEYS = ['slug', 'slugMode', 'parent'] as const\n\n/**\n * Stage a PARTIAL change: merge `patch` into the entity+locale draft, creating\n * the draft if there is none. Keys not in `patch` are left exactly as the draft\n * (or, absent a draft key, the live row) has them.\n *\n * This is the write every editing surface uses since editor D019 — \"every edit\n * on every surface saves to the document's one shared draft\". `saveDraft`\n * REPLACES the blob, which is right for a surface that owns the whole document\n * (the menu editor) and wrong for one that owns a few fields of it: page\n * settings saving `title` through `saveDraft` would erase the block edits the\n * canvas staged a second earlier. A draft is therefore a patch over the row, and\n * every reader that shows editable values reads row ⊕ draft.\n *\n * Judged like the entity PATCH it replaces, BEFORE it is stored:\n * - projected through the field whitelist (`internal`, undeclared keys dropped)\n * - `assertBlockTreesValid` + `assertMediaKindsValid` (grandfathered against the\n * stored draft, same as `saveDraft`)\n * - `assertUpdateValid` — the entity's own update schema. `saveDraft` never ran\n * it, which was harmless while the form's Publish still PATCHed; moving a\n * surface into the draft must not move its refusal to Publish, where the\n * author is no longer looking at the field.\n * - `assertPathAvailable` — the path-conflict guard, as a dry run, when the\n * merge moves the URL (see {@link PATH_KEYS}) on a routable entity (F150).\n *\n * 🔴 ONE STATEMENT, not read-modify-write. The merge is `data || patch` inside\n * `ON CONFLICT DO UPDATE` (`TableClient.upsert`'s `mergeJsonb`), so it cannot\n * lose a concurrent write: a read-then-upsert that interleaved with op-commit's\n * or a bound field's stage would write back the draft as it was read — silently\n * reverting the other writer's change. `writeDraft` merges the same way, so\n * neither can erase the other. Top-level `||`, a SHALLOW merge.\n *\n * Resolves `null` when the projected patch is EMPTY and no draft exists: nothing\n * the entity declares was sent, so nothing is staged and no empty draft row is\n * created.\n *\n * ⚠️ The rest of the write path's hooks — `pathParent()`'s cycle check, the\n * partial-unique slug index, `sluggable()`'s regeneration — still run only at\n * Publish, inside its transaction, where a refusal stops the whole publish. The\n * path check here answers \"as of now\"; Publish runs the real guard again.\n */\nexport async function mergeDraft<F extends Record<string, FieldConfig>>(\n ctx: ContentContext<F>,\n entityId: string,\n patch: InferUpdateInput<F>,\n locale = DEFAULT_LOCALE_SENTINEL,\n user?: { id: string; name?: string },\n): Promise<DraftEntry<InferUpdateInput<F>> | null> {\n validateLocale(locale)\n const client = await getDraftsClient(ctx)\n if (!client) throw new EntityCapabilityError(ctx.entity.name, 'drafts')\n\n const projected = projectToEntityFields(ctx.entity, patch as Record<string, unknown>)\n // Nothing the entity declares: stage nothing. Upserting `{}` would CREATE an\n // empty draft, and the document would then read \"Draft saved · not live\n // yet\" about a change that does not exist.\n if (Object.keys(projected).length === 0) {\n const current = await client.findOne({ entityId, locale })\n return current ? (toDraftEntry(current) as DraftEntry<InferUpdateInput<F>>) : null\n }\n ctx.admin.assertBlockTreesValid(projected)\n ctx.admin.assertUpdateValid(projected)\n const hasBlockTreeValue = blockTreeFieldsOf(ctx.entity).some(({ name }) =>\n Object.hasOwn(projected, name),\n )\n const touchesPath =\n ctx.entity.frontend?.path !== undefined &&\n PATH_KEYS.some((key) => Object.hasOwn(projected, key))\n const existing =\n hasBlockTreeValue || touchesPath ? await client.findOne({ entityId, locale }) : null\n // The contextual judgement — the document's area for everyone, the strict\n // tree for a token-derived caller (agent-access D014) — with the stored\n // draft, or the live row when there is none, to grandfather against. See\n // `saveDraft`.\n await ctx.admin.assertBlockTreesFitDocument(\n projected,\n () => storedTreesFor(ctx, entityId, locale, projected, existing?.data),\n { loadAreaRow: () => liveRow(ctx, entityId, locale) },\n )\n await ctx.admin.assertMediaKindsValid(\n projected,\n existing?.data as Record<string, unknown> | undefined,\n )\n // A staged slug that another document's URL already holds is refused NOW,\n // beside the field the author typed it in — not first at Publish (editor\n // PR60, F150). Checked against what the draft will hold after this merge,\n // since an earlier stage may have set `slugMode` or `parent`.\n if (touchesPath) {\n const staged = {\n ...((existing?.data as Record<string, unknown> | undefined) ?? {}),\n ...projected,\n }\n if (locale === DEFAULT_LOCALE_SENTINEL) {\n await ctx.admin.assertPathAvailable(entityId, staged)\n } else {\n // Checked the way Publish writes it: `updateForLocale` sends a locale's\n // TRANSLATABLE fields through that locale's guard and the rest (a\n // `parent`, a non-translatable slug) through `update()`, whose guard\n // checks the default locale. One guard over everything would test a\n // shared `parent` against the wrong locale's URLs.\n const fields = ctx.entity.allFields as Record<string, { translatable?: boolean } | undefined>\n const translatable: Record<string, unknown> = {}\n const shared: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(staged)) {\n if (fields[key]?.translatable === true) translatable[key] = value\n else shared[key] = value\n }\n const moves = (part: Record<string, unknown>) =>\n PATH_KEYS.some((key) => Object.hasOwn(part, key) && Object.hasOwn(projected, key))\n if (moves(translatable)) await ctx.admin.assertPathAvailable(entityId, translatable, locale)\n if (moves(shared)) await ctx.admin.assertPathAvailable(entityId, shared)\n }\n }\n\n const now = new Date()\n const row = await client.upsert(\n {\n entityId,\n locale,\n data: projected,\n createdBy: user?.id ?? '',\n createdByName: user?.name ?? null,\n createdAt: now,\n updatedAt: now,\n },\n { target: ['entityId', 'locale'], set: { updatedAt: now }, mergeJsonb: ['data'] },\n )\n // What this locale was saved from (agent-access D017) — never fails the save.\n await recordLocaleSave({\n entityName: ctx.entity.name,\n entityId,\n locale,\n userId: user?.id,\n draftData: (row.data as Record<string, unknown> | undefined) ?? {},\n })\n return toDraftEntry(row) as DraftEntry<InferUpdateInput<F>>\n}\n\n/**\n * Get the draft for an entity+locale, or null if none exists (or the\n * entity doesn't support drafts).\n */\nexport async function getDraft<F extends Record<string, FieldConfig>>(\n ctx: ContentContext<F>,\n entityId: string,\n locale = DEFAULT_LOCALE_SENTINEL,\n): Promise<DraftEntry<InferUpdateInput<F>> | null> {\n validateLocale(locale)\n const client = await getDraftsClient(ctx)\n if (!client) return null\n const row = await client.findOne({ entityId, locale })\n return row ? (toDraftEntry(row) as DraftEntry<InferUpdateInput<F>>) : null\n}\n\n/**\n * Delete (discard) a draft for an entity+locale. Returns whether\n * anything was deleted; safely no-ops on entities without drafts.\n */\nexport async function deleteDraft(\n ctx: ContentContext,\n entityId: string,\n locale = DEFAULT_LOCALE_SENTINEL,\n): Promise<boolean> {\n validateLocale(locale)\n const client = await getDraftsClient(ctx)\n if (!client) return false\n const deleted = await client.deleteMany({ entityId, locale })\n // Discarding a draft changes the locale's working text back to the row's\n // (agent-access D017) — record it, or a discarded SOURCE edit keeps every\n // translation reading \"outdated\". `reverted`: nobody wrote a word, so an\n // agent's discard is not machine output. What this does NOT do: un-mark a\n // locale whose discarded draft was a machine translation — one row per locale\n // cannot say what the live row underneath was, so it keeps reading \"not\n // reviewed\" until someone reviews it or saves it.\n if (deleted.length > 0) {\n await recordLocaleSave({ entityName: ctx.entity.name, entityId, locale, reverted: true })\n }\n return deleted.length > 0\n}\n\n/**\n * Publish a draft: make THIS document's staged changes live.\n *\n * \"Publish\" means one thing on every surface (editor D019): the draft's fields\n * are written to the row for the draft's locale AND the row is put live. The\n * draft is then gone and, if versionable, a version snapshot records what went\n * live.\n *\n * Locale routing mirrors the admin PATCH handler (and the taxonomy fix\n * in 10a7cc2b): a default-locale draft writes the base row; a\n * non-default-locale draft routes translatable fields to\n * `saveTranslation` (→ `{entity}_translations`), `status` to the\n * per-locale status table, and only non-translatable fields (which have\n * no per-locale home) to the base row. Without this split, publishing\n * an `et` draft overwrote the default-locale base row wholesale.\n *\n * ## ONE TRANSACTION (editor PR60, R055 §4)\n *\n * The row write, the locale status, `_overrides`, the draft delete and the\n * version snapshot commit together or not at all. They used to be five separate\n * statements, so a failure part-way left a document whose content was live and\n * whose draft still claimed to be pending — or, worse, whose draft was gone while\n * the row write had not landed.\n *\n * The draft is CLAIMED first, by deleting it and publishing what the delete\n * returned. The delete takes the row lock, so an op-commit that is mid-flight on\n * the same draft either committed before (and its edit is in what we publish) or\n * blocks until we commit and then retries its SERIALIZABLE transaction — or, if it\n * had not read the draft yet, inserts a fresh draft holding only its own patch.\n * Either way it does not write a stale copy back over the published one. The editor also flushes and awaits its own in-flight saves\n * before it calls this, so the lock is the backstop, not the mechanism.\n *\n * Path-index and write notifications fire after COMMIT, not inside it —\n * `AdminClient.afterCommit` defers them on a tracked transaction.\n */\nexport async function publishDraft<F extends Record<string, FieldConfig>>(\n ctx: ContentContext<F>,\n entityId: string,\n locale = DEFAULT_LOCALE_SENTINEL,\n user?: { id: string; name?: string },\n): Promise<InferEntityDTO<F>> {\n validateLocale(locale)\n if (!(await getDraftsClient(ctx))) {\n throw new EntityCapabilityError(ctx.entity.name, 'drafts')\n }\n\n // Previous state for the version delta — locale-merged, so the delta compares\n // against what this locale's readers actually saw. Read BEFORE the\n // transaction: it is the committed state the publish replaces.\n const previousState: InferEntityDTO<F> | null = ctx.versionableOptions\n ? await ctx.admin.findById(entityId, localeFindOptions(locale))\n : null\n\n return ctx.db.transaction(async (tx) => {\n // Every table client below binds to `tx` through this context — drafts,\n // locale status, versions and the `_version` column write.\n const txCtx: ContentContext<F> = { ...ctx, db: tx }\n const draftsClient = await getDraftsClient(txCtx)\n if (!draftsClient) throw new EntityCapabilityError(ctx.entity.name, 'drafts')\n const [claimed] = await draftsClient.deleteMany({ entityId, locale })\n if (!claimed) {\n throw new DraftNotFoundError(entityId, locale)\n }\n\n // `?? {}` because the column is `jsonb NOT NULL`, and that forbids SQL NULL\n // while permitting the JSON literal `null` — which deserializes to JS `null`.\n // A bare cast then made `draftData.status` a TypeError, so a malformed row\n // 500'd the publish route instead of taking the ordinary \"nothing declared,\n // publish the row as-is\" path below. Nothing in this package writes such a\n // row; a seed, a migration or a hand-edit can.\n const claimedData = (claimed.data ?? {}) as Record<string, unknown>\n // `publishedAt` is Publish's to set, like `status` below: a staged value\n // would let whoever wrote the draft back- or forward-date the publication.\n // publishable()'s hook fills it when the UPDATE carries none — which, with\n // the staged value dropped, is every publish: it records the LATEST\n // publication, not the first.\n const { publishedAt: _stagedPublishedAt, ...draftData } = claimedData\n // \"Publish\" means MAKE LIVE, always — the status is not the draft's to\n // decide. Block-editor drafts carry no `status` at all, and before D019 a\n // form-saved draft could carry `status: 'draft'`, which then won: Publish\n // wrote the content and left the document unpublished, so the same button\n // meant \"publish\" on one surface and \"stage\" on another. The publishable()\n // behavior auto-sets `publishedAt` on the transition. The publish-permission\n // gate lives in the admin route, not here.\n const updateData = projectToEntityFields(ctx.entity, { ...draftData, status: 'published' })\n const result = await applyLocaleRoutedUpdate(txCtx, entityId, updateData, locale, tx)\n\n // F009 — promote the page's chrome overrides.\n //\n // `projectToEntityFields` drops every `internal: true` field, deliberately, so\n // `_overrides` cannot ride the generic promotion. That guard is NOT relaxed:\n // this is one named field, written through the trusted `updateInternal` path\n // that `with-overrides.ts` documents as \"the only path that can mutate it\".\n // Before F009 that call site did not exist, so an override survived in the\n // draft buffer and never reached the column — the op committed, the canvas\n // updated, and a reload brought the hidden header back.\n //\n // AFTER the main update, so the override never lands against content that\n // failed to — and inside the same transaction, so neither lands alone.\n // `_overrides` is not translatable, so it belongs on the base row for every\n // locale.\n const overrides = readOverridesForPublish(ctx.entity, draftData)\n if (overrides !== undefined) {\n await ctx.admin.updateInternal(entityId, { _overrides: overrides }, { tx })\n }\n\n if (ctx.versionableOptions) {\n await createVersionSnapshot(txCtx, entityId, result, previousState, locale, user)\n }\n\n return result\n })\n}\n\n/**\n * The page's override map from a draft payload, when the entity declares the\n * field and the draft carries one.\n *\n * Returns `undefined` — never `{}` — so an ordinary content publish does not\n * touch the column. Shape-guarded because a draft payload is stored jsonb: an\n * array or a scalar is malformed data, not an override map. ← F009\n */\nfunction readOverridesForPublish(\n entity: { allFields: Record<string, unknown>; behaviors?: readonly { name: string }[] },\n draftData: Record<string, unknown>,\n): Record<string, unknown> | undefined {\n // The BEHAVIOR, not just a field with the right name — a draft payload is\n // stored jsonb and can be crafted or legacy, so this must not become a way\n // to promote arbitrary JSON into an unrelated internal field on an entity\n // that never opted in. Requiring the behavior also means `beforeUpdate` runs\n // `validateOverridesMap` on the way through `updateInternal`.\n if (!(entity.behaviors ?? []).some((b) => b.name === 'withOverrides')) return undefined\n const field = entity.allFields._overrides as { internal?: boolean } | undefined\n if (field === undefined || field.internal !== true) return undefined\n const value = draftData._overrides\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return undefined\n return value as Record<string, unknown>\n}\n\n/**\n * Quick existence check for list badges — does a draft exist?\n */\nexport async function hasDraft(\n ctx: ContentContext,\n entityId: string,\n locale = DEFAULT_LOCALE_SENTINEL,\n): Promise<boolean> {\n validateLocale(locale)\n const client = await getDraftsClient(ctx)\n if (!client) return false\n return client.exists({ entityId, locale })\n}\n\n/**\n * Count drafts for this entity type, optionally filtered by locale.\n * Single indexed COUNT — used by dashboard widgets.\n */\nexport async function countDrafts(\n ctx: ContentContext,\n locale = DEFAULT_LOCALE_SENTINEL,\n): Promise<number> {\n validateLocale(locale)\n const client = await getDraftsClient(ctx)\n if (!client) return 0\n return client.count({ locale })\n}\n\n/**\n * Check draft existence for multiple entities in one query. Returns\n * a set of entity IDs that have a draft for `locale`.\n */\nexport async function hasDraftBatch(\n ctx: ContentContext,\n entityIds: string[],\n locale = DEFAULT_LOCALE_SENTINEL,\n): Promise<Set<string>> {\n validateLocale(locale)\n const result = new Set<string>()\n if (entityIds.length === 0) return result\n const client = await getDraftsClient(ctx)\n if (!client) return result\n\n const rows = await client.findMany({\n where: { entityId: { in: entityIds }, locale },\n })\n for (const row of rows) {\n result.add(row.entityId as string)\n }\n return result\n}\n\n/**\n * Compare the current draft with the live entity. Returns field-level\n * diffs between the published data and the draft (only for fields\n * present in the draft — missing fields are NOT \"changed to empty\").\n */\nexport async function compareDraftWithCurrent<F extends Record<string, FieldConfig>>(\n ctx: ContentContext<F>,\n entityId: string,\n locale = DEFAULT_LOCALE_SENTINEL,\n): Promise<{\n diffs: FieldDiff[]\n current: InferEntityDTO<F>\n draft: DraftEntry<InferUpdateInput<F>>\n} | null> {\n validateLocale(locale)\n const draft = await getDraft(ctx, entityId, locale)\n if (!draft) return null\n\n // Fetch the live entity with the same locale context as the draft.\n const config = getContentConfig()\n const defaultLocale = config.defaultLocale\n const findOptions =\n locale === DEFAULT_LOCALE_SENTINEL ? { defaultLocale } : { locale, defaultLocale }\n const current = await ctx.admin.findById(entityId, findOptions)\n if (!current) return null\n\n const fieldConfigs = ctx.entity.allFields as Record<string, FieldConfig> | undefined\n const currentRecord = current as Record<string, unknown>\n const draftRecord = draft.data as Record<string, unknown>\n const currentSubset: Record<string, unknown> = {}\n for (const key of Object.keys(draftRecord)) {\n currentSubset[key] = currentRecord[key]\n }\n const diffs = diffFields(currentSubset, draftRecord, fieldConfigs)\n for (const diff of diffs) {\n if (diff.type === 'blockTree') {\n // Normalize a null/undefined side to [] so add/clear of the whole field\n // (null ↔ blockTree[]) still produces a structural diff, not an opaque one.\n diff.blockDiffs = diffBlocks(\n Array.isArray(diff.from) ? diff.from : [],\n Array.isArray(diff.to) ? diff.to : [],\n )\n }\n }\n\n return { diffs, current, draft }\n}\n","/**\n * Per-locale publish status — independent draft/published state for\n * each locale of a publishable + translatable entity.\n *\n * Capability: requires `publishable() + at least one translatable\n * field` (the `_locale_status` table is registered only for that\n * combination). Reads silently return falsy on entities without it;\n * `setLocaleStatus` throws `EntityCapabilityError`.\n */\n\nimport 'server-only'\n\nimport type { FieldConfig } from '@murumets-ee/entity'\nimport type { InferUpdateInput } from '@murumets-ee/entity/admin'\nimport { EntityCapabilityError } from './errors.js'\nimport { type ContentContext, getLocaleStatusClient } from './internal/context.js'\nimport { upsertLocaleStatusRow } from './locale-status-slot.js'\nimport { validateLocale } from './locale-utils.js'\nimport { getContentConfig } from './plugin.js'\nimport type { LocalePublishStatus } from './types.js'\n\n/**\n * Get per-locale publish status overrides for an entity.\n * Missing locale = inherits the base entity status (no row written).\n *\n * **Not permission-gated, deliberately — see {@link getLocaleStatusBatch}.**\n */\nexport async function getLocaleStatus(\n ctx: ContentContext,\n entityId: string,\n): Promise<LocalePublishStatus[]> {\n const map = await getLocaleStatusBatch(ctx, [entityId])\n const entry = map.get(entityId)\n if (!entry) return []\n return Object.values(entry)\n}\n\n/**\n * Set per-locale publish status. Upserts into the locale_status\n * table — except when `locale === defaultLocale`, which updates the\n * base entity status column directly (the per-locale table only\n * stores overrides for non-default locales).\n *\n * **Both branches are publish-gated by the entity layer (D041).** The default\n * branch inherits it from `AdminClient.update`; the non-default branch routes\n * through `AdminClient.updateForLocale`, which asserts the SAME\n * `assertPublishAuthority` from the caller's payload before it hands the write\n * to the locale-status writer. This is deliberately a delegation and not a\n * second predicate in this package: `<entity>_locale_status` is the table the\n * public read predicate (`COALESCE(locale_status.status, main.status)`) resolves\n * against, so a direct `TableClient.upsert` here — which is what this function\n * used to do — is a fourth publish door, reachable from any plugin/route/job\n * holding a `ContentClient` (a PUBLIC subpath export) with no `publish` grant\n * ever consulted.\n */\nexport async function setLocaleStatus<F extends Record<string, FieldConfig>>(\n ctx: ContentContext<F>,\n entityId: string,\n locale: string,\n status: 'draft' | 'published',\n): Promise<void> {\n validateLocale(locale)\n const config = getContentConfig()\n\n // Default locale → update base entity status column.\n if (locale === config.defaultLocale) {\n const data: Record<string, unknown> = { status }\n if (status === 'published') data.publishedAt = new Date()\n await ctx.admin.update(entityId, data as InferUpdateInput<F>)\n return\n }\n\n const client = await getLocaleStatusClient(ctx)\n if (!client) {\n // Per-locale status only exists for publishable + translatable\n // entities. Calling on a non-translatable publishable (where the\n // only valid locale is the default) is a programmer error.\n // Checked BEFORE delegating: `updateForLocale` would otherwise fall back to\n // the base `status` column for a missing writer, silently publishing the\n // default locale instead of refusing.\n throw new EntityCapabilityError(ctx.entity.name, 'localeStatus')\n }\n\n // The writer we hand down is the RAW upsert, not this function — the\n // delegation terminates here rather than re-entering `updateForLocale`.\n //\n // Routing through `updateForLocale` rather than calling the upsert directly\n // is what closes the publish door: this branch used to write\n // `<entity>_locale_status` with no permission check at all, so any holder of\n // this public export could make a translation publicly live without\n // `publish`. `updateForLocale` asserts publish authority at the operation\n // entry (D041), so the gate is inherited rather than duplicated here.\n //\n // Widened through `Record<string, unknown>` for the same reason the\n // default-locale branch above does it: `InferUpdateInput<F>` is keyed on the\n // entity's own field map, which a generic `F` cannot be proven to overlap.\n const localeData: Record<string, unknown> = { status }\n await ctx.admin.updateForLocale(entityId, localeData as InferUpdateInput<F>, locale, {\n defaultLocale: config.defaultLocale,\n localeStatusWriter: (id, loc, s) => upsertLocaleStatusRow(client, id, loc, s),\n })\n}\n\n/**\n * Get per-locale publish status for multiple entities in one query.\n *\n * ## Why this read is NOT permission-gated (and what would gate it)\n *\n * It returns publish-state METADATA only — `{ locale, status, publishedAt }` —\n * never field data, so it is not a content-disclosure door the way the write\n * side above is a publish door. What it does expose is an existence oracle for\n * unpublished TRANSLATIONS: a principal without `view_unpublished` learns that\n * `et` is a draft, which `QueryClient` would have hidden. The correct predicate\n * is therefore `view_unpublished` (D017), NOT `publish`.\n *\n * A CodeRabbit pass proposed gating it on exactly that predicate. Deliberately\n * declined, on the strength of **F063**: `view_unpublished` governs `QueryClient`\n * reads — the PUBLIC delivery surface — and is not a disclosure boundary over\n * the admin API, where `AdminClient` shows editors their own drafts by design.\n * `ContentClient` is an in-process server-side API whose consumers are plugins,\n * routes and jobs on the admin side, so gating it here would extend the control\n * onto the surface F063 explicitly recommended NOT extending it to. The concrete\n * cost would be an editor lacking `view_unpublished` no longer able to see that\n * their OWN translation is still a draft.\n *\n * The asymmetry with the write side above is real, not convenient:\n * `setLocaleStatus` MINTS public visibility, so it is gated regardless of which\n * surface calls it. This read hands publish-state metadata to a caller who\n * already holds `view` on the row — they needed its id to ask.\n *\n * It is not applied here because the predicate (`mayViewUnpublishedEntity`) is\n * module-private to `@murumets-ee/entity` — re-deriving it in this package\n * would create exactly the second, drifting copy of a security predicate that\n * D041 exists to eliminate, and there is no read-path equivalent of\n * `updateForLocale` to delegate to. The one in-repo caller\n * (`admin-ui`'s versions route) is already gated by `checkPermission`. Closing\n * this properly means exporting the predicate from `@murumets-ee/entity` and\n * dropping non-`published` rows for principals without it — tracked as the\n * read-side sibling of F060.\n */\nexport async function getLocaleStatusBatch(\n ctx: ContentContext,\n entityIds: string[],\n): Promise<Map<string, Record<string, LocalePublishStatus>>> {\n const result = new Map<string, Record<string, LocalePublishStatus>>()\n if (entityIds.length === 0) return result\n const client = await getLocaleStatusClient(ctx)\n if (!client) return result\n\n const rows = await client.findMany({ where: { entityId: { in: entityIds } } })\n for (const r of rows) {\n const eid = r.entityId as string\n const locale = r.locale as string\n let entry = result.get(eid)\n if (!entry) {\n entry = {}\n result.set(eid, entry)\n }\n entry[locale] = {\n locale,\n status: r.status as 'draft' | 'published',\n publishedAt: (r.publishedAt as Date | null) ?? null,\n }\n }\n return result\n}\n","/**\n * Translation status reporting — per-locale completion of translatable\n * fields for one entity, batches of entities, or the whole entity type.\n *\n * Capability: requires the entity to have at least one translatable\n * field. All methods return falsy / empty when the entity has no\n * translatable fields (read-only and defensive).\n */\n\nimport 'server-only'\n\nimport { getContext, requireSiteFor } from '@murumets-ee/core'\nimport { schemaRegistry } from '@murumets-ee/db'\nimport { buildPartitionCondition, type FieldConfig } from '@murumets-ee/entity'\nimport { and, inArray } from 'drizzle-orm'\nimport { InvalidLocaleError } from './errors.js'\nimport type { ContentContext } from './internal/context.js'\nimport { getContentConfig } from './plugin.js'\nimport { getTranslationProvenanceBatch, translationFreshness } from './translation-provenance.js'\nimport type { TranslationReport, TranslationStatus } from './types.js'\n\n/**\n * The locales a status report covers and the default it skips: the request's\n * — which the admin narrows to its SITE's locales and default (plan `multisite`\n * phase 03) — else the configured content locales.\n */\nfunction statusLocales(): { locales: { code: string }[]; defaultLocale: string } {\n const config = getContentConfig()\n const ctx = getContext()\n const codes = ctx?.availableLocales ?? config.locales.map((l) => l.code)\n return {\n locales: codes.map((code) => ({ code })),\n defaultLocale: ctx?.defaultLocale ?? config.defaultLocale,\n }\n}\n\n/**\n * For one entity, compute per-locale completion status across every\n * translatable field. Default-locale rows are skipped.\n */\nfunction computeStatusForEntity(\n translatableFields: string[],\n translatedByLocale: Map<string, Record<string, unknown>> | undefined,\n locales: { code: string }[],\n defaultLocale: string,\n): TranslationStatus {\n const status: TranslationStatus = {}\n for (const locale of locales) {\n if (locale.code === defaultLocale) continue\n const translated = translatedByLocale?.get(locale.code) ?? {}\n const missing: string[] = []\n for (const fieldName of translatableFields) {\n if (translated[fieldName] === undefined || translated[fieldName] === null) {\n missing.push(fieldName)\n }\n }\n status[locale.code] = {\n complete: missing.length === 0,\n total: translatableFields.length,\n translated: translatableFields.length - missing.length,\n missing,\n }\n }\n return status\n}\n\n/**\n * Get translation status for an entity — per-locale completion report.\n */\nexport async function getTranslationStatus(\n ctx: ContentContext,\n entityId: string,\n): Promise<TranslationStatus> {\n // Single-entity is the batch path with one ID — keeps the two\n // codepaths from drifting.\n const map = await getTranslationStatusBatch(ctx, [entityId])\n return map.get(entityId) ?? {}\n}\n\n/**\n * Get translation status for multiple entities in a single query.\n * O(1) DB roundtrips regardless of `entityIds.length`.\n */\nexport async function getTranslationStatusBatch(\n ctx: ContentContext,\n entityIds: string[],\n): Promise<Map<string, TranslationStatus>> {\n const result = new Map<string, TranslationStatus>()\n if (entityIds.length === 0) return result\n\n const { locales, defaultLocale } = statusLocales()\n\n const translatableFields = Object.entries(ctx.entity.allFields as Record<string, FieldConfig>)\n .filter(([_, f]) => f.translatable)\n .map(([name]) => name)\n if (translatableFields.length === 0) return result\n\n // Translation tables are generated in @murumets-ee/entity (with FK\n // refs); accessed via schemaRegistry + direct Drizzle here.\n const translationTable = schemaRegistry.get(`${ctx.entity.name}_translations`)\n if (!translationTable) return result\n\n // A site-bound entity's translation rows are confined to the request's\n // site (multisite D003): ids alone are no boundary — a caller holding\n // another site's id must learn nothing about its translations.\n const site = await requireSiteFor(ctx.entity)\n const byIds = inArray(translationTable.entityId, entityIds)\n const translations = await ctx.db\n .select()\n .from(translationTable)\n .where(\n site !== undefined\n ? and(byIds, buildPartitionCondition(translationTable, { site }, ctx.entity.name))\n : byIds,\n )\n\n // Group: entityId → locale → { fieldName: value }\n const translationsByEntity = new Map<string, Map<string, Record<string, unknown>>>()\n for (const t of translations) {\n const row = t as Record<string, unknown>\n const eid = row.entityId as string\n const locale = row.locale as string\n const fieldValues: Record<string, unknown> = {}\n for (const fieldName of translatableFields) {\n fieldValues[fieldName] = row[fieldName]\n }\n let entry = translationsByEntity.get(eid)\n if (!entry) {\n entry = new Map()\n translationsByEntity.set(eid, entry)\n }\n entry.set(locale, fieldValues)\n }\n\n // What each locale was last saved from (agent-access D017) — one more query\n // for the whole batch, a comparison of stored hashes per locale after that.\n const provenance = await getTranslationProvenanceBatch(ctx.entity.name, entityIds, ctx.db)\n\n for (const entityId of entityIds) {\n const status = computeStatusForEntity(\n translatableFields,\n translationsByEntity.get(entityId),\n locales,\n defaultLocale,\n )\n const byLocale = provenance.get(entityId)\n for (const [locale, entry] of Object.entries(status)) {\n const freshness = translationFreshness(byLocale, locale)\n if (freshness) entry.freshness = freshness\n }\n result.set(entityId, status)\n }\n\n return result\n}\n\nconst EMPTY_REPORT: TranslationReport = {\n total: 0,\n complete: 0,\n partial: 0,\n missing: 0,\n outdated: 0,\n machineUnreviewed: 0,\n}\n\n/**\n * Roll up translation status across every entity of this type.\n *\n * Defaults to the first non-default configured locale; pass\n * `options.locale` to target a specific one. Returns counts of\n * complete / partial / missing entities for that locale.\n */\nexport async function getTranslationReport(\n ctx: ContentContext,\n options?: { locale?: string },\n): Promise<TranslationReport> {\n const { locales, defaultLocale } = statusLocales()\n const targetLocale = options?.locale ?? locales.find((l) => l.code !== defaultLocale)?.code\n if (!targetLocale) return { ...EMPTY_REPORT }\n // A locale the site does not serve has no report on that site.\n if (!locales.some((l) => l.code === targetLocale)) {\n throw new InvalidLocaleError(\n targetLocale,\n locales.map((l) => l.code),\n )\n }\n\n const entities = await ctx.admin.findMany()\n if (entities.length === 0) return { ...EMPTY_REPORT }\n\n // Single batched query covers every entity at once.\n const statusMap = await getTranslationStatusBatch(\n ctx,\n entities.map((e) => e.id),\n )\n\n let complete = 0\n let partial = 0\n let missing = 0\n let outdated = 0\n let machineUnreviewed = 0\n for (const entity of entities) {\n const status = statusMap.get(entity.id)\n const localeStatus = status?.[targetLocale]\n if (!localeStatus || localeStatus.translated === 0) missing++\n else if (localeStatus.complete) complete++\n else partial++\n // Independent of the three above: a draft translation is \"missing\" (not\n // live yet) and can be machine-unreviewed, or outdated, at the same time.\n if (localeStatus?.freshness?.outdated === true) outdated++\n if (localeStatus?.freshness?.machineUnreviewed === true) machineUnreviewed++\n }\n\n return { total: entities.length, complete, partial, missing, outdated, machineUnreviewed }\n}\n","/**\n * ContentClient — thin shell over per-feature modules.\n *\n * Wraps AdminClient with version history (`./versions.ts`), draft\n * overlays (`./drafts.ts`), translation status reporting\n * (`./translation-status.ts`), per-locale publish status\n * (`./locale-status.ts`), and block-layout operations (`./layout.ts`).\n *\n * The class is generic over the entity's `AllFields` map: when\n * constructed with a typed entity, every method's input/output is\n * inferred end-to-end. When constructed with a runtime `Entity`\n * (admin-ui's heterogeneous entity loops), the generic defaults to\n * `Record<string, FieldConfig>` and methods accept/return the loose\n * shape — same behavior as the pre-generic version.\n *\n * Usage:\n * import { createContentClient } from '@murumets-ee/content/client'\n * const pages = createContentClient(Page)\n * await pages.create({ title: 'Hello', layout: [...] })\n */\n\nimport 'server-only'\n\nimport { getApp, type Logger } from '@murumets-ee/core'\nimport { createAdminClient } from '@murumets-ee/core/clients'\nimport type { Entity, FieldConfig } from '@murumets-ee/entity'\nimport type {\n AdminClient,\n FindManyOptions,\n InferCreateInput,\n InferEntityDTO,\n InferUpdateInput,\n} from '@murumets-ee/entity/admin'\nimport { getVersionableOptions } from './behaviors/versionable.js'\nimport {\n compareDraftWithCurrent,\n countDrafts,\n deleteDraft,\n getDraft,\n hasDraft,\n hasDraftBatch,\n mergeDraft,\n publishDraft,\n saveDraft,\n} from './drafts.js'\nimport { type ContentContext, createContentContext } from './internal/context.js'\nimport { calculateDelta } from './internal/projection.js'\nimport { getLocaleStatus, getLocaleStatusBatch, setLocaleStatus } from './locale-status.js'\nimport {\n getTranslationReport,\n getTranslationStatus,\n getTranslationStatusBatch,\n} from './translation-status.js'\nimport {\n compareVersions,\n createVersionSnapshot,\n getVersion,\n getVersions,\n pruneVersions,\n restoreVersion,\n saveVersionSnapshot,\n writeVersionColumn,\n} from './versions.js'\n\nexport interface ContentClientConfig<\n AllFields extends Record<string, FieldConfig> = Record<string, FieldConfig>,\n> {\n admin: AdminClient<AllFields>\n entity: Entity<AllFields>\n logger?: Logger\n}\n\nexport class ContentClient<\n AllFields extends Record<string, FieldConfig> = Record<string, FieldConfig>,\n> {\n private ctx: ContentContext<AllFields>\n\n constructor(config: ContentClientConfig<AllFields>) {\n const versionableOptions = getVersionableOptions(config.entity.behaviors)\n this.ctx = createContentContext(config, versionableOptions)\n }\n\n // -----------------------------------------------------------------\n // CRUD (delegated to AdminClient + version snapshots)\n // -----------------------------------------------------------------\n\n async create(data: InferCreateInput<AllFields>): Promise<InferEntityDTO<AllFields>> {\n const result = await this.ctx.admin.create(data)\n if (this.ctx.versionableOptions) {\n await saveVersionSnapshot(this.ctx, result.id, result, null, false)\n }\n return result\n }\n\n findById(id: string, options?: { locale?: string }): Promise<InferEntityDTO<AllFields> | null> {\n return this.ctx.admin.findById(id, options)\n }\n\n findMany(options?: FindManyOptions): Promise<InferEntityDTO<AllFields>[]> {\n return this.ctx.admin.findMany(options)\n }\n\n /**\n * Base-row update + version snapshot. Subject to AdminClient's\n * cross-locale write guard (SD021): under a non-default request-context\n * locale, translatable fields throw `CrossLocaleWriteError` — that's\n * enforcement, not a gap. Locale-belonging writes go through the draft\n * flow (`saveDraft` → `publishDraft`) or `admin.updateForLocale` directly.\n */\n async update(id: string, data: InferUpdateInput<AllFields>): Promise<InferEntityDTO<AllFields>> {\n let previousState: InferEntityDTO<AllFields> | null = null\n if (this.ctx.versionableOptions) {\n previousState = await this.ctx.admin.findById(id)\n }\n\n const result = await this.ctx.admin.update(id, data)\n\n if (this.ctx.versionableOptions && previousState) {\n const delta = calculateDelta(previousState, result)\n const version = await saveVersionSnapshot(this.ctx, id, result, delta, false)\n if (version !== undefined) {\n await writeVersionColumn(this.ctx, id, version)\n await pruneVersions(this.ctx, id)\n return { ...result, _version: version } as InferEntityDTO<AllFields>\n }\n await pruneVersions(this.ctx, id)\n }\n\n return result\n }\n\n delete(id: string): Promise<unknown> {\n return this.ctx.admin.delete(id)\n }\n\n // -----------------------------------------------------------------\n // Translation delegation\n // -----------------------------------------------------------------\n\n saveTranslation(entityId: string, locale: string, translations: Record<string, unknown>) {\n return this.ctx.admin.saveTranslation(entityId, locale, translations)\n }\n\n deleteTranslation(entityId: string, locale?: string) {\n return this.ctx.admin.deleteTranslation(entityId, locale)\n }\n\n // -----------------------------------------------------------------\n // Version history\n // -----------------------------------------------------------------\n\n getVersions(entityId: string, options?: { limit?: number; offset?: number; locale?: string }) {\n return getVersions(this.ctx, entityId, options)\n }\n\n getVersion(entityId: string, version: number, locale?: string) {\n return getVersion(this.ctx, entityId, version, locale)\n }\n\n compareVersions(entityId: string, v1: number, v2: number, locale?: string) {\n return compareVersions(this.ctx, entityId, v1, v2, locale)\n }\n\n restoreVersion(entityId: string, version: number, locale?: string) {\n return restoreVersion(this.ctx, entityId, version, locale)\n }\n\n pruneVersions(entityId: string, locale?: string) {\n return pruneVersions(this.ctx, entityId, locale)\n }\n\n createVersionSnapshot(\n entityId: string,\n currentData: Record<string, unknown>,\n previousData?: Record<string, unknown> | null,\n locale?: string,\n user?: { id: string; name?: string },\n ) {\n return createVersionSnapshot(this.ctx, entityId, currentData, previousData, locale, user)\n }\n\n // -----------------------------------------------------------------\n // Translation status\n // -----------------------------------------------------------------\n\n getTranslationStatus(entityId: string) {\n return getTranslationStatus(this.ctx, entityId)\n }\n\n getTranslationStatusBatch(entityIds: string[]) {\n return getTranslationStatusBatch(this.ctx, entityIds)\n }\n\n getTranslationReport(options?: { locale?: string }) {\n return getTranslationReport(this.ctx, options)\n }\n\n // -----------------------------------------------------------------\n // Per-locale publish status\n // -----------------------------------------------------------------\n\n getLocaleStatus(entityId: string) {\n return getLocaleStatus(this.ctx, entityId)\n }\n\n setLocaleStatus(entityId: string, locale: string, status: 'draft' | 'published') {\n return setLocaleStatus(this.ctx, entityId, locale, status)\n }\n\n getLocaleStatusBatch(entityIds: string[]) {\n return getLocaleStatusBatch(this.ctx, entityIds)\n }\n\n // -----------------------------------------------------------------\n // Drafts\n // -----------------------------------------------------------------\n\n saveDraft(\n entityId: string,\n data: InferUpdateInput<AllFields>,\n locale?: string,\n user?: { id: string; name?: string },\n ) {\n return saveDraft(this.ctx, entityId, data, locale, user)\n }\n\n mergeDraft(\n entityId: string,\n patch: InferUpdateInput<AllFields>,\n locale?: string,\n user?: { id: string; name?: string },\n ) {\n return mergeDraft(this.ctx, entityId, patch, locale, user)\n }\n\n getDraft(entityId: string, locale?: string) {\n return getDraft(this.ctx, entityId, locale)\n }\n\n deleteDraft(entityId: string, locale?: string) {\n return deleteDraft(this.ctx, entityId, locale)\n }\n\n publishDraft(entityId: string, locale?: string, user?: { id: string; name?: string }) {\n return publishDraft(this.ctx, entityId, locale, user)\n }\n\n hasDraft(entityId: string, locale?: string) {\n return hasDraft(this.ctx, entityId, locale)\n }\n\n countDrafts(locale?: string) {\n return countDrafts(this.ctx, locale)\n }\n\n hasDraftBatch(entityIds: string[], locale?: string) {\n return hasDraftBatch(this.ctx, entityIds, locale)\n }\n\n compareDraftWithCurrent(entityId: string, locale?: string) {\n return compareDraftWithCurrent(this.ctx, entityId, locale)\n }\n}\n\n/**\n * Factory — creates a ContentClient for an entity. Must be called\n * after `createApp()`. Generic flows from the entity definition:\n * `createContentClient(Article)` returns a `ContentClient<typeof\n * Article['allFields']>` typed end-to-end.\n */\nexport function createContentClient<AllFields extends Record<string, FieldConfig>>(\n entity: Entity<AllFields>,\n): ContentClient<AllFields> {\n const admin = createAdminClient(entity)\n return new ContentClient<AllFields>({\n admin,\n entity,\n logger: getApp().logger.child({ content: entity.name }),\n })\n}\n"],"mappings":"q1BAgCA,SAAS,EAAa,EAA2B,CAC/C,MAAO,CACL,GAAI,EAAI,GACR,SAAU,EAAI,SACd,OAAQ,EAAI,OACZ,KAAM,EAAI,KACV,UAAW,EAAI,UACf,cAAe,EAAI,eAAiB,KACpC,UAAW,EAAI,UACf,UAAW,EAAI,SACjB,CACF,CAOA,eAAe,EACb,EACA,EACA,EAC8C,CAC9C,GAAI,CAKF,OAAQ,MAJU,EAAI,MAAM,SAC1B,EACA,IAAA,IAAqC,CAAC,EAAI,CAAE,QAAO,CACrD,GACkD,IAAA,EACpD,OAAS,EAAO,CACd,EAAI,QAAQ,KACV,CAAE,OAAQ,EAAI,OAAO,KAAM,WAAU,OAAM,EAC3C,qEACF,EACA,MACF,CACF,CAOA,eAAe,EACb,EACA,EACA,EACA,EACA,EAC8C,CAC9C,IAAM,EACkB,OAAO,GAAc,UAA3C,EACK,EACD,IAAA,GAIN,GAAI,CAHY,EAAkB,EAAI,MAAM,CAAC,CAAC,MAC3C,CAAE,UAAW,OAAO,OAAO,EAAW,CAAI,GAAK,CAAC,MAAM,QAAQ,IAAQ,EAAK,CAEnE,EAAG,OAAO,EACrB,IAAM,EAAO,MAAM,EAAQ,EAAK,EAAU,CAAM,EAEhD,OADI,IAAS,IAAA,GAAkB,EACxB,CAAE,GAAG,EAAM,GAAG,CAAM,CAC7B,CAiBA,eAAsB,EACpB,EACA,EACA,EACA,EAAA,IACA,EAC0C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globalThis[e];if(!t)throw Error(`@murumets-ee/content plugin not initialized. Add content() to your plugins array.`);return t}export{t as n,n as t};
2
+ //# sourceMappingURL=content-config-store-8omQF5p5.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-config-store-8omQF5p5.mjs","names":[],"sources":["../src/content-config-store.ts"],"sourcesContent":["/**\n * The `content()` plugin config store — a leaf module holding ONLY the globalThis\n * slot + accessors, with **no** schema / plugin imports.\n *\n * Extracted from `plugin.ts` (which also pulls `defineTable`-backed schema modules)\n * so that `locale-registry.ts` (the SD006 resolvers, re-exported from the **main entry**)\n * can read the shipped locales WITHOUT dragging the schema/table graph into it — that's\n * what stops `@murumets-ee/content`'s main index from transitively evaluating\n * `schema/locks.ts` at import time (the bug that broke the api-handler unit tests).\n *\n * `locale-utils.ts` (validateLocale) deliberately keeps importing `getContentConfig`\n * from `plugin.js`: it is NOT on the main-index import graph (only `content/query` +\n * `content/client`, both already `server-only`, so there's no bundle/jiti benefit), and\n * its consumers' unit tests mock `plugin.js` — repointing it here would ripple through\n * ~7 test mocks for no runtime gain.\n */\n\nimport type { ContentConfig } from './types.js'\n\n/**\n * The active config lives on `globalThis` keyed by `Symbol.for(...)`, NOT in a\n * module-level binding — same Turbopack-dev module-duplication hazard as the\n * content-tables registry (see schema/registry.ts): a lazily-compiled route chunk\n * can get a SECOND instance of this module whose `let` was never assigned, and\n * `getContentConfig()` throws \"not initialized\" on a perfectly initialized app.\n * `Symbol.for` keys are process-global, so every duplicate instance reads the same\n * slot. (pr-review pass-1 M4 — load-bearing on the publish + locale-routing path.)\n */\nconst CONFIG_KEY = Symbol.for('@murumets-ee/content:content-config')\n\ninterface GlobalWithContentConfig {\n [CONFIG_KEY]?: ContentConfig\n}\n\n/** Store the resolved content config (called once by the plugin's `init`). */\nexport function setContentConfig(config: ContentConfig): void {\n ;(globalThis as GlobalWithContentConfig)[CONFIG_KEY] = config\n}\n\n/**\n * Get the content configuration. Throws if the plugin hasn't initialized.\n */\nexport function getContentConfig(): ContentConfig {\n const config = (globalThis as GlobalWithContentConfig)[CONFIG_KEY]\n if (!config) {\n throw new Error(\n '@murumets-ee/content plugin not initialized. Add content() to your plugins array.',\n )\n }\n return config\n}\n"],"mappings":"AA4BA,MAAM,EAAa,OAAO,IAAI,qCAAqC,EAOnE,SAAgB,EAAiB,EAA6B,CAC3D,WAAwC,GAAc,CACzD,CAKA,SAAgB,GAAkC,CAChD,IAAM,EAAU,WAAuC,GACvD,GAAI,CAAC,EACH,MAAU,MACR,mFACF,EAEF,OAAO,CACT"}
@@ -0,0 +1,2 @@
1
+ import{t as e}from"./rolldown-runtime-DK3Fl9T5.mjs";import{t}from"./registry-CaPbY5lm.mjs";import{requireSiteFor as n}from"@murumets-ee/core";import"server-only";var r=e({createContentContext:()=>i,getDraftsClient:()=>a,getLocaleStatusClient:()=>s,getVersionsClient:()=>o});function i(e,t){return{entity:e.entity,admin:e.admin,db:e.admin.getDb(),versionableOptions:t,logger:e.logger}}async function a(e){let{drafts:r}=t(e.entity.name);return r?r.makeClient(e.db,await n(e.entity)):null}async function o(e){let{versions:r}=t(e.entity.name);return r?r.makeClient(e.db,await n(e.entity)):null}async function s(e){let{localeStatus:r}=t(e.entity.name);return r?r.makeClient(e.db,await n(e.entity)):null}export{o as a,s as i,i as n,a as r,r as t};
2
+ //# sourceMappingURL=context-D7eEItCY.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-D7eEItCY.mjs","names":[],"sources":["../src/internal/context.ts"],"sourcesContent":["/**\n * Shared per-instance state for ContentClient feature modules.\n *\n * The package's domain modules (`versions.ts`, `drafts.ts`,\n * `translation-status.ts`, `locale-status.ts`, `layout.ts`) are written\n * as free functions that take a `ContentContext` as their first\n * argument. ContentClient itself is a thin shell that builds the\n * context once and forwards every public method to the corresponding\n * free function.\n *\n * Why free functions instead of one class with everything inline:\n * - 1000+ LoC in one class is impossible to navigate and audit.\n * - Each module has clear inputs (the context + method args) and no\n * hidden dependencies on private state.\n * - Splits cleanly along the same boundaries as the per-entity\n * capability tables (drafts, versions, locale_status, ...) — every\n * module owns exactly one capability surface.\n */\n\nimport 'server-only'\n\nimport { type Logger, requireSiteFor } from '@murumets-ee/core'\nimport type { Entity, FieldConfig } from '@murumets-ee/entity'\nimport type { AdminClient } from '@murumets-ee/entity/admin'\nimport type { PostgresJsDatabase } from 'drizzle-orm/postgres-js'\nimport type { getVersionableOptions } from '../behaviors/versionable.js'\nimport { getContentTables } from '../schema/registry.js'\n\n/**\n * Per-instance content context. Built once in `createContentContext()`\n * and threaded through every domain module's free functions.\n */\nexport interface ContentContext<\n AllFields extends Record<string, FieldConfig> = Record<string, FieldConfig>,\n> {\n entity: Entity<AllFields>\n admin: AdminClient<AllFields>\n db: PostgresJsDatabase\n versionableOptions: ReturnType<typeof getVersionableOptions>\n logger?: Logger | undefined\n}\n\n/**\n * Build a content context from an AdminClient + entity. The DB handle\n * is read off the AdminClient (it owns the read-write connection).\n */\nexport function createContentContext<AllFields extends Record<string, FieldConfig>>(\n config: {\n admin: AdminClient<AllFields>\n entity: Entity<AllFields>\n logger?: Logger\n },\n // Lazy import to avoid a static cycle: behaviors/versionable.ts is loaded\n // by client.ts which would otherwise close the loop. Phase-2 validated\n // the static import graph; this is a private helper bundled into the\n // same chunk so the dynamic-vs-static rule doesn't apply.\n versionableOptions: ReturnType<typeof getVersionableOptions>,\n): ContentContext<AllFields> {\n return {\n entity: config.entity,\n admin: config.admin,\n db: config.admin.getDb(),\n versionableOptions,\n logger: config.logger,\n }\n}\n\n// -------------------------------------------------------------------\n// Per-capability TableClient lookups. For a site-bound entity the client\n// is CONFINED to the request's site (multisite D003) — `requireSiteFor`\n// throws when there is none, so a companion read can never widen to every\n// site. Async for that reason: the single-site answer may need a lookup.\n// Each returns null if the entity\n// hasn't registered the corresponding table (i.e. doesn't have the\n// behavior). ContentClient public methods translate that null into\n// either a thrown EntityCapabilityError (writes) or a falsy return\n// (reads).\n// -------------------------------------------------------------------\n\nexport async function getDraftsClient(ctx: ContentContext) {\n const { drafts } = getContentTables(ctx.entity.name)\n return drafts ? drafts.makeClient(ctx.db, await requireSiteFor(ctx.entity)) : null\n}\n\nexport async function getVersionsClient(ctx: ContentContext) {\n const { versions } = getContentTables(ctx.entity.name)\n return versions ? versions.makeClient(ctx.db, await requireSiteFor(ctx.entity)) : null\n}\n\nexport async function getLocaleStatusClient(ctx: ContentContext) {\n const { localeStatus } = getContentTables(ctx.entity.name)\n return localeStatus ? localeStatus.makeClient(ctx.db, await requireSiteFor(ctx.entity)) : null\n}\n"],"mappings":"kRA8CA,SAAgB,EACd,EASA,EAC2B,CAC3B,MAAO,CACL,OAAQ,EAAO,OACf,MAAO,EAAO,MACd,GAAI,EAAO,MAAM,MAAM,EACvB,qBACA,OAAQ,EAAO,MACjB,CACF,CAcA,eAAsB,EAAgB,EAAqB,CACzD,GAAM,CAAE,UAAW,EAAiB,EAAI,OAAO,IAAI,EACnD,OAAO,EAAS,EAAO,WAAW,EAAI,GAAI,MAAM,EAAe,EAAI,MAAM,CAAC,EAAI,IAChF,CAEA,eAAsB,EAAkB,EAAqB,CAC3D,GAAM,CAAE,YAAa,EAAiB,EAAI,OAAO,IAAI,EACrD,OAAO,EAAW,EAAS,WAAW,EAAI,GAAI,MAAM,EAAe,EAAI,MAAM,CAAC,EAAI,IACpF,CAEA,eAAsB,EAAsB,EAAqB,CAC/D,GAAM,CAAE,gBAAiB,EAAiB,EAAI,OAAO,IAAI,EACzD,OAAO,EAAe,EAAa,WAAW,EAAI,GAAI,MAAM,EAAe,EAAI,MAAM,CAAC,EAAI,IAC5F"}
@@ -0,0 +1,2 @@
1
+ const e=`detail_template`,t=`target`;function n(t){let n=t?.entities;return!n||typeof n.has!=`function`?!1:n.has(e)}export{t as n,n as r,e as t};
2
+ //# sourceMappingURL=detail-template-names-CD1Y9n1U.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detail-template-names-CD1Y9n1U.mjs","names":[],"sources":["../src/detail-template-names.ts"],"sourcesContent":["/**\n * The detail-template entity's name, and the list-time predicate its seeder\n * uses — in a module that imports NOTHING, for the reason\n * `./chrome-entity-names.ts` gives: `available` runs on the seed page's\n * synchronous shell and inside `lumi seed --list`, so it cannot sit behind an\n * `await import`, and importing it from a module that reaches\n * `@murumets-ee/core/clients` would hoist that into `dist/plugin.mjs`.\n */\n\n/** The one detail-template entity. Rows differ by `target`, not by entity name. */\nexport const DETAIL_TEMPLATE_ENTITY_NAME = 'detail_template'\n\n/** The column holding the entity a template draws. Also its unique key. */\nexport const DETAIL_TEMPLATE_TARGET_FIELD = 'target'\n\n/**\n * Does this app have the detail-template entity for the seeder to create rows\n * in? `app` is `unknown` — see `hasChromeEntities`.\n */\nexport function hasDetailTemplateEntity(app: unknown): boolean {\n const entities = (app as { entities?: Map<string, unknown> } | null | undefined)?.entities\n if (!entities || typeof entities.has !== 'function') return false\n return entities.has(DETAIL_TEMPLATE_ENTITY_NAME)\n}\n"],"mappings":"AAUA,MAAa,EAA8B,kBAG9B,EAA+B,SAM5C,SAAgB,EAAwB,EAAuB,CAC7D,IAAM,EAAY,GAAgE,SAElF,MADI,CAAC,GAAY,OAAO,EAAS,KAAQ,WAAmB,GACrD,EAAS,IAAI,CAA2B,CACjD"}
@@ -0,0 +1,28 @@
1
+ import { ToolkitApp } from "@murumets-ee/core";
2
+
3
+ //#region src/detail-template-provider.d.ts
4
+ /** A published template, as stored — its blocks are resolved by the caller. */
5
+ interface DetailTemplateDocument {
6
+ /** The template row's id, for the response's cache tags. */
7
+ readonly id: string;
8
+ readonly blocks: unknown[];
9
+ }
10
+ interface DetailTemplateProvider {
11
+ /** The template entity's name, for the response's cache tags. */
12
+ readonly entity: string;
13
+ readTemplate(opts: {
14
+ entity: string;
15
+ locale: string;
16
+ }): Promise<DetailTemplateDocument | null>;
17
+ publicRow(opts: {
18
+ entity: string;
19
+ row: Readonly<Record<string, unknown>>;
20
+ locale: string;
21
+ }): Promise<Record<string, unknown>>;
22
+ }
23
+ declare function createDetailTemplateProvider(getApp: () => Promise<ToolkitApp> | ToolkitApp, options: {
24
+ defaultLocale: string;
25
+ }): DetailTemplateProvider;
26
+ //#endregion
27
+ export { DetailTemplateDocument, DetailTemplateProvider, createDetailTemplateProvider };
28
+ //# sourceMappingURL=detail-template-provider.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detail-template-provider.d.mts","names":[],"sources":["../src/detail-template-provider.ts"],"mappings":";;;AAmFA;AAAA,UAjBiB,sBAAA;;WAEN,EAAA;EAAA,SACA,MAAM;AAAA;AAAA,UAGA,sBAAA;EAcQ;EAAA,SAZd,MAAA;EACT,YAAA,CAAa,IAAA;IAAQ,MAAA;IAAgB,MAAA;EAAA,IAAmB,OAAA,CAAQ,sBAAA;EAChE,SAAA,CAAU,IAAA;IACR,MAAA;IACA,GAAA,EAAK,QAAA,CAAS,MAAA;IACd,MAAA;EAAA,IACE,OAAA,CAAQ,MAAA;AAAA;AAAA,iBAGE,4BAAA,CACd,MAAA,QAAc,OAAA,CAAQ,UAAA,IAAc,UAAA,EACpC,OAAA;EAAW,aAAA;AAAA,IACV,sBAAA"}
@@ -0,0 +1,2 @@
1
+ import{n as e,t}from"./detail-template-names-CD1Y9n1U.mjs";import{getBlockTreeFieldName as n,isTemplateDrawn as r}from"@murumets-ee/entity";import{createSystemReachResolver as i}from"@murumets-ee/core";import{QueryClient as a}from"@murumets-ee/entity/query";import{schemaRegistry as o}from"@murumets-ee/db";import{eq as s,getTableColumns as c}from"drizzle-orm";import{effectiveDetailSpecs as l,resolveDocumentDetail as u}from"@murumets-ee/blocks/server";const d=i(`detail-template-resolver`),f=new Set([`title`,`text`]);function p(i,p){return{entity:t,readTemplate:async({entity:l,locale:u})=>{let f=await i(),m=f.entities.get(l);if(!m||!r(m))return null;let h=f.entities.get(t);if(!h)return null;let g=n(h),_=o.get(t),v=(_?c(_):void 0)?.[e];if(!g||!v)return null;let y=(await new a({entity:h,db:f.db.readOnly,logger:f.logger.child({resolve:`detail-template`}),contextResolver:d}).findMany({limit:1,locale:u,defaultLocale:p.defaultLocale,where:s(v,l)}))[0];if(!y||typeof y.id!=`string`)return null;let b=y[g];return!Array.isArray(b)||b.length===0?null:{id:y.id,blocks:b}},publicRow:async({entity:e,row:t,locale:n})=>{let r=l(await i()).specs.get(e);if(r===void 0)return{};let a=u(r,t,n,f);return{...a?.title!==void 0&&{title:a.title},...a?.text!==void 0&&{description:a.text}}}}}export{p as createDetailTemplateProvider};
2
+ //# sourceMappingURL=detail-template-provider.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detail-template-provider.mjs","names":[],"sources":["../src/detail-template-provider.ts"],"sourcesContent":["/**\n * The detail-template provider `content-api` is handed (block-library D009).\n *\n * `content-api` is a leaf: it knows an entity is drawn by a template\n * (`frontend.drawnBy`), and nothing about where a template is stored or which\n * of a row's columns a site lets a visitor see. Both answers live here, and are\n * injected as {@link createDetailTemplateProvider}.\n *\n * ## 🔴 What a visitor can reach through this\n *\n * - **`readTemplate`** answers for a row's ENTITY NAME, which the handler takes\n * from a whitelisted entity the caller holds `view` on — never from a request\n * parameter and never from a stored value. It reads the PUBLISHED template\n * for that entity and locale: the read runs under a reach context that grants\n * `view` and withholds `view_unpublished`, so `QueryClient`'s publish filter\n * and trashed-row exclusion still apply. A draft template is `null`, and the\n * page falls back to a plain one.\n *\n * It runs under reach rather than under the caller's own grants on purpose. A\n * template is not a document a visitor asks for; it is how a row they may\n * already read is drawn, the same derivation a menu or a path resolution is.\n * Requiring `detail_template:view` on `public` would be a second grant an\n * operator has to remember, whose absence looks exactly like \"no template\n * published\" — the two-grant trap `chrome-provider.ts` records.\n *\n * - **`publicRow`** is the ONLY thing of the row that crosses, besides its id.\n * It projects `title` and `description` through the site's detail declaration\n * (`blocksPlugin({ details })`), whose columns were validated at boot as\n * declared, non-`internal`, non-`adminOnly`. An entity with no declaration\n * yields `{}`. No stored value names a column.\n *\n * ## Fan-out\n *\n * One query per `readTemplate` call, and the handler calls it once per by-id\n * response. `publicRow` does no I/O (it awaits only the app handle).\n */\n\nimport {\n type DocumentDetailPart,\n effectiveDetailSpecs,\n resolveDocumentDetail,\n} from '@murumets-ee/blocks/server'\nimport type { ToolkitApp } from '@murumets-ee/core'\nimport { createSystemReachResolver } from '@murumets-ee/core'\nimport { schemaRegistry } from '@murumets-ee/db'\nimport type { SecurityContext } from '@murumets-ee/entity'\nimport { getBlockTreeFieldName, isTemplateDrawn } from '@murumets-ee/entity'\nimport { QueryClient } from '@murumets-ee/entity/query'\nimport { eq, getTableColumns } from 'drizzle-orm'\nimport type { PgColumn } from 'drizzle-orm/pg-core'\nimport {\n DETAIL_TEMPLATE_ENTITY_NAME,\n DETAIL_TEMPLATE_TARGET_FIELD,\n} from './detail-template-names.js'\n\n/**\n * Reach, never visibility of unpublished rows — see the file header. Named so\n * its reads are distinguishable from the path and menu resolvers' in audit\n * output.\n */\nconst SYSTEM_CONTEXT: () => SecurityContext = createSystemReachResolver('detail-template-resolver')\n\n/** The parts of a detail that are the row's public name and summary. */\nconst PUBLIC_ROW_PARTS: ReadonlySet<DocumentDetailPart> = new Set(['title', 'text'])\n\n/** A published template, as stored — its blocks are resolved by the caller. */\nexport interface DetailTemplateDocument {\n /** The template row's id, for the response's cache tags. */\n readonly id: string\n readonly blocks: unknown[]\n}\n\nexport interface DetailTemplateProvider {\n /** The template entity's name, for the response's cache tags. */\n readonly entity: string\n readTemplate(opts: { entity: string; locale: string }): Promise<DetailTemplateDocument | null>\n publicRow(opts: {\n entity: string\n row: Readonly<Record<string, unknown>>\n locale: string\n }): Promise<Record<string, unknown>>\n}\n\nexport function createDetailTemplateProvider(\n getApp: () => Promise<ToolkitApp> | ToolkitApp,\n options: { defaultLocale: string },\n): DetailTemplateProvider {\n return {\n entity: DETAIL_TEMPLATE_ENTITY_NAME,\n\n readTemplate: async ({ entity: targetName, locale }) => {\n const app = await getApp()\n // Asked again here rather than trusted from the caller: this is the gate\n // that keeps the provider from being a way to read a template for an\n // entity code never marked as drawn by one.\n const target = app.entities.get(targetName)\n if (!target || !isTemplateDrawn(target)) return null\n\n const templateEntity = app.entities.get(DETAIL_TEMPLATE_ENTITY_NAME)\n if (!templateEntity) return null\n const blockTreeField = getBlockTreeFieldName(templateEntity)\n const table = schemaRegistry.get(DETAIL_TEMPLATE_ENTITY_NAME)\n // `?.` — see `chrome-provider.ts`: a registry entry that is not a real\n // table must degrade to \"no template\", not throw on every detail page.\n const columns = table\n ? (getTableColumns(table) as Record<string, PgColumn> | undefined)\n : undefined\n const targetColumn = columns?.[DETAIL_TEMPLATE_TARGET_FIELD]\n if (!blockTreeField || !targetColumn) return null\n\n const client = new QueryClient({\n entity: templateEntity,\n db: app.db.readOnly,\n logger: app.logger.child({ resolve: 'detail-template' }),\n contextResolver: SYSTEM_CONTEXT,\n })\n // `eq(target)` on the unique column: at most one live row can match.\n const rows = await client.findMany({\n limit: 1,\n locale,\n defaultLocale: options.defaultLocale,\n where: eq(targetColumn, targetName),\n })\n const row = rows[0] as Record<string, unknown> | undefined\n if (!row || typeof row.id !== 'string') return null\n const blocks = row[blockTreeField]\n // A published template with nothing in it is \"no template\": the plain\n // fallback is a better page than an empty one.\n if (!Array.isArray(blocks) || blocks.length === 0) return null\n return { id: row.id, blocks }\n },\n\n publicRow: async ({ entity, row, locale }) => {\n const app = await getApp()\n const spec = effectiveDetailSpecs(app).specs.get(entity)\n if (spec === undefined) return {}\n const detail = resolveDocumentDetail(spec, row, locale, PUBLIC_ROW_PARTS)\n return {\n ...(detail?.title !== undefined && { title: detail.title }),\n ...(detail?.text !== undefined && { description: detail.text }),\n }\n },\n }\n}\n"],"mappings":"scA4DA,MAAM,EAAwC,EAA0B,0BAA0B,EAG5F,EAAoD,IAAI,IAAI,CAAC,QAAS,MAAM,CAAC,EAoBnF,SAAgB,EACd,EACA,EACwB,CACxB,MAAO,CACL,OAAQ,EAER,aAAc,MAAO,CAAE,OAAQ,EAAY,YAAa,CACtD,IAAM,EAAM,MAAM,EAAO,EAInB,EAAS,EAAI,SAAS,I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ets-ee/core";var i=e({siteForDocumentType:()=>a});async function a(e){let i=n()?.app??t();if(!i)return;let a=i.entities.get(e);if(a)return r(a,i)}export{a as n,i as t};
2
+ //# sourceMappingURL=document-site-B8tmEqLw.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document-site-B8tmEqLw.mjs","names":[],"sources":["../src/internal/document-site.ts"],"sourcesContent":["/**\n * The site a document-type-keyed companion access acts on (plan `multisite`\n * D003) — for the stores the block editor calls with a bare `documentType`\n * string rather than an entity object (`document-draft-store.ts`,\n * `document-version-store.ts`).\n *\n * `undefined` for a shared entity, or a type this app does not know (its\n * content tables are not registered either, so nothing is read). Throws\n * `SiteRequiredError` for a bound entity with no site in the request.\n */\n\nimport { getAppOrUndefined, getContext, requireSiteFor } from '@murumets-ee/core'\n\nexport async function siteForDocumentType(documentType: string): Promise<string | undefined> {\n // No booted app (a unit harness): there is no entity to consult, and a\n // bound type's partitioned table then refuses to build an unconfined client\n // — so returning `undefined` here cannot widen anything.\n const app = getContext()?.app ?? getAppOrUndefined()\n if (!app) return undefined\n const entity = app.entities.get(documentType)\n if (!entity) return undefined\n return requireSiteFor(entity, app)\n}\n"],"mappings":"mLAaA,eAAsB,EAAoB,EAAmD,CAI3F,IAAM,EAAM,EAAW,CAAC,EAAE,KAAO,EAAkB,EACnD,GAAI,CAAC,EAAK,OACV,IAAM,EAAS,EAAI,SAAS,IAAI,CAAY,EACvC,KACL,OAAO,EAAe,EAAQ,CAAG,CACnC"}
@@ -0,0 +1,64 @@
1
+ import { t as VersionableFields } from "../versionable-CRvV87nZ.mjs";
2
+ import { a as siteChromeEntity, i as SiteChromeEntityOptions, n as CHROME_PLACEMENT_LABELS, r as ChromePlacement, t as CHROME_PLACEMENTS } from "../site-chrome-DNCcePSR.mjs";
3
+ import { Behavior, Entity, EntityAdminConfig, ForbiddenError } from "@murumets-ee/entity";
4
+
5
+ //#region src/entities/detail-template.d.ts
6
+ interface DetailTemplateEntityOptions {
7
+ /**
8
+ * The entities drawn by a stored template. Each must declare
9
+ * `frontend: { path, drawnBy: 'template' }`; one that does not throws here,
10
+ * at boot, rather than producing a template nothing ever draws.
11
+ *
12
+ * May be empty — a project with no such entity yet keeps the registration and
13
+ * adds a name when it gets one. The entity is then hidden from the sidebar.
14
+ */
15
+ for: readonly Pick<Entity, 'name' | 'frontend'>[];
16
+ /** Role that may read templates in the admin. Default `'editor'`. */
17
+ viewRole?: string;
18
+ /** Role that may edit and publish templates. Default `'editor'`. */
19
+ updateRole?: string;
20
+ /** Role named for create/delete (both are otherwise closed). Default `'admin'`. */
21
+ adminRole?: string;
22
+ /** Snapshots kept per template. Default 30. */
23
+ maxVersions?: number;
24
+ /** The block environment the canvas opens (e.g. `'page'`). */
25
+ environment?: string;
26
+ /** App-supplied behaviors — `withOpLog()` at least. Must contribute no fields. */
27
+ behaviors?: readonly Behavior<Record<never, never>, string>[];
28
+ /** Field naming overrides, merged per field over the English defaults. */
29
+ admin?: {
30
+ fieldOverrides?: EntityAdminConfig['fieldOverrides'];
31
+ };
32
+ }
33
+ /** Thrown when someone tries to delete or trash a detail template. */
34
+ declare class DetailTemplateDeleteRefusedError extends ForbiddenError {
35
+ constructor();
36
+ }
37
+ /** The names a template may target — validated, de-duplicated, in the given order. */
38
+ declare function detailTemplateTargets(entities: readonly Pick<Entity, 'name' | 'frontend'>[]): string[];
39
+ /**
40
+ * Build the `detail_template` entity. The return type is INFERRED, for the
41
+ * reason `siteChromeEntity` gives: annotating it widens the name to `string`.
42
+ */
43
+ declare function detailTemplateEntity(options: DetailTemplateEntityOptions): Entity<{
44
+ id: import("@murumets-ee/entity").IdField;
45
+ } & import("@murumets-ee/entity").AuditableFields & import("@murumets-ee/entity").PublishableFields & VersionableFields & Record<never, never> & {
46
+ target: import("@murumets-ee/entity").SelectField & {
47
+ options: string[];
48
+ } & {
49
+ readonly options: string[];
50
+ readonly required: true;
51
+ readonly unique: true;
52
+ };
53
+ label: import("@murumets-ee/entity").TextField & {
54
+ readonly required: true;
55
+ };
56
+ layout: import("@murumets-ee/entity").BlockTreeField & {
57
+ readonly environment?: string;
58
+ readonly translatable: true;
59
+ readonly rowsFrom: "target";
60
+ };
61
+ }, "detail_template", [Behavior<import("@murumets-ee/entity").AuditableFields, string>, Behavior<import("@murumets-ee/entity").PublishableFields, "publishable">, Behavior<VersionableFields, string>, Behavior<Record<never, never>, "content:detail-template-undeletable">, ...Behavior<Record<never, never>, string>[]]>;
62
+ //#endregion
63
+ export { CHROME_PLACEMENTS, CHROME_PLACEMENT_LABELS, type ChromePlacement, DetailTemplateDeleteRefusedError, type DetailTemplateEntityOptions, type SiteChromeEntityOptions, detailTemplateEntity, detailTemplateTargets, siteChromeEntity };
64
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/entities/detail-template.ts"],"mappings":";;;;;UAqEiB,2BAAA;EA0FwD;;;;;;;;EAjFvE,GAAA,WAAc,IAAA,CAAK,MAAA;;EAEnB,QAAA;;EAEA,UAAA;;EAEA,SAAA;;EAEA,WAAA;;EAEA,WAAA;;EAEA,SAAA,YAAqB,QAAA,CAAS,MAAA;;EAE9B,KAAA;IACE,cAAA,GAAiB,iBAAA;EAAA;AAAA;;cAsBR,gCAAA,SAAyC,cAAc;EAAd,WAAA;AAAA;;iBAwBtC,qBAAA,CACd,QAAA,WAAmB,IAAI,CAAC,MAAA;;;;;iBAmBV,oBAAA,CAAqB,OAAA,EAAS,2BAAA,GAA2B,MAAA;;sGAAA,iBAAA"}
@@ -0,0 +1,2 @@
1
+ import{n as e}from"../versionable-Br_G5VGR.mjs";import{t}from"../detail-template-names-CD1Y9n1U.mjs";import{n,r,t as i}from"../site-chrome-BAtQaAqC.mjs";import{ForbiddenError as a,auditable as o,defineEntity as s,field as c,isTemplateDrawn as l,publishable as u}from"@murumets-ee/entity";const d={label:{label:`Name`,description:`Shown in the admin list and as the editor title. Visitors never see it.`}};function f(e){let t={...d};for(let[n,r]of Object.entries(e??{}))t[n]={...t[n],...r};return t}var p=class extends a{constructor(){super(`A detail template is not deleted: the rows it draws are still on the site. Unpublish it instead — those pages then show a plain fallback, and the draft stays editable.`),this.name=`DetailTemplateDeleteRefusedError`}};const m={name:`content:detail-template-undeletable`,hooks:{beforeDelete:async()=>{throw new p}}};function h(e){let t=[];for(let n of e){if(!l(n))throw Error(`detailTemplateEntity: '${n.name}' is listed in \`for\` but does not declare \`frontend: { path, drawnBy: 'template' }\`. A template for it would never be drawn.`);t.includes(n.name)||t.push(n.name)}return t}function g(n){let r=n.viewRole??`editor`,i=n.updateRole??`editor`,a=n.adminRole??`admin`,l=h(n.for);return s({name:t,site:`bound`,kind:`collection`,fields:{target:c.select({options:l,required:!0,unique:!0}),label:c.text({required:!0}),layout:c.blockTree({translatable:!0,rowsFrom:`target`,...n.environment!==void 0&&{environment:n.environment}})},behaviors:[o(),u(),e({maxPerDoc:n.maxVersions??30}),m,...n.behaviors??[]],scope:`global`,access:{view:r,create:a,update:i,delete:a},admin:{icon:`layout-template`,description:`One page layout per kind of synced record, drawn for every record of that kind.`,rootFields:[`label`],fieldOverrides:f(n.admin?.fieldOverrides),titleField:`label`,group:`Site`,disableCreate:!0,...l.length===0&&{hidden:!0}}})}export{i as CHROME_PLACEMENTS,n as CHROME_PLACEMENT_LABELS,p as DetailTemplateDeleteRefusedError,g as detailTemplateEntity,h as detailTemplateTargets,r as siteChromeEntity};
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/entities/detail-template.ts"],"sourcesContent":["/**\n * `detail_template` — the ONE stored block document per entity type that draws\n * every row of an entity the site does not author (block-library D009).\n *\n * A synced room type or a synced legal document has no block-tree field and\n * cannot have one: its rows are written by a machine, so there is nothing an\n * editor could save a layout into. Its detail page is therefore a document of\n * THIS entity, keyed by the entity it draws. An editor opens \"Room detail\" on\n * the canvas and edits it like a page — adds, moves and removes blocks,\n * translates its fixed copy per locale, publishes it — and the site draws that\n * one published tree for every room, with that room's values in the bound\n * blocks.\n *\n * ## The same shape as `site_chrome`, for the same reasons\n *\n * One entity, one row per key, the key's `unique: true` as the whole\n * cardinality rule (a partial index, `WHERE \"deletedAt\" IS NULL`, because a\n * publishable entity is trashable). `layout` is `translatable`, so each locale\n * is an independent tree. `withOpLog()` comes from the app, because it ships\n * from `@murumets-ee/blocks/server` and this package must not depend on blocks:\n *\n * ```ts\n * import { withOpLog } from '@murumets-ee/blocks/server'\n * import { detailTemplateEntity } from '@murumets-ee/content/entities'\n *\n * export const DetailTemplate = detailTemplateEntity({\n * for: [RoomType, LegalDocument],\n * environment: 'page',\n * behaviors: [withOpLog({ retentionDays: 7 })],\n * })\n * ```\n *\n * Rows are created by the `content:detail-templates` bootstrap seeder (one\n * DRAFT per target, on every `lumi migrate`), so `admin.disableCreate` is on.\n *\n * ## 🔴 `target` is a key, never a choice\n *\n * `target` is a `select` whose options are the names of the entities passed in\n * `for` — each of which must itself declare `frontend: { drawnBy: 'template' }`\n * or this throws at boot. So a stored value can only ever be an entity that\n * CODE offered, and the public read never follows it: the site resolves a URL\n * to a row, and asks for the template WHERE `target` = that row's entity. No\n * request reads a template and then goes looking for the entity it names.\n *\n * `layout`'s `rowsFrom: 'target'` is what tells the canvas to draw the bound\n * blocks with a sample row of that entity, read-only.\n *\n * ## Deleting is refused; unpublishing is the off switch\n *\n * While an entity is drawn by a template its rows are routable, and a deleted\n * template would leave them with nothing an editor can open again (the row is\n * bootstrapped, and `disableCreate` hides the only other way to make one). So\n * delete and trash are refused outright. To take a detail page back to the\n * plain fallback, UNPUBLISH the template: the site then draws the row's title\n * on a plain page, and the draft is still there to publish again.\n */\n\nimport type { Behavior, Entity, EntityAdminConfig } from '@murumets-ee/entity'\nimport {\n auditable,\n defineEntity,\n ForbiddenError,\n field,\n isTemplateDrawn,\n publishable,\n} from '@murumets-ee/entity'\nimport { versionable } from '../behaviors/versionable.js'\nimport { DETAIL_TEMPLATE_ENTITY_NAME } from '../detail-template-names.js'\n\nexport interface DetailTemplateEntityOptions {\n /**\n * The entities drawn by a stored template. Each must declare\n * `frontend: { path, drawnBy: 'template' }`; one that does not throws here,\n * at boot, rather than producing a template nothing ever draws.\n *\n * May be empty — a project with no such entity yet keeps the registration and\n * adds a name when it gets one. The entity is then hidden from the sidebar.\n */\n for: readonly Pick<Entity, 'name' | 'frontend'>[]\n /** Role that may read templates in the admin. Default `'editor'`. */\n viewRole?: string\n /** Role that may edit and publish templates. Default `'editor'`. */\n updateRole?: string\n /** Role named for create/delete (both are otherwise closed). Default `'admin'`. */\n adminRole?: string\n /** Snapshots kept per template. Default 30. */\n maxVersions?: number\n /** The block environment the canvas opens (e.g. `'page'`). */\n environment?: string\n /** App-supplied behaviors — `withOpLog()` at least. Must contribute no fields. */\n behaviors?: readonly Behavior<Record<never, never>, string>[]\n /** Field naming overrides, merged per field over the English defaults. */\n admin?: {\n fieldOverrides?: EntityAdminConfig['fieldOverrides']\n }\n}\n\nconst DEFAULT_FIELD_OVERRIDES: NonNullable<EntityAdminConfig['fieldOverrides']> = {\n label: {\n label: 'Name',\n description: 'Shown in the admin list and as the editor title. Visitors never see it.',\n },\n}\n\nfunction mergeFieldOverrides(\n project: EntityAdminConfig['fieldOverrides'],\n): NonNullable<EntityAdminConfig['fieldOverrides']> {\n const merged: NonNullable<EntityAdminConfig['fieldOverrides']> = { ...DEFAULT_FIELD_OVERRIDES }\n for (const [name, override] of Object.entries(project ?? {})) {\n merged[name] = { ...merged[name], ...override }\n }\n return merged\n}\n\n/** Thrown when someone tries to delete or trash a detail template. */\nexport class DetailTemplateDeleteRefusedError extends ForbiddenError {\n constructor() {\n super(\n 'A detail template is not deleted: the rows it draws are still on the site. ' +\n 'Unpublish it instead — those pages then show a plain fallback, and the draft stays editable.',\n )\n this.name = 'DetailTemplateDeleteRefusedError'\n }\n}\n\n/**\n * Refuse every delete path. `beforeDelete` runs on a single delete, a purge, a\n * trash, `deleteMany` and a cascade, so this one hook covers all of them.\n */\nconst undeletable: Behavior<Record<never, never>, 'content:detail-template-undeletable'> = {\n name: 'content:detail-template-undeletable',\n hooks: {\n beforeDelete: async () => {\n throw new DetailTemplateDeleteRefusedError()\n },\n },\n}\n\n/** The names a template may target — validated, de-duplicated, in the given order. */\nexport function detailTemplateTargets(\n entities: readonly Pick<Entity, 'name' | 'frontend'>[],\n): string[] {\n const names: string[] = []\n for (const entity of entities) {\n if (!isTemplateDrawn(entity)) {\n throw new Error(\n `detailTemplateEntity: '${entity.name}' is listed in \\`for\\` but does not declare ` +\n \"`frontend: { path, drawnBy: 'template' }`. A template for it would never be drawn.\",\n )\n }\n if (!names.includes(entity.name)) names.push(entity.name)\n }\n return names\n}\n\n/**\n * Build the `detail_template` entity. The return type is INFERRED, for the\n * reason `siteChromeEntity` gives: annotating it widens the name to `string`.\n */\nexport function detailTemplateEntity(options: DetailTemplateEntityOptions) {\n const viewRole = options.viewRole ?? 'editor'\n const updateRole = options.updateRole ?? 'editor'\n const adminRole = options.adminRole ?? 'admin'\n const targets = detailTemplateTargets(options.for)\n\n return defineEntity({\n name: DETAIL_TEMPLATE_ENTITY_NAME,\n // Per site, like chrome: each site has its own detail pages.\n site: 'bound',\n kind: 'collection',\n fields: {\n // THE key. Not translatable — which entity a template draws is a property\n // of the document, not of a translation. `unique: true` is the whole\n // one-template-per-entity-type rule, enforced by the database for every\n // writer.\n target: field.select({\n options: targets,\n required: true,\n unique: true,\n }),\n label: field.text({ required: true }),\n layout: field.blockTree({\n translatable: true,\n rowsFrom: 'target',\n ...(options.environment !== undefined && { environment: options.environment }),\n }),\n },\n behaviors: [\n auditable(),\n publishable(),\n versionable({ maxPerDoc: options.maxVersions ?? 30 }),\n undeletable,\n ...(options.behaviors ?? []),\n ],\n scope: 'global',\n access: {\n view: viewRole,\n create: adminRole,\n update: updateRole,\n delete: adminRole,\n },\n admin: {\n icon: 'layout-template',\n description:\n 'One page layout per kind of synced record, drawn for every record of that kind.',\n // `target` is deliberately absent, as `placement` is on chrome: pointing\n // a room template at legal documents by editing a dropdown would collide\n // with the row already holding that target.\n rootFields: ['label'],\n fieldOverrides: mergeFieldOverrides(options.admin?.fieldOverrides),\n titleField: 'label',\n group: 'Site',\n disableCreate: true,\n // Nothing to list until a project has a template-drawn entity.\n ...(targets.length === 0 && { hidden: true }),\n },\n })\n}\n\n/**\n * COMPILE-TIME guard that the name stays a literal — see `site-chrome.ts`'s\n * twin for why it lives in `src/`.\n */\ntype DetailTemplateName = ReturnType<typeof detailTemplateEntity>['name']\nconst _nameIsLiteral: string extends DetailTemplateName ? never : true = true\nvoid _nameIsLiteral\n"],"mappings":"gSAiGA,MAAM,EAA4E,CAChF,MAAO,CACL,MAAO,OACP,YAAa,yEACf,CACF,EAEA,SAAS,EACP,EACkD,CAClD,IAAM,EAA2D,CAAE,GAAG,CAAwB,EAC9F,IAAK,GAAM,CAAC,EAAM,KAAa,OAAO,QAAQ,GAAW,CAAC,CAAC,EACzD,EAAO,GAAQ,CAAE,GAAG,EAAO,GAAO,GAAG,CAAS,EAEhD,OAAO,CACT,CAGA,IAAa,EAAb,cAAsD,CAAe,CACnE,aAAc,CACZ,MACE,yKAEF,EACA,KAAK,KAAO,kCACd,CACF,EAMA,MAAM,EAAqF,CACzF,KAAM,sCACN,MAAO,CACL,aAAc,SAAY,CACxB,MAAM,IAAI,CACZ,CACF,CACF,EAGA,SAAgB,EACd,EACU,CACV,IAAM,EAAkB,CAAC,EACzB,IAAK,IAAM,KAAU,EAAU,CAC7B,GAAI,CAAC,EAAgB,CAAM,EACzB,MAAU,MACR,0BAA0B,EAAO,KAAK,iIAExC,EAEG,EAAM,SAAS,EAAO,IAAI,GAAG,EAAM,KAAK,EAAO,IAAI,CAC1D,CACA,OAAO,CACT,CAMA,SAAgB,EAAqB,EAAsC,CACzE,IAAM,EAAW,EAAQ,UAAY,SAC/B,EAAa,EAAQ,YAAc,SACnC,EAAY,EAAQ,WAAa,QACjC,EAAU,EAAsB,EAAQ,GAAG,EAEjD,OAAO,EAAa,CAClB,KAAM,EAEN,KAAM,QACN,KAAM,aACN,OAAQ,CAKN,OAAQ,EAAM,OAAO,CACnB,QAAS,EACT,SAAU,GACV,OAAQ,EACV,CAAC,EACD,MAAO,EAAM,KAAK,CAAE,SAAU,EAAK,CAAC,EACpC,OAAQ,EAAM,UAAU,CACtB,aAAc,GACd,SAAU,SACV,GAAI,EAAQ,cAAgB,IAAA,IAAa,CAAE,YAAa,EAAQ,WAAY,CAC9E,CAAC,CACH,EACA,UAAW,CACT,EAAU,EACV,EAAY,EACZ,EAAY,CAAE,UAAW,EAAQ,aAAe,EAAG,CAAC,EACpD,EACA,GAAI,EAAQ,WAAa,CAAC,CAC5B,EACA,MAAO,SACP,OAAQ,CACN,KAAM,EACN,OAAQ,EACR,OAAQ,EACR,OAAQ,CACV,EACA,MAAO,CACL,KAAM,kBACN,YACE,kFAIF,WAAY,CAAC,OAAO,EACpB,eAAgB,EAAoB,EAAQ,OAAO,cAAc,EACjE,WAAY,QACZ,MAAO,OACP,cAAe,GAEf,GAAI,EAAQ,SAAW,GAAK,CAAE,OAAQ,EAAK,CAC7C,CACF,CAAC,CACH"}
@@ -0,0 +1,2 @@
1
+ import{t as e}from"./rolldown-runtime-DK3Fl9T5.mjs";import{c as t}from"./schema-BYrYzsmO.mjs";var n=e({enumeratePaths:()=>r,getCanonicalPaths:()=>i});async function*r(e,n,r={}){let i=r.pageSize??200,a=r.publishConcurrency??5,{locale:o,entityType:s}=e,c=e.afterId;for(;;){let e={locale:o,isCanonical:!0};s!==void 0&&(e.entityType=s),c!==void 0&&(e.id={gt:c});let r=await n.pathsClient.findMany({where:e,orderBy:[{column:`id`,dir:`asc`}],limit:i});if(r.length===0)break;let l=new Map;for(let e of r){let t=l.get(e.entityType);t?t.push(e):l.set(e.entityType,[e])}let u=new Map;await t([...l.entries()],a,async([e,t])=>{let r=await n.filterPublished(e,t.map(e=>e.entityId),o);u.set(e,r)});for(let e of r)u.get(e.entityType)?.has(e.entityId)&&(yield{path:e.path,entityType:e.entityType,id:e.entityId,updatedAt:e.updatedAt});let d=r[r.length-1];if(!d||(c=d.id,r.length<i))break}}async function i(e,t,n,r){let i=new Map;for(let a=0;a<t.length;a+=500){let o=t.slice(a,a+500),s=await r.pathsClient.findMany({where:{entityType:e,locale:n,isCanonical:!0,entityId:{in:[...o]}},limit:o.length});for(let e of s)i.set(e.entityId,e.path)}return i}export{n,i as r,r as t};
2
+ //# sourceMappingURL=enumerate-CYHJKQz6.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enumerate-CYHJKQz6.mjs","names":[],"sources":["../src/paths/enumerate.ts"],"sourcesContent":["/**\n * Path enumeration for SSG / sitemaps (plan/routing PR06; phase\n * `05-resolution-and-enumeration-api.md` §2).\n *\n * `enumeratePaths` streams the PUBLISHED canonical `(path, entityType, id,\n * updatedAt)` rows for one locale. It powers `getStaticPaths` + the sitemap\n * helper, so it must NEVER leak an unpublished document (CLAUDE.md #1 — the\n * output feeds public build artifacts).\n *\n * **Security + availability.** Two properties matter here:\n * 1. *No unpublished leak.* `toolkit_paths` carries no publish-status column,\n * so each page's rows are publish-checked against the live entity via the\n * injected {@link EnumeratePathsDeps.filterPublished} — an unpublished (or\n * trashed) document is dropped from the stream.\n * 2. *No unbounded fan-out* (CLAUDE.md \"no amplification\"). Work is bounded by\n * PAGE SIZE, not by total document count: rows are keyset-paginated on the\n * immutable `id` PK (one index query per page), and the publish check is\n * BATCHED — ONE call per distinct entity-type bucket per page (a handful of\n * types at most; the routable set is config-time-fixed, never\n * attacker-influenced), never one call per row.\n *\n * **Leaf module.** Every cross-package dependency (the index reader, the publish\n * filter) is injected via `deps`; this module imports no `@murumets-ee/core` and\n * no `server-only` graph. Concrete deps are built from an app in\n * `./resolve-context.ts` (`buildEnumerateDeps`), keeping the resolution surface\n * off the `lumi` CLI command graph (F027 guardrail).\n *\n * Function-form-path entities need NO special handling — their rows were already\n * materialized into `toolkit_paths` at write time (F004 / phase 05 §2), so a\n * plain index read includes them.\n */\n\nimport { mapBounded } from './apply-path.js'\n\n// ---------------------------------------------------------------------------\n// Read surface (a `type` alias, per index-reader.ts's Deviation-1 rationale, so\n// the real `ToolkitPathsClient` stays assignable to it without any cast).\n// ---------------------------------------------------------------------------\n\n/** The projected `toolkit_paths` row the enumeration + batch lookup read. */\nexport type PathEnumRow = {\n id: string\n entityType: string\n entityId: string\n locale: string\n path: string\n updatedAt: Date\n}\n\n/**\n * The (operator-carrying) where shapes enumeration issues: keyset `id > cursor`,\n * `entityId IN (...)` for the batch lookup, plus plain-value equality filters.\n * A subset of the real client's `ColumnOperators` where-clause, so the real\n * `ToolkitPathsClient` is assignable to {@link PathEnumReader}.\n */\nexport type PathEnumWhere = {\n id?: { gt: string }\n entityType?: string\n entityId?: { in: string[] }\n locale?: string\n /** `{ in }` for a batched membership read (`resolvePublishedPathsAmong`). */\n path?: string | { in: string[] }\n isCanonical?: boolean\n}\n\n/**\n * The batched keyset read surface {@link enumeratePaths} / {@link getCanonicalPaths}\n * need. NARROWER than Task 1's point-lookup `PathIndexReader` (which only orders\n * by `updatedAt` and takes plain-value where): enumeration needs `id`-ordering,\n * a `{ gt }` cursor, and `{ in }` batching. Construct the real client directly\n * (`toolkitPathsTable.makeClient(db)`) — it satisfies this type.\n */\nexport type PathEnumReader = {\n findMany(options: {\n where?: PathEnumWhere\n orderBy?: Array<{ column: 'id'; dir?: 'asc' | 'desc' }>\n limit?: number\n }): Promise<PathEnumRow[]>\n}\n\n/**\n * Batch publish check: return the SUBSET of `entityIds` that is published in\n * `locale`. Called ONCE per entity-type group per page. The concrete\n * implementation (see `resolve-context.ts`) runs an elevated-context\n * `QueryClient.findMany({ where: inArray(getTable().id, ids), locale })` — so no\n * unpublished/trashed id comes back. Since D017 the publish filter is\n * CONDITIONAL (it holds for any principal without `view_unpublished`); what\n * keeps that true here is that the elevated context is a REACH context which\n * withholds that action, not that the filter is unconditional.\n */\nexport type PublishFilter = (\n entityType: string,\n entityIds: readonly string[],\n locale: string,\n) => Promise<ReadonlySet<string>>\n\n// ---------------------------------------------------------------------------\n// Public surface\n// ---------------------------------------------------------------------------\n\n/** One enumerated path row (phase 05 §2 — exact shape). */\nexport interface PathEntry {\n path: string\n entityType: string\n id: string\n updatedAt: Date\n}\n\n/** Options for {@link enumeratePaths} (phase 05 §2 — exact shape). */\nexport interface EnumeratePathsOptions {\n /** Enumerate this locale's canonical rows only. */\n locale: string\n /** Optionally narrow to a single routable entity type. */\n entityType?: string\n /**\n * Resume the keyset AFTER this `toolkit_paths` row id (exclusive); omit to\n * start from the beginning. The value is the opaque `toolkit_paths` PK the\n * internal page cursor advances on — NOT the yielded `PathEntry.id`, which is\n * the DOCUMENT (entity) id. A cross-request paginating caller (e.g. the\n * content-api `_paths` endpoint) resolves the last consumed entry's row PK and\n * passes it here to continue exactly where the prior page stopped, with no row\n * skipped or repeated. Fully backward-compatible: existing callers omit it and\n * traverse from the start unchanged.\n */\n afterId?: string\n}\n\n/** Injected dependencies for {@link enumeratePaths}. */\nexport interface EnumeratePathsDeps {\n pathsClient: PathEnumReader\n filterPublished: PublishFilter\n}\n\n/** Internal tuning seam (page size / batch concurrency). Real callers omit it. */\nexport interface EnumeratePathsTuning {\n /** Rows per index page. Defaults to {@link ENUMERATE_PAGE_SIZE}. Tests force a small value. */\n pageSize?: number\n /** Peak concurrent publish-check groups. Defaults to {@link PUBLISH_CHECK_CONCURRENCY}. */\n publishConcurrency?: number\n}\n\n/**\n * Index page size — mirrors the rebuild job's `REBUILD_PAGE_SIZE`. Must stay\n * ≤ the `defineTable` `MAX_LIMIT` (1000), which THROWS rather than clamps.\n */\nconst ENUMERATE_PAGE_SIZE = 200\n\n/**\n * Peak concurrent publish-check groups per page. A page holds a handful of\n * distinct entity types at most, so this bound is rarely reached — it exists so\n * the fan-out is EXPLICITLY capped (CLAUDE.md), never `Promise.all` over an\n * unbounded set.\n */\nconst PUBLISH_CHECK_CONCURRENCY = 5\n\n/**\n * Stream the published canonical paths for `opts.locale` (optionally narrowed to\n * `opts.entityType`), keyset-paginated with a per-page batched publish filter.\n * See the module header for the security + fan-out guarantees.\n */\nexport async function* enumeratePaths(\n opts: EnumeratePathsOptions,\n deps: EnumeratePathsDeps,\n tuning: EnumeratePathsTuning = {},\n): AsyncGenerator<PathEntry> {\n const pageSize = tuning.pageSize ?? ENUMERATE_PAGE_SIZE\n const concurrency = tuning.publishConcurrency ?? PUBLISH_CHECK_CONCURRENCY\n const { locale, entityType } = opts\n\n // Seed from `opts.afterId` so a caller can resume mid-stream; undefined starts\n // at the beginning (every existing caller's behavior, unchanged).\n let cursorId: string | undefined = opts.afterId\n for (;;) {\n // Keyset cursor on the immutable `id` PK (the rebuild job's precedent):\n // visits every canonical row exactly once even under concurrent mutation,\n // which OFFSET paging cannot guarantee.\n const where: PathEnumWhere = { locale, isCanonical: true }\n if (entityType !== undefined) where.entityType = entityType\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 (bounded: the routable-type set is\n // small + config-fixed), then ONE publish check per group.\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 publishedByType = new Map<string, ReadonlySet<string>>()\n await mapBounded([...byType.entries()], concurrency, async ([type, rows]) => {\n const published = await deps.filterPublished(\n type,\n rows.map((r) => r.entityId),\n locale,\n )\n publishedByType.set(type, published)\n })\n\n // Yield only the page's PUBLISHED rows, preserving the id-ascending order.\n for (const row of page) {\n if (publishedByType.get(row.entityType)?.has(row.entityId)) {\n yield {\n path: row.path,\n entityType: row.entityType,\n id: row.entityId,\n updatedAt: row.updatedAt,\n }\n }\n }\n\n // Advance the cursor to the last (max-id) row of this raw page. `page` is\n // non-empty here (length-0 broke above). Publish-filtering is a POST-filter,\n // so the cursor always steps over every index row regardless of publish state.\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// getCanonicalPaths — batched forward lookup (search url re-point), NO publish filter\n// ---------------------------------------------------------------------------\n\n/** Deps for {@link getCanonicalPaths}. */\nexport interface CanonicalPathsBatchDeps {\n pathsClient: PathEnumReader\n}\n\n/**\n * Max ids per batched index query — well under `defineTable`'s `MAX_LIMIT`\n * (1000, which throws rather than clamps). Search result pages are far smaller\n * than this, so this is one query in practice; larger id sets chunk safely.\n */\nconst CANONICAL_BATCH_SIZE = 500\n\n/**\n * The current canonical paths for many `(entityType, entityId)` in ONE locale,\n * as an `entityId → path` map — the batched sibling of `getCanonicalPath`.\n *\n * **No publish filter — deliberate**, matching `getCanonicalPath` (and the\n * search url builder it re-points): a search result's url is display-only and\n * the caller already gates row visibility. One index query per {@link\n * CANONICAL_BATCH_SIZE}-sized chunk (one query total for a normal search page),\n * so it never fans out per row.\n */\nexport async function getCanonicalPaths(\n entityType: string,\n entityIds: readonly string[],\n locale: string,\n deps: CanonicalPathsBatchDeps,\n): Promise<Map<string, string>> {\n const result = new Map<string, string>()\n for (let i = 0; i < entityIds.length; i += CANONICAL_BATCH_SIZE) {\n const chunk = entityIds.slice(i, i + CANONICAL_BATCH_SIZE)\n const rows = await deps.pathsClient.findMany({\n where: { entityType, locale, isCanonical: true, entityId: { in: [...chunk] } },\n limit: chunk.length,\n })\n for (const row of rows) result.set(row.entityId, row.path)\n }\n return result\n}\n"],"mappings":"sJAgKA,eAAuB,EACrB,EACA,EACA,EAA+B,CAAC,EACL,CAC3B,IAAM,EAAW,EAAO,UAAY,IAC9B,EAAc,EAAO,oBAAsB,EAC3C,CAAE,SAAQ,cAAe,EAI3B,EAA+B,EAAK,QACxC,OAAS,CAIP,IAAM,EAAuB,CAAE,SAAQ,YAAa,EAAK,EACrD,IAAe,IAAA,KAAW,EAAM,WAAa,GAC7C,IAAa,IAAA,KAAW,EAAM,GAA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AAK,IAAM,KAAO,EAAM,EAAO,IAAI,EAAI,SAAU,EAAI,IAAI,CAC3D,CACA,OAAO,CACT"}
@@ -0,0 +1,2 @@
1
+ var e=class extends Error{entityName;capability;constructor(e,t,n){super(n??`Entity "${e}" does not support ${t}. Add the corresponding behavior to defineEntity({ behaviors: [...] }).`),this.name=`EntityCapabilityError`,this.entityName=e,this.capability=t}},t=class extends Error{entityId;locale;constructor(e,t){super(t===`_`?`No pending draft to publish — this document is already up to date.`:`No pending draft to publish for locale "${t}" — it is already up to date.`),this.name=`DraftNotFoundError`,this.entityId=e,this.locale=t}},n=class extends Error{entityId;version;locale;constructor(e,t,n){super(`Version ${t} not found for entity ${e}`),this.name=`VersionNotFoundError`,this.entityId=e,this.version=t,this.locale=n}},r=class extends Error{locale;allowed;constructor(e,t){super(`Invalid locale "${e}". Configured locales: [${t.join(`, `)}]. (The "_" sentinel is also accepted for default-locale storage.)`),this.name=`InvalidLocaleError`,this.locale=e,this.allowed=t}};export{n as i,e as n,r,t};
2
+ //# sourceMappingURL=errors-NRNILhhm.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors-NRNILhhm.mjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/**\n * Domain errors for ContentClient + LockService.\n */\n\n/**\n * Thrown when a caller invokes an entity-capability-specific method on an\n * entity that doesn't have the corresponding behavior — e.g. `saveDraft`\n * on a non-publishable entity, `setLocaleStatus` on an entity without\n * publishable+translatable, `restoreVersion` on a non-versionable entity.\n *\n * Distinct from generic `Error` so admin-ui's API handler can map it to\n * 400 Bad Request (caller's fault) rather than 500 (server bug).\n */\nexport class EntityCapabilityError extends Error {\n readonly entityName: string\n readonly capability: 'drafts' | 'versions' | 'localeStatus' | 'translations'\n\n constructor(\n entityName: string,\n capability: EntityCapabilityError['capability'],\n message?: string,\n ) {\n super(\n message ??\n `Entity \"${entityName}\" does not support ${capability}. ` +\n `Add the corresponding behavior to defineEntity({ behaviors: [...] }).`,\n )\n this.name = 'EntityCapabilityError'\n this.entityName = entityName\n this.capability = capability\n }\n}\n\n/**\n * Thrown by `publishDraft` when there is no pending draft for the requested\n * entity+locale — publishing is a promote-the-draft operation, so \"nothing\n * to promote\" is a caller-state condition, not a server fault.\n *\n * Distinct from generic `Error` so admin-ui's API handler can map it to\n * 409 Conflict with a human-readable message instead of a generic 500\n * (which is what users saw pre-PR-23 — F031 #1).\n */\nexport class DraftNotFoundError extends Error {\n readonly entityId: string\n readonly locale: string\n\n constructor(entityId: string, locale: string) {\n // NB: the `_` default-locale sentinel is an internal storage key — never\n // show it to users (PR 23 user-smoke find).\n super(\n locale === '_'\n ? 'No pending draft to publish — this document is already up to date.'\n : `No pending draft to publish for locale \"${locale}\" — it is already up to date.`,\n )\n this.name = 'DraftNotFoundError'\n this.entityId = entityId\n this.locale = locale\n }\n}\n\n/**\n * Thrown by `restoreVersion` when the requested version snapshot does not\n * exist for the entity+locale — either the version number is out of range,\n * or the entity row itself is gone (a deleted row has no versions).\n *\n * Distinct from generic `Error` so admin-ui's API handler can map it to\n * 404 Not Found, matching the route-level 404 the publishable branch\n * already returns for the same condition. Before this it fell through to\n * the generic 500 branch on non-publishable entities — the same\n * \"caller-state condition audited as a server fault\" defect as\n * `EntityNotFoundError` (`plan/admin-api-hardening` F008).\n */\nexport class VersionNotFoundError extends Error {\n readonly entityId: string\n readonly version: number\n readonly locale: string\n\n constructor(entityId: string, version: number, locale: string) {\n super(`Version ${version} not found for entity ${entityId}`)\n this.name = 'VersionNotFoundError'\n this.entityId = entityId\n this.version = version\n this.locale = locale\n }\n}\n\n/**\n * Thrown when a locale string passed at runtime is not configured in the\n * content plugin. The plugin validates `defaultLocale` at init time, but\n * the per-call `locale` parameter on every read/write is not naturally\n * checked — `validateLocale()` is the boundary check.\n *\n * Allows the `'_'` sentinel (used internally for default-locale rows in\n * versions/drafts/locale_status tables) so callers can pass it through.\n */\nexport class InvalidLocaleError extends Error {\n readonly locale: string\n readonly allowed: readonly string[]\n\n constructor(locale: string, allowed: readonly string[]) {\n super(\n `Invalid locale \"${locale}\". Configured locales: [${allowed.join(', ')}]. ` +\n `(The \"_\" sentinel is also accepted for default-locale storage.)`,\n )\n this.name = 'InvalidLocaleError'\n this.locale = locale\n this.allowed = allowed\n }\n}\n"],"mappings":"AAaA,IAAa,EAAb,cAA2C,KAAM,CAC/C,WACA,WAEA,YACE,EACA,EACA,EACA,CACA,MACE,GACE,WAAW,EAAW,qBAAqB,EAAW,wEAE1D,EACA,KAAK,KAAO,wBACZ,KAAK,WAAa,EAClB,KAAK,WAAa,CACpB,CACF,EAWa,EAAb,cAAwC,KAAM,CAC5C,SACA,OAEA,YAAY,EAAkB,EAAgB,CAG5C,MACE,IAAW,IACP,qEACA,2CAA2C,EAAO,8BACxD,EACA,KAAK,KAAO,qBACZ,KAAK,SAAW,EAChB,KAAK,OAAS,CAChB,CACF,EAca,EAAb,cAA0C,KAAM,CAC9C,SACA,QACA,OAEA,YAAY,EAAkB,EAAiB,EAAgB,CAC7D,MAAM,WAAW,EAAQ,wBAAwB,GAAU,EAC3D,KAAK,KAAO,uBACZ,KAAK,SAAW,EAChB,KAAK,QAAU,EACf,KAAK,OAAS,CAChB,CACF,EAWa,EAAb,cAAwC,KAAM,CAC5C,OACA,QAEA,YAAY,EAAgB,EAA4B,CACtD,MACE,mBAAmB,EAAO,0BAA0B,EAAQ,KAAK,IAAI,EAAE,mEAEzE,EACA,KAAK,KAAO,qBACZ,KAAK,OAAS,EACd,KAAK,QAAU,CACjB,CACF"}