@weatherboard/cms 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +96 -1
  2. package/dist/contracts/query.d.cts +3 -0
  3. package/dist/contracts/query.d.mts +3 -0
  4. package/dist/contracts/query.d.ts +3 -0
  5. package/dist/index.cjs +5 -1
  6. package/dist/index.cjs.map +4 -4
  7. package/dist/index.d.cts +3 -0
  8. package/dist/index.d.mts +3 -0
  9. package/dist/index.d.ts +3 -0
  10. package/dist/index.mjs +5 -1
  11. package/dist/index.mjs.map +4 -4
  12. package/dist/next.cjs +5 -1
  13. package/dist/next.cjs.map +4 -4
  14. package/dist/next.d.cts +3 -0
  15. package/dist/next.d.mts +3 -0
  16. package/dist/next.d.ts +3 -0
  17. package/dist/next.mjs +5 -1
  18. package/dist/next.mjs.map +4 -4
  19. package/dist/portable/menu-options.d.cts +8 -0
  20. package/dist/portable/menu-options.d.mts +8 -0
  21. package/dist/portable/menu-options.d.ts +8 -0
  22. package/dist/portable/menu.d.cts +69 -0
  23. package/dist/portable/menu.d.mts +69 -0
  24. package/dist/portable/menu.d.ts +69 -0
  25. package/dist/portable/sections.d.cts +12 -2
  26. package/dist/portable/sections.d.mts +12 -2
  27. package/dist/portable/sections.d.ts +12 -2
  28. package/dist/portable/site-content.d.cts +2 -2
  29. package/dist/portable/site-content.d.mts +2 -2
  30. package/dist/portable/site-content.d.ts +2 -2
  31. package/dist/sanity.cjs +1 -1
  32. package/dist/sanity.cjs.map +2 -2
  33. package/dist/sanity.mjs +1 -1
  34. package/dist/sanity.mjs.map +2 -2
  35. package/dist/server.cjs +5 -1
  36. package/dist/server.cjs.map +4 -4
  37. package/dist/server.d.cts +3 -0
  38. package/dist/server.d.mts +3 -0
  39. package/dist/server.d.ts +3 -0
  40. package/dist/server.mjs +5 -1
  41. package/dist/server.mjs.map +4 -4
  42. package/dist/site-content.cjs +7 -3
  43. package/dist/site-content.cjs.map +4 -4
  44. package/dist/site-content.mjs +7 -3
  45. package/dist/site-content.mjs.map +4 -4
  46. package/package.json +1 -1
package/README.md CHANGED
@@ -98,7 +98,12 @@ the path in the stored document, never copy:
98
98
  - `section.layout.defaulted`: missing or unknown `layout`; the composition
99
99
  default renders. It never throws and never yields an empty section.
100
100
  - `section.type.unknown`: a section `_type` this reader does not know is
101
- skipped; the rest of the page reads.
101
+ skipped; the rest of the page reads. This warning also requires `type`, the
102
+ schema type name, so a build can log it with `PageContent.slug`. The name is
103
+ truncated to 64 characters; only ASCII letters, digits, `_`, `-` and `.` are
104
+ preserved, and other characters become `?`. Missing or non-string `_type`
105
+ values produce `type: "?"`, without serializing content. `code` and `where`
106
+ stay unchanged; other warning codes have no `type` field.
102
107
  - `section.image.missing-alt`: an image without alt text is dropped, never
103
108
  returned without it. `text_media.image` is then `null`; a gallery keeps its
104
109
  other photos.
@@ -117,6 +122,96 @@ The warnings travel in the page data, not in the server reader's
117
122
 
118
123
  0.3.0 is an additive minor under the pilot semver policy: a new reader kind.
119
124
 
125
+ ## Food and drink menus (0.6.0)
126
+
127
+ 0.6.0 is an additive minor: a new reader kind. `menuBlock` now reads as
128
+ `{ kind: "menu", layout, decoration, menu }` inside `PageContent.sections`.
129
+ Both page queries dereference `menu->{...}` with the saved menu fields.
130
+ `MENU_LAYOUTS` (`stacked`, `columns`), `MENU_DECORATIONS` (`none`, `playful`)
131
+ and `MENU_LAYOUT_DEFAULTS` (`stacked`, `none`) are separate from composition
132
+ layout lists. Missing or unknown choices use these defaults with
133
+ `section.layout.defaulted` at the layout or decoration path.
134
+
135
+ A missing, dangling, draft-only or release-version reference skips that section
136
+ with `section.menu.unavailable` and its `where` path. Other page sections still
137
+ read. Genuinely unknown section types still record `section.type.unknown`.
138
+ Malformed menu fields throw `MalformedContentError` naming their saved path,
139
+ including the section's path for referenced menus. Warnings never carry copy.
140
+
141
+ `menuQuery(id)`, `parseMenuDocument(raw)`, `menuTags(scope, id?)` and the menu
142
+ types are exported from the pure root, `/server` and `/next`. A standalone
143
+ query selects a published `menu` by id and records type and id dependencies.
144
+ The Sanity adapter uses the published perspective. Other transports supplied to
145
+ `createSiteContentReader` must also select published content.
146
+
147
+ `MenuDocument` is CMS-owned saved data, structurally compatible with the
148
+ schema-base mapper: `_type: "menu"` and array `_key` identities survive.
149
+ Other Sanity system fields are dropped except `_id`, `_rev` and `_updatedAt`.
150
+ `_updatedAt` remains the exact published update date; use it for the displayed
151
+ last-updated date, including during an outage. Lists and copy retain their
152
+ order and text. Sanity's omitted/null empty lists become `[]`; omitted/null
153
+ availability becomes `available`. Optional null text is omitted. Money must
154
+ have a whole non-negative safe amount and a three-letter currency code.
155
+ The site maps this document with `menuDocumentToContract` and validates business
156
+ constraints there, including recognised currencies, dietary labels, identity
157
+ uniqueness and currency consistency. `signOff` passes through untouched as
158
+ `unknown` plain JSON data: the site checks its shape and uses the contract's `isLive` to decide
159
+ whether the exact content is approved. This reader never grants approval.
160
+
161
+ Menu parsing accepts plain JSON data as Sanity returns it. It snapshots each
162
+ own data property once before checking fields and builds the result only from
163
+ that snapshot, including an unchanged copy of the opaque sign-off data.
164
+ Accessors are rejected without invoking their getters. Non-plain prototypes,
165
+ symbol keys, sparse arrays, non-finite numbers, undefined values and cycles
166
+ are rejected with a named path. Proxy reflection failures also become
167
+ `MalformedContentError`; ordinary Proxy get traps are never invoked. Portable
168
+ JavaScript cannot identify every transparent Proxy: a Proxy that supplies data
169
+ descriptors is validated solely from the captured descriptor values, never
170
+ from a later caller read. The returned objects share no caller-owned data.
171
+
172
+ CMS has no runtime dependency on the unpublished menu or schema packages.
173
+ Compatibility is exercised with a copied, neutral café saved-shape fixture;
174
+ there is no schema devDependency or menu test-fixture import. Publication tests
175
+ resolve imports in source, all eight entry bundles and their build input paths,
176
+ including relative imports into either forbidden package root and type specifiers.
177
+ Type-only test imports are refused too because the copied-fixture option was used.
178
+
179
+ ```ts
180
+ import { menuQuery, menuTags } from '@weatherboard/cms';
181
+ import { createNextCmsReader, createRevalidateRoute } from '@weatherboard/cms/next';
182
+
183
+ // adapter and lastPublishedMenu come from the site's existing CMS configuration
184
+ // and retained published snapshot. No sample menu is supplied on failure.
185
+ const reader = createNextCmsReader({ adapter });
186
+ const result = await reader.read(menuQuery(menuId), { fallback: lastPublishedMenu });
187
+ const tags = menuTags(adapter.scope, menuId);
188
+ const route = createRevalidateRoute({
189
+ scope: adapter.scope,
190
+ typeToTags: { page: ['page'], menu: ['menu'] },
191
+ });
192
+ ```
193
+
194
+ `menuTags` follows `cmsTags`: `cms:<scope>:type:menu` plus, when an id is
195
+ supplied, `cms:<scope>:id:<id>`. Existing tags are unchanged. Page queries now
196
+ depend on both `page` and `menu`, so a menu webhook invalidates referencing page
197
+ reads too. Add `menu: ['menu']` to the site's existing `typeToTags` mapping;
198
+ retain its other entries. The webhook's existing id invalidation also covers
199
+ standalone menu reads. Keep the adapter's hourly cache policy.
200
+
201
+ **Stale fallback requires a host-retained snapshot.** The existing runtime
202
+ validates the supplied fallback before I/O and returns it on network, timeout,
203
+ upstream, missing-document or malformed-read failures. Tests first read a good
204
+ published menu/page, supply that result as the next fallback, then fail the
205
+ read and check the content and original `_updatedAt`. Never replace this with
206
+ sample content or the current clock. `createCmsReader` does not store last-good
207
+ content itself; the host retains it using its existing persistence/cache path.
208
+ Plain fetch has no persistent cache. A successful page read with an unavailable
209
+ menu deliberately skips the section; it cannot recover an individual menu from
210
+ a previous page snapshot. Per-reference last-good recovery is a runtime gap,
211
+ and this release adds no cache layer. The legacy `createSiteContentReader`
212
+ throws read failures and has no fallback option; use the runtime query API for
213
+ the documented fallback behavior.
214
+
120
215
  ## Schema and release delivery
121
216
 
122
217
  `@weatherboard/sanity-schema-base` derives the hero schema from these rules:
@@ -1,3 +1,4 @@
1
+ import { type MenuDocument } from "../portable/menu.cjs";
1
2
  /** A-1822 S1 owns this implementation. S0 registers the public signatures. */
2
3
  export type CmsParams = Readonly<Record<string, string | number | boolean | null>>;
