@weatherboard/cms 0.8.0 → 0.9.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 +8 -4
- package/dist/next.cjs +4 -4
- package/dist/next.cjs.map +3 -3
- package/dist/next.mjs +4 -4
- package/dist/next.mjs.map +3 -3
- package/dist/runtime/site-readers.d.cts +7 -1
- package/dist/runtime/site-readers.d.mts +7 -1
- package/dist/runtime/site-readers.d.ts +7 -1
- package/dist/runtime/test-fixtures/saved-documents.d.cts +4 -0
- package/dist/runtime/test-fixtures/saved-documents.d.mts +4 -0
- package/dist/runtime/test-fixtures/saved-documents.d.ts +4 -0
- package/dist/server.cjs +3 -3
- package/dist/server.cjs.map +3 -3
- package/dist/server.mjs +2 -2
- package/dist/server.mjs.map +3 -3
- package/package.json +1 -1
package/dist/server.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import"server-only";function M(e){if(!Array.isArray(e))return!1;for(let n=0;n<e.
|
|
|
2
2
|
variants[]{_key, label, note, sections[]{_key, title, service, items[]{
|
|
3
3
|
_key, name, description, priceNote, dietary, allergenNote, availability,
|
|
4
4
|
prices[]{_key, label, amount{minor, currency}}, extras[]{_key, name, amount{minor, currency}}
|
|
5
|
-
}}}`;function W(e,n){return b(e,{types:["menu"],...n===void 0?{}:{ids:[n]}})}function d(e,n){throw new w("menu",[`${e} ${n}`])}function j(e,n,t=new Set,o){if(e===null||typeof e=="string"||typeof e=="boolean"||typeof e=="number"&&Number.isFinite(e))return e;if(typeof e!="object"||e===null)return d(n,"is not plain JSON data");try{if(t.has(e))return d(n,"is not acyclic JSON data");let r=Array.isArray(e),s=Object.getPrototypeOf(e);if(r?s!==Array.prototype:s!==Object.prototype&&s!==null)return d(n,"is not an ordinary saved object");t.add(e);let a=Reflect.ownKeys(e),k=r?[]:{},y=0,p=0;for(let i of a){if(typeof i!="string")return d(n,"has a symbol key");let u=r&&i!=="length"?`${n}[${i}]`:`${n}.${i}`,c;try{c=i==="_id"&&o!==void 0?o:Object.getOwnPropertyDescriptor(e,i)}catch{return d(u,"could not be snapshotted as plain JSON data")}if(!c||!Object.hasOwn(c,"value"))return d(u,"is not a saved data property");if(r&&i==="length"){let $=c.value;if(typeof $!="number"||!Number.isSafeInteger($)||$<0)return d(u,"is not a saved list length");y=$;continue}if(!c.enumerable||r&&!/^(0|[1-9]\d*)$/.test(i))return d(u,"is not a JSON data property");let l=c.value,g=j(l,u,t);Object.defineProperty(k,i,{value:g,enumerable:!0,writable:!0,configurable:!0}),p++}return r&&(p!==y||k.length!==y)?d(n,"is not a complete saved list"):k}catch(r){if(r instanceof w)throw r;return d(n,"could not be snapshotted as plain JSON data")}finally{t.delete(e)}}function C(e,n){return e===null||typeof e!="object"||Array.isArray(e)||Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null?d(n,"is not an ordinary saved object"):e}function f(e,n,t=!0){return typeof e!="string"||t&&e.trim()===""?d(n,"is not saved text"):e}function S(e,n,t){return e[n]===void 0||e[n]===null?{}:{[n]:f(e[n],`${t}.${n}`,!1)}}function _(e,n,t){return e==null?[]:M(e)?e.map((o,r)=>t(o,`${n}[${String(r)}]`)):d(n,"is not a complete saved list")}function L(e,n){let t=C(e,n);if(typeof t.minor!="number"||!Number.isSafeInteger(t.minor)||t.minor<0)return d(`${n}.minor`,"is not a whole non-negative safe amount");let o=f(t.currency,`${n}.currency`);return/^[A-Z]{3}$/.test(o)?{minor:t.minor,currency:o}:d(`${n}.currency`,"is not a three-letter currency code")}function Y(e,n){let t=C(e,n);return{_key:f(t._key,`${n}._key`),amount:L(t.amount,`${n}.amount`),...S(t,"label",n)}}function G(e,n){let t=C(e,n);return{_key:f(t._key,`${n}._key`),name:f(t.name,`${n}.name`),amount:L(t.amount,`${n}.amount`)}}function K(e,n){let t=C(e,n),o=t.availability??"available";return o!=="available"&&o!=="sold-out"&&o!=="hidden"?d(`${n}.availability`,"is not an availability choice"):{_key:f(t._key,`${n}._key`),name:f(t.name,`${n}.name`),...S(t,"description",n),...S(t,"priceNote",n),...S(t,"allergenNote",n),prices:_(t.prices,`${n}.prices`,Y),extras:_(t.extras,`${n}.extras`,G),dietary:_(t.dietary,`${n}.dietary`,f),availability:o}}function X(e,n){let t=C(e,n);return{_key:f(t._key,`${n}._key`),title:f(t.title,`${n}.title`),...S(t,"service",n),items:_(t.items,`${n}.items`,K)}}function ee(e,n){let t=C(e,n);return{_key:f(t._key,`${n}._key`),label:f(t.label,`${n}.label`),...S(t,"note",n),sections:_(t.sections,`${n}.sections`,X)}}function ne(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;let n=e._id;return typeof n=="string"&&n.trim()!==""&&!/^(drafts|versions)\./.test(n)}function x(e,n="menu"){return te(j(e,n),n)}function te(e,n){let t=C(e,n);if(t._type!=="menu")return d(`${n}._type`,"is not menu");if(!ne(t))return d(`${n}._id`,"is not a published menu identity");let o=f(t._updatedAt,`${n}._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 d(`${n}._updatedAt`,"is not an update date");let r=_(t.variants,`${n}.variants`,ee);return r.length===0?d(`${n}.variants`,"has no menu choices"):{_type:"menu",_id:f(t._id,`${n}._id`),_rev:f(t._rev,`${n}._rev`),_updatedAt:o,title:f(t.title,`${n}.title`),locationKeys:_(t.locationKeys,`${n}.locationKeys`,f),variants:r,...S(t,"note",n),...Object.hasOwn(t,"signOff")?{signOff:t.signOff}:{}}}function P(e){if(e===null)return!0;try{return x(e),!0}catch{return!1}}var N="malformed-content",w=class extends Error{code=N;documentId;problems;constructor(n,t){super(`${N}: ${n}: ${t.join("; ")}`),this.name="MalformedContentError",this.documentId=n,this.problems=t}};var v=`{..., "sections": coalesce(sections[]{..., _type == "menuBlock" => {menu->{${R}}}, _type == "linkListBlock" => {links[]{..., "page": page->{title, "slug": slug.current}}}}, sections)}`,De=`*[_type == "page" && defined(slug.current)]|order(slug.current asc)${v}`,Me=`*[_type == "page" && slug.current == $slug][0]${v}`;var oe=/^[A-Za-z][A-Za-z0-9_]{0,63}$/,re=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/,se=/^[a-z0-9]{6,12}\.[a-z][a-z0-9_-]{0,63}$/;function F(e){if(!e||!Array.isArray(e.types)||e.types.length===0)throw new TypeError("CMS dependencies require document types");let n=[...e.types];for(let o of n)if(typeof o!="string"||!oe.test(o))throw new TypeError("Invalid CMS document type");if(e.ids!==void 0&&!Array.isArray(e.ids))throw new TypeError("Invalid CMS document IDs");let t=e.ids===void 0?void 0:[...e.ids];for(let o of t??[])if(typeof o!="string"||!re.test(o)||/^(drafts|versions)\./.test(o))throw new TypeError("Invalid CMS document ID");if(new Set(n).size+new Set(t).size>128)throw new TypeError("Too many CMS tags");return Object.freeze({types:Object.freeze(n),...t===void 0?{}:{ids:Object.freeze(t)}})}function A(e){if(!e||typeof e.name!="string"||!/^[A-Za-z][A-Za-z0-9_.-]{0,127}$/.test(e.name)||typeof e.query!="string"||e.query.trim()===""||typeof e.resolve!="function")throw new TypeError("Invalid CMS query configuration");let n=e.params;if(!n||typeof n!="object"||Object.getPrototypeOf(n)!==Object.prototype&&Object.getPrototypeOf(n)!==null)throw new TypeError("CMS params must be plain JSON scalars");let t={};for(let o of Reflect.ownKeys(n)){let r=Object.getOwnPropertyDescriptor(n,o);if(typeof o!="string"||!r||!Object.hasOwn(r,"value")||!r.enumerable)throw new TypeError("CMS params must be plain JSON scalars");let s=r.value;if(!(s===null||typeof s=="string"||typeof s=="boolean"||typeof s=="number"&&Number.isFinite(s)))throw new TypeError("CMS params must be plain JSON scalars");Object.defineProperty(t,o,{value:s,enumerable:!0})}return Object.freeze({name:e.name,query:e.query,params:Object.freeze(t),dependencies:F(e.dependencies),resolve:e.resolve})}function b(e,n){if(typeof e!="string"||e.length>77||!se.test(e))throw new TypeError("Invalid CMS scope");let t=F(n),o=[...[...new Set(t.types)].sort().map(r=>`cms:${e}:type:${r}`),...[...new Set(t.ids??[])].sort().map(r=>`cms:${e}:id:${r}`)];return Object.freeze(o)}function ie(e){return A({name:"menu.v1",query:`*[_type == "menu" && _id == $id && !(_id in path("drafts.**")) && !(_id in path("versions.**"))][0]{${R}}`,params:{id:e},dependencies:{types:["menu"],ids:[e]},resolve:(n,t)=>{if(!P(t)||t!==null&&t._id!==e)throw new TypeError("Invalid CMS menu fallback");if(n==null)return{data:t,fallbackFields:["$"]};let o=x(n);if(o._id!==e)throw new w("menu",["menu._id does not match the requested document"]);return{data:o,fallbackFields:[]}}})}function q(e){if(!e||!Object.hasOwn(e,"data")||!Array.isArray(e.fallbackFields)||![...e.fallbackFields].every(n=>typeof n=="string"&&(n==="$"||/^[A-Za-z][A-Za-z0-9_.[\]-]{0,127}$/.test(n))))throw new TypeError("Invalid CMS resolution");if(e.warnings!==void 0&&(!Array.isArray(e.warnings)||![...e.warnings].every(n=>n==="siteHero.layout.defaulted"||n==="siteHero.tagline.dropped"||n==="siteHero.taglines.defaulted")))throw new TypeError("Invalid CMS resolution warnings");return{data:e.data,fallbackFields:Object.freeze([...new Set(e.fallbackFields)]),...e.warnings?.length?{warnings:Object.freeze([...new Set(e.warnings)])}:{}}}function le(e){let n=e?.revalidateSeconds??3600;if(!Number.isSafeInteger(n)||n<3600||!e?.adapter||typeof e.adapter.read!="function"||e.onDiagnostic!==void 0&&typeof e.onDiagnostic!="function")throw new TypeError("Invalid CMS reader configuration");let t=e.adapter;b(t.scope,{types:["ScopeValidation"]});let o=r=>{try{e.onDiagnostic?e.onDiagnostic(r):console.warn(JSON.stringify(r))}catch{}};return{async read(r,s){let a,k,y;try{if(a=A(r),y=b(t.scope,a.dependencies),!s||!Object.hasOwn(s,"fallback"))throw new TypeError;k=q(a.resolve(null,s.fallback))}catch{throw new TypeError("Invalid CMS query or fallback configuration")}let p=(c,l,g)=>(o({event:"cms.fallback",query:a.name,reason:c,fields:["$"],...l===void 0?{}:{status:l},...g?{warnings:g}:{}}),{data:k.data,source:"fallback",fallbackFields:["$"],reason:c,...g?{warnings:g}:{}}),i;try{i=await t.read({name:a.name,query:a.query,params:a.params},{tags:y,revalidateSeconds:n})}catch{return p("network")}if(!i.ok){let l=["configuration","network","timeout","rate-limit","upstream","plan-limit","permission","malformed"].includes(i.reason)?i.reason:"malformed",g=Number.isInteger(i.status)&&(i.status??0)>=100&&(i.status??0)<=599?i.status:void 0;return p(l,g)}if(i.value===null||i.value===void 0)return p("missing");let u;try{u=q(a.resolve(i.value,s.fallback))}catch{return p("malformed")}return u.fallbackFields.includes("$")?{...p("invalid-field",void 0,u.warnings),data:u.data}:u.fallbackFields.length>0?(o({event:"cms.partial-fallback",query:a.name,reason:"invalid-field",fields:u.fallbackFields,...u.warnings?{warnings:u.warnings}:{}}),{...u,source:"mixed",reason:"invalid-field"}):{...u,source:"cms"}}}}var h=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),m=e=>typeof e=="string"&&e.trim()?e.trim():null,ae=(e,n)=>e._type===n&&typeof e._id=="string"&&e._id.length>0&&!/^(drafts|versions)\./.test(e._id),ue=/^\d{4}-\d{2}-\d{2}$/,U=/^([01]\d|2[0-3]):[0-5]\d$/,ce=["mon","tue","wed","thu","fri","sat","sun"];async function de(e,n,t){try{let o=await e.read(n,{fallback:t});return{...o,source:o.source==="cms"?"sanity":o.source}}catch{return{data:t,source:"fallback",fallbackFields:["$"],reason:"configuration"}}}var ye=/^[A-Za-z0-9._+-]{1,64}@[A-Za-z0-9-]{1,63}(?:\.[A-Za-z0-9-]{1,63})*\.[A-Za-z]{2,63}$/;function pe(e){let n=m(e);if(!n)return null;try{let t=new URL(n);return t.protocol==="http:"||t.protocol==="https:"?t.href:null}catch{return null}}function T(e){if(typeof e!="function")throw new TypeError("A client validator is required")}function B(e,n,t){if(T(t),!h(e)||e.status!=="open")return null;let o=m(e.closingDate);if(o!==null&&o<n||t(e)!==null)return null;let r=m(e.title),s=e.location==="Other"?m(e.locationNote):m(e.location);if(!r||!s)return null;let a=m(e.pdfUrl);return{id:String(m(e._id)),title:r,location:s,summary:m(e.summary),pdfUrl:a?.startsWith("https://cdn.sanity.io/files/")?a:null,applyUrl:pe(e.applyUrl),applyEmail:typeof e.applyEmail=="string"&&e.applyEmail.length<=254&&ye.test(e.applyEmail)?e.applyEmail:null}}function H(e,n,t){if(T(t),!Array.isArray(e))throw new TypeError("Sanity returned vacancies that are not a list");return e.map(o=>({value:B(o,n,t),order:h(o)&&typeof o.order=="number"&&Number.isFinite(o.order)?o.order:1e6})).filter(o=>o.value!==null).sort((o,r)=>o.order-r.order||o.value.title.toLowerCase().localeCompare(r.value.title.toLowerCase())).map(o=>o.value)}function fe(e){return b(e,{types:["vacancy"]})}function me(e,n){if(!ue.test(e))throw new TypeError("Invalid calendar date");return T(n),A({name:"vacancy.open.v1",query:'*[_type == "vacancy" && status == "open" && !(_id in path("drafts.**")) && !(_id in path("versions.**")) && (!defined(closingDate) || closingDate >= $today)]|order(coalesce(order, 1000000) asc, lower(title) asc){_id, _type, title, location, locationNote, summary, "pdfUrl": jobDescriptionPdf.asset->url, applyUrl, applyEmail, status, closingDate, order}',params:{today:e},dependencies:{types:["vacancy"]},resolve:(t,o)=>({data:t==null?o:H(t,e,n),fallbackFields:t==null?["$"]:[]})})}var ge=["monday","tuesday","wednesday","thursday","friday","saturday","sunday"],he=/^[a-z0-9]+(?:-[a-z0-9]+)*$/;function D(e){return!h(e)||typeof e._id!="string"||!h(e.slug)||typeof e.slug.current!="string"||!he.test(e.slug.current)||m(e.name)===null||e.addressLines!==void 0&&e.addressLines!==null&&(!Array.isArray(e.addressLines)||Array.from(e.addressLines).some(n=>m(n)===null))||e.postcode!==void 0&&e.postcode!==null&&m(e.postcode)===null||e.coordinates!==void 0&&e.coordinates!==null&&(!h(e.coordinates)||typeof e.coordinates.lat!="number"||!Number.isFinite(e.coordinates.lat)||typeof e.coordinates.lng!="number"||!Number.isFinite(e.coordinates.lng))||e.phone!==void 0&&e.phone!==null&&typeof e.phone!="string"||e.email!==void 0&&e.email!==null&&typeof e.email!="string"?null:{name:m(e.name),slug:e.slug.current,addressLines:e.addressLines==null?e.addressLines:e.addressLines.map(n=>n.trim()),postcode:e.postcode==null?e.postcode:String(e.postcode).trim(),coordinates:e.coordinates==null?e.coordinates:{lat:e.coordinates.lat,lng:e.coordinates.lng},phone:e.phone,email:e.email,hours:e.hours}}function Q(e){if(!h(e))return null;let n={};for(let t of ge){let o=e[t];if(!Array.isArray(o)||!Array.from(o).every(r=>h(r)&&typeof r.opens=="string"&&typeof r.closes=="string"))return null;n[t]=o.map(r=>({opens:r.opens,closes:r.closes}))}return n}function z(e,n,t){T(t);let o=D(e);if(o===null||o.slug!==n.id)return{data:n,fallbackFields:["$"]};let r=Q(o.hours),s={id:n.id,label:o.name,addressLines:o.addressLines??n.addressLines,postcode:o.postcode??n.postcode,geo:o.coordinates==null?n.geo:{latitude:o.coordinates.lat,longitude:o.coordinates.lng},telephone:o.phone===void 0?n.telephone:o.phone,email:o.email===void 0?n.email:o.email,hours:r??n.hours};try{return{data:t(s),fallbackFields:r===null?["hours"]:[]}}catch{if(r!==null)try{return{data:t({...s,hours:n.hours}),fallbackFields:["hours"]}}catch{}return{data:n,fallbackFields:["$"]}}}function V(e,n,t){T(t);let o=D(e);if(o===null||o.slug!==n.id)return{data:n,fallbackFields:["$"]};let r=Q(o.hours),s={...n,label:o.name,address:n.address===null?null:{...n.address,streetAddress:o.addressLines??n.address.streetAddress,postalCode:o.postcode??n.address.postalCode},telephone:o.phone===void 0?n.telephone:o.phone,email:o.email===void 0?n.email:o.email,geo:o.coordinates==null?n.geo:{latitude:o.coordinates.lat,longitude:o.coordinates.lng},hours:r??n.hours};try{return{data:t(s),fallbackFields:r===null?["hours"]:[]}}catch{if(r!==null)try{return{data:t({...s,hours:n.hours}),fallbackFields:["hours"]}}catch{}return{data:n,fallbackFields:["$"]}}}function ke(e){return b(e,{types:["location"]})}function J(e,n){return A({name:e,query:'*[_type == "location" && defined(slug.current) && !(_id in path("drafts.**")) && !(_id in path("versions.**"))]{_id, _type, name, slug, addressLines, postcode, coordinates, phone, email, hours}',params:{},dependencies:{types:["location"]},resolve:(t,o)=>{if(!Array.isArray(t))return{data:o,fallbackFields:["$"]};let r=new Map,s=new Set;for(let y of t){let p=D(y);p!==null&&(r.has(p.slug)?s.add(p.slug):r.set(p.slug,y))}let a=[];return{data:o.map((y,p)=>{let i=r.get(y.id),u=i===void 0||s.has(y.id)?{data:y,fallbackFields:["$"]}:n(i,y);return a.push(...u.fallbackFields.map(c=>c==="$"?`locations[${p}]`:`locations[${p}].${c}`)),u.data}),fallbackFields:o.length>0&&a.length===o.length&&a.every(y=>/^locations\[\d+\]$/.test(y))?["$"]:a}}})}function be(e){return T(e),J("locations.v1",(n,t)=>z(n,t,e))}function $e(e){return T(e),J("locations.business.v1",(n,t)=>V(n,t,e))}function Se(e,n,t){let o=`${e}-${n.normalize("NFKD").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"stop"}`,r=o;for(let s=2;t.has(r);s++)r=`${o}-${s}`;return t.add(r),r}function Z(e,n){if(!h(e)||!ae(e,"schedule")||e._id!=="schedule"||e.timeZone!==n.timeZone||!Array.isArray(e.days)||e.days.length!==7)throw new TypeError("Invalid schedule document");let t=e.days.map((o,r)=>{if(!h(o)||o.day!==ce[r]||typeof o.rest!="boolean"||!Array.isArray(o.stops))throw new TypeError("Invalid schedule day");let s=o.day,a=o.rest,k=o.stops,y=n.days.find(c=>c.day===s),p=new Set(y?.stops.map(c=>c.id)??[]),i=new Set,u=k.map(c=>{if(!h(c))throw new TypeError("Invalid schedule stop");let l=c;if(!m(l.name)||!U.test(String(l.from??""))||!U.test(String(l.to??""))||!m(l.address))throw new TypeError("Invalid schedule stop");let g=y?.stops.find($=>$.name===l.name&&!i.has($.id));return g?(i.add(g.id),{...g,name:String(l.name),from:String(l.from),to:String(l.to),address:String(l.address)}):{id:Se(s,String(l.name),p),name:String(l.name),from:String(l.from),to:String(l.to),address:String(l.address),place:null,postcode:null,notes:null,lat:null,lng:null,coordinateSource:null,approximate:!1,needsConfirmation:null,captured:`${l.name}
|
|
5
|
+
}}}`;function W(e,n){return b(e,{types:["menu"],...n===void 0?{}:{ids:[n]}})}function y(e,n){throw new w("menu",[`${e} ${n}`])}function L(e,n,t=new Set,o){if(e===null||typeof e=="string"||typeof e=="boolean"||typeof e=="number"&&Number.isFinite(e))return e;if(typeof e!="object"||e===null)return y(n,"is not plain JSON data");try{if(t.has(e))return y(n,"is not acyclic JSON data");let r=Array.isArray(e),s=Object.getPrototypeOf(e);if(r?s!==Array.prototype:s!==Object.prototype&&s!==null)return y(n,"is not an ordinary saved object");t.add(e);let a=Reflect.ownKeys(e),g=r?[]:{},u=0,p=0;for(let i of a){if(typeof i!="string")return y(n,"has a symbol key");let c=r&&i!=="length"?`${n}[${i}]`:`${n}.${i}`,d;try{d=i==="_id"&&o!==void 0?o:Object.getOwnPropertyDescriptor(e,i)}catch{return y(c,"could not be snapshotted as plain JSON data")}if(!d||!Object.hasOwn(d,"value"))return y(c,"is not a saved data property");if(r&&i==="length"){let $=d.value;if(typeof $!="number"||!Number.isSafeInteger($)||$<0)return y(c,"is not a saved list length");u=$;continue}if(!d.enumerable||r&&!/^(0|[1-9]\d*)$/.test(i))return y(c,"is not a JSON data property");let l=d.value,h=L(l,c,t);Object.defineProperty(g,i,{value:h,enumerable:!0,writable:!0,configurable:!0}),p++}return r&&(p!==u||g.length!==u)?y(n,"is not a complete saved list"):g}catch(r){if(r instanceof w)throw r;return y(n,"could not be snapshotted as plain JSON data")}finally{t.delete(e)}}function C(e,n){return e===null||typeof e!="object"||Array.isArray(e)||Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null?y(n,"is not an ordinary saved object"):e}function f(e,n,t=!0){return typeof e!="string"||t&&e.trim()===""?y(n,"is not saved text"):e}function S(e,n,t){return e[n]===void 0||e[n]===null?{}:{[n]:f(e[n],`${t}.${n}`,!1)}}function _(e,n,t){return e==null?[]:M(e)?e.map((o,r)=>t(o,`${n}[${String(r)}]`)):y(n,"is not a complete saved list")}function j(e,n){let t=C(e,n);if(typeof t.minor!="number"||!Number.isSafeInteger(t.minor)||t.minor<0)return y(`${n}.minor`,"is not a whole non-negative safe amount");let o=f(t.currency,`${n}.currency`);return/^[A-Z]{3}$/.test(o)?{minor:t.minor,currency:o}:y(`${n}.currency`,"is not a three-letter currency code")}function Y(e,n){let t=C(e,n);return{_key:f(t._key,`${n}._key`),amount:j(t.amount,`${n}.amount`),...S(t,"label",n)}}function G(e,n){let t=C(e,n);return{_key:f(t._key,`${n}._key`),name:f(t.name,`${n}.name`),amount:j(t.amount,`${n}.amount`)}}function K(e,n){let t=C(e,n),o=t.availability??"available";return o!=="available"&&o!=="sold-out"&&o!=="hidden"?y(`${n}.availability`,"is not an availability choice"):{_key:f(t._key,`${n}._key`),name:f(t.name,`${n}.name`),...S(t,"description",n),...S(t,"priceNote",n),...S(t,"allergenNote",n),prices:_(t.prices,`${n}.prices`,Y),extras:_(t.extras,`${n}.extras`,G),dietary:_(t.dietary,`${n}.dietary`,f),availability:o}}function X(e,n){let t=C(e,n);return{_key:f(t._key,`${n}._key`),title:f(t.title,`${n}.title`),...S(t,"service",n),items:_(t.items,`${n}.items`,K)}}function ee(e,n){let t=C(e,n);return{_key:f(t._key,`${n}._key`),label:f(t.label,`${n}.label`),...S(t,"note",n),sections:_(t.sections,`${n}.sections`,X)}}function ne(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;let n=e._id;return typeof n=="string"&&n.trim()!==""&&!/^(drafts|versions)\./.test(n)}function x(e,n="menu"){return te(L(e,n),n)}function te(e,n){let t=C(e,n);if(t._type!=="menu")return y(`${n}._type`,"is not menu");if(!ne(t))return y(`${n}._id`,"is not a published menu identity");let o=f(t._updatedAt,`${n}._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 y(`${n}._updatedAt`,"is not an update date");let r=_(t.variants,`${n}.variants`,ee);return r.length===0?y(`${n}.variants`,"has no menu choices"):{_type:"menu",_id:f(t._id,`${n}._id`),_rev:f(t._rev,`${n}._rev`),_updatedAt:o,title:f(t.title,`${n}.title`),locationKeys:_(t.locationKeys,`${n}.locationKeys`,f),variants:r,...S(t,"note",n),...Object.hasOwn(t,"signOff")?{signOff:t.signOff}:{}}}function P(e){if(e===null)return!0;try{return x(e),!0}catch{return!1}}var N="malformed-content",w=class extends Error{code=N;documentId;problems;constructor(n,t){super(`${N}: ${n}: ${t.join("; ")}`),this.name="MalformedContentError",this.documentId=n,this.problems=t}};var v=`{..., "sections": coalesce(sections[]{..., _type == "menuBlock" => {menu->{${R}}}, _type == "linkListBlock" => {links[]{..., "page": page->{title, "slug": slug.current}}}}, sections)}`,De=`*[_type == "page" && defined(slug.current)]|order(slug.current asc)${v}`,Me=`*[_type == "page" && slug.current == $slug][0]${v}`;var oe=/^[A-Za-z][A-Za-z0-9_]{0,63}$/,re=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/,se=/^[a-z0-9]{6,12}\.[a-z][a-z0-9_-]{0,63}$/;function F(e){if(!e||!Array.isArray(e.types)||e.types.length===0)throw new TypeError("CMS dependencies require document types");let n=[...e.types];for(let o of n)if(typeof o!="string"||!oe.test(o))throw new TypeError("Invalid CMS document type");if(e.ids!==void 0&&!Array.isArray(e.ids))throw new TypeError("Invalid CMS document IDs");let t=e.ids===void 0?void 0:[...e.ids];for(let o of t??[])if(typeof o!="string"||!re.test(o)||/^(drafts|versions)\./.test(o))throw new TypeError("Invalid CMS document ID");if(new Set(n).size+new Set(t).size>128)throw new TypeError("Too many CMS tags");return Object.freeze({types:Object.freeze(n),...t===void 0?{}:{ids:Object.freeze(t)}})}function A(e){if(!e||typeof e.name!="string"||!/^[A-Za-z][A-Za-z0-9_.-]{0,127}$/.test(e.name)||typeof e.query!="string"||e.query.trim()===""||typeof e.resolve!="function")throw new TypeError("Invalid CMS query configuration");let n=e.params;if(!n||typeof n!="object"||Object.getPrototypeOf(n)!==Object.prototype&&Object.getPrototypeOf(n)!==null)throw new TypeError("CMS params must be plain JSON scalars");let t={};for(let o of Reflect.ownKeys(n)){let r=Object.getOwnPropertyDescriptor(n,o);if(typeof o!="string"||!r||!Object.hasOwn(r,"value")||!r.enumerable)throw new TypeError("CMS params must be plain JSON scalars");let s=r.value;if(!(s===null||typeof s=="string"||typeof s=="boolean"||typeof s=="number"&&Number.isFinite(s)))throw new TypeError("CMS params must be plain JSON scalars");Object.defineProperty(t,o,{value:s,enumerable:!0})}return Object.freeze({name:e.name,query:e.query,params:Object.freeze(t),dependencies:F(e.dependencies),resolve:e.resolve})}function b(e,n){if(typeof e!="string"||e.length>77||!se.test(e))throw new TypeError("Invalid CMS scope");let t=F(n),o=[...[...new Set(t.types)].sort().map(r=>`cms:${e}:type:${r}`),...[...new Set(t.ids??[])].sort().map(r=>`cms:${e}:id:${r}`)];return Object.freeze(o)}function ie(e){return A({name:"menu.v1",query:`*[_type == "menu" && _id == $id && !(_id in path("drafts.**")) && !(_id in path("versions.**"))][0]{${R}}`,params:{id:e},dependencies:{types:["menu"],ids:[e]},resolve:(n,t)=>{if(!P(t)||t!==null&&t._id!==e)throw new TypeError("Invalid CMS menu fallback");if(n==null)return{data:t,fallbackFields:["$"]};let o=x(n);if(o._id!==e)throw new w("menu",["menu._id does not match the requested document"]);return{data:o,fallbackFields:[]}}})}function q(e){if(!e||!Object.hasOwn(e,"data")||!Array.isArray(e.fallbackFields)||![...e.fallbackFields].every(n=>typeof n=="string"&&(n==="$"||/^[A-Za-z][A-Za-z0-9_.[\]-]{0,127}$/.test(n))))throw new TypeError("Invalid CMS resolution");if(e.warnings!==void 0&&(!Array.isArray(e.warnings)||![...e.warnings].every(n=>n==="siteHero.layout.defaulted"||n==="siteHero.tagline.dropped"||n==="siteHero.taglines.defaulted")))throw new TypeError("Invalid CMS resolution warnings");return{data:e.data,fallbackFields:Object.freeze([...new Set(e.fallbackFields)]),...e.warnings?.length?{warnings:Object.freeze([...new Set(e.warnings)])}:{}}}function le(e){let n=e?.revalidateSeconds??3600;if(!Number.isSafeInteger(n)||n<3600||!e?.adapter||typeof e.adapter.read!="function"||e.onDiagnostic!==void 0&&typeof e.onDiagnostic!="function")throw new TypeError("Invalid CMS reader configuration");let t=e.adapter;b(t.scope,{types:["ScopeValidation"]});let o=r=>{try{e.onDiagnostic?e.onDiagnostic(r):console.warn(JSON.stringify(r))}catch{}};return{async read(r,s){let a,g,u;try{if(a=A(r),u=b(t.scope,a.dependencies),!s||!Object.hasOwn(s,"fallback"))throw new TypeError;g=q(a.resolve(null,s.fallback))}catch{throw new TypeError("Invalid CMS query or fallback configuration")}let p=(d,l,h)=>(o({event:"cms.fallback",query:a.name,reason:d,fields:["$"],...l===void 0?{}:{status:l},...h?{warnings:h}:{}}),{data:g.data,source:"fallback",fallbackFields:["$"],reason:d,...h?{warnings:h}:{}}),i;try{i=await t.read({name:a.name,query:a.query,params:a.params},{tags:u,revalidateSeconds:n})}catch{return p("network")}if(!i.ok){let l=["configuration","network","timeout","rate-limit","upstream","plan-limit","permission","malformed"].includes(i.reason)?i.reason:"malformed",h=Number.isInteger(i.status)&&(i.status??0)>=100&&(i.status??0)<=599?i.status:void 0;return p(l,h)}if(i.value===null||i.value===void 0)return p("missing");let c;try{c=q(a.resolve(i.value,s.fallback))}catch{return p("malformed")}return c.fallbackFields.includes("$")?{...p("invalid-field",void 0,c.warnings),data:c.data}:c.fallbackFields.length>0?(o({event:"cms.partial-fallback",query:a.name,reason:"invalid-field",fields:c.fallbackFields,...c.warnings?{warnings:c.warnings}:{}}),{...c,source:"mixed",reason:"invalid-field"}):{...c,source:"cms"}}}}var k=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),m=e=>typeof e=="string"&&e.trim()?e.trim():null,ae=(e,n)=>e._type===n&&typeof e._id=="string"&&e._id.length>0&&!/^(drafts|versions)\./.test(e._id),ue=/^\d{4}-\d{2}-\d{2}$/,U=/^([01]\d|2[0-3]):[0-5]\d$/,ce=["mon","tue","wed","thu","fri","sat","sun"];async function de(e,n,t){try{let o=await e.read(n,{fallback:t});return{...o,source:o.source==="cms"?"sanity":o.source}}catch{return{data:t,source:"fallback",fallbackFields:["$"],reason:"configuration"}}}var ye=/^[A-Za-z0-9._+-]{1,64}@[A-Za-z0-9-]{1,63}(?:\.[A-Za-z0-9-]{1,63})*\.[A-Za-z]{2,63}$/;function pe(e){let n=m(e);if(!n)return null;try{let t=new URL(n);return t.protocol==="http:"||t.protocol==="https:"?t.href:null}catch{return null}}function T(e){if(typeof e!="function")throw new TypeError("A client validator is required")}function B(e,n,t){if(T(t),!k(e)||e.status!=="open")return null;let o=m(e.closingDate);if(o!==null&&o<n||t(e)!==null)return null;let r=m(e.title),s=k(e.workLocation)?e.workLocation:null,a=m(e.location),g=m(s?.name)??(a==="Other"?null:a)??m(e.locationNote);if(!r||!g)return null;let u=m(e.pdfUrl);return{id:String(m(e._id)),title:r,location:g,locationId:s===null?null:m(s._id),summary:m(e.summary),pdfUrl:u?.startsWith("https://cdn.sanity.io/files/")?u:null,applyUrl:pe(e.applyUrl),applyEmail:typeof e.applyEmail=="string"&&e.applyEmail.length<=254&&ye.test(e.applyEmail)?e.applyEmail:null}}function H(e,n,t){if(T(t),!Array.isArray(e))throw new TypeError("Sanity returned vacancies that are not a list");return e.map(o=>({value:B(o,n,t),order:k(o)&&typeof o.order=="number"&&Number.isFinite(o.order)?o.order:1e6})).filter(o=>o.value!==null).sort((o,r)=>o.order-r.order||o.value.title.toLowerCase().localeCompare(r.value.title.toLowerCase())).map(o=>o.value)}function fe(e){return b(e,{types:["vacancy","location"]})}function me(e,n){if(!ue.test(e))throw new TypeError("Invalid calendar date");return T(n),A({name:"vacancy.open.v2",query:'*[_type == "vacancy" && status == "open" && !(_id in path("drafts.**")) && !(_id in path("versions.**")) && (!defined(closingDate) || closingDate >= $today)]|order(coalesce(order, 1000000) asc, lower(title) asc){_id, _type, title, "workLocation": workLocation->{_id, name}, location, locationNote, summary, "pdfUrl": jobDescriptionPdf.asset->url, applyUrl, applyEmail, status, closingDate, order}',params:{today:e},dependencies:{types:["vacancy","location"]},resolve:(t,o)=>({data:t==null?o:H(t,e,n),fallbackFields:t==null?["$"]:[]})})}var ge=["monday","tuesday","wednesday","thursday","friday","saturday","sunday"],he=/^[a-z0-9]+(?:-[a-z0-9]+)*$/;function D(e){return!k(e)||typeof e._id!="string"||!k(e.slug)||typeof e.slug.current!="string"||!he.test(e.slug.current)||m(e.name)===null||e.addressLines!==void 0&&e.addressLines!==null&&(!Array.isArray(e.addressLines)||Array.from(e.addressLines).some(n=>m(n)===null))||e.postcode!==void 0&&e.postcode!==null&&m(e.postcode)===null||e.coordinates!==void 0&&e.coordinates!==null&&(!k(e.coordinates)||typeof e.coordinates.lat!="number"||!Number.isFinite(e.coordinates.lat)||typeof e.coordinates.lng!="number"||!Number.isFinite(e.coordinates.lng))||e.phone!==void 0&&e.phone!==null&&typeof e.phone!="string"||e.email!==void 0&&e.email!==null&&typeof e.email!="string"?null:{name:m(e.name),slug:e.slug.current,addressLines:e.addressLines==null?e.addressLines:e.addressLines.map(n=>n.trim()),postcode:e.postcode==null?e.postcode:String(e.postcode).trim(),coordinates:e.coordinates==null?e.coordinates:{lat:e.coordinates.lat,lng:e.coordinates.lng},phone:e.phone,email:e.email,hours:e.hours}}function Q(e){if(!k(e))return null;let n={};for(let t of ge){let o=e[t];if(!Array.isArray(o)||!Array.from(o).every(r=>k(r)&&typeof r.opens=="string"&&typeof r.closes=="string"))return null;n[t]=o.map(r=>({opens:r.opens,closes:r.closes}))}return n}function z(e,n,t){T(t);let o=D(e);if(o===null||o.slug!==n.id)return{data:n,fallbackFields:["$"]};let r=Q(o.hours),s={id:n.id,label:o.name,addressLines:o.addressLines??n.addressLines,postcode:o.postcode??n.postcode,geo:o.coordinates==null?n.geo:{latitude:o.coordinates.lat,longitude:o.coordinates.lng},telephone:o.phone===void 0?n.telephone:o.phone,email:o.email===void 0?n.email:o.email,hours:r??n.hours};try{return{data:t(s),fallbackFields:r===null?["hours"]:[]}}catch{if(r!==null)try{return{data:t({...s,hours:n.hours}),fallbackFields:["hours"]}}catch{}return{data:n,fallbackFields:["$"]}}}function V(e,n,t){T(t);let o=D(e);if(o===null||o.slug!==n.id)return{data:n,fallbackFields:["$"]};let r=Q(o.hours),s={...n,label:o.name,address:n.address===null?null:{...n.address,streetAddress:o.addressLines??n.address.streetAddress,postalCode:o.postcode??n.address.postalCode},telephone:o.phone===void 0?n.telephone:o.phone,email:o.email===void 0?n.email:o.email,geo:o.coordinates==null?n.geo:{latitude:o.coordinates.lat,longitude:o.coordinates.lng},hours:r??n.hours};try{return{data:t(s),fallbackFields:r===null?["hours"]:[]}}catch{if(r!==null)try{return{data:t({...s,hours:n.hours}),fallbackFields:["hours"]}}catch{}return{data:n,fallbackFields:["$"]}}}function ke(e){return b(e,{types:["location"]})}function J(e,n){return A({name:e,query:'*[_type == "location" && defined(slug.current) && !(_id in path("drafts.**")) && !(_id in path("versions.**"))]{_id, _type, name, slug, addressLines, postcode, coordinates, phone, email, hours}',params:{},dependencies:{types:["location"]},resolve:(t,o)=>{if(!Array.isArray(t))return{data:o,fallbackFields:["$"]};let r=new Map,s=new Set;for(let u of t){let p=D(u);p!==null&&(r.has(p.slug)?s.add(p.slug):r.set(p.slug,u))}let a=[];return{data:o.map((u,p)=>{let i=r.get(u.id),c=i===void 0||s.has(u.id)?{data:u,fallbackFields:["$"]}:n(i,u);return a.push(...c.fallbackFields.map(d=>d==="$"?`locations[${p}]`:`locations[${p}].${d}`)),c.data}),fallbackFields:o.length>0&&a.length===o.length&&a.every(u=>/^locations\[\d+\]$/.test(u))?["$"]:a}}})}function be(e){return T(e),J("locations.v1",(n,t)=>z(n,t,e))}function $e(e){return T(e),J("locations.business.v1",(n,t)=>V(n,t,e))}function Se(e,n,t){let o=`${e}-${n.normalize("NFKD").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"stop"}`,r=o;for(let s=2;t.has(r);s++)r=`${o}-${s}`;return t.add(r),r}function Z(e,n){if(!k(e)||!ae(e,"schedule")||e._id!=="schedule"||e.timeZone!==n.timeZone||!Array.isArray(e.days)||e.days.length!==7)throw new TypeError("Invalid schedule document");let t=e.days.map((o,r)=>{if(!k(o)||o.day!==ce[r]||typeof o.rest!="boolean"||!Array.isArray(o.stops))throw new TypeError("Invalid schedule day");let s=o.day,a=o.rest,g=o.stops,u=n.days.find(d=>d.day===s),p=new Set(u?.stops.map(d=>d.id)??[]),i=new Set,c=g.map(d=>{if(!k(d))throw new TypeError("Invalid schedule stop");let l=d;if(!m(l.name)||!U.test(String(l.from??""))||!U.test(String(l.to??""))||!m(l.address))throw new TypeError("Invalid schedule stop");let h=u?.stops.find($=>$.name===l.name&&!i.has($.id));return h?(i.add(h.id),{...h,name:String(l.name),from:String(l.from),to:String(l.to),address:String(l.address)}):{id:Se(s,String(l.name),p),name:String(l.name),from:String(l.from),to:String(l.to),address:String(l.address),place:null,postcode:null,notes:null,lat:null,lng:null,coordinateSource:null,approximate:!1,needsConfirmation:null,captured:`${l.name}
|
|
6
6
|
${l.from}-${l.to}
|
|
7
|
-
${l.address}`}});return{day:s,rest:a,stops:a?[]:
|
|
7
|
+
${l.address}`}});return{day:s,rest:a,stops:a?[]:c}});return{timeZone:n.timeZone,days:t}}function _e(e){return b(e,{types:["schedule"],ids:["schedule"]})}function Ce(){return A({name:"schedule.v1",query:'*[_type == "schedule" && _id == "schedule" && !(_id in path("drafts.**")) && !(_id in path("versions.**"))][0]{_id, _type, timeZone, days}',params:{},dependencies:{types:["schedule"],ids:["schedule"]},resolve:(e,n)=>({data:e==null?n:Z(e,n),fallbackFields:e==null?["$"]:[]})})}export{E as MENU_DECORATIONS,I as MENU_LAYOUTS,O as MENU_LAYOUT_DEFAULTS,$e as businessLocationsQuery,le as createCmsReader,ke as locationTags,be as locationsQuery,ie as menuQuery,W as menuTags,me as openVacanciesQuery,V as parseBusinessLocation,z as parseLocationDocument,x as parseMenuDocument,Z as parseScheduleDocument,H as parseVacancies,B as parseVacancyDocument,de as resolveWithFallback,Ce as scheduleQuery,_e as scheduleTags,fe as vacancyTags};
|
|
8
8
|
//# sourceMappingURL=server.mjs.map
|