@weatherboard/cms 0.5.0 → 0.7.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.
- package/README.md +117 -0
- package/dist/contracts/query.d.cts +3 -0
- package/dist/contracts/query.d.mts +3 -0
- package/dist/contracts/query.d.ts +3 -0
- package/dist/index.cjs +5 -1
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.cts +3 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.mjs +5 -1
- package/dist/index.mjs.map +4 -4
- package/dist/next.cjs +5 -1
- package/dist/next.cjs.map +4 -4
- package/dist/next.d.cts +3 -0
- package/dist/next.d.mts +3 -0
- package/dist/next.d.ts +3 -0
- package/dist/next.mjs +5 -1
- package/dist/next.mjs.map +4 -4
- package/dist/portable/menu-options.d.cts +8 -0
- package/dist/portable/menu-options.d.mts +8 -0
- package/dist/portable/menu-options.d.ts +8 -0
- package/dist/portable/menu.d.cts +69 -0
- package/dist/portable/menu.d.mts +69 -0
- package/dist/portable/menu.d.ts +69 -0
- package/dist/portable/sections.d.cts +50 -7
- package/dist/portable/sections.d.mts +50 -7
- package/dist/portable/sections.d.ts +50 -7
- package/dist/portable/site-content.d.cts +41 -10
- package/dist/portable/site-content.d.mts +41 -10
- package/dist/portable/site-content.d.ts +41 -10
- package/dist/sanity.cjs +1 -1
- package/dist/sanity.cjs.map +2 -2
- package/dist/sanity.mjs +1 -1
- package/dist/sanity.mjs.map +2 -2
- package/dist/server.cjs +5 -1
- package/dist/server.cjs.map +4 -4
- package/dist/server.d.cts +3 -0
- package/dist/server.d.mts +3 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.mjs +5 -1
- package/dist/server.mjs.map +4 -4
- package/dist/site-content.cjs +10 -3
- package/dist/site-content.cjs.map +4 -4
- package/dist/site-content.d.cts +2 -2
- package/dist/site-content.d.mts +2 -2
- package/dist/site-content.d.ts +2 -2
- package/dist/site-content.mjs +10 -3
- package/dist/site-content.mjs.map +4 -4
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -79,6 +79,9 @@ optional `page.sections[]` that `@weatherboard/sanity-schema-base` declares
|
|
|
79
79
|
| `faqBlock` (items `faqItem`) | `faq` | HeadingList | `beside` |
|
|
80
80
|
| `galleryBlock` | `gallery` | StaggerRow | `staggered` |
|
|
81
81
|
| `contactBlock` | `contact` | Split | `media-end` |
|
|
82
|
+
| `textItemsBlock` | `text_items` | StaggerRow | `staggered` |
|
|
83
|
+
| `stepsBlock` | `steps` | HeadingList, numbered | `beside` |
|
|
84
|
+
| `linkListBlock` | `link_list` | HeadingList, page links | `beside` |
|
|
82
85
|
|
|
83
86
|
The four home kinds read exactly as they do on the home page. The new kinds
|
|
84
87
|
return every key, `null` where there is nothing, with images as
|
|
@@ -122,6 +125,120 @@ The warnings travel in the page data, not in the server reader's
|
|
|
122
125
|
|
|
123
126
|
0.3.0 is an additive minor under the pilot semver policy: a new reader kind.
|
|
124
127
|
|
|
128
|
+
### Schema extension (0.7.0)
|
|
129
|
+
|
|
130
|
+
Pages may supply `titleTail`; media sections may omit a photo. FAQ headings
|
|
131
|
+
may be absent, and answers can use `faqAnswer.content` Portable Text with links.
|
|
132
|
+
The reader also accepts saved plain string or `copyParagraph` answers, so no
|
|
133
|
+
content migration is needed. Rich FAQ answers carry an explicit rich body so
|
|
134
|
+
links render as links. Text-only bodies remain Markdown strings; bodies with
|
|
135
|
+
tables return ordered structured blocks and rows whose cells contain Portable
|
|
136
|
+
Text spans with marks and link annotations. The site renders the first row as
|
|
137
|
+
a header without parsing cell text as Markdown. Legacy string cells become
|
|
138
|
+
unmarked spans. Empty cells
|
|
139
|
+
and ragged rows are refused. A home
|
|
140
|
+
page may omit `hero.headline` when its site uses the separately validated
|
|
141
|
+
`siteHero` heading; in that case the home composition's `hero` contains that heading.
|
|
142
|
+
An explicitly supplied blank headline is refused.
|
|
143
|
+
|
|
144
|
+
The three new block kinds above read from `page.sections`. `linkListBlock`
|
|
145
|
+
references pages; the page queries project each target's title and slug.
|
|
146
|
+
The reader forms links as `/pages/<slug>/`, matching the shared action
|
|
147
|
+
contract's page path.
|
|
148
|
+
The existing `page` type dependency and site `typeToTags` entry cover both
|
|
149
|
+
the containing page and linked page updates. There is no new document type
|
|
150
|
+
to add to the tag map. Seasonal tiles remain in A-2258's scope.
|
|
151
|
+
|
|
152
|
+
## Food and drink menus (0.6.0)
|
|
153
|
+
|
|
154
|
+
0.6.0 is an additive minor: a new reader kind. `menuBlock` now reads as
|
|
155
|
+
`{ kind: "menu", layout, decoration, menu }` inside `PageContent.sections`.
|
|
156
|
+
Both page queries dereference `menu->{...}` with the saved menu fields.
|
|
157
|
+
`MENU_LAYOUTS` (`stacked`, `columns`), `MENU_DECORATIONS` (`none`, `playful`)
|
|
158
|
+
and `MENU_LAYOUT_DEFAULTS` (`stacked`, `none`) are separate from composition
|
|
159
|
+
layout lists. Missing or unknown choices use these defaults with
|
|
160
|
+
`section.layout.defaulted` at the layout or decoration path.
|
|
161
|
+
|
|
162
|
+
A missing, dangling, draft-only or release-version reference skips that section
|
|
163
|
+
with `section.menu.unavailable` and its `where` path. Other page sections still
|
|
164
|
+
read. Genuinely unknown section types still record `section.type.unknown`.
|
|
165
|
+
Malformed menu fields throw `MalformedContentError` naming their saved path,
|
|
166
|
+
including the section's path for referenced menus. Warnings never carry copy.
|
|
167
|
+
|
|
168
|
+
`menuQuery(id)`, `parseMenuDocument(raw)`, `menuTags(scope, id?)` and the menu
|
|
169
|
+
types are exported from the pure root, `/server` and `/next`. A standalone
|
|
170
|
+
query selects a published `menu` by id and records type and id dependencies.
|
|
171
|
+
The Sanity adapter uses the published perspective. Other transports supplied to
|
|
172
|
+
`createSiteContentReader` must also select published content.
|
|
173
|
+
|
|
174
|
+
`MenuDocument` is CMS-owned saved data, structurally compatible with the
|
|
175
|
+
schema-base mapper: `_type: "menu"` and array `_key` identities survive.
|
|
176
|
+
Other Sanity system fields are dropped except `_id`, `_rev` and `_updatedAt`.
|
|
177
|
+
`_updatedAt` remains the exact published update date; use it for the displayed
|
|
178
|
+
last-updated date, including during an outage. Lists and copy retain their
|
|
179
|
+
order and text. Sanity's omitted/null empty lists become `[]`; omitted/null
|
|
180
|
+
availability becomes `available`. Optional null text is omitted. Money must
|
|
181
|
+
have a whole non-negative safe amount and a three-letter currency code.
|
|
182
|
+
The site maps this document with `menuDocumentToContract` and validates business
|
|
183
|
+
constraints there, including recognised currencies, dietary labels, identity
|
|
184
|
+
uniqueness and currency consistency. `signOff` passes through untouched as
|
|
185
|
+
`unknown` plain JSON data: the site checks its shape and uses the contract's `isLive` to decide
|
|
186
|
+
whether the exact content is approved. This reader never grants approval.
|
|
187
|
+
|
|
188
|
+
Menu parsing accepts plain JSON data as Sanity returns it. It snapshots each
|
|
189
|
+
own data property once before checking fields and builds the result only from
|
|
190
|
+
that snapshot, including an unchanged copy of the opaque sign-off data.
|
|
191
|
+
Accessors are rejected without invoking their getters. Non-plain prototypes,
|
|
192
|
+
symbol keys, sparse arrays, non-finite numbers, undefined values and cycles
|
|
193
|
+
are rejected with a named path. Proxy reflection failures also become
|
|
194
|
+
`MalformedContentError`; ordinary Proxy get traps are never invoked. Portable
|
|
195
|
+
JavaScript cannot identify every transparent Proxy: a Proxy that supplies data
|
|
196
|
+
descriptors is validated solely from the captured descriptor values, never
|
|
197
|
+
from a later caller read. The returned objects share no caller-owned data.
|
|
198
|
+
|
|
199
|
+
CMS has no runtime dependency on the unpublished menu or schema packages.
|
|
200
|
+
Compatibility is exercised with a copied, neutral café saved-shape fixture;
|
|
201
|
+
there is no schema devDependency or menu test-fixture import. Publication tests
|
|
202
|
+
resolve imports in source, all eight entry bundles and their build input paths,
|
|
203
|
+
including relative imports into either forbidden package root and type specifiers.
|
|
204
|
+
Type-only test imports are refused too because the copied-fixture option was used.
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
import { menuQuery, menuTags } from '@weatherboard/cms';
|
|
208
|
+
import { createNextCmsReader, createRevalidateRoute } from '@weatherboard/cms/next';
|
|
209
|
+
|
|
210
|
+
// adapter and lastPublishedMenu come from the site's existing CMS configuration
|
|
211
|
+
// and retained published snapshot. No sample menu is supplied on failure.
|
|
212
|
+
const reader = createNextCmsReader({ adapter });
|
|
213
|
+
const result = await reader.read(menuQuery(menuId), { fallback: lastPublishedMenu });
|
|
214
|
+
const tags = menuTags(adapter.scope, menuId);
|
|
215
|
+
const route = createRevalidateRoute({
|
|
216
|
+
scope: adapter.scope,
|
|
217
|
+
typeToTags: { page: ['page'], menu: ['menu'] },
|
|
218
|
+
});
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
`menuTags` follows `cmsTags`: `cms:<scope>:type:menu` plus, when an id is
|
|
222
|
+
supplied, `cms:<scope>:id:<id>`. Existing tags are unchanged. Page queries now
|
|
223
|
+
depend on both `page` and `menu`, so a menu webhook invalidates referencing page
|
|
224
|
+
reads too. Add `menu: ['menu']` to the site's existing `typeToTags` mapping;
|
|
225
|
+
retain its other entries. The webhook's existing id invalidation also covers
|
|
226
|
+
standalone menu reads. Keep the adapter's hourly cache policy.
|
|
227
|
+
|
|
228
|
+
**Stale fallback requires a host-retained snapshot.** The existing runtime
|
|
229
|
+
validates the supplied fallback before I/O and returns it on network, timeout,
|
|
230
|
+
upstream, missing-document or malformed-read failures. Tests first read a good
|
|
231
|
+
published menu/page, supply that result as the next fallback, then fail the
|
|
232
|
+
read and check the content and original `_updatedAt`. Never replace this with
|
|
233
|
+
sample content or the current clock. `createCmsReader` does not store last-good
|
|
234
|
+
content itself; the host retains it using its existing persistence/cache path.
|
|
235
|
+
Plain fetch has no persistent cache. A successful page read with an unavailable
|
|
236
|
+
menu deliberately skips the section; it cannot recover an individual menu from
|
|
237
|
+
a previous page snapshot. Per-reference last-good recovery is a runtime gap,
|
|
238
|
+
and this release adds no cache layer. The legacy `createSiteContentReader`
|
|
239
|
+
throws read failures and has no fallback option; use the runtime query API for
|
|
240
|
+
the documented fallback behavior.
|
|
241
|
+
|
|
125
242
|
## Schema and release delivery
|
|
126
243
|
|
|
127
244
|
`@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
|
|
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:()=>z,MENU_DECORATIONS:()=>E,MENU_LAYOUTS:()=>A,MENU_LAYOUT_DEFAULTS:()=>C,SITE_HERO:()=>g,SITE_HERO_LAYOUTS:()=>R,SITE_HERO_LAYOUT_WARNING:()=>D,SITE_HERO_TAGLINES_DEFAULTED_WARNING:()=>j,SITE_HERO_TAGLINE_DROPPED_WARNING:()=>N,SITE_HERO_TAGLINE_MAX_LENGTH:()=>M,cmsTags:()=>O,defineCmsQuery:()=>_,menuQuery:()=>K,menuTags:()=>U,parseMenuDocument:()=>$,parseSiteHero:()=>P,siteHeroQuery:()=>G,validateSiteHeroTaglines:()=>H,validateTextDocument:()=>S});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 A=["stacked","columns"],E=["none","playful"],C={layout:"stacked",decoration:"none"},x=`_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 O(n,{types:["menu"],...e===void 0?{}:{ids:[e]}})}function s(n,e){throw new b("menu",[`${n} ${e}`])}function q(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),a=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}`,l;try{l=u==="_id"&&o!==void 0?o:Object.getOwnPropertyDescriptor(n,u)}catch{return s(p,"could not be snapshotted as plain JSON data")}if(!l||!Object.hasOwn(l,"value"))return s(p,"is not a saved data property");if(r&&u==="length"){let T=l.value;if(typeof T!="number"||!Number.isSafeInteger(T)||T<0)return s(p,"is not a saved list length");f=T;continue}if(!l.enumerable||r&&!/^(0|[1-9]\d*)$/.test(u))return s(p,"is not a JSON data property");let w=l.value,V=q(w,p,t);Object.defineProperty(a,u,{value:V,enumerable:!0,writable:!0,configurable:!0}),y++}return r&&(y!==f||a.length!==f)?s(e,"is not a complete saved list"):a}catch(r){if(r instanceof b)throw r;return s(e,"could not be snapshotted as plain JSON data")}finally{t.delete(n)}}function k(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 v(n,e){let t=k(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=k(n,e);return{_key:c(t._key,`${e}._key`),amount:v(t.amount,`${e}.amount`),...m(t,"label",e)}}function ie(n,e){let t=k(n,e);return{_key:c(t._key,`${e}._key`),name:c(t.name,`${e}.name`),amount:v(t.amount,`${e}.amount`)}}function se(n,e){let t=k(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 le(n,e){let t=k(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 ae(n,e){let t=k(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`,le)}}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 $(n,e="menu"){return ce(q(n,e),e)}function ce(n,e){let t=k(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`,ae);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 B(n){if(n===null)return!0;try{return $(n),!0}catch{return!1}}var R=["columns","rows"],M=40,D="siteHero.layout.defaulted",N="siteHero.tagline.dropped",j="siteHero.taglines.defaulted",z=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 de(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 S(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():"",a=de(r,d);Object.defineProperty(a===null?t:o,r.name,{value:a??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=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,a]of n.entries()){if(!a||typeof a!="object"||Array.isArray(a)){r.push({index:d,error:"Enter a key and text for each tagline."});continue}let f=a,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=S({...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=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 F(n){return R.some(e=>n===e)}function P(n,e){let t=S(g,e),o=H(e.taglines??[]);if(!t.ok||!o.ok||e.layout!==void 0&&!F(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=S(g,i),a=d.ok?[]:Object.keys(d.errors);for(let l of g.fields)if(!a.includes(l.name)){let w=d.ok?d.value[l.name]:i[l.name];typeof w=="string"&&(l.name==="heading"||l.name==="intro")&&(r[l.name]=w.trim())}let f=Object.hasOwn(i,"layout")?i.layout:void 0,y=[];F(f)?r.layout=f:(r.layout="columns",a.push("layout"),y.push(D));let u=Y(Object.hasOwn(i,"taglines")?i.taglines:void 0);if(u.ok){r.taglines=u.value;for(let{index:l}of u.dropped)a.push(`taglines[${String(l)}]`);u.dropped.length>0&&y.push(N)}else a.push("taglines"),y.push(j);let p=[...g.fields.map(l=>l.name),"layout","taglines"].every(l=>a.includes(l));return{data:r,fallbackFields:p?["$"]:a,...y.length>0?{warnings:y}:{}}}function G(){return _({name:"siteHero.v1",query:'*[_id == $id && _type == "siteHero"][0]{heading,intro,layout,taglines}',params:{id:"siteHero"},dependencies:{types:["siteHero"],ids:["siteHero"]},resolve:P})}var J="malformed-content",b=class extends Error{code=J;documentId;problems;constructor(e,t){super(`${J}: ${e}: ${t.join("; ")}`),this.name="MalformedContentError",this.documentId=e,this.problems=t}};var Q=`{..., "sections": coalesce(sections[]{..., _type == "menuBlock" => {menu->{${x}}}, _type == "linkListBlock" => {links[]{..., "page": page->{title, "slug": slug.current}}}}, sections)}`,Ce=`*[_type == "page" && defined(slug.current)]|order(slug.current asc)${Q}`,xe=`*[_type == "page" && slug.current == $slug][0]${Q}`;var ye=/^[A-Za-z][A-Za-z0-9_]{0,63}$/,pe=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/,fe=/^[a-z0-9]{6,12}\.[a-z][a-z0-9_-]{0,63}$/;function W(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"||!ye.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"||!pe.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:W(n.dependencies),resolve:n.resolve})}function O(n,e){if(typeof n!="string"||n.length>77||!fe.test(n))throw new TypeError("Invalid CMS scope");let t=W(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 K(n){return _({name:"menu.v1",query:`*[_type == "menu" && _id == $id && !(_id in path("drafts.**")) && !(_id in path("versions.**"))][0]{${x}}`,params:{id:n},dependencies:{types:["menu"],ids:[n]},resolve:(e,t)=>{if(!B(t)||t!==null&&t._id!==n)throw new TypeError("Invalid CMS menu fallback");if(e==null)return{data:t,fallbackFields:["$"]};let o=$(e);if(o._id!==n)throw new b("menu",["menu._id does not match the requested document"]);return{data:o,fallbackFields:[]}}})}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
|
package/dist/index.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/index.ts", "../src/
|
|
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,CACxE,GAAI,CAACA,GAAgB,CAAC,MAAM,QAAQA,EAAa,KAAK,GAAKA,EAAa,MAAM,SAAW,EACvF,MAAM,IAAI,UAAU,yCAAyC,EAE/D,IAAMC,EAAQ,CAAC,GAAGD,EAAa,KAAK,EACpC,QAAWE,KAAQD,EACjB,GAAI,OAAOC,GAAS,UAAY,CAACN,EAAK,KAAKM,CAAI,EAAG,MAAM,IAAI,UAAU,2BAA2B,EAEn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,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", "
|
|
3
|
+
"sources": ["../src/index.ts", "../src/portable/array.ts", "../src/portable/menu-options.ts", "../src/portable/menu.ts", "../src/contracts/text.ts", "../src/portable/site-content.ts", "../src/contracts/query.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", "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", "/**\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 missing home headline\n * uses siteHero only when the home document explicitly selects it and that\n * document supplies a valid heading. Otherwise the home page is refused.\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 rich body content).\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 { SITE_HERO, validateTextDocument } from \"../contracts/text.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 RichInline = {\n readonly children: readonly { readonly text: string; readonly marks: readonly string[] }[];\n readonly markDefs: readonly { readonly key: string; readonly href: string }[];\n};\nexport type RichBodyPart =\n | { readonly kind: \"block\"; readonly style: \"normal\" | \"h2\" | \"h3\" | \"blockquote\"; readonly listItem: \"bullet\" | \"number\" | null; readonly level: number; readonly content: RichInline }\n | { readonly kind: \"heading\"; readonly text: string }\n | { readonly kind: \"table\"; readonly rows: readonly (readonly RichInline[])[] };\nexport type RichBody = string | readonly RichBodyPart[];\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 tail?: CopyInput | null;\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 image?: string | null;\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 /** Campaign text as Markdown, or structured blocks and tables when it contains a table. */\n readonly body: RichBody;\n readonly campaign: CampaignState;\n readonly proposedCopy: readonly ProposedCopy[];\n};\n\nexport type PageContent = {\n readonly slug: string;\n readonly title: string;\n readonly titleTail?: string;\n readonly composition: CompositionInput;\n readonly body: RichBody;\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 rich body content\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 * Text-only input remains a Markdown string. Input with a table produces\n * ordered structured blocks and cells that never enter a Markdown parser.\n */\nexport function portableTextToMarkdown(value: unknown): RichBody {\n const reading = new Reading();\n const markdown = richTextToBody(value, \"body\", reading);\n if (reading.problems.length > 0) throw new MalformedContentError(\"body\", reading.problems);\n return markdown;\n}\n\nfunction richTextToBody(value: unknown, path: string, reading: Reading): RichBody {\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 if (value.some((member) => member !== null && typeof member === \"object\" && !Array.isArray(member) && (member as Raw)[\"_type\"] === \"portableTable\")) {\n return richTextToParts(value, path, reading);\n }\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\nfunction bodyText(body: RichBody): string {\n return typeof body === \"string\" ? body : body.map((part) => part.kind === \"heading\" ? part.text\n : part.kind === \"block\" ? part.content.children.map((child) => child.text).join(\"\")\n : part.rows.map((row) => row.map((cell) => cell.children.map((child) => child.text).join(\"\")).join(\" \")).join(\"\\n\")).join(\"\\n\\n\");\n}\n\nfunction inlineFromBlock(block: Raw, path: string, reading: Reading): RichInline {\n const rawDefs = Array.isArray(block[\"markDefs\"]) ? block[\"markDefs\"] as unknown[] : [];\n if (!reading.dense(rawDefs, `${path}.markDefs`)) return { children: [], markDefs: [] };\n const markDefs: { key: string; href: string }[] = [];\n rawDefs.forEach((entry, index) => {\n const def = reading.object(entry, `${path}.markDefs[${String(index)}]`);\n if (def === null) return;\n if (def[\"_type\"] !== \"link\" || typeof def[\"_key\"] !== \"string\" || typeof def[\"href\"] !== \"string\") {\n reading.fail(`${path}.markDefs[${String(index)}]`, \"is not a link annotation\");\n return;\n }\n markDefs.push({ key: def[\"_key\"], href: def[\"href\"] });\n });\n const rawChildren = block[\"children\"];\n if (!Array.isArray(rawChildren) || !reading.dense(rawChildren, `${path}.children`)) {\n reading.fail(`${path}.children`, \"needs text spans\");\n return { children: [], markDefs };\n }\n const children: { text: string; marks: string[] }[] = [];\n rawChildren.forEach((entry, index) => {\n const at = `${path}.children[${String(index)}]`;\n const span = reading.object(entry, at);\n if (span === null) return;\n if (span[\"_type\"] !== \"span\" || typeof span[\"text\"] !== \"string\") {\n reading.fail(at, \"is not a text span\");\n return;\n }\n const marks = span[\"marks\"] === undefined ? [] : span[\"marks\"];\n if (!Array.isArray(marks) || !reading.dense(marks, `${at}.marks`) || marks.some((mark) => typeof mark !== \"string\"\n || (![\"strong\", \"em\", \"code\"].includes(mark) && !markDefs.some((def) => def.key === mark)))) {\n reading.fail(`${at}.marks`, \"contains an unsupported mark\");\n return;\n }\n children.push({ text: span[\"text\"], marks });\n });\n return { children, markDefs };\n}\n\nfunction richTextToParts(value: unknown[], path: string, reading: Reading): RichBodyPart[] {\n const parts: RichBodyPart[] = [];\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\"] === \"portableTable\") {\n parts.push(tableToData(block, at, reading));\n return;\n }\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 style = block[\"style\"] ?? \"normal\";\n if (style !== \"normal\" && style !== \"h2\" && style !== \"h3\" && style !== \"blockquote\") {\n reading.fail(`${at}.style`, `is ${JSON.stringify(style)}, which the schema does not offer`);\n return;\n }\n const listItem = block[\"listItem\"];\n const level = typeof block[\"level\"] === \"number\" && block[\"level\"] > 1 ? block[\"level\"] : 1;\n parts.push({ kind: \"block\", style, listItem: listItem === \"bullet\" || listItem === \"number\" ? listItem : null,\n level, content: inlineFromBlock(block, at, reading) });\n });\n return parts;\n}\n\nfunction tableToData(table: Raw, path: string, reading: Reading): Extract<RichBodyPart, { kind: \"table\" }> {\n const rows = table[\"rows\"];\n if (!Array.isArray(rows) || rows.length === 0 || !reading.dense(rows, `${path}.rows`)) {\n reading.fail(`${path}.rows`, \"needs at least one row\");\n return { kind: \"table\", rows: [] };\n }\n let width = 0;\n const parsedRows: RichInline[][] = [];\n rows.forEach((entry, index) => {\n const at = `${path}.rows[${String(index)}]`;\n const row = reading.object(entry, at);\n if (row === null) return;\n const cells = row[\"cells\"];\n if (!Array.isArray(cells) || cells.length === 0 || !reading.dense(cells, `${at}.cells`)) {\n reading.fail(`${at}.cells`, \"needs at least one cell\");\n return;\n }\n if (index === 0) width = cells.length;\n if (cells.length !== width) reading.fail(`${at}.cells`, \"has a different number of cells\");\n const parsedCells = cells.map((cell, cellIndex) => {\n const cat = `${at}.cells[${String(cellIndex)}]`;\n const inline = typeof cell === \"string\"\n ? { children: [{ text: cell, marks: [] }], markDefs: [] }\n : (() => {\n const rawCell = reading.object(cell, cat);\n if (rawCell === null) return { children: [], markDefs: [] };\n if (rawCell[\"_type\"] !== \"block\" || (rawCell[\"style\"] !== undefined && rawCell[\"style\"] !== \"normal\") || rawCell[\"listItem\"] !== undefined) {\n reading.fail(cat, \"is not an inline text block\");\n return { children: [], markDefs: [] };\n }\n return inlineFromBlock(rawCell, cat, reading);\n })();\n if (inline.children.map((child) => child.text).join(\"\").trim() === \"\") reading.fail(cat, \"is empty or not text\");\n return inline;\n });\n parsedRows.push(parsedCells);\n });\n return { kind: \"table\", rows: parsedRows };\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 source = doc[\"heroSource\"] ?? \"homePage\";\n if (source !== \"homePage\" && source !== \"siteHero\") reading.fail(\"heroSource\", \"must be homePage or siteHero\");\n let heading = rawHero[\"headline\"] === undefined ? null : reading.requiredCopy(rawHero[\"headline\"], \"hero.headline\");\n if (heading === null && rawHero[\"headline\"] === undefined && source === \"siteHero\") {\n const siteHero = doc[\"_siteHero\"];\n if (siteHero !== null && typeof siteHero === \"object\" && !Array.isArray(siteHero)) {\n const headingField = SITE_HERO.fields.find((field) => field.name === \"heading\");\n if (headingField === undefined) throw new TypeError(\"Missing siteHero heading definition\");\n const validated = validateTextDocument({ ...SITE_HERO, fields: [headingField] }, siteHero as Record<string, unknown>);\n if (validated.ok) heading = validated.value.heading ?? null;\n }\n }\n if (heading === null && rawHero[\"headline\"] === undefined) {\n reading.fail(\"hero.headline\", source === \"siteHero\"\n ? \"is missing and siteHero.heading is missing or invalid\"\n : \"is missing; write a headline or select siteHero with a published heading\");\n }\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: RichBody = \"\";\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 = richTextToBody(campaign[\"body\"], \"campaign.body\", reading);\n if (bodyText(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: bodyText(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 = typeof text === \"string\" ? `# ${plain(title)}\\n\\n${text}` : [{ kind: \"heading\", text: plain(title) }, ...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 const image = reading.photo(raw[\"photo\"], `${at}.photo`);\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 ...(raw[\"photo\"] === undefined ? {} : { image }),\n };\n }\n case \"accentBandBlock\": {\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 = reading.photo(raw[\"photo\"], `${at}.photo`);\n if (heading === null || body === null) return null;\n return { kind: \"accent_band\", heading, body, action, image, ...(raw[\"tail\"] === undefined ? {} : { tail }) };\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 const textItems = (value: unknown, path: string, min: number, max: number): { title: CopyInput; body: CopyInput }[] => {\n if (!Array.isArray(value) || value.length < min || value.length > max || !reading.dense(value, path)) {\n reading.fail(path, `needs ${String(min)} to ${String(max)} items`);\n return [];\n }\n const items: { title: CopyInput; body: CopyInput }[] = [];\n value.forEach((member, index) => {\n const item = reading.object(member, `${path}[${String(index)}]`);\n if (item === null) return;\n const atItem = keyed(path, item, index);\n const title = reading.requiredCopy(item[\"title\"], `${atItem}.title`);\n const body = reading.requiredCopy(item[\"body\"], `${atItem}.body`);\n if (title !== null && body !== null) items.push({ title, body });\n });\n return items;\n };\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.copy(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 savedAnswer = item[\"answer\"];\n const answerObject = typeof savedAnswer === \"object\" && savedAnswer !== null && !Array.isArray(savedAnswer) ? savedAnswer as Raw : null;\n const rich = Array.isArray(savedAnswer) || (answerObject !== null && answerObject[\"content\"] !== undefined);\n const answer = rich\n ? { kind: \"rich\" as const, body: richTextToBody(Array.isArray(savedAnswer) ? savedAnswer : answerObject?.[\"content\"],\n Array.isArray(savedAnswer) ? `${iat}.answer` : `${iat}.answer.content`, reading) }\n : typeof savedAnswer === \"string\" ? savedAnswer : reading.requiredCopy(savedAnswer, `${iat}.answer`);\n if (answer === \"\" || (typeof answer === \"object\" && answer !== null && \"kind\" in answer && bodyText(answer.body) === \"\")) reading.fail(`${iat}.answer`, \"is empty\");\n if (question !== null && answer !== null) items.push({ question, answer });\n });\n return { kind: \"faq\", anchor, layout, heading, tail, intro, items };\n }\n case \"textItemsBlock\": {\n const anchor = jumpLinkOf(raw, at, reading);\n const layout = sectionLayout(raw, at, STAGGER_ROW_LAYOUTS, SECTION_LAYOUT_DEFAULTS.StaggerRow, warnings);\n const items = textItems(raw[\"items\"], `${at}.items`, 2, 4);\n return { kind: \"text_items\", anchor, layout, items };\n }\n case \"stepsBlock\": {\n const anchor = jumpLinkOf(raw, at, reading);\n const layout = sectionLayout(raw, at, HEADING_LIST_LAYOUTS, SECTION_LAYOUT_DEFAULTS.HeadingList, warnings);\n const heading = reading.requiredCopy(raw[\"heading\"], `${at}.heading`);\n const intro = reading.requiredCopy(raw[\"intro\"], `${at}.intro`);\n const items = textItems(raw[\"items\"], `${at}.items`, 1, 100);\n return heading === null || intro === null ? null : { kind: \"steps\", anchor, layout, heading, intro, items };\n }\n case \"linkListBlock\": {\n const anchor = jumpLinkOf(raw, at, reading);\n const layout = sectionLayout(raw, at, HEADING_LIST_LAYOUTS, SECTION_LAYOUT_DEFAULTS.HeadingList, warnings);\n const heading = reading.requiredCopy(raw[\"heading\"], `${at}.heading`);\n const tail = reading.copy(raw[\"tail\"], `${at}.tail`);\n const saved = raw[\"links\"];\n if (!Array.isArray(saved) || saved.length === 0 || !reading.dense(saved, `${at}.links`)) return reading.fail(`${at}.links`, \"needs at least one page\");\n const links: { title: string; href: string }[] = [];\n saved.forEach((member, index) => {\n const item = reading.object(member, `${at}.links[${String(index)}]`);\n if (item === null) return;\n const page = reading.object(item[\"page\"], `${at}.links[${String(index)}].page`);\n if (page === null) return;\n const title = reading.optionalString(page[\"title\"], `${at}.links[${String(index)}].page.title`);\n const slug = reading.optionalString(page[\"slug\"], `${at}.links[${String(index)}].page.slug`);\n if (!title || !slug || !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(slug)) reading.fail(`${at}.links[${String(index)}].page`, \"has no readable page title or slug\");\n else links.push({ title, href: `/pages/${slug}/` });\n });\n return heading === null ? null : { kind: \"link_list\", anchor, layout, heading, tail, links };\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 case \"text_items\":\n case \"steps\":\n case \"link_list\":\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 const titleTail = reading.optionalString(doc[\"titleTail\"], \"titleTail\");\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 = richTextToBody(doc[\"body\"], \"body\", reading);\n if (doc[\"bodyCopySource\"] === \"proposed\") reading.proposed.push({ where: \"body\", text: bodyText(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 ...(doc[\"titleTail\"] === undefined ? {} : { titleTail: titleTail ?? \"\" }),\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]`;\n/** One snapshot contains both possible headline sources. */\nexport const HOME_PAGE_WITH_SITE_HERO_QUERY = `*[_id == $id][0]{..., \"_siteHero\": *[_id == \"siteHero\" && _type == \"siteHero\"][0]{heading}}`;\nconst MENU_PAGE_PROJECTION = `{..., \"sections\": coalesce(sections[]{..., _type == \"menuBlock\" => {menu->{${MENU_DOCUMENT_PROJECTION}}}, _type == \"linkListBlock\" => {links[]{..., \"page\": page->{title, \"slug\": slug.current}}}}, 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_WITH_SITE_HERO_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_WITH_SITE_HERO_QUERY, params: { id: READER_HOME_PAGE_ID },\n dependencies: { types: [\"homePage\", \"siteHero\"], ids: [READER_HOME_PAGE_ID, \"siteHero\"] },\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"],
|
|
5
|
+
"mappings": "+aAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,0BAAAE,EAAA,qBAAAC,EAAA,iBAAAC,EAAA,yBAAAC,EAAA,cAAAC,EAAA,sBAAAC,EAAA,6BAAAC,EAAA,yCAAAC,EAAA,sCAAAC,EAAA,iCAAAC,EAAA,YAAAC,EAAA,mBAAAC,EAAA,cAAAC,EAAA,aAAAC,EAAA,sBAAAC,EAAA,kBAAAC,EAAA,kBAAAC,EAAA,6BAAAC,EAAA,yBAAAC,IAAA,eAAAC,GAAArB,ICCO,SAASsB,EAAaC,EAAoC,CAC/D,GAAI,CA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H,IAAML,EAAST,EAAiBC,CAAY,EACtCc,EAAO,CACX,GAAG,CAAC,GAAG,IAAI,IAAIN,EAAO,KAAK,CAAC,EAAE,KAAK,EAAE,IAAKN,GAAS,OAAOW,CAAK,SAASX,CAAI,EAAE,EAC9E,GAAG,CAAC,GAAG,IAAI,IAAIM,EAAO,KAAO,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAKJ,GAAO,OAAOS,CAAK,OAAOT,CAAE,EAAE,CAC9E,EACA,OAAO,OAAO,OAAOU,CAAI,CAC3B,CAGO,SAASC,EAAUX,EAA2C,CACnE,OAAOC,EAAe,CACpB,KAAM,UACN,MAAO,uGAAuGW,CAAwB,IACtI,OAAQ,CAAE,GAAAZ,CAAG,EAAG,aAAc,CAAE,MAAO,CAAC,MAAM,EAAG,IAAK,CAACA,CAAE,CAAE,EAC3D,QAAS,CAACa,EAAKC,IAAa,CAC1B,GAAI,CAACC,EAAkBD,CAAQ,GAAMA,IAAa,MAAQA,EAAS,MAAQd,EAAK,MAAM,IAAI,UAAU,2BAA2B,EAC/H,GAAIa,GAAQ,KAA2B,MAAO,CAAE,KAAMC,EAAU,eAAgB,CAAC,GAAG,CAAE,EACtF,IAAME,EAAOC,EAAkBJ,CAAG,EAClC,GAAIG,EAAK,MAAQhB,EAAI,MAAM,IAAIkB,EAAsB,OAAQ,CAAC,gDAAgD,CAAC,EAC/G,MAAO,CAAE,KAAAF,EAAM,eAAgB,CAAC,CAAE,CACpC,CACF,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", "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", "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"]
|
|
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";
|