3
4
  export type CmsDependencies = {
@@ -18,3 +19,5 @@ export type CmsQuery<T> = {
18
19
  };
19
20
  export declare function defineCmsQuery<T>(query: CmsQuery<T>): CmsQuery<T>;
20
21
  export declare function cmsTags(scope: string, dependencies: CmsDependencies): readonly string[];
22
+ /** Read one published menu by its document id; host supplies the last good snapshot. */
23
+ export declare function menuQuery(id: string): CmsQuery<MenuDocument | null>;
@@ -1,3 +1,4 @@
1
+ import { type MenuDocument } from "../portable/menu.mjs";
1
2
  /** A-1822 S1 owns this implementation. S0 registers the public signatures. */
2
3
  export type CmsParams = Readonly<Record<string, string | number | boolean | null>>;
3
4
  export type CmsDependencies = {
@@ -18,3 +19,5 @@ export type CmsQuery<T> = {
18
19
  };
19
20
  export declare function defineCmsQuery<T>(query: CmsQuery<T>): CmsQuery<T>;
20
21
  export declare function cmsTags(scope: string, dependencies: CmsDependencies): readonly string[];
22
+ /** Read one published menu by its document id; host supplies the last good snapshot. */
23
+ export declare function menuQuery(id: string): CmsQuery<MenuDocument | null>;
@@ -1,3 +1,4 @@
1
+ import { type MenuDocument } from "../portable/menu.js";
1
2
  /** A-1822 S1 owns this implementation. S0 registers the public signatures. */
2
3
  export type CmsParams = Readonly<Record<string, string | number | boolean | null>>;
3
4
  export type CmsDependencies = {
@@ -18,3 +19,5 @@ export type CmsQuery<T> = {
18
19
  };
19
20
  export declare function defineCmsQuery<T>(query: CmsQuery<T>): CmsQuery<T>;
20
21
  export declare function cmsTags(scope: string, dependencies: CmsDependencies): readonly string[];
22
+ /** Read one published menu by its document id; host supplies the last good snapshot. */
23
+ export declare function menuQuery(id: string): CmsQuery<MenuDocument | null>;
package/dist/index.cjs CHANGED
@@ -1,2 +1,6 @@
1
- "use strict";var m=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var D=(e,t)=>{for(var o in t)m(e,o,{get:t[o],enumerable:!0})},N=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of A(t))!L.call(e,n)&&n!==o&&m(e,n,{get:()=>t[n],enumerable:!(r=v(t,n))||r.enumerable});return e};var $=e=>N(m({},"__esModule",{value:!0}),e);var F={};D(F,{CMS_CONTRACT_VERSION:()=>R,SITE_HERO:()=>y,SITE_HERO_LAYOUTS:()=>T,SITE_HERO_LAYOUT_WARNING:()=>S,SITE_HERO_TAGLINES_DEFAULTED_WARNING:()=>E,SITE_HERO_TAGLINE_DROPPED_WARNING:()=>H,SITE_HERO_TAGLINE_MAX_LENGTH:()=>h,cmsTags:()=>k,defineCmsQuery:()=>f,parseSiteHero:()=>x,siteHeroQuery:()=>I,validateSiteHeroTaglines:()=>w,validateTextDocument:()=>g});module.exports=$(F);var j=/^[A-Za-z][A-Za-z0-9_]{0,63}$/,z=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/,P=/^[a-z0-9]{6,12}\.[a-z][a-z0-9_-]{0,63}$/;function O(e){if(!e||!Array.isArray(e.types)||e.types.length===0)throw new TypeError("CMS dependencies require document types");let t=[...e.types];for(let r of t)if(typeof r!="string"||!j.test(r))throw new TypeError("Invalid CMS document type");if(e.ids!==void 0&&!Array.isArray(e.ids))throw new TypeError("Invalid CMS document IDs");let o=e.ids===void 0?void 0:[...e.ids];for(let r of o??[])if(typeof r!="string"||!z.test(r)||/^(drafts|versions)\./.test(r))throw new TypeError("Invalid CMS document ID");if(new Set(t).size+new Set(o).size>128)throw new TypeError("Too many CMS tags");return Object.freeze({types:Object.freeze(t),...o===void 0?{}:{ids:Object.freeze(o)}})}function f(e){if(!e||typeof e.name!="string"||!/^[A-Za-z][A-Za-z0-9_.-]{0,127}$/.test(e.name)||typeof e.query!="string"||e.query.trim()===""||typeof e.resolve!="function")throw new TypeError("Invalid CMS query configuration");let t=e.params;if(!t||typeof t!="object"||Object.getPrototypeOf(t)!==Object.prototype&&Object.getPrototypeOf(t)!==null)throw new TypeError("CMS params must be plain JSON scalars");let o={};for(let r of Reflect.ownKeys(t)){let n=Object.getOwnPropertyDescriptor(t,r);if(typeof r!="string"||!n||!Object.hasOwn(n,"value")||!n.enumerable)throw new TypeError("CMS params must be plain JSON scalars");let i=n.value;if(!(i===null||typeof i=="string"||typeof i=="boolean"||typeof i=="number"&&Number.isFinite(i)))throw new TypeError("CMS params must be plain JSON scalars");Object.defineProperty(o,r,{value:i,enumerable:!0})}return Object.freeze({name:e.name,query:e.query,params:Object.freeze(o),dependencies:O(e.dependencies),resolve:e.resolve})}function k(e,t){if(typeof e!="string"||e.length>77||!P.test(e))throw new TypeError("Invalid CMS scope");let o=O(t),r=[...[...new Set(o.types)].sort().map(n=>`cms:${e}:type:${n}`),...[...new Set(o.ids??[])].sort().map(n=>`cms:${e}:id:${n}`)];return Object.freeze(r)}var T=["columns","rows"],h=40,S="siteHero.layout.defaulted",H="siteHero.tagline.dropped",E="siteHero.taglines.defaulted",R=1,y={key:"hero",documentId:"siteHero",documentType:"siteHero",fields:[{name:"heading",label:"Heading",noun:{article:"a",word:"heading"},kind:"single-line",required:!0,minLength:1,maxLength:80,noTrailingFullStop:!0},{name:"intro",label:"Introduction",noun:{article:"an",word:"introduction"},kind:"multi-line",required:!0,minLength:1,maxLength:320}],copy:{currentTitle:"On your site now",editTitle:"Edit and publish",empty:"Your site has no hero text yet. Whatever you publish below becomes its first version."}};function M(e,t){let{article:o,word:r}=e.noun;if(t.length===0)return e.required?`Enter ${o} ${r}.`:null;let n=[...t].length;return n<e.minLength?`Make the ${r} at least ${String(e.minLength)} characters. It is ${String(n)} now.`:n>e.maxLength?`Keep the ${r} to ${String(e.maxLength)} characters or fewer. It is ${String(n)} now.`:t.includes("\u2014")?`The ${r} contains a long dash. Use a comma, a colon or a short dash instead.`:e.kind==="single-line"&&/[\r\n]/.test(t)?`The ${r} must be a single line.`:e.noTrailingFullStop===!0&&t.endsWith(".")?`${r.charAt(0).toUpperCase()}${r.slice(1)}s on your site do not end with a full stop. Remove the last full stop.`:null}function g(e,t){let o={},r={};for(let n of e.fields){let i=Object.hasOwn(t,n.name)?t[n.name]:void 0,a=typeof i=="string"?i.trim():"",s=M(n,a);Object.defineProperty(s===null?o:r,n.name,{value:s??a,enumerable:!0})}return Object.keys(r).length>0?{ok:!1,errors:r}:{ok:!0,value:o}}function C(e){if(!Array.isArray(e))return{ok:!1,error:"Enter a list of taglines."};let t=y.fields[0];if(!t)throw new TypeError("Missing siteHero heading definition");let o={...t,name:"text",noun:{article:"a",word:"tagline"},maxLength:h},r=[],n=[],i=new Set;for(let[a,s]of e.entries()){if(!s||typeof s!="object"||Array.isArray(s)){n.push({index:a,error:"Enter a key and text for each tagline."});continue}let c=s,d=Object.hasOwn(c,"key")?c.key:void 0;if(typeof d!="string"||!/^[a-z][a-z0-9_-]{0,31}$/.test(d)){n.push({index:a,error:"Use a lowercase key of 1 to 32 letters, numbers, short dashes or underscores, starting with a letter."});continue}if(i.has(d)){n.push({index:a,error:"Use each tagline key only once."});continue}let u=g({...y,fields:[o]},c);if(!u.ok){n.push({index:a,error:u.errors.text??"Invalid tagline."});continue}let p=u.value.text??"";if((p.match(/\p{L}/gu)?.length??0)>=2&&!/\p{Ll}/u.test(p)){n.push({index:a,error:"Use sentence case for the tagline, rather than all capitals."});continue}i.add(d),r.push({key:d,text:p})}return{ok:!0,value:r,dropped:n}}function w(e){let t=C(e);if(!t.ok)return t;let o=t.dropped[0];return o?{ok:!1,error:o.error}:{ok:!0,value:t.value}}function _(e){return T.some(t=>e===t)}function x(e,t){let o=g(y,t),r=w(t.taglines??[]);if(!o.ok||!r.ok||t.layout!==void 0&&!_(t.layout))throw new TypeError("Invalid siteHero fallback");let n={heading:o.value.heading??"",intro:o.value.intro??"",layout:t.layout??"columns",taglines:r.value};if(e===null||typeof e!="object"||Array.isArray(e))return{data:n,fallbackFields:["$"]};let i=e,a=g(y,i),s=a.ok?[]:Object.keys(a.errors);for(let l of y.fields)if(!s.includes(l.name)){let b=a.ok?a.value[l.name]:i[l.name];typeof b=="string"&&(l.name==="heading"||l.name==="intro")&&(n[l.name]=b.trim())}let c=Object.hasOwn(i,"layout")?i.layout:void 0,d=[];_(c)?n.layout=c:(n.layout="columns",s.push("layout"),d.push(S));let u=C(Object.hasOwn(i,"taglines")?i.taglines:void 0);if(u.ok){n.taglines=u.value;for(let{index:l}of u.dropped)s.push(`taglines[${String(l)}]`);u.dropped.length>0&&d.push(H)}else s.push("taglines"),d.push(E);let p=[...y.fields.map(l=>l.name),"layout","taglines"].every(l=>s.includes(l));return{data:n,fallbackFields:p?["$"]:s,...d.length>0?{warnings:d}:{}}}function I(){return f({name:"siteHero.v1",query:'*[_id == $id && _type == "siteHero"][0]{heading,intro,layout,taglines}',params:{id:"siteHero"},dependencies:{types:["siteHero"],ids:["siteHero"]},resolve:x})}0&&(module.exports={CMS_CONTRACT_VERSION,SITE_HERO,SITE_HERO_LAYOUTS,SITE_HERO_LAYOUT_WARNING,SITE_HERO_TAGLINES_DEFAULTED_WARNING,SITE_HERO_TAGLINE_DROPPED_WARNING,SITE_HERO_TAGLINE_MAX_LENGTH,cmsTags,defineCmsQuery,parseSiteHero,siteHeroQuery,validateSiteHeroTaglines,validateTextDocument});
1
+ "use strict";var I=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var ee=Object.prototype.hasOwnProperty;var ne=(n,e)=>{for(var t in e)I(n,t,{get:e[t],enumerable:!0})},te=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of X(e))!ee.call(n,r)&&r!==t&&I(n,r,{get:()=>e[r],enumerable:!(o=Z(e,r))||o.enumerable});return n};var oe=n=>te(I({},"__esModule",{value:!0}),n);var ge={};ne(ge,{CMS_CONTRACT_VERSION:()=>Q,MENU_DECORATIONS:()=>A,MENU_LAYOUTS:()=>C,MENU_LAYOUT_DEFAULTS:()=>O,SITE_HERO:()=>g,SITE_HERO_LAYOUTS:()=>R,SITE_HERO_LAYOUT_WARNING:()=>N,SITE_HERO_TAGLINES_DEFAULTED_WARNING:()=>j,SITE_HERO_TAGLINE_DROPPED_WARNING:()=>D,SITE_HERO_TAGLINE_MAX_LENGTH:()=>M,cmsTags:()=>x,defineCmsQuery:()=>_,menuQuery:()=>G,menuTags:()=>U,parseMenuDocument:()=>k,parseSiteHero:()=>P,siteHeroQuery:()=>K,validateSiteHeroTaglines:()=>H,validateTextDocument:()=>$});module.exports=oe(ge);function L(n){if(!Array.isArray(n))return!1;for(let e=0;e<n.length;e+=1)if(!Object.hasOwn(n,e))return!1;return!0}var C=["stacked","columns"],A=["none","playful"],O={layout:"stacked",decoration:"none"},E=`_type, _id, _rev, _updatedAt, title, locationKeys, note, signOff,
2
+ variants[]{_key, label, note, sections[]{_key, title, service, items[]{
3
+ _key, name, description, priceNote, dietary, allergenNote, availability,
4
+ prices[]{_key, label, amount{minor, currency}}, extras[]{_key, name, amount{minor, currency}}
5
+ }}}`;function U(n,e){return x(n,{types:["menu"],...e===void 0?{}:{ids:[e]}})}function s(n,e){throw new S("menu",[`${n} ${e}`])}function v(n,e,t=new Set,o){if(n===null||typeof n=="string"||typeof n=="boolean"||typeof n=="number"&&Number.isFinite(n))return n;if(typeof n!="object"||n===null)return s(e,"is not plain JSON data");try{if(t.has(n))return s(e,"is not acyclic JSON data");let r=Array.isArray(n),i=Object.getPrototypeOf(n);if(r?i!==Array.prototype:i!==Object.prototype&&i!==null)return s(e,"is not an ordinary saved object");t.add(n);let d=Reflect.ownKeys(n),l=r?[]:{},f=0,y=0;for(let u of d){if(typeof u!="string")return s(e,"has a symbol key");let p=r&&u!=="length"?`${e}[${u}]`:`${e}.${u}`,a;try{a=u==="_id"&&o!==void 0?o:Object.getOwnPropertyDescriptor(n,u)}catch{return s(p,"could not be snapshotted as plain JSON data")}if(!a||!Object.hasOwn(a,"value"))return s(p,"is not a saved data property");if(r&&u==="length"){let T=a.value;if(typeof T!="number"||!Number.isSafeInteger(T)||T<0)return s(p,"is not a saved list length");f=T;continue}if(!a.enumerable||r&&!/^(0|[1-9]\d*)$/.test(u))return s(p,"is not a JSON data property");let w=a.value,V=v(w,p,t);Object.defineProperty(l,u,{value:V,enumerable:!0,writable:!0,configurable:!0}),y++}return r&&(y!==f||l.length!==f)?s(e,"is not a complete saved list"):l}catch(r){if(r instanceof S)throw r;return s(e,"could not be snapshotted as plain JSON data")}finally{t.delete(n)}}function b(n,e){return n===null||typeof n!="object"||Array.isArray(n)||Object.getPrototypeOf(n)!==Object.prototype&&Object.getPrototypeOf(n)!==null?s(e,"is not an ordinary saved object"):n}function c(n,e,t=!0){return typeof n!="string"||t&&n.trim()===""?s(e,"is not saved text"):n}function m(n,e,t){return n[e]===void 0||n[e]===null?{}:{[e]:c(n[e],`${t}.${e}`,!1)}}function h(n,e,t){return n==null?[]:L(n)?n.map((o,r)=>t(o,`${e}[${String(r)}]`)):s(e,"is not a complete saved list")}function q(n,e){let t=b(n,e);if(typeof t.minor!="number"||!Number.isSafeInteger(t.minor)||t.minor<0)return s(`${e}.minor`,"is not a whole non-negative safe amount");let o=c(t.currency,`${e}.currency`);return/^[A-Z]{3}$/.test(o)?{minor:t.minor,currency:o}:s(`${e}.currency`,"is not a three-letter currency code")}function re(n,e){let t=b(n,e);return{_key:c(t._key,`${e}._key`),amount:q(t.amount,`${e}.amount`),...m(t,"label",e)}}function ie(n,e){let t=b(n,e);return{_key:c(t._key,`${e}._key`),name:c(t.name,`${e}.name`),amount:q(t.amount,`${e}.amount`)}}function se(n,e){let t=b(n,e),o=t.availability??"available";return o!=="available"&&o!=="sold-out"&&o!=="hidden"?s(`${e}.availability`,"is not an availability choice"):{_key:c(t._key,`${e}._key`),name:c(t.name,`${e}.name`),...m(t,"description",e),...m(t,"priceNote",e),...m(t,"allergenNote",e),prices:h(t.prices,`${e}.prices`,re),extras:h(t.extras,`${e}.extras`,ie),dietary:h(t.dietary,`${e}.dietary`,c),availability:o}}function ae(n,e){let t=b(n,e);return{_key:c(t._key,`${e}._key`),title:c(t.title,`${e}.title`),...m(t,"service",e),items:h(t.items,`${e}.items`,se)}}function le(n,e){let t=b(n,e);return{_key:c(t._key,`${e}._key`),label:c(t.label,`${e}.label`),...m(t,"note",e),sections:h(t.sections,`${e}.sections`,ae)}}function ue(n){if(n===null||typeof n!="object"||Array.isArray(n))return!1;let e=n._id;return typeof e=="string"&&e.trim()!==""&&!/^(drafts|versions)\./.test(e)}function k(n,e="menu"){return ce(v(n,e),e)}function ce(n,e){let t=b(n,e);if(t._type!=="menu")return s(`${e}._type`,"is not menu");if(!ue(t))return s(`${e}._id`,"is not a published menu identity");let o=c(t._updatedAt,`${e}._updatedAt`);if(!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/.test(o)||!Number.isFinite(Date.parse(o)))return s(`${e}._updatedAt`,"is not an update date");let r=h(t.variants,`${e}.variants`,le);return r.length===0?s(`${e}.variants`,"has no menu choices"):{_type:"menu",_id:c(t._id,`${e}._id`),_rev:c(t._rev,`${e}._rev`),_updatedAt:o,title:c(t.title,`${e}.title`),locationKeys:h(t.locationKeys,`${e}.locationKeys`,c),variants:r,...m(t,"note",e),...Object.hasOwn(t,"signOff")?{signOff:t.signOff}:{}}}function F(n){if(n===null)return!0;try{return k(n),!0}catch{return!1}}var Y="malformed-content",S=class extends Error{code=Y;documentId;problems;constructor(e,t){super(`${Y}: ${e}: ${t.join("; ")}`),this.name="MalformedContentError",this.documentId=e,this.problems=t}};var z=`{..., "sections": coalesce(sections[]{..., _type == "menuBlock" => {menu->{${E}}}}, sections)}`,Ce=`*[_type == "page" && defined(slug.current)]|order(slug.current asc)${z}`,Ae=`*[_type == "page" && slug.current == $slug][0]${z}`;var de=/^[A-Za-z][A-Za-z0-9_]{0,63}$/,ye=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/,pe=/^[a-z0-9]{6,12}\.[a-z][a-z0-9_-]{0,63}$/;function B(n){if(!n||!Array.isArray(n.types)||n.types.length===0)throw new TypeError("CMS dependencies require document types");let e=[...n.types];for(let o of e)if(typeof o!="string"||!de.test(o))throw new TypeError("Invalid CMS document type");if(n.ids!==void 0&&!Array.isArray(n.ids))throw new TypeError("Invalid CMS document IDs");let t=n.ids===void 0?void 0:[...n.ids];for(let o of t??[])if(typeof o!="string"||!ye.test(o)||/^(drafts|versions)\./.test(o))throw new TypeError("Invalid CMS document ID");if(new Set(e).size+new Set(t).size>128)throw new TypeError("Too many CMS tags");return Object.freeze({types:Object.freeze(e),...t===void 0?{}:{ids:Object.freeze(t)}})}function _(n){if(!n||typeof n.name!="string"||!/^[A-Za-z][A-Za-z0-9_.-]{0,127}$/.test(n.name)||typeof n.query!="string"||n.query.trim()===""||typeof n.resolve!="function")throw new TypeError("Invalid CMS query configuration");let e=n.params;if(!e||typeof e!="object"||Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null)throw new TypeError("CMS params must be plain JSON scalars");let t={};for(let o of Reflect.ownKeys(e)){let r=Object.getOwnPropertyDescriptor(e,o);if(typeof o!="string"||!r||!Object.hasOwn(r,"value")||!r.enumerable)throw new TypeError("CMS params must be plain JSON scalars");let i=r.value;if(!(i===null||typeof i=="string"||typeof i=="boolean"||typeof i=="number"&&Number.isFinite(i)))throw new TypeError("CMS params must be plain JSON scalars");Object.defineProperty(t,o,{value:i,enumerable:!0})}return Object.freeze({name:n.name,query:n.query,params:Object.freeze(t),dependencies:B(n.dependencies),resolve:n.resolve})}function x(n,e){if(typeof n!="string"||n.length>77||!pe.test(n))throw new TypeError("Invalid CMS scope");let t=B(e),o=[...[...new Set(t.types)].sort().map(r=>`cms:${n}:type:${r}`),...[...new Set(t.ids??[])].sort().map(r=>`cms:${n}:id:${r}`)];return Object.freeze(o)}function G(n){return _({name:"menu.v1",query:`*[_type == "menu" && _id == $id && !(_id in path("drafts.**")) && !(_id in path("versions.**"))][0]{${E}}`,params:{id:n},dependencies:{types:["menu"],ids:[n]},resolve:(e,t)=>{if(!F(t)||t!==null&&t._id!==n)throw new TypeError("Invalid CMS menu fallback");if(e==null)return{data:t,fallbackFields:["$"]};let o=k(e);if(o._id!==n)throw new S("menu",["menu._id does not match the requested document"]);return{data:o,fallbackFields:[]}}})}var R=["columns","rows"],M=40,N="siteHero.layout.defaulted",D="siteHero.tagline.dropped",j="siteHero.taglines.defaulted",Q=1,g={key:"hero",documentId:"siteHero",documentType:"siteHero",fields:[{name:"heading",label:"Heading",noun:{article:"a",word:"heading"},kind:"single-line",required:!0,minLength:1,maxLength:80,noTrailingFullStop:!0},{name:"intro",label:"Introduction",noun:{article:"an",word:"introduction"},kind:"multi-line",required:!0,minLength:1,maxLength:320}],copy:{currentTitle:"On your site now",editTitle:"Edit and publish",empty:"Your site has no hero text yet. Whatever you publish below becomes its first version."}};function fe(n,e){let{article:t,word:o}=n.noun;if(e.length===0)return n.required?`Enter ${t} ${o}.`:null;let r=[...e].length;return r<n.minLength?`Make the ${o} at least ${String(n.minLength)} characters. It is ${String(r)} now.`:r>n.maxLength?`Keep the ${o} to ${String(n.maxLength)} characters or fewer. It is ${String(r)} now.`:e.includes("\u2014")?`The ${o} contains a long dash. Use a comma, a colon or a short dash instead.`:n.kind==="single-line"&&/[\r\n]/.test(e)?`The ${o} must be a single line.`:n.noTrailingFullStop===!0&&e.endsWith(".")?`${o.charAt(0).toUpperCase()}${o.slice(1)}s on your site do not end with a full stop. Remove the last full stop.`:null}function $(n,e){let t={},o={};for(let r of n.fields){let i=Object.hasOwn(e,r.name)?e[r.name]:void 0,d=typeof i=="string"?i.trim():"",l=fe(r,d);Object.defineProperty(l===null?t:o,r.name,{value:l??d,enumerable:!0})}return Object.keys(o).length>0?{ok:!1,errors:o}:{ok:!0,value:t}}function W(n){if(!Array.isArray(n))return{ok:!1,error:"Enter a list of taglines."};let e=g.fields[0];if(!e)throw new TypeError("Missing siteHero heading definition");let t={...e,name:"text",noun:{article:"a",word:"tagline"},maxLength:M},o=[],r=[],i=new Set;for(let[d,l]of n.entries()){if(!l||typeof l!="object"||Array.isArray(l)){r.push({index:d,error:"Enter a key and text for each tagline."});continue}let f=l,y=Object.hasOwn(f,"key")?f.key:void 0;if(typeof y!="string"||!/^[a-z][a-z0-9_-]{0,31}$/.test(y)){r.push({index:d,error:"Use a lowercase key of 1 to 32 letters, numbers, short dashes or underscores, starting with a letter."});continue}if(i.has(y)){r.push({index:d,error:"Use each tagline key only once."});continue}let u=$({...g,fields:[t]},f);if(!u.ok){r.push({index:d,error:u.errors.text??"Invalid tagline."});continue}let p=u.value.text??"";if((p.match(/\p{L}/gu)?.length??0)>=2&&!/\p{Ll}/u.test(p)){r.push({index:d,error:"Use sentence case for the tagline, rather than all capitals."});continue}i.add(y),o.push({key:y,text:p})}return{ok:!0,value:o,dropped:r}}function H(n){let e=W(n);if(!e.ok)return e;let t=e.dropped[0];return t?{ok:!1,error:t.error}:{ok:!0,value:e.value}}function J(n){return R.some(e=>n===e)}function P(n,e){let t=$(g,e),o=H(e.taglines??[]);if(!t.ok||!o.ok||e.layout!==void 0&&!J(e.layout))throw new TypeError("Invalid siteHero fallback");let r={heading:t.value.heading??"",intro:t.value.intro??"",layout:e.layout??"columns",taglines:o.value};if(n===null||typeof n!="object"||Array.isArray(n))return{data:r,fallbackFields:["$"]};let i=n,d=$(g,i),l=d.ok?[]:Object.keys(d.errors);for(let a of g.fields)if(!l.includes(a.name)){let w=d.ok?d.value[a.name]:i[a.name];typeof w=="string"&&(a.name==="heading"||a.name==="intro")&&(r[a.name]=w.trim())}let f=Object.hasOwn(i,"layout")?i.layout:void 0,y=[];J(f)?r.layout=f:(r.layout="columns",l.push("layout"),y.push(N));let u=W(Object.hasOwn(i,"taglines")?i.taglines:void 0);if(u.ok){r.taglines=u.value;for(let{index:a}of u.dropped)l.push(`taglines[${String(a)}]`);u.dropped.length>0&&y.push(D)}else l.push("taglines"),y.push(j);let p=[...g.fields.map(a=>a.name),"layout","taglines"].every(a=>l.includes(a));return{data:r,fallbackFields:p?["$"]:l,...y.length>0?{warnings:y}:{}}}function K(){return _({name:"siteHero.v1",query:'*[_id == $id && _type == "siteHero"][0]{heading,intro,layout,taglines}',params:{id:"siteHero"},dependencies:{types:["siteHero"],ids:["siteHero"]},resolve:P})}0&&(module.exports={CMS_CONTRACT_VERSION,MENU_DECORATIONS,MENU_LAYOUTS,MENU_LAYOUT_DEFAULTS,SITE_HERO,SITE_HERO_LAYOUTS,SITE_HERO_LAYOUT_WARNING,SITE_HERO_TAGLINES_DEFAULTED_WARNING,SITE_HERO_TAGLINE_DROPPED_WARNING,SITE_HERO_TAGLINE_MAX_LENGTH,cmsTags,defineCmsQuery,menuQuery,menuTags,parseMenuDocument,parseSiteHero,siteHeroQuery,validateSiteHeroTaglines,validateTextDocument});
2
6
  //# sourceMappingURL=index.cjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/index.ts", "../src/contracts/query.ts", "../src/contracts/text.ts"],
4
- "sourcesContent": ["export { defineCmsQuery, cmsTags } from \"./contracts/query.js\";\nexport type { CmsParams, CmsDependencies, CmsResolution, CmsQuery } from \"./contracts/query.js\";\nexport { SITE_HERO, CMS_CONTRACT_VERSION, validateTextDocument, siteHeroQuery, SITE_HERO_LAYOUTS, SITE_HERO_TAGLINE_MAX_LENGTH, SITE_HERO_LAYOUT_WARNING, SITE_HERO_TAGLINE_DROPPED_WARNING, SITE_HERO_TAGLINES_DEFAULTED_WARNING, parseSiteHero, validateSiteHeroTaglines } from \"./contracts/text.js\";\nexport type { SiteHero, ParsedSiteHero, SiteHeroLayout, SiteHeroTagline, TextFieldDefinition, TextDocumentDefinition, TextValidation } from \"./contracts/text.js\";\n", "/** A-1822 S1 owns this implementation. S0 registers the public signatures. */\nexport type CmsParams = Readonly<Record<string, string | number | boolean | null>>;\nexport type CmsDependencies = {\n readonly types: readonly string[];\n readonly ids?: readonly string[];\n};\nexport type CmsResolution<T> = {\n readonly data: T;\n readonly fallbackFields: readonly string[];\n readonly warnings?: readonly (\"siteHero.layout.defaulted\" | \"siteHero.tagline.dropped\" | \"siteHero.taglines.defaulted\")[];\n};\nexport type CmsQuery<T> = {\n readonly name: string;\n readonly query: string;\n readonly params: CmsParams;\n readonly dependencies: CmsDependencies;\n readonly resolve: (raw: unknown, fallback: T) => CmsResolution<T>;\n};\n\nconst TYPE = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;\nconst ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;\nconst SCOPE = /^[a-z0-9]{6,12}\\.[a-z][a-z0-9_-]{0,63}$/;\n\nfunction dependenciesCopy(dependencies: CmsDependencies): CmsDependencies {\n if (!dependencies || !Array.isArray(dependencies.types) || dependencies.types.length === 0) {\n throw new TypeError(\"CMS dependencies require document types\");\n }\n const types = [...dependencies.types];\n for (const type of types) {\n if (typeof type !== \"string\" || !TYPE.test(type)) throw new TypeError(\"Invalid CMS document type\");\n }\n if (dependencies.ids !== undefined && !Array.isArray(dependencies.ids)) throw new TypeError(\"Invalid CMS document IDs\");\n const ids = dependencies.ids === undefined ? undefined : [...dependencies.ids];\n for (const id of ids ?? []) {\n if (typeof id !== \"string\" || !ID.test(id) || /^(drafts|versions)\\./.test(id)) {\n throw new TypeError(\"Invalid CMS document ID\");\n }\n }\n if (new Set(types).size + new Set(ids).size > 128) throw new TypeError(\"Too many CMS tags\");\n return Object.freeze({ types: Object.freeze(types), ...(ids === undefined ? {} : { ids: Object.freeze(ids) }) });\n}\n\nexport function defineCmsQuery<T>(query: CmsQuery<T>): CmsQuery<T> {\n if (!query || typeof query.name !== \"string\" || !/^[A-Za-z][A-Za-z0-9_.-]{0,127}$/.test(query.name)\n || typeof query.query !== \"string\" || query.query.trim() === \"\" || typeof query.resolve !== \"function\") {\n throw new TypeError(\"Invalid CMS query configuration\");\n }\n const params = query.params;\n if (!params || typeof params !== \"object\" || (Object.getPrototypeOf(params) !== Object.prototype && Object.getPrototypeOf(params) !== null)) {\n throw new TypeError(\"CMS params must be plain JSON scalars\");\n }\n const copied: Record<string, string | number | boolean | null> = {};\n for (const key of Reflect.ownKeys(params)) {\n const descriptor = Object.getOwnPropertyDescriptor(params, key);\n if (typeof key !== \"string\" || !descriptor || !Object.hasOwn(descriptor, \"value\") || !descriptor.enumerable) {\n throw new TypeError(\"CMS params must be plain JSON scalars\");\n }\n const value: unknown = descriptor.value;\n if (!(value === null || typeof value === \"string\" || typeof value === \"boolean\" || (typeof value === \"number\" && Number.isFinite(value)))) {\n throw new TypeError(\"CMS params must be plain JSON scalars\");\n }\n Object.defineProperty(copied, key, { value, enumerable: true });\n }\n return Object.freeze({ name: query.name, query: query.query, params: Object.freeze(copied), dependencies: dependenciesCopy(query.dependencies), resolve: query.resolve });\n}\n\nexport function cmsTags(scope: string, dependencies: CmsDependencies): readonly string[] {\n if (typeof scope !== \"string\" || scope.length > 77 || !SCOPE.test(scope)) throw new TypeError(\"Invalid CMS scope\");\n const copied = dependenciesCopy(dependencies);\n const tags = [\n ...[...new Set(copied.types)].sort().map((type) => `cms:${scope}:type:${type}`),\n ...[...new Set(copied.ids ?? [])].sort().map((id) => `cms:${scope}:id:${id}`),\n ];\n return Object.freeze(tags);\n}\n", "import { defineCmsQuery, type CmsQuery, type CmsResolution } from \"./query.js\";\n\nexport const SITE_HERO_LAYOUTS = [\"columns\", \"rows\"] as const;\nexport const SITE_HERO_TAGLINE_MAX_LENGTH = 40;\nexport const SITE_HERO_LAYOUT_WARNING = \"siteHero.layout.defaulted\" as const;\nexport const SITE_HERO_TAGLINE_DROPPED_WARNING = \"siteHero.tagline.dropped\" as const;\nexport const SITE_HERO_TAGLINES_DEFAULTED_WARNING = \"siteHero.taglines.defaulted\" as const;\nexport type SiteHeroLayout = typeof SITE_HERO_LAYOUTS[number];\nexport type SiteHeroTagline = { readonly key: string; readonly text: string };\n/** Optional additions preserve existing heading/intro-only consumer fallbacks. */\nexport type SiteHero = {\n readonly heading: string;\n readonly intro: string;\n readonly layout?: SiteHeroLayout;\n readonly taglines?: readonly SiteHeroTagline[];\n};\nexport type ParsedSiteHero = SiteHero & {\n readonly layout: SiteHeroLayout;\n readonly taglines: readonly SiteHeroTagline[];\n};\nexport type TextFieldDefinition = {\n readonly name: string;\n readonly label: string;\n readonly noun: { readonly article: \"a\" | \"an\"; readonly word: string };\n readonly kind: \"single-line\" | \"multi-line\";\n readonly required: boolean;\n readonly minLength: number;\n readonly maxLength: number;\n readonly noTrailingFullStop?: boolean;\n};\nexport type TextDocumentDefinition = {\n readonly key: string;\n readonly documentId: string;\n readonly documentType: string;\n readonly fields: readonly TextFieldDefinition[];\n readonly copy: {\n readonly currentTitle: string;\n readonly editTitle: string;\n readonly empty: string;\n };\n};\nexport type TextValidation =\n | { readonly ok: true; readonly value: Readonly<Record<string, string>> }\n | { readonly ok: false; readonly errors: Readonly<Record<string, string>> };\n\nexport const CMS_CONTRACT_VERSION = 1;\n\nexport const SITE_HERO: TextDocumentDefinition = {\n key: \"hero\",\n documentId: \"siteHero\",\n documentType: \"siteHero\",\n fields: [\n {\n name: \"heading\",\n label: \"Heading\",\n noun: { article: \"a\", word: \"heading\" },\n kind: \"single-line\",\n required: true,\n minLength: 1,\n maxLength: 80,\n noTrailingFullStop: true,\n },\n {\n name: \"intro\",\n label: \"Introduction\",\n noun: { article: \"an\", word: \"introduction\" },\n kind: \"multi-line\",\n required: true,\n minLength: 1,\n maxLength: 320,\n },\n ],\n copy: {\n currentTitle: \"On your site now\",\n editTitle: \"Edit and publish\",\n empty: \"Your site has no hero text yet. Whatever you publish below becomes its first version.\",\n },\n};\n\nfunction fieldError(field: TextFieldDefinition, text: string): string | null {\n const { article, word } = field.noun;\n if (text.length === 0) return field.required ? `Enter ${article} ${word}.` : null;\n const count = [...text].length;\n if (count < field.minLength) return `Make the ${word} at least ${String(field.minLength)} characters. It is ${String(count)} now.`;\n if (count > field.maxLength) return `Keep the ${word} to ${String(field.maxLength)} characters or fewer. It is ${String(count)} now.`;\n if (text.includes(\"\\u2014\")) return `The ${word} contains a long dash. Use a comma, a colon or a short dash instead.`;\n if (field.kind === \"single-line\" && /[\\r\\n]/.test(text)) return `The ${word} must be a single line.`;\n if (field.noTrailingFullStop === true && text.endsWith(\".\")) {\n return `${word.charAt(0).toUpperCase()}${word.slice(1)}s on your site do not end with a full stop. Remove the last full stop.`;\n }\n return null;\n}\n\nexport function validateTextDocument(\n definition: TextDocumentDefinition, raw: Readonly<Record<string, unknown>>,\n): TextValidation {\n const value: Record<string, string> = {};\n const errors: Record<string, string> = {};\n for (const field of definition.fields) {\n const submitted = Object.hasOwn(raw, field.name) ? raw[field.name] : undefined;\n const text = typeof submitted === \"string\" ? submitted.trim() : \"\";\n const error = fieldError(field, text);\n Object.defineProperty(error === null ? value : errors, field.name, { value: error ?? text, enumerable: true });\n }\n return Object.keys(errors).length > 0 ? { ok: false, errors } : { ok: true, value };\n}\n\n/** One rule set for strict authoring validation and resilient published reads. */\nfunction scanSiteHeroTaglines(raw: unknown):\n | { readonly ok: true; readonly value: readonly SiteHeroTagline[]; readonly dropped: readonly { index: number; error: string }[] }\n | { readonly ok: false; readonly error: string } {\n if (!Array.isArray(raw)) return { ok: false, error: \"Enter a list of taglines.\" };\n const heading = SITE_HERO.fields[0];\n if (!heading) throw new TypeError(\"Missing siteHero heading definition\");\n const field = { ...heading, name: \"text\", noun: { article: \"a\", word: \"tagline\" } as const,\n maxLength: SITE_HERO_TAGLINE_MAX_LENGTH };\n const value: SiteHeroTagline[] = [];\n const dropped: { index: number; error: string }[] = [];\n const keys = new Set<string>();\n for (const [index, item] of (raw as unknown[]).entries()) {\n if (!item || typeof item !== \"object\" || Array.isArray(item)) {\n dropped.push({ index, error: \"Enter a key and text for each tagline.\" });\n continue;\n }\n const record = item as Record<string, unknown>;\n const key = Object.hasOwn(record, \"key\") ? record.key : undefined;\n if (typeof key !== \"string\" || !/^[a-z][a-z0-9_-]{0,31}$/.test(key)) {\n dropped.push({ index, error: \"Use a lowercase key of 1 to 32 letters, numbers, short dashes or underscores, starting with a letter.\" });\n continue;\n }\n if (keys.has(key)) {\n dropped.push({ index, error: \"Use each tagline key only once.\" });\n continue;\n }\n const text = validateTextDocument({ ...SITE_HERO, fields: [field] }, record);\n if (!text.ok) {\n dropped.push({ index, error: text.errors.text ?? \"Invalid tagline.\" });\n continue;\n }\n const copy = text.value.text ?? \"\";\n if ((copy.match(/\\p{L}/gu)?.length ?? 0) >= 2 && !/\\p{Ll}/u.test(copy)) {\n dropped.push({ index, error: \"Use sentence case for the tagline, rather than all capitals.\" });\n continue;\n }\n keys.add(key);\n value.push({ key, text: copy });\n }\n return { ok: true, value, dropped };\n}\n\n/** Shared with the schema adapter; invalid authoring input is refused as a whole. */\nexport function validateSiteHeroTaglines(raw: unknown):\n | { readonly ok: true; readonly value: readonly SiteHeroTagline[] }\n | { readonly ok: false; readonly error: string } {\n const result = scanSiteHeroTaglines(raw);\n if (!result.ok) return result;\n const first = result.dropped[0];\n return first ? { ok: false, error: first.error } : { ok: true, value: result.value };\n}\n\nfunction isLayout(value: unknown): value is SiteHeroLayout {\n return SITE_HERO_LAYOUTS.some((layout) => value === layout);\n}\n\n/** Invalid published entries are dropped without discarding valid keyed siblings. */\nexport function parseSiteHero(raw: unknown, fallback: SiteHero): CmsResolution<ParsedSiteHero> {\n const local = validateTextDocument(SITE_HERO, fallback);\n const localTaglines = validateSiteHeroTaglines(fallback.taglines ?? []);\n if (!local.ok || !localTaglines.ok || (fallback.layout !== undefined && !isLayout(fallback.layout))) {\n throw new TypeError(\"Invalid siteHero fallback\");\n }\n const data: { heading: string; intro: string; layout: SiteHeroLayout; taglines: readonly SiteHeroTagline[] } = {\n heading: local.value.heading ?? \"\", intro: local.value.intro ?? \"\",\n layout: fallback.layout ?? \"columns\", taglines: localTaglines.value,\n };\n if (raw === null || typeof raw !== \"object\" || Array.isArray(raw)) return { data, fallbackFields: [\"$\"] };\n const record = raw as Readonly<Record<string, unknown>>;\n const text = validateTextDocument(SITE_HERO, record);\n const fallbackFields: string[] = text.ok ? [] : Object.keys(text.errors);\n for (const field of SITE_HERO.fields) {\n if (!fallbackFields.includes(field.name)) {\n const value = text.ok ? text.value[field.name] : record[field.name];\n if (typeof value === \"string\" && (field.name === \"heading\" || field.name === \"intro\")) data[field.name] = value.trim();\n }\n }\n const layout = Object.hasOwn(record, \"layout\") ? record.layout : undefined;\n const warnings: NonNullable<CmsResolution<ParsedSiteHero>[\"warnings\"]>[number][] = [];\n if (isLayout(layout)) data.layout = layout;\n else {\n data.layout = \"columns\";\n fallbackFields.push(\"layout\");\n warnings.push(SITE_HERO_LAYOUT_WARNING);\n }\n const taglines = scanSiteHeroTaglines(Object.hasOwn(record, \"taglines\") ? record.taglines : undefined);\n if (taglines.ok) {\n data.taglines = taglines.value;\n for (const { index } of taglines.dropped) fallbackFields.push(`taglines[${String(index)}]`);\n if (taglines.dropped.length > 0) warnings.push(SITE_HERO_TAGLINE_DROPPED_WARNING);\n } else {\n fallbackFields.push(\"taglines\");\n warnings.push(SITE_HERO_TAGLINES_DEFAULTED_WARNING);\n }\n const wholeFallback = [...SITE_HERO.fields.map((field) => field.name), \"layout\", \"taglines\"].every((field) => fallbackFields.includes(field));\n return { data, fallbackFields: wholeFallback ? [\"$\"] : fallbackFields,\n ...(warnings.length > 0 ? { warnings } : {}) };\n}\n\nexport function siteHeroQuery(): CmsQuery<SiteHero> {\n return defineCmsQuery<SiteHero>({\n name: \"siteHero.v1\", query: '*[_id == $id && _type == \"siteHero\"][0]{heading,intro,layout,taglines}',\n params: { id: \"siteHero\" }, dependencies: { types: [\"siteHero\"], ids: [\"siteHero\"] },\n resolve: parseSiteHero,\n });\n}\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,EAAA,cAAAC,EAAA,sBAAAC,EAAA,6BAAAC,EAAA,yCAAAC,EAAA,sCAAAC,EAAA,iCAAAC,EAAA,YAAAC,EAAA,mBAAAC,EAAA,kBAAAC,EAAA,kBAAAC,EAAA,6BAAAC,EAAA,yBAAAC,IAAA,eAAAC,EAAAf,GCmBA,IAAMgB,EAAO,+BACPC,EAAK,qCACLC,EAAQ,0CAEd,SAASC,EAAiBC,EAAgD,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,IAAKE,GAAUA,EAAM,IAAI,EAAG,SAAU,UAAU,EAAE,MAAOA,GAAU+B,EAAe,SAAS/B,CAAK,CAAC,EAC5I,MAAO,CAAE,KAAA8B,EAAM,eAAgBI,EAAgB,CAAC,GAAG,EAAIH,EACrD,GAAIC,EAAS,OAAS,EAAI,CAAE,SAAAA,CAAS,EAAI,CAAC,CAAG,CACjD,CAEO,SAASG,GAAoC,CAClD,OAAOC,EAAyB,CAC9B,KAAM,cAAe,MAAO,yEAC5B,OAAQ,CAAE,GAAI,UAAW,EAAG,aAAc,CAAE,MAAO,CAAC,UAAU,EAAG,IAAK,CAAC,UAAU,CAAE,EACnF,QAASV,CACX,CAAC,CACH",
6
- "names": ["index_exports", "__export", "CMS_CONTRACT_VERSION", "SITE_HERO", "SITE_HERO_LAYOUTS", "SITE_HERO_LAYOUT_WARNING", "SITE_HERO_TAGLINES_DEFAULTED_WARNING", "SITE_HERO_TAGLINE_DROPPED_WARNING", "SITE_HERO_TAGLINE_MAX_LENGTH", "cmsTags", "defineCmsQuery", "parseSiteHero", "siteHeroQuery", "validateSiteHeroTaglines", "validateTextDocument", "__toCommonJS", "TYPE", "ID", "SCOPE", "dependenciesCopy", "dependencies", "types", "type", "ids", "id", "defineCmsQuery", "query", "params", "copied", "key", "descriptor", "value", "cmsTags", "scope", "tags", "SITE_HERO_LAYOUTS", "SITE_HERO_TAGLINE_MAX_LENGTH", "SITE_HERO_LAYOUT_WARNING", "SITE_HERO_TAGLINE_DROPPED_WARNING", "SITE_HERO_TAGLINES_DEFAULTED_WARNING", "CMS_CONTRACT_VERSION", "SITE_HERO", "fieldError", "field", "text", "article", "word", "count", "validateTextDocument", "definition", "raw", "value", "errors", "submitted", "error", "scanSiteHeroTaglines", "heading", "dropped", "keys", "index", "item", "record", "key", "copy", "validateSiteHeroTaglines", "result", "first", "isLayout", "layout", "parseSiteHero", "fallback", "local", "localTaglines", "data", "fallbackFields", "warnings", "taglines", "wholeFallback", "siteHeroQuery", "defineCmsQuery"]
3
+ "sources": ["../src/index.ts", "../src/portable/array.ts", "../src/portable/menu-options.ts", "../src/portable/menu.ts", "../src/portable/site-content.ts", "../src/contracts/query.ts", "../src/contracts/text.ts"],
4
+ "sourcesContent": ["export { defineCmsQuery, cmsTags } from \"./contracts/query.js\";\nexport type { CmsParams, CmsDependencies, CmsResolution, CmsQuery } from \"./contracts/query.js\";\nexport { SITE_HERO, CMS_CONTRACT_VERSION, validateTextDocument, siteHeroQuery, SITE_HERO_LAYOUTS, SITE_HERO_TAGLINE_MAX_LENGTH, SITE_HERO_LAYOUT_WARNING, SITE_HERO_TAGLINE_DROPPED_WARNING, SITE_HERO_TAGLINES_DEFAULTED_WARNING, parseSiteHero, validateSiteHeroTaglines } from \"./contracts/text.js\";\nexport type { SiteHero, ParsedSiteHero, SiteHeroLayout, SiteHeroTagline, TextFieldDefinition, TextDocumentDefinition, TextValidation } from \"./contracts/text.js\";\nexport { MENU_LAYOUTS, MENU_DECORATIONS, MENU_LAYOUT_DEFAULTS, parseMenuDocument, menuTags } from \"./portable/menu.js\";\nexport { menuQuery } from \"./contracts/query.js\";\nexport type { MenuDocument, MenuVariant, MenuSection, MenuItem, MenuPrice, MenuExtra, MenuMoney, MenuLayout, MenuDecoration, MenuSectionInput } from \"./portable/menu.js\";\n", "/** Content lists must contain an own entry at every index. */\nexport function isDenseArray(value: unknown): value is unknown[] {\n if (!Array.isArray(value)) return false;\n for (let index = 0; index < value.length; index += 1) {\n if (!Object.hasOwn(value, index)) return false;\n }\n return true;\n}\n", "export const MENU_LAYOUTS = [\"stacked\", \"columns\"] as const;\nexport const MENU_DECORATIONS = [\"none\", \"playful\"] as const;\nexport const MENU_LAYOUT_DEFAULTS = { layout: \"stacked\", decoration: \"none\" } as const;\n\n/** Explicit saved fields, shared by the standalone query and page dereference. */\nexport const MENU_DOCUMENT_PROJECTION = `_type, _id, _rev, _updatedAt, title, locationKeys, note, signOff,\n variants[]{_key, label, note, sections[]{_key, title, service, items[]{\n _key, name, description, priceNote, dietary, allergenNote, availability,\n prices[]{_key, label, amount{minor, currency}}, extras[]{_key, name, amount{minor, currency}}\n }}}`;\n\n", "import { isDenseArray } from \"./array.js\";\nimport { MalformedContentError } from \"./site-content.js\";\nimport { cmsTags } from \"../contracts/query.js\";\n\nimport { MENU_LAYOUTS, MENU_DECORATIONS } from \"./menu-options.js\";\nexport { MENU_LAYOUTS, MENU_DECORATIONS, MENU_LAYOUT_DEFAULTS } from \"./menu-options.js\";\nexport type MenuLayout = (typeof MENU_LAYOUTS)[number];\nexport type MenuDecoration = (typeof MENU_DECORATIONS)[number];\n\n/** CMS-owned saved shapes. `_key` remains the mapper's stable array identity. */\nexport type MenuMoney = { readonly minor: number; readonly currency: string };\nexport type MenuPrice = { readonly _key: string; readonly amount: MenuMoney; readonly label?: string };\nexport type MenuExtra = { readonly _key: string; readonly name: string; readonly amount: MenuMoney };\nexport type MenuItem = {\n readonly _key: string; readonly name: string; readonly description?: string;\n readonly prices: readonly MenuPrice[]; readonly priceNote?: string;\n readonly extras: readonly MenuExtra[]; readonly dietary: readonly string[];\n readonly allergenNote?: string; readonly availability: \"available\" | \"sold-out\" | \"hidden\";\n};\nexport type MenuSection = { readonly _key: string; readonly title: string; readonly service?: string; readonly items: readonly MenuItem[] };\nexport type MenuVariant = { readonly _key: string; readonly label: string; readonly note?: string; readonly sections: readonly MenuSection[] };\nexport type MenuDocument = {\n /** The schema discriminator is required by the consuming site's mapper. */\n readonly _type: \"menu\";\n readonly _id: string; readonly _rev: string;\n /** The real published update date, preserved verbatim for stale displays. */\n readonly _updatedAt: string;\n readonly title: string; readonly locationKeys: readonly string[];\n readonly variants: readonly MenuVariant[]; readonly note?: string;\n /** Approval is opaque to this reader. The site validates it with its contract. */\n readonly signOff?: unknown;\n};\nexport type MenuSectionInput = { readonly kind: \"menu\"; readonly layout: MenuLayout; readonly decoration: MenuDecoration; readonly menu: MenuDocument };\n\n/** Uses the same scoped type/id tags as every other CMS query. */\nexport function menuTags(scope: string, id?: string): readonly string[] {\n return cmsTags(scope, { types: [\"menu\"], ...(id === undefined ? {} : { ids: [id] }) });\n}\n\ntype Raw = Record<string, unknown>;\nfunction fail(path: string, reason: string): never {\n throw new MalformedContentError(\"menu\", [`${path} ${reason}`]);\n}\n/** Capture each own data property once; never invoke an accessor or caller get trap. */\nfunction snapshot(value: unknown, path: string, ancestors = new Set<object>(), identity?: PropertyDescriptor): unknown {\n if (value === null || typeof value === \"string\" || typeof value === \"boolean\") return value;\n if (typeof value === \"number\" && Number.isFinite(value)) return value;\n if (typeof value !== \"object\" || value === null) return fail(path, \"is not plain JSON data\");\n try {\n if (ancestors.has(value)) return fail(path, \"is not acyclic JSON data\");\n const array = Array.isArray(value);\n const prototype: unknown = Object.getPrototypeOf(value);\n if (array ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null) {\n return fail(path, \"is not an ordinary saved object\");\n }\n ancestors.add(value);\n const keys = Reflect.ownKeys(value);\n const copied: Record<string, unknown> | unknown[] = array ? [] : {};\n let length = 0;\n let entries = 0;\n for (const key of keys) {\n if (typeof key !== \"string\") return fail(path, \"has a symbol key\");\n const at = array && key !== \"length\" ? `${path}[${key}]` : `${path}.${key}`;\n let descriptor: PropertyDescriptor | undefined;\n try { descriptor = key === \"_id\" && identity !== undefined ? identity : Object.getOwnPropertyDescriptor(value, key); }\n catch { return fail(at, \"could not be snapshotted as plain JSON data\"); }\n if (!descriptor || !Object.hasOwn(descriptor, \"value\")) return fail(at, \"is not a saved data property\");\n if (array && key === \"length\") {\n const savedLength: unknown = descriptor.value;\n if (typeof savedLength !== \"number\" || !Number.isSafeInteger(savedLength) || savedLength < 0) return fail(at, \"is not a saved list length\");\n length = savedLength;\n continue;\n }\n if (!descriptor.enumerable || (array && !/^(0|[1-9]\\d*)$/.test(key))) return fail(at, \"is not a JSON data property\");\n const saved: unknown = descriptor.value;\n const entry = snapshot(saved, at, ancestors);\n Object.defineProperty(copied, key, { value: entry, enumerable: true, writable: true, configurable: true });\n entries++;\n }\n if (array && (entries !== length || (copied as unknown[]).length !== length)) return fail(path, \"is not a complete saved list\");\n return copied;\n } catch (error) {\n if (error instanceof MalformedContentError) throw error;\n return fail(path, \"could not be snapshotted as plain JSON data\");\n } finally {\n ancestors.delete(value);\n }\n}\nfunction object(value: unknown, path: string): Raw {\n if (value === null || typeof value !== \"object\" || Array.isArray(value)\n || (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null)) return fail(path, \"is not an ordinary saved object\");\n return value as Raw;\n}\nfunction text(value: unknown, path: string, required = true): string {\n if (typeof value !== \"string\" || (required && value.trim() === \"\")) return fail(path, \"is not saved text\");\n return value;\n}\nfunction optional(raw: Raw, field: string, path: string): Record<string, string> {\n return raw[field] === undefined || raw[field] === null ? {} : { [field]: text(raw[field], `${path}.${field}`, false) };\n}\nfunction list<T>(value: unknown, path: string, read: (value: unknown, path: string) => T): T[] {\n if (value === undefined || value === null) return [];\n if (!isDenseArray(value)) return fail(path, \"is not a complete saved list\");\n return value.map((entry, index) => read(entry, `${path}[${String(index)}]`));\n}\nfunction money(value: unknown, path: string): MenuMoney {\n const raw = object(value, path);\n if (typeof raw.minor !== \"number\" || !Number.isSafeInteger(raw.minor) || raw.minor < 0) return fail(`${path}.minor`, \"is not a whole non-negative safe amount\");\n const currency = text(raw.currency, `${path}.currency`);\n if (!/^[A-Z]{3}$/.test(currency)) return fail(`${path}.currency`, \"is not a three-letter currency code\");\n return { minor: raw.minor, currency };\n}\nfunction price(value: unknown, path: string): MenuPrice {\n const raw = object(value, path);\n return { _key: text(raw._key, `${path}._key`), amount: money(raw.amount, `${path}.amount`), ...optional(raw, \"label\", path) };\n}\nfunction extra(value: unknown, path: string): MenuExtra {\n const raw = object(value, path);\n return { _key: text(raw._key, `${path}._key`), name: text(raw.name, `${path}.name`), amount: money(raw.amount, `${path}.amount`) };\n}\nfunction item(value: unknown, path: string): MenuItem {\n const raw = object(value, path);\n const availability = raw.availability ?? \"available\";\n if (availability !== \"available\" && availability !== \"sold-out\" && availability !== \"hidden\") return fail(`${path}.availability`, \"is not an availability choice\");\n return {\n _key: text(raw._key, `${path}._key`), name: text(raw.name, `${path}.name`),\n ...optional(raw, \"description\", path), ...optional(raw, \"priceNote\", path), ...optional(raw, \"allergenNote\", path),\n prices: list(raw.prices, `${path}.prices`, price), extras: list(raw.extras, `${path}.extras`, extra),\n dietary: list(raw.dietary, `${path}.dietary`, text), availability,\n };\n}\nfunction section(value: unknown, path: string): MenuSection {\n const raw = object(value, path);\n return { _key: text(raw._key, `${path}._key`), title: text(raw.title, `${path}.title`), ...optional(raw, \"service\", path), items: list(raw.items, `${path}.items`, item) };\n}\nfunction variant(value: unknown, path: string): MenuVariant {\n const raw = object(value, path);\n return { _key: text(raw._key, `${path}._key`), label: text(raw.label, `${path}.label`), ...optional(raw, \"note\", path), sections: list(raw.sections, `${path}.sections`, section) };\n}\n\n/** A reference has resolved only when it carries a published document identity. */\nfunction isPublishedMenuDocument(value: unknown): boolean {\n if (value === null || typeof value !== \"object\" || Array.isArray(value)) return false;\n const id = (value as Raw)._id;\n return typeof id === \"string\" && id.trim() !== \"\" && !/^(drafts|versions)\\./.test(id);\n}\n\n/** Validate saved field shapes without inferring approval or changing copy/order. */\nexport function parseMenuDocument(document: unknown, where = \"menu\"): MenuDocument {\n return parseSnapshot(snapshot(document, where), where);\n}\n\n/** Page references use the same single snapshot before checking their identity. */\nexport function parseReferencedMenuDocument(document: unknown, where: string): MenuDocument | null {\n if (document === undefined || document === null) return null;\n if (typeof document !== \"object\") return null;\n // Missing/draft references remain warnings. Cache the identity descriptor so\n // an available document still contributes each caller property exactly once.\n let identity: PropertyDescriptor | undefined;\n try { identity = Object.getOwnPropertyDescriptor(document, \"_id\"); }\n catch { return fail(`${where}._id`, \"could not be snapshotted as plain JSON data\"); }\n if (identity && !Object.hasOwn(identity, \"value\")) return fail(`${where}._id`, \"is not a saved data property\");\n const id: unknown = identity?.value;\n if (typeof id !== \"string\" || id.trim() === \"\" || /^(drafts|versions)\\./.test(id)) return null;\n return parseSnapshot(snapshot(document, where, new Set(), identity), where);\n}\n\nfunction parseSnapshot(document: unknown, where: string): MenuDocument {\n const raw = object(document, where);\n if (raw._type !== \"menu\") return fail(`${where}._type`, \"is not menu\");\n if (!isPublishedMenuDocument(raw)) return fail(`${where}._id`, \"is not a published menu identity\");\n const updatedAt = text(raw._updatedAt, `${where}._updatedAt`);\n if (!/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:Z|[+-]\\d{2}:\\d{2})$/.test(updatedAt) || !Number.isFinite(Date.parse(updatedAt))) return fail(`${where}._updatedAt`, \"is not an update date\");\n const variants = list(raw.variants, `${where}.variants`, variant);\n if (variants.length === 0) return fail(`${where}.variants`, \"has no menu choices\");\n return {\n _type: \"menu\", _id: text(raw._id, `${where}._id`), _rev: text(raw._rev, `${where}._rev`), _updatedAt: updatedAt,\n title: text(raw.title, `${where}.title`), locationKeys: list(raw.locationKeys, `${where}.locationKeys`, text),\n variants, ...optional(raw, \"note\", where), ...(Object.hasOwn(raw, \"signOff\") ? { signOff: raw.signOff } : {}),\n };\n}\n\nexport function validMenuFallback(value: unknown): value is MenuDocument | null {\n if (value === null) return true;\n try { parseMenuDocument(value); return true; } catch { return false; }\n}\n", "/**\n * A-1713. The site content model, read: the home page, content pages and site\n * settings, validated on read and returned in the shape a site's page\n * composition consumes.\n *\n * ===========================================================================\n * READ ONLY, BY CONSTRUCTION\n * ===========================================================================\n *\n * A client site reads its content with a read-only token. All editing goes\n * through the studio's dashboard, which writes to Sanity; nothing on a client\n * site writes, and this module has no write path to call. It is handed a\n * `ContentClient` (a `query` function) and nothing else.\n *\n * ===========================================================================\n * VALIDATED ON READ, BECAUSE SANITY VALIDATION ONLY ADVISES\n * ===========================================================================\n *\n * The schema's rules warn an editor; they do not refuse a publish, and\n * anything writing over the API skips them entirely. So every document is\n * checked here again, and a malformed one is refused BY NAME\n * (`MalformedContentError`, code `malformed-content`) listing every problem\n * with its path, rather than rendered half-empty. A page that renders with a\n * missing headline and a page whose content is broken look identical to a\n * visitor; a build that fails naming `hero.headline` does not.\n *\n * Absent is not malformed: `null` from `home()` means nobody has created the\n * home page yet, and a site decides what to do about that.\n *\n * ===========================================================================\n * THE SHAPE IT RETURNS\n * ===========================================================================\n *\n * The INPUT shape of a site's composition schema (the reference build's\n * frontmatter): a copy value is a plain string for the client's own words\n * with no claim about their source, `{ text, copySource: \"captured\" }` for\n * words claimed verbatim from the capture (the site checks every such claim\n * against its capture evidence, so the claim must survive Sanity), and\n * `{ text, copySource: \"proposed\" }` for studio-written words awaiting\n * approval. All three round-trip exactly; a photo is its library slug; every key a block declares is\n * present, `null` where there is nothing. So a site validates this with the\n * same schema it validates its Markdown frontmatter with, and its components\n * never know where the content came from.\n *\n * Mapping from the generic model to the composition's names:\n *\n * hero.headline / subline / lead hero.heading / subline / intro\n * hero.photos[0], [1] hero.image, hero.inset\n * hero.primaryAction / secondary... hero.cta / secondaryCta\n * campaign (when shown) the FIRST block, kind `campaign`, and\n * the page body (`# title` + its text)\n * featureStoriesBlock kind `feature_stories`\n * surfaceCardBlock kind `cta`\n * accentBandBlock kind `accent_band`\n * locationsBlock kind `locations` (jumpLink \u2192 anchor)\n *\n * A content page's `sections[]` (A-1915) reads those four kinds plus\n * `text_media`, `faq`, `gallery` and `contact` into `PageContent.sections`,\n * with their named warnings in `PageContent.warnings`. `sections.ts` holds the\n * kinds, the A-1876 layout names and the warning codes.\n *\n * Two places the composition cannot carry a proposed marker: a `cta` block's\n * plain strings, and the campaign's title and body (which travel as Markdown).\n * There the text is returned plain and the line is still listed in\n * `proposedCopy`, which is the list a dashboard and a site both read for\n * approval. Nothing is dropped silently.\n */\n\nimport { parseReferencedMenuDocument } from \"./menu.js\";\nimport { MENU_DECORATIONS, MENU_DOCUMENT_PROJECTION, MENU_LAYOUT_DEFAULTS, MENU_LAYOUTS } from \"./menu-options.js\";\nimport { isDenseArray } from \"./array.js\";\nimport { defineCmsQuery, type CmsQuery, type CmsResolution } from \"../contracts/query.js\";\nimport { validHomeFallback, validPageFallback, validSettingsFallback } from \"./fallback.js\";\nimport {\n HEADING_LIST_LAYOUTS, READER_GALLERY_PHOTO_LIMIT, READER_GALLERY_PHOTO_MIN, SECTION_LAYOUT_DEFAULTS, SECTION_WARNINGS,\n SPLIT_LAYOUTS, STAGGER_ROW_LAYOUTS,\n type FaqSectionInput, type PageSectionInput, type SectionImageInput, type SectionWarning,\n} from \"./sections.js\";\n\n// ---------------------------------------------------------------------------\n// Output types\n// ---------------------------------------------------------------------------\n\nexport type CopyInput = string | { readonly text: string; readonly copySource: \"captured\" | \"proposed\" };\nexport type ActionInput = { readonly label: CopyInput; readonly href: string };\n\nexport type HeroInput = {\n readonly heading: CopyInput;\n readonly subline: CopyInput | null;\n readonly intro: CopyInput | null;\n readonly image: string | null;\n readonly inset: string | null;\n readonly cta: ActionInput | null;\n readonly secondaryCta: ActionInput | null;\n};\n\nexport type StoryInput = {\n readonly heading: CopyInput;\n readonly body: CopyInput;\n readonly action: ActionInput;\n readonly image: string | null;\n readonly shape: \"wide\" | \"tall\" | \"round\" | \"free\";\n readonly card: boolean;\n};\n\nexport type CompositionBlockInput =\n | { readonly kind: \"campaign\"; readonly action: ActionInput | null; readonly images: readonly string[] }\n | {\n readonly kind: \"locations\";\n readonly anchor: string | null;\n readonly heading: CopyInput;\n readonly tail: CopyInput | null;\n readonly image: string | null;\n }\n | {\n readonly kind: \"feature_stories\";\n readonly heading: CopyInput;\n readonly tail: CopyInput | null;\n readonly items: readonly StoryInput[];\n }\n | {\n readonly kind: \"accent_band\";\n readonly heading: CopyInput;\n readonly body: CopyInput;\n readonly action: ActionInput | null;\n readonly image: string | null;\n }\n | {\n readonly kind: \"cta\";\n readonly heading: string;\n readonly body: string | null;\n readonly link: { readonly label: string; readonly href: string };\n };\n\nexport type CompositionInput = {\n readonly intro: string | null;\n readonly photo: string | null;\n readonly hero: HeroInput | null;\n readonly blocks: readonly CompositionBlockInput[];\n};\n\n/** One line of studio-written copy awaiting approval, and where it is in the document. */\nexport type ProposedCopy = { readonly where: string; readonly text: string };\n\nexport type CampaignState = \"shown\" | \"off\" | \"not-started\" | \"ended\" | \"none\";\n\nexport type HomeContent = {\n readonly composition: CompositionInput;\n /** The page body as Markdown: the campaign's title and text when it is shown, otherwise empty. */\n readonly body: string;\n readonly campaign: CampaignState;\n readonly proposedCopy: readonly ProposedCopy[];\n};\n\nexport type PageContent = {\n readonly slug: string;\n readonly title: string;\n readonly composition: CompositionInput;\n readonly body: string;\n readonly migrated: boolean;\n readonly proposedCopy: readonly ProposedCopy[];\n /**\n * A-1915. Present only when the stored page has a `sections` list, so a page\n * written before sections existed reads exactly as it did in 0.2.0.\n */\n readonly sections?: readonly PageSectionInput[];\n /** A-1915. Present with `sections`: every named section warning, with its path. */\n readonly warnings?: readonly SectionWarning[];\n};\n\nexport type SiteSettingsContent = {\n readonly name: string;\n readonly description: string | null;\n readonly contact: { readonly email: string | null; readonly phone: string | null };\n readonly social: readonly { readonly network: string; readonly url: string }[];\n};\n\n// ---------------------------------------------------------------------------\n// The refusal\n// ---------------------------------------------------------------------------\n\nexport const MALFORMED_CONTENT = \"malformed-content\";\n\nexport class MalformedContentError extends Error {\n readonly code = MALFORMED_CONTENT;\n readonly documentId: string;\n readonly problems: readonly string[];\n\n constructor(documentId: string, problems: readonly string[]) {\n super(`${MALFORMED_CONTENT}: ${documentId}: ${problems.join(\"; \")}`);\n this.name = \"MalformedContentError\";\n this.documentId = documentId;\n this.problems = problems;\n }\n}\n\n// ---------------------------------------------------------------------------\n// The rules restated\n// ---------------------------------------------------------------------------\n\n/*\n * Runtime-free rules shared with schema-base. The schema adapter imports these\n * objects; content-client compatibility tests pin the shared references.\n */\nexport const READER_PHOTO_SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;\nexport const READER_ACTION_HREF =\n /^(?:\\/(?![/\\\\])[^\\s]*|#[a-z][a-z0-9]*(?:-[a-z0-9]+)*|mailto:[^\\s@]+@[^\\s@]+|tel:\\+?[0-9][0-9 ()-]*|https?:\\/\\/[^\\s/]+[^\\s]*)$/;\nexport const READER_JUMP_LINK = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;\nexport const READER_STORY_LAYOUTS = [\"wide\", \"tall\", \"round\", \"free\"] as const;\nexport const READER_HOME_PAGE_ID = \"homePage\";\nexport const READER_SITE_SETTINGS_ID = \"siteSettings\";\n\n// ---------------------------------------------------------------------------\n// A small path-aware reader\n// ---------------------------------------------------------------------------\n\ntype Raw = Record<string, unknown>;\n\nclass Reading {\n readonly problems: string[] = [];\n readonly proposed: ProposedCopy[] = [];\n\n fail(path: string, message: string): null {\n this.problems.push(`${path} ${message}`);\n return null;\n }\n\n object(value: unknown, path: string): Raw | null {\n if (typeof value === \"object\" && value !== null && !Array.isArray(value)) return value as Raw;\n return this.fail(path, \"is not an object\");\n }\n\n dense(value: unknown[], path: string): boolean {\n if (isDenseArray(value)) return true;\n this.fail(path, \"contains missing entries\");\n return false;\n }\n\n optionalString(value: unknown, path: string): string | null {\n if (value === undefined || value === null) return null;\n if (typeof value === \"string\") return value.trim() === \"\" ? null : value;\n return this.fail(path, \"is not text\");\n }\n\n /** A copy value, or null when absent or empty. Records a proposed line. */\n copy(value: unknown, path: string): CopyInput | null {\n if (value === undefined || value === null) return null;\n const raw = this.object(value, path);\n if (raw === null) return null;\n const text = raw[\"text\"];\n const source = raw[\"copySource\"];\n if (text !== undefined && typeof text !== \"string\") return this.fail(`${path}.text`, \"is not text\");\n if (source !== undefined && source !== \"captured\" && source !== \"proposed\") {\n return this.fail(`${path}.copySource`, `is ${JSON.stringify(source)}, not captured or proposed`);\n }\n if (typeof text !== \"string\" || text.trim() === \"\") return null;\n if (source === \"proposed\") {\n this.proposed.push({ where: path, text });\n return { text, copySource: \"proposed\" };\n }\n if (source === \"captured\") return { text, copySource: \"captured\" };\n return text;\n }\n\n requiredCopy(value: unknown, path: string): CopyInput | null {\n const copy = this.copy(value, path);\n if (copy === null && !this.problems.some((p) => p.startsWith(path))) this.fail(path, \"is missing its words\");\n return copy;\n }\n\n photo(value: unknown, path: string): string | null {\n if (value === undefined || value === null) return null;\n if (typeof value === \"string\" && READER_PHOTO_SLUG.test(value)) return value;\n return this.fail(path, `is ${JSON.stringify(value)}, not a photo library slug`);\n }\n\n photos(value: unknown, path: string, max: number): string[] {\n if (value === undefined || value === null) return [];\n if (!Array.isArray(value)) {\n this.fail(path, \"is not a list of photos\");\n return [];\n }\n if (!this.dense(value, path)) return [];\n if (value.length > max) this.fail(path, `holds ${String(value.length)} photos; at most ${String(max)}`);\n return value.map((entry, index) => this.photo(entry, `${path}[${String(index)}]`)).filter((p): p is string => p !== null);\n }\n\n action(value: unknown, path: string): ActionInput | null {\n if (value === undefined || value === null) return null;\n const raw = this.object(value, path);\n if (raw === null) return null;\n const label = this.requiredCopy(raw[\"label\"], `${path}.label`);\n const href = raw[\"href\"];\n if (typeof href !== \"string\" || !READER_ACTION_HREF.test(href)) {\n return this.fail(`${path}.href`, `is ${JSON.stringify(href)}, not a site path, #jump-link, mailto:, tel: or web address`);\n }\n return label === null ? null : { label, href };\n }\n\n requiredAction(value: unknown, path: string): ActionInput | null {\n if (value === undefined || value === null) return this.fail(path, \"is missing\");\n return this.action(value, path);\n }\n}\n\nfunction plain(copy: CopyInput): string {\n return typeof copy === \"string\" ? copy : copy.text;\n}\n\n// ---------------------------------------------------------------------------\n// Portable Text to Markdown\n// ---------------------------------------------------------------------------\n\n/**\n * The narrow Portable Text `portableText` declares, back to Markdown: normal,\n * h2, h3 and quote blocks, bullet and numbered lists, bold, italic, code and\n * links. It is the inverse of the seed package's Markdown mapper, and the\n * round-trip test holds the two to each other.\n *\n * An uploaded image inside rich text is REFUSED, not dropped: nothing can\n * upload one yet (the dashboard slice decides how), so one arriving means\n * something wrote the document by hand, and a page silently missing a picture\n * is the failure this reader exists to prevent.\n */\nexport function portableTextToMarkdown(value: unknown): string {\n const reading = new Reading();\n const markdown = richTextToMarkdown(value, \"body\", reading);\n if (reading.problems.length > 0) throw new MalformedContentError(\"body\", reading.problems);\n return markdown;\n}\n\nfunction richTextToMarkdown(value: unknown, path: string, reading: Reading): string {\n if (value === undefined || value === null) return \"\";\n if (!Array.isArray(value)) {\n reading.fail(path, \"is not rich text\");\n return \"\";\n }\n if (!reading.dense(value, path)) return \"\";\n const out: string[] = [];\n let previousWasList = false;\n value.forEach((member, index) => {\n const at = `${path}[${String(index)}]`;\n const block = reading.object(member, at);\n if (block === null) return;\n if (block[\"_type\"] !== \"block\") {\n reading.fail(at, `is a ${JSON.stringify(block[\"_type\"])}; only text is supported in rich text so far`);\n return;\n }\n const text = spansToMarkdown(block, at, reading);\n const listItem = block[\"listItem\"];\n const style = block[\"style\"] ?? \"normal\";\n let line: string;\n if (listItem === \"bullet\" || listItem === \"number\") {\n const level = typeof block[\"level\"] === \"number\" && block[\"level\"] > 1 ? block[\"level\"] : 1;\n line = `${\" \".repeat(level - 1)}${listItem === \"bullet\" ? \"-\" : \"1.\"} ${text}`;\n } else if (style === \"h2\") line = `## ${text}`;\n else if (style === \"h3\") line = `### ${text}`;\n else if (style === \"blockquote\") line = `> ${text}`;\n else if (style === \"normal\") line = text;\n else {\n reading.fail(`${at}.style`, `is ${JSON.stringify(style)}, which the schema does not offer`);\n return;\n }\n const isList = listItem === \"bullet\" || listItem === \"number\";\n if (out.length > 0) out.push(isList && previousWasList ? \"\\n\" : \"\\n\\n\");\n out.push(line);\n previousWasList = isList;\n });\n return out.join(\"\");\n}\n\nconst DECORATORS: Record<string, string> = { strong: \"**\", em: \"*\", code: \"`\" };\n\nfunction spansToMarkdown(block: Raw, path: string, reading: Reading): string {\n const links = new Map<string, string>();\n const markDefs = Array.isArray(block[\"markDefs\"]) ? (block[\"markDefs\"] as unknown[]) : [];\n if (!reading.dense(markDefs, `${path}.markDefs`)) return \"\";\n for (const def of markDefs) {\n const d = def as Raw;\n if (d[\"_type\"] === \"link\" && typeof d[\"_key\"] === \"string\" && typeof d[\"href\"] === \"string\") links.set(d[\"_key\"], d[\"href\"]);\n }\n const children = Array.isArray(block[\"children\"]) ? (block[\"children\"] as unknown[]) : [];\n if (!reading.dense(children, `${path}.children`)) return \"\";\n return children\n .map((child, index) => {\n const span = child as Raw;\n if (span[\"_type\"] !== \"span\" || typeof span[\"text\"] !== \"string\") {\n reading.fail(`${path}.children[${String(index)}]`, \"is not a text span\");\n return \"\";\n }\n let text = span[\"text\"];\n const marks = Array.isArray(span[\"marks\"]) ? (span[\"marks\"] as unknown[]) : [];\n if (!reading.dense(marks, `${path}.children[${String(index)}].marks`)) return \"\";\n let href: string | null = null;\n for (const mark of marks) {\n if (typeof mark !== \"string\") continue;\n const fence = DECORATORS[mark];\n if (fence !== undefined) text = `${fence}${text}${fence}`;\n else if (links.has(mark)) href = links.get(mark) ?? null;\n else reading.fail(`${path}.children[${String(index)}].marks`, `names ${JSON.stringify(mark)}, which is neither a style nor a link`);\n }\n return href === null ? text : `[${text}](${href})`;\n })\n .join(\"\");\n}\n\n// ---------------------------------------------------------------------------\n// The home page\n// ---------------------------------------------------------------------------\n\n/** Whether a campaign is shown at `now`, and if not, why not. */\nexport function campaignState(campaign: unknown, now: Date): CampaignState {\n if (typeof campaign !== \"object\" || campaign === null) return \"none\";\n const c = campaign as Raw;\n if (c[\"enabled\"] !== true) return \"off\";\n const starts = typeof c[\"startsAt\"] === \"string\" ? Date.parse(c[\"startsAt\"]) : null;\n const ends = typeof c[\"endsAt\"] === \"string\" ? Date.parse(c[\"endsAt\"]) : null;\n if (starts !== null && now.getTime() < starts) return \"not-started\";\n if (ends !== null && now.getTime() >= ends) return \"ended\";\n return \"shown\";\n}\n\nfunction keyed(path: string, raw: Raw, index: number): string {\n return typeof raw[\"_key\"] === \"string\" ? `${path}[_key==\"${raw[\"_key\"]}\"]` : `${path}[${String(index)}]`;\n}\n\n/**\n * A stored home page document, validated and mapped. Throws\n * `MalformedContentError` naming every problem. `now` decides whether a\n * scheduled campaign is shown, and is a parameter so a build, a preview and a\n * test each say which moment they mean.\n */\nexport function parseHomePage(document: unknown, options: { readonly now: Date }): HomeContent {\n const reading = new Reading();\n const doc = reading.object(document, \"homePage\");\n if (doc === null) throw new MalformedContentError(READER_HOME_PAGE_ID, reading.problems);\n const id = typeof doc[\"_id\"] === \"string\" ? doc[\"_id\"] : READER_HOME_PAGE_ID;\n if (doc[\"_type\"] !== \"homePage\") reading.fail(\"_type\", `is ${JSON.stringify(doc[\"_type\"])}, not homePage`);\n\n let hero: HeroInput | null = null;\n const rawHero = doc[\"hero\"] === undefined ? reading.fail(\"hero\", \"is missing\") : reading.object(doc[\"hero\"], \"hero\");\n if (rawHero !== null) {\n const photos = reading.photos(rawHero[\"photos\"], \"hero.photos\", 2);\n const heading = reading.requiredCopy(rawHero[\"headline\"], \"hero.headline\");\n const subline = reading.copy(rawHero[\"subline\"], \"hero.subline\");\n const intro = reading.copy(rawHero[\"lead\"], \"hero.lead\");\n const cta = reading.action(rawHero[\"primaryAction\"], \"hero.primaryAction\");\n const secondaryCta = reading.action(rawHero[\"secondaryAction\"], \"hero.secondaryAction\");\n if (heading !== null) {\n hero = { heading, subline, intro, image: photos[0] ?? null, inset: photos[1] ?? null, cta, secondaryCta };\n }\n }\n\n const blocks: CompositionBlockInput[] = [];\n const blockJumps: { where: string; href: string }[] = [];\n let body = \"\";\n const state = campaignState(doc[\"campaign\"], options.now);\n if (state === \"shown\") {\n const campaign = reading.object(doc[\"campaign\"], \"campaign\");\n if (campaign !== null) {\n const title = reading.requiredCopy(campaign[\"title\"], \"campaign.title\");\n const images = reading.photos(campaign[\"photos\"], \"campaign.photos\", 3);\n if (images.length === 0) reading.fail(\"campaign.photos\", \"is empty; a shown campaign needs at least one photo\");\n const text = richTextToMarkdown(campaign[\"body\"], \"campaign.body\", reading);\n if (text === \"\") reading.fail(\"campaign.body\", \"is empty; a shown campaign needs its text\");\n if (campaign[\"bodyCopySource\"] === \"proposed\") reading.proposed.push({ where: \"campaign.body\", text });\n const action = reading.action(campaign[\"action\"], \"campaign.action\");\n if (action !== null) blockJumps.push({ where: \"campaign.action.href\", href: action.href });\n if (title !== null) body = `# ${plain(title)}\\n\\n${text}`;\n blocks.push({ kind: \"campaign\", action, images });\n }\n }\n\n const anchors: string[] = [];\n const rawBlocks = doc[\"blocks\"] ?? [];\n if (!Array.isArray(rawBlocks)) reading.fail(\"blocks\", \"is not a list\");\n else if (reading.dense(rawBlocks, \"blocks\")) {\n rawBlocks.forEach((member, index) => {\n const raw = reading.object(member, `blocks[${String(index)}]`);\n if (raw === null) return;\n const at = keyed(\"blocks\", raw, index);\n const mapped = mapBlock(raw, at, reading);\n if (mapped === null) return;\n blockJumps.push(...buttonsOf(mapped, raw, at));\n if (mapped.kind === \"locations\" && mapped.anchor !== null) {\n if (anchors.includes(mapped.anchor)) reading.fail(`${at}.jumpLink`, `repeats \"${mapped.anchor}\", already used by another section`);\n anchors.push(mapped.anchor);\n }\n blocks.push(mapped);\n });\n }\n\n // A jump link on ANY button must land on a section of this page.\n const jumps: { where: string; href: string }[] = [];\n if (hero?.cta) jumps.push({ where: \"hero.primaryAction.href\", href: hero.cta.href });\n if (hero?.secondaryCta) jumps.push({ where: \"hero.secondaryAction.href\", href: hero.secondaryCta.href });\n jumps.push(...blockJumps);\n for (const { where, href } of jumps) {\n if (href.startsWith(\"#\") && !anchors.includes(href.slice(1))) {\n reading.fail(where, `jumps to ${href}, which no section on the page is named`);\n }\n }\n\n if (reading.problems.length > 0) throw new MalformedContentError(id, reading.problems);\n return {\n composition: { intro: null, photo: null, hero, blocks },\n body,\n campaign: state,\n proposedCopy: reading.proposed,\n };\n}\n\n/** Every button a mapped section carries, with its path in the stored document. */\nfunction buttonsOf(block: CompositionBlockInput, raw: Raw, at: string): { where: string; href: string }[] {\n switch (block.kind) {\n case \"feature_stories\": {\n const stories = Array.isArray(raw[\"stories\"]) ? (raw[\"stories\"] as Raw[]) : [];\n return block.items.map((item, index) => ({\n where: `${keyed(`${at}.stories`, stories[index] ?? {}, index)}.action.href`,\n href: item.action.href,\n }));\n }\n case \"accent_band\":\n return block.action === null ? [] : [{ where: `${at}.action.href`, href: block.action.href }];\n case \"cta\":\n return [{ where: `${at}.action.href`, href: block.link.href }];\n default:\n return [];\n }\n}\n\nfunction jumpLinkOf(raw: Raw, at: string, reading: Reading): string | null {\n const jump = raw[\"jumpLink\"];\n if (jump === undefined || jump === null || jump === \"\") return null;\n if (typeof jump !== \"string\" || !READER_JUMP_LINK.test(jump)) return reading.fail(`${at}.jumpLink`, `is ${JSON.stringify(jump)}, not lowercase words joined by hyphens`);\n return jump;\n}\n\nfunction mapBlock(raw: Raw, at: string, reading: Reading): CompositionBlockInput | null {\n switch (raw[\"_type\"]) {\n case \"featureStoriesBlock\": {\n const heading = reading.requiredCopy(raw[\"heading\"], `${at}.heading`);\n const tail = reading.copy(raw[\"tail\"], `${at}.tail`);\n const stories = raw[\"stories\"];\n if (!Array.isArray(stories) || stories.length === 0) return reading.fail(`${at}.stories`, \"has no stories\");\n if (!reading.dense(stories, `${at}.stories`)) return null;\n const items: StoryInput[] = [];\n stories.forEach((member, index) => {\n const story = reading.object(member, `${at}.stories[${String(index)}]`);\n if (story === null) return;\n const sat = keyed(`${at}.stories`, story, index);\n const sHeading = reading.requiredCopy(story[\"heading\"], `${sat}.heading`);\n const sBody = reading.requiredCopy(story[\"body\"], `${sat}.body`);\n const action = reading.requiredAction(story[\"action\"], `${sat}.action`);\n const image = reading.photo(story[\"photo\"], `${sat}.photo`);\n const layout = story[\"layout\"] ?? \"wide\";\n if (!(READER_STORY_LAYOUTS as readonly unknown[]).includes(layout)) {\n reading.fail(`${sat}.layout`, `is ${JSON.stringify(layout)}, not wide, tall, round or free`);\n return;\n }\n const onCard = story[\"onCard\"] ?? false;\n if (typeof onCard !== \"boolean\") {\n reading.fail(`${sat}.onCard`, \"is not on or off\");\n return;\n }\n if (sHeading === null || sBody === null || action === null) return;\n items.push({ heading: sHeading, body: sBody, action, image, shape: layout as StoryInput[\"shape\"], card: onCard });\n });\n return heading === null ? null : { kind: \"feature_stories\", heading, tail, items };\n }\n case \"surfaceCardBlock\": {\n const heading = reading.requiredCopy(raw[\"heading\"], `${at}.heading`);\n const body = reading.copy(raw[\"body\"], `${at}.body`);\n const action = reading.requiredAction(raw[\"action\"], `${at}.action`);\n if (heading === null || action === null) return null;\n return {\n kind: \"cta\",\n heading: plain(heading),\n body: body === null ? null : plain(body),\n link: { label: plain(action.label), href: action.href },\n };\n }\n case \"accentBandBlock\": {\n const heading = reading.requiredCopy(raw[\"heading\"], `${at}.heading`);\n const body = reading.requiredCopy(raw[\"body\"], `${at}.body`);\n const action = reading.action(raw[\"action\"], `${at}.action`);\n const image = reading.photo(raw[\"photo\"], `${at}.photo`);\n if (heading === null || body === null) return null;\n return { kind: \"accent_band\", heading, body, action, image };\n }\n case \"locationsBlock\": {\n const anchor = jumpLinkOf(raw, at, reading);\n const heading = reading.requiredCopy(raw[\"heading\"], `${at}.heading`);\n const tail = reading.copy(raw[\"tail\"], `${at}.tail`);\n const image = reading.photo(raw[\"photo\"], `${at}.photo`);\n return heading === null ? null : { kind: \"locations\", anchor, heading, tail, image };\n }\n default:\n return reading.fail(`${at}._type`, `is ${JSON.stringify(raw[\"_type\"])}, not a section type this reader knows`);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Page sections (A-1915)\n// ---------------------------------------------------------------------------\n\n/** A stored `layout`, or the composition default with a named warning. Never throws. */\nfunction sectionLayout<T extends string>(raw: Raw, at: string, layouts: readonly T[], fallback: T, warnings: SectionWarning[]): T {\n const value = raw[\"layout\"];\n const layout = layouts.find((name) => name === value);\n if (layout !== undefined) return layout;\n warnings.push({ code: SECTION_WARNINGS.layoutDefaulted, where: `${at}.layout` });\n return fallback;\n}\n\n/** An `imageWithHotspot`, or null. Without alt text or an asset it is dropped with a named warning. */\nfunction sectionImage(value: unknown, path: string, reading: Reading, warnings: SectionWarning[]): SectionImageInput | null {\n if (value === undefined || value === null) return null;\n const raw = reading.object(value, path);\n if (raw === null) return null;\n const asset = raw[\"asset\"];\n const ref = typeof asset === \"object\" && asset !== null ? (asset as Raw)[\"_ref\"] : undefined;\n if (typeof ref !== \"string\" || ref === \"\") {\n warnings.push({ code: SECTION_WARNINGS.imageMissingAsset, where: `${path}.asset` });\n return null;\n }\n const alt = raw[\"alt\"];\n if (typeof alt !== \"string\" || alt.trim() === \"\") {\n warnings.push({ code: SECTION_WARNINGS.imageMissingAlt, where: `${path}.alt` });\n return null;\n }\n const caption = reading.optionalString(raw[\"caption\"], `${path}.caption`);\n let hotspot: SectionImageInput[\"hotspot\"] = null;\n if (raw[\"hotspot\"] !== undefined && raw[\"hotspot\"] !== null) {\n const spot = reading.object(raw[\"hotspot\"], `${path}.hotspot`);\n const x = spot?.[\"x\"];\n const y = spot?.[\"y\"];\n if (typeof x === \"number\" && typeof y === \"number\" && x >= 0 && x <= 1 && y >= 0 && y <= 1) hotspot = { x, y };\n else if (spot !== null) reading.fail(`${path}.hotspot`, \"is not a point inside the image\");\n }\n return { asset: ref, alt, caption, hotspot };\n}\n\n/** Only a bounded schema name may travel in a warning; never coerce non-text values. */\nfunction sectionTypeForWarning(value: unknown): string {\n return typeof value === \"string\" ? value.slice(0, 64).replace(/[^A-Za-z0-9_.-]/g, \"?\") : \"?\";\n}\n\nfunction mapSection(raw: Raw, at: string, reading: Reading, warnings: SectionWarning[]): PageSectionInput | null {\n switch (raw[\"_type\"]) {\n case \"menuBlock\": {\n const menu = parseReferencedMenuDocument(raw[\"menu\"], `${at}.menu`);\n if (menu === null) {\n warnings.push({ code: SECTION_WARNINGS.menuUnavailable, where: `${at}.menu` });\n return null;\n }\n const layout = sectionLayout(raw, at, MENU_LAYOUTS, MENU_LAYOUT_DEFAULTS.layout, warnings);\n const decoration = MENU_DECORATIONS.find((name) => name === raw[\"decoration\"]);\n if (decoration === undefined) warnings.push({ code: SECTION_WARNINGS.layoutDefaulted, where: `${at}.decoration` });\n return { kind: \"menu\", menu, layout, decoration: decoration ?? MENU_LAYOUT_DEFAULTS.decoration };\n }\n case \"featureStoriesBlock\":\n case \"surfaceCardBlock\":\n case \"accentBandBlock\":\n case \"locationsBlock\": {\n const block = mapBlock(raw, at, reading);\n return block === null || block.kind === \"campaign\" ? null : block;\n }\n case \"textMediaBlock\": {\n const anchor = jumpLinkOf(raw, at, reading);\n const heading = reading.requiredCopy(raw[\"heading\"], `${at}.heading`);\n const tail = reading.copy(raw[\"tail\"], `${at}.tail`);\n const body = reading.requiredCopy(raw[\"body\"], `${at}.body`);\n const action = reading.action(raw[\"action\"], `${at}.action`);\n const image = sectionImage(raw[\"photo\"], `${at}.photo`, reading, warnings);\n const layout = sectionLayout(raw, at, SPLIT_LAYOUTS, SECTION_LAYOUT_DEFAULTS.Split, warnings);\n if (heading === null || body === null) return null;\n return { kind: \"text_media\", anchor, layout, heading, tail, body, action, image };\n }\n case \"faqBlock\": {\n const anchor = jumpLinkOf(raw, at, reading);\n const heading = reading.requiredCopy(raw[\"heading\"], `${at}.heading`);\n const tail = reading.copy(raw[\"tail\"], `${at}.tail`);\n const intro = reading.copy(raw[\"intro\"], `${at}.intro`);\n const layout = sectionLayout(raw, at, HEADING_LIST_LAYOUTS, SECTION_LAYOUT_DEFAULTS.HeadingList, warnings);\n const rawItems = raw[\"items\"];\n if (!Array.isArray(rawItems) || rawItems.length === 0) return reading.fail(`${at}.items`, \"has no questions\");\n if (!reading.dense(rawItems, `${at}.items`)) return null;\n const items: FaqSectionInput[\"items\"][number][] = [];\n rawItems.forEach((member, index) => {\n const item = reading.object(member, `${at}.items[${String(index)}]`);\n if (item === null) return;\n const iat = keyed(`${at}.items`, item, index);\n if (item[\"_type\"] !== undefined && item[\"_type\"] !== \"faqItem\") {\n reading.fail(`${iat}._type`, `is ${JSON.stringify(item[\"_type\"])}, not faqItem`);\n return;\n }\n const question = reading.requiredCopy(item[\"question\"], `${iat}.question`);\n const answer = reading.requiredCopy(item[\"answer\"], `${iat}.answer`);\n if (question !== null && answer !== null) items.push({ question, answer });\n });\n return heading === null ? null : { kind: \"faq\", anchor, layout, heading, tail, intro, items };\n }\n case \"galleryBlock\": {\n const anchor = jumpLinkOf(raw, at, reading);\n const heading = reading.copy(raw[\"heading\"], `${at}.heading`);\n const layout = sectionLayout(raw, at, STAGGER_ROW_LAYOUTS, SECTION_LAYOUT_DEFAULTS.StaggerRow, warnings);\n const photos = raw[\"photos\"] ?? [];\n if (!Array.isArray(photos)) return reading.fail(`${at}.photos`, \"is not a list of photos\");\n if (!reading.dense(photos, `${at}.photos`)) return null;\n if (photos.length < READER_GALLERY_PHOTO_MIN || photos.length > READER_GALLERY_PHOTO_LIMIT) {\n return reading.fail(`${at}.photos`, `holds ${String(photos.length)} photos; a gallery shows ${String(READER_GALLERY_PHOTO_MIN)} to ${String(READER_GALLERY_PHOTO_LIMIT)}`);\n }\n const images = photos.flatMap((photo, index) => {\n const image = sectionImage(photo, keyed(`${at}.photos`, typeof photo === \"object\" && photo !== null ? (photo as Raw) : {}, index), reading, warnings);\n return image === null ? [] : [image];\n });\n if (images.length === 0) {\n warnings.push({ code: SECTION_WARNINGS.emptySkipped, where: at });\n return null;\n }\n return { kind: \"gallery\", anchor, layout, heading, images };\n }\n case \"contactBlock\": {\n const anchor = jumpLinkOf(raw, at, reading);\n const heading = reading.requiredCopy(raw[\"heading\"], `${at}.heading`);\n const body = reading.copy(raw[\"body\"], `${at}.body`);\n const shown = (field: \"showEmail\" | \"showPhone\"): boolean => {\n const value = raw[field] ?? true;\n if (typeof value === \"boolean\") return value;\n reading.fail(`${at}.${field}`, \"is not on or off\");\n return false;\n };\n const showEmail = shown(\"showEmail\");\n const showPhone = shown(\"showPhone\");\n const action = reading.action(raw[\"action\"], `${at}.action`);\n const image = sectionImage(raw[\"photo\"], `${at}.photo`, reading, warnings);\n const layout = sectionLayout(raw, at, SPLIT_LAYOUTS, SECTION_LAYOUT_DEFAULTS.Split, warnings);\n if (heading === null) return null;\n if (!showEmail && !showPhone && body === null && action === null) {\n warnings.push({ code: SECTION_WARNINGS.emptySkipped, where: at });\n return null;\n }\n return { kind: \"contact\", anchor, layout, heading, body, showEmail, showPhone, action, image };\n }\n default:\n warnings.push({ code: SECTION_WARNINGS.unknownType, where: `${at}._type`, type: sectionTypeForWarning(raw[\"_type\"]) });\n return null;\n }\n}\n\n/** Every button a mapped page section carries, with its path in the stored document. */\nfunction sectionButtons(section: PageSectionInput, raw: Raw, at: string): { where: string; href: string }[] {\n switch (section.kind) {\n case \"text_media\":\n case \"contact\":\n return section.action === null ? [] : [{ where: `${at}.action.href`, href: section.action.href }];\n case \"menu\":\n case \"faq\":\n case \"gallery\":\n return [];\n default:\n return buttonsOf(section, raw, at);\n }\n}\n\n/** `page.sections[]`, mapped in order. Unknown types are skipped with a warning; malformed content is a problem. */\nfunction parseSections(value: unknown, reading: Reading): { sections: PageSectionInput[]; warnings: SectionWarning[] } {\n const sections: PageSectionInput[] = [];\n const warnings: SectionWarning[] = [];\n if (!Array.isArray(value)) {\n reading.fail(\"sections\", \"is not a list\");\n return { sections, warnings };\n }\n if (!reading.dense(value, \"sections\")) return { sections, warnings };\n const anchors: string[] = [];\n const jumps: { where: string; href: string }[] = [];\n value.forEach((member, index) => {\n const raw = reading.object(member, `sections[${String(index)}]`);\n if (raw === null) return;\n const at = keyed(\"sections\", raw, index);\n const section = mapSection(raw, at, reading, warnings);\n if (section === null) return;\n jumps.push(...sectionButtons(section, raw, at));\n const anchor = \"anchor\" in section ? section.anchor : null;\n if (anchor !== null) {\n if (anchors.includes(anchor)) reading.fail(`${at}.jumpLink`, `repeats \"${anchor}\", already used by another section`);\n anchors.push(anchor);\n }\n sections.push(section);\n });\n for (const { where, href } of jumps) {\n if (href.startsWith(\"#\") && !anchors.includes(href.slice(1))) reading.fail(where, `jumps to ${href}, which no section on the page is named`);\n }\n return { sections, warnings };\n}\n\n// ---------------------------------------------------------------------------\n// Content pages and settings\n// ---------------------------------------------------------------------------\n\nexport function parseContentPage(document: unknown): PageContent {\n const reading = new Reading();\n const doc = reading.object(document, \"page\");\n if (doc === null) throw new MalformedContentError(\"page\", reading.problems);\n const id = typeof doc[\"_id\"] === \"string\" ? doc[\"_id\"] : \"page\";\n if (doc[\"_type\"] !== \"page\") reading.fail(\"_type\", `is ${JSON.stringify(doc[\"_type\"])}, not page`);\n const title = reading.optionalString(doc[\"title\"], \"title\");\n if (title === null) reading.fail(\"title\", \"is missing\");\n if (doc[\"titleCopySource\"] === \"proposed\" && title !== null) reading.proposed.push({ where: \"title\", text: title });\n const slugObject = doc[\"slug\"] as Raw | undefined;\n const slug = typeof slugObject?.[\"current\"] === \"string\" && slugObject[\"current\"] !== \"\" ? slugObject[\"current\"] : null;\n if (slug === null) reading.fail(\"slug.current\", \"is missing\");\n const lead = reading.copy(doc[\"lead\"], \"lead\");\n const photo = reading.photo(doc[\"photo\"], \"photo\");\n const body = richTextToMarkdown(doc[\"body\"], \"body\", reading);\n if (doc[\"bodyCopySource\"] === \"proposed\") reading.proposed.push({ where: \"body\", text: body });\n const sections = doc[\"sections\"] === undefined || doc[\"sections\"] === null ? null : parseSections(doc[\"sections\"], reading);\n if (reading.problems.length > 0 || title === null || slug === null) throw new MalformedContentError(id, reading.problems);\n return {\n slug,\n title,\n composition: { intro: lead === null ? null : plain(lead), photo, hero: null, blocks: [] },\n body,\n migrated: doc[\"migrated\"] === true,\n proposedCopy: reading.proposed,\n ...(sections === null ? {} : sections),\n };\n}\n\nexport function parseSiteSettings(document: unknown): SiteSettingsContent {\n const reading = new Reading();\n const doc = reading.object(document, \"siteSettings\");\n if (doc === null) throw new MalformedContentError(READER_SITE_SETTINGS_ID, reading.problems);\n const name = reading.optionalString(doc[\"title\"], \"title\");\n if (name === null) reading.fail(\"title\", \"is missing; a site needs its name\");\n const description = reading.optionalString(doc[\"description\"], \"description\");\n const contact = doc[\"contact\"] === undefined ? {} : (reading.object(doc[\"contact\"], \"contact\") ?? {});\n const email = reading.optionalString(contact[\"email\"], \"contact.email\");\n const phone = reading.optionalString(contact[\"phone\"], \"contact.phone\");\n const social: { network: string; url: string }[] = [];\n const rawSocial = doc[\"social\"] ?? [];\n if (!Array.isArray(rawSocial)) reading.fail(\"social\", \"is not a list\");\n else if (reading.dense(rawSocial, \"social\"))\n rawSocial.forEach((member, index) => {\n const link = reading.object(member, `social[${String(index)}]`);\n if (link === null) return;\n const network = reading.optionalString(link[\"network\"], `social[${String(index)}].network`);\n const url = reading.optionalString(link[\"url\"], `social[${String(index)}].url`);\n if (network === null || url === null || !/^https?:\\/\\//.test(url)) {\n reading.fail(`social[${String(index)}]`, \"needs a network and a web address\");\n return;\n }\n social.push({ network, url });\n });\n if (reading.problems.length > 0 || name === null) throw new MalformedContentError(READER_SITE_SETTINGS_ID, reading.problems);\n return { name, description, contact: { email, phone }, social };\n}\n\n// ---------------------------------------------------------------------------\n// Queries\n// ---------------------------------------------------------------------------\n\n/** By fixed id: a second home page at a random id is never read. */\nexport const HOME_PAGE_DOCUMENT_QUERY = `*[_id == $id][0]`;\nconst MENU_PAGE_PROJECTION = `{..., \"sections\": coalesce(sections[]{..., _type == \"menuBlock\" => {menu->{${MENU_DOCUMENT_PROJECTION}}}}, sections)}`;\nexport const CONTENT_PAGES_QUERY = `*[_type == \"page\" && defined(slug.current)]|order(slug.current asc)${MENU_PAGE_PROJECTION}`;\nexport const CONTENT_PAGE_BY_SLUG_QUERY = `*[_type == \"page\" && slug.current == $slug][0]${MENU_PAGE_PROJECTION}`;\n\nexport interface SiteContentReader {\n /** `null` when no home page document exists yet. */\n home: (options: { readonly now: Date }) => Promise<HomeContent | null>;\n pages: () => Promise<PageContent[]>;\n /** `null` when no page has that slug. */\n pageBySlug: (slug: string) => Promise<PageContent | null>;\n /** `null` before anyone has filled in the site's details. */\n siteSettings: () => Promise<SiteSettingsContent | null>;\n}\n\nexport function createSiteContentReader(client: { query: <T>(groq: string, options?: { params?: Record<string, unknown>; tags?: readonly string[] }) => Promise<T> }): SiteContentReader {\n return {\n home: async ({ now }) => {\n const doc = await client.query<unknown>(HOME_PAGE_DOCUMENT_QUERY, { params: { id: READER_HOME_PAGE_ID } });\n return doc === null || doc === undefined ? null : parseHomePage(doc, { now });\n },\n pages: async () => {\n const docs = await client.query<unknown>(CONTENT_PAGES_QUERY);\n if (!Array.isArray(docs)) throw new MalformedContentError(\"page\", [\"the page query did not return a list\"]);\n if (!isDenseArray(docs)) throw new MalformedContentError(\"page\", [\"the page query contains missing entries\"]);\n return docs.map((doc) => parseContentPage(doc));\n },\n pageBySlug: async (slug) => {\n const doc = await client.query<unknown>(CONTENT_PAGE_BY_SLUG_QUERY, { params: { slug } });\n return doc === null || doc === undefined ? null : parseContentPage(doc);\n },\n siteSettings: async () => {\n const doc = await client.query<unknown>(HOME_PAGE_DOCUMENT_QUERY, { params: { id: READER_SITE_SETTINGS_ID } });\n return doc === null || doc === undefined ? null : parseSiteSettings(doc);\n },\n };\n}\n\nfunction atomic<T>(raw: unknown, fallback: T, parse: (value: unknown) => T, validFallback: (value: unknown) => boolean): CmsResolution<T> {\n if (!validFallback(fallback)) throw new TypeError(\"Invalid CMS content fallback\");\n if (raw === null || raw === undefined) return { data: fallback, fallbackFields: [\"$\"] };\n // The server reader catches parser errors and classifies the whole fallback\n // as malformed. Returning fallback here would lose that diagnostic reason.\n return { data: parse(raw), fallbackFields: [] };\n}\n\nexport function homeContentQuery(now: Date): CmsQuery<HomeContent | null> {\n if (!(now instanceof Date) || !Number.isFinite(now.getTime())) throw new TypeError(\"Invalid CMS campaign date\");\n const captured = now.getTime();\n return defineCmsQuery({\n name: \"homePage.v1\", query: HOME_PAGE_DOCUMENT_QUERY, params: { id: READER_HOME_PAGE_ID },\n dependencies: { types: [\"homePage\"], ids: [READER_HOME_PAGE_ID] },\n resolve: (raw, fallback) => atomic(raw, fallback, (value) => parseHomePage(value, { now: new Date(captured) }), validHomeFallback),\n });\n}\n\nexport function contentPageQuery(slug: string): CmsQuery<PageContent | null> {\n if (typeof slug !== \"string\" || slug === \"\") throw new TypeError(\"Invalid CMS page slug\");\n return defineCmsQuery({\n name: \"page.v1\", query: CONTENT_PAGE_BY_SLUG_QUERY, params: { slug }, dependencies: { types: [\"page\", \"menu\"] },\n resolve: (raw, fallback) => atomic(raw, fallback, parseContentPage, validPageFallback),\n });\n}\n\nexport function contentPagesQuery(): CmsQuery<readonly PageContent[]> {\n return defineCmsQuery({\n name: \"pages.v1\", query: CONTENT_PAGES_QUERY, params: {}, dependencies: { types: [\"page\", \"menu\"] },\n resolve: (raw, fallback) => atomic(raw, fallback, (value) => {\n if (!Array.isArray(value)) throw new MalformedContentError(\"page\", [\"the page query did not return a list\"]);\n if (!isDenseArray(value)) throw new MalformedContentError(\"page\", [\"the page query contains missing entries\"]);\n return value.map((document: unknown) => parseContentPage(document));\n }, (value) => isDenseArray(value) && value.every((page: unknown) => page !== null && validPageFallback(page))),\n });\n}\n\nexport function siteSettingsQuery(): CmsQuery<SiteSettingsContent | null> {\n return defineCmsQuery({\n name: \"siteSettings.v1\", query: HOME_PAGE_DOCUMENT_QUERY, params: { id: READER_SITE_SETTINGS_ID },\n dependencies: { types: [\"siteSettings\"], ids: [READER_SITE_SETTINGS_ID] },\n resolve: (raw, fallback) => atomic(raw, fallback, parseSiteSettings, validSettingsFallback),\n });\n}\n", "import { MalformedContentError } from \"../portable/site-content.js\";\nimport { MENU_DOCUMENT_PROJECTION } from \"../portable/menu-options.js\";\nimport { parseMenuDocument, validMenuFallback, type MenuDocument } from \"../portable/menu.js\";\n\n/** A-1822 S1 owns this implementation. S0 registers the public signatures. */\nexport type CmsParams = Readonly<Record<string, string | number | boolean | null>>;\nexport type CmsDependencies = {\n readonly types: readonly string[];\n readonly ids?: readonly string[];\n};\nexport type CmsResolution<T> = {\n readonly data: T;\n readonly fallbackFields: readonly string[];\n readonly warnings?: readonly (\"siteHero.layout.defaulted\" | \"siteHero.tagline.dropped\" | \"siteHero.taglines.defaulted\")[];\n};\nexport type CmsQuery<T> = {\n readonly name: string;\n readonly query: string;\n readonly params: CmsParams;\n readonly dependencies: CmsDependencies;\n readonly resolve: (raw: unknown, fallback: T) => CmsResolution<T>;\n};\n\nconst TYPE = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;\nconst ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;\nconst SCOPE = /^[a-z0-9]{6,12}\\.[a-z][a-z0-9_-]{0,63}$/;\n\nfunction dependenciesCopy(dependencies: CmsDependencies): CmsDependencies {\n if (!dependencies || !Array.isArray(dependencies.types) || dependencies.types.length === 0) {\n throw new TypeError(\"CMS dependencies require document types\");\n }\n const types = [...dependencies.types];\n for (const type of types) {\n if (typeof type !== \"string\" || !TYPE.test(type)) throw new TypeError(\"Invalid CMS document type\");\n }\n if (dependencies.ids !== undefined && !Array.isArray(dependencies.ids)) throw new TypeError(\"Invalid CMS document IDs\");\n const ids = dependencies.ids === undefined ? undefined : [...dependencies.ids];\n for (const id of ids ?? []) {\n if (typeof id !== \"string\" || !ID.test(id) || /^(drafts|versions)\\./.test(id)) {\n throw new TypeError(\"Invalid CMS document ID\");\n }\n }\n if (new Set(types).size + new Set(ids).size > 128) throw new TypeError(\"Too many CMS tags\");\n return Object.freeze({ types: Object.freeze(types), ...(ids === undefined ? {} : { ids: Object.freeze(ids) }) });\n}\n\nexport function defineCmsQuery<T>(query: CmsQuery<T>): CmsQuery<T> {\n if (!query || typeof query.name !== \"string\" || !/^[A-Za-z][A-Za-z0-9_.-]{0,127}$/.test(query.name)\n || typeof query.query !== \"string\" || query.query.trim() === \"\" || typeof query.resolve !== \"function\") {\n throw new TypeError(\"Invalid CMS query configuration\");\n }\n const params = query.params;\n if (!params || typeof params !== \"object\" || (Object.getPrototypeOf(params) !== Object.prototype && Object.getPrototypeOf(params) !== null)) {\n throw new TypeError(\"CMS params must be plain JSON scalars\");\n }\n const copied: Record<string, string | number | boolean | null> = {};\n for (const key of Reflect.ownKeys(params)) {\n const descriptor = Object.getOwnPropertyDescriptor(params, key);\n if (typeof key !== \"string\" || !descriptor || !Object.hasOwn(descriptor, \"value\") || !descriptor.enumerable) {\n throw new TypeError(\"CMS params must be plain JSON scalars\");\n }\n const value: unknown = descriptor.value;\n if (!(value === null || typeof value === \"string\" || typeof value === \"boolean\" || (typeof value === \"number\" && Number.isFinite(value)))) {\n throw new TypeError(\"CMS params must be plain JSON scalars\");\n }\n Object.defineProperty(copied, key, { value, enumerable: true });\n }\n return Object.freeze({ name: query.name, query: query.query, params: Object.freeze(copied), dependencies: dependenciesCopy(query.dependencies), resolve: query.resolve });\n}\n\nexport function cmsTags(scope: string, dependencies: CmsDependencies): readonly string[] {\n if (typeof scope !== \"string\" || scope.length > 77 || !SCOPE.test(scope)) throw new TypeError(\"Invalid CMS scope\");\n const copied = dependenciesCopy(dependencies);\n const tags = [\n ...[...new Set(copied.types)].sort().map((type) => `cms:${scope}:type:${type}`),\n ...[...new Set(copied.ids ?? [])].sort().map((id) => `cms:${scope}:id:${id}`),\n ];\n return Object.freeze(tags);\n}\n\n/** Read one published menu by its document id; host supplies the last good snapshot. */\nexport function menuQuery(id: string): CmsQuery<MenuDocument | null> {\n return defineCmsQuery({\n name: \"menu.v1\",\n query: `*[_type == \"menu\" && _id == $id && !(_id in path(\"drafts.**\")) && !(_id in path(\"versions.**\"))][0]{${MENU_DOCUMENT_PROJECTION}}`,\n params: { id }, dependencies: { types: [\"menu\"], ids: [id] },\n resolve: (raw, fallback) => {\n if (!validMenuFallback(fallback) || (fallback !== null && fallback._id !== id)) throw new TypeError(\"Invalid CMS menu fallback\");\n if (raw === null || raw === undefined) return { data: fallback, fallbackFields: [\"$\"] };\n const data = parseMenuDocument(raw);\n if (data._id !== id) throw new MalformedContentError(\"menu\", [\"menu._id does not match the requested document\"]);\n return { data, fallbackFields: [] };\n },\n });\n}\n", "import { defineCmsQuery, type CmsQuery, type CmsResolution } from \"./query.js\";\n\nexport const SITE_HERO_LAYOUTS = [\"columns\", \"rows\"] as const;\nexport const SITE_HERO_TAGLINE_MAX_LENGTH = 40;\nexport const SITE_HERO_LAYOUT_WARNING = \"siteHero.layout.defaulted\" as const;\nexport const SITE_HERO_TAGLINE_DROPPED_WARNING = \"siteHero.tagline.dropped\" as const;\nexport const SITE_HERO_TAGLINES_DEFAULTED_WARNING = \"siteHero.taglines.defaulted\" as const;\nexport type SiteHeroLayout = typeof SITE_HERO_LAYOUTS[number];\nexport type SiteHeroTagline = { readonly key: string; readonly text: string };\n/** Optional additions preserve existing heading/intro-only consumer fallbacks. */\nexport type SiteHero = {\n readonly heading: string;\n readonly intro: string;\n readonly layout?: SiteHeroLayout;\n readonly taglines?: readonly SiteHeroTagline[];\n};\nexport type ParsedSiteHero = SiteHero & {\n readonly layout: SiteHeroLayout;\n readonly taglines: readonly SiteHeroTagline[];\n};\nexport type TextFieldDefinition = {\n readonly name: string;\n readonly label: string;\n readonly noun: { readonly article: \"a\" | \"an\"; readonly word: string };\n readonly kind: \"single-line\" | \"multi-line\";\n readonly required: boolean;\n readonly minLength: number;\n readonly maxLength: number;\n readonly noTrailingFullStop?: boolean;\n};\nexport type TextDocumentDefinition = {\n readonly key: string;\n readonly documentId: string;\n readonly documentType: string;\n readonly fields: readonly TextFieldDefinition[];\n readonly copy: {\n readonly currentTitle: string;\n readonly editTitle: string;\n readonly empty: string;\n };\n};\nexport type TextValidation =\n | { readonly ok: true; readonly value: Readonly<Record<string, string>> }\n | { readonly ok: false; readonly errors: Readonly<Record<string, string>> };\n\nexport const CMS_CONTRACT_VERSION = 1;\n\nexport const SITE_HERO: TextDocumentDefinition = {\n key: \"hero\",\n documentId: \"siteHero\",\n documentType: \"siteHero\",\n fields: [\n {\n name: \"heading\",\n label: \"Heading\",\n noun: { article: \"a\", word: \"heading\" },\n kind: \"single-line\",\n required: true,\n minLength: 1,\n maxLength: 80,\n noTrailingFullStop: true,\n },\n {\n name: \"intro\",\n label: \"Introduction\",\n noun: { article: \"an\", word: \"introduction\" },\n kind: \"multi-line\",\n required: true,\n minLength: 1,\n maxLength: 320,\n },\n ],\n copy: {\n currentTitle: \"On your site now\",\n editTitle: \"Edit and publish\",\n empty: \"Your site has no hero text yet. Whatever you publish below becomes its first version.\",\n },\n};\n\nfunction fieldError(field: TextFieldDefinition, text: string): string | null {\n const { article, word } = field.noun;\n if (text.length === 0) return field.required ? `Enter ${article} ${word}.` : null;\n const count = [...text].length;\n if (count < field.minLength) return `Make the ${word} at least ${String(field.minLength)} characters. It is ${String(count)} now.`;\n if (count > field.maxLength) return `Keep the ${word} to ${String(field.maxLength)} characters or fewer. It is ${String(count)} now.`;\n if (text.includes(\"\\u2014\")) return `The ${word} contains a long dash. Use a comma, a colon or a short dash instead.`;\n if (field.kind === \"single-line\" && /[\\r\\n]/.test(text)) return `The ${word} must be a single line.`;\n if (field.noTrailingFullStop === true && text.endsWith(\".\")) {\n return `${word.charAt(0).toUpperCase()}${word.slice(1)}s on your site do not end with a full stop. Remove the last full stop.`;\n }\n return null;\n}\n\nexport function validateTextDocument(\n definition: TextDocumentDefinition, raw: Readonly<Record<string, unknown>>,\n): TextValidation {\n const value: Record<string, string> = {};\n const errors: Record<string, string> = {};\n for (const field of definition.fields) {\n const submitted = Object.hasOwn(raw, field.name) ? raw[field.name] : undefined;\n const text = typeof submitted === \"string\" ? submitted.trim() : \"\";\n const error = fieldError(field, text);\n Object.defineProperty(error === null ? value : errors, field.name, { value: error ?? text, enumerable: true });\n }\n return Object.keys(errors).length > 0 ? { ok: false, errors } : { ok: true, value };\n}\n\n/** One rule set for strict authoring validation and resilient published reads. */\nfunction scanSiteHeroTaglines(raw: unknown):\n | { readonly ok: true; readonly value: readonly SiteHeroTagline[]; readonly dropped: readonly { index: number; error: string }[] }\n | { readonly ok: false; readonly error: string } {\n if (!Array.isArray(raw)) return { ok: false, error: \"Enter a list of taglines.\" };\n const heading = SITE_HERO.fields[0];\n if (!heading) throw new TypeError(\"Missing siteHero heading definition\");\n const field = { ...heading, name: \"text\", noun: { article: \"a\", word: \"tagline\" } as const,\n maxLength: SITE_HERO_TAGLINE_MAX_LENGTH };\n const value: SiteHeroTagline[] = [];\n const dropped: { index: number; error: string }[] = [];\n const keys = new Set<string>();\n for (const [index, item] of (raw as unknown[]).entries()) {\n if (!item || typeof item !== \"object\" || Array.isArray(item)) {\n dropped.push({ index, error: \"Enter a key and text for each tagline.\" });\n continue;\n }\n const record = item as Record<string, unknown>;\n const key = Object.hasOwn(record, \"key\") ? record.key : undefined;\n if (typeof key !== \"string\" || !/^[a-z][a-z0-9_-]{0,31}$/.test(key)) {\n dropped.push({ index, error: \"Use a lowercase key of 1 to 32 letters, numbers, short dashes or underscores, starting with a letter.\" });\n continue;\n }\n if (keys.has(key)) {\n dropped.push({ index, error: \"Use each tagline key only once.\" });\n continue;\n }\n const text = validateTextDocument({ ...SITE_HERO, fields: [field] }, record);\n if (!text.ok) {\n dropped.push({ index, error: text.errors.text ?? \"Invalid tagline.\" });\n continue;\n }\n const copy = text.value.text ?? \"\";\n if ((copy.match(/\\p{L}/gu)?.length ?? 0) >= 2 && !/\\p{Ll}/u.test(copy)) {\n dropped.push({ index, error: \"Use sentence case for the tagline, rather than all capitals.\" });\n continue;\n }\n keys.add(key);\n value.push({ key, text: copy });\n }\n return { ok: true, value, dropped };\n}\n\n/** Shared with the schema adapter; invalid authoring input is refused as a whole. */\nexport function validateSiteHeroTaglines(raw: unknown):\n | { readonly ok: true; readonly value: readonly SiteHeroTagline[] }\n | { readonly ok: false; readonly error: string } {\n const result = scanSiteHeroTaglines(raw);\n if (!result.ok) return result;\n const first = result.dropped[0];\n return first ? { ok: false, error: first.error } : { ok: true, value: result.value };\n}\n\nfunction isLayout(value: unknown): value is SiteHeroLayout {\n return SITE_HERO_LAYOUTS.some((layout) => value === layout);\n}\n\n/** Invalid published entries are dropped without discarding valid keyed siblings. */\nexport function parseSiteHero(raw: unknown, fallback: SiteHero): CmsResolution<ParsedSiteHero> {\n const local = validateTextDocument(SITE_HERO, fallback);\n const localTaglines = validateSiteHeroTaglines(fallback.taglines ?? []);\n if (!local.ok || !localTaglines.ok || (fallback.layout !== undefined && !isLayout(fallback.layout))) {\n throw new TypeError(\"Invalid siteHero fallback\");\n }\n const data: { heading: string; intro: string; layout: SiteHeroLayout; taglines: readonly SiteHeroTagline[] } = {\n heading: local.value.heading ?? \"\", intro: local.value.intro ?? \"\",\n layout: fallback.layout ?? \"columns\", taglines: localTaglines.value,\n };\n if (raw === null || typeof raw !== \"object\" || Array.isArray(raw)) return { data, fallbackFields: [\"$\"] };\n const record = raw as Readonly<Record<string, unknown>>;\n const text = validateTextDocument(SITE_HERO, record);\n const fallbackFields: string[] = text.ok ? [] : Object.keys(text.errors);\n for (const field of SITE_HERO.fields) {\n if (!fallbackFields.includes(field.name)) {\n const value = text.ok ? text.value[field.name] : record[field.name];\n if (typeof value === \"string\" && (field.name === \"heading\" || field.name === \"intro\")) data[field.name] = value.trim();\n }\n }\n const layout = Object.hasOwn(record, \"layout\") ? record.layout : undefined;\n const warnings: NonNullable<CmsResolution<ParsedSiteHero>[\"warnings\"]>[number][] = [];\n if (isLayout(layout)) data.layout = layout;\n else {\n data.layout = \"columns\";\n fallbackFields.push(\"layout\");\n warnings.push(SITE_HERO_LAYOUT_WARNING);\n }\n const taglines = scanSiteHeroTaglines(Object.hasOwn(record, \"taglines\") ? record.taglines : undefined);\n if (taglines.ok) {\n data.taglines = taglines.value;\n for (const { index } of taglines.dropped) fallbackFields.push(`taglines[${String(index)}]`);\n if (taglines.dropped.length > 0) warnings.push(SITE_HERO_TAGLINE_DROPPED_WARNING);\n } else {\n fallbackFields.push(\"taglines\");\n warnings.push(SITE_HERO_TAGLINES_DEFAULTED_WARNING);\n }\n const wholeFallback = [...SITE_HERO.fields.map((field) => field.name), \"layout\", \"taglines\"].every((field) => fallbackFields.includes(field));\n return { data, fallbackFields: wholeFallback ? [\"$\"] : fallbackFields,\n ...(warnings.length > 0 ? { warnings } : {}) };\n}\n\nexport function siteHeroQuery(): CmsQuery<SiteHero> {\n return defineCmsQuery<SiteHero>({\n name: \"siteHero.v1\", query: '*[_id == $id && _type == \"siteHero\"][0]{heading,intro,layout,taglines}',\n params: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AyB,CAC9B,KAAM,cAAe,MAAO,yEAC5B,OAAQ,CAAE,GAAI,UAAW,EAAG,aAAc,CAAE,MAAO,CAAC,UAAU,EAAG,IAAK,CAAC,UAAU,CAAE,EACnF,QAASV,CACX,CAAC,CACH",
6
+ "names": ["index_exports", "__export", "CMS_CONTRACT_VERSION", "MENU_DECORATIONS", "MENU_LAYOUTS", "MENU_LAYOUT_DEFAULTS", "SITE_HERO", "SITE_HERO_LAYOUTS", "SITE_HERO_LAYOUT_WARNING", "SITE_HERO_TAGLINES_DEFAULTED_WARNING", "SITE_HERO_TAGLINE_DROPPED_WARNING", "SITE_HERO_TAGLINE_MAX_LENGTH", "cmsTags", "defineCmsQuery", "menuQuery", "menuTags", "parseMenuDocument", "parseSiteHero", "siteHeroQuery", "validateSiteHeroTaglines", "validateTextDocument", "__toCommonJS", "isDenseArray", "value", "index", "MENU_LAYOUTS", "MENU_DECORATIONS", "MENU_LAYOUT_DEFAULTS", "MENU_DOCUMENT_PROJECTION", "menuTags", "scope", "id", "cmsTags", "fail", "path", "reason", "MalformedContentError", "snapshot", "value", "ancestors", "identity", "array", "prototype", "keys", "copied", "length", "entries", "key", "at", "descriptor", "savedLength", "saved", "entry", "error", "object", "text", "required", "optional", "raw", "field", "list", "read", "isDenseArray", "index", "money", "currency", "price", "extra", "item", "availability", "section", "variant", "isPublishedMenuDocument", "parseMenuDocument", "document", "where", "parseSnapshot", "parseSnapshot", "document", "where", "raw", "object", "fail", "isPublishedMenuDocument", "updatedAt", "text", "variants", "list", "variant", "optional", "validMenuFallback", "value", "parseMenuDocument", "MALFORMED_CONTENT", "MalformedContentError", "documentId", "problems", "MENU_PAGE_PROJECTION", "MENU_DOCUMENT_PROJECTION", "CONTENT_PAGES_QUERY", "CONTENT_PAGE_BY_SLUG_QUERY", "TYPE", "ID", "SCOPE", "dependenciesCopy", "dependencies", "types", "type", "ids", "id", "defineCmsQuery", "query", "params", "copied", "key", "descriptor", "value", "cmsTags", "scope", "tags", "menuQuery", "MENU_DOCUMENT_PROJECTION", "raw", "fallback", "validMenuFallback", "data", "parseMenuDocument", "MalformedContentError", "SITE_HERO_LAYOUTS", "SITE_HERO_TAGLINE_MAX_LENGTH", "SITE_HERO_LAYOUT_WARNING", "SITE_HERO_TAGLINE_DROPPED_WARNING", "SITE_HERO_TAGLINES_DEFAULTED_WARNING", "CMS_CONTRACT_VERSION", "SITE_HERO", "fieldError", "field", "text", "article", "word", "count", "validateTextDocument", "definition", "raw", "value", "errors", "submitted", "error", "scanSiteHeroTaglines", "heading", "dropped", "keys", "index", "item", "record", "key", "copy", "validateSiteHeroTaglines", "result", "first", "isLayout", "layout", "parseSiteHero", "fallback", "local", "localTaglines", "data", "fallbackFields", "warnings", "taglines", "wholeFallback", "siteHeroQuery", "defineCmsQuery"]
7
7
  }
package/dist/index.d.cts CHANGED
@@ -2,3 +2,6 @@ export { defineCmsQuery, cmsTags } from "./contracts/query.cjs";
2
2
  export type { CmsParams, CmsDependencies, CmsResolution, CmsQuery } from "./contracts/query.cjs";
3
3
  export { SITE_HERO, CMS_CONTRACT_VERSION, validateTextDocument, siteHeroQuery, SITE_HERO_LAYOUTS, SITE_HERO_TAGLINE_MAX_LENGTH, SITE_HERO_LAYOUT_WARNING, SITE_HERO_TAGLINE_DROPPED_WARNING, SITE_HERO_TAGLINES_DEFAULTED_WARNING, parseSiteHero, validateSiteHeroTaglines } from "./contracts/text.cjs";
4
4
  export type { SiteHero, ParsedSiteHero, SiteHeroLayout, SiteHeroTagline, TextFieldDefinition, TextDocumentDefinition, TextValidation } from "./contracts/text.cjs";
5
+ export { MENU_LAYOUTS, MENU_DECORATIONS, MENU_LAYOUT_DEFAULTS, parseMenuDocument, menuTags } from "./portable/menu.cjs";
6
+ export { menuQuery } from "./contracts/query.cjs";
7
+ export type { MenuDocument, MenuVariant, MenuSection, MenuItem, MenuPrice, MenuExtra, MenuMoney, MenuLayout, MenuDecoration, MenuSectionInput } from "./portable/menu.cjs";
package/dist/index.d.mts CHANGED
@@ -2,3 +2,6 @@ export { defineCmsQuery, cmsTags } from "./contracts/query.mjs";
2
2
  export type { CmsParams, CmsDependencies, CmsResolution, CmsQuery } from "./contracts/query.mjs";
3
3
  export { SITE_HERO, CMS_CONTRACT_VERSION, validateTextDocument, siteHeroQuery, SITE_HERO_LAYOUTS, SITE_HERO_TAGLINE_MAX_LENGTH, SITE_HERO_LAYOUT_WARNING, SITE_HERO_TAGLINE_DROPPED_WARNING, SITE_HERO_TAGLINES_DEFAULTED_WARNING, parseSiteHero, validateSiteHeroTaglines } from "./contracts/text.mjs";
4
4
  export type { SiteHero, ParsedSiteHero, SiteHeroLayout, SiteHeroTagline, TextFieldDefinition, TextDocumentDefinition, TextValidation } from "./contracts/text.mjs";
5
+ export { MENU_LAYOUTS, MENU_DECORATIONS, MENU_LAYOUT_DEFAULTS, parseMenuDocument, menuTags } from "./portable/menu.mjs";
6
+ export { menuQuery } from "./contracts/query.mjs";
7
+ export type { MenuDocument, MenuVariant, MenuSection, MenuItem, MenuPrice, MenuExtra, MenuMoney, MenuLayout, MenuDecoration, MenuSectionInput } from "./portable/menu.mjs";
package/dist/index.d.ts CHANGED
@@ -2,3 +2,6 @@ export { defineCmsQuery, cmsTags } from "./contracts/query.js";
2
2
  export type { CmsParams, CmsDependencies, CmsResolution, CmsQuery } from "./contracts/query.js";
3
3
  export { SITE_HERO, CMS_CONTRACT_VERSION, validateTextDocument, siteHeroQuery, SITE_HERO_LAYOUTS, SITE_HERO_TAGLINE_MAX_LENGTH, SITE_HERO_LAYOUT_WARNING, SITE_HERO_TAGLINE_DROPPED_WARNING, SITE_HERO_TAGLINES_DEFAULTED_WARNING, parseSiteHero, validateSiteHeroTaglines } from "./contracts/text.js";
4
4
  export type { SiteHero, ParsedSiteHero, SiteHeroLayout, SiteHeroTagline, TextFieldDefinition, TextDocumentDefinition, TextValidation } from "./contracts/text.js";
5
+ export { MENU_LAYOUTS, MENU_DECORATIONS, MENU_LAYOUT_DEFAULTS, parseMenuDocument, menuTags } from "./portable/menu.js";
6
+ export { menuQuery } from "./contracts/query.js";
7
+ export type { MenuDocument, MenuVariant, MenuSection, MenuItem, MenuPrice, MenuExtra, MenuMoney, MenuLayout, MenuDecoration, MenuSectionInput } from "./portable/menu.js";
package/dist/index.mjs CHANGED
@@ -1,2 +1,6 @@
1
- var _=/^[A-Za-z][A-Za-z0-9_]{0,63}$/,R=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/,C=/^[a-z0-9]{6,12}\.[a-z][a-z0-9_-]{0,63}$/;function T(e){if(!e||!Array.isArray(e.types)||e.types.length===0)throw new TypeError("CMS dependencies require document types");let t=[...e.types];for(let r of t)if(typeof r!="string"||!_.test(r))throw new TypeError("Invalid CMS document type");if(e.ids!==void 0&&!Array.isArray(e.ids))throw new TypeError("Invalid CMS document IDs");let o=e.ids===void 0?void 0:[...e.ids];for(let r of o??[])if(typeof r!="string"||!R.test(r)||/^(drafts|versions)\./.test(r))throw new TypeError("Invalid CMS document ID");if(new Set(t).size+new Set(o).size>128)throw new TypeError("Too many CMS tags");return Object.freeze({types:Object.freeze(t),...o===void 0?{}:{ids:Object.freeze(o)}})}function f(e){if(!e||typeof e.name!="string"||!/^[A-Za-z][A-Za-z0-9_.-]{0,127}$/.test(e.name)||typeof e.query!="string"||e.query.trim()===""||typeof e.resolve!="function")throw new TypeError("Invalid CMS query configuration");let t=e.params;if(!t||typeof t!="object"||Object.getPrototypeOf(t)!==Object.prototype&&Object.getPrototypeOf(t)!==null)throw new TypeError("CMS params must be plain JSON scalars");let o={};for(let r of Reflect.ownKeys(t)){let n=Object.getOwnPropertyDescriptor(t,r);if(typeof r!="string"||!n||!Object.hasOwn(n,"value")||!n.enumerable)throw new TypeError("CMS params must be plain JSON scalars");let i=n.value;if(!(i===null||typeof i=="string"||typeof i=="boolean"||typeof i=="number"&&Number.isFinite(i)))throw new TypeError("CMS params must be plain JSON scalars");Object.defineProperty(o,r,{value:i,enumerable:!0})}return Object.freeze({name:e.name,query:e.query,params:Object.freeze(o),dependencies:T(e.dependencies),resolve:e.resolve})}function I(e,t){if(typeof e!="string"||e.length>77||!C.test(e))throw new TypeError("Invalid CMS scope");let o=T(t),r=[...[...new Set(o.types)].sort().map(n=>`cms:${e}:type:${n}`),...[...new Set(o.ids??[])].sort().map(n=>`cms:${e}:id:${n}`)];return Object.freeze(r)}var S=["columns","rows"],H=40,E="siteHero.layout.defaulted",w="siteHero.tagline.dropped",x="siteHero.taglines.defaulted",v=1,y={key:"hero",documentId:"siteHero",documentType:"siteHero",fields:[{name:"heading",label:"Heading",noun:{article:"a",word:"heading"},kind:"single-line",required:!0,minLength:1,maxLength:80,noTrailingFullStop:!0},{name:"intro",label:"Introduction",noun:{article:"an",word:"introduction"},kind:"multi-line",required:!0,minLength:1,maxLength:320}],copy:{currentTitle:"On your site now",editTitle:"Edit and publish",empty:"Your site has no hero text yet. Whatever you publish below becomes its first version."}};function A(e,t){let{article:o,word:r}=e.noun;if(t.length===0)return e.required?`Enter ${o} ${r}.`:null;let n=[...t].length;return n<e.minLength?`Make the ${r} at least ${String(e.minLength)} characters. It is ${String(n)} now.`:n>e.maxLength?`Keep the ${r} to ${String(e.maxLength)} characters or fewer. It is ${String(n)} now.`:t.includes("\u2014")?`The ${r} contains a long dash. Use a comma, a colon or a short dash instead.`:e.kind==="single-line"&&/[\r\n]/.test(t)?`The ${r} must be a single line.`:e.noTrailingFullStop===!0&&t.endsWith(".")?`${r.charAt(0).toUpperCase()}${r.slice(1)}s on your site do not end with a full stop. Remove the last full stop.`:null}function g(e,t){let o={},r={};for(let n of e.fields){let i=Object.hasOwn(t,n.name)?t[n.name]:void 0,a=typeof i=="string"?i.trim():"",s=A(n,a);Object.defineProperty(s===null?o:r,n.name,{value:s??a,enumerable:!0})}return Object.keys(r).length>0?{ok:!1,errors:r}:{ok:!0,value:o}}function b(e){if(!Array.isArray(e))return{ok:!1,error:"Enter a list of taglines."};let t=y.fields[0];if(!t)throw new TypeError("Missing siteHero heading definition");let o={...t,name:"text",noun:{article:"a",word:"tagline"},maxLength:H},r=[],n=[],i=new Set;for(let[a,s]of e.entries()){if(!s||typeof s!="object"||Array.isArray(s)){n.push({index:a,error:"Enter a key and text for each tagline."});continue}let c=s,d=Object.hasOwn(c,"key")?c.key:void 0;if(typeof d!="string"||!/^[a-z][a-z0-9_-]{0,31}$/.test(d)){n.push({index:a,error:"Use a lowercase key of 1 to 32 letters, numbers, short dashes or underscores, starting with a letter."});continue}if(i.has(d)){n.push({index:a,error:"Use each tagline key only once."});continue}let u=g({...y,fields:[o]},c);if(!u.ok){n.push({index:a,error:u.errors.text??"Invalid tagline."});continue}let p=u.value.text??"";if((p.match(/\p{L}/gu)?.length??0)>=2&&!/\p{Ll}/u.test(p)){n.push({index:a,error:"Use sentence case for the tagline, rather than all capitals."});continue}i.add(d),r.push({key:d,text:p})}return{ok:!0,value:r,dropped:n}}function O(e){let t=b(e);if(!t.ok)return t;let o=t.dropped[0];return o?{ok:!1,error:o.error}:{ok:!0,value:t.value}}function h(e){return S.some(t=>e===t)}function k(e,t){let o=g(y,t),r=O(t.taglines??[]);if(!o.ok||!r.ok||t.layout!==void 0&&!h(t.layout))throw new TypeError("Invalid siteHero fallback");let n={heading:o.value.heading??"",intro:o.value.intro??"",layout:t.layout??"columns",taglines:r.value};if(e===null||typeof e!="object"||Array.isArray(e))return{data:n,fallbackFields:["$"]};let i=e,a=g(y,i),s=a.ok?[]:Object.keys(a.errors);for(let l of y.fields)if(!s.includes(l.name)){let m=a.ok?a.value[l.name]:i[l.name];typeof m=="string"&&(l.name==="heading"||l.name==="intro")&&(n[l.name]=m.trim())}let c=Object.hasOwn(i,"layout")?i.layout:void 0,d=[];h(c)?n.layout=c:(n.layout="columns",s.push("layout"),d.push(E));let u=b(Object.hasOwn(i,"taglines")?i.taglines:void 0);if(u.ok){n.taglines=u.value;for(let{index:l}of u.dropped)s.push(`taglines[${String(l)}]`);u.dropped.length>0&&d.push(w)}else s.push("taglines"),d.push(x);let p=[...y.fields.map(l=>l.name),"layout","taglines"].every(l=>s.includes(l));return{data:n,fallbackFields:p?["$"]:s,...d.length>0?{warnings:d}:{}}}function L(){return f({name:"siteHero.v1",query:'*[_id == $id && _type == "siteHero"][0]{heading,intro,layout,taglines}',params:{id:"siteHero"},dependencies:{types:["siteHero"],ids:["siteHero"]},resolve:k})}export{v as CMS_CONTRACT_VERSION,y as SITE_HERO,S as SITE_HERO_LAYOUTS,E as SITE_HERO_LAYOUT_WARNING,x as SITE_HERO_TAGLINES_DEFAULTED_WARNING,w as SITE_HERO_TAGLINE_DROPPED_WARNING,H as SITE_HERO_TAGLINE_MAX_LENGTH,I as cmsTags,f as defineCmsQuery,k as parseSiteHero,L as siteHeroQuery,O as validateSiteHeroTaglines,g as validateTextDocument};
1
+ function I(n){if(!Array.isArray(n))return!1;for(let e=0;e<n.length;e+=1)if(!Object.hasOwn(n,e))return!1;return!0}var A=["stacked","columns"],O=["none","playful"],E={layout:"stacked",decoration:"none"},$=`_type, _id, _rev, _updatedAt, title, locationKeys, note, signOff,
2
+ variants[]{_key, label, note, sections[]{_key, title, service, items[]{
3
+ _key, name, description, priceNote, dietary, allergenNote, availability,
4
+ prices[]{_key, label, amount{minor, currency}}, extras[]{_key, name, amount{minor, currency}}
5
+ }}}`;function J(n,e){return x(n,{types:["menu"],...e===void 0?{}:{ids:[e]}})}function s(n,e){throw new b("menu",[`${n} ${e}`])}function R(n,e,t=new Set,o){if(n===null||typeof n=="string"||typeof n=="boolean"||typeof n=="number"&&Number.isFinite(n))return n;if(typeof n!="object"||n===null)return s(e,"is not plain JSON data");try{if(t.has(n))return s(e,"is not acyclic JSON data");let r=Array.isArray(n),i=Object.getPrototypeOf(n);if(r?i!==Array.prototype:i!==Object.prototype&&i!==null)return s(e,"is not an ordinary saved object");t.add(n);let d=Reflect.ownKeys(n),l=r?[]:{},f=0,y=0;for(let u of d){if(typeof u!="string")return s(e,"has a symbol key");let p=r&&u!=="length"?`${e}[${u}]`:`${e}.${u}`,a;try{a=u==="_id"&&o!==void 0?o:Object.getOwnPropertyDescriptor(n,u)}catch{return s(p,"could not be snapshotted as plain JSON data")}if(!a||!Object.hasOwn(a,"value"))return s(p,"is not a saved data property");if(r&&u==="length"){let _=a.value;if(typeof _!="number"||!Number.isSafeInteger(_)||_<0)return s(p,"is not a saved list length");f=_;continue}if(!a.enumerable||r&&!/^(0|[1-9]\d*)$/.test(u))return s(p,"is not a JSON data property");let k=a.value,G=R(k,p,t);Object.defineProperty(l,u,{value:G,enumerable:!0,writable:!0,configurable:!0}),y++}return r&&(y!==f||l.length!==f)?s(e,"is not a complete saved list"):l}catch(r){if(r instanceof b)throw r;return s(e,"could not be snapshotted as plain JSON data")}finally{t.delete(n)}}function h(n,e){return n===null||typeof n!="object"||Array.isArray(n)||Object.getPrototypeOf(n)!==Object.prototype&&Object.getPrototypeOf(n)!==null?s(e,"is not an ordinary saved object"):n}function c(n,e,t=!0){return typeof n!="string"||t&&n.trim()===""?s(e,"is not saved text"):n}function g(n,e,t){return n[e]===void 0||n[e]===null?{}:{[e]:c(n[e],`${t}.${e}`,!1)}}function m(n,e,t){return n==null?[]:I(n)?n.map((o,r)=>t(o,`${e}[${String(r)}]`)):s(e,"is not a complete saved list")}function M(n,e){let t=h(n,e);if(typeof t.minor!="number"||!Number.isSafeInteger(t.minor)||t.minor<0)return s(`${e}.minor`,"is not a whole non-negative safe amount");let o=c(t.currency,`${e}.currency`);return/^[A-Z]{3}$/.test(o)?{minor:t.minor,currency:o}:s(`${e}.currency`,"is not a three-letter currency code")}function Q(n,e){let t=h(n,e);return{_key:c(t._key,`${e}._key`),amount:M(t.amount,`${e}.amount`),...g(t,"label",e)}}function W(n,e){let t=h(n,e);return{_key:c(t._key,`${e}._key`),name:c(t.name,`${e}.name`),amount:M(t.amount,`${e}.amount`)}}function K(n,e){let t=h(n,e),o=t.availability??"available";return o!=="available"&&o!=="sold-out"&&o!=="hidden"?s(`${e}.availability`,"is not an availability choice"):{_key:c(t._key,`${e}._key`),name:c(t.name,`${e}.name`),...g(t,"description",e),...g(t,"priceNote",e),...g(t,"allergenNote",e),prices:m(t.prices,`${e}.prices`,Q),extras:m(t.extras,`${e}.extras`,W),dietary:m(t.dietary,`${e}.dietary`,c),availability:o}}function V(n,e){let t=h(n,e);return{_key:c(t._key,`${e}._key`),title:c(t.title,`${e}.title`),...g(t,"service",e),items:m(t.items,`${e}.items`,K)}}function Z(n,e){let t=h(n,e);return{_key:c(t._key,`${e}._key`),label:c(t.label,`${e}.label`),...g(t,"note",e),sections:m(t.sections,`${e}.sections`,V)}}function X(n){if(n===null||typeof n!="object"||Array.isArray(n))return!1;let e=n._id;return typeof e=="string"&&e.trim()!==""&&!/^(drafts|versions)\./.test(e)}function w(n,e="menu"){return ee(R(n,e),e)}function ee(n,e){let t=h(n,e);if(t._type!=="menu")return s(`${e}._type`,"is not menu");if(!X(t))return s(`${e}._id`,"is not a published menu identity");let o=c(t._updatedAt,`${e}._updatedAt`);if(!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/.test(o)||!Number.isFinite(Date.parse(o)))return s(`${e}._updatedAt`,"is not an update date");let r=m(t.variants,`${e}.variants`,Z);return r.length===0?s(`${e}.variants`,"has no menu choices"):{_type:"menu",_id:c(t._id,`${e}._id`),_rev:c(t._rev,`${e}._rev`),_updatedAt:o,title:c(t.title,`${e}.title`),locationKeys:m(t.locationKeys,`${e}.locationKeys`,c),variants:r,...g(t,"note",e),...Object.hasOwn(t,"signOff")?{signOff:t.signOff}:{}}}function N(n){if(n===null)return!0;try{return w(n),!0}catch{return!1}}var D="malformed-content",b=class extends Error{code=D;documentId;problems;constructor(e,t){super(`${D}: ${e}: ${t.join("; ")}`),this.name="MalformedContentError",this.documentId=e,this.problems=t}};var j=`{..., "sections": coalesce(sections[]{..., _type == "menuBlock" => {menu->{${$}}}}, sections)}`,me=`*[_type == "page" && defined(slug.current)]|order(slug.current asc)${j}`,he=`*[_type == "page" && slug.current == $slug][0]${j}`;var ne=/^[A-Za-z][A-Za-z0-9_]{0,63}$/,te=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/,oe=/^[a-z0-9]{6,12}\.[a-z][a-z0-9_-]{0,63}$/;function H(n){if(!n||!Array.isArray(n.types)||n.types.length===0)throw new TypeError("CMS dependencies require document types");let e=[...n.types];for(let o of e)if(typeof o!="string"||!ne.test(o))throw new TypeError("Invalid CMS document type");if(n.ids!==void 0&&!Array.isArray(n.ids))throw new TypeError("Invalid CMS document IDs");let t=n.ids===void 0?void 0:[...n.ids];for(let o of t??[])if(typeof o!="string"||!te.test(o)||/^(drafts|versions)\./.test(o))throw new TypeError("Invalid CMS document ID");if(new Set(e).size+new Set(t).size>128)throw new TypeError("Too many CMS tags");return Object.freeze({types:Object.freeze(e),...t===void 0?{}:{ids:Object.freeze(t)}})}function T(n){if(!n||typeof n.name!="string"||!/^[A-Za-z][A-Za-z0-9_.-]{0,127}$/.test(n.name)||typeof n.query!="string"||n.query.trim()===""||typeof n.resolve!="function")throw new TypeError("Invalid CMS query configuration");let e=n.params;if(!e||typeof e!="object"||Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null)throw new TypeError("CMS params must be plain JSON scalars");let t={};for(let o of Reflect.ownKeys(e)){let r=Object.getOwnPropertyDescriptor(e,o);if(typeof o!="string"||!r||!Object.hasOwn(r,"value")||!r.enumerable)throw new TypeError("CMS params must be plain JSON scalars");let i=r.value;if(!(i===null||typeof i=="string"||typeof i=="boolean"||typeof i=="number"&&Number.isFinite(i)))throw new TypeError("CMS params must be plain JSON scalars");Object.defineProperty(t,o,{value:i,enumerable:!0})}return Object.freeze({name:n.name,query:n.query,params:Object.freeze(t),dependencies:H(n.dependencies),resolve:n.resolve})}function x(n,e){if(typeof n!="string"||n.length>77||!oe.test(n))throw new TypeError("Invalid CMS scope");let t=H(e),o=[...[...new Set(t.types)].sort().map(r=>`cms:${n}:type:${r}`),...[...new Set(t.ids??[])].sort().map(r=>`cms:${n}:id:${r}`)];return Object.freeze(o)}function re(n){return T({name:"menu.v1",query:`*[_type == "menu" && _id == $id && !(_id in path("drafts.**")) && !(_id in path("versions.**"))][0]{${$}}`,params:{id:n},dependencies:{types:["menu"],ids:[n]},resolve:(e,t)=>{if(!N(t)||t!==null&&t._id!==n)throw new TypeError("Invalid CMS menu fallback");if(e==null)return{data:t,fallbackFields:["$"]};let o=w(e);if(o._id!==n)throw new b("menu",["menu._id does not match the requested document"]);return{data:o,fallbackFields:[]}}})}var L=["columns","rows"],U=40,v="siteHero.layout.defaulted",q="siteHero.tagline.dropped",F="siteHero.taglines.defaulted",ie=1,S={key:"hero",documentId:"siteHero",documentType:"siteHero",fields:[{name:"heading",label:"Heading",noun:{article:"a",word:"heading"},kind:"single-line",required:!0,minLength:1,maxLength:80,noTrailingFullStop:!0},{name:"intro",label:"Introduction",noun:{article:"an",word:"introduction"},kind:"multi-line",required:!0,minLength:1,maxLength:320}],copy:{currentTitle:"On your site now",editTitle:"Edit and publish",empty:"Your site has no hero text yet. Whatever you publish below becomes its first version."}};function se(n,e){let{article:t,word:o}=n.noun;if(e.length===0)return n.required?`Enter ${t} ${o}.`:null;let r=[...e].length;return r<n.minLength?`Make the ${o} at least ${String(n.minLength)} characters. It is ${String(r)} now.`:r>n.maxLength?`Keep the ${o} to ${String(n.maxLength)} characters or fewer. It is ${String(r)} now.`:e.includes("\u2014")?`The ${o} contains a long dash. Use a comma, a colon or a short dash instead.`:n.kind==="single-line"&&/[\r\n]/.test(e)?`The ${o} must be a single line.`:n.noTrailingFullStop===!0&&e.endsWith(".")?`${o.charAt(0).toUpperCase()}${o.slice(1)}s on your site do not end with a full stop. Remove the last full stop.`:null}function C(n,e){let t={},o={};for(let r of n.fields){let i=Object.hasOwn(e,r.name)?e[r.name]:void 0,d=typeof i=="string"?i.trim():"",l=se(r,d);Object.defineProperty(l===null?t:o,r.name,{value:l??d,enumerable:!0})}return Object.keys(o).length>0?{ok:!1,errors:o}:{ok:!0,value:t}}function Y(n){if(!Array.isArray(n))return{ok:!1,error:"Enter a list of taglines."};let e=S.fields[0];if(!e)throw new TypeError("Missing siteHero heading definition");let t={...e,name:"text",noun:{article:"a",word:"tagline"},maxLength:U},o=[],r=[],i=new Set;for(let[d,l]of n.entries()){if(!l||typeof l!="object"||Array.isArray(l)){r.push({index:d,error:"Enter a key and text for each tagline."});continue}let f=l,y=Object.hasOwn(f,"key")?f.key:void 0;if(typeof y!="string"||!/^[a-z][a-z0-9_-]{0,31}$/.test(y)){r.push({index:d,error:"Use a lowercase key of 1 to 32 letters, numbers, short dashes or underscores, starting with a letter."});continue}if(i.has(y)){r.push({index:d,error:"Use each tagline key only once."});continue}let u=C({...S,fields:[t]},f);if(!u.ok){r.push({index:d,error:u.errors.text??"Invalid tagline."});continue}let p=u.value.text??"";if((p.match(/\p{L}/gu)?.length??0)>=2&&!/\p{Ll}/u.test(p)){r.push({index:d,error:"Use sentence case for the tagline, rather than all capitals."});continue}i.add(y),o.push({key:y,text:p})}return{ok:!0,value:o,dropped:r}}function z(n){let e=Y(n);if(!e.ok)return e;let t=e.dropped[0];return t?{ok:!1,error:t.error}:{ok:!0,value:e.value}}function P(n){return L.some(e=>n===e)}function B(n,e){let t=C(S,e),o=z(e.taglines??[]);if(!t.ok||!o.ok||e.layout!==void 0&&!P(e.layout))throw new TypeError("Invalid siteHero fallback");let r={heading:t.value.heading??"",intro:t.value.intro??"",layout:e.layout??"columns",taglines:o.value};if(n===null||typeof n!="object"||Array.isArray(n))return{data:r,fallbackFields:["$"]};let i=n,d=C(S,i),l=d.ok?[]:Object.keys(d.errors);for(let a of S.fields)if(!l.includes(a.name)){let k=d.ok?d.value[a.name]:i[a.name];typeof k=="string"&&(a.name==="heading"||a.name==="intro")&&(r[a.name]=k.trim())}let f=Object.hasOwn(i,"layout")?i.layout:void 0,y=[];P(f)?r.layout=f:(r.layout="columns",l.push("layout"),y.push(v));let u=Y(Object.hasOwn(i,"taglines")?i.taglines:void 0);if(u.ok){r.taglines=u.value;for(let{index:a}of u.dropped)l.push(`taglines[${String(a)}]`);u.dropped.length>0&&y.push(q)}else l.push("taglines"),y.push(F);let p=[...S.fields.map(a=>a.name),"layout","taglines"].every(a=>l.includes(a));return{data:r,fallbackFields:p?["$"]:l,...y.length>0?{warnings:y}:{}}}function ae(){return T({name:"siteHero.v1",query:'*[_id == $id && _type == "siteHero"][0]{heading,intro,layout,taglines}',params:{id:"siteHero"},dependencies:{types:["siteHero"],ids:["siteHero"]},resolve:B})}export{ie as CMS_CONTRACT_VERSION,O as MENU_DECORATIONS,A as MENU_LAYOUTS,E as MENU_LAYOUT_DEFAULTS,S as SITE_HERO,L as SITE_HERO_LAYOUTS,v as SITE_HERO_LAYOUT_WARNING,F as SITE_HERO_TAGLINES_DEFAULTED_WARNING,q as SITE_HERO_TAGLINE_DROPPED_WARNING,U as SITE_HERO_TAGLINE_MAX_LENGTH,x as cmsTags,T as defineCmsQuery,re as menuQuery,J as menuTags,w as parseMenuDocument,B as parseSiteHero,ae as siteHeroQuery,z as validateSiteHeroTaglines,C as validateTextDocument};
2
6
  //# sourceMappingURL=index.mjs.map